192 lines
4.2 KiB
C
192 lines
4.2 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 - 33 + 4;
|
|
}
|
|
|
|
inline void mainBufferChar(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;
|
|
|
|
// DEBUG DRAW
|
|
uint8_t tiles[10];
|
|
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
|
|
mainBufferChar(POKER_PLAYERS[j].hand[0], tiles);
|
|
mainBufferChar(POKER_PLAYERS[j].hand[1], tiles + 2);
|
|
|
|
tiles[4] = COMMON_TILE_3;
|
|
|
|
if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_FOLDED) == 0) {
|
|
tiles[5] = COMMON_TILE_3;
|
|
} else {
|
|
tiles[5] = mainGetChar('F');
|
|
}
|
|
|
|
if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_HAS_BET_THIS_ROUND) == 0) {
|
|
tiles[6] = COMMON_TILE_3;
|
|
} else {
|
|
tiles[6] = mainGetChar('H');
|
|
}
|
|
|
|
if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_OUT) == 0) {
|
|
tiles[7] = COMMON_TILE_3;
|
|
} else {
|
|
tiles[7] = mainGetChar('O');
|
|
}
|
|
|
|
if(j == POKER_PLAYER_BETTER) {
|
|
tiles[8] = mainGetChar('<');
|
|
} else {
|
|
tiles[8] = COMMON_TILE_3;
|
|
}
|
|
set_bkg_tiles(0x00, j, 9, 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 {
|
|
mainBufferChar(POKER_COMMUNITY[j], tiles + (j * 2));
|
|
}
|
|
}
|
|
|
|
set_bkg_tiles(0x00, POKER_PLAYER_COUNT + 1, 10, 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_WIN9C00 | LCDCF_WINON | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON;
|
|
// Set the background color palette register
|
|
BGP_REG = OBP0_REG = OBP1_REG = 0xE4U;
|
|
|
|
// Init the random seed
|
|
initarand(DIV_REG);
|
|
|
|
// Prepare time and input
|
|
INPUT_STATE = joypad();
|
|
|
|
// Init things
|
|
timeInit();
|
|
commonTilesInit();
|
|
conversationTextboxInit();
|
|
conversationQueueInit();
|
|
pokerInit();
|
|
|
|
// Fill screen white
|
|
for(j = 0; j < GB_BACKGROUND_COLUMNS * GB_BACKGROUND_ROWS; j++) filled[j] = COMMON_TILE_3;
|
|
set_bkg_tiles(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled);
|
|
SCX_REG = 0x00;
|
|
SCY_REG = 0x00;
|
|
|
|
// Alright begin the game logic here.
|
|
conversationQueueNext();
|
|
|
|
// Now turn the screen on
|
|
DISPLAY_ON;
|
|
enable_interrupts();
|
|
wait_vbl_done();
|
|
|
|
// Begin the loop
|
|
while(1) {
|
|
// Perform non-graphical code updates
|
|
wait_vbl_done();
|
|
|
|
// Update the input state
|
|
INPUT_STATE = joypad();
|
|
|
|
// Tick time.
|
|
timeUpdate();
|
|
|
|
// Update conversation pause effect
|
|
conversationPauseUpdate();
|
|
|
|
// Update conversation textbox
|
|
conversationTextboxUpdate();
|
|
|
|
// Update conversation fade effect
|
|
conversationFadeUpdate();
|
|
}
|
|
}
|