mirror of
https://github.com/irmen/prog8.git
synced 2024-07-26 20:29:55 +00:00
integer word division
This commit is contained in:
parent
ebee8c128f
commit
3b6ffc47b2
@ -63,32 +63,26 @@
|
|||||||
|
|
||||||
sub draw_edges() {
|
sub draw_edges() {
|
||||||
|
|
||||||
sub toscreenx(float x, float z) -> byte {
|
|
||||||
return x/(5.0+z) * (height as float) as byte + width // 2
|
|
||||||
}
|
|
||||||
|
|
||||||
sub toscreeny(float y, float z) -> byte {
|
|
||||||
return y/(5.0+z) * (height as float) as byte + height // 2
|
|
||||||
}
|
|
||||||
|
|
||||||
; plot the points of the 3d cube
|
; plot the points of the 3d cube
|
||||||
; first the points on the back, then the points on the front (painter algorithm)
|
; first the points on the back, then the points on the front (painter algorithm)
|
||||||
|
|
||||||
for ubyte i in 0 to len(xcoor)-1 {
|
for ubyte i in 0 to len(xcoor)-1 {
|
||||||
float rz = rotatedz[i]
|
float rz = rotatedz[i]
|
||||||
if rz >= 0.1 {
|
if rz >= 0.1 {
|
||||||
ubyte sx = toscreenx(rotatedx[i], rz) as ubyte
|
float persp = (5.0+rz)/height
|
||||||
ubyte sy = toscreeny(rotatedy[i], rz) as ubyte
|
ubyte sx = rotatedx[i] / persp + width//2 as ubyte
|
||||||
c64scr.setchrclr(sx, sy, 46, i+2)
|
ubyte sy = rotatedy[i] / persp + height//2 as ubyte
|
||||||
|
c64scr.setcc(sx, sy, 46, i+2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ubyte i in 0 to len(xcoor)-1 {
|
for ubyte i in 0 to len(xcoor)-1 {
|
||||||
float rz = rotatedz[i]
|
float rz = rotatedz[i]
|
||||||
if rz < 0.1 {
|
if rz < 0.1 {
|
||||||
ubyte sx = toscreenx(rotatedx[i], rz) as ubyte
|
float persp = (5.0+rz)/height
|
||||||
ubyte sy = toscreeny(rotatedy[i], rz) as ubyte
|
ubyte sx = rotatedx[i] / persp + width//2 as ubyte
|
||||||
c64scr.setchrclr(sx, sy, 81, i+2)
|
ubyte sy = rotatedy[i] / persp + height//2 as ubyte
|
||||||
|
c64scr.setcc(sx, sy, 81, i+2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
%import c64utils
|
%import c64utils
|
||||||
%import c64flt
|
|
||||||
|
|
||||||
~ main {
|
~ main {
|
||||||
|
|
||||||
@ -74,30 +73,20 @@
|
|||||||
for ubyte i in 0 to len(xcoor)-1 {
|
for ubyte i in 0 to len(xcoor)-1 {
|
||||||
word rz = rotatedz[i]
|
word rz = rotatedz[i]
|
||||||
if rz >= 10 {
|
if rz >= 10 {
|
||||||
const float height_f = height
|
word persp = (rz+200) // height
|
||||||
float persp = (rz as float + 180.0)/height_f
|
byte sx = rotatedx[i] // persp as byte + width//2
|
||||||
byte sx = rotatedx[i] as float / persp as byte + width//2
|
byte sy = rotatedy[i] // persp as byte + height//2
|
||||||
byte sy = rotatedy[i] as float / persp as byte + height//2
|
c64scr.setcc(sx as ubyte, sy as ubyte, 46, i+2)
|
||||||
; @todo switch to this once idiv_w is implemented: (and remove c64flt import)
|
|
||||||
;word persp = (rz+180) // height
|
|
||||||
;byte sx = rotatedx[i] // persp as byte + width//2
|
|
||||||
;byte sy = rotatedy[i] // persp as byte + height//2
|
|
||||||
c64scr.setchrclr(sx as ubyte, sy as ubyte, 46, i+2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ubyte i in 0 to len(xcoor)-1 {
|
for ubyte i in 0 to len(xcoor)-1 {
|
||||||
word rz = rotatedz[i]
|
word rz = rotatedz[i]
|
||||||
if rz < 10 {
|
if rz < 10 {
|
||||||
const float height_f = height
|
word persp = (rz+200) // height
|
||||||
float persp = (rz as float + 180.0)/height_f
|
byte sx = rotatedx[i] // persp as byte + width//2
|
||||||
byte sx = rotatedx[i] as float / persp as byte + width//2
|
byte sy = rotatedy[i] // persp as byte + height//2
|
||||||
byte sy = rotatedy[i] as float / persp as byte + height//2
|
c64scr.setcc(sx as ubyte, sy as ubyte, 81, i+2)
|
||||||
; @todo switch to this once idiv_w is implemented: (and remove c64flt import)
|
|
||||||
;word persp = (rz+180) // height
|
|
||||||
;byte sx = rotatedx[i] // persp as byte + width//2
|
|
||||||
;byte sy = rotatedy[i] // persp as byte + height//2
|
|
||||||
c64scr.setchrclr(sx as ubyte, sy as ubyte, 81, i+2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,23 +14,11 @@
|
|||||||
while true {
|
while true {
|
||||||
float x = sin(t)
|
float x = sin(t)
|
||||||
float y = cos(t*1.1356)
|
float y = cos(t*1.1356)
|
||||||
ubyte xx=screenx(x)
|
ubyte xx=(x * width/2.2) + width/2.0 as ubyte
|
||||||
ubyte yy=screeny(y)
|
ubyte yy=(y * height/2.2) + height/2.0 as ubyte
|
||||||
|
c64scr.setcc(xx, yy, 81, color)
|
||||||
;c64.COLOR = color
|
|
||||||
;c64scr.PLOT(xx,yy)
|
|
||||||
;c64.CHROUT('Q') ; shift-q = filled circle
|
|
||||||
c64scr.setchrclr(xx, yy, 81, color)
|
|
||||||
|
|
||||||
t += 0.08
|
t += 0.08
|
||||||
color++
|
color++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub screenx(float x) -> ubyte {
|
|
||||||
return (x * width/2.2) + width/2.0 as ubyte
|
|
||||||
}
|
|
||||||
sub screeny(float y) -> ubyte {
|
|
||||||
return (y * height/2.2) + height/2.0 as ubyte
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
word y = cos8(msb(angley)) as word
|
word y = cos8(msb(angley)) as word
|
||||||
ubyte xx=msb(x*39) + 20 ; -127..127 -> 0..39
|
ubyte xx=msb(x*39) + 20 ; -127..127 -> 0..39
|
||||||
ubyte yy=msb(y*24) + 12 ; -127..127 -> 0..24
|
ubyte yy=msb(y*24) + 12 ; -127..127 -> 0..24
|
||||||
c64scr.setchrclr(xx, yy, 81, color)
|
c64scr.setcc(xx, yy, 81, color)
|
||||||
|
|
||||||
anglex+=800
|
anglex+=800
|
||||||
angley+=947
|
angley+=947
|
||||||
|
@ -21,32 +21,33 @@
|
|||||||
word w4
|
word w4
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
w1 = 120
|
w1 = 12000
|
||||||
w2 = -13
|
w2 = -333 ; -333
|
||||||
w3 = w1 // w2
|
w3 = w1 // w2
|
||||||
c64scr.print_w(w3)
|
c64scr.print_w(w3)
|
||||||
c64.CHROUT(':')
|
c64.CHROUT('\n')
|
||||||
w1 = -120
|
w1 = -12000 ; -12000
|
||||||
w2 = 13
|
w2 = 333
|
||||||
w3 = w1 // w2
|
w3 = w1 // w2
|
||||||
c64scr.print_w(w3)
|
c64scr.print_w(w3)
|
||||||
c64.CHROUT(':')
|
c64.CHROUT('\n')
|
||||||
w2 = 13
|
w2 = 4444
|
||||||
w3 = w1 // w2
|
w3 = w1 // w2
|
||||||
c64scr.print_w(w3)
|
c64scr.print_w(w3)
|
||||||
c64.CHROUT(':')
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
w3 = w1 // -5
|
w3 = w1 // -5 ; -5
|
||||||
c64scr.print_w(w3)
|
c64scr.print_w(w3)
|
||||||
c64.CHROUT(':')
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
w3 = w1 // -7
|
w3 = w1 // -7 ; -7
|
||||||
c64scr.print_w(w3)
|
c64scr.print_w(w3)
|
||||||
c64.CHROUT(':')
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
w3 = w1 // -99
|
w1 = -w1
|
||||||
|
w3 = w1 // -999 ;-999
|
||||||
c64scr.print_w(w3)
|
c64scr.print_w(w3)
|
||||||
c64.CHROUT(':')
|
c64.CHROUT('\n')
|
||||||
|
|
||||||
c64scr.print_ub(X)
|
c64scr.print_ub(X)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT('\n')
|
||||||
|
@ -1065,10 +1065,10 @@ _colorrows .word $d800 + range(0, 1000, 40)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub setchrclr (ubyte column, ubyte row, ubyte char, ubyte color) {
|
sub setcc (ubyte column, ubyte row, ubyte char, ubyte color) {
|
||||||
; ---- set char+color at the given position on the screen
|
; ---- set char+color at the given position on the screen
|
||||||
%asm {{
|
%asm {{
|
||||||
lda setchrclr_row
|
lda setcc_row
|
||||||
asl a
|
asl a
|
||||||
tay
|
tay
|
||||||
lda setchr._screenrows+1,y
|
lda setchr._screenrows+1,y
|
||||||
@ -1077,15 +1077,15 @@ sub setchrclr (ubyte column, ubyte row, ubyte char, ubyte color) {
|
|||||||
sta _colormod+2
|
sta _colormod+2
|
||||||
lda setchr._screenrows,y
|
lda setchr._screenrows,y
|
||||||
clc
|
clc
|
||||||
adc setchrclr_column
|
adc setcc_column
|
||||||
sta _charmod+1
|
sta _charmod+1
|
||||||
sta _colormod+1
|
sta _colormod+1
|
||||||
bcc +
|
bcc +
|
||||||
inc _charmod+2
|
inc _charmod+2
|
||||||
inc _colormod+2
|
inc _colormod+2
|
||||||
+ lda setchrclr_char
|
+ lda setcc_char
|
||||||
_charmod sta $ffff ; modified
|
_charmod sta $ffff ; modified
|
||||||
lda setchrclr_color
|
lda setcc_color
|
||||||
_colormod sta $ffff ; modified
|
_colormod sta $ffff ; modified
|
||||||
rts
|
rts
|
||||||
}}
|
}}
|
||||||
|
@ -165,11 +165,11 @@ mul_word .proc
|
|||||||
|
|
||||||
idiv_b .proc
|
idiv_b .proc
|
||||||
; signed division: use unsigned division and fix sign of result afterwards
|
; signed division: use unsigned division and fix sign of result afterwards
|
||||||
lda c64.ESTACK_LO+1,x
|
|
||||||
eor c64.ESTACK_LO+2,x
|
|
||||||
php ; save sign of result
|
|
||||||
inx
|
inx
|
||||||
lda c64.ESTACK_LO,x
|
lda c64.ESTACK_LO,x
|
||||||
|
eor c64.ESTACK_LO+1,x
|
||||||
|
php ; save sign of result
|
||||||
|
lda c64.ESTACK_LO,x
|
||||||
bpl +
|
bpl +
|
||||||
eor #$ff
|
eor #$ff
|
||||||
sec
|
sec
|
||||||
@ -206,7 +206,31 @@ idiv_ub .proc
|
|||||||
.pend
|
.pend
|
||||||
|
|
||||||
idiv_w .proc
|
idiv_w .proc
|
||||||
.error "idiv_w not yet implemented"
|
; signed division: use unsigned division and fix sign of result afterwards
|
||||||
|
lda c64.ESTACK_HI+2,x
|
||||||
|
eor c64.ESTACK_HI+1,x
|
||||||
|
php ; save sign of result
|
||||||
|
lda c64.ESTACK_HI+1,x
|
||||||
|
bpl +
|
||||||
|
jsr neg_w ; make value positive
|
||||||
|
+ inx
|
||||||
|
lda c64.ESTACK_HI+1,x
|
||||||
|
bpl +
|
||||||
|
jsr neg_w ; make value positive
|
||||||
|
+ lda c64.ESTACK_LO+1,x
|
||||||
|
sta c64.SCRATCH_ZPWORD1
|
||||||
|
lda c64.ESTACK_HI+1,x
|
||||||
|
sta c64.SCRATCH_ZPWORD1+1
|
||||||
|
lda c64.ESTACK_LO,x
|
||||||
|
ldy c64.ESTACK_HI,x
|
||||||
|
jsr math.divmod_uw_asm
|
||||||
|
sta c64.ESTACK_LO+1,x
|
||||||
|
tya
|
||||||
|
sta c64.ESTACK_HI+1,x
|
||||||
|
plp
|
||||||
|
bpl +
|
||||||
|
jmp neg_w ; negate result
|
||||||
|
+ rts
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
idiv_uw .proc
|
idiv_uw .proc
|
||||||
|
Loading…
Reference in New Issue
Block a user