Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1#include "engine/game.h"
2#include <libgs.h>
3#include <libetc.h>
4#include <libsnd.h>
5
6/* -G8 unit: small variables defined here are reached through $gp, in the small data (.sdata) */
7/* Where the boot image, the 320x480 TIM loaded after the executable, goes in VRAM */
8static RECT BOOT_IMAGE_RECT = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT * 2 };
9static void *ROOT_TASK = NULL; /* the task that runs the game mode */
10
11/* Starts the hardware, the libraries and the engine, then runs a frame per iteration */
12int main(void) {
13 RECT rect;
14 GsIMAGE tim;
15 u_char param[8];
16
17#if PAL_VIDEO
18 if (NTSC_MODE) {
19 SetVideoMode(MODE_NTSC);
20 } else {
21 SetVideoMode(MODE_PAL);
22 }
23#else
24 SetVideoMode(MODE_NTSC);
25#endif
26 ResetCallback();
27 VSync(0);
28 SetDispMask(0);
29 ResetGraph(0);
30 GFX.funcs.reset();
32 rect.x = 0;
33 rect.y = 0;
34 rect.w = 0x280;
35 rect.h = 0x1FF;
36 ClearImage(&rect, 0, 0, 0);
37 DrawSync(0);
38 GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, 1, 1, 0);
39 GsInit3D();
40 SsInit();
41 InitGeom();
42 GFX.funcs.setDisplayMode(320, 640, 1, 0);
43 PutDispEnv(&GFX.disp[0]);
44 VSync(0);
45 /* GsGetTimInfo takes the TIM after its ID word */
46 GsGetTimInfo((u_long *)SUB_OVERLAY_ADDRESS + 1, &tim);
47 VSync(0);
48 LoadImage(&BOOT_IMAGE_RECT, tim.pixel);
49 DrawSync(0);
50 VSync(0);
51 SetDispMask(1);
52 CdInit();
53 CdSetDebug(0);
54 SetGraphDebug(0);
55 param[0] = CdlModeSpeed;
56 while (CdControl(CdlSetmode, param, 0) == 0) {
57 }
58 VSync(3);
59 CdControlB(CdlPause, 0, 0);
60 HEAP.init();
61 SOUND.init();
62 RANDOM.seed(0);
64 PAD.init(0, 0x12);
66 FONT.load();
67 /*
68 * One frame per iteration: when the mode task has died (a new mode was
69 * requested), free everything the mode allocated and start the new one.
70 */
71 for (;;) {
72 if (ROOT_TASK == NULL) {
74 GFX.funcs.reset();
79 }
82 PAD.update();
83 RANDOM.next();
86 }
87}
88
89/* Where the modes' overlays (the .PRO files of AAA/PRO) load, after the
90 * executable, and the stages and other sub-overlays, after CARDGAME. */
#define NULL
Definition common.h:17
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
s32 NTSC_MODE
The European version runs at 50 Hz (PAL) unless NTSC_MODE is set; its clocks then advance 0x133,...
Definition eu_settings.c:14
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
Font FONT
decode is declared without a prototype, as callers would truncate the u8 mode, so decodeChar is cast ...
Definition font.c:78
#define SCREEN_WIDTH
The screen the modes draw on (setDisplayMode, their layers' rects)
Definition gfx.h:36
#define SCREEN_HEIGHT
Definition gfx.h:37
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
#define MEM_MODE
the current mode's: freed by main whenever the mode task ends
Definition heap.h:17
void *const SUB_OVERLAY_ADDRESS
Definition main.c:92
static void * ROOT_TASK
the task that runs the game mode
Definition main.c:9
static RECT BOOT_IMAGE_RECT
Where the boot image, the 320x480 TIM loaded after the executable, goes in VRAM.
Definition main.c:8
int main(void)
Starts the hardware, the libraries and the engine, then runs a frame per iteration.
Definition main.c:12
void *const OVERLAY_ADDRESS
Where the modes' overlays (the .PRO files of AAA/PRO) load, after the executable, and the stages and ...
Definition main.c:91
MemCardFuncs MEMCARD_FUNCS
Definition memcard.c:468
void * createModeTask(void)
Creates the task that runs the current mode (updateModeTask)
Definition overlay.c:48
u8 STAGE_VRAM[]
u8 OVERLAY_VRAM[]
the memory map of mk/version/<version>.mk, which the Makefile gives the linker: where the overlays an...
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
Random RANDOM
Definition random.c:533
TaskRegistry TASK_REGISTRY
Definition registry.c:122
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
void(* update)(void)
Definition file.h:91
void(* load)()
Definition text.h:214
void(* commitMode)()
Definition game_state.h:18
void(* newGame)()
Definition game_state.h:17
GameFuncs funcs
Definition game_state.h:582
void(* reset)(void)
Definition gfx.h:17
void(* freePrimBuffers)(void)
Definition gfx.h:21
void(* setDisplayMode)(s32 w, s32 h, s32 hires, s32 interlace)
Definition gfx.h:26
void(* drawFrame)()
Definition gfx.h:23
void(* startVSync)(void)
Definition gfx.h:22
DISPENV disp[2]
Definition gfx.h:74
GfxFuncs funcs
Definition gfx.h:77
void(* freeByTag)()
Definition heap.h:28
void(* init)()
Definition heap.h:26
void(* init)(void)
Definition memcard.h:111
void(* update)()
PAD_UPDATE.
Definition pad.h:122
void(* init)()
PAD_INIT.
Definition pad.h:120
void(* seed)(s32 seed)
Definition random.h:14
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
void(* init)(void)
Definition sound.h:186
void(* updateLoading)(void)
Definition sound.h:192
struct Task *(* run)(struct Task *task)
Definition task.h:21
void(* clear)(void)
Definition task.h:15
TaskFuncs funcs
Definition task.h:76