Refactoring the codebase and moving closer to decompression

This commit is contained in:
Justin Scofield
2022-06-12 18:20:32 -04:00
parent e154b53fc2
commit b325669ca8
18 changed files with 494 additions and 664 deletions

View File

@@ -4,11 +4,19 @@
#include <array> #include <array>
#include <string> #include <string>
#define TAB_BAR(w) if (ImGui::BeginTabBar(w)) { #define BASIC_BUTTON(w) if (ImGui::Button(w))
#define END_TAB_BAR() ImGui::EndTabBar(); }
#define MENU_BAR() if (ImGui::BeginMenuBar()) { #define TAB_BAR(w) if (ImGui::BeginTabBar(w)) {
#define END_MENU_BAR() ImGui::EndMenuBar(); } #define END_TAB_BAR() \
ImGui::EndTabBar(); \
}
#define MENU_BAR() if (ImGui::BeginMenuBar()) {
#define END_MENU_BAR() \
ImGui::EndMenuBar(); \
}
using byte = unsigned char;
namespace yaze { namespace yaze {
namespace Application { namespace Application {
@@ -20,24 +28,17 @@ using ushort = unsigned short;
//=========================================================================================== //===========================================================================================
// Magic numbers // Magic numbers
//=========================================================================================== //===========================================================================================
/// <summary>
/// Bit set for object priority /// Bit set for object priority
/// </summary>
constexpr ushort TilePriorityBit = 0x2000; constexpr ushort TilePriorityBit = 0x2000;
/// <summary>
/// Bit set for object hflip /// Bit set for object hflip
/// </summary>
constexpr ushort TileHFlipBit = 0x4000; constexpr ushort TileHFlipBit = 0x4000;
/// <summary>
/// Bit set for object vflip /// Bit set for object vflip
/// </summary>
constexpr ushort TileVFlipBit = 0x8000; constexpr ushort TileVFlipBit = 0x8000;
/// <summary>
/// Bits used for tile name /// Bits used for tile name
/// </summary>
constexpr ushort TileNameMask = 0x03FF; constexpr ushort TileNameMask = 0x03FF;
constexpr int Uncompressed3BPPSize = 0x0600; constexpr int Uncompressed3BPPSize = 0x0600;
@@ -49,7 +50,7 @@ constexpr int NumberOfRooms = 296;
constexpr int NumberOfOWMaps = 160; constexpr int NumberOfOWMaps = 160;
constexpr int Map32PerScreen = 256; constexpr int Map32PerScreen = 256;
constexpr int NumberOfMap16 = 3752; // 4096 constexpr int NumberOfMap16 = 3752; // 4096
constexpr int NumberOfMap32 = Map32PerScreen * NumberOfOWMaps; constexpr int NumberOfMap32 = Map32PerScreen * NumberOfOWMaps;
constexpr int NumberOfOWSprites = 352; constexpr int NumberOfOWSprites = 352;
constexpr int NumberOfColors = 3143; constexpr int NumberOfColors = 3143;
@@ -58,17 +59,17 @@ constexpr int NumberOfColors = 3143;
// Graphics // Graphics
// =========================================================================================== // ===========================================================================================
constexpr int tile_address = 0x1B52; // JP = Same constexpr int tile_address = 0x1B52; // JP = Same
constexpr int tile_address_floor = 0x1B5A; // JP = Same constexpr int tile_address_floor = 0x1B5A; // JP = Same
constexpr int subtype1_tiles = 0x8000; // JP = Same constexpr int subtype1_tiles = 0x8000; // JP = Same
constexpr int subtype2_tiles = 0x83F0; // JP = Same constexpr int subtype2_tiles = 0x83F0; // JP = Same
constexpr int subtype3_tiles = 0x84F0; // JP = Same constexpr int subtype3_tiles = 0x84F0; // JP = Same
constexpr int gfx_animated_pointer = 0x10275; // JP 0x10624 //long pointer constexpr int gfx_animated_pointer = 0x10275; // JP 0x10624 //long pointer
constexpr int overworldgfxGroups2 = 0x6073; // 0x60B3 constexpr int overworldgfxGroups2 = 0x6073; // 0x60B3
constexpr int gfx_1_pointer = constexpr int gfx_1_pointer =
0x6790; // 2byte pointer bank 00 pc -> 0x4320 CF80 ; 004F80 0x6790; // 2byte pointer bank 00 pc -> 0x4320 CF80 ; 004F80
constexpr int gfx_2_pointer = 0x6795; // D05F ; 00505F constexpr int gfx_2_pointer = 0x6795; // D05F ; 00505F
constexpr int gfx_3_pointer = 0x679A; // D13E ; 00513E constexpr int gfx_3_pointer = 0x679A; // D13E ; 00513E
constexpr int hud_palettes = 0xDD660; constexpr int hud_palettes = 0xDD660;
constexpr int maxGfx = 0xC3FB5; constexpr int maxGfx = 0xC3FB5;
@@ -100,9 +101,9 @@ constexpr int overworldSpritesAgahnim = 0x4CA21;
constexpr int overworldSpritesZelda = 0x4C901; constexpr int overworldSpritesZelda = 0x4C901;
constexpr int overworldItemsPointers = 0xDC2F9; constexpr int overworldItemsPointers = 0xDC2F9;
constexpr int overworldItemsAddress = 0xDC8B9; // 1BC2F9 constexpr int overworldItemsAddress = 0xDC8B9; // 1BC2F9
constexpr int overworldItemsBank = 0xDC8BF; constexpr int overworldItemsBank = 0xDC8BF;
constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E
constexpr int mapGfx = 0x7C9C; constexpr int mapGfx = 0x7C9C;
constexpr int overlayPointers = 0x77664; constexpr int overlayPointers = 0x77664;
@@ -121,10 +122,10 @@ constexpr int overworldMusicDW = 0x14403;
constexpr int overworldEntranceAllowedTilesLeft = 0xDB8C1; constexpr int overworldEntranceAllowedTilesLeft = 0xDB8C1;
constexpr int overworldEntranceAllowedTilesRight = 0xDB917; constexpr int overworldEntranceAllowedTilesRight = 0xDB917;
constexpr int overworldMapSize = 0x12844; // 0x00 = small maps, 0x20 = large constexpr int overworldMapSize = 0x12844; // 0x00 = small maps, 0x20 = large
// maps // maps
constexpr int overworldMapSizeHighByte = constexpr int overworldMapSizeHighByte =
0x12884; // 0x01 = small maps, 0x03 = large maps 0x12884; // 0x01 = small maps, 0x03 = large maps
// relative to the WORLD + 0x200 per map // relative to the WORLD + 0x200 per map
// large map that are not == parent id = same position as their parent! // large map that are not == parent id = same position as their parent!
@@ -141,7 +142,7 @@ constexpr int overworldScreenSize = 0x1788D;
//=========================================================================================== //===========================================================================================
// Overworld Exits/Entrances Variables // Overworld Exits/Entrances Variables
//=========================================================================================== //===========================================================================================
constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences constexpr int OWExitRoomId = 0x15D8A; // 0x15E07 Credits sequences
// 105C2 Ending maps // 105C2 Ending maps
// 105E2 Sprite Group Table for Ending // 105E2 Sprite Group Table for Ending
constexpr int OWExitMapId = 0x15E28; constexpr int OWExitMapId = 0x15E28;
@@ -162,43 +163,44 @@ constexpr int OWEntrancePos = 0xDBA71;
constexpr int OWEntranceEntranceId = 0xDBB73; constexpr int OWEntranceEntranceId = 0xDBB73;
constexpr int OWHolePos = 0xDB800; //(0x13 entries, 2 bytes each) modified(less constexpr int OWHolePos = 0xDB800; //(0x13 entries, 2 bytes each) modified(less
// 0x400) map16 coordinates for each hole // 0x400) map16 coordinates for each hole
constexpr int OWHoleArea = 0xDB826; //(0x13 entries, 2 bytes each) corresponding constexpr int OWHoleArea =
// area numbers for each hole 0xDB826; //(0x13 entries, 2 bytes each) corresponding
// area numbers for each hole
constexpr int OWHoleEntrance = constexpr int OWHoleEntrance =
0xDB84C; //(0x13 entries, 1 byte each) corresponding entrance numbers 0xDB84C; //(0x13 entries, 1 byte each) corresponding entrance numbers
constexpr int OWExitMapIdWhirlpool = 0x16AE5; // JP = ;016849 constexpr int OWExitMapIdWhirlpool = 0x16AE5; // JP = ;016849
constexpr int OWExitVramWhirlpool = 0x16B07; // JP = ;01686B constexpr int OWExitVramWhirlpool = 0x16B07; // JP = ;01686B
constexpr int OWExitYScrollWhirlpool = 0x16B29; // JP = ;01688D constexpr int OWExitYScrollWhirlpool = 0x16B29; // JP = ;01688D
constexpr int OWExitXScrollWhirlpool = 0x16B4B; // JP = ;016DE7 constexpr int OWExitXScrollWhirlpool = 0x16B4B; // JP = ;016DE7
constexpr int OWExitYPlayerWhirlpool = 0x16B6D; // JP = ;016E09 constexpr int OWExitYPlayerWhirlpool = 0x16B6D; // JP = ;016E09
constexpr int OWExitXPlayerWhirlpool = 0x16B8F; // JP = ;016E2B constexpr int OWExitXPlayerWhirlpool = 0x16B8F; // JP = ;016E2B
constexpr int OWExitYCameraWhirlpool = 0x16BB1; // JP = ;016E4D constexpr int OWExitYCameraWhirlpool = 0x16BB1; // JP = ;016E4D
constexpr int OWExitXCameraWhirlpool = 0x16BD3; // JP = ;016E6F constexpr int OWExitXCameraWhirlpool = 0x16BD3; // JP = ;016E6F
constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91 constexpr int OWExitUnk1Whirlpool = 0x16BF5; // JP = ;016E91
constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3 constexpr int OWExitUnk2Whirlpool = 0x16C17; // JP = ;016EB3
constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94 constexpr int OWWhirlpoolPosition = 0x16CF8; // JP = ;016F94
//=========================================================================================== //===========================================================================================
// Dungeon Related Variables // Dungeon Related Variables
//=========================================================================================== //===========================================================================================
// That could be turned into a pointer : // That could be turned into a pointer :
constexpr int dungeons_palettes_groups = 0x75460; // JP 0x67DD0 constexpr int dungeons_palettes_groups = 0x75460; // JP 0x67DD0
constexpr int dungeons_main_bg_palette_pointers = 0xDEC4B; // JP Same constexpr int dungeons_main_bg_palette_pointers = 0xDEC4B; // JP Same
constexpr int dungeons_palettes = constexpr int dungeons_palettes =
0xDD734; // JP Same (where all dungeons palettes are) 0xDD734; // JP Same (where all dungeons palettes are)
// That could be turned into a pointer : // That could be turned into a pointer :
constexpr int room_items_pointers = 0xDB69; // JP 0xDB67 constexpr int room_items_pointers = 0xDB69; // JP 0xDB67
constexpr int rooms_sprite_pointer = 0x4C298; // JP Same //2byte bank 09D62E constexpr int rooms_sprite_pointer = 0x4C298; // JP Same //2byte bank 09D62E
constexpr int room_header_pointer = 0xB5DD; // LONG constexpr int room_header_pointer = 0xB5DD; // LONG
constexpr int room_header_pointers_bank = 0xB5E7; // JP Same constexpr int room_header_pointers_bank = 0xB5E7; // JP Same
constexpr int gfx_groups_pointer = 0x6237; constexpr int gfx_groups_pointer = 0x6237;
constexpr int room_object_layout_pointer = 0x882D; constexpr int room_object_layout_pointer = 0x882D;
constexpr int room_object_pointer = 0x874C; // Long pointer constexpr int room_object_pointer = 0x874C; // Long pointer
constexpr int chests_length_pointer = 0xEBF6; constexpr int chests_length_pointer = 0xEBF6;
constexpr int chests_data_pointer1 = 0xEBFB; constexpr int chests_data_pointer1 = 0xEBFB;
@@ -206,18 +208,18 @@ constexpr int chests_data_pointer1 = 0xEBFB;
// for expansion constexpr int chests_data_pointer3 = 0xEC10; //Disabled for now // for expansion constexpr int chests_data_pointer3 = 0xEC10; //Disabled for now
// could be used for expansion // could be used for expansion
constexpr int blocks_length = 0x8896; // word value constexpr int blocks_length = 0x8896; // word value
constexpr int blocks_pointer1 = 0x15AFA; constexpr int blocks_pointer1 = 0x15AFA;
constexpr int blocks_pointer2 = 0x15B01; constexpr int blocks_pointer2 = 0x15B01;
constexpr int blocks_pointer3 = 0x15B08; constexpr int blocks_pointer3 = 0x15B08;
constexpr int blocks_pointer4 = 0x15B0F; constexpr int blocks_pointer4 = 0x15B0F;
constexpr int torch_data = 0x2736A; // JP 0x2704A constexpr int torch_data = 0x2736A; // JP 0x2704A
constexpr int torches_length_pointer = 0x88C1; constexpr int torches_length_pointer = 0x88C1;
constexpr int sprite_blockset_pointer = 0x5B57; constexpr int sprite_blockset_pointer = 0x5B57;
constexpr int sprites_data = constexpr int sprites_data =
0x4D8B0; // It use the unused pointers to have more space //Save purpose 0x4D8B0; // It use the unused pointers to have more space //Save purpose
constexpr int sprites_data_empty_room = 0x4D8AE; constexpr int sprites_data_empty_room = 0x4D8AE;
constexpr int sprites_end_data = 0x4EC9E; constexpr int sprites_end_data = 0x4EC9E;
@@ -240,7 +242,7 @@ constexpr int door_pos_left = 0x19AE;
constexpr int door_pos_right = 0x19C6; constexpr int door_pos_right = 0x19C6;
// TEXT EDITOR RELATED CONSTANTS // TEXT EDITOR RELATED CONSTANTS
constexpr int gfx_font = 0x70000; // 2bpp format constexpr int gfx_font = 0x70000; // 2bpp format
constexpr int text_data = 0xE0000; constexpr int text_data = 0xE0000;
constexpr int text_data2 = 0x75F40; constexpr int text_data2 = 0x75F40;
constexpr int pointers_dictionaries = 0x74703; constexpr int pointers_dictionaries = 0x74703;
@@ -249,60 +251,61 @@ constexpr int characters_width = 0x74ADF;
//=========================================================================================== //===========================================================================================
// Dungeon Entrances Related Variables // Dungeon Entrances Related Variables
//=========================================================================================== //===========================================================================================
constexpr int entrance_room = 0x14813; // 0x14577 //word value for each room constexpr int entrance_room = 0x14813; // 0x14577 //word value for each room
constexpr int entrance_scrolledge = constexpr int entrance_scrolledge =
0x1491D; // 0x14681 //8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR 0x1491D; // 0x14681 //8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR
constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 //2bytes each room constexpr int entrance_yscroll = 0x14D45; // 0x14AA9 //2bytes each room
constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 //2bytes constexpr int entrance_xscroll = 0x14E4F; // 0x14BB3 //2bytes
constexpr int entrance_yposition = 0x14F59; // 0x14CBD 2bytes constexpr int entrance_yposition = 0x14F59; // 0x14CBD 2bytes
constexpr int entrance_xposition = 0x15063; // 0x14DC7 2bytes constexpr int entrance_xposition = 0x15063; // 0x14DC7 2bytes
constexpr int entrance_camerayposition = 0x1516D; // 0x14ED1 2bytes constexpr int entrance_camerayposition = 0x1516D; // 0x14ED1 2bytes
constexpr int entrance_cameraxposition = 0x15277; // 0x14FDB 2bytes constexpr int entrance_cameraxposition = 0x15277; // 0x14FDB 2bytes
constexpr int entrance_gfx_group = 0x5D97; constexpr int entrance_gfx_group = 0x5D97;
constexpr int entrance_blockset = 0x15381; // 0x150E5 1byte constexpr int entrance_blockset = 0x15381; // 0x150E5 1byte
constexpr int entrance_floor = 0x15406; // 0x1516A 1byte constexpr int entrance_floor = 0x15406; // 0x1516A 1byte
constexpr int entrance_dungeon = 0x1548B; // 0x151EF 1byte (dungeon id) constexpr int entrance_dungeon = 0x1548B; // 0x151EF 1byte (dungeon id)
constexpr int entrance_door = 0x15510; // 0x15274 1byte constexpr int entrance_door = 0x15510; // 0x15274 1byte
constexpr int entrance_ladderbg = constexpr int entrance_ladderbg =
0x15595; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_- 0x15595; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_-
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_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 constexpr int entrance_music = 0x1582E; // 0x15592
constexpr int startingentrance_room = constexpr int startingentrance_room =
0x15B6E; // 0x158D2 //word value for each room 0x15B6E; // 0x158D2 //word value for each room
constexpr int startingentrance_scrolledge = constexpr int startingentrance_scrolledge =
0x15B7C; // 0x158E0 //8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR 0x15B7C; // 0x158E0 //8 bytes per room, HU, FU, HD, FD, HL, FL, HR, FR
constexpr int startingentrance_yscroll = 0x15BB4; // 0x14AA9 //2bytes each room constexpr int startingentrance_yscroll = 0x15BB4; // 0x14AA9 //2bytes each room
constexpr int startingentrance_xscroll = 0x15BC2; // 0x14BB3 //2bytes constexpr int startingentrance_xscroll = 0x15BC2; // 0x14BB3 //2bytes
constexpr int startingentrance_yposition = 0x15BD0; // 0x14CBD 2bytes constexpr int startingentrance_yposition = 0x15BD0; // 0x14CBD 2bytes
constexpr int startingentrance_xposition = 0x15BDE; // 0x14DC7 2bytes constexpr int startingentrance_xposition = 0x15BDE; // 0x14DC7 2bytes
constexpr int startingentrance_camerayposition = 0x15BEC; // 0x14ED1 2bytes constexpr int startingentrance_camerayposition = 0x15BEC; // 0x14ED1 2bytes
constexpr int startingentrance_cameraxposition = 0x15BFA; // 0x14FDB 2bytes constexpr int startingentrance_cameraxposition = 0x15BFA; // 0x14FDB 2bytes
constexpr int startingentrance_blockset = 0x15C08; // 0x150E5 1byte constexpr int startingentrance_blockset = 0x15C08; // 0x150E5 1byte
constexpr int startingentrance_floor = 0x15C0F; // 0x1516A 1byte constexpr int startingentrance_floor = 0x15C0F; // 0x1516A 1byte
constexpr int startingentrance_dungeon = 0x15C16; // 0x151EF 1byte (dungeon id) constexpr int startingentrance_dungeon = 0x15C16; // 0x151EF 1byte (dungeon id)
constexpr int startingentrance_door = 0x15C2B; // 0x15274 1byte constexpr int startingentrance_door = 0x15C2B; // 0x15274 1byte
constexpr int startingentrance_ladderbg = constexpr int startingentrance_ladderbg =
0x15C1D; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_- 0x15C1D; // 0x152F9 //1 byte, ---b ---a b = bg2, a = need to check -_-
constexpr int startingentrance_scrolling = 0x15C24; // 0x1537E //1byte --h- --v- constexpr int startingentrance_scrolling =
constexpr int startingentrance_scrollquadrant = 0x15C2B; // 0x15403 1byte 0x15C24; // 0x1537E //1byte --h- --v-
constexpr int startingentrance_exit = 0x15C32; // 0x15488 //2byte word constexpr int startingentrance_scrollquadrant = 0x15C2B; // 0x15403 1byte
constexpr int startingentrance_music = 0x15C4E; // 0x15592 constexpr int startingentrance_exit = 0x15C32; // 0x15488 //2byte word
constexpr int startingentrance_music = 0x15C4E; // 0x15592
constexpr int startingentrance_entrance = 0x15C40; constexpr int startingentrance_entrance = 0x15C40;
constexpr int items_data_start = 0xDDE9; // save purpose constexpr int items_data_start = 0xDDE9; // save purpose
constexpr int items_data_end = 0xE6B2; // save purpose constexpr int items_data_end = 0xE6B2; // save purpose
constexpr int initial_equipement = 0x271A6; constexpr int initial_equipement = 0x271A6;
constexpr int messages_id_dungeon = 0x3F61D; constexpr int messages_id_dungeon = 0x3F61D;
constexpr int chests_backupitems = constexpr int chests_backupitems =
0x3B528; // item id you get instead if you already have that item 0x3B528; // item id you get instead if you already have that item
constexpr int chests_yoffset = 0x4836C; constexpr int chests_yoffset = 0x4836C;
constexpr int chests_xoffset = 0x4836C + (76 * 1); constexpr int chests_xoffset = 0x4836C + (76 * 1);
constexpr int chests_itemsgfx = 0x4836C + (76 * 2); constexpr int chests_itemsgfx = 0x4836C + (76 * 2);
@@ -314,39 +317,39 @@ constexpr int chests_msgid = 0x442DD;
constexpr int dungeons_startrooms = 0x7939; constexpr int dungeons_startrooms = 0x7939;
constexpr int dungeons_endrooms = 0x792D; constexpr int dungeons_endrooms = 0x792D;
constexpr int dungeons_bossrooms = 0x10954; // short value constexpr int dungeons_bossrooms = 0x10954; // short value
// Bed Related Values (Starting location) // Bed Related Values (Starting location)
constexpr int bedPositionX = 0x039A37; // short value constexpr int bedPositionX = 0x039A37; // short value
constexpr int bedPositionY = 0x039A32; // short value constexpr int bedPositionY = 0x039A32; // short value
constexpr int bedPositionResetXLow = constexpr int bedPositionResetXLow =
0x02DE53; // short value(on 2 different bytes) 0x02DE53; // short value(on 2 different bytes)
constexpr int bedPositionResetXHigh = 0x02DE58; //^^^^^^ constexpr int bedPositionResetXHigh = 0x02DE58; //^^^^^^
constexpr int bedPositionResetYLow = constexpr int bedPositionResetYLow =
0x02DE5D; // short value(on 2 different bytes) 0x02DE5D; // short value(on 2 different bytes)
constexpr int bedPositionResetYHigh = 0x02DE62; //^^^^^^ constexpr int bedPositionResetYHigh = 0x02DE62; //^^^^^^
constexpr int bedSheetPositionX = 0x0480BD; // short value constexpr int bedSheetPositionX = 0x0480BD; // short value
constexpr int bedSheetPositionY = 0x0480B8; // short value constexpr int bedSheetPositionY = 0x0480B8; // short value
//=========================================================================================== //===========================================================================================
// Gravestones related variables // Gravestones related variables
//=========================================================================================== //===========================================================================================
constexpr int GravesYTilePos = 0x49968; // short (0x0F entries) constexpr int GravesYTilePos = 0x49968; // short (0x0F entries)
constexpr int GravesXTilePos = 0x49986; // short (0x0F entries) constexpr int GravesXTilePos = 0x49986; // short (0x0F entries)
constexpr int GravesTilemapPos = 0x499A4; // short (0x0F entries) constexpr int GravesTilemapPos = 0x499A4; // short (0x0F entries)
constexpr int GravesGFX = 0x499C2; // short (0x0F entries) constexpr int GravesGFX = 0x499C2; // short (0x0F entries)
constexpr int GravesXPos = 0x4994A; // short (0x0F entries) constexpr int GravesXPos = 0x4994A; // short (0x0F entries)
constexpr int GravesYLine = 0x4993A; // short (0x08 entries) constexpr int GravesYLine = 0x4993A; // short (0x08 entries)
constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries constexpr int GravesCountOnY = 0x499E0; // Byte 0x09 entries
constexpr int GraveLinkSpecialHole = 0x46DD9; // short constexpr int GraveLinkSpecialHole = 0x46DD9; // short
constexpr int GraveLinkSpecialStairs = 0x46DE0; // short constexpr int GraveLinkSpecialStairs = 0x46DE0; // short
//=========================================================================================== //===========================================================================================
// Palettes Related Variables - This contain all the palettes of the game // Palettes Related Variables - This contain all the palettes of the game
@@ -357,39 +360,40 @@ constexpr int overworldPaletteAnimated = 0xDE604;
constexpr int globalSpritePalettesLW = 0xDD218; constexpr int globalSpritePalettesLW = 0xDD218;
constexpr int globalSpritePalettesDW = 0xDD290; constexpr int globalSpritePalettesDW = 0xDD290;
constexpr int armorPalettes = constexpr int armorPalettes =
0xDD308; // Green, Blue, Red, Bunny, Electrocuted (15 colors each) 0xDD308; // Green, Blue, Red, Bunny, Electrocuted (15 colors each)
constexpr int spritePalettesAux1 = 0xDD39E; // 7 colors each constexpr int spritePalettesAux1 = 0xDD39E; // 7 colors each
constexpr int spritePalettesAux2 = 0xDD446; // 7 colors each constexpr int spritePalettesAux2 = 0xDD446; // 7 colors each
constexpr int spritePalettesAux3 = 0xDD4E0; // 7 colors each constexpr int spritePalettesAux3 = 0xDD4E0; // 7 colors each
constexpr int swordPalettes = 0xDD630; // 3 colors each - 4 entries constexpr int swordPalettes = 0xDD630; // 3 colors each - 4 entries
constexpr int shieldPalettes = 0xDD648; // 4 colors each - 3 entries constexpr int shieldPalettes = 0xDD648; // 4 colors each - 3 entries
constexpr int hudPalettes = 0xDD660; constexpr int hudPalettes = 0xDD660;
constexpr int dungeonMapPalettes = 0xDD70A; // 21 colors constexpr int dungeonMapPalettes = 0xDD70A; // 21 colors
constexpr int dungeonMainPalettes = 0xDD734; //(15*6) colors each - 20 entries constexpr int dungeonMainPalettes = 0xDD734; //(15*6) colors each - 20 entries
constexpr int dungeonMapBgPalettes = 0xDE544; // 16*6 constexpr int dungeonMapBgPalettes = 0xDE544; // 16*6
constexpr int hardcodedGrassLW = 0x5FEA9; // Mirrored Value at 0x75645 : 0x75625 constexpr int hardcodedGrassLW =
constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F 0x5FEA9; // Mirrored Value at 0x75645 : 0x75625
constexpr int hardcodedGrassDW = 0x05FEB3; // 0x7564F
constexpr int hardcodedGrassSpecial = 0x75640; constexpr int hardcodedGrassSpecial = 0x75640;
//=========================================================================================== //===========================================================================================
// Dungeon Map Related Variables // Dungeon Map Related Variables
//=========================================================================================== //===========================================================================================
constexpr int dungeonMap_rooms_ptr = 0x57605; // 14 pointers of map data constexpr int dungeonMap_rooms_ptr = 0x57605; // 14 pointers of map data
constexpr int dungeonMap_floors = 0x575D9; // 14 words values constexpr int dungeonMap_floors = 0x575D9; // 14 words values
constexpr int dungeonMap_gfx_ptr = 0x57BE4; // 14 pointers of gfx data constexpr int dungeonMap_gfx_ptr = 0x57BE4; // 14 pointers of gfx data
constexpr int dungeonMap_datastart = constexpr int dungeonMap_datastart =
0x57039; // data start for floors/gfx MUST skip 575D9 to 57621 (pointers) 0x57039; // data start for floors/gfx MUST skip 575D9 to 57621 (pointers)
constexpr int dungeonMap_expCheck = constexpr int dungeonMap_expCheck =
0x56652; // IF Byte = 0xB9 dungeon maps are not expanded 0x56652; // IF Byte = 0xB9 dungeon maps are not expanded
constexpr int dungeonMap_tile16 = 0x57009; constexpr int dungeonMap_tile16 = 0x57009;
constexpr int dungeonMap_tile16Exp = 0x109010; constexpr int dungeonMap_tile16Exp = 0x109010;
constexpr int dungeonMap_bossrooms = 0x56807; // 14 words values 0x000F = no constexpr int dungeonMap_bossrooms = 0x56807; // 14 words values 0x000F = no
// boss // boss
constexpr int triforceVertices = 0x04FFD2; // group of 3, X, Y ,Z constexpr int triforceVertices = 0x04FFD2; // group of 3, X, Y ,Z
constexpr int TriforceFaces = 0x04FFE4; // group of 5 constexpr int TriforceFaces = 0x04FFE4; // group of 5
constexpr int crystalVertices = 0x04FF98; constexpr int crystalVertices = 0x04FF98;
@@ -483,7 +487,7 @@ static const std::string SecretItemNames[] = {
"Full Magic", "Cucco", "Green Soldier", "Bush Stal", "Blue Soldier", "Full Magic", "Cucco", "Green Soldier", "Bush Stal", "Blue Soldier",
"Landmine", "Heart", "Fairy", "Heart", "Landmine", "Heart", "Fairy", "Heart",
"Nothing ", // 22 "Nothing ", // 22
"Hole", "Warp", "Staircase", "Bombable", "Switch"}; "Hole", "Warp", "Staircase", "Bombable", "Switch"};
@@ -541,7 +545,7 @@ static const std::string Type1RoomObjectNames[] = {
"Nothing", "Nothing",
"Carpet ↔", "Carpet ↔",
"Carpet trim ↔", "Carpet trim ↔",
"Weird door", // TODO: WEIRD DOOR OBJECT NEEDS INVESTIGATION "Weird door", // TODO: WEIRD DOOR OBJECT NEEDS INVESTIGATION
"Drapes (north) ↔", "Drapes (north) ↔",
"Drapes (west, odd) ↔", "Drapes (west, odd) ↔",
"Statues ↔", "Statues ↔",
@@ -559,10 +563,10 @@ static const std::string Type1RoomObjectNames[] = {
"Water edge ┗━┓ (concave) ↔", "Water edge ┗━┓ (concave) ↔",
"Water edge ┗━┓ (convex) ↔", "Water edge ┗━┓ (convex) ↔",
"Water edge ┏━┛ (convex) ↔", "Water edge ┏━┛ (convex) ↔",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Supports (south) ↔", "Supports (south) ↔",
"Bar ↔", "Bar ↔",
"Shelf A ↔", "Shelf A ↔",
@@ -657,10 +661,10 @@ static const std::string Type1RoomObjectNames[] = {
"Diagonal layer 2 mask A ◣", "Diagonal layer 2 mask A ◣",
"Diagonal layer 2 mask A ◥", "Diagonal layer 2 mask A ◥",
"Diagonal layer 2 mask A ◢", "Diagonal layer 2 mask A ◢",
"Diagonal layer 2 mask B ◤", // TODO: VERIFY "Diagonal layer 2 mask B ◤", // TODO: VERIFY
"Diagonal layer 2 mask B ◣", // TODO: VERIFY "Diagonal layer 2 mask B ◣", // TODO: VERIFY
"Diagonal layer 2 mask B ◥", // TODO: VERIFY "Diagonal layer 2 mask B ◥", // TODO: VERIFY
"Diagonal layer 2 mask B ◢", // TODO: VERIFY "Diagonal layer 2 mask B ◢", // TODO: VERIFY
"Nothing", "Nothing",
"Nothing", "Nothing",
"Nothing", "Nothing",
@@ -699,10 +703,10 @@ static const std::string Type1RoomObjectNames[] = {
"Nothing", "Nothing",
"Icy floor A ⇲", "Icy floor A ⇲",
"Icy floor B ⇲", "Icy floor B ⇲",
"Moving wall flag", // TODO: WTF IS THIS? "Moving wall flag", // TODO: WTF IS THIS?
"Moving wall flag", // TODO: WTF IS THIS? "Moving wall flag", // TODO: WTF IS THIS?
"Moving wall flag", // TODO: WTF IS THIS? "Moving wall flag", // TODO: WTF IS THIS?
"Moving wall flag", // TODO: WTF IS THIS? "Moving wall flag", // TODO: WTF IS THIS?
"Layer 2 mask (medium) ⇲", "Layer 2 mask (medium) ⇲",
"Flood water (large) ⇲", "Flood water (large) ⇲",
"Layer 2 swim mask ⇲", "Layer 2 swim mask ⇲",
@@ -773,34 +777,34 @@ static const std::string Type2RoomObjectNames[] = {
"Star tile (enabled)", "Star tile (enabled)",
"Small torch (lit)", "Small torch (lit)",
"Barrel", "Barrel",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Table", "Table",
"Fairy statue", "Fairy statue",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Chair", "Chair",
"Bed", "Bed",
"Fireplace", "Fireplace",
"Mario portrait", "Mario portrait",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Interroom stairs (up)", "Interroom stairs (up)",
"Interroom stairs (down)", "Interroom stairs (down)",
"Interroom stairs B (down)", "Interroom stairs B (down)",
"Intraroom stairs north B", // TODO: VERIFY LAYER HANDLING "Intraroom stairs north B", // TODO: VERIFY LAYER HANDLING
"Intraroom stairs north (separate layers)", "Intraroom stairs north (separate layers)",
"Intraroom stairs north (merged layers)", "Intraroom stairs north (merged layers)",
"Intraroom stairs north (swim layer)", "Intraroom stairs north (swim layer)",
"Block", "Block",
"Water ladder (north)", "Water ladder (north)",
"Water ladder (south)", // TODO: NEEDS IN GAME VERIFICATION "Water ladder (south)", // TODO: NEEDS IN GAME VERIFICATION
"Dam floodgate", "Dam floodgate",
"Interroom spiral stairs up (top)", "Interroom spiral stairs up (top)",
"Interroom spiral stairs down (top)", "Interroom spiral stairs down (top)",
"Interroom spiral stairs up (bottom)", "Interroom spiral stairs up (bottom)",
"Interroom spiral stairs down (bottom)", "Interroom spiral stairs down (bottom)",
"Sanctuary wall (north)", "Sanctuary wall (north)",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Pew", "Pew",
"Magic bat altar", "Magic bat altar",
}; };
@@ -819,21 +823,21 @@ static const std::string Type3RoomObjectNames[] = {
"Somaria path intersection ┻", "Somaria path intersection ┻",
"Somaria path intersection ┣", "Somaria path intersection ┣",
"Somaria path intersection ┫", "Somaria path intersection ┫",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Somaria path 2-way endpoint", "Somaria path 2-way endpoint",
"Somaria path crossover", "Somaria path crossover",
"Babasu hole (north)", "Babasu hole (north)",
"Babasu hole (south)", "Babasu hole (south)",
"9 blue rupees", "9 blue rupees",
"Telepathy tile", "Telepathy tile",
"Warp door", // TODO: NEEDS IN GAME VERIFICATION THAT THIS IS USELESS "Warp door", // TODO: NEEDS IN GAME VERIFICATION THAT THIS IS USELESS
"Kholdstare's shell", "Kholdstare's shell",
"Hammer peg", "Hammer peg",
"Prison cell", "Prison cell",
"Big key lock", "Big key lock",
"Chest", "Chest",
"Chest (open)", "Chest (open)",
"Intraroom stairs south", // TODO: VERIFY LAYER HANDLING "Intraroom stairs south", // TODO: VERIFY LAYER HANDLING
"Intraroom stairs south (separate layers)", "Intraroom stairs south (separate layers)",
"Intraroom stairs south (merged layers)", "Intraroom stairs south (merged layers)",
"Interroom straight stairs up (north, top)", "Interroom straight stairs up (north, top)",
@@ -849,21 +853,21 @@ static const std::string Type3RoomObjectNames[] = {
"Interroom straight stairs up (south, bottom)", "Interroom straight stairs up (south, bottom)",
"Interroom straight stairs down (south, bottom)", "Interroom straight stairs down (south, bottom)",
"Lamp cones", "Lamp cones",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Liftable large block", "Liftable large block",
"Agahnim's altar", "Agahnim's altar",
"Agahnim's boss room", "Agahnim's boss room",
"Pot", "Pot",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Big chest", "Big chest",
"Big chest (open)", "Big chest (open)",
"Intraroom stairs south (swim layer)", "Intraroom stairs south (swim layer)",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Pipe end (south)", "Pipe end (south)",
"Pipe end (north)", "Pipe end (north)",
"Pipe end (east)", "Pipe end (east)",
@@ -879,7 +883,7 @@ static const std::string Type3RoomObjectNames[] = {
"Pipe crossover", "Pipe crossover",
"Bombable floor", "Bombable floor",
"Fake bombable floor", "Fake bombable floor",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Warp tile", "Warp tile",
"Tool rack", "Tool rack",
"Furnace", "Furnace",
@@ -887,11 +891,11 @@ static const std::string Type3RoomObjectNames[] = {
"Anvil", "Anvil",
"Warp tile (disabled)", "Warp tile (disabled)",
"Pressure plate", "Pressure plate",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Blue peg", "Blue peg",
"Orange peg", "Orange peg",
"Fortune teller room", "Fortune teller room",
"Unknown", // TODO: NEEDS IN GAME CHECKING "Unknown", // TODO: NEEDS IN GAME CHECKING
"Bar corner ▛", "Bar corner ▛",
"Bar corner ▙", "Bar corner ▙",
"Bar corner ▜", "Bar corner ▜",
@@ -1194,9 +1198,9 @@ static const std::string TileTypeNames[] = {
"$FE Door X top? (unused?)", "$FE Door X top? (unused?)",
"$FF Door X top? (unused?)"}; "$FF Door X top? (unused?)"};
} // namespace Constants } // namespace Constants
} // namespace Core } // namespace Core
} // namespace Application } // namespace Application
} // namespace yaze } // namespace yaze
#endif #endif

View File

@@ -41,10 +41,11 @@ static TileInfo GetTilesInfo(ushort tile) {
void Overworld::Load(Utils::ROM rom) { void Overworld::Load(Utils::ROM rom) {
rom_ = rom; rom_ = rom;
for (int i = 0; i < 0x2B; i++) { for (int i = 0; i < 0x2B; i++) {
tileLeftEntrance.push_back( // tileLeftEntrance.push_back(
rom_.ReadShort(Constants::overworldEntranceAllowedTilesLeft + (i * 2))); // rom_.ReadShort(Constants::overworldEntranceAllowedTilesLeft + (i *
tileRightEntrance.push_back(rom_.ReadShort( // 2)));
Constants::overworldEntranceAllowedTilesRight + (i * 2))); // tileRightEntrance.push_back(rom_.ReadShort(
// Constants::overworldEntranceAllowedTilesRight + (i * 2)));
} }
AssembleMap32Tiles(); AssembleMap32Tiles();
@@ -132,8 +133,10 @@ void Overworld::DecompressAllMapTiles() {
<< 8) + << 8) +
(rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh + (rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh +
(int)(3 * i))]); (int)(3 * i))]);
p1 = rom_.SnesToPc(p1);
char* tmp = new char[256];
p1 = lorom_snes_to_pc(p1, &tmp);
std::cout << tmp << std::endl;
int p2 = (rom_.GetRawData()[(Constants::compressedAllMap32PointersLow) + 2 + int p2 = (rom_.GetRawData()[(Constants::compressedAllMap32PointersLow) + 2 +
(int)(3 * i)] (int)(3 * i)]
<< 16) + << 16) +
@@ -142,7 +145,9 @@ void Overworld::DecompressAllMapTiles() {
<< 8) + << 8) +
(rom_.GetRawData()[(Constants::compressedAllMap32PointersLow + (rom_.GetRawData()[(Constants::compressedAllMap32PointersLow +
(int)(3 * i))]); (int)(3 * i))]);
p2 = rom_.SnesToPc(p2); p2 = lorom_snes_to_pc(p2, &tmp);
std::cout << tmp << std::endl;
delete[] tmp;
int ttpos = 0; int ttpos = 0;
unsigned int compressedSize1 = 0; unsigned int compressedSize1 = 0;
@@ -168,10 +173,12 @@ void Overworld::DecompressAllMapTiles() {
} }
} }
auto bytes = alttp_compressor_.DecompressOverworld( auto bytes =
rom_.GetRawData(), p2, 1000, &compressedSize1, &compressedLength1); alttp_decompress_overworld((char*)rom_.GetRawData(), p2, 1000,
auto bytes2 = alttp_compressor_.DecompressOverworld( &compressedSize1, &compressedLength1);
rom_.GetRawData(), p1, 1000, &compressedSize2, &compressedLength2); auto bytes2 =
alttp_decompress_overworld((char*)rom_.GetRawData(), p1, 1000,
&compressedSize2, &compressedLength2);
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
@@ -295,7 +302,7 @@ void Overworld::LoadOverworldMap() {
owactualMapBitmap->Create(&owactualMapTexture); owactualMapBitmap->Create(&owactualMapTexture);
// Mode 7 // Mode 7
byte* ptr = overworldMapPointer; char* ptr = overworldMapPointer;
int pos = 0; int pos = 0;
for (int sy = 0; sy < 16; sy++) { for (int sy = 0; sy < 16; sy++) {

View File

@@ -3,12 +3,13 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <rommapping.h>
#include "Core/Constants.h" #include "Core/Constants.h"
#include "Graphics/Bitmap.h" #include "Graphics/Bitmap.h"
#include "Graphics/Tile.h" #include "Graphics/Tile.h"
#include "OverworldMap.h" #include "OverworldMap.h"
#include "Utils/Compression.h"
#include "Utils/ROM.h" #include "Utils/ROM.h"
namespace yaze { namespace yaze {
@@ -25,18 +26,18 @@ class Overworld {
void Load(Utils::ROM rom); void Load(Utils::ROM rom);
byte* overworldMapPointer = new byte[0x40000]; char* overworldMapPointer = new char[0x40000];
Graphics::Bitmap* overworldMapBitmap; Graphics::Bitmap* overworldMapBitmap;
GLuint overworldMapTexture; GLuint overworldMapTexture;
byte* owactualMapPointer = new byte[0x40000]; char* owactualMapPointer = new char[0x40000];
Graphics::Bitmap* owactualMapBitmap; Graphics::Bitmap* owactualMapBitmap;
GLuint owactualMapTexture; GLuint owactualMapTexture;
private: private:
Utils::ROM rom_; Utils::ROM rom_;
Utils::ALTTPCompression alttp_compressor_;
int gameState = 1; int gameState = 1;
bool isLoaded = false;
byte mapParent[160]; byte mapParent[160];
ushort **allmapsTilesLW; // 64 maps * (32*32 tiles) ushort **allmapsTilesLW; // 64 maps * (32*32 tiles)
@@ -49,8 +50,6 @@ class Overworld {
std::vector<OverworldMap> allmaps; std::vector<OverworldMap> allmaps;
bool isLoaded = false;
std::vector<ushort> tileLeftEntrance; std::vector<ushort> tileLeftEntrance;
std::vector<ushort> tileRightEntrance; std::vector<ushort> tileRightEntrance;
@@ -58,7 +57,6 @@ class Overworld {
Core::Constants::map32TilesTL, Core::Constants::map32TilesTR, Core::Constants::map32TilesTL, Core::Constants::map32TilesTR,
Core::Constants::map32TilesBL, Core::Constants::map32TilesBR}; Core::Constants::map32TilesBL, Core::Constants::map32TilesBR};
enum Dimension { enum Dimension {
map32TilesTL = 0, map32TilesTL = 0,
map32TilesTR = 1, map32TilesTR = 1,

View File

@@ -4,6 +4,8 @@ namespace yaze {
namespace Application { namespace Application {
namespace Editor { namespace Editor {
using namespace Core;
Editor::Editor() { Editor::Editor() {
static bool inited = false; static bool inited = false;
if (!inited) { if (!inited) {
@@ -83,13 +85,19 @@ Editor::Editor() {
asm_editor_.SetLanguageDefinition(language65816Def); asm_editor_.SetLanguageDefinition(language65816Def);
asm_editor_.SetPalette(TextEditor::GetDarkPalette()); asm_editor_.SetPalette(TextEditor::GetDarkPalette());
current_set_.bpp = 3; current_set_.bpp = 4;
current_set_.pcTilesLocation = 0x8000; current_set_.pcTilesLocation = 0x80000;
current_set_.SNESTilesLocation = 0; current_set_.SNESTilesLocation = 0;
current_set_.length = 1000; current_set_.length = 28672;
current_set_.pcPaletteLocation = 0; current_set_.pcPaletteLocation = 0xDD326;
current_set_.SNESPaletteLocation = 0; current_set_.SNESPaletteLocation = 0;
current_set_.compression = "zelda3"; current_set_.compression = "zelda3";
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.0f, 0.5f, 0.0f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.4f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.3f, 0.0f, 0.0f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.3f, 0.7f, 0.9f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
} }
void Editor::UpdateScreen() { void Editor::UpdateScreen() {
@@ -111,12 +119,12 @@ void Editor::UpdateScreen() {
DrawYazeMenu(); DrawYazeMenu();
TAB_BAR("##TabBar"); TAB_BAR("##TabBar");
DrawProjectEditor(); DrawProjectEditor();
DrawOverworldEditor(); DrawOverworldEditor();
DrawDungeonEditor(); DrawDungeonEditor();
DrawGraphicsEditor(); DrawGraphicsEditor();
DrawSpriteEditor(); DrawSpriteEditor();
DrawScreenEditor(); DrawScreenEditor();
END_TAB_BAR(); END_TAB_BAR();
ImGui::End(); ImGui::End();
@@ -124,10 +132,10 @@ void Editor::UpdateScreen() {
void Editor::DrawYazeMenu() { void Editor::DrawYazeMenu() {
MENU_BAR(); MENU_BAR();
DrawFileMenu(); DrawFileMenu();
DrawEditMenu(); DrawEditMenu();
DrawViewMenu(); DrawViewMenu();
DrawHelpMenu(); DrawHelpMenu();
END_MENU_BAR(); END_MENU_BAR();
// display // display
@@ -136,7 +144,6 @@ void Editor::DrawYazeMenu() {
if (ImGuiFileDialog::Instance()->IsOk()) { if (ImGuiFileDialog::Instance()->IsOk()) {
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath(); std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
title_ = ImGuiFileDialog::Instance()->GetCurrentFileName();
rom.LoadFromFile(filePathName); rom.LoadFromFile(filePathName);
overworld_editor_.SetRom(rom); overworld_editor_.SetRom(rom);
rom_data_ = (void *)rom.GetRawData(); rom_data_ = (void *)rom.GetRawData();
@@ -264,7 +271,7 @@ void Editor::DrawViewMenu() {
} }
if (ImGui::BeginMenu("View")) { if (ImGui::BeginMenu("View")) {
ImGui::MenuItem("HEX Editor", nullptr, &MemoryEditor::Open); ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor); ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor);
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo); ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
@@ -291,37 +298,136 @@ void Editor::DrawProjectEditor() {
static bool inited = false; static bool inited = false;
if (ImGui::BeginTabItem("Project")) { if (ImGui::BeginTabItem("Project")) {
ImGui::InputInt("PC Tile Location", &current_set_.pcTilesLocation); if (ImGui::BeginTable("##projectTable", 2,
ImGui::InputScalar("SNES Tile Location", ImGuiDataType_U32, (void*)&current_set_.SNESTilesLocation); ImGuiTableFlags_SizingStretchSame)) {
ImGui::InputScalar("Tile Preset Length", ImGuiDataType_U32, (void*)&current_set_.length); ImGui::TableSetupColumn("##inputs");
ImGui::InputScalar("Bits per Pixel", ImGuiDataType_U32, (void*)&current_set_.bpp); ImGui::TableSetupColumn("##outputs");
ImGui::InputScalar("PC Palette Location", ImGuiDataType_U32, (void*)&current_set_.pcPaletteLocation);
ImGui::InputScalar("SNES Palette Location", ImGuiDataType_U32, (void*)&current_set_.SNESPaletteLocation);
if (rom.isLoaded()) { ImGui::TableNextColumn();
ImGui::Text("Title: %s", rom.getTitle()); ImGui::Text("Title: %s", rom.getTitle());
ImGui::Text("Version: %d", rom.getVersion()); ImGui::Text("Version: %d", rom.getVersion());
ImGui::Text("ROM Size: %ld", rom.getSize()); ImGui::Text("ROM Size: %ld", rom.getSize());
if (!inited) { ImGui::InputInt("PC Tile Location", &current_set_.pcTilesLocation);
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)); // 1, 100, ImGuiInputTextFlags_CharsHexadecimal);
current_palette_.colors.push_back(ImVec4(0.0f, 0.5f, 0.0f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.0f, 0.0f, 0.4f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.3f, 0.0f, 0.0f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.3f, 0.7f, 0.9f, 1.0f));
current_palette_.colors.push_back(ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
current_scene_.buildSurface(rom.ExtractTiles(current_set_), current_palette_, current_set_.tilesPattern); ImGui::InputScalar("SNES Tile Location", ImGuiDataType_U32,
inited = true; (void *)&current_set_.SNESTilesLocation);
ImGui::InputScalar("Tile Preset Length", ImGuiDataType_U32,
(void *)&current_set_.length);
ImGui::InputScalar("Bits per Pixel", ImGuiDataType_U32,
(void *)&current_set_.bpp);
ImGui::InputScalar("PC Palette Location", ImGuiDataType_U32,
(void *)&current_set_.pcPaletteLocation);
ImGui::InputScalar("SNES Palette Location", ImGuiDataType_U32,
(void *)&current_set_.SNESPaletteLocation);
BASIC_BUTTON("ExtractTiles") {
if (rom.isLoaded()) {
tiles_ = rom.ExtractTiles(current_set_);
}
} }
for (const auto & [key, value] : current_scene_.imagesCache) { BASIC_BUTTON("BuildSurface") {
ImGui::Image((void *)(SDL_Texture*)value, ImVec2(8, 8)); if (rom.isLoaded()) {
current_palette_ = rom.ExtractPalette(current_set_);
current_scene_.buildSurface(tiles_, current_palette_,
current_set_.tilesPattern);
}
} }
for (auto &[key, texture] : current_scene_.imagesCache) {
ImGui::Image((void *)(SDL_Texture *)texture, ImVec2(8, 8));
}
ImGui::TableNextColumn();
static ImVector<ImVec2> points;
static ImVec2 scrolling(0.0f, 0.0f);
static bool opt_enable_context_menu = true;
static bool opt_enable_grid = true;
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
ImVec2 canvas_sz = ImGui::GetContentRegionAvail();
ImVec2 canvas_p1 =
ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
// Draw border and background color
const ImGuiIO &io = ImGui::GetIO();
ImDrawList *draw_list = ImGui::GetWindowDrawList();
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(32, 32, 32, 255));
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
// This will catch our interactions
ImGui::InvisibleButton(
"canvas", canvas_sz,
ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
const bool is_active = ImGui::IsItemActive(); // Held
const ImVec2 origin(canvas_p0.x + scrolling.x,
canvas_p0.y + scrolling.y); // Lock scrolled origin
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x,
io.MousePos.y - origin.y);
// Pan (we use a zero mouse threshold when there's no context menu)
const float mouse_threshold_for_pan =
opt_enable_context_menu ? -1.0f : 0.0f;
if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right,
mouse_threshold_for_pan)) {
scrolling.x += io.MouseDelta.x;
scrolling.y += io.MouseDelta.y;
}
// Context menu (under default mouse threshold)
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
if (opt_enable_context_menu && drag_delta.x == 0.0f &&
drag_delta.y == 0.0f)
ImGui::OpenPopupOnItemClick("context",
ImGuiPopupFlags_MouseButtonRight);
if (ImGui::BeginPopup("context")) {
ImGui::MenuItem("Placeholder");
ImGui::EndPopup();
}
// Draw grid + all lines in the canvas
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
if (opt_enable_grid) {
const float GRID_STEP = 64.0f;
for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x;
x += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y),
ImVec2(canvas_p0.x + x, canvas_p1.y),
IM_COL32(200, 200, 200, 40));
for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y;
y += GRID_STEP)
draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y),
ImVec2(canvas_p1.x, canvas_p0.y + y),
IM_COL32(200, 200, 200, 40));
}
if (current_scene_.imagesCache.size() != 0) {
for (const auto &[key, value] : current_scene_.imagesCache) {
const float GRID_STEP = 8.0f;
float x = fmodf(scrolling.x, GRID_STEP);
float y = fmodf(scrolling.y, GRID_STEP);
draw_list->AddImage((void*)(intptr_t)value,
ImVec2(canvas_p0.x + x, canvas_p0.y),
ImVec2(canvas_p0.x + x, canvas_p1.y));
x += GRID_STEP;
if (x == 128) {
x = 0;
y += GRID_STEP;
}
}
}
draw_list->PopClipRect();
ImGui::EndTable();
} }
ImGui::EndTabItem(); ImGui::EndTabItem();
} }
} }

View File

@@ -1,19 +1,18 @@
#ifndef YAZE_APPLICATION_VIEW_EDITOR_H #ifndef YAZE_APPLICATION_VIEW_EDITOR_H
#define YAZE_APPLICATION_VIEW_EDITOR_H #define YAZE_APPLICATION_VIEW_EDITOR_H
#include <ImGuiColorTextEdit/TextEditor.h>
#include <ImGuiFileDialog/ImGuiFileDialog.h>
#include <imgui/imgui.h>
#include <imgui/imgui_memory_editor.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
#include <memory> #include <memory>
#include "Core/Constants.h"
#include "Core/Icons.h" #include "Core/Icons.h"
#include "ImGuiColorTextEdit/TextEditor.h"
#include "ImGuiFileDialog/ImGuiFileDialog.h"
#include "OverworldEditor.h" #include "OverworldEditor.h"
#include "Utils/ROM.h" #include "Utils/ROM.h"
#include "imgui/backends/imgui_impl_sdl.h"
#include "imgui/backends/imgui_impl_sdlrenderer.h"
#include "imgui/imgui.h"
#include "imgui/imgui_internal.h"
#include "imgui/imgui_memory_editor.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
namespace yaze { namespace yaze {
namespace Application { namespace Application {
@@ -41,8 +40,6 @@ class Editor {
void *rom_data_; void *rom_data_;
bool isLoaded = true; bool isLoaded = true;
std::string title_ = "YAZE";
Utils::ROM rom; Utils::ROM rom;
TextEditor asm_editor_; TextEditor asm_editor_;
TextEditor::LanguageDefinition language65816Def; TextEditor::LanguageDefinition language65816Def;
@@ -52,6 +49,8 @@ class Editor {
Graphics::SNESPalette current_palette_; Graphics::SNESPalette current_palette_;
Graphics::TilePreset current_set_; Graphics::TilePreset current_set_;
std::vector<tile8> tiles_;
ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit; ImGuiTableFlags toolset_table_flags = ImGuiTableFlags_SizingFixedFit;
}; };

View File

@@ -8,7 +8,6 @@
#include "Graphics/Palette.h" #include "Graphics/Palette.h"
#include "Graphics/Scene.h" #include "Graphics/Scene.h"
#include "Graphics/Tile.h" #include "Graphics/Tile.h"
#include "Utils/Compression.h"
namespace yaze { namespace yaze {
namespace Application { namespace Application {
@@ -37,7 +36,6 @@ class OverworldEditor {
Utils::ROM rom_; Utils::ROM rom_;
Data::Overworld overworld; Data::Overworld overworld;
Graphics::Scene current_scene_; Graphics::Scene current_scene_;
Utils::ALTTPCompression alttp_compressor_;
Graphics::Bitmap allgfxBitmap; Graphics::Bitmap allgfxBitmap;
Graphics::SNESPalette palette_; Graphics::SNESPalette palette_;
Graphics::TilePreset current_set_; Graphics::TilePreset current_set_;

View File

@@ -1,63 +1,66 @@
#include "Bitmap.h" #include "Bitmap.h"
#include "Utils/ROM.h" #include "Utils/ROM.h"
#include "Utils/Compression.h"
#include "rommapping.h" #include "rommapping.h"
namespace yaze { namespace yaze {
namespace Application { namespace Application {
namespace Graphics { namespace Graphics {
int GetPCGfxAddress(byte *romData, byte id) { int GetPCGfxAddress(char *romData, char id) {
char** info1, **info2,** info3, **info4; char **info1, **info2, **info3, **info4;
int gfxPointer1 = int gfxPointer1 =
lorom_snes_to_pc((romData[Constants::gfx_1_pointer + 1] << 8) + lorom_snes_to_pc((romData[Constants::gfx_1_pointer + 1] << 8) +
(romData[Constants::gfx_1_pointer]), info1); (romData[Constants::gfx_1_pointer]),
info1);
int gfxPointer2 = int gfxPointer2 =
lorom_snes_to_pc((romData[Constants::gfx_2_pointer + 1] << 8) + lorom_snes_to_pc((romData[Constants::gfx_2_pointer + 1] << 8) +
(romData[Constants::gfx_2_pointer]), info2); (romData[Constants::gfx_2_pointer]),
info2);
int gfxPointer3 = int gfxPointer3 =
lorom_snes_to_pc((romData[Constants::gfx_3_pointer + 1] << 8) + lorom_snes_to_pc((romData[Constants::gfx_3_pointer + 1] << 8) +
(romData[Constants::gfx_3_pointer]), info3); (romData[Constants::gfx_3_pointer]),
info3);
byte gfxGamePointer1 = romData[gfxPointer1 + id]; char gfxGamePointer1 = romData[gfxPointer1 + id];
byte gfxGamePointer2 = romData[gfxPointer2 + id]; char gfxGamePointer2 = romData[gfxPointer2 + id];
byte gfxGamePointer3 = romData[gfxPointer3 + id]; char gfxGamePointer3 = romData[gfxPointer3 + id];
return lorom_snes_to_pc(Utils::AddressFromBytes(gfxGamePointer1, gfxGamePointer2, return lorom_snes_to_pc(
gfxGamePointer3), info4); Utils::AddressFromBytes(gfxGamePointer1, gfxGamePointer2,
gfxGamePointer3),
info4);
} }
byte *CreateAllGfxDataRaw(byte *romData) { char *CreateAllGfxDataRaw(char *romData) {
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 bytes // 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 bytes // 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 bytes // 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 bytes // 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 bytes // 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
Utils::ALTTPCompression alttp_compressor_; char *buffer = new char[346624];
byte *buffer = new byte[346624];
int bufferPos = 0; int bufferPos = 0;
byte *data = new byte[2048]; char *data = new char[2048];
unsigned int uncompressedSize = 0; unsigned int uncompressedSize = 0;
unsigned int compressedSize = 0; unsigned int compressedSize = 0;
for (int i = 0; i < Constants::NumberOfSheets; i++) { for (int i = 0; i < Constants::NumberOfSheets; i++) {
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites (i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
(i >= 127 && i <= 217) // Compressed 3bpp sprites (i >= 127 && i <= 217) // Compressed 3bpp sprites
); );
// uncompressed sheets // uncompressed sheets
if (i >= 115 && i <= 126) { if (i >= 115 && i <= 126) {
data = new byte[Constants::Uncompressed3BPPSize]; data = new char[Constants::Uncompressed3BPPSize];
int startAddress = GetPCGfxAddress(romData, (byte)i); int startAddress = GetPCGfxAddress(romData, (char)i);
for (int j = 0; j < Constants::Uncompressed3BPPSize; j++) { for (int j = 0; j < Constants::Uncompressed3BPPSize; j++) {
data[j] = romData[j + startAddress]; data[j] = romData[j + startAddress];
} }
} else { } else {
data = alttp_compressor_.DecompressGfx( data = alttp_decompress_gfx(
romData, GetPCGfxAddress(romData, (byte)i), (char *)romData, GetPCGfxAddress(romData, (char)i),
Constants::UncompressedSheetSize, &uncompressedSize, &compressedSize); Constants::UncompressedSheetSize, &uncompressedSize, &compressedSize);
} }
@@ -71,34 +74,35 @@ byte *CreateAllGfxDataRaw(byte *romData) {
return buffer; return buffer;
} }
void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) { void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
byte* data = CreateAllGfxDataRaw(romData); char *data = CreateAllGfxDataRaw(romData);
byte* newData = char *newData =
new byte[0x6F800]; // NEED TO GET THE APPROPRIATE SIZE FOR THAT new char[0x6F800]; // NEED TO GET THE APPROPRIATE SIZE FOR THAT
byte* mask = new byte[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; unsigned char *mask =
new unsigned char[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
int sheetPosition = 0; int sheetPosition = 0;
// 8x8 tile // 8x8 tile
for (int s = 0; s < Constants::NumberOfSheets; s++) // Per Sheet for (int s = 0; s < Constants::NumberOfSheets; s++) // Per Sheet
{ {
for (int j = 0; j < 4; j++) // Per Tile Line Y for (int j = 0; j < 4; j++) // Per Tile Line Y
{ {
for (int i = 0; i < 16; i++) // Per Tile Line X for (int i = 0; i < 16; i++) // Per Tile Line X
{ {
for (int y = 0; y < 8; y++) // Per Pixel Line for (int y = 0; y < 8; y++) // Per Pixel Line
{ {
if (isbpp3[s]) { if (isbpp3[s]) {
byte lineBits0 = char lineBits0 =
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition]; data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
byte lineBits1 = char lineBits1 =
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition]; data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
byte lineBits2 = char lineBits2 =
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition]; data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
for (int x = 0; x < 4; x++) // Per Pixel X for (int x = 0; x < 4; x++) // Per Pixel X
{ {
byte pixdata = 0; char pixdata = 0;
byte pixdata2 = 0; char pixdata2 = 0;
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) { if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 1; pixdata += 1;
@@ -121,18 +125,18 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
} }
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] = newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
(byte)((pixdata << 4) | pixdata2); (char)((pixdata << 4) | pixdata2);
} }
} else { } else {
byte lineBits0 = char lineBits0 =
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition]; data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
byte lineBits1 = char lineBits1 =
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition]; data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
for (int x = 0; x < 4; x++) // Per Pixel X for (int x = 0; x < 4; x++) // Per Pixel X
{ {
byte pixdata = 0; char pixdata = 0;
byte pixdata2 = 0; char pixdata2 = 0;
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) { if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
pixdata += 1; pixdata += 1;
@@ -149,7 +153,7 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
} }
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] = newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
(byte)((pixdata << 4) | pixdata2); (char)((pixdata << 4) | pixdata2);
} }
} }
} }
@@ -163,14 +167,14 @@ void CreateAllGfxData(byte *romData, byte* allgfx16Ptr) {
} }
} }
byte *allgfx16Data = (byte *) allgfx16Ptr; char *allgfx16Data = (char *)allgfx16Ptr;
for (int i = 0; i < 0x6F800; i++) { for (int i = 0; i < 0x6F800; i++) {
allgfx16Data[i] = newData[i]; allgfx16Data[i] = newData[i];
} }
} }
Bitmap::Bitmap(int width, int height, byte *data) Bitmap::Bitmap(int width, int height, char *data)
: width_(width), height_(height), pixel_data_(data) {} : width_(width), height_(height), pixel_data_(data) {}
void Bitmap::Create(GLuint *out_texture) { void Bitmap::Create(GLuint *out_texture) {
@@ -179,7 +183,7 @@ void Bitmap::Create(GLuint *out_texture) {
// // Create the surface from that RW stream // // Create the surface from that RW stream
// SDL_Surface* surface = SDL_LoadBMP_RW(src, SDL_FALSE); // SDL_Surface* surface = SDL_LoadBMP_RW(src, SDL_FALSE);
// GLenum mode = 0; // GLenum mode = 0;
// Uint8 bpp = surface->format->BytesPerPixel; // Uint8 bpp = surface->format->charsPerPixel;
// Uint32 rm = surface->format->Rmask; // Uint32 rm = surface->format->Rmask;
// if (bpp == 3 && rm == 0x000000ff) mode = GL_RGB; // if (bpp == 3 && rm == 0x000000ff) mode = GL_RGB;
// if (bpp == 3 && rm == 0x00ff0000) mode = GL_BGR; // if (bpp == 3 && rm == 0x00ff0000) mode = GL_BGR;
@@ -221,8 +225,7 @@ bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
// Load from file // Load from file
int image_width = 0; int image_width = 0;
int image_height = 0; int image_height = 0;
if (texture_data == NULL) if (texture_data == NULL) return false;
return false;
// Create a OpenGL texture identifier // Create a OpenGL texture identifier
GLuint image_texture; GLuint image_texture;
@@ -233,9 +236,9 @@ bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE); // This is required on WebGL for non GL_CLAMP_TO_EDGE); // This is required on WebGL for non
// power-of-two textures // power-of-two textures
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
// Upload pixels into texture // Upload pixels into texture
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__) #if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
@@ -251,6 +254,6 @@ bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, GLuint *out_texture,
return true; return true;
} }
} // namespace Graphics } // namespace Graphics
} // namespace Application } // namespace Application
} // namespace yaze } // namespace yaze

View File

@@ -13,13 +13,12 @@ namespace yaze {
namespace Application { namespace Application {
namespace Graphics { namespace Graphics {
using byte = unsigned char;
using namespace Core; using namespace Core;
class Bitmap { class Bitmap {
public: public:
Bitmap() = default; Bitmap() = default;
Bitmap(int width, int height, byte *data); Bitmap(int width, int height, char *data);
void Create(GLuint *out_texture); void Create(GLuint *out_texture);
int GetWidth(); int GetWidth();
@@ -31,14 +30,14 @@ class Bitmap {
private: private:
int width_; int width_;
int height_; int height_;
byte *pixel_data_; char *pixel_data_;
}; };
static bool isbpp3[Constants::NumberOfSheets]; static bool isbpp3[Constants::NumberOfSheets];
int GetPCGfxAddress(byte *romData, byte id); int GetPCGfxAddress(char *romData, char id);
byte *CreateAllGfxDataRaw(byte *romData); char *CreateAllGfxDataRaw(char *romData);
void CreateAllGfxData(byte *romData, byte *allgfx16Ptr); void CreateAllGfxData(char *romData, char *allgfx16Ptr);
} // namespace Graphics } // namespace Graphics
} // namespace Application } // namespace Application

View File

@@ -47,8 +47,7 @@ SNESPalette::SNESPalette(uint8_t mSize) {
} }
SNESPalette::SNESPalette(char* data) { SNESPalette::SNESPalette(char* data) {
// assert((data.size() % 4 == 0) && data.size() <= 32); assert((sizeof(data) % 4 == 0) && (sizeof(data) <= 32));
// size = data.size() / 2;
size = sizeof(data) / 2; size = sizeof(data) / 2;
for (unsigned i = 0; i < sizeof(data); i += 2) { for (unsigned i = 0; i < sizeof(data); i += 2) {
SNESColor col; SNESColor col;

View File

@@ -10,7 +10,6 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
namespace yaze { namespace yaze {
namespace Application { namespace Application {
namespace Graphics { namespace Graphics {
@@ -34,7 +33,6 @@ class SNESPalette {
SNESPalette(std::vector<ImVec4>); SNESPalette(std::vector<ImVec4>);
char* encode(); char* encode();
SDL_Palette* GetSDL_Palette(); SDL_Palette* GetSDL_Palette();
uint8_t size; uint8_t size;

View File

@@ -19,7 +19,6 @@ void Scene::buildSurface(const std::vector<tile8>& tiles, SNESPalette& mPalette,
SDL_PixelFormat* format = newImage->format; SDL_PixelFormat* format = newImage->format;
format->palette = mPalette.GetSDL_Palette(); format->palette = mPalette.GetSDL_Palette();
char* ptr = (char*)newImage->pixels; char* ptr = (char*)newImage->pixels;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {

View File

@@ -13,47 +13,17 @@ namespace yaze {
namespace Application { namespace Application {
namespace Graphics { namespace Graphics {
std::unordered_map<std::string, TilesPattern> TilesPattern::m_Patterns;
ushort TileInfo::toShort() {
ushort value = 0;
// vhopppcc cccccccc
if (over_ == 1) {
value |= 0x2000;
};
if (horizontal_mirror_ == 1) {
value |= 0x4000;
};
if (vertical_mirror_ == 1) {
value |= 0x8000;
};
value |= (ushort)((palette_ << 10) & 0x1C00);
value |= (ushort)(id_ & 0x3FF);
return value;
}
char *hexString(const char *str, const unsigned int size) {
char *toret = (char *)malloc(size * 3 + 1);
unsigned int i;
for (i = 0; i < size; i++) {
sprintf(toret + i * 3, "%02X ", (unsigned char)str[i]);
}
toret[size * 3] = 0;
return toret;
}
TilesPattern::TilesPattern() { TilesPattern::TilesPattern() {
tilesPerRow = 16; tilesPerRow = 16;
numberOfTiles = 16; numberOfTiles = 16;
transformVector.push_back(std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, // std::vector<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9, 11, 12, 13, 14, 15, 16});
11, 12, 13, 14, 15, 16});
// transformVector.push_back(std::vector<int>{0, 1, 2, 3}); transformVector.push_back(std::vector<int>{0, 1, 2, 3});
// transformVector.push_back(std::vector<int>{4, 5, 6, 7}); transformVector.push_back(std::vector<int>{4, 5, 6, 7});
// transformVector.push_back(std::vector<int>{8, 9, 11, 12}); transformVector.push_back(std::vector<int>{8, 9, 11, 12});
// transformVector.push_back(std::vector<int>{13, 14, 15, 16}); transformVector.push_back(std::vector<int>{13, 14, 15, 16});
} }
// [pattern] // [pattern]
// name = "32x32 B (4x4)" // name = "32x32 B (4x4)"
// number_of_tile = 16 // number_of_tile = 16
@@ -97,62 +67,6 @@ void TilesPattern::default_settings() {
std::cout << transformVector.size() << std::endl; std::cout << transformVector.size() << std::endl;
} }
// bool TilesPattern::load(std::string patternFile) {
// QSettings pFile(patternFile, QSettings::IniFormat);
// name = pFile.value("pattern/name").toString();
// description = pFile.value("pattern/description").toString();
// numberOfTiles = pFile.value("pattern/number_of_tile").toInt();
// std::cout << name;
// // unsigned int nbOfTile = pFile.value("_/number_of_tile").toUInt();
// std::string patternString = pFile.value("pattern/pattern").toString();
// std::cout << patternString;
// // Pattern String is a array description
// transformVector.clear();
// QRegExp arrayRegExp("(\\[[\\s|0-F|a-f|,]+\\])");
// int pos = 0;
// while (arrayRegExp.indexIn(patternString, pos) != -1) {
// std::string arrayString = arrayRegExp.cap(1);
// std::vector<int> tmpVect;
// // std::cout << arrayString;
// unsigned int stringPos = 1;
// while (arrayString[stringPos] != ']') {
// while (arrayString[stringPos].isSpace()) stringPos++;
// QRegExp hex("([0-F|a-f]+)");
// bool ok;
// if (hex.indexIn(arrayString, stringPos) == stringPos) {
// tmpVect.append(hex.cap(1).toInt(&ok, 16));
// }
// while (arrayString[stringPos].isSpace()) stringPos++;
// stringPos++; // should be the comma
// }
// pos += arrayRegExp.matchedLength();
// transformVector.append(tmpVect);
// }
// std::cout << transformVector.size() << transformVector;
// return true;
// }
bool TilesPattern::loadPatterns() {
// foreach (std::string fileName, patternDirectory.entryList(QDir::Files)) {
// TilesPattern tp;
// std::cout << "Loading " << fileName;
// if (!tp.load(patternDirectory.absoluteFilePath(fileName))) return false;
// m_Patterns[tp.name] = tp;
// }
return true;
}
TilesPattern TilesPattern::pattern(std::string name) {
return m_Patterns[name];
}
std::unordered_map<std::string, TilesPattern> TilesPattern::Patterns() {
return m_Patterns;
}
std::vector<std::vector<tile8> > TilesPattern::transform( std::vector<std::vector<tile8> > TilesPattern::transform(
const std::vector<tile8> &tiles) const { const std::vector<tile8> &tiles) const {
unsigned int repeatOffsetY = 0; unsigned int repeatOffsetY = 0;
@@ -163,7 +77,7 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
std::vector<std::vector<tile8> > toret; std::vector<std::vector<tile8> > toret;
unsigned int transPerRow = tilesPerRow / tVectWidth; unsigned int transPerRow = tilesPerRow / tVectWidth;
unsigned int nbTransform = tiles.size() / numberOfTiles; unsigned int nbTransform = tiles.size() / numberOfTiles;
printf("Tiles size : %d - nbtransform : %d - pattern number of tiles : %d", printf("Tiles size : %d\nnbtransform : %d\npattern number of tiles : %d\n",
tiles.size(), nbTransform, numberOfTiles); tiles.size(), nbTransform, numberOfTiles);
if (transPerRow > nbTransform) if (transPerRow > nbTransform)
@@ -173,15 +87,11 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
((unsigned int)(((double)nbTransform / (double)transPerRow) + 0.5)) * ((unsigned int)(((double)nbTransform / (double)transPerRow) + 0.5)) *
tVectHeight); tVectHeight);
std::vector<std::vector<tile8> > vec(toret); for (auto &each : toret) {
auto it = vec.begin();
for (auto &each : vec) {
each.resize(tilesPerRow); each.resize(tilesPerRow);
} }
// while (it.hasNext()) {
// it.next().resize(tilesPerRow); std::cout << toret[0].size() << " x " << toret.size();
// }
// std::cout << toret[0].size() << "x" << toret.size();
while (repeat != nbTransform) { while (repeat != nbTransform) {
std::cout << "repeat" << repeat; std::cout << "repeat" << repeat;
for (unsigned int j = 0; j < tVectHeight; j++) { for (unsigned int j = 0; j < tVectHeight; j++) {
@@ -190,7 +100,8 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
unsigned int posX = i + repeatOffsetX; unsigned int posX = i + repeatOffsetX;
unsigned int posY = j + repeatOffsetY; unsigned int posY = j + repeatOffsetY;
printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile); printf("X: %d - Y: %d - posTile : %d", posX, posY, posTile);
toret[posY][posX] = tiles[posTile]; // toret[posY][posX] = tiles[posTile];
toret.at(posY).at(posX) = tiles[posTile];
} }
} }
if (repeatOffsetX + tVectWidth == tilesPerRow) { if (repeatOffsetX + tVectWidth == tilesPerRow) {
@@ -240,21 +151,7 @@ std::vector<std::vector<tile8> > TilesPattern::transform(
return pattern.transform(tiles); return pattern.transform(tiles);
} }
std::vector<std::vector<tile8> > TilesPattern::transform(
const std::string id, const std::vector<tile8> &tiles) {
return m_Patterns[id].transform(tiles);
}
std::vector<tile8> TilesPattern::reverse(const TilesPattern &pattern,
const std::vector<tile8> &tiles) {
return pattern.reverse(tiles);
}
TilePreset::TilePreset() { TilePreset::TilePreset() {
name = "";
romName = "";
romType = "";
pcTilesLocation = -1; pcTilesLocation = -1;
SNESTilesLocation = 0; SNESTilesLocation = 0;
length = 0; length = 0;

View File

@@ -17,6 +17,9 @@ using byte = unsigned char;
using ushort = unsigned short; using ushort = unsigned short;
using uint = unsigned int; using uint = unsigned int;
// vhopppcc cccccccc
// [0, 1]
// [2, 3]
class TileInfo { class TileInfo {
public: public:
ushort id_; ushort id_;
@@ -24,38 +27,24 @@ class TileInfo {
ushort vertical_mirror_; ushort vertical_mirror_;
ushort horizontal_mirror_; ushort horizontal_mirror_;
byte palette_; byte palette_;
TileInfo() {} // vhopppcc cccccccc TileInfo() {}
TileInfo(ushort id, byte palette, ushort v, ushort h, ushort o) TileInfo(ushort id, byte palette, ushort v, ushort h, ushort o)
: id_(id), : id_(id),
palette_(palette), palette_(palette),
vertical_mirror_(v), vertical_mirror_(v),
horizontal_mirror_(h), horizontal_mirror_(h),
over_(o) {} over_(o) {}
ushort toShort();
}; };
class Tile32 { class Tile32 {
public: public:
//[0,1]
//[2,3]
ushort tile0_; ushort tile0_;
ushort tile1_; ushort tile1_;
ushort tile2_; ushort tile2_;
ushort tile3_; ushort tile3_;
Tile32(ushort tile0, ushort tile1, ushort tile2, ushort tile3) Tile32(ushort t0, ushort t1, ushort t2, ushort t3)
: tile0_(tile0), tile1_(tile1), tile2_(tile2), tile3_(tile3) {} : tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {}
explicit Tile32(unsigned long tiles)
: tile0_(tiles),
tile1_(tiles >> 16),
tile2_(tiles >> 32),
tile3_(tiles >> 48) {}
unsigned long getLongValue() {
return ((unsigned long)tile3_ << 48) | ((unsigned long)tile2_ << 32) |
((unsigned long)tile1_ << 16) | (unsigned long)(tile0_);
}
}; };
class Tile16 { class Tile16 {
@@ -65,31 +54,14 @@ class Tile16 {
TileInfo tile2_; TileInfo tile2_;
TileInfo tile3_; TileInfo tile3_;
std::vector<TileInfo> tiles_info; std::vector<TileInfo> tiles_info;
//[0,1]
//[2,3]
Tile16(TileInfo tile0, TileInfo tile1, TileInfo tile2, TileInfo tile3) Tile16(TileInfo t0, TileInfo t1, TileInfo t2, TileInfo t3)
: tile0_(tile0), tile1_(tile1), tile2_(tile2), tile3_(tile3) { : tile0_(t0), tile1_(t1), tile2_(t2), tile3_(t3) {
tiles_info.push_back(tile0_); tiles_info.push_back(tile0_);
tiles_info.push_back(tile1_); tiles_info.push_back(tile1_);
tiles_info.push_back(tile2_); tiles_info.push_back(tile2_);
tiles_info.push_back(tile3_); tiles_info.push_back(tile3_);
} }
explicit Tile16(unsigned long tiles) {
// tile0_ = GFX.gettilesinfo((ushort)tiles);
// tile1_ = GFX.gettilesinfo((ushort)(tiles >> 16));
// tile2_ = GFX.gettilesinfo((ushort)(tiles >> 32));
// tile3_ = GFX.gettilesinfo((ushort)(tiles >> 48));
}
unsigned long getLongValue() {
return ((unsigned long)(tile3_.toShort()) << 48) |
((unsigned long)(tile2_.toShort()) << 32) |
((unsigned long)(tile1_.toShort()) << 16) |
(unsigned long)((tile0_.toShort()));
;
}
}; };
class TilesPattern { class TilesPattern {
@@ -103,24 +75,15 @@ class TilesPattern {
void default_settings(); void default_settings();
static bool loadPatterns();
static TilesPattern pattern(std::string name); static TilesPattern pattern(std::string name);
static std::unordered_map<std::string, TilesPattern> Patterns();
static std::vector<std::vector<tile8> > transform( static std::vector<std::vector<tile8> > transform(
const TilesPattern& pattern, const std::vector<tile8>& tiles); const TilesPattern& pattern, const std::vector<tile8>& tiles);
static std::vector<std::vector<tile8> > transform(
const std::string id, const std::vector<tile8>& tiles);
static std::vector<tile8> reverse(const TilesPattern& pattern,
const std::vector<tile8>& tiles);
protected: protected:
std::vector<std::vector<tile8> > transform( std::vector<std::vector<tile8> > transform(
const std::vector<tile8>& tiles) const; const std::vector<tile8>& tiles) const;
std::vector<tile8> reverse(const std::vector<tile8>& tiles) const; std::vector<tile8> reverse(const std::vector<tile8>& tiles) const;
std::vector<std::vector<int> > transformVector; std::vector<std::vector<int> > transformVector;
private:
static std::unordered_map<std::string, TilesPattern> m_Patterns;
}; };
class TilePreset { class TilePreset {
@@ -130,19 +93,15 @@ class TilePreset {
bool save(const std::string& file); bool save(const std::string& file);
bool load(const std::string& file); bool load(const std::string& file);
std::string name;
std::string romName;
std::string romType;
TilesPattern tilesPattern;
unsigned int SNESTilesLocation;
int pcTilesLocation;
unsigned int SNESPaletteLocation;
unsigned int pcPaletteLocation;
bool paletteNoZeroColor; bool paletteNoZeroColor;
unsigned int length; int pcTilesLocation;
uint16_t SNESTilesLocation;
uint16_t SNESPaletteLocation;
uint32_t pcPaletteLocation;
uint32_t length;
uint32_t bpp;
unsigned int bpp; TilesPattern tilesPattern;
std::string compression; std::string compression;
}; };

View File

@@ -1,73 +0,0 @@
#include "Compression.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstddef>
#include <iostream>
#include <memory>
#include <vector>
#include "compressions/alttpcompression.h"
#include "compressions/stdnintendo.h"
#define INITIAL_ALLOC_SIZE 1024
#define D_CMD_COPY 0
#define D_CMD_BYTE_REPEAT 1
#define D_CMD_WORD_REPEAT 2
#define D_CMD_BYTE_INC 3
#define D_CMD_COPY_EXISTING 4
#define D_MAX_NORMAL_length 32
#define D_max_length 1024
#define D_NINTENDO_C_MODE1 0
#define D_NINTENDO_C_MODE2 1
#define X_ std::byte {
#define _X }
#define MY_BUILD_HEADER(command, length) (command << 5) + ((length)-1)
namespace yaze {
namespace Application {
namespace Utils {
char* ALTTPCompression::DecompressGfx(const char* c_data,
const unsigned int start,
unsigned int max_length,
unsigned int* uncompressed_data_size,
unsigned int* compressed_length) {
char* data = alttp_decompress_gfx(c_data, start, max_length,
uncompressed_data_size, compressed_length);
return data;
}
char* ALTTPCompression::DecompressOverworld(
const char* c_data, const unsigned int start, unsigned int max_length,
unsigned int* uncompressed_data_size, unsigned int* compressed_length) {
char* toret = alttp_decompress_overworld(
c_data, start, max_length, uncompressed_data_size, compressed_length);
return toret;
}
char* ALTTPCompression::CompressGfx(const char* u_data,
const unsigned int start,
const unsigned int length,
unsigned int* compressed_size) {
return alttp_compress_gfx(u_data, start, length, compressed_size);
}
char* ALTTPCompression::CompressOverworld(const char* u_data,
const unsigned int start,
const unsigned int length,
unsigned int* compressed_size) {
return alttp_compress_overworld(u_data, start, length, compressed_size);
}
} // namespace Utils
} // namespace Application
} // namespace yaze

View File

@@ -1,40 +0,0 @@
#ifndef YAZE_APPLICATION_UTILS_COMPRESSION_H
#define YAZE_APPLICATION_UTILS_COMPRESSION_H
#include <cstddef>
#include <cstdlib>
#include <string>
#include <vector>
namespace yaze {
namespace Application {
namespace Utils {
class ALTTPCompression {
public:
char* DecompressGfx(const char* c_data, const unsigned int start,
unsigned int max_length,
unsigned int* uncompressed_data_size,
unsigned int* compressed_length);
char* DecompressOverworld(const char* c_data, const unsigned int start,
unsigned int max_length,
unsigned int* uncompressed_data_size,
unsigned int* compressed_length);
char* CompressGfx(const char* u_data, const unsigned int start,
const unsigned int length, unsigned int* compressed_size);
char* CompressOverworld(const char* u_data, const unsigned int start,
const unsigned int length,
unsigned int* compressed_size);
private:
std::string compression_error_;
std::string decompression_error_;
};
} // namespace Utils
} // namespace Application
} // namespace yaze
#endif

View File

@@ -20,7 +20,7 @@ void ROM::LoadFromFile(const std::string &path) {
// Reading data to array of unsigned chars // Reading data to array of unsigned chars
file = fopen(path.c_str(), "r+"); file = fopen(path.c_str(), "r+");
current_rom_ = (unsigned char *)malloc(size); current_rom_ = (unsigned char *)malloc(size);
rom_data_ = (char *) malloc(size); rom_data_ = (char *)malloc(size);
fread(rom_data_, sizeof(char), size, file); fread(rom_data_, sizeof(char), size, file);
int bytes_read = fread(current_rom_, sizeof(unsigned char), size, file); int bytes_read = fread(current_rom_, sizeof(unsigned char), size, file);
fclose(file); fclose(file);
@@ -33,38 +33,66 @@ void ROM::LoadFromFile(const std::string &path) {
std::vector<tile8> ROM::ExtractTiles(TilePreset &preset) { std::vector<tile8> ROM::ExtractTiles(TilePreset &preset) {
std::cout << "Begin ROM::ExtractTiles" << std::endl; std::cout << "Begin ROM::ExtractTiles" << std::endl;
std::vector<tile8> rawTiles;
uint filePos = 0;
unsigned int size = preset.length;
filePos =
getRomPosition(preset, preset.pcTilesLocation, preset.SNESTilesLocation);
char *data = (char *)rom_data_ + filePos;
memcpy(data, rom_data_ + filePos, preset.length);
data = uint filePos = 0;
alttp_decompress_gfx(data, 0, preset.length, &size, &lastCompressedSize); uint size_out = 0;
uint size = preset.length;
int tilePos = preset.pcTilesLocation;
std::vector<tile8> rawTiles;
filePos = getRomPosition(preset, tilePos, preset.SNESTilesLocation);
// decompress the graphics
char *data = (char *)malloc(sizeof(char) * size);
memcpy(data, (rom_data_ + filePos), size);
data = alttp_decompress_gfx(data, 0, size, &size_out, &lastCompressedSize);
std::cout << "size: " << size << std::endl; std::cout << "size: " << size << std::endl;
std::cout << "lastCompressedSize: " << lastCompressedSize << std::endl; std::cout << "lastCompressedSize: " << lastCompressedSize << std::endl;
if (data == NULL) { if (data == NULL) {
std:: cout << alttp_decompression_error << std::endl; std::cout << alttp_decompression_error << std::endl;
return rawTiles; return rawTiles;
} }
// unpack the tiles based on their depth
unsigned tileCpt = 0; unsigned tileCpt = 0;
std::cout << "Unpacking tiles..." << std::endl;
for (unsigned int tilePos = 0; tilePos < size; tilePos += preset.bpp * 8) { for (unsigned int tilePos = 0; tilePos < size; tilePos += preset.bpp * 8) {
std::cout << "Unpacking tile..." << std::endl;
tile8 newTile = unpack_bpp_tile(data, tilePos, preset.bpp); tile8 newTile = unpack_bpp_tile(data, tilePos, preset.bpp);
newTile.id = tileCpt; newTile.id = tileCpt;
rawTiles.push_back(newTile); rawTiles.push_back(newTile);
tileCpt++; tileCpt++;
} }
free(data);
std::cout << "End ROM::ExtractTiles" << std::endl; std::cout << "End ROM::ExtractTiles" << std::endl;
free(data);
return rawTiles; return rawTiles;
} }
SNESPalette ROM::ExtractPalette(TilePreset &preset) {
unsigned int filePos = getRomPosition(preset, preset.pcPaletteLocation,
preset.SNESPaletteLocation);
std::cout << "Palette pos : " << filePos << std::endl; // TODO: make this hex
unsigned int palette_size = pow(2, preset.bpp); // - 1;
char *ab = (char *)malloc(sizeof(char) * (palette_size * 2));
memcpy(ab, rom_data_ + filePos, palette_size * 2);
for (int i = 0; i < palette_size; i++) {
std::cout << ab[i];
}
std::cout << std::endl;
const char *data = ab;
SNESPalette pal(ab);
if (preset.paletteNoZeroColor) {
SNESColor col;
col.setRgb(ImVec4(153, 153, 153, 255));
pal.colors.push_back(col);
pal.colors.erase(pal.colors.begin(),
pal.colors.begin() + pal.colors.size() - 1);
}
return pal;
}
unsigned int ROM::getRomPosition(const TilePreset &preset, int directAddr, unsigned int ROM::getRomPosition(const TilePreset &preset, int directAddr,
unsigned int snesAddr) { unsigned int snesAddr) {
bool romHasHeader = false; // romInfo.hasHeader bool romHasHeader = false; // romInfo.hasHeader
@@ -82,14 +110,6 @@ unsigned int ROM::getRomPosition(const TilePreset &preset, int directAddr,
return filePos; return filePos;
} }
int ROM::SnesToPc(int addr) {
if (addr >= 0x808000) {
addr -= 0x808000;
}
int temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000);
return (temp + 0x0);
}
int AddressFromBytes(byte addr1, byte addr2, byte addr3) { int AddressFromBytes(byte addr1, byte addr2, byte addr3) {
return (addr1 << 16) | (addr2 << 8) | addr3; return (addr1 << 16) | (addr2 << 8) | addr3;
} }
@@ -98,38 +118,6 @@ short ROM::AddressFromBytes(byte addr1, byte addr2) {
return (short)((addr1 << 8) | (addr2)); return (short)((addr1 << 8) | (addr2));
} }
void ROM::Write(int addr, byte value) { current_rom_[addr] = value; }
void ROM::WriteLong(int addr, int value) {
current_rom_[addr] = (byte)(value & 0xFF);
current_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
current_rom_[addr + 2] = (byte)((value >> 16) & 0xFF);
}
void ROM::WriteShort(int addr, int value) {
current_rom_[addr] = (byte)(value & 0xFF);
current_rom_[addr + 1] = (byte)((value >> 8) & 0xFF);
}
int ROM::ReadLong(int addr) {
return ((current_rom_[addr + 2] << 16) + (current_rom_[addr + 1] << 8) +
current_rom_[addr]);
}
ushort ROM::ReadShort(int addr) {
return (ushort)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
}
short ROM::ReadRealShort(int addr) {
return (short)((current_rom_[addr + 1] << 8) + current_rom_[addr]);
}
ushort ROM::ReadByte(int addr) { return (ushort)(current_rom_[addr]); }
short ROM::ReadReverseShort(int addr) {
return (short)((current_rom_[addr] << 8) + current_rom_[addr + 1]);
}
} // namespace Utils } // namespace Utils
} // namespace Application } // namespace Application
} // namespace yaze } // namespace yaze

View File

@@ -9,7 +9,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "Compression.h"
#include "Core/Constants.h" #include "Core/Constants.h"
#include "Graphics/Tile.h" #include "Graphics/Tile.h"
#include "compressions/alttpcompression.h" #include "compressions/alttpcompression.h"
@@ -32,25 +32,14 @@ class ROM {
public: public:
void LoadFromFile(const std::string& path); void LoadFromFile(const std::string& path);
std::vector<tile8> ExtractTiles(TilePreset& preset); std::vector<tile8> ExtractTiles(TilePreset& preset);
SNESPalette ExtractPalette(TilePreset& preset);
unsigned int getRomPosition(const TilePreset& preset, int directAddr, unsigned int getRomPosition(const TilePreset& preset, int directAddr,
unsigned int snesAddr); unsigned int snesAddr);
int SnesToPc(int addr);
short AddressFromBytes(byte addr1, byte addr2); short AddressFromBytes(byte addr1, byte addr2);
ushort ReadShort(int addr);
void Write(int addr, byte value);
short ReadReverseShort(int addr);
ushort ReadByte(int addr);
short ReadRealShort(int addr);
void WriteShort(int addr, int value);
int ReadLong(int addr);
void WriteLong(int addr, int value);
inline byte* GetRawData() { return current_rom_; } inline byte* GetRawData() { return current_rom_; }
const unsigned char* getTitle() const { return title; } const unsigned char* getTitle() const { return title; }
unsigned int getSize() const { return size; } unsigned int getSize() const { return size; }
char getVersion() const { return version; } char getVersion() const { return version; }
bool isLoaded() const { return loaded; } bool isLoaded() const { return loaded; }
private: private:
@@ -62,14 +51,14 @@ class ROM {
bool fastrom; bool fastrom;
long int size; long int size;
enum rom_type type; enum rom_type type;
unsigned char title[21] = "ROM Not Loaded";
unsigned char version;
bool overrideHeaderInfo; bool overrideHeaderInfo;
bool overridenHeaderInfo; bool overridenHeaderInfo;
unsigned int lastUnCompressSize; unsigned int lastUnCompressSize;
unsigned int lastCompressedSize; unsigned int lastCompressedSize;
unsigned int lastCompressSize; unsigned int lastCompressSize;
unsigned char version;
unsigned char title[21] = "ROM Not Loaded";
}; };
} // namespace Utils } // namespace Utils

View File

@@ -45,7 +45,6 @@ add_executable(
Application/Graphics/Scene.cc Application/Graphics/Scene.cc
Application/Editor/Editor.cc Application/Editor/Editor.cc
Application/Editor/OverworldEditor.cc Application/Editor/OverworldEditor.cc
Application/Utils/Compression.cc
Application/Utils/ROM.cc Application/Utils/ROM.cc
# GUI libraries # GUI libraries
${IMGUI_PATH}/imgui.cpp ${IMGUI_PATH}/imgui.cpp
@@ -64,6 +63,7 @@ add_executable(
${SNESHACKING_PATH}/tilepng.c ${SNESHACKING_PATH}/tilepng.c
${SNESHACKING_PATH}/palette.c ${SNESHACKING_PATH}/palette.c
${SNESHACKING_PATH}/rommapping.c ${SNESHACKING_PATH}/rommapping.c
${SNESHACKING_PATH}/mapping_lorom.c
) )
target_include_directories( target_include_directories(