aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--portstat.s56
-rw-r--r--taipan.c150
-rw-r--r--timed_getch.s11
3 files changed, 151 insertions, 66 deletions
diff --git a/portstat.s b/portstat.s
index 72ef06c..a3dab60 100644
--- a/portstat.s
+++ b/portstat.s
@@ -1,5 +1,12 @@
- .export _port_stat_screen
+ .export _port_stat_screen, _redraw_port_stat
+ .import _port_stat_dirty
+ .importzp ptr1, ptr2
+
+ srcptr = ptr1
+ dstptr = ptr2
+
+ .include "atari.inc"
; PORTSTAT.DAT is created on the H: device by running mkportstats.xex
; in atari800. H: needs to be set writable and pointed to the current
@@ -8,3 +15,50 @@
.rodata
_port_stat_screen:
.incbin "PORTSTAT.DAT"
+screenlen = * - _port_stat_screen
+screenpages = >screenlen
+partial = <screenlen
+
+ .code
+
+; only redraw the port status screen if needed. this saves 53 bytes
+; compared to using memcpy().
+; void redraw_port_stat(void);
+_redraw_port_stat:
+ lda _port_stat_dirty
+ beq @done
+
+ lda #<_port_stat_screen
+ sta srcptr
+ lda #>_port_stat_screen
+ sta srcptr+1
+
+ lda SAVMSC
+ sta dstptr
+ lda SAVMSC+1
+ sta dstptr+1
+
+ ; copy screenpages pages
+ ldx #screenpages
+ ldy #0
+@pageloop:
+ lda (srcptr),y
+ sta (dstptr),y
+ dey
+ bne @pageloop
+ inc srcptr+1
+ inc dstptr+1
+ dex
+ bne @pageloop
+
+ ; copy last (partial) page. we know Y is 0 here.
+ sty _port_stat_dirty
+@partloop:
+ lda (srcptr),y
+ sta (dstptr),y
+ iny
+ cpy #partial
+ bne @partloop
+
+@done:
+ rts
diff --git a/taipan.c b/taipan.c
index 3c58c47..b546b7a 100644
--- a/taipan.c
+++ b/taipan.c
@@ -3,9 +3,6 @@
#include <conio.h>
#include <time.h>
#include <stdlib.h>
-// #include <stdio.h> // finally got rid of it!
-#include <ctype.h>
-#include <string.h> /* only for memcpy() */
#include <peekpoke.h>
#include <stdint.h>
@@ -121,6 +118,10 @@ extern void __fastcall__ damage_lorcha(int which);
extern void __fastcall__ sink_lorcha(int which);
extern void __fastcall__ clear_lorcha(int which);
+/* redraw the static part of the port status screen, but only
+ if nothing has set port_stat_dirty */
+extern void redraw_port_stat(void);
+
/* used to set the background/text colors here, but now the
title screen does it (newtitle.s) */
void atari_text_setup() {
@@ -245,12 +246,14 @@ void too_much_cash(void);
char would_overflow(unsigned long a, unsigned long b);
int get_time(void);
void cprint_taipan_comma(void);
+void cprint_taipan_colon(void);
void cprint_taipan_bang(void);
void cprint_taipan_bangbang(void);
void cprint_taipan_period(void);
void cprint_taipan_prompt(void);
void cprint_elder_brother_wu(void);
void cprint_li_yuen(void);
+void cprint_firm_colon(void);
/* local replacement for strtoul, see strtonum.c */
unsigned long __fastcall__ strtonum(const char* nptr);
@@ -399,6 +402,11 @@ void cprint_taipan_comma(void) {
comma_space();
}
+void cprint_taipan_colon(void) {
+ cprint_taipan();
+ cputs(": ");
+}
+
void cprint_bang(void) {
cputc('!');
}
@@ -452,6 +460,10 @@ void cprint_Do_you_want(void) {
cputs("Do you want ");
}
+void cprint_firm_colon(void) {
+ cputs("Firm:");
+}
+
#ifdef BIGNUM
bignum(big1T) = BIG_1T;
bignum(big1B) = BIG_1B;
@@ -1080,7 +1092,8 @@ int sea_battle(int id, int num_ships) {
total = 0;
gotoxy(0, 3);
- cputs("You have the following on board, Taipan:");
+ cputs("You have the following on board");
+ cprint_taipan_colon();
gotoxy(4, 4);
cputs(item[0]);
cputs(": ");
@@ -1460,7 +1473,7 @@ void port_stats(void)
/* all the static text that used to be in port_stats() has
been moved to mkportstats.c, which creates a .xex file which
will get prepended to taipan.xex and loaded into a chunk of memory
- cc65 won't use. When it's time to print it, it'll get memcpy()ed
+ cc65 won't use. When it's time to print it, it'll get copied
into *SAVMSC. */
#if 0
@@ -1503,18 +1516,16 @@ void port_stats(void)
cputsxy(20, 14, "Bank: ");
#else
- if(port_stat_dirty) {
- void *p = (void *)(PEEK(88) + 256 * PEEK(89));
- memcpy(p, &port_stat_screen, 640);
- port_stat_dirty = 0;
- }
+ redraw_port_stat();
#endif
/* dynamic stuff: */
gotoxy(firmpos, 0);
- cputs("Firm: ");
+ // cputs("Firm: ");
+ cprint_firm_colon();
cputs(firm);
- cputs(", Hong Kong");
+ comma_space();
+ cputs(location[1]);
gotoxy(21, 4);
in_use = warehouse_in_use();
@@ -1625,16 +1636,15 @@ void port_stats(void)
#endif
}
-void mchenry(void)
-{
- static int choice;
+void mchenry(void) {
+ static char choice;
compradores_report();
cprint_taipan_comma();
- cputs("Mc Henry from the Hong Kong\r\n");
- cputs("Shipyards has arrived!! He says, 'I see\r\n");
- cputs("ye've a wee bit of damage to yer ship.'\r\n");
- cputs("Will ye be wanting repairs? ");
+ cputs("Mc Henry from the Hong Kong\r\n"
+ "Shipyards has arrived!! He says, 'I see\r\n"
+ "ye've a wee bit of damage to yer ship.'\r\n"
+ "Will ye be wanting repairs? ");
choice = yngetc('y');
@@ -2405,7 +2415,7 @@ void li_yuen_extortion(void) {
cprint_li_yuen();
cputs(" asks ");
cprintfancy(amount);
- cputs(" in donation\r\nto the temple of Tin Hau, the Sea\r\nGoddess. Will you pay? ");
+ cputs(" in donation\r\nto the temple of Tin Hau, the Sea\r\nGoddess. Will you pay? ");
choice = yngetc(0);
if(choice == 'y') {
@@ -2446,7 +2456,7 @@ void li_yuen_extortion(void) {
cprint_elder_brother_wu();
cputs("will not pay\r\n"
"Li Yuen the difference. I would be very\r\n"
- "wary of pirates if I were you");
+ "wary of pirates if I were you.");
cprint_taipan_period();
crlf();
}
@@ -2509,10 +2519,10 @@ void elder_brother_wu(void)
// choice = agetc();
choice = yngetc('n');
- if ((choice == 'n') || choice == 0)
+ if(choice != 'y')
break;
- if ((cash == 0) &&
+ if((cash == 0) &&
#ifdef BIGNUM
(big_cmp(bank, big0) == 0)
#else
@@ -2531,7 +2541,7 @@ void elder_brother_wu(void)
{
compradores_report();
cputs("Elder Brother is aware of your plight,\r\n"
- "Taipan. He is willing to loan you an\r\n"
+ "Taipan. He is willing to loan you an\r\n"
"additional ");
cprintulong(i);
cputs(" if you will pay back\r\n");
@@ -2554,7 +2564,7 @@ void elder_brother_wu(void)
port_stats();
compradores_report();
- cputs("Very well, Taipan. Good joss!!\r\n");
+ cputs("Very well, Taipan. Good joss!!\r\n");
bad_joss_sound();
timed_getch();
@@ -2778,6 +2788,7 @@ int port_choices(void) {
/* TODO: rewrite in asm, or at least better C */
void name_firm(void) {
unsigned char input, firmlen = 0;
+ unsigned int randseed;
clrscr();
@@ -2795,7 +2806,8 @@ void name_firm(void) {
gotoxy(2, 11);
cputs("What will you name your");
gotoxy(6, 13);
- cputs("Firm:");
+ // cputs("Firm:");
+ cprint_firm_colon();
chlinexy(12, 14, 22);
gotoxy(12, 13);
@@ -2814,11 +2826,19 @@ void name_firm(void) {
} else {
cputc(input);
firm[firmlen++] = input;
+ randseed <<= 1;
+ randseed += (input - 32);
}
}
firm[firmlen] = '\0';
firmpos = 12 - firmlen / 2;
+
+ randseed ^= (PEEKW(19) + PEEK(53770L));
+ srand(randseed);
+ for(input = 0; input < (firm[0] >> 2); ++input)
+ randi();
+
return;
}
@@ -2855,8 +2875,9 @@ void buy(void) {
revers(1);
cputs(" afford ");
gotoxy(31, 23);
- cspaces(9);
- gotoxy(31, 23);
+ // cspaces(9);
+ // gotoxy(31, 23);
+ cblank(9);
if(afford < 100) cspace();
if(afford < 10000) cspace();
@@ -2867,7 +2888,8 @@ void buy(void) {
revers(0);
gotoxy(0, 23);
- cputs("I buy, Taipan: ");
+ cputs("I buy, ");
+ cprint_taipan_colon();
amount = get_num();
if(amount == UINT32_MAX) {
@@ -2897,7 +2919,8 @@ void sell(void) {
how_much();
cputs(item[choice]);
- cputs(" shall\r\nI sell, Taipan: ");
+ cputs(" shall\r\nI sell, ");
+ cprint_taipan_colon();
amount = get_num();
@@ -2980,7 +3003,6 @@ void visit_bank(void)
amount = get_num();
#ifdef BIGNUM
if(amount == UINT32_MAX) {
- // memcpy(bigamt, bank, 6);
big_copy(bigamt, bank);
} else {
ulong_to_big(amount, bigamt);
@@ -3079,7 +3101,7 @@ int main(void) {
#endif
name_firm();
- initrand();
+ // initrand();
cash_or_guns();
set_prices();
@@ -3108,49 +3130,49 @@ int main(void) {
final_stats();
}
- if ((port == 1) && (li == 0) && (cash > 0))
- li_yuen_extortion();
+ if(port == 1) {
+ if((li == 0) && (cash > 0))
+ li_yuen_extortion();
- if ((port == 1) && (damage > 0))
- mchenry();
+ if(damage > 0)
+ mchenry();
- if ((port == 1) && (debt >= 10000) && (wu_warn == 0))
- {
- int braves = randi()%100 + 50;
+ if((debt >= 10000) && (wu_warn == 0)) {
+ int braves = randi()%100 + 50;
- compradores_report();
- cprint_elder_brother_wu();
- cputs("has sent ");
- cprintulong(braves);
- cputs(" braves\r\nto escort you to the Wu mansion");
- cprint_taipan_period();
- crlf();
+ compradores_report();
+ cprint_elder_brother_wu();
+ cputs("has sent ");
+ cprintulong(braves);
+ cputs(" braves\r\nto escort you to the Wu mansion");
+ cprint_taipan_period();
+ crlf();
- timed_getch();
+ timed_getch();
- clear_msg_window();
- cprint_elder_brother_wu();
- cputs("reminds you of the\r\n"
- "Confucian ideal of personal worthiness,\r\n"
- "and how this applies to paying one's\r\ndebts.\r\n");
+ clear_msg_window();
+ cprint_elder_brother_wu();
+ cputs("reminds you of the\r\n"
+ "Confucian ideal of personal worthiness,\r\n"
+ "and how this applies to paying one's\r\ndebts.\r\n");
- timed_getch();
+ timed_getch();
- clear_msg_window();
- cputs("He is reminded of a fabled barbarian\r\n"
- "who came to a bad end, after not caring\r\n"
- "for his obligations.\r\n\n"
- "He hopes no such fate awaits you, his\r\nfriend");
- cprint_taipan_period();
- crlf();
+ clear_msg_window();
+ cputs("He is reminded of a fabled barbarian\r\n"
+ "who came to a bad end, after not caring\r\n"
+ "for his obligations.\r\n\n"
+ "He hopes no such fate awaits you, his\r\nfriend");
+ cprint_taipan_period();
+ crlf();
- timed_getch();
+ timed_getch();
- wu_warn = 1;
- }
+ wu_warn = 1;
+ }
- if(port == 1)
elder_brother_wu();
+ }
if(one_chance_in(4)) {
if(one_chance_in(2))
diff --git a/timed_getch.s b/timed_getch.s
index 9a0f9a1..41b9ecb 100644
--- a/timed_getch.s
+++ b/timed_getch.s
@@ -1,7 +1,7 @@
.export _timed_getch, _set_jiffy_timer, _agetc, _numgetc
.export _yngetc, _lcgetc, _jsleep
- .import _cgetc, _cblank, _cursor
+ .import _cgetc, _cblank, _cursor, _rand
.include "atari.inc"
@@ -69,6 +69,15 @@ _agetc:
jsr _cgetc ; get ATASCII code of keypress
+ ; twitch the random bottle based on the low bit of
+ ; the character entered.
+ pha
+ and #$01
+ beq @nr
+ jsr _rand
+@nr:
+ pla
+
; special cases
cmp #$9b ; enter key, return as-is
beq ok