Make JPN fonts segment shiftable

This commit is contained in:
Ryan Dwyer 2022-11-27 16:52:13 +10:00
parent c790bc5db4
commit 637cc2d823
4 changed files with 77 additions and 54 deletions

View File

@ -255,7 +255,6 @@ O_FILES := \
$(B_DIR)/assets/textureslist.o \
$(B_DIR)/bootloader.o \
$(B_DIR)/firingrange.o \
$(B_DIR)/garbage.o \
$(B_DIR)/getitle.o \
$(B_DIR)/mpconfigs.o \
$(B_DIR)/romheader.o \
@ -271,6 +270,14 @@ ifneq ($(ROMID), ntsc-beta)
O_FILES := $(O_FILES) $(B_DIR)/assets/accessingpakZ.o
endif
ifeq ($(ROMID), jpn-final)
O_FILES := $(O_FILES) $(B_DIR)/assets/fonts/jpn.o
else
O_FILES := $(O_FILES) \
$(B_DIR)/assets/fonts/jpnsingle.o \
$(B_DIR)/assets/fonts/jpnmulti.o
endif
INCLUDES = \
-I include \
-I include/PR \
@ -574,9 +581,6 @@ $(B_DIR)/assets/fonts/%.o: $(A_DIR)/fonts/%.bin
mkdir -p $(B_DIR)/assets/fonts
TOOLCHAIN=$(TOOLCHAIN) ROMID=$(ROMID) tools/mkrawobject $< $@
$(B_DIR)/garbage.o: $(E_DIR)/garbage.bin
TOOLCHAIN=$(TOOLCHAIN) ROMID=$(ROMID) tools/mkrawobject $< $@
$(B_DIR)/getitle.o: $(E_DIR)/getitle.bin
TOOLCHAIN=$(TOOLCHAIN) ROMID=$(ROMID) tools/mkrawobject $< $@

View File

