AppleIIAsm-Collection/disks/disk3_math8_math16/T.MATH16.RND16
nathanriggs 875dd80998 stdio 0.2.0 updates
- fixed a bunch of bugs
- separated common and stdio libraries
- commenting upgrades
- created min versions of each library
2018-12-14 21:23:32 -05:00

85 lines
2.0 KiB
Plaintext

*
*``````````````````````````````*
* RND16 : 16BIT RANDOM NUMBER *
*- -*
* GENERATE A 16BIT PSEUDO- *
* RANDOM NUMBER AND RETURN IT *
* IN Y,X (LOW, HIGH). *
* *
* ORIGINAL AUTHOR IS WHITE *
* FLAME, AS SHARED ON *
* CODEBASE64. I HAVE MADE SOME *
* MINOR ALTERATIONS, BUT NOT *
* NEARLY ENOUGH TO CALL IT MY *
* OWN. *
*- -*
* CLOBBERS: *
* *
* FLAGS: ????---- REG: AXYM *
*- -*
* CYCLES: ??? *
* SIZE: *
*- -*
* USAGE: *
* *
*- -*
* ENTRY *
* *
* LOW BYTE OF RETURN ADDRESS *
* HIGH BYTE OF RETURN ADDRESS *
*- -*
* EXIT *
* *
* Y = HIGH BYTE OF PRODUCT *
* X = LOW BYTE OF PRODUCT *
* A = LOW BYTE OF PRODUCT *
*- -*
* NOTE: THERE ARE 2048 MAGIC *
* NUMBERS THAT COULD BE EOR'D *
* TO GENERATE A PSEUDO-RANDOM *
* PATTERN THAT DOESN'T REPEAT *
* UNTIL 65535 ITERATIONS. TOO *
* MANY TO LIST HERE, BUT SOME *
* ARE: $002D, $1979, $1B47, *
* $41BB, $3D91, $B5E9, $FFEB *
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,*
*
RND16
*
LDA RNDL
STA :SEED
LDA RNDH
STA :SEED+1
*
LDA :SEED
BEQ :LOW0
*
** DO A NORMAL SHIFT
*
ASL :SEED
LDA :SEED+1
ROL
BCC :NOEOR
:DOEOR ; HIGH BYTE IN A
EOR #>$0369
STA :SEED+1
LDA :SEED
EOR #<$0369
STA :SEED
JMP :EXIT
:LOW0
LDA :SEED+1
BEQ :DOEOR
ASL
BEQ :NOEOR
BCS :DOEOR
:NOEOR
STA :SEED+1
:EXIT LDX :SEED+1
LDY :SEED
RTS
*
** DATA
*
:SEED DS 2