From 7eee97429f0584b25304067aa9cad035cc84aef9 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Wed, 17 Jul 2024 17:35:37 -0400 Subject: [PATCH 01/12] Clean up custom LoadTextureBlock in z_map_mark.c and z_lmap_mark.c (#1896) * experimental inc.c * make it look proper * make table types u32 * ZCONST -> COND_CONST * Tharo suggestion and comment * implement MM Decomp suggestions * fix minor nits * Update header guard --- src/code/gDPLoadTextureBlock_Runtime.inc.c | 68 +++++++++++++++++++ src/code/z_map_mark.c | 24 ++----- .../misc/ovl_kaleido_scope/z_lmap_mark.c | 24 ++----- 3 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 src/code/gDPLoadTextureBlock_Runtime.inc.c diff --git a/src/code/gDPLoadTextureBlock_Runtime.inc.c b/src/code/gDPLoadTextureBlock_Runtime.inc.c new file mode 100644 index 0000000000..55be144510 --- /dev/null +++ b/src/code/gDPLoadTextureBlock_Runtime.inc.c @@ -0,0 +1,68 @@ +#ifndef GDP_LOADTEXTUREBLOCK_RUNTIME_INC_C +#define GDP_LOADTEXTUREBLOCK_RUNTIME_INC_C + +#include "gfx.h" + +#ifndef GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS +#define GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS +#endif + +// The Following arrays must be defined as const in z_lmap_mark.c to appear in rodata + +static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz[] = { + G_IM_SIZ_4b, + G_IM_SIZ_8b, + G_IM_SIZ_16b, + G_IM_SIZ_32b, +}; +static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_LOAD_BLOCK[] = { + G_IM_SIZ_4b_LOAD_BLOCK, + G_IM_SIZ_8b_LOAD_BLOCK, + G_IM_SIZ_16b_LOAD_BLOCK, + G_IM_SIZ_32b_LOAD_BLOCK, +}; +static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_INCR[] = { + G_IM_SIZ_4b_INCR, + G_IM_SIZ_8b_INCR, + G_IM_SIZ_16b_INCR, + G_IM_SIZ_32b_INCR, +}; +static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_SHIFT[] = { + G_IM_SIZ_4b_SHIFT, + G_IM_SIZ_8b_SHIFT, + G_IM_SIZ_16b_SHIFT, + G_IM_SIZ_32b_SHIFT, +}; +static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_BYTES[] = { + G_IM_SIZ_4b_BYTES, + G_IM_SIZ_8b_BYTES, + G_IM_SIZ_16b_BYTES, + G_IM_SIZ_32b_BYTES, +}; +static GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS u32 sLoadTextureBlock_siz_LINE_BYTES[] = { + G_IM_SIZ_4b_LINE_BYTES, + G_IM_SIZ_8b_LINE_BYTES, + G_IM_SIZ_16b_LINE_BYTES, + G_IM_SIZ_32b_LINE_BYTES, +}; + +/** + * Implements a version of gDPLoadTextureBlock using table lookups instead of token pasting, to allow values to be + * passed into `siz` during runtime. + */ +#define gDPLoadTextureBlock_Runtime(pkt, timg, fmt, siz, width, height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + _DW({ \ + gDPSetTextureImage(pkt, fmt, sLoadTextureBlock_siz_LOAD_BLOCK[siz], 1, timg); \ + gDPSetTile(pkt, fmt, sLoadTextureBlock_siz_LOAD_BLOCK[siz], 0, 0, G_TX_LOADTILE, 0, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width) * (height) + sLoadTextureBlock_siz_INCR[siz]) >> sLoadTextureBlock_siz_SHIFT[siz]) - 1, \ + CALC_DXT(width, sLoadTextureBlock_siz_BYTES[siz])); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, sLoadTextureBlock_siz[siz], (((width)*sLoadTextureBlock_siz_LINE_BYTES[siz]) + 7) >> 3, \ + 0, G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC); \ + }) +#endif diff --git a/src/code/z_map_mark.c b/src/code/z_map_mark.c index f6cc28833e..a5e5e5d760 100644 --- a/src/code/z_map_mark.c +++ b/src/code/z_map_mark.c @@ -22,21 +22,10 @@ typedef struct { /* 0x14 */ void* vramTable; } MapMarkDataOverlay; // size = 0x18 -static u32 sBaseImageSizes[] = { 0, 1, 2, 3 }; -static u32 sLoadBlockImageSizes[] = { 2, 2, 2, 3 }; -static u32 sIncrImageSizes[] = { 3, 1, 0, 0 }; -static u32 sShiftImageSizes[] = { 2, 1, 0, 0 }; -static u32 sBytesImageSizes[] = { 0, 1, 2, 4 }; -static u32 sLineBytesImageSizes[] = { 0, 1, 2, 2 }; +#define GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS +#include "src/code/gDPLoadTextureBlock_Runtime.inc.c" -#define G_IM_SIZ_MARK sBaseImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_LOAD_BLOCK sLoadBlockImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_INCR sIncrImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_SHIFT sShiftImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_BYTES sBytesImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_LINE_BYTES sLineBytesImageSizes[markInfo->imageSize] - -static MapMarkInfo sMapMarkInfoTable[] = { +MapMarkInfo sMapMarkInfoTable[] = { { gMapChestIconTex, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 8, 32, 32, 1 << 10, 1 << 10 }, // Chest Icon { gMapBossIconTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 8, 32, 32, 1 << 10, 1 << 10 }, // Boss Skull Icon }; @@ -109,9 +98,10 @@ void MapMark_DrawForDungeon(PlayState* play) { markInfo = &sMapMarkInfoTable[mapMarkIconData->markType]; gDPPipeSync(OVERLAY_DISP++); - gDPLoadTextureBlock(OVERLAY_DISP++, markInfo->texture, markInfo->imageFormat, G_IM_SIZ_MARK, - markInfo->textureWidth, markInfo->textureHeight, 0, G_TX_NOMIRROR | G_TX_WRAP, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock_Runtime(OVERLAY_DISP++, markInfo->texture, markInfo->imageFormat, + markInfo->imageSize, markInfo->textureWidth, markInfo->textureHeight, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); rectLeft = ((OOT_DEBUG ? GREG(94) : 0) + markPoint->x + 204) << 2; rectTop = ((OOT_DEBUG ? GREG(95) : 0) + markPoint->y + 140) << 2; diff --git a/src/overlays/misc/ovl_kaleido_scope/z_lmap_mark.c b/src/overlays/misc/ovl_kaleido_scope/z_lmap_mark.c index 8ed0e6005b..7cb49d8f70 100644 --- a/src/overlays/misc/ovl_kaleido_scope/z_lmap_mark.c +++ b/src/overlays/misc/ovl_kaleido_scope/z_lmap_mark.c @@ -13,25 +13,14 @@ typedef struct { /* 0x20 */ u32 dtdy; } PauseMapMarkInfo; // size = 0x24 +#define GDP_LOADTEXTUREBLOCK_RUNTIME_QUALIFIERS const +#include "src/code/gDPLoadTextureBlock_Runtime.inc.c" + static PauseMapMarkInfo sMapMarkInfoTable[] = { { gMapChestIconTex, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 8, 32, 32, 1 << 10, 1 << 10 }, { gMapBossIconTex, G_IM_FMT_IA, G_IM_SIZ_8b, 8, 8, 32, 32, 1 << 10, 1 << 10 }, }; -static const u32 sBaseImageSizes[] = { 0, 1, 2, 3 }; -static const u32 sLoadBlockImageSizes[] = { 2, 2, 2, 3 }; -static const u32 sIncrImageSizes[] = { 3, 1, 0, 0 }; -static const u32 sShiftImageSizes[] = { 2, 1, 0, 0 }; -static const u32 sBytesImageSizes[] = { 0, 1, 2, 4 }; -static const u32 sLineBytesImageSizes[] = { 0, 1, 2, 2 }; - -#define G_IM_SIZ_MARK sBaseImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_LOAD_BLOCK sLoadBlockImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_INCR sIncrImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_SHIFT sShiftImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_BYTES sBytesImageSizes[markInfo->imageSize] -#define G_IM_SIZ_MARK_LINE_BYTES sLineBytesImageSizes[markInfo->imageSize] - extern PauseMapMarksData gPauseMapMarkDataTable[]; void PauseMapMark_Init(PlayState* play) { @@ -122,9 +111,10 @@ void PauseMapMark_DrawForDungeon(PlayState* play) { markInfo = &sMapMarkInfoTable[mapMarkData->markType]; gDPPipeSync(POLY_OPA_DISP++); - gDPLoadTextureBlock(POLY_OPA_DISP++, markInfo->texture, markInfo->imageFormat, G_IM_SIZ_MARK, - markInfo->textureWidth, markInfo->textureHeight, 0, G_TX_NOMIRROR | G_TX_WRAP, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureBlock_Runtime(POLY_OPA_DISP++, markInfo->texture, markInfo->imageFormat, + markInfo->imageSize, markInfo->textureWidth, markInfo->textureHeight, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); Matrix_Push(); From a6438f05334feb4bb3e7c8ac57ec1d8a7df3df10 Mon Sep 17 00:00:00 2001 From: cadmic Date: Wed, 17 Jul 2024 14:56:00 -0700 Subject: [PATCH 02/12] Handle messages with different box types/positions between JPN/NES (#1984) * Handle messages with different box types/positions between JPN/NES * Remove redundant case * More asserts * Be a bit more Pythonic --- tools/msgdis.py | 81 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/tools/msgdis.py b/tools/msgdis.py index aaa26c9cf8..35006b10ef 100755 --- a/tools/msgdis.py +++ b/tools/msgdis.py @@ -4,10 +4,12 @@ # import argparse, re, struct -from typing import Callable, Dict, List, Optional, Tuple +from typing import Callable, Dict, List, Optional, Tuple, TypeVar import version_config +T = TypeVar("T") + item_ids = { 0x00 : "ITEM_DEKU_STICK", 0x01 : "ITEM_DEKU_NUT", @@ -227,6 +229,15 @@ def read_sfx_ids(): return sfx_ids +def unique_or_none(lst : List[T]) -> Optional[T]: + if not lst: + return None + elem = lst[0] + for e in lst[1:]: + if e != elem: + return None + return elem + class MessageDecoder: def __init__(self, sfx_ids : Dict[int,str], control_end : int, control_codes : Dict[int, Tuple[str, str, Optional[Tuple[Callable[[int], str]]]]], extraction_charmap : Dict[int, str]) -> None: self.sfx_ids : Dict[int,str] = sfx_ids @@ -684,16 +695,20 @@ class MessageTableEntry: box_pos = (info >> 0) & 0xF return MessageTableEntry(text_id, box_type, box_pos, addr) -class MessageEntry: - def __init__(self, message_tables : List[Optional[MessageTableDesc]], text_id : int, box_type : int, box_pos : int) -> None: - self.text_id : int = text_id +class MessageData: + def __init__(self, box_type : int, box_pos : int, decoded_text : str): self.box_type : int = box_type self.box_pos : int = box_pos - self.data : List[Tuple[Optional[MessageDecoder], Optional[bytes]]] = [(None,None) for _ in message_tables] + self.decoded_text : str = decoded_text + +class MessageEntry: + def __init__(self, message_tables : List[Optional[MessageTableDesc]], text_id : int) -> None: + self.text_id : int = text_id + self.data : List[Optional[MessageData]] = [None for _ in message_tables] self.select = tuple(tbl is not None for tbl in message_tables) - def box_type_str(self) -> str: - return { + def define_message(self, defn : str, box_type : int, box_pos : int, data : List[Optional[MessageData]]) -> str: + box_type_str = { 0: "TEXTBOX_TYPE_BLACK", 1: "TEXTBOX_TYPE_WOODEN", 2: "TEXTBOX_TYPE_BLUE", @@ -701,37 +716,48 @@ class MessageEntry: 4: "TEXTBOX_TYPE_NONE_BOTTOM", 5: "TEXTBOX_TYPE_NONE_NO_SHADOW", 0xB: "TEXTBOX_TYPE_CREDITS", - }[self.box_type] - - def box_pos_str(self) -> str: - return { + }[box_type] + box_pos_str = { 0: "TEXTBOX_POS_VARIABLE", 1: "TEXTBOX_POS_TOP", 2: "TEXTBOX_POS_MIDDLE", 3: "TEXTBOX_POS_BOTTOM", - }[self.box_pos] + }[box_pos] + out = f"{defn}(0x{self.text_id:04X}, {box_type_str}, {box_pos_str},\n" + out += "\n,\n".join(f"MSG(\n{d.decoded_text}\n)" if d is not None else "MSG(/* MISSING */)" for d in data) + out += "\n)\n" + return out def decode(self) -> str: - selection = tuple(not (select and data == (None,None)) for select,data in zip(self.select,self.data)) - assert any(sel for sel in selection) + selection = tuple(not (select and data is None) for select,data in zip(self.select,self.data)) + assert any(selection) - defn = "" - if all(sel for sel in selection): - # Valid for all languages - defn = "DEFINE_MESSAGE" + out = "" + if all(selection): + shared_box_type = unique_or_none([data.box_type for data in self.data if data is not None]) + shared_box_pos = unique_or_none([data.box_pos for data in self.data if data is not None]) + if shared_box_type is not None and shared_box_pos is not None: + # Valid for all languages + out += self.define_message("DEFINE_MESSAGE", shared_box_type, shared_box_pos, self.data) + else: + # Some NTSC messages have different box types/positions between JPN and NES, + # so emit both DEFINE_MESSAGE_JPN and DEFINE_MESSAGE_NES + assert self.data[0] is not None + assert self.data[1] is not None + assert self.data[2] is None + assert self.data[3] is None + out += self.define_message("DEFINE_MESSAGE_JPN", self.data[0].box_type, self.data[0].box_pos, [self.data[0], None, None, None]) + out += self.define_message("DEFINE_MESSAGE_NES", self.data[1].box_type, self.data[1].box_pos, [None, self.data[1], None, None]) elif selection == (True,False,True,True): # JPN only - defn = "DEFINE_MESSAGE_JPN" + out += self.define_message("DEFINE_MESSAGE_JPN", self.data[0].box_type, self.data[0].box_pos, self.data) elif selection == (False,True,True,True): # NES only - defn = "DEFINE_MESSAGE_NES" + out += self.define_message("DEFINE_MESSAGE_NES", self.data[1].box_type, self.data[1].box_pos, self.data) else: # Other unimplemented cases assert False - out = f"{defn}(0x{self.text_id:04X}, {self.box_type_str()}, {self.box_pos_str()},\n" - out += "\n,\n".join(f"MSG(\n{decoder.decode(data)}\n)" if decoder is not None else "MSG(/* MISSING */)" for decoder,data in self.data) - out += "\n)\n" return out def collect_messages(message_tables : List[Optional[MessageTableDesc]], version : str, @@ -776,8 +802,9 @@ def collect_messages(message_tables : List[Optional[MessageTableDesc]], version size = next_offset - curr_offset if curr.text_id not in messages: - messages[curr.text_id] = MessageEntry(message_tables, curr.text_id, curr.box_type, curr.box_pos) - messages[curr.text_id].data[lang_num] = (desc.decoder, baserom_seg[curr_offset : curr_offset+size]) + messages[curr.text_id] = MessageEntry(message_tables, curr.text_id) + messages[curr.text_id].data[lang_num] = MessageData( + curr.box_type, curr.box_pos, desc.decoder.decode(baserom_seg[curr_offset : curr_offset+size])) else: # Addresses only @@ -794,7 +821,9 @@ def collect_messages(message_tables : List[Optional[MessageTableDesc]], version size = next_offset - curr_offset # The text id is guaranteed to already exist - messages[text_id].data[lang_num] = (desc.decoder, baserom_seg[curr_offset:curr_offset+size]) + parent_data = messages[text_id].data[desc.parent] + messages[text_id].data[lang_num] = MessageData( + parent_data.box_type, parent_data.box_pos, desc.decoder.decode(baserom_seg[curr_offset:curr_offset+size])) return messages From f0796afb8621e60ea56b44a443b73af6a4d763c1 Mon Sep 17 00:00:00 2001 From: cadmic Date: Wed, 17 Jul 2024 15:13:39 -0700 Subject: [PATCH 03/12] Fix extract_assets.py error message (#1985) --- extract_assets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extract_assets.py b/extract_assets.py index 49a165ca7c..815b1af498 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -53,7 +53,7 @@ def ExtractFile(assetConfig: version_config.AssetConfig, outputPath: Path, outpu if exitValue != 0: globalAbort.set() print("\n") - print("Error when extracting from file " + xmlPath, file=os.sys.stderr) + print(f"Error when extracting from file {xmlPath}", file=os.sys.stderr) print("Aborting...", file=os.sys.stderr) print("\n") From 4fbb48177fcf38d339cab6bc725421e13be7d6bb Mon Sep 17 00:00:00 2001 From: cadmic Date: Wed, 17 Jul 2024 15:36:17 -0700 Subject: [PATCH 04/12] Create FILENAME_ macros for NTSC filename encoding (#1986) * Create FILENAME_ macros for NTSC filename encoding * Add defines/comments for all filename characters * FILENAME_EXCLAMATION_POINT -> FILENAME_EXCLAMATION_MARK to match kanji file * hirigana -> hiragana --- include/z64message.h | 31 +++++++ src/code/z_message.c | 24 +++--- src/code/z_sram.c | 86 +++++++++++-------- src/overlays/actors/ovl_En_Mag/z_en_mag.c | 8 +- .../ovl_file_choose/z_file_choose.c | 5 +- .../ovl_file_choose/z_file_nameset.c | 15 ++-- 6 files changed, 113 insertions(+), 56 deletions(-) diff --git a/include/z64message.h b/include/z64message.h index 9b42e60847..cf942a4c51 100644 --- a/include/z64message.h +++ b/include/z64message.h @@ -23,6 +23,37 @@ typedef enum { // TODO get these properties from the textures themselves #define MESSAGE_TEXTURE_STATIC_TEX_SIZE 0x900 +// Macros for generating characters in the filename encoding (specified by message 0xFFFC +// and loaded by Font_LoadOrderedFont). For example, FILENAME_UPPERCASE('A') will encode +// the character 'A'. +#if OOT_NTSC +#define FILENAME_DIGIT(c) ((c) - '0') +// 0x0A - 0x59: hiragana +// 0x5A - 0xAA: katakana +#define FILENAME_UPPERCASE(c) ((c) - 'A' + 0xAB) +#define FILENAME_LOWERCASE(c) ((c) - 'a' + 0xC5) +#define FILENAME_SPACE 0xDF +// 0xE0: unknown +#define FILENAME_QUESTION_MARK 0xE1 +#define FILENAME_EXCLAMATION_MARK 0xE2 +#define FILENAME_COLON 0xE3 +#define FILENAME_DASH 0xE4 +#define FILENAME_LEFT_PARENTHESES 0xE5 +#define FILENAME_RIGHT_PARENTHESES 0xE6 +#define FILENAME_DAKUTEN 0xE7 +#define FILENAME_HANDAKUTEN 0xE8 +#define FILENAME_COMMA 0xE9 +#define FILENAME_PERIOD 0xEA +#define FILENAME_SLASH 0xEB +#else +#define FILENAME_DIGIT(c) ((c) - '0') +#define FILENAME_UPPERCASE(c) ((c) - 'A' + 0x0A) +#define FILENAME_LOWERCASE(c) ((c) - 'a' + 0x24) +#define FILENAME_SPACE 0x3E +#define FILENAME_DASH 0x3F +#define FILENAME_PERIOD 0x40 +#endif + typedef enum { /* 0x00 */ MSGMODE_NONE, /* 0x01 */ MSGMODE_TEXT_START, diff --git a/src/code/z_message.c b/src/code/z_message.c index e0a98beb54..6e34778711 100644 --- a/src/code/z_message.c +++ b/src/code/z_message.c @@ -1303,7 +1303,7 @@ void Message_Decode(PlayState* play) { // Substitute the player name control character for the file's player name. for (playerNameLen = ARRAY_COUNT(gSaveContext.save.info.playerData.playerName); playerNameLen > 0; playerNameLen--) { - if (gSaveContext.save.info.playerData.playerName[playerNameLen - 1] != 0x3E) { + if (gSaveContext.save.info.playerData.playerName[playerNameLen - 1] != FILENAME_SPACE) { break; } } @@ -1311,21 +1311,21 @@ void Message_Decode(PlayState* play) { PRINTF("\n名前 = "); for (i = 0; i < playerNameLen; i++) { curChar2 = gSaveContext.save.info.playerData.playerName[i]; - if (curChar2 == 0x3E) { + if (curChar2 == FILENAME_SPACE) { curChar2 = ' '; - } else if (curChar2 == 0x40) { + } else if (curChar2 == FILENAME_PERIOD) { curChar2 = '.'; - } else if (curChar2 == 0x3F) { + } else if (curChar2 == FILENAME_DASH) { curChar2 = '-'; - } else if (curChar2 < 0xA) { - curChar2 += 0; + } else if (curChar2 <= FILENAME_DIGIT('9')) { + curChar2 -= FILENAME_DIGIT('0'); curChar2 += '0'; - } else if (curChar2 < 0x24) { - curChar2 += 0; - curChar2 += '7'; - } else if (curChar2 < 0x3E) { - curChar2 += 0; - curChar2 += '='; + } else if (curChar2 <= FILENAME_UPPERCASE('Z')) { + curChar2 -= FILENAME_UPPERCASE('A'); + curChar2 += 'A'; + } else if (curChar2 <= FILENAME_LOWERCASE('z')) { + curChar2 -= FILENAME_LOWERCASE('a'); + curChar2 += 'a'; } if (curChar2 != ' ') { Font_LoadChar(font, curChar2 - ' ', charTexIdx); diff --git a/src/code/z_sram.c b/src/code/z_sram.c index b5da4691c9..fb2a4d1195 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -27,23 +27,32 @@ u16 gSramSlotOffsets[] = { static char sZeldaMagic[] = { '\0', '\0', '\0', '\x98', '\x09', '\x10', '\x21', 'Z', 'E', 'L', 'D', 'A' }; static SavePlayerData sNewSavePlayerData = { - { '\0', '\0', '\0', '\0', '\0', '\0' }, // newf - 0, // deaths - { 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E }, // playerName - 0, // n64ddFlag - 0x30, // healthCapacity - 0x30, // defense - 0, // magicLevel - MAGIC_NORMAL_METER, // magic - 0, // rupees - 0, // swordHealth - 0, // naviTimer - false, // isMagicAcquired - 0, // unk_1F - false, // isDoubleMagicAcquired - false, // isDoubleDefenseAcquired - 0, // bgsFlag - 0, // ocarinaGameRoundNum + { '\0', '\0', '\0', '\0', '\0', '\0' }, // newf + 0, // deaths + { + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + }, // playerName + 0, // n64ddFlag + 0x30, // healthCapacity + 0x30, // defense + 0, // magicLevel + MAGIC_NORMAL_METER, // magic + 0, // rupees + 0, // swordHealth + 0, // naviTimer + false, // isMagicAcquired + 0, // unk_1F + false, // isDoubleMagicAcquired + false, // isDoubleDefenseAcquired + 0, // bgsFlag + 0, // ocarinaGameRoundNum { { ITEM_NONE, ITEM_NONE, ITEM_NONE, ITEM_NONE }, // buttonItems { SLOT_NONE, SLOT_NONE, SLOT_NONE }, // cButtonSlots @@ -155,23 +164,32 @@ void Sram_InitNewSave(void) { } static SavePlayerData sDebugSavePlayerData = { - { 'Z', 'E', 'L', 'D', 'A', 'Z' }, // newf - 0, // deaths - { 0x15, 0x12, 0x17, 0x14, 0x3E, 0x3E, 0x3E, 0x3E }, // playerName ( "LINK" ) - 0, // n64ddFlag - 0xE0, // healthCapacity - 0xE0, // health - 0, // magicLevel - MAGIC_NORMAL_METER, // magic - 150, // rupees - 8, // swordHealth - 0, // naviTimer - true, // isMagicAcquired - 0, // unk_1F - false, // isDoubleMagicAcquired - false, // isDoubleDefenseAcquired - 0, // bgsFlag - 0, // ocarinaGameRoundNum + { 'Z', 'E', 'L', 'D', 'A', 'Z' }, // newf + 0, // deaths + { + FILENAME_UPPERCASE('L'), + FILENAME_UPPERCASE('I'), + FILENAME_UPPERCASE('N'), + FILENAME_UPPERCASE('K'), + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + FILENAME_SPACE, + }, // playerName + 0, // n64ddFlag + 0xE0, // healthCapacity + 0xE0, // health + 0, // magicLevel + MAGIC_NORMAL_METER, // magic + 150, // rupees + 8, // swordHealth + 0, // naviTimer + true, // isMagicAcquired + 0, // unk_1F + false, // isDoubleMagicAcquired + false, // isDoubleDefenseAcquired + 0, // bgsFlag + 0, // ocarinaGameRoundNum { { ITEM_NONE, ITEM_NONE, ITEM_NONE, ITEM_NONE }, // buttonItems { SLOT_NONE, SLOT_NONE, SLOT_NONE }, // cButtonSlots diff --git a/src/overlays/actors/ovl_En_Mag/z_en_mag.c b/src/overlays/actors/ovl_En_Mag/z_en_mag.c index e32b01b4e5..840b056a8a 100644 --- a/src/overlays/actors/ovl_En_Mag/z_en_mag.c +++ b/src/overlays/actors/ovl_En_Mag/z_en_mag.c @@ -409,10 +409,14 @@ void EnMag_DrawInner(Actor* thisx, PlayState* play, Gfx** gfxP) { static s16 textFadeDirection = 0; static s16 textFadeTimer = 0; static u8 noControllerFontIndices[] = { - 0x17, 0x18, 0x0C, 0x18, 0x17, 0x1D, 0x1B, 0x18, 0x15, 0x15, 0x0E, 0x1B, + FILENAME_UPPERCASE('N'), FILENAME_UPPERCASE('O'), FILENAME_UPPERCASE('C'), FILENAME_UPPERCASE('O'), + FILENAME_UPPERCASE('N'), FILENAME_UPPERCASE('T'), FILENAME_UPPERCASE('R'), FILENAME_UPPERCASE('O'), + FILENAME_UPPERCASE('L'), FILENAME_UPPERCASE('L'), FILENAME_UPPERCASE('E'), FILENAME_UPPERCASE('R'), }; static u8 pressStartFontIndices[] = { - 0x19, 0x1B, 0x0E, 0x1C, 0x1C, 0x1C, 0x1D, 0x0A, 0x1B, 0x1D, + FILENAME_UPPERCASE('P'), FILENAME_UPPERCASE('R'), FILENAME_UPPERCASE('E'), FILENAME_UPPERCASE('S'), + FILENAME_UPPERCASE('S'), FILENAME_UPPERCASE('S'), FILENAME_UPPERCASE('T'), FILENAME_UPPERCASE('A'), + FILENAME_UPPERCASE('R'), FILENAME_UPPERCASE('T'), }; static void* effectMaskTextures[] = { gTitleEffectMask00Tex, gTitleEffectMask01Tex, gTitleEffectMask02Tex, diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 9569fc956c..df6118dce8 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -169,7 +169,10 @@ void FileSelect_FinishFadeIn(GameState* thisx) { * Update function for `CM_MAIN_MENU` */ void FileSelect_UpdateMainMenu(GameState* thisx) { - static u8 emptyName[] = { 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E }; + static u8 emptyName[] = { + FILENAME_SPACE, FILENAME_SPACE, FILENAME_SPACE, FILENAME_SPACE, + FILENAME_SPACE, FILENAME_SPACE, FILENAME_SPACE, FILENAME_SPACE, + }; FileSelectState* this = (FileSelectState*)thisx; SramContext* sramCtx = &this->sramCtx; Input* input = &this->state.input[0]; diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_nameset.c b/src/overlays/gamestates/ovl_file_choose/z_file_nameset.c index 3067ea368d..b6f452546b 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_nameset.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_nameset.c @@ -373,12 +373,12 @@ void FileSelect_DrawNameEntry(GameState* thisx) { this->kbdY = 5; this->kbdX = 4; } else if (CHECK_BTN_ALL(input->press.button, BTN_B)) { - if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != 0x3E)) { + if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != FILENAME_SPACE)) { for (i = this->newFileNameCharCount; i < 7; i++) { this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; } - this->fileNames[this->buttonIndex][i] = 0x3E; + this->fileNames[this->buttonIndex][i] = FILENAME_SPACE; Audio_PlaySfxGeneral(NA_SE_SY_FSEL_DECIDE_S, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } else { @@ -392,7 +392,7 @@ void FileSelect_DrawNameEntry(GameState* thisx) { this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; } - this->fileNames[this->buttonIndex][i] = 0x3E; + this->fileNames[this->buttonIndex][i] = FILENAME_SPACE; Audio_PlaySfxGeneral(NA_SE_SY_FSEL_DECIDE_S, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); } @@ -419,12 +419,13 @@ void FileSelect_DrawNameEntry(GameState* thisx) { } } else if (CHECK_BTN_ALL(input->press.button, BTN_A) && (this->charPage != this->kbdButton)) { if (this->kbdButton == FS_KBD_BTN_BACKSPACE) { - if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != 0x3E)) { + if ((this->newFileNameCharCount == 7) && + (this->fileNames[this->buttonIndex][7] != FILENAME_SPACE)) { for (i = this->newFileNameCharCount; i < 7; i++) { this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; } - this->fileNames[this->buttonIndex][i] = 0x3E; + this->fileNames[this->buttonIndex][i] = FILENAME_SPACE; Audio_PlaySfxGeneral(NA_SE_SY_FSEL_DECIDE_S, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); @@ -439,7 +440,7 @@ void FileSelect_DrawNameEntry(GameState* thisx) { this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; } - this->fileNames[this->buttonIndex][i] = 0x3E; + this->fileNames[this->buttonIndex][i] = FILENAME_SPACE; Audio_PlaySfxGeneral(NA_SE_SY_FSEL_DECIDE_S, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale, &gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb); @@ -448,7 +449,7 @@ void FileSelect_DrawNameEntry(GameState* thisx) { validName = false; for (i = 0; i < 8; i++) { - if (this->fileNames[this->buttonIndex][i] != 0x3E) { + if (this->fileNames[this->buttonIndex][i] != FILENAME_SPACE) { validName = true; break; } From c83b93aae40de16779219c357d343415f6ff339a Mon Sep 17 00:00:00 2001 From: cadmic Date: Wed, 17 Jul 2024 15:52:38 -0700 Subject: [PATCH 05/12] Match NTSC z_parameter.c and z_construct.c (#1987) * Match NTSC z_parameter.c and z_construct.c * Comment which REG collide * Use new REGs everywhere * Use new REGs everywhere for real --- assets/xml/textures/icon_item_static.xml | 2 +- assets/xml/textures/icon_item_static_pal.xml | 2 +- assets/xml/textures/parameter_static.xml | 2 +- include/regs.h | 19 +++++++++ src/code/z_construct.c | 43 +++++++++++++++++--- src/code/z_kaleido_setup.c | 4 +- src/code/z_parameter.c | 30 ++++++++++++-- 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/assets/xml/textures/icon_item_static.xml b/assets/xml/textures/icon_item_static.xml index e8b842c74d..ca772fddda 100644 --- a/assets/xml/textures/icon_item_static.xml +++ b/assets/xml/textures/icon_item_static.xml @@ -173,7 +173,7 @@ - + diff --git a/assets/xml/textures/icon_item_static_pal.xml b/assets/xml/textures/icon_item_static_pal.xml index 411f0f2015..474a13f249 100644 --- a/assets/xml/textures/icon_item_static_pal.xml +++ b/assets/xml/textures/icon_item_static_pal.xml @@ -175,7 +175,7 @@ - + diff --git a/assets/xml/textures/parameter_static.xml b/assets/xml/textures/parameter_static.xml index 4cfe67916e..41f110180a 100644 --- a/assets/xml/textures/parameter_static.xml +++ b/assets/xml/textures/parameter_static.xml @@ -29,7 +29,7 @@ - + diff --git a/include/regs.h b/include/regs.h index 4a11f7a557..7878d5aada 100644 --- a/include/regs.h +++ b/include/regs.h @@ -112,9 +112,18 @@ #define R_PAUSE_PAGE_SWITCH_FRAME_ADVANCE_ON ZREG(13) #define R_C_BTN_COLOR(i) ZREG(39 + (i)) #define R_B_BTN_COLOR(i) ZREG(43 + (i)) +#if OOT_NTSC +#define R_START_LABEL_SCALE ZREG(48) +#define R_START_LABEL_DD(i) ZREG(49 + (i)) +#define R_START_LABEL_WIDTH ZREG(51) +#define R_START_LABEL_HEIGHT ZREG(52) +#define R_START_LABEL_Y(i) ZREG(53 + (i)) +#define R_START_LABEL_X(i) ZREG(55 + (i)) +#else #define R_START_LABEL_DD(i) ZREG(48 + (i)) #define R_START_LABEL_Y(i) ZREG(51 + (i)) #define R_START_LABEL_X(i) ZREG(54 + (i)) +#endif #define R_C_UP_BTN_X ZREG(62) #define R_C_UP_BTN_Y ZREG(63) #define R_START_BTN_X ZREG(68) @@ -164,11 +173,21 @@ #define R_ROOM_CULL_USED_ENTRIES iREG(88) #define R_ROOM_CULL_DEBUG_TARGET iREG(89) #define R_B_LABEL_DD WREG(0) +#if OOT_NTSC +#define R_B_LABEL_SCALE(i) WREG(8 + (i)) +#define R_B_LABEL_X(i) WREG(10 + (i)) +#define R_B_LABEL_Y(i) WREG(12 + (i)) +#define R_A_LABEL_Z(i) WREG(14 + (i)) +#endif #define R_OW_MINIMAP_X WREG(29) #define R_OW_MINIMAP_Y WREG(30) #define R_MINIMAP_DISABLED WREG(31) +#if OOT_PAL +#define R_B_LABEL_SCALE(i) WREG(37 + (i)) #define R_B_LABEL_X(i) WREG(40 + (i)) #define R_B_LABEL_Y(i) WREG(43 + (i)) +#define R_A_LABEL_Z(i) WREG(46 + (i)) +#endif #define R_DGN_MINIMAP_X WREG(68) #define R_DGN_MINIMAP_Y WREG(69) #define R_TEXTBOX_X VREG(0) diff --git a/src/code/z_construct.c b/src/code/z_construct.c index 143697e199..ac1291e2d0 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -328,6 +328,17 @@ void Regs_InitDataImpl(void) { R_C_BTN_COLOR(2) = 0; ZREG(46) = 1; ZREG(47) = 1; + +#if OOT_NTSC + R_START_LABEL_DD(0) = 86; + R_START_LABEL_DD(1) = 100; + R_START_LABEL_WIDTH = 0; + R_START_LABEL_HEIGHT = 0; + R_START_LABEL_Y(0) = 21; + R_START_LABEL_Y(1) = 20; + R_START_LABEL_X(0) = 122; + R_START_LABEL_X(1) = 120; +#else R_START_LABEL_DD(0) = 100; R_START_LABEL_DD(1) = 89; R_START_LABEL_DD(2) = 92; @@ -337,6 +348,8 @@ void Regs_InitDataImpl(void) { R_START_LABEL_X(0) = 120; R_START_LABEL_X(1) = 119; R_START_LABEL_X(2) = 119; +#endif + ZREG(61) = 1; R_C_UP_BTN_X = C_UP_BUTTON_X; R_C_UP_BTN_Y = C_UP_BUTTON_Y; @@ -464,6 +477,18 @@ void Regs_InitDataImpl(void) { WREG(5) = 3; WREG(6) = 8; WREG(7) = 0; + +#if OOT_NTSC + R_B_LABEL_SCALE(0) = 100; + R_B_LABEL_SCALE(1) = 109; + R_B_LABEL_X(0) = 151; + R_B_LABEL_X(1) = 148; + R_B_LABEL_Y(0) = 23; + R_B_LABEL_Y(1) = 22; + R_A_LABEL_Z(0) = -380; + R_A_LABEL_Z(1) = -350; +#else + // Same as above, although these regs are now unused in PAL versions WREG(8) = 100; WREG(9) = 109; WREG(10) = 151; @@ -472,6 +497,8 @@ void Regs_InitDataImpl(void) { WREG(13) = 22; WREG(14) = -380; WREG(15) = -350; +#endif + WREG(16) = -175; WREG(17) = 155; WREG(18) = 10; @@ -492,18 +519,20 @@ void Regs_InitDataImpl(void) { WREG(33) = 60; WREG(35) = 0; WREG(36) = 0; - WREG(37) = 100; - WREG(38) = 99; - WREG(39) = 109; + +#if OOT_PAL + R_B_LABEL_SCALE(0) = 100; + R_B_LABEL_SCALE(1) = 99; + R_B_LABEL_SCALE(2) = 109; R_B_LABEL_X(0) = B_BUTTON_X - 9; R_B_LABEL_X(1) = B_BUTTON_X - 11; R_B_LABEL_X(2) = B_BUTTON_X - 12; R_B_LABEL_Y(0) = B_BUTTON_Y + 6; R_B_LABEL_Y(1) = B_BUTTON_Y + 5; R_B_LABEL_Y(2) = B_BUTTON_Y + 5; - WREG(46) = -380; - WREG(47) = -360; - WREG(48) = -350; + R_A_LABEL_Z(0) = -380; + R_A_LABEL_Z(1) = -360; + R_A_LABEL_Z(2) = -350; WREG(49) = -48; WREG(50) = 16; WREG(51) = -62; @@ -522,6 +551,8 @@ void Regs_InitDataImpl(void) { WREG(64) = -37; WREG(65) = 30; WREG(66) = -50; +#endif + R_DGN_MINIMAP_X = 204; R_DGN_MINIMAP_Y = 140; WREG(87) = 80; diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index 36a01c1239..3148d6fb58 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -83,8 +83,8 @@ void KaleidoSetup_Update(PlayState* play) { // mainState is also overwritten later before being used. pauseCtx->mainState = PAUSE_MAIN_STATE_SWITCHING_PAGE; - //! @bug REG collision - if (R_START_LABEL_DD(0) == 0) { + //! @bug REG collision, ZREG(48) is also R_START_LABEL_SCALE for NTSC and R_START_LABEL_DD(0) for PAL + if (ZREG(48) == 0) { // Never reached, unused, and the data would be wrong anyway // (scrolling left from this would not bring to the initial page) pauseCtx->eye.x = sKaleidoSetupUnusedEyeX[pauseCtx->pageIndex]; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 8a32dd2a2b..9dc97ff1fc 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -2097,7 +2097,11 @@ void func_80086D5C(s32* buf, u16 size) { } void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 loadOffset) { +#if OOT_NTSC + static void* sDoActionTextures[] = { gAttackDoActionJPNTex, gCheckDoActionJPNTex }; +#else static void* sDoActionTextures[] = { gAttackDoActionENGTex, gCheckDoActionENGTex }; +#endif if (action >= DO_ACTION_MAX) { action = DO_ACTION_NONE; @@ -2762,15 +2766,17 @@ void Interface_DrawActionLabel(GraphicsContext* gfxCtx, void* texture) { } void Interface_DrawItemButtons(PlayState* play) { - static void* cUpLabelTextures[] = { gNaviCUpENGTex, gNaviCUpENGTex, gNaviCUpENGTex }; + static void* cUpLabelTextures[] = LANGUAGE_ARRAY(gNaviCUpJPNTex, gNaviCUpENGTex, gNaviCUpENGTex, gNaviCUpENGTex); static s16 startButtonLeftPos[] = { 132, 130, 130 }; InterfaceContext* interfaceCtx = &play->interfaceCtx; Player* player = GET_PLAYER(play); PauseContext* pauseCtx = &play->pauseCtx; s16 temp; // Used as both an alpha value and a button index +#if OOT_PAL s16 texCoordScale; s16 width; s16 height; +#endif OPEN_DISPS(play->state.gfxCtx, "../z_parameter.c", 2900); @@ -2811,9 +2817,16 @@ void Interface_DrawItemButtons(PlayState* play) { // Start Button Texture, Color & Label gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 120, 120, 120, interfaceCtx->startAlpha); + +#if OOT_NTSC + gSPTextureRectangle(OVERLAY_DISP++, 132 << 2, 17 << 2, (132 + 22) << 2, 39 << 2, G_TX_RENDERTILE, 0, 0, + (s32)(1.4277344 * (1 << 10)), (s32)(1.4277344 * (1 << 10))); +#else gSPTextureRectangle(OVERLAY_DISP++, startButtonLeftPos[gSaveContext.language] << 2, 17 << 2, (startButtonLeftPos[gSaveContext.language] + 22) << 2, 39 << 2, G_TX_RENDERTILE, 0, 0, (s32)(1.4277344 * (1 << 10)), (s32)(1.4277344 * (1 << 10))); +#endif + gDPPipeSync(OVERLAY_DISP++); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->startAlpha); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 0); @@ -2824,6 +2837,16 @@ void Interface_DrawItemButtons(PlayState* play) { DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); +#if OOT_NTSC + R_START_LABEL_SCALE = (1 << 10) / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); + R_START_LABEL_WIDTH = DO_ACTION_TEX_WIDTH / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); + R_START_LABEL_HEIGHT = DO_ACTION_TEX_HEIGHT / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); + gSPTextureRectangle(OVERLAY_DISP++, R_START_LABEL_X(gSaveContext.language) << 2, + R_START_LABEL_Y(gSaveContext.language) << 2, + (R_START_LABEL_X(gSaveContext.language) + R_START_LABEL_WIDTH) << 2, + (R_START_LABEL_Y(gSaveContext.language) + R_START_LABEL_HEIGHT) << 2, G_TX_RENDERTILE, + 0, 0, R_START_LABEL_SCALE, R_START_LABEL_SCALE); +#else texCoordScale = (1 << 10) / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); width = DO_ACTION_TEX_WIDTH / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); height = DO_ACTION_TEX_HEIGHT / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); @@ -2832,6 +2855,7 @@ void Interface_DrawItemButtons(PlayState* play) { (R_START_LABEL_X(gSaveContext.language) + width) << 2, (R_START_LABEL_Y(gSaveContext.language) + height) << 2, G_TX_RENDERTILE, 0, 0, texCoordScale, texCoordScale); +#endif } } @@ -3285,7 +3309,7 @@ void Interface_Draw(PlayState* play) { DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - R_B_LABEL_DD = (1 << 10) / (WREG(37 + gSaveContext.language) / 100.0f); + R_B_LABEL_DD = (1 << 10) / (R_B_LABEL_SCALE(gSaveContext.language) / 100.0f); gSPTextureRectangle(OVERLAY_DISP++, R_B_LABEL_X(gSaveContext.language) << 2, R_B_LABEL_Y(gSaveContext.language) << 2, (R_B_LABEL_X(gSaveContext.language) + DO_ACTION_TEX_WIDTH) << 2, @@ -3347,7 +3371,7 @@ void Interface_Draw(PlayState* play) { PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->aAlpha); gDPSetEnvColor(OVERLAY_DISP++, 0, 0, 0, 0); - Matrix_Translate(0.0f, 0.0f, WREG(46 + gSaveContext.language) / 10.0f, MTXMODE_NEW); + Matrix_Translate(0.0f, 0.0f, R_A_LABEL_Z(gSaveContext.language) / 10.0f, MTXMODE_NEW); Matrix_Scale(1.0f, 1.0f, 1.0f, MTXMODE_APPLY); Matrix_RotateX(interfaceCtx->unk_1F4 / 10000.0f, MTXMODE_APPLY); gSPMatrix(OVERLAY_DISP++, MATRIX_NEW(play->state.gfxCtx, "../z_parameter.c", 3701), From aaad2e1caf0ce184bbba7a9a5c6bb30054bca3cd Mon Sep 17 00:00:00 2001 From: cadmic Date: Wed, 17 Jul 2024 16:11:24 -0700 Subject: [PATCH 06/12] Match NTSC z_en_mag.c (#1989) --- src/overlays/actors/ovl_En_Mag/z_en_mag.c | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/overlays/actors/ovl_En_Mag/z_en_mag.c b/src/overlays/actors/ovl_En_Mag/z_en_mag.c index 840b056a8a..83ad84d110 100644 --- a/src/overlays/actors/ovl_En_Mag/z_en_mag.c +++ b/src/overlays/actors/ovl_En_Mag/z_en_mag.c @@ -508,6 +508,33 @@ void EnMag_DrawInner(Actor* thisx, PlayState* play, Gfx** gfxP) { #endif } +#if OOT_NTSC + if (gSaveContext.language == LANGUAGE_JPN) { + this->unk_E30C++; + gDPPipeSync(gfx++); + gDPSetCycleType(gfx++, G_CYC_2CYCLE); + if ((s16)this->subAlpha < 100) { + gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_CLD_SURF2); + } else { + gDPSetRenderMode(gfx++, G_RM_PASS, G_RM_XLU_SURF2); + } + gDPSetCombineLERP(gfx++, TEXEL1, PRIMITIVE, PRIM_LOD_FRAC, TEXEL0, 0, 0, 0, TEXEL0, PRIMITIVE, ENVIRONMENT, + COMBINED, ENVIRONMENT, COMBINED, 0, PRIMITIVE, 0); + gDPSetPrimColor(gfx++, 0, 0x80, 255, 255, 170, (s16)this->subAlpha); + gDPSetEnvColor(gfx++, 255, 150, 0, 255); + if ((s16)this->subAlpha != 0) { + gDPLoadTextureBlock(gfx++, gTitleTitleJPNTex, G_IM_FMT_I, G_IM_SIZ_8b, 128, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOLOD); + gDPLoadMultiBlock(gfx++, gTitleFlameEffectTex, 0x100, 1, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, 2, 1); + gDPSetTileSize(gfx++, 1, this->unk_E30C & 0x7F, this->effectScroll & 0x7F, + (this->unk_E30C & 0x7F) + ((32 - 1) << 2), (this->effectScroll & 0x7F) + ((32 - 1) << 2)); + gSPTextureRectangle(gfx++, 424, 576, 424 + 512, 576 + 64, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + } + } +#endif + Gfx_SetupDL_39Ptr(&gfx); gDPSetAlphaCompare(gfx++, G_AC_NONE); @@ -517,9 +544,21 @@ void EnMag_DrawInner(Actor* thisx, PlayState* play, Gfx** gfxP) { (s16)this->copyrightAlpha); if ((s16)this->copyrightAlpha != 0) { +#if OOT_NTSC + if (gSaveContext.language == LANGUAGE_JPN) { + gDPLoadTextureBlock(gfx++, gTitleCopyright19982002Tex, G_IM_FMT_IA, G_IM_SIZ_8b, 160, 16, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + } else { + gDPLoadTextureBlock(gfx++, gTitleCopyright19982003Tex, G_IM_FMT_IA, G_IM_SIZ_8b, 160, 16, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + } +#else gDPLoadTextureBlock(gfx++, gTitleCopyright19982003Tex, G_IM_FMT_IA, G_IM_SIZ_8b, 160, 16, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); +#endif gSPTextureRectangle(gfx++, 78 << 2, 198 << 2, 238 << 2, 214 << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); } From a1c7937dba74f265e0bdc07518784ce82a7fd0d7 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Thu, 18 Jul 2024 01:32:55 +0200 Subject: [PATCH 07/12] make format.py clean up extra whitespace, also in .h files (#1991) * make format.py clean up extra whitespace, also in .h files * fixup * cleanup whitespace msg * Update check_format.py to also check non-src files touched by format.py * format --- format.py | 47 ++++++++++++++++++++++++++++++------------ include/z64actor.h | 48 +++++++++++++++++++++---------------------- tools/check_format.py | 29 ++++++++++++++------------ 3 files changed, 74 insertions(+), 50 deletions(-) diff --git a/format.py b/format.py index 520a2d8078..2e5cbd08f7 100755 --- a/format.py +++ b/format.py @@ -4,6 +4,7 @@ import argparse import glob import multiprocessing import os +from pathlib import Path import re import shutil import subprocess @@ -94,14 +95,25 @@ def run_clang_apply_replacements(tmp_dir: str): subprocess.run(exec_str, shell=True) -def add_final_new_line(file: str): - # https://backreference.org/2010/05/23/sanitizing-files-with-no-trailing-newline/index.html - # "gets the last character of the file pipes it into read, which will exit with a nonzero exit - # code if it encounters EOF before newline (so, if the last character of the file isn't a newline). - # If read exits nonzero, then append a newline onto the file using echo (if read exits 0, - # that satisfies the ||, so the echo command isn't run)." (https://stackoverflow.com/a/34865616) - exec_str = f"tail -c1 {file} | read -r _ || echo >> {file}" - subprocess.run(exec_str, shell=True) +def cleanup_whitespace(file: str): + """ + Remove whitespace at the end of lines, + ensure the file ends with an empty line. + """ + file_p = Path(file) + contents = file_p.read_text(encoding="UTF-8") + modified = False + + contents, n_subst = re.subn(r"[^\S\n]+\n", "\n", contents) + if n_subst != 0: + modified = True + + if not contents.endswith("\n"): + contents += "\n" + modified = True + + if modified: + file_p.write_text(contents, encoding="UTF-8") def format_files(src_files: List[str], extra_files: List[str], nb_jobs: int): @@ -134,14 +146,24 @@ def format_files(src_files: List[str], extra_files: List[str], nb_jobs: int): else: run_clang_tidy(src_files) - print("Adding missing final new lines...") - # Adding final new lines is safe to do in parallel and can be applied to all types of files + print("Cleaning up whitespace...") + # Safe to do in parallel and can be applied to all types of files with multiprocessing.get_context("fork").Pool(nb_jobs) as pool: - pool.map(add_final_new_line, src_files + extra_files) + pool.map(cleanup_whitespace, src_files + extra_files) print("Done formatting files.") +def list_files_to_format(): + files = glob.glob("src/**/*.c", recursive=True) + extra_files = ( + glob.glob("assets/**/*.xml", recursive=True) + + glob.glob("include/**/*.h", recursive=True) + + glob.glob("src/**/*.h", recursive=True) + ) + return files, extra_files + + def main(): parser = argparse.ArgumentParser(description="Format files in the codebase to enforce most style rules") parser.add_argument( @@ -179,8 +201,7 @@ def main(): files = args.files extra_files = [] else: - files = glob.glob("src/**/*.c", recursive=True) - extra_files = glob.glob("assets/**/*.xml", recursive=True) + files, extra_files = list_files_to_format() format_files(files, extra_files, nb_jobs) diff --git a/include/z64actor.h b/include/z64actor.h index 3479b7a917..ef436ff9fd 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -140,22 +140,22 @@ typedef struct { /* 0x18 */ Vec3f feetPos[2]; // Update by using `Actor_SetFeetPos` in PostLimbDraw } ActorShape; // size = 0x30 -// +// #define ACTOR_FLAG_0 (1 << 0) -// +// #define ACTOR_FLAG_2 (1 << 2) -// +// #define ACTOR_FLAG_3 (1 << 3) -// +// #define ACTOR_FLAG_4 (1 << 4) -// +// #define ACTOR_FLAG_5 (1 << 5) -// +// #define ACTOR_FLAG_6 (1 << 6) // hidden or revealed by Lens of Truth (depending on room lensMode) @@ -166,64 +166,64 @@ typedef struct { // Actor will retain this flag until `Actor_TalkOfferAccepted` is called or manually turned off by the actor #define ACTOR_FLAG_TALK (1 << 8) -// +// #define ACTOR_FLAG_9 (1 << 9) -// +// #define ACTOR_FLAG_10 (1 << 10) -// +// #define ACTOR_FLAG_ENKUSA_CUT (1 << 11) // Actor will not shake when a quake occurs #define ACTOR_FLAG_IGNORE_QUAKE (1 << 12) -// +// #define ACTOR_FLAG_13 (1 << 13) -// +// #define ACTOR_FLAG_14 (1 << 14) -// +// #define ACTOR_FLAG_15 (1 << 15) -// +// #define ACTOR_FLAG_16 (1 << 16) -// +// #define ACTOR_FLAG_17 (1 << 17) -// +// #define ACTOR_FLAG_18 (1 << 18) -// +// #define ACTOR_FLAG_19 (1 << 19) -// +// #define ACTOR_FLAG_20 (1 << 20) -// +// #define ACTOR_FLAG_21 (1 << 21) // ignores point lights but not directional lights (such as environment lights) #define ACTOR_FLAG_IGNORE_POINT_LIGHTS (1 << 22) -// +// #define ACTOR_FLAG_23 (1 << 23) -// +// #define ACTOR_FLAG_24 (1 << 24) -// +// #define ACTOR_FLAG_25 (1 << 25) -// +// #define ACTOR_FLAG_26 (1 << 26) -// +// #define ACTOR_FLAG_27 (1 << 27) -// +// #define ACTOR_FLAG_28 (1 << 28) #define COLORFILTER_GET_COLORINTENSITY(colorFilterParams) (((colorFilterParams) & 0x1F00) >> 5) diff --git a/tools/check_format.py b/tools/check_format.py index c2d6d7d2a0..f6b23a2280 100644 --- a/tools/check_format.py +++ b/tools/check_format.py @@ -23,14 +23,15 @@ def get_modified_files_to_format(compare_to): modified_files_str = subprocess.check_output( ["git", "diff", "--name-only", compare_to], text=True ) - modified_files = modified_files_str.splitlines() - modified_c_files = [ - f - for f in modified_files - if f.startswith("src" + os.path.sep) and f.endswith(".c") - ] - modified_c_files_existing = [f for f in modified_c_files if os.path.exists(f)] - return modified_c_files_existing + modified_files = set(modified_files_str.splitlines()) + + all_src_files, all_extra_files = format.list_files_to_format() + # Split modified_files between source files and extra files (see format.py) + # This also filters out deleted files that no logner exist + modified_src_files_existing = list(modified_files.intersection(all_src_files)) + modified_extra_files_existing = list(modified_files.intersection(all_extra_files)) + + return modified_src_files_existing, modified_extra_files_existing def main(): @@ -40,21 +41,23 @@ def main(): args = parser.parse_args() if args.compare_to: - src_files = get_modified_files_to_format(args.compare_to) + src_files, extra_files = get_modified_files_to_format(args.compare_to) if args.verbose: - print("Formatting specific files:", len(src_files), src_files) - if not src_files: + print("Formatting specific files:") + print(len(src_files), src_files) + print(len(extra_files), extra_files) + if not src_files and not extra_files: if args.verbose: print("Nothing to format") exit(0) else: - src_files = glob.glob("src/**/*.c", recursive=True) + src_files, extra_files = format.list_files_to_format() nb_jobs = multiprocessing.cpu_count() git_status_pre = get_git_status() - format.format_files(src_files, [], nb_jobs) + format.format_files(src_files, extra_files, nb_jobs) git_status_post = get_git_status() From 17a88746e78ccbcba139c1fae37926636565a5b3 Mon Sep 17 00:00:00 2001 From: Tharo <17233964+Thar0@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:45:22 +0100 Subject: [PATCH 08/12] Fix a couple of render modes (#1994) --- src/code/PreRender.c | 2 +- src/code/z_vismono.c | 2 +- src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c | 5 +---- src/overlays/actors/ovl_En_Box/z_en_box.c | 9 ++------- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/code/PreRender.c b/src/code/PreRender.c index e960acfec2..527b9c8672 100644 --- a/src/code/PreRender.c +++ b/src/code/PreRender.c @@ -267,7 +267,7 @@ void PreRender_CoverageRgba16ToI8(PreRender* this, Gfx** gfxP, void* img, void* gDPSetOtherMode(gfx++, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, - G_AC_NONE | G_ZS_PRIM | G_RM_PASS | G_RM_OPA_CI2); + G_AC_NONE | G_ZS_PRIM | G_RM_OPA_CI | G_RM_OPA_CI2); // Set the combiner to draw the texture as-is, discarding alpha channel gDPSetCombineLERP(gfx++, 0, 0, 0, TEXEL0, 0, 0, 0, 0, 0, 0, 0, TEXEL0, 0, 0, 0, 0); diff --git a/src/code/z_vismono.c b/src/code/z_vismono.c index a35cdcd105..b0c91de601 100644 --- a/src/code/z_vismono.c +++ b/src/code/z_vismono.c @@ -79,7 +79,7 @@ Gfx* VisMono_DesaturateDList(VisMono* this, Gfx* gfx) { gDPSetOtherMode(gfx++, G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_POINT | G_TT_IA16 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_2CYCLE | G_PM_1PRIMITIVE, - G_AC_NONE | G_ZS_PRIM | GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) | G_RM_CLD_SURF2); + G_AC_NONE | G_ZS_PRIM | G_RM_PASS | G_RM_CLD_SURF2); // First color cycle sums texel 1 alpha and texel 0 color // By using IA16 palettes, this means summing A (from the IA16 color texel 1 maps to) // with I (from the IA16 color texel 0 maps to) diff --git a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c index 4372245150..2f9c32a68f 100644 --- a/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c +++ b/src/overlays/actors/ovl_Boss_Tw/z_boss_tw.c @@ -3294,10 +3294,7 @@ void func_80941BC0(BossTw* this, PlayState* play) { (-this->work[CS_TIMER_2] * 2) & 0x3F, 0, 0x10, 0x10)); gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 195, 225, 235, (s16)this->workf[UNK_F9]); gDPSetEnvColor(POLY_XLU_DISP++, 255, 255, 255, 128); - gDPSetRenderMode(POLY_XLU_DISP++, - Z_CMP | IM_RD | CVG_DST_SAVE | ZMODE_DEC | FORCE_BL | - GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA), - G_RM_ZB_OVL_SURF2); + gDPSetRenderMode(POLY_XLU_DISP++, G_RM_FOG_SHADE_A, G_RM_ZB_OVL_SURF2); gSPSetGeometryMode(POLY_XLU_DISP++, G_CULL_BACK | G_FOG); gSPDisplayList(POLY_XLU_DISP++, SEGMENTED_TO_VIRTUAL(gTwinrovaEffectHaloDL)); Matrix_Pop(); diff --git a/src/overlays/actors/ovl_En_Box/z_en_box.c b/src/overlays/actors/ovl_En_Box/z_en_box.c index 77eba65b88..c8077659e9 100644 --- a/src/overlays/actors/ovl_En_Box/z_en_box.c +++ b/src/overlays/actors/ovl_En_Box/z_en_box.c @@ -588,9 +588,7 @@ Gfx* func_809CA4A0(GraphicsContext* gfxCtx) { ASSERT(dListHead != NULL, "gfxp != NULL", "../z_en_box.c", 1546); dList = dListHead; - gDPSetRenderMode(dListHead++, - AA_EN | Z_CMP | Z_UPD | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | ZMODE_XLU | FORCE_BL | - GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA), + gDPSetRenderMode(dListHead++, G_RM_FOG_SHADE_A, AA_EN | Z_CMP | Z_UPD | IM_RD | CLR_ON_CVG | CVG_DST_WRAP | ZMODE_XLU | FORCE_BL | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA)); gSPEndDisplayList(dListHead++); @@ -606,10 +604,7 @@ Gfx* func_809CA518(GraphicsContext* gfxCtx) { ASSERT(dListHead != NULL, "gfxp != NULL", "../z_en_box.c", 1564); dList = dListHead; - gDPSetRenderMode(dListHead++, - AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | ZMODE_OPA | ALPHA_CVG_SEL | - GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA), - G_RM_AA_ZB_OPA_SURF2); + gDPSetRenderMode(dListHead++, G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2); gSPEndDisplayList(dListHead++); return dList; From c1341224f904631e7b702a4eebebad53cc5d6875 Mon Sep 17 00:00:00 2001 From: Tharo <17233964+Thar0@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:58:59 +0100 Subject: [PATCH 09/12] Promote the warnings implicit-int, int-conversion, incompatible-pointer-types to errors (#1995) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c755a4ad66..47e0960e2a 100644 --- a/Makefile +++ b/Makefile @@ -139,7 +139,7 @@ INC := -Iinclude -Iinclude/libc -Isrc -I$(BUILD_DIR) -I. -I$(EXTRACTED_DIR) # Check code syntax with host compiler CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces -CHECK_WARNINGS += -Werror=implicit-function-declaration +CHECK_WARNINGS += -Werror=implicit-int -Werror=implicit-function-declaration -Werror=int-conversion -Werror=incompatible-pointer-types # The `cpp` command behaves differently on macOS (it behaves as if # `-traditional-cpp` was passed) so we use `gcc -E` instead. From e1dc4cf448ea475691ff0be0e89712fb6be91129 Mon Sep 17 00:00:00 2001 From: inspectredc <78732756+inspectredc@users.noreply.github.com> Date: Fri, 19 Jul 2024 02:56:53 +0100 Subject: [PATCH 10/12] Nicer AudioSeq_SequenceChannelProcessScript match (#1996) * Nicer AudioSeq_SequenceChannelProcessScript match * cadmic suggestion --- src/audio/lib/seqplayer.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/audio/lib/seqplayer.c b/src/audio/lib/seqplayer.c index 620f7a4534..80f35bf2d0 100644 --- a/src/audio/lib/seqplayer.c +++ b/src/audio/lib/seqplayer.c @@ -1475,16 +1475,14 @@ void AudioSeq_SequenceChannelProcessScript(SequenceChannel* channel) { case 0xE7: cmdArgU16 = (u16)cmdArgs[0]; data = &seqPlayer->seqData[cmdArgU16]; - channel->muteBehavior = data[0]; - data += 3; - channel->noteAllocPolicy = data[-2]; - AudioSeq_SetChannelPriorities(channel, data[-1]); - channel->transposition = (s8)data[0]; - data += 4; - channel->newPan = data[-3]; - channel->panChannelWeight = data[-2]; - channel->targetReverbVol = data[-1]; - channel->reverbIndex = data[0]; + channel->muteBehavior = *data++; + channel->noteAllocPolicy = *data++; + AudioSeq_SetChannelPriorities(channel, *data++); + channel->transposition = (s8)*data++; + channel->newPan = *data++; + channel->panChannelWeight = *data++; + channel->targetReverbVol = *data++; + channel->reverbIndex = *data++; //! @bug: Not marking reverb state as changed channel->changes.s.pan = true; break; From 2361a333078b2945a0f6a81025f1726f89ffdd43 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sun, 21 Jul 2024 12:22:54 -0700 Subject: [PATCH 11/12] Small cleanup of cleararena (bootclear) (#1999) * cleararena use boot end * cleararena -> bootclear --- src/boot/boot_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boot/boot_main.c b/src/boot/boot_main.c index b8c08fe8ac..23b8495f8f 100644 --- a/src/boot/boot_main.c +++ b/src/boot/boot_main.c @@ -7,15 +7,15 @@ STACK(sIdleThreadStack, 0x400); StackEntry sIdleThreadInfo; STACK(sBootThreadStack, BOOT_STACK_SIZE); -void cleararena(void) { - bzero(_dmadataSegmentStart, osMemSize - OS_K0_TO_PHYSICAL(_dmadataSegmentStart)); +void bootclear(void) { + bzero(_bootSegmentEnd, osMemSize - OS_K0_TO_PHYSICAL(_bootSegmentEnd)); } void bootproc(void) { StackCheck_Init(&sBootThreadInfo, sBootThreadStack, STACK_TOP(sBootThreadStack), 0, -1, "boot"); osMemSize = osGetMemSize(); - cleararena(); + bootclear(); __osInitialize_common(); __osInitialize_autodetect(); From ab2ca85227bb4ed245d3a39faedc25f793a39a45 Mon Sep 17 00:00:00 2001 From: fig02 Date: Sun, 21 Jul 2024 19:27:25 -0400 Subject: [PATCH 12/12] Rename `ANIM_FLAG_NO_MOVE` to `ANIM_FLAG_ADJUST_STARTING_POS` (#1981) * rename flag and draft 1 of comment * draft 2 * tweak wording * format * format --- include/z64animation.h | 22 ++++++++- src/code/z_skelanime.c | 6 +-- .../actors/ovl_player_actor/z_player.c | 45 ++++++++++--------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/include/z64animation.h b/include/z64animation.h index 2365db14bc..782380ad20 100644 --- a/include/z64animation.h +++ b/include/z64animation.h @@ -112,8 +112,28 @@ typedef enum { // (player-only) Call AnimTaskQueue_AddActorMove #define ANIM_FLAG_PLAYER_SETMOVE (1 << 3) +// When this flag is set, movement in all axes will not be applied for one frame. The flag +// is unset automatically after one use, so movement can resume. The intent is for this flag to be used +// when changing between two different animations. +// In some contexts, disabling the first frame of movement is necessary for a seamless transition. // -#define ANIM_FLAG_NO_MOVE (1 << 4) +// Depending on specific implementations, an actor may choose to reset `prevTransl` to `baseTransl` when +// starting a new animation. This is helpful when an animation's translation data starts at the "origin" +// (in this case, the origin refers to `baseTransl`, in model space). +// Some animations have translation data that does not begin at the "origin". This is common when a +// longer sequence of animation is broken up into different parts as seperate animations. +// In this case, when one animation starts its translation at the same position where a different animation +// left off, resetting `prevTransl` is not desireable. This will cause the actor's position to noticeably change +// when the translation data from the first frame of the new animation is applied. +// +// When this flag is used during a transition between two animations, the first frame of movement is not applied. +// This allows the actor's world postiion to stay at the same location as where the previous animation ended. +// Because translations are calculated as a difference from the current and previous frame, all subsequent +// frames have their translation occur relative to this new starting point. +// +// Note that for Player, this flag is only relevant when transitioning from an animation that was also using +// animation translation. This is because of how `prevTransl` gets reset in `Player_AnimReplaceApplyFlags`. +#define ANIM_FLAG_ADJUST_STARTING_POS (1 << 4) // Disables "normal" movement from sources like speed/velocity and collisions, which allows the // animation to have full control over the actor's movement. diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c index bef23de1ef..c7ea06fd51 100644 --- a/src/code/z_skelanime.c +++ b/src/code/z_skelanime.c @@ -1839,7 +1839,7 @@ void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) { f32 cos; // If `ANIM_FLAG_UPDATE_XZ` behaved as expected, it would also be checked here - if (skelAnime->moveFlags & ANIM_FLAG_NO_MOVE) { + if (skelAnime->moveFlags & ANIM_FLAG_ADJUST_STARTING_POS) { diff->x = diff->z = 0.0f; } else { x = skelAnime->jointTable[0].x; @@ -1866,7 +1866,7 @@ void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) { skelAnime->jointTable[0].z = skelAnime->baseTransl.z; if (skelAnime->moveFlags & ANIM_FLAG_UPDATE_Y) { - if (skelAnime->moveFlags & ANIM_FLAG_NO_MOVE) { + if (skelAnime->moveFlags & ANIM_FLAG_ADJUST_STARTING_POS) { diff->y = 0.0f; } else { diff->y = skelAnime->jointTable[0].y - skelAnime->prevTransl.y; @@ -1879,7 +1879,7 @@ void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) { skelAnime->prevTransl.y = skelAnime->jointTable[0].y; } - skelAnime->moveFlags &= ~ANIM_FLAG_NO_MOVE; + skelAnime->moveFlags &= ~ANIM_FLAG_ADJUST_STARTING_POS; } /** diff --git a/src/overlays/actors/ovl_player_actor/z_player.c b/src/overlays/actors/ovl_player_actor/z_player.c index c397d8ea5f..9ac957cc02 100644 --- a/src/overlays/actors/ovl_player_actor/z_player.c +++ b/src/overlays/actors/ovl_player_actor/z_player.c @@ -2008,7 +2008,7 @@ void Player_AnimReplacePlayOnceAdjusted(PlayState* play, Player* this, LinkAnima void Player_AnimReplaceNormalPlayOnceAdjusted(PlayState* play, Player* this, LinkAnimationHeader* anim) { Player_AnimReplacePlayOnceAdjusted(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE); + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS); } void Player_AnimReplacePlayLoopSetSpeed(PlayState* play, Player* this, LinkAnimationHeader* anim, s32 flags, @@ -2027,7 +2027,7 @@ void Player_AnimReplacePlayLoopAdjusted(PlayState* play, Player* this, LinkAnima void Player_AnimReplaceNormalPlayLoopAdjusted(PlayState* play, Player* this, LinkAnimationHeader* anim) { Player_AnimReplacePlayLoopAdjusted(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE); + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS); } void Player_ProcessControlStick(PlayState* play, Player* this) { @@ -3400,7 +3400,7 @@ s32 Player_UpdateUpperBody(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, &gPlayerAnim_link_hook_fly_start); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); func_80832224(this); this->yaw = this->actor.shape.rot.y; this->actor.bgCheckFlags &= ~BGCHECKFLAG_GROUND; @@ -5368,7 +5368,7 @@ s32 func_8083A6AC(Player* this, PlayState* play) { this->stateFlags1 |= PLAYER_STATE1_21; Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_2 | - ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); this->av2.actionVar2 = -1; @@ -6724,7 +6724,7 @@ s32 Player_ActionChange_3(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, D_80854578[temp].anim); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); this->actor.parent = this->rideActor; func_80832224(this); @@ -7071,7 +7071,7 @@ s32 func_8083EC18(Player* this, PlayState* play, u32 wallFlags) { Player_AnimPlayOnce(play, this, anim); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_2 | - ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); return true; @@ -7153,7 +7153,7 @@ s32 Player_TryEnteringCrawlspace(Player* this, PlayState* play, u32 interactWall Player_AnimPlayOnce(play, this, &gPlayerAnim_link_child_tunnel_start); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); return true; } @@ -7243,7 +7243,7 @@ s32 Player_TryLeavingCrawlspace(Player* this, PlayState* play) { Player_AnimPlayOnce(play, this, &gPlayerAnim_link_child_tunnel_end); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); OnePointCutscene_Init(play, 9601, 999, NULL, CAM_ID_MAIN); } else { // Leaving a crawlspace backwards @@ -7253,7 +7253,7 @@ s32 Player_TryLeavingCrawlspace(Player* this, PlayState* play) { 0.0f); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); OnePointCutscene_Init(play, 9602, 999, NULL, CAM_ID_MAIN); } @@ -9983,7 +9983,7 @@ void func_808468A8(PlayState* play, Player* this) { Player_SetupAction(play, this, Player_Action_8084F9A0, 0); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } void func_808468E8(PlayState* play, Player* this) { @@ -11139,7 +11139,7 @@ void Player_UpdateCommon(Player* this, PlayState* play, Input* input) { Player_AnimPlayOnce(play, this, &gPlayerAnim_link_uma_wait_1); Player_AnimReplaceApplyFlags(play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_UPDATE_Y | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); this->av2.actionVar2 = 99; } @@ -14549,7 +14549,7 @@ void func_808510D4(PlayState* play, Player* this, void* anim) { void func_808510F4(PlayState* play, Player* this, void* anim) { Player_AnimReplacePlayOnce(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } @@ -14559,7 +14559,7 @@ void func_80851114(PlayState* play, Player* this, void* anim) { void func_80851134(PlayState* play, Player* this, void* anim) { Player_AnimReplacePlayLoop(play, this, anim, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } @@ -14918,12 +14918,13 @@ void func_80851E28(PlayState* play, Player* this, CsCmdActorCue* cue) { void func_80851E64(PlayState* play, Player* this, CsCmdActorCue* cue) { Player_AnimReplacePlayOnceAdjusted(play, this, &gPlayerAnim_link_swimer_swim_get, - ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | + ANIM_FLAG_OVERRIDE_MOVEMENT); } void func_80851E90(PlayState* play, Player* this, CsCmdActorCue* cue) { Player_AnimReplacePlayOnce(play, this, &gPlayerAnim_clink_op3_negaeri, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); func_80832698(this, NA_SE_VO_LI_GROAN); } @@ -14931,7 +14932,7 @@ void func_80851E90(PlayState* play, Player* this, CsCmdActorCue* cue) { void func_80851ECC(PlayState* play, Player* this, CsCmdActorCue* cue) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_AnimReplacePlayLoop(play, this, &gPlayerAnim_clink_op3_wait2, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } } @@ -14959,7 +14960,7 @@ static AnimSfxEntry D_808551BC[] = { void func_80851FB0(PlayState* play, Player* this, CsCmdActorCue* cue) { if (LinkAnimation_Update(play, &this->skelAnime)) { Player_AnimReplacePlayLoop(play, this, &gPlayerAnim_clink_op3_wait3, - ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | + ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); this->av2.actionVar2 = 1; } else if (this->av2.actionVar2 == 0) { @@ -14985,7 +14986,7 @@ void func_80852048(PlayState* play, Player* this, CsCmdActorCue* cue) { void func_80852080(PlayState* play, Player* this, CsCmdActorCue* cue) { Player_AnimReplacePlayOnceAdjusted(play, this, &gPlayerAnim_clink_demo_futtobi, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_2 | ANIM_FLAG_PLAYER_SETMOVE | - ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); func_80832698(this, NA_SE_VO_LI_FALL_L); } @@ -15033,8 +15034,8 @@ void func_80852234(PlayState* play, Player* this, CsCmdActorCue* cue) { } void func_8085225C(PlayState* play, Player* this, CsCmdActorCue* cue) { - Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE | ANIM_FLAG_OVERRIDE_MOVEMENT); + Player_AnimReplaceApplyFlags( + play, this, ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS | ANIM_FLAG_OVERRIDE_MOVEMENT); } void func_80852280(PlayState* play, Player* this, CsCmdActorCue* cue) { @@ -15466,8 +15467,8 @@ void func_80853148(PlayState* play, Actor* actor) { } if (this->skelAnime.animation == &gPlayerAnim_link_normal_backspace) { - Player_AnimReplaceApplyFlags(play, this, - ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_NO_MOVE); + Player_AnimReplaceApplyFlags( + play, this, ANIM_FLAG_UPDATE_XZ | ANIM_FLAG_PLAYER_SETMOVE | ANIM_FLAG_ADJUST_STARTING_POS); } func_80832224(this);