2017-07-30 18:54:37 +00:00
|
|
|
;
|
|
|
|
; terrain
|
|
|
|
;
|
|
|
|
; Created by Quinn Dunki on 7/29/17
|
|
|
|
;
|
|
|
|
|
|
|
|
|
2017-07-30 22:43:55 +00:00
|
|
|
TERRAINWIDTH = 640 ; In pixels
|
2017-08-12 22:41:25 +00:00
|
|
|
MAXTERRAINHEIGHT = 100 ; In pixels
|
2017-08-13 01:17:14 +00:00
|
|
|
COMPILEDTERRAINROW = TERRAINWIDTH/4+3 ; In words, +2 to make room for clipping jump at end of row
|
|
|
|
VISIBLETERRAINWIDTH = TERRAINWIDTH/4 ; In words- width minus jump return padding
|
|
|
|
VISIBLETERRAINWINDOW = 80 ; In words
|
2017-07-30 18:54:37 +00:00
|
|
|
|
2017-07-31 03:23:32 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; renderTerrain
|
|
|
|
;
|
|
|
|
; No stack operations permitted here!
|
|
|
|
;
|
2017-08-12 22:41:25 +00:00
|
|
|
; Current implementation: X cycles per row
|
|
|
|
; Trashes all registers
|
2017-08-08 05:10:16 +00:00
|
|
|
;
|
2017-07-31 03:23:32 +00:00
|
|
|
renderTerrain:
|
|
|
|
FASTGRAPHICS
|
2017-08-12 22:41:25 +00:00
|
|
|
ldy #MAXTERRAINHEIGHT
|
|
|
|
lda #$9cff ; 4 Point stack to end of VRAM
|
|
|
|
tcs ; 2
|
|
|
|
|
|
|
|
sec
|
2017-08-13 01:17:14 +00:00
|
|
|
lda #compiledTerrainEnd-VISIBLETERRAINWINDOW-3
|
2017-08-12 22:41:25 +00:00
|
|
|
sbc mapScrollPos
|
|
|
|
sta PARAML0
|
2017-07-31 03:23:32 +00:00
|
|
|
|
2017-08-06 19:52:21 +00:00
|
|
|
renderTerrainLoop:
|
2017-08-12 22:41:25 +00:00
|
|
|
lda #$0000 ; Background
|
|
|
|
ldx #$1111 ; Foreground
|
|
|
|
jmp (PARAML0)
|
2017-07-31 03:23:32 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
renderRowComplete:
|
|
|
|
lda PARAML0
|
|
|
|
sec
|
2017-08-13 01:17:14 +00:00
|
|
|
sbc #COMPILEDTERRAINROW
|
2017-08-12 22:41:25 +00:00
|
|
|
sta PARAML0
|
|
|
|
dey
|
|
|
|
bne renderTerrainLoop
|
2017-07-31 03:23:32 +00:00
|
|
|
|
|
|
|
SLOWGRAPHICS
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-30 18:54:37 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-08-12 22:41:25 +00:00
|
|
|
; clipTerrain
|
2017-07-30 18:54:37 +00:00
|
|
|
;
|
|
|
|
;
|
2017-08-12 22:41:25 +00:00
|
|
|
clipTerrain:
|
|
|
|
SAVE_AXY
|
2017-07-31 03:23:32 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
sec
|
2017-08-13 01:17:14 +00:00
|
|
|
lda #COMPILEDTERRAINROW*MAXTERRAINHEIGHT-3
|
2017-08-12 22:41:25 +00:00
|
|
|
sbc mapScrollPos
|
|
|
|
tay
|
|
|
|
ldx #MAXTERRAINHEIGHT
|
2017-07-30 18:54:37 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
clipTerrainLoop:
|
|
|
|
clc ; Compute buffer to for saved data
|
|
|
|
txa
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
adc #clippedTerrainData-4
|
|
|
|
sta PARAML0
|
2017-07-30 19:16:19 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
lda compiledTerrain,y
|
|
|
|
sta (PARAML0) ; Preserve data we're overwriting
|
|
|
|
inc PARAML0
|
|
|
|
inc PARAML0
|
2017-07-30 19:16:19 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
and #$ff00
|
|
|
|
ora #$004c ; jmp in low byte
|
|
|
|
sta compiledTerrain,y
|
2017-07-30 18:54:37 +00:00
|
|
|
iny
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
lda compiledTerrain,y
|
|
|
|
sta (PARAML0) ; Preserve data we're overwriting
|
2017-07-30 18:54:37 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
lda #renderRowComplete
|
|
|
|
sta compiledTerrain,y
|
2017-07-30 18:54:37 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
tya
|
|
|
|
sec
|
2017-08-13 01:17:14 +00:00
|
|
|
sbc #COMPILEDTERRAINROW+1
|
2017-08-12 22:41:25 +00:00
|
|
|
tay
|
2017-07-31 03:23:32 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
dex
|
|
|
|
bne clipTerrainLoop
|
2017-07-30 18:54:37 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
RESTORE_AXY
|
|
|
|
rts
|
2017-08-06 20:26:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-08-12 22:41:25 +00:00
|
|
|
; unclipTerrain
|
2017-08-06 20:26:31 +00:00
|
|
|
;
|
|
|
|
;
|
2017-08-12 22:41:25 +00:00
|
|
|
unclipTerrain:
|
|
|
|
SAVE_AXY
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
sec
|
2017-08-13 01:17:14 +00:00
|
|
|
lda #COMPILEDTERRAINROW*MAXTERRAINHEIGHT-3
|
2017-08-12 22:41:25 +00:00
|
|
|
sbc mapScrollPos
|
|
|
|
tay
|
|
|
|
ldx #MAXTERRAINHEIGHT
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
unclipTerrainLoop:
|
|
|
|
clc ; Compute buffer that saved data is in
|
|
|
|
txa
|
|
|
|
asl
|
2017-08-06 20:26:31 +00:00
|
|
|
asl
|
2017-08-12 22:41:25 +00:00
|
|
|
adc #clippedTerrainData-4
|
|
|
|
sta PARAML0
|
|
|
|
|
|
|
|
lda (PARAML0)
|
|
|
|
sta compiledTerrain,y
|
|
|
|
inc PARAML0
|
|
|
|
inc PARAML0
|
|
|
|
iny
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
lda (PARAML0)
|
|
|
|
sta compiledTerrain,y
|
|
|
|
|
|
|
|
tya
|
|
|
|
sec
|
2017-08-13 01:17:14 +00:00
|
|
|
sbc #COMPILEDTERRAINROW+1
|
2017-08-12 22:41:25 +00:00
|
|
|
tay
|
|
|
|
|
|
|
|
dex
|
|
|
|
bne unclipTerrainLoop
|
|
|
|
|
|
|
|
RESTORE_AXY
|
|
|
|
rts
|
2017-08-06 20:26:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-08-12 22:41:25 +00:00
|
|
|
; compileTerrain
|
2017-08-06 20:26:31 +00:00
|
|
|
;
|
|
|
|
;
|
|
|
|
;
|
2017-08-12 22:41:25 +00:00
|
|
|
compileTerrain:
|
|
|
|
SAVE_AY
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
ldy #MAXTERRAINHEIGHT-1
|
|
|
|
lda #compiledTerrain
|
|
|
|
sta PARAML0
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
compileTerrainLoop:
|
|
|
|
sty PARAML1
|
|
|
|
jsr compileTerrainRow
|
|
|
|
dey
|
|
|
|
bmi compileTerrainDone
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
clc
|
2017-08-13 01:17:14 +00:00
|
|
|
lda #COMPILEDTERRAINROW
|
2017-08-12 22:41:25 +00:00
|
|
|
adc PARAML0
|
|
|
|
sta PARAML0
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
bra compileTerrainLoop
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
compileTerrainDone:
|
|
|
|
RESTORE_AY
|
|
|
|
rts
|
2017-08-06 20:26:31 +00:00
|
|
|
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; compileTerrainRow
|
|
|
|
;
|
|
|
|
; PARAML0 = Start of compiled row data
|
|
|
|
; PARAML1 = Row index
|
|
|
|
;
|
|
|
|
compileTerrainRow:
|
|
|
|
SAVE_AXY
|
|
|
|
ldy #0
|
|
|
|
ldx #0
|
|
|
|
|
|
|
|
compileTerrainColumnLoop:
|
|
|
|
stz compileTerrainOpcode
|
|
|
|
|
|
|
|
; Right half
|
|
|
|
lda terrainData,x
|
|
|
|
cmp PARAML1
|
|
|
|
bcc compileTerrainColumnBGRight
|
|
|
|
beq compileTerrainColumnBGRight
|
|
|
|
lda #$00da
|
|
|
|
compileTerrainColumnLeft:
|
|
|
|
sta compileTerrainOpcode
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
lda terrainData,x
|
|
|
|
cmp PARAML1
|
|
|
|
bcc compileTerrainColumnBGLeft
|
|
|
|
beq compileTerrainColumnBGLeft
|
|
|
|
lda compileTerrainOpcode
|
|
|
|
ora #$da00
|
|
|
|
|
|
|
|
compileTerrainColumnStore:
|
|
|
|
sta (PARAML0),y
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
iny
|
|
|
|
iny
|
2017-08-13 01:17:14 +00:00
|
|
|
cpy #VISIBLETERRAINWIDTH
|
2017-08-12 22:41:25 +00:00
|
|
|
bne compileTerrainColumnLoop
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
RESTORE_AXY
|
2017-08-06 20:26:31 +00:00
|
|
|
rts
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
compileTerrainColumnBGRight:
|
|
|
|
lda #$0048
|
|
|
|
bra compileTerrainColumnLeft
|
|
|
|
|
|
|
|
compileTerrainColumnBGLeft:
|
|
|
|
lda compileTerrainOpcode
|
|
|
|
ora #$4800
|
|
|
|
bra compileTerrainColumnStore
|
|
|
|
|
|
|
|
compileTerrainOpcode:
|
2017-08-06 20:26:31 +00:00
|
|
|
.word 0
|
|
|
|
|
2017-08-13 21:56:23 +00:00
|
|
|
|
|
|
|
|
2017-08-06 20:26:31 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2017-08-12 22:41:25 +00:00
|
|
|
; generateTerrain
|
2017-08-06 20:26:31 +00:00
|
|
|
;
|
2017-08-13 04:25:36 +00:00
|
|
|
; Trashes everything
|
2017-08-06 20:26:31 +00:00
|
|
|
;
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
generateTerrain:
|
|
|
|
ldy #0
|
2017-08-13 04:25:36 +00:00
|
|
|
ldx #0
|
2017-08-12 22:41:25 +00:00
|
|
|
lda #terrainData
|
2017-08-06 20:26:31 +00:00
|
|
|
sta SCRATCHL
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
generateTerrainLoop:
|
|
|
|
|
2017-08-13 04:25:36 +00:00
|
|
|
lda sineTable,x
|
|
|
|
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
|
|
|
|
clc
|
|
|
|
adc #30
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
sta (SCRATCHL),y
|
|
|
|
iny
|
|
|
|
iny
|
2017-08-13 04:25:36 +00:00
|
|
|
|
2017-08-21 00:51:12 +00:00
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
|
2017-08-13 04:25:36 +00:00
|
|
|
txa
|
2017-08-20 22:15:46 +00:00
|
|
|
and #$03ff
|
2017-08-13 04:25:36 +00:00
|
|
|
tax
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
cpy #TERRAINWIDTH/2
|
|
|
|
bne generateTerrainLoop
|
2017-08-06 20:26:31 +00:00
|
|
|
|
2017-09-02 19:32:40 +00:00
|
|
|
lda #1
|
|
|
|
sta terrainData
|
2017-08-06 20:26:31 +00:00
|
|
|
rts
|
2017-08-12 22:41:25 +00:00
|
|
|
|
|
|
|
|
2017-08-31 19:55:02 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
; intersectRect
|
|
|
|
;
|
|
|
|
; A = non zero if rectangle is intersecting terrain
|
|
|
|
;
|
|
|
|
rectParams:
|
|
|
|
.word 0 ; x
|
|
|
|
.word 0 ; y 0=terrain bottom, +y=up
|
|
|
|
.word 0 ; w
|
|
|
|
.word 0 ; h
|
|
|
|
|
|
|
|
intersectRect:
|
|
|
|
phy
|
|
|
|
|
|
|
|
; Convert X to words and compute horizontal extent
|
|
|
|
; Note that X counts from right terrain edge
|
|
|
|
lda rectParams
|
|
|
|
clc
|
|
|
|
adc rectParams+4 ; Reverse rect horizontally
|
|
|
|
lsr ; Convert X to bytes
|
|
|
|
and #$fffe ; Force even
|
|
|
|
sta rectParams
|
|
|
|
|
|
|
|
lda #TERRAINWIDTH/2 ; Reverse X coordinate system
|
|
|
|
sec
|
|
|
|
sbc rectParams
|
|
|
|
sta rectParams
|
|
|
|
tay ; We'll need this later as an index into height data words
|
|
|
|
|
|
|
|
lsr rectParams+4 ; Convert width to bytes
|
|
|
|
sec
|
|
|
|
sbc rectParams+4 ; Convert width to extent
|
|
|
|
sta rectParams+4
|
|
|
|
|
|
|
|
; Convert height to vertical extent
|
|
|
|
lda rectParams+2
|
|
|
|
sec
|
|
|
|
sbc rectParams+6
|
|
|
|
sta rectParams+6
|
|
|
|
|
|
|
|
; Check Y bottom
|
|
|
|
intersectRectBottomLoop:
|
|
|
|
lda terrainData,y
|
|
|
|
cmp rectParams+6
|
|
|
|
bpl intersectRectYep
|
|
|
|
dey
|
|
|
|
dey
|
|
|
|
cpy rectParams+4
|
|
|
|
bpl intersectRectBottomLoop
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
ply
|
|
|
|
rts
|
|
|
|
|
|
|
|
intersectRectYep:
|
|
|
|
lda #1
|
|
|
|
ply
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
2017-08-12 22:41:25 +00:00
|
|
|
; Terrain data, stored as height values 4 pixels wide
|
|
|
|
|
|
|
|
terrainData:
|
2017-08-13 04:25:36 +00:00
|
|
|
.repeat TERRAINWIDTH/4 ; VISIBLETERRAINWIDTH
|
2017-08-12 22:41:25 +00:00
|
|
|
.word 0
|
|
|
|
.endrepeat
|
|
|
|
|
|
|
|
compiledTerrain:
|
2017-08-13 01:17:14 +00:00
|
|
|
.repeat COMPILEDTERRAINROW * MAXTERRAINHEIGHT
|
2017-08-12 22:41:25 +00:00
|
|
|
.byte 0
|
|
|
|
.endrepeat
|
|
|
|
compiledTerrainEnd:
|
|
|
|
|
|
|
|
clippedTerrainData:
|
|
|
|
.repeat MAXTERRAINHEIGHT
|
|
|
|
.byte 0,0,0,0 ; xx,jmp,addr
|
|
|
|
.endrepeat
|
2017-08-06 20:26:31 +00:00
|
|
|
|