From be70f8451de62bf17978146096fa8aa3ea9d79be Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 29 Sep 2021 23:51:04 -0400 Subject: [PATCH] peasant: hook up actual parser not sure how optimized this will be, but it's a start --- games/peasant/parse_input.s | 166 ++++++++++++++++++++++++++--------- games/peasant/peasant3.s | 9 +- games/peasant/tokens.inc | 167 ++++++++++++++++++++++++++++++++++++ games/peasant/zp.inc | 4 + 4 files changed, 297 insertions(+), 49 deletions(-) create mode 100644 games/peasant/tokens.inc diff --git a/games/peasant/parse_input.s b/games/peasant/parse_input.s index c36643f0..1ae34266 100644 --- a/games/peasant/parse_input.s +++ b/games/peasant/parse_input.s @@ -1,14 +1,36 @@ +.include "tokens.inc" + + ;========================== ; parse input + ;========================== + ; input is in input_buffer parse_input: -; jsr hgr_save - lda input_buffer ; get first char FIXME - and #$DF ; make uppercase 0110 0001 -> 0100 0001 + ; uppercase buffer -parse_copy: - cmp #'C' - bne parse_inventory + ldx #0 +upcase_loop: + lda input_buffer,X + beq done_upcase_loop + and #$DF + sta input_buffer,X + inx + jmp upcase_loop +done_upcase_loop: + + jsr get_verb + +; jsr get_noun + +; jsr local_parser + + lda CURRENT_VERB + +check_copy: + + cmp #VERB_COPY + bne check_inventory ; want copy lda #NEW_FROM_DISK @@ -19,29 +41,25 @@ parse_copy: jmp done_parse_message - -parse_inventory: - cmp #'I' - bne parse_l +check_inventory: + cmp #VERB_INVENTORY + bne check_load jsr show_inventory jmp restore_parse_message -parse_l: - cmp #'L' - bne parse_talk +check_load: + cmp #VERB_LOAD + bne check_look - lda input_buffer+2 - and #$DF ; make uppercase 0110 0001 -> 0100 0001 - cmp #'O' - beq parse_look -parse_load: jsr load_menu jmp restore_parse_message -parse_look: +check_look: + cmp #VERB_LOOK + bne check_talk lda #fake_error2 + lda #fake_error2 jmp finish_parse_message -parse_s: - cmp #'S' - bne parse_version +check_save: + cmp #VERB_SAVE + bne check_show - lda input_buffer+2 - and #$DF ; make uppercase 0110 0001 -> 0100 0001 - cmp #'A' - beq parse_save -parse_show: + jsr save_menu + + jmp restore_parse_message + + +check_show: + cmp #VERB_SHOW + bne check_version bit LORES bit PAGE1 @@ -78,21 +99,16 @@ parse_show: jmp done_parse_message -parse_save: - jsr save_menu - - jmp restore_parse_message - -parse_version: - cmp #'V' - bne parse_help +check_version: + cmp #VERB_VERSION + bne check_help lda #version_message jmp finish_parse_message -parse_help: +check_help: lda #help_message @@ -112,3 +128,69 @@ done_parse_message: rts + + + + ;=========================== + ; get verb + ;=========================== + ; +get_verb: + lda #VERB_UNKNOWN ; default + sta CURRENT_VERB + + lda #verb_lookup + sta get_verb_loop+2 + +next_verb_loop: + ldx #0 + stx WORD_MATCH +get_verb_loop: + lda verb_lookup + bmi done_verb + beq done_get_verb_loop + cmp input_buffer,X + beq verb_char_matched +verb_char_nomatch: + dec WORD_MATCH +verb_char_matched: + jsr inc_verb_ptr + inx + jmp get_verb_loop + +done_verb: + ldx WORD_MATCH + beq found_verb + +no_found_verb: + jsr inc_verb_ptr + jmp next_verb_loop + +found_verb: + and #$7f + sta CURRENT_VERB + +done_get_verb_loop: + + rts + +inc_verb_ptr: + inc get_verb_loop+1 + bne inc_verb_ptr_noflo + inc get_verb_loop+2 +inc_verb_ptr_noflo: + + rts + +verb_lookup: +.byte "COPY",VERB_COPY|$80 +.byte "INV",VERB_INVENTORY|$80 +.byte "LOAD",VERB_LOAD|$80 +.byte "LOOK",VERB_LOOK|$80 +.byte "TALK",VERB_TALK|$80 +.byte "SAVE",VERB_SAVE|$80 +.byte "SHOW",VERB_SHOW|$80 +.byte "VER",VERB_VERSION|$80 +.byte $00 diff --git a/games/peasant/peasant3.s b/games/peasant/peasant3.s index 3d609ac7..7af57cbe 100644 --- a/games/peasant/peasant3.s +++ b/games/peasant/peasant3.s @@ -19,17 +19,12 @@ WHICH_PEASANTRY = 2 peasant_quest: lda #0 sta GAME_OVER - + sta FRAME jsr hgr_make_tables jsr hgr2 - - - lda #0 - sta FRAME - ; update map location jsr update_map_location @@ -204,7 +199,7 @@ fake_error2: .include "graphics/graphics_peasant3.inc" -.include "sprites/boat_sprites.inc" +;.include "sprites/boat_sprites.inc" map_backgrounds_low: .byte