diff --git a/GenerateSpanDataTable.py b/GenerateSpanDataTable.py new file mode 100755 index 0000000..1018c12 --- /dev/null +++ b/GenerateSpanDataTable.py @@ -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:]) + diff --git a/equates.s b/equates.s index 092c765..a6e9dc1 100644 --- a/equates.s +++ b/equates.s @@ -27,6 +27,7 @@ SCRATCHL = $19 ; 16-bit version of scratch SCRATCHL2 = $67 ; Second 16-bit scratch 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) +CACHEDATA = $6C ; General purpose cache data (This is almost certainly messing up AppleSoft, but meh) STACKPTR = $70 ; Cache for stack pointer in fast graphics SHADOWREGISTER = $72 ; Cache for shadow register in fast graphics STACKREGISTER = $73 ; Cache for stack register in fast graphics diff --git a/gamemanager.s b/gamemanager.s index f9e4bcf..64b3dc9 100644 --- a/gamemanager.s +++ b/gamemanager.s @@ -31,6 +31,7 @@ beginGameplay: jsr compileTerrainSpans ; jsr compileTerrain ; jsr clipTerrain + jsr renderTerrainSpans ; Create players lda #56 @@ -57,8 +58,8 @@ gameplayLoop: ; lda terrainDirty ; beq gameplayLoopKbd BORDER_COLOR #$3 + jsr unrenderTerrainSpans jsr renderTerrainSpans -; jsr unrenderTerrainSpans stz terrainDirty BORDER_COLOR #$1 diff --git a/gscats.2mg b/gscats.2mg index 51a9bab..e9d254f 100644 Binary files a/gscats.2mg and b/gscats.2mg differ diff --git a/terrain.s b/terrain.s index 0aef0a4..1b02058 100644 --- a/terrain.s +++ b/terrain.s @@ -69,7 +69,12 @@ renderTerrainDone: ; ; renderTerrainSpans: - pha + SAVE_AXY + FASTGRAPHICS + + lda #$800 ; Prepare unrender cache + tcs + lda #terrainSpanWriteCache sta CACHEPTR @@ -77,23 +82,6 @@ renderTerrainSpans: renderTerrainSpansLoop: 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 lda PARAML1 @@ -120,18 +108,17 @@ renderTerrainRowSpans: lda #0 clc - renderTerrainRowSpansFindLeftLoop: adc terrainSpanData+2,y cmp leftScreenEdge bpl renderTerrainRowSpansFoundLeft iny iny - pha + sta CACHEDATA lda SCRATCHL eor #%110000 ; Toggle span color cache sta SCRATCHL - pla + lda CACHEDATA bra renderTerrainRowSpansFindLeftLoop renderTerrainRowSpansFoundLeft: @@ -147,10 +134,11 @@ renderTerrainRowSpansLoop: sta VRAMBANK,x ; Cache the index we wrote to so we can erase later - txa - sta (CACHEPTR) - inc CACHEPTR - inc CACHEPTR + phx +; txa +; sta (CACHEPTR) +; inc CACHEPTR +; inc CACHEPTR ; Advance to end of span clc @@ -171,10 +159,17 @@ renderTerrainRowSpansLoop: bra renderTerrainRowSpansLoop renderTerrainRowSpansDone: + lda PARAML1 + dec + bne renderTerrainSpansLoop + + pea 0 ; Null-terminate the unrender cache + SLOWGRAPHICS RESTORE_AXY rts + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; unrenderTerrainSpans: ; @@ -182,18 +177,25 @@ renderTerrainRowSpansDone: unrenderTerrainSpans: SAVE_AXY + phb + pea $e1e1 ; Work entirely in bank E1 for all local read/writes + plb + plb + + ldy #$800-1 unrenderTerrainSpansLoop: - dec CACHEPTR - dec CACHEPTR - lda (CACHEPTR) + lda 0,y beq unrenderTerrainSpansDone tax lda #0 - sta VRAMBANK,x + sta a:0,x + dey + dey bra unrenderTerrainSpansLoop unrenderTerrainSpansDone: + plb RESTORE_AXY rts