"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,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;
@ -36,4 +38,4 @@ u32 frandmod(u32 arg0) {
frand_seed = frandom(frand_seed);
ret = (frand_seed & 0x7FFFFFFF)%arg0;
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)
{
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,23 +96,23 @@ 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) {
block->flag = 0;
if (block->prev < block && !block->prev->flag) {
block->flag = 0;
block->magic = 205;
block->next->prev = block->prev;
block->prev->next = block->next;
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;
@ -254,4 +257,4 @@ s16 HuPadStatGet(s16 pad)
u32 HuPadRumbleGet(void)
{
return RumbleBit;
}
}

View file

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