Skip to content

Commit

Permalink
Port metrowerks changes to main
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialAmber committed Aug 5, 2024
1 parent b6ab59a commit 5d2013a
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 50 deletions.
9 changes: 4 additions & 5 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,15 @@ def main():
cflags_base += " -sym on -D_DEBUG"
else:
cflags_base += " -DNDEBUG -w off"
cflags_base += " -lang=c99" #TODO: add c99 lang flag on per lib basis
n.variable("cflags_base", cflags_base)
n.variable("cflags_game", "$cflags_base -ipa file -inline auto -use_lmw_stmw on -str reuse,pool,readonly -RTTI on -Cpp_exceptions on -func_align 4")
n.variable("cflags_game", "$cflags_base -lang=c99 -ipa file -inline auto -use_lmw_stmw on -str reuse,pool,readonly -RTTI on -Cpp_exceptions on -func_align 4")
n.variable("cflags_runtime", "$cflags_base -use_lmw_stmw on -str reuse,pool,readonly -gccinc -common off -inline on -func_align 4")
n.variable("cflags_mslc", "$cflags_base -use_lmw_stmw on -str reuse,pool,readonly -fp_contract off -inline on -ipa file -func_align 4")
n.variable("cflags_trk", "$cflags_base -use_lmw_stmw on -inline on -func_align 4")
n.variable("cflags_sdk", "$cflags_base -inline auto -ipa file -fp_contract off -func_align 16")
n.variable("cflags_ndev", "$cflags_base -inline auto -ipa file -func_align 4")
n.variable("cflags_sdk", "$cflags_base -lang=c99 -inline auto -ipa file -fp_contract off -func_align 16")
n.variable("cflags_ndev", "$cflags_base -lang=c99 -inline auto -ipa file -func_align 4")
n.variable("cflags_nw4r", "$cflags_base -inline auto -use_lmw_stmw on -fp_contract off -func_align 4")
n.variable("cflags_criware", "$cflags_base -sdata 0 -sdata2 0 -use_lmw_stmw on -func_align 4 -i libs/CriWare/src/")
n.variable("cflags_criware", "$cflags_base -lang=c99 -sdata 0 -sdata2 0 -use_lmw_stmw on -func_align 4 -i libs/CriWare/src/")


asflags = f"-mgekko -I include -W --strip-local-absolute -gdwarf-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef struct CircleBuffer {
ui32 unkC;
ui32 mBytesToRead;
ui32 mBytesToWrite;
uint mSection;
unsigned int mSection;
ui32 unk1C;
} CircleBuffer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define MW_CRITICAL_SECTION_GC

//MWCriticalSection_gc
void MWInitializeCriticalSection(uint* section);
void MWEnterCriticalSection(uint* section);
void MWExitCriticalSection(uint* section);
void MWTerminateCriticalSection(uint* section);
void MWInitializeCriticalSection(unsigned int* section);
void MWEnterCriticalSection(unsigned int* section);
void MWExitCriticalSection(unsigned int* section);
void MWTerminateCriticalSection(unsigned int* section);

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _TRK_DOLPHIN_TRK_GLUE_H
#define _TRK_DOLPHIN_TRK_GLUE_H

#include "PowerPC_EABI_Support/MetroTRK/dstypes.h"
#include "revolution/OS.h"
#include "PowerPC_EABI_Support/MetroTRK/dstypes.h"
#include "PowerPC_EABI_Support/MetroTRK/UART.h"

