From 177e70580fcf57c7dba61aa0ea7d4f59220a58f6 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 17 May 2020 14:24:27 -0400 Subject: [PATCH] sms/kbd: begin rewriting ps2ctl to Forth So far, the resulting binary matches. --- blk/665 | 2 +- emul/avra.sh | 2 +- recipes/sms/kbd/Makefile | 15 +++-------- recipes/sms/kbd/ps2ctl.fs | 53 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 recipes/sms/kbd/ps2ctl.fs diff --git a/blk/665 b/blk/665 index 2e3c917..236bb0a 100644 --- a/blk/665 +++ b/blk/665 @@ -2,7 +2,7 @@ : OPRdK CREATE C, DOES> C@ ( rd K op ) OVER _r256c 0xf0 AND 4 RSHIFT OR ( rd K op' ) ROT _r16+c 4 LSHIFT ROT 0x0f AND OR ( op' rdK ) A, A, ; -0x70 OPRdK ANDI, 0x30 OPRdK CPI, 0x0e OPRdK LDI, +0x70 OPRdK ANDI, 0x30 OPRdK CPI, 0xe0 OPRdK LDI, 0x60 OPRdK ORI, 0x40 OPRdK SBCI, 0x60 OPRdK SBR, 0x50 OPRdK SUBI, diff --git a/emul/avra.sh b/emul/avra.sh index fa3cb13..72b0d23 100755 --- a/emul/avra.sh +++ b/emul/avra.sh @@ -1,2 +1,2 @@ #!/bin/sh -echo -e "660 LOAD H@ 256 /MOD 2 PC! 2 PC! \n$(cat -)\nH@ 256 /MOD 2 PC! 2 PC! " | ./stage +echo -e "660 LOAD H@ ORG !\n$(cat -)\nORG @ 256 /MOD 2 PC! 2 PC! H@ 256 /MOD 2 PC! 2 PC! " | ./stage diff --git a/recipes/sms/kbd/Makefile b/recipes/sms/kbd/Makefile index fd85f08..35249f0 100644 --- a/recipes/sms/kbd/Makefile +++ b/recipes/sms/kbd/Makefile @@ -1,13 +1,9 @@ PROGNAME = ps2ctl AVRDUDEMCU ?= t45 AVRDUDEARGS ?= -c usbtiny -P usb -TARGETS = $(PROGNAME).bin os.sms +TARGETS = $(PROGNAME).bin BASEDIR = ../../.. -ZASM = $(BASEDIR)/emul/zasm/zasm -KERNEL = $(BASEDIR)/kernel -APPS = $(BASEDIR)/apps -AVRA = $(BASEDIR)/emul/zasm/avra -AVRINC = $(BASEDIR)/avr +EDIR = $(BASEDIR)/emul # Rules @@ -19,11 +15,8 @@ all: $(TARGETS) send: $(PROGNAME).bin avrdude $(AVRDUDEARGS) -p $(AVRDUDEMCU) -U flash:w:$(PROGNAME).bin -$(PROGNAME).bin: $(PROGNAME).asm - $(AVRA) $(AVRINC) < $(PROGNAME).asm > $@ - -os.sms: glue.asm - $(ZASM) $(KERNEL) $(APPS) < glue.asm > $@ +$(PROGNAME).bin: $(PROGNAME).fs + cd $(EDIR) && ./avra.sh < ../recipes/sms/kbd/$(PROGNAME).fs > ../recipes/sms/kbd/$@ clean: rm -f $(TARGETS) diff --git a/recipes/sms/kbd/ps2ctl.fs b/recipes/sms/kbd/ps2ctl.fs new file mode 100644 index 0000000..833a62d --- /dev/null +++ b/recipes/sms/kbd/ps2ctl.fs @@ -0,0 +1,53 @@ +( Receives keystrokes from PS/2 keyboard and send them to the +'164. On the PS/2 side, it works the same way as the controller +in the rc2014/ps2 recipe. However, in this case, what we have +on the other side isn't a z80 bus, it's the one of the two +controller ports of the SMS through a DB9 connector. + +The PS/2 related code is copied from rc2014/ps2 without much +change. The only differences are that it pushes its data to a +'164 instead of a '595 and that it synchronizes with the SMS +with a SR latch, so we don't need PCINT. We can also afford to +run at 1MHz instead of 8. + +*** Register Usage *** + +GPIOR0 flags: +0 - when set, indicates that the DATA pin was high when we + received a bit through INT0. When we receive a bit, we set + flag T to indicate it. + +R16: tmp stuff +R17: recv buffer. Whenever we receive a bit, we push it in + there. +R18: recv step: + - 0: idle + - 1: receiving data + - 2: awaiting parity bit + - 3: awaiting stop bit +R19: Register used for parity computations and tmp value in + some other places +R20: data being sent to the '164 +Y: pointer to the memory location where the next scan code from + ps/2 will be written. +Z: pointer to the next scan code to push to the 595 ) + +0x015f CONSTANT RAMEND +0x11 CONSTANT GPIOR0 +0x16 CONSTANT PINB +1 CONSTANT DATA + +H@ ORG ! +L1 FLBL, ( main ) +L2 FLBL, ( hdlINT0 ) + +( Read DATA and set GPIOR0/0 if high. Then, set flag T. + no SREG fiddling because no SREG-modifying instruction ) +RJMPOP L2 FLBL! ( hdlINT0 ) +PINB DATA SBIC, +GPIOR0 0 SBI, +SET, +RETI, + +RJMPOP L1 FLBL! ( main ) +16 RAMEND 0xff AND LDI,