GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
main.c
1#include "affine_background.h"
2#include "blind.h"
3#include "card.h"
4#include "font.h"
5#include "game.h"
6#include "gbalatro_sys8.h"
7#include "graphic_utils.h"
8#include "joker.h"
9#include "random.h"
10#include "save.h"
11#include "sprite.h"
12
13#include <maxmod.h>
14#include <string.h>
15#include <tonc.h>
16
17// Graphics
18#include "affine_background_gfx.h"
19#include "background_gfx.h"
20#include "graphic_utils.h"
21
22// Audio
23#include "audio_utils.h"
24#include "mgba_logger.h"
25#include "soundbank.h"
26#include "soundbank_bin.h"
27
28void init()
29{
30 rng_init();
31
32 irq_init(NULL);
33 irq_add(II_VBLANK, mmVBlank);
34 irq_add(II_HBLANK, affine_background_hblank);
35
36#ifdef MGBA_LOGGING
38#endif
39
40 // Initialize text engine
41 tte_init_se(
42 0,
43 BG_CBB(TTE_CBB) | BG_SBB(TTE_SBB),
44 0,
45 CLR_WHITE,
46 TTE_BIT_UNPACK_OFFSET,
47 &gbalatro_sys8Font,
48
49 // Explicitly use 8x8 tile text drawing function to improve performance
50 // See https://gbadev.net/tonc/tte.html#ssec-map-reg
51 se_drawg_w8h8
52 );
53 tte_erase_screen();
54 tte_init_con();
55
56 // Will need to be called when starting the game, as some colors will have
57 // been overwritten by the logo and its whopping 10 palettes
58 tte_colors_setup();
59
60 // Set up the video mode
61 // BG0 is the TTE text layer
62 REG_BG0CNT = BG_PRIO(0) | BG_CBB(TTE_CBB) | BG_SBB(TTE_SBB) | BG_4BPP;
63 // BG1 is the main background layer
64 REG_BG1CNT = BG_PRIO(1) | BG_CBB(MAIN_BG_CBB) | BG_SBB(MAIN_BG_SBB) | BG_8BPP;
65 // BG2 is the affine background layer
66 REG_BG2CNT = BG_PRIO(2) | BG_CBB(AFFINE_BG_CBB) | BG_SBB(AFFINE_BG_SBB) | BG_8BPP | BG_WRAP;
67
68 int win1_left = 72;
69 int win1_top = 44;
70 int win1_right = 200;
71 int win1_bottom = 128;
72
73 int win2_left = 72;
74 int win2_top = 0;
75 int win2_right = 232;
76 int win2_bottom = 44;
77
78 REG_WIN0H = win1_left << 8 | win1_right;
79 REG_WIN0V = win1_top << 8 | win1_bottom;
80 REG_WIN0CNT = WIN_ALL | WIN_BLD;
81 REG_WINOUTCNT = WIN_ALL;
82
83 REG_WIN1H = win2_left << 8 | win2_right;
84 REG_WIN1V = win2_top << 8 | win2_bottom;
85 REG_WIN1CNT = WIN_ALL | WIN_BLD;
86
87 REG_BLDCNT = BLD_BUILD(BLD_BG1, BLD_BG2, 1);
88
89 REG_BLDALPHA = BLDA_BUILD(0, 13);
90
91 REG_DISPCNT = DCNT_MODE1 | DCNT_OBJ_1D | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ | DCNT_WIN0 |
92 DCNT_WIN1;
93 // Initialize subsystems
94 mmInitDefault((mm_addr)soundbank_bin, GBAL_MM_NUM_CHANNELS);
98 card_init();
99 blind_init();
100 joker_init();
101 game_init();
102 game_change_state(GAME_STATE_SPLASH_SCREEN);
103}
104
105void update()
106{
108 game_update();
109}
110
111void draw()
112{
113 sprite_draw();
114}
115
116int main()
117{
118 init();
119
120 while (true)
121 {
122 VBlankIntrWait();
123 mmFrame();
124 key_poll();
125 update();
126 draw();
127 }
128
129 return 0;
130}
Utilities for affine background on GBA.
void affine_background_init()
Initialize resources for affine background rendering.
IWRAM_CODE void affine_background_update()
Per-frame update of the affine background.
IWRAM_CODE void affine_background_hblank()
Interrupt routine to update display on HBLANK.
Utilities for using maxmod to play sound effects.
#define GBAL_MM_NUM_CHANNELS
Definition audio_utils.h:56
Data structures and functions relative to the behaviour and graphics of Blinds.
Utility file to interact with custom font.
Graphic utility functions.
Functions relative to the handling of Jokers.
Interface to interact with the mgba logger.
bool mgba_logger_init(void)
Initialize mgba logger.
Definition mgba_logger.c:69
Common functions to handle RNG manipulation. Using this interface has three goals:
void rng_init(void)
Starts counting CPU cycles, which will be used by rng_shuffle_seed to generate a more random seed....
Definition random.c:16
Utils functions to save/load data structures from/to the SRAM.
void load_options(void)
Load options values from SRAM.
Definition save.c:316
Sprite system for Gbalatro.
void sprite_init(void)
Initialize GBAlatro sprite system.
Definition sprite.c:154
void sprite_draw(void)
Draw Sprites to screen, to be called once per frame.
Definition sprite.c:159