Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [ui_input.asm] - Blame information for rev 384

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 68 winston
;The MIT License
2
;
3
;Copyright (c) 2008 Dylan Smith
4
;
5
;Permission is hereby granted, free of charge, to any person obtaining a copy
6
;of this software and associated documentation files (the "Software"), to deal
7
;in the Software without restriction, including without limitation the rights
8
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
;copies of the Software, and to permit persons to whom the Software is
10
;furnished to do so, subject to the following conditions:
11
;
12
;The above copyright notice and this permission notice shall be included in
13
;all copies or substantial portions of the Software.
14
;
15
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
;THE SOFTWARE.
22
 
23
; User Interface input routines - handling the keyboard.
24
; The keyboard routines use the main ZX ROM to decode key strokes.
25
; They are designed to hopefully work without needing the ZX ROM itself to
26
; have initialized (and so can work when the Spectranet has run its RESET
27
; routine, but before the ZX ROM has done the same).
28
; The routines are designed to work regardless of the maskable interrupt
29
; state.
30 384 winston
.include        "sysdefs.inc"
31
.include        "sysvars.inc"
32
.include        "page1.xinc"
33 68 winston
 
34
;===========================================================================
35
; Definitions - special keys returned by K_DECODE (and therefore F_getkey)
36 384 winston
KEY_TRUEVID:    equ 0x04
37
KEY_INVVID:     equ 0x05
38
KEY_CAPSLOCK:   equ 0x06
39
KEY_EDIT:       equ 0x07
40
KEY_LEFT:       equ 0x08
41
KEY_RIGHT:      equ 0x09
42
KEY_DOWN:       equ 0x0A
43
KEY_UP:         equ 0x0B
44
KEY_BACKSPACE:  equ 0x0C
45
KEY_ENTER:      equ 0x0D
46
KEY_EXTEND:     equ 0x0E
47
KEY_GRAPH:      equ 0x0F
48 68 winston
 
49
;===========================================================================
50
; F_getkey:
51
; Waits for a key to be pressed, and returns the key in A.
52
; The routine returns the key on keydown. The calling routine should then
53
; wait for keyup before getting the next key.
54 384 winston
.globl F_getkey
55
F_getkey:
56 179 winston
        ld a, DATAROM           ; key scan routines live here
57
        call F_pushpageA
58 384 winston
.loop1:
59
        call F_key_scan
60
        call F_key_test
61
        jr nc, .loop1
62 68 winston
        ld e, a                 ; partially decoded key is in A, copy it to E
63
        ld d, 8                 ; not in 'K' cursor mode
64
        ld c, 0                 ; FLAGS = 0
65 384 winston
        call F_key_code         ; decode keypress into actual ascii value
66 179 winston
        ld c, a
67
        call F_poppageA         ; restore original page A
68
        ld a, c
69 68 winston
        ret
70
 
71
;===========================================================================
72
; F_keyup:
73
; Waits for the keyboard not being pressed anywhere that will generate
74
; a character.
75 384 winston
.globl F_keyup
76
F_keyup:
77 179 winston
        ld a, DATAROM           ; key scan routines live here
78
        call F_pushpageA
79 384 winston
.loop2:
80
        call F_key_scan
81
        call F_key_test
82
        jr c, .loop2            ; carry set = key being pressed
83 179 winston
        call F_poppageA
84 68 winston
        ret
85
 
86 70 winston
;===========================================================================
87
; F_inputstring:
88
; Get a string from the keyboard, and null terminate.
89
; Parameters: DE = pointer to memory to store the string.
90
;              C = size of buffer (string length + 1, for the null terminator)
91 384 winston
.globl F_inputstring
92
F_inputstring:
93 70 winston
        ld b, c                 ; save length in b
94
        ld (v_stringptr), de    ; save the pointer
95
        ld (v_stringlen), bc    ; save the string lengths
96 384 winston
.inputloop3:
97 70 winston
        ld a, '_'               ; cursor - possible TODO - flashing cursor?
98
        call F_putc_5by8        ; display it
99 384 winston
.keyloop3:
100 70 winston
        call F_keyup            ; wait for keyup before doing anything
101
        call F_getkey           ; wait for a key to be pressed.
102 282 winston
        push hl
103
        ld hl, 0x1000           ; wait some more time so that
104 384 winston
.loop3:                         ; multi key contacts on Spectrum + / 128
105 282 winston
        dec hl                  ; membranes all make. Use a delay loop
106
        ld a, h                 ; rather than halt so this routine works
107
        or l                    ; with interrupts disabled.
108 384 winston
        jr nz, .loop3
109 282 winston
        pop hl
110
 
111 279 winston
        call F_getkey           ; closed.
112 70 winston
        cp KEY_ENTER            ; enter pressed?
113 384 winston
        jr z, .enter3           ; handle enter
114 70 winston
        cp KEY_BACKSPACE        ; backspace pressed?
115 384 winston
        jr z, .backspace3       ; handle it
116 70 winston
        cp ' '                  ; space - lowest printable character
117 384 winston
        jp m, .keyloop3         ; do nothing for non-printable char
118 70 winston
        ex af, af'
119
        ld a, (v_stringlen)     ; get remaining buffer size back
120
        cp 1                    ; and if only one byte is left,
121 384 winston
        jr z, .keyloop3         ; don't accept more input.
122 70 winston
        call F_backspace        ; backspace over the cursor
123
        ex af, af'              ; get keypress back
124
        ld hl, (v_stringptr)    ; get current string pointer
125
        ld (hl), a              ; save entered key
126
        inc hl                  ; update pointer
127
        ld (v_stringptr), hl    ; save pointer
128
        call F_putc_5by8        ; and print the char
129
        ld a, (v_stringlen)     ; get the remaining byte count
130
        dec a                   ; decrement it
131
        ld (v_stringlen), a     ; save remaining length
132 384 winston
        jr .inputloop3          ; and wait for the next key.
133
.backspace3:
134 70 winston
        ld bc, (v_stringlen)    ; is the cursor at the start
135
        ld a, c                 ; of the string?
136
        cp b
137 384 winston
        jr z, .keyloop3         ; yes - so just wait for another key.
138 70 winston
 
139
        ; To update the screen, the cursor and the character behind
140
        ; it must be removed, hence two calls to F_backspace.
141
        inc a                   ; increase the remaining byte count
142
        ld (v_stringlen), a     ; and save it
143
        ld hl, (v_stringptr)    ; get the string pointer
144
        dec hl                  ; rewind the string pointer
145
        ld (v_stringptr), hl    ; save it
146
        call F_backspace        ; remove cursor
147
        call F_backspace        ; remove last character
148 384 winston
        jr .inputloop3
149
.enter3:
150 282 winston
        call F_keyup            ; wait until keyup
151 70 winston
        call F_backspace        ; erase the cursor
152
        ld hl, (v_stringptr)    ; get the string pointer
153
        ld (hl), 0              ; put the null terminator on the string
154
        ret
155