5#include <unordered_map>
25 if (asm_version == 0x00) {
34 std::vector<gfx::Tile16> &tiles16,
45 }
else if (
index_ == 0x88) {
63 return absl::OkStatus();
81 util::logf(
"Error reading message id for map %d",
parent_);
125 }
else if (
index_ == 0x95) {
127 }
else if (
index_ == 0x96) {
129 }
else if (
index_ == 0x97) {
131 }
else if (
index_ == 0x9C) {
133 }
else if (
index_ == 0x9D) {
135 }
else if (
index_ == 0x9E) {
137 }
else if (
index_ == 0x9F) {
139 }
else if (
index_ == 0x88) {
154 }
else if (
index_ == 0x88) {
194 }
else if (
index_ == 0x88) {
203 int index_world = 0x20;
214 const auto overworld_gfx_groups2 =
215 rom_->version_constants().kOverworldGfxGroups2;
218 for (
int i = 0; i < 8; i++) {
220 (uint8_t)(*
rom_)[overworld_gfx_groups2 + (index_world * 8) + i];
223 const auto overworldgfxGroups =
224 rom_->version_constants().kOverworldGfxGroups1;
226 uint8_t temp = (*rom_)[overworldgfxGroups + (
area_graphics_ * 4)];
278 }
else if (
index_ == 0x5B)
282 }
else if (
index_ == 0x80)
310 }
else if (
index_ == 0x88)
348 mosaic_expanded_ = {(mosaicByte & 0x08) != 0x00, (mosaicByte & 0x04) != 0x00,
349 (mosaicByte & 0x02) != 0x00, (mosaicByte & 0x01) != 0x00};
353 if (asm_version >= 0x01 && asm_version != 0xFF) {
354 for (
int i = 0; i < 8; i++) {
361 int index_world = 0x20;
373 for (
int i = 0; i < 8; i++) {
375 (uint8_t)(*
rom_)[
rom_->version_constants().kOverworldGfxGroups2 +
376 (index_world * 8) + i];
379 const auto overworldgfxGroups =
380 rom_->version_constants().kOverworldGfxGroups1;
385 uint8_t temp = (*rom_)[overworldgfxGroups + (
area_graphics_ * 4)];
438 int static_graphics_base = 0x73;
444 for (
int i = 0; i < 4; i++) {
446 ((*rom_)[
rom_->version_constants().kSpriteBlocksetPointer +
448 static_graphics_base);
453 for (
int i = 0; i < 8; i++) {
455 (*rom_)[
rom_->version_constants().kOverworldGfxGroups2 +
478 for (
int i = 0; i < 4; i++) {
479 uint8_t value = (*rom_)[
rom_->version_constants().kOverworldGfxGroups1 +
520 std::array<gfx::SnesColor, 256> new_palette = {};
524 for (
int y = 2; y < 7; y++) {
525 for (
int x = 1; x < 8; x++) {
526 new_palette[x + (16 * y)] =
main[k];
532 for (
int x = 1; x < 8; x++) {
533 new_palette[(16 * 7) + (x)] = animated[(x - 1)];
540 for (
int y = 2; y < 5; y++) {
541 for (
int x = 9; x < 16; x++) {
542 new_palette[x + (16 * y)] = aux1[k];
549 for (
int y = 5; y < 8; y++) {
550 for (
int x = 9; x < 16; x++) {
551 new_palette[x + (16 * y)] = aux2[k];
557 for (
int i = 0; i < 32; i++) {
558 new_palette[i] = hud[i];
562 for (
int i = 0; i < 8; i++) {
563 new_palette[(i * 16)] = bgrcolor;
564 new_palette[(i * 16) + 8] = bgrcolor;
569 for (
int y = 8; y < 9; y++) {
570 for (
int x = 1; x < 8; x++) {
571 new_palette[x + (16 * y)] = rom.
palette_group().sprites_aux1[1][k];
578 for (
int y = 8; y < 9; y++) {
579 for (
int x = 9; x < 16; x++) {
580 new_palette[x + (16 * y)] = rom.
palette_group().sprites_aux3[0][k];
587 for (
int y = 9; y < 13; y++) {
588 for (
int x = 1; x < 16; x++) {
589 new_palette[x + (16 * y)] = rom.
palette_group().global_sprites[0][k];
596 for (
int y = 13; y < 14; y++) {
597 for (
int x = 1; x < 8; x++) {
598 new_palette[x + (16 * y)] = spr[k];
605 for (
int y = 14; y < 15; y++) {
606 for (
int x = 1; x < 8; x++) {
607 new_palette[x + (16 * y)] = spr2[k];
614 for (
int y = 15; y < 16; y++) {
615 for (
int x = 1; x < 16; x++) {
616 new_palette[x + (16 * y)] = rom.
palette_group().armors[0][k];
621 for (
int i = 0; i < 256; i++) {
622 current[i] = new_palette[i];
623 current[(i / 16) * 16].set_transparent(
true);
627 return absl::OkStatus();
635 index = (*rom_)[
rom_->version_constants().kOverworldMapPaletteGroup +
636 (previous_index * 4)];
638 if (index >= limit) {
641 return palette_group[index];
645 int previous_pal_id =
647 int previous_spr_pal_id =
653 uint8_t pal1 = (*rom_)[
rom_->version_constants().kOverworldMapPaletteGroup +
655 uint8_t pal2 = (*rom_)[
rom_->version_constants().kOverworldMapPaletteGroup +
657 uint8_t pal3 = (*rom_)[
rom_->version_constants().kOverworldMapPaletteGroup +
664 auto grass_pal_group =
rom_->palette_group().grass;
665 auto bgr = grass_pal_group[0][0];
667 auto ow_aux_pal_group =
rom_->palette_group().overworld_aux;
669 GetPalette(ow_aux_pal_group, pal1, previous_pal_id, 20));
671 GetPalette(ow_aux_pal_group, pal2, previous_pal_id, 20));
675 pal3 = (*rom_)[
rom_->version_constants().kOverworldMapPaletteGroup +
676 (previous_pal_id * 4) + 2];
681 bgr = grass_pal_group[0][0];
685 bgr = grass_pal_group[0][1];
688 bgr = grass_pal_group[0][2];
695 auto ow_main_pal_group =
rom_->palette_group().overworld_main;
697 GetPalette(ow_main_pal_group, pal0, previous_pal_id, 255));
698 auto ow_animated_pal_group =
rom_->palette_group().overworld_animated;
700 GetPalette(ow_animated_pal_group, std::min((
int)pal3, 13),
701 previous_pal_id, 14));
703 auto hud_pal_group =
rom_->palette_group().hud;
708 previous_spr_pal_id, 24));
711 previous_spr_pal_id, 24));
722 return absl::OkStatus();
726 int size, uint8_t *all_gfx) {
727 for (
int i = 0; i < size; i++) {
728 auto byte = all_gfx[i + (static_graphics_offset * size)];
743 for (
int i = 0; i < 0x10; i++) {
745 rom_->graphics_buffer().data());
747 return absl::OkStatus();
754 const int offsets[] = {0x00, 0x08, 0x400, 0x408};
758 for (
auto i = 0; i < count; i++) {
759 for (
auto tile = 0; tile < 0x04; tile++) {
761 int offset = offsets[tile];
762 for (
auto y = 0; y < 0x08; ++y) {
763 for (
auto x = 0; x < 0x08; ++x) {
775 int xpos = ((info.
id_ % 0x10) * 0x08);
776 int ypos = (((info.
id_ / 0x10)) * 0x400);
777 int source = ypos + xpos + (x + (y * 0x80));
779 auto destination = xx + yy + offset + (mx + (my * 0x80));
793 return absl::OkStatus();
801 for (
int i = 0; i < 0x40000; i++) {
806 int superX =
index_ - (
world_ * 0x40) - (superY * 0x08);
808 for (
int y = 0; y < 0x20; y++) {
809 for (
int x = 0; x < 0x20; x++) {
810 auto xt = x + (superX * 0x20);
811 auto yt = y + (superY * 0x20);
816 return absl::OkStatus();
The Rom class is used to load, save, and modify Rom data.
auto palette_group() const
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.
std::vector< uint8_t > current_gfx_
std::vector< uint8_t > current_blockset_
std::array< bool, 4 > mosaic_expanded_
std::vector< uint8_t > bitmap_data_
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()
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()
gfx::SnesPalette current_palette_
void ProcessGraphicsBuffer(int index, int static_graphics_offset, int size, uint8_t *all_gfx)
void LoadCustomOverworldData()
void LoadSpritesBlocksets()
int main(int argc, char **argv)
#define RETURN_IF_ERROR(expression)
#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, 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 kOverworldSpritePaletteGroup
constexpr int kOverworldSpriteset
constexpr int kSpecialWorldMapIdStart
constexpr int OverworldCustomMosaicArray
constexpr int kNumOverworldMaps
constexpr int OverworldCustomMainPaletteArray
constexpr int kOverworldMusicBeginning
std::vector< std::vector< uint16_t > > OverworldBlockset
Represents tile32 data for the overworld.
constexpr int kOverworldMusicDarkWorld
constexpr int kOverworldSpecialPalGroup
constexpr int kOverworldSpritePaletteIds
constexpr int OverworldCustomASMHasBeenApplied
constexpr int kOverworldMusicAgahnim
constexpr int kOverworldMusicMasterSword
constexpr int kOverworldMusicZelda
constexpr int kOverworldMessageIds
constexpr int kOverworldMapSize
constexpr int OverworldCustomAnimatedGFXArray
constexpr int kDarkWorldMapIdStart
constexpr int OverworldCustomTileGFXGroupArray
constexpr int kOverworldMapPaletteIds
constexpr int kOverworldSpecialGfxGroup
constexpr int OverworldCustomSubscreenOverlayArray
Main namespace for the application.
Represents a group of palettes.
Represents a set of palettes used in a SNES graphics system.