aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rw-r--r--bigfloat.s (renamed from bignum.s)0
-rw-r--r--bignum.h49
-rw-r--r--newtitle.s15
-rw-r--r--taipan.c31
5 files changed, 63 insertions, 43 deletions
diff --git a/Makefile b/Makefile
index 4375957..c3a46b4 100644
--- a/Makefile
+++ b/Makefile
@@ -93,9 +93,14 @@ TAIMAIN_ASM_SRC=rand.s draw_lorcha.s timed_getch.s jsleep.s portstat.s clrtobot.
# 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
+BIGNUM_SRC=bigfloat.s
+BIGNUM_HDRS=bignum.h bigfloat.h
+BIGNUM_CFLAGS=-DBIGNUM=BIGFLOAT
+
+# Uncomment these for experimental int48 big numbers
+#BIGNUM_SRC=bigint48.c
+#BIGNUM_HDRS=bignum.h bigint48.h
+#BIGNUM_CFLAGS=-DBIGNUM=BIGINT48
# Default rule for plain 'make' command is to build the binary.
all: $(XEX)
diff --git a/bignum.s b/bigfloat.s
index 9cfae63..9cfae63 100644
--- a/bignum.s
+++ b/bigfloat.s
diff --git a/bignum.h b/bignum.h
index 501d47c..4bf754c 100644
--- a/bignum.h
+++ b/bignum.h
@@ -21,34 +21,21 @@
which looks a little weird I admit.
*/
-#define bignum(x) char x[6]
-#define bignump char *
-
-/****** constants ******/
-/* zero */
-#define BIG_0 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-
-/* TODO: calculate bank interest differently: this bignum
- implementation is floating point, but I might swap it out
- for an int-based one! */
-/* 1.005 (bank interest) */
-#define BIG_1_005 { 0x40, 0x01, 0x00, 0x50, 0x00, 0x00 }
-
-/* bignum 100, used for score calculations in final_stats() */
-#define BIG_100 { 0x41, 0x01, 0x00, 0x00, 0x00, 0x00 }
-
-/* one thousand, one million, one hundred million */
-#define BIG_1K { 0x41, 0x10, 0x00, 0x00, 0x00, 0x00 }
-#define BIG_1M { 0x43, 0x01, 0x00, 0x00, 0x00, 0x00 }
-#define BIG_100M { 0x44, 0x01, 0x00, 0x00, 0x00, 0x00 }
-
-/* 10 million, one billion, one trillion */
-#define BIG_10M { 0x43, 0x10, 0x00, 0x00, 0x00, 0x00 }
-#define BIG_1B { 0x44, 0x10, 0x00, 0x00, 0x00, 0x00 }
-#define BIG_1T { 0x46, 0x01, 0x00, 0x00, 0x00, 0x00 }
-
-/* max value for a ulong */
-#define BIG_MAX_ULONG { 0x44, 0x42, 0x94, 0x96, 0x72, 0x95 }
+/* list all our implementations here */
+#define BIGFLOAT 1
+#define BIGINT48 2
+
+#ifndef BIGNUM
+#error bignum.h requires BIGNUM to be defined
+#endif
+
+#if BIGNUM == BIGFLOAT
+#include "bigfloat.h"
+#elif BIGNUM == BIGINT48
+#include "bigint48.h"
+#else
+#error BIGNUM must be defined to one of: BIGFLOAT BIGINT48
+#endif
/****** functions ******/
@@ -92,7 +79,7 @@ extern char __cdecl__ big_sub(bignump dest, bignump minuend, bignump subtrahend)
extern char __cdecl__ big_mul(bignump dest, bignump multiplicand, bignump multiplier);
extern char __cdecl__ big_div(bignump dest, bignump dividend, bignump divisor);
-/* dest = src * -1 */
+/* negation: dest = src * -1, or dest = -src if you prefer. */
extern void __fastcall__ big_negate(bignump dest, bignump src);
/* returns true if the bank is maxed out. We do this by checking the exponent
@@ -105,7 +92,5 @@ extern void __fastcall__ big_negate(bignump dest, bignump src);
*/
extern char __fastcall__ bank_maxed_out(bignump b);
-// signed char big_cmp(const bignum *a, const bignum *b)
-
-extern unsigned long cformat_big(char *magnitude, bignump b);
+/* print a bignum, Taipan-style. Code for this lives in taipan.c actually. */
extern void cprintfancy_big(bignump b);
diff --git a/newtitle.s b/newtitle.s
index 15b73ad..8997d82 100644
--- a/newtitle.s
+++ b/newtitle.s
@@ -9,6 +9,13 @@
; change this here, change it in sounds.h also!
sound_disabled = $06ff
+ ; since we're changing the font and colors, we'll save the old
+ ; ones here. If you change these, change them in taipan.c
+ ; also.
+fontsave = $06fc
+color1save = $06fd
+color2save = $06fe
+
; where our screen was loaded (see newtitle.pl)
;screendata = $2400
@@ -127,6 +134,14 @@ sounddisp = help + 78
; executable code here
start:
+ ; save old color registers and font addr.
+ lda CHBAS
+ sta fontsave
+ lda COLOR1
+ sta color1save
+ lda COLOR2
+ sta color2save
+
; setup color registers
lda colorchoices
sta COLOR2 ; text bg
diff --git a/taipan.c b/taipan.c
index 97d2271..fc3bb7b 100644
--- a/taipan.c
+++ b/taipan.c
@@ -1860,10 +1860,21 @@ void final_stats(void)
return;
}
- /* restore ROM character set. TODO: save old PEEK(756)
- in newtitle.s, restore that here instead of using
- hardcoded value. */
- POKE(756, 224);
+
+ /* exit(0) works by itself in DOS 2.0S or 2.5, or any DUP.SYS
+ style DOS that reopens the E: device when entering the menu.
+ However, command-line DOSes (XL and Sparta) don't do this,
+ which results in garbage on screen and wrong colors. So: */
+
+ /* restore CHBAS to its original value, generally the ROM font.
+ This is called fontsave in newtitle.s. */
+ POKE(756, PEEK(0x6fc));
+
+ /* restore COLOR1 and COLOR2. These locations are called
+ color1save and color2save in newtitle.s. */
+ POKE(709, PEEK(0x6fd));
+ POKE(710, PEEK(0x6fe));
+
exit(0);
}
@@ -2919,10 +2930,14 @@ void visit_bank(void)
continue;
}
- big_sub(bank, bank, bigamt);
- big_add(bigcash, bigcash, bigamt);
- big_to_ulong(bigcash, &cash);
- break;
+ if(big_cmp(bank, bigamt) < 0) {
+ you_only_have(1);
+ } else {
+ big_sub(bank, bank, bigamt);
+ big_add(bigcash, bigcash, bigamt);
+ big_to_ulong(bigcash, &cash);
+ break;
+ }
#else
if (amount == -1)
{