From 976d6018964b7e33714adde20de9209bc116e112 Mon Sep 17 00:00:00 2001 From: Brad Grantham Date: Tue, 31 Jul 2018 12:01:19 -0700 Subject: [PATCH] add platform files Add files defining platform constants In particular, break out platform.c and do not optimize so that side-effects are honored. --- platform.c | 35 +++++++++++++++++++++++++++++++++++ platform.h | 11 +++++++++++ 2 files changed, 46 insertions(+) create mode 100644 platform.c create mode 100644 platform.h diff --git a/platform.c b/platform.c new file mode 100644 index 0000000..9bb7f83 --- /dev/null +++ b/platform.c @@ -0,0 +1,35 @@ +#include "platform.h" + +#define KBD_STATUS_OR_KEY ((volatile unsigned char *)0xC000) +#define KBD_CLEAR_CURRENT_KEY ((volatile unsigned char *)0xC010) + +#define KEY_READY_MASK 0x80 +#define KEY_VALUE_MASK 0x7F + +// Returns non-zero if a key is ready to be read. +int keyboard_test(void) +{ + return *KBD_STATUS_OR_KEY & KEY_READY_MASK; +} + +// Clears current key, sets up next one for test or get +void keyboard_clear(void) +{ + unsigned char clear_key; + + // On 6502, a write cycle READS AND THEN WRITES, so just read the + // "latch next key" strobe. + clear_key = *KBD_CLEAR_CURRENT_KEY; +} + +// Wait until a key is ready and then return it without high bit set +unsigned char keyboard_get(void) +{ + unsigned char key; + + while(!((key = *KBD_STATUS_OR_KEY) & KEY_READY_MASK)); + + keyboard_clear(); + + return key & KEY_VALUE_MASK; +} diff --git a/platform.h b/platform.h new file mode 100644 index 0000000..eae9beb --- /dev/null +++ b/platform.h @@ -0,0 +1,11 @@ +#define TEXT_PAGE1_BASE ((volatile unsigned char *)0x400) +#define TEXT_PAGE2_BASE ((volatile unsigned char *)0x800) + +// Returns non-zero if a key is ready to be read. +extern int keyboard_test(void); + +// Clears current key, sets up next one for test or get +extern void keyboard_next(void); + +// Wait until a key is ready and then return it without high bit set +extern unsigned char keyboard_get(void);