Changes in emu/cpu.c [05e6dbe:212bc4c] in buchla-emu


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/cpu.c

    r05e6dbe r212bc4c  
    5252} hw_t;
    5353
    54 static uint64_t freq;
    55 static uint64_t quan;
    56 
    57 SDL_mutex *cpu_mutex;
    58 
    5954static bool reset = true;
    6055
     
    7469static hw_t hw_map[] = {
    7570        { 0x180000, 0x200000, 0, fpu_init, fpu_quit, fpu_exec, fpu_read, fpu_write },
    76         { 0x200000, 0x280002, 0, vid_init, vid_quit, vid_exec, vid_read, vid_write },
    77         { 0x3a0001, 0x3a4001, 0, tim_init, tim_quit, tim_exec, tim_read, tim_write },
     71        { 0x200000, 0x280000, 0, vid_init, vid_quit, vid_exec, vid_read, vid_write },
     72        { 0x3a0001, 0x3a4001, 4, tim_init, tim_quit, tim_exec, tim_read, tim_write },
    7873        { 0x3a4001, 0x3a8001, 0, lcd_init, lcd_quit, lcd_exec, lcd_read, lcd_write },
    7974        { 0x3a8001, 0x3ac001, 5, ser_init, ser_quit, ser_exec, ser_read, ser_write },
     
    384379        }
    385380
    386         // once midas.abs gets loaded, activate RAM
     381        // handle loading midas.abs
    387382
    388383        if (addr == APP_START) {
    389                 ram_data[addr] = (uint8_t)val;
    390384                ram_rw_beg = APP_START;
    391385                ram_rw_end = RAM_START + RAM_SIZE;
     
    468462}
    469463
    470 uint8_t cpu_peek(int32_t addr)
    471 {
    472         if (addr >= RAM_START && addr <= RAM_START + RAM_SIZE - 1) {
    473                 return ram_data[addr - RAM_START];
    474         }
    475 
    476         if (addr >= ROM_START && addr <= ROM_START + ROM_SIZE - 1) {
    477                 return rom_data[addr - ROM_START];
    478         }
    479 
    480         return 0;
    481 }
    482 
    483 void cpu_poke(int32_t addr, uint8_t val)
    484 {
    485         if (addr >= RAM_START && addr <= RAM_START + RAM_SIZE - 1) {
    486                 ram_data[addr - RAM_START] = val;
    487         }
    488 
    489         if (addr >= ROM_START && addr <= ROM_START + ROM_SIZE - 1) {
    490                 rom_data[addr - ROM_START] = val;
    491         }
    492 }
    493 
    494464static void inst_cb(void)
    495465{
    496466        uint32_t pc = m68k_get_reg(NULL, M68K_REG_PC);
    497467        uint32_t op = m68k_read_memory_16(pc);
    498 
    499         gdb_inst(op == 0x4e4f);
    500468
    501469        if (op == 0x4e4d) {
     
    651619}
    652620
    653 void cpu_init(void)
    654 {
    655         cpu_mutex = SDL_CreateMutex();
    656 
    657         if (cpu_mutex == NULL) {
    658                 fail("SDL_CreateMutex() failed: %s", SDL_GetError());
    659         }
    660 
    661         freq = SDL_GetPerformanceFrequency();
    662         quan = freq / PER_SEC;
    663 
    664         inf("freq %" PRIu64 " quan %" PRIu64, freq, quan);
    665 
     621void cpu_loop(void)
     622{
    666623        hw_init();
    667624        bios_init();
    668625
     626        inf("entering CPU loop");
    669627        m68k_init();
    670628        m68k_set_cpu_type(M68K_CPU_TYPE_68000);
    671629        m68k_set_instr_hook_callback(inst_cb);
    672630        m68k_pulse_reset();
    673 }
    674 
    675 void cpu_quit(void)
    676 {
    677         hw_quit();
    678         SDL_DestroyMutex(cpu_mutex);
    679 }
    680 
    681 void cpu_loop(void)
    682 {
    683         inf("entering CPU loop");
    684         int32_t count = 0;
    685 
    686         while (SDL_AtomicGet(&run) != 0) {
     631
     632        uint64_t freq = SDL_GetPerformanceFrequency();
     633        uint64_t quan = freq / PER_SEC;
     634        inf("freq %" PRIu64 " quan %" PRIu64, freq, quan);
     635
     636        bool run = true;
     637
     638#if defined EMU_LINUX
     639        SDL_Scancode down = SDL_SCANCODE_UNKNOWN;
     640#endif
     641
     642        while (run) {
    687643                uint64_t until = SDL_GetPerformanceCounter() + quan;
    688 
    689                 if (SDL_LockMutex(cpu_mutex) < 0) {
    690                         fail("SDL_LockMutex() failed: %s", SDL_GetError());
    691                 }
    692644
    693645                m68k_execute(CPU_FREQ / PER_SEC);
     
    700652                m68k_set_irq(irq);
    701653
    702                 if (SDL_UnlockMutex(cpu_mutex) < 0) {
    703                         fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
    704                 }
    705 
    706                 if ((++count & 0x1ff) == 0) {
    707                         SDL_Delay(0);
     654                SDL_Event ev;
     655
     656                while (SDL_PollEvent(&ev) > 0) {
     657#if defined EMU_LINUX
     658                        // Work around duplicate key-down events on Linux.
     659
     660                        if (ev.type == SDL_KEYDOWN) {
     661                                if (down == ev.key.keysym.scancode) {
     662                                        continue;
     663                                }
     664
     665                                down = ev.key.keysym.scancode;
     666                        }
     667                        else if (ev.type == SDL_KEYUP) {
     668                                down = SDL_SCANCODE_UNKNOWN;
     669                        }
     670#endif
     671
     672                        if (ev.type == SDL_QUIT ||
     673                                        (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_ESCAPE)) {
     674                                run = false;
     675                                continue;
     676                        }
     677
     678                        if (ev.type == SDL_TEXTINPUT) {
     679                                ser_text(&ev.text);
     680                                continue;
     681                        }
     682
     683                        if (ev.type == SDL_KEYDOWN) {
     684                                ser_key(&ev.key);
     685                                continue;
     686                        }
    708687                }
    709688
    710689                while (SDL_GetPerformanceCounter() < until) {
    711                         for (int32_t i = 0; i < 100; ++i) {
    712                                 _mm_pause();
    713                         }
     690                        _mm_pause();
    714691                }
    715692        }
    716693
    717694        inf("leaving CPU loop");
    718 }
     695        hw_quit();
     696}
Note: See TracChangeset for help on using the changeset viewer.