aboutsummaryrefslogtreecommitdiff
path: root/rand.s
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2021-03-25 03:52:27 -0400
committerB. Watson <yalhcru@gmail.com>2021-03-25 03:52:27 -0400
commitea2d5014ade974ca99678d3aac36ebd4c8e4d8c6 (patch)
treee02923fba1a64c3c7dfa4ff24d69ad09f9c1eef0 /rand.s
parent9535946177debc5295ff47a9a09143d2c2de8c96 (diff)
downloadtaipan-ea2d5014ade974ca99678d3aac36ebd4c8e4d8c6.tar.gz
Save 11 bytes
Diffstat (limited to 'rand.s')
-rw-r--r--rand.s12
1 files changed, 11 insertions, 1 deletions
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