Improved terrain data structure

Terrain debug rendering
This commit is contained in:
blondie7575 2017-07-30 11:54:37 -07:00
parent 2e8dfde290
commit b60043e4b2
9 changed files with 213 additions and 43 deletions

View File

@ -7,6 +7,9 @@
objects = {
/* Begin PBXFileReference section */
700C39C51F2E5CA800C24F9C /* trigtables.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = trigtables.s; sourceTree = "<group>"; };
706DF1641F2D39F700AA6680 /* loader.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = loader.s; sourceTree = "<group>"; };
706DF1651F2D4A8100AA6680 /* terrain.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = terrain.s; sourceTree = "<group>"; };
70E9D85F1F2BD95400555C19 /* equates.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = equates.s; sourceTree = "<group>"; };
70E9D8601F2BD95400555C19 /* graphics.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = graphics.s; sourceTree = "<group>"; };
70E9D8611F2BD95400555C19 /* gscats.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gscats.s; sourceTree = "<group>"; };
@ -21,6 +24,9 @@
70E9D85F1F2BD95400555C19 /* equates.s */,
70E9D8601F2BD95400555C19 /* graphics.s */,
70E9D8621F2BD95400555C19 /* macros.s */,
706DF1641F2D39F700AA6680 /* loader.s */,
706DF1651F2D4A8100AA6680 /* terrain.s */,
700C39C51F2E5CA800C24F9C /* trigtables.s */,
70E9D8611F2BD95400555C19 /* gscats.s */,
70E9D8631F2BD95400555C19 /* Makefile */,
);

Binary file not shown.

View File

@ -19,3 +19,4 @@ PARAML1 = $08
SCRATCH0 = $19
SCRATCH1 = $1a
SCRATCHL = $19 ; 16-bit version of scratch
PARAM24 = $67 ; 24-bit param (This is almost certainly messing up AppleSoft, but meh)

Binary file not shown.

View File

@ -1,6 +1,5 @@
;
; gsshr
; GS sample application
; gscats
;
; Created by Quinn Dunki on 7/9/17
;
@ -8,43 +7,7 @@
.include "macros.s"
.include "equates.s"
.org $800
main:
NATIVE
mainCopyStart:
ldx #0
lda #mainBank2
sta mainCopyDest+1
mainCopyLoop:
lda mainBank2,x
mainCopyDest:
sta $020800,x
inx
cpx #endMainBank2-mainBank2
bne mainCopyLoop
lda #returnToProDOS
sta proDOSLongJump
lda #mainBank2
sta mainLongJump
jml (mainLongJump)
returnToProDOS:
SYNCDBR
EMULATION
rts
mainLongJump:
.byte 00,08,02
proDOSLongJump:
.byte 00,00,00
.include "loader.s"
mainBank2:
SYNCDBR
@ -54,6 +17,7 @@ mainBank2:
sta TEXTCOLOR
BITS16
; Set up SCBs
jsr initSCBs
SHRVIDEO
@ -62,9 +26,12 @@ mainBank2:
lda #0
jsr setPalette
ldx #$1111
ldx #$2222
jsr colorFill
jsr generateTerrain
jsr renderTerrainColumns
jsr kbdWait
CLASSICVIDEO
@ -91,12 +58,12 @@ kbdWaitLoop:
basePalette:
.word $0F00,$00F0,$000F,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
.word $0000,$0080,$0000,$000F,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0000
.include "graphics.s"
.include "terrain.s"
.include "trigTables.s"
endMainBank2:

52
loader.s Normal file
View File

