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) {
96 }
else if (
index_ == 0x88) {
113 if (cached_tileset && !cached_tileset->empty()) {
124 return absl::OkStatus();
292 }
else if (
index_ == 0x80) {
308 }
else if (
index_ == 0x94) {
313 }
else if (
index_ == 0x95) {
317 }
else if (
index_ == 0x96) {
321 }
else if (
index_ == 0x9C) {
387 int index_world = 0x20;
398 for (
int i = 0; i < 8; i++) {
400 (uint8_t)(*
rom_)[overworld_gfx_groups2 + (index_world * 8) + i];
406 uint8_t temp = (*rom_)[overworldgfxGroups + (
area_graphics_ * 4)];
464 }
else if (
index_ == 0x80) {
521 (mosaicByte & 0x04) != 0x00,
522 (mosaicByte & 0x02) != 0x00,
523 (mosaicByte & 0x01) != 0x00};
570 for (
int i = 0; i < 8; i++) {
576 int index_world = 0x20;
585 for (
int i = 0; i < 8; i++) {
588 (index_world * 8) + i];
591 const auto overworldgfxGroups =
597 uint8_t temp = (*rom_)[overworldgfxGroups + (
area_graphics_ * 4)];
651 }
else if (
index_ == 0x80) {
654 }
else if (
index_ == 0x88) {
680 int static_graphics_base = 0x73;
686 for (
int i = 0; i < 4; i++) {
690 static_graphics_base);
695 for (
int i = 0; i < 8; i++) {
720 for (
int i = 0; i < 4; i++) {
752 for (
int i = 0; i < 8; i++) {
754 if (custom_sheet == 0x00 || custom_sheet == 0xFF) {
762namespace palette_internal {
774 std::array<gfx::SnesColor, 256> new_palette = {};
778 for (
int y = 2; y < 7; y++) {
779 for (
int x = 1; x < 8; x++) {
780 new_palette[x + (16 * y)] =
main[k];
786 for (
int x = 1; x < 8; x++) {
787 new_palette[(16 * 7) + (x)] = animated[(x - 1)];
794 for (
int y = 2; y < 5; y++) {
795 for (
int x = 9; x < 16; x++) {
796 new_palette[x + (16 * y)] = aux1[k];
803 for (
int y = 5; y < 8; y++) {
804 for (
int x = 9; x < 16; x++) {
805 new_palette[x + (16 * y)] = aux2[k];
811 for (
int i = 0; i < 32; i++) {
812 new_palette[i] = hud[i];
816 for (
int i = 0; i < 8; i++) {
817 new_palette[(i * 16)] = bgrcolor;
818 new_palette[(i * 16) + 8] = bgrcolor;
823 for (
int y = 8; y < 9; y++) {
824 for (
int x = 1; x < 8; x++) {
832 for (
int y = 8; y < 9; y++) {
833 for (
int x = 9; x < 16; x++) {
841 for (
int y = 9; y < 13; y++) {
842 for (
int x = 1; x < 16; x++) {
850 for (
int y = 13; y < 14; y++) {
851 for (
int x = 1; x < 8; x++) {
852 new_palette[x + (16 * y)] = spr[k];
859 for (
int y = 14; y < 15; y++) {
860 for (
int x = 1; x < 8; x++) {
861 new_palette[x + (16 * y)] = spr2[k];
868 for (
int y = 15; y < 16; y++) {
869 for (
int x = 1; x < 16; x++) {
875 for (
int i = 0; i < 256; i++) {
876 current[i] = new_palette[i];
877 current[(i / 16) * 16].set_transparent(
true);
881 return absl::OkStatus();
890 (previous_index * 4)];
892 if (index >= limit) {
895 return palette_group[index];
902 int previous_pal_id = 0;
903 int previous_spr_pal_id = 0;
932 auto bgr = grass_pal_group[0][0];
937 (previous_pal_id * 4)];
942 (previous_pal_id * 4) + 1];
947 (previous_pal_id * 4) + 2];
952 GetPalette(ow_aux_pal_group, pal1, previous_pal_id, 20));
954 GetPalette(ow_aux_pal_group, pal2, previous_pal_id, 20));
957 bool use_area_specific_bg =
960 if (use_area_specific_bg) {
971 bgr = grass_pal_group[0][0];
974 bgr = grass_pal_group[0][1];
976 bgr = grass_pal_group[0][2];
989 GetPalette(ow_main_pal_group, pal0, previous_pal_id, 255));
992 GetPalette(ow_animated_pal_group, std::min((
int)pal3, 13),
993 previous_pal_id, 14));
1018 previous_spr_pal_id, 24));
1021 previous_spr_pal_id, 24));
1025 hud, bgr, spr, spr2));
1032 return absl::OkStatus();
1046 return absl::OkStatus();
1057 address = ((address & 0x7F0000) >> 1) | (address & 0x7FFF);
1065 address = ((address & 0x7F0000) >> 1) | (address & 0x7FFF);
1073 return absl::OkStatus();
1078 uint8_t b = (*rom_)[address];
1081 while (b != 0x60 && address < rom_->size()) {
1153 if (address < rom_->size()) {
1154 b = (*rom_)[address];
1169 return absl::OkStatus();
1173 int size,
const uint8_t* all_gfx) {
1175 int max_offset = static_graphics_offset * size + size;
1178 for (
int i = 0; i < size; i++) {
1184 for (
int i = 0; i < size; i++) {
1185 auto byte = all_gfx[i + (static_graphics_offset * size)];
1203 return absl::FailedPreconditionError(
"GameData not set");
1207 for (
int i = 0; i < 8; i++) {
1215 for (
int i = 8; i < 16; i++) {
1228 return absl::OkStatus();
1236 const int offsets[] = {0x00, 0x08, 0x400, 0x408};
1240 for (
auto i = 0; i < count; i++) {
1241 for (
auto tile = 0; tile < 0x04; tile++) {
1243 int offset = offsets[tile];
1244 for (
auto y = 0; y < 0x08; ++y) {
1245 for (
auto x = 0; x < 0x08; ++x) {
1257 int xpos = ((info.
id_ % 0x10) * 0x08);
1258 int ypos = (((info.
id_ / 0x10)) * 0x400);
1259 int source = ypos + xpos + (x + (y * 0x80));
1261 auto destination = xx + yy + offset + (mx + (my * 0x80));
1275 return absl::OkStatus();
1283 for (
int i = 0; i < 0x40000; i++) {
1288 int superX =
index_ - (
world_ * 0x40) - (superY * 0x08);
1290 for (
int y = 0; y < 0x20; y++) {
1291 for (
int x = 0; x < 0x20; x++) {
1292 auto xt = x + (superX * 0x20);
1293 auto yt = y + (superY * 0x20);
1298 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