Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frame advance (for real this time) #83

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions genhooks
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ genhook()
}

genhook "$sym_update_hook" "jal $sym_fpUpdateEntry;"
genhook "$sym_background_hook" "jal $sym_fpBackgroundEntry;"
genhook "$sym_draw_frame_hook" "jal $sym_fpFrameEntry;"
genhook "$sym_draw_hook" "jal $sym_fpDrawEntry;"
genhook "$sym_after_draw_hook" "jal $sym_fpAfterDrawEntry;"
genhook "$sym_update_camera_mode_6_hook" "jal $sym_fpUpdateCameraMode6;"
Expand Down
10 changes: 10 additions & 0 deletions lib/libpm-jp.a
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ pm_gItemTable = 0x800878B0;
pm_gItemHudScripts = 0x8008A650;
pm_gAreas = 0x800934C0;
pm_viFrames = 0x80093B64;
pm_D_8009A5B8 = 0x8009A598;
pm_timeFreezeMode = 0x8009A5B8;
pm_gameState = 0x8009A5E0;
nuGfxCfb_ptr = 0x8009A62C;
pm_masterGfxPos = 0x8009A64C;
pm_gDisplayContext = 0x8009A654;
pm_logicalSaveInfo = 0x8009BA10;
pm_gameMode = 0x8009E700;
pm_gMapTransitionAlpha = 0x8009E750;
Expand All @@ -27,6 +29,7 @@ pm_gPartnerActionStatus = 0x8010ED70;
pm_gUiStatus = 0x8010F118;
pm_gPlayerStatus = 0x8010F188;
pm_gHudElementSizes = 0x8015406C;
pm_screen_overlay_frontZoom = 0x8015B884;
pm_musicCurrentVolume = 0x8015EA66;
pm_gActionCommandStatus = 0x8029FED0;
pm_gNumScripts = 0x802DA488;
Expand All @@ -44,11 +47,13 @@ pm_update_cameras = 0x8002D090;
pm_update_camera_zone_interp = 0x80031124;
pm_setCurtainDrawCallback = 0x8002BEC4;
pm_setCurtainFadeGoal = 0x8002BED4;
nuGfxTaskStart = 0x8002CF24;
pm_setGameMode = 0x80033180;
pm_get_npc_safe = 0x8003A808;
pm_func_800554A4 = 0x80055154;
pm_removeEffect = 0x8005A100;
nuPiReadRom = 0x8005F140;
nuContDataGet = 0x8005F300;
__osPiGetAccess = 0x80061474;
__osPiRelAccess = 0x800614E0;
osWritebackDCacheAll = 0x800618A0;
Expand Down Expand Up @@ -84,6 +89,11 @@ pm_saveGame = 0x802DC150;
update_hook = 0x80026100;
pm_step_game_loop = 0x80026710;

background_hook = 0x80026124;
draw_frame_hook = 0x8002612C;
pm_gfx_task_background = 0x800269C0;
pm_gfx_draw_frame = 0x80026AD4;

draw_hook = 0x80026C88;
pm_state_render_frontUI = 0x801181D4;

Expand Down
10 changes: 10 additions & 0 deletions lib/libpm-us.a
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ pm_gItemTable = 0x800878E0;
pm_gItemHudScripts = 0x8008A680;
pm_gAreas = 0x800934F0;
pm_viFrames = 0x80093B94;
pm_D_8009A5B8 = 0x8009A5B8;
pm_timeFreezeMode = 0x8009A5D8;
pm_gameState = 0x8009A600;
nuGfxCfb_ptr = 0x8009A64C;
pm_masterGfxPos = 0x8009A66C;
pm_gDisplayContext = 0x8009A674;
pm_logicalSaveInfo = 0x8009BA30;
pm_gameMode = 0x800A08F0;
pm_gMapTransitionAlpha = 0x800A0940;
Expand All @@ -27,6 +29,7 @@ pm_gPartnerActionStatus = 0x8010EBB0;
pm_gUiStatus = 0x8010EF58;
pm_gPlayerStatus = 0x8010EFC8;
pm_gHudElementSizes = 0x8014EFCC;
pm_screen_overlay_frontZoom = 0x80156904;
pm_musicCurrentVolume = 0x80159AE6;
pm_gActionCommandStatus = 0x8029FBE0;
pm_gNumScripts = 0x802DA488;
Expand All @@ -42,13 +45,15 @@ pm_fioWriteFlash = 0x8002B948;
pm_setCurtainScaleGoal = 0x8002BEDC;
pm_setCurtainDrawCallback = 0x8002BF04;
pm_setCurtainFadeGoal = 0x8002BF14;
nuGfxTaskStart = 0x8002CCC4;
pm_update_cameras = 0x8002D400;
pm_update_camera_zone_interp = 0x80031494;
pm_setGameMode = 0x800334F0;
pm_get_npc_safe = 0x8003AB48;
pm_func_800554A4 = 0x800554A4;
pm_removeEffect = 0x8005A450;
nuPiReadRom = 0x8005F490;
nuContDataGet = 0x8005F650;
__osPiGetAccess = 0x800614A4;
__osPiRelAccess = 0x80061510;
osWritebackDCacheAll = 0x800618D0;
Expand Down Expand Up @@ -84,6 +89,11 @@ pm_saveGame = 0x802E11A0;
update_hook = 0x8002611C;
pm_step_game_loop = 0x80026740;

background_hook = 0x80026140;
draw_frame_hook = 0x80026148;
pm_gfx_task_background = 0x800269EC;
pm_gfx_draw_frame = 0x80026B08;

draw_hook = 0x80026CBC;
pm_state_render_frontUI = 0x80112FC4;

Expand Down
22 changes: 22 additions & 0 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct Command fpCommands[COMMAND_MAX] = {
{"break free", COMMAND_PRESS_ONCE, 0, commandBreakFreeProc },
{"toggle in. disp.", COMMAND_PRESS_ONCE, 0, commandToggleInpDispProc },
{"clippy", COMMAND_PRESS_ONCE, 0, commandClippyProc },
{"pause", COMMAND_PRESS_ONCE, 0, commandPauseProc },
{"advance", COMMAND_PRESS_ONCE, 0, commandAdvanceProc },
};

void showMenu(void) {
Expand Down Expand Up @@ -108,6 +110,8 @@ bool fpWarp(enum Areas area, u16 map, u16 entrance) {
pm_setCurtainFadeGoal(0.0f);

fp.warp = TRUE;
// disable frame advance when warping
fp.pendingFrames = -1;

return TRUE;
}
Expand Down Expand Up @@ -285,3 +289,21 @@ void commandClippyProc(void) {
fpLog("clippy enabled");
}
}

void commandPauseProc() {
if (fp.pendingFrames == 0) {
fp.pendingFrames = -1;
fpLog("unpaused");
} else {
fp.pendingFrames = 0;
fpLog("paused");
}
}

void commandAdvanceProc(void) {
if (fp.pendingFrames == 0) {
fp.pendingFrames++;
} else {
commandPauseProc();
}
}
4 changes: 4 additions & 0 deletions src/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum Commands {
COMMAND_BREAK_FREE,
COMMAND_TOGGLE_INPUT_DISPLAY,
COMMAND_CLIPPY,
COMMAND_PAUSE,
COMMAND_ADVANCE,
COMMAND_MAX
};

Expand Down Expand Up @@ -57,6 +59,8 @@ void commandShowHideTimerProc(void);
void commandBreakFreeProc(void);
void commandToggleInpDispProc(void);
void commandClippyProc(void);
void commandPauseProc(void);
void commandAdvanceProc(void);

extern struct Command fpCommands[COMMAND_MAX];

Expand Down
38 changes: 35 additions & 3 deletions src/fp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <stdlib.h>
#include <string.h>

FpCtxt fp = {.savedArea = 0x1c, .camDistMin = 100, .camDistMax = 1000};
FpCtxt fp = {.savedArea = 0x1c, .camDistMin = 100, .camDistMax = 1000, .pendingFrames = -1};

// Initializes and uses new stack instead of using games main thread stack.
static void initStack(void (*func)(void)) {
Expand Down Expand Up @@ -525,7 +525,7 @@ void fpDraw(void) {

menuDraw(fp.global);
fpDrawLog(font, cellWidth, cellHeight, menuAlpha);
gfxFlush();
gfxFlush(fp.prevPendingFrames);
}

/* ========================== HOOK ENTRY POINTS ========================== */
Expand All @@ -538,10 +538,42 @@ ENTRY void fpUpdateEntry(void) {
PRINTF("\n**** fp initialized ****\n\n");
}

pm_step_game_loop();
fp.prevPendingFrames = fp.pendingFrames;
if (fp.pendingFrames) {
pm_step_game_loop();
if (fp.pendingFrames > 0) {
fp.pendingFrames--;
}
}
initStack(fpUpdate);
}