typedef enum{
Expand All @@ -11,6 +11,8 @@ typedef enum{
HARDWARE_BBA = 2
} HardwareType;

typedef signed long OSInterrupt;

typedef int (*DBCommFunc)();
typedef int (*DBCommInitFunc)(void*, OSInterruptHandler);
typedef int (*DBCommReadFunc)(ui8*, int);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ typedef unsigned long ui32;
typedef unsigned long long ui64;
typedef unsigned char ui128[16];

typedef signed char s8;
typedef signed short s16;
typedef signed long s32;

typedef unsigned long size_t;
typedef unsigned int uint;

typedef int bool;

#define true 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "PowerPC_EABI_Support/MetroTRK/dstypes.h"
#include "PowerPC_EABI_Support/MetroTRK/trk.h"
#include <stddef.h>


typedef int MessageBufferID;
Expand Down
3 changes: 0 additions & 3 deletions libs/PowerPC_EABI_Support/src/MSL_C/MSL_Common/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

typedef long long intmax_t;

#define PTRDIFF __typeof__((char*)0-(char*)0)
typedef PTRDIFF ptrdiff_t;

enum justification_options {
left_justification,
right_justification,
Expand Down
3 changes: 0 additions & 3 deletions libs/PowerPC_EABI_Support/src/MSL_C/MSL_Common/scanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

typedef long long intmax_t;

#define PTRDIFF __typeof__((char*)0-(char*)0)
typedef PTRDIFF ptrdiff_t;

enum argument_options {
normal_argument,
char_argument,
Expand Down
3 changes: 0 additions & 3 deletions libs/PowerPC_EABI_Support/src/MSL_C/MSL_Common/wprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

typedef long long intmax_t;

#define PTRDIFF __typeof__((char*)0-(char*)0)
typedef PTRDIFF ptrdiff_t;

enum justification_options {
left_justification,
right_justification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ void CircleBufferTerminate(CircleBuffer* cb){
}

int CircleBufferWriteBytes(CircleBuffer* cb, ui8* buf, ui32 size){
ui32 r29;

if(size > cb->mBytesToWrite) return -1;

MWEnterCriticalSection(&(cb->mSection));

ui32 r29 = cb->unkC - (cb->unk4 - cb->unk8);
r29 = cb->unkC - (cb->unk4 - cb->unk8);

if(r29 >= size){
memcpy(cb->unk4, buf, size);
Expand All @@ -56,11 +58,13 @@ int CircleBufferWriteBytes(CircleBuffer* cb, ui8* buf, ui32 size){
}

int CircleBufferReadBytes(CircleBuffer* cb, ui8* buf, ui32 size){
ui32 r29;

if(size > cb->mBytesToRead) return -1;

MWEnterCriticalSection(&(cb->mSection));

ui32 r29 = cb->unkC - (cb->unk0 - cb->unk8);
r29 = cb->unkC - (cb->unk0 - cb->unk8);

if(size < r29){
memcpy(buf, cb->unk0, size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

extern "C" {

void MWInitializeCriticalSection(uint* section){
void MWInitializeCriticalSection(unsigned int* section){
}

void MWEnterCriticalSection(uint* section){
void MWEnterCriticalSection(unsigned int* section){
*section = OSDisableInterrupts();
}

void MWExitCriticalSection(uint* section){
void MWExitCriticalSection(unsigned int* section){
OSRestoreInterrupts(*section);
}

//unused
void MWTerminateCriticalSection(uint* section){
void MWTerminateCriticalSection(unsigned int* section){
}

}
3 changes: 2 additions & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/custconn/cc_gdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ int gdev_cc_read(ui8* dest, int size){
}

while(CBGetBytesAvailableForRead(&gRecvCB) < size){
int r29;
r30 = 0;
int r29 = DBQueryData();
r29 = DBQueryData();
if(r29 != 0){
r30 = DBRead(buf, size);
if(r30 == 0){
Expand Down
3 changes: 2 additions & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
DSError TRK_DispatchMessage(MessageBuffer* buffer) {
DSError result = kDispatchError;
MessageBuffer* temp = buffer;
ui8 command;

TRK_SetBufferPosition(buffer, 0);

ui8 command = temp->fData[4];
command = temp->fData[4];

switch(command){
case kDSConnect:
Expand Down
2 changes: 1 addition & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/dolphin_trk_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ asm void TRKLoadContext(OSContext* ctx, ui32 r4){
b TRK_InterruptHandler
}

void TRKEXICallBack(s32 r3, OSContext* ctx){
void TRKEXICallBack(OSInterrupt r3, OSContext* ctx){
OSEnableScheduler();
TRKLoadContext(ctx, 0x500);
}
Expand Down
6 changes: 4 additions & 2 deletions libs/PowerPC_EABI_Support/src/MetroTRK/mem_TRK.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ static void ppc_writebyte1(ui8* ptr, ui8 val){
void* TRK_memcpy(void* dst, const void* src, int size){
ui8* srcTemp = (ui8*)src;
ui8* dstTemp = (ui8*)dst;
int i;

for(int i = 0; i != size; i++){
for(i = 0; i != size; i++){
ppc_writebyte1(dstTemp, ppc_readbyte1(srcTemp));
srcTemp++;
dstTemp++;
Expand All @@ -29,8 +30,9 @@ void* TRK_memcpy(void* dst, const void* src, int size){

void TRK_fill_mem(ui8* dst, int val, int size){
ui8 b = val;
int i;

for(int i = 0; i != size; i++){
for(i = 0; i != size; i++){
ppc_writebyte1(dst, b);
dst++;
}
Expand Down
3 changes: 2 additions & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ TRKPacketSeq gPacketSeq;

DSError TRK_MessageSend(MessageBuffer* msg)
{
ui32 write_val;
ui16 val = gPacketSeq.unk0;
if(val == 0) val = 1;
*(ui16*)(msg->fData + 6) = val;
gPacketSeq.unk0 = (val & 0xFFFF) + 1;

ui32 write_val = TRK_WriteUARTN(&msg->fData, msg->fLength);
write_val = TRK_WriteUARTN(&msg->fData, msg->fLength);
if(write_val != 0) OSReport("MetroTRK - TRK_WriteUARTN returned %ld\n", write_val);
return kNoError;
}
6 changes: 4 additions & 2 deletions libs/PowerPC_EABI_Support/src/MetroTRK/msgbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static void TRK_SetBufferUsed(MessageBuffer* b, bool state){
}

DSError TRK_InitializeMessageBuffers(){
for(int i = 0; i < NUM_BUFFERS; i++){
int i;
for(i = 0; i < NUM_BUFFERS; i++){
TRK_SetBufferUsed(&gTRKMsgBufs.buffers[i],false);
}

Expand All @@ -23,9 +24,10 @@ DSError TRK_InitializeMessageBuffers(){

DSError TRK_GetFreeBuffer(int* bufferIndexPtr, MessageBuffer** destBufPtr){
DSError error = kNoMessageBufferAvailable;
int i;
*destBufPtr = NULL;

for(int i = 0; i < NUM_BUFFERS; i++){
for(i = 0; i < NUM_BUFFERS; i++){
MessageBuffer* buf = TRKGetBuffer(i);

if(!buf->fInUse){
Expand Down
3 changes: 2 additions & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/msghndlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ DSError TRKDoStep(MessageBuffer *b){
ui8 count;
ui32 rangeStart;
ui32 rangeEnd;
ui32 pc;

TRK_SetBufferPosition(b, 0);

Expand All @@ -454,7 +455,7 @@ DSError TRKDoStep(MessageBuffer *b){
//Range step
case kDSStepIntoRange:
case kDSStepOverRange:
ui32 pc = TRKTargetGetPC();
pc = TRKTargetGetPC();
//Continue if the current pc is within the step range
if(pc >= rangeStart && pc <= rangeEnd){
break;
Expand Down
3 changes: 2 additions & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/mslsupp.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ int convertFileMode(){

DSIOResult __access_file(__file_handle handle, ui8* buffer, size_t* count, __ref_con ref_con, MessageCommandID id){
size_t countTemp;
ui32 r0;

if(!GetTRKConnected()) return kDSIOError;

countTemp = *count;
ui32 r0 = TRKAccessFile(id, handle, &countTemp, buffer);
r0 = TRKAccessFile(id, handle, &countTemp, buffer);
*count = countTemp;

switch((ui8)r0){
Expand Down
2 changes: 1 addition & 1 deletion libs/PowerPC_EABI_Support/src/MetroTRK/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ DSError HandlePositionFileSupportRequest(ui32 param_1, ui32* param_2, ui8 param_
reply.command[0] = kDSPositionFile;
reply.msg_length = TRK_MSG_HEADER_LENGTH;
*(DSFileHandle *)reply.handle = param_1;
*(s32*)reply.length = *param_2;
*(int*)reply.length = *param_2;
reply.data[0] = param_3;
error = TRK_GetFreeBuffer(&bufferId1,&buffer1);

Expand Down
8 changes: 4 additions & 4 deletions libs/PowerPC_EABI_Support/src/MetroTRK/targimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ DSError TRKValidMemory32(const void* addr, size_t length, ValidMemoryOptions rea
DSError err = kInvalidMemory;
const ui8* start;
const ui8* end;
s32 i;
int i;

start = (const ui8*)addr;
end = ((const ui8*)addr + (length - 1));
Expand All @@ -213,7 +213,7 @@ DSError TRKValidMemory32(const void* addr, size_t length, ValidMemoryOptions rea
return kInvalidMemory;
}

for(i = 0; i < (s32)(sizeof(gTRKMemMap)/sizeof(memRange)); i++){
for(i = 0; i < (int)(sizeof(gTRKMemMap)/sizeof(memRange)); i++){
if(start <= (const ui8*)gTRKMemMap[i].end && end >= (const ui8*)gTRKMemMap[i].start){
if((readWriteable == kValidMemoryReadable && !gTRKMemMap[i].readable) || (readWriteable == kValidMemoryWriteable && !gTRKMemMap[i].writeable)){
err = kInvalidMemory;
Expand Down Expand Up @@ -861,7 +861,7 @@ DSError TRKTargetAddStopInfo(MessageBuffer* b){
error = TRKAppendBuffer_ui8(b, (ui8*)&reply, TRK_MSG_HEADER_LENGTH);

if (error == kNoError) {
s32 i;
int i;

for(i = 0; i < 0x20; i++) {
TRKAppendBuffer1_ui32(b, gTRKCPUState.Default.GPR[i]);
Expand Down Expand Up @@ -890,7 +890,7 @@ DSError TRKTargetAddStopInfo(MessageBuffer* b){
}

if (error == kNoError) {
s8 writeData[1024];
char writeData[1024];
size_t length = sizeof(writeData);

error = TRKTargetAccessMemory((void*)writeData, (void*)(gTRKCPUState.Default.PC & 0xfffffc00),&length,kUserMemory,true);
Expand Down
2 changes: 1 addition & 1 deletion src/kyoshin/appgame/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void CGame::GameMain(){
UNKTYPE* temp_r3 = func_80455AA0();
u32 r29 = *(u32*)((u32)temp_r3 + 0x4C);
CDesktop* desktop = CDesktop::getInstance();
const char* name = "‹_"; //"Bionis"
const char* name = "巨神"; //"Bionis"
CGame* cGame = new (WorkThreadSystem::getHeapIndex()) CGame(name, desktop);
cGame->func_80438BD8(desktop, 0);
cGame->unk1E4 = r29;
Expand Down
31 changes: 31 additions & 0 deletions src/kyoshin/appgame/NandData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "kyoshin/appgame/NandData.hpp"

static const char* nandTitleText = "ゼノブレイド";
static const char* nandDescriptionText = "巨神と機神 モナドが未来を斬り開く";
static const char* nandBannerFilename = "bannerTexture.tpl";
static const char* nandIconTextureFilenames[] = {
"iconTexture[0].tpl",
"iconTexture[1].tpl",
"iconTexture[2].tpl",
"iconTexture[3].tpl",
"iconTexture[4].tpl",
"iconTexture[5].tpl",
"iconTexture[6].tpl",
"iconTexture[7].tpl",
nullptr
};
static int nandIconTextureSomething[] = {
2,
2,
2,
2,
2,
2,
2,
2,
0
};

CNBanner nBanner = CNBanner(nandTitleText, nandDescriptionText, nandBannerFilename, nandIconTextureFilenames, nandIconTextureSomething);


4 changes: 4 additions & 0 deletions src/kyoshin/appgame/NandData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#include "types.h"
#include "monolib/CNBanner.hpp"
2 changes: 1 addition & 1 deletion src/kyoshin/appgame/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "kyoshin/appgame/CGame.hpp"
#include "kyoshin/appgame/ErrMesData.hpp"

FunctionStruct lbl_80528380 = {"ƒQ[ƒ€ƒƒCƒ“", &CGame::GameMain};
FunctionStruct lbl_80528380 = {"ゲームメイン", &CGame::GameMain};
const char* const staticArcStr = "static.arc";

const char* const pkhFilenames[13] = {
Expand Down

0 comments on commit 5d2013a

Please sign in to comment.