7#include <unordered_map>
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
25 : index_(index), parent_(index), rom_(rom), game_data_(game_data) {
71 std::vector<gfx::Tile16>& tiles16,
79 int count,
int game_state,
int world, std::vector<gfx::Tile16>& tiles16,
81 const std::vector<uint8_t>* cached_tileset) {
102 }
else if (
index_ == 0x88) {
120 if (cached_tileset && !cached_tileset->empty()) {
131 return absl::OkStatus();
299 }
else if (
index_ == 0x80) {
315 }
else if (
index_ == 0x94) {
320 }
else if (
index_ == 0x95) {
324 }
else if (
index_ == 0x96) {
328 }
else if (
index_ == 0x9C) {
394 int index_world = 0x20;
405 for (
int i = 0; i < 8; i++) {
407 (uint8_t)(*
rom_)[overworld_gfx_groups2 + (index_world * 8) + i];
413 uint8_t temp = (*rom_)[overworldgfxGroups + (
area_graphics_ * 4)];
471 }
else if (
index_ == 0x80) {
528 (mosaicByte & 0x04) != 0x00,
529 (mosaicByte & 0x02) != 0x00,
530 (mosaicByte & 0x01) != 0x00};
577 for (
int i = 0; i < 8; i++) {
583 int index_world = 0x20;
592 for (
int i = 0; i < 8; i++) {
595 (index_world * 8) + i];
598 const auto overworldgfxGroups =
604 uint8_t temp = (*rom_)[overworldgfxGroups + (
area_graphics_ * 4)];
658 }
else if (
index_ == 0x80) {
661 }
else if (
index_ == 0x88) {
687 int static_graphics_base = 0x73;
693 for (
int i = 0; i < 4; i++) {
697 static_graphics_base);
702 for (
int i = 0; i < 8; i++) {
727 for (
int i = 0; i < 4; i++) {
759 for (
int i = 0; i < 8; i++) {
761 if (custom_sheet == 0x00 || custom_sheet == 0xFF) {
769namespace palette_internal {
781 std::array<gfx::SnesColor, 256> new_palette = {};
785 for (
int y = 2; y < 7; y++) {
786 for (
int x = 1; x < 8; x++) {
787 new_palette[x + (16 * y)] =
main[k];
793 for (
int x = 1; x < 8; x++) {
794 new_palette[(16 * 7) + (x)] = animated[(x - 1)];
801 for (
int y = 2; y < 5; y++) {
802 for (
int x = 9; x < 16; x++) {
803 new_palette[x + (16 * y)] = aux1[k];
810 for (
int y = 5; y < 8; y++) {
811 for (
int x = 9; x < 16; x++) {
812 new_palette[x + (16 * y)] = aux2[k];
818 for (
int i = 0; i < 32; i++) {
819 new_palette[i] = hud[i];
823 for (
int i = 0; i < 8; i++) {
824 new_palette[(i * 16)] = bgrcolor;
825 new_palette[(i * 16) + 8] = bgrcolor;
830 for (
int y = 8; y < 9; y++) {
831 for (
int x = 1; x < 8; x++) {
839 for (
int y = 8; y < 9; y++) {
840 for (
int x = 9; x < 16; x++) {
848 for (
int y = 9; y < 13; y++) {
849 for (
int x = 1; x < 16; x++) {
857 for (
int y = 13; y < 14; y++) {
858 for (
int x = 1; x < 8; x++) {
859 new_palette[x + (16 * y)] = spr[k];
866 for (
int y = 14; y < 15; y++) {
867 for (
int x = 1; x < 8; x++) {
868 new_palette[x + (16 * y)] = spr2[k];
875 for (
int y = 15; y < 16; y++) {
876 for (
int x = 1; x < 16; x++) {
882 for (
int i = 0; i < 256; i++) {
883 current[i] = new_palette[i];
884 current[(i / 16) * 16].set_transparent(
true);
888 return absl::OkStatus();
897 (previous_index * 4)];
899 if (index >= limit) {
902 return palette_group[index];
908 return absl::OkStatus();
914 int previous_pal_id = 0;
915 int previous_spr_pal_id = 0;
944 auto bgr = grass_pal_group[0][0];
949 (previous_pal_id * 4)];
954 (previous_pal_id * 4) + 1];
959 (previous_pal_id * 4) + 2];
964 GetPalette(ow_aux_pal_group, pal1, previous_pal_id, 20));
966 GetPalette(ow_aux_pal_group, pal2, previous_pal_id, 20));
969 bool use_area_specific_bg =
972 if (use_area_specific_bg) {
983 bgr = grass_pal_group[0][0];
986 bgr = grass_pal_group[0][1];
988 bgr = grass_pal_group[0][2];
1001 GetPalette(ow_main_pal_group, pal0, previous_pal_id, 255));
1004 GetPalette(ow_animated_pal_group, std::min((
int)pal3, 13),
1005 previous_pal_id, 14));
1030 previous_spr_pal_id, 24));
1033 previous_spr_pal_id, 24));
1037 hud, bgr, spr, spr2));
1044 return absl::OkStatus();
1058 return absl::OkStatus();
1069 address = ((address & 0x7F0000) >> 1) | (address & 0x7FFF);
1077 address = ((address & 0x7F0000) >> 1) | (address & 0x7FFF);
1085 return absl::OkStatus();
1090 uint8_t b = (*rom_)[address];
1093 while (b != 0x60 && address < rom_->size()) {
1165 if (address < rom_->size()) {
1166 b = (*rom_)[address];
1181 return absl::OkStatus();
1185 int size,
const uint8_t* all_gfx) {
1187 int max_offset = static_graphics_offset * size + size;
1190 for (
int i = 0; i < size; i++) {
1196 for (
int i = 0; i < size; i++) {
1197 auto byte = all_gfx[i + (static_graphics_offset * size)];
1216 return absl::OkStatus();
1220 for (
int i = 0; i < 8; i++) {
1228 for (
int i = 8; i < 16; i++) {
1241 return absl::OkStatus();
1249 const int offsets[] = {0x00, 0x08, 0x400, 0x408};
1253 for (
auto i = 0; i < count; i++) {
1254 for (
auto tile = 0; tile < 0x04; tile++) {
1256 int offset = offsets[tile];
1257 for (
auto y = 0; y < 0x08; ++y) {
1258 for (
auto x = 0; x < 0x08; ++x) {
1270 int xpos = ((info.
id_ % 0x10) * 0x08);
1271 int ypos = (((info.
id_ / 0x10)) * 0x400);
1272 int source = ypos + xpos + (x + (y * 0x80));
1274 auto destination = xx + yy + offset + (mx + (my * 0x80));
1288 return absl::OkStatus();
1296 for (
int i = 0; i < 0x40000; i++) {
1301 int superX =
index_ - (
world_ * 0x40) - (superY * 0x08);
1303 for (
int y = 0; y < 0x20; y++) {
1304 for (
int x = 0; x < 0x20; x++) {
1305 auto xt = x + (superX * 0x20);
1306 auto yt = y + (superY * 0x20);
1311 return absl::OkStatus();
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
static std::unordered_map< uint8_t, gfx::Paletteset > palettesets_
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void set_size(size_t size)
SNES 16-bit tile metadata container.
void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size, const uint8_t *all_gfx)
zelda3_version_pointers version_constants() const
std::vector< uint8_t > current_gfx_
std::vector< uint8_t > current_blockset_
std::array< bool, 4 > mosaic_expanded_
absl::Status LoadVanillaOverlayData()
std::vector< uint8_t > bitmap_data_
absl::Status LoadOverlay()
absl::Status BuildMapWithCache(int count, int game_state, int world, std::vector< gfx::Tile16 > &tiles16, OverworldBlockset &world_blockset, const std::vector< uint8_t > *cached_tileset)
Build map with optional cached tileset for performance.
void SetupCustomTileset(uint8_t asm_version)
absl::StatusOr< gfx::SnesPalette > GetPalette(const gfx::PaletteGroup &group, int index, int previous_index, int limit)
absl::Status BuildTiles16Gfx(std::vector< gfx::Tile16 > &tiles16, int count)
absl::Status BuildMap(int count, int game_state, int world, std::vector< gfx::Tile16 > &tiles16, OverworldBlockset &world_blockset)
std::array< uint8_t, 3 > sprite_graphics_
void LoadAreaGraphicsBlocksets()
absl::Status BuildTileset()
void LoadDeathMountainGFX()
uint8_t ComputeWorldBasedMainPalette() const
absl::Status BuildBitmap(OverworldBlockset &world_blockset)
std::array< uint8_t, 3 > sprite_palette_
std::array< uint8_t, 4 > area_music_
std::array< uint8_t, 16 > static_graphics_
uint16_t subscreen_overlay_
std::array< uint8_t, 8 > custom_gfx_ids_
absl::Status LoadPalette()
void LoadMainBlocksetId()
std::vector< uint8_t > overlay_data_
void UseCachedTileset(const std::vector< uint8_t > &cached_gfx)
Use a pre-computed tileset from cache instead of rebuilding.
gfx::SnesPalette current_palette_
void LoadCustomOverworldData()
void LoadSpritesBlocksets()
uint16_t area_specific_bg_color_
static bool SupportsCustomBGColors(OverworldVersion version)
Check if ROM supports custom background colors per area (v2+)
static OverworldVersion GetVersion(const Rom &rom)
Detect ROM version from ASM marker byte.
static uint8_t GetAsmVersion(const Rom &rom)
Get raw ASM version byte from ROM.
static bool SupportsAreaEnum(OverworldVersion version)
Check if ROM supports area enum system (v3+ only)
static bool SupportsCustomTileGFX(OverworldVersion version)
Check if ROM supports custom tile GFX groups (v3+)
int main(int argc, char **argv)
struct destination destination
Room transition destination.
#define ASSIGN_OR_RETURN(type_variable_name, expression)
void CopyTile8bpp16(int x, int y, int tile, std::vector< uint8_t > &bitmap, std::vector< uint8_t > &blockset)
absl::Status SetColorsPalette(Rom &rom, GameData *game_data, int index, gfx::SnesPalette ¤t, gfx::SnesPalette main, gfx::SnesPalette animated, gfx::SnesPalette aux1, gfx::SnesPalette aux2, gfx::SnesPalette hud, gfx::SnesColor bgrcolor, gfx::SnesPalette spr, gfx::SnesPalette spr2)
Zelda 3 specific classes and functions.
constexpr int kAreaGfxIdPtr
constexpr int OverworldCustomTileGFXGroupEnabled
constexpr int OverworldCustomAreaSpecificBGEnabled
constexpr int kOverworldSpritePaletteGroup
constexpr int kOverworldSpriteset
constexpr int kOverworldScreenSize
constexpr int kOverlayData1
constexpr int kSpecialWorldMapIdStart
constexpr int OverworldCustomMosaicArray
constexpr int OverworldCustomAnimatedGFXEnabled
constexpr int OverworldCustomMainPaletteEnabled
constexpr int kNumOverworldMaps
constexpr int OverworldCustomMainPaletteArray
constexpr int kOverworldSpecialSpritePaletteExpandedTemp
constexpr int kOverworldMapParentIdExpanded
constexpr int kOverworldSpecialSpriteGfxGroupExpandedTemp
constexpr int kOverworldMusicBeginning
std::vector< std::vector< uint16_t > > OverworldBlockset
Represents tile32 data for the overworld.
AreaSizeEnum
Area size enumeration for v3+ ROMs.
constexpr int kOverworldMusicDarkWorld
constexpr int kOverlayPointersBank
constexpr int kOverworldSpecialPalGroup
constexpr int kOverworldSpritePaletteIds
constexpr int OverworldCustomASMHasBeenApplied
constexpr int kOverworldMusicAgahnim
constexpr int kOverworldMapParentId
@ kZSCustomV2
Parent system, BG colors, main palettes.
@ kVanilla
0xFF in ROM, no ZScream ASM applied
@ kZSCustomV3
Area enum, wide/tall areas, all features.
constexpr int kOverworldPalettesScreenToSetNew
constexpr int kOverworldMessagesExpanded
constexpr int kOverworldMusicMasterSword
constexpr int kOverworldMusicZelda
constexpr int kOverworldMessageIds
constexpr int kOverlayData2
constexpr int OverworldCustomAnimatedGFXArray
constexpr int kDarkWorldMapIdStart
constexpr int OverworldCustomMosaicEnabled
constexpr int OverworldCustomTileGFXGroupArray
constexpr int OverworldCustomSubscreenOverlayEnabled
constexpr int OverworldCustomAreaSpecificBGPalette
constexpr int kOverlayPointers
constexpr int kOverworldMapPaletteIds
constexpr int kOverworldSpecialGfxGroup
constexpr int OverworldCustomSubscreenOverlayArray
#define RETURN_IF_ERROR(expr)
Room transition destination.
PaletteGroup overworld_main
PaletteGroup overworld_aux
PaletteGroup sprites_aux1
PaletteGroup overworld_animated
PaletteGroup sprites_aux3
PaletteGroup global_sprites
Represents a group of palettes.
Represents a set of palettes used in a SNES graphics system.
gfx::PaletteGroupMap palette_groups
std::vector< uint8_t > graphics_buffer
uint32_t kOverworldMapPaletteGroup
uint32_t kOverworldGfxGroups1
uint32_t kSpriteBlocksetPointer
uint32_t kOverworldGfxGroups2