From ea2d5014ade974ca99678d3aac36ebd4c8e4d8c6 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 25 Mar 2021 03:52:27 -0400 Subject: Save 11 bytes --- NOTES.txt | 4 ++++ rand.s | 12 +++++++++++- taipan.c | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/NOTES.txt b/NOTES.txt index 6d8d37f..6825336 100644 --- a/NOTES.txt +++ b/NOTES.txt @@ -23,6 +23,10 @@ arcade game). Deliberate differences between the Apple II and Atari ports: +0. The Atari version is noticeably faster than the Apple version on II+ or + IIe. This is because it's written in C and assembly, not interpreted + BASIC. A IIgs on the other hand... + 1. "Press ESC for help" rather than ESC to start. Starting the game is done with the space bar or return key. diff --git a/rand.s b/rand.s index a284592..6efcabd 100644 --- a/rand.s +++ b/rand.s @@ -1,5 +1,5 @@ - .export _randl + .export _randl, _rand1to3 .import _rand ; .export _randb, _randi, _randl ; .export _rand1in5 @@ -27,6 +27,16 @@ _randl: ldx tmp3 rts +; return 1, 2, or 3. equivalent to: randi()%3+1 +; replacing both occurences of the expression in taipan.c with a calls +; to this function saves 11 bytes. +_rand1to3: + jsr _rand ; returns 16 bits: X is MSB (which we ignore), A is LSB + and #$03 ; A now 0..3 + beq _rand1to3 ; try again, if it's 0 + ldx #0 ; now A is 1..3, but we have to force X to 0... + rts + ;;; rest of file is commented out ; RANDOM is the POKEY LFSR read address. According to the POKEY data diff --git a/taipan.c b/taipan.c index bd67589..d1cb8ed 100644 --- a/taipan.c +++ b/taipan.c @@ -97,6 +97,8 @@ extern unsigned int __fastcall__ randi(void); #define randi() ((unsigned int)rand()) #endif +extern unsigned char rand1to3(void); + /* random long, 0 to 2**32-1 */ extern unsigned long __fastcall__ randl(void); @@ -1626,7 +1628,7 @@ void cash_or_guns(void) { void set_prices(void) { char i; for(i = 0; i < 4; ++i) - price[i] = base_price[i][port] / 2 * (randi()%3 + 1) * base_price[i][0]; + price[i] = base_price[i][port] / 2 * rand1to3() * base_price[i][0]; } unsigned int warehouse_in_use() { @@ -2825,7 +2827,7 @@ void elder_brother_wu(void) { } if((debt > 20000) && (cash > 0) && (one_chance_in(5))) { - unsigned char num = randi()%3 + 1; + unsigned char num = rand1to3(); cash = 0; port_stats(); -- cgit v1.2.3