2020-03-12 16:44:11 +00:00
|
|
|
|
NEW
|
|
|
|
|
AUTO 3,1
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.AND lda #$32 AND (zp)
|
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
M32.OR lda #$12 ORA (zp)
|
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
M32.XOR lda #$52 EOR (zp)
|
|
|
|
|
.HS 2C BIT ABS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.ADD lda #$72 ADC (zp)
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.SUB lda #$F2 SBC (zp)
|
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
sta .2
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
asl CS if SBC, CC if ADC others = don't care
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
|
|
|
|
ldy #4
|
|
|
|
|
ldx #4
|
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.1 lda (pStack),y
|
|
|
|
|
.2 adc (pStack) SELF MODIFIED
|
2020-03-12 16:44:11 +00:00
|
|
|
|
sta (pStack),y
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
|
|
|
|
inc pStack
|
2020-03-12 16:44:11 +00:00
|
|
|
|
dex
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
M32.SHL sec
|
|
|
|
|
.HS 90 BCC
|
|
|
|
|
M32.SHR clc
|
|
|
|
|
|
|
|
|
|
lda (pStack)
|
|
|
|
|
inc pStack
|
|
|
|
|
inc pStack
|
|
|
|
|
inc pStack
|
|
|
|
|
inc pStack
|
|
|
|
|
|
|
|
|
|
tax
|
|
|
|
|
beq .8
|
|
|
|
|
bcc .3
|
|
|
|
|
|
|
|
|
|
.1 ldy #0
|
|
|
|
|
|
|
|
|
|
clc
|
|
|
|
|
|
|
|
|
|
.2 lda (pStack),y
|
|
|
|
|
rol
|
|
|
|
|
sta (pStack),y
|
|
|
|
|
|
|
|
|
|
iny
|
|
|
|
|
tya
|
|
|
|
|
eor #4
|
2021-04-29 11:56:34 +00:00
|
|
|
|
bne .2
|
2021-05-04 17:31:21 +00:00
|
|
|
|
|
|
|
|
|
dex
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
.8 rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.3 ldy #3
|
|
|
|
|
|
|
|
|
|
clc
|
|
|
|
|
|
|
|
|
|
.4 lda (pStack),y
|
|
|
|
|
ror
|
|
|
|
|
sta (pStack),y
|
|
|
|
|
|
|
|
|
|
dey
|
|
|
|
|
bpl .4
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
dex
|
|
|
|
|
bne .3
|
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
rts
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.L ldx #0
|
2021-05-09 12:39:40 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.LE ldx #1
|
2021-05-09 12:39:40 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.G ldx #2
|
2021-05-09 12:39:40 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.GE ldx #3
|
2021-05-09 12:39:40 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.E ldx #4
|
2021-05-09 12:39:40 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.NE ldx #5
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-05-09 12:39:40 +00:00
|
|
|
|
M32.CMP lda MATH.CMPT,x
|
|
|
|
|
sta .3+1
|
|
|
|
|
|
|
|
|
|
jsr M32.SUB
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
|
|
|
|
tay A = BYTE 3
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bmi .1
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
ldy #2
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.10 ora (pStack),y
|
|
|
|
|
dey
|
|
|
|
|
bpl .10
|
|
|
|
|
|
|
|
|
|
tay
|
|
|
|
|
beq .2
|
|
|
|
|
|
|
|
|
|
lda #%001
|
2021-04-29 11:56:34 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.1 lda #%100
|
|
|
|
|
.HS 2C BIT ABS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.2 lda #%010
|
|
|
|
|
|
2021-05-09 12:39:40 +00:00
|
|
|
|
.3 and #$ff SELF MODIFIED
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bra M32.LOR2
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
M32.LAND jsr M32.AND
|
|
|
|
|
bra M32.LOR1
|
|
|
|
|
|
|
|
|
|
M32.LOR jsr M32.OR
|
|
|
|
|
|
|
|
|
|
M32.LOR1 lda (pStack)
|
|
|
|
|
|
|
|
|
|
ldy #3
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.1 ora (pStack),y
|
|
|
|
|
dey
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
tay
|
|
|
|
|
|
|
|
|
|
M32.LOR2 beq .1
|
|
|
|
|
|
|
|
|
|
lda #1
|
|
|
|
|
|
|
|
|
|
.1 sta (pStack)
|
|
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
|
|
|
|
|
|
ldy #3
|
|
|
|
|
|
|
|
|
|
.2 sta (pStack),y
|
|
|
|
|
dey
|
|
|
|
|
bne .2
|
|
|
|
|
|
|
|
|
|
rts
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.UMUL clc
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.HS B0 BCS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.IMUL sec
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
php
|
2021-04-29 11:56:34 +00:00
|
|
|
|
jsr M32.MULDIVMOD
|
|
|
|
|
jsr M32.MUL
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
plp
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bcc M32.PutTMP
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
|
|
|
|
M32.ITMP lda ACC32.Sign
|
2020-03-12 16:44:11 +00:00
|
|
|
|
eor ARG32.Sign
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bpl M32.PutTMP
|
2021-04-29 11:56:34 +00:00
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
* M32.PutnTMP
|
2021-04-29 11:56:34 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
lda #TMP32
|
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.PutnARG lda #ARG32
|
2021-04-29 11:56:34 +00:00
|
|
|
|
sta .1+1
|
|
|
|
|
ldy #0
|
|
|
|
|
ldx #3
|
|
|
|
|
sec
|
|
|
|
|
|
|
|
|
|
.1 lda $ff,y SELF MODIFIED
|
|
|
|
|
eor #$ff two's complement of X bytes
|
|
|
|
|
adc #0
|
|
|
|
|
sta (pStack),y
|
|
|
|
|
iny
|
|
|
|
|
dex
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
rts
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.UDIV clc
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.HS B0 BCS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.IDIV sec
|
2020-03-12 16:44:11 +00:00
|
|
|
|
clv
|
2021-04-29 11:56:34 +00:00
|
|
|
|
bra M32.MOD
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.UMOD clc
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.HS B0 BCS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.IMOD sec
|
|
|
|
|
bit M32.RTS $60
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.MOD php
|
|
|
|
|
jsr M32.MULDIVMOD
|
|
|
|
|
jsr M32.DIVMOD
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
plp
|
|
|
|
|
bcc .3 unsigned
|
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
bvs M32.ITMP return ITMP
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
lda ACC32.Sign IDIV
|
|
|
|
|
eor ARG32.Sign
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bpl M32.PutARG
|
|
|
|
|
bra M32.PutnARG
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.3 bvc M32.PutARG DIV
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.PutTMP lda #TMP32 MOD
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.PutARG lda #ARG32
|
2020-03-12 16:44:11 +00:00
|
|
|
|
sta .1+1
|
|
|
|
|
|
|
|
|
|
ldy #3
|
|
|
|
|
|
|
|
|
|
.1 lda $ff,y SELF MODIFIED
|
|
|
|
|
sta (pStack),y
|
|
|
|
|
dey
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.PopACC ldy #0
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
.1 lda (pStack)
|
|
|
|
|
inc pStack
|
|
|
|
|
sta ACC32,y
|
|
|
|
|
iny
|
|
|
|
|
cpy #4
|
|
|
|
|
bne .1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
sta ACC32.Sign
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.GetARG ldy #0
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
.1 lda (pStack),y
|
|
|
|
|
sta ARG32,y
|
|
|
|
|
iny
|
|
|
|
|
cpy #4
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
sta ARG32.Sign
|
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.RTS rts
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.MULDIVMOD php
|
2021-05-04 17:31:21 +00:00
|
|
|
|
jsr M32.PopACC
|
|
|
|
|
jsr M32.GetARG
|
2020-03-12 16:44:11 +00:00
|
|
|
|
plp
|
2021-04-29 11:56:34 +00:00
|
|
|
|
bcc M32.RTS
|
|
|
|
|
jsr .1
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* M32.ARG32ABS
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
lda ARG32.Sign
|
2021-05-04 17:31:21 +00:00
|
|
|
|
bmi M32.nARG
|
2021-04-29 11:56:34 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* M32.ACC32ABS
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.1 lda ACC32.Sign
|
|
|
|
|
bpl M32.RTS
|
|
|
|
|
*--------------------------------------
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.nACC ldy #ACC32
|
2021-04-29 11:56:34 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-05-04 17:31:21 +00:00
|
|
|
|
M32.nARG ldy #ARG32
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
|
|
|
|
ldx #3
|
|
|
|
|
sec
|
|
|
|
|
|
|
|
|
|
.1 lda $0,y two's complement of X bytes
|
|
|
|
|
eor #$ff
|
|
|
|
|
adc #0
|
|
|
|
|
sta $0,y
|
|
|
|
|
iny
|
|
|
|
|
dex
|
|
|
|
|
bpl .1
|
|
|
|
|
|
|
|
|
|
rts
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* http://6502.org/source/integers/32muldiv.htm
|
|
|
|
|
* http://nparker.llx.com/a2/mult.html
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* ARG32*ACC32->TMP32
|
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.MUL jsr M32.TMP32Z
|
2020-03-12 16:44:11 +00:00
|
|
|
|
ldx #32
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.1 lsr ARG32+3
|
|
|
|
|
ror ARG32+2
|
|
|
|
|
ror ARG32+1
|
|
|
|
|
ror ARG32
|
|
|
|
|
bcc .3
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
clc
|
|
|
|
|
|
|
|
|
|
ldy #0
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.2 lda TMP32,y
|
|
|
|
|
adc ACC32,y
|
|
|
|
|
sta TMP32,y
|
|
|
|
|
|
|
|
|
|
iny
|
|
|
|
|
tya
|
|
|
|
|
eor #4
|
|
|
|
|
bne .2
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2021-05-04 17:31:21 +00:00
|
|
|
|
.3 jsr MATH.ACC32x2
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
dex
|
|
|
|
|
bne .1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* ARG32 = ARG32 div ACC32
|
|
|
|
|
* TMP32 = ARG32 mod ACC32
|
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.DIVMOD jsr M32.TMP32Z
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
ldx #32
|
|
|
|
|
|
|
|
|
|
.1 asl ARG32
|
|
|
|
|
rol ARG32+1
|
|
|
|
|
rol ARG32+2
|
|
|
|
|
rol ARG32+3
|
2021-05-04 17:31:21 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
rol TMP32
|
|
|
|
|
rol TMP32+1
|
|
|
|
|
rol TMP32+2
|
|
|
|
|
rol TMP32+3
|
2021-05-04 17:31:21 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
sec
|
2021-05-04 17:31:21 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
lda TMP32
|
|
|
|
|
sbc ACC32
|
|
|
|
|
pha
|
|
|
|
|
lda TMP32+1
|
|
|
|
|
sbc ACC32+1
|
|
|
|
|
pha
|
|
|
|
|
lda TMP32+2
|
|
|
|
|
sbc ACC32+2
|
|
|
|
|
pha
|
|
|
|
|
lda TMP32+3
|
|
|
|
|
sbc ACC32+3
|
|
|
|
|
bcs .2
|
|
|
|
|
|
|
|
|
|
pla
|
|
|
|
|
pla
|
|
|
|
|
pla
|
|
|
|
|
dex
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
.2 sta TMP32+3
|
|
|
|
|
pla
|
|
|
|
|
sta TMP32+2
|
|
|
|
|
pla
|
|
|
|
|
sta TMP32+1
|
|
|
|
|
pla
|
|
|
|
|
sta TMP32
|
|
|
|
|
inc ARG32 bit0 always 0 because of .1 asl
|
|
|
|
|
|
|
|
|
|
dex
|
|
|
|
|
bne .1
|
|
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2020-11-23 22:05:27 +00:00
|
|
|
|
*uint32_t lcg_parkmiller(uint32_t *state)
|
|
|
|
|
*{
|
|
|
|
|
* // Precomputed parameters for Schrage's method
|
|
|
|
|
* const uint32_t M = 0x7fffffff;
|
|
|
|
|
* const uint32_t A = 48271;
|
|
|
|
|
* const uint32_t Q = M / A; // 44488
|
|
|
|
|
* const uint32_t R = M % A; // 3399
|
|
|
|
|
*
|
|
|
|
|
* uint32_t div = *state / Q; // max: M / Q = A = 48,271
|
|
|
|
|
* uint32_t rem = *state % Q; // max: Q - 1 = 44,487
|
|
|
|
|
*
|
|
|
|
|
* int32_t s = rem * A; // max: 44,487 * 48,271 = 2,147,431,977 = 0x7fff3629
|
|
|
|
|
* int32_t t = div * R; // max: 48,271 * 3,399 = 164,073,129
|
|
|
|
|
* int32_t result = s - t;
|
|
|
|
|
*
|
|
|
|
|
* if (result < 0)
|
|
|
|
|
* result += M;
|
|
|
|
|
*
|
|
|
|
|
* return *state = result;
|
|
|
|
|
*}
|
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
* M32.RND TODO
|
2020-03-16 06:50:15 +00:00
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.A2ACC32 sta ACC32
|
2020-03-16 06:50:15 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.ACC32Z stz ACC32
|
2020-03-16 06:50:15 +00:00
|
|
|
|
stz ACC32+1
|
|
|
|
|
stz ACC32+2
|
|
|
|
|
stz ACC32+3
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.TMP32Z stz TMP32
|
2020-03-16 06:50:15 +00:00
|
|
|
|
stz TMP32+1
|
|
|
|
|
stz TMP32+2
|
|
|
|
|
stz TMP32+3
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
2020-03-12 16:44:11 +00:00
|
|
|
|
MAN
|
2020-12-15 13:23:22 +00:00
|
|
|
|
SAVE usr/src/sys/kernel.s.math32
|
|
|
|
|
LOAD usr/src/sys/kernel.s
|
2020-03-12 16:44:11 +00:00
|
|
|
|
ASM
|