Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DrawTriangle:
- ;IN: x1,y1,u1,v1,x2,y2,u2,v2,x3,y3,u3,v3
- ;scherm = 96*64
- ld hl, (y1)
- ld de, (y2)
- cpHLDE
- jr c, Y1SmallerThanY2
- ld (y1), de
- ld (y2), hl
- ld hl, (x1)
- ld de, (x2)
- ld (x1), de
- ld (x2), hl
- Y1SmallerThanY2:
- ld hl, (y1)
- ld de, (y3)
- cpHLDE
- jr c, Y1SmallerThanY3
- ld (y1), de
- ld (y3), hl
- ld hl, (x1)
- ld de, (x3)
- ld (x1), de
- ld (x3), hl
- Y1SmallerThanY3:
- ld hl, (y2)
- ld de, (y3)
- cpHLDE
- jr c, Y2SmallerThanY3
- ld (y2), de
- ld (y3), hl
- ld hl, (x2)
- ld de, (x3)
- ld (x2), de
- ld (x3), hl
- Y2SmallerThanY3:
- push IY
- pop hl
- ld (SaveIY), hl
- ld hl, TempFlags
- push hl
- pop IY
- res 0, (IY) ;in bit 0, (IY) wordt opgeslagen bij welke helft het is. 0=eerste helft, 1= tweede helft
- res 1, (IY) ;bit 1, (IY) = interval texturen al berekend
- ld hl, (y2)
- ld de, (y1)
- subFP ;hier gebruikt om 16-bit getallen af te trekken I.P.V. fixed-point getallen
- ld h, l
- ld l, 0
- push hl
- ld hl, (x2)
- ld de, (x1)
- subFP
- ld h, l
- ld l, 0
- pop de
- call DivFP
- ld (dx1), hl
- ld hl, (y3)
- ld de, (y2)
- subFP
- ld h, l
- ld l, 0
- push hl
- ld hl, (x3)
- ld de, (x2)
- subFP
- ld h, l
- ld l, 0
- pop de
- call DivFP
- ld (dx2), hl
- ld hl, (y3)
- ld de, (y1)
- subFP
- ld h, l
- ld l, 0
- push hl
- ld hl, (x3)
- ld de, (x1)
- subFP
- ld h, l
- ld l, 0
- pop de
- call DivFP
- ld (dx3), hl
- ; ld hl, (dx1)
- ; ld de, (dx3)
- ; cpHLDE
- ; jr nc, TNoChange
- ; ld (dx1), de
- ; ld (dx3), hl
- ;TNoChange:
- ld hl, (x1)
- bit 7, h
- jr z, TPos1
- ld (tx1+1),hl \ ld a, $FF \ ld (tx1),a
- ld (tx2+1),hl \ ld a, $FF \ ld (tx2),a
- jr TEnd1
- TPos1:
- ld (tx1+1),hl \ xor a \ ld (tx1),a ;store the 16bit integer at hl into 16.8 fixed point number tx1
- ld (tx2+1),hl \ xor a \ ld (tx2),a
- TEnd1:
- ld hl, (y1)
- ld (_ty), hl
- ld hl, (Y1)
- ld de, (y2)
- cpHLDE
- jp z, __TEndLoop
- TDrawLoop:
- ;(h,l) (d,e)
- ; ld a, (tx1+1)
- ; ld h, a
- ; ld a, (_ty)
- ; ld l, a
- ; ld e, a
- ; ld a, (tx2+1)
- ; ld d, a
- ; call DrawLine
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Horizontal line drawing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- ld a, (_ty)
- ld l, a
- #comment
- ld hl, (tu1)
- ld (tmpu), hl
- ld hl, (tv1)
- ld (tmpv), hl
- ld hl, (tu2)
- ld (temp2), hl
- ld hl, (tv2)
- ld (temp3), hl
- #endcomment
- ld a, (tx2+1)
- ld (temp+1), a
- ld b, a
- ld a, (tx1+1)
- ld (temp), a
- cp b
- jr c, TOrdered
- #comment
- ld hl, (tu2)
- ld (tmpu), hl
- ld hl, (tv2)
- ld (tmpv), hl
- ld hl, (tu1)
- ld (temp2), hl
- ld hl, (tv1)
- ld (temp3), hl
- #endcomment
- ld a, (tx2+1)
- ld (temp), a
- ld a, (tx1+1)
- ld (temp+1), a
- TOrdered:
- ld a, (temp)
- call GetPixel
- ld (mask), a
- ld (pointer), hl
- ;#comment
- bit 1, (IY)
- jr nz, EndCalc
- ld hl, (tx1)
- ld de, (tx2)
- cpHLDE
- jr z, EndCalc
- ld a, (temp)
- ld h, a
- ld l, 0
- ld a, (temp+1)
- ld d, a
- ld e, 0
- subFP
- push hl
- ld hl, (tmpu)
- ld de, (temp2)
- subFP
- pop de
- call DivFP
- ld (tmpdu), hl
- ld a, (temp)
- ld h, a
- ld l, 0
- ld a, (temp+1)
- ld d, a
- ld e, 0
- subFP
- push hl
- ld hl, (tmpv)
- ld de, (temp3)
- subFP
- pop de
- call DivFP
- ld (tmpdv), hl
- EndCalc:
- ;#endcomment
- TPlotLoop:
- ld a, (mask)
- ld hl, (pointer)
- or (hl)
- ld (hl), a
- ld hl, mask
- rrc (hl)
- jr nc, TNoCarry
- ld hl, (pointer)
- inc hl
- ld (pointer), hl
- TNoCarry:
- ;#comment
- ld hl, (tmpu)
- ld de, (tmpdu)
- add hl, de
- ld (tmpu), hl
- ld hl, (tmpv)
- ld de, (tmpdv)
- add hl, de
- ld (tmpv), hl
- ;#endcomment
- ld a, (temp+1)
- ld b, a
- ld a, (temp)
- ld hl, temp
- inc (hl)
- cp b
- jr nz, TPlotLoop
- ; ld hl, (tx1)
- ; ld de, (dx1)
- ; add hl, de
- ; ld a, (tx1+2)
- ; bit 7, d
- ; jr z, TPos2
- ; adc a, $FF
- ; jr Tend2
- ;TPos2:
- ; adc a, 0
- ;TEnd2:
- ; ld (tx1), hl
- ; ld (tx1+2), a
- ; ld hl,(tx1) \ ld de, (dx1) \ ld a, d \ rla \ sbc a,a \ add hl, de \ ld b, a \ ld a, (tx1+2) \ adc a, b \ ld (tx1+2), a \ ld (tx1), hl
- ; ld hl, (tx1)
- ; ld de, (dx1)
- ; ld a,(tx1+2)
- ; bit 7, d
- ; jr nz, __Substract1
- ; add hl, de
- ; jr nc, __End1
- ; inc a
- ; ld (tx1+2), a
- ; jr __End1
- ;__Substract1:
- ; call NegDE
- ; or a
- ; sbc hl, de
- ; jr nc, __End1
- ; dec a
- ; ld (tx1+2), a
- ;__End1:
- ; ld (tx1), hl
- ld hl,(tx1)
- ld de, (dx1)
- ld a, d
- rla
- sbc a, a
- ld b, a
- add hl, de
- ld (tx1), hl
- ld a, (tx1+2)
- adc a, b
- ld (tx1+2), a
- ; ld hl, (tx2)
- ; ld de, (dx3)
- ; add hl, de
- ; ld a, (tx2+2)
- ; bit 7, d
- ; jr z, TPos3
- ; adc a, $FF
- ; jr Tend3
- ;TPos3:
- ; adc a, 0
- ;TEnd3:
- ; ld (tx2), hl
- ; ld (tx2+2), a
- ; ld hl,(tx2) \ ld de, (dx3) \ ld a, d \ rla \ sbc a,a \ add hl, de \ ld b, a \ ld a, (tx2+2) \ adc a, b \ ld (tx2+2), a \ ld (tx2), hl
- ; ld hl, (tx2)
- ; ld de, (dx3)
- ; ld a,(tx2+2)
- ; bit 7, d
- ; jr nz, __Substract2
- ; add hl, de
- ; jr nc, __End2
- ; inc a
- ; ld (tx2+2), a
- ; jr __End2
- ;__Substract2:
- ; call NegDE
- ; or a
- ; sbc hl, de
- ; jr nc, __End2
- ; dec a
- ; ld (tx2+2), a
- ;__End2:
- ; ld (tx2), hl
- ld hl,(tx2)
- ld de, (dx3)
- ld a, d
- rla
- sbc a, a
- ld b, a
- add hl, de
- ld (tx2), hl
- ld a, (tx2+2)
- adc a, b
- ld (tx2+2), a
- ld hl, (_ty)
- inc hl
- ld (_ty), hl
- ld de, (y2)
- cpHLDE
- jp c, TDrawLoop
- bit 0, (IY)
- jr nz, _TEnd
- __TEndLoop:
- ;Begin tweede keer tekenen:
- ld hl, (y2)
- ld (_ty), hl
- ld hl, (y3)
- ld (y2), hl
- ld hl, (dx2)
- ld (dx1), hl
- ld hl, (x2)
- bit 7, h
- jr nz, TPos4
- ld (tx1+1),hl \ ld a, $FF \ ld (tx1),a
- jr TEnd4
- TPos4:
- ld (tx1+1),hl \ xor a \ ld (tx1),a
- Tend4:
- set 0, (IY)
- jp TDrawLoop
- _TEnd:
- ld hl, (SaveIY)
- push hl
- pop IY
- ret
- getPixel:
- ld h, 0
- ld d, h
- ld e, l
- add hl, hl
- add hl, de
- add hl, hl
- add hl, hl
- ld e, a
- srl e
- srl e
- srl e
- add hl, de
- ld de, PlotSScreen
- add hl, de
- and 7
- ld b, a
- ld a, $80
- ret z
- rrca
- djnz $-1
- ret
Add Comment
Please, Sign In to add comment