"various changes to get it building for mac, as well as 64-bit" from zestydev

This commit is contained in:
dbalatoni13 2025-04-04 04:05:31 +02:00
parent ed2a2225d7
commit caea40c6aa
11 changed files with 216 additions and 162 deletions

View file

@ -1,8 +1,18 @@
cmake_minimum_required(VERSION 3.13)
if (APPLE)
project(marioparty4 LANGUAGES C CXX OBJC)
else ()
project(marioparty4 LANGUAGES C CXX)
endif ()
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
# Set build type to Debug if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -fsanitize=address -fsanitize-address-use-after-scope")
@ -12,6 +22,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX 32)
endif ()
if(APPLE)
add_compile_options(-Wno-declaration-after-statement)
endif ()
add_subdirectory(extern/aurora EXCLUDE_FROM_ALL)
add_subdirectory(extern/musyx EXCLUDE_FROM_ALL)
@ -52,6 +66,15 @@ source_group("Dolphin" FILES ${DOLPHIN_FILES})
source_group("Game" FILES ${GAME_FILES})
source_group("Port" FILES ${PORT_FILES})
if (NOT MSVC)
foreach(file ${DOLPHIN_FILES})
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "-std=c89 -Dinline=")
endforeach()
foreach(file ${GAME_FILES})
set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "-std=c89 -Dinline=")
endforeach()
endif ()
add_executable(marioparty4 ${DOLPHIN_FILES} ${GAME_FILES} ${PORT_FILES})
target_compile_definitions(marioparty4 PRIVATE TARGET_PC VERSION=0)
target_compile_definitions(musyx PRIVATE MUSY_VERSION_MAJOR=1 MUSY_VERSION_MINOR=5 MUSY_VERSION_PATCH=4)

View file

