diff --git a/Makefile b/Makefile index 80bef68..0884463 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ LIBS=clib-6502.a # Common source files ASM_SRCS = tk2k_startup.s C_SRCS = main.c monitor_subroutines.c utility.c \ - game_graphics.c game_logic.c + game_graphics.c game_logic.c input.c # Object files OBJS = $(ASM_SRCS:%.s=%.o) $(C_SRCS:%.c=%.o) diff --git a/linker-files/linker.scm b/linker-files/linker.scm index 2f179cf..d35ced4 100644 --- a/linker-files/linker.scm +++ b/linker-files/linker.scm @@ -6,8 +6,8 @@ (memory program (address (#x801 . #x1fff)) (type ram) (section (programStart #x801) (startup #x80e) code)) (memory displayPage1 (address (#x2000 . #x3fff)) (type ram)) - (memory datamem (address (#x4000 . #x92ff)) (type ram) (section cdata data_init_table)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it, usermem 1 is used as scratch - (memory upperData (address (#x9300 . #x9fff)) (section cstack zdata heap)) + (memory datamem (address (#x4000 . #x91ff)) (type ram) (section idata cdata data_init_table)) ;;; usermem goes from 0x4000 to 0x9FFFF (included), we are splitting it + (memory upperData (address (#x9200 . #x9fff)) (section cstack zdata data heap)) (memory displayPage2 (address (#xa000 . #xbfff)) (type ram)) (memory io (address (#xc000 . #xc0ff)) (type ram)) (memory rombank (address (#xc100 . #xffff)) (type rom)) diff --git a/src/input.c b/src/input.c new file mode 100644 index 0000000..81acefc --- /dev/null +++ b/src/input.c @@ -0,0 +1,20 @@ +#include "input.h" + +#include "utility.h" +#include "mem_registers.h" + +key read_kb(void) { + POKE(IO_DATAOUT, 0x40); + if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_UP; + + POKE(IO_DATAOUT, 0x20); + if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_DOWN; + + POKE(IO_DATAOUT, 0x10); + if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_RIGHT; + + POKE(IO_DATAOUT, 0x08); + if (PEEK(IO_DATAIN) & DATAIN_KB_MASK) return K_LEFT; + + return K_NONE; +} diff --git a/src/input.h b/src/input.h new file mode 100644 index 0000000..404355d --- /dev/null +++ b/src/input.h @@ -0,0 +1,16 @@ +#ifndef _INPUT_HEADER_ +#define _INPUT_HEADER_ + +#include + +typedef enum { + K_NONE = 0, + K_UP, + K_DOWN, + K_LEFT, + K_RIGHT, +} key; + +key read_kb(void); + +#endif /* _INPUT_HEADER_ */ diff --git a/src/main.c b/src/main.c index 0d5ea5e..eaf19d9 100644 --- a/src/main.c +++ b/src/main.c @@ -6,9 +6,9 @@ #include "utility.h" #include "mem_registers.h" #include "mem_map.h" +#include "input.h" -#include "monitor_subroutines.h" - +void __low_level_init(void); // Low level initialization void __low_level_init(void) { @@ -24,10 +24,11 @@ void __low_level_init(void) { } __task int main(void) { - - + key k; + while(1){ - + lfsr_update(); + k = read_kb(); }; return 0; diff --git a/src/mem_registers.h b/src/mem_registers.h index 63a0394..5ca2394 100644 --- a/src/mem_registers.h +++ b/src/mem_registers.h @@ -11,7 +11,7 @@ #define ZP_WNDBTM 0x0023 // 24, bottom line of the scroll window #define ZP_CH 0x0024 // Displacement from window left for the cursor -#define ZP_CV 0x0025 // Displacement from top of screen (now window!) for the cursor +#define ZP_CV 0x0025 // Displacement from top of screen (not window!) for the cursor #define ZP_INVFLAG 0x0032 // Either 0x00 or 0x7F, set text color inversion #define ZP_PROMPT 0x0033 // Prompt character @@ -21,11 +21,10 @@ #define P3_PWRDUP_REF 0x03F3 #define P3_PWRDUP 0x03F4 // Already-powered-up indicator. If it is set to the content of 0x03F3 XOR'd with 0xA5, the soft reset vector is considered valid -typedef struct { - uint8_t kb: 5; // 0:5 - uint8_t prnt: 6; - uint8_t tapein: 7; -} datain; + +#define DATAIN_KB_MASK 0x3F +#define DATAIN_PRNT_MASK 0x40 +#define DATAIN_TAPEIN_MASK 0x80 #define IO_DATAOUT 0xC000 // (W) To keyboard and printer port #define IO_DATAIN 0xC010 // (R) Data input from keyboard (0:5), printer (6) and tape (7)