home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Go64!
/
Go64_2002-11_2002_CSW_Side_B.d64
/
rotflatshadn.txt
< prev
next >
Wrap
Text File
|
2023-02-26
|
48KB
|
2,259 lines
; go64! tutorial on 3-d graphics
; part 8: flat shading
; go64! 3d-kurs
; teil 8: flat shading
sincoslo = $4d00
sincoshi = $4f00
log2tabl = $5480
log2tbh0 = $5500
log2tbh1 = $5580
reciptbl = $5600
reciptbh = $5700
persptab = $5800
vicbank = %00000011; $0000-$4000
v = vicbank($03*$4000;=$0000
scrn = $0400
spdxofsl = $0e00
spdxofsh = $0f00
charset0 = $2000
charset1 = $2800
charset2 = $3000
fillbuff = $3800
spidcod0 = $5900
spidcod1 = $6480
spidcod2 = $7000
filspid0 = $7b80
filspid1 = $a300
filspid2 = $ca80
eraspeed = $f200
spdt1ofs = $0400
spdt2ofs = $07c0
basezp = $02
currscrn = $00+basezp
pointers = $01+basezp
alphalo = $04+basezp
betalo = $05+basezp
gammalo = $06+basezp
alphahi = $07+basezp
betahi = $08+basezp
gammahi = $09+basezp
alpha = $0a+basezp
beta = $0b+basezp
gamma = $0c+basezp
sinbufl0 = $0d+basezp
sinbufh0 = $0e+basezp
sinbufl1 = $0f+basezp
sinbufh1 = $10+basezp
unitxxlo = $11+basezp
unitxxhi = $12+basezp
unitxylo = $13+basezp
unitxyhi = $14+basezp
unitxzlo = $15+basezp
unitxzhi = $16+basezp
unityxlo = $17+basezp
unityxhi = $18+basezp
unityylo = $19+basezp
unityyhi = $1a+basezp
unityzlo = $1b+basezp
unityzhi = $1c+basezp
unitzxlo = $1d+basezp
unitzxhi = $1e+basezp
unitzylo = $1f+basezp
unitzyhi = $20+basezp
unitzzlo = $21+basezp
unitzzhi = $22+basezp
x2dcords = $27+basezp
y2dcords = $2f+basezp
z2dcords = $37+basezp
oldxcrds = $3f+basezp
oldycrds = $47+basezp
oldvisib = $4f+basezp
begx = $0d+basezp
endx = $0e+basezp
begy = $0f+basezp
endy = $10+basezp
deltax = $11+basezp
deltay = $12+basezp
linslopl = $13+basezp
linsloph = $14+basezp
multizpg = $15+basezp
cullbuff = $17+basezp
visiblin = $19+basezp
cntdepth = $5b+basezp
coltable = $61+basezp
backgndc = $06
xpos = $0c; char matrix coordinates
ypos = $05; zeichenmatrixkoordinaten
alphaadd = $ff55
betaadd = $0255; angle add values
gammaadd = $0100; winkeladditionswerte
numpoint = $08
*= $4000
sei
lda #$35
sta $01
lda #<return;nmi
sta $fffa
lda #>return;nmi
sta $fffb
bit $d011
bpl *-$03
bit $d011
bmi *-$03
lda #$00
sta $d011
lda #backgndc
sta $d020
; build tables
; tabellen generieren
lda #spidraw1-spidraw0
ldx #$00
jsr mkxofstb
lda #spidrawe-spidraw1
ldx #$40
jsr mkxofstb
lda #erasraw1-erasraw0
ldx #$80
jsr mkxofstb
lda #erasrawe-erasraw1
ldx #$c0
jsr mkxofstb
ldx #$00
lda sincoslo+$00,x
sta sincoslo+$0100,x
lda sincoshi+$00,x
sta sincoshi+$0100,x
inx
bne *-$0d
; build speedcode
; speedcode generieren
lda #%01000000
ldx #<spidcod0
ldy #>spidcod0
jsr maklinsp
lda #%10000000
ldx #<spidcod1
ldy #>spidcod1
jsr maklinsp
lda #%11000000
ldx #<spidcod2
ldy #>spidcod2
jsr maklinsp
lda #$30
sta $01
lda #>charset0+v
ldx #<filspid0
ldy #>filspid0
jsr mkfilspd
lda #>charset1+v
ldx #<filspid1
ldy #>filspid1
jsr mkfilspd
lda #>charset2+v
ldx #<filspid2
ldy #>filspid2
jsr mkfilspd
lda #$35
sta $01
clc
lda #<eraspeed
sta pointers+$00
sta pointers+$02
lda #>eraspeed
sta pointers+$01
sta pointers+$03
lda #>fillbuff
sta pointers+$04
sta erasraw0+$04
lda #$04
sta pointers+$05
ldx #$40; 64 pixels width
; 64 pixel breite
mkers0lp ldy #erasraw1-erasraw0-$01
lda erasraw0,y
sta (pointers+$00),y
dey
bpl mkers0lp+$02
lda #erasraw1-erasraw0
ldy #erasraw0-erasraw0
jsr nexteras
bne mkers0lp+$00
lda #$88; op-code for dey
; op-code fuer dey
ldx #<eraspeed+$0340
ldy #>eraspeed+$0340
jsr mkers1sb
lda #$c8; op-code for iny
; op-code fuer iny
ldx #<eraspeed+$0640
ldy #>eraspeed+$0640
jsr mkers1sb
; clear the charsets and the
; filling buffer
; die zeichensaetze und den
; fuellpuffer loeschen
ldy #<charset0+v
sty pointers+$00
sty pointers+$02
sty pointers+$04
lda #>charset0+v
sta pointers+$01
lda #>charset1+v
sta pointers+$03
lda #>charset2+v
sta pointers+$05
lda #<fillbuff
sta pointers+$06
lda #>fillbuff
sta pointers+$07
ldx #$08
clearchr lda #%11111111
sta (pointers+$00),y
sta (pointers+$02),y
sta (pointers+$04),y
lda #%00000000
sta (pointers+$06),y
iny
bne clearchr
inc pointers+$01
inc pointers+$03
inc pointers+$05
inc pointers+$07
dex
bne clearchr
; clear screen
; bildschirm loeschen
lda #$00
tax
sta scrn+v+$00,x
sta scrn+v+$0100,x
sta scrn+v+$0200,x
sta scrn+v+$0300,x
inx
bne *-$0d
; set up screen matrix
; bildschirmmatrix bilden
clc
lda #<xpos+(ypos*$28)+scrn+v
sta pointers+$00
lda #>xpos+(ypos*$28)+scrn+v
sta pointers+$01
ldx #$00
setupscr txa
ldy #$00
sta (pointers+$00),y
adc #$10
iny
cpy #$10
bne setupscr+$03
lda #$27
adc pointers+$00
sta pointers+$00
bcc *+$04
inc pointers+$01
inx
cpx #$10
bne setupscr
; init colours
; farben initialisieren
lda #backgndc
sta $d021
sta $d022
sta $d023
lda #backgndc.$08; multicolour
ldx #$00
sta $d800,x
sta $d900,x
sta $da00,x
sta $db00,x
inx
bne *-$0d
stx currscrn
; set vic registers
; vic-register setzen
bit $d011
bpl *-$03
bit $d011
bmi *-$03
lda #%00011011
sta $d011
lda #%00011000
sta $d016
lda #scrn/64.(charset0/1024).1
sta $d018
lda $dd00
and #%11111100
ora #vicbank
sta $dd00
lda #$ff
sta $d012
lda #$01
sta $d01a
lda #$7f
sta $dc0d
lda #<irq
sta $fffe
lda #>irq
sta $ffff
bit $dc0d
dec $d019
cli
; reset angles and coordinates
; koordinaten&winkel nullsetzen
lda #$00
ldx #numpoint-$01
sta oldvisib,x
dex
bpl *-$03
sta alphalo
sta betalo
sta gammalo
sta alphahi
sta betahi
sta gammahi
; main loop
; hauptschleife
mainloop ; rotate unit vectors
; (absolutely unoptimized)
; einheitsvektoren rotieren
; (absolut unoptimiert)
sei
lda alphahi
sta alpha
lda gammahi
sta gamma
lda betahi
sta beta
cli
; cos (beta) * cos (gamma)
clc
adc #$40 ; (cos)
sec
sbc gamma
sec
sbc #$40 ; (cos)
tax ; beta-gamma
clc
lda beta
adc #$40 ; (cos)
clc
adc gamma
clc
adc #$40 ; (cos)
tay ; beta+gamma
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta unitxxlo
lda sincoshi+$40,x; cos(b-g)
sbc sincoshi+$40,y; - cos(b+g)
sta unitxxhi
; - sin(a) * sin(b) * cos(g)
; - cos(a) * sin(g)
clc
lda beta
adc gamma
clc
adc #$40 ; (cos)
sec
sbc alpha
sec
sbc #$80 ; (-)
tax ; beta+gamma-alpha
clc
lda alpha
adc #$80 ; (-)
clc
adc gamma
clc
adc #$40 ; (cos)
sec
sbc beta
tay ; alpha+gamma-beta
clc
lda sincoslo+$00,x
adc sincoslo+$00,y
sta sinbufl0
lda sincoshi+$00,x; sin(b+g-a)
adc sincoshi+$00,y;+ sin(a+g-b)
cmp #$80
ror a
ror sinbufl0
sta sinbufh0
clc
lda alpha
adc #$80 ; (-)
clc
adc beta
sec
sbc gamma
sec
sbc #$40 ; (cos)
tax ; alpha+beta-gamma
clc
lda alpha
adc #$80 ; (-)
clc
adc beta
clc
adc gamma
clc
adc #$40 ; (cos)
tay ; alpha+beta+gamma
sec
lda sincoslo+$00,x
sbc sincoslo+$00,y
sta sinbufl1
lda sincoshi+$00,x; sin(a+b-g)
sbc sincoshi+$00,y;- sin(a+b+g)
cmp #$80
ror a
tax
lda sinbufl1
ror a
clc
adc sinbufl0
sta sinbufl1
txa
adc sinbufh0; - sin(a) * sin(b)
sta sinbufh1; * cos(g)
clc
lda alpha
adc #$40+$80 ; (-cos)
sec
sbc gamma
tax ; alpha-gamma
clc
lda alpha
adc #$40+$80 ; (-cos)
clc
adc gamma
tay ; alpha+gamma
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta sinbufl0 ; cos(a-g)
lda sincoshi+$40,x; - cos(a+g)
sbc sincoshi+$40,y
sta sinbufh0 ; - cos(a)*sin(g)
clc
lda sinbufl0
adc sinbufl1
sta unitxylo
lda sinbufh0
adc sinbufh1
sta unitxyhi
; cos(a) * sin(b) * cos(g)
; - sin(a) * sin(g)
clc
lda beta
adc gamma
clc
adc #$40 ; (cos)
sec
sbc alpha
sec
sbc #$40 ; (cos)
tax ; beta+gamma-alpha
clc
lda alpha
adc #$40 ; (cos)
clc
adc gamma
clc
adc #$40 ; (cos)
sec
sbc beta
tay ; alpha+gamma-beta
clc
lda sincoslo+$00,x
adc sincoslo+$00,y
sta sinbufl0
lda sincoshi+$00,x; sin(b+g-a)
adc sincoshi+$00,y;+ sin(a+g-b)
cmp #$80
ror a
ror sinbufl0
sta sinbufh0
clc
lda alpha
adc #$40 ; (cos)
clc
adc beta
sec
sbc gamma
sec
sbc #$40 ; (cos)
tax ; alpha+beta-gamma
clc
lda alpha
adc #$40 ; (cos)
clc
adc beta
clc
adc gamma
clc
adc #$40 ; (cos)
tay ; alpha+beta+gamma
sec
lda sincoslo+$00,x
sbc sincoslo+$00,y
sta sinbufl1
lda sincoshi+$00,x; sin(a+b-g)
sbc sincoshi+$00,y;- sin(a+b+g)
cmp #$80
ror a
tax
lda sinbufl1
ror a
clc
adc sinbufl0
sta sinbufl1
txa
adc sinbufh0; cos(a) * sin(b)
sta sinbufh1; * cos(g)
clc
lda alpha
adc #$80 ; (-)
sec
sbc gamma
tax ; alpha-gamma
clc
lda alpha
adc #$80 ; (-)
clc
adc gamma
tay ; alpha+gamma
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta sinbufl0 ; cos(a-g)
lda sincoshi+$40,x; - cos(a+g)
sbc sincoshi+$40,y
sta sinbufh0 ; - sin(a)*sin(g)
clc
lda sinbufl0
adc sinbufl1
sta unitxzlo
lda sinbufh0
adc sinbufh1
sta unitxzhi
; - cos (beta) * sin (gamma)
clc
lda beta
adc #$40+$80 ; (-cos)
sec
sbc gamma
tax ; beta-gamma
clc
lda beta
adc #$40+$80 ; (-cos)
clc
adc gamma
tay ; beta+gamma
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta unityxlo
lda sincoshi+$40,x; cos(b-g)
sbc sincoshi+$40,y; - cos(b+g)
sta unityxhi
; sin(a) * sin(b) * sin(g)
; - cos(a) * cos(g)
clc
lda beta
adc gamma
sec
sbc alpha
tax ; beta+gamma-alpha
clc
lda alpha
adc gamma
sec
sbc beta
tay ; alpha+gamma-beta
clc
lda sincoslo+$00,x
adc sincoslo+$00,y
sta sinbufl0
lda sincoshi+$00,x; sin(b+g-a)
adc sincoshi+$00,y;+ sin(a+g-b)
cmp #$80
ror a
ror sinbufl0
sta sinbufh0
clc
lda alpha
adc beta
sec
sbc gamma
tax ; alpha+beta-gamma
clc
lda alpha
adc beta
clc
adc gamma
tay ; alpha+beta+gamma
sec
lda sincoslo+$00,x
sbc sincoslo+$00,y
sta sinbufl1
lda sincoshi+$00,x; sin(a+b-g)
sbc sincoshi+$00,y;- sin(a+b+g)
cmp #$80
ror a
tax
lda sinbufl1
ror a
clc
adc sinbufl0
sta sinbufl1
txa
adc sinbufh0; sin(a) * sin(b)
sta sinbufh1; * sin(g)
clc
lda alpha
adc #$40+$80 ; (-cos)
sec
sbc gamma
sec
sbc #$40 ; (cos)
tax ; alpha-gamma
clc
lda alpha
adc #$40+$80 ; (-cos)
clc
adc gamma
clc
adc #$40 ; (cos)
tay ; alpha+gamma
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta sinbufl0 ; cos(a-g)
lda sincoshi+$40,x; - cos(a+g)
sbc sincoshi+$40,y
sta sinbufh0 ; - cos(a)*cos(g)
clc
lda sinbufl0
adc sinbufl1
sta unityylo
lda sinbufh0
adc sinbufh1
sta unityyhi
; - cos(a) * sin(b) * sin(g)
; - sin(a) * cos(g)
clc
lda beta
adc gamma
sec
sbc alpha
sec
sbc #$40+$80 ; (-cos)
tax ; beta+gamma-alpha
clc
lda alpha
adc #$40+$80 ; (-cos)
clc
adc gamma
sec
sbc beta
tay ; alpha+gamma-beta
clc
lda sincoslo+$00,x
adc sincoslo+$00,y
sta sinbufl0
lda sincoshi+$00,x; sin(b+g-a)
adc sincoshi+$00,y;+ sin(a+g-b)
cmp #$80
ror a
ror sinbufl0
sta sinbufh0
clc
lda alpha
adc #$40+$80 ; (-cos)
clc
adc beta
sec
sbc gamma
tax ; alpha+beta-gamma
clc
lda alpha
adc #$40+$80 ; (-cos)
clc
adc beta
clc
adc gamma
tay ; alpha+beta+gamma
sec
lda sincoslo+$00,x
sbc sincoslo+$00,y
sta sinbufl1
lda sincoshi+$00,x; sin(a+b-g)
sbc sincoshi+$00,y;- sin(a+b+g)
cmp #$80
ror a
tax
lda sinbufl1
lsr a
clc
adc sinbufl0
sta sinbufl1
txa
adc sinbufh0; - cos(a) * sin(b)
sta sinbufh1; * sin(g)
clc
lda alpha
adc #$80 ; (-)
sec
sbc gamma
sec
sbc #$40 ; (cos)
tax ; alpha-gamma
clc
lda alpha
adc #$80 ; (-)
clc
adc gamma
clc
adc #$40 ; (cos)
tay ; alpha+gamma
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta sinbufl0 ; cos(a-g)
lda sincoshi+$40,x; - cos(a+g)
sbc sincoshi+$40,y
sta sinbufh0 ; - sin(a)*cos(g)
clc
lda sinbufl0
adc sinbufl1
sta unityzlo
lda sinbufh0
adc sinbufh1
sta unityzhi
; sin (beta)
ldx beta
lda sincoslo+$00,x
asl a
sta unitzxlo
lda sincoshi+$00,x
rol a
sta unitzxhi
; sin (alpha) * cos (beta)
sec
lda alpha
sbc beta
sec
sbc #$40 ; (cos)
tax ; alpha-beta
clc
lda alpha
adc beta
clc
adc #$40 ; (cos)
tay ; alpha+beta
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta unitzylo
lda sincoshi+$40,x; cos(a-b)
sbc sincoshi+$40,y; - cos(a+b)
sta unitzyhi
; - cos (alpha) * cos (beta)
clc
lda alpha
adc #$80+$40 ; (-cos)
sec
sbc beta
sec
sbc #$40 ; (cos)
tax ; alpha-beta
clc
lda alpha
adc #$80+$40 ; (-cos)
clc
adc beta
clc
adc #$40 ; (cos)
tay ; alpha+beta
sec
lda sincoslo+$40,x
sbc sincoslo+$40,y
sta unitzzlo
lda sincoshi+$40,x; cos(a-b)
sbc sincoshi+$40,y; - cos(a+b)
sta unitzzhi
; calculate new coordinates,
; pretty unoptimized too
; neue koordinaten berechnen,
; auch ziemlich unoptimiert
; p(-1;+1;+1)
clc
lda unitxylo
adc unitxzlo
tax
lda unitxyhi
adc unitxzhi
cpx unitxxlo
sbc unitxxhi
sta x2dcords+$00
clc
lda unityylo
adc unityzlo
tax
lda unityyhi
adc unityzhi
cpx unityxlo
sbc unityxhi
sta y2dcords+$00
clc
lda unitzylo
adc unitzzlo
tax
lda unitzyhi
adc unitzzhi
cpx unitzxlo
sbc unitzxhi
sta z2dcords+$00
; p(+1;+1;+1)
clc
lda unitxxlo
adc unitxylo
tax
lda unitxxhi
adc unitxyhi
tay
clc
txa
adc unitxzlo
tya
adc unitxzhi
sta x2dcords+$01
clc
lda unityxlo
adc unityylo
tax
lda unityxhi
adc unityyhi
tay
clc
txa
adc unityzlo
tya
adc unityzhi
sta y2dcords+$01
clc
lda unitzxlo
adc unitzylo
tax
lda unitzxhi
adc unitzyhi
tay
clc
txa
adc unitzzlo
tya
adc unitzzhi
sta z2dcords+$01
; p(-1;+1;-1)
sec
lda unitxylo
sbc unitxxlo
tax
lda unitxyhi
sbc unitxxhi
cpx unitxzlo
sbc unitxzhi
sta x2dcords+$02
sec
lda unityylo
sbc unityxlo
tax
lda unityyhi
sbc unityxhi
cpx unityzlo
sbc unityzhi
sta y2dcords+$02
sec
lda unitzylo
sbc unitzxlo
tax
lda unitzyhi
sbc unitzxhi
cpx unitzzlo
sbc unitzzhi
sta z2dcords+$02
; p(+1;+1;-1)
clc
lda unitxxlo
adc unitxylo
tax
lda unitxxhi
adc unitxyhi
cpx unitxzlo
sbc unitxzhi
sta x2dcords+$03
clc
lda unityxlo
adc unityylo
tax
lda unityxhi
adc unityyhi
cpx unityzlo
sbc unityzhi
sta y2dcords+$03
clc
lda unitzxlo
adc unitzylo
tax
lda unitzxhi
adc unitzyhi
cpx unitzzlo
sbc unitzzhi
sta z2dcords+$03
; p(-1;-1;+1)
sec
lda unitxzlo
sbc unitxxlo
tax
lda unitxzhi
sbc unitxxhi
cpx unitxylo
sbc unitxyhi
sta x2dcords+$04
sec
lda unityzlo
sbc unityxlo
tax
lda unityzhi
sbc unityxhi
cpx unityylo
sbc unityyhi
sta y2dcords+$04
sec
lda unitzzlo
sbc unitzxlo
tax
lda unitzzhi
sbc unitzxhi
cpx unitzylo
sbc unitzyhi
sta z2dcords+$04
; p(+1;-1;+1)
clc
lda unitxxlo
adc unitxzlo
tax
lda unitxxhi
adc unitxzhi
cpx unitxylo
sbc unitxyhi
sta x2dcords+$05
clc
lda unityxlo
adc unityzlo
tax
lda unityxhi
adc unityzhi
cpx unityylo
sbc unityyhi
sta y2dcords+$05
clc
lda unitxzlo
adc unitzzlo
tax
lda unitzxhi
adc unitzzhi
cpx unitzylo
sbc unitzyhi
sta z2dcords+$05
; p(-1;-1;-1)
sec
lda #$00
sbc unitxxlo
tax
lda #$00
sbc unitxxhi
tay
sec
txa
sbc unitxylo
tax
tya
sbc unitxyhi
cpx unitxzlo
sbc unitxzhi
sta x2dcords+$06
sec
lda #$00
sbc unityxlo
tax
lda #$00
sbc unityxhi
tay
sec
txa
sbc unityylo
tax
tya
sbc unityyhi
cpx unityzlo
sbc unityzhi
sta y2dcords+$06
sec
lda #$00
sbc unitzxlo
tax
lda #$00
sbc unitzxhi
tay
sec
txa
sbc unitzylo
tax
tya
sbc unitzyhi
cpx unitzzlo
sbc unitzzhi
sta z2dcords+$06
; p(+1;-1;-1)
sec
lda unitxxlo
sbc unitxylo
tax
lda unitxxhi
sbc unitxyhi
cpx unitxzlo
sbc unitxzhi
sta x2dcords+$07
sec
lda unityxlo
sbc unityylo
tax
lda unityxhi
sbc unityyhi
cpx unityzlo
sbc unityzhi
sta y2dcords+$07
sec
lda unitzxlo
sbc unitzylo
tax
lda unitzxhi
sbc unitzyhi
cpx unitzzlo
sbc unitzzhi
sta z2dcords+$07
; store depth of the
; face centroids
; tiefe der flaechen-
; mittelpunkte ablegen
; p( 1; 0; 0)
lda unityxhi
sta cntdepth+$02
; p(-1; 0; 0)
clc
eor #$ff
adc #$01
sta cntdepth+$04
; p( 0; 1; 0)
lda unityyhi
sta cntdepth+$00
; p( 0;-1; 0)
clc
eor #$ff
adc #$01
sta cntdepth+$05
; p( 0; 0; 1)
lda unityzhi
sta cntdepth+$01
; p( 0; 0;-1)
clc
eor #$ff
adc #$01
sta cntdepth+$03
; convert coordinates to 2-d
; koordinaten nach 2d wandeln
ldx #numpoint-$01
convto2d ldy y2dcords,x
lda persptab,y
ldy x2dcords,x
jsr perspmul
clc
adc #$40
lsr a ; multicolour
sta x2dcords,x
ldy y2dcords,x
lda persptab,y
ldy z2dcords,x
jsr perspmul
clc
adc #$40
sta y2dcords,x
dex
bpl convto2d
; perform backface culling
; backface culling vollfuehren
lda #%00000000
ldx #linepnt1-linepnt0-$01
sta visiblin,x
dex
bpl *-$03
ldx #facepnt1-facepnt0-$01
backcull sec
ldy facepnt0,x; z1 - z2
lda y2dcords,y
ldy facepnt1,x
sbc y2dcords,y
pha
sec
ldy facepnt2,x; x3 - x2
lda x2dcords,y
ldy facepnt1,x
sbc x2dcords,y
tay
pla
jsr cullmul
sta cullbuff+$00
sty cullbuff+$01
sec
ldy facepnt0,x; x1 - x2
lda x2dcords,y
ldy facepnt1,x
sbc x2dcords,y
pha
sec
ldy facepnt2,x; z3 - z2
lda y2dcords,y
ldy facepnt1,x
sbc y2dcords,y
tay
pla
jsr cullmul
cpy cullbuff+$01; compare
sbc cullbuff+$00; factors
bpl notvisib
lda facecols,x
ldy facelin0,x
eor visiblin,y
sta visiblin,y
lda facecols,x
ldy facelin1,x
eor visiblin,y
sta visiblin,y
lda facecols,x
ldy facelin2,x
eor visiblin,y
sta visiblin,y
lda facecols,x
ldy facelin3,x
eor visiblin,y
sta visiblin,y
lda facecols,x; assign the
eor #%00000011; depth values
tay ; tiefenwerte
lda cntdepth,x; zuweisen
sta coltable,y
notvisib dex
bmi *+$05
jmp backcull
; erase vector object
; vektorobjekt loeschen
ldy #linepnt1-linepnt0-$01
erasloop lda oldvisib,y
beq donteras
sty pointers+$02
ldx linepnt0,y
lda oldxcrds,x
sta begx
lda oldycrds,x
sta begy
ldx linepnt1,y
lda oldxcrds,x
ldy oldycrds,x
tax
jsr erasline
ldy pointers+$02
donteras dey
bpl erasloop
; draw vector object
; vektorobjekt zeichnen
ldy #linepnt1-linepnt0-$01
drawloop lda visiblin,y
beq dontdraw
pha
sty pointers+$02
ldx linepnt0,y
lda x2dcords,x
sta begx
lda y2dcords,x
sta begy
ldx linepnt1,y
lda x2dcords,x
ldy y2dcords,x
tax
pla
jsr drawline
ldy pointers+$02
dontdraw dey
bpl drawloop
ldx #linepnt1-linepnt0-$01
putoldvi lda visiblin,x
sta oldvisib,x
dex
bpl putoldvi
ldx #numpoint-$01
putoldco lda x2dcords,x
sta oldxcrds,x
lda y2dcords,x
sta oldycrds,x
dex
bpl putoldco
; fill the object
; das objekt fuellen
ldx currscrn
lda scrntabl+$01,x
cmp $d018
beq *-$03
lda #$30
sta $01
lda #%11111111
dex
bpl *+$08
jsr filspid2
jmp postfill
dex
bpl *+$08
jsr filspid0
jmp postfill
jsr filspid1
postfill lda #$35
sta $01
; switch visible screen
; sichtbaren bildschirm
; umschalten
ldx currscrn
inx
cpx #$03
bne *+$04
ldx #$00
stx currscrn
jmp mainloop
; irq routine
; irq-routine
irq pha
txa
pha
lda $01
pha
lda #$35
sta $01
; update screen and colours
; bildschirm und farben
; aktualisieren
lda #$00; some colour interlace
eor #$01; etwas farbinterlace
sta *-$03
lsr a
ldx currscrn
lda scrntabl,x
sta $d018
ldx coltable+$00
bcc *+$03
inx
lda brightab-$b6,x
sta $d021
ldx coltable+$01
bcc *+$03
inx
lda brightab-$b6,x
sta $d022
ldx coltable+$02
bcc *+$03
inx
lda brightab-$b6,x
sta $d023
; advance angles
; winkel erhoehen
clc
lda #<alphaadd
adc alphalo
sta alphalo
lda #>alphaadd
adc alphahi
sta alphahi
clc
lda #<betaadd
adc betalo
sta betalo
lda #>betaadd
adc betahi
sta betahi
clc
lda #<gammaadd
adc gammalo
sta gammalo
lda #>gammaadd
adc gammahi
sta gammahi
dec $d019
pla
sta $01
pla
tax
pla
rti
; perform multiply, fully
; optimized
; multiplikation vollfuehren,
; vollkommen optimiert
pla
zeromul lda #$00
tay
rts
cullmul beq zeromul+$02
pha
tya
beq zeromul-$01
sec
ldy #$00
sbc #$01
bpl *+$07
eor #$ff
sbc #$01
iny
sta multizpg+$01
pla
bne mulmain
perspmul sec
sbc #$01
bcc zeromul+$00
sta multizpg+$01
tya
beq zeromul+$03
ldy #$00
mulmain cmp #$80
bcc *+$07
dey
sbc #$01
eor #$ff
lsr a
sta multizpg+$00
lda #$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
bcc *+$04
adc multizpg+$01
ror a
ror multizpg+$00
cpy #$00
bne *+$05
ldy multizpg+$00
rts
sta multizpg+$01
lda #$00
sbc multizpg+$00
tay
lda #$00
sbc multizpg+$01
rts
; draw a line
; eine linie zeichnen
drawline sta pointers+$00
stx endx
sty endy
cpx begx
beq drawline-$01
bcs *+$0e; swap line end points
lda begx ; if the line runs
sta endx ; from right to left
lda begy ; linienendpunkte ver-
sta endy ; tauschen, wenn die
stx begx ; linie von rechts
sty begy ; nach links verlaeuft
sec
lda endx
sbc begx
sta deltax
lda begy
sbc endy
bcc lintype2
sta deltay
cmp deltax
bcs lintype3
; line angles from -45 to 0
; degrees
; linienwinkel von -45 bis 0
; grad
lintype1 lda #<spdt1ofs
pha
lda #>spdt1ofs
bcc putline
lintype2 eor #$ff
adc #$01
sta deltay
cmp deltax
bcs lintype3
; line angles from 0 to 45
; degrees
; linienwinkel von 0 bis 45
; grad
lda #<spdt2ofs
pha
lda #>spdt2ofs
bcc putline
; line angles from +/-45 to
; +/-90 degrees
; linienwinkel von +/-45 bis
; +/-90 grad
lintype3 lda #$00
pha
putline pha
ldx deltax
ldy deltay
bcc *+$06
ldx deltay
ldy deltax
sec ;perform divi-
lda log2tabl,x ; sion to calc-
sbc log2tabl,y ; ulate the
sta clcslope+$01; line slope
lda log2tbh0,x ;division voll-
sbc log2tbh1,y ; fuehren, um
sta clcslope+$02; den linien-
clcslope lda !$00 ; anstieg zu
sta linslopl ; berechnen
clc
pla
tay
pla
ldx pointers+$00
adc spidadrl-$01,x
sta pointers+$00
tya
adc spidadrh-$01,x
sta pointers+$01
lda deltay
cmp deltax
ldx begx
bcs bigslope
lda pointers+$00 ; determine
adc spdxofsl+$40,x; jump-in
sta speedjsr+$01 ; address
lda pointers+$01 ; einsprung-
adc spdxofsh+$40,x; adresse
sta speedjsr+$02 ; bestimmen
ldx endx
dex
lda spdxofsl+$40,x
adc pointers+$00
sta pointers+$00
lda spdxofsh+$40,x
jmp linedraw
bigslope ldy linslopl ; determine
lda begy ; perpendi-
cmp endy ; cular
lda reciptbl,y ; slope
bcc *+$04
eor #$ff ; senkrechten
sta linslopl ; anstieg
lda reciptbh,y ; bestimmen
bcc *+$04
eor #$ff
sta linsloph
clc ; determine
lda pointers+$00 ; jump-in
adc spdxofsl+$00,x; address
sta speedjsr+$01
lda pointers+$01 ; einsprung-
adc spdxofsh+$00,x; adresse
sta speedjsr+$02 ; bestimmen
ldx endx
dex
lda spdxofsl+$00,x; determine
adc pointers+$00 ; return
sta pointers+$00 ; address
lda spdxofsh+$00,x; rueckkehr-
linedraw adc pointers+$01; adresse
sta pointers+$01; bestimmen
ldy #$08
lda #$60; op-code for rts
sta (pointers+$00),y; op-code
; fuer rts
ldx #$80
ldy begy
speedjsr jsr !$00; draw the line
; die linie zeichnen
ldy #$08
lda #$8a; op-code for txa
sta (pointers+$00),y; op-code
; fuer txa
rts
; erase a line
; eine linie loeschen
erasline sta pointers+$00
stx endx
sty endy
cpx begx
beq erasline-$01
bcs *+$0e; swap line end points
lda begx ; if the line runs
sta endx ; from right to left
lda begy ; linienendpunkte ver-
sta endy ; tauschen, wenn die
stx begx ; linie von rechts
sty begy ; nach links verlaeuft
sec
lda endx
sbc begx
sta deltax
lda begy
sbc endy
bcc erstype2
sta deltay
cmp deltax
bcs erstype3
; line angles from -45 to 0
; degrees
; linienwinkel von -45 bis 0
; grad
erstype1 ldx #<eraspeed+$0340
ldy #>eraspeed+$0340
bcc linerase
erstype2 eor #$ff
adc #$01
sta deltay
cmp deltax
bcs erstype3
; line angles from 0 to 45
; degrees
; linienwinkel von 0 bis 45
; grad
ldx #<eraspeed+$0640
ldy #>eraspeed+$0640
bcc linerase
; line angles from +/-45 to
; +/-90 degrees
; linienwinkel von +/-45 bis
; +/-90 grad
erstype3 ldx #<eraspeed+$00
ldy #>eraspeed+$00
linerase stx pointers+$00
sty pointers+$01
ldx deltax
ldy deltay
bcc *+$06
ldx deltay
ldy deltax
sec ;perform divi-
lda log2tabl,x ; sion to calc-
sbc log2tabl,y ; ulate the
sta eraslope+$01; line slope
lda log2tbh0,x ;division voll-
sbc log2tbh1,y ; fuehren, um
sta eraslope+$02; den linien-
eraslope lda !$00 ; anstieg zu
sta linslopl ; berechnen
lda deltay
cmp deltax
ldx begx
bcs ersbigsl
lda pointers+$00 ; determine
adc spdxofsl+$c0,x; jump-in
sta erasejsr+$01 ; address
lda pointers+$01 ; einsprung-
adc spdxofsh+$c0,x; adresse
sta erasejsr+$02 ; bestimmen
ldx endx
dex
lda spdxofsl+$c0,x
adc pointers+$00
sta pointers+$00
lda spdxofsh+$c0,x
jmp lineeras
ersbigsl ldy linslopl ; determine
lda begy ; perpendi-
cmp endy ; cular
lda reciptbl,y ; slope
bcc *+$04
eor #$ff ; senkrechten
sta linslopl ; anstieg
lda reciptbh,y ; bestimmen
bcc *+$04
eor #$ff
sta linsloph
clc ; determine
lda pointers+$00 ; jump-in
adc spdxofsl+$80,x; address
sta erasejsr+$01
lda pointers+$01 ; einsprung-
adc spdxofsh+$80,x; adresse
sta erasejsr+$02 ; bestimmen
ldx endx
dex
lda spdxofsl+$80,x; determine
adc pointers+$00 ; return
sta pointers+$00 ; address
lda spdxofsh+$80,x; rueckkehr-
lineeras adc pointers+$01; adresse
sta pointers+$01; bestimmen
ldy #$05
lda #$60; op-code for rts
sta (pointers+$00),y; op-code
; fuer rts
ldx #$80
ldy begy
erasejsr jsr !$00; draw the line
; die linie zeichnen
ldy #$05
lda #$8a; op-code for txa
sta (pointers+$00),y; op-code
; fuer txa
rts
mkxofstb clc
sta pointers+$00
txa
adc #$40
sta pointers+$01
lda #$00
tay
mkxofslp sta spdxofsl+$00,x
pha
tya
sta spdxofsh+$00,x
pla
clc
adc pointers+$00
bcc *+$03
iny
inx
cpx pointers+$01
bne mkxofslp
rts
; subroutine to build
; the line speedcode
; unterroutine zum generieren
; des linienspeedcodes
maklinsp clc
sta spidraw0+$01
sta spidraw1+$01
stx pointers+$02
sty pointers+$03
lda #>fillbuff
sta pointers+$04
lda pointers+$02
sta pointers+$00
lda pointers+$03
sta pointers+$01
lda pointers+$04
sta spidraw0+$04
sta spidraw0+$07
ldx #$40; 64 pixels width
; 64 pixel breite
mkspt0lp ldy #spidraw1-spidraw0-$01
lda spidraw0,y
sta (pointers+$00),y
dey
bpl mkspt0lp+$02
lda #spidraw1-spidraw0
ldy #spidraw0-spidraw0
jsr nextline
bne mkspt0lp+$00
lda #$88; op-code for dey
; op-code fuer dey
ldx #<spdt1ofs
ldy #>spdt1ofs
jsr mkspt1sb
lda #$c8; op-code for iny
; op-code fuer iny
ldx #<spdt2ofs
ldy #>spdt2ofs
mkspt1sb clc
sta sprw1dir
txa
adc pointers+$02
sta pointers+$00
tya
adc pointers+$03
sta pointers+$01
lda pointers+$04
sta spidraw1+$04
sta spidraw1+$07
ldx #$40; 64 pixels width
; 64 pixel breite
mkspt1lp ldy #spidrawe-spidraw1-$01
lda spidraw1,y
sta (pointers+$00),y
dey
bpl mkspt1lp+$02
lda #spidrawe-spidraw1
ldy #spidraw1-spidraw0
jsr nextline
bne mkspt1lp+$00
rts
nextline clc
adc pointers+$00
sta pointers+$00
bcc *+$04
inc pointers+$01
lda spidraw0+$01,y
pha
lsr a
pla
ror a
pha
lsr a
pla
ror a
sta spidraw0+$01,y
cmp #%01000000
bcc nxtspret
lda #$7f; 1 char column is 128
; (16x8) bytes
; 1 zeichenspalte sind
; 128 (16*8) bytes
adc spidraw0+$03,y
sta spidraw0+$03,y
sta spidraw0+$06,y
lda #$00
adc spidraw0+$04,y
sta spidraw0+$04,y
sta spidraw0+$07,y
nxtspret dex
rts
mkers1sb clc
sta ersrwdir
stx pointers+$00
sty pointers+$01
lda pointers+$04
sta erasraw1+$04
ldx #$40; 64 pixels width
; 64 pixel breite
mkers1lp ldy #erasrawe-erasraw1-$01
lda erasraw1,y
sta (pointers+$00),y
dey
bpl mkers1lp+$02
lda #erasrawe-erasraw1
ldy #erasraw1-erasraw0
jsr nexteras
bne mkers1lp+$00
rts
nexteras clc
adc pointers+$00
sta pointers+$00
bcc *+$04
inc pointers+$01
dec pointers+$05
bne nxtersrt
clc
lda #$80; 1 char column is 128
; (16x8) bytes
; 1 zeichenspalte sind
; 128 (16*8) bytes
adc erasraw0+$03,y
sta erasraw0+$03,y
lda #$00
adc erasraw0+$04,y
sta erasraw0+$04,y
lda #$04
sta pointers+$05
nxtersrt dex
rts
; subroutine to build
; the fill speedcode
; unterroutine zum generieren
; des fuellspeedcodes
mkfilspd sta pointers+$04
stx pointers+$00
sty pointers+$01
lda #<fillbuff
sta pointers+$02
lda #>fillbuff
sta pointers+$03
ldx #$00
mkfilup0 sec
lda spidybeg,x
ora pointers+$02
sta pointers+$02
ora #$7f
sbc spidybeg,x
sta pointers+$05
mkfilup1 ldy #$00
lda #$4d ; op-code eor abs
sta (pointers+$00),y
iny
lda pointers+$02
sta (pointers+$00),y
iny
lda pointers+$03
sta (pointers+$00),y
iny
lda #$8d ; op-code sta abs
sta (pointers+$00),y
iny
lda pointers+$02
sta (pointers+$00),y
iny
lda pointers+$04
sta (pointers+$00),y
iny
clc
tya
adc pointers+$00
sta pointers+$00
bcc *+$04
inc pointers+$01
lda pointers+$02
inc pointers+$02
cmp pointers+$05
bne mkfilup1
and #%10000000
adc #$80
sta pointers+$02
bcc *+$06
inc pointers+$03
inc pointers+$04
inx
cpx #$10 ; 16 char columns
; 16 zeichenspalten
bne mkfilup0
ldy #$00
lda #$60
sta (pointers+$00),y
rts
; speedcode element for a
; slope angle of +/-90 to
; +/-45 degrees
; speedcodeelement fuer einen
; steigungswinkel von +/-90
; bis +/-45 grad
spidraw0 lda #$00
eor !$00,y
sta !$00,y
txa
adc linslopl
tax
tya
adc linsloph
tay
; speedcode element for a
; slope angle of +/-45 to 0
; degrees
; speedcodeelement fuer einen
; steigungswinkel von +/-45
; bis 0 grad
spidraw1 lda #$00
eor !$00,y
sta !$00,y
txa
adc linslopl
tax
bcc *+$03
sprw1dir .byte $00
spidrawe
; speedcode element for a
; slope angle of +/-90 to
; +/-45 degrees
; speedcodeelement fuer einen
; steigungswinkel von +/-90
; bis +/-45 grad
erasraw0 lda #$00
sta !$00,y
txa
adc linslopl
tax
tya
adc linsloph
tay
; speedcode element for a
; slope angle of +/-45 to 0
; degrees
; speedcodeelement fuer einen
; steigungswinkel von +/-45
; bis 0 grad
erasraw1 lda #$00
sta !$00,y
txa
adc linslopl
tax
bcc *+$03
ersrwdir .byte $00
erasrawe
; table of the y start points
; of the speed code
; tabelle der y-startpunkte
; des fuellspeedcodes
spidybeg .byte $25,$17,$0f,$09,$05,$03
.byte $01,$00,$00,$01,$03,$05
.byte $09,$0f,$17,$25
scrntabl .byte scrn/64.(charset0/1024).1
.byte scrn/64.(charset1/1024).1
.byte scrn/64.(charset2/1024).1
.byte scrn/64.(charset0/1024).1
; table of the face vertices
; for the backface culling
; tabelle der seiteneckpunkte
; fuer das backface culling
facepnt0 .byte $00,$00,$01,$02,$00,$04
facepnt1 .byte $01,$04,$05,$03,$02,$06
facepnt2 .byte $03,$01,$03,$06,$04,$05
; table of the face colours
; tabelle der seitenfarben
facecols .byte $01,$02,$03,$02,$03,$01
; table of the face lines
; tabelle der seitenlinien
facelin0 .byte $00,$00,$01,$02,$03,$08
facelin1 .byte $01,$04,$05,$06,$04,$09
facelin2 .byte $02,$05,$07,$07,$06,$0a
facelin3 .byte $03,$08,$09,$0a,$0b,$0b
; table of the line begin
; and end points
; tabelle der linienanfangs-
; und endpunkte
linepnt0 .byte $00,$01,$03,$02,$00,$01
.byte $02,$03,$04,$05,$07,$06
linepnt1 .byte $01,$03,$02,$00,$04,$05
.byte $06,$07,$05,$07,$06,$04
; table of speed code addresses
; tabelle der speedcodeadressen
spidadrl .byte <spidcod0,<spidcod1
.byte <spidcod2
spidadrh .byte >spidcod0,>spidcod1
.byte >spidcod2
; colour table for the shading
; farbtabelle fuer das shading
brightab .byte $01,$01,$01,$01,$0d,$0d
.byte $0d,$0d,$07,$07,$07,$07
.byte $03,$03,$03,$03,$0f,$0f
.byte $0f,$0f,$05,$05,$05,$05
.byte $0a,$0a,$0a,$0a,$0e,$0e
.byte $0e,$0e,$0c,$0c,$0c,$0c
.byte $04,$04,$04,$04,$08,$08
.byte $08,$08,$0b,$0b,$0b,$0b
.byte $02,$02,$02,$02,$09,$09
.byte $09,$09,$00,$00,$00,$00
nmi rti
*= $0800
return sei
lda #$37
sta $01
ldx #$ff
txs
jsr $fda3
lda #$00
tay
sta $02,y
sta $0200,y
sta $0300,y
iny
bne *-$0a
ldx #$3c
ldy #$03
stx $b2
sty $b3
ldx #$00
ldy #$a0
jsr $fd8c
jsr $fd15
jsr $ff5b
jsr $e453
jsr $e3bf
ldx #$01
stx $df06
dex
stx $df02
stx $df04
ldy #$08
sty $df03
sty $df05
ldy #$f8
sty $df07
dey
sty $df08
stx $df0a
lda #$ec
sta $df01
ldy #$1f
lda doreturn,y
sta $0340,y
dey
bpl *-$07
jsr $0340
stx $df06
lda #$ed
sta $df01
lda #$8f
pha
lda #$ff
pha
jmp $0340
doreturn sei
lda #$30
sta $01
lda $ff00
sta $ff00
lda #$37
sta $01
rts