word and uword and float comparisons

This commit is contained in:
Irmen de Jong 2018-12-09 16:16:46 +01:00
parent 21b9c2f011
commit b8150f645d
8 changed files with 1236 additions and 158 deletions

View File

@ -0,0 +1,153 @@
%import c64utils
%import mathlib
~ main {
sub start() {
byte v1
byte v2
ubyte cr
; done:
; ubyte all 6 comparisons
; byte all 6 comparisons
; check stack usage:
rsave()
c64.STROUT("signed byte ")
rrestore()
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT(' ')
rrestore()
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT('\n')
rrestore()
; comparisons:
rsave()
v1=-20
v2=125
c64.STROUT("v1=-20, v2=125\n")
rrestore()
compare()
rsave()
v1=80
v2=80
c64.STROUT("v1 = v2 = 80\n")
rrestore()
compare()
rsave()
v1=20
v2=-111
c64.STROUT("v1=20, v2=-111\n")
rrestore()
compare()
sub compare() {
rsave()
c64.STROUT(" == != < > <= >=\n")
rrestore()
if v1==v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1!=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
c64.CHROUT('\n')
}
}
}

View File

@ -0,0 +1,175 @@
%import c64utils
%import mathlib
%option enable_floats
~ main {
sub start() {
float v1
float v2
ubyte cr
; done:
; ubyte all 6 comparisons
; byte all 6 comparisons
; uword all 6 comparisons
; word all 6 comparisons
; float all 6 comparisons
; check stack usage:
rsave()
c64.STROUT("floating point ")
rrestore()
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT(' ')
rrestore()
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT('\n')
rrestore()
; comparisons:
rsave()
v1=20
v2=666.66
c64.STROUT("v1=20, v2=666.66\n")
rrestore()
compare()
rsave()
v1=-20
v2=666.66
c64.STROUT("v1=-20, v2=666.66\n")
rrestore()
compare()
rsave()
v1=666.66
v2=555.55
c64.STROUT("v1=666.66, v2=555.55\n")
rrestore()
compare()
rsave()
v1=3.1415
v2=-3.1415
c64.STROUT("v1 = 3.1415, v2 = -3.1415\n")
rrestore()
compare()
rsave()
v1=3.1415
v2=3.1415
c64.STROUT("v1 = v2 = 3.1415\n")
rrestore()
compare()
rsave()
v1=0
v2=0
c64.STROUT("v1 = v2 = 0\n")
rrestore()
compare()
sub compare() {
rsave()
c64.STROUT(" == != < > <= >=\n")
rrestore()
if v1==v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1!=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
c64.CHROUT('\n')
}
}
}

View File

@ -0,0 +1,152 @@
%import c64utils
%import mathlib
~ main {
sub start() {
ubyte v1
ubyte v2
ubyte cr
; done:
; ubyte all 6 comparisons
; check stack usage:
rsave()
c64.STROUT("unsigned byte ")
rrestore()
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT(' ')
rrestore()
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT('\n')
rrestore()
; comparisons:
rsave()
v1=20
v2=199
c64.STROUT("v1=20, v2=199\n")
rrestore()
compare()
rsave()
v1=80
v2=80
c64.STROUT("v1 = v2 = 80\n")
rrestore()
compare()
rsave()
v1=220
v2=10
c64.STROUT("v1=220, v2=10\n")
rrestore()
compare()
sub compare() {
rsave()
c64.STROUT(" == != < > <= >=\n")
rrestore()
if v1==v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1!=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
c64.CHROUT('\n')
}
}
}

View File

