"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

@ -197,7 +197,8 @@ static inline void GWRumbleSet(s32 value)
{
GWGameStat.rumble = value;
if (value == 0) {
HuPadRumbleAllStop();
// 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;

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);
#endif
DemoCurrentBuffer = DemoFrameBuffer2;
#if VERSION_PAL
fb1 = DemoFrameBuffer1;
@ -156,17 +161,26 @@ static void InitMem()
DCStoreRangeNoSync(DemoFrameBuffer1, fb_size);
DCStoreRangeNoSync(DemoFrameBuffer2, fb_size);
#endif
#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

@ -48,7 +48,11 @@ static void *HuMemMemoryAlloc2(void *heap_ptr, s32 size, u32 num, uintptr_t reta
do {
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;
@ -82,7 +86,6 @@ void HuMemMemoryFreeNum(void *heap_ptr, u32 num, uintptr_t retaddr)
}
block = block_next;
} while (block != heap_ptr);
}
static void HuMemTailMemoryAlloc2() // Required for string literal
@ -161,30 +164,33 @@ void HuMemHeapDump(void *heap_ptr, s16 status)
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);
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) {
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);
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);
}
@ -197,7 +203,8 @@ s32 HuMemMemorySizeGet(void *ptr)
block = DATA_GET_BLOCK(ptr);
if (block->flag == 1 && block->magic == 165) {
return block->size - 32;
} else {
}
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>