mirror of
https://github.com/nathanriggs/AppleIIAsm-Collection.git
synced 2024-12-10 17:52:35 +00:00
56 lines
1.5 KiB
Plaintext
56 lines
1.5 KiB
Plaintext
|
*
|
||
|
*``````````````````````````````*
|
||
|
* RAND8 :: 8-BIT RANDOM NUMBER *
|
||
|
*- -*
|
||
|
* GENERATES A PSEUDO-RANDOM *
|
||
|
* NUMBER BETWEEN 1..255 (BYTE) *
|
||
|
* AND RETURNS THE VALUE IN .A *
|
||
|
* *
|
||
|
* THIS USES THE GALOIS LINEAR *
|
||
|
* FEEDBACK SHIFT REGISTER *
|
||
|
* ALGORITHM WITH POLYNOMIAL *
|
||
|
* $002D. THE SEQUENCE WILL *
|
||
|
* REPEAT AFTER 65535 CALLS. *
|
||
|
*- -*
|
||
|
* CLOBBERS: *
|
||
|
* *
|
||
|
* FLAGS: ????---- REG: AX-- *
|
||
|
*- -*
|
||
|
* CYCLES: ??? *
|
||
|
* SIZE: *
|
||
|
*- -*
|
||
|
* USAGE: JSR RND8 *
|
||
|
*- -*
|
||
|
* EXIT *
|
||
|
* *
|
||
|
* .Y = NOT AFFECTED *
|
||
|
* .X = CLOBBERED *
|
||
|
* .A = RANDOM NUM 1..255 *
|
||
|
*- -*
|
||
|
* NOTE: BASED ON THE PRNG *
|
||
|
* LISTING FOUND IN THE NESDEV *
|
||
|
* WIKI. *
|
||
|
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
|
||
|
*
|
||
|
RAND8
|
||
|
*
|
||
|
LDX #8
|
||
|
LDA RNDL+0
|
||
|
:A
|
||
|
ASL ;SHIFT THE REG
|
||
|
ROL RNDL+1
|
||
|
BCC :B
|
||
|
EOR #$2D ; APPLY XOR FEEDBACK
|
||
|
; WHENEVER A 1 BIT IS
|
||
|
; SHIFTED OUT
|
||
|
:B
|
||
|
DEX
|
||
|
BNE :A
|
||
|
STA RNDL+0
|
||
|
STA RETURN
|
||
|
LDY #1
|
||
|
STY RETLEN
|
||
|
CMP #0 ; RELOAD FLAGS
|
||
|
RTS
|
||
|
*
|