Compare commits

..

4 Commits

Author SHA1 Message Date
Virgil Dupras
bb2e528b65 ti/lcd: clear screen on init
LCD RAM persists between reboots, makingit necessary to clear it.

ref #41
2019-11-08 21:54:03 -05:00
Virgil Dupras
c896b77143 ti/kbd: implement A-Lock
ref #41
2019-11-08 20:27:43 -05:00
Virgil Dupras
8d5c26f299 ti/kbd: add alpha support
no a-lock or lowercase yet.

ref #41
2019-11-08 15:45:45 -05:00
Virgil Dupras
ca8b315e9d ti/kbd: widen char detection
no alpha yet.

ref #41
2019-11-08 14:58:29 -05:00
3 changed files with 188 additions and 96 deletions

View File

@ -5,10 +5,26 @@
; *** Constants ***
.equ KBD_PORT 0x01
; Keys that have a special meaning in GetC. All >= 0x80. They are interpreted
; by GetC directly and are never returned as-is.
.equ KBD_KEY_ALPHA 0x80
.equ KBD_KEY_2ND 0x81
; *** Variables ***
; active long-term modifiers, such as a-lock
; bit 0: A-Lock
.equ KBD_MODS KBD_RAMSTART
.equ KBD_RAMEND @+1
; *** Code ***
; Wait for a digit to be pressed and sets the A register to the value (0-9) of
; that digit.
kbdInit:
xor a
ld (KBD_MODS), a
ret
; Wait for a digit to be pressed and sets the A register ASCII value
; corresponding to that key press.
;
; This routine waits for a key to be pressed, but before that, it waits for
; all keys to be de-pressed. It does that to ensure that two calls to
@ -22,78 +38,74 @@
; if the result isn't 0xff, at least one key is pressed.
kbdGetC:
push bc
push hl
; loop until a digit is pressed
; During this GetC loop, register C holds the modificators
; bit 0: Alpha
; bit 1: 2nd
; Initial value should be zero, but if A-Lock is on, it's 1
ld a, (KBD_MODS)
and 1
ld c, a
; loop until a digit is pressed
.loop:
; When we check for digits, we go through all 3 groups containing them.
; for each group, we load the digit we check for in B and then test the
; bit for that key. If the bit is reset, our key is pressed. we can
; jump to the end, copy B into A and return.
; check group 2
ld a, 0xfb
ld hl, .dtbl
; we go through the 7 rows of the table
ld b, 7
; is alpha mod enabled?
bit 0, c
jr z, .inner ; unset? skip next
ld hl, .atbl ; set? we're in alpha mode
.inner:
ld a, (hl) ; group mask
call .get
ld b, '3'
bit 1, a
jr z, .end
ld b, '6'
bit 2, a
jr z, .end
ld b, '9'
bit 3, a
jr z, .end
ld a, 0xf7
call .get
ld b, '2'
bit 1, a
jr z, .end
ld b, '5'
bit 2, a
jr z, .end
ld b, '8'
bit 3, a
jr z, .end
; check group 4
ld a, 0xef
call .get
ld b, '0'
bit 0, a
jr z, .end
ld b, '1'
bit 1, a
jr z, .end
ld b, '4'
bit 2, a
jr z, .end
ld b, '7'
bit 3, a
jr z, .end
jr .loop ; nothing happened? loop
cp 0xff
jr nz, .something
; nothing for that group, let's scan the next group
ld a, 9
call addHL ; go to next row
djnz .inner
; found nothing, loop
jr .loop
.something:
; We have something on that row! Let's find out which char. Register A
; currently contains a mask with the pressed char bit unset.
ld b, 8
inc hl
.findchar:
rrca ; is next bit unset?
jr nc, .gotit ; yes? we have our char!
inc hl
djnz .findchar
.gotit:
ld a, (hl)
or a ; is char 0?
jr z, .loop ; yes? unsupported. loop.
call .debounce
cp KBD_KEY_ALPHA
jr c, .end ; A < 0x80? valid char, return it.
jr z, .handleAlpha
cp KBD_KEY_2ND
jr z, .handle2nd
jp .loop
.handleAlpha:
set 0, c
bit 1, c ; 2nd set?
jp z, .loop ; unset? loop
; we've just hit Alpha with 2nd set. Toggle A-Lock and set Alpha to
; the value A-Lock has.
ld a, (KBD_MODS)
xor 1
ld (KBD_MODS), a
ld c, a
jp .loop
.handle2nd:
set 1, c
jp .loop
.end:
; loop until all keys are de-pressed
.loop2:
xor a
call .get
inc a ; if a was 0xff, will become 0 (nz test)
jr nz, .loop2 ; non-zero? something is pressed
; copy result into A
ld a, b
pop hl
pop bc
ret
.get:
@ -106,3 +118,35 @@ kbdGetC:
in a, (KBD_PORT)
ei
ret
.debounce:
; wait until all keys are de-pressed
push af ; --> lvl 1
.wait:
xor a
call .get
inc a ; if a was 0xff, will become 0 (nz test)
jr nz, .wait ; non-zero? something is pressed
pop af ; <-- lvl 1
ret
; digits table. each row represents a group. first item is group mask.
; 0 means unsupported. no group 7 because it has no keys.
.dtbl:
.db 0xfe, 0, 0, 0, 0, 0, 0, 0, 0
.db 0xfd, 0x0d, '+' ,'-' ,'*', '/', '^', 0, 0
.db 0xfb, 0, '3', '6', '9', ')', 0, 0, 0
.db 0xf7, '.', '2', '5', '8', '(', 0, 0, 0
.db 0xef, '0', '1', '4', '7', ',', 0, 0, 0
.db 0xdf, 0, 0, 0, 0, 0, 0, 0, KBD_KEY_ALPHA
.db 0xbf, 0, 0, 0, 0, 0, KBD_KEY_2ND, 0, 0x7f
; alpha table. same as .dtbl, for when we're in alpha mode.
.atbl:
.db 0xfe, 0, 0, 0, 0, 0, 0, 0, 0
.db 0xfd, 0x0d, '"' ,'W' ,'R', 'M', 'H', 0, 0
.db 0xfb, '?', 0, 'V', 'Q', 'L', 'G', 0, 0
.db 0xf7, ':', 'Z', 'U', 'P', 'K', 'F', 'C', 0
.db 0xef, '_', 'Y', 'T', 'O', 'J', 'E', 'B', 0
.db 0xdf, 0, 'X', 'S', 'N', 'I', 'D', 'A', KBD_KEY_ALPHA
.db 0xbf, 0, 0, 0, 0, 0, KBD_KEY_2ND, 0, 0x7f

