diff options
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | rand.s | 4 | ||||
-rw-r--r-- | taipan.c | 158 |
3 files changed, 101 insertions, 71 deletions
@@ -89,6 +89,12 @@ TAIMAIN_HDRS=sounds.h TAIMAIN_C_SRC=taipan.c sounds.c TAIMAIN_ASM_SRC=rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s clrtobot.s ultostr.s +# Comment these lines out to build without big number support. +# This will stop being possible at some point. +BIGNUM_SRC=bignum.s +BIGNUM_HDRS=bignum.h +BIGNUM_CFLAGS=-DBIGNUM + # Default rule for plain 'make' command is to build the binary. all: $(XEX) @@ -153,8 +159,8 @@ help.dat: help.txt text2screen.pl # The main executable. All the C and asm code goes here, except the init # segment in newtitle.s. -taimain.xex: $(TAIMAIN_C_SRC) $(TAIMAIN_ASM_SRC) $(TAIMAIN_HDRS) - cl65 -m taipan.map $(CFLAGS) -o taimain.xex $(TAIMAIN_C_SRC) $(TAIMAIN_ASM_SRC) +taimain.xex: $(TAIMAIN_C_SRC) $(TAIMAIN_ASM_SRC) $(TAIMAIN_HDRS) $(BIGNUM_SRC) $(BIGNUM_HDRS) + cl65 -m taipan.map $(CFLAGS) $(BIGNUM_CFLAGS) -o taimain.xex $(TAIMAIN_C_SRC) $(TAIMAIN_ASM_SRC) $(BIGNUM_SRC) #cl65 --mapfile taipan.map $(CFLAGS) -o taimain.xex taipan.c sounds.c rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s clrtobot.s @@ -17,8 +17,8 @@ randb: ; asm-callable (doesn't trash X reg) sta tmp3 nop ; let the LFSR cook for a bit... nop - lda RTCLOK ; different amount of cooking depending on whether - and #$01 ; we're on an even or odd numbered TV frame + lda RTCLOK+2 ; different amount of cooking depending on whether + and #$01 ; we're on an even or odd numbered TV frame bne @1 nop nop @@ -22,7 +22,7 @@ /* define this for testing sea_battle(). it causes a pirate attack every time you leave port. */ -// #define COMBAT_TEST +#define COMBAT_TEST /* define this to show internals of damage calculation */ // #define DAMAGE_TEST @@ -136,69 +136,6 @@ void atari_text_setup() { /**** End of atari-specific stuff. Supposed to be, anyway. */ -#ifdef BIGNUM -bignum(big1M) = BIG_1M; -bignum(big100M) = BIG_100M; -bignum(big1B) = BIG_1B; - -/* -Requires a bit of explanation. b's value will always be zero or -positive, and can range up to 1.0e+14 (aka 100 trillion). - -magnitude values: -0 - result is used as-is (result range 0 - 999999) - b range 0 - 999999 -1 - result is in 100000's, print result/10 Million (range 0-9999) - b range 1,000,000 - 999,999,999 (999 Million) -2 - result is in 100 millions, print result/10 Billion (range 0-9999) - b range 1,000,000,000 (1 Billion) - 999,999,999,999 (1 trillion - 1) - -The calling code decides whether or not to print a decimal point -and 10ths digit (using integer math only). -*/ - -unsigned long cformat_big(char *magnitude, bignump b) { - bignum(tmp); - unsigned long ret; - if(big_cmp(b, big1M) < 0) { - *magnitude = 0; - big_to_ulong(b, &ret); - } else if(big_cmp(b, big1B) < 0) { - *magnitude = 1; - big_to_ulong(b, &ret); - ret /= 100000L; - } else { - *magnitude = 2; - big_div(tmp, b, big100M); - big_to_ulong(tmp, &ret); - } - return ret; -} - -void cprintfancy_big(bignump b) { - char m; - unsigned long l = cformat_big(&m, b); - if(!m) { - // cprintf("%lu", l); - cprintulong(l); - } else { - if(l > 100) { - // cprintf("%lu ", l / 10L); - cprintulong(l / 10L); - } else { - // cprintf("%lu.%lu ", l / 10L, l % 10L); - cprintulong(l / 10L); - cputc('.'); - cprintulong(l % 10L); - } - cputc(' '); - cputc(m == 1 ? 'M' : 'B'); - cputs("illion"); - } - cputs("\r\n"); -} -#endif - /* old version of this used to just 'return randl()%clamp'. If clamp were 0, the return value would be the unclamped result from randl() (x % 0 == x, in cc65). If it were 1, @@ -298,6 +235,7 @@ void retire(void); void final_stats(void); void you_only_have(unsigned char in_bank); +void cprintulong(unsigned long ul); void cprintfancy_ctr(unsigned long num, unsigned char center); #define cprintfancy(num) cprintfancy_ctr(num, 0) @@ -366,6 +304,70 @@ unsigned char port = 1, // displaying ship status. long damage = 0, capacity = 60, newdamage; +#ifdef BIGNUM +bignum(big1M) = BIG_1M; +bignum(big100M) = BIG_100M; +bignum(big1B) = BIG_1B; + +/* +Requires a bit of explanation. b's value will always be zero or +positive, and can range up to 1.0e+14 (aka 100 trillion). + +magnitude values: +0 - result is used as-is (result range 0 - 999999) + b range 0 - 999999 +1 - result is in 100000's, print result/10 Million (range 0-9999) + b range 1,000,000 - 999,999,999 (999 Million) +2 - result is in 100 millions, print result/10 Billion (range 0-9999) + b range 1,000,000,000 (1 Billion) - 999,999,999,999 (1 trillion - 1) + +The calling code decides whether or not to print a decimal point +and 10ths digit (using integer math only). +*/ + +unsigned long cformat_big(char *magnitude, bignump b) { + bignum(tmp); + unsigned long ret; + if(big_cmp(b, big1M) < 0) { + *magnitude = 0; + big_to_ulong(b, &ret); + } else if(big_cmp(b, big1B) < 0) { + *magnitude = 1; + big_to_ulong(b, &ret); + ret /= 100000L; + } else { + *magnitude = 2; + big_div(tmp, b, big100M); + big_to_ulong(tmp, &ret); + } + return ret; +} + +void cprintfancy_big(bignump b) { + char m; + unsigned long l = cformat_big(&m, b); + if(!m) { + // cprintf("%lu", l); + cprintulong(l); + } else { + if(l > 100) { + // cprintf("%lu ", l / 10L); + cprintulong(l / 10L); + } else { + // cprintf("%lu.%lu ", l / 10L, l % 10L); + cprintulong(l / 10L); + cputc('.'); + cprintulong(l % 10L); + } + cputc(' '); + cputc(m == 1 ? 'M' : 'B'); + cputs("illion"); + } + cputs("\r\n"); +} +#endif + + /* print an int or long as a string, conio-style */ void cprintulong(unsigned long ul) { cputs(ultoa(ul, fancy_buf, 10)); @@ -1567,6 +1569,8 @@ void retire(void) void final_stats(void) { +#ifdef BIGNUM +#else /* TODO: write cprintlong() to print signed value */ long finalcash; @@ -1714,7 +1718,7 @@ void final_stats(void) return; } - +#endif /* restore ROM character set. TODO: save old PEEK(756) in newtitle.s, restore that here instead of using hardcoded value. */ @@ -2232,7 +2236,7 @@ void elder_brother_wu(void) } else if (choice == 'y') { if (((int)cash == 0) && #ifdef BIGNUM - (bigcmp(bank, B_0) == 0) + (big_cmp(bank, B_0) == 0) #else ((int)bank == 0) #endif @@ -2430,7 +2434,7 @@ void good_prices(void) int port_choices(void) { int choice = 0; - char retire_ok; + char retire_ok = 0; compradores_report(); cputs("Taipan, present prices per unit here are"); /* NB: exactly 40 cols */ @@ -2450,6 +2454,20 @@ int port_choices(void) { cursor(0); #ifdef BIGNUM + // TODO: make this smaller! + if(port == 1) { + if(cash > 1000000L) { + retire_ok = 1; + } else if(big_cmp(bank, BIG_1M) >= 0) { + retire_ok = 1; + } else { + bignum(tmp); + ulong_to_big(cash, tmp); + big_add(tmp, tmp, bank); + if(big_cmp(tmp, BIG_1M) >= 0) + retire_ok = 1; + } + } #else retire_ok = (port == 1 && ((cash + bank) >= 1000000L)); #endif @@ -2711,9 +2729,12 @@ void visit_bank(void) } if (amount <= cash) { +#ifdef BIGNUM +#else cash -= amount; bank += amount; break; +#endif } else { you_only_have(0); } @@ -2726,6 +2747,8 @@ void visit_bank(void) cputs("How much will you withdraw? "); amount = get_num(); +#ifdef BIGNUM +#else if (amount == -1) { amount = bank; @@ -2735,6 +2758,7 @@ void visit_bank(void) cash += amount; bank -= amount; break; +#endif } else { you_only_have(1); } |