Popout PaletteEditor, general housekeeping

This commit is contained in:
scawful
2023-05-22 09:16:20 -05:00
parent 02b1adb6ab
commit 5ac7002c88
45 changed files with 254 additions and 334 deletions

View File

@@ -0,0 +1,89 @@
#include "inventory.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/gui/canvas.h"
namespace yaze {
namespace app {
namespace zelda3 {
void Inventory::Create() {
data_.reserve(256 * 256);
for (int i = 0; i < 256 * 256; i++) {
data_.push_back(0xFF);
}
PRINT_IF_ERROR(BuildTileset())
for (int i = 0; i < 0x500; i += 0x08) {
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos)));
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos + 0x02)));
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos + 0x04)));
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos + 0x08)));
}
const int offsets[] = {0x00, 0x08, 0x800, 0x808};
auto xx = 0;
auto yy = 0;
int i = 0;
for (const auto& tile : tiles_) {
int offset = offsets[i];
for (auto y = 0; y < 0x08; ++y) {
for (auto x = 0; x < 0x08; ++x) {
int mx = x;
int my = y;
if (tile.horizontal_mirror_ != 0) {
mx = 0x07 - x;
}
if (tile.vertical_mirror_ != 0) {
my = 0x07 - y;
}
int xpos = ((tile.id_ % 0x10) * 0x08);
int ypos = (((tile.id_ / 0x10)) * 0x400);
int source = ypos + xpos + (x + (y * 0x80));
auto destination = xx + yy + offset + (mx + (my * 0x100));
data_[destination] = (test_[source] & 0x0F) + tile.palette_ * 0x08;
}
}
if (i == 4) {
i = 0;
xx += 0x10;
if (xx >= 0x100) {
yy += 0x1000;
xx = 0;
}
} else {
i++;
}
}
bitmap_.Create(256, 256, 128, data_);
bitmap_.ApplyPalette(palette_);
rom_.RenderBitmap(&bitmap_);
}
absl::Status Inventory::BuildTileset() {
tilesheets_.reserve(6 * 0x2000);
for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
ASSIGN_OR_RETURN(tilesheets_, rom_.Load2bppGraphics())
Bytes test;
for (int i = 0; i < 0x4000; i++) {
test_.push_back(tilesheets_[i]);
}
for (int i = 0x8000; i < +0x8000 + 0x2000; i++) {
test_.push_back(tilesheets_[i]);
}
tilesheets_bmp_.Create(128, 0x130, 64, test_);
palette_ = rom_.GetPaletteGroup("hud")[0];
tilesheets_bmp_.ApplyPalette(palette_);
rom_.RenderBitmap(&tilesheets_bmp_);
return absl::OkStatus();
}
} // namespace zelda3
} // namespace app
} // namespace yaze

View File

@@ -0,0 +1,47 @@
#ifndef YAZE_APP_ZELDA3_INVENTORY_H
#define YAZE_APP_ZELDA3_INVENTORY_H
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/gfx/snes_palette.h"
#include "app/rom.h"
#include "app/gui/canvas.h"
namespace yaze {
namespace app {
namespace zelda3 {
constexpr int kInventoryStart = 0x6564A;
constexpr int kBowItemPos = 0x6F631;
class Inventory {
public:
void SetupROM(ROM& rom) { rom_ = rom; }
auto Bitmap() const { return bitmap_; }
auto Tilesheet() const { return tilesheets_bmp_; }
auto Palette() const { return palette_; }
void Create();
private:
absl::Status BuildTileset();
ROM rom_;
Bytes data_;
gfx::Bitmap bitmap_;
Bytes tilesheets_;
Bytes test_;
gfx::Bitmap tilesheets_bmp_;
gfx::SNESPalette palette_;
gui::Canvas canvas_;
std::vector<gfx::TileInfo> tiles_;
};
} // namespace zelda3
} // namespace app
} // namespace yaze
#endif

View File