View File

@ -35,35 +35,32 @@ lcdInit:
xor a
ld (LCD_CURROW), a
; Clear screen
call lcdClrScr
; Enable the LCD
ld a, LCD_CMD_ENABLE
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
; Hack to get LCD to work. According to WikiTI, we're to sure why TIOS
; sends these, but it sends it, and it is required to make the LCD
; work. So...
ld a, 0x17
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
ld a, 0x0b
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
; Set some usable contrast
ld a, LCD_CMD_CONTRAST+0x34
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
; Enable 6-bit mode.
ld a, LCD_CMD_6BIT
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
; Enable X-increment mode
ld a, LCD_CMD_XINC
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
ret
@ -78,11 +75,23 @@ lcdWait:
pop af
ret
; Send cmd A to LCD
lcdCmd:
out (LCD_PORT_CMD), a
jr lcdWait
; Send data A to LCD
lcdData:
out (LCD_PORT_DATA), a
jr lcdWait
; Turn LCD off
lcdOff:
push af
ld a, LCD_CMD_DISABLE
call lcdWait
call lcdCmd
out (LCD_PORT_CMD), a
pop af
ret
; Set LCD's current column to A
@ -90,8 +99,7 @@ lcdSetCol:
push af
; The col index specified in A is compounded with LCD_CMD_COL
add a, LCD_CMD_COL
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
pop af
ret
@ -100,8 +108,7 @@ lcdSetRow:
push af
; The col index specified in A is compounded with LCD_CMD_COL
add a, LCD_CMD_ROW
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
pop af
ret
@ -120,26 +127,22 @@ lcdSendGlyph:
.loop:
ld a, (hl)
inc hl
call lcdWait
out (LCD_PORT_DATA), a
call lcdData
djnz .loop
; Now that we've sent our 7 rows of pixels, let's go in "Y-increment"
; mode to let the LCD increase by one column after we've sent our 8th
; line, which is blank (padding).
ld a, LCD_CMD_YINC
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
; send blank line
xor a
call lcdWait
out (LCD_PORT_DATA), a
call lcdData
; go back in X-increment mode
ld a, LCD_CMD_XINC
call lcdWait
out (LCD_PORT_CMD), a
call lcdCmd
pop hl
pop bc
@ -157,6 +160,49 @@ lcdLinefeed:
pop af
ret
; Clears B rows starting at row A
; The LCD will then be set back at row A, column 0
; B is not preserved by this routine
lcdClrX:
push af
call lcdSetRow
ld a, LCD_CMD_8BIT
call lcdCmd
.outer:
push bc ; --> lvl 1
ld b, 11
ld a, LCD_CMD_YINC
call lcdCmd
xor a
call lcdSetCol
.inner:
call lcdData
djnz .inner
ld a, LCD_CMD_XINC
call lcdCmd
xor a
call lcdData
pop bc ; <-- lvl 1
djnz .outer
ld a, LCD_CMD_6BIT
call lcdCmd
pop af
ret
lcdClrLn:
push bc
ld b, FNT_HEIGHT+1
call lcdClrX
pop bc
ret
lcdClrScr:
push bc
ld b, 64
call lcdClrX
pop bc
ret
lcdPutC:
cp ASCII_LF
jp z, lcdLinefeed

View File

@ -28,8 +28,9 @@
.inc "fnt/mgm.asm"
.equ LCD_RAMSTART RAMSTART
.inc "ti/lcd.asm"
.equ KBD_RAMSTART LCD_RAMEND
.inc "ti/kbd.asm"
.equ STDIO_RAMSTART LCD_RAMEND
.equ STDIO_RAMSTART KBD_RAMEND
.equ STDIO_GETC kbdGetC
.equ STDIO_PUTC lcdPutC
.inc "stdio.asm"
@ -60,6 +61,7 @@ boot:
halt
main:
call kbdInit
call lcdInit
xor a
call lcdSetCol