aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-14 17:32:21 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-14 17:32:21 -0500
commit5bc66d574cf71cbebe79b2bc27f5a076cbc0c912 (patch)
tree417fb78f056a8d6e8b3ae62ef1d101aa6212d7b1
parent9dbe0b40cfda998339fcc1e57b6aafe2cf5bc689 (diff)
downloadtaipan-5bc66d574cf71cbebe79b2bc27f5a076cbc0c912.tar.gz
initial attempt at floating bank (with bugs!)
-rw-r--r--bignum.h3
-rw-r--r--bignum.s2
-rw-r--r--taipan.c61
3 files changed, 56 insertions, 10 deletions
diff --git a/bignum.h b/bignum.h
index cb33c62..1519c87 100644
--- a/bignum.h
+++ b/bignum.h
@@ -38,6 +38,9 @@
#define BIG_100M { 0x44, 0x01, 0x00, 0x00, 0x00, 0x00 }
#define BIG_1B { 0x44, 0x10, 0x00, 0x00, 0x00, 0x00 }
+/* max value for a ulong */
+#define BIG_MAX_ULONG { 0x44, 0x42, 0x94, 0x96, 0x72, 0x95 }
+
// void int_to_big(int i, bignum *b);
// void uint_to_big(unsigned int i, bignum *b);
diff --git a/bignum.s b/bignum.s
index 06e99ab..27580d5 100644
--- a/bignum.s
+++ b/bignum.s
@@ -312,7 +312,7 @@ _big_cmp:
; subtract (and throw away the result, only care about sign)
jsr FSUB ; FR0 = FR0 - FR1
- ldx #0
lda FR0 ; exponent has sign bit, and happily is 0 if the result was 0!
+ tax ; sign extension, grr.
rts
diff --git a/taipan.c b/taipan.c
index 0ccba5d..d0a8cda 100644
--- a/taipan.c
+++ b/taipan.c
@@ -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
@@ -33,7 +33,7 @@
/* define this to start the game in the year 1869, with
1000 capacity, 20 guns, and 1 billion cash and bank. */
-// #define TIMEWARP
+#define TIMEWARP
/* define this to start the game in a 99% damaged ship */
// #define ALMOST_DEAD
@@ -262,6 +262,8 @@ char *st[] = { "Critical", " Poor", " Fair",
#ifdef BIGNUM
bignum(bank) = BIG_0;
+bignum(interest_rate) = BIG_1_005;
+bignum(big_max_ulong) = BIG_MAX_ULONG;
#else
unsigned long bank = 0;
#endif
@@ -1284,7 +1286,12 @@ void cash_or_guns(void)
year = 1869;
cash = 1000000000L;
// cash = 3500000L;
+#ifdef BIGNUM
+ memcpy(bank, big1M, 6); // FIXME: big_copy
+ big_mul(bank, bank, big1M);
+#else
bank = 1000000000L;
+#endif
debt = 0;
capacity = 1000;
hold = 800;
@@ -2062,7 +2069,7 @@ void quit(void)
if(debt >= DEBT_MAX) wu_assassin = 1;
#ifdef BIGNUM
- big_bank_interest();
+ big_mul(bank, bank, interest_rate);
#else
/* bank calculation original formula was:
bank = bank + (bank * .005);
@@ -2236,7 +2243,7 @@ void elder_brother_wu(void)
} else if (choice == 'y') {
if (((int)cash == 0) &&
#ifdef BIGNUM
- (big_cmp(bank, B_0) == 0)
+ (bank[0] == '\0')
#else
((int)bank == 0)
#endif
@@ -2458,13 +2465,13 @@ int port_choices(void) {
if(port == 1) {
if(cash > 1000000L) {
retire_ok = 1;
- } else if(big_cmp(bank, BIG_1M) >= 0) {
+ } else if(big_cmp(bank, big1M) >= 0) {
retire_ok = 1;
} else {
bignum(tmp);
ulong_to_big(cash, tmp);
big_add(tmp, tmp, bank);
- if(big_cmp(tmp, BIG_1M) >= 0)
+ if(big_cmp(tmp, big1M) >= 0)
retire_ok = 1;
}
}
@@ -2716,6 +2723,11 @@ void sell(void) {
void visit_bank(void)
{
long amount = 0;
+#ifdef BIGNUM
+ bignum(bigamt);
+ bignum(biglimit);
+ bignum(bigcash);
+#endif
for (;;)
{
@@ -2729,12 +2741,14 @@ void visit_bank(void)
}
if (amount <= cash)
{
+ cash -= amount;
#ifdef BIGNUM
+ ulong_to_big(amount, bigamt);
+ big_add(bank, bank, bigamt);
#else
- cash -= amount;
bank += amount;
- break;
#endif
+ break;
} else {
you_only_have(0);
}
@@ -2748,6 +2762,35 @@ void visit_bank(void)
amount = get_num();
#ifdef BIGNUM
+ if(amount == -1) {
+ memcpy(bigamt, bank, 6); // FIXME: big_copy
+ } else {
+ ulong_to_big(amount, bigamt);
+ }
+
+ ulong_to_big(cash, bigcash);
+ big_sub(biglimit, big_max_ulong, bigcash);
+ cputs("\rcash ");
+ cprintfancy_big(bigcash);
+ agetc();
+ cputs("\ramt ");
+ cprintfancy_big(bigamt);
+ agetc();
+ cputs("\rlimit ");
+ cprintfancy_big(biglimit);
+ agetc();
+ if(big_cmp(bigamt, biglimit) >= 0) {
+// hangx: goto hangx;
+ cputs("\r\nYou cannot carry so much cash, Taipan!");
+ bad_joss_sound();
+ timed_getch(TMOUT_1S);
+ continue;
+ }
+
+ big_sub(bank, bank, bigamt);
+ big_add(bigcash, bigcash, bigamt);
+ big_to_ulong(bigcash, &cash);
+ break;
#else
if (amount == -1)
{
@@ -2758,10 +2801,10 @@ void visit_bank(void)
cash += amount;
bank -= amount;
break;
-#endif
} else {
you_only_have(1);
}
+#endif
}
port_stats();