Changeset bdd5a63 in buchla-emu for emu/cpu.c


Ignore:
Timestamp:
08/01/2017 10:32:52 PM (7 years ago)
Author:
Thomas Lopatic <thomas@…>
Branches:
master
Children:
6e313dd
Parents:
ea878ba
Message:

Separate thread for rendering.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • emu/cpu.c

    rea878ba rbdd5a63  
    5252} hw_t;
    5353
     54static uint64_t freq;
     55static uint64_t quan;
     56
     57SDL_mutex *cpu_mutex;
     58
    5459static bool reset = true;
    5560
     
    620625}
    621626
    622 void cpu_loop(void)
    623 {
     627void cpu_init(void)
     628{
     629        cpu_mutex = SDL_CreateMutex();
     630
     631        if (cpu_mutex == NULL) {
     632                fail("SDL_CreateMutex() failed: %s", SDL_GetError());
     633        }
     634
     635        freq = SDL_GetPerformanceFrequency();
     636        quan = freq / PER_SEC;
     637
     638        inf("freq %" PRIu64 " quan %" PRIu64, freq, quan);
     639
    624640        hw_init();
    625641        bios_init();
    626642
    627         inf("entering CPU loop");
    628643        m68k_init();
    629644        m68k_set_cpu_type(M68K_CPU_TYPE_68000);
    630645        m68k_set_instr_hook_callback(inst_cb);
    631646        m68k_pulse_reset();
    632 
    633         uint64_t freq = SDL_GetPerformanceFrequency();
    634         uint64_t quan = freq / PER_SEC;
    635         inf("freq %" PRIu64 " quan %" PRIu64, freq, quan);
    636 
    637         bool run = true;
    638 
    639 #if defined EMU_LINUX
    640         SDL_Scancode down = SDL_SCANCODE_UNKNOWN;
    641 #endif
    642 
    643         while (run) {
     647}
     648
     649void cpu_quit(void)
     650{
     651        hw_quit();
     652        SDL_DestroyMutex(cpu_mutex);
     653}
     654
     655void cpu_loop(void)
     656{
     657        inf("entering CPU loop");
     658
     659        while (SDL_AtomicGet(&run) != 0) {
    644660                uint64_t until = SDL_GetPerformanceCounter() + quan;
     661
     662                if (SDL_LockMutex(cpu_mutex) < 0) {
     663                        fail("SDL_LockMutex() failed: %s", SDL_GetError());
     664                }
    645665
    646666                m68k_execute(CPU_FREQ / PER_SEC);
     
    653673                m68k_set_irq(irq);
    654674
    655                 SDL_Event ev;
    656 
    657                 while (SDL_PollEvent(&ev) > 0) {
    658 #if defined EMU_LINUX
    659                         // Work around duplicate key-down events on Linux.
    660 
    661                         if (ev.type == SDL_KEYDOWN) {
    662                                 if (down == ev.key.keysym.scancode) {
    663                                         continue;
    664                                 }
    665 
    666                                 down = ev.key.keysym.scancode;
    667                         }
    668                         else if (ev.type == SDL_KEYUP) {
    669                                 down = SDL_SCANCODE_UNKNOWN;
    670                         }
    671 #endif
    672 
    673                         if (ev.type == SDL_QUIT ||
    674                                         (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_ESCAPE)) {
    675                                 run = false;
    676                                 continue;
    677                         }
    678 
    679                         if (ev.type == SDL_TEXTINPUT) {
    680                                 ser_text(&ev.text);
    681                                 continue;
    682                         }
    683 
    684                         if (ev.type == SDL_KEYDOWN) {
    685                                 ser_key(&ev.key);
    686                                 continue;
    687                         }
     675                if (SDL_UnlockMutex(cpu_mutex) < 0) {
     676                        fail("SDL_UnlockMutex() failed: %s", SDL_GetError());
    688677                }
    689678
     
    694683
    695684        inf("leaving CPU loop");
    696         hw_quit();
    697 }
     685}
Note: See TracChangeset for help on using the changeset viewer.