floating point 1.0 no longer referenced from ROM because cx16 doesn't have it. Added some more cx16 examples.

This commit is contained in:
Irmen de Jong 2020-09-05 00:17:58 +02:00
parent a6f3c84e28
commit 13d7f239ab
35 changed files with 2167 additions and 63 deletions

View File

@ -233,8 +233,8 @@ inc_var_f .proc
sty P8ZP_SCRATCH_W1+1
stx P8ZP_SCRATCH_REG_X
jsr MOVFM
lda #<FL_FONE
ldy #>FL_FONE
lda #<ONE
ldy #>ONE
jsr FADD
ldx P8ZP_SCRATCH_W1
ldy P8ZP_SCRATCH_W1+1
@ -248,8 +248,8 @@ dec_var_f .proc
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
stx P8ZP_SCRATCH_REG_X
lda #<FL_FONE
ldy #>FL_FONE
lda #<ONE
ldy #>ONE
jsr MOVFM
lda P8ZP_SCRATCH_W1
ldy P8ZP_SCRATCH_W1+1
@ -573,8 +573,8 @@ func_ceil .proc
jsr FCOMP
cmp #0
beq +
lda #<FL_FONE
ldy #>FL_FONE
lda #<ONE
ldy #>ONE
jsr FADD
+ jmp push_fac1_as_result
.pend

View File

