Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 533cd57

Browse files
committed
Align core.c with SA3
1 parent 60b1bca commit 533cd57

1 file changed

Lines changed: 111 additions & 1 deletion

File tree

src/core.c

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,41 @@ static VBlankProcessFunc const sVblankFuncs[] = {
225225
SA2_LABEL(sub_8002B20),
226226
};
227227

228+
#if (ENGINE == ENGINE_3)
229+
// Multiboot area?
230+
extern u8 gUnknown_02035000[0xA000];
231+
extern void sub_80C4B48(void);
232+
233+
// (99.97%) https://decomp.me/scratch/hVNLQ
234+
NONMATCH("asm/non_matching/engine/EngineInit_sa3.inc", void EngineInit(void))
235+
#else
236+
// TODO: All DMAs are followed by a DmaWait(3) call in SA3... is this global and should be part of the macros?
228237
void EngineInit(void)
238+
#endif
229239
{
230240
s16 i;
231241
u16 errorIdentifying;
232242

243+
#if (ENGINE == ENGINE_3)
244+
REG_IME = 0;
245+
#endif
233246
REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3;
234247
gFlags = 0;
235248
gFlagsPreVBlank = 0;
249+
#if (ENGINE >= ENGINE_3)
250+
gUnknown_030035A4 = ~0;
251+
#endif
236252

237253
#ifndef COLLECT_RINGS_ROM
238254
if ((REG_RCNT & 0xC000) != 0x8000) {
239255
gFlags = FLAGS_200;
256+
257+
#if (ENGINE == ENGINE_3)
258+
DmaCopy16(3, (void *)BG_SCREEN_ADDR(24), gUnknown_02035000, sizeof(gUnknown_02035000));
259+
DmaWait(3);
260+
#else
240261
DmaCopy16(3, (void *)OBJ_VRAM0, EWRAM_START + 0x3B000, 0x5000);
262+
#endif
241263
}
242264
#endif
243265

@@ -246,47 +268,96 @@ void EngineInit(void)
246268
if (gInput == (START_BUTTON | SELECT_BUTTON | B_BUTTON | A_BUTTON)) {
247269
gFlags |= FLAGS_SKIP_INTRO;
248270
} else {
271+
#if (ENGINE == ENGINE_3)
272+
gFlags = 0;
273+
#else
249274
gFlags &= ~FLAGS_SKIP_INTRO;
275+
#endif
250276
}
251277

252278
#if COLLECT_RINGS_ROM
253279
DmaCopy16(3, (void *)OBJ_VRAM0, (void *)(EWRAM_START + 0x3b000), 0x5000);
254280
#else
255281
DmaFill32(3, 0, (void *)VRAM, VRAM_SIZE);
282+
#if (ENGINE == ENGINE_3)
283+
DmaWait(3);
284+
#endif
256285
#endif
257286
DmaFill32(3, 0, (void *)OAM, OAM_SIZE);
287+
#if (ENGINE == ENGINE_3)
288+
DmaWait(3);
289+
#endif
258290
DmaFill32(3, 0, (void *)PLTT, PLTT_SIZE);
291+
#if (ENGINE == ENGINE_3)
292+
DmaWait(3);
293+
#endif
259294

295+
#if (ENGINE == ENGINE_3)
296+
sLastCalledVblankFuncId = VBLANK_FUNC_ID_NONE;
297+
298+
gBackgroundsCopyQueueIndex = gBackgroundsCopyQueueCursor = 0;
299+
gBgSpritesCount = 0;
300+
gVramGraphicsCopyCursor = 0;
301+
gVramGraphicsCopyQueueIndex = gVramGraphicsCopyCursor = 0;
302+
#else
260303
sLastCalledVblankFuncId = VBLANK_FUNC_ID_NONE;
261304
gBackgroundsCopyQueueCursor = 0;
262305
gBackgroundsCopyQueueIndex = 0;
263306
gBgSpritesCount = 0;
264307
gVramGraphicsCopyCursor = 0;
265308
gVramGraphicsCopyQueueIndex = 0;
266-
309+
#endif
267310
DmaFill32(3, 0, gBgSprites_Unknown2, sizeof(gBgSprites_Unknown2));
311+
#if (ENGINE == ENGINE_3)
312+
DmaWait(3);
313+
#endif
268314

269315
// TODO: sort out this type
270316
*(u32 *)gBgSprites_Unknown1 = 0;
271317

272318
DmaFill32(3, 0, gBgScrollRegs, sizeof(gBgScrollRegs));
319+
#if (ENGINE == ENGINE_3)
320+
DmaWait(3);
321+
#endif
273322

274323
gSpriteOffset.x = 0;
275324
gSpriteOffset.y = 0;
276325

277326
gDispCnt = DISPCNT_FORCED_BLANK;
278327

279328
DmaFill32(3, 0, gVramGraphicsCopyQueue, sizeof(gVramGraphicsCopyQueue));
329+
#if (ENGINE == ENGINE_3)
330+
DmaWait(3);
331+
#endif
280332

281333
gOamFreeIndex = 0;
282334
gOamFirstPausedIndex = 0;
283335

284336
DmaFill16(3, 0x200, gOamBuffer, sizeof(gOamBuffer));
337+
#if (ENGINE == ENGINE_3)
338+
DmaWait(3);
339+
#endif
285340
DmaFill16(3, 0x200, gOamMallocBuffer, sizeof(gOamMallocBuffer));
341+
#if (ENGINE == ENGINE_3)
342+
DmaWait(3);
343+
#endif
286344
DmaFill32(3, ~0, gOamMallocOrders_StartIndex, sizeof(gOamMallocOrders_StartIndex));
345+
#if (ENGINE == ENGINE_3)
346+
DmaWait(3);
347+
#endif
287348
DmaFill32(3, ~0, gOamMallocOrders_EndIndex, sizeof(gOamMallocOrders_EndIndex));
349+
#if (ENGINE == ENGINE_3)
350+
DmaWait(3);
351+
#endif
288352
DmaFill32(3, 0, gObjPalette, sizeof(gObjPalette));
353+
#if (ENGINE == ENGINE_3)
354+
DmaWait(3);
355+
#endif
289356
DmaFill32(3, 0, gBgPalette, sizeof(gBgPalette));
357+
#if (ENGINE == ENGINE_3)
358+
DmaWait(3);
359+
sub_80C4B48();
360+
#endif
290361

291362
// BG2
292363
gBgAffineRegs[0].pa = 0x100;
@@ -355,6 +426,9 @@ void EngineInit(void)
355426
}
356427

