Housekeeping

This commit is contained in:
scawful
2023-12-17 21:02:28 -05:00
parent 10785357ef
commit 20515d2f0b
11 changed files with 66 additions and 73 deletions

View File

@@ -87,6 +87,18 @@
} \ } \
type_variable_name = std::move(*error_or_value); type_variable_name = std::move(*error_or_value);
#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression) \
ASSIGN_OR_LOG_ERROR_IMPL(APPEND_NUMBER(error_or_value, __LINE__), \
type_variable_name, expression)
#define ASSIGN_OR_LOG_ERROR_IMPL(error_or_value, type_variable_name, \
expression) \
auto error_or_value = expression; \
if (!error_or_value.ok()) { \
std::cout << error_or_value.status().ToString() << std::endl; \
} \
type_variable_name = std::move(*error_or_value);
#define APPEND_NUMBER(expression, number) \ #define APPEND_NUMBER(expression, number) \
APPEND_NUMBER_INNER(expression, number) APPEND_NUMBER_INNER(expression, number)

View File

@@ -138,7 +138,6 @@ void Controller::OnInput() {
break; break;
} }
break; break;
default: default:
break; break;
} }

View File

@@ -112,6 +112,8 @@ class RecentFilesManager {
} // namespace } // namespace
using ImGui::BeginMenu;
using ImGui::MenuItem;
using ImGui::Text; using ImGui::Text;
void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) { void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
@@ -275,8 +277,8 @@ void MasterEditor::DrawYazeMenu() {
void MasterEditor::DrawFileMenu() { void MasterEditor::DrawFileMenu() {
static bool save_as_menu = false; static bool save_as_menu = false;
if (ImGui::BeginMenu("File")) { if (BeginMenu("File")) {
if (ImGui::MenuItem("Open", "Ctrl+O")) { if (MenuItem("Open", "Ctrl+O")) {
if (flags()->kNewFileDialogWrapper) { if (flags()->kNewFileDialogWrapper) {
auto file_name = FileDialogWrapper::ShowOpenFileDialog(); auto file_name = FileDialogWrapper::ShowOpenFileDialog();
PRINT_IF_ERROR(rom()->LoadFromFile(file_name)); PRINT_IF_ERROR(rom()->LoadFromFile(file_name));
@@ -290,14 +292,14 @@ void MasterEditor::DrawFileMenu() {
} }
} }
if (ImGui::BeginMenu("Open Recent")) { if (BeginMenu("Open Recent")) {
static RecentFilesManager manager("recent_files.txt"); static RecentFilesManager manager("recent_files.txt");
manager.Load(); manager.Load();
if (manager.GetRecentFiles().empty()) { if (manager.GetRecentFiles().empty()) {
ImGui::MenuItem("No Recent Files", nullptr, false, false); MenuItem("No Recent Files", nullptr, false, false);
} else { } else {
for (const auto& filePath : manager.GetRecentFiles()) { for (const auto& filePath : manager.GetRecentFiles()) {
if (ImGui::MenuItem(filePath.c_str())) { if (MenuItem(filePath.c_str())) {
status_ = rom()->LoadFromFile(filePath); status_ = rom()->LoadFromFile(filePath);
} }
} }
@@ -315,8 +317,8 @@ void MasterEditor::DrawFileMenu() {
ImGui::Separator(); ImGui::Separator();
if (ImGui::BeginMenu("Options")) { if (BeginMenu("Options")) {
ImGui::MenuItem("Backup ROM", "", &backup_rom_); MenuItem("Backup ROM", "", &backup_rom_);
ImGui::Separator(); ImGui::Separator();
Text("Experiment Flags"); Text("Experiment Flags");
ImGui::Checkbox("Enable Texture Streaming", ImGui::Checkbox("Enable Texture Streaming",
@@ -339,7 +341,7 @@ void MasterEditor::DrawFileMenu() {
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("Quit", "Ctrl+Q")) { if (MenuItem("Quit", "Ctrl+Q")) {
// TODO: Implement quit confirmation dialog. // TODO: Implement quit confirmation dialog.
} }
@@ -363,7 +365,7 @@ void MasterEditor::DrawFileMenu() {
} }
void MasterEditor::DrawEditMenu() { void MasterEditor::DrawEditMenu() {
if (ImGui::BeginMenu("Edit")) { if (BeginMenu("Edit")) {
MENU_ITEM2("Undo", "Ctrl+Z") { status_ = current_editor_->Undo(); } MENU_ITEM2("Undo", "Ctrl+Z") { status_ = current_editor_->Undo(); }
MENU_ITEM2("Redo", "Ctrl+Y") { status_ = current_editor_->Redo(); } MENU_ITEM2("Redo", "Ctrl+Y") { status_ = current_editor_->Redo(); }
ImGui::Separator(); ImGui::Separator();
@@ -439,23 +441,23 @@ void MasterEditor::DrawViewMenu() {
ImGui::End(); ImGui::End();
} }
if (ImGui::BeginMenu("View")) { if (BeginMenu("View")) {
ImGui::MenuItem("Emulator", nullptr, &show_emulator); MenuItem("Emulator", nullptr, &show_emulator);
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor); MenuItem("HEX Editor", nullptr, &show_memory_editor);
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor); MenuItem("ASM Editor", nullptr, &show_asm_editor);
ImGui::MenuItem("Palette Editor", nullptr, &show_palette_editor); MenuItem("Palette Editor", nullptr, &show_palette_editor);
ImGui::MenuItem("Memory Viewer", nullptr, &show_memory_viewer); MenuItem("Memory Viewer", nullptr, &show_memory_viewer);
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo); MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
ImGui::MenuItem("ImGui Metrics", nullptr, &show_imgui_metrics); MenuItem("ImGui Metrics", nullptr, &show_imgui_metrics);
ImGui::EndMenu(); ImGui::EndMenu();
} }
} }
void MasterEditor::DrawHelpMenu() { void MasterEditor::DrawHelpMenu() {
static bool open_rom_help = false; static bool open_rom_help = false;
if (ImGui::BeginMenu("Help")) { if (BeginMenu("Help")) {
if (ImGui::MenuItem("How to open a ROM")) open_rom_help = true; if (MenuItem("How to open a ROM")) open_rom_help = true;
if (ImGui::MenuItem("About")) about_ = true; if (MenuItem("About")) about_ = true;
ImGui::EndMenu(); ImGui::EndMenu();
} }

View File

@@ -62,7 +62,7 @@ absl::Status GfxGroupEditor::Update() {
auto &sheet = *rom()->bitmap_manager()[sheet_id]; auto &sheet = *rom()->bitmap_manager()[sheet_id];
if (sheet_id != last_sheet_id_) { if (sheet_id != last_sheet_id_) {
last_sheet_id_ = sheet_id; last_sheet_id_ = sheet_id;
auto palette_group = rom()->GetPaletteGroup("ow_main"); auto palette_group = rom()->palette_group("ow_main");
auto palette = palette_group[preview_palette_id_]; auto palette = palette_group[preview_palette_id_];
sheet.ApplyPalette(palette); sheet.ApplyPalette(palette);
rom()->UpdateBitmap(&sheet); rom()->UpdateBitmap(&sheet);

View File

@@ -96,8 +96,8 @@ absl::Status PaletteEditor::DrawPaletteGroup(int category) {
} }
const auto size = const auto size =
rom()->GetPaletteGroup(kPaletteGroupNames[category].data()).size(); rom()->palette_group(kPaletteGroupNames[category].data()).size();
auto palettes = rom()->GetPaletteGroup(kPaletteGroupNames[category].data()); auto palettes = rom()->palette_group(kPaletteGroupNames[category].data());
static bool edit_color = false; static bool edit_color = false;
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++) {
ImGui::Text("%d", j); ImGui::Text("%d", j);

View File

@@ -112,7 +112,7 @@ absl::Status Tile16Editor::UpdateBlockset() {
if (notify_tile16.modified()) { if (notify_tile16.modified()) {
current_tile16_bmp_ = tile16_individual_[notify_tile16]; current_tile16_bmp_ = tile16_individual_[notify_tile16];
current_tile16_bmp_.ApplyPalette( current_tile16_bmp_.ApplyPalette(
rom()->GetPaletteGroup("ow_main")[current_palette_]); rom()->palette_group("ow_main")[current_palette_]);
rom()->RenderBitmap(&current_tile16_bmp_); rom()->RenderBitmap(&current_tile16_bmp_);
} }
} }
@@ -163,9 +163,9 @@ void Tile16Editor::DrawTileEditControls() {
notify_palette.apply_changes(); notify_palette.apply_changes();
if (notify_palette.modified()) { if (notify_palette.modified()) {
current_gfx_bmp_.ApplyPalette( current_gfx_bmp_.ApplyPalette(
rom()->GetPaletteGroup("ow_main")[notify_palette.get()]); rom()->palette_group("ow_main")[notify_palette.get()]);
current_tile16_bmp_.ApplyPalette( current_tile16_bmp_.ApplyPalette(
rom()->GetPaletteGroup("ow_main")[notify_palette.get()]); rom()->palette_group("ow_main")[notify_palette.get()]);
rom()->UpdateBitmap(&current_gfx_bmp_); rom()->UpdateBitmap(&current_gfx_bmp_);
} }
@@ -250,7 +250,7 @@ absl::Status Tile16Editor::LoadTile8() {
current_gfx_individual_.emplace_back(); current_gfx_individual_.emplace_back();
current_gfx_individual_[index].Create(0x08, 0x08, 0x80, tile_data); current_gfx_individual_[index].Create(0x08, 0x08, 0x80, tile_data);
current_gfx_individual_[index].ApplyPalette( current_gfx_individual_[index].ApplyPalette(
rom()->GetPaletteGroup("ow_main")[current_palette_]); rom()->palette_group("ow_main")[current_palette_]);
rom()->RenderBitmap(&current_gfx_individual_[index]); rom()->RenderBitmap(&current_gfx_individual_[index]);
}; };
@@ -272,7 +272,7 @@ absl::Status Tile16Editor::LoadTile8() {
// for (int i = 0; i < 128; i++) { // for (int i = 0; i < 128; i++) {
// std::vector<uint8_t> tile_data(0x40, 0x00); // std::vector<uint8_t> tile_data(0x40, 0x00);
// // Copy the pixel data for the current tile into the vector // Copy the pixel data for the current tile into the vector
// for (int ty = 0; ty < 8; ty++) { // for (int ty = 0; ty < 8; ty++) {
// for (int tx = 0; tx < 8; tx++) { // for (int tx = 0; tx < 8; tx++) {
// int position = tx + (ty * 0x10); // int position = tx + (ty * 0x10);
@@ -287,7 +287,7 @@ absl::Status Tile16Editor::LoadTile8() {
// current_gfx_individual_.emplace_back(); // current_gfx_individual_.emplace_back();
// current_gfx_individual_[i].Create(0x08, 0x08, 0x80, tile_data); // current_gfx_individual_[i].Create(0x08, 0x08, 0x80, tile_data);
// current_gfx_individual_[i].ApplyPalette( // current_gfx_individual_[i].ApplyPalette(
// rom()->GetPaletteGroup("ow_main")[current_palette_]); // rom()->palette_group("ow_main")[current_palette_]);
// rom()->RenderBitmap(&current_gfx_individual_[i]); // rom()->RenderBitmap(&current_gfx_individual_[i]);
// } // }
return absl::OkStatus(); return absl::OkStatus();

View File

@@ -466,6 +466,8 @@ void OverworldEditor::DrawOverworldCanvas() {
DrawOverworldMapSettings(); DrawOverworldMapSettings();
Separator(); Separator();
} }
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7); if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysVerticalScrollbar |
@@ -486,6 +488,7 @@ void OverworldEditor::DrawOverworldCanvas() {
ow_map_canvas_.DrawOverlay(); ow_map_canvas_.DrawOverlay();
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::PopStyleVar(2);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -342,7 +342,7 @@ class CPU : public Memory, public Loggable, public core::ExperimentFlags {
void WriteWord(uint32_t address, uint16_t value) override { void WriteWord(uint32_t address, uint16_t value) override {
memory.WriteWord(address, value); memory.WriteWord(address, value);
} }
void WriteLong(uint32_t address, uint32_t value) { void WriteLong(uint32_t address, uint32_t value) override {
memory.WriteLong(address, value); memory.WriteLong(address, value);
} }

View File

@@ -279,15 +279,7 @@ class ROM : public core::ExperimentFlags {
return result; return result;
} }
absl::StatusOr<uint16_t> ReadShort(int offset) { absl::StatusOr<uint32_t> ReadLong(int offset) {
if (offset + 1 >= rom_data_.size()) {
return absl::InvalidArgumentError("Offset out of range");
}
auto result = (uint16_t)(rom_data_[offset] | (rom_data_[offset + 1] << 8));
return result;
}
absl::StatusOr<uint32_t> ReadShortLong(int offset) {
if (offset + 2 >= rom_data_.size()) { if (offset + 2 >= rom_data_.size()) {
return absl::InvalidArgumentError("Offset out of range"); return absl::InvalidArgumentError("Offset out of range");
} }
@@ -312,16 +304,16 @@ class ROM : public core::ExperimentFlags {
// Skip 8 bytes per tile. // Skip 8 bytes per tile.
auto tpos = 0x78000 + (tile16_id * 0x08); auto tpos = 0x78000 + (tile16_id * 0x08);
gfx::Tile16 tile16; gfx::Tile16 tile16;
ASSIGN_OR_RETURN(auto new_tile0, ReadShort(tpos)) ASSIGN_OR_RETURN(auto new_tile0, ReadWord(tpos))
tile16.tile0_ = gfx::WordToTileInfo(new_tile0); tile16.tile0_ = gfx::WordToTileInfo(new_tile0);
tpos += 2; tpos += 2;
ASSIGN_OR_RETURN(auto new_tile1, ReadShort(tpos)) ASSIGN_OR_RETURN(auto new_tile1, ReadWord(tpos))
tile16.tile1_ = gfx::WordToTileInfo(new_tile1); tile16.tile1_ = gfx::WordToTileInfo(new_tile1);
tpos += 2; tpos += 2;
ASSIGN_OR_RETURN(auto new_tile2, ReadShort(tpos)) ASSIGN_OR_RETURN(auto new_tile2, ReadWord(tpos))
tile16.tile2_ = gfx::WordToTileInfo(new_tile2); tile16.tile2_ = gfx::WordToTileInfo(new_tile2);
tpos += 2; tpos += 2;
ASSIGN_OR_RETURN(auto new_tile3, ReadShort(tpos)) ASSIGN_OR_RETURN(auto new_tile3, ReadWord(tpos))
tile16.tile3_ = gfx::WordToTileInfo(new_tile3); tile16.tile3_ = gfx::WordToTileInfo(new_tile3);
return tile16; return tile16;
} }
@@ -411,7 +403,7 @@ class ROM : public core::ExperimentFlags {
return core::SnesToPc(snes_addr); return core::SnesToPc(snes_addr);
} }
gfx::PaletteGroup GetPaletteGroup(const std::string& group) { gfx::PaletteGroup palette_group(const std::string& group) {
return palette_groups_[group]; return palette_groups_[group];
} }
auto mutable_palette_group(const std::string& group) { auto mutable_palette_group(const std::string& group) {
@@ -433,27 +425,12 @@ class ROM : public core::ExperimentFlags {
auto begin() { return rom_data_.begin(); } auto begin() { return rom_data_.begin(); }
auto end() { return rom_data_.end(); } auto end() { return rom_data_.end(); }
auto data() { return rom_data_.data(); } auto data() { return rom_data_.data(); }
auto push_back(uint8_t byte) { rom_data_.push_back(byte); }
auto vector() const { return rom_data_; } auto vector() const { return rom_data_; }
auto filename() const { return filename_; } auto filename() const { return filename_; }
auto isLoaded() const { return is_loaded_; } auto isLoaded() const { return is_loaded_; }
auto char_data() {
return static_cast<char*>(static_cast<void*>(rom_data_.data()));
}
auto push_back(uchar byte) { rom_data_.push_back(byte); }
auto version() const { return version_; } auto version() const { return version_; }
void malloc(int n_bytes) {
rom_data_.clear();
rom_data_.reserve(n_bytes);
rom_data_.resize(n_bytes);
for (int i = 0; i < n_bytes; i++) {
rom_data_.push_back(0x00);
}
size_ = n_bytes;
}
uchar& operator[](int i) { uchar& operator[](int i) {
if (i > size_) { if (i > size_) {
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_ std::cout << "ROM: Index " << i << " out of bounds, size: " << size_

View File

@@ -92,7 +92,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current,
k = 0; k = 0;
for (int y = 8; y < 9; y++) { for (int y = 8; y < 9; y++) {
for (int x = 1; x < 8; x++) { for (int x = 1; x < 8; x++) {
new_palette[x + (16 * y)] = rom.GetPaletteGroup("sprites_aux1")[1][k]; new_palette[x + (16 * y)] = rom.palette_group("sprites_aux1")[1][k];
k++; k++;
} }
} }
@@ -101,7 +101,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current,
k = 0; k = 0;
for (int y = 8; y < 9; y++) { for (int y = 8; y < 9; y++) {
for (int x = 9; x < 16; x++) { for (int x = 9; x < 16; x++) {
new_palette[x + (16 * y)] = rom.GetPaletteGroup("sprites_aux3")[0][k]; new_palette[x + (16 * y)] = rom.palette_group("sprites_aux3")[0][k];
k++; k++;
} }
} }
@@ -110,7 +110,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current,
k = 0; k = 0;
for (int y = 9; y < 13; y++) { for (int y = 9; y < 13; y++) {
for (int x = 1; x < 16; x++) { for (int x = 1; x < 16; x++) {
new_palette[x + (16 * y)] = rom.GetPaletteGroup("global_sprites")[0][k]; new_palette[x + (16 * y)] = rom.palette_group("global_sprites")[0][k];
k++; k++;
} }
} }
@@ -137,7 +137,7 @@ void SetColorsPalette(ROM& rom, int index, gfx::SNESPalette& current,
k = 0; k = 0;
for (int y = 15; y < 16; y++) { for (int y = 15; y < 16; y++) {
for (int x = 1; x < 16; x++) { for (int x = 1; x < 16; x++) {
new_palette[x + (16 * y)] = rom.GetPaletteGroup("armors")[0][k]; new_palette[x + (16 * y)] = rom.palette_group("armors")[0][k];
k++; k++;
} }
} }
@@ -337,9 +337,9 @@ gfx::SNESPalette OverworldMap::GetPalette(const std::string& group, int index,
if (index >= limit) { if (index >= limit) {
index = limit - 1; index = limit - 1;
} }
return rom_.GetPaletteGroup(group)[index]; return rom_.palette_group(group)[index];
} else { } else {
return rom_.GetPaletteGroup(group)[0]; return rom_.palette_group(group)[0];
} }
} }
@@ -362,7 +362,7 @@ void OverworldMap::LoadPalette() {
uchar pal5 = rom_[overworldSpritePaletteGroup + uchar pal5 = rom_[overworldSpritePaletteGroup +
(sprite_palette_[game_state_] * 2) + 1]; (sprite_palette_[game_state_] * 2) + 1];
gfx::SNESColor bgr = rom_.GetPaletteGroup("grass")[0].GetColor(0); gfx::SNESColor bgr = rom_.palette_group("grass")[0].GetColor(0);
gfx::SNESPalette aux1 = GetPalette("ow_aux", pal1, previousPalId, 20); gfx::SNESPalette aux1 = GetPalette("ow_aux", pal1, previousPalId, 20);
gfx::SNESPalette aux2 = GetPalette("ow_aux", pal2, previousPalId, 20); gfx::SNESPalette aux2 = GetPalette("ow_aux", pal2, previousPalId, 20);
@@ -374,13 +374,13 @@ void OverworldMap::LoadPalette() {
} }
if (parent_ < 0x40) { if (parent_ < 0x40) {
pal0 = parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07 ? 2 : 0; pal0 = parent_ == 0x03 || parent_ == 0x05 || parent_ == 0x07 ? 2 : 0;
bgr = rom_.GetPaletteGroup("grass")[0].GetColor(0); bgr = rom_.palette_group("grass")[0].GetColor(0);
} else if (parent_ >= 0x40 && parent_ < 0x80) { } else if (parent_ >= 0x40 && parent_ < 0x80) {
pal0 = parent_ == 0x43 || parent_ == 0x45 || parent_ == 0x47 ? 3 : 1; pal0 = parent_ == 0x43 || parent_ == 0x45 || parent_ == 0x47 ? 3 : 1;
bgr = rom_.GetPaletteGroup("grass")[0].GetColor(1); bgr = rom_.palette_group("grass")[0].GetColor(1);
} else if (parent_ >= 128 && parent_ < kNumOverworldMaps) { } else if (parent_ >= 128 && parent_ < kNumOverworldMaps) {
pal0 = 0; pal0 = 0;
bgr = rom_.GetPaletteGroup("grass")[0].GetColor(2); bgr = rom_.palette_group("grass")[0].GetColor(2);
} }
if (parent_ == 0x88) { if (parent_ == 0x88) {
pal0 = 4; pal0 = 4;
@@ -388,7 +388,7 @@ void OverworldMap::LoadPalette() {
gfx::SNESPalette main = GetPalette("ow_main", pal0, previousPalId, 255); gfx::SNESPalette main = GetPalette("ow_main", pal0, previousPalId, 255);
gfx::SNESPalette animated = gfx::SNESPalette animated =
GetPalette("ow_animated", std::min((int)pal3, 13), previousPalId, 14); GetPalette("ow_animated", std::min((int)pal3, 13), previousPalId, 14);
gfx::SNESPalette hud = rom_.GetPaletteGroup("hud")[0]; gfx::SNESPalette hud = rom_.palette_group("hud")[0];
gfx::SNESPalette spr = GetPalette("sprites_aux3", pal4, previousSprPalId, 24); gfx::SNESPalette spr = GetPalette("sprites_aux3", pal4, previousSprPalId, 24);
gfx::SNESPalette spr2 = gfx::SNESPalette spr2 =

View File

@@ -79,7 +79,7 @@ absl::Status Inventory::BuildTileset() {
test_.push_back(tilesheets_[i]); test_.push_back(tilesheets_[i]);
} }
tilesheets_bmp_.Create(128, 0x130, 64, test_); tilesheets_bmp_.Create(128, 0x130, 64, test_);
palette_ = rom()->GetPaletteGroup("hud")[0]; palette_ = rom()->palette_group("hud")[0];
tilesheets_bmp_.ApplyPalette(palette_); tilesheets_bmp_.ApplyPalette(palette_);
rom()->RenderBitmap(&tilesheets_bmp_); rom()->RenderBitmap(&tilesheets_bmp_);
return absl::OkStatus(); return absl::OkStatus();