Basic graphics routines in separate file and optimizations

This commit is contained in:
Pecusx
2023-05-04 19:19:12 +02:00
parent cf00674136
commit 367e87093e
5 changed files with 228 additions and 213 deletions
+224
View File
@@ -0,0 +1,224 @@
.IF *>0 ;this is a trick that prevents compiling this file alone
; Basic hardware-dependent graphics routines.
; -----------------------------------------
.proc unPlot
; plots a point and saves the plotted byte, reverts the previous plot.
; -----------------------------------------
ldx #0 ; only one pixel
unPlotAfterX
stx WhichUnPlot
; first remake the oldie
lda oldplotL,x
sta oldplot
lda oldplotH,x
sta oldplot+1
lda oldply,x
tay
lda oldora,x
sta (oldplot),y
; is it not out of the screen ????
cpw ydraw #screenheight
jcc CheckX
mwa #0 ydraw
CheckX
cpw xdraw #screenwidth
jcs EndOfUnPlot
MakeUnPlot
; let's count coordinates taken from xdraw and ydraw
;xbyte = xbyte/8
lda xdraw+1
lsr
lda xdraw
ror ;just one bit over 256. Max screenwidth = 512!!!
lsr
lsr
;---
tay
ldx WhichUnPlot
tya
sta oldply,x
ldx ydraw
lda linetableL,x
sta xbyte
sta oldplot
lda linetableH,x
sta xbyte+1
sta oldplot+1
lda xdraw
and #$7
tax
lda color
bne ClearUnPlot
;plotting here
lda (xbyte),y
sta OldOraTemp
ora bittable,x
sta (xbyte),y
bne ContinueUnPlot ; allways <>0
ClearUnPlot
lda (xbyte),y
sta OldOraTemp
and bittable2,x
sta (xbyte),y
ContinueUnPlot
ldx WhichUnPlot
lda OldOraTemp
sta oldora,x
lda oldplot
sta oldplotL,x
lda oldplot+1
sta oldplotH,x
; and now we must solve the problem of several plots
; in one byte
ldx #4
ldy WhichUnPlot
LetsCheckOverlapping
cpx WhichUnPlot
beq SkipThisPlot
lda oldplotL,x
cmp oldplotL,y
bne NotTheSamePlot
lda oldplotH,x
cmp oldplotH,y
bne NotTheSamePlot
lda oldply,x
cmp oldply,y
bne NotTheSamePlot
; the pixel is in the same byte so let's take correct contents
lda oldora,x
sta oldora,y
NotTheSamePlot
SkipThisPlot
dex
bpl LetsCheckOverlapping
EndOfUnPlot
rts
.endp
; -----------------------------------------
.proc plot ;plot (xdraw, ydraw, color)
; color == 1 --> put pixel
; color == 0 --> erase pixel
; this is one of the most important routines in the whole
; game. If you are going to speed up the game, start with
; plot - it is used by every single effect starting from explosions
; through line drawing and small text output!!!
;
; Optimized by 0xF (Fox) THXXXX!!!
; -----------------------------------------
; is it not over the screen ???
cpw ydraw #(screenheight+1); changed for one additional line. cpw ydraw #(screenheight-1)
bcs unPlot.EndOfUnPlot ;nearest RTS
CheckX02
cpw xdraw #screenwidth
bcs EndOfPlot
MakePlot
; let's calculate coordinates from xdraw and ydraw
;xbyte = xbyte/8
lda xdraw+1
lsr
lda xdraw
ror ;just one bit over 256. Max screenwidth = 512!!!
lsr
lsr
sta xbyte
;---
ldx ydraw
ldy linetableL,x
lda linetableH,x
sta xbyte+1
lda xdraw
and #$7
tax
lda color
bne ClearPlot
lda (xbyte),y
ora bittable,x
sta (xbyte),y
EndOfPlot
rts
ClearPlot
lda (xbyte),y
and bittable2,x
sta (xbyte),y
rts
.endp
; -----------------------------------------
.proc point_plot
; -----------------------------------------
; checks state of the pixel (coordinates in xdraw and ydraw)
; result is in A (zero or appropriate bit is set)
; let's calculate coordinates from xdraw and ydraw
;xbyte = xbyte/8
lda xdraw+1
lsr
lda xdraw
ror ;just one bit over 256. Max screenwidht = 512!!!
lsr
lsr
sta xbyte
;---
ldx ydraw
ldy linetableL,x
lda linetableH,x
sta xbyte+1
lda xdraw
and #$7
tax
lda (xbyte),y
eor #$ff
and bittable,x
rts
.endp
;--------------------------------------------------
.proc ClearScreen
;--------------------------------------------------
mwa #display temp
ldy #0
@ lda #$ff
sta (temp),y
inw temp
cpw temp #display+screenheight*screenBytes+1
bne @-
rts
.endp
;--------------------------------------------------
.proc GenerateLineTable
mwa #display temp
mwa #linetableL temp2
mwa #linetableH modify
ldy #0
@ lda temp
sta (temp2),y
lda temp+1
sta (modify),y
adw temp #40
iny
cpy #screenheight+1
bne @-
rts
.endp
.ENDIF
+3 -201
View File
@@ -473,19 +473,6 @@ endcircleloop
RTS RTS
.endp .endp
;--------------------------------------------------
.proc ClearScreen
;--------------------------------------------------
mwa #display temp
ldy #0
@ lda #$ff
sta (temp),y
inw temp
cpw temp #display+screenheight*screenBytes+1
bne @-
rts
.endp
;-------------------------------*------------------ ;-------------------------------*------------------
.proc placetanks .proc placetanks
;-------------------------------------------------- ;--------------------------------------------------
@@ -1643,195 +1630,10 @@ NotHigher
rts rts
.endp .endp
; ----------------------------------------- ;---------------------------------------------------
.proc unPlot icl 'gr_basics.asm'
; plots a point and saves the plotted byte, reverts the previous plot. ;---------------------------------------------------
; -----------------------------------------
ldx #0 ; only one pixel
unPlotAfterX
stx WhichUnPlot
; first remake the oldie
lda oldplotL,x
sta oldplot
lda oldplotH,x
sta oldplot+1
lda oldply,x
tay
lda oldora,x
sta (oldplot),y
; is it not out of the screen ????
cpw ydraw #screenheight
jcc CheckX
mwa #0 ydraw
CheckX
cpw xdraw #screenwidth
jcs EndOfUnPlot
MakeUnPlot
; let's count coordinates taken from xdraw and ydraw
mwa xdraw xbyte
lda xbyte
and #$7
sta ybit
lsrw xbyte
rorw xbyte
rorw xbyte
;---
ldy xbyte
ldx WhichUnPlot
tya
sta oldply,x
ldx ydraw
lda linetableL,x
sta xbyte
sta oldplot
lda linetableH,x
sta xbyte+1
sta oldplot+1
ldx ybit
lda color
bne ClearUnPlot
;plotting here
lda (xbyte),y
sta OldOraTemp
ora bittable,x
sta (xbyte),y
jmp ContinueUnPlot
ClearUnPlot
lda (xbyte),y
sta OldOraTemp
and bittable2,x
sta (xbyte),y
ContinueUnPlot
ldx WhichUnPlot
lda OldOraTemp
sta oldora,x
lda oldplot
sta oldplotL,x
lda oldplot+1
sta oldplotH,x
; and now we must solve the problem of several plots
; in one byte
ldx #4
ldy WhichUnPlot
LetsCheckOverlapping
cpx WhichUnPlot
beq SkipThisPlot
lda oldplotL,x
cmp oldplotL,y
bne NotTheSamePlot
lda oldplotH,x
cmp oldplotH,y
bne NotTheSamePlot
lda oldply,x
cmp oldply,y
bne NotTheSamePlot
; the pixel is in the same byte so let's take correct contents
lda oldora,x
sta oldora,y
NotTheSamePlot
SkipThisPlot
dex
bpl LetsCheckOverlapping
EndOfUnPlot
rts
.endp
; -----------------------------------------
.proc plot ;plot (xdraw, ydraw, color)
; color == 1 --> put pixel
; color == 0 --> erase pixel
; this is one of the most important routines in the whole
; game. If you are going to speed up the game, start with
; plot - it is used by every single effect starting from explosions
; through line drawing and small text output!!!
;
; Optimized by 0xF (Fox) THXXXX!!!
; -----------------------------------------
; is it not over the screen ???
cpw ydraw #(screenheight+1); changed for one additional line. cpw ydraw #(screenheight-1)
bcs unPlot.EndOfUnPlot ;nearest RTS
CheckX02
cpw xdraw #screenwidth
bcs EndOfPlot
MakePlot
; let's calculate coordinates from xdraw and ydraw
;xbyte = xbyte/8
lda xdraw+1
lsr
lda xdraw
ror ;just one bit over 256. Max screenwidth = 512!!!
lsr
lsr
sta xbyte
;---
ldx ydraw
ldy linetableL,x
lda linetableH,x
sta xbyte+1
lda xdraw
and #$7
tax
lda color
bne ClearPlot
lda (xbyte),y
ora bittable,x
sta (xbyte),y
EndOfPlot
rts
ClearPlot
lda (xbyte),y
and bittable2,x
sta (xbyte),y
rts
.endp
; -----------------------------------------
.proc point_plot
; -----------------------------------------
; checks state of the pixel (coordinates in xdraw and ydraw)
; result is in A (zero or appropriate bit is set)
; let's calculate coordinates from xdraw and ydraw
;xbyte = xbyte/8
lda xdraw+1
lsr
lda xdraw
ror ;just one bit over 256. Max screenwidht = 512!!!
lsr
lsr
sta xbyte
;---
ldx ydraw
ldy linetableL,x
lda linetableH,x
sta xbyte+1
lda xdraw
and #$7
tax
lda (xbyte),y
eor #$ff
and bittable,x
rts
.endp
;-------------------------------------------------- ;--------------------------------------------------
.proc TypeChar .proc TypeChar
; puts char on the graphics screen ; puts char on the graphics screen
+1 -12
View File
@@ -322,18 +322,7 @@ no5200splash
jsr SelectNextGradient.NotWind jsr SelectNextGradient.NotWind
; generate linetables ; generate linetables
mwa #display temp jsr GenerateLineTable
mwa #linetableL temp2
mwa #linetableH modify
ldy #0
@ lda temp
sta (temp2),y
lda temp+1
sta (modify),y
adw temp #40
iny
cpy #screenheight+1
bne @-
.IF TARGET = 800 .IF TARGET = 800
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.