1.1 --- a/src/main.c Wed Feb 09 22:05:42 2011 +0000 1.2 +++ b/src/main.c Wed Feb 09 23:45:55 2011 +0000 1.3 @@ -211,15 +211,18 @@ 1.4 const uint32_t TIMESLOT_FREQUENCY = 1000;//240; // Hz 1.5 const uint32_t MILLISECS_PER_TIMESLOT = 1e3 / TIMESLOT_FREQUENCY; 1.6 const uint32_t CLOCKS_PER_60HZ = (10e6 / 60); 1.7 + const uint32_t CLOCKS_PER_KBC_REFRESH = (10e6 / 10); 1.8 uint32_t next_timeslot = SDL_GetTicks() + MILLISECS_PER_TIMESLOT; 1.9 - uint32_t clock_cycles = 0; 1.10 + uint32_t clock_cycles = 0, keyb_clocks = 0, tmp; 1.11 bool exitEmu = false; 1.12 - bool lastirq_fdc = false; 1.13 + bool lastirq_fdc = false, lastirq_kbc = false; 1.14 for (;;) { 1.15 // Run the CPU for however many cycles we need to. CPU core clock is 1.16 // 10MHz, and we're running at 240Hz/timeslot. Thus: 10e6/240 or 1.17 // 41667 cycles per timeslot. 1.18 - clock_cycles += m68k_execute(10e6/TIMESLOT_FREQUENCY); 1.19 + tmp = m68k_execute(10e6/TIMESLOT_FREQUENCY); 1.20 + clock_cycles += tmp; 1.21 + keyb_clocks += tmp; 1.22 1.23 // Run the DMA engine 1.24 if (state.dmaen) { 1.25 @@ -333,14 +336,15 @@ 1.26 if (wd2797_get_irq(&state.fdc_ctx)) { 1.27 lastirq_fdc = true; 1.28 m68k_set_irq(2); 1.29 - } else { 1.30 - lastirq_fdc = false; 1.31 } 1.32 -*/ if (keyboard_get_irq(&state.kbd)) { 1.33 - // TODO: this is a LEVEL, not an EDGE! 1.34 - m68k_set_irq(3); 1.35 +*/ if (!lastirq_kbc) { 1.36 + if (keyboard_get_irq(&state.kbd)) { 1.37 + lastirq_fdc = true; 1.38 + m68k_set_irq(3); 1.39 + } 1.40 } else { 1.41 lastirq_fdc = wd2797_get_irq(&state.fdc_ctx); 1.42 + lastirq_kbc = keyboard_get_irq(&state.kbd); 1.43 m68k_set_irq(0); 1.44 } 1.45 1.46 @@ -349,10 +353,16 @@ 1.47 // Refresh the screen 1.48 refreshScreen(screen); 1.49 // TODO: trigger periodic interrupt (if enabled) 1.50 + // decrement clock cycle counter, we've handled the intr. 1.51 + clock_cycles -= CLOCKS_PER_60HZ; 1.52 + } 1.53 + 1.54 + // Is it time to run the keyboard refresh yet? 1.55 + if (keyb_clocks > CLOCKS_PER_KBC_REFRESH) { 1.56 // scan the keyboard 1.57 keyboard_scan(&state.kbd); 1.58 - // decrement clock cycle counter, we've handled the intr. 1.59 - clock_cycles -= CLOCKS_PER_60HZ; 1.60 + // decrement clock cycle counter 1.61 + keyb_clocks -= CLOCKS_PER_KBC_REFRESH; 1.62 } 1.63 1.64 // handle SDL events -- returns true if we need to exit