- Timestamp:
- 08/01/2017 10:32:52 PM (7 years ago)
- Branches:
- master
- Children:
- 6e313dd
- Parents:
- ea878ba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emu/cpu.c
rea878ba rbdd5a63 52 52 } hw_t; 53 53 54 static uint64_t freq; 55 static uint64_t quan; 56 57 SDL_mutex *cpu_mutex; 58 54 59 static bool reset = true; 55 60 … … 620 625 } 621 626 622 void cpu_loop(void) 623 { 627 void 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 624 640 hw_init(); 625 641 bios_init(); 626 642 627 inf("entering CPU loop");628 643 m68k_init(); 629 644 m68k_set_cpu_type(M68K_CPU_TYPE_68000); 630 645 m68k_set_instr_hook_callback(inst_cb); 631 646 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 649 void cpu_quit(void) 650 { 651 hw_quit(); 652 SDL_DestroyMutex(cpu_mutex); 653 } 654 655 void cpu_loop(void) 656 { 657 inf("entering CPU loop"); 658 659 while (SDL_AtomicGet(&run) != 0) { 644 660 uint64_t until = SDL_GetPerformanceCounter() + quan; 661 662 if (SDL_LockMutex(cpu_mutex) < 0) { 663 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 664 } 645 665 646 666 m68k_execute(CPU_FREQ / PER_SEC); … … 653 673 m68k_set_irq(irq); 654 674 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()); 688 677 } 689 678 … … 694 683 695 684 inf("leaving CPU loop"); 696 hw_quit(); 697 } 685 }
Note:
See TracChangeset
for help on using the changeset viewer.