summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2003-09-08 04:01:32 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2003-09-08 04:01:32 (GMT)
commita579b98814f0bd4eb7cc11915d3f48d8e67f36c3 (patch)
tree96d5eee7999c5f64c926e079a28646bd0cc66e22
parentbfffcd2b83eaa4feb5582000c321ae5208143d0b (diff)
downloadkeyboard-a579b98814f0bd4eb7cc11915d3f48d8e67f36c3.zip
keyboard-a579b98814f0bd4eb7cc11915d3f48d8e67f36c3.tar.gz
keyboard-a579b98814f0bd4eb7cc11915d3f48d8e67f36c3.tar.bz2
keyboard-a579b98814f0bd4eb7cc11915d3f48d8e67f36c3.tar.xz
*** empty log message ***
-rw-r--r--data/Makefile1
-rw-r--r--data/keyboard.asm120
2 files changed, 116 insertions, 5 deletions
diff --git a/data/Makefile b/data/Makefile
index 9db3228..88817a4 100644
--- a/data/Makefile
+++ b/data/Makefile
@@ -7,6 +7,7 @@ BIN2MIF = ./bin2mif.pl
.obj.bin:
linkz80 -r $@ $< || ( rm -f $@ ; exit 1 )
+ ls -l $@
all : keyboard.mif
diff --git a/data/keyboard.asm b/data/keyboard.asm
index b315494..839431f 100644
--- a/data/keyboard.asm
+++ b/data/keyboard.asm
@@ -47,15 +47,15 @@ r24_done
;
; Delay a specific number of microseconds in A; this
- ; assumes a 50 MHz clock.
+ ; assumes a 50 MHz clock. A = 0 on return
;
-us_delay
+udelay
push hl ; 11 cycles
inc hl ; 6 cycles
dec hl ; 6 cycles
pop hl ; 10 cycles
dec a ; 4 cycles
- jr nz,us_delay ; 12 cycles (taken)
+ jr nz,udelay ; 12 cycles (taken)
ret
; Probe the status of the keyboard port; require N/2
@@ -91,13 +91,14 @@ read_byte
ld a,#0x1F ; Control port; no drivers
out (#0),a
+rb_loop
rb_waitclk ; Wait for CLK# = 0
ld e,#0x02
call (debounce)
jr c,rb_waitclk
ld a,#2
- call (us_delay)
+ call (udelay)
ld e,#0x01
call (debounce)
@@ -110,7 +111,7 @@ rb_waitnoclk ; Wait for CLK# = 1
jr nc,rb_waitnoclk
; More bits to get...
- djnz rb_waitclk
+ djnz rb_loop
; Now the proper value is in bits <13:6> in HL
sla l
@@ -124,6 +125,71 @@ rb_waitnoclk ; Wait for CLK# = 1
pop bc
ret
+
+ ;
+ ; Send a byte (A) to the keyboard
+ ;
+write_byte
+ push bc
+ push de
+ push hl
+
+ ld h,#0xfe ; Stop+ack bit
+ and a
+ jp po,(wb_parity)
+ inc h ; If parity is not odd, set parity bit
+wb_parity
+ ld l,a
+ ; Now HL contains the whole bit string to be sent, including
+ ; data+parity+stop+ack, but not including the start bit,
+ ; starting with the LSB. The start bit is a bit special,
+ ; since we have to clock it ourselves. On the other hand,
+ ; ack is just a normal bit for which we do not assert the data
+ ; line.
+ ld b,#11 ; Numbers of bits in HL
+
+ ld a,#0x1d ; Assert CLK#
+ out (#0),a
+ ld a,#150 ; 150 us
+ call (udelay)
+
+ ld a,#0x1c ; Assert DATA#
+ out (#0),a
+ ld a,#10 ; 10 us
+ call (udelay)
+
+ ld a,#0x1e ; Release CLK#
+ out (#0),a
+
+wb_loop
+wb_waitclk ; Wait for CLK# = 0
+ ld e,#0x02
+ call (debounce)
+ jr c,wb_waitclk
+
+ ld a,#5
+ call (udelay)
+ ; A = 0
+
+ srl h
+ rr l
+ ; Now flag C = bit to send
+ adc a,#0x1e ; 1E for zero, 1F for one
+ out (#0),a
+
+wb_waitnoclk ; Wait for CLK# = 1
+ ld e,#0x02
+ call (debounce)
+ jr nc,wb_waitnoclk
+
+ ; More to send...
+ djnz wb_loop
+
+ pop hl
+ pop de
+ pop bc
+ ret
+
;
; Display a hexadecimal number on the serial port
;
@@ -159,11 +225,55 @@ printhex
hextbl
byte "0123456789ABCDEF"
+ ;
+ ; Send a byte to the keyboard that is expected to be replied
+ ; with ACK (FA). If we get resend (FE) instead, resend,
+ ; otherwise assume it was a stray byte and wait.
+ ; Returns reply in A; trashes E
+ ;
+send_with_ack
+ ld e,a
+ push af ; Debug
+ ld a,#0x3c
+ rst 8
+ pop af
+ call (printhex)
+
+ call (write_byte)
+swa_reply
+ call (read_byte)
+ push af ; Debug
+ ld a,#0x3e
+ rst 8
+ pop af
+ call (printhex)
+ cp #0xfa
+ ret z
+ cp #0xfe
+ ld a,e
+ jr z,send_with_ack
+ jr swa_reply
+
_start
; Test
ld a,#0x69
call (printhex)
+ ld a,#0xff ; Reset keyboard
+ call (send_with_ack)
+ call (read_byte) ; Post-reset status code
+ call (printhex)
+ ld a,#0xed ; Set LEDs
+ call (send_with_ack)
+ ld a,#0x05 ; Caps+Scroll
+ call (send_with_ack)
+ ld a,#0xf0 ; Set scan code set
+ call (send_with_ack)
+ ld a,#0x03 ; Scan code set 3
+ call (send_with_ack)
+ ld a,#0xfa ; Set all keys Make/Break/Typematic
+ call (send_with_ack)
+
read_and_print
call (read_byte)
call (printhex)