@ -9,9 +9,11 @@
c64flt {
; ---- this block contains C-64 floating point related functions ----
const float PI = 3.141592653589793
const float TWOPI = 6.283185307179586
const float ZERO = 0.0
; TODO fix var storage in ASM when declared const:
float PI = 3.141592653589793
float TWOPI = 6.283185307179586
float ZERO = 0.0
float ONE = 1.0
; ---- C64 basic and kernal ROM float constants and functions ----

View File

@ -9,9 +9,11 @@
c64flt {
; ---- this block contains C-64 floating point related functions ----
const float PI = 3.141592653589793
const float TWOPI = 6.283185307179586
const float ZERO = 0.0
; TODO fix var storage in ASM when declared const:
float PI = 3.141592653589793
float TWOPI = 6.283185307179586
float ZERO = 0.0
float ONE = 1.0
; ---- ROM float functions ----

View File

@ -54,6 +54,36 @@ asmsub fill_screen (ubyte char @ A, ubyte txtcolor @ Y) clobbers(A) {
}
asmsub clear_screenchars (ubyte char @ A) clobbers(Y) {
; ---- clear the character screen with the given fill character (leaves colors)
; (assumes screen matrix is at the default address)
%asm {{
pha
phx
jsr c64.SCREEN ; get dimensions in X/Y
dex
dey
txa
asl a
sta P8ZP_SCRATCH_B1
pla
- ldx P8ZP_SCRATCH_B1
- stz cx16.VERA_ADDR_H
stx cx16.VERA_ADDR_L
sty cx16.VERA_ADDR_M
sta cx16.VERA_DATA0
dex
dex
cpx #254
bne -
dey
bpl --
plx
rts
}}
}
ubyte[16] color_to_charcode = [$90,$05,$1c,$9f,$9c,$1e,$1f,$9e,$81,$95,$96,$97,$98,$99,$9a,$9b]
sub color (ubyte txtcol) {

View File

@ -57,7 +57,7 @@ main {
float Azy = cosb*sinc
float Azz = cosb*cosc
ubyte i
ubyte @zp i
for i in 0 to len(xcoor)-1 {
rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
rotatedy[i] = Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]
@ -69,9 +69,9 @@ main {
; plot the points of the 3d cube
; first the points on the back, then the points on the front (painter algorithm)
ubyte i
float rz
float persp
ubyte @zp i
float @zp rz ; TODO compiler warning that float can't be in ZP?
float @zp persp
ubyte sx
ubyte sy

View File

@ -66,7 +66,7 @@ main {
word Azy = wcosb*wsinc / 128
word Azz = wcosb*wcosc / 128
ubyte i
ubyte @zp i
for i in 0 to len(xcoor)-1 {
; don't normalize by dividing by 128, instead keep some precision for perspective calc later
rotatedx[i] = (Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i])
@ -75,17 +75,20 @@ main {
}
}
const uword screen_width = 320
const ubyte screen_height = 200
sub draw_lines() {
ubyte i
ubyte @zp i
for i in len(edgesFrom) -1 downto 0 {
ubyte vFrom = edgesFrom[i]
ubyte vTo = edgesTo[i]
word persp1 = 256 + rotatedz[vFrom]/256
word persp2 = 256 + rotatedz[vTo]/256
graphics.line(rotatedx[vFrom] / persp1 + 160.w as uword,
rotatedy[vFrom] / persp1 + 100 as ubyte,
rotatedx[vTo] / persp2 + 160.w as uword,
rotatedy[vTo] / persp2 + 100 as ubyte)
ubyte @zp vFrom = edgesFrom[i]
ubyte @zp vTo = edgesTo[i]
word @zp persp1 = 256 + rotatedz[vFrom]/256
word @zp persp2 = 256 + rotatedz[vTo]/256
graphics.line(rotatedx[vFrom] / persp1 + screen_width/2 as uword,
rotatedy[vFrom] / persp1 + screen_height/2 as ubyte,
rotatedx[vTo] / persp2 + screen_width/2 as uword,
rotatedy[vTo] / persp2 + screen_height/2 as ubyte)
}
}
}

View File

@ -122,7 +122,7 @@ main {
word Azy = wcosb*wsinc / 128
word Azz = wcosb*wcosc / 128
ubyte i
ubyte @zp i
for i in 0 to len(xcoor)-1 {
; don't normalize by dividing by 128, instead keep some precision for perspective calc later
rotatedx[i] = (Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i])
@ -138,8 +138,8 @@ main {
; first sort vertices to sprite order so the back/front order is correct as well
; (simple bubble sort as it's only 8 items to sort)
ubyte i
ubyte i1
ubyte @zp i
ubyte @zp i1
for i in 6 downto 0 {
for i1 in 0 to i {
ubyte i2 = i1+1
@ -154,7 +154,7 @@ main {
ubyte[] spritecolors = [1,1,7,15,12,11,9,9]
for i in 0 to 7 {
word zc = rotatedz[i]
word @zp zc = rotatedz[i]
word persp = 300+zc/256
ubyte sx = rotatedx[i] / persp + width/2 as ubyte + 20
ubyte sy = rotatedy[i] / persp + height/2 as ubyte + 40

View File

@ -62,7 +62,7 @@ main {
word Azy = wcosb*wsinc / 128
word Azz = wcosb*wcosc / 128
ubyte i
ubyte @zp i
for i in 0 to len(xcoor)-1 {
; don't normalize by dividing by 128, instead keep some precision for perspective calc later
rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
@ -76,9 +76,9 @@ main {
; plot the points of the 3d cube
; first the points on the back, then the points on the front (painter algorithm)
ubyte i
word rz
word persp
ubyte @zp i
word @zp rz
word @zp persp
byte sx
byte sy

View File

@ -0,0 +1,108 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
ubyte[] ubarr = [100, 0, 99, 199, 22]
byte[] barr = [-100, 0, 99, -122, 22]
uword[] uwarr = [1000, 0, 222, 4444, 999]
word[] warr = [-1000, 0, 999, -4444, 222]
float[] farr = [-1000.1, 0, 999.9, -4444.4, 222.2]
str name = "irmen"
ubyte ub
byte bb
word ww
uword uw
float ff
; LEN/STRLEN
ubyte length = len(name)
if length!=5 txt.print("error len1\n")
length = len(uwarr)
if length!=5 txt.print("error len2\n")
length=strlen(name)
if length!=5 txt.print("error strlen1\n")
name[3] = 0
length=strlen(name)
if length!=3 txt.print("error strlen2\n")
; MAX
ub = max(ubarr)
if ub!=199 txt.print("error max1\n")
bb = max(barr)
if bb!=99 txt.print("error max2\n")
uw = max(uwarr)
if uw!=4444 txt.print("error max3\n")
ww = max(warr)
if ww!=999 txt.print("error max4\n")
ff = max(farr)
if ff!=999.9 txt.print("error max5\n")
; MIN
ub = min(ubarr)
if ub!=0 txt.print("error min1\n")
bb = min(barr)
if bb!=-122 txt.print("error min2\n")
uw = min(uwarr)
if uw!=0 txt.print("error min3\n")
ww = min(warr)
if ww!=-4444 txt.print("error min4\n")
ff = min(farr)
if ff!=-4444.4 txt.print("error min5\n")
; SUM
uw = sum(ubarr)
if uw!=420 txt.print("error sum1\n")
ww = sum(barr)
if ww!=-101 txt.print("error sum2\n")
uw = sum(uwarr)
if uw!=6665 txt.print("error sum3\n")
ww = sum(warr)
if ww!=-4223 txt.print("error sum4\n")
ff = sum(farr)
if ff!=-4222.4 txt.print("error sum5\n")
; ANY
ub = any(ubarr)
if ub==0 txt.print("error any1\n")
ub = any(barr)
if ub==0 txt.print("error any2\n")
ub = any(uwarr)
if ub==0 txt.print("error any3\n")
ub = any(warr)
if ub==0 txt.print("error any4\n")
ub = any(farr)
if ub==0 txt.print("error any5\n")
; ALL
ub = all(ubarr)
if ub==1 txt.print("error all1\n")
ub = all(barr)
if ub==1 txt.print("error all2\n")
ub = all(uwarr)
if ub==1 txt.print("error all3\n")
ub = all(warr)
if ub==1 txt.print("error all4\n")
ub = all(farr)
if ub==1 txt.print("error all5\n")
ubarr[1]=$40
barr[1]=$40
uwarr[1]=$4000
warr[1]=$4000
farr[1]=1.1
ub = all(ubarr)
if ub==0 txt.print("error all6\n")
ub = all(barr)
if ub==0 txt.print("error all7\n")
ub = all(uwarr)
if ub==0 txt.print("error all8\n")
ub = all(warr)
if ub==0 txt.print("error all9\n")
ub = all(farr)
if ub==0 txt.print("error all10\n")
txt.print("\nyou should see no errors printed above (only at first run).")
}
}

View File

@ -0,0 +1,923 @@
%import cx16textio
%zeropage basicsafe
main {
sub start() {
ubyte A
txt.print("ubyte shift left\n")
A = shiftlb0()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb1()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb2()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb3()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb4()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb5()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb6()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb7()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb8()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftlb9()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("ubyte shift right\n")
A = shiftrb0()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb1()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb2()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb3()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb4()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb5()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb6()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb7()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb8()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
A = shiftrb9()
txt.print_ubbin(A, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed byte shift left\n")
byte signedb
signedb = shiftlsb0()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb1()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb2()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb3()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb4()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb5()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb6()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb7()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb8()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftlsb9()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed byte shift right\n")
signedb = shiftrsb0()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb1()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb2()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb3()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb4()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb5()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb6()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb7()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb8()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
signedb = shiftrsb9()
txt.print_ubbin(signedb as ubyte, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("uword shift left\n")
uword uw
uw = shiftluw0()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw1()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw2()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw3()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw4()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw5()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw6()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw7()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw8()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw9()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw10()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw11()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw12()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw13()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw14()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw15()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw16()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftluw17()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("uword shift right\n")
uw = shiftruw0()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw1()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw2()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw3()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw4()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw5()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw6()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw7()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw8()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw9()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw10()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw11()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw12()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw13()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw14()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw15()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw16()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
uw = shiftruw17()
txt.print_uwbin(uw, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed word shift left\n")
word sw
sw = shiftlsw0()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw1()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw2()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw3()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw4()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw5()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw6()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw7()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw8()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw9()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw10()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw11()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw12()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw13()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw14()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw15()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw16()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftlsw17()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
txt.print("enter to continue:\n")
void c64.CHRIN()
txt.print("signed word shift right\n")
sw = shiftrsw0()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw1()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw2()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw3()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw4()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw5()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw6()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw7()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw8()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw9()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw10()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw11()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw12()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw13()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw14()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw15()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw16()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
sw = shiftrsw17()
txt.print_uwbin(sw as uword, true)
c64.CHROUT('\n')
}
sub shiftruw0() -> uword {
uword q = $a49f
return q >> 0
}
sub shiftruw1() -> uword {
uword q = $a49f
return q >> 1
}
sub shiftruw2() -> uword {
uword q = $a49f
return q >> 2
}
sub shiftruw3() -> uword {
uword q = $a49f
return q >> 3
}
sub shiftruw4() -> uword {
uword q = $a49f
return q >> 4
}
sub shiftruw5() -> uword {
uword q = $a49f
return q >> 5
}
sub shiftruw6() -> uword {
uword q = $a49f
return q >> 6
}
sub shiftruw7() -> uword {
uword q = $a49f
return q >> 7
}
sub shiftruw8() -> uword {
uword q = $a49f
return (q >> 8)
}
sub shiftruw9() -> uword {
uword q = $a49f
return (q >> 9)
}
sub shiftruw10() -> uword {
uword q = $a49f
return (q >> 10)
}
sub shiftruw11() -> uword {
uword q = $a49f
return (q >> 11)
}
sub shiftruw12() -> uword {
uword q = $a49f
return (q >> 12)
}
sub shiftruw13() -> uword {
uword q = $a49f
return (q >> 13)
}
sub shiftruw14() -> uword {
uword q = $a49f
return (q >> 14)
}
sub shiftruw15() -> uword {
uword q = $a49f
return (q >> 15)
}
sub shiftruw16() -> uword {
uword q = $a49f
return (q >> 16)
}
sub shiftruw17() -> uword {
uword q = $a49f
return (q >> 17)
}
sub shiftrsw0() -> word {
word q = -12345
return q >> 0
}
sub shiftrsw1() -> word {
word q = -12345
return q >> 1
}
sub shiftrsw2() -> word {
word q = -12345
return q >> 2
}
sub shiftrsw3() -> word {
word q = -12345
return q >> 3
}
sub shiftrsw4() -> word {
word q = -12345
return q >> 4
}
sub shiftrsw5() -> word {
word q = -12345
return q >> 5
}
sub shiftrsw6() -> word {
word q = -12345
return q >> 6
}
sub shiftrsw7() -> word {
word q = -12345
return q >> 7
}
sub shiftrsw8() -> word {
word q = -12345
return (q >> 8)
}
sub shiftrsw9() -> word {
word q = -12345
return (q >> 9)
}
sub shiftrsw10() -> word {
word q = -12345
return (q >> 10)
}
sub shiftrsw11() -> word {
word q = -12345
return (q >> 11)
}
sub shiftrsw12() -> word {
word q = -12345
return (q >> 12)
}
sub shiftrsw13() -> word {
word q = -12345
return (q >> 13)
}
sub shiftrsw14() -> word {
word q = -12345
return (q >> 14)
}
sub shiftrsw15() -> word {
word q = -12345
return (q >> 15)
}
sub shiftrsw16() -> word {
word q = -12345
return (q >> 16)
}
sub shiftrsw17() -> word {
word q = -12345
return (q >> 17)
}
sub shiftluw0() -> uword {
uword q = $a49f
return q << 0
}
sub shiftluw1() -> uword {
uword q = $a49f
return q << 1
}
sub shiftluw2() -> uword {
uword q = $a49f
return q << 2
}
sub shiftluw3() -> uword {
uword q = $a49f
return q << 3
}
sub shiftluw4() -> uword {
uword q = $a49f
return q << 4
}
sub shiftluw5() -> uword {
uword q = $a49f
return q << 5
}
sub shiftluw6() -> uword {
uword q = $a49f
return q << 6
}
sub shiftluw7() -> uword {
uword q = $a49f
return q << 7
}
sub shiftluw8() -> uword {
uword q = $a49f
return q << 8
}
sub shiftluw9() -> uword {
uword q = $a49f
return q << 9
}
sub shiftluw10() -> uword {
uword q = $a49f
return q << 10
}
sub shiftluw11() -> uword {
uword q = $a49f
return q << 11
}
sub shiftluw12() -> uword {
uword q = $a49f
return q << 12
}
sub shiftluw13() -> uword {
uword q = $a49f
return q << 13
}
sub shiftluw14() -> uword {
uword q = $a49f
return q << 14
}
sub shiftluw15() -> uword {
uword q = $a49f
return q << 15
}
sub shiftluw16() -> uword {
uword q = $a49f
return q << 16
}
sub shiftluw17() -> uword {
uword q = $a49f
return q << 17
}
sub shiftlsw0() -> word {
word q = -12345
return q << 0
}
sub shiftlsw1() -> word {
word q = -12345
return q << 1
}
sub shiftlsw2() -> word {
word q = -12345
return q << 2
}
sub shiftlsw3() -> word {
word q = -12345
return q << 3
}
sub shiftlsw4() -> word {
word q = -12345
return q << 4
}
sub shiftlsw5() -> word {
word q = -12345
return q << 5
}
sub shiftlsw6() -> word {
word q = -12345
return q << 6
}
sub shiftlsw7() -> word {
word q = -12345
return q << 7
}
sub shiftlsw8() -> word {
word q = -12345
return q << 8
}
sub shiftlsw9() -> word {
word q = -12345
return q << 9
}
sub shiftlsw10() -> word {
word q = -12345
return q << 10
}
sub shiftlsw11() -> word {
word q = -12345
return q << 11
}
sub shiftlsw12() -> word {
word q = -12345
return q << 12
}
sub shiftlsw13() -> word {
word q = -12345
return q << 13
}
sub shiftlsw14() -> word {
word q = -12345
return q << 14
}
sub shiftlsw15() -> word {
word q = -12345
return q << 15
}
sub shiftlsw16() -> word {
word q = -12345
return q << 16
}
sub shiftlsw17() -> word {
word q = -12345
return q << 17
}
sub shiftlb0() -> ubyte {
ubyte yy=$ed
return yy << 0
}
sub shiftlb1() -> ubyte {
ubyte yy=$ed
return yy << 1
}
sub shiftlb2() -> ubyte {
ubyte yy=$ed
return yy << 2
}
sub shiftlb3() -> ubyte {
ubyte yy=$ed
return yy << 3
}
sub shiftlb4() -> ubyte {
ubyte yy=$ed
return yy << 4
}
sub shiftlb5() -> ubyte {
ubyte yy=$ed
return yy << 5
}
sub shiftlb6() -> ubyte {
ubyte yy=$ed
return yy << 6
}
sub shiftlb7() -> ubyte {
ubyte yy=$ed
return yy << 7
}
sub shiftlb8() -> ubyte {
ubyte yy=$ed
return yy << 8
}
sub shiftlb9() -> ubyte {
ubyte yy=$ed
return yy << 9
}
sub shiftrb0() -> ubyte {
ubyte yy=$ed
return yy >> 0
}
sub shiftrb1() -> ubyte {
ubyte yy=$ed
return yy >> 1
}
sub shiftrb2() -> ubyte {
ubyte yy=$ed
return yy >> 2
}
sub shiftrb3() -> ubyte {
ubyte yy=$ed
return yy >> 3
}
sub shiftrb4() -> ubyte {
ubyte yy=$ed
return yy >> 4
}
sub shiftrb5() -> ubyte {
ubyte yy=$ed
return yy >> 5
}
sub shiftrb6() -> ubyte {
ubyte yy=$ed
return yy >> 6
}
sub shiftrb7() -> ubyte {
ubyte yy=$ed
return yy >> 7
}
sub shiftrb8() -> ubyte {
ubyte yy=$ed
return yy >> 8
}
sub shiftrb9() -> ubyte {
ubyte yy=$ed
return yy >> 9
}
sub shiftlsb0() -> byte {
byte yy=-123
return yy << 0
}
sub shiftlsb1() -> byte {
byte yy=-123
return yy << 1
}
sub shiftlsb2() -> byte {
byte yy=-123
return yy << 2
}
sub shiftlsb3() -> byte {
byte yy=-123
return yy << 3
}
sub shiftlsb4() -> byte {
byte yy=-123
return yy << 4
}
sub shiftlsb5() -> byte {
byte yy=-123
return yy << 5
}
sub shiftlsb6() -> byte {
byte yy=-123
return yy << 6
}
sub shiftlsb7() -> byte {
byte yy=-123
return yy << 7
}
sub shiftlsb8() -> byte {
byte yy=-123
return yy << 8
}
sub shiftlsb9() -> byte {
byte yy=-123
return yy << 9
}
sub shiftrsb0() -> byte {
byte yy=-123
return yy >> 0
}
sub shiftrsb1() -> byte {
byte yy=-123
return yy >> 1
}
sub shiftrsb2() -> byte {
byte yy=-123
return yy >> 2
}
sub shiftrsb3() -> byte {
byte yy=-123
return yy >> 3
}
sub shiftrsb4() -> byte {
byte yy=-123
return yy >> 4
}
sub shiftrsb5() -> byte {
byte yy=-123
return yy >> 5
}
sub shiftrsb6() -> byte {
byte yy=-123
return yy >> 6
}
sub shiftrsb7() -> byte {
byte yy=-123
return yy >> 7
}
sub shiftrsb8() -> byte {
byte yy=-123
return yy >> 8
}
sub shiftrsb9() -> byte {
byte yy=-123
return yy >> 9
}
}

View File

@ -0,0 +1,103 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
div_ubyte(0, 1, 0)
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_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_float(0,1,0)
div_float(999.9,111.0,9.008108108108107)
}
sub div_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" / ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub div_byte(byte a1, byte a2, byte c) {
byte r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" / ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub div_uword(uword a1, uword a2, uword c) {
uword r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" / ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub div_word(word a1, word a2, word c) {
word r = a1/a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" / ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub div_float(float a1, float a2, float c) {
float r = a1/a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" / ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -0,0 +1,111 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
minus_ubyte(0, 0, 0)
minus_ubyte(200, 0, 200)
minus_ubyte(200, 100, 100)
minus_ubyte(100, 200, 156)
minus_byte(0, 0, 0)
minus_byte(100, 100, 0)
minus_byte(50, -50, 100)
minus_byte(0, -30, 30)
minus_byte(-30, 0, -30)
minus_uword(0,0,0)
minus_uword(50000,0, 50000)
minus_uword(50000,20000,30000)
minus_uword(20000,50000,35536)
minus_word(0,0,0)
minus_word(1000,1000,0)
minus_word(-1000,1000,-2000)
minus_word(1000,500,500)
minus_word(0,-3333,3333)
minus_word(-3333,0,-3333)
minus_float(0,0,0)
minus_float(2.5,1.5,1.0)
minus_float(-1.5,3.5,-5.0)
}
sub minus_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" - ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub minus_byte(byte a1, byte a2, byte c) {
byte r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" - ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub minus_uword(uword a1, uword a2, uword c) {
uword r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" - ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub minus_word(word a1, word a2, word c) {
word r = a1-a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" - ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub minus_float(float a1, float a2, float c) {
float r = a1-a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" - ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -0,0 +1,105 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
mul_ubyte(0, 0, 0)
mul_ubyte(20, 1, 20)
mul_ubyte(20, 10, 200)
mul_byte(0, 0, 0)
mul_byte(10, 10, 100)
mul_byte(5, -5, -25)
mul_byte(0, -30, 0)
mul_uword(0,0,0)
mul_uword(50000,1, 50000)
mul_uword(500,100,50000)
mul_word(0,0,0)
mul_word(-10,1000,-10000)
mul_word(1,-3333,-3333)
mul_float(0,0,0)
mul_float(2.5,10,25)
mul_float(-1.5,10,-15)
}
sub mul_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" * ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub mul_byte(byte a1, byte a2, byte c) {
byte r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" * ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub mul_uword(uword a1, uword a2, uword c) {
uword r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" * ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub mul_word(word a1, word a2, word c) {
word r = a1*a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" * ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub mul_float(float a1, float a2, float c) {
float r = a1*a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" * ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -0,0 +1,109 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
plus_ubyte(0, 0, 0)
plus_ubyte(0, 200, 200)
plus_ubyte(100, 200, 44)
plus_byte(0, 0, 0)
plus_byte(-100, 100, 0)
plus_byte(-50, 100, 50)
plus_byte(0, -30, -30)
plus_byte(-30, 0, -30)
plus_uword(0,0,0)
plus_uword(0,50000,50000)
plus_uword(50000,20000,4464)
plus_word(0,0,0)
plus_word(-1000,1000,0)
plus_word(-500,1000,500)
plus_word(0,-3333,-3333)
plus_word(-3333,0,-3333)
plus_float(0,0,0)
plus_float(1.5,2.5,4.0)
plus_float(-1.5,3.5,2.0)
plus_float(-1.1,3.3,2.2)
}
sub plus_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" + ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub plus_byte(byte a1, byte a2, byte c) {
byte r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("byte ")
txt.print_b(a1)
txt.print(" + ")
txt.print_b(a2)
txt.print(" = ")
txt.print_b(r)
c64.CHROUT('\n')
}
sub plus_uword(uword a1, uword a2, uword c) {
uword r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" + ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
sub plus_word(word a1, word a2, word c) {
word r = a1+a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("word ")
txt.print_w(a1)
txt.print(" + ")
txt.print_w(a2)
txt.print(" = ")
txt.print_w(r)
c64.CHROUT('\n')
}
sub plus_float(float a1, float a2, float c) {
float r = a1+a2
if abs(r-c)<0.00001
txt.print(" ok ")
else
txt.print("err! ")
txt.print("float ")
c64flt.print_f(a1)
txt.print(" + ")
c64flt.print_f(a2)
txt.print(" = ")
c64flt.print_f(r)
c64.CHROUT('\n')
}
}

View File

@ -0,0 +1,140 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
txt.plot(0,24)
ubyte Y
ubyte ub=200
byte bb=-100
uword uw = 2000
word ww = -1000
float fl = 999.99
ubyte[3] ubarr = 200
byte[3] barr = -100
uword[3] uwarr = 2000
word[3] warr = -1000
float[3] flarr = 999.99
txt.print("++\n")
ub++
bb++
uw++
ww++
fl++
ubarr[1]++
barr[1]++
uwarr[1]++
warr[1]++
flarr[1] ++
check_ub(ub, 201)
Y=100
Y++
check_ub(Y, 101)
check_fl(fl, 1000.99)
check_b(bb, -99)
check_uw(uw, 2001)
check_w(ww, -999)
check_ub(ubarr[0], 200)
check_fl(flarr[0], 999.99)
check_b(barr[0], -100)
check_uw(uwarr[0], 2000)
check_w(warr[0], -1000)
check_ub(ubarr[1], 201)
check_fl(flarr[1], 1000.99)
check_b(barr[1], -99)
check_uw(uwarr[1], 2001)
check_w(warr[1], -999)
txt.print("--\n")
ub--
bb--
uw--
ww--
fl--
ubarr[1]--
barr[1]--
uwarr[1]--
warr[1]--
flarr[1] --
check_ub(ub, 200)
Y=100
Y--
check_ub(Y, 99)
check_fl(fl, 999.99)
check_b(bb, -100)
check_uw(uw, 2000)
check_w(ww, -1000)
check_ub(ubarr[1], 200)
check_fl(flarr[1], 999.99)
check_b(barr[1], -100)
check_uw(uwarr[1], 2000)
check_w(warr[1], -1000)
}
sub check_ub(ubyte value, ubyte expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" ubyte ")
txt.print_ub(value)
c64.CHROUT(',')
txt.print_ub(expected)
c64.CHROUT('\n')
}
sub check_b(byte value, byte expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" byte ")
txt.print_b(value)
c64.CHROUT(',')
txt.print_b(expected)
c64.CHROUT('\n')
}
sub check_uw(uword value, uword expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" uword ")
txt.print_uw(value)
c64.CHROUT(',')
txt.print_uw(expected)
c64.CHROUT('\n')
}
sub check_w(word value, word expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" word ")
txt.print_w(value)
c64.CHROUT(',')
txt.print_w(expected)
c64.CHROUT('\n')
}
sub check_fl(float value, float expected) {
if value==expected
txt.print(" ok ")
else
txt.print("err! ")
txt.print(" float ")
c64flt.print_f(value)
c64.CHROUT(',')
c64flt.print_f(expected)
c64.CHROUT('\n')
}
}

View File

@ -0,0 +1,47 @@
%import cx16textio
%zeropage basicsafe
main {
sub start() {
remainder_ubyte(0, 1, 0)
remainder_ubyte(100, 6, 4)
remainder_ubyte(255, 2, 1)
remainder_ubyte(255, 20, 15)
remainder_uword(0,1,0)
remainder_uword(40000,511,142)
remainder_uword(40000,500,0)
remainder_uword(43211,12,11)
}
sub remainder_ubyte(ubyte a1, ubyte a2, ubyte c) {
ubyte r = a1%a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("ubyte ")
txt.print_ub(a1)
txt.print(" % ")
txt.print_ub(a2)
txt.print(" = ")
txt.print_ub(r)
c64.CHROUT('\n')
}
sub remainder_uword(uword a1, uword a2, uword c) {
uword r = a1%a2
if r==c
txt.print(" ok ")
else
txt.print("err! ")
txt.print("uword ")
txt.print_uw(a1)
txt.print(" % ")
txt.print_uw(a2)
txt.print(" = ")
txt.print_uw(r)
c64.CHROUT('\n')
}
}

View File

@ -0,0 +1,131 @@
%import cx16flt
%import cx16textio
%zeropage basicsafe
main {
sub start() {
byte b1
byte b2
ubyte ub1
ubyte ub2
word w1
word w2
uword uw1
uword uw2
float f1
float f2
b1 = 10
b2 = 10
if sgn(b2-b1) != 0
txt.print("sgn1 error1\n")
b1 = -100
b2 = -100
if sgn(b2-b1) != 0
txt.print("sgn1 error2\n")
ub1 = 200
ub2 = 200
if sgn(ub2-ub1) != 0
txt.print("sgn1 error3\n")
w1 = 100
w2 = 100
if sgn(w2-w1) != 0
txt.print("sgn1 error4\n")
w1 = -2000
w2 = -2000
if sgn(w2-w1) != 0
txt.print("sgn1 error5\n")
uw1 = 999
uw2 = 999
if sgn(uw2-uw1) != 0
txt.print("sgn1 error6\n")
f1 = 3.45
f2 = 3.45
if sgn(f2-f1) != 0
txt.print("sgn1 error7\n")
; -1
b1 = 11
b2 = 10
if sgn(b2-b1) != -1
txt.print("sgn2 error1\n")
b1 = -10
b2 = -100
if sgn(b2-b1) != -1
txt.print("sgn2 error2\n")
ub1 = 202
ub2 = 200
if sgn(ub2 as byte - ub1 as byte) != -1
txt.print("sgn2 error3\n")
w1 = 101
w2 = 100
if sgn(w2-w1) != -1
txt.print("sgn2 error4\n")
w1 = -200
w2 = -2000
if sgn(w2-w1) != -1
txt.print("sgn2 error5\n")
uw1 = 2222
uw2 = 999
if sgn((uw2 as word) - (uw1 as word)) != -1
txt.print("sgn2 error6a\n")
if sgn(uw2 - uw1) != 1 ; always 0 or 1 if unsigned
txt.print("sgn2 error6b\n")
f1 = 3.45
f2 = 1.11
if sgn(f2-f1) != -1
txt.print("sgn2 error7\n")
; +1
b1 = 11
b2 = 20
if sgn(b2-b1) != 1
txt.print("sgn3 error1\n")
b1 = -10
b2 = -1
if sgn(b2-b1) != 1
txt.print("sgn3 error2\n")
ub1 = 202
ub2 = 205
if sgn(ub2-ub1) != 1
txt.print("sgn3 error3\n")
w1 = 101
w2 = 200
if sgn(w2-w1) != 1
txt.print("sgn3 error4\n")
w1 = -200
w2 = -20
if sgn(w2-w1) != 1
txt.print("sgn3 error5\n")
uw1 = 2222
uw2 = 9999
if sgn(uw2-uw1) != 1
txt.print("sgn3 error6\n")
f1 = 3.45
f2 = 5.11
if sgn(f2-f1) != 1
txt.print("sgn3 error7\n")
txt.print("should see no sgn errors\n")
}
}

View File

@ -0,0 +1,110 @@
%import cx16flt
%import cx16textio
; TODO fix compilation when zeropage is not basicsafe
%zeropage basicsafe
main {
const uword width = 80
const uword height = 60
; vertices
float[] xcoor = [ -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0 ]
float[] ycoor = [ -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0 ]
float[] zcoor = [ -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ]
; storage for rotated coordinates
float[len(xcoor)] rotatedx=0.0
float[len(ycoor)] rotatedy=0.0
float[len(zcoor)] rotatedz=-1.0
sub start() {
float time=0.0
ubyte timer_jiffies
repeat {
rotate_vertices(time)
txt.clear_screenchars(' ')
draw_edges()
time+=0.1
txt.plot(0,0)
txt.print("3d cube! (floating point calc) ")
%asm {{
phx
jsr c64.RDTIM ; A/X/Y
sta timer_jiffies
lda #0
jsr c64.SETTIM
plx
}}
txt.print_ub(timer_jiffies)
txt.print(" jiffies/fr = ")
txt.print_ub(60/timer_jiffies)
txt.print(" fps")
}
}
sub rotate_vertices(float t) {
; rotate around origin (0,0,0)
; set up the 3d rotation matrix values
float cosa = cos(t)
float sina = sin(t)
float cosb = cos(t*0.33)
float sinb = sin(t*0.33)
float cosc = cos(t*0.78)
float sinc = sin(t*0.78)
float cosa_sinb = cosa*sinb
float sina_sinb = sina*sinb
float Axx = cosa*cosb
float Axy = cosa_sinb*sinc - sina*cosc
float Axz = cosa_sinb*cosc + sina*sinc
float Ayx = sina*cosb
float Ayy = sina_sinb*sinc + cosa*cosc
float Ayz = sina_sinb*cosc - cosa*sinc
float Azx = -sinb
float Azy = cosb*sinc
float Azz = cosb*cosc
ubyte @zp i
for i in 0 to len(xcoor)-1 {
rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
rotatedy[i] = Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]
rotatedz[i] = Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i]
}
}
sub draw_edges() {
; plot the points of the 3d cube
; first the points on the back, then the points on the front (painter algorithm)
ubyte @zp i
float rz
float persp
ubyte sx
ubyte sy
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz >= 0.1 {
persp = (5.0+rz)/(height as float)
sx = rotatedx[i] / persp + width/2.0 as ubyte
sy = rotatedy[i] / persp + height/2.0 as ubyte
txt.setcc(sx, sy, 46, 1)
}
}
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz < 0.1 {
persp = (5.0+rz)/(height as float)
sx = rotatedx[i] / persp + width/2.0 as ubyte
sy = rotatedy[i] / persp + height/2.0 as ubyte
txt.setcc(sx, sy, 81, 1)
}
}
}
}

