From 3cdb25bfda518673737a9bad6d2d9d87365e9882 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 29 Jun 2019 11:18:37 -0400 Subject: [PATCH] recipes/rc2014/ps2: implement scan code buffer --- recipes/rc2014/ps2/ps2ctl.asm | 57 +++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/recipes/rc2014/ps2/ps2ctl.asm b/recipes/rc2014/ps2/ps2ctl.asm index c7205c8..352fb6e 100644 --- a/recipes/rc2014/ps2/ps2ctl.asm +++ b/recipes/rc2014/ps2/ps2ctl.asm @@ -33,9 +33,10 @@ ; *** Buffering scan codes *** ; -; The whole SRAM (from SRAM_START to RAMEND) is used as a scan code buffer, with -; Z chasing Y. When Y == Z, the buffer is empty. When RAMEND is reached, we go -; back to SRAM_START. +; The buffer starts at SRAM and stops at 0x100. It leaves space for the stack +; and makes overflow check easy. Also, we don't need a very big buffer. In this +; address space, Z chasing Y. When Y == Z, the buffer is empty. When 0x100 is +; reached, we go back to SRAM_START. ; ; Whenever a new scan code is received, we place it in Y and increase it. ; Whenever we send a scan code to the 595 (which can't be done when Z == Y @@ -59,7 +60,6 @@ ; *** Register Usage *** ; -; R1: when set, indicates that value in R17 is valid ; R2: When set, indicate that the 595 holds a value that hasn't been read by the ; z80 yet. ; R16: tmp stuff @@ -75,7 +75,7 @@ ; R20: data being sent to the 595 ; Y: pointer to the memory location where the next scan code from ps/2 will be ; written. -; Z: pointer to last scan code pushed to the 595 +; Z: pointer to the next scan code to push to the 595 ; ; *** Constants *** ; @@ -104,6 +104,7 @@ hdlPCINT: sbi PORTB, RCLK cbi PORTB, RCLK clr r2 ; 595 is now free + reti main: ldi r16, low(RAMEND) @@ -119,7 +120,6 @@ main: ; init variables - clr r1 clr r2 clr r19 clr r18 @@ -135,6 +135,12 @@ main: ldi r16, (1<