Wed, 16 Apr 2014 02:20:43 -0600
fixed bus error handling for real this time (save registers before every instruction and push the saved registers if a bus error occurs, since the instruction may have changed registers before the bus error, and also stop the instruction immediately with longjmp so it won't change memory after the bus error)
This isn't actually what a real 68k does, but it is a good enough approximation. A real 68k will jump back into the middle of the faulted instruction and resume it from the memory access that faulted as opposed to restarting from the beginning like this CPU emulation does. It would be a lot harder to do that with the way this CPU library is designed. Newer versions of MESS basically do the same thing (they use a newer version of this library).
philpem@86 | 1 | #ifndef _KEYBOARD_H |
philpem@86 | 2 | #define _KEYBOARD_H |
philpem@86 | 3 | |
philpem@80 | 4 | #include "SDL.h" |
philpem@86 | 5 | |
philpem@80 | 6 | /// Keyboard buffer size in bytes |
philpem@80 | 7 | #define KEYBOARD_BUFFER_SIZE 256 |
philpem@80 | 8 | |
philpem@86 | 9 | typedef struct { |
philpem@80 | 10 | /// Key states |
philpem@80 | 11 | int keystate[0x80]; |
philpem@80 | 12 | |
philpem@80 | 13 | /// Keyboard buffer |
philpem@90 | 14 | uint8_t buffer[KEYBOARD_BUFFER_SIZE]; |
philpem@80 | 15 | |
philpem@80 | 16 | /// Read pointer |
philpem@80 | 17 | size_t readp; |
philpem@80 | 18 | |
philpem@80 | 19 | /// Write pointer |
philpem@80 | 20 | size_t writep; |
philpem@80 | 21 | |
philpem@80 | 22 | /// Number of bytes in keyboard buffer |
philpem@80 | 23 | size_t buflen; |
philpem@80 | 24 | |
philpem@80 | 25 | /// Transmit Interrupt Enable |
philpem@80 | 26 | bool txie; |
philpem@90 | 27 | |
philpem@80 | 28 | /// Receive Interrupt Enable |
philpem@80 | 29 | bool rxie; |
philpem@91 | 30 | |
philpem@91 | 31 | /// "Keyboard State Changed" flag |
philpem@91 | 32 | bool update_flag; |
philpem@86 | 33 | } KEYBOARD_STATE; |
philpem@86 | 34 | |
philpem@86 | 35 | /** |
philpem@80 | 36 | * Initialise a keyboard state block. |
philpem@86 | 37 | * |
philpem@80 | 38 | * Call this once when the keyboard is added to the emulation. |
philpem@86 | 39 | */ |
philpem@80 | 40 | void keyboard_init(KEYBOARD_STATE *ks); |
philpem@86 | 41 | |
philpem@86 | 42 | /** |
philpem@80 | 43 | * SDL_Event delegation routine. |
philpem@86 | 44 | * |
philpem@80 | 45 | * Call this when an SDL keyup or keydown event is received. |
philpem@86 | 46 | */ |
philpem@80 | 47 | void keyboard_event(KEYBOARD_STATE *ks, SDL_Event *ev); |
philpem@80 | 48 | |
philpem@80 | 49 | /** |
philpem@80 | 50 | * Keyboard scan routine. |
philpem@80 | 51 | * |
philpem@80 | 52 | * Call this periodically to scan the keyboard. 60 times/sec should be fine. |
philpem@80 | 53 | */ |
philpem@80 | 54 | void keyboard_scan(KEYBOARD_STATE *ks); |
philpem@80 | 55 | |
philpem@80 | 56 | bool keyboard_get_irq(KEYBOARD_STATE *ks); |
philpem@80 | 57 | uint8_t keyboard_read(KEYBOARD_STATE *ks, uint8_t addr); |
philpem@80 | 58 | void keyboard_write(KEYBOARD_STATE *ks, uint8_t addr, uint8_t val); |
philpem@86 | 59 | |
philpem@86 | 60 | #endif |