View File

@ -0,0 +1,92 @@
%import cx16lib
; TODO fix compilation when zeropage is not basicsafe
%zeropage basicsafe
main {
; vertices
word[] xcoor = [ -100, -100, -100, -100, 100, 100, 100, 100 ]
word[] ycoor = [ -100, -100, 100, 100, -100, -100, 100, 100 ]
word[] zcoor = [ -100, 100, -100, 100, -100, 100, -100, 100 ]
; storage for rotated coordinates
word[len(xcoor)] rotatedx
word[len(ycoor)] rotatedy
word[len(zcoor)] rotatedz
; edges
ubyte[] edgesFrom = [ 0, 2, 6, 4, 1, 3, 7, 5, 0, 2, 6, 4]
ubyte[] edgesTo = [ 2, 6, 4, 0, 3, 7, 5, 1, 1, 3, 7, 5]
sub start() {
uword anglex
uword angley
uword anglez
void cx16.screen_set_mode($80)
cx16.r0 = 0
cx16.GRAPH_init()
cx16.GRAPH_set_colors(1, 2, 0)
repeat {
rotate_vertices(msb(anglex), msb(angley), msb(anglez))
cx16.GRAPH_clear()
draw_lines()
anglex-=250
angley+=109
anglez+=226
}
}
sub rotate_vertices(ubyte ax, ubyte ay, ubyte az) {
; rotate around origin (0,0,0)
; set up the 3d rotation matrix values
word wcosa = cos8(ax)
word wsina = sin8(ax)
word wcosb = cos8(ay)
word wsinb = sin8(ay)
word wcosc = cos8(az)
word wsinc = sin8(az)
word wcosa_sinb = wcosa*wsinb / 128
word wsina_sinb = wsina*wsinb / 128
word Axx = wcosa*wcosb / 128
word Axy = (wcosa_sinb*wsinc - wsina*wcosc) / 128
word Axz = (wcosa_sinb*wcosc + wsina*wsinc) / 128
word Ayx = wsina*wcosb / 128
word Ayy = (wsina_sinb*wsinc + wcosa*wcosc) / 128
word Ayz = (wsina_sinb*wcosc - wcosa*wsinc) / 128
word Azx = -wsinb
word Azy = wcosb*wsinc / 128
word Azz = wcosb*wcosc / 128
ubyte @zp i
for i in 0 to len(xcoor)-1 {
; don't normalize by dividing by 128, instead keep some precision for perspective calc later
rotatedx[i] = (Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i])
rotatedy[i] = (Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i])
rotatedz[i] = (Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i])
}
}
const uword screen_width = 320
const ubyte screen_height = 200
sub draw_lines() {
ubyte @zp i
for i in len(edgesFrom) -1 downto 0 {
ubyte @zp vFrom = edgesFrom[i]
ubyte @zp vTo = edgesTo[i]
word persp1 = 256 + rotatedz[vFrom]/256
word persp2 = 256 + rotatedz[vTo]/256
cx16.r0 = rotatedx[vFrom] / persp1 + screen_width/2 as uword
cx16.r1 = rotatedy[vFrom] / persp1 + screen_height/2 as uword
cx16.r2 = rotatedx[vTo] / persp2 + screen_width/2 as uword
cx16.r3 = rotatedy[vTo] / persp2 + screen_height/2 as uword
cx16.GRAPH_draw_line() ; TODO are there bugs in here? the lines are all wrong...
}
}
}

