2020-03-12 16:44:11 +00:00
|
|
|
|
NEW
|
|
|
|
|
AUTO 3,1
|
|
|
|
|
*--------------------------------------
|
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)
|
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
sta .3
|
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
asl CS if SBC, CC if ADC
|
|
|
|
|
|
|
|
|
|
ldy #4
|
|
|
|
|
ldx #4
|
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.2 lda (pStack),y
|
2021-04-29 11:56:34 +00:00
|
|
|
|
.3 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-04-29 11:56:34 +00:00
|
|
|
|
bne .2
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
rts
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
|
|
|
|
* Returns:
|
|
|
|
|
* ff X < Y
|
|
|
|
|
* 0 X = Y
|
|
|
|
|
* 1 X > Y
|
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
*M32.UCMP
|
|
|
|
|
*M32.ICMP
|
|
|
|
|
M32.CMP jsr M32.SUB
|
|
|
|
|
|
|
|
|
|
tay A = BYTE 3
|
2020-03-12 16:44:11 +00:00
|
|
|
|
bmi .2
|
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
.1 ora (pStack) BYTE 0
|
|
|
|
|
ldy #1
|
|
|
|
|
ora (pStack),y BYTE 1
|
|
|
|
|
iny
|
|
|
|
|
ora (pStack),y BYTE 2
|
2020-03-12 16:44:11 +00:00
|
|
|
|
beq .8
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
2020-03-12 16:44:11 +00:00
|
|
|
|
lda #1
|
2021-04-29 11:56:34 +00:00
|
|
|
|
.HS 2C BIT ABS
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
|
|
|
|
.2 lda #$ff
|
2021-04-29 11:56:34 +00:00
|
|
|
|
|
|
|
|
|
.8 inc pStack
|
|
|
|
|
inc pStack
|
|
|
|
|
inc pStack
|
|
|
|
|
inc pStack
|
|
|
|
|
|
|
|
|
|
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-04-29 11:56:34 +00:00
|
|
|
|
bcc M32.PutTMP32
|
|
|
|
|
|
|
|
|
|
M32.ITMP lda ACC32.Sign
|
2020-03-12 16:44:11 +00:00
|
|
|
|
eor ARG32.Sign
|
2021-04-29 11:56:34 +00:00
|
|
|
|
bpl M32.PutTMP32
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* M32.PutnTMP32
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
lda #TMP32
|
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
M32.PutnARG32 lda #ARG32
|
|
|
|
|
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-04-29 11:56:34 +00:00
|
|
|
|
bpl M32.PutARG32
|
|
|
|
|
bra M32.PutnARG32
|
2020-03-12 16:44:11 +00:00
|
|
|
|
|
2021-04-29 11:56:34 +00:00
|
|
|
|
.3 bvc M32.PutARG32 DIV
|
2020-03-12 16:44:11 +00:00
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.PutTMP32 lda #TMP32 MOD
|
2020-03-12 16:44:11 +00:00
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
*--------------------------------------
|
2021-04-29 11:56:34 +00:00
|
|
|
|
M32.PutARG32 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-04-29 11:56:34 +00:00
|
|
|
|
M32.PopACC32 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-04-29 11:56:34 +00:00
|
|
|
|
M32.GetARG32 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
|
|
|
|
|
jsr M32.PopACC32
|
|
|
|
|
jsr M32.GetARG32
|
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
|
|
|
|
|
bmi M32.nARG32
|
|
|
|
|
rts
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
* M32.ACC32ABS
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
.1 lda ACC32.Sign
|
|
|
|
|
bpl M32.RTS
|
|
|
|
|
*--------------------------------------
|
|
|
|
|
M32.nACC32 ldy #ACC32
|
|
|
|
|
.HS 2C BIT ABS
|
|
|
|
|
M32.nARG32 ldy #ARG32
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
.3 asl ACC32
|
|
|
|
|
rol ACC32+1
|
|
|
|
|
rol ACC32+2
|
|
|
|
|
rol ACC32+3
|
|
|
|
|
|
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
|
|
|
|
clc
|
|
|
|
|
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
|
|
|
|
|
rol TMP32
|
|
|
|
|
rol TMP32+1
|
|
|
|
|
rol TMP32+2
|
|
|
|
|
rol TMP32+3
|
|
|
|
|
sec
|
|
|
|
|
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
|