mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-25 17:52:27 +11:00
Add code to read KB
This commit is contained in:
parent
d8f5c22350
commit
8ea172e603
6 changed files with 50 additions and 14 deletions
2
Makefile
2
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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
20
src/input.c
Normal file
20
src/input.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
16
src/input.h
Normal file
16
src/input.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _INPUT_HEADER_
|
||||
#define _INPUT_HEADER_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
K_NONE = 0,
|
||||
K_UP,
|
||||
K_DOWN,
|
||||
K_LEFT,
|
||||
K_RIGHT,
|
||||
} key;
|
||||
|
||||
key read_kb(void);
|
||||
|
||||
#endif /* _INPUT_HEADER_ */
|
||||
11
src/main.c
11
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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue