From 4f74d630b9b23ce3a0df1433933a98782ae9dd1c Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Thu, 23 Jul 2020 23:41:12 -0400 Subject: [PATCH] Start coding support for the spider. Also, try to show the performance of the main game loop in the border colour. --- BuGS.xcodeproj/project.pbxproj | 2 + BuGS/game.s | 34 +++- BuGS/gameScorpion.s | 2 - BuGS/gameSpider.s | 279 +++++++++++++++++++++++++++++++++ BuGS/globals.s | 1 + 5 files changed, 314 insertions(+), 4 deletions(-) create mode 100644 BuGS/gameSpider.s diff --git a/BuGS.xcodeproj/project.pbxproj b/BuGS.xcodeproj/project.pbxproj index 7c3d409..035de72 100644 --- a/BuGS.xcodeproj/project.pbxproj +++ b/BuGS.xcodeproj/project.pbxproj @@ -86,6 +86,7 @@ 9DB1505024C3801100558B87 /* gameFlea.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = gameFlea.s; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; @@ -134,6 +135,7 @@ 9D8FFC612491CAF0005C9327 /* game.h */, 9DB1505024C3801100558B87 /* gameFlea.s */, 9DB1505124C6875C00558B87 /* gameScorpion.s */, + 9DB1505324C9E54C00558B87 /* gameSpider.s */, 9D62AF3B249871A300348F45 /* colour.s */, 9D2FF6DA24C4C79A000181E5 /* random.s */, 9DB1505224C7495400558B87 /* globals.s */, diff --git a/BuGS/game.s b/BuGS/game.s index 90cb3f3..152b988 100644 --- a/BuGS/game.s +++ b/BuGS/game.s @@ -32,10 +32,12 @@ game start gameLoop anop jsl drawDirtyGameTiles jsl drawScorpion + jsl drawSpider jsl drawFlea jsl drawDirtyNonGameTiles jsl updateScorpion + jsl updateSpider jsl updateFlea jsl checkKeyboard @@ -44,6 +46,13 @@ gameLoop anop lda shouldQuit bne gameLoop + short i,m + lda >BORDER_COLOUR_REGISTER + and #$f0 + ora borderColour + sta >BORDER_COLOUR_REGISTER + long i,m + rtl @@ -605,7 +614,10 @@ setupScreen entry lda #$a1 sta >NEW_VIDEO_REGISTER ; Enable SHR mode + lda >BORDER_COLOUR_REGISTER long i,m + and #$000f + sta borderColour sei phd @@ -663,6 +675,11 @@ checkKey_loop2 anop cmp #'S' beq checkKey_shootScorpion + cmp #'p' + beq checkKey_addSpider + cmp #'P' + beq checkKey_shootSpider + lda colourPalette inc a cmp #NUM_COLOUR_PALETTES @@ -684,6 +701,12 @@ checkKey_addScorpion anop checkKey_shootScorpion anop jmp shootScorpion +checkKey_addSpider anop + jmp addSpider + +checkKey_shootSpider anop + jmp shootSpider + checkKey_quit anop stz shouldQuit @@ -703,6 +726,9 @@ waitForKey_loop anop waitForVbl entry short i,m + lda >BORDER_COLOUR_REGISTER + and #$f0 + sta >BORDER_COLOUR_REGISTER vblLoop1 anop lda #$fe cmp >READ_VBL @@ -710,11 +736,15 @@ vblLoop1 anop vblLoop2 anop cmp >READ_VBL bmi vblLoop2 + lda >BORDER_COLOUR_REGISTER + ora #$0f + sta >BORDER_COLOUR_REGISTER long i,m rtl -colourPalette dc i2'0' -shouldQuit dc i2'1' +colourPalette dc i2'0' +shouldQuit dc i2'1' +borderColour dc i2'0' end diff --git a/BuGS/gameScorpion.s b/BuGS/gameScorpion.s index 88b2c57..1fdd0a8 100644 --- a/BuGS/gameScorpion.s +++ b/BuGS/gameScorpion.s @@ -60,7 +60,6 @@ drawScorpion_nonGame1 anop sty numDirtyNonGameTiles drawScorpion_skipTile1 anop - ldx scorpionTileOffsets+2 lda tiles+TILE_DIRTY_OFFSET,x bne drawScorpion_skipTile2 @@ -85,7 +84,6 @@ drawScorpion_nonGame2 anop sty numDirtyNonGameTiles drawScorpion_skipTile2 anop - ldx scorpionTileOffsets+4 lda tiles+TILE_DIRTY_OFFSET,x bne drawScorpion_done diff --git a/BuGS/gameSpider.s b/BuGS/gameSpider.s new file mode 100644 index 0000000..21486b7 --- /dev/null +++ b/BuGS/gameSpider.s @@ -0,0 +1,279 @@ +; +; gameSpider.s +; BuGS +; +; Created by Jeremy Rand on 2020-07-23. +;Copyright © 2020 Jeremy Rand. All rights reserved. +; + + case on + mcopy gameSpider.macros + keep gameSpider + +gameSpider start + using globalData + +SPIDER_STATE_NONE equ 0 +SPIDER_STATE_LEFT_DIAG_DOWN equ 1 +SPIDER_STATE_LEFT_DIAG_UP equ 2 +SPIDER_STATE_LEFT_DOWN equ 3 +SPIDER_STATE_LEFT_UP equ 4 +SPIDER_STATE_RIGHT_DIAG_DOWN equ 5 +SPIDER_STATE_RIGHT_DIAG_UP equ 6 +SPIDER_STATE_RIGHT_DOWN equ 7 +SPIDER_STATE_RIGHT_UP equ 8 +SPIDER_STATE_EXPLODING equ 9 + +drawSpider entry + lda spiderState + bne drawSpider_cont + rtl + +drawSpider_cont anop + ldy spiderScreenOffset + 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 + + 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+2 + 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 + cmp #SPIDER_STATE_EXPLODING + beq spiderJump_exploding + + lda spiderScreenShift + beq spiderJump_shift + + lda spiderJumpTable,x + sta jumpInst+1 + + lda spiderJumpTable+2,x + sta jumpInst+3 + bra jumpInst + +spiderJump_shift anop + lda spiderShiftJumpTable,x + sta jumpInst+1 + + lda spiderShiftJumpTable+2,x + sta jumpInst+3 + bra jumpInst + +spiderJump_exploding anop + tya + clc + adc #TILE_BYTE_WIDTH + tay + + lda explosionJumpTable,x + sta jumpInst+1 + + lda explosionJumpTable+2,x + sta jumpInst+3 + +jumpInst jmp >spider1 + nop + + +updateSpider entry +; Write this code + rtl + + +addSpider entry + lda spiderState + bne addSpider_done + + lda #SPIDER_STATE_RIGHT_DOWN + sta spiderState + + stz spiderScreenShift + +; Write this code + +addSpider_done anop + rtl + + +shootSpider entry +; Write this code + rtl + + +spiderState dc i2'SPIDER_STATE_NONE' +spiderSprite dc i2'0' +spiderScreenOffset dc i2'0' +spiderScreenShift dc i2'0' +spiderShiftInTile dc i2'0' + +spiderTileOffsets dc i2'0' + dc i2'0' + dc i2'0' + dc i2'0' + dc i2'0' + dc i2'0' + +SPIDER_SPRITE_LAST_OFFSET gequ 7*4 +spiderJumpTable dc i4'spider7' + dc i4'spider6' + dc i4'spider2' + dc i4'spider3' + dc i4'spider4' + dc i4'spider3' + dc i4'spider2' + dc i4'spider1' + + +spiderShiftJumpTable dc i4'spider7s' + dc i4'spider6s' + dc i4'spider2s' + dc i4'spider3s' + dc i4'spider4s' + dc i4'spider3s' + dc i4'spider2s' + dc i4'spider1s' + + end diff --git a/BuGS/globals.s b/BuGS/globals.s index a09e394..f338885 100644 --- a/BuGS/globals.s +++ b/BuGS/globals.s @@ -125,6 +125,7 @@ KEYBOARD_STROBE gequ $e0c010 READ_VBL gequ $e0c019 SHADOW_REGISTER gequ $e0c035 NEW_VIDEO_REGISTER gequ $e0c029 +BORDER_COLOUR_REGISTER gequ $e0c034 STATE_REGISTER gequ $e1c068