2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-07-09 01:54:39 +00:00
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
typedef enum {
|
|
|
|
/* 0 */ LETTERBOX_STATE_IDLE,
|
|
|
|
/* 1 */ LETTERBOX_STATE_GROWING,
|
|
|
|
/* 2 */ LETTERBOX_STATE_SHRINKING
|
|
|
|
} LetterboxState;
|
2020-07-09 01:54:39 +00:00
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
s32 sLetterboxState = LETTERBOX_STATE_IDLE;
|
2020-07-09 01:54:39 +00:00
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
s32 sLetterboxSizeTarget = 0;
|
|
|
|
s32 sLetterboxSize = 0;
|
|
|
|
|
|
|
|
void Letterbox_SetSizeTarget(s32 target) {
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_LETTERBOX && R_LETTERBOX_ENABLE_LOGS == 1) {
|
2022-08-15 13:39:06 +00:00
|
|
|
osSyncPrintf("shrink_window_setval(%d)\n", target);
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
2022-08-15 13:39:06 +00:00
|
|
|
|
|
|
|
sLetterboxSizeTarget = target;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
u32 Letterbox_GetSizeTarget(void) {
|
|
|
|
return sLetterboxSizeTarget;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
void Letterbox_SetSize(s32 size) {
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_LETTERBOX && R_LETTERBOX_ENABLE_LOGS == 1) {
|
2022-08-15 13:39:06 +00:00
|
|
|
osSyncPrintf("shrink_window_setnowval(%d)\n", size);
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
2022-08-15 13:39:06 +00:00
|
|
|
|
|
|
|
sLetterboxSize = size;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
u32 Letterbox_GetSize(void) {
|
|
|
|
return sLetterboxSize;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
void Letterbox_Init(void) {
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_LETTERBOX && R_LETTERBOX_ENABLE_LOGS == 1) {
|
2020-07-09 01:54:39 +00:00
|
|
|
osSyncPrintf("shrink_window_init()\n");
|
|
|
|
}
|
2022-08-15 13:39:06 +00:00
|
|
|
|
|
|
|
sLetterboxState = LETTERBOX_STATE_IDLE;
|
|
|
|
sLetterboxSizeTarget = 0;
|
|
|
|
sLetterboxSize = 0;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
void Letterbox_Destroy(void) {
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_LETTERBOX && R_LETTERBOX_ENABLE_LOGS == 1) {
|
2020-07-09 01:54:39 +00:00
|
|
|
osSyncPrintf("shrink_window_cleanup()\n");
|
|
|
|
}
|
2022-08-15 13:39:06 +00:00
|
|
|
|
|
|
|
sLetterboxSize = 0;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
void Letterbox_Update(s32 updateRate) {
|
|
|
|
s32 step;
|
2020-07-09 01:54:39 +00:00
|
|
|
|
|
|
|
if (updateRate == 3) {
|
2022-08-15 13:39:06 +00:00
|
|
|
step = 10;
|
2020-07-09 01:54:39 +00:00
|
|
|
} else {
|
2022-08-15 13:39:06 +00:00
|
|
|
step = 30 / updateRate;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
if (sLetterboxSize < sLetterboxSizeTarget) {
|
|
|
|
if (sLetterboxState != LETTERBOX_STATE_GROWING) {
|
|
|
|
sLetterboxState = LETTERBOX_STATE_GROWING;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
if (sLetterboxSize + step < sLetterboxSizeTarget) {
|
|
|
|
sLetterboxSize += step;
|
2020-07-09 01:54:39 +00:00
|
|
|
} else {
|
2022-08-15 13:39:06 +00:00
|
|
|
sLetterboxSize = sLetterboxSizeTarget;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
2022-08-15 13:39:06 +00:00
|
|
|
} else if (sLetterboxSizeTarget < sLetterboxSize) {
|
|
|
|
if (sLetterboxState != LETTERBOX_STATE_SHRINKING) {
|
|
|
|
sLetterboxState = LETTERBOX_STATE_SHRINKING;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-08-15 13:39:06 +00:00
|
|
|
if (sLetterboxSizeTarget < sLetterboxSize - step) {
|
|
|
|
sLetterboxSize -= step;
|
2020-07-09 01:54:39 +00:00
|
|
|
} else {
|
2022-08-15 13:39:06 +00:00
|
|
|
sLetterboxSize = sLetterboxSizeTarget;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-15 13:39:06 +00:00
|
|
|
sLetterboxState = LETTERBOX_STATE_IDLE;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
if (R_HREG_MODE == HREG_MODE_LETTERBOX) {
|
|
|
|
if (R_LETTERBOX_INIT != HREG_MODE_LETTERBOX) {
|
|
|
|
R_LETTERBOX_INIT = HREG_MODE_LETTERBOX;
|
|
|
|
R_LETTERBOX_ENABLE_LOGS = 0;
|
|
|
|
HREG(82) = 0; // this reg is not used in this mode
|
|
|
|
R_LETTERBOX_STATE = 0;
|
|
|
|
R_LETTERBOX_SIZE = 0;
|
|
|
|
R_LETTERBOX_TARGET_SIZE = 0;
|
|
|
|
R_LETTERBOX_STEP = 0;
|
|
|
|
|
|
|
|
// these regs are not used in this mode
|
2020-07-09 01:54:39 +00:00
|
|
|
HREG(87) = 0;
|
|
|
|
HREG(88) = 0;
|
|
|
|
HREG(89) = 0;
|
|
|
|
}
|
2022-08-15 13:39:06 +00:00
|
|
|
|
2022-11-26 20:22:01 +00:00
|
|
|
R_LETTERBOX_STATE = sLetterboxState;
|
|
|
|
R_LETTERBOX_SIZE = sLetterboxSize;
|
|
|
|
R_LETTERBOX_TARGET_SIZE = sLetterboxSizeTarget;
|
|
|
|
R_LETTERBOX_STEP = step;
|
2020-07-09 01:54:39 +00:00
|
|
|
}
|
|
|
|
}
|