"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) cmake_minimum_required(VERSION 3.13)
if (APPLE)
project(marioparty4 LANGUAGES C CXX OBJC)
else ()
project(marioparty4 LANGUAGES C CXX) project(marioparty4 LANGUAGES C CXX)
endif ()
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20) 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) if (CMAKE_SYSTEM_NAME STREQUAL Linux)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter") 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") 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) set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX 32)
endif () endif ()
if(APPLE)
add_compile_options(-Wno-declaration-after-statement)
endif ()
add_subdirectory(extern/aurora EXCLUDE_FROM_ALL) add_subdirectory(extern/aurora EXCLUDE_FROM_ALL)
add_subdirectory(extern/musyx 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("Game" FILES ${GAME_FILES})
source_group("Port" FILES ${PORT_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}) add_executable(marioparty4 ${DOLPHIN_FILES} ${GAME_FILES} ${PORT_FILES})
target_compile_definitions(marioparty4 PRIVATE TARGET_PC VERSION=0) 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) 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 int OSHeapHandle;
typedef void (*OSAllocVisitor)(void *obj, u32 size); typedef void (*OSAllocVisitor)(void *obj, u32 size);
void *OSInitAlloc(void *arenaStart, void *arenaEnd, int maxHeaps); 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 OSDestroyHeap(OSHeapHandle heap);
void OSAddToHeap(OSHeapHandle heap, void *start, void *end); void OSAddToHeap(OSHeapHandle heap, void *start, void *end);
OSHeapHandle OSSetCurrentHeap(OSHeapHandle heap); OSHeapHandle OSSetCurrentHeap(OSHeapHandle heap);
void *OSAllocFromHeap(OSHeapHandle heap, u32 size); void *OSAllocFromHeap(int heap, unsigned long size);
void *OSAllocFixed(void **rstart, void **rend); void *OSAllocFixed(void **rstart, void **rend);
void OSFreeToHeap(OSHeapHandle heap, void *ptr); void OSFreeToHeap(OSHeapHandle heap, void *ptr);
long OSCheckHeap(OSHeapHandle heap); long OSCheckHeap(OSHeapHandle heap);
void OSDumpHeap(OSHeapHandle heap); void OSDumpHeap(OSHeapHandle heap);
u32 OSReferentSize(void *ptr); unsigned long OSReferentSize(void *ptr);
void OSVisitAllocated(OSAllocVisitor visitor); void OSVisitAllocated(void (*visitor)(void *, unsigned long));
extern volatile OSHeapHandle __OSCurrHeap; extern volatile OSHeapHandle __OSCurrHeap;
#define OSAlloc(size) OSAllocFromHeap(__OSCurrHeap, (size)) #define OSAlloc(size) OSAllocFromHeap(__OSCurrHeap, (size))
#define OSFree(ptr) OSFreeToHeap(__OSCurrHeap, (ptr)) #define OSFree(ptr) OSFreeToHeap(__OSCurrHeap, (ptr))

View file

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

View file

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

View file

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

View file

@ -2,6 +2,8 @@
static u32 frand_seed; static u32 frand_seed;
extern s32 rand8(void);
static inline u32 frandom(u32 param) static inline u32 frandom(u32 param)
{ {
s32 rand2, rand3; s32 rand2, rand3;
@ -36,4 +38,4 @@ u32 frandmod(u32 arg0) {
frand_seed = frandom(frand_seed); frand_seed = frandom(frand_seed);
ret = (frand_seed & 0x7FFFFFFF)%arg0; ret = (frand_seed & 0x7FFFFFFF)%arg0;
return ret; return ret;
} }

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) static inline void ResetBoardSettings(void)
{ {
GWRumbleSet(1); GWRumbleSet(1);

View file

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

View file

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

View file

@ -2,6 +2,9 @@
#include "game/msm.h" #include "game/msm.h"
#include "game/pad.h" #include "game/pad.h"
#ifdef TARGET_PC
#include <stdlib.h>
#endif
typedef struct pad_rumble { typedef struct pad_rumble {
s16 duration; s16 duration;
@ -254,4 +257,4 @@ s16 HuPadStatGet(s16 pad)
u32 HuPadRumbleGet(void) u32 HuPadRumbleGet(void)
{ {
return RumbleBit; return RumbleBit;
} }

View file

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