Use macros to reduce the copy/pasted code for marking tiles as dirty. Rough out the support for body and head segments.

This commit is contained in:
Jeremy Rand 2020-07-30 23:34:48 -04:00
parent 2b45813cbb
commit 7d7afc908d
10 changed files with 123 additions and 267 deletions

View File

@ -87,6 +87,8 @@
9DB1505124C6875C00558B87 /* gameScorpion.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameScorpion.s; sourceTree = "<group>"; }; 9DB1505124C6875C00558B87 /* gameScorpion.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameScorpion.s; sourceTree = "<group>"; };
9DB1505224C7495400558B87 /* globals.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = globals.s; sourceTree = "<group>"; }; 9DB1505224C7495400558B87 /* globals.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = globals.s; sourceTree = "<group>"; };
9DB1505324C9E54C00558B87 /* gameSpider.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSpider.s; sourceTree = "<group>"; }; 9DB1505324C9E54C00558B87 /* gameSpider.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSpider.s; sourceTree = "<group>"; };
9DB1505424D3BF6C00558B87 /* gameSegments.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSegments.s; sourceTree = "<group>"; };
9DB1505524D3BFCE00558B87 /* global.macros */ = {isa = PBXFileReference; lastKnownFileType = text; path = global.macros; sourceTree = "<group>"; };
9DC4D7BD24B7652100BACF4B /* ship.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = ship.s; sourceTree = "<group>"; }; 9DC4D7BD24B7652100BACF4B /* ship.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = ship.s; sourceTree = "<group>"; };
9DC4D7BE24B80C9600BACF4B /* shot.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = shot.s; sourceTree = "<group>"; }; 9DC4D7BE24B80C9600BACF4B /* shot.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = shot.s; sourceTree = "<group>"; };
9DC4D7BF24BE9F7100BACF4B /* tiles.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tiles.h; sourceTree = "<group>"; }; 9DC4D7BF24BE9F7100BACF4B /* tiles.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tiles.h; sourceTree = "<group>"; };
@ -136,9 +138,11 @@
9DB1505024C3801100558B87 /* gameFlea.s */, 9DB1505024C3801100558B87 /* gameFlea.s */,
9DB1505124C6875C00558B87 /* gameScorpion.s */, 9DB1505124C6875C00558B87 /* gameScorpion.s */,
9DB1505324C9E54C00558B87 /* gameSpider.s */, 9DB1505324C9E54C00558B87 /* gameSpider.s */,
9DB1505424D3BF6C00558B87 /* gameSegments.s */,
9D62AF3B249871A300348F45 /* colour.s */, 9D62AF3B249871A300348F45 /* colour.s */,
9D2FF6DA24C4C79A000181E5 /* random.s */, 9D2FF6DA24C4C79A000181E5 /* random.s */,
9DB1505224C7495400558B87 /* globals.s */, 9DB1505224C7495400558B87 /* globals.s */,
9DB1505524D3BFCE00558B87 /* global.macros */,
9D3396F324AECACC003222B3 /* sprites */, 9D3396F324AECACC003222B3 /* sprites */,
9D1716912491C49300C83148 /* main.rez */, 9D1716912491C49300C83148 /* main.rez */,
9D1716932491C49300C83148 /* Makefile */, 9D1716932491C49300C83148 /* Makefile */,

View File

@ -54,7 +54,7 @@ REZFLAGS+=
MACGENFLAGS+= MACGENFLAGS+=
# Add any other macro libraries to include in this variable: # Add any other macro libraries to include in this variable:
MACGENMACROS+=sprites/sprites.macros MACGENMACROS+=sprites/sprites.macros global.macros
# Add any arguments you want passed to the assembler to this variable: # Add any arguments you want passed to the assembler to this variable:
ASMFLAGS+= ASMFLAGS+=

View File

@ -31,9 +31,10 @@ game start
gameLoop anop gameLoop anop
jsl drawDirtyGameTiles jsl drawDirtyGameTiles
jsl drawScorpion
jsl drawSpider jsl drawSpider
jsl drawScorpion
jsl drawFlea jsl drawFlea
jsl drawSegments
jsl drawDirtyNonGameTiles jsl drawDirtyNonGameTiles
short i,m short i,m
@ -45,6 +46,7 @@ gameLoop anop
jsl updateScorpion jsl updateScorpion
jsl updateSpider jsl updateSpider
jsl updateFlea jsl updateFlea
jsl updateSegments
jsl checkKeyboard jsl checkKeyboard
jsl waitForVbl jsl waitForVbl

