aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-08 06:07:26 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-08 06:07:26 -0500
commit7012ad570a2739a51f9f1f5605a9efa44416869c (patch)
tree1f33e1b3944198160e7f6901d68b9102fcf34dd4
parent0de843a9d404d1022ac40ba1e25da0194f367027 (diff)
downloadtaipan-7012ad570a2739a51f9f1f5605a9efa44416869c.tar.gz
fancy_numbers replacement, make some variables chars/ints instead of longs
-rw-r--r--README.txt22
-rw-r--r--taipan.c307
2 files changed, 191 insertions, 138 deletions
diff --git a/README.txt b/README.txt
index 1716b82..e361781 100644
--- a/README.txt
+++ b/README.txt
@@ -121,28 +121,20 @@ arcade game).
Bugs! At least these:
-- If using cc65's rand(), booty is coming up negative. Pretty sure
- this is fixed (it was due to my randi() having an unsigned int
- return type, but rand() returns signed, even though it never returns
- a negative numer). Anyway the real fix here is to get POKEY random
- numbers working correctly and ditch rand() again.
-
-- If using POKEY random numbers, 0 is never returned (since the POKEY
- uses a LFSR).
-
- When exiting to DOS and reloading, the title screen graphics are
messed up. The playtester who reported this was running on real
hardware (not an emulator). I can't see how this is happening, but I
expect it's related to this:
-- The BSS overlaps the start of the title screen. Consequences: There
- is a momentary graphics glitch when the main game is done loading and
- before it shows the "name your firm" screen. Also, we can't go back
- and display the title screen (but that's not something really necessary
- anyway). The fix: make the damn code smaller!
+- The BSS can overlap the start of the title screen (it's very close
+ anyway). Consequences: There is a momentary graphics glitch when the
+ main game is done loading and before it shows the "name your firm"
+ screen. Also, we can't go back and display the title screen (but that's
+ not something really necessary anyway). The fix: make the damn code
+ smaller!
- After a battle, the prices don't get reset (or, not always?) when
- entering the new port.
+ entering the new port (confirm?).
- The "negative interest" bug is currently missing, due to using
unsigned values for debt. Plus, it's cheating. It'll get added back when
diff --git a/taipan.c b/taipan.c
index 98f4f06..2624842 100644
--- a/taipan.c
+++ b/taipan.c
@@ -112,6 +112,8 @@ extern void __fastcall__ damage_lorcha(int which);
extern void __fastcall__ sink_lorcha(int which);
extern void __fastcall__ clear_lorcha(int which);
+/* used to set the background/text colors here, but now the
+ title screen does it (newtitle.s) */
void atari_text_setup() {
jsleep(1);
POKE(560, PEEK(212)); // restore the
@@ -119,8 +121,6 @@ void atari_text_setup() {
jsleep(1);
POKE(559, 34); // turn on the screen (normal playfield)
jsleep(1);
- // POKE(710, 0xc0); // green background
- // POKE(709, 0x0c); // bright text
POKE(756, 0xb8); // use our custom font
POKE(731, 1); // disable keyclick on XL/XE (does nothing on 400/800)
}
@@ -128,7 +128,7 @@ void atari_text_setup() {
/* this didn't work out, bummer. */
// extern void __fastcall__ waitvcount(unsigned char c);
-/**** End of atari-specific stuff */
+/**** End of atari-specific stuff. Supposed to be, anyway. */
/* old version of this used to just 'return randl()%clamp'.
If clamp were 0, the return value would be the unclamped
@@ -203,15 +203,26 @@ void visit_bank(void);
void transfer(void);
void quit(void);
void overload(void);
-void fancy_numbers(unsigned long num, char *fancy);
+// void fancy_numbers(unsigned long num, char *fancy);
int sea_battle(int id, int num_ships);
void fight_stats(int ships, int orders);
void mchenry(void);
void retire(void);
void final_stats(void);
+void you_only_have(unsigned char in_bank);
+void cprintfancy_ctr(unsigned long num, unsigned char center);
+#define cprintfancy(num) cprintfancy_ctr(num, 0)
+
+unsigned char firmpos;
+
+/*
char firm[23],
fancy_num[24];
+ */
+
+char *firm = (char *) 0x680;
+char *fancy_buf = (char *) 0x600;
char *item[] = { "Opium", "Silk", "Arms", "General Cargo" };
@@ -227,9 +238,9 @@ char *st[] = { "Critical", " Poor", " Fair",
unsigned long cash = 0,
bank = 0,
debt = 0,
- booty = 0,
- ec = 20,
- ed = 1; // used to be a float, 0.5
+ booty = 0;
+ // ec = 20,
+ // ed = 1; // used to be a float, 0.5
unsigned long price[4];
@@ -241,32 +252,34 @@ int base_price[4][8] = { {1000, 11, 16, 15, 14, 12, 10, 13},
int hkw_[4],
hold_[4];
-int hold = 0,
- // capacity = 60,
- guns = 0,
- bp = 0,
- // damage = 0,
- month = 1,
- year = 1860,
- li = 0,
- port = 1,
- wu_warn = 0,
- wu_bailout = 0;
+/* this really can go negative */
+int hold = 0;
+
+/* these being negative would be a Bad Thing */
+unsigned int guns = 0,
+ month = 1,
+ year = 1860,
+ ec = 20,
+ ed = 1;
+
+/* 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;
// these need to be longs to avoid int overflow when
// displaying ship status.
long damage = 0, capacity = 60, newdamage;
-// fancy_numbers() will get replaced sooner or later.
-// void cprintfancy(unsigned long ul) {
-// }
-
/* print an int or long as a string, conio-style */
void cprintulong(unsigned long ul) {
- cputs(ultoa(ul, fancy_num, 10));
+ cputs(ultoa(ul, fancy_buf, 10));
}
-
void at_sea() {
gotoxy(30, 6);
cputc(' ');
@@ -319,7 +332,7 @@ void new_ship(void) {
return;
}
- fancy_numbers(amount, fancy_num);
+ // fancy_numbers(amount, fancy_num);
compradores_report();
cputs("Do you wish to trade in your ");
@@ -332,7 +345,8 @@ void new_ship(void) {
}
cputs("\r\nship for one with 50 more capacity by\r\n");
cputs("paying an additional ");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(amount);
cputs(", Taipan? ");
choice = yngetc(0);
@@ -368,11 +382,12 @@ void new_gun(void)
return;
}
- fancy_numbers(amount, fancy_num);
+ // fancy_numbers(amount, fancy_num);
compradores_report();
cputs("Do you wish to buy a ship's gun\r\nfor ");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(amount);
cputs(", Taipan? ");
choice = yngetc(0);
@@ -387,8 +402,80 @@ void new_gun(void)
return;
}
-void fancy_numbers(unsigned long num, char *fancy)
-{
+/* replaces old fancy_numbers. same logic, but stuff is just
+ printed on the screen rather than being kept in a buffer.
+ center is a boolean.
+ Since we no longer return a string, port_stats() can't use
+ strlen() to position the debt amount... so we have to do
+ it here. Complicates the logic.
+ One minor difference between this and fancy_numbers() is that
+ we print "1.10 Million" rather than "1.1 Million" (extra zero).
+ I don't think anyone's going to complain.
+ */
+void cprintfancy_ctr(unsigned long num, unsigned char center) {
+ char mil = 1;
+ char *fancy_buf = (char*)0x600;
+ unsigned long tmp;
+
+ if(num >= 100000000L) {
+ /* 100 million and up:
+ |1000 Million|
+ |100 Million | */
+ if(center) revers(1);
+ cputs(ultoa(num / 1000000L, fancy_buf, 10));
+ } else if (num >= 10000000L) {
+ /* 10 million to 99 million:
+ | 10 Million |
+ |10.1 Million|*/
+ tmp = (num % 1000000L) / 100000L;
+ if(center && !tmp) cputc(' ');
+ if(center) revers(1);
+ cputs(ultoa(num / 1000000L, fancy_buf, 10));
+ if(tmp) {
+ cputc('.');
+ cputs(ultoa(tmp, fancy_buf, 10));
+ }
+ } else if (num >= 1000000L) {
+ /* 1 million to 9 million:
+ | 1 Million |
+ |1.10 Million| // always has 0, never 1.1
+ |1.23 Million| */
+ tmp = (num % 1000000L) / 10000L;
+ if(center && !tmp) cputc(' ');
+ if(center) revers(1);
+ cputs(ultoa(num / 1000000L, fancy_buf, 10));
+ if(tmp) {
+ cputc('.');
+ cputs(ultoa(tmp, fancy_buf, 10));
+ }
+ } else {
+ /* 0 to 999999:
+ | 999999 |
+ | 99999 |
+ | 9999 |
+ | 999 |
+ | 99 |
+ | 9 | */
+ mil = 0;
+
+ if(center) {
+ cputc(' ');
+ cputc(' ');
+ cputc(' ');
+ tmp = 0;
+ for(tmp = 100L; tmp < 1000000L; tmp *= 100L)
+ if(num < tmp) cputc(' ');
+ }
+ if(center) revers(1);
+ cputs(ultoa(num, fancy_buf, 10));
+ }
+
+ if(mil) cputs(" Million");
+ revers(0);
+}
+
+/*
+void fancy_numbers(unsigned long num, char *fancy) {
static char number[18];
char mil = 0;
unsigned int num1, num2;
@@ -426,6 +513,7 @@ void fancy_numbers(unsigned long num, char *fancy)
if(mil) strcat(fancy, " Million");
}
+*/
void fight_stats(int ships, int orders)
{
@@ -1213,7 +1301,6 @@ void set_prices(void)
void port_stats(void)
{
- static int firmpos = 0;
int i, in_use,
status = 100 - ((damage * 100L) / capacity);
@@ -1266,7 +1353,7 @@ void port_stats(void)
if(port_stat_dirty) {
void *p = (void *)(PEEK(88) + 256 * PEEK(89));
/* don't update the top of the screen while ANTIC is
- reading from it (prevents tearing) */
+ reading from it (prevents tearing)... but it doesn't work :( */
// waitvcount(84);
memcpy(p, &port_stat_screen, 640);
port_stat_dirty = 0;
@@ -1276,7 +1363,6 @@ void port_stats(void)
/* dynamic stuff: */
// waitvcount(84);
cursor(0);
- if(!firmpos) firmpos = 12 - strlen(firm) / 2;
gotoxy(firmpos, 0);
cputs("Firm: ");
cputs(firm);
@@ -1347,16 +1433,18 @@ void port_stats(void)
gotoxy(30, 6);
cblank(10);
revers(1);
- cputsxy(30, 6, location[port]);
+ if(port == 4 || port == 5) cputc(' ');
+ cputs(location[port]);
revers(0);
- gotoy(9);
- fancy_numbers(debt, fancy_num);
- gotox(34 - strlen(fancy_num) / 2);
+ gotoxy(28, 9);
+ // fancy_numbers(debt, fancy_num);
+ // gotox(34 - strlen(fancy_num) / 2);
clrtoeol();
- revers(1);
- cputs(fancy_num);
- revers(0);
+ // revers(1);
+ cprintfancy_ctr(debt, 1);
+ // cputs(fancy_num);
+ // revers(0);
gotoxy(29, 12);
clrtoeol();
@@ -1371,12 +1459,14 @@ void port_stats(void)
gotoxy(6, 14);
cblank(14);
- fancy_numbers(cash, fancy_num);
- cputs(fancy_num);
+ // fancy_numbers(cash, fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(cash);
gotoxy(26, 14);
cblank(13);
- fancy_numbers(bank, fancy_num);
- cputs(fancy_num);
+ // fancy_numbers(bank, fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(bank);
}
void mchenry(void)
@@ -1470,9 +1560,10 @@ void final_stats(void)
clrscr();
cputs("Your final status:\r\n\r\n");
finalcash = cash + bank - debt;
- fancy_numbers(finalcash, fancy_num);
+ // fancy_numbers(finalcash, fancy_num);
cputs("Net cash: ");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(finalcash);
cputs("\r\nShip size: ");
cprintulong(capacity);
cputs(" units with ");
@@ -1823,10 +1914,11 @@ void quit(void)
captains_report();
if (result == 1)
{
- fancy_numbers(booty, fancy_num);
+ // fancy_numbers(booty, fancy_num);
cputs("We captured some booty.\r\n");
cputs("It's worth ");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(booty);
cputc('!');
cash += booty;
good_joss_sound();
@@ -1982,11 +2074,12 @@ void li_yuen_extortion(void)
// amount = ((cash / i) * ((float) randi() / RAND_MAX)) + j;
amount = randclamp((cash >> (i - 1))) + j;
- fancy_numbers(amount, fancy_num);
+ // fancy_numbers(amount, fancy_num);
compradores_report();
cputs("Li Yuen asks ");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(amount);
cputs(" in donation\r\nto the temple of Tin Hau, the Sea\r\n");
while ((choice != 'Y') && (choice != 'y') &&
@@ -2051,6 +2144,20 @@ void li_yuen_extortion(void)
return;
}
+void you_only_have(unsigned char in_bank) {
+ gotoxy(0, 18);
+ clrtobot();
+
+ cputs("Taipan, you only have ");
+ cprintfancy(in_bank ? bank : cash);
+ cputs("\r\nin ");
+ cputs(in_bank ? "the bank" : "cash");
+ cputs(".\r\n");
+ good_joss_sound();
+
+ timed_getch(TMOUT_5S);
+}
+
void elder_brother_wu(void)
{
int choice = 0;
@@ -2067,10 +2174,10 @@ void elder_brother_wu(void)
// choice = get_one();
choice = yngetc('n');
- if ((choice == 'N') || (choice == 'n') || choice == 0)
+ if ((choice == 'n') || choice == 0)
{
break;
- } else if ((choice == 'Y') || (choice == 'y')) {
+ } else if (choice == 'y') {
if (((int)cash == 0) && ((int)bank == 0) && (guns == 0) &&
(hold_[0] == 0) && (hkw_[0] == 0) &&
(hold_[1] == 0) && (hkw_[1] == 0) &&
@@ -2095,7 +2202,7 @@ void elder_brother_wu(void)
cputs(". Are you willing, Taipan? ");
choice = get_one();
- if ((choice == 'N') || (choice == 'n'))
+ if (choice == 'n')
{
compradores_report();
cputs("Very well, Taipan, the game is over!\r\n");
@@ -2104,7 +2211,7 @@ void elder_brother_wu(void)
timed_getch(TMOUT_5S);
final_stats();
- } else if ((choice == 'Y') || (choice == 'y')) {
+ } else if (choice == 'y') {
cash += i;
debt += j;
port_stats();
@@ -2146,15 +2253,7 @@ void elder_brother_wu(void)
*/
break;
} else {
- gotoxy(0, 18);
- clrtobot();
- fancy_numbers(cash, fancy_num);
- cputs("Taipan, you only have ");
- cputs(fancy_num);
- cputs("\r\nin cash.\r\n");
- good_joss_sound();
-
- timed_getch(TMOUT_5S);
+ you_only_have(0);
}
}
}
@@ -2184,7 +2283,11 @@ void elder_brother_wu(void)
}
port_stats();
- break;
+ // break;
+
+ /* do NOT let him steal the money back on the SAME TURN
+ he loans it to you! */
+ return;
}
}
@@ -2392,13 +2495,8 @@ int port_choices(void) {
/* TODO: rewrite in asm, or at least better C */
-void name_firm(void)
-{
- /*
- int input,
- character = 0;
- */
- unsigned char input, count = 0;
+void name_firm(void) {
+ unsigned char input, firmlen = 0;
cursor(0);
clrscr();
@@ -2423,51 +2521,26 @@ void name_firm(void)
gotoxy(12, 13);
- while((input = agetc()) && (count < 22)) {
+ while((input = agetc()) && (firmlen < 22)) {
if(input == ENTER) {
- if(count)
+ if(firmlen)
break;
else
bad_joss_sound();
} else if(input == BKSP) {
- if(count) {
+ if(firmlen) {
backspace();
- firm[count--] = '\0';
+ firm[firmlen--] = '\0';
}
} else {
cputc(input);
- firm[count++] = input;
+ firm[firmlen++] = input;
}
}
cursor(0);
- firm[count] = '\0';
-
- /*
- while (((input = cgetc()) != ENTER) && (character < 22))
- {
- if (((input == BKSP) || (input == 127)) && (character == 0))
- {
- // nop
- } else if ((input == BKSP) || (input == 127)) {
- gotox(12 + character - 1);
- cputc(' ');
- gotox(12 + character - 1);
- firm[character] = '\0';
- character--;
- } else if (input == '\33') {
- flushinp();
- } else {
- cputc(input);
- firm[character] = input;
- character++;
- }
- }
-
- cursor(0);
- firm[character] = '\0';
- */
-
+ firm[firmlen] = '\0';
+ firmpos = 12 - firmlen / 2;
return;
}
@@ -2658,15 +2731,7 @@ void visit_bank(void)
bank += amount;
break;
} else {
- gotoxy(0, 18);
- clrtobot();
- fancy_numbers(cash, fancy_num);
- cputs("Taipan, you only have ");
- cputs(fancy_num);
- cputs("\r\nin cash.\r\n");
- good_joss_sound();
-
- timed_getch(TMOUT_5S);
+ you_only_have(0);
}
}
port_stats();
@@ -2687,13 +2752,7 @@ void visit_bank(void)
bank -= amount;
break;
} else {
- fancy_numbers(cash, fancy_num);
- cputs("Taipan, you only have ");
- cputs(fancy_num);
- cputs("\r\nin the bank.");
- good_joss_sound();
-
- timed_getch(TMOUT_5S);
+ you_only_have(1);
}
}
port_stats();
@@ -2806,12 +2865,13 @@ int main(void) {
port_stats();
- fancy_numbers(fine, fancy_num);
+ // fancy_numbers(fine, fancy_num);
compradores_report();
cputs("Bad Joss!!\r\n");
cputs("The local authorities have seized your\r\n");
cputs("Opium cargo and have also fined you\r\n");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(fine);
cputs(", Taipan!\r\n");
timed_getch(TMOUT_5S);
@@ -2868,12 +2928,13 @@ int main(void) {
cash -= robbed;
port_stats();
- fancy_numbers(robbed, fancy_num);
+ // fancy_numbers(robbed, fancy_num);
compradores_report();
cputs("Bad Joss!!\r\n");
cputs("You've been beaten up and\r\n");
cputs("robbed of ");
- cputs(fancy_num);
+ // cputs(fancy_num);
+ cprintfancy(robbed);
cputs(" in cash, Taipan!!\r\n");
under_attack_sound();