diff --git a/src/app/core/constants.h b/src/app/core/constants.h index 54eba4c7..df2d8256 100644 --- a/src/app/core/constants.h +++ b/src/app/core/constants.h @@ -26,8 +26,8 @@ #define MENU_ITEM2(w, v) if (ImGui::MenuItem(w, v)) #define CHECK_STATUS(w) \ - if (!w.ok()) { \ - return w; \ + if (!w.ok()) { \ + return w; \ } using ushort = unsigned short; @@ -39,9 +39,16 @@ namespace yaze { namespace app { namespace core { -//=========================================================================================== +// ============================================================================ +// Window Variables +// ============================================================================ + +constexpr int kScreenWidth = 1200; +constexpr int kScreenHeight = 800; + +// ============================================================================ // 65816 LanguageDefinition -//=========================================================================================== +// ============================================================================ static const char *const kKeywords[] = { "ADC", "AND", "ASL", "BCC", "BCS", "BEQ", "BIT", "BMI", "BNE", @@ -66,9 +73,9 @@ static const char *const kIdentifiers[] = { "srand", "strcat", "strcmp", "strerror", "time", "tolower", "toupper"}; -//=========================================================================================== +// ============================================================================ // Magic numbers -//=========================================================================================== +// ============================================================================ /// Bit set for object priority constexpr ushort TilePriorityBit = 0x2000; @@ -96,9 +103,9 @@ constexpr int NumberOfMap32 = Map32PerScreen * kNumOverworldMaps; constexpr int NumberOfOWSprites = 352; constexpr int NumberOfColors = 3143; -// =========================================================================================== -// gfx -// =========================================================================================== +// ============================================================================ +// Game Graphics +// ============================================================================ constexpr int tile_address = 0x1B52; // JP = Same constexpr int tile_address_floor = 0x1B5A; // JP = Same @@ -107,8 +114,9 @@ constexpr int subtype2_tiles = 0x83F0; // JP = Same constexpr int subtype3_tiles = 0x84F0; // JP = Same constexpr int gfx_animated_pointer = 0x10275; // JP 0x10624 //long pointer constexpr int overworldgfxGroups2 = 0x6073; // 0x60B3 -constexpr int gfx_1_pointer = - 0x6790; // 2byte pointer bank 00 pc -> 0x4320 CF80 ; 004F80 + +// 2 byte pointer bank 00 pc -> 0x4320 +constexpr int gfx_1_pointer = 0x6790; // CF80 ; 004F80 constexpr int gfx_2_pointer = 0x6795; // D05F ; 00505F constexpr int gfx_3_pointer = 0x679A; // D13E ; 00513E constexpr int hud_palettes = 0xDD660; @@ -118,9 +126,9 @@ constexpr int kTilesheetWidth = 128; constexpr int kTilesheetHeight = 32; constexpr int kTilesheetDepth = 8; -// =========================================================================================== +// ============================================================================ // Overworld Related Variables -// =========================================================================================== +// ============================================================================ constexpr int compressedAllMap32PointersHigh = 0x1794D; constexpr int compressedAllMap32PointersLow = 0x17B2D; @@ -157,7 +165,6 @@ constexpr int overlayPointersBank = 0x0E; constexpr int overworldTilesType = 0x71459; constexpr int overworldMessages = 0x3F51D; -// TODO: constexpr int overworldMusicBegining = 0x14303; constexpr int overworldMusicZelda = 0x14303 + 0x40; constexpr int overworldMusicMasterSword = 0x14303 + 0x80; @@ -167,10 +174,11 @@ constexpr int overworldMusicDW = 0x14403; constexpr int overworldEntranceAllowedTilesLeft = 0xDB8C1; constexpr int overworldEntranceAllowedTilesRight = 0xDB917; -constexpr int overworldMapSize = 0x12844; // 0x00 = small maps, 0x20 = large - // maps -constexpr int overworldMapSizeHighByte = - 0x12884; // 0x01 = small maps, 0x03 = large maps +// 0x00 = small maps, 0x20 = large maps +constexpr int overworldMapSize = 0x12844; + +// 0x01 = small maps, 0x03 = large maps +constexpr int overworldMapSizeHighByte = 0x12884; // relative to the WORLD + 0x200 per map // large map that are not == parent id = same position as their parent! @@ -184,9 +192,9 @@ constexpr int overworldTransitionPositionX = 0x12944; constexpr int overworldScreenSize = 0x1788D; -//=========================================================================================== +// ============================================================================ // Overworld Exits/Entrances Variables -//=========================================================================================== +// ============================================================================ constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences // 105C2 Ending maps // 105E2 Sprite Group Table for Ending @@ -226,9 +234,10 @@ constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91 constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3 constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94 -//=========================================================================================== +// ============================================================================ // Dungeon Related Variables -//=========================================================================================== +// ============================================================================ + // That could be turned into a pointer : constexpr int dungeons_palettes_groups = 0x75460; // JP 0x67DD0 constexpr int dungeons_main_bg_palette_pointers = 0xDEC4B; // JP Same @@ -275,7 +284,6 @@ constexpr int doorPointers = 0xF83C0; // doors constexpr int door_gfx_up = 0x4D9E; -// constexpr int door_gfx_down = 0x4E06; constexpr int door_gfx_cavexit_down = 0x4E06; constexpr int door_gfx_left = 0x4E66; @@ -293,14 +301,17 @@ constexpr int text_data2 = 0x75F40; constexpr int pointers_dictionaries = 0x74703; constexpr int characters_width = 0x74ADF; -//=========================================================================================== +// ============================================================================ // Dungeon Entrances Related Variables -//=========================================================================================== -constexpr int entrance_room = 0x14813; // 0x14577 //word value for each room +// ============================================================================ + +// 0x14577 word value for each room +constexpr int entrance_room = 0x14813; + // 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR constexpr int entrance_scrolledge = 0x1491D; // 0x14681 -constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 //2bytes each room -constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 //2bytes +constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 2 bytes each room +constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 2 bytes constexpr int entrance_yposition = 0x14F59; // 0x14CBD 2bytes constexpr int entrance_xposition = 0x15063; // 0x14DC7 2bytes constexpr int entrance_camerayposition = 0x1516D; // 0x14ED1 2bytes @@ -311,15 +322,17 @@ constexpr int entrance_blockset = 0x15381; // 0x150E5 1byte constexpr int entrance_floor = 0x15406; // 0x1516A 1byte constexpr int entrance_dungeon = 0x1548B; // 0x151EF 1byte (dungeon id) constexpr int entrance_door = 0x15510; // 0x15274 1byte -// 1 byte, ---b ---a b = bg2, a = need to check -_- + +// 1 byte, ---b ---a b = bg2, a = need to check constexpr int entrance_ladderbg = 0x15595; // 0x152F9 -constexpr int entrance_scrolling = 0x1561A; // 0x1537E //1byte --h- --v- +constexpr int entrance_scrolling = 0x1561A; // 0x1537E 1byte --h- --v- constexpr int entrance_scrollquadrant = 0x1569F; // 0x15403 1byte -constexpr int entrance_exit = 0x15724; // 0x15488 //2byte word +constexpr int entrance_exit = 0x15724; // 0x15488 2byte word constexpr int entrance_music = 0x1582E; // 0x15592 // word value for each room constexpr int startingentrance_room = 0x15B6E; // 0x158D2 + // 8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR constexpr int startingentrance_scrolledge = 0x15B7C; // 0x158E0 constexpr int startingentrance_yscroll = 0x15BB4; // 0x14AA9 //2bytes each room @@ -335,7 +348,7 @@ constexpr int startingentrance_dungeon = 0x15C16; // 0x151EF 1byte (dungeon id) constexpr int startingentrance_door = 0x15C2B; // 0x15274 1byte -// 1 byte, ---b ---a b = bg2, a = need to check -_- +// 1 byte, ---b ---a b = bg2, a = need to check constexpr int startingentrance_ladderbg = 0x15C1D; // 0x152F9 // 1byte --h- --v- constexpr int startingentrance_scrolling = 0x15C24; // 0x1537E @@ -365,24 +378,23 @@ constexpr int dungeons_endrooms = 0x792D; constexpr int dungeons_bossrooms = 0x10954; // short value // Bed Related Values (Starting location) - constexpr int bedPositionX = 0x039A37; // short value constexpr int bedPositionY = 0x039A32; // short value // short value (on 2 different bytes) constexpr int bedPositionResetXLow = 0x02DE53; -constexpr int bedPositionResetXHigh = 0x02DE58; //^^^^^^ +constexpr int bedPositionResetXHigh = 0x02DE58; // short value (on 2 different bytes) constexpr int bedPositionResetYLow = 0x02DE5D; -constexpr int bedPositionResetYHigh = 0x02DE62; //^^^^^^ +constexpr int bedPositionResetYHigh = 0x02DE62; constexpr int bedSheetPositionX = 0x0480BD; // short value constexpr int bedSheetPositionY = 0x0480B8; // short value -//=========================================================================================== +// ============================================================================ // Gravestones related variables -//=========================================================================================== +// ============================================================================ constexpr int GravesYTilePos = 0x49968; // short (0x0F entries) constexpr int GravesXTilePos = 0x49986; // short (0x0F entries) @@ -396,9 +408,9 @@ constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries constexpr int GraveLinkSpecialHole = 0x46DD9; // short constexpr int GraveLinkSpecialStairs = 0x46DE0; // short -//=========================================================================================== +// ============================================================================ // Palettes Related Variables - This contain all the palettes of the game -//=========================================================================================== +// ============================================================================ constexpr int overworldPaletteMain = 0xDE6C8; constexpr int overworldPaletteAuxialiary = 0xDE86C; constexpr int overworldPaletteAnimated = 0xDE604; @@ -420,19 +432,23 @@ constexpr int hardcodedGrassLW = 0x5FEA9; constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F constexpr int hardcodedGrassSpecial = 0x75640; -//=========================================================================================== +// ============================================================================ // Dungeon Map Related Variables -//=========================================================================================== +// ============================================================================ + constexpr int dungeonMap_rooms_ptr = 0x57605; // 14 pointers of map data constexpr int dungeonMap_floors = 0x575D9; // 14 words values constexpr int dungeonMap_gfx_ptr = 0x57BE4; // 14 pointers of gfx data + // data start for floors/gfx MUST skip 575D9 to 57621 (pointers) constexpr int dungeonMap_datastart = 0x57039; + // IF Byte = 0xB9 dungeon maps are not expanded constexpr int dungeonMap_expCheck = 0x56652; constexpr int dungeonMap_tile16 = 0x57009; constexpr int dungeonMap_tile16Exp = 0x109010; + // 14 words values 0x000F = no boss constexpr int dungeonMap_bossrooms = 0x56807; constexpr int triforceVertices = 0x04FFD2; // group of 3, X, Y ,Z @@ -440,9 +456,10 @@ constexpr int TriforceFaces = 0x04FFE4; // group of 5 constexpr int crystalVertices = 0x04FF98; -//=========================================================================================== +// ============================================================================ // Names -//=========================================================================================== +// ============================================================================ + static const absl::string_view RoomEffect[] = {"Nothing", "Nothing", "Moving Floor", diff --git a/src/app/core/controller.cc b/src/app/core/controller.cc index 9994226f..98d43baa 100644 --- a/src/app/core/controller.cc +++ b/src/app/core/controller.cc @@ -154,8 +154,8 @@ absl::Status Controller::CreateWindow() { SDL_CreateWindow("Yet Another Zelda3 Editor", // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position - 1200, // width, in pixels - 800, // height, in pixels + kScreenWidth, // width, in pixels + kScreenHeight, // height, in pixels SDL_WINDOW_RESIZABLE), sdl_deleter()); if (window_ == nullptr) { diff --git a/src/app/rom.cc b/src/app/rom.cc index c53f32c6..0369b4bd 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -576,6 +576,7 @@ absl::Status ROM::LoadFromFile(const absl::string_view& filename) { return absl::InternalError( absl::StrCat("Could not open ROM file: ", filename)); } + size_ = std::filesystem::file_size(filename); rom_data_.resize(size_); for (auto i = 0; i < size_; ++i) { @@ -583,9 +584,12 @@ absl::Status ROM::LoadFromFile(const absl::string_view& filename) { file.read(&byte_to_read, sizeof(char)); rom_data_[i] = byte_to_read; } + + // copy ROM title + memcpy(title, rom_data_.data() + kTitleStringOffset, kTitleStringLength); + file.close(); is_loaded_ = true; - memcpy(title, rom_data_.data() + 32704, 20); // copy ROM title return absl::OkStatus(); } diff --git a/src/app/rom.h b/src/app/rom.h index 3039664f..ab809410 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -36,6 +36,8 @@ constexpr int kMaxLengthCompression = 1024; constexpr int kNintendoMode1 = 0; constexpr int kNintendoMode2 = 1; constexpr int kTile32Num = 4432; +constexpr int kTitleStringOffset = 0x7FC0; +constexpr int kTitleStringLength = 20; constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};