diff --git a/gr_basics.asm b/gr_basics.asm new file mode 100644 index 0000000..b7dbe55 --- /dev/null +++ b/gr_basics.asm @@ -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 \ No newline at end of file diff --git a/grafproc.asm b/grafproc.asm index a3fe794..c69f73f 100644 --- a/grafproc.asm +++ b/grafproc.asm @@ -473,19 +473,6 @@ endcircleloop 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 placetanks ;-------------------------------------------------- @@ -1643,195 +1630,10 @@ NotHigher rts .endp -; ----------------------------------------- -.proc unPlot -; plots a point and saves the plotted byte, reverts the previous plot. -; ----------------------------------------- - ldx #0 ; only one pixel -unPlotAfterX - stx WhichUnPlot +;--------------------------------------------------- + icl 'gr_basics.asm' +;--------------------------------------------------- - ; 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 ; puts char on the graphics screen diff --git a/scorch.asm b/scorch.asm index 0df711b..39e8d3f 100644 --- a/scorch.asm +++ b/scorch.asm @@ -322,18 +322,7 @@ no5200splash jsr SelectNextGradient.NotWind ; generate linetables - 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 @- + jsr GenerateLineTable .IF TARGET = 800 diff --git a/scorch.bin b/scorch.bin index d1efd87..a614b78 100644 Binary files a/scorch.bin and b/scorch.bin differ diff --git a/scorch.xex b/scorch.xex index 33483f5..87efd68 100644 Binary files a/scorch.xex and b/scorch.xex differ