@ -0,0 +1,52 @@
;
; loader
; A very simplistic code loader designed to manage
; GS code under ProDOS 8 (if it's good enough for Will Harvey...)
;
; Created by Quinn Dunki on 7/29/17
;
.org $800
main:
NATIVE
; Copy main code that ProDOS 8 loaded into bank 2.
; Bank 2 is our "main" code bank because the GS fast
; graphics path really messes with banks 0 and 1.
; ProDOS 8 doesn't know anything about non-zero banks
; though, so things get loaded here and moved.
mainCopyStart:
ldx #0
lda #mainBank2
sta mainCopyDest+1
mainCopyLoop:
lda mainBank2,x
mainCopyDest:
sta $020800,x
inx
cpx #endMainBank2-mainBank2
bne mainCopyLoop
; Set up a long jump into bank 2, and
; a way for game code to get back here to exit
; properly to ProDOS 8
lda #returnToProDOS
sta proDOSLongJump
lda #mainBank2
sta mainLongJump
jml (mainLongJump)
returnToProDOS:
SYNCDBR
EMULATION
rts
mainLongJump:
.byte 00,08,02
proDOSLongJump:
.byte 00,00,00

View File

@ -110,6 +110,12 @@
.endmacro
.macro LOADPARAM24 bankNumDoubled,addr16
lda #bankNumDoubled
sta PARAM24+1
lda #addr16
sta PARAM24
.endmacro
;;;;;;;;;;
; Stack Macros

105
terrain.s Normal file
View File

@ -0,0 +1,105 @@
;
; terrain
;
; Created by Quinn Dunki on 7/29/17
;
TERRAINWIDTH = 320 ; In pixels
MAXTERRAINHEIGHT = 80 ; In pixels
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderTerrainColumn
;
; This is not fast- probably only useful for debugging
;
; Y = Index into height data
; PARAM24 = 24-bit pointer to bottom of column in VRAM
;
; Trashes A and X
renderTerrainColumn:
phy
BITS8
lda PARAM24+2
sta renderTerrainColumnSMC+3
BITS16
ply
lda PARAM24
sta renderTerrainColumnSMC+1
pha ; Cache 16-bit VRAM pointer on the stack
lda terrainData,y
and #$00ff
tax
renderTerrainColumnLoop:
dex
beq renderTerrainColumnDone
lda #$1111
renderTerrainColumnSMC:
sta $e19c60
pla
sec
sbc #160
sta renderTerrainColumnSMC+1
pha
bra renderTerrainColumnLoop
renderTerrainColumnDone:
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; renderTerrainColumns
;
; This is not fast- probably only useful for debugging
;
renderTerrainColumns:
LOADPARAM24 $e1e1,$9c60
ldy #0
renderTerrainColumnsLoop:
jsr renderTerrainColumn
iny
cpy #TERRAINWIDTH/4
beq renderTerrainColumnsDone
inc PARAM24
inc PARAM24
bra renderTerrainColumnsLoop
renderTerrainColumnsDone:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; generateTerrain
;
; Trashes A and Y
;
generateTerrain:
ldy #0
lda #terrainData
sta SCRATCHL
lda #MAXTERRAINHEIGHT
generateTerrainLoop:
sta (SCRATCHL),y
iny
cpy #TERRAINWIDTH/4
bne generateTerrainLoop
rts
; Terrain data, stored as height values 4 pixels wide
terrainData:
.repeat TERRAINWIDTH/4
.byte 0
.endrepeat

33
trigtables.s Normal file
View File

@ -0,0 +1,33 @@
sineTable:
.byte $80, $83, $86, $89, $8C, $90, $93, $96
.byte $99, $9C, $9F, $A2, $A5, $A8, $AB, $AE
.byte $B1, $B3, $B6, $B9, $BC, $BF, $C1, $C4
.byte $C7, $C9, $CC, $CE, $D1, $D3, $D5, $D8
.byte $DA, $DC, $DE, $E0, $E2, $E4, $E6, $E8
.byte $EA, $EB, $ED, $EF, $F0, $F1, $F3, $F4
.byte $F5, $F6, $F8, $F9, $FA, $FA, $FB, $FC
.byte $FD, $FD, $FE, $FE, $FE, $FF, $FF, $FF
.byte $FF, $FF, $FF, $FF, $FE, $FE, $FE, $FD
.byte $FD, $FC, $FB, $FA, $FA, $F9, $F8, $F6
.byte $F5, $F4, $F3, $F1, $F0, $EF, $ED, $EB
.byte $EA, $E8, $E6, $E4, $E2, $E0, $DE, $DC
.byte $DA, $D8, $D5, $D3, $D1, $CE, $CC, $C9
.byte $C7, $C4, $C1, $BF, $BC, $B9, $B6, $B3
.byte $B1, $AE, $AB, $A8, $A5, $A2, $9F, $9C
.byte $99, $96, $93, $90, $8C, $89, $86, $83
.byte $80, $7D, $7A, $77, $74, $70, $6D, $6A
.byte $67, $64, $61, $5E, $5B, $58, $55, $52
.byte $4F, $4D, $4A, $47, $44, $41, $3F, $3C
.byte $39, $37, $34, $32, $2F, $2D, $2B, $28
.byte $26, $24, $22, $20, $1E, $1C, $1A, $18
.byte $16, $15, $13, $11, $10, $0F, $0D, $0C
.byte $0B, $0A, $08, $07, $06, $06, $05, $04
.byte $03, $03, $02, $02, $02, $01, $01, $01
.byte $01, $01, $01, $01, $02, $02, $02, $03
.byte $03, $04, $05, $06, $06, $07, $08, $0A
.byte $0B, $0C, $0D, $0F, $10, $11, $13, $15
.byte $16, $18, $1A, $1C, $1E, $20, $22, $24
.byte $26, $28, $2B, $2D, $2F, $32, $34, $37
.byte $39, $3C, $3F, $41, $44, $47, $4A, $4D
.byte $4F, $52, $55, $58, $5B, $5E, $61, $64
.byte $67, $6A, $6D, $70, $74, $77, $7A, $7D