mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-08-24 20:28:59 +00:00
Working on sprite-ization
This commit is contained in:
parent
65e7f9c5b0
commit
69116f7bad
@ -55,6 +55,7 @@ minX = $5C ; len 1
|
|||||||
maxX = $5D ; len 1
|
maxX = $5D ; len 1
|
||||||
minY = $5E ; len 1
|
minY = $5E ; len 1
|
||||||
maxY = $5F ; len 1
|
maxY = $5F ; len 1
|
||||||
|
screenCol = $60 ; len 1
|
||||||
|
|
||||||
; Other monitor locations
|
; Other monitor locations
|
||||||
a2l = $3E
|
a2l = $3E
|
||||||
|
@ -271,8 +271,12 @@ pow2_w_w:
|
|||||||
; Input: pRayData, plus Y reg: precalculated ray data (4 bytes)
|
; Input: pRayData, plus Y reg: precalculated ray data (4 bytes)
|
||||||
; playerX, playerY (integral and fractional bytes of course)
|
; playerX, playerY (integral and fractional bytes of course)
|
||||||
; pMap: pointer to current row on the map (mapBase + playerY{>}*height)
|
; pMap: pointer to current row on the map (mapBase + playerY{>}*height)
|
||||||
; Output: lineCt - height to draw in double-lines
|
; screenCol: column on the screen for buffer store
|
||||||
; txColumn - column in the texture to draw
|
; Output: (where x is screenCol)
|
||||||
|
; heightBuf,x - height to draw in double-lines
|
||||||
|
; depthBuf,x - depth (log of height basically), for compositing order
|
||||||
|
; txNumBuf,x - texture number to draw
|
||||||
|
; txColBuf,x - column in the texture to draw
|
||||||
castRay:
|
castRay:
|
||||||
; First, grab the precalculated ray data from the table.
|
; First, grab the precalculated ray data from the table.
|
||||||
ldx #1 ; default X step: forward one column of the map
|
ldx #1 ; default X step: forward one column of the map
|
||||||
@ -349,12 +353,6 @@ castRay:
|
|||||||
ldx playerY+1
|
ldx playerY+1
|
||||||
stx mapY
|
stx mapY
|
||||||
|
|
||||||
; Also init the min/max trackers
|
|
||||||
sty minX
|
|
||||||
sty maxX
|
|
||||||
stx minY
|
|
||||||
stx maxY
|
|
||||||
|
|
||||||
; the DDA algorithm
|
; the DDA algorithm
|
||||||
@DDA_step:
|
@DDA_step:
|
||||||
lda sideDistX
|
lda sideDistX
|
||||||
@ -386,7 +384,8 @@ castRay:
|
|||||||
; We hit something!
|
; We hit something!
|
||||||
@hitX:
|
@hitX:
|
||||||
DEBUG_STR " Hit."
|
DEBUG_STR " Hit."
|
||||||
sta txNum ; store the texture number we hit
|
ldx screenCol
|
||||||
|
sta txNumBuf,x ; store the texture number we hit
|
||||||
lda #0
|
lda #0
|
||||||
sec
|
sec
|
||||||
sbc playerX ; inverse of low byte of player coord
|
sbc playerX ; inverse of low byte of player coord
|
||||||
@ -409,12 +408,12 @@ castRay:
|
|||||||
bit stepX ; if stepping forward in X...
|
bit stepX ; if stepping forward in X...
|
||||||
bmi :+
|
bmi :+
|
||||||
eor #$FF ; ...invert the texture coord
|
eor #$FF ; ...invert the texture coord
|
||||||
: sta txColumn
|
: ldx screenCol
|
||||||
|
sta txColBuf,x ; and save the final coordinate
|
||||||
.if DEBUG
|
.if DEBUG
|
||||||
jmp @debugFinal
|
jsr @debugFinal
|
||||||
.else
|
|
||||||
rts
|
|
||||||
.endif
|
.endif
|
||||||
|
rts
|
||||||
; taking a step in the Y direction
|
; taking a step in the Y direction
|
||||||
@takeStepY:
|
@takeStepY:
|
||||||
lda pMap ; get ready to switch map row
|
lda pMap ; get ready to switch map row
|
||||||
@ -450,7 +449,8 @@ castRay:
|
|||||||
@hitY:
|
@hitY:
|
||||||
; We hit something!
|
; We hit something!
|
||||||
DEBUG_STR " Hit."
|
DEBUG_STR " Hit."
|
||||||
sta txNum ; store the texture number we hit
|
ldx screenCol
|
||||||
|
sta txNumBuf,x ; store the texture number we hit
|
||||||
lda #0
|
lda #0
|
||||||
sec
|
sec
|
||||||
sbc playerY ; inverse of low byte of player coord
|
sbc playerY ; inverse of low byte of player coord
|
||||||
@ -473,12 +473,12 @@ castRay:
|
|||||||
bit stepY ; if stepping backward in Y
|
bit stepY ; if stepping backward in Y
|
||||||
bpl :+
|
bpl :+
|
||||||
eor #$FF ; ...invert the texture coord
|
eor #$FF ; ...invert the texture coord
|
||||||
: sta txColumn
|
: ldx screenCol
|
||||||
|
sta txColBuf,x ; and save the final coord
|
||||||
.if DEBUG
|
.if DEBUG
|
||||||
jmp @debugFinal
|
jsr @debugFinal
|
||||||
.else
|
|
||||||
rts
|
|
||||||
.endif
|
.endif
|
||||||
|
rts
|
||||||
|
|
||||||
; wall calculation: X=dir1, Y=dir2, A=dir2step
|
; wall calculation: X=dir1, Y=dir2, A=dir2step
|
||||||
@wallCalc:
|
@wallCalc:
|
||||||
@ -549,23 +549,30 @@ castRay:
|
|||||||
sec
|
sec
|
||||||
sbc diff
|
sbc diff
|
||||||
tay
|
tay
|
||||||
sta depth
|
|
||||||
lda #6
|
lda #6
|
||||||
sbc diff+1
|
sbc diff+1
|
||||||
tax
|
tax
|
||||||
lsr ; Depth is 4 bits of exponent + upper 4 bits of mantissa
|
sta tmp
|
||||||
ror depth
|
tya
|
||||||
lsr
|
lsr tmp ; Depth is 4 bits of exponent + upper 4 bits of mantissa
|
||||||
ror depth
|
ror
|
||||||
lsr
|
lsr tmp
|
||||||
ror depth
|
ror
|
||||||
lsr
|
lsr tmp
|
||||||
ror depth
|
ror
|
||||||
|
lsr tmp
|
||||||
|
ror
|
||||||
|
pha ; stash it on stack (we don't have X reg free yet for indexed store)
|
||||||
jsr pow2_w_w ; calculate 2 ^ (log(64) - diff) =~ 64.0 / dist
|
jsr pow2_w_w ; calculate 2 ^ (log(64) - diff) =~ 64.0 / dist
|
||||||
cpx #0
|
cpx #0
|
||||||
beq :+
|
beq :+
|
||||||
lda #$FF ; clamp large line heights to 255
|
lda #$FF ; clamp large line heights to 255
|
||||||
: sta lineCt
|
: ldx screenCol
|
||||||
|
sta heightBuf,x ; save final height to the buffer
|
||||||
|
pla ; get the depth back...
|
||||||
|
sta depthBuf,x ; and save it too
|
||||||
|
lda #0
|
||||||
|
sta linkBuf,x ; might as well clear the link buffer while we're at it
|
||||||
; Update min/max trackers
|
; Update min/max trackers
|
||||||
lda mapX
|
lda mapX
|
||||||
cmp minX
|
cmp minX
|
||||||
@ -595,14 +602,17 @@ castRay:
|
|||||||
DEBUG_LN
|
DEBUG_LN
|
||||||
rts
|
rts
|
||||||
@debugFinal:
|
@debugFinal:
|
||||||
DEBUG_STR " lineCt="
|
ldx screenCol
|
||||||
DEBUG_BYTE lineCt
|
DEBUG_STR " height="
|
||||||
|
DEBUG_BYTE heightBuf,x
|
||||||
|
DEBUG_STR "depth="
|
||||||
|
DEBUG_BYTE depthBuf,x
|
||||||
DEBUG_STR "txNum="
|
DEBUG_STR "txNum="
|
||||||
DEBUG_BYTE txNum
|
DEBUG_BYTE txNumBuf,x
|
||||||
DEBUG_STR "txCol="
|
DEBUG_STR "txCol="
|
||||||
DEBUG_BYTE txColumn
|
DEBUG_BYTE txColBuf,x
|
||||||
DEBUG_LN
|
DEBUG_LN
|
||||||
jsr rdkey
|
jmp rdkey
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
; Advance pLine to the next line on the hi-res screen
|
; Advance pLine to the next line on the hi-res screen
|
||||||
@ -1249,25 +1259,33 @@ graphInit:
|
|||||||
rts
|
rts
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------
|
||||||
; Render one whole frame
|
; Draw all the rays from the current player coord
|
||||||
renderFrame:
|
drawAllRays:
|
||||||
.if DOUBLE_BUFFER
|
|
||||||
jsr setBackBuf
|
|
||||||
.endif
|
|
||||||
|
|
||||||
; Initialize pointer into precalculated ray table, based on player dir.
|
; Initialize pointer into precalculated ray table, based on player dir.
|
||||||
; The table has 256 bytes per direction.
|
; The table has 256 bytes per direction.
|
||||||
lda #0
|
ldx #0
|
||||||
sta pRayData
|
stx pRayData
|
||||||
lda playerDir
|
lda playerDir
|
||||||
clc
|
clc
|
||||||
adc #>precast_0
|
adc #>precast_0
|
||||||
sta pRayData+1
|
sta pRayData+1
|
||||||
|
|
||||||
|
; start at column zero
|
||||||
|
stx screenCol
|
||||||
|
|
||||||
|
; Init the min/max trackers, which are used after casting
|
||||||
|
; to filter out non-visible sprites
|
||||||
|
stx maxX
|
||||||
|
stx maxY
|
||||||
|
dex
|
||||||
|
stx minX
|
||||||
|
stx minY
|
||||||
|
|
||||||
; Calculate pointer to the map row based on playerY
|
; Calculate pointer to the map row based on playerY
|
||||||
lda mapBase ; start at row 0, col 0 of the map
|
lda mapBase ; start at row 0, col 0 of the map
|
||||||
ldy mapBase+1
|
ldy mapBase+1
|
||||||
ldx playerY+1 ; integral part of player's Y coord
|
ldx playerY+1 ; integer part of player's Y coord
|
||||||
beq @gotMapRow
|
beq @gotMapRow
|
||||||
clc
|
clc
|
||||||
@mapLup: ; advance forward one row
|
@mapLup: ; advance forward one row
|
||||||
@ -1278,34 +1296,42 @@ renderFrame:
|
|||||||
: dex ; until we reach players Y coord
|
: dex ; until we reach players Y coord
|
||||||
bne @mapLup
|
bne @mapLup
|
||||||
@gotMapRow:
|
@gotMapRow:
|
||||||
tax ; map row ptr now in X(lo) / Y(hi)
|
sta mapRayOrigin
|
||||||
|
sty mapRayOrigin+1
|
||||||
|
|
||||||
.if DEBUG
|
; Calculate the height, depth, texture number, and texture column for one ray
|
||||||
stx tmp
|
; [ref BigBlue3_50]
|
||||||
sty tmp+1
|
lda screenCol ; calculate ray offset...
|
||||||
DEBUG_STR "Initial pMap="
|
@oneCol:
|
||||||
DEBUG_WORD tmp
|
asl ; as screen column * 4
|
||||||
DEBUG_LN
|
asl
|
||||||
ldx tmp
|
tay
|
||||||
ldy tmp+1
|
lda mapRayOrigin ; set initial map pointer for the ray
|
||||||
|
sta pMap
|
||||||
|
lda mapRayOrigin+1
|
||||||
|
sta pMap+1
|
||||||
|
jsr castRay ; cast the ray across the map
|
||||||
|
inc screenCol ; advance to next column
|
||||||
|
lda screenCol
|
||||||
|
cmp #63 ; stop after we do 63 columns = 126 bw pix
|
||||||
|
bne @oneCol
|
||||||
|
rts
|
||||||
|
|
||||||
|
;-------------------------------------------------------------------------------
|
||||||
|
; Render one whole frame
|
||||||
|
renderFrame:
|
||||||
|
.if DOUBLE_BUFFER
|
||||||
|
jsr setBackBuf
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
|
jsr castAllRays
|
||||||
|
|
||||||
lda #0
|
lda #0
|
||||||
sta pixNum
|
sta pixNum
|
||||||
sta byteNum
|
sta byteNum
|
||||||
; A-reg needs to be zero at this point -- it is the ray offset.
|
sta screenCol
|
||||||
; Calculate the height, texture number, and texture column for one ray
|
|
||||||
; [ref BigBlue3_50]
|
|
||||||
@oneCol:
|
@oneCol:
|
||||||
stx pMap ; set initial map pointer for the ray
|
|
||||||
sty pMap+1
|
|
||||||
pha ; save ray offset
|
|
||||||
tay ; ray offset where it needs to be
|
|
||||||
lda pMap+1 ; save map row ptr
|
|
||||||
pha
|
|
||||||
txa
|
|
||||||
pha
|
|
||||||
jsr castRay ; cast the ray across the map
|
|
||||||
lda pixNum
|
lda pixNum
|
||||||
bne :+
|
bne :+
|
||||||
jsr clearBlit ; clear blit on the first pixel
|
jsr clearBlit ; clear blit on the first pixel
|
||||||
@ -1319,6 +1345,7 @@ renderFrame:
|
|||||||
jsr prbyte
|
jsr prbyte
|
||||||
DEBUG_LN
|
DEBUG_LN
|
||||||
.endif
|
.endif
|
||||||
|
inc screenCol ; next column
|
||||||
inc pixNum ; do we need to flush the pixel buffer?
|
inc pixNum ; do we need to flush the pixel buffer?
|
||||||
lda pixNum
|
lda pixNum
|
||||||
cmp #7
|
cmp #7
|
||||||
@ -2618,6 +2645,14 @@ precast_15:
|
|||||||
.byte $7E,$07,$05,$56
|
.byte $7E,$07,$05,$56
|
||||||
.res 4 ; to bring it up to 256 bytes per angle
|
.res 4 ; to bring it up to 256 bytes per angle
|
||||||
|
|
||||||
|
; Rendering buffers
|
||||||
|
txNumBuf: .res 256
|
||||||
|
txColBuf: .res 256
|
||||||
|
heightBuf: .res 256
|
||||||
|
depthBuf: .res 256
|
||||||
|
linkBuf: .res 256
|
||||||
|
|
||||||
|
; Useful constants
|
||||||
wLog256: .word $0800
|
wLog256: .word $0800
|
||||||
wLogViewDist: .word $0E3F
|
wLogViewDist: .word $0E3F
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user