diff --git a/src/libsrc/int32.pla b/src/libsrc/int32.pla new file mode 100644 index 0000000..1eee3e7 --- /dev/null +++ b/src/libsrc/int32.pla @@ -0,0 +1,231 @@ +// +// 32 bit integer math routines +// +include "inc/cmdsys.plh" +// +// Include zero page definitions +// +asm int32Inc + !SOURCE "vmsrc/plvmzp.inc" +ACCUM32 = DSTH+1 +end +export asm accum32zero#0 + LDA #$00 + STA ACCUM32+0 + STA ACCUM32+1 + STA ACCUM32+2 + STA ACCUM32+3 + RTS +end +export asm accum32neg#0 + LDA #$00 + SEC + SBC ACCUM32+0 + STA ACCUM32+0 + LDA #$00 + SBC ACCUM32+1 + STA ACCUM32+1 + LDA #$00 + SBC ACCUM32+2 + STA ACCUM32+2 + LDA #$00 + SBC ACCUM32+3 + STA ACCUM32+3 + RTS +end +export asm accum32loadi(imm16)#0 + LDY #$00 + LDA ESTKL+0,X + STA ACCUM32+0 + LDA ESTKH+0,X + BPL + ; SIGN EXTEND + DEY ++ STA ACCUM32+1 + STY ACCUM32+2 + STY ACCUM32+3 + INX + RTS +end +export asm accum32load(i32ptr)#0 + LDA ESTKL+0,X ; i32PTR + STA SRCL + LDA ESTKH+0,X ; I32PTR + STA SRCL + LDY #$00 + LDA (SRC),Y + STA ACCUM32+0 + INY + LDA (SRC),Y + STA ACCUM32+1 + INY + LDA (SRC),Y + STA ACCUM32+2 + INY + LDA (SRC),Y + STA ACCUM32+3 + INX + RTS +end +export asm accum32store(i32ptr)#0 + LDA ESTKL+0,X ; i32PTR + STA DSTL + LDA ESTKH+0,X ; I32PTR + STA DSTL + LDY #$00 + LDA ACCUM32+0 + STA (DST),Y + INY + LDA ACCUM32+1 + STA (DST),Y + INY + LDA ACCUM32+2 + STA (DST),Y + INY + LDA ACCUM32+3 + STA (DST),Y + RTS +end +export asm accum32addi(imm16)#0 + LDY #$00 + LDA ESTKL+0,X ; IMM16 + CLC + ADC ACCUM32+0 + STA ACCUM32+0 + LDA ESTKH+0,X ; IMM16 + BPL + + DEY ++ ADC ACCUM32+1 + STA ACCUM32+1 + TYA + ADC ACCUM32+2 + STA ACCUM32+2 + TYA + ADC ACCUM32+3 + STA ACCUM32+3 + INX + RTS +end +export asm accum32add(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA SRCL + LDA ESTKH+0,X ; I32PTR + STA SRCL + LDY #$00 + LDA (SRC),Y + CLC + ADC ACCUM32+0 + STA ACCUM32+0 + INY + ADC ACCUM32+1 + STA ACCUM32+1 + INY + ADC ACCUM32+2 + STA ACCUM32+2 + INY + ADC ACCUM32+3 + STA ACCUM32+3 + INX + RTS +end +export asm accum32subi(imm16)#0 + LDY #$00 + LDA ESTKL+0,X ; IMM16 + SEC + SBC ACCUM32+0 + STA ACCUM32+0 + LDA ESTKH+0,X ; IMM16 + BPL + + DEY ++ SBC ACCUM32+1 + STA ACCUM32+1 + TYA + SBC ACCUM32+2 + STA ACCUM32+2 + TYA + SBC ACCUM32+3 + STA ACCUM32+3 + INX + RTS +end +export asm accum32sub(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA SRCL + LDA ESTKH+0,X ; I32PTR + STA SRCL + LDY #$00 + LDA (SRC),Y + SEC + SBC ACCUM32+0 + STA ACCUM32+0 + INY + SBC ACCUM32+1 + STA ACCUM32+1 + INY + SBC ACCUM32+2 + STA ACCUM32+2 + INY + SBC ACCUM32+3 + STA ACCUM32+3 + INX + RTS +end +export asm accum32mul(i32ptr)#0 + LDA ESTKL+1,X ; I32PTR + STA SRCL + LDA ESTKH+1,X ; I32PTR + STA SRCH + STX ESP + LDX #$00 + LDY #$03 + STY IPY + LDA #$80 +_MULLP PHA + LDY IPY + AND (TMP),Y + BEQ + + LDY #$00 + CLC + LDA (SRC),Y + ADC (DST),Y + STA (DST),Y + INY + LDA (SRC),Y + ADC (DST),Y + STA (DST),Y + INY + LDA (SRC),Y + ADC (DST),Y + STA (DST),Y + INY + LDA (SRC),Y + ADC (DST),Y + STA (DST),Y ++ DEX + BEQ ++ + LDY #$00 + ASL (DST),Y + INY + ROL (DST),Y + INY + ROL (DST),Y + INY + ROL (DST),Y + PLA + LSR + BNE _MULLP + LDA #$80 + DEC IPY + +_SHLPRD LDY + ASL ESTKL,X ; MULTPLNDL + ROL ESTKH,X ; MULTPLNDH + DEX + BNE _MULLP + STA ESTKH+1,X ; PRODH + + LDX ESP + INX + INX + INX + RTS +end