diff --git a/include/apple2.h b/include/apple2.h index 052736c..01f1382 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -305,12 +305,10 @@ typedef struct { vm_8bit memory_mode; /* - * The last_key field is the ASCII value of the last key that was - * pressed. We also have a simple boolean value to determine if the - * strobe is set (it always is when the key is pressed, and stays - * that way until someone reads the "any-key-down" soft switch). + * We have a simple boolean value to determine if the strobe is set + * (it always is when the key is pressed, and stays that way until + * someone reads the "any-key-down" soft switch). */ - vm_8bit last_key; bool strobe; /* diff --git a/include/apple2.kb.h b/include/apple2.kb.h index 57e4eb3..04af5bd 100644 --- a/include/apple2.kb.h +++ b/include/apple2.kb.h @@ -2,6 +2,10 @@ #define _APPLE2_KB_H_ #include "apple2.h" +#include "vm_screen.h" #include "vm_segment.h" +extern void apple2_kb_map(vm_segment *); +extern SEGMENT_READER(apple2_kb_switch_read); + #endif diff --git a/include/vm_screen.h b/include/vm_screen.h index ce5895a..3f58d8d 100644 --- a/include/vm_screen.h +++ b/include/vm_screen.h @@ -5,6 +5,7 @@ #include #include "vm_area.h" +#include "vm_bits.h" typedef struct { /* @@ -31,10 +32,12 @@ typedef struct { int ycoords; /* - * This is true when a key is pressed, and false if not. We - * determine this from an SDL_PollEvent() call. + * Hang onto the last key pressed and the status of whether a key + * is pressed right now or not. */ + vm_8bit last_key; bool key_pressed; + } vm_screen; extern bool vm_screen_active(vm_screen *); diff --git a/sources.cmake b/sources.cmake index e28164e..d40f748 100644 --- a/sources.cmake +++ b/sources.cmake @@ -4,6 +4,7 @@ set(erc_sources apple2.dbuf.c apple2.dd.c apple2.draw.c + apple2.kb.c apple2.mem.c apple2.pc.c log.c diff --git a/src/apple2.kb.c b/src/apple2.kb.c index 5f90126..039faf1 100644 --- a/src/apple2.kb.c +++ b/src/apple2.kb.c @@ -4,6 +4,23 @@ #include "apple2.kb.h" +/* + * This mapper is considerably simpler than most, because it handles + * only two addresses and only read maps. It merely performs the mapping + * for keyboard switches. + */ +void +apple2_kb_map(vm_segment *seg) +{ + vm_segment_read_map(seg, 0xC000, apple2_kb_switch_read); + vm_segment_read_map(seg, 0xC010, apple2_kb_switch_read); +} + +/* + * This mapper handles reads to switches that report info on the + * keyboard state. Note that there is no write switch function; there + * are only reads that need to be handled. + */ SEGMENT_READER(apple2_kb_switch_read) { apple2 *mach = (apple2 *)_mach; @@ -50,4 +67,8 @@ SEGMENT_READER(apple2_kb_switch_read) // pressed down. return 0; } + + // This can only happen if we were mapped to an address we weren't + // prepared to handle + return 0; } diff --git a/src/apple2.mem.c b/src/apple2.mem.c index d8942a6..f0f65fe 100644 --- a/src/apple2.mem.c +++ b/src/apple2.mem.c @@ -4,9 +4,10 @@ #include "apple2.bank.h" #include "apple2.dbuf.h" -#include "apple2.pc.h" #include "apple2.h" +#include "apple2.kb.h" #include "apple2.mem.h" +#include "apple2.pc.h" #include "objstore.h" static size_t switch_reads[] = { @@ -49,8 +50,13 @@ apple2_mem_map(apple2 *mach, vm_segment *segment) // Here we handle the 80STORE bit for our display buffers. apple2_dbuf_map(segment); + // All of our peripheral card (PC) mapper functions are handled + // here. apple2_pc_map(segment); + // And this handles our keyboard soft switches + apple2_kb_map(segment); + // We will do the mapping for the zero page and stack addresses. // Accessing those addresses can be affected by bank-switching, but // those addresses do not actually exist in the capital diff --git a/src/vm_screen.c b/src/vm_screen.c index 1abeca1..1dfa250 100644 --- a/src/vm_screen.c +++ b/src/vm_screen.c @@ -175,16 +175,16 @@ vm_screen_active(vm_screen *screen) ch = '\0'; // It seems we may have pressed a key... - if (event.key) { + if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) { // The sym field is of type SDL_Keycode; this type, however, // maps roughly to Unicode, which of course maps roughly to // ASCII in the low range. - ch = (char)event.key->keysym.sym; + ch = (char)event.key.keysym.sym; // If we had shift pressed, we need to uppercase the // character. - if (event.key->keysym.mod & KMOD_LSHIFT || - event.key->keysym.mod & KMOD_RSHIFT + if (event.key.keysym.mod & KMOD_LSHIFT || + event.key.keysym.mod & KMOD_RSHIFT ) { ch = toupper(ch); }