aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-02-16 07:04:56 -0500
committerB. Watson <yalhcru@gmail.com>2016-02-16 07:04:56 -0500
commitb2f7604ac51db075201ea0aa40d002d3d5e7e071 (patch)
tree7836fa910955599688f5fde5cb3fed49c14416f9
parent3a22a9af57b8b564301cd86e8e933eb1a22981ce (diff)
downloadtaipan-b2f7604ac51db075201ea0aa40d002d3d5e7e071.tar.gz
shrink code, 5599 bytes free, move some code so it runs straight from bank 3 in cartridge
-rw-r--r--bank2.s7
-rw-r--r--bigfloat.s6
-rw-r--r--cartbank3.cfg4
-rw-r--r--console.s7
-rw-r--r--draw_lorcha.s7
-rw-r--r--explosion.s6
-rw-r--r--portstat.s6
-rw-r--r--rand.s6
-rw-r--r--soundasm.s6
-rw-r--r--taipan.c56
-rw-r--r--timed_getch.s6
-rw-r--r--ultostr.s6
12 files changed, 88 insertions, 35 deletions
diff --git a/bank2.s b/bank2.s
index d700fc5..6f36b38 100644
--- a/bank2.s
+++ b/bank2.s
@@ -3,4 +3,11 @@ start = $8000
end = $9fff
.org start
.incbin "splitrom.raw.2"
+
+ .if * > end
+ .fatal "bank2 code too large"
+ .else
+ .out .sprintf("=> %d bytes free in bank 2", end - *)
+ .endif
+
.res end-*+1, $ff
diff --git a/bigfloat.s b/bigfloat.s
index 529de1a..5acbecf 100644
--- a/bigfloat.s
+++ b/bigfloat.s
@@ -23,7 +23,11 @@ BIG_64K: ; 65535 (2**16-1) in float format.
;BIG_ULONG_MAX:
;.byte $44, $42, $94, $96, $72, $95
- .code
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
; It seems like fr0_to_fptemp and friends should be using the OS
; FLD* and FST* routines, doesn't it? But look:
diff --git a/cartbank3.cfg b/cartbank3.cfg
index e50d755..1e6e5cc 100644
--- a/cartbank3.cfg
+++ b/cartbank3.cfg
@@ -28,8 +28,9 @@ MEMORY {
RAM: file = %O, define = yes, start = %S, size = $BC20 - __STACKSIZE__ - __RESERVED_MEMORY__ - %S;
TRAILER: file = %O, start = $0000, size = $0006;
-# read-only data goes in a cart bank
+# read-only data (and some code) goes in a cart bank
HIGHDATA: file = "rodata.8000" start = $8000, size = $2000;
+
}
SEGMENTS {
EXEHDR: load = HEADER, type = ro;
@@ -42,6 +43,7 @@ SEGMENTS {
INIT: load = RAM, type = ro, optional = yes;
CODE: load = RAM, type = ro, define = yes;
RODATA: load = HIGHDATA, type = ro;
+ HIGHCODE: load = HIGHDATA, type = ro;
DATA: load = RAM, type = rw;
INITBSS: load = RAM, type = bss, optional = yes;
BSS: load = RAM, type = bss, define = yes;
diff --git a/console.s b/console.s
index 2bbdb04..7be2fb3 100644
--- a/console.s
+++ b/console.s
@@ -9,6 +9,13 @@
.importzp destptr ; from draw_lorcha.s
.import _cspace
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
+
+
; void clrtobot(void);
; void clrtoeol(void);
; void clrtoline(unsigned char line);
diff --git a/draw_lorcha.s b/draw_lorcha.s
index ae82bd2..3cd56ec 100644
--- a/draw_lorcha.s
+++ b/draw_lorcha.s
@@ -9,6 +9,7 @@
; libsrc/atari/mul40.s, which is getting linked anyway
; because conio uses it.
+ .rodata
; offset from start of screen for each ship position (0-9)
lorcha_pos_lo:
.byte <320, <328, <336, <344, <352
@@ -42,6 +43,12 @@ lorcha_data:
damaged_data:
.incbin "DAMAGED.DAT"
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
+
; void __fastcall__ flash_lorcha(int which);
_flash_lorcha:
ldx #$80
diff --git a/explosion.s b/explosion.s
index 678e2c0..64747eb 100644
--- a/explosion.s
+++ b/explosion.s
@@ -32,6 +32,12 @@
.importzp tmp1, tmp2
.import _jsleep
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
+
; how many times the screen will appear to flash.
flashes = 3
diff --git a/portstat.s b/portstat.s
index a3dab60..fa68b9f 100644
--- a/portstat.s
+++ b/portstat.s
@@ -19,7 +19,11 @@ screenlen = * - _port_stat_screen
screenpages = >screenlen
partial = <screenlen
- .code
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
; only redraw the port status screen if needed. this saves 53 bytes
; compared to using memcpy().
diff --git a/rand.s b/rand.s
index f2e2449..a284592 100644
--- a/rand.s
+++ b/rand.s
@@ -8,6 +8,12 @@
.include "atari.inc"
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
+
; unsigned long __fastcall__ randl(void);
; this returns the full range of an unsigned long, 0 to 2**32-1
_randl:
diff --git a/soundasm.s b/soundasm.s
index d606b9a..b47de30 100644
--- a/soundasm.s
+++ b/soundasm.s
@@ -25,6 +25,12 @@
.export _bad_joss_sound, _good_joss_sound, _under_attack_sound
.importzp tmp1, tmp2, tmp3, tmp4, sreg
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
+
initialpitch = sreg
delay = sreg+1
pitch = tmp1
diff --git a/taipan.c b/taipan.c
index 15b7827..2bbe84a 100644
--- a/taipan.c
+++ b/taipan.c
@@ -253,6 +253,7 @@ void cprint_taipan_prompt(void);
void cprint_elder_brother_wu(void);
void cprint_li_yuen(void);
void cprint_firm_colon(void);
+int get_ship_status(void);
/* local replacement for strtoul, see strtonum.c */
unsigned long __fastcall__ strtonum(const char* nptr);
@@ -463,6 +464,11 @@ void cprint_firm_colon(void) {
cputs("Firm:");
}
+/* making this a function saved 52 bytes */
+int get_ship_status(void) {
+ return 100 - ((damage * 100L) / capacity);
+}
+
#ifdef BIGNUM
bignum(big1T) = BIG_1T;
bignum(big1B) = BIG_1B;
@@ -589,14 +595,14 @@ void overload(void) {
return;
}
+unsigned int gunamt(void) {
+ return randi()%(1000 * (get_time() + 5) / 6);
+}
+
void new_ship(void) {
- int choice = 0,
- time;
unsigned long amount;
- // time = ((year - 1860) * 12) + month;
- time = get_time();
- amount = randi()%(1000 * (time + 5) / 6) * (capacity / 50) + 1000;
+ amount = gunamt() * (capacity / 50) + 1000;
if(cash < amount) {
return;
@@ -613,50 +619,37 @@ void new_ship(void) {
cprintfancy(amount);
cprint_taipan_prompt();
- choice = yngetc(0);
- if(choice == 'y') {
+ if(yngetc(0) == 'y') {
cash -= amount;
hold += 50;
capacity += 50;
damage = 0;
}
- if (one_chance_in(2) && (guns < 1000))
- {
- port_stats();
+ port_stats();
+ if(one_chance_in(2))
new_gun();
- }
-
- port_stats();
return;
}
-void new_gun(void)
-{
- int choice = 0,
- time;
+void new_gun(void) {
+ unsigned int amount;
- unsigned long amount;
+ if(guns >= 1000) return;
- // time = ((year - 1860) * 12) + month;
- time = get_time();
- amount = randi()%(1000 * (time + 5) / 6) + 500;
+ amount = gunamt() + 500;
if((cash < amount) || (hold < 10)) {
return;
}
- // fancy_numbers(amount, fancy_num);
-
compradores_report();
cputs("Do you wish to buy a ship's gun\r\nfor ");
- // cputs(fancy_num);
cprintfancy(amount);
cprint_taipan_prompt();
- choice = yngetc(0);
- if(choice == 'y') {
+ if(yngetc(0) == 'y') {
cash -= amount;
hold -= 10;
guns += 1;
@@ -876,7 +869,8 @@ int sea_battle(int id, int num_ships) {
while(num_ships > 0) {
if(damage >= capacity) return 4;
- status = 100L - ((damage * 100L / capacity));
+ // status = 100L - ((damage * 100L / capacity));
+ status = get_ship_status();
/* // I think this is a problem:
if(status <= 0) {
return 4;
@@ -1466,8 +1460,8 @@ unsigned int warehouse_in_use() {
void port_stats(void)
{
- int i, in_use,
- status = 100 - ((damage * 100L) / capacity);
+ int i, in_use, status = get_ship_status();
+ // status = 100 - ((damage * 100L) / capacity);
/* all the static text that used to be in port_stats() has
been moved to mkportstats.c, which creates a .xex file which
@@ -2401,7 +2395,7 @@ void li_yuen_extortion(void) {
unsigned int i = 2, j = 0;
if(time > 12) {
- j = randi() % (1000 * time) + (1000 * time);
+ j = randi() % (2 * (1000 * time));
i = 1;
}
@@ -3176,7 +3170,7 @@ int main(void) {
if(one_chance_in(4)) {
if(one_chance_in(2))
new_ship();
- else if (guns < 1000)
+ else
new_gun();
}
diff --git a/timed_getch.s b/timed_getch.s
index 41b9ecb..510c885 100644
--- a/timed_getch.s
+++ b/timed_getch.s
@@ -5,6 +5,12 @@
.include "atari.inc"
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
+
; keyboard and timer functions for taipan.
; sleep for j jiffies.
diff --git a/ultostr.s b/ultostr.s
index 29420e4..e63fd3e 100644
--- a/ultostr.s
+++ b/ultostr.s
@@ -18,7 +18,11 @@
radix = 10
-.code
+ .ifdef CART_TARGET
+ .segment "HIGHCODE"
+ .else
+ .code
+ .endif
_ultostr:
; pop the arguments