mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-26 05:55:15 +00:00
Make anim dma table dynamic
This commit is contained in:
parent
c45e76c870
commit
6798b2db29
6 changed files with 70 additions and 96 deletions
|
@ -336,14 +336,14 @@ static void level_cmd_load_mario_head(void) {
|
||||||
gSkipInterpolationTitleScreen = true;
|
gSkipInterpolationTitleScreen = true;
|
||||||
gGlobalTimer = 0;
|
gGlobalTimer = 0;
|
||||||
// TODO: Fix these hardcoded sizes
|
// TODO: Fix these hardcoded sizes
|
||||||
void *addr = main_pool_alloc(DOUBLE_SIZE_ON_64_BIT(0xE1000), MEMORY_POOL_LEFT);
|
static void* sMarioHead = NULL;
|
||||||
if (addr != NULL) {
|
if (!sMarioHead) { sMarioHead = calloc(1, DOUBLE_SIZE_ON_64_BIT(0xE1000)); }
|
||||||
gdm_init(addr, DOUBLE_SIZE_ON_64_BIT(0xE1000));
|
if (sMarioHead != NULL) {
|
||||||
|
gdm_init(sMarioHead, DOUBLE_SIZE_ON_64_BIT(0xE1000));
|
||||||
gd_add_to_heap(gZBuffer, sizeof(gZBuffer)); // 0x25800
|
gd_add_to_heap(gZBuffer, sizeof(gZBuffer)); // 0x25800
|
||||||
gd_add_to_heap(gFrameBuffer0, 3 * sizeof(gFrameBuffer0)); // 0x70800
|
gd_add_to_heap(gFrameBuffer0, 3 * sizeof(gFrameBuffer0)); // 0x70800
|
||||||
gdm_setup();
|
gdm_setup();
|
||||||
gdm_maketestdl(CMD_GET(s16, 2));
|
gdm_maketestdl(CMD_GET(s16, 2));
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sCurrentCmd = CMD_NEXT;
|
sCurrentCmd = CMD_NEXT;
|
||||||
|
|
|
@ -32,29 +32,27 @@
|
||||||
// FIXME: I'm not sure all of these variables belong in this file, but I don't
|
// FIXME: I'm not sure all of these variables belong in this file, but I don't
|
||||||
// know of a good way to split them
|
// know of a good way to split them
|
||||||
|
|
||||||
struct Controller gControllers[MAX_PLAYERS];
|
struct Controller gControllers[MAX_PLAYERS] = { 0 };
|
||||||
struct SPTask *gGfxSPTask;
|
struct SPTask *gGfxSPTask = NULL;
|
||||||
Gfx *gDisplayListHead;
|
Gfx *gDisplayListHead = NULL;
|
||||||
u8 *gGfxPoolEnd;
|
u8 *gGfxPoolEnd = NULL;
|
||||||
struct GfxPool *gGfxPool;
|
struct GfxPool *gGfxPool = NULL;
|
||||||
OSContStatus gControllerStatuses[4];
|
OSContStatus gControllerStatuses[4] = { 0 };
|
||||||
OSContPad gControllerPads[4];
|
OSContPad gControllerPads[4] = { 0 };
|
||||||
u8 gControllerBits;
|
u8 gControllerBits = 0;
|
||||||
s8 gEepromProbe;
|
s8 gEepromProbe = 0;
|
||||||
OSMesgQueue gGameVblankQueue;
|
OSMesgQueue gGameVblankQueue = { 0 };
|
||||||
OSMesgQueue D_80339CB8;
|
OSMesgQueue D_80339CB8 = { 0 };
|
||||||
OSMesg D_80339CD0;
|
OSMesg D_80339CD0 = NULL;
|
||||||
OSMesg D_80339CD4;
|
OSMesg D_80339CD4 = NULL;
|
||||||
struct VblankHandler gGameVblankHandler;
|
struct VblankHandler gGameVblankHandler = { 0 };
|
||||||
uintptr_t gPhysicalFrameBuffers[3];
|
uintptr_t gPhysicalFrameBuffers[3] = { 0 };
|
||||||
uintptr_t gPhysicalZBuffer;
|
uintptr_t gPhysicalZBuffer = 0;
|
||||||
void *D_80339CF0[MAX_PLAYERS];
|
void *D_80339CF0[MAX_PLAYERS] = { 0 };
|
||||||
void *D_80339CF4;
|
void *gDemoTargetAnim = NULL;
|
||||||
struct MarioAnimation D_80339D10[MAX_PLAYERS];
|
struct MarioAnimation D_80339D10[MAX_PLAYERS] = { 0 };
|
||||||
struct MarioAnimation gDemo;
|
struct MarioAnimation gDemo = { 0 };
|
||||||
UNUSED u8 filler80339D30[0x90];
|
|
||||||
|
|
||||||
s32 unused8032C690 = 0;
|
|
||||||
u32 gGlobalTimer = 0;
|
u32 gGlobalTimer = 0;
|
||||||
|
|
||||||
static u16 sCurrFBNum = 0;
|
static u16 sCurrFBNum = 0;
|
||||||
|
@ -556,8 +554,6 @@ void init_controllers(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_game_memory(void) {
|
void setup_game_memory(void) {
|
||||||
UNUSED u8 pad[8];
|
|
||||||
|
|
||||||
set_segment_base_addr(0, (void *) 0x80000000);
|
set_segment_base_addr(0, (void *) 0x80000000);
|
||||||
osCreateMesgQueue(&D_80339CB8, &D_80339CD4, 1);
|
osCreateMesgQueue(&D_80339CB8, &D_80339CD4, 1);
|
||||||
osCreateMesgQueue(&gGameVblankQueue, &D_80339CD0, 1);
|
osCreateMesgQueue(&gGameVblankQueue, &D_80339CD0, 1);
|
||||||
|
@ -566,13 +562,13 @@ void setup_game_memory(void) {
|
||||||
gPhysicalFrameBuffers[1] = VIRTUAL_TO_PHYSICAL(gFrameBuffer1);
|
gPhysicalFrameBuffers[1] = VIRTUAL_TO_PHYSICAL(gFrameBuffer1);
|
||||||
gPhysicalFrameBuffers[2] = VIRTUAL_TO_PHYSICAL(gFrameBuffer2);
|
gPhysicalFrameBuffers[2] = VIRTUAL_TO_PHYSICAL(gFrameBuffer2);
|
||||||
for (s32 i = 0; i < MAX_PLAYERS; i++) {
|
for (s32 i = 0; i < MAX_PLAYERS; i++) {
|
||||||
D_80339CF0[i] = main_pool_alloc(0x4000, MEMORY_POOL_LEFT);
|
D_80339CF0[i] = calloc(1, 0x4000);
|
||||||
set_segment_base_addr(17, (void *)D_80339CF0[i]);
|
set_segment_base_addr(17, (void *)D_80339CF0[i]);
|
||||||
func_80278A78(&D_80339D10[i], gMarioAnims, D_80339CF0[i]);
|
alloc_anim_dma_table(&D_80339D10[i], gMarioAnims, D_80339CF0[i]);
|
||||||
}
|
}
|
||||||
D_80339CF4 = main_pool_alloc(2048, MEMORY_POOL_LEFT);
|
gDemoTargetAnim = calloc(1, 2048);
|
||||||
set_segment_base_addr(24, (void *) D_80339CF4);
|
set_segment_base_addr(24, (void *) gDemoTargetAnim);
|
||||||
func_80278A78(&gDemo, gDemoInputs, D_80339CF4);
|
alloc_anim_dma_table(&gDemo, gDemoInputs, gDemoTargetAnim);
|
||||||
load_segment(0x10, _entrySegmentRomStart, _entrySegmentRomEnd, MEMORY_POOL_LEFT);
|
load_segment(0x10, _entrySegmentRomStart, _entrySegmentRomEnd, MEMORY_POOL_LEFT);
|
||||||
load_segment_decompress(2, _segment2_mio0SegmentRomStart, _segment2_mio0SegmentRomEnd);
|
load_segment_decompress(2, _segment2_mio0SegmentRomStart, _segment2_mio0SegmentRomEnd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ extern struct VblankHandler gGameVblankHandler;
|
||||||
extern uintptr_t gPhysicalFrameBuffers[3];
|
extern uintptr_t gPhysicalFrameBuffers[3];
|
||||||
extern uintptr_t gPhysicalZBuffer;
|
extern uintptr_t gPhysicalZBuffer;
|
||||||
extern void *D_80339CF0[MAX_PLAYERS];
|
extern void *D_80339CF0[MAX_PLAYERS];
|
||||||
extern void *D_80339CF4;
|
extern void *gDemoTargetAnim;
|
||||||
extern struct SPTask *gGfxSPTask;
|
extern struct SPTask *gGfxSPTask;
|
||||||
extern Gfx *gDisplayListHead;
|
extern Gfx *gDisplayListHead;
|
||||||
extern u8 *gGfxPoolEnd;
|
extern u8 *gGfxPoolEnd;
|
||||||
|
|
|
@ -67,10 +67,10 @@ s16 gChangeLevelTransition = -1;
|
||||||
s16 gChangeActNum = -1;
|
s16 gChangeActNum = -1;
|
||||||
|
|
||||||
static bool sFirstCastleGroundsMenu = true;
|
static bool sFirstCastleGroundsMenu = true;
|
||||||
bool isDemoActive = false;
|
static bool sIsDemoActive = false;
|
||||||
bool gInPlayerMenu = false;
|
bool gInPlayerMenu = false;
|
||||||
static u16 gDemoCountdown = 0;
|
static u16 gDemoCountdown = 0;
|
||||||
int demoNumber = -1;
|
static int sDemoNumber = -1;
|
||||||
|
|
||||||
// TODO: Make these ifdefs better
|
// TODO: Make these ifdefs better
|
||||||
const char *credits01[] = { "1GAME DIRECTOR", "SHIGERU MIYAMOTO" };
|
const char *credits01[] = { "1GAME DIRECTOR", "SHIGERU MIYAMOTO" };
|
||||||
|
@ -1125,56 +1125,56 @@ void basic_update(UNUSED s16 *arg) {
|
||||||
bool find_demo_number(void) {
|
bool find_demo_number(void) {
|
||||||
switch (gCurrLevelNum) {
|
switch (gCurrLevelNum) {
|
||||||
case LEVEL_BOWSER_1:
|
case LEVEL_BOWSER_1:
|
||||||
demoNumber = 0;
|
sDemoNumber = 0;
|
||||||
return true;
|
return true;
|
||||||
case LEVEL_WF:
|
case LEVEL_WF:
|
||||||
demoNumber = 1;
|
sDemoNumber = 1;
|
||||||
return true;
|
return true;
|
||||||
case LEVEL_CCM:
|
case LEVEL_CCM:
|
||||||
demoNumber = 2;
|
sDemoNumber = 2;
|
||||||
return true;
|
return true;
|
||||||
case LEVEL_BBH:
|
case LEVEL_BBH:
|
||||||
demoNumber = 3;
|
sDemoNumber = 3;
|
||||||
return true;
|
return true;
|
||||||
case LEVEL_JRB:
|
case LEVEL_JRB:
|
||||||
demoNumber = 4;
|
sDemoNumber = 4;
|
||||||
return true;
|
return true;
|
||||||
case LEVEL_HMC:
|
case LEVEL_HMC:
|
||||||
demoNumber = 5;
|
sDemoNumber = 5;
|
||||||
return true;
|
return true;
|
||||||
case LEVEL_PSS:
|
case LEVEL_PSS:
|
||||||
demoNumber = 6;
|
sDemoNumber = 6;
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
demoNumber = -1;
|
sDemoNumber = -1;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void start_demo(void) {
|
static void start_demo(void) {
|
||||||
if (isDemoActive) {
|
if (sIsDemoActive) {
|
||||||
isDemoActive = false;
|
sIsDemoActive = false;
|
||||||
} else {
|
} else {
|
||||||
isDemoActive = true;
|
sIsDemoActive = true;
|
||||||
|
|
||||||
if (find_demo_number()) {
|
if (find_demo_number()) {
|
||||||
gChangeLevel = gCurrLevelNum;
|
gChangeLevel = gCurrLevelNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (demoNumber <= 6 || demoNumber > -1) {
|
if (sDemoNumber <= 6 || sDemoNumber > -1) {
|
||||||
gCurrDemoInput = NULL;
|
gCurrDemoInput = NULL;
|
||||||
func_80278A78(&gDemo, gDemoInputs, D_80339CF4);
|
alloc_anim_dma_table(&gDemo, gDemoInputs, gDemoTargetAnim);
|
||||||
load_patchable_table(&gDemo, demoNumber);
|
load_patchable_table(&gDemo, sDemoNumber);
|
||||||
gCurrDemoInput = ((struct DemoInput *) gDemo.targetAnim);
|
gCurrDemoInput = ((struct DemoInput *) gDemo.targetAnim);
|
||||||
} else {
|
} else {
|
||||||
isDemoActive = false;
|
sIsDemoActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_demo(UNUSED struct DjuiBase* caller) {
|
void stop_demo(UNUSED struct DjuiBase* caller) {
|
||||||
if (isDemoActive) {
|
if (sIsDemoActive) {
|
||||||
isDemoActive = false;
|
sIsDemoActive = false;
|
||||||
gCurrDemoInput = NULL;
|
gCurrDemoInput = NULL;
|
||||||
gChangeLevel = gCurrLevelNum;
|
gChangeLevel = gCurrLevelNum;
|
||||||
gDemoCountdown = 0;
|
gDemoCountdown = 0;
|
||||||
|
@ -1201,12 +1201,12 @@ s32 play_mode_normal(void) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gDjuiInMainMenu && gCurrDemoInput == NULL && configMenuDemos && !gInPlayerMenu) {
|
if (gDjuiInMainMenu && gCurrDemoInput == NULL && configMenuDemos && !gInPlayerMenu) {
|
||||||
if ((++gDemoCountdown) == PRESS_START_DEMO_TIMER && (find_demo_number() && (demoNumber <= 6 || demoNumber > -1))) {
|
if ((++gDemoCountdown) == PRESS_START_DEMO_TIMER && (find_demo_number() && (sDemoNumber <= 6 || sDemoNumber > -1))) {
|
||||||
start_demo();
|
start_demo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((gCurrDemoInput != NULL) && (gPlayer1Controller->buttonPressed & END_DEMO || !isDemoActive || !gDjuiInMainMenu || gNetworkType != NT_NONE || gInPlayerMenu)) || (gCurrDemoInput == NULL && isDemoActive)) {
|
if (((gCurrDemoInput != NULL) && (gPlayer1Controller->buttonPressed & END_DEMO || !sIsDemoActive || !gDjuiInMainMenu || gNetworkType != NT_NONE || gInPlayerMenu)) || (gCurrDemoInput == NULL && sIsDemoActive)) {
|
||||||
gPlayer1Controller->buttonPressed &= ~END_DEMO;
|
gPlayer1Controller->buttonPressed &= ~END_DEMO;
|
||||||
stop_demo(NULL);
|
stop_demo(NULL);
|
||||||
}
|
}
|
||||||
|
@ -1436,7 +1436,7 @@ void update_menu_level(void) {
|
||||||
|
|
||||||
// warp to level, this feels buggy
|
// warp to level, this feels buggy
|
||||||
if (gCurrLevelNum != curLevel) {
|
if (gCurrLevelNum != curLevel) {
|
||||||
if (isDemoActive) {
|
if (sIsDemoActive) {
|
||||||
stop_demo(NULL);
|
stop_demo(NULL);
|
||||||
}
|
}
|
||||||
if (curLevel == LEVEL_JRB) {
|
if (curLevel == LEVEL_JRB) {
|
||||||
|
@ -1450,7 +1450,7 @@ void update_menu_level(void) {
|
||||||
}
|
}
|
||||||
gDemoCountdown = 0;
|
gDemoCountdown = 0;
|
||||||
}
|
}
|
||||||
if (isDemoActive) {
|
if (sIsDemoActive) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ u8 *sPoolEnd;
|
||||||
struct MainPoolBlock *sPoolListHeadL;
|
struct MainPoolBlock *sPoolListHeadL;
|
||||||
struct MainPoolBlock *sPoolListHeadR;
|
struct MainPoolBlock *sPoolListHeadR;
|
||||||
|
|
||||||
|
|
||||||
static struct MainPoolState *gMainPoolState = NULL;
|
static struct MainPoolState *gMainPoolState = NULL;
|
||||||
|
|
||||||
uintptr_t set_segment_base_addr(s32 segment, void *addr) {
|
uintptr_t set_segment_base_addr(s32 segment, void *addr) {
|
||||||
|
@ -79,7 +78,6 @@ void *virtual_to_segmented(UNUSED u32 segment, const void *addr) {
|
||||||
void move_segment_table_to_dmem(void) {
|
void move_segment_table_to_dmem(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the main memory pool. This pool is conceptually a pair of stacks
|
* Initialize the main memory pool. This pool is conceptually a pair of stacks
|
||||||
* that grow inward from the left and right. It therefore only supports
|
* that grow inward from the left and right. It therefore only supports
|
||||||
|
@ -219,47 +217,27 @@ u32 main_pool_pop_state(void) {
|
||||||
return sPoolFreeSpace;
|
return sPoolFreeSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static struct MarioAnimDmaRelatedThing* func_802789F0(u8* srcAddr) {
|
||||||
* Perform a DMA read from ROM. The transfer is split into 4KB blocks, and this
|
u32 count = 0;
|
||||||
* function blocks until completion.
|
memcpy(&count, srcAddr, sizeof(u32));
|
||||||
*/
|
u32 size = sizeof(u32) + (sizeof(u8 *) - sizeof(u32)) + sizeof(u8 *) + count * sizeof(struct OffsetSizePair);
|
||||||
static void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) {
|
|
||||||
memcpy(dest, srcStart, srcEnd - srcStart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
struct MarioAnimDmaRelatedThing *sp1C = malloc(size);
|
||||||
* Perform a DMA read from ROM, allocating space in the memory pool to write to.
|
memcpy(sp1C, srcAddr, size);
|
||||||
* Return the destination address.
|
|
||||||
*/
|
|
||||||
static void *dynamic_dma_read(u8 *srcStart, u8 *srcEnd, u32 side) {
|
|
||||||
void *dest;
|
|
||||||
u32 size = ALIGN16(srcEnd - srcStart);
|
|
||||||
|
|
||||||
dest = main_pool_alloc(size, side);
|
|
||||||
if (dest != NULL) {
|
|
||||||
dma_read(dest, srcStart, srcEnd);
|
|
||||||
}
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct MarioAnimDmaRelatedThing *func_802789F0(u8 *srcAddr) {
|
|
||||||
struct MarioAnimDmaRelatedThing *sp1C = dynamic_dma_read(srcAddr, srcAddr + sizeof(u32),
|
|
||||||
MEMORY_POOL_LEFT);
|
|
||||||
u32 size = sizeof(u32) + (sizeof(u8 *) - sizeof(u32)) + sizeof(u8 *) +
|
|
||||||
sp1C->count * sizeof(struct OffsetSizePair);
|
|
||||||
main_pool_free(sp1C);
|
|
||||||
|
|
||||||
sp1C = dynamic_dma_read(srcAddr, srcAddr + size, MEMORY_POOL_LEFT);
|
|
||||||
sp1C->srcAddr = srcAddr;
|
sp1C->srcAddr = srcAddr;
|
||||||
return sp1C;
|
return sp1C;
|
||||||
}
|
}
|
||||||
|
|
||||||
void func_80278A78(struct MarioAnimation *a, void *b, struct Animation *target) {
|
void alloc_anim_dma_table(struct MarioAnimation* marioAnim, void* srcAddr, struct Animation* targetAnim) {
|
||||||
if (b != NULL) {
|
if (srcAddr) {
|
||||||
a->animDmaTable = func_802789F0(b);
|
if (marioAnim->animDmaTable) {
|
||||||
|
free(marioAnim->animDmaTable);
|
||||||
|
marioAnim->animDmaTable = NULL;
|
||||||
}
|
}
|
||||||
a->currentAnimAddr = NULL;
|
marioAnim->animDmaTable = func_802789F0(srcAddr);
|
||||||
a->targetAnim = target;
|
}
|
||||||
|
marioAnim->currentAnimAddr = NULL;
|
||||||
|
marioAnim->targetAnim = targetAnim;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (Scrub C)
|
// TODO: (Scrub C)
|
||||||
|
@ -275,7 +253,7 @@ s32 load_patchable_table(struct MarioAnimation *a, u32 index) {
|
||||||
size = sp20->anim[index].size;
|
size = sp20->anim[index].size;
|
||||||
} while (0);
|
} while (0);
|
||||||
if (a->currentAnimAddr != addr) {
|
if (a->currentAnimAddr != addr) {
|
||||||
dma_read((u8 *) a->targetAnim, addr, addr + size);
|
memcpy(a->targetAnim, addr, size);
|
||||||
a->currentAnimAddr = addr;
|
a->currentAnimAddr = addr;
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ void growing_pool_free_pool(struct GrowingPool *pool);
|
||||||
void alloc_display_list_reset(void);
|
void alloc_display_list_reset(void);
|
||||||
void *alloc_display_list(u32 size);
|
void *alloc_display_list(u32 size);
|
||||||
|
|
||||||
void func_80278A78(struct MarioAnimation *a, void *b, struct Animation *target);
|
void alloc_anim_dma_table(struct MarioAnimation* marioAnim, void *b, struct Animation *targetAnim);
|
||||||
s32 load_patchable_table(struct MarioAnimation *a, u32 b);
|
s32 load_patchable_table(struct MarioAnimation *a, u32 b);
|
||||||
|
|
||||||
#endif // MEMORY_H
|
#endif // MEMORY_H
|
||||||
|
|
Loading…
Reference in a new issue