Skip to content

Commit 3ec171b

Browse files
committed
"SWITCH ON XXX" and "TURN ON YYY" work.
This updates #22.
1 parent 918a887 commit 3ec171b

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

game.z80

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,17 +550,69 @@ uppercase_ok:
550550
ret
551551

552552

553+
553554
;
554-
; Helper function. Remove " THE " from any input
555+
; Helper function, filter our input buffer, by removing some words
555556
;
556557
filter_input_buffer:
558+
call filter_input_buffer_on
559+
call filter_input_buffer_the
560+
ret
561+
562+
563+
;
564+
; Helper function. Remove " ON " from any input
565+
;
566+
filter_input_buffer_on:
567+
ld hl, INPUT_BUFFER+1
568+
ld a, (hl)
569+
ld b, a ; b contains the number of chacters
570+
inc hl ; hl points to the text the user entered
571+
572+
compare_loop_on:
573+
push bc ; preserve count
574+
push hl ; preserve starting char
575+
576+
ld b, 4 ; strlen(" ON " )
577+
ld de, ON
578+
579+
call CompareStringsWithLength
580+
jp z, we_found_on
581+
582+
pop hl
583+
pop bc
584+
585+
inc hl
586+
djnz compare_loop_on
587+
588+
; Didn't find " THE " at any character position in the input-buffer.
589+
ret
590+
591+
we_found_on:
592+
pop hl
593+
pop de
594+
595+
; we have " THE " at the location HL points to
596+
ld a, " "
597+
ld (hl), a ; " " -> " "
598+
inc hl
599+
ld (hl), a ; "O" -> " "
600+
inc hl
601+
ld (hl), a ; "N" -> " "
602+
ret
603+
604+
605+
;
606+
; Helper function. Remove " THE " from any input.
607+
;
608+
filter_input_buffer_the:
557609

558610
ld hl, INPUT_BUFFER+1
559611
ld a, (hl)
560612
ld b, a ; b contains the number of chacters
561613
inc hl ; hl points to the text the user entered
562614

563-
compare_loop:
615+
compare_loop_the:
564616
push bc ; preserve count
565617
push hl ; preserve starting char
566618

@@ -574,7 +626,7 @@ compare_loop:
574626
pop bc
575627

576628
inc hl
577-
djnz compare_loop
629+
djnz compare_loop_the
578630

579631
; Didn't find " THE " at any character position in the input-buffer.
580632
ret
@@ -2685,6 +2737,8 @@ NOW_YOU_SEE:
26852737
db "Now you can see where you are:", 0x0a, 0x0d, "$"
26862738
THE:
26872739
db " THE "
2740+
ON:
2741+
db " ON "
26882742
usage_message:
26892743
db 0x0a, 0x0d
26902744

@@ -2937,6 +2991,10 @@ command_table:
29372991
DEFW use_function
29382992
DEFB 5, 'LIGHT', 1
29392993
DEFW use_function
2994+
DEFB 6, 'SWITCH', 1 ; switch on generator, etc
2995+
DEFW use_function
2996+
DEFB 4, 'TURN', 1 ; turn on torch, etc.
2997+
DEFW use_function
29402998
;; easter-eges
29412999
DEFB 4, 'CALL', 1
29423000
DEFW call_function

0 commit comments

Comments
 (0)