@ -73,20 +73,6 @@ OUTPUT_ARCH (mips)
SECTIONS
{
#if VERSION >= VERSION_JPN_FINAL
_jpndata1 = 0x178c40;
_jpndata2 = 0x18b340;
#elif VERSION >= VERSION_PAL_BETA
_jpndata1 = 0x17fc40;
_jpndata2 = 0x18b340;
#elif VERSION >= VERSION_NTSC_1_0
_jpndata1 = 0x194440;
_jpndata2 = 0x19fb40;
#else
_jpndata1 = 0x148c40;
_jpndata2 = 0x154340;
#endif
osTvType = 0x80000300;
osRomType = 0x80000304;
osRomBase = 0x80000308;
@ -282,19 +268,42 @@ SECTIONS
__rompos = _inflateSegmentRomEnd + ROMALLOCATION_GAME;
/***************************************************************************
* garbage
* jpnfonts
* -------------------------------------------------------------------------
* ROM range: 0x00194b30 - 0x001a15c0
* ROM range: 0x00178c40 - 0x00190c50 (jpn-final)
* RAM range: N/A
* -------------------------------------------------------------------------
* On NTSC, this contains unused JPN fonts. On PAL, not sure what this is.
* On all versions of the game, the start of this segment overlaps with the
* end of the gamezips segment, and the start is overwritten with data from
* gamezips. This isn't a problem because the early character codes are
* non-visual characters and therefore not used. However the SegmentRomStart
* linker variable points at the original start. To avoid issues with
* overlapping segments, the segment we extracted from the base ROM is just
* the non-overlapping part, which means we have to subtract an amount to
* get the SegmentRomStart value.
*
* Note that all versions of the game have this segment. There is basic
* support for Japanese characters even in the NTSC beta version.
*
* In most versions the fonts are split into two font segments: single-byte
* and multi-byte. jpn-final combines them into one segment.
*/
BEGIN_SEG(garbage)
{
build/ROMID/garbage.o (.data);
}
END_SEG(garbage)
#if VERSION == VERSION_JPN_FINAL
FONT(jpn)
#else
FONT(jpnsingle)
FONT(jpnmulti)
#endif
/* Subtract based on how much overlap there is */
#if VERSION == VERSION_JPN_FINAL
_fontjpnSegmentRomStart = _fontjpnSegmentRomStart - 0x6f0;
#elif VERSION >= VERSION_PAL_BETA
_fontjpnsingleSegmentRomStart = _fontjpnsingleSegmentRomStart - 0x6f0;
#elif VERSION >= VERSION_NTSC_1_0
_fontjpnsingleSegmentRomStart = _fontjpnsingleSegmentRomStart - 0x6e0;
#endif
/***************************************************************************
* animations

View File

@ -212,8 +212,9 @@ u32 langGetLangBankIndexFromStagenum(s32 stagenum)
return bank;
}
extern u8 _jpndata1;
extern u8 _jpndata2;
extern u8 _fontjpnSegmentRomStart;
extern u8 _fontjpnsingleSegmentRomStart;
extern u8 _fontjpnmultiSegmentRomStart;
struct jpncharpixels *langGetJpnCharPixels(s32 codepoint)
{
@ -287,7 +288,7 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint)
g_JpnCacheCacheItems[freeindexsingle].codepoint = codepoint;
dmaExec((u8 *) (freeindexsingle * (TMUL * 0x0c) + (u32)&g_JpnCharCachePixels[0]),
(u32) &_jpndata1 + ((codepoint * TMUL) * 0xc + TMUL * (24 * 0xc)),
(u32) &_fontjpnSegmentRomStart + ((codepoint * TMUL) * 0xc + TMUL * (24 * 0xc)),
TMUL * 0x0c);
return &g_JpnCharCachePixels[TMUL * freeindexsingle];
@ -308,7 +309,7 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint)
g_JpnCacheCacheItems[freeindexsingle].ttl = 2;
g_JpnCacheCacheItems[freeindexsingle].codepoint = codepoint >> 1;
dmaExec(&g_JpnCharCachePixels[freeindexsingle * 8], (u32)&_jpndata1 + (codepoint >> SHIFTAMOUNT) * 0x60, 0x60);
dmaExec(&g_JpnCharCachePixels[freeindexsingle * 8], (u32)&_fontjpnsingleSegmentRomStart + (codepoint >> SHIFTAMOUNT) * 0x60, 0x60);
return &g_JpnCharCachePixels[freeindexsingle * 8];
}
@ -319,7 +320,7 @@ struct jpncharpixels *langGetJpnCharPixels(s32 codepoint)
g_JpnCacheCacheItems[freeindexmulti + 0].codepoint = codepoint >> 1;
g_JpnCacheCacheItems[freeindexmulti + 1].codepoint = codepoint >> 1;
dmaExec(&g_JpnCharCachePixels[freeindexmulti * 8], (u32)&_jpndata2 + ((codepoint & 0x1fff) >> SHIFTAMOUNT) * 0x80, 0x80);
dmaExec(&g_JpnCharCachePixels[freeindexmulti * 8], (u32)&_fontjpnmultiSegmentRomStart + ((codepoint & 0x1fff) >> SHIFTAMOUNT) * 0x80, 0x80);
return &g_JpnCharCachePixels[freeindexmulti * 8];
}

View File

@ -26,8 +26,8 @@ class Extractor:
self.extract_firingrange()
self.extract_fonts()
self.extract_game()
self.extract_garbage()
self.extract_getitle()
self.extract_jpnfonts()
self.extract_lib()
self.extract_mpconfigs()
self.extract_mpstrings()
@ -236,6 +236,13 @@ class Extractor:
self.extract_font('font8', 'font9', 'ocramd')
self.extract_font('font9', 'sfxctl', 'ocralg')
def extract_jpnfonts(self):
if self.romid == 'jpn-final':
self.extract_font('jpnfontcombined', 'animations', 'jpn')
else:
self.extract_font('jpnfontsingle', 'jpnfontmulti', 'jpnsingle')
self.extract_font('jpnfontmulti', 'animations', 'jpnmulti')
def extract_bootloader(self):
self.write_extracted('bootloader.bin', self.rom[0x40:0x1000])
@ -451,28 +458,30 @@ class Extractor:
]
vals = {
# ntsc-beta ntsc-1.0 ntsc-final pal-beta pal-final jpn-final
'files': [0x29160, 0x28080, 0x28080, 0x29b90, 0x28910, 0x28800, ],
'data': [0x30850, 0x39850, 0x39850, 0x39850, 0x39850, 0x39850, ],
'game': [0x43c40, 0x4fc40, 0x4fc40, 0x4fc40, 0x4fc40, 0x4fc40, ],
'garbage': [0x148c40, 0x194b20, 0x194b20, 0x180330, 0x180330, 0x179330, ],
'animations': [0x155dc0, 0x1a15c0, 0x1a15c0, 0x18cdc0, 0x18cdc0, 0x190c50, ],
'mpconfigs': [0x785130, 0x7d0a40, 0x7d0a40, 0x7bc240, 0x7bc240, 0x7c00d0, ],
'firingrange': [0x79e410, 0x7e9d20, 0x7e9d20, 0x7d5520, 0x7d5520, 0x7d93b0, ],
'textureconfig': [0x79f960, 0x7eb270, 0x7eb270, 0x7d6a70, 0x7d6a70, 0x7da900, ],
'font0': [0x7a6a80, 0x7f2390, 0x7f2390, 0x7ddb90, 0x7ddb90, 0x7e1a20, ],
'font1': [0x7a9020, 0x7f4930, 0x7f4930, 0x7e0130, 0x7e0130, 0x7e3fc0, ],
'font2': [0x7abf50, 0x7f7860, 0x7f7860, 0x7e3060, 0x7e3060, 0x7e6ef0, ],
'font3': [0x7ad210, 0x7f8b20, 0x7f8b20, 0x7e4320, 0x7e4320, 0x7e81b0, ],
'font4': [0x7ae420, 0x7f9d30, 0x7f9d30, 0x7e5530, 0x7e5530, 0x7e93c0, ],
'font5': [0x7b06a0, 0x7fbfb0, 0x7fbfb0, 0x7e87b0, 0x7e87b0, 0x7ec640, ],
'font6': [0x7b2470, 0x7fdd80, 0x7fdd80, 0x7eae20, 0x7eae20, 0x7eecb0, ],
'font7': [0x7b4fd0, 0x8008e0, 0x8008e0, 0x7eee70, 0x7eee70, 0x7f2d00, ],
'font8': [0x7b8490, 0x803da0, 0x803da0, 0x7f2330, 0x7f2330, 0x7f61c0, ],
'font9': [0x7bb1b0, 0x806ac0, 0x806ac0, 0x7f5050, 0x7f5050, 0x7f8ee0, ],
'sfxctl': [0x7be940, 0x80a250, 0x80a250, 0x7f87e0, 0x7f87e0, 0x7fc670, ],
'textures': [0x1d12fe0, 0x1d65f40, 0x1d65f40, 0x1d5bb50, 0x1d5ca20, 0x1d61f90, ],
'copyright': [0x1fabac0, 0x1ffea20, 0x1ffea20, 0x1ff4630, 0x1ff5500, 0x1ffd6b0, ],
# ntsc-beta ntsc-1.0 ntsc-final pal-beta pal-final jpn-final
'files': [0x29160, 0x28080, 0x28080, 0x29b90, 0x28910, 0x28800, ],
'data': [0x30850, 0x39850, 0x39850, 0x39850, 0x39850, 0x39850, ],
'game': [0x43c40, 0x4fc40, 0x4fc40, 0x4fc40, 0x4fc40, 0x4fc40, ],
'jpnfontsingle': [0x148c40, 0x194b20, 0x194b20, 0x180330, 0x180330, 0, ],
'jpnfontmulti': [0x154340, 0x19fb40, 0x19fb40, 0x18b340, 0x18b340, 0, ],
'jpnfontcombined': [0, 0, 0, 0, 0, 0x179330, ],
'animations': [0x155dc0, 0x1a15c0, 0x1a15c0, 0x18cdc0, 0x18cdc0, 0x190c50, ],
'mpconfigs': [0x785130, 0x7d0a40, 0x7d0a40, 0x7bc240, 0x7bc240, 0x7c00d0, ],
'firingrange': [0x79e410, 0x7e9d20, 0x7e9d20, 0x7d5520, 0x7d5520, 0x7d93b0, ],
'textureconfig': [0x79f960, 0x7eb270, 0x7eb270, 0x7d6a70, 0x7d6a70, 0x7da900, ],
'font0': [0x7a6a80, 0x7f2390, 0x7f2390, 0x7ddb90, 0x7ddb90, 0x7e1a20, ],
'font1': [0x7a9020, 0x7f4930, 0x7f4930, 0x7e0130, 0x7e0130, 0x7e3fc0, ],
'font2': [0x7abf50, 0x7f7860, 0x7f7860, 0x7e3060, 0x7e3060, 0x7e6ef0, ],
'font3': [0x7ad210, 0x7f8b20, 0x7f8b20, 0x7e4320, 0x7e4320, 0x7e81b0, ],
'font4': [0x7ae420, 0x7f9d30, 0x7f9d30, 0x7e5530, 0x7e5530, 0x7e93c0, ],
'font5': [0x7b06a0, 0x7fbfb0, 0x7fbfb0, 0x7e87b0, 0x7e87b0, 0x7ec640, ],
'font6': [0x7b2470, 0x7fdd80, 0x7fdd80, 0x7eae20, 0x7eae20, 0x7eecb0, ],
'font7': [0x7b4fd0, 0x8008e0, 0x8008e0, 0x7eee70, 0x7eee70, 0x7f2d00, ],
'font8': [0x7b8490, 0x803da0, 0x803da0, 0x7f2330, 0x7f2330, 0x7f61c0, ],
'font9': [0x7bb1b0, 0x806ac0, 0x806ac0, 0x7f5050, 0x7f5050, 0x7f8ee0, ],
'sfxctl': [0x7be940, 0x80a250, 0x80a250, 0x7f87e0, 0x7f87e0, 0x7fc670, ],
'textures': [0x1d12fe0, 0x1d65f40, 0x1d65f40, 0x1d5bb50, 0x1d5ca20, 0x1d61f90, ],
'copyright': [0x1fabac0, 0x1ffea20, 0x1ffea20, 0x1ff4630, 0x1ff5500, 0x1ffd6b0, ],
}
extractor = Extractor()