src/main.c

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