aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.txt9
-rw-r--r--rand.s50
-rw-r--r--taipan.c6
3 files changed, 47 insertions, 18 deletions
diff --git a/README.txt b/README.txt
index 3f1939a..1716b82 100644
--- a/README.txt
+++ b/README.txt
@@ -132,10 +132,8 @@ Bugs! At least these:
- 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).
-
-- After a battle, the prices don't get reset (or, not always?) when
- entering the new port.
+ 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
@@ -143,6 +141,9 @@ Bugs! At least these:
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.
+
- The "negative interest" bug is currently missing, due to using
unsigned values for debt. Plus, it's cheating. It'll get added back when
I either start using big numbers (floats or 64-bit ints or whatever),
diff --git a/rand.s b/rand.s
index 1fa7d8d..8b4c502 100644
--- a/rand.s
+++ b/rand.s
@@ -1,26 +1,54 @@
- .export _randi, _randl
- .importzp sreg
+ .export _randb, _randi, _randl
+ .importzp sreg, tmp3
-RANDOM = 53770 ; POKEY LFSR read address, defined in the Atari OS
+ .include "atari.inc"
-; void __fastcall__ randi(void);
+; RANDOM is the POKEY LFSR read address.
+; unfortunately, a read from this address will never
+; return 0, since LFSR's can't do that. So there's
+; extra code in here to (try to) compensate.
+
+; unsigned char __fastcall__ randb(void);
+_randb: ; C-callable entry point
+ ldx #0
+randb: ; asm-callable (doesn't trash X reg)
+ lda RANDOM ; bit 7 of this read ends up as bit 0 of result
+ sta tmp3
+ nop ; let the LFSR cook for a bit...
+ nop
+ lda RTCLOK ; different amount of cooking depending on whether
+ and #$01 ; we're on an even or odd numbered TV frame
+ bne @1
+ nop
+ nop
+ nop
+@1:
+ rol tmp3 ; tmp3 bit 7 now in carry
+ lda RANDOM
+ rol ; carry now in bit 0 of A
+ nop
+ nop
+ rts
+
+; unsigned int __fastcall__ randi(void);
; NB cc65's rand() returns a positive signed int, meaning
; 0 to 0x7fff.
_randi:
- lda RANDOM
+ jsr randb
and #$7f
tax
- lda RANDOM
+ jsr randb
rts
-; void __fastcall__ randl(void);
+; unsigned long __fastcall__ randl(void);
_randl:
- lda RANDOM
+ jsr randb
sta sreg
- lda RANDOM
+ jsr randb
sta sreg+1
- lda RANDOM
- ldx RANDOM
+ jsr randb
+ tax
+ jsr randb
rts
diff --git a/taipan.c b/taipan.c
index 6fdd1d2..98f4f06 100644
--- a/taipan.c
+++ b/taipan.c
@@ -11,7 +11,7 @@
/* define this to use cc65's rand() instead of POKEY's RANDOM
register. Leave disabled for now as POKEY never returns 0 (it's an
LFSR, I should have known that would happen...) */
-// #define POKEY_RANDOM
+#define POKEY_RANDOM
/* define this for testing sea_battle(). it causes a pirate
attack every time you leave port. Don't leave defined for
@@ -73,11 +73,11 @@ extern void __fastcall__ jsleep(unsigned int j);
/* Atari-specific random number functions from rand.s.
Non-Atari platforms can probably just:
#define initrand() _randomize()
-#define randi() rand()
+#define randi() ((unsigned int)rand())
#define randl() (unsigned long)((randi() << 16) | randi())
*/
-#if POKEY_RANDOM
+#ifdef POKEY_RANDOM
#define initrand() /* no-op on Atari */
/* random positive int, 0 to 32767 */
extern unsigned int __fastcall__ randi(void);