@ -0,0 +1,193 @@
%import c64utils
%import mathlib
~ main {
sub start() {
uword v1
uword v2
ubyte cr
; done:
; ubyte all 6 comparisons
; byte all 6 comparisons
; uword all 6 comparisons
; check stack usage:
rsave()
c64.STROUT("unsigned word ")
rrestore()
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT(' ')
rrestore()
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT('\n')
rrestore()
; comparisons:
rsave()
v1=20
v2=$00aa
c64.STROUT("v1=20, v2=$00aa\n")
rrestore()
compare()
rsave()
v1=20
v2=$ea00
c64.STROUT("v1=20, v2=$ea00\n")
rrestore()
compare()
rsave()
v1=$c400
v2=$22
c64.STROUT("v1=$c400, v2=$22\n")
rrestore()
compare()
rsave()
v1=$c400
v2=$2a00
c64.STROUT("v1=$c400, v2=$2a00\n")
rrestore()
compare()
rsave()
v1=$c433
v2=$2a00
c64.STROUT("v1=$c433, v2=$2a00\n")
rrestore()
compare()
rsave()
v1=$c433
v2=$2aff
c64.STROUT("v1=$c433, v2=$2aff\n")
rrestore()
compare()
rsave()
v1=$aabb
v2=$aabb
c64.STROUT("v1 = v2 = aabb\n")
rrestore()
compare()
rsave()
v1=$aa00
v2=$aa00
c64.STROUT("v1 = v2 = aa00\n")
rrestore()
compare()
rsave()
v1=$aa
v2=$aa
c64.STROUT("v1 = v2 = aa\n")
rrestore()
compare()
sub compare() {
rsave()
c64.STROUT(" == != < > <= >=\n")
rrestore()
if v1==v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1!=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
c64.CHROUT('\n')
}
}
}

View File

@ -0,0 +1,244 @@
%import c64utils
%import mathlib
~ main {
sub start() {
word v1
word v2
ubyte cr
; done:
; ubyte all 6 comparisons
; byte all 6 comparisons
; uword all 6 comparisons
; word all 6 comparisons
; check stack usage:
rsave()
c64.STROUT("signed word ")
rrestore()
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT(' ')
rrestore()
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT('\n')
rrestore()
; comparisons:
rsave()
v1=20
v2=$00aa
c64.STROUT("v1=20, v2=$00aa\n")
rrestore()
compare()
rsave()
v1=20
v2=$7a00
c64.STROUT("v1=20, v2=$7a00\n")
rrestore()
compare()
rsave()
v1=$7400
v2=$22
c64.STROUT("v1=$7400, v2=$22\n")
rrestore()
compare()
rsave()
v1=$7400
v2=$2a00
c64.STROUT("v1=$7400, v2=$2a00\n")
rrestore()
compare()
rsave()
v1=$7433
v2=$2a00
c64.STROUT("v1=$7433, v2=$2a00\n")
rrestore()
compare()
rsave()
v1=$7433
v2=$2aff
c64.STROUT("v1=$7433, v2=$2aff\n")
rrestore()
compare()
; with negative numbers:
rsave()
v1=-512
v2=$00aa
c64.STROUT("v1=-512, v2=$00aa\n")
rrestore()
compare()
rsave()
v1=-512
v2=$7a00
c64.STROUT("v1=-512, v2=$7a00\n")
rrestore()
compare()
rsave()
v1=$7400
v2=-512
c64.STROUT("v1=$7400, v2=-512\n")
rrestore()
compare()
rsave()
v1=-20000
v2=-1000
c64.STROUT("v1=-20000, v2=-1000\n")
rrestore()
compare()
rsave()
v1=-1000
v2=-20000
c64.STROUT("v1=-1000, v2=-20000\n")
rrestore()
compare()
rsave()
v1=-1
v2=32767
c64.STROUT("v1=-1, v2=32767\n")
rrestore()
compare()
rsave()
v1=32767
v2=-1
c64.STROUT("v1=32767, v2=-1\n")
rrestore()
compare()
rsave()
v1=$7abb
v2=$7abb
c64.STROUT("v1 = v2 = 7abb\n")
rrestore()
compare()
rsave()
v1=$7a00
v2=$7a00
c64.STROUT("v1 = v2 = 7a00\n")
rrestore()
compare()
rsave()
v1=$aa
v2=$aa
c64.STROUT("v1 = v2 = aa\n")
rrestore()
compare()
sub compare() {
rsave()
c64.STROUT(" == != < > <= >=\n")
rrestore()
if v1==v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1!=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1<=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
c64.CHROUT('\n')
}
}
}

