summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2003-09-06 06:03:59 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2003-09-06 06:03:59 (GMT)
commit4de7b57c6b0d835300e8f973bdbcd7d1e40fe41e (patch)
tree75b5939a7826306e1aba9498354b4d9e1664cb7f
parenta70ddf6a903829699ebd4071b93f94dc46f0493e (diff)
downloadkeyboard-4de7b57c6b0d835300e8f973bdbcd7d1e40fe41e.zip
keyboard-4de7b57c6b0d835300e8f973bdbcd7d1e40fe41e.tar.gz
keyboard-4de7b57c6b0d835300e8f973bdbcd7d1e40fe41e.tar.bz2
keyboard-4de7b57c6b0d835300e8f973bdbcd7d1e40fe41e.tar.xz
*** empty log message ***
-rw-r--r--data/keyboard.asm205
1 files changed, 133 insertions, 72 deletions
diff --git a/data/keyboard.asm b/data/keyboard.asm
index 29f49d1..b315494 100644
--- a/data/keyboard.asm
+++ b/data/keyboard.asm
@@ -3,107 +3,168 @@
; This is a test...
;
-_start
+rst0
; Enter here after reset
- ld sp,#2048 ; Initialize stack pointer
+ di
+ ld sp,#2048
+ jp (_start)
+ nop
- ; Test the serial port
- ; Send one character followed by a long pause
- ld a,#0x58
- call (sendchar)
+rst8
+ ; Print a character in A on serial port
+ push af
+sc_notready
+ in a,(#1)
+ cp #0x80 ; Bit 7 = serial port ready
+ jr c,sc_notready
+ pop af
+ out (#1),a
+ ret
+
+ nop
+ nop
+ nop
+ nop
+ nop
- ld hl,#0
-zzz
- dec hl
- ld a,h
- or l
- jr nz,zzz
- ; Send a string
- ld hl,hello_msg
-send_msg
- ld a,(hl)
- inc hl
+rst24
+ ; Print a string -> DE on serial port
+ ; (DE is used because it is the register pair least
+ ; likely to be actively in use)
+ push af
+r24_loop
+ ld a,(de)
and a
- jr z,sm_done
- call (sendchar)
- jr send_msg
-sm_done
+ jr z,r24_done
+ rst 8
+ inc de
+ jr r24_loop
+r24_done
+ pop af
+ ret
- ; Now, other stuff...
-
- xor a ; A <- 0
- ld b,a
- ld h,a
- ld l,a
-scan
- out (#3),a
- push af
- ld a,b
- out (#2),a
-delay
+ ;
+ ; Delay a specific number of microseconds in A; this
+ ; assumes a 50 MHz clock.
+ ;
+us_delay
+ 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)
+ ret
+
+ ; Probe the status of the keyboard port; require N/2
+ ; samples to consider it debounced; should have the
+ ; mask to probe in E. Destroys A. C=1 on return if
+ ; the bit was set.
+debounce
+ push bc
+ ld bc,#0x1008 ; Need 8/16 samples
+ ld d,#128
+db_loop
+ in a,(#0)
+ and e
+ jr z,db_zero
+ dec c
+db_zero
+ djnz db_loop
+ ld a,c
+ pop bc
+ add a,#0x80
+ ret
+
+ ;
+ ; Read a byte from the keyboard -> A
+ ;
+read_byte
+ push bc
push de
- pop de
- dec hl
- ld a,h
- or l
- jr nz,delay
+ push hl
+
+ ld hl,#0 ; Accumulated word
+ ld b,#11 ; Bits to read (including start+parity+stop)
+
+ ld a,#0x1F ; Control port; no drivers
+ out (#0),a
+rb_waitclk ; Wait for CLK# = 0
+ ld e,#0x02
+ call (debounce)
+ jr c,rb_waitclk
- ; Rotate A left inserting the inverse byte
- pop af
- cp #0x80 ; Set C iff A < 0x7F
- rla
+ ld a,#2
+ call (us_delay)
- jr nz,scan
+ ld e,#0x01
+ call (debounce)
+ rr h
+ rr l
- ; Loop counter (increment when A <- 0)
- inc b
+rb_waitnoclk ; Wait for CLK# = 1
+ ld e,#0x02
+ call (debounce)
+ jr nc,rb_waitnoclk
- ; Output the loop counter on the serial port
+ ; More bits to get...
+ djnz rb_waitclk
+
+ ; Now the proper value is in bits <13:6> in HL
+ sla l
+ rl h
+ rl l ; Parity bit <- bit 0 of L
+ rl h
+
+ ld a,h
+ pop hl
+ pop de
+ pop bc
+ ret
+
+ ;
+ ; Display a hexadecimal number on the serial port
+ ;
+printhex
push af
push hl
push de
+ push af
ld de,hextbl
ld h,#0
- ld l,b
- srl l
- srl l
- srl l
- srl l
+ srl a
+ srl a
+ srl a
+ srl a
+ ld l,a
add hl,de
ld a,(hl)
- call (sendchar)
+ rst 8
ld h,#0
- ld a,b
+ pop af
and #0x0F
ld l,a
add hl,de
ld a,(hl)
- call (sendchar)
+ rst 8
ld a,#32
- call (sendchar)
+ rst 8
pop de
pop hl
pop af
-
- jr scan
-
-;
-; Send a byte to the debug serial port
-;
-sendchar
- push af
-sc_notready
- in a,(#1)
- cp #0x80 ; Bit 7 = serial port ready
- jr c,sc_notready
- pop af
- out (#1),a
ret
-hello_msg
- byte "Hello, World!", 13, 10, 0
-
hextbl
byte "0123456789ABCDEF"
+
+_start
+ ; Test
+ ld a,#0x69
+ call (printhex)
+
+read_and_print
+ call (read_byte)
+ call (printhex)
+ jr read_and_print