c7ef3c0047
Extend the bitmap font pipeline with the Chinese Joker glyph subset and encode supported UTF-8 text for Tonc TTE. Move the affine map clear of the expanded font, add a compile-time VRAM overlap guard, and cover every custom glyph with host tests.
156 lines
3.7 KiB
C
156 lines
3.7 KiB
C
#include "affine_background.h"
|
|
#include "blind.h"
|
|
#include "card.h"
|
|
#include "font.h"
|
|
#include "game.h"
|
|
#include "gbalatro_sys8.h"
|
|
#include "graphic_utils.h"
|
|
#include "joker.h"
|
|
#include "random.h"
|
|
#include "save.h"
|
|
#include "sprite.h"
|
|
|
|
#include <maxmod.h>
|
|
#include <string.h>
|
|
#include <tonc.h>
|
|
|
|
// Graphics
|
|
#include "affine_background_gfx.h"
|
|
#include "background_gfx.h"
|
|
#include "graphic_utils.h"
|
|
|
|
// Audio
|
|
#include "audio_utils.h"
|
|
#include "mgba_logger.h"
|
|
#include "soundbank.h"
|
|
#include "soundbank_bin.h"
|
|
|
|
enum
|
|
{
|
|
TTE_ASCII_GLYPH_COUNT = 96,
|
|
FONT_TILES_PER_ROW = 16,
|
|
CHARBLOCK_4BPP_TILE_COUNT = 512,
|
|
SCREENBLOCK_4BPP_TILE_COUNT = 64,
|
|
CHINESE_GLYPH_COUNT = 0
|
|
#define CHINESE_GLYPH(codepoint) +1
|
|
#include "def_chinese_glyph_table.h"
|
|
#undef CHINESE_GLYPH
|
|
,
|
|
TTE_FONT_TILE_COUNT =
|
|
TTE_ASCII_GLYPH_COUNT +
|
|
((CHINESE_GLYPH_COUNT + FONT_TILES_PER_ROW - 1) / FONT_TILES_PER_ROW) * FONT_TILES_PER_ROW,
|
|
TTE_FONT_FIRST_TILE = TTE_CBB * CHARBLOCK_4BPP_TILE_COUNT,
|
|
TTE_FONT_END_TILE = TTE_FONT_FIRST_TILE + TTE_FONT_TILE_COUNT,
|
|
AFFINE_BG_MAP_FIRST_TILE = AFFINE_BG_SBB * SCREENBLOCK_4BPP_TILE_COUNT,
|
|
AFFINE_BG_MAP_END_TILE = AFFINE_BG_MAP_FIRST_TILE + SCREENBLOCK_4BPP_TILE_COUNT,
|
|
};
|
|
|
|
_Static_assert(
|
|
TTE_FONT_END_TILE <= AFFINE_BG_MAP_FIRST_TILE || AFFINE_BG_MAP_END_TILE <= TTE_FONT_FIRST_TILE,
|
|
"TTE font tiles overlap the affine background map"
|
|
);
|
|
|
|
void init()
|
|
{
|
|
rng_init();
|
|
|
|
irq_init(NULL);
|
|
irq_add(II_VBLANK, mmVBlank);
|
|
irq_add(II_HBLANK, affine_background_hblank);
|
|
|
|
#ifdef MGBA_LOGGING
|
|
mgba_logger_init();
|
|
#endif
|
|
|
|
// Initialize text engine
|
|
tte_init_se(
|
|
0,
|
|
BG_CBB(TTE_CBB) | BG_SBB(TTE_SBB),
|
|
0,
|
|
CLR_WHITE,
|
|
TTE_BIT_UNPACK_OFFSET,
|
|
&gbalatro_sys8Font,
|
|
|
|
// Explicitly use 8x8 tile text drawing function to improve performance
|
|
// See https://gbadev.net/tonc/tte.html#ssec-map-reg
|
|
se_drawg_w8h8
|
|
);
|
|
tte_erase_screen();
|
|
tte_init_con();
|
|
|
|
// Will need to be called when starting the game, as some colors will have
|
|
// been overwritten by the logo and its whopping 10 palettes
|
|
tte_colors_setup();
|
|
|
|
// Set up the video mode
|
|
// BG0 is the TTE text layer
|
|
REG_BG0CNT = BG_PRIO(0) | BG_CBB(TTE_CBB) | BG_SBB(TTE_SBB) | BG_4BPP;
|
|
// BG1 is the main background layer
|
|
REG_BG1CNT = BG_PRIO(1) | BG_CBB(MAIN_BG_CBB) | BG_SBB(MAIN_BG_SBB) | BG_8BPP;
|
|
// BG2 is the affine background layer
|
|
REG_BG2CNT = BG_PRIO(2) | BG_CBB(AFFINE_BG_CBB) | BG_SBB(AFFINE_BG_SBB) | BG_8BPP | BG_WRAP;
|
|
|
|
int win1_left = 72;
|
|
int win1_top = 44;
|
|
int win1_right = 200;
|
|
int win1_bottom = 128;
|
|
|
|
int win2_left = 72;
|
|
int win2_top = 0;
|
|
int win2_right = 232;
|
|
int win2_bottom = 44;
|
|
|
|
REG_WIN0H = win1_left << 8 | win1_right;
|
|
REG_WIN0V = win1_top << 8 | win1_bottom;
|
|
REG_WIN0CNT = WIN_ALL | WIN_BLD;
|
|
REG_WINOUTCNT = WIN_ALL;
|
|
|
|
REG_WIN1H = win2_left << 8 | win2_right;
|
|
REG_WIN1V = win2_top << 8 | win2_bottom;
|
|
REG_WIN1CNT = WIN_ALL | WIN_BLD;
|
|
|
|
REG_BLDCNT = BLD_BUILD(BLD_BG1, BLD_BG2, 1);
|
|
|
|
REG_BLDALPHA = BLDA_BUILD(0, 13);
|
|
|
|
REG_DISPCNT = DCNT_MODE1 | DCNT_OBJ_1D | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_OBJ | DCNT_WIN0 |
|
|
DCNT_WIN1;
|
|
// Initialize subsystems
|
|
mmInitDefault((mm_addr)soundbank_bin, GBAL_MM_NUM_CHANNELS);
|
|
load_options();
|
|
affine_background_init();
|
|
sprite_init();
|
|
card_init();
|
|
blind_init();
|
|
joker_init();
|
|
game_init();
|
|
game_change_state(GAME_STATE_SPLASH_SCREEN);
|
|
}
|
|
|
|
void update()
|
|
{
|
|
affine_background_update();
|
|
game_update();
|
|
}
|
|
|
|
void draw()
|
|
{
|
|
sprite_draw();
|
|
}
|
|
|
|
int main()
|
|
{
|
|
init();
|
|
|
|
while (true)
|
|
{
|
|
VBlankIntrWait();
|
|
mmFrame();
|
|
key_poll();
|
|
update();
|
|
draw();
|
|
}
|
|
|
|
return 0;
|
|
}
|