implemented almost all math operations

This commit is contained in:
Irmen de Jong 2020-08-27 20:47:22 +02:00
parent a77d3c92ad
commit d97da3bb7b
7 changed files with 845 additions and 726 deletions

View File

@ -86,7 +86,8 @@ result .byte 0,0,0,0
.pend
divmod_ub .proc
divmod_ub_asm .proc
; TODO divmod_ub_asm doesn't work correctly. (remainder = ok, quotient = FAULTY)
; -- divide A by Y, result quotient in Y, remainder in A (unsigned)
; division by zero will result in quotient = 255 and remainder = original number
sty P8ZP_SCRATCH_REG

View File

@ -339,7 +339,7 @@ idiv_b .proc
eor #$ff
sec
adc #0 ; make num2 positive
+ jsr math.divmod_ub
+ jsr math.divmod_ub_asm
sta _remainder
tya
plp ; get sign of result
@ -357,7 +357,7 @@ idiv_ub .proc
inx
ldy P8ESTACK_LO,x
lda P8ESTACK_LO+1,x
jsr math.divmod_ub
jsr math.divmod_ub_asm
tya
sta P8ESTACK_LO+1,x
rts
@ -410,7 +410,7 @@ remainder_ub .proc
inx
ldy P8ESTACK_LO,x ; right operand
lda P8ESTACK_LO+1,x ; left operand
jsr math.divmod_ub
jsr math.divmod_ub_asm
sta P8ESTACK_LO+1,x
rts
.pend

View File

@ -2,7 +2,7 @@
%import c64textio
%zeropage basicsafe
; TODO implement DIV asm generation
; TODO implement signed byte/word DIV asm generation, fix unsigned DIV asm generation (for in-place)
main {
@ -11,17 +11,17 @@ main {
div_ubyte(100, 6, 16)
div_ubyte(255, 2, 127)
div_byte(0, 1, 0)
div_byte(100, -6, -16)
div_byte(127, -2, -63)
;div_byte(0, 1, 0) ; TODO implement
;div_byte(100, -6, -16) ; TODO implement
;div_byte(127, -2, -63) ; TODO implement
div_uword(0,1,0)
div_uword(40000,500,80)
div_uword(43211,2,21605)
div_word(0,1,0)
div_word(-20000,500,-40)
div_word(-2222,2,-1111)
;div_word(0,1,0) ; TODO implement
;div_word(-20000,500,-40) ; TODO implement
;div_word(-2222,2,-1111) ; TODO implement
div_float(0,1,0)
div_float(999.9,111.0,9.008108108108107)

View File

@ -2,8 +2,6 @@
%import c64textio
%zeropage basicsafe
; TODO implement MUL asm generation
main {
sub start() {

View File

@ -1,8 +1,6 @@
%import c64textio
%zeropage basicsafe
; TODO implement REMAINDER asmgeneration
main {
sub start() {

View File

@ -1,15 +1,18 @@
%import c64flt
%import c64textio
%zeropage basicsafe
main {
sub start() {
float f1 = 2.2
float f2 = 1.0
float f4 = 4.0
float f5 = 5.0
ubyte b1 = 2
ubyte b2 = 13
ubyte b3 = 100
f1 /= f2+f4
c64flt.print_f(f1)
uword w1 = 2222
uword w2 = 11
uword w3 = 33
w1 %= (w2+w3)
txt.print_uw(w1)
c64.CHROUT('\n')
}
}