aboutsummaryrefslogtreecommitdiff
path: root/rand.s
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-20 06:02:46 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-20 06:02:46 -0500
commit6ed92fecc6eebcde1f8e855f76fa6a0d6afa749c (patch)
treeb4bb45959ad641c4286dd4e8bc5d70ea895229e4 /rand.s
parent12114dbef93e85bb7b5832f60410bd73855883dd (diff)
downloadtaipan-6ed92fecc6eebcde1f8e855f76fa6a0d6afa749c.tar.gz
fix and simplify cprintfancy, allow Delete key and K/M for 1000/1M when entering numbers
Diffstat (limited to 'rand.s')
-rw-r--r--rand.s44
1 files changed, 40 insertions, 4 deletions
diff --git a/rand.s b/rand.s
index fa181cc..af4b693 100644
--- a/rand.s
+++ b/rand.s
@@ -1,13 +1,48 @@
.export _randb, _randi, _randl
+; .export _rand1in5
+; .export _randbit
.importzp sreg, tmp3
.include "atari.inc"
-; 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.
+; RANDOM is the POKEY LFSR read address. This appears to be the low 8
+; bits of a 17-bit LFSR (Atari calls it a poly counter). Unfortunately,
+; a read from this address will never return 0, since LFSR's can't do
+; that. If Atari had made the RANDOM register read the higher order bits
+; of the LFSR, rather than the bottom 8, this wouldn't be a problem... but
+; they didn't, so there's extra code in here to (try to) compensate.
+
+; Might use this at some point:
+;_randbit:
+; lda RANDOM
+; asl
+; lda #0
+; adc #0
+; rts
+
+; unsigned char __fastcall__ randbit(void);
+;_randbit:
+; ldx #0
+;randbit:
+; lda RANDOM
+; lsr
+; and #$01
+; rts
+
+; This doesn't give evenly distributed results, it's twice as
+; likely to return 2 or 3 than 0, 1, or 4.
+; unsigned char __fastcall__ rand1in5(void);
+;_rand1in5:
+; ldx #0
+;rand1in5:
+; lda RANDOM
+; lsr
+; lsr
+; and #$03
+; adc #0
+; rts
+
; unsigned char __fastcall__ randb(void);
_randb: ; C-callable entry point
@@ -42,6 +77,7 @@ _randi:
rts
; unsigned long __fastcall__ randl(void);
+; this returns the full range of an unsigned long, 0 to 2**32-1
_randl:
jsr randb
sta sreg