From 7d7afc908d9c226565ade10e4dd188e9b6763dc4 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Thu, 30 Jul 2020 23:34:48 -0400 Subject: [PATCH] Use macros to reduce the copy/pasted code for marking tiles as dirty. Rough out the support for body and head segments. --- BuGS.xcodeproj/project.pbxproj | 4 + BuGS/Makefile | 2 +- BuGS/game.s | 4 +- BuGS/gameFlea.s | 50 +---------- BuGS/gameScorpion.s | 74 +--------------- BuGS/gameSegments.s | 42 ++++++++++ BuGS/gameSpider.s | 149 ++------------------------------- BuGS/global.macros | 56 +++++++++++++ BuGS/sprites/sprites.macros | 4 +- BuGS/sprites/sprites.md | 5 +- 10 files changed, 123 insertions(+), 267 deletions(-) create mode 100644 BuGS/gameSegments.s create mode 100644 BuGS/global.macros diff --git a/BuGS.xcodeproj/project.pbxproj b/BuGS.xcodeproj/project.pbxproj index 035de72..5d539f5 100644 --- a/BuGS.xcodeproj/project.pbxproj +++ b/BuGS.xcodeproj/project.pbxproj @@ -87,6 +87,8 @@ 9DB1505124C6875C00558B87 /* gameScorpion.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameScorpion.s; sourceTree = ""; }; 9DB1505224C7495400558B87 /* globals.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = globals.s; sourceTree = ""; }; 9DB1505324C9E54C00558B87 /* gameSpider.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSpider.s; sourceTree = ""; }; + 9DB1505424D3BF6C00558B87 /* gameSegments.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameSegments.s; sourceTree = ""; }; + 9DB1505524D3BFCE00558B87 /* global.macros */ = {isa = PBXFileReference; lastKnownFileType = text; path = global.macros; sourceTree = ""; }; 9DC4D7BD24B7652100BACF4B /* ship.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = ship.s; sourceTree = ""; }; 9DC4D7BE24B80C9600BACF4B /* shot.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = shot.s; sourceTree = ""; }; 9DC4D7BF24BE9F7100BACF4B /* tiles.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tiles.h; sourceTree = ""; }; @@ -136,9 +138,11 @@ 9DB1505024C3801100558B87 /* gameFlea.s */, 9DB1505124C6875C00558B87 /* gameScorpion.s */, 9DB1505324C9E54C00558B87 /* gameSpider.s */, + 9DB1505424D3BF6C00558B87 /* gameSegments.s */, 9D62AF3B249871A300348F45 /* colour.s */, 9D2FF6DA24C4C79A000181E5 /* random.s */, 9DB1505224C7495400558B87 /* globals.s */, + 9DB1505524D3BFCE00558B87 /* global.macros */, 9D3396F324AECACC003222B3 /* sprites */, 9D1716912491C49300C83148 /* main.rez */, 9D1716932491C49300C83148 /* Makefile */, diff --git a/BuGS/Makefile b/BuGS/Makefile index 832a08a..28f1608 100644 --- a/BuGS/Makefile +++ b/BuGS/Makefile @@ -54,7 +54,7 @@ REZFLAGS+= MACGENFLAGS+= # 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: ASMFLAGS+= diff --git a/BuGS/game.s b/BuGS/game.s index 8ab9dc2..0fdc05c 100644 --- a/BuGS/game.s +++ b/BuGS/game.s @@ -31,9 +31,10 @@ game start gameLoop anop jsl drawDirtyGameTiles - jsl drawScorpion jsl drawSpider + jsl drawScorpion jsl drawFlea + jsl drawSegments jsl drawDirtyNonGameTiles short i,m @@ -45,6 +46,7 @@ gameLoop anop jsl updateScorpion jsl updateSpider jsl updateFlea + jsl updateSegments jsl checkKeyboard jsl waitForVbl diff --git a/BuGS/gameFlea.s b/BuGS/gameFlea.s index 79a18bb..87be5e1 100644 --- a/BuGS/gameFlea.s +++ b/BuGS/gameFlea.s @@ -33,53 +33,11 @@ drawFlea entry ldy numDirtyGameTiles - ldx fleaTileOffsets - lda tiles+TILE_DIRTY_OFFSET,x - bne drawFlea_skipTile1 - lda #TILE_STATE_DIRTY - sta tiles+TILE_DIRTY_OFFSET,x - txa - sta dirtyGameTiles,y - iny - iny + _dirtyGameTile fleaTileOffsets + _dirtyGameTile fleaTileOffsets+2 + _dirtyGameTile fleaTileOffsets+4 + _dirtyGameTile fleaTileOffsets+6 -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 drawFlea_done anop diff --git a/BuGS/gameScorpion.s b/BuGS/gameScorpion.s index 43ecbb6..b2c9f24 100644 --- a/BuGS/gameScorpion.s +++ b/BuGS/gameScorpion.s @@ -36,78 +36,10 @@ drawScorpion_cont anop ldx scorpionSprite jsl scorpionJump - ldx scorpionTileOffsets - lda tiles+TILE_DIRTY_OFFSET,x - bne drawScorpion_skipTile1 - lda #TILE_STATE_DIRTY - sta tiles+TILE_DIRTY_OFFSET,x - txa - cmp #RHS_FIRST_TILE_OFFSET - bge drawScorpion_nonGame1 + _dirtyGameOrNonGameTile scorpionTileOffsets + _dirtyGameOrNonGameTile scorpionTileOffsets+2 + _dirtyGameOrNonGameTile scorpionTileOffsets+4 - 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 diff --git a/BuGS/gameSegments.s b/BuGS/gameSegments.s new file mode 100644 index 0000000..5259e40 --- /dev/null +++ b/BuGS/gameSegments.s @@ -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 diff --git a/BuGS/gameSpider.s b/BuGS/gameSpider.s index ad8477f..f0565c0 100644 --- a/BuGS/gameSpider.s +++ b/BuGS/gameSpider.s @@ -71,150 +71,13 @@ drawSpider_cont anop ldx spiderSprite jsl spiderJump - ldx spiderTileOffsets - lda tiles+TILE_DIRTY_OFFSET,x - bne drawSpider_skipTile1 - lda #TILE_STATE_DIRTY - sta tiles+TILE_DIRTY_OFFSET,x - txa - cmp #RHS_FIRST_TILE_OFFSET - bge drawSpider_nonGame1 + _dirtyGameOrNonGameTile spiderTileOffsets + _dirtyGameOrNonGameTile spiderTileOffsets+2 + _dirtyGameOrNonGameTile spiderTileOffsets+4 + _dirtyGameOrNonGameTile spiderTileOffsets+6 + _dirtyGameOrNonGameTile spiderTileOffsets+8 + _dirtyGameOrNonGameTile spiderTileOffsets+10 - 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 spiderJump entry diff --git a/BuGS/global.macros b/BuGS/global.macros new file mode 100644 index 0000000..1eef6b9 --- /dev/null +++ b/BuGS/global.macros @@ -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 diff --git a/BuGS/sprites/sprites.macros b/BuGS/sprites/sprites.macros index d97ce2b..4d4ec37 100644 --- a/BuGS/sprites/sprites.macros +++ b/BuGS/sprites/sprites.macros @@ -708,10 +708,10 @@ tax and &mask - beq ~&SYSCNT + beq _noCollision_&SYSCNT sta collision -~&SYSCNT anop +_noCollision_&SYSCNT anop txa mend diff --git a/BuGS/sprites/sprites.md b/BuGS/sprites/sprites.md index 9ae2598..396af36 100644 --- a/BuGS/sprites/sprites.md +++ b/BuGS/sprites/sprites.md @@ -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) 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 * fleas - * scores * centipede segments * missle * 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. -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.