diff --git a/Makefile b/Makefile index 1e9d9466..3256d4ba 100755 --- a/Makefile +++ b/Makefile @@ -9,8 +9,6 @@ $(eval $(call validate-option,NON_MATCHING,ido gcc)) # Define a custom boot file if desired to use something other than the vanilla one BOOT_CUSTOM ?= mods/boot_custom.bin -BOOT_CIC ?= 6103 -$(eval $(call validate-option,BOOT_CIC,6102 6103)) LIBULTRA_VERSION_DEFINE := -DBUILD_VERSION=4 -DBUILD_VERSION_STRING=\"2.0G\" @@ -138,7 +136,6 @@ else MATCHDEFS += ANTI_TAMPER=1 # Override compiler choice on matching builds. COMPILER := ido - BOOT_CIC := 6103 C_STANDARD := -std=gnu90 endif @@ -148,10 +145,20 @@ ASM_DEFINES = $(foreach d,$(DEFINES),$(if $(findstring =,$(d)),--defsym $(d),)) # If NON_MATCHING and using a custom boot file, (Right now just 6102). # Define this so it will change the entrypoint in the header +BOOT_CIC := ifeq ($(NON_MATCHING),1) ifeq ("$(wildcard $(BOOT_CUSTOM))","") -BOOT_CIC := 6103 + BOOT_CIC := 6103 +else +# Determine the CIC type automatically by checking the boot bin. + BOOT_CIC := $(shell $(PYTHON) $(TOOLS_DIR)/python/extract_custom_boot.py) +# The above returns 0 if it errors out, so course correct if it somehow happens. + ifeq ($(BOOT_CIC),0) + BOOT_CIC := 6103 + endif endif +else + BOOT_CIC := 6103 endif ASM_DEFINES += --defsym BOOT_$(BOOT_CIC)=1 diff --git a/include/save_layout.h b/include/save_layout.h new file mode 100644 index 00000000..0faa12e1 --- /dev/null +++ b/include/save_layout.h @@ -0,0 +1,233 @@ +#ifndef _SAVE_LAYOUT_H_ +#define _SAVE_LAYOUT_H_ + +#include "types.h" +#include "structs.h" +#include "macros.h" +#include "save_layout.h" +#include "src/save_data.h" +#include "PR/os_cont.h" + +/** + * File contains the struct and macro definitions for the save layout for DKR. +*/ + +#define TT_COURSES \ + unsigned courseAL : 1; \ + unsigned courseFC : 1; \ + unsigned courseJF : 1; \ + unsigned courseHTV : 1; \ + \ + unsigned courseWB : 1; \ + unsigned courseCI : 1; \ + unsigned coursePL : 1; \ + unsigned courseTC : 1; \ + \ + unsigned courseEP : 1; \ + unsigned courseWC : 1; \ + unsigned courseSV : 1; \ + unsigned courseFV : 1; \ + \ + unsigned courseBC : 1; \ + unsigned courseGV : 1; \ + unsigned courseWP : 1; \ + unsigned courseHW : 1; \ + \ + unsigned courseSA : 1; \ + unsigned courseDMC : 1; \ + unsigned courseSC : 1; \ + unsigned courseSPA : 1; + +#define SAVE_COURSES \ + unsigned courseBluey1 : 2; \ + unsigned courseFossilCanyon : 2; \ + unsigned coursePirateLagoon : 2; \ + unsigned courseAncientLake : 2; \ + unsigned courseWalrusCove : 2; \ + unsigned courseHotTopVolcano : 2; \ + unsigned courseWhaleBay : 2; \ + unsigned courseSnowballValley : 2; \ + unsigned courseCrescentIsland : 2; \ + unsigned courseFireMountain : 2; \ + unsigned courseEverfrostPeak : 2; \ + unsigned courseSpaceportAlpha : 2; \ + unsigned courseSpacedustAlley : 2; \ + unsigned courseGreenwoodVillage : 2; \ + unsigned courseBoulderCanyon : 2; \ + unsigned courseWindmillPlains : 2; \ + unsigned courseSmokeyCastle : 2; \ + unsigned courseDarkwaterBeach : 2; \ + unsigned courseIciclePyramid : 2; \ + unsigned courseFrostyVillage : 2; \ + unsigned courseJungleFalls : 2; \ + unsigned courseTreasureCaves : 2; \ + unsigned courseHauntedWoods : 2; \ + unsigned courseDarkmoonCaverns : 2; \ + unsigned courseStarCity : 2; \ + unsigned courseWizpig1 : 2; \ + unsigned courseTricky1 : 2; \ + unsigned courseBubbler1 : 2; \ + unsigned courseSmokey1 : 2; \ + unsigned courseTricky2 : 2; \ + unsigned courseBluey2 : 2; \ + unsigned courseBubbler2 : 2; \ + unsigned courseSmokey2 : 2; \ + unsigned courseWizpig2 : 2; + +enum CourseRecordNames { + COURSE_FC_CAR, + COURSE_FC_HOVER, + COURSE_FC_PLANE, + COURSE_PL_HOVER, + COURSE_AL_CAR, + COURSE_AL_HOVER, + COURSE_AL_PLANE, + COURSE_WC_CAR, + COURSE_WC_HOVER, + COURSE_HTV_HOVER, + COURSE_HTV_PLANE, + COURSE_WB_HOVER, + COURSE_SV_CAR, + COURSE_SV_HOVER, + COURSE_CI_CAR, + COURSE_CI_HOVER, + COURSE_EP_CAR, + COURSE_EP_HOVER, + COURSE_EP_PLANE, + COURSE_SPA_CAR, + COURSE_SPA_HOVER, + COURSE_SPA_PLANE, + COURSE_SA_CAR, + COURSE_SA_HOVER, + COURSE_SA_PLANE, + COURSE_GV_CAR, + COURSE_GV_HOVER, + COURSE_BC_HOVER, + COURSE_WP_CAR, + COURSE_WP_HOVER, + COURSE_WP_PLANE, + COURSE_FV_CAR, + COURSE_FV_HOVER, + COURSE_FV_PLANE, + COURSE_JF_CAR, + COURSE_JF_HOVER, + COURSE_JF_PLANE, + COURSE_TC_CAR, + COURSE_TC_HOVER, + COURSE_TC_PLANE, + COURSE_HW_CAR, + COURSE_HW_HOVER, + COURSE_DMC_CAR, + COURSE_DMC_HOVER, + COURSE_SC_CAR, + COURSE_SC_HOVER, + COURSE_SC_PLANE, + + COURSE_RECORD_TOTAL +}; + +typedef struct SaveConfig { + unsigned unlockedAdv2 : 1; + unsigned unlockedDrumstick : 1; + unsigned language : 2; + TT_COURSES + unsigned subtitles : 1; + unsigned unk0 : 31; + // unsigned checksum : 8; // For some reason, the struct becomes 12 bytes if this is there. +} SaveConfig ALIGNED8; + +typedef struct SaveFile { + unsigned checksum : 16; + SAVE_COURSES + unsigned tajFlags : 6; + + unsigned trophy1 : 2; + unsigned trophy2 : 2; + unsigned trophy3 : 2; + unsigned trophy4 : 2; + unsigned trophy5 : 2; + + unsigned bossWizpig1 : 1; + unsigned bossTricky1 : 1; + unsigned bossBubbler1 : 1; + unsigned bossBluey1 : 1; + unsigned bossSmokey1 : 1; + unsigned bossWizpig2 : 1; + unsigned bossTricky2 : 1; + unsigned bossBubbler2 : 1; + unsigned bossBluey2 : 1; + unsigned bossSmokey2 : 1; + unsigned bossUnused1 : 1; + unsigned bossUnused2 : 1; + + unsigned balloonsTotal : 7; + unsigned balloonsWorld1 : 7; // Dino Domain + unsigned balloonsWorld2 : 7; // Sherbet Island + unsigned balloonsWorld3 : 7; // Snowflake Mountain + unsigned balloonsWorld4 : 7; // Dragon Forest + unsigned balloonsWorld5 : 7; // Future Fun Land + + unsigned amuletTT : 3; + unsigned amuletWizpig : 3; + + unsigned flagsWorld0 : 16; // Hub, balloons + unsigned flagsWorld1 : 16; // Dino Domain + unsigned flagsWorld2 : 16; // Sherbet Island + unsigned flagsWorld3 : 16; // Snowflake Mountain + unsigned flagsWorld4 : 16; // Dragon Forest + unsigned flagsWorld5 : 16; // Future Fun Land + + unsigned keyWorld0 : 1; // Hub world, unused + unsigned keyWorld1 : 1; // Dino Domain + unsigned keyWorld2 : 1; // Snowflake Mountain + unsigned keyWorld3 : 1; // Sherbet Island + unsigned keyWorld4 : 1; // Dragon Forest + unsigned keyWorld5 : 1; // Future Fun Land, unused + unsigned keyWorld6 : 1; // Unused + unsigned keyWorld7 : 1; // Unused + + unsigned sceneLighthouse : 1; + unsigned sceneTTHelp : 1; + unsigned sceneAdv2 : 1; + unsigned sceneWorld1Boss1 : 1; + unsigned sceneWorld2Boss1 : 1; + unsigned sceneWorld3Boss1 : 1; + unsigned sceneWorld4Boss1 : 1; + unsigned sceneWorld5Boss1 : 1; + unsigned sceneWorld1Boss2 : 1; + unsigned sceneWorld2Boss2 : 1; + unsigned sceneWorld3Boss2 : 1; + unsigned sceneWorld4Boss2 : 1; + unsigned sceneWorld5Boss2 : 1; + unsigned sceneWizpigFace : 1; + unsigned sceneWorld1Key : 1; + unsigned sceneWorld2Key : 1; + unsigned sceneWorld3Key : 1; + unsigned sceneWorld4Key : 1; + unsigned sceneWorld5Key : 1; // Unused + + unsigned name : 15; +} SaveFile ALIGNED8; + +typedef struct CourseRecords { + u16 checksum; + u16 padding; + u32 courseTime[COURSE_RECORD_TOTAL]; +} CourseRecords ALIGNED8; + +typedef struct SaveBuffer { + SaveFile gameSave[NUMBER_OF_SAVE_FILES]; + SaveConfig config; + CourseRecords fastLaps; + CourseRecords courseTimes; +} SaveBuffer ALIGNED8; + +// Eeprom works in 8 byte blocks, so divide by 8 for those functions. +#define BLOCK_SIZE(x) (x / sizeof(u64)) +#define SAVE_START (0) +#define CONFIG_START (SAVE_START + (sizeof(SaveFile) * NUMBER_OF_SAVE_FILES)) +#define FASTEST_LAPS_START (CONFIG_START + sizeof(SaveConfig)) +#define COURSE_TIMES_START (FASTEST_LAPS_START + sizeof(CourseRecords)) +#define SAVE_SIZE (sizeof(SaveBuffer)) + +#endif diff --git a/src/audio_vehicle.c b/src/audio_vehicle.c index fd2dab7e..5e0e7fc1 100644 --- a/src/audio_vehicle.c +++ b/src/audio_vehicle.c @@ -178,8 +178,8 @@ void racer_sound_update(Object *obj, u32 buttonsPressed, u32 buttonsHeld, s32 up if (gRacerSound != NULL) { if (get_race_countdown()) { if (gSoundRacerObj->playerIndex != PLAYER_COMPUTER) { - buttonsHeld = get_buttons_held_from_player(gSoundRacerObj->playerIndex); - buttonsPressed = get_buttons_pressed_from_player(gSoundRacerObj->playerIndex); + buttonsHeld = input_held(gSoundRacerObj->playerIndex); + buttonsPressed = input_pressed(gSoundRacerObj->playerIndex); } } if (gRacerSound->unk0[0] == 0) { diff --git a/src/game.c b/src/game.c index 1bd076fc..0c41b21f 100644 --- a/src/game.c +++ b/src/game.c @@ -147,7 +147,7 @@ void init_level_globals(void) { checksumCount += ((u8 *) (&viewport_rsp_set))[j]; } if (checksumCount != gViewportFuncChecksum) { - disable_button_mask(); + drm_disable_input(); } #endif } diff --git a/src/game_text.c b/src/game_text.c index 7b2e6a64..adb43706 100644 --- a/src/game_text.c +++ b/src/game_text.c @@ -456,7 +456,7 @@ s32 dialogue_challenge_loop(void) { index = func_800C38B4(index, &textBox); } } while (keepLooping); - playerButtons = get_buttons_pressed_from_player(PLAYER_ONE); + playerButtons = input_pressed(PLAYER_ONE); if (D_8012A787 == 0) { playerButtons = 0; } diff --git a/src/game_ui.c b/src/game_ui.c index 40759dd7..5ea861f6 100644 --- a/src/game_ui.c +++ b/src/game_ui.c @@ -414,7 +414,7 @@ void render_hud(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, s3 gCurrentHud = gPlayerHud[gHudCurrentViewport]; if (cutscene_id() != 10) { if (gHUDNumPlayers == ONE_PLAYER) { - if (get_buttons_pressed_from_player(D_80126D10) & D_CBUTTONS && racer->raceFinished == FALSE && + if (input_pressed(D_80126D10) & D_CBUTTONS && racer->raceFinished == FALSE && ((gHudLevelHeader->race_type == RACETYPE_DEFAULT) || gHudLevelHeader->race_type == RACETYPE_HORSESHOE_GULCH) && gHudRaceStart) { @@ -426,7 +426,7 @@ void render_hud(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, s3 gHudIndicatorTimer = 0; } } - } else if (get_buttons_pressed_from_player(D_80126D10) & D_CBUTTONS && + } else if (input_pressed(D_80126D10) & D_CBUTTONS && racer->raceFinished == FALSE && !(gHudLevelHeader->race_type & RACETYPE_CHALLENGE) && gHudRaceStart) { if (D_800E2794[gHUDNumPlayers][racer->playerIndex] < PLAYER_FOUR) { @@ -436,7 +436,7 @@ void render_hud(Gfx **dList, MatrixS **mtx, Vertex **vertexList, Object *obj, s3 } sound_play((SOUND_TING_HIGHEST - (D_800E2794[gHUDNumPlayers][racer->playerIndex] == 0)), NULL); } - if (get_buttons_pressed_from_player(D_80126D10) & R_CBUTTONS && racer->raceFinished == FALSE && + if (input_pressed(D_80126D10) & R_CBUTTONS && racer->raceFinished == FALSE && gHudRaceStart && gMinimapOpacity == 0) { gHudToggleSettings[gHUDNumPlayers] = 1 - gHudToggleSettings[gHUDNumPlayers]; if (gHudToggleSettings[gHUDNumPlayers] == 0) { diff --git a/src/joypad.c b/src/joypad.c index 4e10d59f..e56c6396 100644 --- a/src/joypad.c +++ b/src/joypad.c @@ -19,7 +19,7 @@ u8 sPlayerID[16]; * Return the serial interface message queue. * Official name: joyMessageQ */ -OSMesgQueue *get_si_mesg_queue(void) { +OSMesgQueue *si_mesg(void) { return &sSIMesgQueue; } @@ -27,7 +27,7 @@ OSMesgQueue *get_si_mesg_queue(void) { * Initialise the player controllers, and return the status when finished. * Official name: joyInit */ -s32 init_controllers(void) { +s32 input_init(void) { UNUSED s32 *temp1; u8 bitpattern; UNUSED s32 *temp2; @@ -36,7 +36,7 @@ s32 init_controllers(void) { osSetEventMesg(OS_EVENT_SI, &sSIMesgQueue, gSIMesg); osContInit(&sSIMesgQueue, &bitpattern, gControllerStatus); osContStartReadData(&sSIMesgQueue); - initialise_player_ids(); + input_assign_players(); sNoControllerPluggedIn = FALSE; @@ -56,7 +56,7 @@ s32 init_controllers(void) { * Also reads the latest inputs from the controllers, and sets their values. * Official name: joyRead */ -s32 handle_save_data_and_read_controller(s32 saveDataFlags, s32 updateRate) { +s32 input_update(s32 saveDataFlags, s32 updateRate) { Settings **allSaves; OSMesg unusedMsg; Settings *settings; @@ -125,7 +125,7 @@ s32 handle_save_data_and_read_controller(s32 saveDataFlags, s32 updateRate) { * Set the first 4 player ID's to the controller numbers, so players can input in the menus after boot. * Official name: joyResetMap */ -void initialise_player_ids(void) { +void input_assign_players(void) { s32 i; for (i = 0; i < MAXCONTROLLERS; i++) { sPlayerID[i] = i; @@ -156,7 +156,7 @@ void charselect_assign_players(s8 *activePlayers) { * Returns the id of the selected index. * Official name: joyGetController */ -u8 get_player_id(s32 player) { +u8 input_player_id(s32 player) { return sPlayerID[player]; } @@ -164,7 +164,7 @@ u8 get_player_id(s32 player) { * Swaps the ID's of the first two indexes. * This applies in 2 player adventure, so that player 2 can control the car in the overworld. */ -void swap_player_1_and_2_ids(void) { +void input_swap_id(void) { u8 tempID = sPlayerID[0]; sPlayerID[0] = sPlayerID[1]; sPlayerID[1] = tempID; @@ -174,7 +174,7 @@ void swap_player_1_and_2_ids(void) { * Returns the buttons that are currently pressed down on the controller. * Official name: joyGetButtons */ -u16 get_buttons_held_from_player(s32 player) { +u16 input_held(s32 player) { return gControllerCurrData[sPlayerID[player]].button; } @@ -183,7 +183,7 @@ u16 get_buttons_held_from_player(s32 player) { * NOTE: This was a u16, but we only got a match in menu_ghost_data_loop when it was a u32 for some reason * Official name: joyGetPressed */ -u32 get_buttons_pressed_from_player(s32 player) { +u32 input_pressed(s32 player) { return gControllerButtonsPressed[sPlayerID[player]]; } @@ -191,7 +191,7 @@ u32 get_buttons_pressed_from_player(s32 player) { * Returns the buttons that are no longer pressed in that frame. * Official name: joyGetReleased */ -u16 get_buttons_released_from_player(s32 player) { +u16 input_released(s32 player) { return gControllerButtonsReleased[sPlayerID[player]]; } @@ -199,23 +199,23 @@ u16 get_buttons_released_from_player(s32 player) { * Clamps the X joystick axis of the selected player to 70 and returns it. * Official name: joyGetStickX */ -s32 clamp_joystick_x_axis(s32 player) { - return clamp_joystick(gControllerCurrData[sPlayerID[player]].stick_x); +s32 input_clamp_stick_x(s32 player) { + return input_clamp_stick_mag(gControllerCurrData[sPlayerID[player]].stick_x); } /** * Clamps the Y joystick axis of the selected player to 70 and returns it. * Official name: joyGetStickY */ -s32 clamp_joystick_y_axis(s32 player) { - return clamp_joystick(gControllerCurrData[sPlayerID[player]].stick_y); +s32 input_clamp_stick_y(s32 player) { + return input_clamp_stick_mag(gControllerCurrData[sPlayerID[player]].stick_y); } /** * Keeps the joysticks axis reads no higher than 70 (of a possible 127 or -128) * Will also pull the reading towards the centre. */ -s8 clamp_joystick(s8 stickMag) { +s8 input_clamp_stick_mag(s8 stickMag) { if (stickMag < JOYSTICK_DEADZONE && stickMag > -JOYSTICK_DEADZONE) { return 0; } @@ -237,6 +237,6 @@ s8 clamp_joystick(s8 stickMag) { * Used when anti-cheat/anti-tamper has failed in init_level_globals() * Official Name: joySetSecurity */ -void disable_button_mask(void) { +void drm_disable_input(void) { gButtonMask = 0; } diff --git a/src/joypad.h b/src/joypad.h index efa1500b..a963b203 100644 --- a/src/joypad.h +++ b/src/joypad.h @@ -12,19 +12,19 @@ #define JOYSTICK_DEADZONE 8 #define JOYSTICK_MAX_RANGE 70 -OSMesgQueue *get_si_mesg_queue(void); -s32 init_controllers(void); -s32 handle_save_data_and_read_controller(s32 saveDataFlags, s32 updateRate); -void initialise_player_ids(void); +OSMesgQueue *si_mesg(void); +s32 input_init(void); +s32 input_update(s32 saveDataFlags, s32 updateRate); +void input_assign_players(void); void charselect_assign_players(s8 *activePlayers); -u8 get_player_id(s32 player); -void swap_player_1_and_2_ids(void); -u16 get_buttons_held_from_player(s32 player); -u32 get_buttons_pressed_from_player(s32 player); -u16 get_buttons_released_from_player(s32 player); -s32 clamp_joystick_x_axis(s32 player); -s32 clamp_joystick_y_axis(s32 player); -s8 clamp_joystick(s8 stickMag); -void disable_button_mask(void); +u8 input_player_id(s32 player); +void input_swap_id(void); +u16 input_held(s32 player); +u32 input_pressed(s32 player); +u16 input_released(s32 player); +s32 input_clamp_stick_x(s32 player); +s32 input_clamp_stick_y(s32 player); +s8 input_clamp_stick_mag(s8 stickMag); +void drm_disable_input(void); #endif diff --git a/src/menu.c b/src/menu.c index 280f9d9d..149b44fa 100644 --- a/src/menu.c +++ b/src/menu.c @@ -29,6 +29,7 @@ #include "joypad.h" #include "math_util.h" #include "PRinternal/viint.h" +#include "save_layout.h" /** * @file Contains all the code used for every menu in the game. @@ -2841,7 +2842,7 @@ s32 postrace_render(s32 updateRate) { if (gPostraceState != POSTRACE_SLIDE_END) { if (gIgnorePlayerInputTime == 0) { for (i = 0; i < gNumberOfActivePlayers; i++) { - buttonsPressedAllPlayers |= get_buttons_pressed_from_player(i); + buttonsPressedAllPlayers |= input_pressed(i); } } gMenuElementScaleTimer += updateRate; @@ -3309,7 +3310,7 @@ void menu_title_screen_init(void) { gSaveFileIndex = 0; gTitleScreenCurrentOption = 0; gNumberOfActivePlayers = 4; - initialise_player_ids(); + input_assign_players(); music_play(SEQUENCE_NONE2); sMenuMusicVolume = music_volume(); if (gResetTitleScale) { @@ -3662,7 +3663,7 @@ s32 menu_options_loop(s32 updateRate) { analogueY = 0; if (gIgnorePlayerInputTime == 0 && gMenuDelay == 0) { for (i = 0; i < MAXCONTROLLERS; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); analogueX += gControllersXAxisDirection[i]; analogueY += gControllersYAxisDirection[i]; } @@ -3930,8 +3931,8 @@ s32 menu_audio_options_loop(s32 updateRate) { buttonsPressed = 0; contXAxis = 0; for (i = 0; i < 4; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); - contXAxis += clamp_joystick_x_axis(i); + buttonsPressed |= input_pressed(i); + contXAxis += input_clamp_stick_x(i); contX += gControllersXAxisDirection[i]; contY += gControllersYAxisDirection[i]; } @@ -5151,7 +5152,7 @@ s32 menu_save_options_loop(s32 updateRate) { for (i = 0; i < 4; i++) { xAxis += gControllersXAxisDirection[i]; yAxis += gControllersYAxisDirection[i]; - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); } } if (gMenuStage & 8) { @@ -5513,11 +5514,11 @@ void bootscreen_init_cpak(void) { s32 i; // Starting point - gBootPakData[0] = mempool_alloc_safe(SAVE_SIZE_MENU, COLOUR_TAG_WHITE); + gBootPakData[0] = mempool_alloc_safe(CPAK_HEAP_SIZE, COLOUR_TAG_WHITE); // Fills in the table. for (i = 1; i < ARRAY_COUNT(gBootPakData); i++) { - gBootPakData[i] = (char *) (((u32) gBootPakData[0]) + (i * (SAVE_SIZE_MENU / ARRAY_COUNT(gBootPakData)))); + gBootPakData[i] = (char *) (((u32) gBootPakData[0]) + (i * (CPAK_HEAP_SIZE / ARRAY_COUNT(gBootPakData)))); } // Only check cpak 0 @@ -5741,7 +5742,7 @@ s32 menu_controller_pak_loop(s32 updateRate) { xStick = 0; yStick = 0; for (i = 0; i < MAXCONTROLLERS; i++) { - pressedButtons |= get_buttons_pressed_from_player(i); + pressedButtons |= input_pressed(i); xStick += gControllersXAxisDirection[i]; yStick += gControllersYAxisDirection[i]; } @@ -6138,7 +6139,7 @@ s32 menu_magic_codes_loop(s32 updateRate) { yDir = 0; if (gIgnorePlayerInputTime == 0 && gMenuDelay == 0) { for (i = 0; i < MAXCONTROLLERS; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); xDir += gControllersXAxisDirection[i]; yDir += gControllersYAxisDirection[i]; } @@ -6505,7 +6506,7 @@ s32 menu_magic_codes_list_loop(s32 updateRate) { yAxis = 0; if (gIgnorePlayerInputTime == 0 && gMenuDelay == 0) { for (i = 0; i < MAXCONTROLLERS; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); xAxis += gControllersXAxisDirection[i]; yAxis += gControllersYAxisDirection[i]; } @@ -6722,7 +6723,7 @@ void menu_character_select_init(void) { u8 *channelVolumes; breakTheLoop = FALSE; - initialise_player_ids(); + input_assign_players(); if (is_drumstick_unlocked()) { if (is_tt_unlocked()) { gCurrCharacterSelectData = (CharacterSelectData(*)[10]) & gCharacterSelectBytesComplete; @@ -7235,7 +7236,7 @@ s32 menu_caution_loop(s32 updateRate) { if (gMenuDelay) { gMenuDelay += updateRate; } else if (gIgnorePlayerInputTime <= 0 && - (get_buttons_pressed_from_player(PLAYER_ONE) & (A_BUTTON | B_BUTTON | START_BUTTON))) { + (input_pressed(PLAYER_ONE) & (A_BUTTON | B_BUTTON | START_BUTTON))) { sound_play(SOUND_SELECT2, NULL); gMenuDelay = 1; transition_begin(&sMenuTransitionFadeIn); @@ -7409,11 +7410,11 @@ s32 menu_game_select_loop(s32 updateRate) { } else { gameselect_render(updateRate); if ((gMenuDelay == 0) && (gOpacityDecayTimer == 0)) { - playerInputs = get_buttons_pressed_from_player(PLAYER_ONE); + playerInputs = input_pressed(PLAYER_ONE); playerYDir = gControllersYAxisDirection[0]; playerInputs = playerInputs; if (gNumberOfActivePlayers == 2) { - playerInputs |= get_buttons_pressed_from_player(1); + playerInputs |= input_pressed(1); playerYDir += gControllersYAxisDirection[1]; } if (playerInputs & (A_BUTTON | START_BUTTON)) { @@ -7699,11 +7700,11 @@ s32 fileselect_input_root(UNUSED s32 updateRate) { s32 prevOption; u32 buttonsPressedPlayer2; - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); xAxisDirection = gControllersXAxisDirection[PLAYER_ONE]; yAxisDirection = gControllersYAxisDirection[PLAYER_ONE]; if (gNumberOfActivePlayers == 2) { - buttonsPressedPlayer2 = get_buttons_pressed_from_player(PLAYER_TWO); + buttonsPressedPlayer2 = input_pressed(PLAYER_TWO); buttonsPressed |= buttonsPressedPlayer2; xAxisDirection += gControllersXAxisDirection[PLAYER_TWO]; yAxisDirection += gControllersYAxisDirection[PLAYER_TWO]; @@ -7793,10 +7794,10 @@ void fileselect_input_copy(UNUSED s32 updateRate) { u32 buttonsPressedPlayerTwo; settings = get_settings(); - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); xAxisDirection = gControllersXAxisDirection[PLAYER_ONE]; if (gNumberOfActivePlayers == 2) { - buttonsPressedPlayerTwo = get_buttons_pressed_from_player(PLAYER_TWO); + buttonsPressedPlayerTwo = input_pressed(PLAYER_TWO); buttonsPressed |= buttonsPressedPlayerTwo; xAxisDirection += gControllersXAxisDirection[PLAYER_TWO]; } @@ -7886,11 +7887,11 @@ void fileselect_input_erase(UNUSED s32 updateRate) { s32 controllerXAxisDirection; s32 prevOption; - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); controllerXAxisDirection = gControllersXAxisDirection[0]; if (gNumberOfActivePlayers == 2) { - buttonsPressed |= get_buttons_pressed_from_player(PLAYER_TWO); + buttonsPressed |= input_pressed(PLAYER_TWO); controllerXAxisDirection += gControllersXAxisDirection[1]; } @@ -8004,7 +8005,7 @@ s32 menu_file_select_loop(s32 updateRate) { } else if (gFileErase) { fileselect_input_erase(updateRate); } else if (gFileNew) { - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); if (buttonsPressed & B_BUTTON && gNameEntryLength == 0) { menu_unload_bigfont(); gFileNew = FALSE; @@ -8145,7 +8146,7 @@ void menu_input(void) { gMenuStickY[i] = 0; } for (i = 0; i < MAXCONTROLLERS; i++) { - buttonsHeld[i] = get_buttons_held_from_player(i); + buttonsHeld[i] = input_held(i); gMenuStickX[i] = gControllersXAxisDirection[i]; gMenuStickY[i] = gControllersYAxisDirection[i]; if (i < gNumberOfActivePlayers) { @@ -10093,7 +10094,7 @@ void menu_pause_init(void) { gLastPlayerWhoPaused = -1; for (i = 0; (get_active_player_count() > i && gLastPlayerWhoPaused < 0); i++) { - if (get_buttons_held_from_player(i) & START_BUTTON) { + if (input_held(i) & START_BUTTON) { gLastPlayerWhoPaused = i; } } @@ -10176,11 +10177,11 @@ void pausemenu_render(UNUSED s32 updateRate) { halfX = x >> 1; set_current_dialogue_box_coords(7, SCREEN_WIDTH_HALF - halfX, y - halfTemp, SCREEN_WIDTH_HALF + halfX, halfTemp + y); - colour = &gPlayerPauseBgColour[get_player_id(gLastPlayerWhoPaused)]; + colour = &gPlayerPauseBgColour[input_player_id(gLastPlayerWhoPaused)]; set_current_dialogue_background_colour(7, colour->r, colour->g, colour->b, colour->a); set_dialogue_font(7, ASSET_FONTS_FUNFONT); set_current_text_background_colour(7, 128, 128, 255, 0); - colour = &gPlayerPauseOptionsTextColour[get_player_id(gLastPlayerWhoPaused)]; + colour = &gPlayerPauseOptionsTextColour[input_player_id(gLastPlayerWhoPaused)]; set_current_text_colour(7, colour->r, colour->g, colour->b, colour->a, 255); alpha = gOptionBlinkTimer * 8; if (alpha > 255) { @@ -10244,7 +10245,7 @@ s32 menu_pause_loop(UNUSED Gfx **dl, s32 updateRate) { buttonsPressed = 0; if (gIgnorePlayerInputTime == 0) { - buttonsPressed = get_buttons_pressed_from_player(gLastPlayerWhoPaused); + buttonsPressed = input_pressed(gLastPlayerWhoPaused); } if (gMenuDelay == 0) { @@ -10825,7 +10826,7 @@ s32 menu_postrace(Gfx **dList, MatrixS **matrices, Vertex **vertices, s32 update buttonsPressed = 0; if (gIgnorePlayerInputTime == FALSE && gPostRace.unk0_s32 < 0) { for (i = 0; i < numPlayers; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); } } switch (gMenuStage) { @@ -11715,8 +11716,8 @@ s32 filename_enter(s32 updateRate) { s32 i; s32 joytickXAxis; - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); - joytickXAxis = clamp_joystick_x_axis(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); + joytickXAxis = input_clamp_stick_x(PLAYER_ONE); if (joytickXAxis > -35 && (joytickXAxis < 35)) { joytickXAxis = 0; } @@ -12270,7 +12271,7 @@ s32 menu_trophy_race_rankings_loop(s32 updateRate) { buttonsPressed = 0; prevOption = gMenuOption; for (i = 0; i < gNumberOfActivePlayers; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); if (gControllersYAxisDirection[i] < 0) { gMenuOption++; } @@ -12701,7 +12702,7 @@ s32 menu_ghost_data_loop(s32 updateRate) { yStick = 0; if (!gIgnorePlayerInputTime && gMenuDelay == 0) { for (i = 0; i < MAXCONTROLLERS; i++) { - pressedButtons |= get_buttons_pressed_from_player(i); + pressedButtons |= input_pressed(i); xStick += gControllersXAxisDirection[i]; yStick += gControllersYAxisDirection[i]; } @@ -12848,7 +12849,7 @@ s32 menu_cinematic_loop(UNUSED s32 updateRate) { buttonsPressed = 0; if (gIgnorePlayerInputTime == 0) { for (i = 0; i < gNumberOfActivePlayers; i++) { - buttonsPressed |= get_buttons_pressed_from_player(i); + buttonsPressed |= input_pressed(i); } } if (func_800214C4() != 0) { @@ -13222,7 +13223,7 @@ s32 menu_credits_loop(s32 updateRate) { buttonsPressedAllPlayers = 0; if (gIgnorePlayerInputTime == 0 && gMenuDelay == 0) { for (nextIndex = 0; nextIndex < MAXCONTROLLERS; nextIndex++) { - buttonsPressedAllPlayers |= get_buttons_pressed_from_player(nextIndex); + buttonsPressedAllPlayers |= input_pressed(nextIndex); } } @@ -13387,8 +13388,8 @@ void update_controller_sticks(void) { s32 XClamp, YClamp; s32 i; for (i = 0; i < 4; i++) { - XClamp = clamp_joystick_x_axis(i); - YClamp = clamp_joystick_y_axis(i); + XClamp = input_clamp_stick_x(i); + YClamp = input_clamp_stick_y(i); gControllersXAxisDirection[i] = 0; gControllersYAxisDirection[i] = 0; @@ -14048,7 +14049,7 @@ s32 taj_menu_loop(void) { set_dialogue_font(1, ASSET_FONTS_FUNFONT); } dialogueResult = 0; - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); sDialogueOptionMax = 0; switch (sCurrentMenuID) { @@ -14226,7 +14227,7 @@ s32 dialogue_race_defeat(void) { set_current_dialogue_box_coords(1, 24, 16, 184, 135); set_dialogue_font(1, ASSET_FONTS_FUNFONT); state = 0; - playerInput = get_buttons_pressed_from_player(PLAYER_ONE); + playerInput = input_pressed(PLAYER_ONE); sDialogueOptionMax = 0; gNextTajChallengeMenu = 0; render_dialogue_text(1, POS_CENTRED, 6, gMenuText[ASSET_MENU_TEXT_LOSETOTAJ_0], 1, @@ -14293,7 +14294,7 @@ s32 tt_menu_loop(void) { } set_dialogue_font(1, ASSET_FONTS_FUNFONT); currentOption = 0; - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE) << 0; + buttonsPressed = input_pressed(PLAYER_ONE) << 0; sDialogueOptionMax = 0; gDialogueOptionYOffset = 32; switch (sCurrentMenuID) { @@ -14630,7 +14631,7 @@ s32 trophy_race_cabinet_menu_loop(void) { set_current_dialogue_box_coords(1, 24, 16, 184, SCREEN_HEIGHT_HALF); set_dialogue_font(1, ASSET_FONTS_FUNFONT); currentOption = 0; - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); render_dialogue_text(1, POS_CENTRED, 6, gMenuText[ASSET_MENU_TEXT_TROPHYRACE], 1, HORZ_ALIGN_CENTER); // TROPHY RACE if (gControllersYAxisDirection[0] < 0) { gDialogueSubmenu++; diff --git a/src/object_functions.c b/src/object_functions.c index 63338ced..0c0339fd 100644 --- a/src/object_functions.c +++ b/src/object_functions.c @@ -876,7 +876,7 @@ void obj_loop_rocketsignpost(Object *obj, UNUSED s32 updateRate) { if (interactObj->distance < 200) { if (playerObj == interactObj->obj) { // Detect if the player honks or slams into the signpost. - if ((get_buttons_pressed_from_player(PLAYER_ONE) & Z_TRIG) || playerObj == obj->unk5C->unk100) { + if ((input_pressed(PLAYER_ONE) & Z_TRIG) || playerObj == obj->unk5C->unk100) { begin_lighthouse_rocket_cutscene(); } } @@ -1248,7 +1248,7 @@ void obj_loop_stopwatchman(Object *obj, s32 updateRate) { obj->properties.npc.timer = 1; } } - index = get_buttons_pressed_from_player(PLAYER_ONE); + index = input_pressed(PLAYER_ONE); if (obj->properties.npc.action == TT_MODE_ROAM && distance < 300.0 && obj->properties.npc.timer == 0) { if (angleDiff > -0x2000 && angleDiff < 0x2000) { if ((obj->interactObj->flags & INTERACT_FLAGS_PUSHING && racerObj == obj->interactObj->obj) || @@ -1832,7 +1832,7 @@ void obj_init_animation(Object *obj, LevelObjectEntry_Animation *entry, s32 arg2 path_enable(); obj->properties.animatedObj.behaviourID = entry->actorIndex; obj->properties.animatedObj.action = arg2; - if (arg2 != 0 && (get_buttons_pressed_from_player(PLAYER_ONE) & R_CBUTTONS)) { + if (arg2 != 0 && (input_pressed(PLAYER_ONE) & R_CBUTTONS)) { obj->properties.animatedObj.action = 2; } if (((cutscene_id() == entry->channel) || (entry->channel == 20)) && (obj->unk64 == NULL) && (entry->order == 0) && @@ -2221,7 +2221,7 @@ void obj_loop_infopoint(Object *obj, UNUSED s32 updateRate) { if (playerObj->segment.header->behaviorId == 1) { Object_InfoPoint *playerObj64 = &playerObj->unk64->info_point; player = playerObj64->unk0; - if ((player != PLAYER_COMPUTER) && (get_buttons_pressed_from_player(player) & Z_TRIG)) { + if ((player != PLAYER_COMPUTER) && (input_pressed(player) & Z_TRIG)) { set_current_text(obj->properties.infoPoint.radius & 0xFF); } } @@ -2586,7 +2586,7 @@ void obj_loop_parkwarden(Object *obj, s32 updateRate) { zPosDiff = (racerObj->segment.trans.z_position - (racer->oz1 * 50.0f)) - obj->segment.trans.z_position; distance = sqrtf((xPosDiff * xPosDiff) + (zPosDiff * zPosDiff)); } - buttonsPressed = get_buttons_pressed_from_player(PLAYER_ONE); + buttonsPressed = input_pressed(PLAYER_ONE); var_a2 = FALSE; if ((obj->properties.npc.action == NULL) && (distance < 300.0) && (((obj->interactObj->flags & INTERACT_FLAGS_PUSHING) && (racerObj == obj->interactObj->obj)) || diff --git a/src/objects.c b/src/objects.c index 5ad21d31..5f939c16 100644 --- a/src/objects.c +++ b/src/objects.c @@ -2404,7 +2404,7 @@ void func_80010994(s32 updateRate) { if ((gEventCountdown == 0x50) && (gCutsceneID == 0)) { sp54 = 0; for (i = 0; i < MAXCONTROLLERS; i++) { - tempVal = get_buttons_pressed_from_player(i); + tempVal = input_pressed(i); sp54 |= tempVal; } @@ -4550,7 +4550,7 @@ void race_transition_adventure(s32 updateRate) { hud_visibility(1); } } - i = get_buttons_pressed_from_player(PLAYER_ONE) & A_BUTTON; + i = input_pressed(PLAYER_ONE) & A_BUTTON; settings = get_settings(); if (!(settings->cutsceneFlags & 0x40000)) { i = 0; diff --git a/src/racer.c b/src/racer.c index 351c27e0..be5064bc 100644 --- a/src/racer.c +++ b/src/racer.c @@ -2329,15 +2329,15 @@ void update_player_racer(Object *obj, s32 updateRate) { tempVar = 1 - tempVar; } // Cap the joystick tilt and write the button inputs to the current buffer. - gCurrentStickX = clamp_joystick_x_axis(tempVar); + gCurrentStickX = input_clamp_stick_x(tempVar); // Flip the steering for adventure 2. if (get_filtered_cheats() & CHEAT_MIRRORED_TRACKS) { gCurrentStickX = -gCurrentStickX; } - gCurrentStickY = clamp_joystick_y_axis(tempVar); - gCurrentRacerInput = get_buttons_held_from_player(tempVar); - gCurrentButtonsPressed = get_buttons_pressed_from_player(tempVar); - gCurrentButtonsReleased = get_buttons_released_from_player(tempVar); + gCurrentStickY = input_clamp_stick_y(tempVar); + gCurrentRacerInput = input_held(tempVar); + gCurrentButtonsPressed = input_pressed(tempVar); + gCurrentButtonsReleased = input_released(tempVar); } else { racer_enter_door(tempRacer, updateRate); } diff --git a/src/save_data.c b/src/save_data.c index 4e8eddba..5656d026 100644 --- a/src/save_data.c +++ b/src/save_data.c @@ -12,6 +12,7 @@ #include "joypad.h" #include "PRinternal/viint.h" #include "PR/os_motor.h" +#include "save_layout.h" /************ .data ************/ @@ -69,7 +70,7 @@ u8 input_get_id(s32 controllerIndex) { if ((controllerIndex == 0 || controllerIndex == 1) && func_8000E158()) { controllerIndex = 1 - controllerIndex; } - return get_player_id(controllerIndex); + return input_player_id(controllerIndex); } #if VERSION >= VERSION_79 @@ -833,28 +834,28 @@ s32 read_save_file(s32 saveFileNum, Settings *settings) { s32 block; s32 ret; - if (osEepromProbe(get_si_mesg_queue()) == 0) { + if (osEepromProbe(si_mesg()) == 0) { stubbed_printf("WARNING : No Eprom\n"); return -1; } switch (saveFileNum) { case 0: - startingAddress = 0; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 0)); break; case 1: - startingAddress = 5; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 1)); break; case 2: - startingAddress = 10; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 2)); break; default: - startingAddress = 10; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 2)); break; } blocks = 5; saveData = mempool_alloc_safe(blocks * sizeof(u64), COLOUR_TAG_WHITE); for (block = 0, address = startingAddress; block < blocks; block++, address++) { - osEepromRead(get_si_mesg_queue(), address, (u8 *) &saveData[block]); + osEepromRead(si_mesg(), address, (u8 *) &saveData[block]); } populate_settings_from_save_data(settings, (u8 *) saveData); mempool_free(saveData); @@ -876,7 +877,7 @@ void erase_save_file(s32 saveFileNum, Settings *settings) { s32 address; s32 i; - if (osEepromProbe(get_si_mesg_queue()) != 0) { + if (osEepromProbe(si_mesg()) != 0) { get_number_of_levels_and_worlds(&levelCount, &worldCount); for (i = 0; i < levelCount; i++) { settings->courseFlagsPtr[i] = 0; @@ -891,16 +892,16 @@ void erase_save_file(s32 saveFileNum, Settings *settings) { settings->newGame = TRUE; switch (saveFileNum) { case 0: - startingAddress = 0; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 0)); break; case 1: - startingAddress = 5; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 1)); break; case 2: - startingAddress = 10; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 2)); break; default: - startingAddress = 10; + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 2)); break; } blockSize = 5; @@ -914,7 +915,7 @@ void erase_save_file(s32 saveFileNum, Settings *settings) { if (!is_reset_pressed()) { for (i = 0, address = startingAddress; i < blockSize; i++, address++) { - osEepromWrite(get_si_mesg_queue(), address, (u8 *) &alloc[i]); + osEepromWrite(si_mesg(), address, (u8 *) &alloc[i]); } } mempool_free(alloc); @@ -937,23 +938,23 @@ s32 write_save_data(s32 saveFileNum, Settings *settings) { s32 blocks; s32 i; - if (osEepromProbe(get_si_mesg_queue()) == 0) { + if (osEepromProbe(si_mesg()) == 0) { stubbed_printf("WARNING : No Eprom\n"); return -1; } switch (saveFileNum) { case 0: - startingAddress = 0x00 / sizeof(u64); + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 0)); break; case 1: - startingAddress = 0x28 / sizeof(u64); + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 1)); break; case 2: - startingAddress = 0x50 / sizeof(u64); + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 2)); break; default: - startingAddress = 0x50 / sizeof(u64); + startingAddress = BLOCK_SIZE(SAVE_START + (sizeof(SaveFile) * 2)); break; } @@ -963,7 +964,7 @@ s32 write_save_data(s32 saveFileNum, Settings *settings) { if (!is_reset_pressed()) { for (i = 0, address = startingAddress; i < blocks; i++, address++) { - osEepromWrite(get_si_mesg_queue(), address, (u8 *) &alloc[i]); + osEepromWrite(si_mesg(), address, (u8 *) &alloc[i]); } } @@ -983,25 +984,26 @@ s32 read_eeprom_data(Settings *settings, u8 flags) { u64 *alloc; s32 i; - if (osEepromProbe(get_si_mesg_queue()) == 0) { + if (osEepromProbe(si_mesg()) == 0) { stubbed_printf("WARNING : No Eprom\n"); return -1; } - alloc = mempool_alloc_safe(SAVE_SIZE, COLOUR_TAG_WHITE); + alloc = mempool_alloc_safe(COURSE_TIMES_START + sizeof(CourseRecords), COLOUR_TAG_WHITE); if (flags & SAVE_DATA_FLAG_READ_FLAP_TIMES) { - s32 blocks = EEP_FLAP_SIZE; + s32 blocks = BLOCK_SIZE(sizeof(CourseRecords)); for (i = 0; i < blocks; i++) { - osEepromRead(get_si_mesg_queue(), i + EEP_FLAP_OFFSET, (u8 *) &alloc[i]); + osEepromRead(si_mesg(), BLOCK_SIZE(FASTEST_LAPS_START) + i, (u8 *) &alloc[i]); } func_80073588(settings, (u8 *) alloc, SAVE_DATA_FLAG_READ_FLAP_TIMES); } if (flags & SAVE_DATA_FLAG_READ_COURSE_TIMES) { - s32 blocks = EEP_COURSE_RECORD_SIZE; + s32 blocks = BLOCK_SIZE(sizeof(CourseRecords)); for (i = 0; i < blocks; i++) { - osEepromRead(get_si_mesg_queue(), i + EEP_COURSE_TIME_OFFSET, (u8 *) (&alloc[EEP_FLAP_SIZE] + i)); + osEepromRead(si_mesg(), BLOCK_SIZE(COURSE_TIMES_START) + i, + (u8 *) (&alloc[sizeof(CourseRecords) / sizeof(u64)] + i)); } func_80073588(settings, (u8 *) alloc, SAVE_DATA_FLAG_READ_COURSE_TIMES); } @@ -1022,30 +1024,31 @@ s32 write_eeprom_data(Settings *settings, u8 flags) { u64 *alloc; s32 i; - if (osEepromProbe(get_si_mesg_queue()) == 0) { + if (osEepromProbe(si_mesg()) == 0) { stubbed_printf("WARNING : No Eprom\n"); return -1; } - alloc = mempool_alloc_safe(SAVE_SIZE, COLOUR_TAG_WHITE); + alloc = mempool_alloc_safe(COURSE_TIMES_START + sizeof(CourseRecords), COLOUR_TAG_WHITE); func_800738A4(settings, (u8 *) alloc); if (flags & SAVE_DATA_FLAG_READ_FLAP_TIMES) { - s32 size = EEP_FLAP_SIZE; + s32 blocks = BLOCK_SIZE(sizeof(CourseRecords)); if (1) {} // Fake Match - if (!is_reset_pressed()) { - for (i = 0; i != size; i++) { - osEepromWrite(get_si_mesg_queue(), i + EEP_FLAP_OFFSET, (u8 *) &alloc[i]); + if (is_reset_pressed() == FALSE) { + for (i = 0; i != blocks; i++) { + osEepromWrite(si_mesg(), BLOCK_SIZE(FASTEST_LAPS_START) + i, (u8 *) &alloc[i]); } } } if (flags & SAVE_DATA_FLAG_READ_COURSE_TIMES) { - s32 size = EEP_COURSE_RECORD_SIZE; - if (!is_reset_pressed()) { - for (i = 0; i != size; i++) { - osEepromWrite(get_si_mesg_queue(), i + EEP_COURSE_TIME_OFFSET, (u8 *) (&alloc[EEP_FLAP_SIZE] + i)); + s32 blocks = BLOCK_SIZE(sizeof(CourseRecords)); + if (is_reset_pressed() == FALSE) { + for (i = 0; i != blocks; i++) { + osEepromWrite(si_mesg(), BLOCK_SIZE(COURSE_TIMES_START) + i, + (u8 *) (&alloc[sizeof(CourseRecords) / sizeof(u64)] + i)); } } } @@ -1075,24 +1078,25 @@ s32 calculate_eeprom_settings_checksum(u64 eepromSettings) { * Address (0xF * sizeof(u64)) = 0x78 - 0x80 of the actual save data file */ s32 read_eeprom_settings(u64 *eepromSettings) { - s32 temp; - s32 sp20; + s32 checksum; + s32 expected; - if (osEepromProbe(get_si_mesg_queue()) == 0) { + if (osEepromProbe(si_mesg()) == 0) { stubbed_printf("WARNING : No Eprom\n"); return -1; } - osEepromRead(get_si_mesg_queue(), 0xF, (u8 *) eepromSettings); - sp20 = calculate_eeprom_settings_checksum(*eepromSettings); - temp = *eepromSettings >> 56; - if (sp20 != temp) { + osEepromRead(si_mesg(), BLOCK_SIZE(CONFIG_START), (u8 *) eepromSettings); + expected = calculate_eeprom_settings_checksum(*eepromSettings); + checksum = *eepromSettings >> 56; + if (expected != checksum) { // bit 24 = Unknown // bit 25 = Seems to be a flag for whether subtitles are enabled or not. #if REGION == REGION_JP - *eepromSettings = 0x300000C; + // JP additionally forces the language setting to Japanese. + *eepromSettings = (1 << 2) | (1 << 3) | (1 << 24) | (1 << 25); #else - *eepromSettings = 0x3000000; // Sets bits 24 and 25 high + *eepromSettings = (1 << 24) | (1 << 25); // Sets bits 24 and 25 high #endif *eepromSettings <<= 8; *eepromSettings >>= 8; @@ -1108,15 +1112,15 @@ s32 read_eeprom_settings(u64 *eepromSettings) { * Address (0xF * sizeof(u64)) = 0x78 - 0x80 of the actual save data file */ s32 write_eeprom_settings(u64 *eepromSettings) { - if (osEepromProbe(get_si_mesg_queue()) == 0) { + if (osEepromProbe(si_mesg()) == 0) { stubbed_printf("WARNING : No Eprom\n"); return -1; } *eepromSettings <<= 8; *eepromSettings >>= 8; - *eepromSettings |= (s64) (calculate_eeprom_settings_checksum(*eepromSettings)) << 56; - if (is_reset_pressed() == 0) { - osEepromWrite(get_si_mesg_queue(), 0xF, (u8 *) eepromSettings); + *eepromSettings |= (u64) (calculate_eeprom_settings_checksum(*eepromSettings)) << 56; + if (is_reset_pressed() == FALSE) { + osEepromWrite(si_mesg(), BLOCK_SIZE(CONFIG_START), (u8 *) eepromSettings); } return 1; } @@ -1593,7 +1597,7 @@ void init_controller_paks(void) { u8 pakPattern; s8 maxControllers; - sControllerMesgQueue = get_si_mesg_queue(); + sControllerMesgQueue = si_mesg(); sRumbleTable = (s16 *) get_misc_asset(ASSET_MISC_RUMBLE_DATA); gRumbleIdle = gRumbleActive = 0xF; gRumbleOn = TRUE; diff --git a/src/save_data.h b/src/save_data.h index c10c508b..cb6bc935 100644 --- a/src/save_data.h +++ b/src/save_data.h @@ -26,20 +26,12 @@ #define MAX_CPAK_FILES 16 -// Most of this is temporary really until we figure out where the size comes from -#define EEP_FLAP_OFFSET (0x80 / sizeof(u64)) -#define EEP_COURSE_TIME_OFFSET (0x140 / sizeof(u64)) -#define EEP_FLAP_SIZE (0xC0 / sizeof(u64)) -#define EEP_COURSE_RECORD_SIZE (0xC0 / sizeof(u64)) - #if REGION == REGION_JP // The Save size constant seems to change depending on the file being compiled in JP? -#define SAVE_SIZE_MENU 0x400 -#define SAVE_SIZE 0x200 +#define CPAK_HEAP_SIZE 0x400 #define SAVE_FILE_BYTES 48 #else -#define SAVE_SIZE_MENU 0x200 -#define SAVE_SIZE 0x200 +#define CPAK_HEAP_SIZE 0x200 #define SAVE_FILE_BYTES 24 #endif diff --git a/src/thread3_main.c b/src/thread3_main.c index ec4db787..ce72cb91 100644 --- a/src/thread3_main.c +++ b/src/thread3_main.c @@ -152,7 +152,7 @@ UNUSED s32 D_80123568[3]; // BSS Padding */ void thread3_main(UNUSED void *unused) { init_game(); - gSaveDataFlags = handle_save_data_and_read_controller(gSaveDataFlags, 0); + gSaveDataFlags = input_update(gSaveDataFlags, 0); sBootDelayTimer = 0; gGameMode = GAMEMODE_INTRO; while (1) { @@ -213,7 +213,7 @@ void init_game(void) { gfxtask_init(&gMainSched); audio_init(&gMainSched); func_80008040(); // Should be very similar to allocate_object_model_pools - sControllerStatus = init_controllers(); + sControllerStatus = input_init(); tex_init_textures(); allocate_object_model_pools(); allocate_object_pools(); @@ -280,7 +280,7 @@ void main_game_loop(void) { rsp_init(&gCurrDisplayList); rdp_init(&gCurrDisplayList); bgdraw_render(&gCurrDisplayList, (Matrix *) &gGameCurrMatrix, TRUE); - gSaveDataFlags = handle_save_data_and_read_controller(gSaveDataFlags, sLogicUpdateRate); + gSaveDataFlags = input_update(gSaveDataFlags, sLogicUpdateRate); if (get_lockup_status()) { render_epc_lock_up_display(); gGameMode = GAMEMODE_LOCKUP; @@ -433,8 +433,8 @@ void mode_game(s32 updateRate) { // Get input data for all 4 players. for (i = 0; i < get_active_player_count(); i++) { - buttonHeldInputs |= get_buttons_held_from_player(i); - buttonPressedInputs |= get_buttons_pressed_from_player(i); + buttonHeldInputs |= input_held(i); + buttonPressedInputs |= input_pressed(i); } #ifdef ANTI_TAMPER // Spam the start button, making the game unplayable because it's constantly paused. @@ -1545,7 +1545,7 @@ void swap_lead_player(void) { u8 *first_racer_data; u8 *second_racer_data; - swap_player_1_and_2_ids(); + input_swap_id(); func_8000E194(); first_racer_data = (u8 *) (gSettingsPtr->racers); @@ -1574,7 +1574,7 @@ void mode_intro(void) { s32 buttonInputs = 0; for (i = 0; i < MAXCONTROLLERS; i++) { - buttonInputs |= get_buttons_held_from_player(i); + buttonInputs |= input_held(i); } if (buttonInputs & START_BUTTON) { gShowControllerPakMenu = TRUE; diff --git a/tools/python/extract_custom_boot.py b/tools/python/extract_custom_boot.py index a6ad863e..165a5a86 100644 --- a/tools/python/extract_custom_boot.py +++ b/tools/python/extract_custom_boot.py @@ -17,9 +17,15 @@ def N64GetCIC(data: bytes) -> int: 0xACC8580A: 6106, }.get(crc, 0) +# Extract a boot bin from the given rom, provided the setup is correct def boot_extract(input_file, output_file="boot_custom.bin"): mods_missing = True cictype = 6103 + + if not (os.path.isfile(input_file)): + print(input_file + " cannot be found. Check the spelling in your input.") + return + if not (input_file.endswith(".z64")): print("ROM file must be .z64. Use https://hack64.net/tools/swapper.php to convert.") return @@ -28,7 +34,7 @@ def boot_extract(input_file, output_file="boot_custom.bin"): f.seek(0x40) data = f.read(0xFC0) - if os.path.isdir('mods'): + if os.path.isdir("mods"): print("Mods folder detected, outputting there.") output_file = "./mods/boot_custom.bin" mods_missing = False @@ -41,18 +47,18 @@ def boot_extract(input_file, output_file="boot_custom.bin"): cictype = 6102 else: print("CIC: " + str(cictype)) - if os.path.isfile("Makefile"): - print("Makefile detected, modifying CIC type.") - with open("Makefile", 'r') as f: - lines = f.readlines() - with open("Makefile", 'w') as f: - for line in lines: - if line.startswith("BOOT_CIC ?="): - f.write("BOOT_CIC ?= " + str(cictype) + "\n") - else: - f.write(line) - if os.path.isfile("./build/asm/header.s.o"): - os.remove("./build/asm/header.s.o") + #if os.path.isfile("Makefile"): + # print("Makefile detected, modifying CIC type.") + # with open("Makefile", 'r') as f: + # lines = f.readlines() + # with open("Makefile", 'w') as f: + # for line in lines: + # if line.startswith("BOOT_CIC ?="): + # f.write("BOOT_CIC ?= " + str(cictype) + "\n") + # else: + # f.write(line) + if os.path.isfile("./build/asm/header.s.o"): + os.remove("./build/asm/header.s.o") with open(output_file, "wb") as f: @@ -63,4 +69,22 @@ def boot_extract(input_file, output_file="boot_custom.bin"): else: print("Finished!") -boot_extract(sys.argv[1]) +# Read the current custom boot bin and return its CIC +def boot_write(): + if not os.path.isdir("mods"): + print("0") + return + if not os.path.isfile("mods/boot_custom.bin"): + print("0") + return + with open("./mods/boot_custom.bin", "rb") as f: + data = f.read(0xFC0) + cictype = N64GetCIC(data) + if (cictype == 0): + cictype = 6102 + print(cictype) + +if (len(sys.argv) > 1): + boot_extract(sys.argv[1]) +else: + boot_write() \ No newline at end of file diff --git a/ver/symbols/symbol_addrs.jpn.v79.txt b/ver/symbols/symbol_addrs.jpn.v79.txt index 4bb3c389..ef421d49 100644 --- a/ver/symbols/symbol_addrs.jpn.v79.txt +++ b/ver/symbols/symbol_addrs.jpn.v79.txt @@ -937,20 +937,20 @@ debug_print_fixed_matrix_values = 0x8006A034; debug_print_float_matrix_values = 0x8006A10C; // controller.c .text -get_si_mesg_queue = 0x8006A1D0; -init_controllers = 0x8006A1DC; -handle_save_data_and_read_controller = 0x8006A294; -initialise_player_ids = 0x8006A504; +si_mesg = 0x8006A1D0; +input_init = 0x8006A1DC; +input_update = 0x8006A294; +input_assign_players = 0x8006A504; charselect_assign_players = 0x8006A528; -get_player_id = 0x8006A5C8; -swap_player_1_and_2_ids = 0x8006A5DC; -get_buttons_held_from_player = 0x8006A5F8; -get_buttons_pressed_from_player = 0x8006A624; -get_buttons_released_from_player = 0x8006A648; -clamp_joystick_x_axis = 0x8006A66C; -clamp_joystick_y_axis = 0x8006A6B0; -clamp_joystick = 0x8006A6F4; -disable_button_mask = 0x8006A770; +input_player_id = 0x8006A5C8; +input_swap_id = 0x8006A5DC; +input_held = 0x8006A5F8; +input_pressed = 0x8006A624; +input_released = 0x8006A648; +input_clamp_stick_x = 0x8006A66C; +input_clamp_stick_y = 0x8006A6B0; +input_clamp_stick_mag = 0x8006A6F4; +drm_disable_input = 0x8006A770; // game.c .text init_level_globals = 0x8006A780; diff --git a/ver/symbols/symbol_addrs.pal.v77.txt b/ver/symbols/symbol_addrs.pal.v77.txt index 290ef866..647d3d2f 100644 --- a/ver/symbols/symbol_addrs.pal.v77.txt +++ b/ver/symbols/symbol_addrs.pal.v77.txt @@ -935,20 +935,20 @@ debug_print_fixed_matrix_values = 0x80069F64; debug_print_float_matrix_values = 0x8006A03C; // controller.c .text -get_si_mesg_queue = 0x8006A100; -init_controllers = 0x8006A10C; -handle_save_data_and_read_controller = 0x8006A1C4; -initialise_player_ids = 0x8006A434; +si_mesg = 0x8006A100; +input_init = 0x8006A10C; +input_update = 0x8006A1C4; +input_assign_players = 0x8006A434; charselect_assign_players = 0x8006A458; -get_player_id = 0x8006A4F8; -swap_player_1_and_2_ids = 0x8006A50C; -get_buttons_held_from_player = 0x8006A528; -get_buttons_pressed_from_player = 0x8006A554; -get_buttons_released_from_player = 0x8006A578; -clamp_joystick_x_axis = 0x8006A59C; -clamp_joystick_y_axis = 0x8006A5E0; -clamp_joystick = 0x8006A624; -disable_button_mask = 0x8006A6A0; +input_player_id = 0x8006A4F8; +input_swap_id = 0x8006A50C; +input_held = 0x8006A528; +input_pressed = 0x8006A554; +input_released = 0x8006A578; +input_clamp_stick_x = 0x8006A59C; +input_clamp_stick_y = 0x8006A5E0; +input_clamp_stick_mag = 0x8006A624; +drm_disable_input = 0x8006A6A0; // game.c .text init_level_globals = 0x8006A6B0; diff --git a/ver/symbols/symbol_addrs.pal.v80.txt b/ver/symbols/symbol_addrs.pal.v80.txt index ddaf8950..0449c37a 100644 --- a/ver/symbols/symbol_addrs.pal.v80.txt +++ b/ver/symbols/symbol_addrs.pal.v80.txt @@ -879,20 +879,20 @@ set_camera_shake_by_distance = 0x8006A054; set_camera_shake = 0x8006A168; debug_print_fixed_matrix_values = 0x8006A1A4; debug_print_float_matrix_values = 0x8006A27C; -get_si_mesg_queue = 0x8006A340; -init_controllers = 0x8006A34C; -handle_save_data_and_read_controller = 0x8006A404; -initialise_player_ids = 0x8006A674; +si_mesg = 0x8006A340; +input_init = 0x8006A34C; +input_update = 0x8006A404; +input_assign_players = 0x8006A674; charselect_assign_players = 0x8006A698; -get_player_id = 0x8006A738; -swap_player_1_and_2_ids = 0x8006A74C; -get_buttons_held_from_player = 0x8006A768; -get_buttons_pressed_from_player = 0x8006A794; -get_buttons_released_from_player = 0x8006A7B8; -clamp_joystick_x_axis = 0x8006A7DC; -clamp_joystick_y_axis = 0x8006A820; -clamp_joystick = 0x8006A864; -disable_button_mask = 0x8006A8E0; +input_player_id = 0x8006A738; +input_swap_id = 0x8006A74C; +input_held = 0x8006A768; +input_pressed = 0x8006A794; +input_released = 0x8006A7B8; +input_clamp_stick_x = 0x8006A7DC; +input_clamp_stick_y = 0x8006A820; +input_clamp_stick_mag = 0x8006A864; +drm_disable_input = 0x8006A8E0; init_level_globals = 0x8006A8F0; func_8006ABB4 = 0x8006ADF4; search_level_properties_forwards = 0x8006AE40; diff --git a/ver/symbols/symbol_addrs.us.v77.txt b/ver/symbols/symbol_addrs.us.v77.txt index ef10e315..0df9ceef 100644 --- a/ver/symbols/symbol_addrs.us.v77.txt +++ b/ver/symbols/symbol_addrs.us.v77.txt @@ -935,20 +935,20 @@ debug_print_fixed_matrix_values = 0x80069F64; debug_print_float_matrix_values = 0x8006A03C; // controller.c .text -get_si_mesg_queue = 0x8006A100; -init_controllers = 0x8006A10C; -handle_save_data_and_read_controller = 0x8006A1C4; -initialise_player_ids = 0x8006A434; +si_mesg = 0x8006A100; +input_init = 0x8006A10C; +input_update = 0x8006A1C4; +input_assign_players = 0x8006A434; charselect_assign_players = 0x8006A458; -get_player_id = 0x8006A4F8; -swap_player_1_and_2_ids = 0x8006A50C; -get_buttons_held_from_player = 0x8006A528; -get_buttons_pressed_from_player = 0x8006A554; -get_buttons_released_from_player = 0x8006A578; -clamp_joystick_x_axis = 0x8006A59C; -clamp_joystick_y_axis = 0x8006A5E0; -clamp_joystick = 0x8006A624; -disable_button_mask = 0x8006A6A0; +input_player_id = 0x8006A4F8; +input_swap_id = 0x8006A50C; +input_held = 0x8006A528; +input_pressed = 0x8006A554; +input_released = 0x8006A578; +input_clamp_stick_x = 0x8006A59C; +input_clamp_stick_y = 0x8006A5E0; +input_clamp_stick_mag = 0x8006A624; +drm_disable_input = 0x8006A6A0; // game.c .text init_level_globals = 0x8006A6B0; diff --git a/ver/symbols/symbol_addrs.us.v80.txt b/ver/symbols/symbol_addrs.us.v80.txt index b99b632c..94e875c6 100644 --- a/ver/symbols/symbol_addrs.us.v80.txt +++ b/ver/symbols/symbol_addrs.us.v80.txt @@ -879,20 +879,20 @@ set_camera_shake_by_distance = 0x8006A054; set_camera_shake = 0x8006A168; debug_print_fixed_matrix_values = 0x8006A1A4; debug_print_float_matrix_values = 0x8006A27C; -get_si_mesg_queue = 0x8006A340; -init_controllers = 0x8006A34C; -handle_save_data_and_read_controller = 0x8006A404; -initialise_player_ids = 0x8006A674; +si_mesg = 0x8006A340; +input_init = 0x8006A34C; +input_update = 0x8006A404; +input_assign_players = 0x8006A674; charselect_assign_players = 0x8006A698; -get_player_id = 0x8006A738; -swap_player_1_and_2_ids = 0x8006A74C; -get_buttons_held_from_player = 0x8006A768; -get_buttons_pressed_from_player = 0x8006A794; -get_buttons_released_from_player = 0x8006A7B8; -clamp_joystick_x_axis = 0x8006A7DC; -clamp_joystick_y_axis = 0x8006A820; -clamp_joystick = 0x8006A864; -disable_button_mask = 0x8006A8E0; +input_player_id = 0x8006A738; +input_swap_id = 0x8006A74C; +input_held = 0x8006A768; +input_pressed = 0x8006A794; +input_released = 0x8006A7B8; +input_clamp_stick_x = 0x8006A7DC; +input_clamp_stick_y = 0x8006A820; +input_clamp_stick_mag = 0x8006A864; +drm_disable_input = 0x8006A8E0; init_level_globals = 0x8006A8F0; func_8006ABB4 = 0x8006ADF4; search_level_properties_forwards = 0x8006AE40;