mirror of
https://github.com/nathanriggs/AppleIIAsm-Collection.git
synced 2024-12-02 12:52:03 +00:00
16c1731e54
- bugfixes - implemented required library - commenting updates - .min of every routine
199 lines
3.4 KiB
Plaintext
199 lines
3.4 KiB
Plaintext
JMP XMATH8
|
|
*
|
|
** RAND8
|
|
*
|
|
LDX #8
|
|
LDA RNDL+0
|
|
:A
|
|
ASL
|
|
ROL RNDL+1
|
|
BCC :B
|
|
EOR #$2D
|
|
:B
|
|
DEX
|
|
BNE :A
|
|
STA RNDL+0
|
|
STA RETURN
|
|
LDY #1
|
|
STY RETLEN
|
|
CMP #0
|
|
RTS
|
|
*
|
|
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
|
|
*
|
|
MULT8
|
|
*
|
|
PLA
|
|
STA RETADR
|
|
PLA
|
|
STA RETADR+1
|
|
PLA
|
|
STA :MUL1
|
|
PLA
|
|
STA :MUL2
|
|
LDA #$00
|
|
TAY
|
|
TAX
|
|
STY :MUL1H
|
|
BEQ :GOLOOP
|
|
:DOADD
|
|
CLC
|
|
ADC :MUL1
|
|
TAY
|
|
TXA
|
|
ADC :MUL1H
|
|
TAX
|
|
TYA
|
|
:LP
|
|
ASL :MUL1
|
|
ROL :MUL1H
|
|
:GOLOOP
|
|
LSR :MUL2
|
|
BCS :DOADD
|
|
BNE :LP
|
|
LDA RETADR+1
|
|
PHA
|
|
LDA RETADR
|
|
PHA
|
|
STY RETURN
|
|
STX RETURN+1
|
|
LDA #2
|
|
STA RETLEN
|
|
RTS
|
|
:MUL1 DS 1
|
|
:MUL2 DS 1
|
|
:MUL1H DS 1
|
|
*
|
|
DIVD8
|
|
*
|
|
PLA
|
|
STA RETADR
|
|
PLA
|
|
STA RETADR+1
|
|
PLA
|
|
STA :DVEND
|
|
PLA
|
|
STA :DVSOR
|
|
LDA #$00
|
|
LDY #8
|
|
ASL :DVSOR
|
|
:L1 ROL
|
|
CMP :DVEND
|
|
BCC :L2
|
|
SBC :DVEND
|
|
:L2 ROL :DVSOR
|
|
DEY
|
|
BNE :L1
|
|
STA :REM
|
|
LDA RETADR+1
|
|
PHA
|
|
LDA RETADR
|
|
PHA
|
|
LDY :REM
|
|
LDA #1
|
|
STA RETLEN
|
|
LDA :DVSOR
|
|
STA RETURN
|
|
RTS
|
|
:REM DS 1
|
|
:DVEND DS 1
|
|
:DVSOR DS 1
|
|
*
|
|
XMATH8
|