View File

@ -33,53 +33,11 @@ drawFlea entry
ldy numDirtyGameTiles ldy numDirtyGameTiles
ldx fleaTileOffsets _dirtyGameTile fleaTileOffsets
lda tiles+TILE_DIRTY_OFFSET,x _dirtyGameTile fleaTileOffsets+2
bne drawFlea_skipTile1 _dirtyGameTile fleaTileOffsets+4
lda #TILE_STATE_DIRTY _dirtyGameTile fleaTileOffsets+6
sta tiles+TILE_DIRTY_OFFSET,x
txa
sta dirtyGameTiles,y
iny
iny
drawFlea_skipTile1 anop
ldx fleaTileOffsets+2
lda tiles+TILE_DIRTY_OFFSET,x
bne drawFlea_skipTile2
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
sta dirtyGameTiles,y
iny
iny
drawFlea_skipTile2 anop
ldx fleaTileOffsets+4
lda tiles+TILE_DIRTY_OFFSET,x
bne drawFlea_skipTile3
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
sta dirtyGameTiles,y
iny
iny
drawFlea_skipTile3 anop
ldx fleaTileOffsets+6
lda tiles+TILE_DIRTY_OFFSET,x
bne drawFlea_skipTile4
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
sta dirtyGameTiles,y
iny
iny
drawFlea_skipTile4 anop
sty numDirtyGameTiles sty numDirtyGameTiles
drawFlea_done anop drawFlea_done anop

View File

@ -36,78 +36,10 @@ drawScorpion_cont anop
ldx scorpionSprite ldx scorpionSprite
jsl scorpionJump jsl scorpionJump
ldx scorpionTileOffsets _dirtyGameOrNonGameTile scorpionTileOffsets
lda tiles+TILE_DIRTY_OFFSET,x _dirtyGameOrNonGameTile scorpionTileOffsets+2
bne drawScorpion_skipTile1 _dirtyGameOrNonGameTile scorpionTileOffsets+4
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawScorpion_nonGame1
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawScorpion_skipTile1
drawScorpion_nonGame1 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawScorpion_skipTile1 anop
ldx scorpionTileOffsets+2
lda tiles+TILE_DIRTY_OFFSET,x
bne drawScorpion_skipTile2
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawScorpion_nonGame2
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawScorpion_skipTile2
drawScorpion_nonGame2 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawScorpion_skipTile2 anop
ldx scorpionTileOffsets+4
lda tiles+TILE_DIRTY_OFFSET,x
bne drawScorpion_done
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawScorpion_nonGame3
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
rtl
drawScorpion_nonGame3 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawScorpion_done anop
rtl rtl

42
BuGS/gameSegments.s Normal file
View File

@ -0,0 +1,42 @@
;
; gameSegments.s
; BuGS
;
; Created by Jeremy Rand on 2020-07-30.
;Copyright © 2020 Jeremy Rand. All rights reserved.
;
case on
mcopy gameSegments.macros
keep gameSegments
gameSegments start
using globalData
drawSegments entry
; Write this code...
rtl
updateSegments entry
; Write this code...
rtl
addBodySegment entry
; Write this code...
rtl
addHeadSegment entry
; Write this code...
rtl
shootSegment entry
; Write this code...
rtl
end

View File

@ -71,150 +71,13 @@ drawSpider_cont anop
ldx spiderSprite ldx spiderSprite
jsl spiderJump jsl spiderJump
ldx spiderTileOffsets _dirtyGameOrNonGameTile spiderTileOffsets
lda tiles+TILE_DIRTY_OFFSET,x _dirtyGameOrNonGameTile spiderTileOffsets+2
bne drawSpider_skipTile1 _dirtyGameOrNonGameTile spiderTileOffsets+4
lda #TILE_STATE_DIRTY _dirtyGameOrNonGameTile spiderTileOffsets+6
sta tiles+TILE_DIRTY_OFFSET,x _dirtyGameOrNonGameTile spiderTileOffsets+8
txa _dirtyGameOrNonGameTile spiderTileOffsets+10
cmp #RHS_FIRST_TILE_OFFSET
bge drawSpider_nonGame1
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawSpider_skipTile1
drawSpider_nonGame1 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawSpider_skipTile1 anop
ldx spiderTileOffsets+2
lda tiles+TILE_DIRTY_OFFSET,x
bne drawSpider_skipTile2
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawSpider_nonGame2
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawSpider_skipTile2
drawSpider_nonGame2 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawSpider_skipTile2 anop
ldx spiderTileOffsets+4
lda tiles+TILE_DIRTY_OFFSET,x
bne drawSpider_skipTile3
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawSpider_nonGame3
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawSpider_skipTile3
drawSpider_nonGame3 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawSpider_skipTile3 anop
ldx spiderTileOffsets+6
lda tiles+TILE_DIRTY_OFFSET,x
bne drawSpider_skipTile4
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawSpider_nonGame4
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawSpider_skipTile4
drawSpider_nonGame4 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawSpider_skipTile4 anop
ldx spiderTileOffsets+8
lda tiles+TILE_DIRTY_OFFSET,x
bne drawSpider_skipTile5
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawSpider_nonGame5
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra drawSpider_skipTile5
drawSpider_nonGame5 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawSpider_skipTile5 anop
ldx spiderTileOffsets+10
lda tiles+TILE_DIRTY_OFFSET,x
bne drawSpider_done
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge drawSpider_nonGame6
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
rtl
drawSpider_nonGame6 anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
drawSpider_done anop
rtl rtl
spiderJump entry spiderJump entry

