First working version of virtual stack unrender

So fast!!
This commit is contained in:
blondie7575 2018-01-06 15:30:06 -08:00
parent e0a48fc5ac
commit c82e9d8a30
5 changed files with 59 additions and 30 deletions

25
GenerateSpanDataTable.py Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import sys
def main(argv):
print ("terrainSpanDataPtr:",end="")
rowCount = 19
MAXTERRAINHEIGHT = 100 # Must match assembly code!
for jump in range(0,MAXTERRAINHEIGHT):
rowCount += 1
if (rowCount==20):
print ("\n\t.word ", end="")
rowCount=0
print ("SPANROWSIZE*%d" % (jump), end="")
if (rowCount<19):
print (",", end="")
if __name__ == "__main__":
main(sys.argv[1:])

View File

@ -27,6 +27,7 @@ SCRATCHL = $19 ; 16-bit version of scratch
SCRATCHL2 = $67 ; Second 16-bit scratch SCRATCHL2 = $67 ; Second 16-bit scratch
PARAM24 = $67 ; 24-bit param (This is almost certainly messing up AppleSoft, but meh) PARAM24 = $67 ; 24-bit param (This is almost certainly messing up AppleSoft, but meh)
CACHEPTR = $6A ; General purpose cache pointer (This is almost certainly messing up AppleSoft, but meh) CACHEPTR = $6A ; General purpose cache pointer (This is almost certainly messing up AppleSoft, but meh)
CACHEDATA = $6C ; General purpose cache data (This is almost certainly messing up AppleSoft, but meh)
STACKPTR = $70 ; Cache for stack pointer in fast graphics STACKPTR = $70 ; Cache for stack pointer in fast graphics
SHADOWREGISTER = $72 ; Cache for shadow register in fast graphics SHADOWREGISTER = $72 ; Cache for shadow register in fast graphics
STACKREGISTER = $73 ; Cache for stack register in fast graphics STACKREGISTER = $73 ; Cache for stack register in fast graphics

View File

@ -31,6 +31,7 @@ beginGameplay:
jsr compileTerrainSpans jsr compileTerrainSpans
; jsr compileTerrain ; jsr compileTerrain
; jsr clipTerrain ; jsr clipTerrain
jsr renderTerrainSpans
; Create players ; Create players
lda #56 lda #56
@ -57,8 +58,8 @@ gameplayLoop:
; lda terrainDirty ; lda terrainDirty
; beq gameplayLoopKbd ; beq gameplayLoopKbd
BORDER_COLOR #$3 BORDER_COLOR #$3
jsr unrenderTerrainSpans
jsr renderTerrainSpans jsr renderTerrainSpans
; jsr unrenderTerrainSpans
stz terrainDirty stz terrainDirty
BORDER_COLOR #$1 BORDER_COLOR #$1

Binary file not shown.

View File

@ -69,7 +69,12 @@ renderTerrainDone:
; ;
; ;
renderTerrainSpans: renderTerrainSpans:
pha SAVE_AXY
FASTGRAPHICS
lda #$800 ; Prepare unrender cache
tcs
lda #terrainSpanWriteCache lda #terrainSpanWriteCache
sta CACHEPTR sta CACHEPTR
@ -77,23 +82,6 @@ renderTerrainSpans:
renderTerrainSpansLoop: renderTerrainSpansLoop:
sta PARAML1 sta PARAML1
jsr renderTerrainRowSpans
dec
bne renderTerrainSpansLoop
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderTerrainRowSpans:
;
; PARAML1 = Row index (bottom relative)
;
; Trashes SCRATCHL,SCRATCHL2,PARAML0
;
renderTerrainRowSpans:
SAVE_AXY
; Find row data ; Find row data
lda PARAML1 lda PARAML1
@ -120,18 +108,17 @@ renderTerrainRowSpans:
lda #0 lda #0
clc clc
renderTerrainRowSpansFindLeftLoop: renderTerrainRowSpansFindLeftLoop:
adc terrainSpanData+2,y adc terrainSpanData+2,y
cmp leftScreenEdge cmp leftScreenEdge
bpl renderTerrainRowSpansFoundLeft bpl renderTerrainRowSpansFoundLeft
iny iny
iny iny
pha sta CACHEDATA
lda SCRATCHL lda SCRATCHL
eor #%110000 ; Toggle span color cache eor #%110000 ; Toggle span color cache
sta SCRATCHL sta SCRATCHL
pla lda CACHEDATA
bra renderTerrainRowSpansFindLeftLoop bra renderTerrainRowSpansFindLeftLoop
renderTerrainRowSpansFoundLeft: renderTerrainRowSpansFoundLeft:
@ -147,10 +134,11 @@ renderTerrainRowSpansLoop:
sta VRAMBANK,x sta VRAMBANK,x
; Cache the index we wrote to so we can erase later ; Cache the index we wrote to so we can erase later
txa phx
sta (CACHEPTR) ; txa
inc CACHEPTR ; sta (CACHEPTR)
inc CACHEPTR ; inc CACHEPTR
; inc CACHEPTR
; Advance to end of span ; Advance to end of span
clc clc
@ -171,10 +159,17 @@ renderTerrainRowSpansLoop:
bra renderTerrainRowSpansLoop bra renderTerrainRowSpansLoop
renderTerrainRowSpansDone: renderTerrainRowSpansDone:
lda PARAML1
dec
bne renderTerrainSpansLoop
pea 0 ; Null-terminate the unrender cache
SLOWGRAPHICS
RESTORE_AXY RESTORE_AXY
rts rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; unrenderTerrainSpans: ; unrenderTerrainSpans:
; ;
@ -182,18 +177,25 @@ renderTerrainRowSpansDone:
unrenderTerrainSpans: unrenderTerrainSpans:
SAVE_AXY SAVE_AXY
phb
pea $e1e1 ; Work entirely in bank E1 for all local read/writes
plb
plb
ldy #$800-1
unrenderTerrainSpansLoop: unrenderTerrainSpansLoop:
dec CACHEPTR lda 0,y
dec CACHEPTR
lda (CACHEPTR)
beq unrenderTerrainSpansDone beq unrenderTerrainSpansDone
tax tax
lda #0 lda #0
sta VRAMBANK,x sta a:0,x
dey
dey
bra unrenderTerrainSpansLoop bra unrenderTerrainSpansLoop
unrenderTerrainSpansDone: unrenderTerrainSpansDone:
plb
RESTORE_AXY RESTORE_AXY
rts rts