Skip to content

Commit 9d7dc99

Browse files
committed
Restrict input length for ZX Spectrum
* Update the input routine to cap input at a sane size, to avoid scrolling on input. * Reworded "invalid command" message to fit on the spectrum screen.
1 parent 02b73e0 commit 9d7dc99

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

bios.z80

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
; platform-specific code we need.
2121
;
2222

23+
IF SPECTRUM
24+
MAX_INPUT_LENGTH: EQU 30
25+
ELSE
26+
MAX_INPUT_LENGTH: EQU 78
27+
ENDIF
2328

2429
;
2530
; Initialization routine for the BIOS, if needed
@@ -236,15 +241,15 @@ IF SPECTRUM
236241

237242
xor a
238243
ld (hl),a ; size is now zero
239-
inc hl ; point to the character
244+
inc hl ; point to the start of the character buffer
240245

241246
read_input_again:
242247
; read a char
243248
call bios_await_keypress
244249

245250
; return? Then we're done
246251
cp 13
247-
jr z, read_input_over
252+
jp z, read_input_over
248253

249254
; delete? remove the last character
250255
cp 12
@@ -254,6 +259,25 @@ read_input_again:
254259
cp 7
255260
jr z, reset_line
256261

262+
; too many characters?
263+
push de
264+
push af
265+
ld a,(de) ; get the count of characters we've entered
266+
cp MAX_INPUT_LENGTH ; ignore input if too long
267+
jr nc,too_many_characters
268+
jr z, too_many_characters
269+
pop af
270+
pop de
271+
jr continue_input
272+
273+
too_many_characters:
274+
; too many characters, cleanup stack and ignore the character
275+
pop af
276+
pop de
277+
jr read_input_again
278+
279+
continue_input:
280+
257281
; display the new character
258282
push de
259283
ld e,a
@@ -344,7 +368,7 @@ loopy:
344368
pop bc
345369
pop de
346370
pop hl
347-
jr read_input_again
371+
jp read_input_again
348372

349373
reset_line:
350374
; clear the screen, and restart the input process

game.z80

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,8 +2729,8 @@ NEWLINE:
27292729
TAB:
27302730
db " $"
27312731
invalid_msg:
2732-
db 0x0a, 0x0d, "I did not understand your command.", 0x0a, 0x0d
2733-
db "For a list of several of our recognized words type 'HELP'.", 0x0a, 0x0d, "$"
2732+
db 0x0a, 0x0d, "I did not understand your input.", 0x0a, 0x0d, 0x0a, 0x0d
2733+
db "Enter 'HELP' to see some of our commands.", 0x0a, 0x0d, "$"
27342734
BAD_LANGUAGE_MSG:
27352735
db 0x0a, 0x0d, "What language!", 0x0a, 0x0d, "$"
27362736
NO_PHONE_HERE:
@@ -3607,8 +3607,8 @@ ITEM_COUNT: EQU ( item_last - items ) / ITEM_ENTRY_LENGTH
36073607
; http://www.gaby.de/cpm/manuals/archive/cpm22htm/ch5.htm#Function_10
36083608
;
36093609
INPUT_BUFFER:
3610-
db 100 ; size of our input-buffer
3611-
db 0x00 ; Count of characters returned.
3610+
db MAX_INPUT_LENGTH ; size of our input-buffer
3611+
db 0x00 ; Count of characters returned.
36123612

36133613

36143614

0 commit comments

Comments
 (0)