101
examples/cx16/cube3d.p8 Normal file
View File

@ -0,0 +1,101 @@
%import cx16textio
; TODO fix compilation when zeropage is not basicsafe
%zeropage basicsafe
main {
const uword screen_width = 80
const uword screen_height = 60
; vertices
word[] xcoor = [ -40, -40, -40, -40, 40, 40, 40, 40 ]
word[] ycoor = [ -40, -40, 40, 40, -40, -40, 40, 40 ]
word[] zcoor = [ -40, 40, -40, 40, -40, 40, -40, 40 ]
; storage for rotated coordinates
word[len(xcoor)] rotatedx
word[len(ycoor)] rotatedy
word[len(zcoor)] rotatedz
sub start() {
uword anglex
uword angley
uword anglez
ubyte timer_jiffies
repeat {
rotate_vertices(msb(anglex), msb(angley), msb(anglez))
txt.clear_screenchars(' ')
draw_edges()
anglex+=500
angley+=215
anglez+=453
}
}
sub rotate_vertices(ubyte ax, ubyte ay, ubyte az) {
; rotate around origin (0,0,0)
; set up the 3d rotation matrix values
word wcosa = cos8(ax)
word wsina = sin8(ax)
word wcosb = cos8(ay)
word wsinb = sin8(ay)
word wcosc = cos8(az)
word wsinc = sin8(az)
word wcosa_sinb = wcosa*wsinb / 128
word wsina_sinb = wsina*wsinb / 128
word Axx = wcosa*wcosb / 128
word Axy = (wcosa_sinb*wsinc - wsina*wcosc) / 128
word Axz = (wcosa_sinb*wcosc + wsina*wsinc) / 128
word Ayx = wsina*wcosb / 128
word Ayy = (wsina_sinb*wsinc + wcosa*wcosc) / 128
word Ayz = (wsina_sinb*wcosc - wcosa*wsinc) / 128
word Azx = -wsinb
word Azy = wcosb*wsinc / 128
word Azz = wcosb*wcosc / 128
ubyte @zp i
for i in 0 to len(xcoor)-1 {
; don't normalize by dividing by 128, instead keep some precision for perspective calc later
rotatedx[i] = Axx*xcoor[i] + Axy*ycoor[i] + Axz*zcoor[i]
rotatedy[i] = Ayx*xcoor[i] + Ayy*ycoor[i] + Ayz*zcoor[i]
rotatedz[i] = Azx*xcoor[i] + Azy*ycoor[i] + Azz*zcoor[i]
}
}
sub draw_edges() {
; plot the points of the 3d cube
; first the points on the back, then the points on the front (painter algorithm)
ubyte @zp i
word @zp rz
word @zp persp
byte sx
byte sy
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz >= 10 {
persp = 500 + rz/64
sx = rotatedx[i] / persp as byte + screen_width/2
sy = rotatedy[i] / persp as byte + screen_height/2
txt.setcc(sx as ubyte, sy as ubyte, 46, 7)
}
}
for i in 0 to len(xcoor)-1 {
rz = rotatedz[i]
if rz < 10 {
persp = 500 + rz/64
sx = rotatedx[i] / persp as byte + screen_width/2
sy = rotatedy[i] / persp as byte + screen_height/2
txt.setcc(sx as ubyte, sy as ubyte, 81, 7)
}
}
}
}

