diff options
author | B. Watson <yalhcru@gmail.com> | 2016-01-08 02:10:00 -0500 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2016-01-08 02:10:00 -0500 |
commit | 0de843a9d404d1022ac40ba1e25da0194f367027 (patch) | |
tree | 9602d312e26497d16793ea9f9aa08a17de9e9e83 /rand.s | |
parent | d3fa8aeeb26ece734b54395b743b2d4a341f5613 (diff) | |
download | taipan-0de843a9d404d1022ac40ba1e25da0194f367027.tar.gz |
fix POKEY random wrappers, I hope
Diffstat (limited to 'rand.s')
-rw-r--r-- | rand.s | 50 |
1 files changed, 39 insertions, 11 deletions
@@ -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 |