diff --git a/Makefile b/Makefile index ca34fef..b3fc266 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ else CC := cc LDFLAGS := -lm -shared endif -CFLAGS := -g -Wall -fPIC -DSM64_LIB_EXPORT +CFLAGS := -g -Wall -fPIC -DSM64_LIB_EXPORT -DGBI_FLOATS SRC_DIRS := src src/decomp src/decomp/engine src/decomp/game src/decomp/mario src/decomp/tools BUILD_DIR := build @@ -72,6 +72,6 @@ run: test ./$(TEST_FILE) clean: - rm -rf $(BUILD_DIR) $(DIST_DIR) src/decomp/mario test/level.? $(TEST_FILE) + rm -rf $(BUILD_DIR) $(DIST_DIR) $(TEST_FILE) -include $(DEP_FILES) diff --git a/src/debug_print.h b/src/debug_print.h index 913ed42..987cc31 100644 --- a/src/debug_print.h +++ b/src/debug_print.h @@ -10,8 +10,5 @@ extern SM64DebugPrintFunctionPtr g_debug_print_func; char debugStr[1024]; \ sprintf( debugStr, __VA_ARGS__ ); \ g_debug_print_func( debugStr ); \ - } else { \ - printf( __VA_ARGS__ ); \ - printf( "\n" ); \ } \ } while(0) diff --git a/src/decomp/engine/guMtxF2L.c b/src/decomp/engine/guMtxF2L.c index 7d89761..246336b 100644 --- a/src/decomp/engine/guMtxF2L.c +++ b/src/decomp/engine/guMtxF2L.c @@ -44,6 +44,9 @@ void guMtxL2F(float mf[4][4], Mtx *m) { void guMtxF2L(float mf[4][4], Mtx *m) { memcpy(m, mf, sizeof(Mtx)); } +void guMtxL2F(float mf[4][4], Mtx *m) { + memcpy(mf, m, sizeof(Mtx)); +} #endif void guMtxIdentF(float mf[4][4]) { diff --git a/src/decomp/game/area.h b/src/decomp/game/area.h index fee150b..84b05d6 100644 --- a/src/decomp/game/area.h +++ b/src/decomp/game/area.h @@ -35,7 +35,7 @@ struct InstantWarp struct SpawnInfo { - /*0x00*/ Vec3s startPos; + /*0x00*/ Vec3f startPos; /*0x06*/ Vec3s startAngle; /*0x0C*/ s8 areaIndex; /*0x0D*/ s8 activeAreaIndex; diff --git a/src/decomp/game/mario.c b/src/decomp/game/mario.c index 34f2fc0..2cd16c1 100644 --- a/src/decomp/game/mario.c +++ b/src/decomp/game/mario.c @@ -1329,7 +1329,9 @@ void update_mario_geometry_inputs(struct MarioState *m) { m->floorHeight = find_floor(m->pos[0], m->pos[1], m->pos[2], &m->floor); - m->curTerrain = m->floor->terrain; + if(m->floor != NULL) { + m->curTerrain = m->floor->terrain; + } // If Mario is OOB, move his position to his graphical position (which was not updated) // and check for the floor there. @@ -1836,7 +1838,7 @@ int init_mario(void) { vec3s_copy(gMarioState->faceAngle, gMarioSpawnInfo->startAngle); vec3s_set(gMarioState->angleVel, 0, 0, 0); - vec3s_to_vec3f(gMarioState->pos, gMarioSpawnInfo->startPos); + vec3f_copy(gMarioState->pos, gMarioSpawnInfo->startPos); vec3f_set(gMarioState->vel, 0, 0, 0); gMarioState->floorHeight = diff --git a/src/decomp/game/object_stuff.c b/src/decomp/game/object_stuff.c index f5e1bdc..e0f4615 100644 --- a/src/decomp/game/object_stuff.c +++ b/src/decomp/game/object_stuff.c @@ -81,8 +81,12 @@ static struct Object *allocate_object(void) { obj->numCollidedObjs = 0; for (i = 0; i < 0x50; i++) { +#ifdef _WIN32 obj->rawData.asS32[i] = 0; +#endif +#ifdef _WIN64 obj->ptrData.asVoidPtr[i] = NULL; +#endif } obj->unused1 = 0; diff --git a/src/decomp/shim.h b/src/decomp/shim.h index c0df3ab..11c762e 100644 --- a/src/decomp/shim.h +++ b/src/decomp/shim.h @@ -4,6 +4,7 @@ #include "game/area.h" #include "game/level_update.h" #include "../libsm64.h" +#include "../play_sound.h" #include "global_state.h" #define COURSE_MIN 0 @@ -36,7 +37,6 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" -static void play_sound(s32 soundBits, f32 *pos) {} static void enable_time_stop() {} static void disable_time_stop() {} static void *segmented_to_virtual(const void *addr) { return (void*)addr; } diff --git a/src/gfx_adapter.c b/src/gfx_adapter.c index 9265b0e..ba7fc1d 100644 --- a/src/gfx_adapter.c +++ b/src/gfx_adapter.c @@ -41,7 +41,7 @@ static void convert_uv_to_atlas( float *atlas_uv_out, short tc[] ) static void process_display_list( void *dl ) { - int64_t *ptr = (int64_t *)dl; + intptr_t *ptr = (intptr_t *)dl; Vtx *vdata = NULL; for( ;; ) @@ -50,23 +50,23 @@ static void process_display_list( void *dl ) { case GFXCMD_VertexData: { - UNUSED int64_t v = *ptr++; - UNUSED int64_t n = *ptr++; - UNUSED int64_t v0 = *ptr++; + UNUSED intptr_t v = *ptr++; + UNUSED intptr_t n = *ptr++; + UNUSED intptr_t v0 = *ptr++; vdata = (Vtx*)v; break; } case GFXCMD_Triangle: { - int64_t v00 = *ptr++; - int64_t v01 = *ptr++; - int64_t v02 = *ptr++; - UNUSED int64_t flag0 = *ptr++; + intptr_t v00 = *ptr++; + intptr_t v01 = *ptr++; + intptr_t v02 = *ptr++; + UNUSED intptr_t flag0 = *ptr++; - short x0 = vdata[v00].v.ob[0], y0 = vdata[v00].v.ob[1], z0 = vdata[v00].v.ob[2]; - short x1 = vdata[v01].v.ob[0], y1 = vdata[v01].v.ob[1], z1 = vdata[v01].v.ob[2]; - short x2 = vdata[v02].v.ob[0], y2 = vdata[v02].v.ob[1], z2 = vdata[v02].v.ob[2]; + float x0 = vdata[v00].v.ob[0], y0 = vdata[v00].v.ob[1], z0 = vdata[v00].v.ob[2]; + float x1 = vdata[v01].v.ob[0], y1 = vdata[v01].v.ob[1], z1 = vdata[v01].v.ob[2]; + float x2 = vdata[v02].v.ob[0], y2 = vdata[v02].v.ob[1], z2 = vdata[v02].v.ob[2]; Vec3f p0 = { (float)x0, (float)y0, (float)z0 }; Vec3f p1 = { (float)x1, (float)y1, (float)z1 }; Vec3f p2 = { (float)x2, (float)y2, (float)z2 }; @@ -129,8 +129,8 @@ static void process_display_list( void *dl ) case GFXCMD_Light: { - int64_t l = *ptr++; - int64_t n = *ptr++; + intptr_t l = *ptr++; + intptr_t n = *ptr++; if( n == 1 ) { @@ -145,9 +145,9 @@ static void process_display_list( void *dl ) case GFXCMD_Texture: { - int64_t s = *ptr++; - int64_t t = *ptr++; - int64_t on = *ptr++; + intptr_t s = *ptr++; + intptr_t t = *ptr++; + intptr_t on = *ptr++; s_scaleS = (uint16_t)s; s_scaleT = (uint16_t)t; @@ -158,7 +158,7 @@ static void process_display_list( void *dl ) case GFXCMD_SetTextureImage: { - int64_t i = *ptr++; + intptr_t i = *ptr++; s_textureIndex = (int)i; s_texWidth = mario_tex_widths[s_textureIndex]; @@ -169,8 +169,8 @@ static void process_display_list( void *dl ) case GFXCMD_SetTileSize: { - int64_t uls = *ptr++; - int64_t ult = *ptr++; + intptr_t uls = *ptr++; + intptr_t ult = *ptr++; ptr++; // lrs ptr++; // lrt @@ -182,7 +182,7 @@ static void process_display_list( void *dl ) case GFXCMD_SubDisplayList: { - int64_t dl = *ptr++; + intptr_t dl = *ptr++; process_display_list( (void*)dl ); break; } diff --git a/src/gfx_macros.h b/src/gfx_macros.h index 35b2988..3bbe1d0 100644 --- a/src/gfx_macros.h +++ b/src/gfx_macros.h @@ -74,11 +74,13 @@ typedef struct { #define G_OFF 0 #define G_TEXTURE_IMAGE_FRAC 2 +typedef intptr_t Gfx; + #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}}} } #define gsSPVertex(v, n, v0) \ GFXCMD_VertexData, \ - (int64_t)v, n, v0 + (intptr_t)v, n, v0 #define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ GFXCMD_Triangle, \ @@ -95,11 +97,11 @@ typedef struct { #define gsSPDisplayList(dl) \ GFXCMD_SubDisplayList, \ - (int64_t)dl + (intptr_t)dl #define gsSPLight(l, n) \ GFXCMD_Light, \ - (int64_t)l, n + (intptr_t)l, n #define gsSPTexture(s, t, level, tile, on) \ GFXCMD_Texture, \ @@ -123,6 +125,4 @@ typedef struct { #define gsDPTileSync() (GFXCMD_None) #define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, maskt, shiftt, cms, masks, shifts) (GFXCMD_None) #define gsDPLoadBlock(tile, uls, ult, lrs, dxt) (GFXCMD_None) -#define gsDPLoadSync() (GFXCMD_None) - -typedef int64_t Gfx; \ No newline at end of file +#define gsDPLoadSync() (GFXCMD_None) \ No newline at end of file diff --git a/src/libsm64.c b/src/libsm64.c index f184223..003837a 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -79,13 +79,25 @@ static void free_area( struct Area *area ) free( area ); } -SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugPrintFunctionPtr debugPrintFunction ) +typedef void (*SM64DebugPrintFunctionPtr)( const char * ); +SM64_LIB_FN void sm64_register_debug_print_function( SM64DebugPrintFunctionPtr debugPrintFunction ) +{ + g_debug_print_func = debugPrintFunction; +} + +typedef void (*SM64PlaySoundFunctionPtr)( uint32_t soundBits, f32 *pos ); +SM64_LIB_FN void sm64_register_play_sound_function( SM64PlaySoundFunctionPtr playSoundFunction ) +{ + g_play_sound_func = playSoundFunction; +} + + +SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture ) { if( s_init_global ) sm64_global_terminate(); s_init_global = true; - g_debug_print_func = debugPrintFunction; load_mario_textures_from_rom( rom, outTexture ); load_mario_anims_from_rom( rom ); @@ -127,7 +139,7 @@ SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArr surfaces_load_static( surfaceArray, numSurfaces ); } -SM64_LIB_FN int32_t sm64_mario_create( int16_t x, int16_t y, int16_t z ) +SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z ) { int32_t marioIndex = obj_pool_alloc_index( &s_mario_instance_pool, sizeof( struct MarioInstance )); struct MarioInstance *newInstance = s_mario_instance_pool.objects[marioIndex]; diff --git a/src/libsm64.h b/src/libsm64.h index 6274477..2a10146 100644 --- a/src/libsm64.h +++ b/src/libsm64.h @@ -5,6 +5,8 @@ #include #include +#include "decomp/include/types.h" + #ifdef _WIN32 #ifdef SM64_LIB_EXPORT #define SM64_LIB_FN __declspec(dllexport) @@ -20,7 +22,7 @@ struct SM64Surface int16_t type; int16_t force; uint16_t terrain; - int16_t vertices[3][3]; + int32_t vertices[3][3]; }; struct SM64MarioInputs @@ -60,8 +62,6 @@ struct SM64MarioGeometryBuffers uint16_t numTrianglesUsed; }; -typedef void (*SM64DebugPrintFunctionPtr)( const char * ); - enum { SM64_TEXTURE_WIDTH = 64 * 11, @@ -69,12 +69,20 @@ enum SM64_GEO_MAX_TRIANGLES = 1024, }; -extern SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugPrintFunctionPtr debugPrintFunction ); + +typedef void (*SM64DebugPrintFunctionPtr)( const char * ); +extern SM64_LIB_FN void sm64_register_debug_print_function( SM64DebugPrintFunctionPtr debugPrintFunction ); + +typedef void (*SM64PlaySoundFunctionPtr)( uint32_t soundBits, f32 *pos ); +extern SM64_LIB_FN void sm64_register_play_sound_function( SM64PlaySoundFunctionPtr playSoundFunction ); + + +extern SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture ); extern SM64_LIB_FN void sm64_global_terminate( void ); extern SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces ); -extern SM64_LIB_FN int32_t sm64_mario_create( int16_t x, int16_t y, int16_t z ); +extern SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z ); extern SM64_LIB_FN void sm64_mario_tick( int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers ); extern SM64_LIB_FN void sm64_mario_delete( int32_t marioId ); diff --git a/src/play_sound.c b/src/play_sound.c new file mode 100644 index 0000000..0560ba3 --- /dev/null +++ b/src/play_sound.c @@ -0,0 +1,9 @@ +#include "play_sound.h" + +SM64PlaySoundFunctionPtr g_play_sound_func = NULL; + +extern void play_sound( uint32_t soundBits, f32 *pos ) { + if ( g_play_sound_func ) { + g_play_sound_func(soundBits, pos); + } +} \ No newline at end of file diff --git a/src/play_sound.h b/src/play_sound.h new file mode 100644 index 0000000..ab486b3 --- /dev/null +++ b/src/play_sound.h @@ -0,0 +1,9 @@ +#pragma once + +#include "decomp/include/types.h" +#include "libsm64.h" +#include + +extern SM64PlaySoundFunctionPtr g_play_sound_func; + +extern void play_sound( uint32_t soundBits, f32 *pos ); \ No newline at end of file