Changes in emu/cpu.c [212bc4c:05e6dbe] in buchla-emu
Legend:
- Unmodified
- Added
- Removed
-
emu/cpu.c
r212bc4c r05e6dbe 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 … … 69 74 static hw_t hw_map[] = { 70 75 { 0x180000, 0x200000, 0, fpu_init, fpu_quit, fpu_exec, fpu_read, fpu_write }, 71 { 0x200000, 0x28000 0, 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 }, 73 78 { 0x3a4001, 0x3a8001, 0, lcd_init, lcd_quit, lcd_exec, lcd_read, lcd_write }, 74 79 { 0x3a8001, 0x3ac001, 5, ser_init, ser_quit, ser_exec, ser_read, ser_write }, … … 379 384 } 380 385 381 // handle loading midas.abs386 // once midas.abs gets loaded, activate RAM 382 387 383 388 if (addr == APP_START) { 389 ram_data[addr] = (uint8_t)val; 384 390 ram_rw_beg = APP_START; 385 391 ram_rw_end = RAM_START + RAM_SIZE; … … 462 468 } 463 469 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 464 494 static void inst_cb(void) 465 495 { 466 496 uint32_t pc = m68k_get_reg(NULL, M68K_REG_PC); 467 497 uint32_t op = m68k_read_memory_16(pc); 498 499 gdb_inst(op == 0x4e4f); 468 500 469 501 if (op == 0x4e4d) { … … 619 651 } 620 652 621 void cpu_loop(void) 622 { 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 623 666 hw_init(); 624 667 bios_init(); 625 668 626 inf("entering CPU loop");627 669 m68k_init(); 628 670 m68k_set_cpu_type(M68K_CPU_TYPE_68000); 629 671 m68k_set_instr_hook_callback(inst_cb); 630 672 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 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) { 643 687 uint64_t until = SDL_GetPerformanceCounter() + quan; 688 689 if (SDL_LockMutex(cpu_mutex) < 0) { 690 fail("SDL_LockMutex() failed: %s", SDL_GetError()); 691 } 644 692 645 693 m68k_execute(CPU_FREQ / PER_SEC); … … 652 700 m68k_set_irq(irq); 653 701 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(); 666 713 } 667 else if (ev.type == SDL_KEYUP) {668 down = SDL_SCANCODE_UNKNOWN;669 }670 #endif671 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();691 714 } 692 715 } 693 716 694 717 inf("leaving CPU loop"); 695 hw_quit(); 696 } 718 }
Note:
See TracChangeset
for help on using the changeset viewer.