aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--explosion.s46
-rw-r--r--taipan.c210
2 files changed, 142 insertions, 114 deletions
diff --git a/explosion.s b/explosion.s
index 581e987..dc72538 100644
--- a/explosion.s
+++ b/explosion.s
@@ -21,38 +21,42 @@
.importzp tmp1, tmp2
.import _jsleep
-color1save = tmp1
-color2save = tmp2
+iloop_count = tmp1
; extern void explosion(void);
_explosion:
; {
- ; save original colors (don't hardcode, they can be changed on the title screen)
- lda COLOR1
- sta color1save
- lda COLOR2
- sta color2save
-
- ; dark text
- lda #0
- sta COLOR1
ldy #3 ; loop counter, counts 3 2 1
; {
@loop:
- lda color2save
- ora #$0c ; embrighten text background (without changing the hue)
- sta COLOR2
+ lda #$05
+ sta iloop_count
+
+@iloop:
+ lda RTCLOK+2
+@a:
+cmp RTCLOK+2
+ beq @a
+
+@b:
+ lda VCOUNT
+ cmp #(4+8)*4
+ bne @b
+ sta WSYNC
+ lda RANDOM
+ sta CHBASE
- ldx #0 ;\
- lda #$0a ; | jsleep(10);
- jsr _jsleep ;/
+ lda RTCLOK+2
+@c:
+cmp RTCLOK+2
+ beq @c
- lda color2save ; put text bg back like it was...
- sta COLOR2
+ dec iloop_count
+ bne @iloop
- ldx #0 ; ...and jsleep(10) again
+ ldx #0 ; jsleep(10)
lda #$0a
jsr _jsleep
@@ -60,7 +64,5 @@ _explosion:
bne @loop ; we're done if Y==0
; }
- lda color1save ; restore text color
- sta COLOR1
rts
; }
diff --git a/taipan.c b/taipan.c
index 04b6896..ad4b1a3 100644
--- a/taipan.c
+++ b/taipan.c
@@ -148,16 +148,26 @@ unsigned long randclamp(unsigned long clamp) {
return r % clamp;
}
-unsigned char chance_1_in(unsigned char odds) {
+unsigned char one_chance_in(unsigned char odds) {
return ( (randi() % odds) == 0);
}
+/* print 'count' spaces */
+void cspaces(unsigned char count) {
+ while(count--) cputc(' ');
+}
+
+/* print 1 space */
+void cspace(void) {
+ cputc(' ');
+}
+
/* print 'count' spaces, but leave the cursor where it was.
TODO: rewrite in asm. */
void cblank(unsigned char count) {
char oldx = wherex();
char oldy = wherey();
- while(count--) cputc(' ');
+ cspaces(count);
gotoxy(oldx, oldy);
}
@@ -174,17 +184,7 @@ void backspace() {
if allow_all is true, allows '*', which is used for
'throw cargo' in sea_battle. */
unsigned char get_item(unsigned char allow_all) {
- // unsigned char i;
-
for(;;) {
- /* using a switch makes the code 12 bytes smaller here
- i = lcgetc();
- if(i == 'o') return 0;
- if(i == 's') return 1;
- if(i == 'a') return 2;
- if(i == 'g') return 3;
- if(allow_all && i == '*') return 4;
- */
switch(lcgetc()) {
case 'o': return 0;
case 's': return 1;
@@ -213,7 +213,6 @@ char wu_assassin = 0;
/* title screen now a separate xex segment (see Makefile for details) */
// void splash_intro(void);
-#define get_one() agetc();
unsigned long get_num(void);
void name_firm(void);
void cash_or_guns(void);
@@ -438,7 +437,7 @@ void cprintfancy_big(bignump b) {
}
if(letter) {
- cputc(' ');
+ cspace();
cputc(letter);
cputs("illion");
}
@@ -454,21 +453,14 @@ void cprintulong(unsigned long ul) {
cputs(ultoa(ul, num_buf, 10));
}
-void at_sea() {
+void at_sea(void) {
gotoxy(30, 6);
- cputc(' ');
+ cspace();
revers(1);
cputs(location[0]);
revers(0);
- /* this is 24 bytes smaller: */
- cputs(" ");
-
- /* than this:
- cputc(' ');
- cputc(' ');
- cputc(' ');
- */
+ cspaces(3);
}
/* this bit of code was duplicated a *bunch* of times,
@@ -538,7 +530,7 @@ void new_ship(void) {
damage = 0;
}
- if (chance_1_in(2) && (guns < 1000))
+ if (one_chance_in(2) && (guns < 1000))
{
port_stats();
new_gun();
@@ -593,13 +585,14 @@ void cprintfancy_centered(unsigned long num) {
| 999 |
| 99 |
| 9 | */
- cputs(" ");
- if(num < 100L) cputc(' ');
- if(num < 10000L) cputc(' ');
+ // cputs(" ");
+ cspaces(3);
+ if(num < 100L) cspace();
+ if(num < 10000L) cspace();
revers(1);
cprintulong(num);
} else {
- // if(num < 10000000L) cputc(' ');
+ // if(num < 10000000L) cspace();
revers(1);
cprintfancy(num);
}
@@ -711,15 +704,15 @@ void fancy_numbers(unsigned long num, char *fancy) {
*/
void justify_int(unsigned int num) {
- if(num < 1000) cputc(' ');
- if(num < 100) cputc(' ');
- if(num < 10) cputc(' ');
+ if(num < 1000) cspace();
+ if(num < 100) cspace();
+ if(num < 10) cspace();
cprintulong(num);
}
void hide_cursor() {
gotoxy(0,23);
- cputc(' ');
+ cspace();
}
void update_guns() {
@@ -811,7 +804,8 @@ int sea_battle(int id, int num_ships) {
gotoxy(30, 0);
cputs(" We have");
gotoxy(30, 1);
- cputs(" guns");
+ cspaces(6);
+ cputs("guns");
revers(0);
update_guns();
@@ -1138,7 +1132,7 @@ int sea_battle(int id, int num_ships) {
cputs("Couldn't lose 'em.");
timed_getch();
- if((num_ships > 2) && (chance_1_in(5))) {
+ if((num_ships > 2) && (one_chance_in(5))) {
static int lost;
lost = (randi()%num_ships / 2) + 1;
@@ -1249,18 +1243,18 @@ int sea_battle(int id, int num_ships) {
gotoxy(0, 23);
clrtoeol();
cprintulong(ed);
- cputc(' ');
+ cspace();
cprintulong(i);
- cputc(' ');
+ cspace();
cprintulong(id);
- cputc(' ');
+ cspace();
cprintulong(damage);
- cputc(' ');
+ cspace();
cprintulong(newdamage);
cgetc();
#endif
- if((id == GENERIC) && (chance_1_in(20))) {
+ if((id == GENERIC) && (one_chance_in(20))) {
return 2;
}
}
@@ -1331,19 +1325,21 @@ void cash_or_guns(void)
int choice = 0;
clrscr();
- cputs("Do you want to start . . .\r\n\r\n");
- cputs(" 1) With cash (and a debt)\r\n\r\n");
- cputs(" -- or --\r\n\r\n");
+ cputs("Do you want to start . . .\r\n\n");
+ cputs(" 1) With cash (and a debt)\r\n\n");
+ // cputs(" -- or --\r\n\n");
+ cspaces(16);
+ cputs("-- or --\r\n\n");
cputs(" 2) With five guns and no cash\r\n");
- cputs(" (But no debt!)\r\n");
+ // cputs(" (But no debt!)\r\n");
+ cspaces(16);
+ cputs("(But no debt!)\r\n");
while ((choice != '1') && (choice != '2'))
{
gotoxy(10, 10);
- // cursor(1);
cputc('?');
- choice = get_one();
- // cursor(0);
+ choice = agetc();
}
cputc(choice);
@@ -1528,13 +1524,13 @@ void port_stats(void)
revers(1);
cputs(months[month - 1]);
revers(0);
- cputc(' ');
+ cspace();
cprintulong(year);
gotoxy(30, 6);
cblank(10);
revers(1);
- if(port == 4 || port == 5) cputc(' ');
+ if(port == 4 || port == 5) cspace();
cputs(location[port]);
revers(0);
@@ -1628,44 +1624,69 @@ void mchenry(void)
return;
}
+/*
void retire_blanks(void) {
char i;
- for(i = 0; i < 29; ++i) cputc(' ');
+ for(i = 0; i < 29; ++i) cspace();
crlf();
// above loop saves a measly 6 bytes over this:
// cputs(" \r\n");
}
+*/
+
+void retire_blanks(void) {
+ cspaces(29);
+ crlf();
+}
#ifdef BIGNUM
void aire(void) {
+ char endspace = 1;
bignum(networth);
bignum(big1T) = BIG_1T;
ulong_to_big(cash, networth);
big_add(networth, networth, bank);
+ // cputs(" ");
+ cspaces(4);
if(big_cmp(networth, big1B) < 0) {
- cputs(" M I L L I O N A I R E ! \r\n");
+ cputc('M');
} else if(big_cmp(networth, big1T) < 0) {
- cputs(" B I L L I O N A I R E ! \r\n");
+ cputc('B');
} else {
- cputs(" T R I L L I O N A I R E !\r\n");
+ cputs("T R");
+ endspace = 0;
}
+ cputs(" I L L I O N A I R E !");
+ if(endspace) cspaces(2);
+ crlf();
}
#endif
void retire(void) {
compradores_report();
revers(1);
+ // cspaces(29);
+ // crlf();
retire_blanks();
- cputs(" Y o u ' r e a \r\n");
+
+ // cputs(" Y o u ' r e a \r\n");
+ cputs(" Y o u ' r e a");
+ cspaces(9);
+ crlf();
+
+ // cspaces(29);
+ // crlf();
retire_blanks();
#ifdef BIGNUM
aire();
#else
cputs(" M I L L I O N A I R E ! \r\n");
#endif
+ // cspaces(29);
+ // crlf();
retire_blanks();
revers(0);
timed_getch();
@@ -1713,7 +1734,7 @@ void final_stats(void)
port_stat_dirty = 1;
clrscr();
- cputs("Your final status:\r\n\r\n"
+ cputs("Your final status:\r\n\n"
"Net cash: ");
#ifdef BIGNUM
cprintfancy_big(finalcash);
@@ -1724,7 +1745,7 @@ void final_stats(void)
cprintulong(capacity);
cputs(" units with ");
cprintulong(guns);
- cputs(" guns\r\n\r\n"
+ cputs(" guns\r\n\n"
"You traded for ");
cprintulong(years);
cputs(" year");
@@ -1739,7 +1760,7 @@ void final_stats(void)
{
cputc('s');
}
- cputs("\r\n\r\n");
+ cputs("\r\n\n");
revers(1);
cputs("Your score is ");
#ifdef BIGNUM
@@ -1751,12 +1772,12 @@ void final_stats(void)
revers(0);
if ((score < 100) && (score >= 0))
{
- cputs("Have you considered a land based job?\r\n\r\n\r\n");
+ cputs("Have you considered a land based job?\r\n\n\n");
} else if (score < 0) {
cputs("The crew has requested that you stay on\r\n"
- "shore for their safety!!\r\n\r\n");
+ "shore for their safety!!\r\n\n");
} else {
- cputs("\r\n\r\n\r\n");
+ cputs("\r\n\n\n");
}
cputs("Your Rating:\r\n");
cputc(17); // upper left corner
@@ -1772,7 +1793,8 @@ void final_stats(void)
}
cputs("Ma Tsu");
revers(0);
- cputs(" 50,000 and over |\r\n");
+ cspaces(9);
+ cputs("50,000 and over |\r\n");
cputc('|');
if ((score < 50000L) && (score > 7999L))
@@ -1788,9 +1810,11 @@ void final_stats(void)
{
revers(1);
}
- cputs("Taipan");
+ // cputs("Taipan");
+ cprint_taipan();
revers(0);
- cputs(" 1,000 to 7,999|\r\n");
+ cspaces(10);
+ cputs("1,000 to 7,999|\r\n");
cputc('|');
if ((score < 1000) && (score > 499))
@@ -1799,7 +1823,8 @@ void final_stats(void)
}
cputs("Compradore");
revers(0);
- cputs(" 500 to 999|\r\n");
+ cspaces(8);
+ cputs("500 to 999|\r\n");
cputc('|');
if (score < 500)
@@ -1808,7 +1833,8 @@ void final_stats(void)
}
cputs("Galley Hand");
revers(0);
- cputs(" less than 500|\r\n");
+ cspaces(7);
+ cputs("less than 500|\r\n");
cputc(26); // lower left corner
chline(31);
@@ -2148,7 +2174,7 @@ void quit(void)
timed_getch();
}
- if(chance_1_in(10)) {
+ if(one_chance_in(10)) {
clear_msg_window();
// gotoxy(0, 18);
// clrtobot();
@@ -2160,7 +2186,7 @@ void quit(void)
bad_joss_sound();
timed_getch();
- if(chance_1_in(30)) {
+ if(one_chance_in(30)) {
cputs(" I think we're going down!!\r\n\n");
timed_getch();
@@ -2194,7 +2220,7 @@ void quit(void)
bad_joss_sound();
timed_getch();
- if(chance_1_in(3)) {
+ if(one_chance_in(3)) {
int orig = port;
while(port == orig)
@@ -2300,11 +2326,11 @@ void li_yuen_extortion(void) {
cputs("DEBUG li_yuen_extortion()\r\n");
cputs("amount time i j\r\n");
cprintulong(amount);
- cputc(' ');
+ cspace();
cprintulong(time);
- cputc(' ');
+ cspace();
cprintulong(i);
- cputc(' ');
+ cspace();
cprintulong(j);
agetc();
*/
@@ -2326,7 +2352,7 @@ void li_yuen_extortion(void) {
// gotoxy(0, 18);
// clrtobot();
cprint_taipan_comma();
- cputs("you do not have enough cash!!\r\n\r\n");
+ cputs("you do not have enough cash!!\r\n\n");
timed_getch();
@@ -2413,7 +2439,7 @@ void elder_brother_wu(void)
{
gotoxy(21, 19);
- // choice = get_one();
+ // choice = agetc();
choice = yngetc('n');
if ((choice == 'n') || choice == 0)
break;
@@ -2444,7 +2470,7 @@ void elder_brother_wu(void)
cprintulong(j);
cputs(". Are you willing, Taipan? ");
- choice = get_one();
+ choice = agetc();
if(choice != 'y') {
compradores_report();
cputs("Very well, Taipan, the game is over!\r\n");
@@ -2532,7 +2558,7 @@ void elder_brother_wu(void)
return;
}
- if((debt > 20000) && (cash > 0) && (chance_1_in(5))) {
+ if((debt > 20000) && (cash > 0) && (one_chance_in(5))) {
int num = randi()%3 + 1;
cash = 0;
@@ -2743,7 +2769,7 @@ void buy(void) {
cputs("What do you wish me to buy, Taipan? ");
- choice = tolower(get_one());
+ choice = tolower(agetc());
if(choice == 'o') {
choice = 0;
break;
@@ -2777,13 +2803,14 @@ void buy(void) {
revers(1);
cputs(" afford ");
gotoxy(31, 23);
- cputs(" ");
+ // cputs(" ");
+ cspaces(9);
gotoxy(31, 23);
- if(afford < 100) cputc(' ');
- if(afford < 10000) cputc(' ');
- if(afford < 1000000) cputc(' ');
- if(afford < 100000000) cputc(' ');
+ if(afford < 100) cspace();
+ if(afford < 10000) cspace();
+ if(afford < 1000000) cspace();
+ if(afford < 100000000) cspace();
cprintulong(afford);
revers(0);
@@ -2824,7 +2851,7 @@ void sell(void) {
cputs("What do you wish me to sell, Taipan? ");
- choice = tolower(get_one());
+ choice = tolower(agetc());
if(choice == 'o') {
choice = 0;
break;
@@ -2996,10 +3023,9 @@ void bignum_test(void) {
for(i = 0; i < 14; i++) {
cprintfancy_big(n);
- cputc(' ');
+ cspace();
big_negate(n);
cprintfancy_big(n);
- // cputs("\r\n");
crlf();
big_mul(n, n, o);
}
@@ -3113,14 +3139,14 @@ int main(void) {
if(port == 1)
elder_brother_wu();
- if(chance_1_in(4)) {
- if(chance_1_in(2))
+ if(one_chance_in(4)) {
+ if(one_chance_in(2))
new_ship();
else if (guns < 1000)
new_gun();
}
- if((port != 1) && (chance_1_in(18)) && (hold_[0] > 0)) {
+ if((port != 1) && (one_chance_in(18)) && (hold_[0] > 0)) {
// float fine = ((cash / 1.8) * ((float) randi() / RAND_MAX)) + 1;
// the 1.8 is now a 2
unsigned long fine = 0;
@@ -3148,7 +3174,7 @@ int main(void) {
timed_getch();
}
- if ((chance_1_in(50)) &&
+ if ((one_chance_in(50)) &&
((hkw_[0] + hkw_[1] + hkw_[2] + hkw_[3]) > 0))
{
int i;
@@ -3171,12 +3197,12 @@ int main(void) {
timed_getch();
}
- if(chance_1_in(20)) {
+ if(one_chance_in(20)) {
if (li > 0) li++;
if (li == 4) li = 0;
}
- if((port != 1) && (li == 0) && (!chance_1_in(4))) {
+ if((port != 1) && (li == 0) && (!one_chance_in(4))) {
compradores_report();
cputs("Li Yuen has sent a Lieutenant,\r\n"
"Taipan. He says his admiral wishes\r\n"
@@ -3185,10 +3211,10 @@ int main(void) {
timed_getch();
}
- if(chance_1_in(9))
+ if(one_chance_in(9))
good_prices();
- if((cash > 25000) && (chance_1_in(20))) {
+ if((cash > 25000) && (one_chance_in(20))) {
// float robbed = ((cash / 1.4) * ((float) randi() / RAND_MAX));
// line below changes the 1.4 to 1.5
unsigned long robbed = randclamp((cash >> 2) + (cash >> 1));