src/main.c

changeset 92
3d5680edc1f0
parent 91
781c15e60012
child 95
6e01339b218d
     1.1 diff -r 781c15e60012 -r 3d5680edc1f0 src/main.c
     1.2 --- a/src/main.c	Wed Feb 09 23:45:55 2011 +0000
     1.3 +++ b/src/main.c	Thu Feb 10 00:07:59 2011 +0000
     1.4 @@ -208,21 +208,20 @@
     1.5  	 * The 3B1 CPU runs at 10MHz, with DMA running at 1MHz and video refreshing at
     1.6  	 * around 60Hz (???), with a 60Hz periodic interrupt.
     1.7  	 */
     1.8 +	const uint32_t SYSTEM_CLOCK = 10e6; // Hz
     1.9  	const uint32_t TIMESLOT_FREQUENCY = 1000;//240;	// Hz
    1.10  	const uint32_t MILLISECS_PER_TIMESLOT = 1e3 / TIMESLOT_FREQUENCY;
    1.11 -	const uint32_t CLOCKS_PER_60HZ = (10e6 / 60);
    1.12 -	const uint32_t CLOCKS_PER_KBC_REFRESH = (10e6 / 10);
    1.13 +	const uint32_t CLOCKS_PER_60HZ = (SYSTEM_CLOCK / 60);
    1.14  	uint32_t next_timeslot = SDL_GetTicks() + MILLISECS_PER_TIMESLOT;
    1.15 -	uint32_t clock_cycles = 0, keyb_clocks = 0, tmp;
    1.16 +	uint32_t clock_cycles = 0, tmp;
    1.17  	bool exitEmu = false;
    1.18 -	bool lastirq_fdc = false, lastirq_kbc = false;
    1.19 +	bool lastirq_fdc = false;
    1.20  	for (;;) {
    1.21  		// Run the CPU for however many cycles we need to. CPU core clock is
    1.22  		// 10MHz, and we're running at 240Hz/timeslot. Thus: 10e6/240 or
    1.23  		// 41667 cycles per timeslot.
    1.24 -		tmp = m68k_execute(10e6/TIMESLOT_FREQUENCY);
    1.25 +		tmp = m68k_execute(SYSTEM_CLOCK/TIMESLOT_FREQUENCY);
    1.26  		clock_cycles += tmp;
    1.27 -		keyb_clocks += tmp;
    1.28  
    1.29  		// Run the DMA engine
    1.30  		if (state.dmaen) {
    1.31 @@ -337,14 +336,11 @@
    1.32  				lastirq_fdc = true;
    1.33  				m68k_set_irq(2);
    1.34  			}
    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 +*/
    1.41 +		if (keyboard_get_irq(&state.kbd)) {
    1.42 +			m68k_set_irq(3);
    1.43  		} else {
    1.44  			lastirq_fdc = wd2797_get_irq(&state.fdc_ctx);
    1.45 -			lastirq_kbc = keyboard_get_irq(&state.kbd);
    1.46  			m68k_set_irq(0);
    1.47  		}
    1.48  
    1.49 @@ -353,18 +349,12 @@
    1.50  			// Refresh the screen
    1.51  			refreshScreen(screen);
    1.52  			// TODO: trigger periodic interrupt (if enabled)
    1.53 +			// scan the keyboard
    1.54 +			keyboard_scan(&state.kbd);
    1.55  			// decrement clock cycle counter, we've handled the intr.
    1.56  			clock_cycles -= CLOCKS_PER_60HZ;
    1.57  		}
    1.58  
    1.59 -		// Is it time to run the keyboard refresh yet?
    1.60 -		if (keyb_clocks > CLOCKS_PER_KBC_REFRESH) {
    1.61 -			// scan the keyboard
    1.62 -			keyboard_scan(&state.kbd);
    1.63 -			// decrement clock cycle counter
    1.64 -			keyb_clocks -= CLOCKS_PER_KBC_REFRESH;
    1.65 -		}
    1.66 -
    1.67  		// handle SDL events -- returns true if we need to exit
    1.68  		if (HandleSDLEvents(screen))
    1.69  			exitEmu = true;