From 47f494288d0ab525ddc93efefaf08dfb084dd10c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 19 Apr 2021 15:26:48 -0400 Subject: Allow pressing Enter to abort buy/sell (costs 15 bytes) --- taipan.c | 13 ++++++------ timed_getch.s | 68 +++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/taipan.c b/taipan.c index 933fd2f..36993bc 100644 --- a/taipan.c +++ b/taipan.c @@ -251,10 +251,9 @@ void backspace() { } */ -/* get an inventory item, return its index into items[]. - if allow_all is true, allows '*', which is used for - 'throw cargo' in sea_battle. */ -extern unsigned char get_item(unsigned char allow_all); + +extern unsigned char get_item_port(void); +extern unsigned char get_item_battle(void); /* rewritten in asm, in timed_getch.s, here's the original: @@ -1319,7 +1318,7 @@ char sea_battle(char id, int num_ships) { print_msg(M_what_shall_i_throw); cprint_taipan_prompt(); - choice = get_item(1); + choice = get_item_battle(); if(choice < 4) { gotox0y(6); @@ -3082,7 +3081,7 @@ char what_do_you_wish_me_to(char *buy_or_sell) { print_msg(M_me_to); cputs(buy_or_sell); cprint_taipan_prompt(); - return get_item(0); + return get_item_port(); } #ifdef CART_TARGET # pragma code-name (pop) @@ -3093,6 +3092,7 @@ void buy(void) { unsigned long afford, amount; choice = what_do_you_wish_me_to("buy"); + if(choice == 5) return; for (;;) { gotoxy(31, 21); @@ -3152,6 +3152,7 @@ void sell(void) { unsigned long amount; choice = what_do_you_wish_me_to("sell"); + if(choice == 5) return; for (;;) { gotox0y22(); diff --git a/timed_getch.s b/timed_getch.s index 5c5ff7c..6ea1bff 100644 --- a/timed_getch.s +++ b/timed_getch.s @@ -1,6 +1,6 @@ .export _timed_getch, _set_jiffy_timer, _agetc, _numgetc - .export _yngetc, _lcgetc, _jsleep, _get_item, _tjsleep + .export _yngetc, _lcgetc, _jsleep, _get_item_port, _get_item_battle, _tjsleep .import _cgetc, _cblank, putchar, _rand, _turbo .include "atari.inc" @@ -175,28 +175,54 @@ _yngetc: beq _yngetc ; no default, get another keypress rts ; else return the default -; extern unsigned char get_item(unsigned char allow_all); -_get_item: - sta FR0 ; stash arg +; extern unsigned char get_item_port(void) +; return 0-3 for opium, silk, arms, general. +; return 5 for Enter key (nothing chosen) +_get_item_port: + lda #4 + .byte $2c + +; extern unsigned char get_item_battle(void) +; return 0-4 for opium, silk, arms, general, all. +_get_item_battle: + lda #5 + sta FR0 +@get_loop: + jsr get_item + cmp FR0 + beq @get_loop + rts + + +get_item: @getkey: jsr _lcgetc ; switch(lcgetc()) { - ldx #0 - cmp #'o' - beq @gi_done ; case 'o': return 0; - inx - cmp #'s' - beq @gi_done ; case 's': return 1; - inx - cmp #'a' - beq @gi_done ; case 'a': return 2; - inx - cmp #'g' - beq @gi_done ; case 'g': return 3; - ldy FR0 - beq @getkey ; if allow_all is false, get another key - inx - cmp #'*' ; case '*': return 4; - bne @getkey ; if none of the above, get another key + sta FR0+1 + +;;; ldx #0 +;;; cmp #'o' +;;; beq @gi_done ; case 'o': return 0; +;;; inx +;;; cmp #'s' +;;; beq @gi_done ; case 's': return 1; +;;; inx +;;; cmp #'a' +;;; beq @gi_done ; case 'a': return 2; +;;; inx +;;; cmp #'g' +;;; beq @gi_done ; case 'g': return 3; + + ldx #5 +@giloop: + lda items_tbl,x + cmp FR0+1 + beq @gi_done + dex + bpl @giloop + bmi @getkey @gi_done: txa rts + +.rodata + items_tbl: .byte "osag*",$9b -- cgit v1.2.3