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


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/cpu.c

    r212bc4c r05e6dbe  
    5252} hw_t;
    5353
     54static uint64_t freq;
     55static uint64_t quan;
     56
     57SDL_mutex *cpu_mutex;
     58
    5459static bool reset = true;
    5560
     
    6974static hw_t hw_map[] = {
    7075        { 0x180000, 0x200000, 0, fpu_init, fpu_quit, fpu_exec, fpu_read, fpu_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 },
     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 },
    7378        { 0x3a4001, 0x3a8001, 0, lcd_init, lcd_quit, lcd_exec, lcd_read, lcd_write },
    7479        { 0x3a8001, 0x3ac001, 5, ser_init, ser_quit, ser_exec, ser_read, ser_write },
     
    379384        }
    380385
    381         // handle loading midas.abs
     386        // once midas.abs gets loaded, activate RAM
    382387
    383388        if (addr == APP_START) {
     389                ram_data[addr] = (uint8_t)val;
    384390                ram_rw_beg = APP_START;
    385391                ram_rw_end = RAM_START + RAM_SIZE;
     
    462468}
    463469
     470uint8_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
     483void 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
    464494static void inst_cb(void)
    465495{
    466496        uint32_t pc = m68k_get_reg(NULL, M68K_REG_PC);
    467497        uint32_t op = m68k_read_memory_16(pc);
     498
     499        gdb_inst(op == 0x4e4f);
    468500
    469501        if (op == 0x4e4d) {
     
    619651}
    620652
    621 void cpu_loop(void)
    622 {
     653void 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
    623666        hw_init();
    624667        bios_init();
    625668
    626         inf("entering CPU loop");
    627669        m68k_init();
    628670        m68k_set_cpu_type(M68K_CPU_TYPE_68000);
    629671        m68k_set_instr_hook_callback(inst_cb);
    630672        m68k_pulse_reset();
    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) {
     673}
     674
     675void cpu_quit(void)
     676{
     677        hw_quit();
     678        SDL_DestroyMutex(cpu_mutex);
     679}
     680
     681void cpu_loop(void)
     682{
     683        inf("entering CPU loop");
     684        int32_t count = 0;
     685
     686        while (SDL_AtomicGet(&run) != 0) {
    643687                uint64_t until = SDL_GetPerformanceCounter() + quan;
     688
     689                if (SDL_LockMutex(cpu_mutex) < 0) {
     690                        fail("SDL_LockMutex() failed: %s", SDL_GetError());
     691                }
    644692
    645693                m68k_execute(CPU_FREQ / PER_SEC);
     
    652700                m68k_set_irq(irq);
    653701
    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;
     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);
     708                }
     709
     710                while (SDL_GetPerformanceCounter() < until) {
     711                        for (int32_t i = 0; i < 100; ++i) {
     712                                _mm_pause();
    666713                        }
    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                         }
    687                 }
    688 
    689                 while (SDL_GetPerformanceCounter() < until) {
    690                         _mm_pause();
    691714                }
    692715        }
    693716
    694717        inf("leaving CPU loop");
    695         hw_quit();
    696 }
     718}
Note: See TracChangeset for help on using the changeset viewer.