View File

@ -1,4 +1,4 @@
; CommanderX16 text clock example!
; CommanderX16 text datetime example!
; make sure to compile with the cx16 compiler target.
%import cx16textio

View File

@ -1,23 +0,0 @@
; CommanderX16 floating point example!
; make sure to compile with the cx16 compiler target.
%import cx16textio
%import cx16flt
%zeropage basicsafe
main {
sub start() {
float f1 = 5.55
float f2 = 33.3
float f3 = f1 * f2
c64flt.print_f(f1)
c64.CHROUT('*')
c64flt.print_f(f2)
c64.CHROUT('=')
c64flt.print_f(f3)
c64.CHROUT('\n')
}
}

View File

@ -385,9 +385,9 @@ waitkey:
}
sub drawBlock(ubyte x, ubyte y, ubyte character) {
ubyte i
ubyte @zp i
for i in 15 downto 0 {
ubyte c=blocklogic.currentBlock[i]
ubyte @zp c=blocklogic.currentBlock[i]
if c
txt.setcc((i&3)+x, (i/4)+y, character, c)
}
@ -534,7 +534,7 @@ blocklogic {
}
sub noCollision(ubyte xpos, ubyte ypos) -> ubyte {
ubyte i
ubyte @zp i
for i in 15 downto 0 {
if currentBlock[i] and txt.getchr(xpos + (i&3), ypos+i/4)!=32
return false

View File

@ -1,4 +1,4 @@
%import c64textio
%import cx16textio
%zeropage basicsafe
main {
@ -10,6 +10,16 @@ main {
; sub color(...) {}
; sub other(ubyte color) {} ; TODO don't cause name conflict
c64.CHROUT('\n')
; TODO fix var storage in ASM when declared const:
float PI = 3.141592653589793
float TWOPI = 6.283185307179586
float ZERO = 0.0
float ONE = 1.0
float @zp rz ; TODO compiler warning that float can't be in ZP?
}
}