View File

@ -1,137 +1,192 @@
%import c64utils
%import mathlib
%option enable_floats
~ main {
sub start() {
ubyte ub1
ubyte ub2
byte b1
byte b2
uword uw1
uword uw2
word w1
word w2
float f1
float f2
uword v1
uword v2
ubyte cr
; done:
; ubyte all 6 comparisons
; byte all 6 comparisons
; check stack usage:
rsave()
c64.STROUT("unsigned word ")
rrestore()
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT(' ')
rrestore()
cr=v1==v2
cr=v1==v2
cr=v1==v2
cr=v1!=v2
cr=v1!=v2
cr=v1!=v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1<v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1>v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1<=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
cr=v1>=v2
rsave()
c64scr.print_byte_decimal(X)
c64.CHROUT('\n')
rrestore()
ub2=b1<b2
ub2=b1<b2
ub2=b1<b2
ub2=b1<b2
ub2=b1>b2
ub2=b1>b2
ub2=b1>b2
ub2=b1>b2
ub2=b1>b2
ub2=b1<=b2
ub2=b1<=b2
ub2=b1<=b2
ub2=b1<=b2
ub2=b1>=b2
ub2=b1>=b2
ub2=b1>=b2
ub2=b1>=b2
ub2=b1>=b2
; comparisons:
rsave()
b1=-20
b2=99
c64.STROUT("b1=-20,b2=99\n")
v1=20
v2=$00aa
c64.STROUT("v1=20, v2=$00aa\n")
rrestore()
compare()
rsave()
v1=20
v2=$ea00
c64.STROUT("v1=20, v2=$ea00\n")
rrestore()
compare()
rsave()
v1=$c400
v2=$22
c64.STROUT("v1=$c400, v2=$22\n")
rrestore()
compare()
rsave()
v1=$c400
v2=$2a00
c64.STROUT("v1=$c400, v2=$2a00\n")
rrestore()
compare()
rsave()
v1=$c433
v2=$2a00
c64.STROUT("v1=$c433, v2=$2a00\n")
rrestore()
compare()
rsave()
v1=$c433
v2=$2aff
c64.STROUT("v1=$c433, v2=$2aff\n")
rrestore()
compare()
; rsave()
; v1=$aabb
; v2=$aabb
; c64.STROUT("v1 = v2 = aabb\n")
; rrestore()
; compare()
;
; rsave()
; v1=$aa00
; v2=$aa00
; c64.STROUT("v1 = v2 = aa00\n")
; rrestore()
; compare()
;
; rsave()
; v1=$aa
; v2=$aa
; c64.STROUT("v1 = v2 = aa\n")
; rrestore()
; compare()
sub compare() {
if b1<b2 {
rsave()
c64.STROUT(" true: b1<b2 ")
rrestore()
} else {
rsave()
c64.STROUT(" false: b1<b2 ")
rrestore()
}
if b1>b2 {
rsave()
c64.STROUT(" true: b1>b2\n")
rrestore()
} else {
rsave()
c64.STROUT(" false: b1>b2\n")
rrestore()
}
if b1<=b2 {
rsave()
c64.STROUT(" true: b1<=b2 ")
rrestore()
} else {
rsave()
c64.STROUT(" false: b1<=b2 ")
rrestore()
}
if b1>=b2 {
rsave()
c64.STROUT(" true: b1>=b2\n")
rrestore()
} else {
rsave()
c64.STROUT(" false: b1>=b2\n")
rrestore()
}
if b1==b2 {
rsave()
c64.STROUT(" true: b1==b2 ")
rrestore()
} else {
rsave()
c64.STROUT(" false: b1==b2 ")
rrestore()
}
if b1!=b2 {
rsave()
c64.STROUT(" true: b1!=b2\n")
rrestore()
} else {
rsave()
c64.STROUT(" false: b1!=b2\n")
rrestore()
}
}
rsave()
b1=-80
b2=-80
c64.STROUT("b1=b2=-80\n")
c64.STROUT(" == != < > <= >=\n")
rrestore()
compare()
if v1==v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1!=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
rsave()
b1=120
b2=-10
c64.STROUT("b1=120,b2=-10\n")
rrestore()
if v1<v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
compare()
if v1>v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
rsave()
c64scr.print_byte_decimal(X)
if v1<=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
if v1>=v2 {
rsave()
c64.STROUT(" Q ")
rrestore()
} else {
rsave()
c64.STROUT(" . ")
rrestore()
}
c64.CHROUT('\n')
rrestore()
}
}
}

