src/main.c

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