diff --git a/BuGS.xcodeproj/project.pbxproj b/BuGS.xcodeproj/project.pbxproj index 7609933..6c9e955 100644 --- a/BuGS.xcodeproj/project.pbxproj +++ b/BuGS.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 9D1716A52491C49300C83148 /* system601.2mg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9D1716A42491C49300C83148 /* system601.2mg */; }; 9D1716A72491C49300C83148 /* tail.mk in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9D1716A62491C49300C83148 /* tail.mk */; }; 9D1716AA2491C49300C83148 /* BuGS.xcscheme in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9D1716A92491C49300C83148 /* BuGS.xcscheme */; }; + 9DC4D7C124BE9F7100BACF4B /* tiles.c in Sources */ = {isa = PBXBuildFile; fileRef = 9DC4D7C024BE9F7100BACF4B /* tiles.c */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -83,6 +84,8 @@ 9D8FFC612491CAF0005C9327 /* game.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = game.h; 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 = ""; }; + 9DC4D7C024BE9F7100BACF4B /* tiles.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tiles.c; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -121,6 +124,8 @@ children = ( 9D17168E2491C49300C83148 /* main.c */, 9D1716902491C49300C83148 /* main.h */, + 9DC4D7BF24BE9F7100BACF4B /* tiles.h */, + 9DC4D7C024BE9F7100BACF4B /* tiles.c */, 9D8FFC602491CA28005C9327 /* game.s */, 9D8FFC612491CAF0005C9327 /* game.h */, 9D62AF3B249871A300348F45 /* colour.s */, @@ -292,6 +297,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9DC4D7C124BE9F7100BACF4B /* tiles.c in Sources */, 9D1716942491C49300C83148 /* Makefile in Sources */, 9D17168F2491C49300C83148 /* main.c in Sources */, ); diff --git a/BuGS/game.s b/BuGS/game.s index aa24d59..d3900ad 100644 --- a/BuGS/game.s +++ b/BuGS/game.s @@ -27,6 +27,109 @@ game start lda colourPalette jsl setColour + jsl drawDirtyGameTiles + + jsl drawDirtyNonGameTiles + + jsl waitForKey + rtl + + +drawDirtyGameTiles entry + ldy #$0 +dirtyTileLoop anop + cpy numDirtyGameTiles + blt handleDirtyTile + stz numDirtyGameTiles + rtl +handleDirtyTile anop + phy + tya + asl a + tay + + lda dirtyGameTiles,y + asl a + asl a + asl a + tax + + stz tiles,x + + txy + iny + iny + + ldx tiles,y + + iny + iny + + lda tiles,y + + jsl drawTile + + ply + iny + bra dirtyTileLoop + + +drawDirtyNonGameTiles entry + ldy #$0 +dirtyTileLoop2 anop + cpy numDirtyNonGameTiles + blt handleDirtyTile2 + stz numDirtyNonGameTiles + rtl +handleDirtyTile2 anop + phy + tya + asl a + tay + + lda dirtyNonGameTiles,y + asl a + asl a + asl a + tax + + stz tiles,x + + txy + iny + iny + + ldx tiles,y + + iny + iny + + lda tiles,y + + jsl drawTile + + ply + iny + bra dirtyTileLoop2 + +drawTile entry + asl a + asl a + tay + + lda tileJumpTable,y + sta jumpInst+1 + iny + iny + + lda tileJumpTable,y + sta jumpInst+3 + +jumpInst jmp >mushroom1 + nop + + +drawAll entry ldx #$2003 jsl mushroom1 @@ -516,7 +619,6 @@ game start ldx #$8408 jsl drawShotShift - jsl waitForKey rtl @@ -586,4 +688,58 @@ quit rtl backupStack dc i2'0' colourPalette dc i2'0' +tileJumpTable dc a4'solid0' + dc a4'mushroom4' + dc a4'mushroom3' + dc a4'mushroom2' + dc a4'mushroom1' + dc a4'symbolC' + dc a4'symbolP' + dc a4'symbolDot' + dc a4'symbolColon' + dc a4'poisonedMushroom4' + dc a4'poisonedMushroom3' + dc a4'poisonedMushroom2' + dc a4'poisonedMushroom1' + dc a4'letterA' + dc a4'letterB' + dc a4'letterC' + dc a4'letterD' + dc a4'letterE' + dc a4'letterF' + dc a4'letterG' + dc a4'letterH' + dc a4'letterI' + dc a4'letterJ' + dc a4'letterK' + dc a4'letterL' + dc a4'letterM' + dc a4'letterN' + dc a4'letterO' + dc a4'letterP' + dc a4'letterQ' + dc a4'letterR' + dc a4'letterS' + dc a4'letterT' + dc a4'letterU' + dc a4'letterV' + dc a4'letterW' + dc a4'letterX' + dc a4'letterY' + dc a4'letterZ' + dc a4'number0' + dc a4'number1' + dc a4'number2' + dc a4'number3' + dc a4'number4' + dc a4'number5' + dc a4'number6' + dc a4'number7' + dc a4'number8' + dc a4'number9' + dc a4'solid1' + dc a4'solid2' + dc a4'solid3' + dc a4'drawPlayer' + end diff --git a/BuGS/main.c b/BuGS/main.c index ae205cb..dba5e25 100644 --- a/BuGS/main.c +++ b/BuGS/main.c @@ -8,13 +8,15 @@ */ +#include #include #include #include #include "main.h" -#include "game.h"s +#include "game.h" +#include "tiles.h" /* Defines and macros */ @@ -23,24 +25,14 @@ if (toolerror()) SysFailMgr(toolerror(), "\p" string "\n\r Error Code -> $"); -/* Types */ - - /* Globals */ -BOOLEAN shouldQuit; unsigned int userid; /* Implementation */ -void initGlobals(void) -{ - shouldQuit = FALSE; -} - - int main(void) { int event; @@ -61,6 +53,12 @@ int main(void) NewHandle(0x9000, userid, attrLocked | attrFixed | attrAddr | attrBank, (Pointer)0x011000); TOOLFAIL("Unable to allocate SHR screen"); + srand((int)(time(NULL))); + + initTiles(); + initPlayer(); + addStartingMushrooms(); + game(); ShutDownTools(refIsHandle, toolStartupRef); diff --git a/BuGS/sprites/ship.s b/BuGS/sprites/ship.s index fc24b3d..f929277 100644 --- a/BuGS/sprites/ship.s +++ b/BuGS/sprites/ship.s @@ -28,6 +28,8 @@ drawShip entry ; ..OO|O... ; ..OO|O... + stz collision + lda $0,s _collision #$0c00 and #$f0ff @@ -150,6 +152,8 @@ drawShipShift entry ; ...O|OO.. ; ...O|OO.. + stz collision + lda $2,s _collision #$00c0 and #$ff0f @@ -255,10 +259,84 @@ drawShipShift entry lda collision rtl +; This differs from the above by being a tile draw routine for drawing the number of lives left. +; It assumes it is drawing to the background and overwrites what may be there and does not check +; for collisions +drawPlayer entry + _spriteHeader -clearShipCollision entry - lda #$0000 - sta collision +; $1 - Green +; $2 - Red +; $3 - Off-white +; +; ...O|.... +; ..OO|O... +; .RRO|RR.. +; ORRO|RRO. +; OOOO|OOO. +; .OOO|OO.. +; ..OO|O... +; ..OO|O... +; +; Colours #$0000 - Black, Black, Black, Black (x1) +; #$0300 - Black, Black, Black, Off-white (x1) +; #$3300 - Black, Black, Off-white, Off-white (x3) +; #$0030 - Off-white, Black, Black, Black (x3) +; #$2302 - Black, Red, Red, Off-white (x1) +; #$0022 - Red, Red, Black, Black (x1) +; #$2332 - Off-white, Red, Red, Off-white (x1) +; #$3022 - Red, Red, Off-white, Black (x1) +; #$3333 - Off-white, Off-white, Off-white, Off-white (x1) +; #$3033 - Off-white, Off-white, Off-white, Black (x1) +; #$3303 - Black, Off-white, Off-white, Off-white (x1) +; #$0033 - Off-white, Off-white, Black, Black (x1) + + pea $0000 + pea $0300 + + adc #$00a0 + tcs + + pea $0030 + pea $3300 + + adc #$00a0 + tcs + + pea $0022 + pea $2302 + + adc #$00a0 + tcs + + pea $3022 + pea $2332 + + adc #$00a0 + tcs + + pea $3033 + pea $3333 + + adc #$00a0 + tcs + + pea $0033 + pea $3303 + + adc #$00a0 + tcs + + pea $0030 + pea $3300 + + adc #$00a0 + tcs + + pea $0030 + pea $3300 + + _spriteFooter rtl diff --git a/BuGS/tiles.c b/BuGS/tiles.c new file mode 100644 index 0000000..d28cec2 --- /dev/null +++ b/BuGS/tiles.c @@ -0,0 +1,129 @@ +/* + * tiles.c + * BuGS + * + * Created by Jeremy Rand on 2020-07-14. + * Copyright © 2020 Jeremy Rand. All rights reserved. + */ + +#include + +#include "tiles.h" + + +/* Defines */ + +#define TILE_WIDTH 8 +#define TILE_HEIGHT 8 + +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 200 + +#define GAME_LEFT_MOST_X_POS (13 * TILE_WIDTH) /* 13 tiles from the left */ +#define GAME_TOP_MOST_Y_POS (0 * TILE_HEIGHT) + +#define TILE_OFFSET_FOR_X_Y(X, Y) \ + (0x2000 + (0xa0 * (Y)) + ((X) / 2) + 3) + +#define STARTING_NUM_MUSHROOMS 30 +#define STARTING_NUM_PLAYERS 3 + + +/* Globals */ + +tTile tiles[TOTAL_GAME_TILES]; + +unsigned int dirtyGameTiles[NUM_GAME_TILES]; +unsigned int numDirtyGameTiles; + +unsigned int dirtyNonGameTiles[NUM_NON_GAME_TILES]; +unsigned int numDirtyNonGameTiles; + +unsigned int numPlayers; + + +/* Implementation */ + +void initTiles(void) +{ + int tileX; + int tileY; + int lastOffset; + tTile * tilePtr = &(tiles[0]); + tTile * playerTilePtr = &(tiles[FIRST_PLAYER_TILE]); + + for (tileY = 0; tileY < GAME_NUM_TILES_TALL; tileY++) + { + lastOffset = TILE_OFFSET_FOR_X_Y(GAME_LEFT_MOST_X_POS, GAME_TOP_MOST_Y_POS + (tileY * TILE_HEIGHT)); + tilePtr->dirty = 0; + tilePtr->offset = lastOffset; + tilePtr->type = TILE_EMPTY; + tilePtr->dummy = 0; + tilePtr++; + + for (tileX = 1; tileX < GAME_NUM_TILES_WIDE; tileX++) + { + lastOffset += 4; + tilePtr->dirty = 0; + tilePtr->offset = lastOffset; + tilePtr->type = TILE_EMPTY; + tilePtr->dummy = 0; + tilePtr++; + } + + lastOffset += 4; + playerTilePtr->dirty = 0; + playerTilePtr->offset = lastOffset; + playerTilePtr->type = TILE_EMPTY; + playerTilePtr->dummy = 0; + playerTilePtr++; + + lastOffset += 4; + playerTilePtr->dirty = 0; + playerTilePtr->offset = lastOffset; + playerTilePtr->type = TILE_EMPTY; + playerTilePtr->dummy = 0; + playerTilePtr++; + } + + numDirtyGameTiles = 0; +} + + +void initPlayer(void) +{ + unsigned int i; + unsigned int tileNum; + numPlayers = STARTING_NUM_PLAYERS; + for (i = 0; i < numPlayers; i++) + { + tileNum = FIRST_PLAYER_TILE + i; + tiles[tileNum].dirty = 1; + tiles[tileNum].type = TILE_PLAYER; + + dirtyNonGameTiles[numDirtyNonGameTiles] = tileNum; + numDirtyNonGameTiles++; + } +} + + +void addStartingMushrooms(void) +{ + int tileNum; + int numMushrooms = 0; + + while (numMushrooms < STARTING_NUM_MUSHROOMS) + { + /* We do not put mushrooms in the bottom tile so we subtract the width here to find + a tile number above that last line */ + tileNum = rand() % (NUM_GAME_TILES - GAME_NUM_TILES_WIDE); + if (tiles[tileNum].type != TILE_EMPTY) + continue; + + tiles[tileNum].type = TILE_MUSHROOM4; + tiles[tileNum].dirty = 1; + dirtyGameTiles[numDirtyGameTiles] = tileNum; + numDirtyGameTiles++; + numMushrooms++; + } +} diff --git a/BuGS/tiles.h b/BuGS/tiles.h new file mode 100644 index 0000000..3524720 --- /dev/null +++ b/BuGS/tiles.h @@ -0,0 +1,117 @@ +/* + * tiles.h + * BuGS + * + * Created by Jeremy Rand on 2020-07-14. + * Copyright © 2020 Jeremy Rand. All rights reserved. + */ + +#ifndef _GUARD_PROJECTBuGS_FILEtiles_ +#define _GUARD_PROJECTBuGS_FILEtiles_ + + +/* Defines */ + +#define GAME_NUM_TILES_WIDE 25 +#define GAME_NUM_TILES_TALL 25 + +#define NUM_GAME_TILES (GAME_NUM_TILES_WIDE * GAME_NUM_TILES_TALL) + +#define NUM_PLAYER_TILES (2 * GAME_NUM_TILES_TALL) +#define FIRST_PLAYER_TILE NUM_GAME_TILES + +#define NUM_NON_GAME_TILES (NUM_PLAYER_TILES) + +#define TOTAL_GAME_TILES (NUM_GAME_TILES + NUM_NON_GAME_TILES) + + +/* Types */ + +typedef enum { + TILE_EMPTY = 0, + TILE_MUSHROOM1 = 1, + TILE_MUSHROOM2 = 2, + TILE_MUSHROOM3 = 3, + TILE_MUSHROOM4 = 4, + TILE_POISON_MUSHROOM1 = 9, + TILE_POISON_MUSHROOM2 = 10, + TILE_POISON_MUSHROOM3 = 11, + TILE_POISON_MUSHROOM4 = 12, + + TILE_SYMBOL_C = 5, + TILE_SYMBOL_P = 6, + TILE_SYMBOL_DOT = 7, + TILE_SYMBOL_COLON = 8, + + TILE_LETTER_A = 13, + TILE_LETTER_B = 14, + TILE_LETTER_C = 15, + TILE_LETTER_D = 16, + TILE_LETTER_E = 17, + TILE_LETTER_F = 18, + TILE_LETTER_G = 19, + TILE_LETTER_H = 20, + TILE_LETTER_I = 21, + TILE_LETTER_J = 22, + TILE_LETTER_K = 23, + TILE_LETTER_L = 24, + TILE_LETTER_M = 25, + TILE_LETTER_N = 26, + TILE_LETTER_O = 27, + TILE_LETTER_P = 28, + TILE_LETTER_Q = 29, + TILE_LETTER_R = 30, + TILE_LETTER_S = 31, + TILE_LETTER_T = 32, + TILE_LETTER_U = 33, + TILE_LETTER_V = 34, + TILE_LETTER_W = 35, + TILE_LETTER_X = 36, + TILE_LETTER_Y = 37, + TILE_LETTER_Z = 38, + + TILE_NUMBER_0 = 39, + TILE_NUMBER_1 = 40, + TILE_NUMBER_2 = 41, + TILE_NUMBER_3 = 42, + TILE_NUMBER_4 = 43, + TILE_NUMBER_5 = 44, + TILE_NUMBER_6 = 45, + TILE_NUMBER_7 = 46, + TILE_NUMBER_8 = 47, + TILE_NUMBER_9 = 48, + + TILE_SOLID1 = 49, + TILE_SOLID2 = 50, + TILE_SOLID3 = 51, + + TILE_PLAYER = 52, +} tTileType; + + +typedef struct +{ + unsigned int dirty; + unsigned int offset; + tTileType type; + unsigned int dummy; /* I want a size which is a multiple of 2 */ +} tTile; + + +/* Globals */ + +extern tTile tiles[TOTAL_GAME_TILES]; +extern unsigned int dirtyGameTiles[NUM_GAME_TILES]; +extern unsigned int numDirtyGameTiles; +extern unsigned int dirtyNonGameTiles[NUM_NON_GAME_TILES]; +extern unsigned int numDirtyNonGameTiles; + + +/* API */ + +extern void initTiles(void); +extern void initPlayer(void); +extern void addStartingMushrooms(void); + + +#endif /* define _GUARD_PROJECTBuGS_FILEtiles_ */