From 22a45003f0c5d34139444906e85d6a6182ed2f05 Mon Sep 17 00:00:00 2001 From: Cem Gokmen Date: Sun, 4 Nov 2018 17:50:55 -0500 Subject: [PATCH] Now this compiles --- gameGraphics.c | 3 +++ gameGraphics.h | 5 +++++ gameLogic.c | 5 ++++- gameLogic.h | 5 +++++ gba.c | 33 +++++++++++++++++++++------------ gba.h | 15 ++++++++++----- main.c | 12 ++++++------ 7 files changed, 54 insertions(+), 24 deletions(-) diff --git a/gameGraphics.c b/gameGraphics.c index 34676cd..e89059f 100644 --- a/gameGraphics.c +++ b/gameGraphics.c @@ -13,16 +13,19 @@ // including the background and whatnot. void fullDrawGame(Game *game) { // TA-TODO: IMPLEMENT. + UNUSED(game); } // This function will be used to undraw (i.e. erase) things that might // move in a frame. E.g. in a Snake game, erase the Snake, the food & the score. void undrawGame(Game *game) { // TA-TODO: IMPLEMENT. + UNUSED(game); } // This function will be used to draw things that might have moved in a frame. // For example, in a Snake game, draw the snake, the food, the score. void drawGame(Game *game) { // TA-TODO: IMPLEMENT. + UNUSED(game); } diff --git a/gameGraphics.h b/gameGraphics.h index 4e8d587..62c37c5 100644 --- a/gameGraphics.h +++ b/gameGraphics.h @@ -1,3 +1,6 @@ +#ifndef GRAPHICS_SEEN +#define GRAPHICS_SEEN + #include "gameLogic.h" // This function will be used to draw everything about the game @@ -14,3 +17,5 @@ void drawGame(Game *game); // If you have anything else you need accessible from outside the gameLogic.c // file, you can add them here. You likely won't. + +#endif diff --git a/gameLogic.c b/gameLogic.c index 1cf65f4..abb9f5a 100644 --- a/gameLogic.c +++ b/gameLogic.c @@ -4,6 +4,7 @@ void initializeGame(Game* game) { // TA-TODO: Initialize everything that's part of this Game struct here. // Suppose the struct contains random values, make sure everything gets // the value it should have when the game begins. + UNUSED(game); } // TA-TODO: Add any process functions for sub-elements of your game here. @@ -30,5 +31,7 @@ void processGame(Game *game, u32 keysPressedBefore, u32 keysPressedNow) { * * Do not do any drawing here. */ - + UNUSED(game); + UNUSED(keysPressedBefore); + UNUSED(keysPressedNow); } diff --git a/gameLogic.h b/gameLogic.h index ea98fae..86d4ce2 100644 --- a/gameLogic.h +++ b/gameLogic.h @@ -1,3 +1,6 @@ +#ifndef LOGIC_SEEN +#define LOGIC_SEEN + #include "gba.h" typedef struct { @@ -39,3 +42,5 @@ void processGame(Game *game, u32 keysPressedBefore, u32 keysPressedNow); // If you have anything else you need accessible from outside the gameLogic.c // file, you can add them here. You likely won't. + +#endif diff --git a/gba.c b/gba.c index 6b6afc9..590f5e9 100644 --- a/gba.c +++ b/gba.c @@ -1,9 +1,9 @@ #include "gba.h" -u16 *videoBuffer = (u16 *)0x6000000; +volatile unsigned short *videoBuffer = (u16 *)0x6000000; u32 vBlankCounter = 0; -void waitForVBlank() { +void waitForVBlank(void) { // TA-TODO: IMPLEMENT // Write a while loop that keeps going until we're NOT in vBlank anymore: @@ -19,13 +19,7 @@ void waitForVBlank() { } static int __qran_seed= 42; -static int sqran(int seed) { - int old= __qran_seed; - __qran_seed= seed; - return old; -} - -static int qran() { +static int qran(void) { __qran_seed= 1664525*__qran_seed+1013904223; return (__qran_seed>>16) & 0x7FFF; } @@ -36,29 +30,44 @@ int randint(int min, int max) { void setPixel(int x, int y, u16 color) { // TA-TODO: IMPLEMENT + UNUSED(x); + UNUSED(y); + UNUSED(color); } void drawRectDMA(int x, int y, int width, int height, volatile u16 color) { // TA-TODO: IMPLEMENT + UNUSED(x); + UNUSED(y); + UNUSED(width); + UNUSED(height); + UNUSED(color); } void drawFullScreenImageDMA(u16 *image) { // TA-TODO: IMPLEMENT + UNUSED(image); } void drawImageDMA(int x, int y, int width, int height, u16 *image) { // TA-TODO: IMPLEMENT + UNUSED(x); + UNUSED(y); + UNUSED(width); + UNUSED(height); + UNUSED(image); } void fillScreenDMA(volatile u16 color) { // TA-TODO: IMPLEMENT + UNUSED(color); } void drawChar(int col, int row, char ch, u16 color) { for(int r = 0; r<8; r++) { for(int c=0; c<6; c++) { if(fontdata_6x8[OFFSET(r, c, 6) + ch*48]) { - setPixel(videoBuffer, col+c, row+r, color); + setPixel(col+c, row+r, color); } } } @@ -66,7 +75,7 @@ void drawChar(int col, int row, char ch, u16 color) { void drawString(int col, int row, char *str, u16 color) { while(*str) { - drawChar(videoBuffer, col, row, *str++, color); + drawChar(col, row, *str++, color); col += 6; } } @@ -84,5 +93,5 @@ void drawCenteredString(int x, int y, int width, int height, char *str, u16 colo int col = x + ((width - strWidth) >> 1); int row = y + ((height - strHeight) >> 1); - drawString(videoBuffer, col, row, str, color); + drawString(col, row, str, color); } diff --git a/gba.h b/gba.h index 6c5a0d4..07ae702 100644 --- a/gba.h +++ b/gba.h @@ -1,3 +1,6 @@ +#ifndef GBA_SEEN +#define GBA_SEEN + // --------------------------------------------------------------------------- // USEFUL TYPEDEFS // --------------------------------------------------------------------------- @@ -112,12 +115,12 @@ extern u32 vblankCounter; /** * Runs a blocking loop until the start of next VBlank. */ -void waitForVBlank(); +void waitForVBlank(void); // --------------------------------------------------------------------------- // MISC // --------------------------------------------------------------------------- -#define UNUSED_PARAM(param) ((void)((param))) +#define UNUSED(param) ((void)((param))) /** * Generates a pseudo-random number between min and max, inclusive. @@ -136,10 +139,12 @@ void drawRectDMA(int x, int y, int width, int height, volatile u16 color); void drawFullScreenImageDMA(u16 *image); void drawImageDMA(int x, int y, int width, int height, u16 *image); void fillScreenDMA(volatile u16 color); -void drawChar(int x, int y, char ch, u16 color); -void drawString(int x, int y, char *str, u16 color); -void drawCenteredString(int x, int y, int width, int height, char *str, u16 color); +void drawChar(int col, int row, char ch, u16 color); +void drawString(int col, int row, char *str, u16 color); +void drawCenteredString(int col, int row, int width, int height, char *str, u16 color); /** Contains the pixels of each character from a 6x8 font */ // This is in the font.c file. You can replace the font if you want. extern const unsigned char fontdata_6x8[12288]; + +#endif diff --git a/main.c b/main.c index 148110e..2056647 100644 --- a/main.c +++ b/main.c @@ -18,7 +18,7 @@ typedef enum { GAMEOVER_NODRAW, } GBAState; -int main() { +int main(void) { GBAState state = START; Game game; @@ -47,22 +47,22 @@ int main() { break; case GAME_INIT: // Initialize the game. Switch to the GAME state. - initializeGame(game); + initializeGame(&game); // Draw the initial state of the game - fullDrawGame(game); + fullDrawGame(&game); state = GAME; break; case GAME: // Un-draw any potentially moving elements of the game - undrawGame(game); + undrawGame(&game); // Process the game for one frame - processGame(game, previousButtons, currentButtons); + processGame(&game, previousButtons, currentButtons); // Draw the current state of the game - drawGame(game); + drawGame(&game); // Check if the game is over. If it is, then go to the gameover state. if (game.gameOver) state = GAMEOVER;