Skip to content

Commit e8c324f

Browse files
committed
CodeWarrior version w/ Newer 1.30 changes
1 parent 970325a commit e8c324f

File tree

360 files changed

+6589
-16140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+6589
-16140
lines changed

.gitignore

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
Kamek/Build
2+
Kamek/Build_*
13
Kamek/processed
24
Kamek/AnotherASM
5+
Kamek/SummerASM
36
Kamek/NewerASM
4-
Kamek/kamek_pal.x
7+
Kamek/XmasASM
8+
Kamek/FallingLeafASM
59
Kamek/kamek_pal2.x
610
Kamek/kamek_ntsc.x
711
Kamek/kamek_ntsc2.x
812
Kamek/kamek_jpn.x
913
Kamek/kamek_jpn2.x
14+
Kamek/kamek_kor.x
15+
Kamek/kamek_twn.x
16+
Kamek/kamek_chn.x
17+
Kamek/tools/cw
1018
Kamek/tools/*.pyc
11-
Kamek/*.pyc
12-
Kamek/.DS_Store
19+
*.pyc
20+
Kamek/tools/__pycache__
21+
__pycache__
22+
.DS_Store
23+
Bootstrap/BoostrapOutput
24+
Bootstrap/-v

Bootstrap/NewerBootstrapProject.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
output_dir: "BootstrapOutput"
3+
modules: [bootstrap.yaml]
4+
code_address: 0x80001800
5+

Bootstrap/bootstrap.x

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
OUTPUT_FORMAT ("binary")
2+
3+
MEMORY {
4+
loader_section : ORIGIN = 0x80001800, LENGTH = 0x1800
5+
}
6+
7+
SECTIONS {
8+
_Z12PAL_OSReportPKcz = 0x8015F870;
9+
_Z11PAL_OSFatal7GXColorS_PKc = 0x801AF710;
10+
11+
_Z28PAL_DVDConvertPathToEntrynumPKc = 0x801CA7C0;
12+
_Z15PAL_DVDFastOpeniP9DVDHandle = 0x801CAAD0;
13+
_Z15PAL_DVDReadPrioP9DVDHandlePviii = 0x801CAC60;
14+
_Z12PAL_DVDCloseP9DVDHandle = 0x801CAB40;
15+
16+
_Z20PAL_EGG__Heap__allocmiPv = 0x802B8E00;
17+
_Z19PAL_EGG__Heap__freePvS_ = 0x802B90B0;
18+
19+
20+
_Z13NTSC_OSReportPKcz = 0x8015F730;
21+
_Z12NTSC_OSFatal7GXColorS_PKc = 0x801AF5D0;
22+
23+
_Z29NTSC_DVDConvertPathToEntrynumPKc = 0x801CA680;
24+
_Z16NTSC_DVDFastOpeniP9DVDHandle = 0x801CA990;
25+
_Z16NTSC_DVDReadPrioP9DVDHandlePviii = 0x801CAB20;
26+
_Z13NTSC_DVDCloseP9DVDHandle = 0x801CAA00;
27+
28+
_Z21NTSC_EGG__Heap__allocmiPv = 0x802B8CC0;
29+
_Z20NTSC_EGG__Heap__freePvS_ = 0x802B8F70;
30+
31+
.text : {
32+
FILL (0)
33+
34+
__text_start = . ;
35+
*(.init)
36+
*(.text)
37+
*(.ctors)
38+
*(.dtors)
39+
*(.rodata)
40+
*(.sdata)
41+
*(.sbss)
42+
*(.fini)
43+
*(.rodata.*)
44+
__text_end = . ;
45+
}
46+
}

Bootstrap/bootstrap.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source_files: [redirect.S, mpatcher.S, linker.S]
3+
4+
hooks:
5+
- name: NewerBootstrapNTSC
6+
type: add_func_pointer
7+
src_addr_newerbs: 0x80328130
8+
target_func: 'JumpToBootstrap'
9+
10+
- name: NewerBootstrapPAL
11+
type: add_func_pointer
12+
src_addr_newerbs: 0x80328478
13+
target_func: 'JumpToBootstrap'
14+

Bootstrap/bootstrapNormal.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
struct FileHandle {
2+
void *filePtr;
3+
int length;
4+
};
5+
6+
struct DVDHandle {
7+
int unk1; // 00
8+
int unk2; // 04
9+
int unk3; // 08
10+
int unk4; // 0C
11+
int unk5; // 10
12+
int unk6; // 14
13+
int unk7; // 18
14+
int unk8; // 1C
15+
int unk9; // 20
16+
int unk10; // 24
17+
int unk11; // 28
18+
int unk12; // 2C
19+
int address; // 30
20+
int length; // 34
21+
int unk13; // 38
22+
};
23+
24+
25+
void OSReport(const char *format, ...);
26+
27+
typedef struct { unsigned char r, g, b, a; } GXColor;
28+
void OSFatal(GXColor fg, GXColor bg, const char *msg);
29+
30+
int DVDConvertPathToEntrynum(const char *path);
31+
bool DVDFastOpen(int entrynum, DVDHandle *handle);
32+
int DVDReadPrio(DVDHandle *handle, void *buffer, int length, int offset, int unk);
33+
bool DVDClose(DVDHandle *handle);
34+
35+
void *EGG__Heap__alloc(unsigned long size, int unk, void *heap);
36+
void EGG__Heap__free(void *ptr, void *heap);
37+
38+
void inline *GetArchiveHeap() {
39+
#ifdef REGION_PAL
40+
return *((void**)0x8042A72C);
41+
#endif
42+
#ifdef REGION_NTSC
43+
return *((void**)0x8042A44C);
44+
#endif
45+
}
46+
47+
extern "C" {
48+
void ApplyKamekPatch(void *buf);
49+
}
50+
51+
52+
53+
bool NewerBootstrap() {
54+
GXColor errorfg, errorbg;
55+
errorfg.r = 255;
56+
errorfg.g = 255;
57+
errorfg.b = 255;
58+
errorbg.r = 0;
59+
errorbg.g = 0;
60+
errorbg.b = 0;
61+
62+
OSReport("* Loading sysfile.\n");
63+
64+
int entryNum = DVDConvertPathToEntrynum("/NewerRes/System.bin");
65+
if (entryNum == -1) {
66+
OSFatal(errorfg, errorbg, "FATAL ERROR: Sysfile not found.");
67+
}
68+
69+
DVDHandle dvdhandle;
70+
if (!DVDFastOpen(entryNum, &dvdhandle)) {
71+
OSFatal(errorfg, errorbg, "FATAL ERROR: Cannot open sysfile.");
72+
}
73+
74+
OSReport("* Sysfile opened, %d bytes. Reading...\n", dvdhandle.length);
75+
76+
void *filePtr = EGG__Heap__alloc((dvdhandle.length+0x1F) & ~0x1F, 0x20, GetArchiveHeap());
77+
if (!filePtr) {
78+
OSFatal(errorfg, errorbg, "FATAL ERROR: Failed to allocate memory.");
79+
}
80+
81+
int ret = DVDReadPrio(&dvdhandle, filePtr, (dvdhandle.length+0x1F) & ~0x1F, 0, 2);
82+
83+
OSReport("* Reading complete.\n");
84+
85+
ApplyKamekPatch(filePtr);
86+
87+
OSReport("* Sysfile has been loaded.\n");
88+
89+
EGG__Heap__free(filePtr, GetArchiveHeap());
90+
DVDClose(&dvdhandle);
91+
92+
return true;
93+
}

Bootstrap/hooks.py

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import binascii
2+
import struct
3+
4+
u32 = struct.Struct('>I')
5+
6+
def make_branch_insn(fromAddr, toAddr, branchType):
7+
branchTypes = ['b', 'bl', 'ba', 'bla']
8+
if branchType not in branchTypes:
9+
raise ValueError, 'invalid branch type: %s' % branchType
10+
11+
extra = branchTypes.index(branchType)
12+
13+
distance = toAddr - fromAddr
14+
if distance >= 0x2000000 or distance <= -0x2000000:
15+
raise ValueError, 'branching too far'
16+
17+
return (distance & 0x3FFFFFC) | 0x48000000 | extra
18+
19+
20+
21+
class HookContext(object):
22+
"""Object which can be used by each hook type to hold data."""
23+
24+
def __init__(self):
25+
self.hooks = []
26+
27+
28+
29+
class Hook(object):
30+
"""Generic hook class"""
31+
32+
has_context = False
33+
required_data = []
34+
35+
def __init__(self, builder, module, data):
36+
"""Sets up a hook"""
37+
self.builder = builder
38+
self.module = module
39+
self.data = data
40+
41+
if self.has_context:
42+
hookType = type(self)
43+
self.context = builder._hook_contexts[hookType]
44+
self.context.hooks.append(self)
45+
46+
# validate the hook's data
47+
current_config_name = builder._config_short_name
48+
49+
for field in self.required_data:
50+
field = field.replace('%CONFIG%', current_config_name)
51+
if field not in data:
52+
raise ValueError, 'hook %s : %s is missing the field %s' % (module.moduleName, data['name'], field)
53+
54+
def create_patches(self):
55+
pass
56+
57+
58+
59+
class BasicPatchHook(Hook):
60+
"""Hook that simply patches data to an address"""
61+
62+
required_data = ['addr_%CONFIG%', 'data']
63+
64+
def __init__(self, builder, module, data):
65+
Hook.__init__(self, builder, module, data)
66+
67+
def create_patches(self):
68+
addr = self.data['addr_%s' % self.builder._config_short_name]
69+
70+
hex_data = self.data['data']
71+
72+
whitespace = ' \n\r\t'
73+
for char in whitespace:
74+
hex_data = hex_data.replace(char, '')
75+
76+
patch = binascii.unhexlify(hex_data)
77+
78+
self.builder._add_patch(addr, patch)
79+
80+
81+
82+
class BranchInsnHook(Hook):
83+
"""Hook that replaces the instruction at a specific address with a branch"""
84+
85+
required_data = ['branch_type', 'src_addr_%CONFIG%']
86+
87+
def __init__(self, builder, module, data):
88+
Hook.__init__(self, builder, module, data)
89+
90+
def create_patches(self):
91+
try:
92+
target_func = self.data['target_func']
93+
except KeyError:
94+
target_func = self.data['target_func_%s' % self.builder._config_short_name]
95+
96+
if isinstance(target_func, str):
97+
target_func = self.builder._find_func_by_symbol(target_func)
98+
else:
99+
# assume it's an address
100+
pass
101+
102+
103+
src_addr = self.data['src_addr_%s' % self.builder._config_short_name]
104+
branch_insn = make_branch_insn(src_addr, target_func, self.data['branch_type'])
105+
106+
self.builder._add_patch(src_addr, u32.pack(branch_insn))
107+
108+
109+
110+
class AddFunctionPointerHook(Hook):
111+
"""Hook that places a function pointer at an address"""
112+
113+
required_data = ['src_addr_%CONFIG%']
114+
115+
def __init__(self, builder, module, data):
116+
Hook.__init__(self, builder, module, data)
117+
118+
def create_patches(self):
119+
try:
120+
target_func = self.data['target_func']
121+
except KeyError:
122+
target_func = self.data['target_func_%s' % self.builder._config_short_name]
123+
124+
if isinstance(target_func, str):
125+
target_func = self.builder._find_func_by_symbol(target_func)
126+
else:
127+
# assume it's an address
128+
pass
129+
130+
131+
src_addr = self.data['src_addr_%s' % self.builder._config_short_name]
132+
133+
self.builder._add_patch(src_addr, u32.pack(target_func))
134+
135+
136+
137+
class NopInsnHook(Hook):
138+
"""Hook that NOPs out the instruction(s) at an address"""
139+
140+
required_data = ['area_%CONFIG%']
141+
142+
def __init__(self, builder, module, data):
143+
Hook.__init__(self, builder, module, data)
144+
145+
def create_patches(self):
146+
area = self.data['area_%s' % self.builder._config_short_name]
147+
148+
if isinstance(area, list):
149+
addr, end = area
150+
count = (end + 4 - addr) / 4
151+
nop_patch = '\x60\x00\x00\x00' * count
152+
else:
153+
addr = area
154+
nop_patch = '\x60\x00\x00\x00'
155+
156+
self.builder._add_patch(addr, nop_patch)
157+
158+
159+
160+
HookTypes = {
161+
'patch': BasicPatchHook,
162+
'branch_insn': BranchInsnHook,
163+
'add_func_pointer': AddFunctionPointerHook,
164+
'nop_insn': NopInsnHook,
165+
}
166+

0 commit comments

Comments
 (0)