Skip to content

Commit

Permalink
More JKernel stealing & matching
Browse files Browse the repository at this point in the history
Stole JKRDisposer, JKRFileLoader and JKRThread from AC, fixed them to
match 100%. Also did some light matching in JKRHeap, it's better now.
Next, had to change OSThread a little bit because the header was weird.
Some symbols not present in sms were removed along the way because why
have them when we cannot verify that they match via this particular
game. Finally, added progress categories to a couple of libs.
  • Loading branch information
Mrkol committed Dec 23, 2024
1 parent 7146216 commit f14dbe2
Show file tree
Hide file tree
Showing 14 changed files with 1,129 additions and 1,064 deletions.
10 changes: 10 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
"-fp fmadd",
"-char signed",
"-rostr",
"-common on"
]

cflags_game = [
Expand Down Expand Up @@ -283,6 +284,7 @@ def MatchingFor(*versions):
"lib": "main",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"progress_category": "game",
"objects": [
Object(Matching, "main.cpp"),
],
Expand All @@ -291,6 +293,7 @@ def MatchingFor(*versions):
"lib": "JSystem",
"mw_version": "GC/1.2.5",
"cflags": cflags_jsystem,
"progress_category": "jsystem",
"objects": [
Object(Matching, "JSystem/J3DClusterLoader.cpp"),
Object(Matching, "JSystem/JASProbe.cpp"),
Expand All @@ -302,13 +305,17 @@ def MatchingFor(*versions):
Object(Matching, "JSystem/J3DVertex.cpp"),
Object(Matching, "JSystem/J3DPacket.cpp"),
# Object(Matching, "JSystem/J3DShape.cpp"),
Object(Matching, "JSystem/JKRDisposer.cpp"),
Object(Matching, "JSystem/JKRHeap.cpp"),
Object(Matching, "JSystem/JKRFileLoader.cpp"),
Object(Matching, "JSystem/JKRThread.cpp"),
],
},
{
"lib": "MarioUtil",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"progress_category": "game",
"objects": [
Object(Matching, "MarioUtil/MapUtil.cpp"),
Object(Matching, "MarioUtil/RumbleType.cpp"),
Expand All @@ -322,6 +329,7 @@ def MatchingFor(*versions):
"lib": "Player",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"progress_category": "game",
"objects": [
Object(Matching, "Player/MarioAccess.cpp"),
],
Expand All @@ -330,6 +338,7 @@ def MatchingFor(*versions):
"lib": "NPC",
"mw_version": "GC/1.2.5",
"cflags": cflags_game,
"progress_category": "game",
"objects": [
Object(Matching, "NPC/NpcBalloon.cpp"),
Object(Matching, "NPC/NpcInitActionData.cpp"),
Expand Down Expand Up @@ -515,6 +524,7 @@ def MatchingFor(*versions):
# Adjust as desired for your project
config.progress_categories = [
ProgressCategory("game", "Game Code"),
ProgressCategory("jsystem", "JSystem Middleware"),
ProgressCategory("sdk", "SDK Code"),
]
config.progress_each_module = args.verbose
Expand Down
17 changes: 17 additions & 0 deletions include/JSystem/JKernel/JKREnum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef JKR_ENUM_H
#define JKR_ENUM_H


#define JKRCOMPRESSION_NONE 0
#define JKRCOMPRESSION_YAY0 1
#define JKRCOMPRESSION_YAZ0 2
#define JKRCOMPRESSION_ASR 3

enum JKRExpandSwitch
{
EXPAND_SWITCH_DEFAULT, /* Do nothing? treated same as 2 */
EXPAND_SWITCH_DECOMPRESS, /* Check for compression and decompress */
EXPAND_SWITCH_NONE /* Do nothing */
};

#endif
73 changes: 68 additions & 5 deletions include/JSystem/JKernel/JKRFileLoader.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,73 @@
#ifndef JKR_FILE_LOADER_HPP
#define JKR_FILE_LOADER_HPP
#ifndef JKR_FILELOADER_HPP
#define JKR_FILELOADER_HPP

#include <JSystem/J3D/J3DModelLoader.hpp>
#include "JSystem/JKernel/JKREnum.hpp"
#include "JSystem/JKernel/JKRDisposer.hpp"
#include "JSystem/JSupport/JSUList.hpp"

struct JKRFileLoader {
static J3DModelLoaderDataBase* getGlbResource(const char*);
class JKRFileFinder;

class JKRFileLoader : public JKRDisposer {
public:
JKRFileLoader();

virtual ~JKRFileLoader(); // _08
virtual void unmount(); // _0C
static JKRFileLoader* getVolume(const char*);
virtual bool becomeCurrent(const char*) = 0; // _10
virtual void* getResource(const char* path) = 0; // _14
virtual void* getResource(u32 type, const char* name) = 0; // _18
virtual size_t readResource(void* resourceBuffer, u32 bufferSize,
const char* path, JKRExpandSwitch expandSwitch)
= 0; // _1C
virtual size_t readResource(void* resourceBuffer, u32 bufferSize, u32 type,
const char* name)
= 0; // _20
virtual void removeResourceAll() = 0; // _24
virtual bool removeResource(void*) = 0; // _28
virtual bool detachResource(void*) = 0; // _2C
virtual long getResSize(const void*) const = 0; // _30
virtual u32 countFile(const char*) const = 0; // _34
virtual JKRFileFinder* getFirstFile(const char*) const = 0; // _38

bool isMounted() const { return mIsMounted; }
u32 getVolumeType() const { return mVolumeType; }

static void changeDirectory(const char* dir);

static void* getGlbResource(const char*);
static void* getGlbResource(const char*, JKRFileLoader* fileLoader);
static long getResSize(void* resourceBuffer, JKRFileLoader* fileLoader);
static size_t readGlbResource(void* resourceBuffer, u32 bufferSize,
const char* path,
JKRExpandSwitch expandSwitch);

static bool removeResource(void* resourceBuffer, JKRFileLoader* fileLoader);
static bool detachResource(void* resourceBuffer, JKRFileLoader* fileLoader);

static JKRFileLoader* findVolume(const char**);
static JKRFileFinder* findFirstFile(const char*);
static const char* fetchVolumeName(char*, long, const char*);

static JKRFileLoader* getCurrentVolume() { return sCurrentVolume; }
static void setCurrentVolume(JKRFileLoader* fileLoader)
{
sCurrentVolume = fileLoader;
}
static JSUList<JKRFileLoader>& getVolumeList() { return sVolumeList; }

static JKRFileLoader* sCurrentVolume;
static JSUList<JKRFileLoader> sVolumeList;

protected:
/* 0x00 */ // vtable
/* 0x04 */ // JKRDisposer
JSULink<JKRFileLoader> mFileLoaderLink; // 0x18
const char* mVolumeName; // 0x28
u32 mVolumeType; // 0x2C
bool mIsMounted; // 0x30
u8 field_0x31[3]; // 0x31
u32 mMountCount; // 0x34
};

#endif
19 changes: 15 additions & 4 deletions include/JSystem/JKernel/JKRHeap.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#ifndef JKRHEAP_H
#define JKRHEAP_H
#ifndef JKR_HEAP_H
#define JKR_HEAP_H

#include <types.h>
#include <dolphin/os/OSMutex.h>
#include <JSystem/JKernel/JKRDisposer.hpp>

#ifdef __cplusplus
typedef void JKRHeapErrorHandler(void*, u32, int);

class JKRHeap : public JKRDisposer {
Expand Down Expand Up @@ -121,6 +120,19 @@ class JKRHeap : public JKRDisposer {
void resize(void*, u32);
static s32 getSize(void*, JKRHeap*);

// TODO: pure speculation but helped JKRThread to match
template <class T> static inline T* allocOne(int align, JKRHeap* heap)
{
return (T*)alloc(sizeof(T), align, heap);
}

// TODO: pure speculation but helped JKRThread to match
template <class T>
static inline T* allocArray(size_t cnt, int align, JKRHeap* heap)
{
return (T*)alloc(cnt * sizeof(T), align, heap);
}

// ... more functions

s32 getSize(void* ptr);
Expand Down Expand Up @@ -277,4 +289,3 @@ void operator delete(void*);
void operator delete[](void*);

#endif
#endif
13 changes: 13 additions & 0 deletions include/JSystem/JKernel/JKRMacro.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef JKR_MACRO_HPP
#define JKR_MACRO_HPP

#define JKR_ISALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment)-1)) == 0)
#define JKR_ISALIGNED32(addr) (JKR_ISALIGNED(addr, 32))

#define JKR_ISNOTALIGNED(addr, alignment) ((((u32)addr) & (((u32)alignment)-1)) != 0)
#define JKR_ISNOTALIGNED32(addr) (JKR_ISNOTALIGNED(addr, 32))

#define JKR_ALIGN(addr, alignment) (((u32)addr) & (~(((u32)alignment)-1)))
#define JKR_ALIGN32(addr) (JKR_ALIGN(addr, 32))

#endif
Loading

0 comments on commit f14dbe2

Please sign in to comment.