k, i think this is the source for the simp( function, if i missed a include file or something, tell me and ill post it. arg, i am gonna need help translating it to basic.
i need it converted to TI-BASIC, but im not trying to put it on the calc
Code: simplify:
simp2:
;*
call memAssert
;*
push hl
pop ix
ld a,(ix)
or a
jp z,simNum
cp 1
jp z,simNum2
cp 080h
jp z,simNum3
ld l,(ix+1)
ld h,(ix+2)
inc ix
push ix
call simp2
pop ix
ld b,0
ld l,(ix+2)
ld h,(ix+3) ;hl = the node that is not 1 or 0
ld e,(ix)
ld d,(ix+1) ;de = the node that is 1 or 0
or a
push ix
call z,simpZero
cp 1
call z,simpOne
pop ix
cp 254
ret z
ld l,(ix+2)
ld h,(ix+3)
ld a,(ix-1)
cp tsqrt ;radical
jp z,reduceRad
cp tln
jp z,reduceLn
cp tlog
jp z,reduceLog
; cp 0b0h
; jp z,simNum2
cp 0b0h
jp z,operNeg
call isOpenParen
; or a
jp z,simNum2 ;has only one child, and we want to make sure the prog knows this is not a number (a=0)
inc ix
inc ix
push ix
call simp2
pop ix
ld b,1
ld l,(ix-2)
ld h,(ix-1) ;hl = the node that is not 1 or 0
ld e,(ix)
ld d,(ix+1) ;de = the node that is 1 or 0
or a
push ix ;necessary for the routines that read from the stack
call z,simpZero
cp 1
call z,simpOne
pop ix
cp 254
ret z
ld a,(ix-3)
cp tdiv
jp z,operDiv
cp tmul
jp z,operMult
cp tadd
jp z,operAdd
cp tsub
jp z,operSub
cp tpower
jp z,operExp
jp simNum2
operExp1Sqrt:
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ld (ix-2),e
ld (ix-1),d
call makeTwo
ld hl,(freeRam)
ld c,(ix)
ld b,(ix+1)
ld (ix),l
ld (ix+1),h
ld (hl),tdiv
inc hl
ld (hl),c
inc hl
ld (hl),b
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (freeRam),hl
jp setMod
operExp:
ld l,(ix-2)
ld h,(ix-1)
ld a,(hl)
or a
jp z,operExp1Num
cp tpower
jp z,operExp1Exp
cp tmul
jp z,operExp1Mult
cp tsqrt
jr z,operExp1Sqrt
cp tdiv
jr nz,operExp2
push hl
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(de)
or a
jr z,operExp1Div
cp tsqrt
jr z,operExp1Div2
ld e,(hl)
inc hl
ld d,(hl)
ld a,(de)
or a
jr z,operExp1Div
cp tsqrt
jr z,operExp1Div2
operExp20:
pop hl
operExp2:
ex de,hl
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
cp 0B0h
jr z,operExp2Neg;is power negative?
jp simNum2
operExp2Neg:
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ld (ix),e
ld (ix+1),d
ld e,(ix-2)
ld d,(ix-1)
push de
call makeOne
ld hl,(freeRam)
ld (ix-2),l
ld (ix-1),h
ld (hl),tdiv
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
pop de
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (freeRam),hl
jp setmod
; inc hl
; ld e,(hl)
; inc hl
; ld d,(hl)
; ld (ix),e
; ld (ix+1),d ;get rid of negative
; call makeOne
; ld hl,(freeRam)
; push hl
; ld (hl),tdiv
; inc hl
; ld (hl),e
; inc hl
; ld (hl),d
; inc hl
; push ix
; pop de
; dec de
; dec de
; dec de
; ld (hl),e
; inc hl
; ld (hl),d
; inc hl
; ld (freeRam),hl
; pop de
; pop bc
; pop hl
; push hl
; push bc
; ld (hl),e
; inc hl
; ld (hl),d
; jp setMod
operExp1Div:
ld e,(ix)
ld d,(ix+1)
ld a,(de)
or a
jr nz,operExp20
operExp1Div2:
ld e,(ix)
ld d,(ix+1)
ld (ix-3),tdiv
pop hl
ld (hl),tpower
inc hl
inc hl
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
push bc
push ix
call copySub
pop ix
pop bc
ld hl,(freeRam)
ld (ix),l
ld (ix+1),h
ld (hl),tpower
inc hl
ld (hl),c
inc hl
ld (hl),b
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (freeRam),hl
jp setMod
operExp1Num:
ex de,hl
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
or a
jp nz,operExp2
push hl
push de
B_CALL mov9toop2
pop hl
; B_CALL mov9toop1
rst rmov9toop1
B_CALL ytox
pop de
push de
B_CALL movfrop1
pop bc
pop de
pop hl
push hl
push de
ld (hl),c
inc hl
ld (hl),b
jp setMod
operExp1Exp:
ld e,(ix)
ld d,(ix+1)
ld (ix),l
ld (ix+1),h
ld (hl),tmul
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld (ix-2),c
ld (ix-1),b
jp setMod
operNeg:
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
cp 0b0h
jr z,operNegNeg
cp tsub
jp nz,simNum2
inc hl
ld c,(hl)
inc hl
push hl
ld b,(hl)
inc hl
ld e,(hl)
ld (hl),c
inc hl
ld d,(hl)
ld (hl),b
pop hl
ld (hl),d
dec hl
ld (hl),e
dec hl
;hl = new node... ix is bad node
pop bc
pop de
push de
push bc
ex de,hl
ld (hl),e
inc hl
ld (hl),d
jp setmod
operNegNeg:
;--(u)=u
inc hl
ld e,(hl)
inc hl
ld d,(hl)
pop bc
pop hl
push hl
push bc
ld (hl),e
inc hl
ld (hl),d
jp setmod
operAdd:
ld l,(ix-2)
ld h,(ix-1)
ld a,(hl)
cp 0b0h
jp z,operAdd1Neg
cp tsub
jp z,operAdd1Sub
cp tadd
jp z,operAdd1Add
ex de,hl
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
cp 0b0h
jp z,operAdd2Neg
cp tsub
jp z,operAdd2Sub
ld a,(mod2Flag)
or a
jp nz,simNum2
;we can now see if terms can be combined
ld (tempHL),ix
ld (tempBC),hl
ld (pro1Parent),de
push hl
pop de
ld a,(hl)
cp tadd
jp nz,skipSome
inc hl
ld e,(hl)
inc hl
ld d,(hl)
skipSome:
ld (pro2Parent),de
ld hl,(pro1Parent)
ld a,(hl)
cp tdiv
jp z,operAdd1Div
ex de,hl
ld a,(hl)
cp tdiv
jp z,operAdd1NoDiv2Div
;here we have (!/) and (!/)
call cmpIgCoeff
jp nz,simNum2
;yes! combine terms!
ld hl,(pro1Parent)
call getCoeff
; ld de,op1
; ld bc,9
; ldir
rst rmov9toop1
ld hl,(pro2Parent)
call getCoeff
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
; B_CALL fpadd
rst rfpadd
ld hl,(pro1Parent)
call insertCoeff
ld ix,(tempBC)
ld a,(ix)
cp tadd
jp nz,pull2Top
ld l,(ix+3)
ld h,(ix+4)
ld ix,(tempHL)
ld (ix-2),l
ld (ix-1),h
ld (ix),c
ld (ix+1),b
jp setMod
;input: bc node to pull to the top
pull2Top:
pop de
pop hl
push hl
push de
ld (hl),c
inc hl
ld (hl),b
jp setMod
operAdd1NoDiv2Div:
;here we have (!/) and ?/?
push hl
pop ix
ld l,(ix+3)
ld h,(ix+4)
ld a,(hl)
or a
jp nz,simNum2 ;must be a number if both are not /
;here we have (!/) and (?/#)
ld l,(ix+1)
ld h,(ix+2)
ld de,(pro1Parent)
call cmpIgCoeff
jp nz,simNum2
;yes! combine terms!
ld hl,(pro1Parent)
call getCoeff
; ld de,op1
; ld bc,9
; ldir
rst rmov9toop1
ld ix,(pro2Parent)
ld l,(ix+3)
ld h,(ix+4)
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
B_CALL fpmult
ld hl,(pro2Parent)
ld l,(ix+1)
ld h,(ix+2)
call getCoeff
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
; B_CALL fpadd
rst rfpadd
ld ix,(pro2Parent)
ld l,(ix+1)
ld h,(ix+2)
push ix
call insertCoeff
pop ix
ld (ix+1),c
ld (ix+2),b
ld bc,(tempBC)
jp pull2Top
operAdd1Div:
ex de,hl
ld a,(hl)
cp tdiv
jp z,operAdd1Div2Div
push de
pop ix
ex de,hl
ld l,(ix+3)
ld h,(ix+4)
ld a,(hl)
or a
jp nz,simNum2 ;must be a number if both are not /
;here we have ?/# and (!/)
ld l,(ix+1)
ld h,(ix+2)
call cmpIgCoeff
jp nz,simNum2
;yes! combine terms!
ld hl,(pro2Parent)
call getCoeff
; ld de,op1
; ld bc,9
; ldir
rst rmov9toop1
ld ix,(pro1Parent)
ld l,(ix+3)
ld h,(ix+4)
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
B_CALL fpmult
ld hl,(pro1Parent)
ld l,(ix+1)
ld h,(ix+2)
call getCoeff
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
; B_CALL fpadd
rst rfpadd
ld ix,(pro1Parent)
ld l,(ix+1)
ld h,(ix+2)
push ix
call insertCoeff
pop hl
push hl
inc hl
ld (hl),c
inc hl
ld (hl),b
pop bc
ld ix,(tempBC)
ld a,(ix)
cp tadd
jp nz,pull2Top
ld c,(ix+3)
ld b,(ix+4)
ld hl,(tempHL)
ld (hl),c
inc hl
ld (hl),b
jp setMod
operAdd1Div2Div: ;hl=pro2parent
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld c,(hl)
inc hl
ld b,(hl)
ld ix,(pro1Parent)
ld l,(ix+1)
ld h,(ix+2)
push bc
push ix
call cmpIgCoeff
pop ix
pop de
jp nz,simNum2
ld l,(ix+3)
ld h,(ix+4)
push ix
push hl
push de
call cmpIgCoeff
pop hl ;pro2parent divisor
pop de ;pro1parent divisor
pop ix
jp nz,simNum2
push hl
push de
call getCoeff
pop de
push hl
push de
; ld de,op1
; ld bc,9
; ldir ;op1 = coeff of denominator of pro2parent
rst rmov9toop1
ld l,(ix+1)
ld h,(ix+2)
call getCoeff
; ld de,op2 ;op2 = coeff of numerator of pro1parent
; ld bc,9
; ldir
B_CALL mov9toop2
B_CALL fpmult
; ld hl,op1
; ld de,op4
; ld bc,9
; ldir ;op4 = c of d of p2 * c of n of p1
B_CALL op1toop4
pop hl ;pro1parent denominator
call getCoeff
push hl
; ld de,op1
; ld bc,9
; ldir ;op1 = coeff of p1 denominator
rst rmov9toop1
ld hl,(pro2Parent)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
push hl
call getCoeff
; ld de,op2
; ld bc,9
; ldir ;op2 = coeff of p2 numerator
B_CALL mov9toop2
B_CALL fpmult
; ld hl,op4
; ld de,op2
; ld bc,9
; ldir
B_CALL op4toop2
; B_CALL fpadd
rst rfpadd
pop hl
call insertCoeff
ld hl,(pro2Parent)
inc hl
ld (hl),c
inc hl
ld (hl),b
pop hl
; ld de,op1
; ld bc,9
; ldir
rst rmov9toop1
pop hl
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
B_CALL fpmult
pop hl
call insertCoeff
ld ix,(pro2Parent)
ld (ix+3),c
ld (ix+4),b
ld bc,(tempBC)
jp pull2Top
operMult1Mult:
operAdd1Add:
ld e,(ix)
ld d,(ix+1)
ld (ix),l
ld (ix+1),h
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld (ix-2),c
ld (ix-1),b
jp setMod
operMult1Div:
operAdd1Sub:
ld (ix-3),a
ld e,(ix)
ld d,(ix+1)
dec (hl)
inc hl
inc hl
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld (ix),c
ld (ix+1),b
jp setMod
operMult2Div
operAdd2Sub:
ld (ix-3),a
ld (ix-2),l
ld (ix-1),h
dec (hl)
inc hl
inc hl
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld (ix),c
ld (ix+1),b
jp setMod
operAdd1Neg:
ld e,(ix)
ld d,(ix+1)
ld (ix-2),e
ld (ix-1),d
ld (ix),l
ld (ix+1),h
operAdd2Neg:
ld (ix-3),tsub
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ld (ix),e
ld (ix+1),d
jp setmod
operSub:
ld l,(ix-2)
ld h,(ix-1)
ld a,(hl)
cp tsub ;do you want to put those operAdd1Add thingies back?
jp z,operSub1Sub
ld a,(mod2Flag)
or a
jr nz,operSub2 ;there are simpler things to do if there are positive terms
ld a,(hl)
cp 0b0h
jp z,operSub1Neg
operSub2:
ex de,hl ;also finish doing fixing the swapped nodes bug
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
cp tsub
jp z,operSub2Sub
cp 0b0h
jp z,operSub2Neg
ld a,(mod2Flag)
or a
jp nz,simNum2
;now check for matches
ld (pro1Parent),ix
dec ix
dec ix
ld (pro2Parent),ix
subCancel:
push de
subCancel2:
push hl
push de
ld a,(hl)
cp tadd
jr nz,subCancel3
inc hl
ld (pro1Parent),hl
ld c,(hl)
inc hl
ld b,(hl)
push bc
pop hl
subCancel3:
ld (tempHL),hl
ex de,hl
ld a,(hl)
cp tadd
jr nz,subCancel4
inc hl
ld (pro2Parent),hl
ld c,(hl)
inc hl
ld b,(hl)
push bc
pop hl
subCancel4:
ld (tempBC),hl
; call cmpIgCoeff
; jr z,subCancelMatch
ld a,(hl)
cp tdiv
jp z,subCancel1Div
ld a,(de)
cp tdiv
jr z,subCancel2Div
;!/ and !/
call cmpIgCoeff
jp z,subCancelMatch
jp subnotequal
;!/ and ?/?
subCancel2Div:
push hl
ex de,hl
inc hl
ld e,(hl)
inc hl
ld d,(hl)
pop hl
call cmpIgCoeff
jp nz,subnotequal
ld hl,(tempHL) ;neg node
inc hl
inc hl
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
ld a,(hl)
or a
jp nz,subnotequal
B_CALL mov9toop2
ld hl,(tempBC)
call getCoeff
; B_CALL mov9toop1
rst rmov9toop1
B_CALL fpmult
ld hl,(tempHL)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call getCoeff
B_CALL mov9toop2
B_CALL fpsub
pop af
pop af
pop af
ld a,(op1)
cp 80h
jr z,subCancel2DivNeg
subCancelSwapper:
ld hl,(tempHL)
inc hl
ld e,(hl)
inc hl
push hl
ld d,(hl)
ex de,hl
call insertCoeff
pop hl
ld (hl),b
dec hl
ld (hl),c
dec hl
ex de,hl
ld hl,(pro2Parent)
ld (hl),e
inc hl
ld (hl),d
B_CALL op1set0
ld hl,(tempHL)
call insertCoeff
ld hl,(pro1Parent)
ld (hl),c
inc hl
ld (hl),b
jp setMod
subCancel2DivNeg:
xor a
ld (op1),a
ld hl,(tempHL)
inc hl
push hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call insertCoeff
pop hl
jp subNeg2
;?/? and
subCancel1Div:
ld a,(de)
cp tdiv
jr z,subCancel1Div2Div
;?/? and !/
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld c,(hl)
inc hl
ld b,(hl)
ld a,(bc)
or a
jp nz,subnotequal
ld hl,(tempHL)
push hl
push bc
push de
call cmpIgCoeff
pop de
pop bc
pop hl
jp nz,subnotequal
push de
push bc
call getCoeff
; B_CALL mov9toop1
rst rmov9toop1
pop hl
B_CALL mov9toop2
B_CALL fpmult
pop hl
call getCoeff
B_CALL mov9toop2
B_CALL fpsub
pop af
pop af
pop af
ld a,(op1)
cp 80h
jr z,subCancel1DivNeg
ld hl,(tempHL)
ld bc,(tempBC)
ld (tempHL),bc
ld (tempBC),hl
ld hl,(pro1Parent)
ld bc,(pro2Parent)
ld (pro1Parent),bc
ld (pro2Parent),hl
jp subCancelSwapper
subCancel1DivNeg:
xor a
ld (op1),a
ld hl,(tempBC)
inc hl
push hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call insertCoeff
pop hl
jp subPos2
;?/? and ?/?
subCancel1Div2Div:
inc hl
ld c,(hl)
inc hl
ld b,(hl)
inc hl
push hl
ex de,hl
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
push hl
ld h,b
ld l,c
call cmpIgCoeff
pop de
pop hl
jp nz,subnotequal
ld c,(hl)
inc hl
ld b,(hl)
ex de,hl
ld e,(hl)
inc hl
ld d,(hl)
ld h,b
ld l,c
push hl
push de
call cmpIgCoeff
pop de
pop hl
jp nz,subnotequal
push de
; B_CALL mov9toop1
call getCoeff
rst rmov9toop1
pop hl
call getCoeff
B_CALL mov9toop2
B_CALL cpop1op2
jr z,likedenoms
B_CALL op1toop4
B_CALL fpmult
B_CALL op1toop6
ld hl,(tempBC)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call getCoeff
; B_CALL mov9toop1
rst rmov9toop1
B_CALL fpmult
B_CALL op1toop5
ld hl,(tempHL)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call getCoeff
; B_CALL mov9toop1
rst rmov9toop1
B_CALL op4toop2
B_CALL fpmult
B_CALL op5toop2
jr subCancel1Div2DivFinish
likedenoms:
B_CALL op1toop6
ld hl,(tempBC)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call getCoeff
B_CALL mov9toop2
ld hl,(tempHL)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call getCoeff
; B_CALL mov9toop1
rst rmov9toop1
subCancel1Div2DivFinish:
B_CALL op1exop2
B_CALL fpsub
B_CALL op2set0
ld a,(op1)
or a
jr z,properops
xor a
ld (op1),a
B_CALL op1exop2
properops:
ld hl,(tempBC)
call makefractions
B_CALL op2toop1
ld hl,(tempHL)
call makefractions
pop af
pop af
pop af
jp setMod
makefractions:
inc hl
push hl
ld e,(hl)
inc hl
ld d,(hl)
ex de,hl
call insertCoeff
pop hl
ld (hl),c
inc hl
ld (hl),b
inc hl
ld e,(hl)
inc hl
ld d,(hl)
push hl
push de
B_CALL op6toop1
pop hl
call insertCoeff
pop hl
ld (hl),b
dec hl
ld (hl),c
ret
subnotequal:
pop hl
ld a,(hl)
cp tadd
jr nz,subCancel5
inc hl
inc hl
inc hl
ld (pro2Parent),hl
ld e,(hl)
inc hl
ld d,(hl)
pop hl
;i don't think pro1Parent will be different in this case
jp subCancel2
subCancel5:
pop hl
pop de
ld a,(hl)
cp tadd
jp nz,simNum2
inc hl
inc hl
inc hl
ld (pro1Parent),hl
ld c,(hl)
inc hl
ld b,(hl)
push bc
pop hl
jp subCancel
subCancelMatch: ;(sp) = pos node (sp-2) = neg node;pro parents = like terms
pop af
pop af
pop af
ld hl,(tempHL)
call getCoeff
; ld de,op2
; ld bc,9
; ldir
B_CALL mov9toop2
ld hl,(tempBC)
call getCoeff
; ld de,op1
; ld bc,9
; ldir
rst rmov9toop1
B_CALL fpsub
B_CALL ckop1fp0
jr z,subCancelBoth
B_CALL ckop1pos
jr z,subPos
subNeg:
xor a
ld (op1),a
ld hl,(tempHL)
call insertCoeff
ld hl,(pro1Parent)
subNeg2:
ld (hl),c
inc hl
ld (hl),b
B_CALL op1set0
jr subcommon
; ld hl,(tempBC)
; call insertCoeff
; ld hl,(pro2Parent)
; ld (hl),c
; inc hl
; ld (hl),b
; jp setMod
subPos
ld hl,(tempBC)
call insertCoeff
ld hl,(pro2Parent)
subPos2:
ld (hl),c
inc hl
ld (hl),b
B_CALL op1set0
ld hl,(tempHL)
call insertCoeff
ld hl,(pro1Parent)
; ld (hl),c
; inc hl
; ld (hl),b
; jp setMod
jr ldbcinhlsetmod
subCancelBoth:
ld hl,(tempHL)
call insertCoeff
ld hl,(pro1Parent)
ld (hl),c
inc hl
ld (hl),b
subcommon:
ld hl,(tempBC)
call insertCoeff
ld hl,(pro2Parent)
ldbcinhlsetmod:
ld (hl),c
inc hl
ld (hl),b
jr setmod_sub
; jp setMod
operSub1Neg:
dec ix
dec ix
dec ix
inc hl
ld c,(hl)
inc hl
ld b,(hl)
push ix
pop de
ld (hl),d
dec hl
ld (hl),e
dec hl
ld (ix),tadd
ld (ix+1),c
ld (ix+2),b
ex de,hl
pop bc
pop hl
push hl
push bc
ld (hl),e
inc hl
ld (hl),d
setmod_sub:
jp setmod
operSub2Neg:
ld (ix-3),tadd
inc hl
ld e,(hl)
inc hl
ld d,(hl)
ld (ix),e
ld (ix+1),d
; jp setmod
jr setmod_sub
operDiv1Div:
operSub1Sub:
ld e,(ix)
ld d,(ix+1)
ld (ix),l
ld (ix+1),h
dec (hl)
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld (ix-2),c
ld (ix-1),b
; jp setmod
jr setmod_sub
operDiv2Div:
operSub2Sub:
ld (ix-2),l
ld (ix-1),h
dec (hl)
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld (ix),c
ld (ix+1),b
; jp setmod
jr setmod_sub
operMult:
ld l,(ix-2)
ld h,(ix-1)
ld a,(hl)
cp tmul
jp z,operMult1Mult
cp tdiv
jp z,operMult1Div
cp tadd
jp z,operMult1Add
cp tsub
jp z,operMult1Sub
cp 0b0h
jp z,operMult1Neg
or a
jp z,operMult1Num
ex de,hl
operMult2:
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
cp tdiv
jp z,operMult2Div
cp 0b0h
jp z,operMult2Neg
cp tadd
jp z,operMult2Add
cp tsub
jp z,operMult2Sub
ld a,(mod2Flag)
or a
jp nz,simNum2
;now see if terms can be combined
ld (tempBC),hl
ld (pro1Parent),de
push ix
pop bc
dec bc
dec bc
dec bc
ld (tempHL),bc
ld ix,tempBC
jp iterateMult3
iterateMult:
ld hl,(tempHL)
ld a,(hl)
cp tmul
jp nz,simNum2
inc hl
inc hl
inc hl
push hl
pop ix
ld c,(hl)
inc hl
ld b,(hl)
push bc
pop hl
ld (tempHL),hl
iterateMult3:
ld a,(hl)
cp tmul
jp nz,iterateMult2
inc hl
push hl
pop ix
ld c,(hl)
inc hl
ld b,(hl)
push bc
pop hl
iterateMult2:
ld (pro2Parent),hl
ld de,(pro1Parent)
push ix
call cmpIgPow
pop ix
jp nz,iterateMult
ld hl,(pro2Parent)
push hl
call getPower
ld hl,(freeRam)
push hl
ld (hl),tadd
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
push hl
inc hl
inc hl
ld (freeRam),hl
ld hl,(pro1Parent)
call getPower
pop hl
ld (hl),e
inc hl
ld (hl),d
pop de
pop hl
call insertExp
ld (ix),l
ld (ix+1),h
ld bc,(tempBC)
jp pull2Top
operExp1Mult:
ld c,a
ld b,tpower
jr operExpMult2
operMult1Sub:
operMult1Add:
;i need to give the divide routine time to cancel terms, then i can expand.
;the symbolic divide will catch what the canceler does not
ld b,tmul
ld c,a
ld a,(lastFlag)
or a
jp z,simNum2
operExpMult2:
ld (ix-3),c
ld e,(ix)
ld d,(ix+1)
push ix
push de
push hl
push bc
call copySub
pop bc
pop ix
ld (ix),b
ld l,(ix+3)
ld (ix+3),e
ld h,(ix+4)
ld (ix+4),d
ex de,hl
ld hl,(freeRam)
ld (hl),b
push hl
pop bc
inc hl
ld (hl),e
inc hl
ld (hl),d
inc hl
pop de
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (freeRam),hl
pop hl
ld (hl),c
inc hl
ld (hl),b
jp setMod
operMult2Sub:
operMult2Add:
ld c,a
ld a,(lastFlag)
or a
jp z,simNum2
ld (ix-3),c
push de
push hl
push ix
call copySub
pop ix
pop hl
ld (ix-2),l
ld (ix-1),h
ld (hl),tmul
inc hl
inc hl
inc hl
ld c,(hl)
ld (hl),e
inc hl
ld b,(hl)
ld (hl),d
ld hl,(freeRam)
push hl
ld (hl),tmul
inc hl
ld (hl),c
inc hl
ld (hl),b
inc hl
pop bc
pop de
ld (hl),e
inc hl
ld (hl),d
inc hl
ld (freeRam),hl
ld (ix),c
ld (ix+1),b
jp setMod
operMult1Num:
ex de,hl
ld l,(ix)
ld h,(ix+1)
ld a,(hl)
or a
jp z,operMult1Num2Num
cp tmul
jp nz,operMult2
operMult1Num2:
push hl
inc hl
ld c,(hl)
inc hl ; *
ld b,(hl) ; / \
push bc ;#a * <- bc = this location; de = #a
pop hl ; / \
pop bc ; ?b ?c <- hl = ?b
ld a,(hl)
or a
jp nz,operMult2
operMult1Num22: ;optimizable... use pull2top method
push bc
push hl
push de
; B_CALL mov9toop1
rst rmov9toop1
pop hl
B_CALL mov9toop2
B_CALL fpmult
pop de
operMult1Num2NumCommon:
B_CALL movfrop1
pop bc
pop de
pop hl
push hl
push de
ld (hl),c
inc hl
ld (hl),b
jp simNum2
arg! it doesnt fit in one post! |