Compare commits
4 Commits
dca6ce4e8e
...
bb2e528b65
Author | SHA1 | Date | |
---|---|---|---|
|
bb2e528b65 | ||
|
c896b77143 | ||
|
8d5c26f299 | ||
|
ca8b315e9d |
@ -5,10 +5,26 @@
|
|||||||
; *** Constants ***
|
; *** Constants ***
|
||||||
.equ KBD_PORT 0x01
|
.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 ***
|
; *** Code ***
|
||||||
|
|
||||||
; Wait for a digit to be pressed and sets the A register to the value (0-9) of
|
kbdInit:
|
||||||
; that digit.
|
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
|
; 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
|
; 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.
|
; if the result isn't 0xff, at least one key is pressed.
|
||||||
kbdGetC:
|
kbdGetC:
|
||||||
push bc
|
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:
|
.loop:
|
||||||
; When we check for digits, we go through all 3 groups containing them.
|
ld hl, .dtbl
|
||||||
; for each group, we load the digit we check for in B and then test the
|
; we go through the 7 rows of the table
|
||||||
; bit for that key. If the bit is reset, our key is pressed. we can
|
ld b, 7
|
||||||
; jump to the end, copy B into A and return.
|
; is alpha mod enabled?
|
||||||
|
bit 0, c
|
||||||
; check group 2
|
jr z, .inner ; unset? skip next
|
||||||
ld a, 0xfb
|
ld hl, .atbl ; set? we're in alpha mode
|
||||||
|
.inner:
|
||||||
|
ld a, (hl) ; group mask
|
||||||
call .get
|
call .get
|
||||||
|
cp 0xff
|
||||||
ld b, '3'
|
jr nz, .something
|
||||||
bit 1, a
|
; nothing for that group, let's scan the next group
|
||||||
jr z, .end
|
ld a, 9
|
||||||
|
call addHL ; go to next row
|
||||||
ld b, '6'
|
djnz .inner
|
||||||
bit 2, a
|
; found nothing, loop
|
||||||
jr z, .end
|
jr .loop
|
||||||
|
.something:
|
||||||
ld b, '9'
|
; We have something on that row! Let's find out which char. Register A
|
||||||
bit 3, a
|
; currently contains a mask with the pressed char bit unset.
|
||||||
jr z, .end
|
ld b, 8
|
||||||
|
inc hl
|
||||||
ld a, 0xf7
|
.findchar:
|
||||||
call .get
|
rrca ; is next bit unset?
|
||||||
|
jr nc, .gotit ; yes? we have our char!
|
||||||
ld b, '2'
|
inc hl
|
||||||
bit 1, a
|
djnz .findchar
|
||||||
jr z, .end
|
.gotit:
|
||||||
|
ld a, (hl)
|
||||||
ld b, '5'
|
or a ; is char 0?
|
||||||
bit 2, a
|
jr z, .loop ; yes? unsupported. loop.
|
||||||
jr z, .end
|
call .debounce
|
||||||
|
cp KBD_KEY_ALPHA
|
||||||
ld b, '8'
|
jr c, .end ; A < 0x80? valid char, return it.
|
||||||
bit 3, a
|
jr z, .handleAlpha
|
||||||
jr z, .end
|
cp KBD_KEY_2ND
|
||||||
|
jr z, .handle2nd
|
||||||
; check group 4
|
jp .loop
|
||||||
ld a, 0xef
|
.handleAlpha:
|
||||||
call .get
|
set 0, c
|
||||||
|
bit 1, c ; 2nd set?
|
||||||
ld b, '0'
|
jp z, .loop ; unset? loop
|
||||||
bit 0, a
|
; we've just hit Alpha with 2nd set. Toggle A-Lock and set Alpha to
|
||||||
jr z, .end
|
; the value A-Lock has.
|
||||||
|
ld a, (KBD_MODS)
|
||||||
ld b, '1'
|
xor 1
|
||||||
bit 1, a
|
ld (KBD_MODS), a
|
||||||
jr z, .end
|
ld c, a
|
||||||
|
jp .loop
|
||||||
ld b, '4'
|
.handle2nd:
|
||||||
bit 2, a
|
set 1, c
|
||||||
jr z, .end
|
jp .loop
|
||||||
|
|
||||||
ld b, '7'
|
|
||||||
bit 3, a
|
|
||||||
jr z, .end
|
|
||||||
|
|
||||||
jr .loop ; nothing happened? loop
|
|
||||||
|
|
||||||
.end:
|
.end:
|
||||||
; loop until all keys are de-pressed
|
pop hl
|
||||||
.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 bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
.get:
|
.get:
|
||||||
@ -106,3 +118,35 @@ kbdGetC:
|
|||||||
in a, (KBD_PORT)
|
in a, (KBD_PORT)
|
||||||
ei
|
ei
|
||||||
ret
|
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
|
||||||
|
@ -35,35 +35,32 @@ lcdInit:
|
|||||||
xor a
|
xor a
|
||||||
ld (LCD_CURROW), a
|
ld (LCD_CURROW), a
|
||||||
|
|
||||||
|
; Clear screen
|
||||||
|
call lcdClrScr
|
||||||
|
|
||||||
; Enable the LCD
|
; Enable the LCD
|
||||||
ld a, LCD_CMD_ENABLE
|
ld a, LCD_CMD_ENABLE
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
; Hack to get LCD to work. According to WikiTI, we're to sure why TIOS
|
; 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
|
; sends these, but it sends it, and it is required to make the LCD
|
||||||
; work. So...
|
; work. So...
|
||||||
ld a, 0x17
|
ld a, 0x17
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
ld a, 0x0b
|
ld a, 0x0b
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
; Set some usable contrast
|
; Set some usable contrast
|
||||||
ld a, LCD_CMD_CONTRAST+0x34
|
ld a, LCD_CMD_CONTRAST+0x34
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
; Enable 6-bit mode.
|
; Enable 6-bit mode.
|
||||||
ld a, LCD_CMD_6BIT
|
ld a, LCD_CMD_6BIT
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
; Enable X-increment mode
|
; Enable X-increment mode
|
||||||
ld a, LCD_CMD_XINC
|
ld a, LCD_CMD_XINC
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -78,11 +75,23 @@ lcdWait:
|
|||||||
pop af
|
pop af
|
||||||
ret
|
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
|
; Turn LCD off
|
||||||
lcdOff:
|
lcdOff:
|
||||||
|
push af
|
||||||
ld a, LCD_CMD_DISABLE
|
ld a, LCD_CMD_DISABLE
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
out (LCD_PORT_CMD), a
|
||||||
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Set LCD's current column to A
|
; Set LCD's current column to A
|
||||||
@ -90,8 +99,7 @@ lcdSetCol:
|
|||||||
push af
|
push af
|
||||||
; The col index specified in A is compounded with LCD_CMD_COL
|
; The col index specified in A is compounded with LCD_CMD_COL
|
||||||
add a, LCD_CMD_COL
|
add a, LCD_CMD_COL
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -100,8 +108,7 @@ lcdSetRow:
|
|||||||
push af
|
push af
|
||||||
; The col index specified in A is compounded with LCD_CMD_COL
|
; The col index specified in A is compounded with LCD_CMD_COL
|
||||||
add a, LCD_CMD_ROW
|
add a, LCD_CMD_ROW
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -120,26 +127,22 @@ lcdSendGlyph:
|
|||||||
.loop:
|
.loop:
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
inc hl
|
inc hl
|
||||||
call lcdWait
|
call lcdData
|
||||||
out (LCD_PORT_DATA), a
|
|
||||||
djnz .loop
|
djnz .loop
|
||||||
|
|
||||||
; Now that we've sent our 7 rows of pixels, let's go in "Y-increment"
|
; 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
|
; mode to let the LCD increase by one column after we've sent our 8th
|
||||||
; line, which is blank (padding).
|
; line, which is blank (padding).
|
||||||
ld a, LCD_CMD_YINC
|
ld a, LCD_CMD_YINC
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
; send blank line
|
; send blank line
|
||||||
xor a
|
xor a
|
||||||
call lcdWait
|
call lcdData
|
||||||
out (LCD_PORT_DATA), a
|
|
||||||
|
|
||||||
; go back in X-increment mode
|
; go back in X-increment mode
|
||||||
ld a, LCD_CMD_XINC
|
ld a, LCD_CMD_XINC
|
||||||
call lcdWait
|
call lcdCmd
|
||||||
out (LCD_PORT_CMD), a
|
|
||||||
|
|
||||||
pop hl
|
pop hl
|
||||||
pop bc
|
pop bc
|
||||||
@ -157,6 +160,49 @@ lcdLinefeed:
|
|||||||
pop af
|
pop af
|
||||||
ret
|
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:
|
lcdPutC:
|
||||||
cp ASCII_LF
|
cp ASCII_LF
|
||||||
jp z, lcdLinefeed
|
jp z, lcdLinefeed
|
||||||
|
@ -28,8 +28,9 @@
|
|||||||
.inc "fnt/mgm.asm"
|
.inc "fnt/mgm.asm"
|
||||||
.equ LCD_RAMSTART RAMSTART
|
.equ LCD_RAMSTART RAMSTART
|
||||||
.inc "ti/lcd.asm"
|
.inc "ti/lcd.asm"
|
||||||
|
.equ KBD_RAMSTART LCD_RAMEND
|
||||||
.inc "ti/kbd.asm"
|
.inc "ti/kbd.asm"
|
||||||
.equ STDIO_RAMSTART LCD_RAMEND
|
.equ STDIO_RAMSTART KBD_RAMEND
|
||||||
.equ STDIO_GETC kbdGetC
|
.equ STDIO_GETC kbdGetC
|
||||||
.equ STDIO_PUTC lcdPutC
|
.equ STDIO_PUTC lcdPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
@ -60,6 +61,7 @@ boot:
|
|||||||
halt
|
halt
|
||||||
|
|
||||||
main:
|
main:
|
||||||
|
call kbdInit
|
||||||
call lcdInit
|
call lcdInit
|
||||||
xor a
|
xor a
|
||||||
call lcdSetCol
|
call lcdSetCol
|
||||||
|
Loading…
Reference in New Issue
Block a user