1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/keyboard.h Wed Feb 09 15:03:31 2011 +0000 1.3 @@ -0,0 +1,56 @@ 1.4 +#ifndef _KEYBOARD_H 1.5 +#define _KEYBOARD_H 1.6 + 1.7 +#include "SDL.h" 1.8 + 1.9 +/// Keyboard buffer size in bytes 1.10 +#define KEYBOARD_BUFFER_SIZE 256 1.11 + 1.12 +typedef struct { 1.13 + /// Key states 1.14 + int keystate[0x80]; 1.15 + 1.16 + /// Keyboard buffer 1.17 + char buffer[KEYBOARD_BUFFER_SIZE]; 1.18 + 1.19 + /// Read pointer 1.20 + size_t readp; 1.21 + 1.22 + /// Write pointer 1.23 + size_t writep; 1.24 + 1.25 + /// Number of bytes in keyboard buffer 1.26 + size_t buflen; 1.27 + 1.28 + /// Transmit Interrupt Enable 1.29 + bool txie; 1.30 + /// Receive Interrupt Enable 1.31 + bool rxie; 1.32 +} KEYBOARD_STATE; 1.33 + 1.34 +/** 1.35 + * Initialise a keyboard state block. 1.36 + * 1.37 + * Call this once when the keyboard is added to the emulation. 1.38 + */ 1.39 +void keyboard_init(KEYBOARD_STATE *ks); 1.40 + 1.41 +/** 1.42 + * SDL_Event delegation routine. 1.43 + * 1.44 + * Call this when an SDL keyup or keydown event is received. 1.45 + */ 1.46 +void keyboard_event(KEYBOARD_STATE *ks, SDL_Event *ev); 1.47 + 1.48 +/** 1.49 + * Keyboard scan routine. 1.50 + * 1.51 + * Call this periodically to scan the keyboard. 60 times/sec should be fine. 1.52 + */ 1.53 +void keyboard_scan(KEYBOARD_STATE *ks); 1.54 + 1.55 +bool keyboard_get_irq(KEYBOARD_STATE *ks); 1.56 +uint8_t keyboard_read(KEYBOARD_STATE *ks, uint8_t addr); 1.57 +void keyboard_write(KEYBOARD_STATE *ks, uint8_t addr, uint8_t val); 1.58 + 1.59 +#endif