View File

@ -1,6 +1,6 @@
package prog8.compiler.target.c64
import prog8.compiler.CompilerException
import java.io.CharConversionException
class Petscii {
companion object {
@ -1057,7 +1057,7 @@ class Petscii {
val petscii = lookup[it]
if(petscii==null) {
val case = if(lowercase) "lower" else "upper"
throw CompilerException("no ${case}case Petscii character for '$it'")
throw CharConversionException("no ${case}case Petscii character for '$it'")
}
petscii.toShort()
}
@ -1074,7 +1074,7 @@ class Petscii {
val screencode = lookup[it]
if(screencode==null) {
val case = if(lowercase) "lower" else "upper"
throw CompilerException("no ${case}Screencode character for '$it'")
throw CharConversionException("no ${case}Screencode character for '$it'")
}
screencode.toShort()
}

View File

@ -270,20 +270,6 @@ remainder_f .proc
.pend
equal_b .proc
; -- are the two bytes on the stack identical?
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
bne _equal_b_false
_equal_b_true lda #1
_equal_b_store inx
sta ESTACK_LO+1,x
rts
_equal_b_false lda #0
beq _equal_b_store
.pend
equal_w .proc
; -- are the two words on the stack identical?
; @todo optimize according to http://www.6502.org/tutorials/compare_beyond.html
@ -338,59 +324,120 @@ less_b .proc
.pend
less_uw .proc
rts
.warn "not implemented"
lda ESTACK_HI+2,x
cmp ESTACK_HI+1,x
bcc equal_b._equal_b_true
bne equal_b._equal_b_false
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
bcc equal_b._equal_b_true
bcs equal_b._equal_b_false
.pend
less_w .proc
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
lda ESTACK_HI+2,x
sbc ESTACK_HI+1,x
bvc +
eor #$80
+ bmi equal_b._equal_b_true
bpl equal_b._equal_b_false
.pend
equal_b .proc
; -- are the two bytes on the stack identical?
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
bne _equal_b_false
_equal_b_true lda #1
_equal_b_store inx
sta ESTACK_LO+1,x
rts
.warn "not implemented"
_equal_b_false lda #0
beq _equal_b_store
.pend
lesseq_ub .proc
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
bcc equal_b._equal_b_true
beq equal_b._equal_b_true
beq equal_b._equal_b_true ; @todo optimize by flipping comparison
bcs equal_b._equal_b_false
.pend
lesseq_b .proc
rts
.warn "not implemented"
; see http://www.6502.org/tutorials/compare_beyond.html
lda ESTACK_LO+2,x
clc
sbc ESTACK_LO+1,x
bvc +
eor #$80
+ bmi equal_b._equal_b_true
bpl equal_b._equal_b_false
.pend
lesseq_uw .proc
rts
.warn "not implemented"
lda ESTACK_HI+1,x
cmp ESTACK_HI+2,x
bcc equal_b._equal_b_false
bne equal_b._equal_b_true
lda ESTACK_LO+1,x
cmp ESTACK_LO+2,x
bcs equal_b._equal_b_true
bcc equal_b._equal_b_false
.pend
lesseq_w .proc
rts
.warn "not implemented"
lda ESTACK_LO+1,x
cmp ESTACK_LO+2,x
lda ESTACK_HI+1,x
sbc ESTACK_HI+2,x
bvc +
eor #$80
+ bpl equal_b._equal_b_true
bmi equal_b._equal_b_false
.pend
greater_ub .proc
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
beq equal_b._equal_b_false
bcs equal_b._equal_b_true
bcs equal_b._equal_b_true ; @todo optimize by flipping comparison?
bcc equal_b._equal_b_false
.pend
greater_b .proc
rts
.warn "not implemented"
; see http://www.6502.org/tutorials/compare_beyond.html
lda ESTACK_LO+2,x
clc
sbc ESTACK_LO+1,x
bvc +
eor #$80
+ bpl equal_b._equal_b_true
bmi equal_b._equal_b_false
.pend
greater_uw .proc
rts
.warn "not implemented"
lda ESTACK_HI+1,x
cmp ESTACK_HI+2,x
bcc equal_b._equal_b_true
bne equal_b._equal_b_false
lda ESTACK_LO+1,x
cmp ESTACK_LO+2,x
bcc equal_b._equal_b_true
bcs equal_b._equal_b_false
.pend
greater_w .proc
rts
.warn "not implemented"
lda ESTACK_LO+1,x
cmp ESTACK_LO+2,x
lda ESTACK_HI+1,x
sbc ESTACK_HI+2,x
bvc +
eor #$80
+ bmi equal_b._equal_b_true
bpl equal_b._equal_b_false
.pend
greatereq_ub .proc
@ -401,23 +448,40 @@ greatereq_ub .proc
.pend
greatereq_b .proc
rts
.warn "not implemented"
; see http://www.6502.org/tutorials/compare_beyond.html
lda ESTACK_LO+2,x
sec
sbc ESTACK_LO+1,x
bvc +
eor #$80
+ bpl equal_b._equal_b_true
bmi equal_b._equal_b_false
.pend
greatereq_uw .proc
rts
.warn "not implemented"
lda ESTACK_HI+2,x
cmp ESTACK_HI+1,x
bcc equal_b._equal_b_false
bne equal_b._equal_b_true
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
bcs equal_b._equal_b_true
bcc equal_b._equal_b_false
.pend
greatereq_w .proc
rts
.warn "not implemented"
lda ESTACK_LO+2,x
cmp ESTACK_LO+1,x
lda ESTACK_HI+2,x
sbc ESTACK_HI+1,x
bvc +
eor #$80
+ bpl equal_b._equal_b_true
bmi equal_b._equal_b_false
.pend
equal_f .proc
; -- are the two mflpt5 numbers on the stack identical?
; @todo optimize according to http://www.6502.org/tutorials/compare_beyond.html
inx
inx
inx
@ -449,25 +513,67 @@ notequal_f .proc
.pend
less_f .proc
rts
.warn "not implemented"
; -- is f1 < f2?
jsr compare_floats
cmp #255
beq compare_floats._return_true
bne compare_floats._return_false
.pend
lesseq_f .proc
rts
.warn "not implemented"
; -- is f1 <= f2?
jsr compare_floats
cmp #255
beq compare_floats._return_true
cmp #0
beq compare_floats._return_true
bne compare_floats._return_false
.pend
greater_f .proc
rts
.warn "not implemented"
; -- is f1 > f2?
jsr compare_floats
cmp #1
beq compare_floats._return_true
bne compare_floats._return_false
.pend
greatereq_f .proc
rts
.warn "not implemented"
; -- is f1 >= f2?
jsr compare_floats
cmp #1
beq compare_floats._return_true
cmp #0
beq compare_floats._return_true
bne compare_floats._return_false
.pend
compare_floats .proc
lda #<_flt2
ldy #>_flt2
jsr pop_float
lda #<_flt1
ldy #>_flt1
jsr pop_float
lda #<_flt1
ldy #>_flt1
jsr c64.MOVFM ; fac1 = flt1
lda #<_flt2
ldy #>_flt2
stx SCRATCH_ZPREG
jsr c64.FCOMP ; A = flt1 compared with flt2 (0=equal, 1=flt1>flt2, 255=flt1<flt2)
ldx SCRATCH_ZPREG
rts
_flt1 .fill 5
_flt2 .fill 5
_return_false lda #0
_return_result sta ESTACK_LO,x
dex
rts
_return_true lda #1
bne _return_result
.pend
func_sin .proc