56
BuGS/global.macros Normal file
View File

@ -0,0 +1,56 @@
;
; global.macros
; BuGS
;
; Created by Jeremy Rand on 2020-07-30.
;Copyright © 2020 Jeremy Rand. All rights reserved.
;
; Call this with Y already loaded with the numDirtyGameTiles. Also, the new
; numDirtyGameTiles is left in Y. The caller must store it.
macro
_dirtyGameTile &tileOffset
ldx &tileOffset
lda tiles+TILE_DIRTY_OFFSET,x
bne _dirtyGameTile_skip&SYSCNT
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
sta dirtyGameTiles,y
iny
iny
_dirtyGameTile_skip&SYSCNT anop
mend
macro
_dirtyGameOrNonGameTile &tileOffset
ldx &tileOffset
lda tiles+TILE_DIRTY_OFFSET,x
bne _dirtyGameTile_skip&SYSCNT
lda #TILE_STATE_DIRTY
sta tiles+TILE_DIRTY_OFFSET,x
txa
cmp #RHS_FIRST_TILE_OFFSET
bge _dirtyGameTile_nonGame&SYSCNT
ldy numDirtyGameTiles
sta dirtyGameTiles,y
iny
iny
sty numDirtyGameTiles
bra _dirtyGameTile_skip&SYSCNT
_dirtyGameTile_nonGame&SYSCNT anop
ldy numDirtyNonGameTiles
sta dirtyNonGameTiles,y
iny
iny
sty numDirtyNonGameTiles
_dirtyGameTile_skip&SYSCNT anop
mend

View File

@ -708,10 +708,10 @@
tax tax
and &mask and &mask
beq ~&SYSCNT beq _noCollision_&SYSCNT
sta collision sta collision
~&SYSCNT anop _noCollision_&SYSCNT anop
txa txa
mend mend

View File

@ -43,10 +43,9 @@ Each colour is 4 bits wide. All zeros is always black in all the different pall
* solid squares (primarily the all black square) * solid squares (primarily the all black square)
These sprites generally draw first and overwrite what may have been there before. After the background layer is drawn, other things are drawn in this order: These sprites generally draw first and overwrite what may have been there before. After the background layer is drawn, other things are drawn in this order:
* spiders * spiders/scores
* scorpions * scorpions
* fleas * fleas
* scores
* centipede segments * centipede segments
* missle * missle
* player * player
@ -63,4 +62,4 @@ An exception to the "background is drawn first" rule though is the non-playable
We also need to clip a flea which is dropping down from the top. The solution there is that the game allocates memory before the SHR page, enough for an extra unseen tile above the screen. A partially obscured flea is drawn offscreen into that part of memory before the SHR page. We also need to clip a flea which is dropping down from the top. The solution there is that the game allocates memory before the SHR page, enough for an extra unseen tile above the screen. A partially obscured flea is drawn offscreen into that part of memory before the SHR page.
There is a similar problem when the flea reaches the bottom of the screen. I haven't decided how to handle this yet. After the SHR screen are the screen control bytes and the colour palettes so I can't just overwrite that memory with the off-screen flea sprite. I could maybe allow the flea to corrupt this memory and then try to repair it. Or maybe the flea sprite code will need to have special cases for the last few lines of the screen. This problem is still to be solved. There is a similar problem when the flea reaches the bottom of the screen. I have decided to just not handle it. The flea disappears once it reaches the bottom of the screen. It does not scroll off the bottom.