Add count factor and adjust some timings accordingly

This commit is contained in:
Arceveti
2024-05-06 16:59:16 -07:00
parent f59c34315d
commit ca31ea4195
7 changed files with 33 additions and 7 deletions

View File

@@ -74,7 +74,9 @@ const ControlType gCSControlDescriptions[] = {
// Updates gCSDirectionFlags with directional inputs. Analog stick, D-pad, or C-buttons.
void cs_update_direction_input(void) {
OSTime currTime = osGetTime();
//! TODO: Is the count factor thing correct?
u32 divFactor = ((gCountFactor == 1) ? 2 : 1);
OSTime currTime = osGetTime() / divFactor;
gCSDirectionFlags.pressed.up = FALSE;
gCSDirectionFlags.pressed.down = FALSE;
@@ -93,7 +95,7 @@ void cs_update_direction_input(void) {
_Bool right = ((buttonDown & (R_CBUTTONS | R_JPAD)) || (rawStickX > deadzone));
// How long to wait when holding a direction before it becomes continuous.
const OSTime cursorWaitCycles = FRAMES_TO_CYCLES(cs_get_setting_val(CS_OPT_GROUP_CONTROLS, CS_OPT_CONTROLS_CURSOR_WAIT_FRAMES));
const OSTime cursorWaitCycles = FRAMES_TO_CYCLES(cs_get_setting_val(CS_OPT_GROUP_CONTROLS, CS_OPT_CONTROLS_CURSOR_WAIT_FRAMES)) / divFactor;
if (up ^ down) {
if (

View File

@@ -41,6 +41,8 @@ Address gLastCSSelectedAddress = 0x00000000; // Used for debugging crash screen
Word gWatchLo = 0x00000000; // Save $WatchLo on crash.
u32 gCountFactor = 0; // Count factor.
/**
* @brief Reinitialize the crash screen's global variables, settings, buffers, etc.
@@ -115,14 +117,28 @@ void cs_play_sound(struct CSThreadInfo* threadInfo, s32 sound) {
* @brief Get $WatchLo on CP0 and set it to 0 so that it doesn't affect the crash screen.
*/
ALWAYS_INLINE static Word get_and_reset_watchlo(void) {
const u32 saved = __osDisableInt();
Word watchLo = 0;
asm volatile("mfc0 %0,$"EXPAND_AND_STRINGIFY(C0_WATCHLO):"=r"(watchLo));
asm volatile("mtc0 $0,$"EXPAND_AND_STRINGIFY(C0_WATCHLO)); //! TODO: Do this on game boot too? Libdragon does.
__osRestoreInt(saved);
return watchLo;
}
/**
* @brief Get the count factor.
* TODO: TODO: Is this correct? This returns 0 on console and ares, and on ParaLLEl 2 without overclock CPU, and 1 with overclock CPU.
*
* @return u32 the count ractor.
*/
u32 pj64_get_count_factor_asm(void); // defined in asm/pj64_get_count_factor_asm.s
static inline u32 check_count_factor() {
const u32 saved = __osDisableInt();
const u32 cf = pj64_get_count_factor_asm();
__osRestoreInt(saved);
return cf;
}
/**
* @brief Runs once on every crash.
*
@@ -153,6 +169,8 @@ static void on_crash(struct CSThreadInfo* threadInfo) {
// Only on the first crash:
if (sFirstCrash) {
gCountFactor = check_count_factor();
sFirstCrash = FALSE;
// Set the crashed game thread pointer.

View File

@@ -49,7 +49,9 @@ extern OSThread* gInspectThread;
extern Address gSelectedAddress;
extern Address gLastCSSelectedAddress;
extern Address gWatchLo;
extern Word gWatchLo;
extern u32 gCountFactor;
void create_crash_screen_thread(void);

View File

@@ -403,7 +403,8 @@ size_t cs_print_impl(ScreenCoord_u32 x, ScreenCoord_u32 y, size_t charLimit, con
extraChar = 1;
charLimit += extraChar;
// Floats are used here to prevent overflow from directly multiplying gCSFrameCounter.
u32 scrollSpeed = ((f32)gCSFrameCounter * ((f32)scrollSpeedSetting / (f32)CRASH_SCREEN_LETTER_WIDTH));
//! TODO: Is the count factor thing correct?
u32 scrollSpeed = ((f32)(gCSFrameCounter / ((gCountFactor == 1) ? 2 : 1)) * ((f32)scrollSpeedSetting / (f32)CRASH_SCREEN_LETTER_WIDTH));
cs_scroll_buffer(phase1FormattedSize, charLimit, scrollSpeed);
tx -= (scrollSpeed % CRASH_SCREEN_LETTER_WIDTH);
}

View File

@@ -235,6 +235,7 @@ void _cs_about_func_emulator(char* buf) {
p += sprintf(p, " "STR_LPL_VERSION, v->major, v->minor, v->patch);
}
}
ABOUT_ENTRY_FUNC(count_factor, "%d", gCountFactor)
#ifdef LIBPL
ABOUT_ENTRY_FUNC(gfx_plugin, libpl_get_graphics_plugin()->name);
void _cs_about_func_launcher(char* buf) {
@@ -346,6 +347,7 @@ CSAboutEntry sCSAboutEntries_misc[CS_NUM_ABOUT_ENTRIES_MISC] = {
CSAboutEntry sCSAboutEntries_emulator[CS_NUM_ABOUT_ENTRIES_EMULATOR] = {
[CS_ABOUT_GROUP_HEADER_EMULATOR ] = ABOUT_ENTRY_HEADER("emulator", TRUE),
[CS_ABOUT_ENTRY_EMULATOR_EMULATOR ] = ABOUT_ENTRY_SINGLE(emulator, "EMULATOR" ),
[CS_ABOUT_ENTRY_EMULATOR_COUNT_FACTOR ] = ABOUT_ENTRY_SINGLE(count_factor, "COUNT FACTOR" ),
#ifdef LIBPL
[CS_ABOUT_ENTRY_EMULATOR_GFX_PLUGIN ] = ABOUT_ENTRY_SINGLE_LPL(gfx_plugin, "GFX PLUGIN" ),
[CS_ABOUT_ENTRY_EMULATOR_LAUNCHER ] = ABOUT_ENTRY_SINGLE_LPL(launcher, "LAUNCHER" ),

View File

@@ -102,6 +102,7 @@ enum CSAboutEntries_Misc {
enum CSAboutEntries_Emulator {
CS_ABOUT_GROUP_HEADER_EMULATOR,
CS_ABOUT_ENTRY_EMULATOR_EMULATOR,
CS_ABOUT_ENTRY_EMULATOR_COUNT_FACTOR,
#ifdef LIBPL
CS_ABOUT_ENTRY_EMULATOR_GFX_PLUGIN,
CS_ABOUT_ENTRY_EMULATOR_LAUNCHER,

View File

@@ -232,7 +232,7 @@ CSTextCoord_u32 cs_registers_draw_register_list(CSTextCoord_u32 line, enum Regis
if (drawSel && (fullRow || (col == cursor->selX)) && (row == cursor->selY)) {
cs_draw_row_selection_box_impl(TEXT_X(charX), TEXT_Y(charY),
(TEXT_WIDTH(columnCharWidth - 1)), TEXT_HEIGHT(1),
(TEXT_WIDTH(columnCharWidth - !fullRow)), TEXT_HEIGHT(1),
COLOR_RGBA32_CRASH_SELECT_HIGHLIGHT
);
}