From 6ed92fecc6eebcde1f8e855f76fa6a0d6afa749c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 20 Jan 2016 06:02:46 -0500 Subject: fix and simplify cprintfancy, allow Delete key and K/M for 1000/1M when entering numbers --- rand.s | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'rand.s') 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 -- cgit v1.2.3