@ -9,17 +9,17 @@ extern "C" {
typedef int OSHeapHandle;
typedef void (*OSAllocVisitor)(void *obj, u32 size);
void *OSInitAlloc(void *arenaStart, void *arenaEnd, int maxHeaps);
OSHeapHandle OSCreateHeap(void *start, void *end);
uintptr_t OSCreateHeap(void *start, void *end);
void OSDestroyHeap(OSHeapHandle heap);
void OSAddToHeap(OSHeapHandle heap, void *start, void *end);
OSHeapHandle OSSetCurrentHeap(OSHeapHandle heap);
void *OSAllocFromHeap(OSHeapHandle heap, u32 size);
void *OSAllocFromHeap(int heap, unsigned long size);
void *OSAllocFixed(void **rstart, void **rend);
void OSFreeToHeap(OSHeapHandle heap, void *ptr);
long OSCheckHeap(OSHeapHandle heap);
void OSDumpHeap(OSHeapHandle heap);
u32 OSReferentSize(void *ptr);
void OSVisitAllocated(OSAllocVisitor visitor);
unsigned long OSReferentSize(void *ptr);
void OSVisitAllocated(void (*visitor)(void *, unsigned long));
extern volatile OSHeapHandle __OSCurrHeap;
#define OSAlloc(size) OSAllocFromHeap(__OSCurrHeap, (size))
#define OSFree(ptr) OSFreeToHeap(__OSCurrHeap, (ptr))

View file

@ -5,7 +5,7 @@
#include "game/flag.h"
#include "version.h"
//HACK: to prevent prototype errors
// HACK: to prevent prototype errors
extern void HuPadRumbleAllStop(void);
typedef struct player_config {
@ -17,12 +17,12 @@ typedef struct player_config {
} PlayerConfig;
typedef struct system_state {
/* 0x00 */ struct {
/* 0x00 */ struct {
u8 party : 1;
u8 team : 1;
};
/* 0x01 */ u8 diff_story;
/* 0x02 */ struct {
/* 0x01 */ u8 diff_story;
/* 0x02 */ struct {
u16 bonus_star : 1;
u16 explain_mg : 1;
u16 show_com_mg : 1;
@ -30,35 +30,35 @@ typedef struct system_state {
u16 mess_speed : 2;
u16 save_mode : 2;
};
/* 0x04 */ u8 turn;
/* 0x05 */ u8 max_turn;
/* 0x06 */ u8 star_flag;
/* 0x07 */ u8 star_total;
/* 0x08 */ struct {
/* 0x04 */ u8 turn;
/* 0x05 */ u8 max_turn;
/* 0x06 */ u8 star_flag;
/* 0x07 */ u8 star_total;
/* 0x08 */ struct {
u8 star_pos : 3;
u8 board : 5;
};
/* 0x09 */ s8 last5_effect;
/* 0x0A */ s8 player_curr;
/* 0x0B */ u8 storyCharBit;
/* 0x0C */ s8 storyChar;
/* 0x0E */ s16 block_pos;
/* 0x10 */ u8 ATTRIBUTE_ALIGN(4) board_data[32];
/* 0x30 */ u8 mess_delay;
/* 0x31 */ struct {
};
/* 0x09 */ s8 last5_effect;
/* 0x0A */ s8 player_curr;
/* 0x0B */ u8 storyCharBit;
/* 0x0C */ s8 storyChar;
/* 0x0E */ s16 block_pos;
/* 0x10 */ u8 ATTRIBUTE_ALIGN(4) board_data[32];
/* 0x30 */ u8 mess_delay;
/* 0x31 */ struct {
u8 bowser_loss : 4;
u8 bowser_event : 4;
};
/* 0x32 */ s8 lucky_value;
/* 0x34 */ u16 mg_next;
/* 0x36 */ s16 mg_type;
/* 0x38 */ u16 unk_38;
/* 0x3A */ u8 flag[3][16];
/* 0x6A */ u8 unk_6A[0x72];
} SystemState; //8018fcf8, sizeof 0xDC
/* 0x32 */ s8 lucky_value;
/* 0x34 */ u16 mg_next;
/* 0x36 */ s16 mg_type;
/* 0x38 */ u16 unk_38;
/* 0x3A */ u8 flag[3][16];
/* 0x6A */ u8 unk_6A[0x72];
} SystemState; // 8018fcf8, sizeof 0xDC
typedef struct player_state {
/* 0x00 */ struct {
/* 0x00 */ struct {
u16 diff : 2;
u16 com : 1;
u16 character : 4;
@ -66,15 +66,15 @@ typedef struct player_state {
u16 draw_ticket : 1;
u16 ticket_player : 6;
};
/* 0x02 */ struct {
/* 0x02 */ struct {
u8 team : 1;
u8 spark : 1;
u8 player_idx : 2;
};
/* 0x03 */ s8 handicap;
/* 0x04 */ s8 port;
/* 0x05 */ s8 items[3];
/* 0x08 */ struct {
/* 0x03 */ s8 handicap;
/* 0x04 */ s8 port;
/* 0x05 */ s8 items[3];
/* 0x08 */ struct {
u16 color : 2;
u16 moving : 1;
u16 jump : 1;
@ -85,30 +85,30 @@ typedef struct player_state {
u16 bowser_suit : 1;
u16 team_backup : 1;
};
/* 0x0A */ s8 roll;
/* 0x0C */ s16 space_curr;
/* 0x0E */ s16 space_prev;
/* 0x10 */ s16 space_next;
/* 0x12 */ s16 space_shock;
/* 0x14 */ s8 blue_count;
/* 0x15 */ s8 red_count;
/* 0x16 */ s8 question_count;
/* 0x17 */ s8 fortune_count;
/* 0x18 */ s8 bowser_count;
/* 0x19 */ s8 battle_count;
/* 0x1A */ s8 mushroom_count;
/* 0x1B */ s8 warp_count;
/* 0x1C */ s16 coins;
/* 0x1E */ s16 coins_mg;
/* 0x20 */ s16 coins_total;
/* 0x22 */ s16 coins_max;
/* 0x24 */ s16 coins_battle;
/* 0x26 */ s16 coin_collect;
/* 0x28 */ s16 coin_win;
/* 0x2A */ s16 stars;
/* 0x2C */ s16 stars_max;
/* 0x2E */ char unk_2E[2];
} PlayerState; //size of 0x30
/* 0x0A */ s8 roll;
/* 0x0C */ s16 space_curr;
/* 0x0E */ s16 space_prev;
/* 0x10 */ s16 space_next;
/* 0x12 */ s16 space_shock;
/* 0x14 */ s8 blue_count;
/* 0x15 */ s8 red_count;
/* 0x16 */ s8 question_count;
/* 0x17 */ s8 fortune_count;
/* 0x18 */ s8 bowser_count;
/* 0x19 */ s8 battle_count;
/* 0x1A */ s8 mushroom_count;
/* 0x1B */ s8 warp_count;
/* 0x1C */ s16 coins;
/* 0x1E */ s16 coins_mg;
/* 0x20 */ s16 coins_total;
/* 0x22 */ s16 coins_max;
/* 0x24 */ s16 coins_battle;
/* 0x26 */ s16 coin_collect;
/* 0x28 */ s16 coin_win;
/* 0x2A */ s16 stars;
/* 0x2C */ s16 stars_max;
/* 0x2E */ char unk_2E[2];
} PlayerState; // size of 0x30
typedef struct pause_backup_config {
u8 explain_mg : 1;
@ -119,21 +119,21 @@ typedef struct pause_backup_config {
} PauseBackupConfig;
typedef struct game_stat {
/* 0x0 */ s16 unk_00;
/* 0x2 */ u8 language;
/* 0x3 */ u8 sound_mode;
/* 0x4 */ s8 rumble;
/* 0x6 */ u16 total_stars;
/* 0x8 */ OSTime create_time;
/* 0x10 */ u32 mg_custom[2];
/* 0x18 */ u32 mg_avail[2];
/* 0x20 */ u32 mg_record[15];
/* 0x5C */ u8 board_win_count[9][8];
/* 0xA4 */ u8 board_play_count[9];
/* 0xAE */ u16 board_max_stars[9];
/* 0xC0 */ u16 board_max_coins[9];
/* 0xD2 */ u8 present[60];
/* 0x10E */ struct {
/* 0x0 */ s16 unk_00;
/* 0x2 */ u8 language;
/* 0x3 */ u8 sound_mode;
/* 0x4 */ s8 rumble;
/* 0x6 */ u16 total_stars;
/* 0x8 */ OSTime create_time;
/* 0x10 */ u32 mg_custom[2];
/* 0x18 */ u32 mg_avail[2];
/* 0x20 */ u32 mg_record[15];
/* 0x5C */ u8 board_win_count[9][8];
/* 0xA4 */ u8 board_play_count[9];
/* 0xAE */ u16 board_max_stars[9];
/* 0xC0 */ u16 board_max_coins[9];
/* 0xD2 */ u8 present[60];
/* 0x10E */ struct {
u8 story_continue : 1;
u8 party_continue : 1;
u8 open_w06 : 1;
@ -141,8 +141,8 @@ typedef struct game_stat {
u8 customPackEnable : 1;
u8 musicAllF : 1;
};
/* 0x10F */ PauseBackupConfig story_pause;
/* 0x110 */ PauseBackupConfig party_pause;
/* 0x10F */ PauseBackupConfig story_pause;
/* 0x110 */ PauseBackupConfig party_pause;
} GameStat;
extern s16 GwLanguage;
@ -196,8 +196,9 @@ static inline s32 GWRumbleGet(void)
static inline void GWRumbleSet(s32 value)
{
GWGameStat.rumble = value;
if(value == 0) {
HuPadRumbleAllStop();
if (value == 0) {
// TODO: get rumble working
// HuPadRumbleAllStop();
}
}
@ -206,7 +207,6 @@ static inline s32 GWBonusStarGet(void)
return GWSystem.bonus_star;
}
static inline s32 GWMGExplainGet(void)
{
return GWSystem.explain_mg;
@ -250,9 +250,9 @@ static inline s32 GWMessSpeedGet(void)
static inline void GWMessSpeedSet(s32 value)
{
#if VERSION_NTSC
#if VERSION_NTSC
GWSystem.mess_speed = value;
switch(value) {
switch (value) {
case 0:
GWSystem.mess_delay = 16;
break;
@ -265,9 +265,9 @@ static inline void GWMessSpeedSet(s32 value)
GWSystem.mess_delay = 32;
break;
}
#else
#else
GWSystem.mess_speed = value;
switch(value) {
switch (value) {
case 0:
GWSystem.mess_delay = 32;
break;
@ -284,7 +284,7 @@ static inline void GWMessSpeedSet(s32 value)
GWSystem.mess_delay = 120;
break;
}
#endif
#endif
}
static inline void GWSaveModeSet(s32 value)
@ -367,7 +367,7 @@ static inline void GWPlayerCoinWinSet(s32 player, s16 value)
}
}
#define GWPlayerCoinWinAdd(player, value) GWPlayerCoinWinSet((player), GWPlayerCoinWinGet((player))+(value))
#define GWPlayerCoinCollectAdd(player, value) GWPlayerCoinCollectSet((player), (s32)GWPlayerCoinCollectGet((player))+(value))
#define GWPlayerCoinWinAdd(player, value) GWPlayerCoinWinSet((player), GWPlayerCoinWinGet((player)) + (value))
#define GWPlayerCoinCollectAdd(player, value) GWPlayerCoinCollectSet((player), (s32)GWPlayerCoinCollectGet((player)) + (value))
#endif

View file

@ -1,6 +1,7 @@
#include <dolphin.h>
#include <dolphin/os.h>
#include <dolphin/os/OSPriv.h>
#include <stdlib.h>
#define ALIGNMENT 32
@ -203,12 +204,12 @@ void *OSAllocFixed(void **rstart, void **rend)
void *end;
void *cellEnd;
start = (void *)((*(u32 *)rstart) & ~((32) - 1));
end = (void *)((*(u32 *)rend + 0x1FU) & ~((32) - 1));
start = (void *)((*(uintptr_t *)rstart) & ~((32) - 1));
end = (void *)((*(uintptr_t *)rend + 0x1FU) & ~((32) - 1));
ASSERTMSG1(0x1B0, HeapArray, "OSAllocFixed(): heap is not initialized.");
ASSERTMSG1(0x1B1, (u32)start < (u32)end, "OSAllocFixed(): invalid range.");
ASSERTMSG1(0x1B3, ((u32)ArenaStart <= (u32)start) && ((u32)end <= (u32)ArenaEnd), "OSAllocFixed(): invalid range.");
ASSERTMSG1(0x1B1, (uintptr_t)start < (uintptr_t)end, "OSAllocFixed(): invalid range.");
ASSERTMSG1(0x1B3, ((uintptr_t)ArenaStart <= (uintptr_t)start) && ((uintptr_t)start <= (uintptr_t)ArenaEnd), "OSAllocFixed(): invalid range.");
for (i = 0; i < NumHeaps; i++) {
hd = &HeapArray[i];
@ -245,7 +246,7 @@ void *OSAllocFixed(void **rstart, void **rend)
ASSERTMSG(0x1F3, MINOBJSIZE <= (char *)cellEnd - (char *)end);
newCell = (struct Cell *)end;
newCell->size = (s32)((char *)cellEnd - (char *)end);
newCell->size = (intptr_t)((char *)cellEnd - (char *)end);
newCell->next = cell->next;
if (newCell->next) {
newCell->next->prev = newCell;
@ -292,9 +293,9 @@ void *OSAllocFixed(void **rstart, void **rend)
ASSERTMSG(0x225, OFFSET(start, ALIGNMENT) == 0);
ASSERTMSG(0x226, OFFSET(end, ALIGNMENT) == 0);
ASSERTMSG(0x227, start < end);
*(u32 *)rstart = (u32)start;
*(u32 *)rend = (u32)end;
return (void *)*(u32 *)rstart;
*(uintptr_t *)rstart = (uintptr_t)start;
*(uintptr_t *)rend = (uintptr_t)end;
return (void *)*(uintptr_t *)rstart;
}
void OSFreeToHeap(int heap, void *ptr)
@ -336,8 +337,8 @@ void *OSInitAlloc(void *arenaStart, void *arenaEnd, int maxHeaps)
struct HeapDesc *hd;
ASSERTMSG1(0x283, maxHeaps > 0, "OSInitAlloc(): invalid number of heaps.");
ASSERTMSG1(0x285, (u32)arenaStart < (u32)arenaEnd, "OSInitAlloc(): invalid range.");
ASSERTMSG1(0x288, maxHeaps <= (((u32)arenaEnd - (u32)arenaStart) / 24U), "OSInitAlloc(): too small range.");
ASSERTMSG1(0x285, (uintptr_t)arenaStart < (uintptr_t)arenaEnd, "OSInitAlloc(): invalid range.");
ASSERTMSG1(0x288, maxHeaps <= (((uintptr_t)arenaEnd - (uintptr_t)arenaStart) / 24U), "OSInitAlloc(): too small range.");
arraySize = maxHeaps * sizeof(struct HeapDesc);
HeapArray = arenaStart;
NumHeaps = maxHeaps;
@ -348,34 +349,34 @@ void *OSInitAlloc(void *arenaStart, void *arenaEnd, int maxHeaps)
hd->free = hd->allocated = 0;
}
__OSCurrHeap = -1;
arenaStart = (void *)((u32)((char *)HeapArray + arraySize));
arenaStart = (void *)(((u32)arenaStart + 0x1F) & 0xFFFFFFE0);
arenaStart = (void *)((uintptr_t)((char *)HeapArray + arraySize));
arenaStart = (void *)(((uintptr_t)arenaStart + 0x1F) & 0xFFFFFFFFFFFFFFE0);
ArenaStart = arenaStart;
ArenaEnd = (void *)((u32)arenaEnd & 0xFFFFFFE0);
ASSERTMSG1(0x2A4, ((u32)ArenaEnd - (u32)ArenaStart) >= 0x40U, "OSInitAlloc(): too small range.");
ArenaEnd = (void *)((uintptr_t)arenaEnd & 0xFFFFFFFFFFFFFFE0);
ASSERTMSG1(0x2A4, ((uintptr_t)ArenaEnd - (uintptr_t)ArenaStart) >= 0x40U, "OSInitAlloc(): too small range.");
return arenaStart;
}
int OSCreateHeap(void *start, void *end)
uintptr_t OSCreateHeap(void *start, void *end)
{
int heap;
uintptr_t heap;
struct HeapDesc *hd;
struct Cell *cell;
ASSERTMSG1(0x2BD, HeapArray, "OSCreateHeap(): heap is not initialized.");
ASSERTMSG1(0x2BE, (u32)start < (u32)end, "OSCreateHeap(): invalid range.");
ASSERTMSG1(0x2BE, start < end, "OSCreateHeap(): invalid range.");
start = (void *)(((u32)start + 0x1FU) & ~((32) - 1));
end = (void *)(((u32)end) & ~((32) - 1));
start = (void *)(((uintptr_t)start + 0x1FU) & ~((32) - 1));
end = (void *)(((uintptr_t)end) & ~((32) - 1));
ASSERTMSG1(0x2C1, (u32)start < (u32)end, "OSCreateHeap(): invalid range.");
ASSERTMSG1(0x2C3, (u32)ArenaStart <= (u32)start && (u32)end <= (u32)ArenaEnd, "OSCreateHeap(): invalid range.");
ASSERTMSG1(0x2C5, ((u32)end - (u32)start) >= 0x40U, "OSCreateHeap(): too small range.");
ASSERTMSG1(0x2C1, (uintptr_t)start < (uintptr_t)end, "OSCreateHeap(): invalid range.");
ASSERTMSG1(0x2C3, (uintptr_t)ArenaStart <= (uintptr_t)start && (uintptr_t)end <= (uintptr_t)ArenaEnd, "OSCreateHeap(): invalid range.");
ASSERTMSG1(0x2C5, ((uintptr_t)end - (uintptr_t)start) >= 0x40U, "OSCreateHeap(): too small range.");
for (heap = 0; heap < NumHeaps; heap++) {
hd = &HeapArray[heap];
if (hd->size < 0) {
hd->size = (u32)end - (u32)start;
hd->size = (uintptr_t)end - (uintptr_t)start;
cell = start;
cell->prev = 0;
cell->next = 0;

View file

@ -3,8 +3,8 @@
#include <dolphin/os.h>
#include <dolphin/sipriv.h>
extern OSTime __OSGetSystemTime();
extern u32 VIGetCurrentLine(void);
typedef struct SIControl {
s32 chan;

View file

@ -2,6 +2,8 @@
static u32 frand_seed;
extern s32 rand8(void);
static inline u32 frandom(u32 param)
{
s32 rand2, rand3;

View file

@ -39,6 +39,13 @@ static inline void InitPlayerConfig(void)
}
}
// TODO: get these properly declared somewhere
extern void GWRumbleSet(s32 value);
extern void GWMGExplainSet(s32 value);
extern void GWMGShowComSet(s32 value);
extern void GWMessSpeedSet(s32 value);
extern void GWSaveModeSet(s32 value);
static inline void ResetBoardSettings(void)
{
GWRumbleSet(1);

View file

@ -140,12 +140,17 @@ static void InitMem()
{
void *arena_lo = OSGetArenaLo();
void *arena_hi = OSGetArenaHi();
u32 fb_size = (u16)(((u16)RenderMode->fbWidth+15) & ~15)*RenderMode->xfbHeight*2;
u32 *fb1;
u32 *fb2;
uintptr_t fb_size = (u16)(((u16)RenderMode->fbWidth+15) & ~15)*RenderMode->xfbHeight*2;
uintptr_t *fb1;
uintptr_t *fb2;
u32 i;
#ifdef TARGET_PC
DemoFrameBuffer1 = (void *)arena_lo;
DemoFrameBuffer2 = (void *)((uintptr_t)DemoFrameBuffer1 + fb_size);
#else
DemoFrameBuffer1 = (void *)OSRoundUp32B((u32)arena_lo);
DemoFrameBuffer2 = (void *)OSRoundUp32B((u32)DemoFrameBuffer1+fb_size);
DemoFrameBuffer2 = (void *)OSRoundUp32B((u32)DemoFrameBuffer1 + fb_size);
#endif
DemoCurrentBuffer = DemoFrameBuffer2;
#if VERSION_PAL
fb1 = DemoFrameBuffer1;
@ -156,17 +161,26 @@ static void InitMem()
DCStoreRangeNoSync(DemoFrameBuffer1, fb_size);
DCStoreRangeNoSync(DemoFrameBuffer2, fb_size);
#endif
arena_lo = (void *)OSRoundUp32B((u32)DemoFrameBuffer2+fb_size);
#ifdef TARGET_PC
arena_lo = (void *)((uintptr_t)DemoFrameBuffer2 + fb_size);
#else
arena_lo = (void *)OSRoundUp32B((u32)DemoFrameBuffer2 + fb_size);
#endif
OSSetArenaLo(arena_lo);
if(OSGetConsoleType() == OS_CONSOLE_DEVHW1 && OSGetPhysicalMemSize() != 0x400000 && OSGetConsoleSimulatedMemSize() < 0x1800000) {
LoadMemInfo();
} else {
#ifdef TARGET_PC
arena_lo = OSGetArenaLo();
arena_hi = OSGetArenaHi();
arena_lo = OSInitAlloc(arena_lo, arena_hi, 1);
OSSetArenaLo(arena_lo);
#else
arena_lo = (void *)OSRoundUp32B((u32)arena_lo);
arena_hi = (void *)OSRoundDown32B((u32)arena_hi);
#endif
arena_lo = OSInitAlloc(arena_lo, arena_hi, 1);
OSSetArenaLo(arena_lo);
arena_lo = (void *)arena_lo;
arena_hi = (void *)arena_hi;
OSSetCurrentHeap(currentHeapHandle = OSCreateHeap(arena_lo, arena_hi));
arena_lo = arena_hi;
OSSetArenaLo(arena_lo);

View file

@ -1,10 +1,10 @@
#include "game/memory.h"
#include "dolphin/os.h"
#define DATA_GET_BLOCK(ptr) ((struct memory_block *)(((char *)(ptr))-32))
#define BLOCK_GET_DATA(block) (((char *)(block))+32)
#define DATA_GET_BLOCK(ptr) ((struct memory_block *)(((char *)(ptr)) - 32))
#define BLOCK_GET_DATA(block) (((char *)(block)) + 32)
#define MEM_ALLOC_SIZE(size) (((size)+63) & 0xFFFFFFE0)
#define MEM_ALLOC_SIZE(size) (((size) + 63) & 0xFFFFFFE0)
struct memory_block {
s32 size;
@ -46,10 +46,14 @@ static void *HuMemMemoryAlloc2(void *heap_ptr, s32 size, u32 num, uintptr_t reta
s32 alloc_size = MEM_ALLOC_SIZE(size);
struct memory_block *block = heap_ptr;
do {
if(!block->flag && block->size >= alloc_size) {
if(block->size-alloc_size > 32u) {
struct memory_block *new_block = (struct memory_block *)(((u32)block)+alloc_size);
new_block->size = block->size-alloc_size;
if (!block->flag && block->size >= alloc_size) {
if (block->size - alloc_size > 32u) {
#ifdef TARGET_PC
struct memory_block *new_block = (struct memory_block *)(((char *)block) + alloc_size);
#else
struct memory_block *new_block = (struct memory_block *)(((u32)block) + alloc_size);
#endif
new_block->size = block->size - alloc_size;
new_block->magic = 205;
new_block->flag = 0;
new_block->retaddr = retaddr;
@ -66,7 +70,7 @@ static void *HuMemMemoryAlloc2(void *heap_ptr, s32 size, u32 num, uintptr_t reta
return BLOCK_GET_DATA(block);
}
block = block->next;
} while(block != heap_ptr);
} while (block != heap_ptr);
OSReport("HuMem>memory alloc error %08x(%08X): Call %08x\n", size, num, retaddr);
HuMemHeapDump(heap_ptr, -1);
return NULL;
@ -77,15 +81,14 @@ void HuMemMemoryFreeNum(void *heap_ptr, u32 num, uintptr_t retaddr)
struct memory_block *block = heap_ptr;
do {
struct memory_block *block_next = block->next;
if(block->flag && block->num == num) {
if (block->flag && block->num == num) {
HuMemMemoryFree(BLOCK_GET_DATA(block), retaddr);
}
block = block_next;
} while(block != heap_ptr);
} while (block != heap_ptr);
}
static void HuMemTailMemoryAlloc2() //Required for string literal
static void HuMemTailMemoryAlloc2() // Required for string literal
{
OSReport("memory allocation(tail) error.\n");
}
@ -93,15 +96,15 @@ static void HuMemTailMemoryAlloc2() //Required for string literal
void HuMemMemoryFree(void *ptr, uintptr_t retaddr)
{
struct memory_block *block;
if(!ptr) {
if (!ptr) {
return;
}
block = DATA_GET_BLOCK(ptr);
if(block->magic != 165) {
if (block->magic != 165) {
OSReport("HuMem>memory free error. %08x( call %08x)\n", ptr, retaddr);
return;
}
if(block->prev < block && !block->prev->flag) {
if (block->prev < block && !block->prev->flag) {
block->flag = 0;
block->magic = 205;
block->next->prev = block->prev;
@ -109,7 +112,7 @@ void HuMemMemoryFree(void *ptr, uintptr_t retaddr)
block->prev->size += block->size;
block = block->prev;
}
if(block->next > block && !block->next->flag) {
if (block->next > block && !block->next->flag) {
block->next->next->prev = block;
block->size += block->next->size;
block->next = block->next->next;
@ -124,11 +127,11 @@ s32 HuMemUsedMemorySizeGet(void *heap_ptr)
struct memory_block *block = heap_ptr;
s32 size = 0;
do {
if(block->flag == 1) {
if (block->flag == 1) {
size += block->size;
}
block = block->next;
} while(block != heap_ptr);
} while (block != heap_ptr);
return size;
}
@ -137,11 +140,11 @@ s32 HuMemUsedMemoryBlockGet(void *heap_ptr)
struct memory_block *block = heap_ptr;
s32 num_blocks = 0;
do {
if(block->flag == 1) {
if (block->flag == 1) {
num_blocks++;
}
block = block->next;
} while(block != heap_ptr);
} while (block != heap_ptr);
return num_blocks;
}
@ -159,45 +162,49 @@ void HuMemHeapDump(void *heap_ptr, s16 status)
s32 num_unused_blocks = 0;
u8 dump_type;
if(status < 0) {
if (status < 0) {
dump_type = 10;
} else if(status == 0) {
}
else if (status == 0) {
dump_type = 0;
} else {
}
else {
dump_type = 1;
}
OSReport("======== HuMem heap dump %08x ========\n", heap_ptr);
OSReport("MCB-----+Size----+MG+FL+Prev----+Next----+UNum----+Body----+Call----\n");
do {
if(dump_type == 10 || block->flag == dump_type) {
OSReport("%08x %08x %02x %02x %08x %08x %08x %08x %08x\n", block, block->size, block->magic, block->flag,
block->prev, block->next, block->num, BLOCK_GET_DATA(block), block->retaddr);
if (dump_type == 10 || block->flag == dump_type) {
OSReport("%08x %08x %02x %02x %08x %08x %08x %08x %08x\n", block, block->size, block->magic, block->flag, block->prev, block->next,
block->num, BLOCK_GET_DATA(block), block->retaddr);
}
if(block->flag == 1) {
if (block->flag == 1) {
size += block->size;
num_blocks++;
} else {
}
else {
inactive_size += block->size;
num_unused_blocks++;
}
block = block->next;
} while(block != heap_ptr);
OSReport("MCB:%d(%d/%d) MEM:%08x(%08x/%08x)\n", num_blocks+num_unused_blocks, num_blocks, num_unused_blocks,
size+inactive_size, size, inactive_size);
} while (block != heap_ptr);
OSReport("MCB:%d(%d/%d) MEM:%08x(%08x/%08x)\n", num_blocks + num_unused_blocks, num_blocks, num_unused_blocks, size + inactive_size, size,
inactive_size);
OSReport("======== HuMem heap dump %08x end =====\n", heap_ptr);
}
s32 HuMemMemorySizeGet(void *ptr)
{
struct memory_block *block;
if(!ptr) {
if (!ptr) {
return 0;
}
block = DATA_GET_BLOCK(ptr);
if(block->flag == 1 && block->magic == 165) {
return block->size-32;
} else {
if (block->flag == 1 && block->magic == 165) {
return block->size - 32;
}
else {
return 0;
}
}

View file

@ -2,6 +2,9 @@
#include "game/msm.h"
#include "game/pad.h"
#ifdef TARGET_PC
#include <stdlib.h>
#endif
typedef struct pad_rumble {
s16 duration;

View file

@ -1,7 +1,4 @@
extern "C"
{
#include "port/imgui.h"
}
#include <array>
#include <atomic>