Skip to content

Commit 7957269

Browse files
add os_GetTokenInput
also fixes bugs in os_GetStringInput
1 parent 7e0231b commit 7957269

File tree

3 files changed

+361
-84
lines changed

3 files changed

+361
-84
lines changed

src/ce/getstringinput.src

Lines changed: 128 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
; ---
2-
; void os_GetStringInput(char *string, char *buf, size_t size)
3-
; ---
41
assume adl=1
52

63
kUp := 3
@@ -9,9 +6,11 @@ kDown := 4
96
kEnter := 5
107
kClear := 9
118
kRight := 1
9+
kQuit := $40
10+
kIns := $0B
1211
curLock := 4
1312
flags := $D00080
14-
curRow := $D00595
13+
curRow := $D00595 ; also includes curCol
1514
curUnder := $D00599
1615
_PutS := $207C0
1716
_PutC := $207B8
@@ -23,120 +22,174 @@ _PullDownChk := $208BC
2322
_ConvKeyToTok := $20E40
2423
_GetTokString := $20874
2524
_PutTokString := $20D74
25+
_ClrTxtShd := $20818
2626

2727
section .text
2828
public _os_GetStringInput
2929
_os_GetStringInput:
3030
push ix
3131
ld ix,0
3232
add ix,sp
33+
push ix
34+
ld iy,flags
35+
ld a,(iy + $0d)
36+
ld (.smc.text_flag_0),a
37+
ld a,(iy + $4c)
38+
ld (.smc.text_flag_1),a
39+
set 1,(iy + $0d) ; use text buffer
40+
res 5,(iy + $4c) ; use text buffer
41+
call _ClrTxtShd
42+
pop ix
3343
ld hl,(ix+6) ; hl -> input string prompt
3444
add hl,de
3545
xor a,a
3646
sbc hl,de
37-
jr z,__nodisp
3847
ld iy,flags
39-
call _PutS
40-
__nodisp:
48+
call nz,_PutS
4149
ld hl,(curRow)
42-
ld (__savecur),hl
43-
ld a,(ix+12)
44-
dec a
45-
ld (ix+12),a
46-
ld (ix+6),a
47-
__start:
48-
ld de,(ix+9)
49-
jr __loop
50-
__skiploop:
50+
ld (.smc.curRow),hl
51+
ld hl,(ix+12)
52+
add hl,de
53+
xor a,a
54+
sbc hl,de
55+
jr nz,.not_empty
5156
pop ix
52-
pop de
53-
__loop:
54-
ld a,' '
55-
ld (curUnder),a
56-
push de
57+
ret
58+
.not_empty:
59+
dec hl ; subtract 1 for null pointer
60+
ld (ix+12),hl
61+
ld (ix+6),hl ; save initial size
62+
.start:
63+
ld hl,(ix+6) ; restore initial size
64+
ld (ix+12),hl
65+
or a,a
66+
sbc hl,hl
67+
ld (.smc.str_len),hl
68+
.loop:
69+
ld iy,flags
5770
push ix
5871
call _CursorOn
59-
__getkey:
72+
.getkey:
6073
call _GetKey
6174
call _CursorOff
6275
call _PullDownChk
76+
push af
6377
call _CursorOn
64-
jr c,__getkey
78+
pop af
79+
jr c,.getkey
80+
pop ix
81+
cp a,kQuit
82+
jp z,.done
6583
cp a,kLeft
66-
jr z,__skiploop
84+
jr z,.loop
6785
cp a,kDown
68-
jr z,__skiploop
86+
jr z,.loop
6987
cp a,kRight
70-
jr z,__skiploop
88+
jr z,.loop
7189
cp a,kUp
72-
jr z,__skiploop
90+
jr z,.loop
7391
cp a,kClear
74-
jr z,__clearpop
92+
jp z,.clear
7593
cp a,kEnter
76-
jr z,__done
94+
jp z,.done
95+
cp a,kIns
96+
jr z,.loop
97+
ld de,(ix+9)
98+
ld hl,(.smc.str_len)
99+
add hl,de
100+
push hl ; save buf pointer
101+
push ix
102+
cp a,$F3 ; for lists? idk something is wrong with _PullDownChk
103+
jr z,.sub_key
104+
cp a,$F4
105+
jr z,.sub_key
106+
cp a,$F5
107+
jr z,.sub_key
108+
cp a,$F6
109+
jr z,.sub_key
110+
cp a,$F7
111+
jr z,.sub_key
112+
cp a,$F8
113+
jr z,.sub_key
114+
cp a,$F9
115+
jr z,.sub_key
116+
cp a,$FA
117+
jr z,.sub_key
118+
cp a,$FB
119+
jr z,.sub_key
120+
jr .conv_key
121+
.sub_key:
122+
sub a,$7C
123+
ld ($0D0058E),a
124+
ld a,$FE
125+
.conv_key:
77126
call _ConvKeyToTok
78127
call _GetTokString
79128
pop ix
80-
pop de
81-
ld b,(hl)
129+
pop de ; restore buf pointer
130+
ld b,(hl) ; token string length
82131
inc hl
83-
ld a,(ix+12)
84-
sub a,b
85-
jr nc,__notfull
86-
ld b,(ix+12)
132+
.draw_string:
133+
push hl
134+
ld hl,(ix+12)
135+
add hl,de
87136
xor a,a
88-
__notfull:
89-
ld (ix+12),a
90-
__draw:
137+
sbc hl,de ; check if done
138+
dec hl
139+
ld (ix+12),hl
140+
pop hl
141+
jr z,.full
142+
push hl
143+
ld hl,(.smc.str_len)
144+
inc hl
145+
ld (.smc.str_len),hl
146+
pop hl
91147
ld a,(hl)
92148
ld (de),a
93149
inc hl
94150
inc de
95151
call _PutC
96-
djnz __draw
97-
ld a,(ix+12)
98-
or a,a
99-
jr nz,__loop
100-
__full:
101-
ld a,' '
102-
ld (curUnder),a
103-
push de
152+
djnz .draw_string
153+
jp .loop
154+
.full:
155+
push ix
104156
call _GetKey
105-
pop de
106-
cp a,kClear
107-
jr z,__clear
108-
cp a,kEnter
109-
jr z,__exit
110-
jr __full
111-
__clearpop:
112157
pop ix
113-
pop de
114-
__clear:
115-
__savecur := $+1
158+
cp a,kEnter
159+
jr z,.done
160+
cp a,kClear
161+
jr nz,.full
162+
.clear:
163+
.smc.curRow := $+1
116164
ld hl,0
117165
ld (curRow),hl
118-
ld a,(ix+6)
119-
ld b,(ix+12)
120-
ld (ix+12),a
121-
sub a,b
122-
ld b,a
123-
inc b
124-
__clearloop:
166+
ld hl,(.smc.str_len)
167+
inc hl
168+
.clear_loop:
169+
push hl
125170
ld a,' '
126171
call _PutC
127-
djnz __clearloop
128-
ld hl,(__savecur)
172+
pop hl
173+
ld bc,1
174+
or a,a
175+
sbc hl,bc
176+
jr nz,.clear_loop
177+
ld hl,(.smc.curRow)
129178
ld (curRow),hl
130-
jp __start
131-
__done:
132-
pop ix
133-
pop de
134-
__exit:
135-
ld a,' '
136-
ld (curUnder),a
137-
xor a,a
138-
ld (de),a
179+
jp .start
180+
.done:
181+
call _ClrTxtShd
139182
call _CursorOff
140-
di
183+
.smc.text_flag_0 := $+1
184+
ld a,0
185+
ld (iy + $0d),a
186+
.smc.text_flag_1 := $+1
187+
ld a,0
188+
ld (iy + $4c),a
189+
ld de,(ix+9)
190+
.smc.str_len := $+1
191+
ld hl,0
192+
add hl,de
193+
ld (hl),0
141194
pop ix
142195
ret

0 commit comments

Comments
 (0)