remove edge-sensive kbc intr handler, was breaking the keyboard stuff. also made kbd refresh at same rate as 60Hz tick.

Thu, 10 Feb 2011 00:07:59 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Thu, 10 Feb 2011 00:07:59 +0000
changeset 92
3d5680edc1f0
parent 91
781c15e60012
child 93
09e3ddeb869a

remove edge-sensive kbc intr handler, was breaking the keyboard stuff. also made kbd refresh at same rate as 60Hz tick.

src/keyboard.c file | annotate | diff | revisions
src/main.c file | annotate | diff | revisions
     1.1 --- a/src/keyboard.c	Wed Feb 09 23:45:55 2011 +0000
     1.2 +++ b/src/keyboard.c	Thu Feb 10 00:07:59 2011 +0000
     1.3 @@ -232,6 +232,7 @@
     1.4  
     1.5  		// If no keys down, then send All Keys Up byte
     1.6  		if (nkeys == 0) {
     1.7 +				printf("\tKBC ALL KEYS UP\n");
     1.8  			ks->buffer[ks->writep] = KEY_ALL_UP;
     1.9  			ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.10  			if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.11 @@ -240,7 +241,7 @@
    1.12  		// TODO: inject "mouse data follows" chunk header and mouse movement info
    1.13  
    1.14  		// Last Entry In List
    1.15 -//		ks->buffer[ks->writep] = 0x80;
    1.16 +//		ks->buffer[ks->writep] = KEY_LIST_END;
    1.17  //		ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.18  //		if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.19  	}
     2.1 --- a/src/main.c	Wed Feb 09 23:45:55 2011 +0000
     2.2 +++ b/src/main.c	Thu Feb 10 00:07:59 2011 +0000
     2.3 @@ -208,21 +208,20 @@
     2.4  	 * The 3B1 CPU runs at 10MHz, with DMA running at 1MHz and video refreshing at
     2.5  	 * around 60Hz (???), with a 60Hz periodic interrupt.
     2.6  	 */
     2.7 +	const uint32_t SYSTEM_CLOCK = 10e6; // Hz
     2.8  	const uint32_t TIMESLOT_FREQUENCY = 1000;//240;	// Hz
     2.9  	const uint32_t MILLISECS_PER_TIMESLOT = 1e3 / TIMESLOT_FREQUENCY;
    2.10 -	const uint32_t CLOCKS_PER_60HZ = (10e6 / 60);
    2.11 -	const uint32_t CLOCKS_PER_KBC_REFRESH = (10e6 / 10);
    2.12 +	const uint32_t CLOCKS_PER_60HZ = (SYSTEM_CLOCK / 60);
    2.13  	uint32_t next_timeslot = SDL_GetTicks() + MILLISECS_PER_TIMESLOT;
    2.14 -	uint32_t clock_cycles = 0, keyb_clocks = 0, tmp;
    2.15 +	uint32_t clock_cycles = 0, tmp;
    2.16  	bool exitEmu = false;
    2.17 -	bool lastirq_fdc = false, lastirq_kbc = false;
    2.18 +	bool lastirq_fdc = false;
    2.19  	for (;;) {
    2.20  		// Run the CPU for however many cycles we need to. CPU core clock is
    2.21  		// 10MHz, and we're running at 240Hz/timeslot. Thus: 10e6/240 or
    2.22  		// 41667 cycles per timeslot.
    2.23 -		tmp = m68k_execute(10e6/TIMESLOT_FREQUENCY);
    2.24 +		tmp = m68k_execute(SYSTEM_CLOCK/TIMESLOT_FREQUENCY);
    2.25  		clock_cycles += tmp;
    2.26 -		keyb_clocks += tmp;
    2.27  
    2.28  		// Run the DMA engine
    2.29  		if (state.dmaen) {
    2.30 @@ -337,14 +336,11 @@
    2.31  				lastirq_fdc = true;
    2.32  				m68k_set_irq(2);
    2.33  			}
    2.34 -*/		if (!lastirq_kbc) {
    2.35 -			if (keyboard_get_irq(&state.kbd)) {
    2.36 -				lastirq_fdc = true;
    2.37 -				m68k_set_irq(3);
    2.38 -			}
    2.39 +*/
    2.40 +		if (keyboard_get_irq(&state.kbd)) {
    2.41 +			m68k_set_irq(3);
    2.42  		} else {
    2.43  			lastirq_fdc = wd2797_get_irq(&state.fdc_ctx);
    2.44 -			lastirq_kbc = keyboard_get_irq(&state.kbd);
    2.45  			m68k_set_irq(0);
    2.46  		}
    2.47  
    2.48 @@ -353,18 +349,12 @@
    2.49  			// Refresh the screen
    2.50  			refreshScreen(screen);
    2.51  			// TODO: trigger periodic interrupt (if enabled)
    2.52 +			// scan the keyboard
    2.53 +			keyboard_scan(&state.kbd);
    2.54  			// decrement clock cycle counter, we've handled the intr.
    2.55  			clock_cycles -= CLOCKS_PER_60HZ;
    2.56  		}
    2.57  
    2.58 -		// Is it time to run the keyboard refresh yet?
    2.59 -		if (keyb_clocks > CLOCKS_PER_KBC_REFRESH) {
    2.60 -			// scan the keyboard
    2.61 -			keyboard_scan(&state.kbd);
    2.62 -			// decrement clock cycle counter
    2.63 -			keyb_clocks -= CLOCKS_PER_KBC_REFRESH;
    2.64 -		}
    2.65 -
    2.66  		// handle SDL events -- returns true if we need to exit
    2.67  		if (HandleSDLEvents(screen))
    2.68  			exitEmu = true;