From 29deabc35a3b9b9bdbd6b759e1fccabe16d3195c Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Sat, 20 May 2023 21:14:40 -0400 Subject: [PATCH] Add files --- include/JSystem/JKernel/JKREnum.h | 20 ++++ include/MSL_C/math.h | 20 ++++ include/dolphin/os/OSModule.h | 72 ++++++++++++++ include/dolphin/os/OSReset.h | 25 +++++ include/dolphin/pad.h | 28 ++++++ include/game_h.h | 16 +++ include/initial_menu.h | 17 ++++ include/jaudio_NES/game64.h | 18 ++++ include/libultra/contreaddata.h | 16 +++ include/libultra/initialize.h | 16 +++ include/libultra/shutdown.h | 16 +++ include/nintendo_hi_0.h | 18 ++++ include/sys_math.h | 18 ++++ rel/m_controller.c | 157 ++++++++++++++++++++++++++++++ src/libultra/contreaddata.c | 3 + src/nintendo_hi_0.c | 5 + 16 files changed, 465 insertions(+) create mode 100644 include/JSystem/JKernel/JKREnum.h create mode 100644 include/MSL_C/math.h create mode 100644 include/dolphin/os/OSModule.h create mode 100644 include/dolphin/os/OSReset.h create mode 100644 include/dolphin/pad.h create mode 100644 include/game_h.h create mode 100644 include/initial_menu.h create mode 100644 include/jaudio_NES/game64.h create mode 100644 include/libultra/contreaddata.h create mode 100644 include/libultra/initialize.h create mode 100644 include/libultra/shutdown.h create mode 100644 include/nintendo_hi_0.h create mode 100644 include/sys_math.h create mode 100644 rel/m_controller.c create mode 100644 src/libultra/contreaddata.c create mode 100644 src/nintendo_hi_0.c diff --git a/include/JSystem/JKernel/JKREnum.h b/include/JSystem/JKernel/JKREnum.h new file mode 100644 index 00000000..8652231b --- /dev/null +++ b/include/JSystem/JKernel/JKREnum.h @@ -0,0 +1,20 @@ +#ifndef JKRENUM_H +#define JKRENUM_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum JKRExpandSwitch { + EXPAND_SWITCH_DEFAULT, /* Do nothing? treated same as 2 */ + EXPAND_SWITCH_DECOMPRESS, /* Check for compression and decompress */ + EXPAND_SWITCH_NONE /* Do nothing */ +} JKRExpandSwitch; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/MSL_C/math.h b/include/MSL_C/math.h new file mode 100644 index 00000000..72e16597 --- /dev/null +++ b/include/MSL_C/math.h @@ -0,0 +1,20 @@ +#ifndef MATH_H +#define MATH_H + +#include "types.h" +#include "MSL_C/w_math.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PI 3.14159265358979323846 +#define F_PI ((f32)PI) + +#define SQRTF(f) (__frsqrte(f)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/dolphin/os/OSModule.h b/include/dolphin/os/OSModule.h new file mode 100644 index 00000000..ba06e28f --- /dev/null +++ b/include/dolphin/os/OSModule.h @@ -0,0 +1,72 @@ +#ifndef DOLPHIN_OSMODULE_H +#define DOLPHIN_OSMODULE_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OSModuleInfo_s OSModuleInfo; + +typedef struct OSModuleQueue_s { + OSModuleInfo* head; + OSModuleInfo* tail; +} OSModuleQueue; + +typedef struct OSModuleLink_s { + OSModuleInfo* next; + OSModuleInfo* prev; +} OSModuleLink; + +typedef struct OSModuleInfo_s { + u32 id; + OSModuleLink link; + u32 numSections; + u32 sectionInfoOfs; + u32 nameOfs; + u32 nameSize; + u32 version; +} OSModuleInfo; + +typedef struct OSModuleHeader_s { + OSModuleInfo info; + u32 bssSize; + u32 relOfs; + u32 impOfs; + u32 impSize; + + u8 prologSection; + u8 epilogSection; + u8 unresolvedSection; + u8 bssSection; + + u32 prolog; + u32 epilog; + u32 unresolved; + /* OS_MODULE_VERSION >= 2 */ + + u32 align; + u32 bssAlign; +} OSModuleHeader; + +typedef struct OSSectionInfo_s { + u32 offset; + u32 size; +} OSSectionInfo; + +#define OSGetSectionInfo(module) \ + ((OSSectionInfo*) (((OSModuleInfo*) (module))->sectionInfoOfs)) + +#define OS_SECTIONINFO_EXEC 1 +#define OS_SECTIONINFO_OFFSET(offset) ((offset) & ~OS_SECTIONINFO_EXEC) + +void OSSetStringTable (const void* strTable); +BOOL OSLink(OSModuleInfo* module, void* bss); +BOOL OSUnlink(OSModuleInfo* module); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/dolphin/os/OSReset.h b/include/dolphin/os/OSReset.h new file mode 100644 index 00000000..a5d74d43 --- /dev/null +++ b/include/dolphin/os/OSReset.h @@ -0,0 +1,25 @@ +#ifndef OSRESET_H +#define OSRESET_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OS_RESETCODE_RESTART 0x80000000 + +#define OS_RESET_RESTART 0 +#define OS_RESET_HOTRESET 1 /* Soft reset */ +#define OS_RESET_SHUTDOWN 2 + +u32 OSGetResetCode(); +void OSResetSystem(int reset, u32 resetCode, BOOL forceMenu); +BOOL OSGetResetSwitchState(); +void OSGetSaveRegion(void** start, void** end); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/dolphin/pad.h b/include/dolphin/pad.h new file mode 100644 index 00000000..1c1980df --- /dev/null +++ b/include/dolphin/pad.h @@ -0,0 +1,28 @@ +#ifndef DOLPHIN_PAD_H +#define DOLPHIN_PAD_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PAD_BUTTON_LEFT 0x0001 +#define PAD_BUTTON_RIGHT 0x0002 +#define PAD_BUTTON_DOWN 0x0004 +#define PAD_BUTTON_UP 0x0008 +#define PAD_TRIGGER_Z 0x0010 +#define PAD_TRIGGER_R 0x0020 +#define PAD_TRIGGER_L 0x0040 +#define PAD_BUTTON_A 0x0100 +#define PAD_BUTTON_B 0x0200 +#define PAD_BUTTON_X 0x0400 +#define PAD_BUTTON_Y 0x0800 +#define PAD_BUTTON_MENU 0x1000 +#define PAD_BUTTON_START 0x1000 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/game_h.h b/include/game_h.h new file mode 100644 index 00000000..b9927e97 --- /dev/null +++ b/include/game_h.h @@ -0,0 +1,16 @@ +#ifndef GAME_H_H +#define GAME_H_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct game_s GAME; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/initial_menu.h b/include/initial_menu.h new file mode 100644 index 00000000..4003c8ce --- /dev/null +++ b/include/initial_menu.h @@ -0,0 +1,17 @@ +#ifndef INITIAL_MENU_H +#define INITIAL_MENU_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void initial_menu_init(); +extern void initial_menu_cleanup(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/jaudio_NES/game64.h b/include/jaudio_NES/game64.h new file mode 100644 index 00000000..c7430c6f --- /dev/null +++ b/include/jaudio_NES/game64.h @@ -0,0 +1,18 @@ +#ifndef GAME64_H +#define GAME64_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void Na_InitAudio(void (*fatal_callback)(), u8* load_addr, size_t load_size, u8* bootsound, size_t bootsound_size, BOOL cut_flag); +extern void Na_GameFrame(); +extern u8 Na_CheckNeosBoot(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libultra/contreaddata.h b/include/libultra/contreaddata.h new file mode 100644 index 00000000..95d88199 --- /dev/null +++ b/include/libultra/contreaddata.h @@ -0,0 +1,16 @@ +#ifndef CONTREADDATA_H +#define CONTREADDATA_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern u8 __osResetSwitchPressed; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libultra/initialize.h b/include/libultra/initialize.h new file mode 100644 index 00000000..d9c9667e --- /dev/null +++ b/include/libultra/initialize.h @@ -0,0 +1,16 @@ +#ifndef INITIALIZE_H +#define INITIALIZE_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void __osInitialize_common(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libultra/shutdown.h b/include/libultra/shutdown.h new file mode 100644 index 00000000..f25fc8f1 --- /dev/null +++ b/include/libultra/shutdown.h @@ -0,0 +1,16 @@ +#ifndef SHUTDOWN_H +#define SHUTDOWN_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void osShutdownStart(int shutdown_type); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/nintendo_hi_0.h b/include/nintendo_hi_0.h new file mode 100644 index 00000000..6c11eafc --- /dev/null +++ b/include/nintendo_hi_0.h @@ -0,0 +1,18 @@ +#ifndef NINTENDO_HI_0_H +#define NINTENDO_HI_0_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define NINTENDO_HI_0_SIZE 0x9900 +#define NINTENDO_HI_0_AW_SIZE 0x66A0 +extern u8 nintendo_hi_0[NINTENDO_HI_0_SIZE]; // This should be nintendo_hi_0.aw + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/sys_math.h b/include/sys_math.h new file mode 100644 index 00000000..2c5feaf5 --- /dev/null +++ b/include/sys_math.h @@ -0,0 +1,18 @@ +#ifndef SYS_MATH_H +#define SYS_MATH_H + +#include "types.h" +#include "MSL_C/math.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern s16 atans_table(f32 x, f32 y); +extern f32 atanf_table(f32 x, f32 y); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/rel/m_controller.c b/rel/m_controller.c new file mode 100644 index 00000000..dbe93033 --- /dev/null +++ b/rel/m_controller.c @@ -0,0 +1,157 @@ +#include "m_controller.h" +#include "game.h" +#include "m_lib.h" +#include "m_event.h" +#include "MSL_C/w_math.h" + +/** + * @brief Constructor for MCON. + **/ +extern void mCon_ct() { } + +/** + * @brief Destructor for MCON. + **/ +extern void mCon_dt() { } + +/** + * @brief Controller input processing function. + * Only processes port 1 controller. + * + * @param mcon Pointer to MCON struct which will be updated + * @param stick_x Joystick X position + * @param stick_y Joystick Y position + **/ +extern void mCon_calc(MCON* mcon, f32 stick_x, f32 stick_y) { + f32 t; + + mcon->last_move_pX = mcon->move_pX; + mcon->last_move_pY = mcon->move_pY; + mcon->last_move_pR = mcon->move_pR; + mcon->last_move_angle = mcon->move_angle; + + mcon->last_adjusted_pX = mcon->adjusted_pX; + mcon->last_adjusted_pY = mcon->adjusted_pY; + mcon->last_adjusted_pR = mcon->adjusted_pR; + + t = sqrtf(stick_x * stick_x + stick_y * stick_y); + + if (t <= STICK_MIN) { + mcon->move_pX = 0.0f; + mcon->move_pY = 0.0f; + mcon->move_pR = 0.0f; + + mcon->adjusted_pX = 0.0f; + mcon->adjusted_pY = 0.0f; + mcon->adjusted_pR = 0.0f; + } + else { + s16 stick_angle = atans_table(stick_x, stick_y); + if (t > STICK_MAX) { + stick_x = cos_s(stick_angle) * STICK_MAX; + stick_y = sin_s(stick_angle) * STICK_MAX; + t = STICK_MAX; + } + + mcon->move_angle = stick_angle; + mcon->move_pX = check_percent_abs(stick_x, STICK_MIN, STICK_MAX, STICK_UNCORRECTED_SCALE, 0); + mcon->move_pY = check_percent_abs(stick_y, STICK_MIN, STICK_MAX, STICK_UNCORRECTED_SCALE, 0); + mcon->move_pR = check_percent_abs( t, STICK_MIN, STICK_MAX, STICK_UNCORRECTED_SCALE, 0); + + mcon->adjusted_pX = check_percent_abs(stick_x, STICK_MIN, STICK_MAX, STICK_CORRECTED_SCALE, 1); + mcon->adjusted_pY = check_percent_abs(stick_y, STICK_MIN, STICK_MAX, STICK_CORRECTED_SCALE, 1); + mcon->adjusted_pR = check_percent_abs( t, STICK_MIN, STICK_MAX, STICK_CORRECTED_SCALE, 1); + } +} + +/** + * @brief Controller main process. + * + * @param game Pointer to current GAME structure + **/ +extern void mCon_main(GAME* game) { + f32 stick_x = getJoystick_X(); + f32 stick_y = getJoystick_Y(); + + mCon_calc(&game->mcon, stick_x, stick_y); +} + +/** + * @brief Checks if a specific button combination currently pressed. + * + * @param mask Button combination to check + * @return TRUE when the button combination is pressed, FALSE otherwise + **/ +extern int chkButton(u16 mask) { + if (mEv_CheckTitleDemo() > 0) { + return FALSE; + } + + return (mask & (gamePT->pads[0].now.button)) == mask; +} + +/** + * @brief Gets the currently pressed buttons. + * + * @return Pressed buttons + **/ +extern u16 getButton() { + if (mEv_CheckTitleDemo() > 0) { + return BUTTON_NONE; + } + + return gamePT->pads[0].now.button; +} + +/** + * @brief Checks if a specific button combination was pressed this frame. + * + * @param mask Button combination to check + * @return TRUE when the button combination was pressed this frame, FALSE otherwise + **/ +extern int chkTrigger(u16 mask) { + if (mEv_CheckTitleDemo() > 0) { + return FALSE; + } + + return (mask & (gamePT->pads[0].on.button)) == mask; +} + +/** + * @brief Gets the buttons pressed on the current frame. + * + * @return Buttons pressed on the current frame + **/ +extern u16 getTrigger() { + if (mEv_CheckTitleDemo() > 0) { + return BUTTON_NONE; + } + + return gamePT->pads[0].on.button; +} + +/** + * @brief Gets the current joystick X position. + * + * @return Joystick X position + **/ +extern int getJoystick_X() { + if (mEv_CheckTitleDemo() > 0) { + return 0; + } + + return gamePT->pads[0].now.stick_x; +} + +/** + * @brief Gets the current joystick Y position. + * + * @return Joystick Y position + **/ +extern int getJoystick_Y() { + if (mEv_CheckTitleDemo() > 0) { + return 0; + } + + return gamePT->pads[0].now.stick_y; +} diff --git a/src/libultra/contreaddata.c b/src/libultra/contreaddata.c new file mode 100644 index 00000000..1d5ebed3 --- /dev/null +++ b/src/libultra/contreaddata.c @@ -0,0 +1,3 @@ +#include "contreaddata.h" + +u8 __osResetSwitchPressed; diff --git a/src/nintendo_hi_0.c b/src/nintendo_hi_0.c new file mode 100644 index 00000000..5ec1abc2 --- /dev/null +++ b/src/nintendo_hi_0.c @@ -0,0 +1,5 @@ +#include "nintendo_hi_0.h" + +u8 nintendo_hi_0[] ATTRIBUTE_ALIGN(32) = { +#include "assets/nintendo_hi_0.inc" +};