peasant: update input to match actual game better

This commit is contained in:
Vince Weaver
2024-09-21 23:10:34 -04:00
parent 3b5369fa63
commit 439475f6af
8 changed files with 162 additions and 41 deletions

View File

@@ -232,6 +232,7 @@ qload.inc: generate_common QLOAD
./generate_common -a 0xb00 -s hgr_partial_restore qload.lst >> qload.inc ./generate_common -a 0xb00 -s hgr_partial_restore qload.lst >> qload.inc
./generate_common -a 0xb00 -s clear_bottom qload.lst >> qload.inc ./generate_common -a 0xb00 -s clear_bottom qload.lst >> qload.inc
./generate_common -a 0xb00 -s hgr_input qload.lst >> qload.inc ./generate_common -a 0xb00 -s hgr_input qload.lst >> qload.inc
./generate_common -a 0xb00 -s done_hgr_input qload.lst >> qload.inc
./generate_common -a 0xb00 -s draw_box qload.lst >> qload.inc ./generate_common -a 0xb00 -s draw_box qload.lst >> qload.inc
./generate_common -a 0xb00 -s disp_put_string qload.lst >> qload.inc ./generate_common -a 0xb00 -s disp_put_string qload.lst >> qload.inc
./generate_common -a 0xb00 -s disp_one_line qload.lst >> qload.inc ./generate_common -a 0xb00 -s disp_one_line qload.lst >> qload.inc

View File

@@ -5,66 +5,86 @@
; TODO: arbitrary Y location ; TODO: arbitrary Y location
; TODO: when backspacing, erase old char not XOR ; TODO: when backspacing, erase old char not XOR
; INPUT_X points to next char
; we print to chars to right
hgr_input: hgr_input:
bit KEYRESET ldx INPUT_ACTIVE
bne input_currently_happening
inc INPUT_ACTIVE ; make input active
; current keypress in A
pha
; activate typing area
jsr clear_bottom
ldx #0 ldx #0
ldy #184 ldy #184
lda #'>' lda #'>'
jsr hgr_put_char jsr hgr_put_char
ldx #1 ldx #0 ; reset INPUT_X
stx INPUT_X stx INPUT_X
hgr_input_loop: pla
lda KEYPRESS input_currently_happening:
bpl hgr_input_loop
bit KEYRESET ; check for backspace
; actually DELETE (on Apple IIe) or ^B (II+)
; we can't use backspace/^H as maps to left arrow
; and the game assumes that means you want to walk left
; this does mean it's hard to backspace on some emulators,
; but that's an eternal challenge with Apple II emulators
and #$7f ; trim off top? cmp #$7f ; check if DELETE (backspace)
cmp #13 ; if return, then done
beq done_hgr_input
cmp #$7f ; check if backspace
beq hgr_input_backspace beq hgr_input_backspace
cmp #8 cmp #2 ; ^B, option for Apple II+
beq hgr_input_backspace beq hgr_input_backspace
ldx INPUT_X ldx INPUT_X
sta input_buffer-1,X ; store to buffer sta input_buffer,X ; store to buffer
ldy #184 ; print char ldy #184 ; print char
ldx INPUT_X ldx INPUT_X
inx ; print two to the right
inx ; because of prompt
jsr hgr_put_char jsr hgr_put_char
ldx INPUT_X ldx INPUT_X
cpx #38 cpx #37
bcs input_too_big ; FIXME this is a hack bcs input_too_big ; FIXME this is a hack
inc INPUT_X inc INPUT_X
input_too_big: input_too_big:
jmp hgr_input_loop
rts
hgr_input_backspace: hgr_input_backspace:
ldx INPUT_X ldx INPUT_X
cpx #1 ; don't backspace too far beq done_backspace ; don't backspace too far
beq hgr_input_loop
dec INPUT_X dec INPUT_X
ldx INPUT_X ldx INPUT_X
lda input_buffer-1,X ; load old char lda input_buffer,X ; load old char
inx
inx
ldy #184 ldy #184
jsr hgr_put_char ; xor it on top jsr hgr_put_char ; xor it on top
jmp hgr_input_loop
done_backspace:
rts
done_hgr_input: done_hgr_input:
ldx INPUT_X ; NUL terminate ldx INPUT_X ; NUL terminate
lda #0 lda #0
sta input_buffer-1,X sta INPUT_ACTIVE
sta input_buffer,X
rts rts

View File

@@ -16,6 +16,7 @@ peasant_quest_intro:
sta ESC_PRESSED sta ESC_PRESSED
sta LEVEL_OVER sta LEVEL_OVER
sta PEASANT_STEPS sta PEASANT_STEPS
sta INPUT_ACTIVE
sta GAME_STATE_2 sta GAME_STATE_2
jsr hgr_make_tables jsr hgr_make_tables

View File

