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