From 7f4716a7064cd1ff49d0cab901c84dff20a0a96c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 6 May 2021 03:33:52 -0400 Subject: Save 3 bytes code, plus shrink xex by 36 bytes by moving some vars to the BSS --- taipan.c | 124 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 65 insertions(+), 59 deletions(-) (limited to 'taipan.c') diff --git a/taipan.c b/taipan.c index aa2a479..367c7be 100644 --- a/taipan.c +++ b/taipan.c @@ -319,7 +319,7 @@ extern char *ultostr(unsigned long value, char* s); you assassinated, game over. Value is: int((2**31 - 1) / 1.1) */ #define DEBT_MAX 1952257860L -char wu_assassin = 0; +char wu_assassin; /* taipan functions (modified as little as possible) */ #define GENERIC 1 @@ -424,9 +424,9 @@ bignum(big_max_ulong) = BIG_MAX_ULONG; unsigned long bank = 0; #endif -unsigned long cash = 0, - debt = 0, - booty = 0; +unsigned long cash, + debt, + booty; // ec = 20, // ed = 1; // used to be a float, 0.5 @@ -462,27 +462,27 @@ unsigned long hold_[4]; even then, they can do multiple transactions on the same turn. Need a signed version of would_overflow() to do this right. */ -long hold = 0; +long hold; /* these being negative would be a Bad Thing */ -unsigned char month = 1; -unsigned int guns = 0, - year = 1860, - ec = 20, - ed = 1; +unsigned char month; +unsigned int guns, + year, + ec, + ed; /* ec+=20, ed++ every game-year (12 turns). player would have to play until 15 Jan 5168 to overflow ec. */ -unsigned char port = 1, - bp = 0, - li = 0, - wu_warn = 0, - wu_bailout = 0; +unsigned char port, + bp, + li, + wu_warn, + wu_bailout; // these need to be longs to avoid int overflow when // displaying ship status. -long damage = 0, capacity = 60, newdamage; +long damage, capacity, newdamage; /* a bunch of text strings that occur multiple times in the prompts. Each of these actually does save a few bytes, but @@ -622,11 +622,6 @@ void cprint_firm_colon(void) { char get_ship_status(void) { return 100 - ((damage * 100L) / capacity); } -/* -#ifdef CART_TARGET -# pragma code-name (pop) -#endif -*/ #ifdef BIGNUM bignum(big1T) = BIG_1T; @@ -634,7 +629,46 @@ bignum(big1B) = BIG_1B; bignum(big1M) = BIG_1M; bignum(big1K) = BIG_1K; bignum(big0) = BIG_0; +#endif + +void init_game(void) { +#ifdef BIGNUM + big_copy(bank, big0); +#else + bank = 0; +#endif + hkw_[0] = 0; + hkw_[1] = 0; + hkw_[3] = 0; + hkw_[4] = 0; + hold_[0] = 0; + hold_[1] = 0; + hold_[2] = 0; + hold_[3] = 0; + hold = 0; + damage = 0; + wu_warn = 0; + wu_bailout = 0; + wu_assassin = 0; + month = 1; + port = 1; + ed = 1; + capacity = 60; + year = 1860; + ec = 20; + + name_firm(); + cash_or_guns(); + set_prices(); +} + +/* +#ifdef CART_TARGET +# pragma code-name (pop) +#endif +*/ +#ifdef BIGNUM /* what we should have: For Million/Billion, 3 significant digits. range printed as @@ -1637,12 +1671,12 @@ void cash_or_guns(void) { cash = 1000000000L; // cash = 4294000000L; // cash = 3500000L; -#ifdef BIGNUM +# ifdef BIGNUM big_copy(bank, big1M); big_mul(bank, bank, big1M); -#else +# else bank = 1000000000L; -#endif +# endif debt = 0; capacity = 1000; hold = 800; @@ -1651,14 +1685,14 @@ void cash_or_guns(void) { bp = 7; ed = 9; ec = 90; -#else +#else /* !TIMEWARP */ cash = 0; debt = 0; hold = 10; guns = 5; li = 1; bp = 7; -#endif +#endif /* TIMEWARP */ #ifdef ALMOST_DEAD damage = capacity - 1; #endif @@ -2116,35 +2150,10 @@ void final_stats(void) print_msg(M_play_again); choice = yngetc(0); - if(choice == 'y') { -#ifdef BIGNUM - big_copy(bank, big0); -#else - bank = 0; -#endif - hkw_[0] = 0; - hkw_[1] = 0; - hkw_[3] = 0; - hkw_[4] = 0; - hold_[0] = 0; - hold_[1] = 0; - hold_[2] = 0; - hold_[3] = 0; - hold = 0; - damage = 0; - month = 1; - port = 1; - ed = 1; - capacity = 60; - year = 1860; - ec = 20; - - name_firm(); - cash_or_guns(); - set_prices(); - - return; - } + if(choice == 'y') { + init_game(); + return; + } /* player said No, don't play again... for the xex build, exit(0) gets us back to DOS. @@ -3428,10 +3437,7 @@ int main(void) { bignum_test(); #endif - name_firm(); - // initrand(); - cash_or_guns(); - set_prices(); + init_game(); for (;;) { port_stats(); -- cgit v1.2.3