ENTRY void fpBackgroundEntry(void) {
init_gp();
if (fp.prevPendingFrames) {
pm_gfx_task_background();
fp.savedBackgroundGfx = pm_masterGfxPos;
} else {
if (pm_screen_overlay_frontZoom != 255.f) {
nuGfxTaskStart(&pm_gDisplayContext->backgroundGfx[0],
(u32)(fp.savedBackgroundGfx - pm_gDisplayContext->backgroundGfx) * 8, 0, 0);
}
}
}

ENTRY void fpFrameEntry(void) {
init_gp();
if (fp.prevPendingFrames) {
pm_gfx_draw_frame();
} else {
initStack(fpDraw);
if (pm_screen_overlay_frontZoom != 255.f) {
nuGfxTaskStart(pm_gDisplayContext->mainGfx, (u32)(pm_masterGfxPos - pm_gDisplayContext->mainGfx) * 8, 0,
0x40000);
}
}
}

ENTRY void fpDrawEntry(void) {
init_gp();
pm_state_render_frontUI();
Expand Down
3 changes: 3 additions & 0 deletions src/fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ typedef struct {
pm_Camera savedCam;
s8 freeCamMoveSpeed;
s8 freeCamPanSpeed;
s32 pendingFrames;
s32 prevPendingFrames;
Gfx *savedBackgroundGfx;
} FpCtxt;

extern FpCtxt fp;
Expand Down
27 changes: 27 additions & 0 deletions src/pm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,26 @@ typedef struct Action {
/* 0x0C */ s8 flag;
} pm_Action; // size = 0x10

typedef struct {
/* 0x00 */ u16 button;
/* 0x02 */ s8 stick_x;
/* 0x03 */ s8 stick_y;
/* 0z04 */ u8 errno;
} OSContPad; // size = 0x06

typedef struct {
/* 0x00000 */ LookAt lookAt;
/* 0x00020 */ Hilite hilite;
/* 0x00030 */ Mtx camPerspMatrix[8]; // could only be length 4, unsure
#if PM64_VERSION == US
/* 0x00230 */ Gfx mainGfx[0x2080];
#else
/* 0x00230 */ Gfx mainGfx[0x2000];
#endif
/* 0x10630 */ Gfx backgroundGfx[0x200]; // used by gfx_task_background
/* 0x11630 */ Mtx matrixStack[0x200];
} DisplayContext; // size = 0x19630

typedef void *(*PrintCallback)(void *, const char *, u32);
typedef pm_Evt *pm_ScriptList[128];

Expand All @@ -1214,10 +1234,12 @@ extern_data pm_ItemData pm_gItemTable[0x16C];
extern_data pm_IconHudScriptPair pm_gItemHudScripts[337];
extern_data pm_Area pm_gAreas[29];
extern_data u32 pm_viFrames;
extern_data OSContPad pm_D_8009A5B8;
extern_data s32 pm_timeFreezeMode;
extern_data s32 pm_gameState;
extern_data u16 *nuGfxCfb_ptr;
extern_data Gfx *pm_masterGfxPos;
extern_data DisplayContext *pm_gDisplayContext;
extern_data s32 pm_logicalSaveInfo[4][2];
extern_data s16 pm_gameMode;
extern_data s16 pm_gMapTransitionAlpha;
Expand All @@ -1235,6 +1257,7 @@ extern_data pm_PartnerActionStatus pm_gPartnerActionStatus;
extern_data pm_UiStatus pm_gUiStatus;
extern_data pm_PlayerStatus pm_gPlayerStatus;
extern_data pm_HudElementSize pm_gHudElementSizes[26];
extern_data f32 pm_screen_overlay_frontZoom;
extern_data s16 pm_musicCurrentVolume;
extern_data pm_ActionCommandStatus pm_gActionCommandStatus;
extern_data s32 pm_gNumScripts;
Expand All @@ -1251,13 +1274,15 @@ void pm_fioWriteFlash(s32 slot, void *buffer, u32 size);
void pm_setCurtainScaleGoal(f32 goal);
void pm_setCurtainDrawCallback(void *callback);
void pm_setCurtainFadeGoal(f32 goal);
void nuGfxTaskStart(Gfx *gfxList_ptr, u32 gfxListSize, u32 ucode, u32 flag);
void pm_update_cameras(void);
void pm_update_camera_zone_interp(pm_Camera *camera);
void pm_setGameMode(s32 mode);
pm_Npc *pm_get_npc_safe(s32 npcID);
s32 pm_func_800554A4(s32);
void pm_removeEffect(pm_EffectInstance *effect);
void nuPiReadRom(u32 rom_addr, void *buf_ptr, u32 size);
void nuContDataGet(OSContPad *contdata, u32 padno);
void osWritebackDCacheAll(void);
s32 _Printf(PrintCallback pfn, void *arg, const char *fmt, va_list ap);
u64 osGetTime(void);
Expand All @@ -1281,6 +1306,8 @@ pm_ApiStatus pm_useIdleAnimation(pm_Evt *script, s32 isInitialCall);
pm_ApiStatus pm_gotoMap(pm_Evt *script, s32 isInitialCall);
void pm_saveGame(void);

void pm_gfx_task_background(void);
void pm_gfx_draw_frame(void);
void pm_state_render_frontUI(void);
void pm_step_game_loop(void);
void pm_update_camera_mode_6(pm_Camera *camera);
Expand Down
10 changes: 8 additions & 2 deletions src/sys/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static Gfx *gfxDisp;
static Gfx *gfxDispW;
static Gfx *gfxDispP;
static Gfx *gfxDispD;
static u32 *fpDispPos;

#define GFX_STACK_LENGTH 8
static u64 gfxModes[GFX_MODE_ALL];
Expand Down Expand Up @@ -167,10 +168,15 @@ void *gfxDataAppend(void *data, size_t size) {
return gfxDispD;
}

void gfxFlush(void) {
void gfxFlush(s32 pendingFrames) {
flushChars();
gSPEndDisplayList(gfxDispP++);
gSPDisplayList(pm_masterGfxPos++, gfxDisp);
if (pendingFrames) {
fpDispPos = ((u32 *)pm_masterGfxPos + 1);
gSPDisplayList(pm_masterGfxPos++, gfxDisp);
} else {
*fpDispPos = (u32)gfxDisp;
}
Gfx *disp_w = gfxDispW;
gfxDispW = gfxDisp;
gfxDisp = disp_w;
Expand Down
2 changes: 1 addition & 1 deletion src/sys/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void gfxModeReplace(enum GfxMode mode, u64 value);
/* all sizes are specified in number of bytes */
Gfx *gfxDispAppend(Gfx *disp, size_t size);
void *gfxDataAppend(void *data, size_t size);
void gfxFlush(void);
void gfxFlush(s32 pendingFrames);

void gfxTexldrInit(struct GfxTexldr *texldr);
struct GfxTexture *gfxTexldrLoad(struct GfxTexldr *texldr, const struct GfxTexdesc *texdesc,
Expand Down
34 changes: 31 additions & 3 deletions src/sys/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,37 @@ const u32 inputButtonColor[] = {
};

void inputUpdate(void) {
joyX = pm_gGameStatus.stickX[0];
joyY = pm_gGameStatus.stickY[0];
u16 pmPad = pm_gGameStatus.currentButtons[0].buttons;
OSContPad *cont = &pm_D_8009A5B8;
nuContDataGet(cont, 0);

joyX = cont->stick_x;
joyY = cont->stick_y;
if (joyX > 0) {
joyX -= 4;
if (joyX < 0) {
joyX = 0;
}
}
if (joyX < 0) {
joyX += 4;
if (joyX > 0) {
joyX = 0;
}
}
if (joyY > 0) {
joyY -= 4;
if (joyY < 0) {
joyY = 0;
}
}
if (joyY < 0) {
joyY += 4;
if (joyY > 0) {
joyY = 0;
}
}

u16 pmPad = cont->button;
padPressedRaw = (pad ^ pmPad) & pmPad;
padReleased = (pad ^ pmPad) & ~pmPad;
pad = pmPad;
Expand Down
Loading
Loading