This repository has been archived on 2024-11-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Dawn-GB/archive/main.c

237 lines
5.6 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "main.h"
/*
inline uint8_t mainGetChar(char c) {
return c - TEXTBOX_FONT_START + FONT_DATA_POSITION;
}
inline void mainBufferCard(uint8_t card, uint8_t *tiles) {
uint8_t suit, number;
if(card >= CARD_DECK_SIZE) {
tiles[0] = mainGetChar('N');
tiles[1] = mainGetChar('A');
return;
}
suit = cardGetSuit(card);
number = cardGetNumber(card);
switch(suit) {
case CARD_SUIT_CLUBS:
tiles[0] = mainGetChar('C');
break;
case CARD_SUIT_DIAMONDS:
tiles[0] = mainGetChar('D');
break;
case CARD_SUIT_HEARTS:
tiles[0] = mainGetChar('H');
break;
case CARD_SUIT_SPADES:
tiles[0] = mainGetChar('S');
break;
}
switch(number) {
case CARD_TWO:
tiles[1] = mainGetChar('2');
break;
case CARD_THREE:
tiles[1] = mainGetChar('3');
break;
case CARD_FOUR:
tiles[1] = mainGetChar('4');
break;
case CARD_FIVE:
tiles[1] = mainGetChar('5');
break;
case CARD_SIX:
tiles[1] = mainGetChar('6');
break;
case CARD_SEVEN:
tiles[1] = mainGetChar('7');
break;
case CARD_EIGHT:
tiles[1] = mainGetChar('8');
break;
case CARD_NINE:
tiles[1] = mainGetChar('9');
break;
case CARD_TEN:
tiles[1] = mainGetChar('T');
break;
case CARD_JACK:
tiles[1] = mainGetChar('J');
break;
case CARD_QUEEN:
tiles[1] = mainGetChar('Q');
break;
case CARD_KING:
tiles[1] = mainGetChar('K');
break;
case CARD_ACE:
tiles[1] = mainGetChar('A');
break;
}
}
inline void mainDebugDraw() {
uint8_t j, i, n;
// DEBUG DRAW
uint8_t tiles[15];
char buffer[6];
buffer[0] = '\0';
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
n = 0;
if(j == POKER_PLAYER_BETTER) {
tiles[n++] = mainGetChar('>');
} else {
tiles[n++] = COMMON_TILE_3;
}
mainBufferCard(POKER_PLAYERS[j].hand[0], tiles+n);
n+=2;
mainBufferCard(POKER_PLAYERS[j].hand[1], tiles+n);
n+=2;
tiles[n++] = COMMON_TILE_3;
if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_FOLDED) == 0) {
tiles[n++] = COMMON_TILE_3;
} else {
tiles[n++] = mainGetChar('F');
}
if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_HAS_BET_THIS_ROUND) == 0) {
tiles[n++] = COMMON_TILE_3;
} else {
tiles[n++] = mainGetChar('H');
}
if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_OUT) == 0) {
tiles[n++] = COMMON_TILE_3;
} else {
tiles[n++] = mainGetChar('O');
}
tiles[n++] = COMMON_TILE_3;
// Print chips
sprintf(buffer, "%u", (uint16_t)POKER_PLAYERS[j].chips);
for(i = 0; i < strlen(buffer); i++) {
tiles[n++] = mainGetChar(buffer[i]);
}
while(n < 15) tiles[n++] = COMMON_TILE_3;
set_bkg_tiles(0x00, j, n - 1, 1, tiles);
}
for(j = 0; j < POKER_COMMUNITY_SIZE_MAX; j++) {
if(j >= POKER_COMMUNITY_SIZE) {
tiles[j*2] = COMMON_TILE_3;
tiles[(j*2) + 1] = COMMON_TILE_3;
} else {
mainBufferCard(POKER_COMMUNITY[j], tiles + (j * 2));
}
}
set_bkg_tiles(0x00, POKER_PLAYER_COUNT + 1, POKER_COMMUNITY_SIZE_MAX * 2, 1, tiles);
// Print Pot
n = 0;
sprintf(buffer, "%u", (uint16_t)POKER_POTS[POKER_POT_CURRENT].chips);
for(i = 0; i < strlen(buffer); i++) {
tiles[n++] = mainGetChar(buffer[i]);
}
while(n < 5) tiles[n++] = COMMON_TILE_3;
set_bkg_tiles(0x00, POKER_PLAYER_COUNT + 2, n, 1, tiles);
}
*/
void main() {
int16_t j;
uint8_t filled[GB_BACKGROUND_COLUMNS*GB_BACKGROUND_ROWS];
// Set up the GAMEBOY's registers.
disable_interrupts();
DISPLAY_OFF;
LCDC_REG = LCDCF_OFF | LCDCF_BG8000 | LCDCF_BG9800 | LCDCF_BGON;
// Set the background color palette register
BGP_REG = OBP0_REG = OBP1_REG = 0xE4U;
// Init the random seed
initarand(DIV_REG);
// Init things
spriteTilesetBuffer(0x00);
spriteFontBuffer(TEXTBOX_SPRITE_FONT_POSITION);
spriteBorderBuffer(TEXTBOX_SPRITE_BORDER_POSITION);
spriteCardsBuffer(TEXTBOX_SPRITE_BORDER_POSITION + BORDER_IMAGE_TILES);
conversationTextboxInit();
conversationQueueInit();
pokerInit();
// Fill screen white
for(j = 0; j < GB_BACKGROUND_COLUMNS * GB_BACKGROUND_ROWS; j++) filled[j] = SPRITE_TILESET_BLACK_LOW;
spriteBufferBackgroundLow(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled);
SCX_REG = 0x00;
SCY_REG = 0x00;
// Card Test
uint8_t cardTiles[4 * 6];
spriteCardBufferTiles(
TEXTBOX_SPRITE_BORDER_POSITION+BORDER_IMAGE_TILES,
cardTiles,
CARD_HEARTS_TWO
);
// set_bkg_tiles(0x00, 0x00, 4, 6, cardTiles);
// Now turn the screen on
DISPLAY_ON;
enable_interrupts();
wait_vbl_done();
// Begin game
// conversationQueueNext();
// Begin the loop
while(1) {
// Perform non-graphical code updates
wait_vbl_done();
continue;
// Update the input state
INPUT_LAST = INPUT_STATE;
INPUT_STATE = joypad();
INPUT_PRESSED = (~INPUT_LAST) & INPUT_STATE;
// Tick time.
timeUpdate();
// Update conversation pause effect
conversationPauseUpdate();
// Update question box and textbox
questionBoxUpdate();
conversationTextboxUpdate();
// Update conversation fade effect
conversationFadeUpdate();
// mainDebugDraw();
}
}