357428
DmaFill32(3, 0, &gBgOffsetsBuffer, sizeof(gBgOffsetsBuffer));
429+
#if (ENGINE == ENGINE_3)
430+
DmaWait(3);
431+
#endif
358432

359433
gBgOffsetsHBlankPrimary = gBgOffsetsBuffer[0];
360434
gBgOffsetsHBlankSecondary = gBgOffsetsBuffer[1];
@@ -364,13 +438,25 @@ void EngineInit(void)
364438
gNumHBlankIntrs = 0;
365439

366440
DmaFill32(3, 0, gHBlankCallbacks, sizeof(gHBlankCallbacks));
441+
#if (ENGINE == ENGINE_3)
442+
DmaWait(3);
443+
#endif
367444
DmaFill32(3, 0, gHBlankIntrs, sizeof(gHBlankCallbacks));
445+
#if (ENGINE == ENGINE_3)
446+
DmaWait(3);
447+
#endif
368448

369449
gNumVBlankCallbacks = 0;
370450
gNumVBlankIntrs = 0;
371451

372452
DmaFill32(3, 0, gVBlankCallbacks, sizeof(gVBlankCallbacks));
453+
#if (ENGINE == ENGINE_3)
454+
DmaWait(3);
455+
#endif
373456
DmaFill32(3, 0, gVBlankIntrs, sizeof(gVBlankIntrs));
457+
#if (ENGINE == ENGINE_3)
458+
DmaWait(3);
459+
#endif
374460

375461
m4aSoundInit();
376462
m4aSoundMode(DEFAULT_SOUND_MODE);
@@ -404,24 +490,48 @@ void EngineInit(void)
404490
// On GBA the function gets pushed into IWRAM because executing it there is very,
405491
// very fast
406492
DmaCopy32(3, IntrMain, gIntrMainBuf, sizeof(gIntrMainBuf));
493+
#if (ENGINE == ENGINE_3)
494+
DmaWait(3);
495+
#endif
407496
INTR_VECTOR = (void *)gIntrMainBuf;
408497
#else
409498
// On platforms where the whole program is in main RAM anyway, that is not necessary
410499
INTR_VECTOR = IntrMain;
411500
#endif
412501

502+
#if (ENGINE == ENGINE_3)
503+
REG_IE = INTR_FLAG_VBLANK;
504+
REG_DISPSTAT = DISPSTAT_HBLANK_INTR | DISPSTAT_VBLANK_INTR;
505+
REG_IME = INTR_FLAG_VBLANK;
506+
#else
413507
REG_IME = INTR_FLAG_VBLANK;
414508
REG_IE = INTR_FLAG_VBLANK;
415509
REG_DISPSTAT = DISPSTAT_HBLANK_INTR | DISPSTAT_VBLANK_INTR;
510+
#endif
416511

417512
// Setup multi sio
418513
DmaFill32(3, 0, &gMultiSioSend, sizeof(gMultiSioSend));
514+
#if (ENGINE == ENGINE_3)
515+
DmaWait(3);
516+
#endif
419517
DmaFill32(3, 0, gMultiSioRecv, sizeof(gMultiSioRecv));
518+
#if (ENGINE == ENGINE_3)
519+
DmaWait(3);
520+
#endif
420521
gMultiSioStatusFlags = 0;
421522
gMultiSioEnabled = FALSE;
422523

423524
MultiSioInit(0);
525+
526+
#if (ENGINE == ENGINE_3)
527+
gUnknown_0300620C = 0;
528+
gUnknown_03002BF0 = 0;
529+
gUnknown_03002C60 = 0;
530+
#endif
424531
}
532+
#if (ENGINE == ENGINE_3)
533+
END_NONMATCH
534+
#endif
425535

426536
void EngineMainLoop(void)
427537
{

0 commit comments

Comments
 (0)