@@ -0,0 +1,129 @@
#include "title_screen.h"
#include <cstdint>
#include "app/core/common.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace zelda3 {
void TitleScreen::Create() {
tiles8Bitmap.Create(128, 512, 8, 0x20000);
tilesBG1Bitmap.Create(256, 256, 8, 0x80000);
tilesBG2Bitmap.Create(256, 256, 8, 0x80000);
oamBGBitmap.Create(256, 256, 8, 0x80000);
BuildTileset();
LoadTitleScreen();
}
void TitleScreen::BuildTileset() {
uchar staticgfx[16];
// Main Blocksets
// TODO: get the gfx from the GFX class rather than the rom.
// for (int i = 0; i < 8; i++) {
// staticgfx[i] = GfxGroups.mainGfx[titleScreenTilesGFX][i];
// }
staticgfx[8] = 115 + 0;
// staticgfx[9] = (GfxGroups.spriteGfx[titleScreenSpritesGFX][3] + 115);
staticgfx[10] = 115 + 6;
staticgfx[11] = 115 + 7;
// staticgfx[12] = (GfxGroups.spriteGfx[titleScreenSpritesGFX][0] + 115);
staticgfx[13] = 112;
staticgfx[14] = 112;
staticgfx[15] = 112;
// Loaded gfx for the current screen (empty at this point)
uchar* currentmapgfx8Data = tiles8Bitmap.GetData();
// All gfx of the game pack of 2048 bytes (4bpp)
uchar* allgfxData = nullptr; // rom_.GetMasterGraphicsBin();
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 2048; j++) {
uchar mapByte = allgfxData[j + (staticgfx[i] * 2048)];
switch (i) {
case 0:
case 3:
case 4:
case 5:
mapByte += 0x88;
break;
}
currentmapgfx8Data[(i * 2048) + j] = mapByte; // Upload used gfx data
}
}
}
void TitleScreen::LoadTitleScreen() {
int pos =
(rom_[0x138C + 3] << 16) + (rom_[0x1383 + 3] << 8) + rom_[0x137A + 3];
for (int i = 0; i < 1024; i++) {
tilesBG1Buffer[i] = 492;
tilesBG2Buffer[i] = 492;
}
pos = core::SnesToPc(pos);
while ((rom_[pos] & 0x80) != 0x80) {
int dest_addr = pos; // $03 and $04
pos += 2;
short length = pos;
bool increment64 = (length & 0x8000) == 0x8000;
bool fixsource = (length & 0x4000) == 0x4000;
pos += 2;
length = (short)((length & 0x07FF));
int j = 0;
int jj = 0;
int posB = pos;
while (j < (length / 2) + 1) {
ushort tiledata = (ushort)pos;
if (dest_addr >= 0x1000) {
// destAddr -= 0x1000;
if (dest_addr < 0x2000) {
tilesBG1Buffer[dest_addr - 0x1000] = tiledata;
}
} else {
if (dest_addr < 0x1000) {
tilesBG2Buffer[dest_addr] = tiledata;
}
}
if (increment64) {
dest_addr += 32;
} else {
dest_addr++;
}
if (!fixsource) {
pos += 2;
}
jj += 2;
j++;
}
if (fixsource) {
pos += 2;
} else {
pos = posB + jj;
}
}
pal_selected_ = 2;
}
} // namespace zelda3
} // namespace app
} // namespace yaze

View File

@@ -0,0 +1,81 @@
#ifndef YAZE_APP_ZELDA3_SCREEN_H
#define YAZE_APP_ZELDA3_SCREEN_H
#include <cstdint>
#include "app/core/common.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace zelda3 {
class TitleScreen {
public:
void Create();
private:
void BuildTileset();
void LoadTitleScreen();
int sword_x_ = 0;
int mx_click_ = 0;
int my_click_ = 0;
int mx_dist_ = 0;
int my_dist_ = 0;
int last_x_ = 0;
int last_y_ = 0;
int x_in_ = 0;
int y_in_ = 0;
int dungmap_selected_tile_ = 0;
int dungmap_selected_ = 0;
int selected_palette_ = 0;
int total_floors_ = 0;
int current_floor_ = 0;
int num_basement_ = 0;
int num_floor_ = 0;
int selected_map_tile = 0;
int current_floor_rooms; // [1][];
int current_floor_gfx; // [1][];
int copied_data_rooms; // 25
int copied_data_gfx; // 25
int pal_selected_;
int addresses[7] = {0x53de4, 0x53e2c, 0x53e08, 0x53e50,
0x53e74, 0x53e98, 0x53ebc};
int addressesgfx[7] = {0x53ee0, 0x53f04, 0x53ef2, 0x53f16,
0x53f28, 0x53f3a, 0x53f4c};
ushort bossRoom = 0x000F;
ushort selected_tile = 0;
ushort tilesBG1Buffer[0x1000]; // 0x1000
ushort tilesBG2Buffer[0x1000]; // 0x1000
uchar mapdata; // 64 * 64
uchar dwmapdata; // 64 * 64
bool mDown = false;
bool swordSelected = false;
bool darkWorld = false;
bool currentDungeonChanged = false;
bool editedFromEditor = false;
bool mouseDown = false;
bool mdown = false;
ROM rom_;
gfx::OAMTile oam_data[10];
gfx::OAMTile selected_oam_tile;
gfx::OAMTile last_selected_oam_tile;
gfx::Bitmap tilesBG1Bitmap; // 0x80000
gfx::Bitmap tilesBG2Bitmap; // 0x80000
gfx::Bitmap oamBGBitmap; // 0x80000
gfx::Bitmap tiles8Bitmap; // 0x20000
};
} // namespace zelda3
} // namespace app
} // namespace yaze
#endif