merge heads

Wed, 09 Feb 2011 22:05:42 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 09 Feb 2011 22:05:42 +0000
changeset 90
934ae2efdd01
parent 85
9883eb142f70
parent 89
22198d0a7bef
child 91
781c15e60012

merge heads

src/keyboard.c file | annotate | diff | revisions
src/keyboard.h file | annotate | diff | revisions
src/main.c file | annotate | diff | revisions
     1.1 --- a/src/keyboard.c	Wed Feb 09 17:11:48 2011 +0000
     1.2 +++ b/src/keyboard.c	Wed Feb 09 22:05:42 2011 +0000
     1.3 @@ -128,6 +128,29 @@
     1.4  	{ SDLK_DELETE,			0,	0x7f }	// Dlete
     1.5  };
     1.6  
     1.7 +/**
     1.8 + * List of special key codes
     1.9 + */
    1.10 +enum {
    1.11 +	KEY_ALL_UP				= 0x40,		///< All keys up
    1.12 +	KEY_LIST_END			= 0x80,		///< End of key code list
    1.13 +	KEY_BEGIN_MOUSE			= 0xCF,		///< Mouse data follows
    1.14 +	KEY_BEGIN_KEYBOARD		= 0xDF,		///< Keyboard data follows
    1.15 +};
    1.16 +
    1.17 +/**
    1.18 + * List of keyboard commands
    1.19 + */
    1.20 +enum {
    1.21 +	KEY_CMD_RESET			= 0x92,		///< Reset keyboard
    1.22 +	KEY_CMD_CAPSLED_OFF		= 0xB1,		///< Caps Lock LED off--CHECK!
    1.23 +	KEY_CMD_CAPSLED_ON		= 0xB0,		///< Caps Lock LED on --CHECK!
    1.24 +	KEY_CMD_NUMLED_OFF		= 0xA1,		///< Num Lock LED off --CHECK!
    1.25 +	KEY_CMD_NUMLED_ON		= 0xA0,		///< Num Lock LED on  --CHECK!
    1.26 +	KEY_CMD_MOUSE_ENABLE	= 0xD0,		///< Enable mouse
    1.27 +	KEY_CMD_MOUSE_DISABLE	= 0xD1		///< Disable mouse
    1.28 +};
    1.29 +
    1.30  void keyboard_init(KEYBOARD_STATE *ks)
    1.31  {
    1.32  	// Set all key states to "not pressed"
    1.33 @@ -141,29 +164,40 @@
    1.34  
    1.35  void keyboard_event(KEYBOARD_STATE *ks, SDL_Event *ev)
    1.36  {
    1.37 -	// Ignore non-keyboard events
    1.38 -	if ((ev->type != SDL_KEYDOWN) && (ev->type != SDL_KEYUP)) return;
    1.39 +	int v = 0;
    1.40 +	switch (ev->type) {
    1.41 +		case SDL_KEYDOWN:
    1.42 +			// Key down (pressed)
    1.43 +			v = 1;
    1.44 +			break;
    1.45 +		case SDL_KEYUP:
    1.46 +			// Key up (released)
    1.47 +			v = 0;
    1.48 +			break;
    1.49 +		default:
    1.50 +			// Not a keyboard event
    1.51 +			return;
    1.52 +	}
    1.53  
    1.54  	// scan the keymap
    1.55 -	int keyidx = 0;
    1.56 -	bool found = false;
    1.57 -	for (keyidx=0; keyidx < sizeof(keymap)/sizeof(keymap[0]); keyidx++) {
    1.58 -		if (keymap[keyidx].key == ev->key.keysym.sym) {
    1.59 -			found = true;
    1.60 -			break;
    1.61 +	for (int i=0; i < sizeof(keymap)/sizeof(keymap[0]); i++) {
    1.62 +		if (keymap[i].key == ev->key.keysym.sym) {
    1.63 +			// Keycode match. Is this an Extended Map key?
    1.64 +			if (keymap[i].extended) {
    1.65 +				// Yes -- need ALT set when pressing the key for this to be a match
    1.66 +				if (ev->key.keysym.mod & KMOD_ALT) {
    1.67 +					ks->keystate[keymap[i].scancode] = v;
    1.68 +					break;
    1.69 +				}
    1.70 +			} else {
    1.71 +				// Standard Map key. ALT must NOT be pressed for this to be a match
    1.72 +				if (!(ev->key.keysym.mod & KMOD_ALT)) {
    1.73 +					ks->keystate[keymap[i].scancode] = v;
    1.74 +					break;
    1.75 +				}
    1.76 +			}
    1.77  		}
    1.78  	}
    1.79 -
    1.80 -	switch (ev->type) {
    1.81 -		// key pressed
    1.82 -		case SDL_KEYDOWN:
    1.83 -			ks->keystate[keymap[keyidx].scancode] = 1;
    1.84 -			break;
    1.85 -		// key released
    1.86 -		case SDL_KEYUP:
    1.87 -			ks->keystate[keymap[keyidx].scancode] = 0;
    1.88 -			break;
    1.89 -	}
    1.90  }
    1.91  
    1.92  void keyboard_scan(KEYBOARD_STATE *ks)
     2.1 --- a/src/keyboard.h	Wed Feb 09 17:11:48 2011 +0000
     2.2 +++ b/src/keyboard.h	Wed Feb 09 22:05:42 2011 +0000
     2.3 @@ -11,7 +11,7 @@
     2.4  	int keystate[0x80];
     2.5  
     2.6  	/// Keyboard buffer
     2.7 -	char buffer[KEYBOARD_BUFFER_SIZE];
     2.8 +	uint8_t buffer[KEYBOARD_BUFFER_SIZE];
     2.9  
    2.10  	/// Read pointer
    2.11  	size_t readp;
    2.12 @@ -24,6 +24,7 @@
    2.13  
    2.14  	/// Transmit Interrupt Enable
    2.15  	bool txie;
    2.16 +
    2.17  	/// Receive Interrupt Enable
    2.18  	bool rxie;
    2.19  } KEYBOARD_STATE;
     3.1 --- a/src/main.c	Wed Feb 09 17:11:48 2011 +0000
     3.2 +++ b/src/main.c	Wed Feb 09 22:05:42 2011 +0000
     3.3 @@ -340,6 +340,7 @@
     3.4  			// TODO: this is a LEVEL, not an EDGE!
     3.5  			m68k_set_irq(3);
     3.6  		} else {
     3.7 +			lastirq_fdc = wd2797_get_irq(&state.fdc_ctx);
     3.8  			m68k_set_irq(0);
     3.9  		}
    3.10  
     4.1 --- a/src/utils.h	Wed Feb 09 17:11:48 2011 +0000
     4.2 +++ b/src/utils.h	Wed Feb 09 22:05:42 2011 +0000
     4.3 @@ -1,5 +1,7 @@
     4.4 -#ifndef _H_UTILS
     4.5 -#define _H_UTILS
     4.6 +#ifndef _UTILS_H
     4.7 +#define _UTILS_H
     4.8 +
     4.9 +#include <stdio.h>
    4.10  
    4.11  #ifndef NDEBUG
    4.12  /// Log a message to stderr
    4.13 @@ -11,4 +13,7 @@
    4.14  #define LOG_IF(cond, x, ...)
    4.15  #endif
    4.16  
    4.17 +/// Get the number of elements in an array
    4.18 +#define NELEMS(x) (sizeof(x)/sizeof(x[0]))
    4.19 +
    4.20  #endif // _H_UTILS