├── clean.bat ├── screenshot.png ├── src ├── decomp │ ├── audio │ │ ├── globals_start.c │ │ ├── load_dat.c │ │ ├── load_dat.h │ │ ├── seqplayer.h │ │ ├── effects.h │ │ ├── playback.h │ │ ├── external.h │ │ ├── synthesis.h │ │ ├── load.h │ │ ├── data.h │ │ └── heap.h │ ├── game │ │ ├── behavior_actions.h │ │ ├── mario_actions_airborne.h │ │ ├── mario_actions_automatic.h │ │ ├── mario_actions_submerged.h │ │ ├── platform_displacement.h │ │ ├── mario_actions_object.h │ │ ├── object_stuff.h │ │ ├── mario_actions_moving.h │ │ ├── mario_actions_cutscene.h │ │ ├── behavior_actions.c │ │ ├── mario_step.h │ │ ├── rendering_graph_node.h │ │ ├── mario_misc.h │ │ ├── mario_actions_stationary.h │ │ ├── mario.h │ │ ├── level_update.h │ │ ├── platform_displacement.c │ │ └── area.h │ ├── engine │ │ ├── guMtxF2L.h │ │ ├── surface_collision.h │ │ ├── guMtxF2L.c │ │ ├── graph_node_manager.c │ │ ├── geo_layout.h │ │ └── math_util.h │ ├── include │ │ ├── PR │ │ │ ├── os_misc.h │ │ │ ├── os_libc.h │ │ │ ├── libultra.h │ │ │ ├── os_internal.h │ │ │ ├── libaudio.h │ │ │ ├── os_time.h │ │ │ ├── ucode.h │ │ │ ├── ultratypes.h │ │ │ ├── os_thread.h │ │ │ ├── os_pi.h │ │ │ ├── os_ai.h │ │ │ ├── os_rdp.h │ │ │ ├── os_cache.h │ │ │ ├── os_vi.h │ │ │ ├── os_tlb.h │ │ │ ├── os_eeprom.h │ │ │ ├── sptask.h │ │ │ └── os_exception.h │ │ ├── platform_info.h │ │ ├── ultra64.h │ │ ├── level_misc_macros.h │ │ ├── mario_geo_switch_case_ids.h │ │ ├── command_macros_base.h │ │ ├── seq_ids.h │ │ ├── macros.h │ │ └── special_preset_names.h │ ├── memory.h │ ├── global_state.c │ ├── tools │ │ ├── convUtils.h │ │ ├── libmio0.h │ │ ├── convTypes.h │ │ ├── n64graphics.h │ │ └── utils.h │ ├── global_state.h │ ├── memory.c │ ├── pc │ │ ├── alBnkfNew.c │ │ ├── libultra_internal.h │ │ ├── libaudio_internal.h │ │ └── mixer.h │ └── shim.h ├── debug_print.c ├── Classic64_audio.h ├── load_audio_data.h ├── play_sound.h ├── load_anim_data.h ├── gfx_adapter_commands.h ├── obj_pool.h ├── debug_print.h ├── Classic64_network.h ├── Classic64_events.h ├── fake_interaction.h ├── gfx_adapter.h ├── play_sound.c ├── sha1 │ └── sha1.h ├── load_surfaces.h ├── obj_pool.c ├── load_audio_data.c ├── load_tex_data.h ├── Classic64_settings.h ├── load_tex_data.c ├── Classic64_audio.c ├── Classic64.h ├── Classic64_events.c ├── load_anim_data.c ├── gfx_macros.h └── Classic64_network.c ├── .gitmodules ├── .gitignore ├── test ├── level.h ├── context.h ├── level.c ├── ns_clock.h ├── context.c └── cglm.h ├── MCGalaxy └── README.md ├── dll2lib.bat ├── import-test-collision.py ├── import-mario-geo.py ├── Makefile ├── README.md └── .github └── workflows └── c-cpp.yml /clean.bat: -------------------------------------------------------------------------------- 1 | make clean 2 | PAUSE -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/headshot2017/Classic64/HEAD/screenshot.png -------------------------------------------------------------------------------- /src/decomp/audio/globals_start.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | u64 gAudioGlobalsStartMarker; 4 | -------------------------------------------------------------------------------- /src/debug_print.c: -------------------------------------------------------------------------------- 1 | #include "debug_print.h" 2 | 3 | SM64DebugPrintFunctionPtr g_debug_print_func = NULL; -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ClassiCube"] 2 | path = ClassiCube 3 | url = https://github.com/ClassiCube/ClassiCube.git 4 | -------------------------------------------------------------------------------- /src/Classic64_audio.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASSIC64_AUDIO_H 2 | #define CLASSIC64_AUDIO_H 3 | 4 | void classic64_audio_init(); 5 | 6 | #endif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | src/decomp/mario 2 | /build/ 3 | /dist/ 4 | run-test 5 | *.z64 6 | *.so 7 | compile_commands.json 8 | /.cache/ 9 | *.a 10 | *.exe 11 | *.def 12 | -------------------------------------------------------------------------------- /src/load_audio_data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern bool g_is_audio_initialized; 7 | 8 | extern void load_audio_banks( const uint8_t *rom ); -------------------------------------------------------------------------------- /test/level.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../src/libsm64.h" 4 | 5 | extern const struct SM64Surface surfaces[]; 6 | extern const size_t surfaces_count; 7 | extern const int32_t spawn[3]; 8 | -------------------------------------------------------------------------------- /src/decomp/game/behavior_actions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../include/types.h" 4 | #include "../mario/model.inc.h" 5 | 6 | extern Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx); -------------------------------------------------------------------------------- /src/decomp/engine/guMtxF2L.h: -------------------------------------------------------------------------------- 1 | #ifndef GUMTXF2L_H 2 | #define GUMTXF2L_H 3 | 4 | #include "../include/PR/gbi.h" 5 | 6 | extern void guMtxF2L(float mf[4][4], Mtx *m); 7 | extern void guMtxL2F(float mf[4][4], Mtx *m); 8 | 9 | #endif//GUMTXF2L_H -------------------------------------------------------------------------------- /src/play_sound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "decomp/include/types.h" 4 | #include "libsm64.h" 5 | #include 6 | 7 | extern SM64PlaySoundFunctionPtr g_play_sound_func; 8 | 9 | extern void play_sound( uint32_t soundBits, f32 *pos ); -------------------------------------------------------------------------------- /src/decomp/audio/load_dat.c: -------------------------------------------------------------------------------- 1 | #include "load_dat.h" 2 | 3 | struct seqFile *gSoundDataADSR; 4 | 5 | struct seqFile *gSoundDataRaw; 6 | 7 | struct seqFile *gMusicData; 8 | 9 | #ifndef VERSION_SH 10 | unsigned char* gBankSetsData; 11 | #endif -------------------------------------------------------------------------------- /src/decomp/include/PR/os_misc.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_OS_MISC_H_ 2 | #define _ULTRA64_OS_MISC_H_ 3 | #include "ultratypes.h" 4 | /* Miscellaneous OS functions */ 5 | 6 | void osInitialize(void); 7 | u32 osGetCount(void); 8 | 9 | uintptr_t osVirtualToPhysical(void *); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_airborne.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_AIRBORNE_H 2 | #define MARIO_ACTIONS_AIRBORNE_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | s32 mario_execute_airborne_action(struct MarioState *m); 9 | 10 | #endif // MARIO_ACTIONS_AIRBORNE_H 11 | -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_automatic.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_AUTOMATIC_H 2 | #define MARIO_ACTIONS_AUTOMATIC_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | s32 mario_execute_automatic_action(struct MarioState *m); 9 | 10 | #endif // MARIO_ACTIONS_AUTOMATIC_H 11 | -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_submerged.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_SUBMERGED_H 2 | #define MARIO_ACTIONS_SUBMERGED_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | s32 mario_execute_submerged_action(struct MarioState *m); 9 | 10 | #endif // MARIO_ACTIONS_SUBMERGED_H 11 | -------------------------------------------------------------------------------- /src/load_anim_data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "decomp/include/types.h" 7 | 8 | extern void load_mario_animation(struct MarioAnimation *a, u32 index); 9 | extern void load_mario_anims_from_rom( const uint8_t *rom ); 10 | extern void unload_mario_anims( void ); -------------------------------------------------------------------------------- /src/decomp/audio/load_dat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../tools/convTypes.h" 4 | #include 5 | 6 | extern struct seqFile *gSoundDataADSR; 7 | 8 | extern struct seqFile *gSoundDataRaw; 9 | 10 | extern struct seqFile *gMusicData; 11 | 12 | #ifndef VERSION_SH 13 | extern unsigned char *gBankSetsData; 14 | #endif -------------------------------------------------------------------------------- /src/decomp/game/platform_displacement.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_DISPLACEMENT_H 2 | #define PLATFORM_DISPLACEMENT_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | #include "../include/types.h" 6 | 7 | void update_mario_platform(void); 8 | void apply_mario_platform_displacement(void); 9 | 10 | #endif // PLATFORM_DISPLACEMENT_H 11 | -------------------------------------------------------------------------------- /src/gfx_adapter_commands.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum GFXAdapterCommands 4 | { 5 | GFXCMD_None = 0, 6 | GFXCMD_VertexData, 7 | GFXCMD_Triangle, 8 | GFXCMD_Light, 9 | GFXCMD_Texture, 10 | GFXCMD_SetTileSize, 11 | GFXCMD_SetTextureImage, 12 | GFXCMD_SubDisplayList, 13 | GFXCMD_EndDisplayList, 14 | }; -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_object.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_OBJECT_H 2 | #define MARIO_ACTIONS_OBJECT_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | s32 mario_update_punch_sequence(struct MarioState *m); 9 | s32 mario_execute_object_action(struct MarioState *m); 10 | 11 | #endif // MARIO_ACTIONS_OBJECT_H 12 | -------------------------------------------------------------------------------- /src/decomp/game/object_stuff.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../include/types.h" 4 | 5 | struct Object *hack_allocate_mario(void); 6 | void bhv_mario_update(void); 7 | void create_transformation_from_matrices(Mat4 a0, Mat4 a1, Mat4 a2); 8 | void obj_update_pos_from_parent_transformation(Mat4 a0, struct Object *a1); 9 | void obj_set_gfx_pos_from_pos(struct Object *obj); -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_moving.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_MOVING 2 | #define MARIO_ACTIONS_MOVING 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | void play_step_sound(struct MarioState *m, s16 frame1, s16 frame2); 9 | s32 mario_execute_moving_action(struct MarioState *m); 10 | 11 | #endif // MARIO_ACTIONS_MOVING 12 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_libc.h: -------------------------------------------------------------------------------- 1 | #ifndef _OS_LIBC_H_ 2 | #define _OS_LIBC_H_ 3 | 4 | #ifndef __APPLE__ 5 | #include "ultratypes.h" 6 | 7 | // Old deprecated functions from strings.h, replaced by memcpy/memset. 8 | extern void bcopy(const void *, void *, size_t); 9 | extern void bzero(void *, size_t); 10 | 11 | #endif /* !__APPLE__ */ 12 | #endif /* !_OS_LIBC_H_ */ 13 | -------------------------------------------------------------------------------- /src/obj_pool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct ObjPool 7 | { 8 | size_t size; 9 | void **objects; 10 | }; 11 | 12 | extern uint32_t obj_pool_alloc_index( struct ObjPool *pool, size_t size ); 13 | extern void obj_pool_free_index( struct ObjPool *pool, uint32_t index ); 14 | extern void obj_pool_free_all( struct ObjPool *pool ); -------------------------------------------------------------------------------- /src/debug_print.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "libsm64.h" 4 | #include 5 | 6 | extern SM64DebugPrintFunctionPtr g_debug_print_func; 7 | 8 | #define DEBUG_PRINT( ... ) do { \ 9 | if( g_debug_print_func ) { \ 10 | char debugStr[1024]; \ 11 | sprintf( debugStr, __VA_ARGS__ ); \ 12 | g_debug_print_func( debugStr ); \ 13 | } \ 14 | } while(0) 15 | -------------------------------------------------------------------------------- /src/decomp/include/platform_info.h: -------------------------------------------------------------------------------- 1 | #ifndef PLATFORM_INFO_H 2 | #define PLATFORM_INFO_H 3 | 4 | #ifdef TARGET_N64 5 | #define IS_64_BIT 0 6 | #define IS_BIG_ENDIAN 1 7 | #else 8 | #include 9 | #define IS_64_BIT (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFU) 10 | #define IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 11 | #endif 12 | 13 | #define DOUBLE_SIZE_ON_64_BIT(size) ((size) * 2) 14 | 15 | #endif // PLATFORM_INFO_H 16 | -------------------------------------------------------------------------------- /src/decomp/include/PR/libultra.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBULTRA_H 2 | #define _LIBULTRA_H 3 | 4 | #define TV_TYPE_NTSC 1 5 | #define TV_TYPE_PAL 0 6 | #define TV_TYPE_MPAL 2 7 | 8 | #define RESET_TYPE_COLD_RESET 0 9 | #define RESET_TYPE_NMI 1 10 | #define RESET_TYPE_BOOT_DISK 2 11 | 12 | extern u32 osTvType; 13 | extern u32 osRomBase; 14 | extern u32 osResetType; 15 | extern u32 osMemSize; 16 | extern u8 osAppNmiBuffer[64]; 17 | 18 | #endif /* _LIBULTRA_H */ 19 | -------------------------------------------------------------------------------- /src/Classic64_network.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASSIC64_NETWORK_H 2 | #define CLASSIC64_NETWORK_H 3 | 4 | #include "../ClassiCube/src/Core.h" 5 | 6 | // from Stream.h 7 | cc_uint16 Stream_GetU16_BE(const cc_uint8* data); 8 | cc_uint32 Stream_GetU32_BE(const cc_uint8* data); 9 | void Stream_SetU16_BE(cc_uint8* data, cc_uint16 value); 10 | void Stream_SetU32_BE(cc_uint8* data, cc_uint32 value); 11 | 12 | void sendMarioColors(); 13 | void sendMarioTick(); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/decomp/memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/types.h" 4 | 5 | struct AllocOnlyPool; 6 | 7 | extern void memory_init(void); 8 | extern void memory_terminate(void); 9 | 10 | extern struct AllocOnlyPool *alloc_only_pool_init(void); 11 | extern void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size); 12 | extern void alloc_only_pool_free(struct AllocOnlyPool *pool); 13 | 14 | extern void display_list_pool_reset(void); 15 | extern void *alloc_display_list(u32 size); -------------------------------------------------------------------------------- /src/Classic64_events.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASSIC64_EVENTS_H 2 | #define CLASSIC64_EVENTS_H 3 | 4 | #include "../ClassiCube/src/String.h" 5 | 6 | void OnChatMessage(void* obj, const cc_string* msg, int msgType); 7 | void OnHacksChanged(void* obj); 8 | void OnKeyDown(void* obj, int key, cc_bool repeating); 9 | void OnKeyUp(void* obj, int key); 10 | void OnContextLost(void* obj); 11 | void OnContextRecreated(void* obj); 12 | void OnPluginMessage(void* obj, cc_uint8 channel, cc_uint8* data); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_OS_INTERNAL_H_ 2 | #define _ULTRA64_OS_INTERNAL_H_ 3 | #include "os_message.h" 4 | 5 | /* Internal functions used by the operating system */ 6 | /* Do not include this header in application code */ 7 | 8 | /* Variables */ 9 | 10 | //extern u64 osClockRate; 11 | 12 | /* Functions */ 13 | 14 | /*u32 __osProbeTLB(void *); 15 | u32 __osDisableInt(void); 16 | void __osRestoreInt(u32);*/ 17 | OSThread *__osGetCurrFaultedThread(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /test/context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __APPLE__ 6 | # include 7 | # include 8 | #elif _WIN32 9 | # define HAVE_M_PI 10 | # include 11 | # include 12 | #else 13 | # include 14 | # include 15 | #endif 16 | 17 | extern void context_init( const char *title, int width, int height ); 18 | extern bool context_flip_frame_poll_events( void ); 19 | extern SDL_GameController *context_get_controller( void ); 20 | extern void context_terminate( void ); -------------------------------------------------------------------------------- /src/decomp/include/PR/libaudio.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_LIBAUDIO_H_ 2 | #define _ULTRA64_LIBAUDIO_H_ 3 | 4 | #include "abi.h" 5 | #include 6 | 7 | typedef struct 8 | { 9 | u8 *offset __attribute__((aligned (8))); 10 | s32 len __attribute__((aligned (8))); 11 | } ALSeqData; 12 | 13 | typedef struct 14 | { 15 | unsigned short revision; 16 | unsigned short seqCount; 17 | unsigned int pad; 18 | ALSeqData seqArray[1]; 19 | } __attribute__((aligned (16))) ALSeqFile; 20 | 21 | void alSeqFileNew(ALSeqFile *f, u8 *base); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/decomp/global_state.c: -------------------------------------------------------------------------------- 1 | #include "global_state.h" 2 | 3 | #include 4 | #include 5 | 6 | struct GlobalState *g_state = 0; 7 | 8 | struct GlobalState *global_state_create(void) 9 | { 10 | struct GlobalState *state = malloc( sizeof( struct GlobalState )); 11 | memset( state, 0, sizeof( struct GlobalState )); 12 | state->msSwimStrength = MIN_SWIM_STRENGTH; 13 | return state; 14 | } 15 | 16 | void global_state_bind(struct GlobalState *state) 17 | { 18 | g_state = state; 19 | } 20 | 21 | void global_state_delete(struct GlobalState *state) 22 | { 23 | free( state ); 24 | } -------------------------------------------------------------------------------- /src/fake_interaction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "decomp/include/types.h" 3 | 4 | u32 fake_determine_knockback_action(struct MarioState *m, s32 damage,float xSrc,float ySrc,float zSrc); 5 | s16 fake_mario_obj_angle_to_object(struct MarioState *m, float xSrc,float zSrc); 6 | uint32_t fake_damage_knock_back(struct MarioState *m, uint32_t damage,uint32_t interactionSubtype,float xSrc,float ySrc,float zSrc); 7 | u32 fake_interact_hit_from_below(struct MarioState *m, float x, float y, float z, float hitboxHeight); 8 | u32 fake_interact_bounce_top(struct MarioState *m, float x, float y, float z, float hitboxHeight); -------------------------------------------------------------------------------- /src/decomp/include/PR/os_time.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_TIME_H_ 2 | #define _ULTRA64_TIME_H_ 3 | 4 | #include "ultratypes.h" 5 | #include "os_message.h" 6 | 7 | /* Types */ 8 | 9 | typedef struct OSTimer_str 10 | { 11 | struct OSTimer_str *next; 12 | struct OSTimer_str *prev; 13 | u64 interval; 14 | u64 remaining; 15 | OSMesgQueue *mq; 16 | OSMesg *msg; 17 | } OSTimer; 18 | 19 | typedef u64 OSTime; 20 | 21 | /* Functions */ 22 | 23 | OSTime osGetTime(void); 24 | void osSetTime(OSTime time); 25 | u32 osSetTimer(OSTimer *, OSTime, OSTime, OSMesgQueue *, OSMesg); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/gfx_adapter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "decomp/engine/graph_node.h" 4 | #include "libsm64.h" 5 | 6 | // Commented out in gbi.h - Replaced here 7 | #define gDPPipeSync(pkt) ({}) 8 | #define gSPSetGeometryMode(pkt, word) ({}) 9 | #define gSPClearGeometryMode(pkt, word) ({}) 10 | #define gDPFillRectangle(pkt, ulx, uly, lrx, lry) ({}) 11 | #define gSPViewport(pkt, v) ({}) 12 | extern void gSPMatrix( void *pkt, Mtx *m, uint8_t flags ); 13 | extern void gSPDisplayList( void *pkt, struct DisplayListNode *dl ); 14 | 15 | extern void gfx_adapter_bind_output_buffers( struct SM64MarioGeometryBuffers *outBuffers ); -------------------------------------------------------------------------------- /MCGalaxy/README.md: -------------------------------------------------------------------------------- 1 | # Classic64-MCGalaxy 2 | Plugin for MCGalaxy servers which will enhance the Classic64 multiplayer experience. 3 | * Sync custom Mario colors across players 4 | * Sync changes on Mario's cap to other players 5 | * Sends your Mario inputs to other players (to display crouching, punching, etc) for the best experience 6 | * Switching to Mario with the client command `/client mario64 force` will be displayed to other players 7 | 8 | You can also use some specific MOTD flags: 9 | * `+mario64` allows switching to Mario even when hacks are disabled 10 | * `-mario64` forcefully denies switching to Mario 11 | -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_cutscene.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_CUTSCENE_H 2 | #define MARIO_ACTIONS_CUTSCENE_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/macros.h" 7 | #include "../include/types.h" 8 | 9 | void print_displaying_credits_entry(void); 10 | void bhv_end_peach_loop(void); 11 | void bhv_end_toad_loop(void); 12 | s32 geo_switch_peach_eyes(s32 run, struct GraphNode *node, UNUSED s32 a2); 13 | s32 mario_ready_to_speak(void); 14 | s32 set_mario_npc_dialog(s32 actionArg); 15 | s32 mario_execute_cutscene_action(struct MarioState *m); 16 | 17 | #endif // MARIO_ACTIONS_CUTSCENE_H 18 | -------------------------------------------------------------------------------- /src/decomp/include/PR/ucode.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_UCODE_H_ 2 | #define _ULTRA64_UCODE_H_ 3 | 4 | #define SP_DRAM_STACK_SIZE8 0x400 5 | #define SP_UCODE_SIZE 0x1000 6 | #define SP_UCODE_DATA_SIZE 0x800 7 | 8 | // standard boot ucode 9 | extern u64 rspF3DBootStart[], rspF3DBootEnd[]; 10 | 11 | // F3D ucode 12 | extern u64 rspF3DStart[], rspF3DEnd[]; 13 | 14 | // F3D ucode data 15 | extern u64 rspF3DDataStart[], rspF3DDataEnd[]; 16 | 17 | // aspMain (audio) ucode 18 | extern u64 rspAspMainStart[], rspAspMainEnd[]; 19 | 20 | // aspMain ucode data 21 | extern u64 rspAspMainDataStart[], rspAspMainDataEnd[]; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/decomp/audio/seqplayer.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SEQPLAYER_H 2 | #define AUDIO_SEQPLAYER_H 3 | 4 | #include 5 | 6 | #include "internal.h" 7 | #include "playback.h" 8 | 9 | void seq_channel_layer_disable(struct SequenceChannelLayer *seqPlayer); 10 | void sequence_channel_disable(struct SequenceChannel *seqPlayer); 11 | void sequence_player_disable(struct SequencePlayer* seqPlayer); 12 | void audio_list_push_back(struct AudioListItem *list, struct AudioListItem *item); 13 | void *audio_list_pop_back(struct AudioListItem *list); 14 | void process_sequences(s32 iterationsRemaining); 15 | void init_sequence_player(u32 player); 16 | void init_sequence_players(void); 17 | 18 | #endif // AUDIO_SEQPLAYER_H 19 | -------------------------------------------------------------------------------- /src/decomp/include/ultra64.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_H_ 2 | #define _ULTRA64_H_ 3 | 4 | #include 5 | 6 | #ifndef _LANGUAGE_C 7 | #define _LANGUAGE_C 8 | #endif 9 | 10 | #include "PR/ultratypes.h" 11 | #include "PR/os_exception.h" 12 | #include "PR/os_misc.h" 13 | #include "PR/os_rdp.h" 14 | #include "PR/os_thread.h" 15 | #include "PR/os_time.h" 16 | #include "PR/os_message.h" 17 | #include "PR/os_cont.h" 18 | #include "PR/os_tlb.h" 19 | #include "PR/sptask.h" 20 | #include "PR/ucode.h" 21 | #include "PR/os_cache.h" 22 | #include "PR/os_vi.h" 23 | #include "PR/os_pi.h" 24 | #include "PR/os_internal.h" 25 | #include "PR/os_eeprom.h" 26 | #include "PR/os_libc.h" 27 | #include "PR/os_ai.h" 28 | #include "PR/libaudio.h" 29 | #include "PR/libultra.h" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/decomp/tools/convUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../pc/libaudio_internal.h" 6 | 7 | #define read_u16_le(p) ((uint8_t*)p)[1] * 0x100u + ((uint8_t*)p)[0] 8 | 9 | struct EnvelopeMeta { 10 | uintptr_t orig; 11 | struct CEnvelope* addr; 12 | int size; 13 | }; 14 | 15 | struct SampleList { 16 | int count; 17 | uintptr_t orig_addrs[256]; 18 | struct CSample* addrs[256]; 19 | }; 20 | 21 | struct seqFile* parse_seqfile(unsigned char* seq); 22 | struct CTL* parse_ctl_data(unsigned char* ctlData, uintptr_t* pos); 23 | struct TBL* parse_tbl_data(unsigned char* tbl); 24 | struct SEQ* parse_seq_data(unsigned char* seq); 25 | void ptrs_to_offsets(struct seqFile* ctl); 26 | void ctl_free(); 27 | #define INITIAL_GFX_ALLOC 10 28 | #define INITIAL_GEO_ALLOC 10 -------------------------------------------------------------------------------- /src/decomp/game/behavior_actions.c: -------------------------------------------------------------------------------- 1 | #include "behavior_actions.h" 2 | #include "rendering_graph_node.h" 3 | #include "object_stuff.h" 4 | #include "../shim.h" 5 | 6 | // not sure what this is doing here. not in a behavior file. 7 | Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { 8 | Mat4 sp20; 9 | struct Object *sp1C; 10 | 11 | if (run == TRUE) { 12 | sp1C = (struct Object *) gCurGraphNodeObject; 13 | if (sp1C == gMarioObject && sp1C->prevObj != NULL) { 14 | create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr); 15 | obj_update_pos_from_parent_transformation(sp20, sp1C->prevObj); 16 | obj_set_gfx_pos_from_pos(sp1C->prevObj); 17 | } 18 | } 19 | return NULL; 20 | } -------------------------------------------------------------------------------- /src/play_sound.c: -------------------------------------------------------------------------------- 1 | #include "play_sound.h" 2 | 3 | #include "decomp/audio/external.h" 4 | #include "debug_print.h" 5 | #include "load_audio_data.h" 6 | 7 | SM64PlaySoundFunctionPtr g_play_sound_func = NULL; 8 | 9 | extern void play_sound( uint32_t soundBits, f32 *pos ) { 10 | if (pos[0] == -1 && pos[1] == -1 && pos[2] == -1) 11 | return; // Classic64: dirty hack for non-local players 12 | 13 | if ( g_is_audio_initialized ) { 14 | DEBUG_PRINT("$ play_sound(%d) request %d; pos %f %f %f\n", soundBits,sSoundRequestCount,pos[0],pos[1],pos[2]); 15 | sSoundRequests[sSoundRequestCount].soundBits = soundBits; 16 | sSoundRequests[sSoundRequestCount].position = pos; 17 | sSoundRequestCount++; 18 | } 19 | 20 | if ( g_play_sound_func ) { 21 | g_play_sound_func(soundBits, pos); 22 | } 23 | } -------------------------------------------------------------------------------- /src/sha1/sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef SHA1_H 2 | #define SHA1_H 3 | 4 | /* 5 | SHA-1 in C 6 | By Steve Reid 7 | 100% Public Domain 8 | */ 9 | 10 | #include "stdint.h" 11 | 12 | typedef struct 13 | { 14 | uint32_t state[5]; 15 | uint32_t count[2]; 16 | unsigned char buffer[64]; 17 | } SHA1_CTX; 18 | 19 | void SHA1Transform( 20 | uint32_t state[5], 21 | const unsigned char buffer[64] 22 | ); 23 | 24 | void SHA1Init( 25 | SHA1_CTX * context 26 | ); 27 | 28 | void SHA1Update( 29 | SHA1_CTX * context, 30 | const unsigned char *data, 31 | uint32_t len 32 | ); 33 | 34 | void SHA1Final( 35 | unsigned char digest[20], 36 | SHA1_CTX * context 37 | ); 38 | 39 | void SHA1( 40 | char *hash_out, 41 | const char *str, 42 | int len); 43 | 44 | #endif /* SHA1_H */ 45 | -------------------------------------------------------------------------------- /src/load_surfaces.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "decomp/include/types.h" 4 | #include "libsm64.h" 5 | 6 | extern uint32_t loaded_surface_iter_group_count( void ); 7 | extern uint32_t loaded_surface_iter_group_size( uint32_t groupIndex ); 8 | extern struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index( uint32_t groupIndex, uint32_t surfaceIndex ); 9 | 10 | extern void surfaces_load_static( const struct SM64Surface *surfaceArray, uint32_t numSurfaces ); 11 | extern uint32_t surfaces_load_object( const struct SM64SurfaceObject *surfaceObject ); 12 | extern void surface_object_update_transform( uint32_t objId, const struct SM64ObjectTransform *newTransform ); 13 | extern struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr( uint32_t objId ); 14 | extern void surfaces_unload_object( uint32_t objId ); 15 | extern void surfaces_unload_all( void ); 16 | 17 | struct LoadedSurfaceObject* get_all_surface_objects(uint32_t* count); -------------------------------------------------------------------------------- /src/decomp/include/level_misc_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef LEVEL_MISC_MACROS_H 2 | #define LEVEL_MISC_MACROS_H 3 | 4 | #define MACRO_OBJECT_WITH_BEH_PARAM(preset, yaw, posX, posY, posZ, behParam) \ 5 | ((s16)((yaw * 0x10 / 45) << 9) | (preset + 0x1F)), posX, posY, posZ, behParam 6 | 7 | #define MACRO_OBJECT(preset, yaw, posX, posY, posZ) \ 8 | MACRO_OBJECT_WITH_BEH_PARAM(preset, yaw, posX, posY, posZ, 0) 9 | 10 | #define MACRO_OBJECT_END() \ 11 | 0x001E 12 | 13 | #define SPECIAL_OBJECT(preset, posX, posY, posZ) \ 14 | preset, posX, posY, posZ 15 | 16 | #define SPECIAL_OBJECT_WITH_YAW(preset, posX, posY, posZ, yaw) \ 17 | preset, posX, posY, posZ, yaw 18 | 19 | #define SPECIAL_OBJECT_WITH_YAW_AND_PARAM(preset, posX, posY, posZ, yaw, param) \ 20 | preset, posX, posY, posZ, yaw, param 21 | 22 | #define TRAJECTORY_POS(trajId, x, y, z) \ 23 | trajId, x, y, z 24 | 25 | #define TRAJECTORY_END() \ 26 | -1 27 | 28 | #endif // LEVEL_MISC_MACROS_H 29 | -------------------------------------------------------------------------------- /src/obj_pool.c: -------------------------------------------------------------------------------- 1 | #include "obj_pool.h" 2 | 3 | #include 4 | 5 | uint32_t obj_pool_alloc_index( struct ObjPool *pool, size_t size ) 6 | { 7 | for( uint32_t i = 0; i < pool->size; ++i ) 8 | { 9 | if( pool->objects[i] == NULL ) 10 | { 11 | pool->objects[i] = malloc( size ); 12 | return i; 13 | } 14 | } 15 | 16 | uint32_t i = pool->size; 17 | pool->size++; 18 | pool->objects = realloc( pool->objects, pool->size * sizeof( void * )); 19 | pool->objects[i] = malloc( size ); 20 | return i; 21 | } 22 | 23 | void obj_pool_free_index( struct ObjPool *pool, uint32_t index ) 24 | { 25 | free( pool->objects[index] ); 26 | pool->objects[index] = NULL; 27 | } 28 | 29 | void obj_pool_free_all( struct ObjPool *pool ) 30 | { 31 | for( uint32_t i = 0; i < pool->size; ++i ) 32 | free( pool->objects[i] ); 33 | free( pool->objects ); 34 | 35 | pool->size = 0; 36 | pool->objects = NULL; 37 | } -------------------------------------------------------------------------------- /src/load_audio_data.c: -------------------------------------------------------------------------------- 1 | #include "load_audio_data.h" 2 | 3 | #include 4 | 5 | #include "decomp/tools/convUtils.h" 6 | #include "decomp/audio/external.h" 7 | #include "decomp/audio/load.h" 8 | #include "decomp/audio/load_dat.h" 9 | 10 | bool g_is_audio_initialized = false; 11 | 12 | extern void load_audio_banks( const uint8_t *rom ) { 13 | // FIXME: rom_copy purposfully leaks here 14 | uint8_t *rom_copy = malloc( 0x800000 ); 15 | 16 | memcpy( rom_copy, rom, 0x800000 ); 17 | 18 | gSoundDataADSR = parse_seqfile( rom_copy+0x57B720 ); //ctl 19 | gSoundDataRaw = parse_seqfile( rom_copy+0x593560 ); //tbl 20 | gMusicData = parse_seqfile( rom_copy+0x7B0860 ); 21 | gBankSetsData = rom_copy+0x7CC621; 22 | memmove( gBankSetsData+0x45,gBankSetsData+0x45-1,0x5B ); 23 | gBankSetsData[0x45]=0x00; 24 | ptrs_to_offsets( gSoundDataADSR ); 25 | 26 | audio_init(); 27 | sound_init(); 28 | sound_reset( 0 ); 29 | 30 | g_is_audio_initialized = true; 31 | } 32 | -------------------------------------------------------------------------------- /src/decomp/engine/surface_collision.h: -------------------------------------------------------------------------------- 1 | #ifndef SURFACE_COLLISION_H 2 | #define SURFACE_COLLISION_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../../libsm64.h" 7 | #include "../include/types.h" 8 | 9 | #define LEVEL_BOUNDARY_MAX 0x2000 10 | #define CELL_SIZE 0x400 11 | 12 | #define CELL_HEIGHT_LIMIT 100000.f 13 | #define FLOOR_LOWER_LIMIT -110000.f 14 | 15 | s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius); 16 | s32 find_wall_collisions(struct SM64WallCollisionData *colData); 17 | f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct SM64SurfaceCollisionData **pceil); 18 | f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct SM64FloorCollisionData **floorGeo); 19 | f32 find_floor_height(f32 x, f32 y, f32 z); 20 | f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct SM64SurfaceCollisionData **pfloor); 21 | f32 find_water_level(f32 x, f32 z); 22 | f32 find_poison_gas_level(f32 x, f32 z); 23 | 24 | #endif // SURFACE_COLLISION_H 25 | -------------------------------------------------------------------------------- /src/decomp/include/PR/ultratypes.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_TYPES_H_ 2 | #define _ULTRA64_TYPES_H_ 3 | 4 | #ifndef NULL 5 | #define NULL (void *)0 6 | #endif 7 | 8 | #define TRUE 1 9 | #define FALSE 0 10 | 11 | typedef signed char s8; 12 | typedef unsigned char u8; 13 | typedef signed short int s16; 14 | typedef unsigned short int u16; 15 | typedef signed int s32; 16 | typedef unsigned int u32; 17 | typedef signed long long int s64; 18 | typedef unsigned long long int u64; 19 | 20 | typedef volatile u8 vu8; 21 | typedef volatile u16 vu16; 22 | typedef volatile u32 vu32; 23 | typedef volatile u64 vu64; 24 | typedef volatile s8 vs8; 25 | typedef volatile s16 vs16; 26 | typedef volatile s32 vs32; 27 | typedef volatile s64 vs64; 28 | 29 | typedef float f32; 30 | typedef double f64; 31 | 32 | #ifdef TARGET_N64 33 | typedef u32 size_t; 34 | typedef s32 ssize_t; 35 | typedef u32 uintptr_t; 36 | typedef s32 intptr_t; 37 | typedef s32 ptrdiff_t; 38 | #else 39 | #include 40 | #include 41 | typedef ptrdiff_t ssize_t; 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /dll2lib.bat: -------------------------------------------------------------------------------- 1 | REM Usage: dll2lib [32|64] some-file.dll 2 | REM 3 | REM Generates some-file.lib from some-file.dll, making an intermediate 4 | REM some-file.def from the results of dumpbin /exports some-file.dll. 5 | REM Currently must run without path on DLL. 6 | REM (Fix by removing path when of lib_name for LIBRARY line below?) 7 | REM 8 | REM Requires 'dumpbin' and 'lib' in PATH - run from VS developer prompt. 9 | REM 10 | REM Script inspired by http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll 11 | SETLOCAL 12 | if "%1"=="32" (set machine=x86) else (set machine=x64) 13 | set dll_file=%2 14 | set dll_file_no_ext=%dll_file:~0,-4% 15 | set exports_file=%dll_file_no_ext%-exports.txt 16 | set def_file=%dll_file_no_ext%.def 17 | set lib_file=%dll_file_no_ext%.lib 18 | set lib_name=%dll_file_no_ext% 19 | 20 | dumpbin /exports %dll_file% > %exports_file% 21 | 22 | echo LIBRARY %lib_name% > %def_file% 23 | echo EXPORTS >> %def_file% 24 | for /f "skip=19 tokens=1,4" %%A in (%exports_file%) do if NOT "%%B" == "" (echo %%B @%%A >> %def_file%) 25 | 26 | lib /def:%def_file% /out:%lib_file% /machine:%machine% 27 | 28 | REM Clean up temporary intermediate files 29 | del %exports_file% %def_file% %dll_file_no_ext%.exp -------------------------------------------------------------------------------- /src/load_tex_data.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | enum MarioTextures 6 | { 7 | mario_texture_metal = 0, 8 | mario_texture_yellow_button, 9 | mario_texture_m_logo, 10 | mario_texture_hair_sideburn, 11 | mario_texture_mustache, 12 | mario_texture_eyes_front, 13 | mario_texture_eyes_half_closed, 14 | mario_texture_eyes_closed, 15 | mario_texture_eyes_dead, 16 | mario_texture_wings_half_1, 17 | mario_texture_wings_half_2, 18 | mario_texture_metal_wings_half_1 = -99, 19 | mario_texture_metal_wings_half_2, 20 | mario_texture_eyes_closed_unused1, 21 | mario_texture_eyes_closed_unused2, 22 | mario_texture_eyes_right, 23 | mario_texture_eyes_left, 24 | mario_texture_eyes_up, 25 | mario_texture_eyes_down 26 | }; 27 | 28 | #define NUM_USED_TEXTURES 11 29 | 30 | static const int mario_tex_offsets[NUM_USED_TEXTURES] = { 144, 4240, 6288, 8336, 10384, 12432, 14480, 16528, 30864, 32912, 37008 }; 31 | static const int mario_tex_widths [NUM_USED_TEXTURES] = { 64, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 }; 32 | static const int mario_tex_heights[NUM_USED_TEXTURES] = { 32, 32, 32, 32, 32, 32, 32, 32, 32, 64, 64 }; 33 | 34 | extern void load_mario_textures_from_rom( const uint8_t *rom, uint8_t *outTexture ); -------------------------------------------------------------------------------- /src/decomp/include/mario_geo_switch_case_ids.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_GEO_SWITCH_CASE_IDS_H 2 | #define MARIO_GEO_SWITCH_CASE_IDS_H 3 | 4 | /* Mario Geo-Switch-Case IDs */ 5 | 6 | enum MarioEyesGSCId 7 | { 8 | /*0x00*/ MARIO_EYES_BLINK, 9 | /*0x01*/ MARIO_EYES_OPEN, 10 | /*0x02*/ MARIO_EYES_HALF_CLOSED, 11 | /*0x03*/ MARIO_EYES_CLOSED, 12 | /*0x04*/ MARIO_EYES_LOOK_LEFT, // unused 13 | /*0x05*/ MARIO_EYES_LOOK_RIGHT, // unused 14 | /*0x06*/ MARIO_EYES_LOOK_UP, // unused 15 | /*0x07*/ MARIO_EYES_LOOK_DOWN, // unused 16 | /*0x08*/ MARIO_EYES_DEAD 17 | }; 18 | 19 | enum MarioHandGSCId 20 | { 21 | /*0x00*/ MARIO_HAND_FISTS, 22 | /*0x01*/ MARIO_HAND_OPEN, 23 | /*0x02*/ MARIO_HAND_PEACE_SIGN, 24 | /*0x03*/ MARIO_HAND_HOLDING_CAP, 25 | /*0x04*/ MARIO_HAND_HOLDING_WING_CAP, 26 | /*0x05*/ MARIO_HAND_RIGHT_OPEN 27 | }; 28 | 29 | enum MarioCapGSCId 30 | { 31 | /*0x00*/ MARIO_HAS_DEFAULT_CAP_ON, 32 | /*0x01*/ MARIO_HAS_DEFAULT_CAP_OFF, 33 | /*0x02*/ MARIO_HAS_WING_CAP_ON, 34 | /*0x03*/ MARIO_HAS_WING_CAP_OFF // unused 35 | }; 36 | 37 | enum MarioGrabPosGSCId 38 | { 39 | /*0x00*/ GRAB_POS_NULL, 40 | /*0x01*/ GRAB_POS_LIGHT_OBJ, 41 | /*0x02*/ GRAB_POS_HEAVY_OBJ, 42 | /*0x03*/ GRAB_POS_BOWSER 43 | }; 44 | 45 | #endif // MARIO_GEO_SWITCH_CASE_IDS_H 46 | -------------------------------------------------------------------------------- /src/decomp/include/command_macros_base.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMAND_MACROS_BASE_H 2 | #define COMMAND_MACROS_BASE_H 3 | 4 | #include "PR/gbi.h" 5 | 6 | #if IS_BIG_ENDIAN 7 | #if IS_64_BIT 8 | #define CMD_BBBB(a, b, c, d) ((uintptr_t)(_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 8, 8) | _SHIFTL(d, 0, 8)) << 32) 9 | #define CMD_BBH(a, b, c) ((uintptr_t)(_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 0, 16)) << 32) 10 | #define CMD_HH(a, b) ((uintptr_t)(_SHIFTL(a, 16, 16) | _SHIFTL(b, 0, 16)) << 32) 11 | #define CMD_W(a) ((uintptr_t)(a) << 32) 12 | #else 13 | #define CMD_BBBB(a, b, c, d) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 8, 8) | _SHIFTL(d, 0, 8)) 14 | #define CMD_BBH(a, b, c) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 0, 16)) 15 | #define CMD_HH(a, b) (_SHIFTL(a, 16, 16) | _SHIFTL(b, 0, 16)) 16 | #define CMD_W(a) (a) 17 | #endif 18 | #else 19 | #define CMD_BBBB(a, b, c, d) (_SHIFTL(a, 0, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 16, 8) | _SHIFTL(d, 24, 8)) 20 | #define CMD_BBH(a, b, c) (_SHIFTL(a, 0, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 16, 16)) 21 | #define CMD_HH(a, b) (_SHIFTL(a, 0, 16) | _SHIFTL(b, 16, 16)) 22 | #define CMD_W(a) (a) 23 | #endif 24 | #define CMD_PTR(a) ((uintptr_t)(a)) 25 | 26 | #define CMD_HHHHHH(a, b, c, d, e, f) CMD_HH(a, b), CMD_HH(c, d), CMD_HH(e, f) 27 | 28 | #endif // COMMAND_MACROS_BASE_H 29 | -------------------------------------------------------------------------------- /src/decomp/game/mario_step.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_STEP_H 2 | #define MARIO_STEP_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | struct BullyCollisionData { 9 | /*0x00*/ f32 conversionRatio; 10 | /*0x04*/ f32 radius; 11 | /*0x08*/ f32 posX; 12 | /*0x0C*/ f32 posZ; 13 | /*0x10*/ f32 velX; 14 | /*0x14*/ f32 velZ; 15 | }; 16 | 17 | extern struct SM64SurfaceCollisionData gWaterSurfacePseudoFloor; 18 | 19 | f32 get_additive_y_vel_for_jumps(void); 20 | void stub_mario_step_1(struct MarioState *); 21 | void stub_mario_step_2(void); 22 | 23 | void mario_bonk_reflection(struct MarioState *, u32); 24 | void transfer_bully_speed(struct BullyCollisionData *obj1, struct BullyCollisionData *obj2); 25 | BAD_RETURN(s32) init_bully_collision_data(struct BullyCollisionData *data, f32 posX, f32 posZ, 26 | f32 forwardVel, s16 yaw, f32 conversionRatio, f32 radius); 27 | u32 mario_update_quicksand(struct MarioState *, f32); 28 | u32 mario_push_off_steep_floor(struct MarioState *, u32, u32); 29 | u32 mario_update_moving_sand(struct MarioState *); 30 | u32 mario_update_windy_ground(struct MarioState *); 31 | void stop_and_set_height_to_floor(struct MarioState *); 32 | s32 stationary_ground_step(struct MarioState *); 33 | s32 perform_ground_step(struct MarioState *); 34 | s32 perform_air_step(struct MarioState *, u32); 35 | 36 | #endif // MARIO_STEP_H -------------------------------------------------------------------------------- /src/decomp/game/rendering_graph_node.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERING_GRAPH_NODE_H 2 | #define RENDERING_GRAPH_NODE_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../engine/graph_node.h" 7 | 8 | extern struct GraphNodeRoot *gCurGraphNodeRoot; 9 | extern struct GraphNodeMasterList *gCurGraphNodeMasterList; 10 | extern struct GraphNodePerspective *gCurGraphNodeCamFrustum; 11 | extern struct GraphNodeCamera *gCurGraphNodeCamera; 12 | extern struct GraphNodeObject *gCurGraphNodeObject; 13 | extern struct GraphNodeHeldObject *gCurGraphNodeHeldObject; 14 | 15 | // after processing an object, the type is reset to this 16 | #define ANIM_TYPE_NONE 0 17 | 18 | // Not all parts have full animation: to save space, some animations only 19 | // have xz, y, or no translation at all. All animations have rotations though 20 | #define ANIM_TYPE_TRANSLATION 1 21 | #define ANIM_TYPE_VERTICAL_TRANSLATION 2 22 | #define ANIM_TYPE_LATERAL_TRANSLATION 3 23 | #define ANIM_TYPE_NO_TRANSLATION 4 24 | 25 | // Every animation includes rotation, after processing any of the above 26 | // translation types the type is set to this 27 | #define ANIM_TYPE_ROTATION 5 28 | 29 | void geo_process_node_and_siblings(struct GraphNode *firstNode); 30 | //void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor); 31 | void geo_process_root_hack_single_node(struct GraphNode *node); 32 | 33 | #endif // RENDERING_GRAPH_NODE_H 34 | -------------------------------------------------------------------------------- /src/decomp/audio/effects.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_EFFECTS_H 2 | #define AUDIO_EFFECTS_H 3 | 4 | #include 5 | 6 | #include "internal.h" 7 | #include 8 | 9 | #define ADSR_STATE_DISABLED 0 10 | #define ADSR_STATE_INITIAL 1 11 | #define ADSR_STATE_START_LOOP 2 12 | #define ADSR_STATE_LOOP 3 13 | #define ADSR_STATE_FADE 4 14 | #define ADSR_STATE_HANG 5 15 | #define ADSR_STATE_DECAY 6 16 | #define ADSR_STATE_RELEASE 7 17 | #define ADSR_STATE_SUSTAIN 8 18 | 19 | #define ADSR_ACTION_RELEASE 0x10 20 | #define ADSR_ACTION_DECAY 0x20 21 | #define ADSR_ACTION_HANG 0x40 22 | 23 | #define ADSR_DISABLE 0 24 | #define ADSR_HANG -1 25 | #define ADSR_GOTO -2 26 | #define ADSR_RESTART -3 27 | 28 | // Envelopes are always stored as big endian, to match sequence files which are 29 | // byte blobs and can embed envelopes. Hence this byteswapping macro. 30 | #if IS_BIG_ENDIAN 31 | #define BSWAP16(x) (x) 32 | #else 33 | #define BSWAP16(x) (((x) & 0xff) << 8 | (((x) >> 8) & 0xff)) 34 | #endif 35 | 36 | extern f32 gTrackVolume; 37 | 38 | void sequence_player_process_sound(struct SequencePlayer *seqPlayer); 39 | void note_vibrato_update(struct Note *note); 40 | void note_vibrato_init(struct Note *note); 41 | void adsr_init(struct AdsrState *adsr, struct AdsrEnvelope *envelope, s16 *volOut); 42 | #if defined(VERSION_EU) || defined(VERSION_SH) 43 | f32 adsr_update(struct AdsrState *adsr); 44 | #else 45 | s32 adsr_update(struct AdsrState *adsr); 46 | #endif 47 | 48 | #endif // AUDIO_EFFECTS_H 49 | -------------------------------------------------------------------------------- /src/decomp/global_state.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/types.h" 4 | #include "game/area.h" 5 | 6 | struct GlobalState 7 | { 8 | // interaction.c 9 | u8 msDelayInvincTimer; 10 | s16 msInvulnerable; 11 | 12 | // mario_actions_moving.c 13 | Mat4 msFloorAlignMatrix; 14 | 15 | // mario_actions_submerged.c 16 | s16 msWasAtSurface; 17 | s16 msSwimStrength; 18 | s16 mD_80339FD0; 19 | s16 mD_80339FD2; 20 | f32 mD_80339FD4; 21 | 22 | // mario_misc.c 23 | struct MarioBodyState mgBodyStates[2]; 24 | s16 msMarioAttackAnimCounter; 25 | 26 | // rendering_graph_node.c 27 | u16 mgAreaUpdateCounter; 28 | 29 | // misc 30 | u32 mgGlobalTimer; 31 | u8 mgSpecialTripleJump; 32 | s16 mgCurrLevelNum; 33 | s16 mgCameraMovementFlags; 34 | u32 mgAudioRandom; 35 | s8 mgShowDebugText; 36 | s8 mgDebugLevelSelect; 37 | s16 mgCurrSaveFileNum; 38 | struct Controller mgController; 39 | struct SpawnInfo mgMarioSpawnInfoVal; 40 | struct Area *mgCurrentArea; 41 | struct Object *mgCurrentObject; 42 | struct Object *mgMarioObject; 43 | struct MarioAnimation mD_80339D10; 44 | struct MarioState mgMarioStateVal; 45 | }; 46 | 47 | // From mario_actions_submerged.c, needed to initialize global state 48 | #define MIN_SWIM_STRENGTH 160 49 | 50 | extern struct GlobalState *g_state; 51 | 52 | extern struct GlobalState *global_state_create(void); 53 | extern void global_state_bind(struct GlobalState *state); 54 | extern void global_state_delete(struct GlobalState *state); -------------------------------------------------------------------------------- /src/Classic64_settings.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASSIC64_SETTINGS_H 2 | #define CLASSIC64_SETTINGS_H 3 | 4 | #include 5 | 6 | #include "../ClassiCube/src/String.h" 7 | 8 | enum 9 | { 10 | PLUGINOPTION_FIRST_USE, 11 | PLUGINOPTION_HURT, 12 | PLUGINOPTION_CAMERA, 13 | PLUGINOPTION_BGR, 14 | PLUGINOPTION_INTERP, 15 | PLUGINOPTION_KEY_CROUCH, 16 | PLUGINOPTION_KEY_ATTACK, 17 | PLUGINOPTION_CUSTOM_COLORS, 18 | PLUGINOPTION_COLOR_OVERALLS, 19 | PLUGINOPTION_COLOR_SHIRT_HAT, 20 | PLUGINOPTION_COLOR_SKIN, 21 | PLUGINOPTION_COLOR_HAIR, 22 | PLUGINOPTION_COLOR_GLOVES, 23 | PLUGINOPTION_COLOR_SHOES, 24 | #ifdef CLASSIC64_DEBUG 25 | PLUGINOPTION_SURFACE_DEBUGGER, 26 | #endif 27 | PLUGINOPTIONS_MAX, 28 | 29 | PLUGINOPTION_VALUE_NUMBER=0, 30 | PLUGINOPTION_VALUE_STRING, 31 | PLUGINOPTION_VALUE_BOOL, 32 | PLUGINOPTION_VALUE_RGB 33 | }; 34 | 35 | struct RGBCol 36 | { 37 | uint8_t r, g, b; 38 | }; 39 | 40 | extern const char* keyNames[]; 41 | extern const cc_string usageStrings[]; 42 | extern const struct RGBCol defaultColors[]; 43 | 44 | struct PluginOption { 45 | cc_string name; 46 | cc_string desc[3]; 47 | int descLines; 48 | int valueType; 49 | union ValueUnion 50 | { 51 | struct numValue { 52 | int current, min, max; 53 | } num; 54 | struct strValue { 55 | char current[64]; 56 | const char **validList; 57 | int validMax; 58 | } str; 59 | bool on; 60 | struct RGBCol col; 61 | } value; 62 | bool hidden; 63 | }; 64 | 65 | extern struct PluginOption pluginOptions[]; 66 | 67 | void saveSettings(); 68 | void loadSettings(); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/load_tex_data.c: -------------------------------------------------------------------------------- 1 | #include "load_tex_data.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include "libsm64.h" 7 | 8 | #include "decomp/tools/libmio0.h" 9 | #include "decomp/tools/n64graphics.h" 10 | 11 | #define MARIO_TEX_ROM_OFFSET 1132368 12 | #define ATLAS_WIDTH (16 * 64) 13 | #define ATLAS_HEIGHT 64 14 | 15 | static void blt_image_to_atlas( rgba *img, int i, int w, int h, uint8_t *outTexture ) 16 | { 17 | for( int iy = 0; iy < h; ++iy ) 18 | for( int ix = 0; ix < w; ++ix ) 19 | { 20 | int o = (ix + 64 * i) + iy * ATLAS_WIDTH; 21 | int q = ix + iy * w; 22 | outTexture[4*o + 0] = img[q].red; 23 | outTexture[4*o + 1] = img[q].green; 24 | outTexture[4*o + 2] = img[q].blue; 25 | outTexture[4*o + 3] = img[q].alpha; 26 | } 27 | } 28 | 29 | void load_mario_textures_from_rom( const uint8_t *rom, uint8_t *outTexture ) 30 | { 31 | memset( outTexture, 0, 4 * ATLAS_WIDTH * ATLAS_HEIGHT ); 32 | 33 | mio0_header_t head; 34 | const uint8_t *in_buf = rom + MARIO_TEX_ROM_OFFSET; 35 | 36 | mio0_decode_header( in_buf, &head ); 37 | uint8_t *out_buf = malloc( head.dest_size ); 38 | mio0_decode( in_buf, out_buf, NULL ); 39 | 40 | for( int i = 0; i < 16; ++i ) 41 | { 42 | uint8_t *raw = out_buf + mario_tex_offsets[i]; 43 | rgba *img = raw2rgba( raw, mario_tex_widths[i], mario_tex_heights[i], 16 ); 44 | blt_image_to_atlas( img, i, mario_tex_widths[i], mario_tex_heights[i], outTexture ); 45 | free( img ); 46 | } 47 | 48 | free( out_buf ); 49 | } -------------------------------------------------------------------------------- /src/decomp/game/mario_misc.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_MISC_H 2 | #define MARIO_MISC_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/macros.h" 7 | #include "../include/types.h" 8 | 9 | // Gfx *geo_draw_mario_head_goddard(s32 callContext, struct GraphNode *node, Mat4 *c); 10 | void bhv_toad_message_loop(void); 11 | void bhv_toad_message_init(void); 12 | void bhv_unlock_door_star_init(void); 13 | void bhv_unlock_door_star_loop(void); 14 | Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 15 | Gfx *geo_switch_mario_stand_run(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx); 16 | Gfx *geo_switch_mario_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 17 | Gfx *geo_mario_tilt_torso(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 18 | Gfx *geo_mario_head_rotation(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 19 | Gfx *geo_switch_mario_hand(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 20 | Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 21 | Gfx *geo_switch_mario_cap_effect(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 22 | Gfx *geo_switch_mario_cap_on_off(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 23 | Gfx *geo_mario_rotate_wing_cap_wings(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 24 | Gfx *geo_switch_mario_hand_grab_pos(s32 callContext, struct GraphNode *b, Mat4 *mtx); 25 | Gfx *geo_render_mirror_mario(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 26 | Gfx *geo_mirror_mario_backface_culling(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c); 27 | 28 | #endif // MARIO_MISC_H 29 | -------------------------------------------------------------------------------- /src/decomp/memory.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "memory.h" 5 | 6 | // TODO don't handle every individual allocation with malloc, it sucks on windows 7 | 8 | struct AllocOnlyPool 9 | { 10 | size_t allocatedCount; 11 | void **allocatedBlocks; 12 | }; 13 | 14 | struct AllocOnlyPool *s_display_list_pool; 15 | 16 | void memory_init(void) 17 | { 18 | s_display_list_pool = alloc_only_pool_init(); 19 | } 20 | 21 | void memory_terminate(void) 22 | { 23 | alloc_only_pool_free( s_display_list_pool ); 24 | } 25 | 26 | struct AllocOnlyPool *alloc_only_pool_init(void) 27 | { 28 | struct AllocOnlyPool *newPool = malloc( sizeof( struct AllocOnlyPool )); 29 | newPool->allocatedCount = 0; 30 | newPool->allocatedBlocks = NULL; 31 | return newPool; 32 | } 33 | 34 | void *alloc_only_pool_alloc(struct AllocOnlyPool *pool, s32 size) 35 | { 36 | pool->allocatedCount++; 37 | pool->allocatedBlocks = realloc( pool->allocatedBlocks, pool->allocatedCount * sizeof( void * )); 38 | pool->allocatedBlocks[ pool->allocatedCount - 1 ] = malloc( size ); 39 | return pool->allocatedBlocks[ pool->allocatedCount - 1 ]; 40 | } 41 | 42 | void alloc_only_pool_free(struct AllocOnlyPool *pool) 43 | { 44 | for( int i = 0; i < pool->allocatedCount; ++i ) 45 | free( pool->allocatedBlocks[i] ); 46 | free( pool->allocatedBlocks ); 47 | free( pool ); 48 | } 49 | 50 | void display_list_pool_reset(void) 51 | { 52 | alloc_only_pool_free( s_display_list_pool ); 53 | s_display_list_pool = alloc_only_pool_init(); 54 | } 55 | 56 | void *alloc_display_list(u32 size) 57 | { 58 | return alloc_only_pool_alloc( s_display_list_pool, (s32)size ); 59 | } -------------------------------------------------------------------------------- /src/decomp/tools/libmio0.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBMIO0_H_ 2 | #define LIBMIO0_H_ 3 | 4 | // defines 5 | 6 | #define MIO0_HEADER_LENGTH 16 7 | 8 | // typedefs 9 | 10 | typedef struct 11 | { 12 | unsigned int dest_size; 13 | unsigned int comp_offset; 14 | unsigned int uncomp_offset; 15 | } mio0_header_t; 16 | 17 | // function prototypes 18 | 19 | // decode MIO0 header 20 | // returns 1 if valid header, 0 otherwise 21 | int mio0_decode_header(const unsigned char *buf, mio0_header_t *head); 22 | 23 | // encode MIO0 header from struct 24 | void mio0_encode_header(unsigned char *buf, const mio0_header_t *head); 25 | 26 | // decode MIO0 data in memory 27 | // in: buffer containing MIO0 data 28 | // out: buffer for output data 29 | // end: output offset of the last byte decoded from in (set to NULL if unwanted) 30 | // returns bytes extracted to 'out' or negative value on failure 31 | int mio0_decode(const unsigned char *in, unsigned char *out, unsigned int *end); 32 | 33 | // encode MIO0 data in memory 34 | // in: buffer containing raw data 35 | // out: buffer for MIO0 data 36 | // returns size of compressed data in 'out' including MIO0 header 37 | int mio0_encode(const unsigned char *in, unsigned int length, unsigned char *out); 38 | 39 | // decode an entire MIO0 block at an offset from file to output file 40 | // in_file: input filename 41 | // offset: offset to start decoding from in_file 42 | // out_file: output filename 43 | int mio0_decode_file(const char *in_file, unsigned long offset, const char *out_file); 44 | 45 | // encode an entire file 46 | // in_file: input filename containing raw data to be encoded 47 | // out_file: output filename to write MIO0 compressed data to 48 | int mio0_encode_file(const char *in_file, const char *out_file); 49 | 50 | #endif // LIBMIO0_H_ 51 | -------------------------------------------------------------------------------- /test/level.c: -------------------------------------------------------------------------------- 1 | #include "level.h" 2 | #include "../src/decomp/include/surface_terrains.h" 3 | const struct SM64Surface surfaces[] = { 4 | // bottom of block 5 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{0, 0, 256}, {0, 0, 0}, {256, 0, 256}}}, // bottom left, top right, top left 6 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{256, 0, 0}, {256, 0, 256}, {0, 0, 0}}}, // top right, bottom left, bottom right 7 | 8 | // left (Z+) 9 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{0, 0, 256}, {256, 256, 256}, {0, 256, 256}}}, // bottom left, top right, top left 10 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{256, 256, 256}, {0, 0, 256}, {256, 0, 256}}}, // top right, bottom left, bottom right 11 | 12 | // right (Z-) 13 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{256, 0, 0}, {0, 256, 0}, {256, 256, 0}}}, // bottom left, top right, top left 14 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{0, 256, 0}, {256, 0, 0}, {0, 0, 0}}}, // top right, bottom left, bottom right 15 | 16 | // back (X+) 17 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{256, 0, 0}, {256, 256, 0}, {256, 256, 256}}}, // bottom left, top right, top left 18 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{256, 256, 256}, {256, 0, 256}, {256, 0, 0}}}, // top right, bottom left, bottom right 19 | 20 | // front (X-) 21 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{0, 0, 256}, {0, 256, 256}, {0, 256, 0}}}, // bottom left, top right, top left 22 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{0, 256, 0}, {0, 0, 0}, {0, 0, 256}}}, // top right, bottom left, bottom right 23 | 24 | // top of block 25 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{256, 256, 256}, {0, 256, 0}, {0, 256, 256}}}, // bottom left, top right, top left 26 | {SURFACE_DEFAULT,0,TERRAIN_STONE,{{0, 256, 0}, {256, 256, 256}, {256, 256, 0}}}, // top right, bottom left, bottom right 27 | }; 28 | const size_t surfaces_count = sizeof( surfaces ) / sizeof( surfaces[0] ); 29 | const int32_t spawn[] = {0, 256, 0}; 30 | -------------------------------------------------------------------------------- /test/ns_clock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // From: http://roxlu.com/2014/047/high-resolution-timer-function-in-c-c-- 4 | /* ----------------------------------------------------------------------- */ 5 | /* 6 | Easy embeddable cross-platform high resolution timer function. For each 7 | platform we select the high resolution timer. You can call the 'ns()' 8 | function in your file after embedding this. 9 | */ 10 | #include 11 | #if defined(__linux) 12 | # define HAVE_POSIX_TIMER 13 | # include 14 | # ifdef CLOCK_MONOTONIC 15 | # define CLOCKID CLOCK_MONOTONIC 16 | # else 17 | # define CLOCKID CLOCK_REALTIME 18 | # endif 19 | #elif defined(__APPLE__) 20 | # define HAVE_MACH_TIMER 21 | # include 22 | #elif defined(_WIN32) 23 | # define WIN32_LEAN_AND_MEAN 24 | # include 25 | #endif 26 | static uint64_t ns_clock() { 27 | static uint64_t is_init = 0; 28 | #if defined(__APPLE__) 29 | static mach_timebase_info_data_t info; 30 | if (0 == is_init) { 31 | mach_timebase_info(&info); 32 | is_init = 1; 33 | } 34 | uint64_t now; 35 | now = mach_absolute_time(); 36 | now *= info.numer; 37 | now /= info.denom; 38 | return now; 39 | #elif defined(__linux) 40 | static struct timespec linux_rate; 41 | if (0 == is_init) { 42 | clock_getres(CLOCKID, &linux_rate); 43 | is_init = 1; 44 | } 45 | uint64_t now; 46 | struct timespec spec; 47 | clock_gettime(CLOCKID, &spec); 48 | now = spec.tv_sec * 1.0e9 + spec.tv_nsec; 49 | return now; 50 | #elif defined(_WIN32) 51 | static LARGE_INTEGER win_frequency; 52 | if (0 == is_init) { 53 | QueryPerformanceFrequency(&win_frequency); 54 | is_init = 1; 55 | } 56 | LARGE_INTEGER now; 57 | QueryPerformanceCounter(&now); 58 | return (uint64_t) ((1e9 * now.QuadPart) / win_frequency.QuadPart); 59 | #endif 60 | } -------------------------------------------------------------------------------- /src/decomp/include/seq_ids.h: -------------------------------------------------------------------------------- 1 | #ifndef SEQ_IDS_H 2 | #define SEQ_IDS_H 3 | 4 | #define SEQ_VARIATION 0x80 5 | 6 | enum SeqId { 7 | SEQ_SOUND_PLAYER, // 0x00 8 | SEQ_EVENT_CUTSCENE_COLLECT_STAR, // 0x01 9 | SEQ_MENU_TITLE_SCREEN, // 0x02 10 | SEQ_LEVEL_GRASS, // 0x03 11 | SEQ_LEVEL_INSIDE_CASTLE, // 0x04 12 | SEQ_LEVEL_WATER, // 0x05 13 | SEQ_LEVEL_HOT, // 0x06 14 | SEQ_LEVEL_BOSS_KOOPA, // 0x07 15 | SEQ_LEVEL_SNOW, // 0x08 16 | SEQ_LEVEL_SLIDE, // 0x09 17 | SEQ_LEVEL_SPOOKY, // 0x0A 18 | SEQ_EVENT_PIRANHA_PLANT, // 0x0B 19 | SEQ_LEVEL_UNDERGROUND, // 0x0C 20 | SEQ_MENU_STAR_SELECT, // 0x0D 21 | SEQ_EVENT_POWERUP, // 0x0E 22 | SEQ_EVENT_METAL_CAP, // 0x0F 23 | SEQ_EVENT_KOOPA_MESSAGE, // 0x10 24 | SEQ_LEVEL_KOOPA_ROAD, // 0x11 25 | SEQ_EVENT_HIGH_SCORE, // 0x12 26 | SEQ_EVENT_MERRY_GO_ROUND, // 0x13 27 | SEQ_EVENT_RACE, // 0x14 28 | SEQ_EVENT_CUTSCENE_STAR_SPAWN, // 0x15 29 | SEQ_EVENT_BOSS, // 0x16 30 | SEQ_EVENT_CUTSCENE_COLLECT_KEY, // 0x17 31 | SEQ_EVENT_ENDLESS_STAIRS, // 0x18 32 | SEQ_LEVEL_BOSS_KOOPA_FINAL, // 0x19 33 | SEQ_EVENT_CUTSCENE_CREDITS, // 0x1A 34 | SEQ_EVENT_SOLVE_PUZZLE, // 0x1B 35 | SEQ_EVENT_TOAD_MESSAGE, // 0x1C 36 | SEQ_EVENT_PEACH_MESSAGE, // 0x1D 37 | SEQ_EVENT_CUTSCENE_INTRO, // 0x1E 38 | SEQ_EVENT_CUTSCENE_VICTORY, // 0x1F 39 | SEQ_EVENT_CUTSCENE_ENDING, // 0x20 40 | SEQ_MENU_FILE_SELECT, // 0x21 41 | SEQ_EVENT_CUTSCENE_LAKITU, // 0x22 (not in JP) 42 | SEQ_COUNT 43 | }; 44 | 45 | #endif // SEQ_IDS_H 46 | -------------------------------------------------------------------------------- /src/decomp/engine/guMtxF2L.c: -------------------------------------------------------------------------------- 1 | #include "guMtxF2L.h" 2 | 3 | #ifdef GBI_FLOATS 4 | #include 5 | #endif 6 | 7 | #ifndef GBI_FLOATS 8 | void guMtxF2L(float mf[4][4], Mtx *m) { 9 | int r, c; 10 | s32 tmp1; 11 | s32 tmp2; 12 | s32 *m1 = &m->m[0][0]; 13 | s32 *m2 = &m->m[2][0]; 14 | for (r = 0; r < 4; r++) { 15 | for (c = 0; c < 2; c++) { 16 | tmp1 = mf[r][2 * c] * 65536.0f; 17 | tmp2 = mf[r][2 * c + 1] * 65536.0f; 18 | *m1++ = (tmp1 & 0xffff0000) | ((tmp2 >> 0x10) & 0xffff); 19 | *m2++ = ((tmp1 << 0x10) & 0xffff0000) | (tmp2 & 0xffff); 20 | } 21 | } 22 | } 23 | void guMtxL2F(float mf[4][4], Mtx *m) { 24 | int r, c; 25 | u32 tmp1; 26 | u32 tmp2; 27 | u32 *m1; 28 | u32 *m2; 29 | s32 stmp1, stmp2; 30 | m1 = (u32 *) &m->m[0][0]; 31 | m2 = (u32 *) &m->m[2][0]; 32 | for (r = 0; r < 4; r++) { 33 | for (c = 0; c < 2; c++) { 34 | tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff); 35 | tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff); 36 | stmp1 = *(s32 *) &tmp1; 37 | stmp2 = *(s32 *) &tmp2; 38 | mf[r][c * 2 + 0] = stmp1 / 65536.0f; 39 | mf[r][c * 2 + 1] = stmp2 / 65536.0f; 40 | } 41 | } 42 | } 43 | #else 44 | void guMtxF2L(float mf[4][4], Mtx *m) { 45 | memcpy(m, mf, sizeof(Mtx)); 46 | } 47 | void guMtxL2F(float mf[4][4], Mtx *m) { 48 | memcpy(mf, m, sizeof(Mtx)); 49 | } 50 | #endif 51 | 52 | void guMtxIdentF(float mf[4][4]) { 53 | int r, c; 54 | for (r = 0; r < 4; r++) { 55 | for (c = 0; c < 4; c++) { 56 | if (r == c) { 57 | mf[r][c] = 1.0f; 58 | } else { 59 | mf[r][c] = 0.0f; 60 | } 61 | } 62 | } 63 | } 64 | void guMtxIdent(Mtx *m) { 65 | #ifndef GBI_FLOATS 66 | float mf[4][4]; 67 | guMtxIdentF(mf); 68 | guMtxF2L(mf, m); 69 | #else 70 | guMtxIdentF(m->m); 71 | #endif 72 | } 73 | -------------------------------------------------------------------------------- /import-test-collision.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import os 3 | import shutil 4 | import urllib.request 5 | 6 | BOB_COLLISION_URL = "https://raw.githubusercontent.com/n64decomp/sm64/06ec56df7f951f88da05f468cdcacecba496145a/levels/bob/areas/1/collision.inc.c" 7 | 8 | LEVEL_H = """#pragma once 9 | 10 | #include "../src/libsm64.h" 11 | 12 | extern const struct SM64Surface surfaces[]; 13 | extern const size_t surfaces_count; 14 | """ 15 | 16 | def main(): 17 | print("Downloading " + BOB_COLLISION_URL) 18 | in_lines = urllib.request.urlopen(BOB_COLLISION_URL).read().decode('utf8').splitlines() 19 | 20 | verts = [] 21 | tris = [] 22 | mode = "" 23 | 24 | for line in in_lines: 25 | if not line.strip().startswith("COL_"): 26 | continue; 27 | 28 | tokens = line.strip().replace("(", ",").replace(")", "").split(",") 29 | 30 | if tokens[0] == "COL_VERTEX": 31 | verts.append([ int(tokens[1]), int(tokens[2]), int(tokens[3]) ]) 32 | elif tokens[0] == "COL_TRI_INIT": 33 | mode = tokens[1] 34 | elif tokens[0] == "COL_TRI": 35 | tris.append([ int(tokens[1]), int(tokens[2]), int(tokens[3]), mode ]) 36 | 37 | out_lines = [] 38 | 39 | for tri in tris: 40 | out_lines.append("{%s,0,TERRAIN_SNOW,{{%s,%s,%s},{%s,%s,%s},{%s,%s,%s}}}"%(tri[3], \ 41 | verts[tri[0]][0], verts[tri[0]][1], verts[tri[0]][2], \ 42 | verts[tri[1]][0], verts[tri[1]][1], verts[tri[1]][2], \ 43 | verts[tri[2]][0], verts[tri[2]][1], verts[tri[2]][2])) 44 | 45 | out_str = ",\n".join(out_lines) 46 | out_str = "const struct SM64Surface surfaces[] = {\n" + out_str + "};\n\n" 47 | out_str += "const size_t surfaces_count = sizeof( surfaces ) / sizeof( surfaces[0] );" 48 | out_str = '#include "../src/decomp/include/surface_terrains.h"\n' + out_str 49 | out_str = '#include "level.h"\n' + out_str 50 | 51 | with open("test/level.c", "w") as file: 52 | file.write(out_str) 53 | 54 | with open("test/level.h", "w") as file: 55 | file.write(LEVEL_H) 56 | 57 | if __name__ == "__main__": 58 | main() 59 | -------------------------------------------------------------------------------- /src/Classic64_audio.c: -------------------------------------------------------------------------------- 1 | #include "Classic64_audio.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "libsm64.h" 11 | 12 | static SDL_AudioDeviceID dev; 13 | 14 | pthread_t gSoundThread; 15 | long long timeInMilliseconds(void) 16 | { 17 | struct timeval tv; 18 | gettimeofday(&tv, NULL); 19 | 20 | return(((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000); 21 | } 22 | 23 | void* audio_thread(void* keepAlive) 24 | { 25 | // from https://github.com/ckosmic/libsm64/blob/audio/src/libsm64.c#L535-L555 26 | // except keepAlive is a null pointer here, so don't use it 27 | 28 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL); 29 | pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL); 30 | 31 | long long currentTime = timeInMilliseconds(); 32 | long long targetTime = 0; 33 | while(1) 34 | { 35 | //if(!*((bool*)keepAlive)) return NULL; 36 | 37 | int16_t audioBuffer[544 * 2 * 2]; 38 | uint32_t numSamples = sm64_audio_tick(SDL_GetQueuedAudioSize(dev)/4, 1100, audioBuffer); 39 | if (SDL_GetQueuedAudioSize(dev)/4 < 6000) 40 | SDL_QueueAudio(dev, audioBuffer, numSamples * 2 * 4); 41 | 42 | targetTime = currentTime + 33; 43 | while (timeInMilliseconds() < targetTime) 44 | { 45 | usleep(100); 46 | //if(!*((bool*)keepAlive)) return NULL; 47 | } 48 | currentTime = timeInMilliseconds(); 49 | } 50 | } 51 | 52 | void classic64_audio_init() 53 | { 54 | if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { 55 | fprintf(stderr, "SDL_InitSubSystem(SDL_INIT_AUDIO) failed: %s\n", SDL_GetError()); 56 | return; 57 | } 58 | 59 | SDL_AudioSpec want, have; 60 | SDL_zero(want); 61 | want.freq = 32000; 62 | want.format = AUDIO_S16; 63 | want.channels = 2; 64 | want.samples = 512; 65 | want.callback = NULL; 66 | dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0); 67 | if (dev == 0) { 68 | fprintf(stderr, "SDL_OpenAudio error: %s\n", SDL_GetError()); 69 | return; 70 | } 71 | SDL_PauseAudioDevice(dev, 0); 72 | 73 | // it's best to run audio in a separate thread 74 | pthread_create(&gSoundThread, NULL, audio_thread, NULL); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/decomp/audio/playback.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_PLAYBACK_H 2 | #define AUDIO_PLAYBACK_H 3 | 4 | #include 5 | 6 | #include "internal.h" 7 | 8 | // Mask bits denoting where to allocate notes from, according to a channel's 9 | // noteAllocPolicy. Despite being checked as bitmask bits, the bits are not 10 | // orthogonal; rather, the smallest bit wins, except for NOTE_ALLOC_LAYER, 11 | // which *is* orthogonal to the other. SEQ implicitly includes CHANNEL. 12 | // If none of the CHANNEL/SEQ/GLOBAL_FREELIST bits are set, all three locations 13 | // are tried. 14 | #define NOTE_ALLOC_LAYER 1 15 | #define NOTE_ALLOC_CHANNEL 2 16 | #define NOTE_ALLOC_SEQ 4 17 | #define NOTE_ALLOC_GLOBAL_FREELIST 8 18 | 19 | void process_notes(void); 20 | void seq_channel_layer_note_decay(struct SequenceChannelLayer *seqLayer); 21 | void seq_channel_layer_note_release(struct SequenceChannelLayer *seqLayer); 22 | void init_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLayer); 23 | void init_note_lists(struct NotePool *pool); 24 | void init_note_free_list(void); 25 | void note_pool_clear(struct NotePool *pool); 26 | void note_pool_fill(struct NotePool *pool, s32 count); 27 | void audio_list_push_front(struct AudioListItem *list, struct AudioListItem *item); 28 | void audio_list_remove(struct AudioListItem *item); 29 | struct Note *alloc_note(struct SequenceChannelLayer *seqLayer); 30 | void reclaim_notes(void); 31 | void note_init_all(void); 32 | 33 | #if defined(VERSION_SH) 34 | void note_set_vel_pan_reverb(struct Note *note, struct ReverbInfo *reverbInfo); 35 | #elif defined(VERSION_EU) 36 | void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbVol); 37 | #endif 38 | 39 | #if defined(VERSION_EU) || defined(VERSION_SH) 40 | struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instrument, s32 semitone); 41 | struct Instrument *get_instrument_inner(s32 bankId, s32 instId); 42 | struct Drum *get_drum(s32 bankId, s32 drumId); 43 | void note_init_volume(struct Note *note); 44 | void note_set_frequency(struct Note *note, f32 frequency); 45 | void note_enable(struct Note *note); 46 | void note_disable(struct Note *note); 47 | #endif 48 | 49 | 50 | #endif // AUDIO_PLAYBACK_H 51 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_thread.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_THREAD_H_ 2 | #define _ULTRA64_THREAD_H_ 3 | #include "ultratypes.h" 4 | /* Recommended priorities for system threads */ 5 | #define OS_PRIORITY_MAX 255 6 | #define OS_PRIORITY_VIMGR 254 7 | #define OS_PRIORITY_RMON 250 8 | #define OS_PRIORITY_RMONSPIN 200 9 | #define OS_PRIORITY_PIMGR 150 10 | #define OS_PRIORITY_SIMGR 140 11 | #define OS_PRIORITY_APPMAX 127 12 | #define OS_PRIORITY_IDLE 0 13 | 14 | #define OS_STATE_STOPPED 1 15 | #define OS_STATE_RUNNABLE 2 16 | #define OS_STATE_RUNNING 4 17 | #define OS_STATE_WAITING 8 18 | 19 | /* Types */ 20 | 21 | typedef s32 OSPri; 22 | typedef s32 OSId; 23 | 24 | typedef union 25 | { 26 | struct {f32 f_odd; f32 f_even;} f; 27 | } __OSfp; 28 | 29 | typedef struct 30 | { 31 | /* registers */ 32 | /*0x20*/ u64 at, v0, v1, a0, a1, a2, a3; 33 | /*0x58*/ u64 t0, t1, t2, t3, t4, t5, t6, t7; 34 | /*0x98*/ u64 s0, s1, s2, s3, s4, s5, s6, s7; 35 | /*0xD8*/ u64 t8, t9, gp, sp, s8, ra; 36 | /*0x108*/ u64 lo, hi; 37 | /*0x118*/ u32 sr, pc, cause, badvaddr, rcp; 38 | /*0x12C*/ u32 fpcsr; 39 | __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; 40 | __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; 41 | } __OSThreadContext; 42 | 43 | typedef struct 44 | { 45 | u32 flag; 46 | u32 count; 47 | u64 time; 48 | } __OSThreadprofile_s; 49 | 50 | typedef struct OSThread_s 51 | { 52 | /*0x00*/ struct OSThread_s *next; 53 | /*0x04*/ OSPri priority; 54 | /*0x08*/ struct OSThread_s **queue; 55 | /*0x0C*/ struct OSThread_s *tlnext; 56 | /*0x10*/ u16 state; 57 | /*0x12*/ u16 flags; 58 | /*0x14*/ OSId id; 59 | /*0x18*/ int fp; 60 | /*0x1C*/ __OSThreadprofile_s *thprof; 61 | /*0x20*/ __OSThreadContext context; 62 | } OSThread; 63 | 64 | 65 | /* Functions */ 66 | 67 | void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *), 68 | void *arg, void *sp, OSPri pri); 69 | OSId osGetThreadId(OSThread *thread); 70 | OSPri osGetThreadPri(OSThread *thread); 71 | void osSetThreadPri(OSThread *thread, OSPri pri); 72 | void osStartThread(OSThread *thread); 73 | void osStopThread(OSThread *thread); 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/decomp/tools/convTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define TYPE_CTL 1 7 | #define TYPE_TBL 2 8 | #define TYPE_SEQ 3 9 | 10 | struct CLoop 11 | { 12 | unsigned int start; 13 | unsigned int end; 14 | int count; 15 | unsigned int pad; 16 | short state[1]; 17 | }; 18 | 19 | 20 | struct CBook 21 | { 22 | int order; // must be 2 23 | int npredictors; // must be 2 24 | short table[32]; // 8 * order * npredictors 25 | }; 26 | 27 | struct CSample{ 28 | unsigned int zero; 29 | uintptr_t addr; 30 | struct CLoop* loop; // must not be null 31 | struct CBook* book; // must not be null 32 | unsigned int sample_size; 33 | }; 34 | 35 | struct CSound{ 36 | struct CSample* sample_addr; 37 | float tuning; 38 | }; 39 | 40 | struct delay_arg{ 41 | unsigned short delay; 42 | unsigned short arg; 43 | }; 44 | 45 | struct CEnvelope{ 46 | struct delay_arg delay_args[1]; // array of [(delay,arg)] 47 | }; 48 | 49 | struct CDrum{ 50 | unsigned char release_rate; 51 | unsigned char pan; 52 | unsigned char loaded; 53 | unsigned char pad; 54 | struct CSound snd; 55 | struct CEnvelope* env_addr; 56 | }; 57 | 58 | struct CInstrument{ 59 | unsigned char loaded; 60 | unsigned char normal_range_lo; 61 | unsigned char normal_range_hi; 62 | unsigned char release_rate; 63 | struct CEnvelope* env_addr; 64 | struct CSound sound_lo; 65 | struct CSound sound_med; 66 | struct CSound sound_hi; 67 | }; 68 | 69 | struct TBL{ 70 | unsigned char* data; 71 | }; 72 | 73 | struct SEQ{ 74 | unsigned char* data; 75 | }; 76 | 77 | struct CTL 78 | { 79 | unsigned int numInstruments; 80 | unsigned int numDrums; 81 | unsigned int shared; 82 | unsigned int iso_date; 83 | struct CDrum** drum_pointers; 84 | struct CInstrument* instrument_pointers[1]; 85 | }; 86 | 87 | struct seqObject{ 88 | uintptr_t offset __attribute__((aligned (8))); 89 | unsigned int len __attribute__((aligned (8))); 90 | }; 91 | 92 | struct seqFile{ 93 | unsigned short revision; 94 | unsigned short seqCount; 95 | unsigned int pad; 96 | struct seqObject seqArray[1]; 97 | } __attribute__((aligned (16))); -------------------------------------------------------------------------------- /src/decomp/include/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef MACROS_H 2 | #define MACROS_H 3 | 4 | #include "platform_info.h" 5 | 6 | #ifndef __sgi 7 | #define GLOBAL_ASM(...) 8 | #endif 9 | 10 | // ===== PATCH ===== 11 | #define NON_MATCHING 1 12 | #define AVOID_UB 1 13 | // ================= 14 | 15 | #if !defined(__sgi) && (!defined(NON_MATCHING) || !defined(AVOID_UB)) 16 | // asm-process isn't supported outside of IDO, and undefined behavior causes 17 | // crashes. 18 | #error Matching build is only possible on IDO; please build with NON_MATCHING=1. 19 | #endif 20 | 21 | #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) 22 | 23 | #define GLUE(a, b) a ## b 24 | #define GLUE2(a, b) GLUE(a, b) 25 | 26 | // Avoid compiler warnings for unused variables 27 | #ifdef __GNUC__ 28 | #define UNUSED __attribute__((unused)) 29 | #else 30 | #define UNUSED 31 | #endif 32 | 33 | // Avoid undefined behaviour for non-returning functions 34 | #ifdef __GNUC__ 35 | #define NORETURN __attribute__((noreturn)) 36 | #else 37 | #define NORETURN 38 | #endif 39 | 40 | // Static assertions 41 | #ifdef __GNUC__ 42 | #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) 43 | #else 44 | #define STATIC_ASSERT(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1] 45 | #endif 46 | 47 | // Align to 8-byte boundary for DMA requirements 48 | #ifdef __GNUC__ 49 | #define ALIGNED8 __attribute__((aligned(8))) 50 | #else 51 | #define ALIGNED8 52 | #endif 53 | 54 | // Align to 16-byte boundary for audio lib requirements 55 | #ifdef __GNUC__ 56 | #define ALIGNED16 __attribute__((aligned(16))) 57 | #else 58 | #define ALIGNED16 59 | #endif 60 | 61 | #ifndef NO_SEGMENTED_MEMORY 62 | // convert a virtual address to physical. 63 | #define VIRTUAL_TO_PHYSICAL(addr) ((uintptr_t)(addr) & 0x1FFFFFFF) 64 | 65 | // convert a physical address to virtual. 66 | #define PHYSICAL_TO_VIRTUAL(addr) ((uintptr_t)(addr) | 0x80000000) 67 | 68 | // another way of converting virtual to physical 69 | #define VIRTUAL_TO_PHYSICAL2(addr) ((u8 *)(addr) - 0x80000000U) 70 | #else 71 | // no conversion needed other than cast 72 | #define VIRTUAL_TO_PHYSICAL(addr) ((addr)) 73 | #define PHYSICAL_TO_VIRTUAL(addr) ((addr)) 74 | #define VIRTUAL_TO_PHYSICAL2(addr) ((void *)(addr)) 75 | #endif 76 | 77 | #endif // MACROS_H 78 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_pi.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_PI_H_ 2 | #define _ULTRA64_PI_H_ 3 | #include 4 | 5 | /* Ultra64 Parallel Interface */ 6 | 7 | /* Types */ 8 | 9 | typedef struct { 10 | #if !defined(VERSION_EU) 11 | u32 errStatus; 12 | #endif 13 | void *dramAddr; 14 | void *C2Addr; 15 | u32 sectorSize; 16 | u32 C1ErrNum; 17 | u32 C1ErrSector[4]; 18 | } __OSBlockInfo; 19 | 20 | typedef struct { 21 | u32 cmdType; // 0 22 | u16 transferMode; // 4 23 | u16 blockNum; // 6 24 | s32 sectorNum; // 8 25 | uintptr_t devAddr; // c 26 | #if defined(VERSION_EU) 27 | u32 errStatus; //error status added moved to blockinfo 28 | #endif 29 | u32 bmCtlShadow; // 10 30 | u32 seqCtlShadow; // 14 31 | __OSBlockInfo block[2]; // 18 32 | } __OSTranxInfo; 33 | 34 | typedef struct OSPiHandle_s { 35 | struct OSPiHandle_s *next; 36 | u8 type; 37 | u8 latency; 38 | u8 pageSize; 39 | u8 relDuration; 40 | u8 pulse; 41 | u8 domain; 42 | u32 baseAddress; 43 | u32 speed; 44 | __OSTranxInfo transferInfo; 45 | } OSPiHandle; 46 | 47 | typedef struct { 48 | u8 type; 49 | uintptr_t address; 50 | } OSPiInfo; 51 | 52 | typedef struct { 53 | u16 type; 54 | u8 pri; 55 | u8 status; 56 | OSMesgQueue *retQueue; 57 | } OSIoMesgHdr; 58 | 59 | typedef struct { 60 | /*0x00*/ OSIoMesgHdr hdr; 61 | /*0x08*/ void *dramAddr; 62 | /*0x0C*/ uintptr_t devAddr; 63 | /*0x10*/ size_t size; 64 | #if defined(VERSION_EU) || defined(VERSION_SH) 65 | OSPiHandle *piHandle; // from the official definition 66 | #endif 67 | } OSIoMesg; 68 | 69 | /* Definitions */ 70 | 71 | #define OS_READ 0 // device -> RDRAM 72 | #define OS_WRITE 1 // device <- RDRAM 73 | 74 | #define OS_MESG_PRI_NORMAL 0 75 | #define OS_MESG_PRI_HIGH 1 76 | 77 | /* Functions */ 78 | 79 | s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, uintptr_t devAddr, void *vAddr, 80 | size_t nbytes, OSMesgQueue *mq); 81 | void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt); 82 | OSMesgQueue *osPiGetCmdQueue(void); 83 | s32 osPiWriteIo(uintptr_t devAddr, u32 data); 84 | s32 osPiReadIo(uintptr_t devAddr, u32 *data); 85 | 86 | s32 osPiRawStartDma(s32 dir, u32 cart_addr, void *dram_addr, size_t size); 87 | s32 osEPiRawStartDma(OSPiHandle *piHandle, s32 dir, u32 cart_addr, void *dram_addr, size_t size); 88 | #endif 89 | -------------------------------------------------------------------------------- /src/decomp/game/mario_actions_stationary.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_ACTIONS_STATIONARY 2 | #define MARIO_ACTIONS_STATIONARY 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/types.h" 7 | 8 | s32 check_common_idle_cancels(struct MarioState *m); 9 | s32 check_common_hold_idle_cancels(struct MarioState *m); 10 | s32 act_idle(struct MarioState *m); 11 | void play_anim_sound(struct MarioState *m, u32 actionState, s32 animFrame, u32 sound); 12 | s32 act_start_sleeping(struct MarioState *m); 13 | s32 act_sleeping(struct MarioState *m); 14 | s32 act_waking_up(struct MarioState *m); 15 | s32 act_shivering(struct MarioState *m); 16 | s32 act_coughing(struct MarioState *m); 17 | s32 act_standing_against_wall(struct MarioState *m); 18 | s32 act_in_quicksand(struct MarioState *m); 19 | s32 act_crouching(struct MarioState *m); 20 | s32 act_panting(struct MarioState *m); 21 | void stopping_step(struct MarioState *m, s32 animID, u32 action); 22 | s32 act_braking_stop(struct MarioState *m); 23 | s32 act_butt_slide_stop(struct MarioState *m); 24 | s32 act_hold_butt_slide_stop(struct MarioState *m); 25 | s32 act_slide_kick_slide_stop(struct MarioState *m); 26 | s32 act_start_crouching(struct MarioState *m); 27 | s32 act_stop_crouching(struct MarioState *m); 28 | s32 act_start_crawling(struct MarioState *m); 29 | s32 act_stop_crawling(struct MarioState *m); 30 | s32 act_shockwave_bounce(struct MarioState *m); 31 | s32 landing_step(struct MarioState *m, s32 arg1, u32 action); 32 | s32 check_common_landing_cancels(struct MarioState *m, u32 action); 33 | s32 act_jump_land_stop(struct MarioState *m); 34 | s32 act_double_jump_land_stop(struct MarioState *m); 35 | s32 act_side_flip_land_stop(struct MarioState *m); 36 | s32 act_freefall_land_stop(struct MarioState *m); 37 | s32 act_triple_jump_land_stop(struct MarioState *m); 38 | s32 act_backflip_land_stop(struct MarioState *m); 39 | s32 act_lava_boost_land(struct MarioState *m); 40 | s32 act_long_jump_land_stop(struct MarioState *m); 41 | s32 act_hold_jump_land_stop(struct MarioState *m); 42 | s32 act_hold_freefall_land_stop(struct MarioState *m); 43 | s32 act_air_throw_land(struct MarioState *m); 44 | s32 act_twirl_land(struct MarioState *m); 45 | s32 act_ground_pound_land(struct MarioState *m); 46 | s32 act_first_person(struct MarioState *m); 47 | s32 check_common_stationary_cancels(struct MarioState *m); 48 | s32 mario_execute_stationary_action(struct MarioState *m); 49 | 50 | #endif // MARIO_ACTIONS_STATIONARY 51 | -------------------------------------------------------------------------------- /src/Classic64.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASSIC64_H 2 | #define CLASSIC64_H 3 | 4 | #define MARIO_SCALE 128.f 5 | #define IMARIO_SCALE 128 6 | #define MAX_SURFACES 128 7 | #define DEBUGGER_MAX_VERTICES 8192 8 | 9 | #include 10 | 11 | #include "Classic64_settings.h" 12 | #include "libsm64.h" 13 | 14 | #include "../ClassiCube/src/Bitmap.h" 15 | #include "../ClassiCube/src/Entity.h" 16 | #include "../ClassiCube/src/Graphics.h" 17 | #include "../ClassiCube/src/Vectors.h" 18 | 19 | enum 20 | { 21 | OPCODE_MARIO_HAS_PLUGIN=1, 22 | OPCODE_MARIO_TICK, 23 | OPCODE_MARIO_SET_COLORS, 24 | OPCODE_MARIO_SET_CAP, 25 | OPCODE_MARIO_FORCE, 26 | 27 | MARIOUPDATE_FLAG_COLORS = (1 << 0), 28 | MARIOUPDATE_FLAG_CAP = (1 << 1), 29 | }; 30 | 31 | struct MarioUpdate 32 | { 33 | int flags; 34 | 35 | uint32_t cap; 36 | bool customColors; 37 | struct RGBCol newColors[6]; 38 | }; 39 | extern struct MarioUpdate *marioUpdates[256]; 40 | 41 | extern bool serverHasPlugin; 42 | extern GfxResourceID marioTextureID; 43 | extern struct Bitmap marioBitmap; 44 | 45 | struct MarioInstance // represents a Mario object in the plugin 46 | { 47 | int32_t ID; 48 | uint32_t surfaces[MAX_SURFACES]; 49 | const struct EntityVTABLE* OriginalVTABLE; 50 | struct EntityVTABLE marioVTABLE; 51 | bool customColors; 52 | struct RGBCol colors[6]; 53 | 54 | Vec3 lastPos; 55 | Vec3 currPos; 56 | Vec3 lastGeom[3 * SM64_GEO_MAX_TRIANGLES], lastTexturedGeom[3 * SM64_GEO_MAX_TRIANGLES]; 57 | Vec3 currGeom[3 * SM64_GEO_MAX_TRIANGLES], currTexturedGeom[3 * SM64_GEO_MAX_TRIANGLES]; 58 | 59 | Vec3 lastPole; 60 | int lastPoleHeight; 61 | 62 | struct SM64MarioInputs input; 63 | struct SM64MarioState state; 64 | struct SM64MarioGeometryBuffers geometry; 65 | 66 | struct VertexTextured vertices[4 * SM64_GEO_MAX_TRIANGLES]; 67 | struct VertexTextured texturedVertices[4 * SM64_GEO_MAX_TRIANGLES]; 68 | GfxResourceID vertexID; 69 | GfxResourceID texturedVertexID; 70 | uint16_t numTexturedTriangles; 71 | #ifdef CLASSIC64_DEBUG 72 | struct VertexTextured debuggerVertices[DEBUGGER_MAX_VERTICES]; 73 | uint16_t numDebuggerTriangles; 74 | GfxResourceID debuggerVertexID; 75 | #endif 76 | }; 77 | extern struct MarioInstance *marioInstances[256]; 78 | 79 | bool isGuiOpen(); 80 | void setMarioCap(int i, uint32_t capFlag); 81 | void updateMarioColors(int i, bool on, struct RGBCol colors[6]); 82 | void sendMarioColors(); 83 | 84 | void SendChat(const char* format, const void* arg1, const void* arg2, const void* arg3, const void* arg4); 85 | void OnMarioClientCmd(const cc_string* args, int argsCount); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_ai.h: -------------------------------------------------------------------------------- 1 | 2 | /*==================================================================== 3 | * os_ai.h 4 | * 5 | * Copyright 1995, Silicon Graphics, Inc. 6 | * All Rights Reserved. 7 | * 8 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, 9 | * Inc.; the contents of this file may not be disclosed to third 10 | * parties, copied or duplicated in any form, in whole or in part, 11 | * without the prior written permission of Silicon Graphics, Inc. 12 | * 13 | * RESTRICTED RIGHTS LEGEND: 14 | * Use, duplication or disclosure by the Government is subject to 15 | * restrictions as set forth in subdivision (c)(1)(ii) of the Rights 16 | * in Technical Data and Computer Software clause at DFARS 17 | * 252.227-7013, and/or in similar or successor clauses in the FAR, 18 | * DOD or NASA FAR Supplement. Unpublished - rights reserved under the 19 | * Copyright Laws of the United States. 20 | *====================================================================*/ 21 | 22 | /*---------------------------------------------------------------------* 23 | Copyright (C) 1998 Nintendo. (Originated by SGI) 24 | 25 | $RCSfile: os_ai.h,v $ 26 | $Revision: 1.1 $ 27 | $Date: 1998/10/09 08:01:04 $ 28 | *---------------------------------------------------------------------*/ 29 | 30 | #ifndef _OS_AI_H_ 31 | #define _OS_AI_H_ 32 | 33 | #ifdef _LANGUAGE_C_PLUS_PLUS 34 | extern "C" { 35 | #endif 36 | 37 | #include "ultratypes.h" 38 | 39 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 40 | 41 | /************************************************************************** 42 | * 43 | * Type definitions 44 | * 45 | */ 46 | 47 | 48 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 49 | 50 | /************************************************************************** 51 | * 52 | * Global definitions 53 | * 54 | */ 55 | 56 | 57 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 58 | 59 | /************************************************************************** 60 | * 61 | * Macro definitions 62 | * 63 | */ 64 | 65 | 66 | /************************************************************************** 67 | * 68 | * Extern variables 69 | * 70 | */ 71 | 72 | 73 | /************************************************************************** 74 | * 75 | * Function prototypes 76 | * 77 | */ 78 | 79 | /* Audio interface (Ai) */ 80 | extern u32 osAiGetStatus(void); 81 | extern u32 osAiGetLength(void); 82 | extern s32 osAiSetFrequency(u32); 83 | extern s32 osAiSetNextBuffer(void *, u32); 84 | 85 | 86 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 87 | 88 | #ifdef _LANGUAGE_C_PLUS_PLUS 89 | } 90 | #endif 91 | 92 | #endif /* !_OS_AI_H_ */ 93 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_rdp.h: -------------------------------------------------------------------------------- 1 | 2 | /*==================================================================== 3 | * os_rdp.h 4 | * 5 | * Copyright 1995, Silicon Graphics, Inc. 6 | * All Rights Reserved. 7 | * 8 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, 9 | * Inc.; the contents of this file may not be disclosed to third 10 | * parties, copied or duplicated in any form, in whole or in part, 11 | * without the prior written permission of Silicon Graphics, Inc. 12 | * 13 | * RESTRICTED RIGHTS LEGEND: 14 | * Use, duplication or disclosure by the Government is subject to 15 | * restrictions as set forth in subdivision (c)(1)(ii) of the Rights 16 | * in Technical Data and Computer Software clause at DFARS 17 | * 252.227-7013, and/or in similar or successor clauses in the FAR, 18 | * DOD or NASA FAR Supplement. Unpublished - rights reserved under the 19 | * Copyright Laws of the United States. 20 | *====================================================================*/ 21 | 22 | /*---------------------------------------------------------------------* 23 | Copyright (C) 1998 Nintendo. (Originated by SGI) 24 | 25 | $RCSfile: os_rdp.h,v $ 26 | $Revision: 1.1 $ 27 | $Date: 1998/10/09 08:01:16 $ 28 | *---------------------------------------------------------------------*/ 29 | 30 | #ifndef _OS_RDP_H_ 31 | #define _OS_RDP_H_ 32 | 33 | #ifdef _LANGUAGE_C_PLUS_PLUS 34 | extern "C" { 35 | #endif 36 | 37 | #include "ultratypes.h" 38 | 39 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 40 | 41 | /************************************************************************** 42 | * 43 | * Type definitions 44 | * 45 | */ 46 | 47 | 48 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 49 | 50 | /************************************************************************** 51 | * 52 | * Global definitions 53 | * 54 | */ 55 | 56 | 57 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 58 | 59 | /************************************************************************** 60 | * 61 | * Macro definitions 62 | * 63 | */ 64 | 65 | 66 | /************************************************************************** 67 | * 68 | * Extern variables 69 | * 70 | */ 71 | 72 | 73 | /************************************************************************** 74 | * 75 | * Function prototypes 76 | * 77 | */ 78 | 79 | /* Display processor interface (Dp) */ 80 | extern u32 osDpGetStatus(void); 81 | extern void osDpSetStatus(u32); 82 | extern void osDpGetCounters(u32 *); 83 | extern s32 osDpSetNextBuffer(void *, u64); 84 | 85 | 86 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 87 | 88 | #ifdef _LANGUAGE_C_PLUS_PLUS 89 | } 90 | #endif 91 | 92 | #endif /* !_OS_RDP_H_ */ 93 | -------------------------------------------------------------------------------- /src/decomp/engine/graph_node_manager.c: -------------------------------------------------------------------------------- 1 | #include "../include/PR/ultratypes.h" 2 | 3 | #include "../include/types.h" 4 | 5 | #include "geo_layout.h" 6 | #include "graph_node.h" 7 | 8 | #if IS_64_BIT 9 | static s16 next_s16_in_geo_script(s16 **src) { 10 | s16 ret; 11 | if (((uintptr_t)(*src) & 7) == 4) { 12 | *src += 2; // skip 32 bits 13 | } 14 | ret = *(*src)++; 15 | if (((uintptr_t)(*src) & 7) == 4) { 16 | *src += 2; // skip 32 bits 17 | } 18 | return ret; 19 | } 20 | #else 21 | #define next_s16_in_geo_script(src) (*(*src)++) 22 | #endif 23 | 24 | /** 25 | * Takes a pointer to three shorts (supplied by a geo layout script) and 26 | * copies it to the destination float vector. 27 | */ 28 | s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) { 29 | dst[0] = next_s16_in_geo_script(&src); 30 | dst[1] = next_s16_in_geo_script(&src); 31 | dst[2] = next_s16_in_geo_script(&src); 32 | return src; 33 | } 34 | 35 | /** 36 | * Takes a pointer to three shorts (supplied by a geo layout script) and 37 | * copies it to the destination vector. It's essentially a memcpy but consistent 38 | * with the other two 'geo-script vector to internal vector' functions. 39 | */ 40 | s16 *read_vec3s(Vec3s dst, s16 *src) { 41 | dst[0] = next_s16_in_geo_script(&src); 42 | dst[1] = next_s16_in_geo_script(&src); 43 | dst[2] = next_s16_in_geo_script(&src); 44 | return src; 45 | } 46 | 47 | /** 48 | * Takes a pointer to three angles in degrees (supplied by a geo layout script) 49 | * and converts it to a vector of three in-game angle units in [-32768, 32767] 50 | * range. 51 | */ 52 | s16 *read_vec3s_angle(Vec3s dst, s16 *src) { 53 | dst[0] = (next_s16_in_geo_script(&src) << 15) / 180; 54 | dst[1] = (next_s16_in_geo_script(&src) << 15) / 180; 55 | dst[2] = (next_s16_in_geo_script(&src) << 15) / 180; 56 | return src; 57 | } 58 | 59 | /** 60 | * Add the given graph node as a child to the current top of the gfx stack: 61 | * 'gCurGraphNodeList'. This is called from geo_layout commands to add nodes 62 | * to the scene graph. 63 | */ 64 | void register_scene_graph_node(struct GraphNode *graphNode) { 65 | if (graphNode != NULL) { 66 | gCurGraphNodeList[gCurGraphNodeIndex] = graphNode; 67 | 68 | if (gCurGraphNodeIndex == 0) { 69 | if (gCurRootGraphNode == NULL) { 70 | gCurRootGraphNode = graphNode; 71 | } 72 | } else { 73 | if (gCurGraphNodeList[gCurGraphNodeIndex - 1]->type == GRAPH_NODE_TYPE_OBJECT_PARENT) { 74 | ((struct GraphNodeObjectParent *) gCurGraphNodeList[gCurGraphNodeIndex - 1]) 75 | ->sharedChild = graphNode; 76 | } else { 77 | geo_add_child(gCurGraphNodeList[gCurGraphNodeIndex - 1], graphNode); 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/decomp/include/special_preset_names.h: -------------------------------------------------------------------------------- 1 | #ifndef SPECIAL_PRESET_NAMES_H 2 | #define SPECIAL_PRESET_NAMES_H 3 | 4 | enum SpecialPresets { 5 | special_null_start, 6 | special_yellow_coin, 7 | special_yellow_coin_2, 8 | special_unknown_3, 9 | special_boo, 10 | special_unknown_5, 11 | special_lll_moving_octagonal_mesh_platform, 12 | special_snow_ball, 13 | special_lll_drawbridge_spawner, 14 | special_empty_9, 15 | special_lll_rotating_block_with_fire_bars, 16 | special_lll_floating_wood_bridge, 17 | special_tumbling_platform, 18 | special_lll_rotating_hexagonal_ring, 19 | special_lll_sinking_rectangular_platform, 20 | special_lll_sinking_square_platforms, 21 | special_lll_tilting_square_platform, 22 | special_lll_bowser_puzzle, 23 | special_mr_i, 24 | special_small_bully, 25 | special_big_bully, 26 | special_empty_21, 27 | special_empty_22, 28 | special_empty_23, 29 | special_empty_24, 30 | special_empty_25, 31 | special_moving_blue_coin, 32 | special_jrb_chest, 33 | special_water_ring, 34 | special_mine, 35 | special_empty_30, 36 | special_empty_31, 37 | special_butterfly, 38 | special_bowser, 39 | special_wf_rotating_wooden_platform, 40 | special_small_bomp, 41 | special_wf_sliding_platform, 42 | special_tower_platform_group, 43 | special_rotating_counter_clockwise, 44 | special_wf_tumbling_bridge, 45 | special_large_bomp, 46 | 47 | special_level_geo_03 = 0x65, 48 | special_level_geo_04, 49 | special_level_geo_05, 50 | special_level_geo_06, 51 | special_level_geo_07, 52 | special_level_geo_08, 53 | special_level_geo_09, 54 | special_level_geo_0A, 55 | special_level_geo_0B, 56 | special_level_geo_0C, 57 | special_level_geo_0D, 58 | special_level_geo_0E, 59 | special_level_geo_0F, 60 | special_level_geo_10, 61 | special_level_geo_11, 62 | special_level_geo_12, 63 | special_level_geo_13, 64 | special_level_geo_14, 65 | special_level_geo_15, 66 | special_level_geo_16, 67 | special_bubble_tree, 68 | special_spiky_tree, 69 | special_snow_tree, 70 | special_unknown_tree, 71 | special_palm_tree, 72 | special_wooden_door, 73 | special_haunted_door = special_wooden_door, 74 | special_unknown_door, 75 | special_metal_door, 76 | special_hmc_door, 77 | special_unknown2_door, 78 | special_wooden_door_warp, 79 | special_unknown1_door_warp, 80 | special_metal_door_warp, 81 | special_unknown2_door_warp, 82 | special_unknown3_door_warp, 83 | special_castle_door_warp, 84 | special_castle_door, 85 | special_0stars_door, 86 | special_1star_door, 87 | special_3star_door, 88 | special_key_door, 89 | 90 | special_null_end = 0xFF 91 | }; 92 | 93 | #endif // SPECIAL_PRESET_NAMES_H 94 | -------------------------------------------------------------------------------- /src/decomp/pc/alBnkfNew.c: -------------------------------------------------------------------------------- 1 | #include "libultra_internal.h" 2 | #include "libaudio_internal.h" 3 | 4 | #define PATCH(SRC, BASE, TYPE) //SRC = (TYPE)((uintptr_t) SRC + (uintptr_t) BASE) 5 | 6 | void alSeqFileNew(ALSeqFile *f, u8 *base) { 7 | int i; 8 | for (i = 0; i < f->seqCount; i++) { 9 | PATCH(f->seqArray[i].offset, base, u8 *); 10 | } 11 | } 12 | 13 | static void _bnkfPatchBank(ALInstrument *inst, ALBankFile *f, u8 *table) { 14 | int i; 15 | ALSound *sound; 16 | ALWaveTable *wavetable; 17 | u8 *table2; 18 | 19 | if (inst->flags) { 20 | return; 21 | } 22 | 23 | inst->flags = 1; 24 | 25 | for (i = 0; i < inst->soundCount; i++) { 26 | PATCH(inst->soundArray[i], f, ALSound *); 27 | sound = inst->soundArray[i]; 28 | if (sound->flags) { 29 | continue; 30 | } 31 | 32 | table2 = table; 33 | 34 | sound->flags = 1; 35 | PATCH(sound->envelope, f, ALEnvelope *); 36 | PATCH(sound->keyMap, f, ALKeyMap *); 37 | PATCH(sound->wavetable, f, ALWaveTable *); 38 | wavetable = sound->wavetable; 39 | if (wavetable->flags) { 40 | continue; 41 | } 42 | 43 | wavetable->flags = 1; 44 | PATCH(wavetable->base, table2, u8 *); 45 | if (wavetable->type == 0) { 46 | PATCH(wavetable->waveInfo.adpcmWave.book, f, ALADPCMBook *); 47 | if (wavetable->waveInfo.adpcmWave.loop != NULL) { 48 | PATCH(wavetable->waveInfo.adpcmWave.loop, f, ALADPCMloop *); 49 | } 50 | } else if (wavetable->type == 1) { 51 | if (wavetable->waveInfo.rawWave.loop != NULL) { 52 | PATCH(wavetable->waveInfo.rawWave.loop, f, ALRawLoop *); 53 | } 54 | } 55 | } 56 | } 57 | 58 | // Force adding another jr $ra. Has to be called or it doesn't get put in the 59 | // right place. 60 | static void unused(void) { 61 | } 62 | 63 | void alBnkfNew(ALBankFile *f, u8 *table) { 64 | ALBank *bank; 65 | int i; 66 | int j; 67 | unused(); 68 | if (f->revision != AL_BANK_VERSION) { 69 | return; 70 | } 71 | 72 | for (i = 0; i < f->bankCount; i++) { 73 | PATCH(f->bankArray[i], f, ALBank *); 74 | if (f->bankArray[i] == NULL) { 75 | continue; 76 | } 77 | 78 | bank = f->bankArray[i]; 79 | if (bank->flags == 0) { 80 | bank->flags = 1; 81 | if (bank->percussion != NULL) { 82 | PATCH(bank->percussion, f, ALInstrument *); 83 | _bnkfPatchBank(bank->percussion, f, table); 84 | } 85 | for (j = 0; j < bank->instCount; j++) { 86 | PATCH(bank->instArray[j], f, ALInstrument *); 87 | if (bank->instArray[j] != NULL) { 88 | _bnkfPatchBank(bank->instArray[j], f, table); 89 | } 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_cache.h: -------------------------------------------------------------------------------- 1 | 2 | /*==================================================================== 3 | * os_cache.h 4 | * 5 | * Copyright 1995, Silicon Graphics, Inc. 6 | * All Rights Reserved. 7 | * 8 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, 9 | * Inc.; the contents of this file may not be disclosed to third 10 | * parties, copied or duplicated in any form, in whole or in part, 11 | * without the prior written permission of Silicon Graphics, Inc. 12 | * 13 | * RESTRICTED RIGHTS LEGEND: 14 | * Use, duplication or disclosure by the Government is subject to 15 | * restrictions as set forth in subdivision (c)(1)(ii) of the Rights 16 | * in Technical Data and Computer Software clause at DFARS 17 | * 252.227-7013, and/or in similar or successor clauses in the FAR, 18 | * DOD or NASA FAR Supplement. Unpublished - rights reserved under the 19 | * Copyright Laws of the United States. 20 | *====================================================================*/ 21 | 22 | /*---------------------------------------------------------------------* 23 | Copyright (C) 1998 Nintendo. (Originated by SGI) 24 | 25 | $RCSfile: os_cache.h,v $ 26 | $Revision: 1.1 $ 27 | $Date: 1998/10/09 08:01:04 $ 28 | *---------------------------------------------------------------------*/ 29 | 30 | #ifndef _OS_CACHE_H_ 31 | #define _OS_CACHE_H_ 32 | 33 | #ifdef _LANGUAGE_C_PLUS_PLUS 34 | extern "C" { 35 | #endif 36 | 37 | #include "ultratypes.h" 38 | 39 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 40 | 41 | /************************************************************************** 42 | * 43 | * Type definitions 44 | * 45 | */ 46 | 47 | 48 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 49 | 50 | /************************************************************************** 51 | * 52 | * Global definitions 53 | * 54 | */ 55 | 56 | 57 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 58 | 59 | /************************************************************************** 60 | * 61 | * Macro definitions 62 | * 63 | */ 64 | 65 | #define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) 66 | #define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) 67 | 68 | 69 | /************************************************************************** 70 | * 71 | * Extern variables 72 | * 73 | */ 74 | 75 | 76 | /************************************************************************** 77 | * 78 | * Function prototypes 79 | * 80 | */ 81 | 82 | /* Cache operations and macros */ 83 | 84 | extern void osInvalDCache(void *, size_t); 85 | extern void osInvalICache(void *, size_t); 86 | extern void osWritebackDCache(void *, size_t); 87 | extern void osWritebackDCacheAll(void); 88 | 89 | 90 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 91 | 92 | #ifdef _LANGUAGE_C_PLUS_PLUS 93 | } 94 | #endif 95 | 96 | #endif /* !_OS_CACHE_H_ */ 97 | -------------------------------------------------------------------------------- /src/decomp/shim.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "include/types.h" 4 | #include "game/area.h" 5 | #include "game/level_update.h" 6 | #include "../libsm64.h" 7 | #include "../play_sound.h" 8 | #include "global_state.h" 9 | 10 | #define COURSE_MIN 0 11 | #define COURSE_MAX 14 12 | #define LEVEL_LLL 99 13 | #define LEVEL_SSL 98 14 | #define LEVEL_DDD 97 15 | #define LEVEL_TTC 96 16 | #define LEVEL_CASTLE 95 17 | #define LEVEL_THI 94 18 | 19 | #define gGlobalTimer (g_state->mgGlobalTimer) 20 | #define gSpecialTripleJump (g_state->mgSpecialTripleJump) 21 | #define gCurrLevelNum (g_state->mgCurrLevelNum) 22 | #define gCameraMovementFlags (g_state->mgCameraMovementFlags) 23 | //#define gAudioRandom (g_state->mgAudioRandom) 24 | #define gShowDebugText (g_state->mgShowDebugText) 25 | #define gDebugLevelSelect (g_state->mgDebugLevelSelect) 26 | #define gCurrSaveFileNum (g_state->mgCurrSaveFileNum) 27 | #define gController (g_state->mgController) 28 | #define gMarioSpawnInfoVal (g_state->mgMarioSpawnInfoVal) 29 | #define gMarioSpawnInfo (&g_state->mgMarioSpawnInfoVal) 30 | #define gCurrentArea (g_state->mgCurrentArea) 31 | #define gCurrentObject (g_state->mgCurrentObject) 32 | #define gMarioObject (g_state->mgMarioObject) 33 | #define D_80339D10 (g_state->mD_80339D10) 34 | #define gMarioState (&g_state->mgMarioStateVal) 35 | #define gAreaUpdateCounter (g_state->mgAreaUpdateCounter) 36 | 37 | #pragma GCC diagnostic push 38 | #pragma GCC diagnostic ignored "-Wunused-function" 39 | 40 | static void enable_time_stop() {} 41 | static void disable_time_stop() {} 42 | static void *segmented_to_virtual(const void *addr) { return (void*)addr; } 43 | static void *virtual_to_segmented(u32 segment, const void *addr) { return (void*)addr; } 44 | static void func_80320A4C(u8 bankIndex, u8 arg1) {} 45 | static void raise_background_noise(s32 a) {} 46 | static void lower_background_noise(s32 a) {} 47 | static void set_camera_mode(struct Camera *c, s16 mode, s16 frames) {} 48 | static void print_text_fmt_int(s32 x, s32 y, const char *str, s32 n) {} 49 | static s16 level_trigger_warp(struct MarioState *m, s32 warpOp) { return 0; } 50 | static void play_cap_music(u16 seqArgs) {} 51 | static void fadeout_cap_music(void) {} 52 | static void stop_cap_music(void) {} 53 | static void play_infinite_stairs_music(void) {} 54 | static s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse) { return 0; } 55 | static u32 save_file_get_flags(void) { return 0; } 56 | static void save_file_set_flags(u32 flags) {} 57 | static void save_file_clear_flags(u32 flags) {} 58 | static void spawn_wind_particles(s16 pitch, s16 yaw) {} 59 | static void set_camera_shake_from_hit(s16 shake) {} 60 | static void load_level_init_text(u32 arg) {} 61 | static void spawn_default_star(f32 sp20, f32 sp24, f32 sp28) {} 62 | static void play_shell_music(void) {} 63 | static void stop_shell_music(void) {} 64 | static u16 level_control_timer(s32 timerOp) { return 0; } 65 | 66 | #pragma GCC diagnostic pop -------------------------------------------------------------------------------- /src/decomp/include/PR/os_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_VI_H_ 2 | #define _ULTRA64_VI_H_ 3 | 4 | #include "ultratypes.h" 5 | #include "os_message.h" 6 | 7 | /* Ultra64 Video Interface */ 8 | 9 | 10 | /* Special Features */ 11 | #define OS_VI_GAMMA_ON 0x0001 12 | #define OS_VI_GAMMA_OFF 0x0002 13 | #define OS_VI_GAMMA_DITHER_ON 0x0004 14 | #define OS_VI_GAMMA_DITHER_OFF 0x0008 15 | #define OS_VI_DIVOT_ON 0x0010 16 | #define OS_VI_DIVOT_OFF 0x0020 17 | #define OS_VI_DITHER_FILTER_ON 0x0040 18 | #define OS_VI_DITHER_FILTER_OFF 0x0080 19 | 20 | #define OS_VI_GAMMA 0x08 21 | #define OS_VI_GAMMA_DITHER 0x04 22 | #define OS_VI_DIVOT 0x10 23 | #define OS_VI_DITHER_FILTER 0x10000 24 | #define OS_VI_UNK200 0x200 25 | #define OS_VI_UNK100 0x100 26 | 27 | 28 | /* Types */ 29 | 30 | typedef struct 31 | { 32 | u32 ctrl; 33 | u32 width; 34 | u32 burst; 35 | u32 vSync; 36 | u32 hSync; 37 | u32 leap; 38 | u32 hStart; 39 | u32 xScale; 40 | u32 vCurrent; 41 | } OSViCommonRegs; 42 | 43 | typedef struct 44 | { 45 | u32 origin; 46 | u32 yScale; 47 | u32 vStart; 48 | u32 vBurst; 49 | u32 vIntr; 50 | } OSViFieldRegs; 51 | 52 | typedef struct 53 | { 54 | u8 type; 55 | OSViCommonRegs comRegs; 56 | OSViFieldRegs fldRegs[2]; 57 | } OSViMode; 58 | 59 | typedef struct 60 | { 61 | /* 0x00 */ u16 unk00; //some kind of flags. swap buffer sets to 0x10 62 | /* 0x02 */ u16 retraceCount; 63 | /* 0x04 */ void* buffer; 64 | /* 0x08 */ OSViMode *modep; 65 | /* 0x0c */ u32 features; 66 | /* 0x10 */ OSMesgQueue *mq; 67 | /* 0x14 */ OSMesg *msg; 68 | /* 0x18 */ u32 unk18; 69 | /* 0x1c */ u32 unk1c; 70 | /* 0x20 */ u32 unk20; 71 | /* 0x24 */ f32 unk24; 72 | /* 0x28 */ u16 unk28; 73 | /* 0x2c */ u32 unk2c; 74 | } OSViContext; 75 | 76 | void osCreateViManager(OSPri pri); 77 | void osViSetMode(OSViMode *mode); 78 | void osViSetEvent(OSMesgQueue *mq, OSMesg msg, u32 retraceCount); 79 | void osViBlack(u8 active); 80 | void osViSetSpecialFeatures(u32 func); 81 | void osViSwapBuffer(void *vaddr); 82 | 83 | 84 | #define OS_VI_NTSC_LPN1 0 /* NTSC */ 85 | #define OS_VI_NTSC_LPF1 1 86 | #define OS_VI_NTSC_LAN1 2 87 | #define OS_VI_NTSC_LAF1 3 88 | #define OS_VI_NTSC_LPN2 4 89 | #define OS_VI_NTSC_LPF2 5 90 | #define OS_VI_NTSC_LAN2 6 91 | #define OS_VI_NTSC_LAF2 7 92 | #define OS_VI_NTSC_HPN1 8 93 | #define OS_VI_NTSC_HPF1 9 94 | #define OS_VI_NTSC_HAN1 10 95 | #define OS_VI_NTSC_HAF1 11 96 | #define OS_VI_NTSC_HPN2 12 97 | #define OS_VI_NTSC_HPF2 13 98 | 99 | #define OS_VI_PAL_LPN1 14 /* PAL */ 100 | #define OS_VI_PAL_LPF1 15 101 | #define OS_VI_PAL_LAN1 16 102 | #define OS_VI_PAL_LAF1 17 103 | #define OS_VI_PAL_LPN2 18 104 | #define OS_VI_PAL_LPF2 19 105 | #define OS_VI_PAL_LAN2 20 106 | #define OS_VI_PAL_LAF2 21 107 | #define OS_VI_PAL_HPN1 22 108 | #define OS_VI_PAL_HPF1 23 109 | #define OS_VI_PAL_HAN1 24 110 | #define OS_VI_PAL_HAF1 25 111 | #define OS_VI_PAL_HPN2 26 112 | #define OS_VI_PAL_HPF2 27 113 | 114 | extern OSViMode osViModeTable[]; /* Global VI mode table */ 115 | 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /src/decomp/game/mario.h: -------------------------------------------------------------------------------- 1 | #ifndef MARIO_H 2 | #define MARIO_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../include/macros.h" 7 | #include "../include/types.h" 8 | 9 | s32 is_anim_at_end(struct MarioState *m); 10 | s32 is_anim_past_end(struct MarioState *m); 11 | s16 set_mario_animation(struct MarioState *m, s32 targetAnimID); 12 | s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel); 13 | void set_anim_to_frame(struct MarioState *m, s16 animFrame); 14 | s32 is_anim_past_frame(struct MarioState *m, s16 animFrame); 15 | s16 find_mario_anim_flags_and_translation(struct Object *o, s32 yaw, Vec3s translation); 16 | void update_mario_pos_for_anim(struct MarioState *m); 17 | s16 return_mario_anim_y_translation(struct MarioState *m); 18 | void play_sound_if_no_flag(struct MarioState *m, u32 soundBits, u32 flags); 19 | void play_mario_jump_sound(struct MarioState *m); 20 | void adjust_sound_for_speed(struct MarioState *m); 21 | void play_sound_and_spawn_particles(struct MarioState *m, u32 soundBits, u32 waveParticleType); 22 | void play_mario_action_sound(struct MarioState *m, u32 soundBits, u32 waveParticleType); 23 | void play_mario_landing_sound(struct MarioState *m, u32 soundBits); 24 | void play_mario_landing_sound_once(struct MarioState *m, u32 soundBits); 25 | void play_mario_heavy_landing_sound(struct MarioState *m, u32 soundBits); 26 | void play_mario_heavy_landing_sound_once(struct MarioState *m, u32 soundBits); 27 | void play_mario_sound(struct MarioState *m, s32 primarySoundBits, s32 scondarySoundBits); 28 | void mario_set_forward_vel(struct MarioState *m, f32 speed); 29 | s32 mario_get_floor_class(struct MarioState *m); 30 | u32 mario_get_terrain_sound_addend(struct MarioState *m); 31 | struct SM64SurfaceCollisionData *resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius); 32 | f32 vec3f_find_ceil(Vec3f pos, f32 height, struct SM64SurfaceCollisionData **ceil); 33 | s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw); 34 | u32 mario_floor_is_slippery(struct MarioState *m); 35 | s32 mario_floor_is_slope(struct MarioState *m); 36 | s32 mario_floor_is_steep(struct MarioState *m); 37 | f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario); 38 | s16 find_floor_slope(struct MarioState *m, s16 yawOffset); 39 | void update_mario_sound_and_camera(struct MarioState *m); 40 | void set_steep_jump_action(struct MarioState *m); 41 | u32 set_mario_action(struct MarioState *, u32 action, u32 actionArg); 42 | s32 set_jump_from_landing(struct MarioState *m); 43 | s32 set_jumping_action(struct MarioState *m, u32 action, u32 actionArg); 44 | s32 drop_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg); 45 | s32 hurt_and_set_mario_action(struct MarioState *m, u32 action, u32 actionArg, s16 hurtCounter); 46 | s32 check_common_action_exits(struct MarioState *m); 47 | s32 check_common_hold_action_exits(struct MarioState *m); 48 | s32 transition_submerged_to_walking(struct MarioState *m); 49 | s32 set_water_plunge_action(struct MarioState *m); 50 | s32 execute_mario_action(UNUSED struct Object *o); 51 | int init_mario(void); 52 | void init_mario_from_save_file(void); 53 | 54 | #endif // MARIO_H 55 | -------------------------------------------------------------------------------- /src/decomp/audio/external.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_EXTERNAL_H 2 | #define AUDIO_EXTERNAL_H 3 | 4 | #include 5 | 6 | #include 7 | 8 | // Sequence arguments, passed to seq_player_play_sequence. seqId may be bit-OR'ed with 9 | // SEQ_VARIATION; this will load the same sequence, but set a variation 10 | // bit which may be read by the sequence script. 11 | #define SEQUENCE_ARGS(priority, seqId) ((priority << 8) | seqId) 12 | 13 | #define SOUND_MODE_STEREO 0 14 | #define SOUND_MODE_MONO 3 15 | #define SOUND_MODE_HEADSET 1 16 | 17 | #define SEQ_PLAYER_LEVEL 0 // Level background music 18 | #define SEQ_PLAYER_ENV 1 // Misc music like the puzzle jingle 19 | #define SEQ_PLAYER_SFX 2 // Sound effects 20 | 21 | extern s32 gAudioErrorFlags; 22 | extern f32 gGlobalSoundSource[3]; 23 | extern u32 gAudioRandom; 24 | extern f32 gAudioVolume; 25 | extern u8 gAudioReverb; 26 | 27 | struct Sound { 28 | s32 soundBits; 29 | f32 *position; 30 | }; // size = 0x8 31 | 32 | extern struct Sound sSoundRequests[0x100]; 33 | extern u8 sSoundRequestCount; 34 | 35 | extern u8 gAudioSPTaskYieldBuffer[]; // ucode yield data ptr; only used in JP 36 | 37 | struct SPTask *create_next_audio_frame_task(void); 38 | void create_next_audio_buffer(s16 *samples, u32 num_samples); 39 | void audio_signal_game_loop_tick(void); 40 | void update_game_sound(void); 41 | void seq_player_fade_out(u8 player, u16 fadeDuration); 42 | void fade_volume_scale(u8 player, u8 targetScale, u16 fadeDuration); 43 | void seq_player_lower_volume(u8 player, u16 fadeDuration, u8 percentage); 44 | void seq_player_unlower_volume(u8 player, u16 fadeDuration); 45 | void set_audio_muted(u8 muted); 46 | void sound_init(void); 47 | void get_currently_playing_sound(u8 bank, u8 *numPlayingSounds, u8 *numSoundsInBank, u8 *soundId); 48 | void stop_sound(u32 soundBits, f32 *pos); 49 | void stop_sounds_from_source(f32 *pos); 50 | void stop_sounds_in_continuous_banks(void); 51 | void sound_banks_disable(u8 player, u16 bankMask); 52 | void sound_banks_enable(u8 player, u16 bankMask); 53 | void set_sound_moving_speed(u8 bank, u8 speed); 54 | void play_dialog_sound(u8 dialogID); 55 | void play_music(u8 player, u16 seqArgs, u16 fadeTimer); 56 | void stop_background_music(u16 seqId); 57 | void fadeout_background_music(u16 arg0, u16 fadeOut); 58 | void drop_queued_background_music(void); 59 | u16 get_current_background_music(void); 60 | void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer); 61 | void func_80321080(u16 fadeTimer); 62 | void func_803210D4(u16 fadeOutTime); 63 | void play_course_clear(void); 64 | void play_peachs_jingle(void); 65 | void play_puzzle_jingle(void); 66 | void play_star_fanfare(void); 67 | void play_power_star_jingle(u8 arg0); 68 | void play_race_fanfare(void); 69 | void play_toads_jingle(void); 70 | void sound_reset(u8 presetId); 71 | void audio_set_sound_mode(u8 arg0); 72 | 73 | void audio_init(void); // in load.c 74 | void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2); 75 | 76 | #if defined(VERSION_EU) || defined(VERSION_SH) 77 | struct SPTask *unused_80321460(); 78 | struct SPTask *unused_80321460(void); 79 | #endif 80 | 81 | #endif // AUDIO_EXTERNAL_H 82 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_tlb.h: -------------------------------------------------------------------------------- 1 | 2 | /*==================================================================== 3 | * os_tlb.h 4 | * 5 | * Copyright 1995, Silicon Graphics, Inc. 6 | * All Rights Reserved. 7 | * 8 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, 9 | * Inc.; the contents of this file may not be disclosed to third 10 | * parties, copied or duplicated in any form, in whole or in part, 11 | * without the prior written permission of Silicon Graphics, Inc. 12 | * 13 | * RESTRICTED RIGHTS LEGEND: 14 | * Use, duplication or disclosure by the Government is subject to 15 | * restrictions as set forth in subdivision (c)(1)(ii) of the Rights 16 | * in Technical Data and Computer Software clause at DFARS 17 | * 252.227-7013, and/or in similar or successor clauses in the FAR, 18 | * DOD or NASA FAR Supplement. Unpublished - rights reserved under the 19 | * Copyright Laws of the United States. 20 | *====================================================================*/ 21 | 22 | /*---------------------------------------------------------------------* 23 | Copyright (C) 1998 Nintendo. (Originated by SGI) 24 | 25 | $RCSfile: os_tlb.h,v $ 26 | $Revision: 1.1 $ 27 | $Date: 1998/10/09 08:01:20 $ 28 | *---------------------------------------------------------------------*/ 29 | 30 | #ifndef _OS_TLB_H_ 31 | #define _OS_TLB_H_ 32 | 33 | #ifdef _LANGUAGE_C_PLUS_PLUS 34 | extern "C" { 35 | #endif 36 | 37 | #include "ultratypes.h" 38 | 39 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 40 | 41 | /************************************************************************** 42 | * 43 | * Type definitions 44 | * 45 | */ 46 | 47 | typedef u32 OSPageMask; 48 | 49 | 50 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 51 | 52 | /************************************************************************** 53 | * 54 | * Global definitions 55 | * 56 | */ 57 | 58 | /* 59 | * Page size argument for TLB routines 60 | */ 61 | #define OS_PM_4K 0x0000000 62 | #define OS_PM_16K 0x0006000 63 | #define OS_PM_64K 0x001e000 64 | #define OS_PM_256K 0x007e000 65 | #define OS_PM_1M 0x01fe000 66 | #define OS_PM_4M 0x07fe000 67 | #define OS_PM_16M 0x1ffe000 68 | 69 | 70 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 71 | 72 | /************************************************************************** 73 | * 74 | * Macro definitions 75 | * 76 | */ 77 | 78 | 79 | /************************************************************************** 80 | * 81 | * Extern variables 82 | * 83 | */ 84 | 85 | 86 | /************************************************************************** 87 | * 88 | * Function prototypes 89 | * 90 | */ 91 | 92 | /* TLB management routines */ 93 | 94 | extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); 95 | extern void osMapTLBRdb(void); 96 | extern void osUnmapTLB(s32); 97 | extern void osUnmapTLBAll(void); 98 | extern void osSetTLBASID(s32); 99 | 100 | 101 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 102 | 103 | #ifdef _LANGUAGE_C_PLUS_PLUS 104 | } 105 | #endif 106 | 107 | #endif /* !_OS_TLB_H_ */ 108 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_eeprom.h: -------------------------------------------------------------------------------- 1 | 2 | /*==================================================================== 3 | * os_eeprom.h 4 | * 5 | * Copyright 1995, Silicon Graphics, Inc. 6 | * All Rights Reserved. 7 | * 8 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, 9 | * Inc.; the contents of this file may not be disclosed to third 10 | * parties, copied or duplicated in any form, in whole or in part, 11 | * without the prior written permission of Silicon Graphics, Inc. 12 | * 13 | * RESTRICTED RIGHTS LEGEND: 14 | * Use, duplication or disclosure by the Government is subject to 15 | * restrictions as set forth in subdivision (c)(1)(ii) of the Rights 16 | * in Technical Data and Computer Software clause at DFARS 17 | * 252.227-7013, and/or in similar or successor clauses in the FAR, 18 | * DOD or NASA FAR Supplement. Unpublished - rights reserved under the 19 | * Copyright Laws of the United States. 20 | *====================================================================*/ 21 | 22 | /*---------------------------------------------------------------------* 23 | Copyright (C) 1998 Nintendo. (Originated by SGI) 24 | 25 | $RCSfile: os_eeprom.h,v $ 26 | $Revision: 1.1 $ 27 | $Date: 1998/10/09 08:01:06 $ 28 | *---------------------------------------------------------------------*/ 29 | 30 | #ifndef _OS_EEPROM_H_ 31 | #define _OS_EEPROM_H_ 32 | 33 | #ifdef _LANGUAGE_C_PLUS_PLUS 34 | extern "C" { 35 | #endif 36 | 37 | #include "ultratypes.h" 38 | #include "os_message.h" 39 | 40 | 41 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 42 | 43 | /************************************************************************** 44 | * 45 | * Type definitions 46 | * 47 | */ 48 | 49 | 50 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 51 | 52 | /************************************************************************** 53 | * 54 | * Global definitions 55 | * 56 | */ 57 | 58 | /* EEPROM TYPE */ 59 | 60 | #define EEPROM_TYPE_4K 0x01 61 | #define EEPROM_TYPE_16K 0x02 62 | 63 | /* definition for EEPROM */ 64 | 65 | #define EEPROM_MAXBLOCKS 64 66 | #define EEP16K_MAXBLOCKS 256 67 | #define EEPROM_BLOCK_SIZE 8 68 | 69 | 70 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 71 | 72 | /************************************************************************** 73 | * 74 | * Macro definitions 75 | * 76 | */ 77 | 78 | 79 | /************************************************************************** 80 | * 81 | * Extern variables 82 | * 83 | */ 84 | 85 | 86 | /************************************************************************** 87 | * 88 | * Function prototypes 89 | * 90 | */ 91 | 92 | /* EEPROM interface */ 93 | 94 | extern s32 osEepromProbe(OSMesgQueue *); 95 | extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); 96 | extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); 97 | extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); 98 | extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); 99 | 100 | 101 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 102 | 103 | #ifdef _LANGUAGE_C_PLUS_PLUS 104 | } 105 | #endif 106 | 107 | #endif /* !_OS_EEPROM_H_ */ 108 | -------------------------------------------------------------------------------- /src/decomp/engine/geo_layout.h: -------------------------------------------------------------------------------- 1 | #ifndef GEO_LAYOUT_H 2 | #define GEO_LAYOUT_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | 6 | #include "../memory.h" 7 | #include "../include/macros.h" 8 | #include "../include/types.h" 9 | 10 | #define GEO_CMD_FLAGS_RESET 0 11 | #define GEO_CMD_FLAGS_SET 1 12 | #define GEO_CMD_FLAGS_CLEAR 2 13 | 14 | #define CMD_SIZE_SHIFT (sizeof(void *) >> 3) 15 | #define CMD_PROCESS_OFFSET(offset) (((offset) & 3) | (((offset) & ~3) << CMD_SIZE_SHIFT)) 16 | 17 | #define cur_geo_cmd_u8(offset) \ 18 | (gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)]) 19 | 20 | #define cur_geo_cmd_s16(offset) \ 21 | (*(s16 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)]) 22 | 23 | #define cur_geo_cmd_s32(offset) \ 24 | (*(s32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)]) 25 | 26 | #define cur_geo_cmd_u32(offset) \ 27 | (*(u32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)]) 28 | 29 | #define cur_geo_cmd_ptr(offset) \ 30 | (*(void **) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)]) 31 | 32 | extern struct AllocOnlyPool *gGraphNodePool; 33 | extern struct GraphNode *gCurRootGraphNode; 34 | extern UNUSED s32 D_8038BCA8; 35 | extern struct GraphNode **gGeoViews; 36 | extern u16 gGeoNumViews; 37 | extern uintptr_t gGeoLayoutStack[]; 38 | extern struct GraphNode *gCurGraphNodeList[]; 39 | extern s16 gCurGraphNodeIndex; 40 | extern s16 gGeoLayoutStackIndex; 41 | extern UNUSED s16 D_8038BD7C; 42 | extern s16 gGeoLayoutReturnIndex; 43 | extern u8 *gGeoLayoutCommand; 44 | extern struct GraphNode gObjParentGraphNode; 45 | 46 | extern struct AllocOnlyPool *D_8038BCA0; 47 | extern struct GraphNode *D_8038BCA4; 48 | extern s16 D_8038BD78; 49 | extern struct GraphNode *D_8038BCF8[]; 50 | 51 | void geo_layout_cmd_branch_and_link(void); 52 | void geo_layout_cmd_end(void); 53 | void geo_layout_cmd_branch(void); 54 | void geo_layout_cmd_return(void); 55 | void geo_layout_cmd_open_node(void); 56 | void geo_layout_cmd_close_node(void); 57 | void geo_layout_cmd_assign_as_view(void); 58 | void geo_layout_cmd_update_node_flags(void); 59 | void geo_layout_cmd_node_root(void); 60 | void geo_layout_cmd_node_ortho_projection(void); 61 | void geo_layout_cmd_node_perspective(void); 62 | void geo_layout_cmd_node_start(void); 63 | void geo_layout_cmd_nop3(void); 64 | void geo_layout_cmd_node_master_list(void); 65 | void geo_layout_cmd_node_level_of_detail(void); 66 | void geo_layout_cmd_node_switch_case(void); 67 | void geo_layout_cmd_node_camera(void); 68 | void geo_layout_cmd_node_translation_rotation(void); 69 | void geo_layout_cmd_node_translation(void); 70 | void geo_layout_cmd_node_rotation(void); 71 | void geo_layout_cmd_node_scale(void); 72 | void geo_layout_cmd_nop2(void); 73 | void geo_layout_cmd_node_animated_part(void); 74 | void geo_layout_cmd_node_billboard(void); 75 | void geo_layout_cmd_node_display_list(void); 76 | void geo_layout_cmd_node_shadow(void); 77 | void geo_layout_cmd_node_object_parent(void); 78 | void geo_layout_cmd_node_generated(void); 79 | void geo_layout_cmd_node_background(void); 80 | void geo_layout_cmd_nop(void); 81 | void geo_layout_cmd_copy_view(void); 82 | void geo_layout_cmd_node_held_obj(void); 83 | void geo_layout_cmd_node_culling_radius(void); 84 | 85 | struct GraphNode *process_geo_layout(struct AllocOnlyPool *a0, void *segptr); 86 | 87 | #endif // GEO_LAYOUT_H 88 | -------------------------------------------------------------------------------- /test/context.c: -------------------------------------------------------------------------------- 1 | #include "context.h" 2 | 3 | #include 4 | 5 | static SDL_Window *s_sdlWindow; 6 | static SDL_GLContext s_sdlGlContext; 7 | static SDL_GameController *s_controller; 8 | static int s_windowWidth; 9 | static int s_windowHeight; 10 | 11 | void context_init( const char *title, int width, int height ) 12 | { 13 | if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 ) goto err; 14 | 15 | SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); 16 | SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 ); 17 | SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 ); 18 | SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 ); 19 | SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); 20 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); 21 | SDL_GL_SetSwapInterval( 1 ); 22 | 23 | s_windowWidth = width; 24 | s_windowHeight = height; 25 | 26 | s_sdlWindow = SDL_CreateWindow( 27 | title, 28 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 29 | width, height, 30 | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE 31 | ); 32 | 33 | if( !s_sdlWindow ) goto err; 34 | 35 | s_sdlGlContext = SDL_GL_CreateContext( s_sdlWindow ); 36 | 37 | if( !s_sdlGlContext ) goto err; 38 | 39 | #ifndef __APPLE__ 40 | glewExperimental = GL_TRUE; 41 | const GLenum glewInitResult = glewInit(); 42 | if( glewInitResult != GLEW_OK ) goto err; 43 | #endif 44 | 45 | s_controller = NULL; 46 | 47 | for( int i = 0; i < SDL_NumJoysticks(); ++i ) 48 | { 49 | if( ! SDL_IsGameController( i ) ) continue; 50 | s_controller = SDL_GameControllerOpen( i ); 51 | printf( "Using game controller: %s", SDL_GameControllerName( s_controller ) ); 52 | if( s_controller ) break; 53 | } 54 | 55 | return; 56 | 57 | err: 58 | SDL_GL_DeleteContext( s_sdlGlContext ); 59 | SDL_DestroyWindow( s_sdlWindow ); 60 | SDL_Quit(); 61 | } 62 | 63 | SDL_GameController *context_get_controller( void ) 64 | { 65 | return s_controller; 66 | } 67 | 68 | bool context_flip_frame_poll_events( void ) 69 | { 70 | bool still_running = true; 71 | 72 | SDL_GL_SwapWindow( s_sdlWindow ); 73 | 74 | SDL_Event event; 75 | 76 | while( SDL_PollEvent( &event ) ) 77 | { 78 | switch( event.type ) 79 | { 80 | case SDL_QUIT: 81 | still_running = false; 82 | break; 83 | 84 | case SDL_KEYDOWN: 85 | if( event.key.keysym.sym == SDLK_ESCAPE ) 86 | still_running = false; 87 | 88 | case SDL_WINDOWEVENT: 89 | if( event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED ) 90 | { 91 | s_windowWidth = event.window.data1; 92 | s_windowHeight = event.window.data2; 93 | glViewport( 0, 0, s_windowWidth, s_windowHeight ); 94 | } 95 | break; 96 | } 97 | } 98 | 99 | return still_running; 100 | } 101 | 102 | void context_terminate( void ) 103 | { 104 | if( !s_sdlWindow ) 105 | return; 106 | 107 | if( s_controller ) 108 | SDL_GameControllerClose( s_controller ); 109 | 110 | SDL_GL_DeleteContext( s_sdlGlContext ); 111 | SDL_DestroyWindow( s_sdlWindow ); 112 | SDL_Quit(); 113 | 114 | s_sdlWindow = NULL; 115 | } -------------------------------------------------------------------------------- /src/Classic64_events.c: -------------------------------------------------------------------------------- 1 | #include "Classic64_events.h" 2 | 3 | #include "Classic64.h" 4 | #include "Classic64_settings.h" 5 | 6 | #include "../ClassiCube/src/Entity.h" 7 | #include "../ClassiCube/src/Graphics.h" 8 | #include "../ClassiCube/src/Model.h" 9 | #include "../ClassiCube/src/Protocol.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | void OnChatMessage(void* obj, const cc_string* msg, int msgType) 16 | { 17 | // if message starts with this, run as a mario64 client command 18 | cc_string magicCmd = String_FromConst("&0!mario64"); 19 | 20 | if (msgType == 0 && String_CaselessStarts(msg, &magicCmd)) 21 | { 22 | // i probably should not be using the unsafe functions?... 23 | cc_string args[64]; 24 | 25 | int argsCount = String_UNSAFE_Split(msg, ' ', args, 64); 26 | for (int i=0; iHacks; 39 | 40 | if (!String_ContainsConst(&hax->HacksFlags, "+mario64") && !hax->CanFly) 41 | { 42 | cc_string humanModelName = String_FromReadonly(Models.Human->name); 43 | Entity_SetModel(&p->Base, &humanModelName); 44 | } 45 | } 46 | 47 | void OnKeyDown(void* obj, int key, cc_bool repeating) 48 | { 49 | if (repeating || isGuiOpen()) return; 50 | 51 | if (marioInstances[ENTITIES_SELF_ID]) 52 | { 53 | if (strcmp(pluginOptions[PLUGINOPTION_KEY_CROUCH].value.str.current, keyNames[key]) == 0) 54 | marioInstances[ENTITIES_SELF_ID]->input.buttonZ = true; 55 | else if (strcmp(pluginOptions[PLUGINOPTION_KEY_ATTACK].value.str.current, keyNames[key]) == 0) 56 | marioInstances[ENTITIES_SELF_ID]->input.buttonB = true; 57 | } 58 | } 59 | 60 | void OnKeyUp(void* obj, int key) 61 | { 62 | if (isGuiOpen()) return; 63 | 64 | if (marioInstances[ENTITIES_SELF_ID]) 65 | { 66 | if (strcmp(pluginOptions[PLUGINOPTION_KEY_CROUCH].value.str.current, keyNames[key]) == 0) 67 | marioInstances[ENTITIES_SELF_ID]->input.buttonZ = false; 68 | else if (strcmp(pluginOptions[PLUGINOPTION_KEY_ATTACK].value.str.current, keyNames[key]) == 0) 69 | marioInstances[ENTITIES_SELF_ID]->input.buttonB = false; 70 | } 71 | } 72 | 73 | void OnContextLost(void* obj) 74 | { 75 | Gfx_DeleteTexture(&marioTextureID); 76 | for (int i=0; i<256; i++) 77 | { 78 | if (marioInstances[i]) 79 | { 80 | struct MarioInstance* obj = marioInstances[i]; 81 | Gfx_DeleteDynamicVb(&obj->vertexID); 82 | Gfx_DeleteDynamicVb(&obj->texturedVertexID); 83 | #ifdef CLASSIC64_DEBUG 84 | Gfx_DeleteDynamicVb(&obj->debuggerVertexID); 85 | #endif 86 | } 87 | } 88 | } 89 | 90 | void OnContextRecreated(void* obj) 91 | { 92 | marioTextureID = Gfx_CreateTexture(&marioBitmap, 0, false); 93 | for (int i=0; i<256; i++) 94 | { 95 | if (marioInstances[i]) 96 | { 97 | struct MarioInstance* obj = marioInstances[i]; 98 | obj->vertexID = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, 4 * SM64_GEO_MAX_TRIANGLES); 99 | obj->texturedVertexID = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, 4 * SM64_GEO_MAX_TRIANGLES); 100 | #ifdef CLASSIC64_DEBUG 101 | obj->debuggerVertexID = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, DEBUGGER_MAX_VERTICES); 102 | #endif 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/decomp/pc/libultra_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBULTRA_INTERNAL_H_ 2 | #define _LIBULTRA_INTERNAL_H_ 3 | #include 4 | 5 | /* 6 | * This define is needed because the original definitions in __osDequeueThread.c are declared 7 | * seperately instead of part of a single struct, however some code alises over this memory 8 | * assuming a unified structure. To fix this, we declare the full type here and then alias the 9 | * symbol names to the correct members in AVOID_UB. 10 | */ 11 | #ifdef AVOID_UB 12 | typedef struct OSThread_ListHead_s 13 | { 14 | /*0x00*/ struct OSThread_s *next; 15 | /*0x04*/ OSPri priority; 16 | /*0x08*/ struct OSThread_s *queue; 17 | /*0x0C*/ struct OSThread_s *tlnext; 18 | /*0x10*/ struct OSThread_s *unk10; 19 | /*0x14*/ u32 unk14; 20 | } OSThread_ListHead; 21 | 22 | // Now fix the symbols to the new one. 23 | extern OSThread_ListHead D_80334890_fix; 24 | 25 | #define D_80334890 D_80334890_fix.next 26 | #define D_80334894 D_80334890_fix.priority 27 | #define D_80334898 D_80334890_fix.queue 28 | #define D_8033489C D_80334890_fix.tlnext 29 | #define D_803348A0 D_80334890_fix.unk10 30 | 31 | // Fix for the EEPROM array. 32 | extern u32 D_80365E00[16]; 33 | 34 | // alias the last array element correctly 35 | #define D_80365E3C D_80365E00[15] 36 | #else 37 | // Original OSThread_ListHead definitions 38 | extern OSThread *D_80334890; 39 | extern u32 D_80334894; 40 | extern OSThread *D_80334898; 41 | extern OSThread *D_8033489C; 42 | extern OSThread *D_803348A0; 43 | 44 | // Original EEPROM definitions 45 | extern u32 D_80365E00[15]; 46 | extern u32 D_80365E3C; 47 | #endif 48 | 49 | typedef struct { 50 | u32 initialized; // probably something like initialized? 51 | OSThread *mgrThread; 52 | OSMesgQueue *cmdQueue; 53 | OSMesgQueue *eventQueue; 54 | OSMesgQueue *accessQueue; 55 | s32 (*dma_func)(s32, u32, void *, size_t); 56 | #if defined(VERSION_EU) || defined(VERSION_SH) 57 | s32 (*edma_func)(OSPiHandle*, s32, u32, void *, size_t); 58 | #else 59 | u64 force_align; 60 | #endif 61 | } OSMgrArgs; 62 | 63 | s32 __osDisableInt(void); 64 | void __osRestoreInt(s32); 65 | void __osEnqueueAndYield(OSThread **); 66 | void __osDequeueThread(OSThread **, OSThread *); 67 | void __osEnqueueThread(OSThread **, OSThread *); 68 | OSThread *__osPopThread(OSThread **); 69 | s32 __osSiRawStartDma(s32, void *); 70 | void __osSiCreateAccessQueue(void); 71 | void __osSiGetAccess(void); 72 | void __osSiRelAccess(void); 73 | u32 __osProbeTLB(void *); 74 | void __osPiCreateAccessQueue(void); 75 | void __osPiGetAccess(void); 76 | void __osSetSR(u32); 77 | u32 __osGetSR(void); 78 | void __osSetFpcCsr(u32); 79 | s32 __osSiRawReadIo(void *, u32 *); 80 | s32 __osSiRawWriteIo(void *, u32); 81 | s32 osPiRawReadIo(u32 a0, u32 *a1); 82 | void __osSpSetStatus(u32); 83 | u32 __osSpGetStatus(void); 84 | s32 __osSpSetPc(void *); 85 | s32 __osSpDeviceBusy(void); 86 | s32 __osSiDeviceBusy(void); 87 | s32 __osSpRawStartDma(u32 dir, void *sp_ptr, void *dram_ptr, size_t size); 88 | void __osViInit(void); 89 | OSViContext *__osViGetCurrentContext(void); 90 | OSViContext *__osViGetCurrentContext2(void); 91 | void __osViSwapContext(void); 92 | void __osSetTimerIntr(u64); 93 | u64 __osInsertTimer(OSTimer *); 94 | void __osSetCompare(u32); 95 | s32 __osAiDeviceBusy(void); 96 | void __osDispatchThread(void); 97 | u32 __osGetCause(void); 98 | s32 __osAtomicDec(u32 *); 99 | #endif 100 | -------------------------------------------------------------------------------- /src/decomp/include/PR/sptask.h: -------------------------------------------------------------------------------- 1 | #ifndef _ULTRA64_SPTASK_H_ 2 | #define _ULTRA64_SPTASK_H_ 3 | 4 | /* Task Types */ 5 | #define M_GFXTASK 1 6 | #define M_AUDTASK 2 7 | #define M_VIDTASK 3 8 | #define M_HVQTASK 6 9 | #define M_HVQMTASK 7 10 | 11 | #if (defined(F3DEX_GBI) || defined(F3DLP_GBI) || defined(F3DEX_GBI_2)) 12 | #define OS_YIELD_DATA_SIZE 0xc00 13 | #else 14 | #define OS_YIELD_DATA_SIZE 0x900 15 | #endif 16 | #define OS_YIELD_AUDIO_SIZE 0x400 17 | 18 | /* Flags */ 19 | #define M_TASK_FLAG0 1 20 | #define M_TASK_FLAG1 2 21 | #ifdef VERSION_SH 22 | #define M_TASK_FLAG2 4 23 | #endif 24 | 25 | /* SpStatus */ 26 | #define SPSTATUS_CLEAR_HALT 0x00000001 27 | #define SPSTATUS_SET_HALT 0x00000002 28 | #define SPSTATUS_CLEAR_BROKE 0x00000004 29 | #define SPSTATUS_CLEAR_INTR 0x00000008 30 | #define SPSTATUS_SET_INTR 0x00000010 31 | #define SPSTATUS_CLEAR_SSTEP 0x00000020 32 | #define SPSTATUS_SET_SSTEP 0x00000040 33 | #define SPSTATUS_CLEAR_INTR_ON_BREAK 0x00000080 34 | #define SPSTATUS_SET_INTR_ON_BREAK 0x00000100 35 | #define SPSTATUS_CLEAR_SIGNAL0 0x00000200 36 | #define SPSTATUS_SET_SIGNAL0 0x00000400 37 | #define SPSTATUS_CLEAR_SIGNAL1 0x00000800 38 | #define SPSTATUS_SET_SIGNAL1 0x00001000 39 | #define SPSTATUS_CLEAR_SIGNAL2 0x00002000 40 | #define SPSTATUS_SET_SIGNAL2 0x00004000 41 | #define SPSTATUS_CLEAR_SIGNAL3 0x00008000 42 | #define SPSTATUS_SET_SIGNAL3 0x00010000 43 | #define SPSTATUS_CLEAR_SIGNAL4 0x00020000 44 | #define SPSTATUS_SET_SIGNAL4 0x00040000 45 | #define SPSTATUS_CLEAR_SIGNAL5 0x00080000 46 | #define SPSTATUS_SET_SIGNAL5 0x00100000 47 | #define SPSTATUS_CLEAR_SIGNAL6 0x00200000 48 | #define SPSTATUS_SET_SIGNAL6 0x00800000 49 | #define SPSTATUS_CLEAR_SIGNAL7 0x01000000 50 | #define SPSTATUS_SET_SIGNAL7 0x02000000 51 | 52 | #define SPSTATUS_HALT 0x0001 53 | #define SPSTATUS_BROKE 0x0002 54 | #define SPSTATUS_DMA_BUSY 0x0004 55 | #define SPSTATUS_DMA_FULL 0x0008 56 | #define SPSTATUS_IO_FULL 0x0010 57 | #define SPSTATUS_SINGLE_STEP 0x0020 58 | #define SPSTATUS_INTERRUPT_ON_BREAK 0x0040 59 | #define SPSTATUS_SIGNAL0_SET 0x0080 60 | #define SPSTATUS_SIGNAL1_SET 0x0100 61 | #define SPSTATUS_SIGNAL2_SET 0x0200 62 | #define SPSTATUS_SIGNAL3_SET 0x0400 63 | #define SPSTATUS_SIGNAL4_SET 0x0800 64 | #define SPSTATUS_SIGNAL5_SET 0x1000 65 | #define SPSTATUS_SIGNAL6_SET 0x2000 66 | #define SPSTATUS_SIGNAL7_SET 0x4000 67 | 68 | /* Types */ 69 | /* Types */ 70 | 71 | typedef struct 72 | { 73 | /*0x00*/ u32 type; 74 | /*0x04*/ u32 flags; 75 | 76 | /*0x08*/ u64 *ucode_boot; 77 | /*0x0C*/ u32 ucode_boot_size; 78 | 79 | /*0x10*/ u64 *ucode; 80 | /*0x14*/ u32 ucode_size; 81 | 82 | /*0x18*/ u64 *ucode_data; 83 | /*0x1C*/ u32 ucode_data_size; 84 | 85 | /*0x20*/ u64 *dram_stack; 86 | /*0x24*/ u32 dram_stack_size; 87 | 88 | /*0x28*/ u64 *output_buff; 89 | /*0x2C*/ u64 *output_buff_size; 90 | 91 | /*0x30*/ u64 *data_ptr; 92 | /*0x34*/ u32 data_size; 93 | 94 | /*0x38*/ u64 *yield_data_ptr; 95 | /*0x3C*/ u32 yield_data_size; 96 | } OSTask_t; // size = 0x40 97 | 98 | typedef union { 99 | OSTask_t t; 100 | long long int force_structure_alignment; 101 | } OSTask; 102 | 103 | typedef u32 OSYieldResult; 104 | 105 | /* Functions */ 106 | 107 | #define osSpTaskStart(p) \ 108 | osSpTaskLoad(p); \ 109 | osSpTaskStartGo(p); 110 | 111 | void osSpTaskLoad(OSTask *task); 112 | void osSpTaskStartGo(OSTask *task); 113 | void osSpTaskYield(void); 114 | OSYieldResult osSpTaskYielded(OSTask *task); 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /src/decomp/tools/n64graphics.h: -------------------------------------------------------------------------------- 1 | #ifndef N64GRAPHICS_H_ 2 | #define N64GRAPHICS_H_ 3 | 4 | #include 5 | 6 | // intermediate formats 7 | typedef struct _rgba 8 | { 9 | uint8_t red; 10 | uint8_t green; 11 | uint8_t blue; 12 | uint8_t alpha; 13 | } rgba; 14 | 15 | typedef struct _ia 16 | { 17 | uint8_t intensity; 18 | uint8_t alpha; 19 | } ia; 20 | 21 | // CI palette 22 | typedef struct 23 | { 24 | uint16_t data[256]; 25 | int max; // max number of entries 26 | int used; // number of entries used 27 | } palette_t; 28 | 29 | //--------------------------------------------------------- 30 | // N64 RGBA/IA/I/CI -> intermediate RGBA/IA 31 | //--------------------------------------------------------- 32 | 33 | // N64 raw RGBA16/RGBA32 -> intermediate RGBA 34 | rgba *raw2rgba(const uint8_t *raw, int width, int height, int depth); 35 | 36 | // N64 raw IA1/IA4/IA8/IA16 -> intermediate IA 37 | ia *raw2ia(const uint8_t *raw, int width, int height, int depth); 38 | 39 | // N64 raw I4/I8 -> intermediate IA 40 | ia *raw2i(const uint8_t *raw, int width, int height, int depth); 41 | 42 | //--------------------------------------------------------- 43 | // intermediate RGBA/IA -> N64 RGBA/IA/I/CI 44 | // returns length written to 'raw' used or -1 on error 45 | //--------------------------------------------------------- 46 | 47 | // intermediate RGBA -> N64 raw RGBA16/RGBA32 48 | int rgba2raw(uint8_t *raw, const rgba *img, int width, int height, int depth); 49 | 50 | // intermediate IA -> N64 raw IA1/IA4/IA8/IA16 51 | int ia2raw(uint8_t *raw, const ia *img, int width, int height, int depth); 52 | 53 | // intermediate IA -> N64 raw I4/I8 54 | int i2raw(uint8_t *raw, const ia *img, int width, int height, int depth); 55 | 56 | 57 | //--------------------------------------------------------- 58 | // N64 CI <-> N64 RGBA16/IA16 59 | //--------------------------------------------------------- 60 | 61 | // N64 CI raw data and palette to raw data (either RGBA16 or IA16) 62 | uint8_t *ci2raw(const uint8_t *rawci, const uint8_t *palette, int width, int height, int ci_depth); 63 | 64 | // convert from raw (RGBA16 or IA16) format to CI + palette 65 | int raw2ci(uint8_t *rawci, palette_t *pal, const uint8_t *raw, int raw_len, int ci_depth); 66 | 67 | 68 | //--------------------------------------------------------- 69 | // intermediate RGBA/IA -> PNG 70 | //--------------------------------------------------------- 71 | 72 | // intermediate RGBA write to PNG file 73 | int rgba2png(const char *png_filename, const rgba *img, int width, int height); 74 | 75 | // intermediate IA write to grayscale PNG file 76 | int ia2png(const char *png_filename, const ia *img, int width, int height); 77 | 78 | 79 | //--------------------------------------------------------- 80 | // PNG -> intermediate RGBA/IA 81 | //--------------------------------------------------------- 82 | 83 | // PNG file -> intermediate RGBA 84 | rgba *png2rgba(const char *png_filename, int *width, int *height); 85 | 86 | // PNG file -> intermediate IA 87 | ia *png2ia(const char *png_filename, int *width, int *height); 88 | 89 | 90 | //--------------------------------------------------------- 91 | // version 92 | //--------------------------------------------------------- 93 | 94 | // get version of underlying graphics reading library 95 | const char *n64graphics_get_read_version(void); 96 | 97 | // get version of underlying graphics writing library 98 | const char *n64graphics_get_write_version(void); 99 | 100 | #endif // N64GRAPHICS_H_ 101 | -------------------------------------------------------------------------------- /src/decomp/engine/math_util.h: -------------------------------------------------------------------------------- 1 | #ifndef MATH_UTIL_H 2 | #define MATH_UTIL_H 3 | 4 | #include "../include/PR/ultratypes.h" 5 | #include "../include/PR/gbi.h" 6 | 7 | #include "../include/types.h" 8 | 9 | /* 10 | * The sine and cosine tables overlap, but "#define gCosineTable (gSineTable + 11 | * 0x400)" doesn't give expected codegen; gSineTable and gCosineTable need to 12 | * be different symbols for code to match. Most likely the tables were placed 13 | * adjacent to each other, and gSineTable cut short, such that reads overflow 14 | * into gCosineTable. 15 | * 16 | * These kinds of out of bounds reads are undefined behavior, and break on 17 | * e.g. GCC (which doesn't place the tables next to each other, and probably 18 | * exploits array sizes for range analysis-based optimizations as well). 19 | * Thus, for non-IDO compilers we use the standard-compliant version. 20 | */ 21 | extern f32 gSineTable[]; 22 | #ifdef AVOID_UB 23 | #define gCosineTable (gSineTable + 0x400) 24 | #else 25 | extern f32 gCosineTable[]; 26 | #endif 27 | 28 | #define sins(x) gSineTable[(u16) (x) >> 4] 29 | #define coss(x) gCosineTable[(u16) (x) >> 4] 30 | 31 | #define min(a, b) ((a) <= (b) ? (a) : (b)) 32 | #define max(a, b) ((a) > (b) ? (a) : (b)) 33 | 34 | #define sqr(x) ((x) * (x)) 35 | 36 | void *vec3f_copy(Vec3f dest, Vec3f src); 37 | void *vec3f_set(Vec3f dest, f32 x, f32 y, f32 z); 38 | void *vec3f_add(Vec3f dest, Vec3f a); 39 | void *vec3f_sum(Vec3f dest, Vec3f a, Vec3f b); 40 | void *vec3s_copy(Vec3s dest, Vec3s src); 41 | void *vec3s_set(Vec3s dest, s16 x, s16 y, s16 z); 42 | void *vec3s_add(Vec3s dest, Vec3s a); 43 | void *vec3s_sum(Vec3s dest, Vec3s a, Vec3s b); 44 | void *vec3s_sub(Vec3s dest, Vec3s a); 45 | void *vec3s_to_vec3f(Vec3f dest, Vec3s a); 46 | void *vec3f_to_vec3s(Vec3s dest, Vec3f a); 47 | void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c); 48 | void *vec3f_cross(Vec3f dest, Vec3f a, Vec3f b); 49 | void *vec3f_normalize(Vec3f dest); 50 | void mtxf_copy(Mat4 dest, Mat4 src); 51 | void mtxf_identity(Mat4 mtx); 52 | void mtxf_translate(Mat4 dest, Vec3f b); 53 | void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll); 54 | void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f translate, Vec3s rotate); 55 | void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c); 56 | void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle); 57 | void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw); 58 | void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius); 59 | void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b); 60 | void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s); 61 | void mtxf_mul_vec3s(Mat4 mtx, Vec3s b); 62 | void mtxf_mul_vec3f(Mat4 mtx, Vec3f b); 63 | void mtxf_to_mtx(Mtx *dest, Mat4 src); 64 | void mtxf_rotate_xy(Mtx *mtx, s16 angle); 65 | void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx); 66 | void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *yaw); 67 | void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw); 68 | s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec); 69 | f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec); 70 | s16 atan2s(f32 y, f32 x); 71 | f32 atan2f(f32 a, f32 b); 72 | void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c); 73 | void anim_spline_init(Vec4s *keyFrames); 74 | s32 anim_spline_poll(Vec3f result); 75 | 76 | 77 | // From object_helpers.c 78 | void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v); 79 | void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v); 80 | 81 | 82 | #endif // MATH_UTIL_H 83 | -------------------------------------------------------------------------------- /src/decomp/audio/synthesis.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_SYNTHESIS_H 2 | #define AUDIO_SYNTHESIS_H 3 | 4 | #include "internal.h" 5 | 6 | #ifdef VERSION_SH 7 | #define DEFAULT_LEN_1CH 0x180 8 | #define DEFAULT_LEN_2CH 0x300 9 | #else 10 | #define DEFAULT_LEN_1CH 0x140 11 | #define DEFAULT_LEN_2CH 0x280 12 | #endif 13 | 14 | #if defined(VERSION_EU) || defined(VERSION_SH) 15 | #define MAX_UPDATES_PER_FRAME 5 16 | #else 17 | #define MAX_UPDATES_PER_FRAME 4 18 | #endif 19 | 20 | struct ReverbRingBufferItem 21 | { 22 | s16 numSamplesAfterDownsampling; 23 | s16 chunkLen; // never read 24 | s16 *toDownsampleLeft; 25 | s16 *toDownsampleRight; // data pointed to by left and right are adjacent in memory 26 | s32 startPos; // start pos in ring buffer 27 | s16 lengthA; // first length in ring buffer (from startPos, at most until end) 28 | s16 lengthB; // second length in ring buffer (from pos 0) 29 | }; // size = 0x14 30 | 31 | struct SynthesisReverb 32 | { 33 | /*0x00, 0x00, 0x00*/ u8 resampleFlags; 34 | /*0x01, 0x01, 0x01*/ u8 useReverb; 35 | /*0x02, 0x02, 0x02*/ u8 framesLeftToIgnore; 36 | /*0x03, 0x03, 0x03*/ u8 curFrame; 37 | #if defined(VERSION_EU) || defined(VERSION_SH) 38 | /* 0x04, 0x04*/ u8 downsampleRate; 39 | #ifdef VERSION_SH 40 | /* 0x05*/ s8 unk5; 41 | #endif 42 | /* 0x06, 0x06*/ u16 windowSize; // same as bufSizePerChannel 43 | #endif 44 | #ifdef VERSION_SH 45 | /* 0x08*/ u16 unk08; 46 | #endif 47 | /*0x04, 0x08, 0x0A*/ u16 reverbGain; 48 | /*0x06, 0x0A, 0x0C*/ u16 resampleRate; 49 | #ifdef VERSION_SH 50 | /* 0x0E*/ u16 panRight; 51 | /* 0x10*/ u16 panLeft; 52 | #endif 53 | /*0x08, 0x0C, 0x14*/ s32 nextRingBufferPos; 54 | /*0x0C, 0x10, 0x18*/ s32 unkC; // never read 55 | /*0x10, 0x14, 0x1C*/ s32 bufSizePerChannel; 56 | struct 57 | { 58 | s16 *left; 59 | s16 *right; 60 | } ringBuffer; 61 | /*0x1C, 0x20, 0x28*/ s16 *resampleStateLeft; 62 | /*0x20, 0x24, 0x2C*/ s16 *resampleStateRight; 63 | /*0x24, 0x28, 0x30*/ s16 *unk24; // never read 64 | /*0x28, 0x2C, 0x34*/ s16 *unk28; // never read 65 | /*0x2C, 0x30, 0x38*/ struct ReverbRingBufferItem items[2][MAX_UPDATES_PER_FRAME]; 66 | #if defined(VERSION_EU) || defined(VERSION_SH) 67 | // Only used in sh: 68 | /* 0x100*/ s16 *unk100; 69 | /* 0x104*/ s16 *unk104; 70 | /* 0x108*/ s16 *unk108; 71 | /* 0x10C*/ s16 *unk10C; 72 | #endif 73 | }; // 0xCC <= size <= 0x100 74 | #if defined(VERSION_EU) || defined(VERSION_SH) 75 | extern struct SynthesisReverb gSynthesisReverbs[4]; 76 | extern s8 gNumSynthesisReverbs; 77 | extern struct NoteSubEu *gNoteSubsEu; 78 | extern f32 gLeftVolRampings[3][1024]; 79 | extern f32 gRightVolRampings[3][1024]; 80 | extern f32 *gCurrentLeftVolRamping; // Points to any of the three left buffers above 81 | extern f32 *gCurrentRightVolRamping; // Points to any of the three right buffers above 82 | #else 83 | extern struct SynthesisReverb gSynthesisReverb; 84 | #endif 85 | 86 | #ifdef VERSION_SH 87 | extern s16 D_SH_803479B4; 88 | #endif 89 | 90 | u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen); 91 | #if defined(VERSION_JP) || defined(VERSION_US) 92 | void note_init_volume(struct Note *note); 93 | void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverbVol); 94 | void note_set_frequency(struct Note *note, f32 frequency); 95 | void note_enable(struct Note *note); 96 | void note_disable(struct Note *note); 97 | #endif 98 | 99 | #endif // AUDIO_SYNTHESIS_H 100 | -------------------------------------------------------------------------------- /import-mario-geo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import os 3 | import shutil 4 | import urllib.request 5 | 6 | GEO_URL = "https://raw.githubusercontent.com/n64decomp/sm64/06ec56df7f951f88da05f468cdcacecba496145a/actors/mario/geo.inc.c" 7 | MODEL_URL = "https://raw.githubusercontent.com/n64decomp/sm64/06ec56df7f951f88da05f468cdcacecba496145a/actors/mario/model.inc.c" 8 | 9 | geo_inc_c_header = """ 10 | #include "../include/sm64.h" 11 | #include "../include/types.h" 12 | #include "../include/geo_commands.h" 13 | #include "../game/rendering_graph_node.h" 14 | #include "../shim.h" 15 | #include "../game/object_stuff.h" 16 | #include "../game/behavior_actions.h" 17 | #include "model.inc.h" 18 | 19 | #define SHADOW_CIRCLE_PLAYER 99 20 | """ 21 | 22 | geo_inc_c_footer = """ 23 | const GeoLayout mario_geo_libsm64[] = { 24 | GEO_SHADOW(SHADOW_CIRCLE_PLAYER, 0xB4, 100), 25 | GEO_OPEN_NODE(), 26 | GEO_ZBUFFER(1), 27 | GEO_OPEN_NODE(), 28 | GEO_SCALE(0x00, 16384), 29 | GEO_OPEN_NODE(), 30 | GEO_ASM(0, geo_mirror_mario_backface_culling), 31 | GEO_ASM(0, geo_mirror_mario_set_alpha), 32 | GEO_BRANCH(1, mario_geo_load_body), 33 | GEO_ASM(1, geo_mirror_mario_backface_culling), 34 | GEO_CLOSE_NODE(), 35 | GEO_CLOSE_NODE(), 36 | GEO_CLOSE_NODE(), 37 | GEO_END(), 38 | }; 39 | 40 | void *mario_geo_ptr = (void*)mario_geo_libsm64; 41 | 42 | """ 43 | 44 | geo_inc_h = """ 45 | #pragma once 46 | 47 | extern void *mario_geo_ptr; 48 | """ 49 | 50 | model_inc_h = """ 51 | #pragma once 52 | 53 | #include "../include/types.h" 54 | #include "../include/PR/gbi.h" 55 | 56 | extern Lights1 mario_blue_lights_group[]; 57 | extern Lights1 mario_red_lights_group[]; 58 | extern Lights1 mario_white_lights_group[]; 59 | extern Lights1 mario_brown1_lights_group[]; 60 | extern Lights1 mario_beige_lights_group[]; 61 | extern Lights1 mario_brown2_lights_group[]; 62 | """ 63 | 64 | def main(): 65 | global model_inc_h 66 | 67 | shutil.rmtree("src/decomp/mario", ignore_errors=True) 68 | os.makedirs("src/decomp/mario", exist_ok=True) 69 | 70 | print("Downloading " + GEO_URL) 71 | geo_inc_c = urllib.request.urlopen(GEO_URL).read().decode('utf8') 72 | print("Downloading " + MODEL_URL) 73 | model_inc_c = urllib.request.urlopen(MODEL_URL).read().decode('utf8') 74 | 75 | lines = model_inc_c.splitlines() 76 | 77 | skip = 0 78 | for i in range(len(lines)): 79 | if skip > 0: 80 | skip = skip - 1 81 | lines[i] = "//" + lines[i] 82 | elif lines[i].startswith("ALIGNED8 static const u8 mario_"): 83 | skip = 2 84 | lines[i] = "//" + lines[i] 85 | elif lines[i].startswith("const "): 86 | model_inc_h += "\nextern " + lines[i].replace(" = {", ";") 87 | elif lines[i].startswith("static const Lights1 "): 88 | lines[i] = lines[i].replace("static const Lights1", "Lights1") 89 | 90 | lines.insert(0, "#include \"../../gfx_macros.h\"") 91 | lines.insert(0, "#include \"../../load_tex_data.h\"") 92 | model_inc_c = "\n".join(lines) 93 | 94 | 95 | with open("src/decomp/mario/geo.inc.c", "w") as file: 96 | file.write(geo_inc_c_header + geo_inc_c + geo_inc_c_footer) 97 | 98 | with open("src/decomp/mario/model.inc.c", "w") as file: 99 | file.write(model_inc_c) 100 | 101 | with open("src/decomp/mario/model.inc.h", "w") as file: 102 | file.write(model_inc_h) 103 | 104 | with open("src/decomp/mario/geo.inc.h", "w") as file: 105 | file.write(geo_inc_h) 106 | 107 | if __name__ == "__main__": 108 | main() 109 | -------------------------------------------------------------------------------- /src/decomp/include/PR/os_exception.h: -------------------------------------------------------------------------------- 1 | 2 | /*==================================================================== 3 | * os_exception.h 4 | * 5 | * Copyright 1995, Silicon Graphics, Inc. 6 | * All Rights Reserved. 7 | * 8 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, 9 | * Inc.; the contents of this file may not be disclosed to third 10 | * parties, copied or duplicated in any form, in whole or in part, 11 | * without the prior written permission of Silicon Graphics, Inc. 12 | * 13 | * RESTRICTED RIGHTS LEGEND: 14 | * Use, duplication or disclosure by the Government is subject to 15 | * restrictions as set forth in subdivision (c)(1)(ii) of the Rights 16 | * in Technical Data and Computer Software clause at DFARS 17 | * 252.227-7013, and/or in similar or successor clauses in the FAR, 18 | * DOD or NASA FAR Supplement. Unpublished - rights reserved under the 19 | * Copyright Laws of the United States. 20 | *====================================================================*/ 21 | 22 | /*---------------------------------------------------------------------* 23 | Copyright (C) 1998 Nintendo. (Originated by SGI) 24 | 25 | $RCSfile: os_exception.h,v $ 26 | $Revision: 1.1 $ 27 | $Date: 1998/10/09 08:01:07 $ 28 | *---------------------------------------------------------------------*/ 29 | 30 | #ifndef _OS_EXCEPTION_H_ 31 | #define _OS_EXCEPTION_H_ 32 | 33 | #ifdef _LANGUAGE_C_PLUS_PLUS 34 | extern "C" { 35 | #endif 36 | 37 | #include "ultratypes.h" 38 | 39 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 40 | 41 | /************************************************************************** 42 | * 43 | * Type definitions 44 | * 45 | */ 46 | 47 | typedef u32 OSIntMask; 48 | typedef u32 OSHWIntr; 49 | 50 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 51 | 52 | /************************************************************************** 53 | * 54 | * Global definitions 55 | * 56 | */ 57 | 58 | /* Flags for debugging purpose */ 59 | 60 | #define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ 61 | #define OS_FLAG_FAULT 2 /* CPU fault has occurred */ 62 | 63 | /* Interrupt masks */ 64 | 65 | #define OS_IM_NONE 0x00000001 66 | #define OS_IM_SW1 0x00000501 67 | #define OS_IM_SW2 0x00000601 68 | #define OS_IM_CART 0x00000c01 69 | #define OS_IM_PRENMI 0x00001401 70 | #define OS_IM_RDBWRITE 0x00002401 71 | #define OS_IM_RDBREAD 0x00004401 72 | #define OS_IM_COUNTER 0x00008401 73 | #define OS_IM_CPU 0x0000ff01 74 | #define OS_IM_SP 0x00010401 75 | #define OS_IM_SI 0x00020401 76 | #define OS_IM_AI 0x00040401 77 | #define OS_IM_VI 0x00080401 78 | #define OS_IM_PI 0x00100401 79 | #define OS_IM_DP 0x00200401 80 | #define OS_IM_ALL 0x003fff01 81 | #define RCP_IMASK 0x003f0000 82 | #define RCP_IMASKSHIFT 16 83 | 84 | 85 | #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) 86 | 87 | /************************************************************************** 88 | * 89 | * Macro definitions 90 | * 91 | */ 92 | 93 | 94 | /************************************************************************** 95 | * 96 | * Extern variables 97 | * 98 | */ 99 | 100 | 101 | /************************************************************************** 102 | * 103 | * Function prototypes 104 | * 105 | */ 106 | 107 | /* Interrupt operations */ 108 | 109 | extern OSIntMask osGetIntMask(void); 110 | extern OSIntMask osSetIntMask(OSIntMask); 111 | 112 | 113 | #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ 114 | 115 | #ifdef _LANGUAGE_C_PLUS_PLUS 116 | } 117 | #endif 118 | 119 | #endif /* !_OS_EXCEPTION_H_ */ 120 | -------------------------------------------------------------------------------- /src/load_anim_data.c: -------------------------------------------------------------------------------- 1 | #include "load_anim_data.h" 2 | 3 | #include 4 | 5 | static uint32_t s_num_entries = 0; 6 | static struct Animation *s_libsm64_mario_animations = NULL; 7 | 8 | #define ANIM_DATA_ADDRESS 0x004EC000 9 | 10 | static uint16_t read_u16_be( const uint8_t *p ) 11 | { 12 | return 13 | (uint32_t)p[0] << 8 | 14 | (uint32_t)p[1]; 15 | 16 | } 17 | 18 | static uint16_t read_s16_be( const uint8_t *p ) 19 | { 20 | return (int16_t)read_u16_be( p ); 21 | } 22 | 23 | static uint32_t read_u32_be( const uint8_t *p ) 24 | { 25 | return 26 | (uint32_t)p[0] << 24 | 27 | (uint32_t)p[1] << 16 | 28 | (uint32_t)p[2] << 8 | 29 | (uint32_t)p[3]; 30 | } 31 | 32 | void load_mario_anims_from_rom( const uint8_t *rom ) 33 | { 34 | #define GET_OFFSET( n ) (read_u32_be((uint8_t*)&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->offset)) 35 | #define GET_SIZE( n ) (read_u32_be((uint8_t*)&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->size )) 36 | 37 | const uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS; 38 | s_num_entries = read_u32_be( read_ptr ); 39 | 40 | s_libsm64_mario_animations = malloc( s_num_entries * sizeof( struct Animation )); 41 | struct Animation *anims = s_libsm64_mario_animations; 42 | 43 | for( int i = 0; i < s_num_entries; ++i ) 44 | { 45 | read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i); 46 | 47 | anims[i].flags = read_s16_be( read_ptr ); read_ptr += 2; 48 | anims[i].animYTransDivisor = read_s16_be( read_ptr ); read_ptr += 2; 49 | anims[i].startFrame = read_s16_be( read_ptr ); read_ptr += 2; 50 | anims[i].loopStart = read_s16_be( read_ptr ); read_ptr += 2; 51 | anims[i].loopEnd = read_s16_be( read_ptr ); read_ptr += 2; 52 | anims[i].unusedBoneCount = read_s16_be( read_ptr ); read_ptr += 2; 53 | uint32_t values_offset = read_u32_be( read_ptr ); read_ptr += 4; 54 | uint32_t index_offset = read_u32_be( read_ptr ); read_ptr += 4; 55 | uint32_t end_offset = read_u32_be( read_ptr ); 56 | 57 | read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + index_offset; 58 | const uint8_t *values_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + values_offset; 59 | const uint8_t *end_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + end_offset; 60 | 61 | anims[i].index = malloc( values_offset - index_offset ); 62 | anims[i].values = malloc( end_offset - values_offset ); 63 | 64 | int j = 0; 65 | while( read_ptr < values_ptr ) 66 | { 67 | anims[i].index[j++] = read_u16_be( read_ptr ); 68 | read_ptr += 2; 69 | } 70 | 71 | j = 0; 72 | while( read_ptr < end_ptr ) 73 | { 74 | anims[i].values[j++] = read_u16_be( read_ptr ); 75 | read_ptr += 2; 76 | } 77 | } 78 | 79 | #undef GET_OFFSET 80 | #undef GET_SIZE 81 | } 82 | 83 | void load_mario_animation(struct MarioAnimation *a, u32 index) 84 | { 85 | if (a->currentAnimAddr != 1 + index) { 86 | a->currentAnimAddr = 1 + index; 87 | a->targetAnim = &s_libsm64_mario_animations[index]; 88 | } 89 | } 90 | 91 | void unload_mario_anims( void ) 92 | { 93 | for( int i = 0; i < s_num_entries; ++i ) 94 | { 95 | free( s_libsm64_mario_animations[i].index ); 96 | free( s_libsm64_mario_animations[i].values ); 97 | } 98 | 99 | free( s_libsm64_mario_animations ); 100 | s_libsm64_mario_animations = NULL; 101 | s_num_entries = 0; 102 | } -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: debug 2 | 3 | CC := gcc 4 | CXX := g++ 5 | CFLAGS := -Wall -Wno-incompatible-pointer-types -Wno-int-conversion -fPIC -DSM64_LIB_EXPORT -DVERSION_US -DNO_SEGMENTED_MEMORY -DGBI_FLOATS 6 | LDFLAGS := -lm -shared -lpthread 7 | ENDFLAGS := -fPIC -lSDL2 8 | 9 | DIST_DIR := dist 10 | LIB_FILE := $(DIST_DIR)/libClassic64.so 11 | 12 | ifeq ($(OS),Windows_NT) 13 | LIB_FILE := $(DIST_DIR)/Classic64.dll 14 | CFLAGS := $(CFLAGS) -D_WIN32_WINNT=0x0501 15 | LDFLAGS := $(LDFLAGS) -mwindows 16 | ENDFLAGS := $(ENDFLAGS) -static -L. -lClassiCube -lole32 -lwinmm -loleaut32 -limm32 -lversion -lsetupapi 17 | 18 | else ifeq ($(shell uname -s),Darwin) 19 | BREW_SDL2_PREFIX := $(shell brew --prefix sdl2) 20 | CFLAGS := $(CFLAGS) -isystem $(BREW_SDL2_PREFIX)/include -Isrc/decomp/include 21 | LDFLAGS := $(LDFLAGS) -L$(BREW_SDL2_PREFIX)/lib 22 | ENDFLAGS := $(ENDFLAGS) -undefined dynamic_lookup 23 | LIB_FILE := libClassic64.dylib 24 | 25 | endif 26 | 27 | SRC_DIRS := src src/decomp src/decomp/audio src/decomp/engine src/decomp/game src/decomp/mario src/decomp/pc src/decomp/tools src/sha1 28 | BUILD_DIR := build 29 | ALL_DIRS := $(addprefix $(BUILD_DIR)/,$(SRC_DIRS)) 30 | 31 | TEST_FILE := run-test 32 | 33 | C_IMPORTED := src/decomp/mario/geo.inc.c src/decomp/mario/model.inc.c 34 | H_IMPORTED := $(C_IMPORTED:.c=.h) 35 | IMPORTED := $(C_IMPORTED) $(H_IMPORTED) 36 | 37 | C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(C_IMPORTED) 38 | CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp)) 39 | O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) $(foreach file,$(CXX_FILES),$(BUILD_DIR)/$(file:.cpp=.o)) 40 | DEP_FILES := $(O_FILES:.o=.d) 41 | 42 | TEST_SRCS := test/main.c test/context.c test/level.c 43 | TEST_OBJS := $(foreach file,$(TEST_SRCS),$(BUILD_DIR)/$(file:.c=.o)) 44 | 45 | ifeq ($(OS),Windows_NT) 46 | TEST_FILE := $(DIST_DIR)/$(TEST_FILE) 47 | endif 48 | 49 | DUMMY != mkdir -p $(ALL_DIRS) build/test src/decomp/mario $(DIST_DIR)/include 50 | 51 | 52 | $(filter-out src/decomp/mario/geo.inc.c,$(IMPORTED)): src/decomp/mario/geo.inc.c 53 | src/decomp/mario/geo.inc.c: ./import-mario-geo.py 54 | ./import-mario-geo.py 55 | 56 | $(BUILD_DIR)/%.o: %.c $(IMPORTED) 57 | @mkdir -p $(@D) 58 | @$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< 59 | $(CC) -c $(CFLAGS) -isystem src/decomp/include -o $@ $< 60 | 61 | $(BUILD_DIR)/%.o: %.cpp $(IMPORTED) 62 | @mkdir -p $(@D) 63 | @$(CXX) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< 64 | $(CXX) -c $(CFLAGS) -isystem src/decomp/include -o $@ $< 65 | 66 | $(LIB_FILE): $(O_FILES) 67 | $(CC) $(LDFLAGS) -o $@ $^ $(ENDFLAGS) 68 | 69 | test/main.c: test/level.h 70 | 71 | $(BUILD_DIR)/test/%.o: test/%.c 72 | @$(CC) $(CFLAGS) -MM -MP -MT $@ -MF $(BUILD_DIR)/test/$*.d $< 73 | ifeq ($(OS),Windows_NT) 74 | $(CC) -c $(CFLAGS) -isystem src/decomp/include -I/mingw64/include/SDL2 -I/mingw64/include/GL -o $@ $< 75 | else 76 | $(CC) -c $(CFLAGS) -isystem src/decomp/include -o $@ $< 77 | endif 78 | 79 | $(TEST_FILE): $(LIB_FILE) $(TEST_OBJS) 80 | ifeq ($(OS),Windows_NT) 81 | $(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lglew32 -lglu32 -lopengl32 -lSDL2 -lSDL2main -lm 82 | else 83 | $(CC) -o $@ $(TEST_OBJS) $(LIB_FILE) -lGLEW -lGL -lSDL2 -lSDL2main -lm 84 | endif 85 | 86 | debug: CFLAGS += -g -DCLASSIC64_DEBUG 87 | debug: LDFLAGS += -g 88 | debug: $(LIB_FILE) 89 | 90 | # libsm64 refuses to work with -O3 and -O2 91 | release: CFLAGS += -O1 92 | release: LDFLAGS += -O1 93 | release: $(LIB_FILE) 94 | 95 | test: $(TEST_FILE) 96 | 97 | run: test 98 | ./$(TEST_FILE) 99 | 100 | clean: 101 | rm -rf $(BUILD_DIR) $(DIST_DIR) $(TEST_FILE) 102 | 103 | -include $(DEP_FILES) 104 | -------------------------------------------------------------------------------- /src/decomp/pc/libaudio_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIBAUDIO_INTERNAL_H_ 2 | #define _LIBAUDIO_INTERNAL_H_ 3 | #include 4 | #define AL_BANK_VERSION 0x4231 /* 'B1' */ 5 | 6 | typedef u8 ALPan; 7 | typedef s32 ALMicroTime; 8 | 9 | /* Possible wavetable types */ 10 | enum 11 | { 12 | AL_ADPCM_WAVE = 0, 13 | AL_RAW16_WAVE 14 | }; 15 | 16 | typedef struct 17 | { 18 | u32 start; 19 | u32 end; 20 | u32 count; 21 | } ALRawLoop; 22 | 23 | typedef struct 24 | { 25 | u32 start; 26 | u32 end; 27 | u32 count; 28 | ADPCM_STATE state; 29 | } ALADPCMloop; 30 | 31 | typedef struct 32 | { 33 | s32 order; 34 | s32 npredictors; 35 | s16 book[1]; // variable size, 8-byte aligned 36 | } ALADPCMBook; 37 | 38 | typedef struct 39 | { 40 | ALMicroTime attackTime; 41 | ALMicroTime decayTime; 42 | ALMicroTime releaseTime; 43 | u8 attackVolume; 44 | u8 decayVolume; 45 | } ALEnvelope; 46 | 47 | typedef struct 48 | { 49 | u8 velocityMin; 50 | u8 velocityMax; 51 | u8 keyMin; 52 | u8 keyMax; 53 | u8 keyBase; 54 | s8 detune; 55 | } ALKeyMap; 56 | 57 | typedef struct 58 | { 59 | ALADPCMloop *loop; 60 | ALADPCMBook *book; 61 | } ALADPCMWaveInfo; 62 | 63 | typedef struct 64 | { 65 | ALRawLoop *loop; 66 | } ALRAWWaveInfo; 67 | 68 | typedef struct ALWaveTable_s 69 | { 70 | u8 *base; /* ptr to start of wave data */ 71 | s32 len; /* length of data in bytes */ 72 | u8 type; /* compression type */ 73 | u8 flags; /* offset/address flags */ 74 | union { 75 | ALADPCMWaveInfo adpcmWave; 76 | ALRAWWaveInfo rawWave; 77 | } waveInfo; 78 | } ALWaveTable; 79 | 80 | typedef struct ALSound_s 81 | { 82 | ALEnvelope *envelope; 83 | ALKeyMap *keyMap; 84 | ALWaveTable *wavetable; /* offset to wavetable struct */ 85 | ALPan samplePan; 86 | u8 sampleVolume; 87 | u8 flags; 88 | } ALSound; 89 | 90 | typedef struct 91 | { 92 | u8 volume; /* overall volume for this instrument */ 93 | ALPan pan; /* 0 = hard left, 127 = hard right */ 94 | u8 priority; /* voice priority for this instrument */ 95 | u8 flags; 96 | u8 tremType; /* the type of tremelo osc. to use */ 97 | u8 tremRate; /* the rate of the tremelo osc. */ 98 | u8 tremDepth; /* the depth of the tremelo osc */ 99 | u8 tremDelay; /* the delay for the tremelo osc */ 100 | u8 vibType; /* the type of tremelo osc. to use */ 101 | u8 vibRate; /* the rate of the tremelo osc. */ 102 | u8 vibDepth; /* the depth of the tremelo osc */ 103 | u8 vibDelay; /* the delay for the tremelo osc */ 104 | s16 bendRange; /* pitch bend range in cents */ 105 | s16 soundCount; /* number of sounds in this array */ 106 | ALSound *soundArray[1]; 107 | } ALInstrument; 108 | 109 | typedef struct ALBank_s 110 | { 111 | s16 instCount; /* number of programs in this bank */ 112 | u8 flags; 113 | u8 pad; 114 | s32 sampleRate; /* e.g. 44100, 22050, etc... */ 115 | ALInstrument *percussion; /* default percussion for GM */ 116 | ALInstrument *instArray[1]; /* ARRAY of instruments */ 117 | } ALBank; 118 | 119 | typedef struct 120 | { /* Note: sizeof won't be correct */ 121 | s16 revision; /* format revision of this file */ 122 | s16 bankCount; /* number of banks */ 123 | ALBank *bankArray[1]; /* ARRAY of bank offsets */ 124 | } ALBankFile; 125 | 126 | void alBnkfNew(ALBankFile *f, u8 *table); 127 | #endif 128 | -------------------------------------------------------------------------------- /src/gfx_macros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "decomp/include/types.h" 4 | #include "gfx_adapter_commands.h" 5 | 6 | /* 7 | * Vertex (set up for use with colors) 8 | */ 9 | typedef struct { 10 | #ifndef GBI_FLOATS 11 | short ob[3]; /* x, y, z */ 12 | #else 13 | float ob[3]; /* x, y, z */ 14 | #endif 15 | unsigned short flag; 16 | short tc[2]; /* texture coord */ 17 | unsigned char cn[4]; /* color & alpha */ 18 | } Vtx_t; 19 | 20 | /* 21 | * Vertex (set up for use with normals) 22 | */ 23 | typedef struct { 24 | #ifndef GBI_FLOATS 25 | short ob[3]; /* x, y, z */ 26 | #else 27 | float ob[3]; /* x, y, z */ 28 | #endif 29 | unsigned short flag; 30 | short tc[2]; /* texture coord */ 31 | signed char n[3]; /* normal */ 32 | unsigned char a; /* alpha */ 33 | } Vtx_tn; 34 | 35 | typedef union { 36 | Vtx_t v; /* Use this one for colors */ 37 | Vtx_tn n; /* Use this one for normals */ 38 | long long int force_structure_alignment; 39 | } Vtx; 40 | 41 | typedef struct { 42 | unsigned char col[3]; /* diffuse light value (rgba) */ 43 | char pad1; 44 | unsigned char colc[3]; /* copy of diffuse light value (rgba) */ 45 | char pad2; 46 | signed char dir[3]; /* direction of light (normalized) */ 47 | char pad3; 48 | } Light_t; 49 | 50 | typedef struct { 51 | unsigned char col[3]; /* ambient light value (rgba) */ 52 | char pad1; 53 | unsigned char colc[3]; /* copy of ambient light value (rgba) */ 54 | char pad2; 55 | } Ambient_t; 56 | 57 | typedef union { 58 | Light_t l; 59 | long long int force_structure_alignment[2]; 60 | } Light; 61 | 62 | typedef union { 63 | Ambient_t l; 64 | long long int force_structure_alignment[1]; 65 | } Ambient; 66 | 67 | typedef struct { 68 | Ambient a; 69 | Light l[1]; 70 | } Lights1; 71 | 72 | #define G_TX_RENDERTILE 0 73 | #define G_ON 1 74 | #define G_OFF 0 75 | #define G_TEXTURE_IMAGE_FRAC 2 76 | 77 | typedef intptr_t Gfx; 78 | 79 | #define gdSPDefLights1(ar,ag,ab,r1,g1,b1,x1,y1,z1) {{{ {ar,ag,ab},0,{ar,ag,ab},0}}, {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}} } 80 | 81 | #define gsSPVertex(v, n, v0) \ 82 | GFXCMD_VertexData, \ 83 | (intptr_t)v, n, v0 84 | 85 | #define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ 86 | GFXCMD_Triangle, \ 87 | v00, v01, v02, flag0, \ 88 | GFXCMD_Triangle, \ 89 | v10, v11, v12, flag1 90 | 91 | #define gsSP1Triangle(v00, v01, v02, flag0) \ 92 | GFXCMD_Triangle, \ 93 | v00, v01, v02, flag0 94 | 95 | #define gsSPEndDisplayList() \ 96 | GFXCMD_EndDisplayList 97 | 98 | #define gsSPDisplayList(dl) \ 99 | GFXCMD_SubDisplayList, \ 100 | (intptr_t)dl 101 | 102 | #define gsSPLight(l, n) \ 103 | GFXCMD_Light, \ 104 | (intptr_t)l, n 105 | 106 | #define gsSPTexture(s, t, level, tile, on) \ 107 | GFXCMD_Texture, \ 108 | s, t, on 109 | 110 | #define gsDPSetTextureImage(f, s, w, i) \ 111 | GFXCMD_SetTextureImage, \ 112 | i 113 | 114 | #define gsDPSetTileSize(t, uls, ult, lrs, lrt) \ 115 | GFXCMD_SetTileSize, \ 116 | uls, ult, lrs, lrt 117 | 118 | #define gsDPPipeSync() (GFXCMD_None) 119 | #define gsDPSetCombineMode(a, b) (GFXCMD_None) 120 | #define gsSPSetGeometryMode(word) (GFXCMD_None) 121 | #define gsDPLoadTextureBlock(timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) (GFXCMD_None) 122 | #define gsSPClearGeometryMode(word) (GFXCMD_None) 123 | #define gsDPSetEnvColor(r, g, b, a) (GFXCMD_None) 124 | #define gsDPSetAlphaCompare(type) (GFXCMD_None) 125 | #define gsDPTileSync() (GFXCMD_None) 126 | #define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, maskt, shiftt, cms, masks, shifts) (GFXCMD_None) 127 | #define gsDPLoadBlock(tile, uls, ult, lrs, dxt) (GFXCMD_None) 128 | #define gsDPLoadSync() (GFXCMD_None) -------------------------------------------------------------------------------- /test/cglm.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////// 2 | // A few choice functions and types from the cglm library 3 | // https://github.com/recp/cglm 4 | // 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | typedef float vec2[2]; 11 | typedef float vec3[3]; 12 | typedef float vec4[4]; 13 | typedef float mat4[4][4]; 14 | 15 | static void 16 | glm_mat4_zero( mat4 m ) 17 | { 18 | memset( m, 0, sizeof(mat4) ); 19 | } 20 | 21 | static void 22 | glm_mat4_identity( mat4 m ) 23 | { 24 | glm_mat4_zero( m ); 25 | m[0][0] = 1.0f; 26 | m[1][1] = 1.0f; 27 | m[2][2] = 1.0f; 28 | m[3][3] = 1.0f; 29 | } 30 | 31 | static void 32 | glm_vec4_scale(vec4 v, float s, vec4 dest) { 33 | dest[0] = v[0] * s; 34 | dest[1] = v[1] * s; 35 | dest[2] = v[2] * s; 36 | dest[3] = v[3] * s; 37 | } 38 | 39 | static void 40 | glm_vec4_add(vec4 a, vec4 b, vec4 dest) { 41 | dest[0] = a[0] + b[0]; 42 | dest[1] = a[1] + b[1]; 43 | dest[2] = a[2] + b[2]; 44 | dest[3] = a[3] + b[3]; 45 | } 46 | 47 | static void 48 | glm_vec3_scale(vec3 v, float s, vec3 dest) { 49 | dest[0] = v[0] * s; 50 | dest[1] = v[1] * s; 51 | dest[2] = v[2] * s; 52 | } 53 | 54 | static void 55 | glm_vec3_sub(vec3 a, vec3 b, vec3 dest) { 56 | dest[0] = a[0] - b[0]; 57 | dest[1] = a[1] - b[1]; 58 | dest[2] = a[2] - b[2]; 59 | } 60 | 61 | static float 62 | glm_vec3_dot(vec3 a, vec3 b) { 63 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; 64 | } 65 | 66 | static float 67 | glm_vec3_norm2(vec3 v) { 68 | return glm_vec3_dot(v, v); 69 | } 70 | 71 | static float 72 | glm_vec3_norm(vec3 v) { 73 | return sqrtf(glm_vec3_norm2(v)); 74 | } 75 | 76 | static void 77 | glm_vec3_normalize(vec3 v) { 78 | float norm; 79 | 80 | norm = glm_vec3_norm(v); 81 | 82 | if (norm == 0.0f) { 83 | v[0] = v[1] = v[2] = 0.0f; 84 | return; 85 | } 86 | 87 | glm_vec3_scale(v, 1.0f / norm, v); 88 | } 89 | 90 | static void 91 | glm_vec3_cross(vec3 a, vec3 b, vec3 dest) { 92 | /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ 93 | dest[0] = a[1] * b[2] - a[2] * b[1]; 94 | dest[1] = a[2] * b[0] - a[0] * b[2]; 95 | dest[2] = a[0] * b[1] - a[1] * b[0]; 96 | } 97 | 98 | static void 99 | glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) { 100 | glm_vec3_cross(a, b, dest); 101 | glm_vec3_normalize(dest); 102 | } 103 | 104 | static void 105 | glm_perspective(float fovy, 106 | float aspect, 107 | float nearVal, 108 | float farVal, 109 | mat4 dest) { 110 | float f, fn; 111 | 112 | glm_mat4_zero(dest); 113 | 114 | f = 1.0f / tanf(fovy * 0.5f); 115 | fn = 1.0f / (nearVal - farVal); 116 | 117 | dest[0][0] = f / aspect; 118 | dest[1][1] = f; 119 | dest[2][2] = (nearVal + farVal) * fn; 120 | dest[2][3] =-1.0f; 121 | dest[3][2] = 2.0f * nearVal * farVal * fn; 122 | } 123 | 124 | static void 125 | glm_translate(mat4 m, vec3 v) { 126 | vec4 v1, v2, v3; 127 | 128 | glm_vec4_scale(m[0], v[0], v1); 129 | glm_vec4_scale(m[1], v[1], v2); 130 | glm_vec4_scale(m[2], v[2], v3); 131 | 132 | glm_vec4_add(v1, m[3], m[3]); 133 | glm_vec4_add(v2, m[3], m[3]); 134 | glm_vec4_add(v3, m[3], m[3]); 135 | } 136 | 137 | static void 138 | glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { 139 | vec3 f, u, s; 140 | 141 | glm_vec3_sub(center, eye, f); 142 | glm_vec3_normalize(f); 143 | 144 | glm_vec3_crossn(f, up, s); 145 | glm_vec3_cross(s, f, u); 146 | 147 | dest[0][0] = s[0]; 148 | dest[0][1] = u[0]; 149 | dest[0][2] =-f[0]; 150 | dest[1][0] = s[1]; 151 | dest[1][1] = u[1]; 152 | dest[1][2] =-f[1]; 153 | dest[2][0] = s[2]; 154 | dest[2][1] = u[2]; 155 | dest[2][2] =-f[2]; 156 | dest[3][0] =-glm_vec3_dot(s, eye); 157 | dest[3][1] =-glm_vec3_dot(u, eye); 158 | dest[3][2] = glm_vec3_dot(f, eye); 159 | dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; 160 | dest[3][3] = 1.0f; 161 | } -------------------------------------------------------------------------------- /src/decomp/audio/load.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_LOAD_H 2 | #define AUDIO_LOAD_H 3 | 4 | #include 5 | 6 | #include "internal.h" 7 | 8 | #define AUDIO_FRAME_DMA_QUEUE_SIZE 0x40 9 | 10 | #define PRELOAD_BANKS 2 11 | #define PRELOAD_SEQUENCE 1 12 | 13 | #define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gSequenceChannelNone) 14 | 15 | extern struct Note *gNotes; 16 | 17 | // Music in SM64 is played using 3 players: 18 | // gSequencePlayers[0] is level background music 19 | // gSequencePlayers[1] is misc music, like the puzzle jingle 20 | // gSequencePlayers[2] is sound 21 | extern struct SequencePlayer gSequencePlayers[SEQUENCE_PLAYERS]; 22 | 23 | extern struct SequenceChannel gSequenceChannels[SEQUENCE_CHANNELS]; 24 | extern struct SequenceChannelLayer gSequenceLayers[SEQUENCE_LAYERS]; 25 | 26 | extern struct SequenceChannel gSequenceChannelNone; 27 | 28 | extern struct AudioListItem gLayerFreeList; 29 | extern struct NotePool gNoteFreeLists; 30 | 31 | extern OSMesgQueue gCurrAudioFrameDmaQueue; 32 | extern u32 gSampleDmaNumListItems; 33 | extern ALSeqFile *gAlCtlHeader; 34 | extern ALSeqFile *gAlTbl; 35 | extern ALSeqFile *gSeqFileHeader; 36 | extern u8 *gAlBankSets; 37 | 38 | extern struct CtlEntry *gCtlEntries; 39 | #if defined(VERSION_EU) || defined(VERSION_SH) 40 | extern struct AudioBufferParametersEU gAudioBufferParameters; 41 | #endif 42 | extern s32 gAiFrequency; 43 | #ifdef VERSION_SH 44 | extern s16 gCurrAiBufferLength; 45 | extern s32 D_SH_8034F68C; 46 | #endif 47 | extern s32 gMaxAudioCmds; 48 | 49 | extern s32 gMaxSimultaneousNotes; 50 | extern s32 gSamplesPerFrameTarget; 51 | extern s32 gMinAiBufferLength; 52 | extern s16 gTempoInternalToExternal; 53 | extern s8 gAudioUpdatesPerFrame; // = 4 54 | extern s8 gSoundMode; 55 | 56 | #ifdef VERSION_SH 57 | extern OSMesgQueue gUnkQueue1; 58 | 59 | struct UnkStructSH8034EC88 { 60 | u8 *endAndMediumIdentification; 61 | struct AudioBankSample *sample; 62 | u8 *ramAddr; 63 | u32 encodedInfo; 64 | s32 isFree; 65 | }; 66 | 67 | struct PatchStruct { 68 | s32 bankId1; 69 | s32 bankId2; 70 | void *baseAddr1; 71 | void *baseAddr2; 72 | s32 medium1; 73 | s32 medium2; 74 | }; 75 | 76 | extern struct UnkStructSH8034EC88 D_SH_8034EC88[0x80]; 77 | #endif 78 | 79 | struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1); 80 | 81 | void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg); 82 | void decrease_sample_dma_ttls(void); 83 | #ifdef VERSION_SH 84 | void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s32 medium); 85 | #else 86 | void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef); 87 | #endif 88 | void init_sample_dma_buffers(s32 arg0); 89 | #if defined(VERSION_SH) 90 | void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo); 91 | #else 92 | void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 numDrums); 93 | #endif 94 | #ifdef VERSION_SH 95 | void preload_sequence(u32 seqId, s32 preloadMask); 96 | #else 97 | void preload_sequence(u32 seqId, u8 preloadMask); 98 | #endif 99 | void load_sequence(u32 player, u32 seqId, s32 loadAsync); 100 | 101 | #ifdef VERSION_SH 102 | void func_sh_802f3158(s32 seqId, s32 arg1, s32 arg2, OSMesgQueue *retQueue); 103 | u8 *func_sh_802f3220(u32 seqId, u32 *a1); 104 | struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx); 105 | s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io); 106 | void *func_sh_802f3f08(s32 poolIdx, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue *retQueue); 107 | void func_sh_802f41e4(s32 audioResetStatus); 108 | BAD_RETURN(s32) func_sh_802f3368(s32 bankId); 109 | void *func_sh_802f3764(s32 arg0, s32 idx, s32 *arg2); 110 | s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2); 111 | void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3); 112 | void func_sh_802f3288(s32 idx); 113 | 114 | #endif 115 | 116 | #endif // AUDIO_LOAD_H 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Classic64 2 | A plugin for [ClassiCube](https://classicube.net) which uses libsm64 to insert a playable Mario from Super Mario 64 into the game. 3 | 4 | ![Hey stinky!](screenshot.png) 5 | 6 | This project was not created by, or is related with the developers of the Minecraft mod "Retro64".
7 | [ClassiCube](https://github.com/UnknownShadow200/ClassiCube) is a custom Minecraft Classic client written in C. 8 | 9 | ## Compiling the plugin 10 | ### Windows 11 | * Download the [MSYS2](https://msys2.org/#installation) development environment, launch MSYS2 MinGW x64 and install the dependencies: `pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-tools mingw-w64-x86_64-SDL2`. 12 | * To compile for 32-bit, open MSYS MinGW x86 instead, and replace `x86_64` with `i686` in the command 13 | * Follow [these instructions](https://github.com/ClassiCube/ClassiCube/blob/master/doc/plugin-dev.md#using-mingw-w64) to compile libClassiCube.a (needed to compile the plugin) 14 | * Run `make`. 15 | 16 | A folder named "dist" will be created and inside will sit the plugin dll file "Classic64.dll". 17 | Copy this to your ClassiCube plugins folder. 18 | 19 | ### Linux 20 | Install gcc, g++ and make using your package manager: 21 | ``` 22 | # For Ubuntu and derivatives like Linux Mint and Pop!_OS: 23 | sudo apt install gcc g++ make 24 | 25 | # For Arch Linux and derivatives like Manjaro: 26 | sudo pacman -S gcc make 27 | ``` 28 | 29 | By default, the makefile will compile with SDL2 for providing sound, so you must install the dependency as well: 30 | ``` 31 | # For Ubuntu and derivatives like Linux Mint and Pop!_OS: 32 | sudo apt install libsdl2-dev 33 | 34 | # For Arch Linux and derivatives like Manjaro: 35 | sudo pacman -S sdl2 36 | ``` 37 | 38 | ## Running the plugin 39 | **You are required to supply a dumped copy of your Super Mario 64 US ROM, placed inside the plugins folder, with the filename "sm64.us.z64". 40 | Otherwise the plugin will refuse to work.** 41 | 42 | This plugin works on Windows and Linux, 32-bit and 64-bit. macOS has not been tested. 43 | 44 | ## How to play 45 | To turn into Mario, run the command `/model mario64`. This will let everyone on the server using this plugin know that you're playing as Mario, and will display the model on their end. 46 | 47 | If you are on a server with hacks enabled (flying, speed, etc) but the "/model" command is not allowed, you can run the client-side command `/client mario64 force`. 48 | If the server is running the Classic64 MCGalaxy plugin, everyone will see the client-side change as well. 49 | 50 | ## Running client-side commands with MessageBlocks or Bots 51 | If you're making a map intended for Mario, you can alter certain aspects of the plugin through your map by using MessageBlocks, or Bots! (Only on MCGalaxy servers) 52 | 53 | The format is `&0!mario64`, followed by one of the client-side commands listed below. 54 | 55 | Examples:
56 | If you want to play music ID 27 (Correct Solution) when breaking a white wool block: `/mb white &0!mario64 music 27`
57 | If you want to instantly kill Mario when a bot kills the player: `/bot deathmessage &0!mario64 kill` 58 | 59 | ## Client-side commands 60 | All client-side commands start with `/client mario64` 61 | 62 | * `/client mario64 music `
63 | Plays music from Super Mario 64.
64 | To stop music, use music ID 0. 65 | 66 | * `/client mario64 cap