@@ -7,12 +7,15 @@
; Movement ; Movement
; Note in the game, pressing a key starts walking ; Note in the game, pressing a key starts walking
; To stop you have to press the same direction again ; To stop you have to press the same direction again
; This is convenient as this is how actual Apple II works
; Text ; Text
; We require ENTER/RETURN pressed before entering text ; We originally tries having WASD but it's a bit of a pain
; this is mildly annoying, but lets us use ; so instead on Apple II+ use :,/ for up/down
; WASD to walk. The Apple II+ doesn't have ; and have text input like original game
; up or down buttons
; Can walk while typing text, but
; Once enter is pressed, stop walking
check_keyboard: check_keyboard:
@@ -21,17 +24,19 @@ check_keyboard:
rts rts
key_was_pressed: key_was_pressed:
inc SEEDL bit KEYRESET
and #$5f ; strip off high bit and make uppercase inc SEEDL ; does this help?
and #$7f ; strip off high bit
; don't convert to uppercase, we can handle lowercase
;========================== ;==========================
; Left ; Left
;========================== ;==========================
check_left: check_left:
cmp #$8 cmp #$8
beq left_pressed
cmp #'A'
bne check_right bne check_right
left_pressed: ; if peasant_moving_left, stop left_pressed: ; if peasant_moving_left, stop
; otherwise clear all movement, move left ; otherwise clear all movement, move left
@@ -54,8 +59,6 @@ continue_left:
check_right: check_right:
cmp #$15 cmp #$15
beq right_pressed
cmp #'D'
bne check_up bne check_up
right_pressed: right_pressed:
@@ -76,7 +79,7 @@ continue_right:
jmp done_check_keyboard jmp done_check_keyboard
check_up: check_up:
cmp #'W' cmp #';'
beq up_pressed beq up_pressed
cmp #$0B cmp #$0B
bne check_down bne check_down
@@ -102,7 +105,7 @@ continue_up:
jmp done_check_keyboard jmp done_check_keyboard
check_down: check_down:
cmp #'S' cmp #'/'
beq down_pressed beq down_pressed
cmp #$0A cmp #$0A
bne check_enter bne check_enter
@@ -128,19 +131,29 @@ continue_down:
check_enter: check_enter:
cmp #13 cmp #13
beq enter_pressed beq enter_pressed
cmp #' '
bne done_check_keyboard all_other_keys:
enter_pressed:
jsr clear_bottom
jsr hgr_input jsr hgr_input
; could tail-call here
jmp done_check_keyboard
enter_pressed:
jsr stop_peasant
jsr done_hgr_input
jsr parse_input jsr parse_input
jsr clear_bottom jsr clear_bottom
done_check_keyboard: lda #0 ; reset buffer
sta input_buffer
bit KEYRESET done_check_keyboard:
rts rts

View File

@@ -16,6 +16,7 @@ parse_input_file_begin:
; input is in input_buffer ; input is in input_buffer
parse_input: parse_input:
;=========================== ;===========================
; special case: pot on head ; special case: pot on head

View File

@@ -344,16 +344,24 @@ skip_level_specific:
;==================== ;====================
; check keyboard ; check keyboard
lda #13
sta WAIT_LOOP
wait_loop:
jsr check_keyboard jsr check_keyboard
lda #50 ; approx 7ms
jsr wait
dec WAIT_LOOP
bne wait_loop
;===================== ;=====================
; delay ; delay
lda #200 ; lda #200 ; approx 100ms
jsr wait ; jsr wait
jmp game_loop jmp game_loop

View File

@@ -0,0 +1,75 @@
;====================
; hgr input
;====================
; TODO: save to string
; TODO: arbitrary Y location
; TODO: when backspacing, erase old char not XOR
hgr_input:
bit KEYRESET
ldx #0
ldy #184
lda #'>'
jsr hgr_put_char
ldx #1
stx INPUT_X
hgr_input_loop:
lda KEYPRESS
bpl hgr_input_loop
bit KEYRESET
and #$7f ; trim off top?
cmp #13 ; if return, then done
beq done_hgr_input
cmp #$7f ; check if backspace
beq hgr_input_backspace
cmp #8
beq hgr_input_backspace
ldx INPUT_X
sta input_buffer-1,X ; store to buffer
ldy #184 ; print char
ldx INPUT_X
jsr hgr_put_char
ldx INPUT_X
cpx #38
bcs input_too_big ; FIXME this is a hack
inc INPUT_X
input_too_big:
jmp hgr_input_loop
hgr_input_backspace:
ldx INPUT_X
cpx #1 ; don't backspace too far
beq hgr_input_loop
dec INPUT_X
ldx INPUT_X
lda input_buffer-1,X ; load old char
ldy #184
jsr hgr_put_char ; xor it on top
jmp hgr_input_loop
done_hgr_input:
ldx INPUT_X ; NUL terminate
lda #0
sta input_buffer-1,X
rts
input_buffer:
.byte 0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0
.byte 0,0,0,0,0,0,0,0,0,0

View File

@@ -261,6 +261,8 @@ END_OF_SAVE = $AD
CURRENT_VERB = $B0 ; parser CURRENT_VERB = $B0 ; parser
CURRENT_NOUN = $B1 CURRENT_NOUN = $B1
WORD_MATCH = $B2 WORD_MATCH = $B2
INPUT_ACTIVE = $B3
WAIT_LOOP = $B4
INPUT_X = $C0 INPUT_X = $C0
BOX_X1L = $C1 BOX_X1L = $C1