Animation data loaded from rom
This commit is contained in:
@@ -93,15 +93,4 @@ def main():
|
|||||||
with open("src/mario/geo.inc.h", "w") as file:
|
with open("src/mario/geo.inc.h", "w") as file:
|
||||||
file.write(geo_inc_h)
|
file.write(geo_inc_h)
|
||||||
|
|
||||||
# os.chdir("sm64-port")
|
|
||||||
# mario_anims_pipe = subprocess.run(["tools/mario_anims_converter.py", "-l"], stdout=subprocess.PIPE)
|
|
||||||
# mario_anims_string = mario_anims_pipe.stdout.decode('utf-8')
|
|
||||||
# os.chdir("..")
|
|
||||||
#
|
|
||||||
# with open("src/mario/anim_data.c", "w") as file:
|
|
||||||
# file.write(mario_anims_string.replace('#include "types.h"', '#include "../include/types.h"\n#include "anim_data.h"') + anim_data_c_footer)
|
|
||||||
#
|
|
||||||
# with open("src/mario/anim_data.h", "w") as file:
|
|
||||||
# file.write(anim_data_h)
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
+4
-4
@@ -69,9 +69,9 @@ s32 is_anim_past_end(struct MarioState *m) {
|
|||||||
*/
|
*/
|
||||||
s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
|
s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
|
||||||
struct Object *o = m->marioObj;
|
struct Object *o = m->marioObj;
|
||||||
struct Animation *targetAnim = m->animation->targetAnim;
|
|
||||||
|
|
||||||
hack_load_mario_animation(m->animation, targetAnimID);
|
hack_load_mario_animation_ex(m->animation, targetAnimID);
|
||||||
|
struct Animation *targetAnim = m->animation->targetAnim;
|
||||||
//if (load_patchable_table(m->animation, targetAnimID)) {
|
//if (load_patchable_table(m->animation, targetAnimID)) {
|
||||||
// targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
|
// targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
|
||||||
// targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index);
|
// targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index);
|
||||||
@@ -103,9 +103,9 @@ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) {
|
|||||||
*/
|
*/
|
||||||
s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) {
|
s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) {
|
||||||
struct Object *o = m->marioObj;
|
struct Object *o = m->marioObj;
|
||||||
struct Animation *targetAnim = m->animation->targetAnim;
|
|
||||||
|
|
||||||
hack_load_mario_animation(m->animation, targetAnimID);
|
hack_load_mario_animation_ex(m->animation, targetAnimID);
|
||||||
|
struct Animation *targetAnim = m->animation->targetAnim;
|
||||||
//if (load_patchable_table(m->animation, targetAnimID)) {
|
//if (load_patchable_table(m->animation, targetAnimID)) {
|
||||||
// targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
|
// targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values);
|
||||||
// targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index);
|
// targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index);
|
||||||
|
|||||||
+2
-2
@@ -91,8 +91,8 @@ struct Animation {
|
|||||||
/*0x06*/ s16 loopStart;
|
/*0x06*/ s16 loopStart;
|
||||||
/*0x08*/ s16 loopEnd;
|
/*0x08*/ s16 loopEnd;
|
||||||
/*0x0A*/ s16 unusedBoneCount;
|
/*0x0A*/ s16 unusedBoneCount;
|
||||||
/*0x0C*/ const s16 *values;
|
/*0x0C*/ s16 *values;
|
||||||
/*0x10*/ const u16 *index;
|
/*0x10*/ u16 *index;
|
||||||
/*0x14*/ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
|
/*0x14*/ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -91,11 +91,11 @@ void sm64_global_init( uint8_t *rom, SM64DebugPrintFunctionPtr debugPrintFunctio
|
|||||||
s_mario_geo_pool = alloc_only_pool_init();
|
s_mario_geo_pool = alloc_only_pool_init();
|
||||||
s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr );
|
s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr );
|
||||||
|
|
||||||
D_80339D10.animDmaTable = gMarioAnimsPtr; // mario_anims_ptr;
|
D_80339D10.animDmaTable = NULL; // gMarioAnimsPtr; // mario_anims_ptr;
|
||||||
D_80339D10.currentAnimAddr = NULL;
|
D_80339D10.currentAnimAddr = NULL;
|
||||||
D_80339D10.targetAnim = malloc( 0x4000 );
|
D_80339D10.targetAnim = NULL;
|
||||||
|
|
||||||
DEBUG_LOG( "Mario animations loaded from address %lu", (uint64_t)D_80339D10.animDmaTable );
|
//DEBUG_LOG( "Mario animations loaded from address %lu", (uint64_t)D_80339D10.animDmaTable );
|
||||||
}
|
}
|
||||||
|
|
||||||
void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces )
|
void sm64_load_surfaces( uint16_t terrainType, const struct SM64Surface *surfaceArray, size_t numSurfaces )
|
||||||
|
|||||||
+44
-128
@@ -1,167 +1,83 @@
|
|||||||
#include "load_anim_data.h"
|
#include "load_anim_data.h"
|
||||||
#include "include/types.h"
|
#include "include/types.h"
|
||||||
#include "anim_datac.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static struct MarioAnimsObj s_marioAnimsObj;
|
struct Animation *gLibSm64MarioAnimations;
|
||||||
|
static struct Animation *s_marioAnimations;
|
||||||
|
|
||||||
#define ANIM_DATA_ADDRESS 0x004EC000
|
#define ANIM_DATA_ADDRESS 0x004EC000
|
||||||
|
|
||||||
#define MAX_ANIM_DATA_SIZE ( 1024 * 1024 )
|
uint16_t read_u16_be( uint8_t *p )
|
||||||
|
|
||||||
void *gMarioAnimsPtr;
|
|
||||||
|
|
||||||
uint16_t read_u16_be( uint8_t **ptr )
|
|
||||||
{
|
{
|
||||||
uint8_t *p = *ptr;
|
return
|
||||||
|
|
||||||
uint32_t result =
|
|
||||||
(uint32_t)p[0] << 8 |
|
(uint32_t)p[0] << 8 |
|
||||||
(uint32_t)p[1];
|
(uint32_t)p[1];
|
||||||
|
|
||||||
*ptr += 2;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t read_s16_be( uint8_t **ptr )
|
uint16_t read_s16_be( uint8_t *p )
|
||||||
{
|
{
|
||||||
return (int16_t)read_u16_be(ptr);
|
return (int16_t)read_u16_be( p );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t read_u32_be( uint8_t **ptr )
|
uint32_t read_u32_be( uint8_t *p )
|
||||||
{
|
{
|
||||||
uint8_t *p = *ptr;
|
return
|
||||||
|
|
||||||
uint32_t result =
|
|
||||||
(uint32_t)p[0] << 24 |
|
(uint32_t)p[0] << 24 |
|
||||||
(uint32_t)p[1] << 16 |
|
(uint32_t)p[1] << 16 |
|
||||||
(uint32_t)p[2] << 8 |
|
(uint32_t)p[2] << 8 |
|
||||||
(uint32_t)p[3];
|
(uint32_t)p[3];
|
||||||
|
|
||||||
*ptr += 4;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_u16_se( uint8_t **ptr, uint16_t val )
|
|
||||||
{
|
|
||||||
while( (size_t)(*ptr) % 2 > 0 )
|
|
||||||
*ptr += 1;
|
|
||||||
|
|
||||||
uint16_t *p = *ptr;
|
|
||||||
*p = val;
|
|
||||||
*ptr += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_s16_se( uint8_t **ptr, int16_t val )
|
|
||||||
{
|
|
||||||
while( (size_t)(*ptr) % 2 > 0 )
|
|
||||||
*ptr += 1;
|
|
||||||
|
|
||||||
uint16_t *p = *ptr;
|
|
||||||
*p = (uint16_t)val;
|
|
||||||
*ptr += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_u32_se( uint8_t **ptr, uint32_t val )
|
|
||||||
{
|
|
||||||
while( (size_t)(*ptr) % 4 > 0 )
|
|
||||||
*ptr += 1;
|
|
||||||
|
|
||||||
uint32_t *p = *ptr;
|
|
||||||
*p = val;
|
|
||||||
*ptr += 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_u64_se( uint8_t **ptr, uint64_t val )
|
|
||||||
{
|
|
||||||
while( (size_t)(*ptr) % 8 > 0 )
|
|
||||||
*ptr += 1;
|
|
||||||
|
|
||||||
uint64_t *p = *ptr;
|
|
||||||
*p = val;
|
|
||||||
*ptr += 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define GET_OFFSET_SIZE_PAIR_PTR( n ) ((struct OffsetSizePair*)( buffer + 8 + sizeof(void*) + (n)*8 ))
|
|
||||||
#define OVERWRITE_OFFSET( n, v ) do { ((struct OffsetSizePair*)( buffer + 8 + sizeof(void*) + (n)*8 ))->offset = (v); } while(0)
|
|
||||||
#define OVERWRITE_SIZE( n, v ) do { ((struct OffsetSizePair*)( buffer + 8 + sizeof(void*) + (n)*8 ))->size = (v); } while(0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void load_mario_anims_from_rom( uint8_t *rom )
|
void load_mario_anims_from_rom( uint8_t *rom )
|
||||||
{
|
{
|
||||||
uint8_t *buffer = malloc( MAX_ANIM_DATA_SIZE );
|
#define GET_OFFSET( n ) (read_u32_be(&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->offset))
|
||||||
|
#define GET_SIZE( n ) (read_u32_be(&((struct OffsetSizePair*)( rom + ANIM_DATA_ADDRESS + 8 + (n)*8 ))->size ))
|
||||||
|
|
||||||
uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS;
|
uint8_t *read_ptr = rom + ANIM_DATA_ADDRESS;
|
||||||
uint8_t *write_ptr = buffer;
|
uint32_t num_entries = read_u32_be( read_ptr );
|
||||||
|
|
||||||
uint32_t num_entries = read_u32_be( &read_ptr );
|
s_marioAnimations = malloc( num_entries * sizeof( struct Animation ));
|
||||||
write_u32_se( &write_ptr, num_entries );
|
|
||||||
write_u32_se( &write_ptr, 0 );
|
|
||||||
|
|
||||||
read_u32_be( &read_ptr );
|
|
||||||
write_u64_se( &write_ptr, 0 );
|
|
||||||
|
|
||||||
// Read all of the offset/size pairs for animation entries from the ROM.
|
|
||||||
for( int i = 0; i < num_entries; ++i )
|
|
||||||
{
|
|
||||||
uint32_t offset = read_u32_be( &read_ptr );
|
|
||||||
uint32_t size = read_u32_be( &read_ptr );
|
|
||||||
|
|
||||||
write_u32_se( &write_ptr, offset );
|
|
||||||
write_u32_se( &write_ptr, size );
|
|
||||||
}
|
|
||||||
|
|
||||||
int ptr_size_diff = sizeof(void*) - 4;
|
|
||||||
|
|
||||||
printf("\n\n");
|
|
||||||
|
|
||||||
for( int i = 0; i < num_entries; ++i )
|
for( int i = 0; i < num_entries; ++i )
|
||||||
{
|
{
|
||||||
struct OffsetSizePair rom_osp = *GET_OFFSET_SIZE_PAIR_PTR(i);
|
read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i);
|
||||||
read_ptr = rom + ANIM_DATA_ADDRESS + rom_osp.offset;
|
|
||||||
|
|
||||||
//offset = offset(top)
|
s_marioAnimations[i].flags = read_s16_be( read_ptr ); read_ptr += 2;
|
||||||
//size = offset(values) + size(values) - offset(top)
|
s_marioAnimations[i].animYTransDivisor = read_s16_be( read_ptr ); read_ptr += 2;
|
||||||
size_t offset = write_ptr - buffer;
|
s_marioAnimations[i].startFrame = read_s16_be( read_ptr ); read_ptr += 2;
|
||||||
OVERWRITE_OFFSET(i, offset);
|
s_marioAnimations[i].loopStart = read_s16_be( read_ptr ); read_ptr += 2;
|
||||||
|
s_marioAnimations[i].loopEnd = read_s16_be( read_ptr ); read_ptr += 2;
|
||||||
|
s_marioAnimations[i].unusedBoneCount = read_s16_be( read_ptr ); read_ptr += 2;
|
||||||
|
uint32_t values_offset = read_u32_be( read_ptr ); read_ptr += 4;
|
||||||
|
uint32_t index_offset = read_u32_be( read_ptr ); read_ptr += 4;
|
||||||
|
uint32_t end_offset = read_u32_be( read_ptr );
|
||||||
|
|
||||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // flags
|
read_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + index_offset;
|
||||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // animYTransDivisor
|
uint8_t *values_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + values_offset;
|
||||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // startFrame
|
uint8_t *end_ptr = rom + ANIM_DATA_ADDRESS + GET_OFFSET(i) + end_offset;
|
||||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // loopStart
|
|
||||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // loopEnd
|
|
||||||
write_s16_se( &write_ptr, read_s16_be( &read_ptr )); // unusedBoneCount
|
|
||||||
|
|
||||||
//values_ptr = offset(values) - offset(top)
|
s_marioAnimations[i].index = malloc( values_offset - index_offset );
|
||||||
//index_ptr = offset(indices) - offset(top)
|
s_marioAnimations[i].values = malloc( end_offset - values_offset );
|
||||||
//length = offset(values) + size(values) - offset(top)
|
|
||||||
|
|
||||||
uint32_t values_ptr = read_u32_be( &read_ptr ) + 2 * ptr_size_diff;
|
int j = 0;
|
||||||
uint32_t index_ptr = read_u32_be( &read_ptr ) + 2 * ptr_size_diff;
|
while( read_ptr < values_ptr )
|
||||||
uint32_t length = read_u32_be( &read_ptr ) + 4 * ptr_size_diff;
|
{
|
||||||
|
s_marioAnimations[i].index[j++] = read_u16_be( read_ptr );
|
||||||
|
read_ptr += 2;
|
||||||
|
}
|
||||||
|
|
||||||
OVERWRITE_SIZE(i, length);
|
j = 0;
|
||||||
|
while( read_ptr < end_ptr )
|
||||||
printf(" > %x %x \n", offset, length);
|
{
|
||||||
printf(" >>> %x %x \n", gMarioAnims.entries[i].offset, gMarioAnims.entries[i].size);
|
s_marioAnimations[i].values[j++] = read_u16_be( read_ptr );
|
||||||
|
read_ptr += 2;
|
||||||
write_u64_se( &write_ptr, values_ptr );
|
}
|
||||||
write_u64_se( &write_ptr, index_ptr );
|
|
||||||
write_u32_se( &write_ptr, length );
|
|
||||||
|
|
||||||
size_t data_bytes = i < num_entries - 1
|
|
||||||
? rom + ANIM_DATA_ADDRESS + GET_OFFSET_SIZE_PAIR_PTR(i + 1)->offset - read_ptr
|
|
||||||
: length;
|
|
||||||
|
|
||||||
for( int i = 0; i < data_bytes; ++i )
|
|
||||||
*write_ptr++ = *read_ptr++;
|
|
||||||
|
|
||||||
write_ptr += 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gMarioAnimsPtr = buffer; // &gMarioAnims;
|
gLibSm64MarioAnimations = s_marioAnimations;
|
||||||
|
|
||||||
|
#undef GET_OFFSET
|
||||||
|
#undef GET_SIZE
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "include/types.h"
|
#include "include/types.h"
|
||||||
|
|
||||||
extern void *gMarioAnimsPtr;
|
extern struct Animation *gLibSm64MarioAnimations;
|
||||||
|
//extern void *gMarioAnimsPtr;
|
||||||
|
|
||||||
extern void load_mario_anims_from_rom( uint8_t *rom );
|
extern void load_mario_anims_from_rom( uint8_t *rom );
|
||||||
+29
-20
@@ -1,5 +1,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "shim.h"
|
#include "shim.h"
|
||||||
|
#include "load_anim_data.h"
|
||||||
|
|
||||||
u32 gGlobalTimer = 0;
|
u32 gGlobalTimer = 0;
|
||||||
u8 gSpecialTripleJump = FALSE;
|
u8 gSpecialTripleJump = FALSE;
|
||||||
@@ -22,29 +23,37 @@ struct MarioState gMarioStateVal;
|
|||||||
struct MarioState *gMarioState = &gMarioStateVal;
|
struct MarioState *gMarioState = &gMarioStateVal;
|
||||||
SM64DebugPrintFunctionPtr gDebugPrint = NULL;
|
SM64DebugPrintFunctionPtr gDebugPrint = NULL;
|
||||||
|
|
||||||
|
void hack_load_mario_animation_ex(struct MarioAnimation *a, u32 index)
|
||||||
|
{
|
||||||
|
if ((u32)a->currentAnimAddr == 1 + index)
|
||||||
|
return;
|
||||||
|
|
||||||
|
a->currentAnimAddr = (u8*)(1 + index);
|
||||||
|
a->targetAnim = &gLibSm64MarioAnimations[index];
|
||||||
|
}
|
||||||
|
|
||||||
void hack_load_mario_animation(struct MarioAnimation *a, u32 index)
|
void hack_load_mario_animation(struct MarioAnimation *a, u32 index)
|
||||||
{
|
{
|
||||||
struct MarioAnimDmaRelatedThing *sp20 = a->animDmaTable;
|
// struct MarioAnimDmaRelatedThing *sp20 = a->animDmaTable;
|
||||||
u8 *addr;
|
// u8 *addr;
|
||||||
u32 size;
|
// u32 size;
|
||||||
|
//
|
||||||
if (index < sp20->count) {
|
// if (index < sp20->count) {
|
||||||
addr = sp20->srcAddr + sp20->anim[index].offset;
|
// addr = sp20->srcAddr + sp20->anim[index].offset;
|
||||||
size = sp20->anim[index].size;
|
// size = sp20->anim[index].size;
|
||||||
|
//
|
||||||
if (a->currentAnimAddr != addr) {
|
// if (a->currentAnimAddr != addr) {
|
||||||
u32 a0 = sp20->anim[index].offset;
|
// u32 a0 = sp20->anim[index].offset;
|
||||||
u32 b0 = sp20->anim[index].size;
|
// u32 b0 = sp20->anim[index].size;
|
||||||
|
//
|
||||||
memcpy( (u8*)a->targetAnim, (u8*)sp20 + a0, b0 );
|
// memcpy( (u8*)a->targetAnim, (u8*)sp20 + a0, b0 );
|
||||||
a->currentAnimAddr = addr;
|
// a->currentAnimAddr = addr;
|
||||||
|
//
|
||||||
struct Animation *targetAnim = a->targetAnim;
|
// struct Animation *targetAnim = a->targetAnim;
|
||||||
targetAnim->values =(void*)( (u8 *)targetAnim + (uintptr_t)targetAnim->values );
|
// targetAnim->values =(void*)( (u8 *)targetAnim + (uintptr_t)targetAnim->values );
|
||||||
targetAnim->index = (void*)( (u8 *)targetAnim + (uintptr_t)targetAnim->index );
|
// targetAnim->index = (void*)( (u8 *)targetAnim + (uintptr_t)targetAnim->index );
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void *segmented_to_virtual(const void *addr)
|
void *segmented_to_virtual(const void *addr)
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ extern SM64DebugPrintFunctionPtr gDebugPrint;
|
|||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
extern void hack_load_mario_animation_ex(struct MarioAnimation *a, u32 index);
|
||||||
extern void hack_load_mario_animation(struct MarioAnimation *a, u32 index);
|
extern void hack_load_mario_animation(struct MarioAnimation *a, u32 index);
|
||||||
extern void *segmented_to_virtual(const void *addr);
|
extern void *segmented_to_virtual(const void *addr);
|
||||||
extern void *virtual_to_segmented(u32 segment, const void *addr);
|
extern void *virtual_to_segmented(u32 segment, const void *addr);
|
||||||
|
|||||||
Reference in New Issue
Block a user