AppleIIAsm-Collection/disks/disk3_math/T.RANDB.MIN
nathanriggs 16c1731e54 Strings 0.2.0 update
- bugfixes
- implemented required library
- commenting updates
- .min of every routine
2018-12-22 20:35:05 -05:00

98 lines
1.8 KiB
Plaintext

RANDB
*
PLA
STA RETADR
PLA
STA RETADR+1
PLA
STA :NEWMAX
PLA
STA :NEWMIN
LDA #1
STA :OLDMIN
LDA #255
STA :OLDMAX
JSR RAND8
STA :OLDVAL
LDA :OLDMAX
SEC
SBC :OLDMIN
STA :OLDRANGE
LDA :NEWMAX
SEC
SBC :NEWMIN
STA :NEWRANGE
LDA :OLDVAL
SEC
SBC :OLDMIN
STA :VALRANGE
LDA #00
TAY
STY :NUM1HI
BEQ :ENTLP
:DOADD
CLC
ADC :VALRANGE
TAX
TYA
ADC :NUM1HI
TAY
TXA
:MLP
ASL :VALRANGE
ROL :NUM1HI
:ENTLP
LSR :NEWRANGE
BCS :DOADD
BNE :MLP
STA :MULRANGE
STY :MULRANGE+1
:DIVIDE
LDA #0
STA :REMAIN
STA :REMAIN+1
LDX #16
:DIVLP
ASL :MULRANGE
ROL :MULRANGE+1
ROL :REMAIN
ROL :REMAIN+1
LDA :REMAIN
SEC
SBC :OLDRANGE
TAY
LDA :REMAIN+1
SBC :OLDRANGE+1
BCC :SKIP
STA :REMAIN+1
STY :REMAIN
INC :DIVRANGE
:SKIP DEX
BNE :DIVLP
LDA :DIVRANGE ; LO BYTE ONLY
CLC
ADC :NEWMIN
STA :NEWVAL
LDA RETADR+1
PHA
LDA RETADR
PHA
LDA :NEWVAL ; RETURN # IN A
STA RETURN
LDX #1
STX RETLEN
RTS
:OLDRANGE DS 2
:NEWRANGE DS 2
:MULRANGE DS 2
:DIVRANGE DS 2
:VALRANGE DS 2
:OLDVAL DS 2
:NEWVAL DS 2
:OLDMIN DS 2
:NEWMIN DS 2
:OLDMAX DS 2
:NEWMAX DS 2
:NUM1HI DS 2
:REMAIN DS 2