Skip to content

Commit

Permalink
Final vga_render comment update and excel temp file ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
cspang1 committed Aug 31, 2023
1 parent 621a215 commit 9b47d9e
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ incremental_db/

**/Graphics Resources/*.txt

# Excel temp files
~$*.xls*
4 changes: 2 additions & 2 deletions dev/software/JCAP System Explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ VGA_RENDER:
- The initial scanline a given cog will always use is set via semaphore
- The next scanline to be rendered after the initial one is calculated
- Counter B is initialized in logic.always mode to facilitate fast tile loading
- The parallax table is iterated over in reverse order to find the first entry with a scanline index less than or equal to a given render cog's initial scanline
- The horizontal & vertical parallax positions of that entry are masked out
- The last parallax table entry that affects the given render cog is identified
- The current scanline's parallax positions are parsed, and the next scanline's parallax table entry is calculated
-

What's happening here is that a given scanline rendered by a render cog is beholden to the parallax effect of the closest scanline index in the parallax table less than it. E.g., if we're rendering scanline #35, and the closest parallax table entry index without going over 35 is say 25, then we will use the parallax effect dictated by that entry for all lines from 25 through whatever the next parallax table entry scanline index dictates, which would include out current scanline 35.
Expand Down
217 changes: 111 additions & 106 deletions dev/software/vga_render.spin
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ nxtcal call #nxt ' Get current and next parallax
mov temp, horpos ' Calculate tile map column memory address due to horizontal parallax
mov thpos, temp ' |
shr temp, #3 ' |
mov remtil, #system#MEM_TILE_MAP_WIDTH+1 ' | pre-incremented for tile load subroutine
mov remtil, #system#MEM_TILE_MAP_WIDTH+1 ' |
sub remtil, temp ' |
shl temp, #1 ' |
add tmindx, temp ' |
Expand All @@ -132,13 +132,13 @@ nxtcal call #nxt ' Get current and next parallax
' Determine horizontal pixel location in tile
and thpos, #%111 ' Calculate start pixel in tile and patch
add patch, thpos ' |
shl thpos, #2 ' |
shl curpt, thpos ' Shift to first pixel and load relevant offset
patch mov temp, ptable ' |
movs patch, #ptable ' |
trset mov px7, shlcall ' make sure we don't corrupt location 0 (might be important some day)
movd tiset, temp ' Set next frame's reset
movd trset, temp ' Set this frame's tile load routine call location
shl thpos, #2 ' Calculate tile offset and shift to first pixel
shl curpt, thpos ' |
patch mov temp, ptable ' Retrieve first pixel load subroutine address
movs patch, #ptable ' Reset the patch instruction
trset mov px7, shlcall ' Reset the previously patched pixel subroutine
movd tiset, temp ' Set this frame's tile load routine call location
movd trset, temp ' Set the next frame's patched pixel subroutine reset dest
tiset mov 0-0, tldcall ' Set this frame's tile load

' Parse palette tile pixels
Expand All @@ -149,61 +149,61 @@ tile mov temp, curpt ' Load current palette tile into temp va
mov pxbuf1, curcp ' Initialize first half-tile pixel buffer
ror pxbuf1, #8 ' Allocate space for next color
px0 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
or pxbuf1, curcp ' Store color
ror pxbuf1, #8 ' Allocate space for next color
px1 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
or pxbuf1, curcp ' Store color
ror pxbuf1, #8 ' Allocate space for next color
px2 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
or pxbuf1, curcp ' Store color
ror pxbuf1, #8 ' Allocate space for next color
px3 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
mov temp, curpt ' Process second pixel
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
or pxbuf1, curcp ' |
ror pxbuf1, #8 ' |
px1 shl curpt, #4 ' |
mov temp, curpt ' Process third pixel
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
or pxbuf1, curcp ' |
ror pxbuf1, #8 ' |
px2 shl curpt, #4 ' |
mov temp, curpt ' Process fourth pixel
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
or pxbuf1, curcp ' |
ror pxbuf1, #8 ' |
px3 shl curpt, #4 ' |
mov temp, curpt ' Process fifth pixel
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
mov pxbuf2, curcp ' Initialize second half-tile pixel buffer
ror pxbuf2, #8 ' Allocate space for next color
px4 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
or pxbuf2, curcp ' Store color
ror pxbuf2, #8 ' Allocate space for next color
px5 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
or pxbuf2, curcp ' Store color
ror pxbuf2, #8 ' Allocate space for next color
px6 shl curpt, #4 ' Shift palette tile left 4 bits
mov temp, curpt ' Load current palette tile into temp variable
shr temp, #28 ' LSB align palette index
add temp, cpindx ' Calculate color palette offset
rdbyte curcp, temp ' Load color
or pxbuf2, curcp ' Store color
ror pxbuf2, #8 ' Allocate space for next color
px7 shl curpt, #4 ' Shift palette tile left 4 bits
px4 shl curpt, #4 ' Process sixth pixel
mov temp, curpt ' |
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
or pxbuf2, curcp ' |
ror pxbuf2, #8 ' |
px5 shl curpt, #4 ' |
mov temp, curpt ' Process seventh pixel
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
or pxbuf2, curcp ' |
ror pxbuf2, #8 ' |
px6 shl curpt, #4 ' |
mov temp, curpt ' Process eighth pixel
shr temp, #28 ' |
add temp, cpindx ' |
rdbyte curcp, temp ' |
or pxbuf2, curcp ' |
ror pxbuf2, #8 ' |
px7 shl curpt, #4 ' |

' Store tile pixels
shbuf1 mov slbuff+4, pxbuf1 ' Allocate space for color
add shbuf1, d1 ' Increment scanline buffer OR position
shbuf2 mov slbuff+5, pxbuf2 ' Allocate space for color
add shbuf2, d1 ' Increment scanline buffer OR position
shbuf1 mov slbuff+4, pxbuf1 ' Store the two 4-pixel halves
add shbuf1, d1 ' |
shbuf2 mov slbuff+5, pxbuf2 ' |
add shbuf2, d1 ' |
djnz index , #tile ' Repeat for all tiles in scanline
movd shbuf1, #slbuff+4 ' Reset shbuf destination address
movd shbuf2, #slbuff+5 ' Reset shbuf destination address
Expand All @@ -213,7 +213,7 @@ shbuf2 mov slbuff+5, pxbuf2 ' Allocate space for color
mov tmindx, satptr ' Initialize sprite attribute table index

sprites ' Load sprite vertical position and check visibility
rdlong curmt, tmindx ' Load sprite attributes from Main RAM
rdlong curmt, tmindx ' Parse SAT entry component
mov spypos, curmt ' Copy sprite attributes to temp variable
shr spypos, #7 ' Shift vertical position to LSB
and spypos, #255 wz ' Mask out vertical position, checking invisibility
Expand Down Expand Up @@ -304,38 +304,43 @@ sprites ' Load sprite vertical position and check visibility
djnz index, #sprites ' Repeat for all sprites in SAT

' Wait for target scanline
mov index, numSegs ' Initialize current scanline segment
mov curvb, slbptr ' Initialize Main RAM video buffer memory location
mov ptr, curvb ' Initialize transfer counter
gettsl rdlong temp, cslptr ' Read target scanline index from Main RAM
cmp temp, cursl wz ' Check if current scanline is being requested for display
if_nz jmp #gettsl ' If not, re-read target scanline
mov index, numSegs ' Wait until current scanline data is requested by display cog
mov curvb, slbptr ' |
mov ptr, curvb ' |
gettsl rdlong temp, cslptr ' |
cmp temp, cursl wz ' |
if_nz jmp #gettsl ' |

' Write scanline buffer to video buffer in Main RAM
movd long0, #ptr-5 ' last long in cog buffer
movd long1, #ptr-6 ' second-to-last long in cog buffer
add ptr, #system#VID_BUFFER_SIZE*4-1 ' last byte in hub buffer (8n + 7)
movi ptr, #system#VID_BUFFER_SIZE-2 ' add magic marker
long0 wrlong 0-0, ptr ' |
sub long0, d1 ' |
sub ptr, i2s7 wc ' |
long1 wrlong 0-0, ptr ' |
sub long1, d1 ' |
if_nc djnz ptr, #long0 ' sub #7/djnz (Thanks Phil!)
add cursl, #system#NUM_REN_COGS ' Increment current scanline for next render
cmp cursl, numLines wc ' Check if at bottom of screen
mov nxtsl, cursl
add nxtsl, #system#NUM_REN_COGS
if_c jmp #slgen ' If not continue to next scanline, otherwise...
mov temptr, pxtptr
add temptr, plxoff
mov cursl, initsl ' Reinitialize current scanline
mov nxtsl, cursl
add nxtsl, #system#NUM_REN_COGS
waitdat rdlong temp, datptr wz ' Check if graphics resources ready
if_nz jmp #waitdat ' Wait for graphics resources to be ready
jmp #frame ' Generate next frame

movd long0, #ptr-5 ' last long in cog buffer
movd long1, #ptr-6 ' second-to-last long in cog buffer
add ptr, #system#VID_BUFFER_SIZE*4-1 ' last byte in hub buffer (8n + 7)
movi ptr, #system#VID_BUFFER_SIZE-2 ' add magic marker
long0 wrlong 0-0, ptr ' |
sub long0, d1 ' |
sub ptr, i2s7 wc ' |
long1 wrlong 0-0, ptr ' |
sub long1, d1 ' |
if_nc djnz ptr, #long0 ' sub #7/djnz (Thanks Phil!)

' Prepare for next scanline to render
add cursl, #system#NUM_REN_COGS ' Increment current scanline for next render
cmp cursl, numLines wc ' Check if at bottom of screen {{ MOVE THIS DOWN BELOW mov/add??? }}
mov nxtsl, cursl ' Calculate next scanline index
add nxtsl, #system#NUM_REN_COGS ' |
if_c jmp #slgen ' If not continue to next scanline, otherwise...

' Prepare for next frame to render
mov temptr, pxtptr ' Re-calculate the first parallax table entry to check for the next frame
add temptr, plxoff ' | {{ WE SHOULD STORE THIS VALUE PERMANENTLY TO AVOID RE-CALCULATING EACH FRAME }}
mov cursl, initsl ' Re-initialize current and next scanlines
mov nxtsl, cursl ' |
add nxtsl, #system#NUM_REN_COGS ' |
waitdat rdlong temp, datptr wz ' Wait for graphics resources to be ready to render next frame
if_nz jmp #waitdat ' |
jmp #frame ' |

' We can move the entire nxt routine back inline
nxt mov horpos, nxtpte ' Capture horizontal and vertical parallax values for this scanline
mov verpos, horpos ' |
shr horpos, #20 ' |
Expand Down Expand Up @@ -372,13 +377,13 @@ tld djnz remtil, #:next ' Wrap to beginning of tile map row if a
tld_ret ret

' Instructions for dynamic tile shifting
nxtcall call #nxt
nopcall nop
tldcall call #tld ' Tile load instr call
shlcall shl curpt, #4 ' Shift left instr call
nxtcall call #nxt {{ THIS CAN BE REMOVED }}
nopcall nop {{ THIS CAN BE REMOVED }}
tldcall call #tld ' Tile load instr call
shlcall shl curpt, #4 ' Shift left instr call

' Video attributes
maxHor long system#MAX_MEM_HOR_POS ' Maximum horizontal position
maxHor long system#MAX_MEM_HOR_POS ' Maximum horizontal position {{ CAN BE REMOVED }}
maxHVis long system#MAX_VIS_HOR_POS-1 ' Maximum visible horizontal position
maxVVis long system#MAX_VIS_VER_POS-1 ' Maximum visible vertical position
numLines long system#MAX_VIS_VER_POS-16 ' Number of rendered scanlines
Expand All @@ -401,22 +406,22 @@ tpptr long 32 ' Pointer to location of tile palettes in Main RAM w/ of
spptr long 36 ' Pointer to location of sprite palettes in Main RAM w/ offset

' Other values
d0 long 1 << 9 ' Value to increment destination register
d1 long 1 << 10 ' Value to increment destination register
i2s7 long 2 << 23 | 7 ' Value to summon Cthullu
pxmask long $FFFFFF00 ' Mask for pixels in scanline buffer
vpmask long $FFF ' Mask for vertical game world position
ptable long px7, px6, px5, px4 ' Patch table for modifying tile load logic
long px3, px2, px1, px0
neg8 long -8 ' Value to modify sprite position given wide+mirrored
d0 long 1 << 9 ' Value to increment destination register {{ CAN BE REMOVED }}
d1 long 1 << 10 ' Value to increment destination register
i2s7 long 2 << 23 | 7 ' Value to summon Cthullu
pxmask long $FFFFFF00 ' Mask for pixels in scanline buffer
vpmask long $FFF ' Mask for vertical game world position
ptable long px7, px6, px5, px4 ' Patch table for modifying tile load logic
long px3, px2, px1, px0 ' |
neg8 long -8 ' Value to modify sprite position given wide+mirrored

' Scanline buffer
slbuff res system#VID_BUFFER_SIZE+8 ' Buffer containing scanline
slbuff res system#VID_BUFFER_SIZE+8 ' Buffer containing scanline w/ off-screen padding
ptr res 1 ' Data pointer assisting scanline buffer cog->hub tx

' Tile pointers
tmindx res 1 ' Tile map index
tpindx res 1 ' Tile palette index
tpindx res 1 ' Tile palette index {{ CAN BE REMOVED }}
cpindx res 1 ' Color palette index
curmt res 1 ' Current map tile
curpt res 1 ' Current palette tile
Expand Down Expand Up @@ -452,7 +457,7 @@ temptr res 1 ' Container for temporary pointer to parallax table
maxptr res 1 ' Container for max parallax array pointer
nxtptr res 1 ' Container for next parallax array pointer
nxtpte res 1 ' Container for next parallax table entry
nextvp res 1 ' Container for next vertical parallax position
nextvp res 1 ' Container for next vertical parallax position {{ CAN BE REMOVED }}
nxtpsl res 1 ' Container for next parallax change scanline
thpos res 1 ' Container for temporary horizontal position
temp res 1 ' Container for temporary variables
Expand Down

0 comments on commit 9b47d9e

Please sign in to comment.