mirror of
https://github.com/blondie7575/GSCats.git
synced 2025-02-10 16:31:51 +00:00
Optimizations and cleanup
This commit is contained in:
parent
68c55aee3b
commit
51c5ec644e
@ -6,7 +6,7 @@ import sys
|
||||
def main(argv):
|
||||
|
||||
# Prologue
|
||||
print ("vramRowEnds:",end="")
|
||||
print ("vramRowEndsMinusOne:",end="")
|
||||
v = 0x20a0
|
||||
rowCount = 19
|
||||
|
||||
@ -16,7 +16,7 @@ def main(argv):
|
||||
print ("\n\t.word ", end="")
|
||||
rowCount=0
|
||||
|
||||
print ("$%x" % v, end="")
|
||||
print ("$%x" % (v-1), end="")
|
||||
if (rowCount<19):
|
||||
print (",", end="")
|
||||
v += 160
|
||||
|
BIN
gscats.2mg
BIN
gscats.2mg
Binary file not shown.
22
tables.s
22
tables.s
@ -32,14 +32,14 @@ sineTable:
|
||||
.byte $4F, $52, $55, $58, $5B, $5E, $61, $64
|
||||
.byte $67, $6A, $6D, $70, $74, $77, $7A, $7D
|
||||
|
||||
vramRowEnds:
|
||||
.word $20a0,$2140,$21e0,$2280,$2320,$23c0,$2460,$2500,$25a0,$2640,$26e0,$2780,$2820,$28c0,$2960,$2a00,$2aa0,$2b40,$2be0,$2c80
|
||||
.word $2d20,$2dc0,$2e60,$2f00,$2fa0,$3040,$30e0,$3180,$3220,$32c0,$3360,$3400,$34a0,$3540,$35e0,$3680,$3720,$37c0,$3860,$3900
|
||||
.word $39a0,$3a40,$3ae0,$3b80,$3c20,$3cc0,$3d60,$3e00,$3ea0,$3f40,$3fe0,$4080,$4120,$41c0,$4260,$4300,$43a0,$4440,$44e0,$4580
|
||||
.word $4620,$46c0,$4760,$4800,$48a0,$4940,$49e0,$4a80,$4b20,$4bc0,$4c60,$4d00,$4da0,$4e40,$4ee0,$4f80,$5020,$50c0,$5160,$5200
|
||||
.word $52a0,$5340,$53e0,$5480,$5520,$55c0,$5660,$5700,$57a0,$5840,$58e0,$5980,$5a20,$5ac0,$5b60,$5c00,$5ca0,$5d40,$5de0,$5e80
|
||||
.word $5f20,$5fc0,$6060,$6100,$61a0,$6240,$62e0,$6380,$6420,$64c0,$6560,$6600,$66a0,$6740,$67e0,$6880,$6920,$69c0,$6a60,$6b00
|
||||
.word $6ba0,$6c40,$6ce0,$6d80,$6e20,$6ec0,$6f60,$7000,$70a0,$7140,$71e0,$7280,$7320,$73c0,$7460,$7500,$75a0,$7640,$76e0,$7780
|
||||
.word $7820,$78c0,$7960,$7a00,$7aa0,$7b40,$7be0,$7c80,$7d20,$7dc0,$7e60,$7f00,$7fa0,$8040,$80e0,$8180,$8220,$82c0,$8360,$8400
|
||||
.word $84a0,$8540,$85e0,$8680,$8720,$87c0,$8860,$8900,$89a0,$8a40,$8ae0,$8b80,$8c20,$8cc0,$8d60,$8e00,$8ea0,$8f40,$8fe0,$9080
|
||||
.word $9120,$91c0,$9260,$9300,$93a0,$9440,$94e0,$9580,$9620,$96c0,$9760,$9800,$98a0,$9940,$99e0,$9a80,$9b20,$9bc0,$9c60,$9d00
|
||||
vramRowEndsMinusOne:
|
||||
.word $209f,$213f,$21df,$227f,$231f,$23bf,$245f,$24ff,$259f,$263f,$26df,$277f,$281f,$28bf,$295f,$29ff,$2a9f,$2b3f,$2bdf,$2c7f
|
||||
.word $2d1f,$2dbf,$2e5f,$2eff,$2f9f,$303f,$30df,$317f,$321f,$32bf,$335f,$33ff,$349f,$353f,$35df,$367f,$371f,$37bf,$385f,$38ff
|
||||
.word $399f,$3a3f,$3adf,$3b7f,$3c1f,$3cbf,$3d5f,$3dff,$3e9f,$3f3f,$3fdf,$407f,$411f,$41bf,$425f,$42ff,$439f,$443f,$44df,$457f
|
||||
.word $461f,$46bf,$475f,$47ff,$489f,$493f,$49df,$4a7f,$4b1f,$4bbf,$4c5f,$4cff,$4d9f,$4e3f,$4edf,$4f7f,$501f,$50bf,$515f,$51ff
|
||||
.word $529f,$533f,$53df,$547f,$551f,$55bf,$565f,$56ff,$579f,$583f,$58df,$597f,$5a1f,$5abf,$5b5f,$5bff,$5c9f,$5d3f,$5ddf,$5e7f
|
||||
.word $5f1f,$5fbf,$605f,$60ff,$619f,$623f,$62df,$637f,$641f,$64bf,$655f,$65ff,$669f,$673f,$67df,$687f,$691f,$69bf,$6a5f,$6aff
|
||||
.word $6b9f,$6c3f,$6cdf,$6d7f,$6e1f,$6ebf,$6f5f,$6fff,$709f,$713f,$71df,$727f,$731f,$73bf,$745f,$74ff,$759f,$763f,$76df,$777f
|
||||
.word $781f,$78bf,$795f,$79ff,$7a9f,$7b3f,$7bdf,$7c7f,$7d1f,$7dbf,$7e5f,$7eff,$7f9f,$803f,$80df,$817f,$821f,$82bf,$835f,$83ff
|
||||
.word $849f,$853f,$85df,$867f,$871f,$87bf,$885f,$88ff,$899f,$8a3f,$8adf,$8b7f,$8c1f,$8cbf,$8d5f,$8dff,$8e9f,$8f3f,$8fdf,$907f
|
||||
.word $911f,$91bf,$925f,$92ff,$939f,$943f,$94df,$957f,$961f,$96bf,$975f,$97ff,$989f,$993f,$99df,$9a7f,$9b1f,$9bbf,$9c5f,$9cff
|
||||
|
418
terrain.s
418
terrain.s
@ -8,6 +8,218 @@
|
||||
TERRAINWIDTH = 640 ; In pixels
|
||||
MAXTERRAINHEIGHT = 100 ; In pixels
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderTerrain
|
||||
;
|
||||
; No stack operations permitted here!
|
||||
;
|
||||
renderTerrain:
|
||||
lda #199*2
|
||||
sta <ROWINDEX
|
||||
sty <MAPSCROLLPOS
|
||||
|
||||
FASTGRAPHICS
|
||||
|
||||
renderTerrainLoop:
|
||||
; = 29 cycles per row
|
||||
ldy <ROWINDEX ; 3
|
||||
lda vramRowEndsMinusOne,y ; 4 Point stack to end of VRAM row
|
||||
tcs ; 2
|
||||
|
||||
jmp renderClippedSpanChain ; 3
|
||||
|
||||
renderSpanChainComplete:
|
||||
lda <ROWINDEX ; 3
|
||||
dec ; 2
|
||||
dec ; 2
|
||||
cmp #(200-MAXTERRAINHEIGHT)*2 ; 2
|
||||
beq renderTerrainDone ; 2/3
|
||||
sta <ROWINDEX ; 3
|
||||
bra renderTerrainLoop ; 2/3
|
||||
|
||||
renderTerrainDone:
|
||||
SLOWGRAPHICS
|
||||
rts
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderClippedSpanChain
|
||||
;
|
||||
; No stack operations permitted here!
|
||||
;
|
||||
;
|
||||
renderClippedSpanChain:
|
||||
|
||||
; Prepare our state
|
||||
; = 24 cycles per row + 80 cycles for actual pixels
|
||||
lda #80 ; 2
|
||||
sta <XLEFT ; 3
|
||||
lda #$1111 ; 2
|
||||
sta <CURRMAPPIXELS ; 3
|
||||
ldy #spanChainEnd-spanChain-2 ; 2
|
||||
lda <MAPSCROLLPOS ; 3
|
||||
sta <RIGHTEDGE ; 3
|
||||
lda #renderClippedSpanChainRenderNext ; 2
|
||||
sta renderSpanComplete+1 ; 4
|
||||
|
||||
; Find right edge of screen within span chains
|
||||
; = 27 cycles per skipped span
|
||||
renderClippedSpanChainLoop:
|
||||
|
||||
lda spanChain,y ; 5
|
||||
sec ; 2
|
||||
sbc <RIGHTEDGE ; 3
|
||||
bmi renderClippedSpanChainNextSpan ; 2/3
|
||||
beq renderClippedSpanChainNextSpan ; 2/3
|
||||
|
||||
renderClippedSpanChainLoop2:
|
||||
; Now render spans until left edge of screen
|
||||
; = 28 cycles per span rendered
|
||||
cmp <XLEFT ; 3
|
||||
bcs renderClippedSpanChainLastSpan ; 2/3
|
||||
|
||||
; Render this span
|
||||
ldx spanColors,y ; 4
|
||||
stx <CURRMAPPIXELS ; 3
|
||||
|
||||
asl ; 2
|
||||
tax ; 2
|
||||
jmp (renderSpanJumpTable,x) ; 6 (jmp back = 6)
|
||||
|
||||
renderSpanComplete:
|
||||
; This is modified to redirect return from the
|
||||
; unrolled span rendering blocks
|
||||
jmp renderClippedSpanChainRenderNext ; 3
|
||||
|
||||
|
||||
renderClippedSpanChainRenderNext:
|
||||
; Track remaining words until left edge
|
||||
; = 26 cycles per span rendered
|
||||
lsr ; 2
|
||||
eor #$ffff ; 2
|
||||
inc ; 2
|
||||
clc ; 2
|
||||
adc <XLEFT ; 3
|
||||
sta <XLEFT ; 3
|
||||
dey ; 2
|
||||
dey ; 2
|
||||
|
||||
; For mid-stream spans, bypass the right-edge clipping code
|
||||
lda spanChain,y ; 5
|
||||
bra renderClippedSpanChainLoop2 ; 3
|
||||
|
||||
renderClippedSpanChainNextSpan:
|
||||
; Track remaining distance from right edge and
|
||||
; continue searching for visible right edge
|
||||
eor #$ffff ; 2
|
||||
inc ; 2
|
||||
sta <RIGHTEDGE ; 3
|
||||
dey ; 2
|
||||
dey ; 2
|
||||
bra renderClippedSpanChainLoop ; 3
|
||||
|
||||
renderClippedSpanChainLastSpan:
|
||||
; Render visible portion of last visible span
|
||||
; = 26 cycles per row
|
||||
ldx spanColors,y ; 4
|
||||
stx <CURRMAPPIXELS ; 3
|
||||
|
||||
lda <XLEFT ; 3
|
||||
asl ; 2
|
||||
tax ; 2
|
||||
|
||||
lda #renderSpanChainComplete ; 2
|
||||
sta renderSpanComplete+1 ; 4
|
||||
jmp (renderSpanJumpTable,x) ; 6
|
||||
|
||||
|
||||
|
||||
; Clipping state in zero page. All distances in words (4 px)
|
||||
MAPSCROLLPOS = $06 ; Right edge of visible region
|
||||
XLEFT = $08 ; Remaining horizontal distance to render
|
||||
RIGHTEDGE = $19 ; Distance from right edge of terrain to right edge of visible region
|
||||
CURRMAPPIXELS = $67 ; 4 pixels being rendered right now
|
||||
ROWINDEX = $69 ; Index of row being rendered
|
||||
|
||||
spanChain:
|
||||
.word 20,40,10,5,5,5,5,10,40,20
|
||||
spanChainEnd:
|
||||
|
||||
spanColors:
|
||||
.word $1111,$0000,$1111,$0000,$1111,$0000,$1111,$0000,$1111,$0000
|
||||
|
||||
spanChainIndex:
|
||||
.word 0
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; generateTerrain
|
||||
;
|
||||
; Trashes A and Y
|
||||
;
|
||||
|
||||
generateTerrain:
|
||||
ldy #0
|
||||
lda #terrainData
|
||||
sta SCRATCHL
|
||||
|
||||
generateTerrainLoop:
|
||||
|
||||
phy
|
||||
tya ; Pull an interesting value out of the sine table
|
||||
and #$00ff
|
||||
tay
|
||||
lda sineTable,y
|
||||
and #$7f7f
|
||||
ply
|
||||
|
||||
sta (SCRATCHL),y
|
||||
iny
|
||||
cpy #TERRAINWIDTH/4
|
||||
bne generateTerrainLoop
|
||||
|
||||
rts
|
||||
|
||||
|
||||
.include "spanRender.s"
|
||||
|
||||
; Terrain data, stored as height values 4 pixels wide
|
||||
|
||||
terrainData:
|
||||
.repeat TERRAINWIDTH/2
|
||||
.byte 0
|
||||
.endrepeat
|
||||
|
||||
|
||||
.if 0
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderSpanChain
|
||||
;
|
||||
; Trashes all registers
|
||||
; No stack operations permitted here!
|
||||
; This is fast, but doesn't support scrolling, so probably not useful
|
||||
;
|
||||
|
||||
renderSpanChain:
|
||||
stz spanChainIndex
|
||||
|
||||
renderSpanChainLoop:
|
||||
ldx spanChainIndex
|
||||
ldy spanChain+2,x
|
||||
lda spanChain,x
|
||||
beq renderSpanChainComplete
|
||||
dec
|
||||
asl
|
||||
tax
|
||||
jmp (renderSpanJumpTable,x)
|
||||
|
||||
;renderSpanComplete:
|
||||
inc spanChainIndex
|
||||
inc spanChainIndex
|
||||
inc spanChainIndex
|
||||
inc spanChainIndex
|
||||
bra renderSpanChainLoop
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderTerrainColumn
|
||||
;
|
||||
@ -93,209 +305,5 @@ renderTerrainColumnsLoop:
|
||||
|
||||
renderTerrainColumnsDone:
|
||||
rts
|
||||
.endif
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderTerrain
|
||||
;
|
||||
; No stack operations permitted here!
|
||||
;
|
||||
renderTerrain:
|
||||
lda #199
|
||||
sta spanChainIndex
|
||||
sty <MAPSCROLLPOS
|
||||
|
||||
FASTGRAPHICS
|
||||
|
||||
renderTerrainLoop:
|
||||
lda spanChainIndex
|
||||
asl
|
||||
tay
|
||||
lda vramRowEnds,y ;$9d00-1 ; Point stack to end of VRAM row
|
||||
dec
|
||||
tcs
|
||||
|
||||
jmp renderClippedSpanChain
|
||||
|
||||
renderSpanChainComplete:
|
||||
lda spanChainIndex
|
||||
dec
|
||||
cmp #200-MAXTERRAINHEIGHT
|
||||
beq renderTerrainDone
|
||||
sta spanChainIndex
|
||||
bra renderTerrainLoop
|
||||
|
||||
renderTerrainDone:
|
||||
SLOWGRAPHICS
|
||||
rts
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderSpanChain
|
||||
;
|
||||
; Trashes all registers
|
||||
; No stack operations permitted here!
|
||||
;
|
||||
|
||||
renderSpanChain:
|
||||
stz spanChainIndex
|
||||
|
||||
renderSpanChainLoop:
|
||||
ldx spanChainIndex
|
||||
ldy spanChain+2,x
|
||||
lda spanChain,x
|
||||
beq renderSpanChainComplete
|
||||
dec
|
||||
asl
|
||||
tax
|
||||
jmp (renderSpanJumpTable,x)
|
||||
|
||||
;renderSpanComplete:
|
||||
inc spanChainIndex
|
||||
inc spanChainIndex
|
||||
inc spanChainIndex
|
||||
inc spanChainIndex
|
||||
bra renderSpanChainLoop
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; renderClippedSpanChain
|
||||
;
|
||||
; No stack operations permitted here!
|
||||
;
|
||||
;
|
||||
renderClippedSpanChain:
|
||||
|
||||
; Prepare our state
|
||||
lda #80
|
||||
sta <XLEFT
|
||||
lda #$1111
|
||||
sta <CURRMAPPIXELS
|
||||
ldy #spanChainEnd-spanChain-2
|
||||
lda <MAPSCROLLPOS
|
||||
sta <RIGHTEDGE
|
||||
lda #renderClippedSpanChainRenderNext
|
||||
sta renderSpanComplete+1
|
||||
|
||||
; Find right edge of screen within span chains
|
||||
renderClippedSpanChainLoop:
|
||||
|
||||
lda spanChain,y ; 5
|
||||
sec ; 2
|
||||
sbc <RIGHTEDGE ; 3
|
||||
bmi renderClippedSpanChainNextSpan ; 2/3
|
||||
beq renderClippedSpanChainNextSpan ; 2/3
|
||||
|
||||
renderClippedSpanChainLoop2:
|
||||
cmp <XLEFT ; 3
|
||||
bcs renderClippedSpanChainLastSpan ; 2/3
|
||||
|
||||
; Render this span
|
||||
ldx spanColors,y ; 4
|
||||
stx <CURRMAPPIXELS ; 3
|
||||
|
||||
asl ; 2
|
||||
tax ; 2
|
||||
jmp (renderSpanJumpTable,x) ; 6
|
||||
|
||||
renderSpanComplete:
|
||||
; This is modified to redirect return from the
|
||||
; unrolled span rendering blocks
|
||||
jmp renderClippedSpanChainRenderNext ; 3
|
||||
|
||||
|
||||
renderClippedSpanChainRenderNext:
|
||||
|
||||
; Track remaining words until left edge
|
||||
lsr ; 2
|
||||
eor #$ffff ; 2
|
||||
inc ; 2
|
||||
clc ; 2
|
||||
adc <XLEFT ; 3
|
||||
sta <XLEFT ; 3
|
||||
dey ; 2
|
||||
dey ; 2
|
||||
|
||||
; For mid-stream spans, bypass the right-edge clipping code
|
||||
lda spanChain,y ; 5
|
||||
bra renderClippedSpanChainLoop2 ; 3
|
||||
|
||||
renderClippedSpanChainNextSpan:
|
||||
; Track remaining distance from right edge and
|
||||
; continue searching for visible right edge
|
||||
eor #$ffff ; 2
|
||||
inc ; 2
|
||||
sta <RIGHTEDGE ; 3
|
||||
dey ; 2
|
||||
dey ; 2
|
||||
bra renderClippedSpanChainLoop ; 3
|
||||
|
||||
renderClippedSpanChainLastSpan:
|
||||
|
||||
; Render visible portion of last visible span
|
||||
ldx spanColors,y ; 4
|
||||
stx <CURRMAPPIXELS ; 3
|
||||
|
||||
lda <XLEFT ; 3
|
||||
asl ; 2
|
||||
tax ; 2
|
||||
|
||||
lda #renderSpanChainComplete
|
||||
sta renderSpanComplete+1
|
||||
jmp (renderSpanJumpTable,x) ; 6
|
||||
|
||||
|
||||
|
||||
; Clipping state in zero page. All distances in words (4 px)
|
||||
MAPSCROLLPOS = $06 ; Right edge of visible region
|
||||
XLEFT = $08 ; Remaining horizontal distance to render
|
||||
RIGHTEDGE = $19 ; Distance from right edge of terrain to right edge of visible region
|
||||
CURRMAPPIXELS = $67 ; 4 pixels being rendered right now
|
||||
|
||||
spanChain:
|
||||
.word 20,40,10,5,5,5,5,10,40,20
|
||||
spanChainEnd:
|
||||
|
||||
spanColors:
|
||||
.word $1111,$0000,$1111,$0000,$1111,$0000,$1111,$0000,$1111,$0000
|
||||
|
||||
spanChainIndex:
|
||||
.word 0
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; generateTerrain
|
||||
;
|
||||
; Trashes A and Y
|
||||
;
|
||||
|
||||
generateTerrain:
|
||||
ldy #0
|
||||
lda #terrainData
|
||||
sta SCRATCHL
|
||||
|
||||
generateTerrainLoop:
|
||||
|
||||
phy
|
||||
tya ; Pull an interesting value out of the sine table
|
||||
and #$00ff
|
||||
tay
|
||||
lda sineTable,y
|
||||
and #$7f7f
|
||||
ply
|
||||
|
||||
sta (SCRATCHL),y
|
||||
iny
|
||||
cpy #TERRAINWIDTH/4
|
||||
bne generateTerrainLoop
|
||||
|
||||
rts
|
||||
|
||||
|
||||
.include "spanRender.s"
|
||||
|
||||
; Terrain data, stored as height values 4 pixels wide
|
||||
|
||||
terrainData:
|
||||
.repeat TERRAINWIDTH/2
|
||||
.byte 0
|
||||
.endrepeat
|
||||
|
Loading…
x
Reference in New Issue
Block a user