Change Load2BppGraphics to standalone fn, add mutable_data accessor
This commit is contained in:
@@ -596,7 +596,7 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
|
|||||||
sizeof(col_file_name_));
|
sizeof(col_file_name_));
|
||||||
status_ = temp_rom_.LoadFromFile(col_file_path_,
|
status_ = temp_rom_.LoadFromFile(col_file_path_,
|
||||||
/*z3_load=*/false);
|
/*z3_load=*/false);
|
||||||
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
|
auto col_data_ = gfx::GetColFileData(temp_rom_.mutable_data());
|
||||||
if (col_file_palette_group_.size() != 0) {
|
if (col_file_palette_group_.size() != 0) {
|
||||||
col_file_palette_group_.clear();
|
col_file_palette_group_.clear();
|
||||||
}
|
}
|
||||||
@@ -757,7 +757,8 @@ absl::Status GraphicsEditor::DrawMemoryEditor() {
|
|||||||
std::string title = "Memory Editor";
|
std::string title = "Memory Editor";
|
||||||
if (is_open_) {
|
if (is_open_) {
|
||||||
static MemoryEditor mem_edit;
|
static MemoryEditor mem_edit;
|
||||||
mem_edit.DrawWindow(title.c_str(), temp_rom_.data(), temp_rom_.size());
|
mem_edit.DrawWindow(title.c_str(), temp_rom_.mutable_data(),
|
||||||
|
temp_rom_.size());
|
||||||
}
|
}
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,9 +336,10 @@ void MessageEditor::ReadAllTextDataV2() {
|
|||||||
current_raw_message.append("]");
|
current_raw_message.append("]");
|
||||||
|
|
||||||
uint32_t address = core::Get24LocalFromPC(
|
uint32_t address = core::Get24LocalFromPC(
|
||||||
rom()->data(), kPointersDictionaries + (dictionary * 2));
|
rom()->mutable_data(), kPointersDictionaries + (dictionary * 2));
|
||||||
uint32_t address_end = core::Get24LocalFromPC(
|
uint32_t address_end = core::Get24LocalFromPC(
|
||||||
rom()->data(), kPointersDictionaries + ((dictionary + 1) * 2));
|
rom()->mutable_data(),
|
||||||
|
kPointersDictionaries + ((dictionary + 1) * 2));
|
||||||
|
|
||||||
for (uint32_t i = address; i < address_end; i++) {
|
for (uint32_t i = address; i < address_end; i++) {
|
||||||
parsed_message.push_back(rom()->data()[i]);
|
parsed_message.push_back(rom()->data()[i]);
|
||||||
@@ -435,9 +436,9 @@ void MessageEditor::ReadAllTextData() {
|
|||||||
current_message_raw.append("]");
|
current_message_raw.append("]");
|
||||||
|
|
||||||
uint32_t address = core::Get24LocalFromPC(
|
uint32_t address = core::Get24LocalFromPC(
|
||||||
rom()->data(), kPointersDictionaries + (dictionary * 2));
|
rom()->mutable_data(), kPointersDictionaries + (dictionary * 2));
|
||||||
uint32_t address_end = core::Get24LocalFromPC(
|
uint32_t address_end = core::Get24LocalFromPC(
|
||||||
rom()->data(), kPointersDictionaries + ((dictionary + 1) * 2));
|
rom()->mutable_data(), kPointersDictionaries + ((dictionary + 1) * 2));
|
||||||
|
|
||||||
for (uint32_t i = address; i < address_end; i++) {
|
for (uint32_t i = address; i < address_end; i++) {
|
||||||
temp_bytes_parsed.push_back(rom()->data()[i]);
|
temp_bytes_parsed.push_back(rom()->data()[i]);
|
||||||
|
|||||||
@@ -34,17 +34,17 @@ int GetGraphicsAddress(const uchar *data, uint8_t addr, uint32_t ptr1,
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
absl::StatusOr<std::vector<uint8_t>> Rom::Load2BppGraphics() {
|
absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom &rom) {
|
||||||
std::vector<uint8_t> sheet;
|
std::vector<uint8_t> sheet;
|
||||||
const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
|
const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
|
||||||
|
|
||||||
for (const auto &sheet_id : sheets) {
|
for (const auto &sheet_id : sheets) {
|
||||||
auto offset = GetGraphicsAddress(data(), sheet_id,
|
auto offset = GetGraphicsAddress(rom.data(), sheet_id,
|
||||||
version_constants().kOverworldGfxPtr1,
|
rom.version_constants().kOverworldGfxPtr1,
|
||||||
version_constants().kOverworldGfxPtr2,
|
rom.version_constants().kOverworldGfxPtr2,
|
||||||
version_constants().kOverworldGfxPtr3);
|
rom.version_constants().kOverworldGfxPtr3);
|
||||||
ASSIGN_OR_RETURN(auto decomp_sheet,
|
ASSIGN_OR_RETURN(auto decomp_sheet,
|
||||||
gfx::lc_lz2::DecompressV2(data(), offset))
|
gfx::lc_lz2::DecompressV2(rom.data(), offset))
|
||||||
auto converted_sheet = gfx::SnesTo8bppSheet(decomp_sheet, 2);
|
auto converted_sheet = gfx::SnesTo8bppSheet(decomp_sheet, 2);
|
||||||
for (const auto &each_pixel : converted_sheet) {
|
for (const auto &each_pixel : converted_sheet) {
|
||||||
sheet.push_back(each_pixel);
|
sheet.push_back(each_pixel);
|
||||||
|
|||||||
@@ -133,16 +133,6 @@ constexpr uint32_t kMaxGraphics = 0xC3FB5;
|
|||||||
*/
|
*/
|
||||||
class Rom : public core::ExperimentFlags {
|
class Rom : public core::ExperimentFlags {
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief Loads 2bpp graphics from Rom data.
|
|
||||||
*
|
|
||||||
* This function loads 2bpp graphics from Rom data by iterating over a list of
|
|
||||||
* sheet IDs, decompressing the sheet data, converting it to 8bpp format, and
|
|
||||||
* appending the converted sheet data to a byte vector.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Loads the players 4bpp graphics sheet from Rom data.
|
* @brief Loads the players 4bpp graphics sheet from Rom data.
|
||||||
*/
|
*/
|
||||||
@@ -456,9 +446,12 @@ class Rom : public core::ExperimentFlags {
|
|||||||
|
|
||||||
auto title() const { return title_; }
|
auto title() const { return title_; }
|
||||||
auto size() const { return size_; }
|
auto size() const { return size_; }
|
||||||
|
auto data() const { return rom_data_.data(); }
|
||||||
|
auto mutable_data() { return rom_data_.data(); }
|
||||||
|
|
||||||
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 vector() const { return rom_data_; }
|
auto vector() const { return rom_data_; }
|
||||||
auto version() const { return version_; }
|
auto version() const { return version_; }
|
||||||
auto filename() const { return filename_; }
|
auto filename() const { return filename_; }
|
||||||
@@ -568,6 +561,16 @@ class Rom : public core::ExperimentFlags {
|
|||||||
Z3_Version version_ = Z3_Version::US;
|
Z3_Version version_ = Z3_Version::US;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Loads 2bpp graphics from Rom data.
|
||||||
|
*
|
||||||
|
* This function loads 2bpp graphics from Rom data by iterating over a list of
|
||||||
|
* sheet IDs, decompressing the sheet data, converting it to 8bpp format, and
|
||||||
|
* appending the converted sheet data to a byte vector.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom& rom);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A class to hold a shared pointer to a Rom object.
|
* @brief A class to hold a shared pointer to a Rom object.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ unsigned char *Tracker::GetSpcAddr(Rom &rom, unsigned short addr, short bank) {
|
|||||||
spcbank = bank + 1;
|
spcbank = bank + 1;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
rom_ptr = rom.data() + sbank_ofs[spcbank];
|
rom_ptr = rom.mutable_data() + sbank_ofs[spcbank];
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
a = *(unsigned short *)rom_ptr;
|
a = *(unsigned short *)rom_ptr;
|
||||||
@@ -424,7 +424,7 @@ void Tracker::LoadSongs(Rom &rom) {
|
|||||||
srsize = 0;
|
srsize = 0;
|
||||||
song_range_ = 0;
|
song_range_ = 0;
|
||||||
sp_mark = 0;
|
sp_mark = 0;
|
||||||
b = rom.data();
|
b = rom.mutable_data();
|
||||||
|
|
||||||
sbank_ofs[1] = (b[0x91c] << 15) + ((b[0x918] & 127) << 8) + b[0x914];
|
sbank_ofs[1] = (b[0x91c] << 15) + ((b[0x918] & 127) << 8) + b[0x914];
|
||||||
sbank_ofs[3] = (b[0x93a] << 15) + ((b[0x936] & 127) << 8) + b[0x932];
|
sbank_ofs[3] = (b[0x93a] << 15) + ((b[0x936] & 127) << 8) + b[0x932];
|
||||||
@@ -550,7 +550,7 @@ void Tracker::LoadSongs(Rom &rom) {
|
|||||||
numinst = spclen / 6;
|
numinst = spclen / 6;
|
||||||
|
|
||||||
b = GetSpcAddr(rom, 0x3e00, 0);
|
b = GetSpcAddr(rom, 0x3e00, 0);
|
||||||
m_ofs = b - rom.data() + spclen;
|
m_ofs = b - rom.mutable_data() + spclen;
|
||||||
sndinsts = (ZeldaSfxInstrument *)malloc(spclen);
|
sndinsts = (ZeldaSfxInstrument *)malloc(spclen);
|
||||||
memcpy(sndinsts, b, spclen);
|
memcpy(sndinsts, b, spclen);
|
||||||
numsndinst = spclen / 9;
|
numsndinst = spclen / 9;
|
||||||
@@ -784,7 +784,7 @@ short Tracker::SaveSpcCommand(Rom &rom, short num, short songtime,
|
|||||||
|
|
||||||
int Tracker::WriteSpcData(Rom &rom, void *buf, int len, int addr, int spc,
|
int Tracker::WriteSpcData(Rom &rom, void *buf, int len, int addr, int spc,
|
||||||
int limit) {
|
int limit) {
|
||||||
unsigned char *rom_data = rom.data();
|
unsigned char *rom_data = rom.mutable_data();
|
||||||
|
|
||||||
if (!len) return addr;
|
if (!len) return addr;
|
||||||
|
|
||||||
@@ -872,7 +872,7 @@ void Tracker::SaveSongs(Rom &rom) {
|
|||||||
|
|
||||||
// set it so the music has not been modified. (reset the status)
|
// set it so the music has not been modified. (reset the status)
|
||||||
m_modf = 0;
|
m_modf = 0;
|
||||||
rom_data = rom.data();
|
rom_data = rom.mutable_data();
|
||||||
|
|
||||||
// SetCursor(wait_cursor);
|
// SetCursor(wait_cursor);
|
||||||
|
|
||||||
@@ -1240,7 +1240,7 @@ void Tracker::SaveSongs(Rom &rom) {
|
|||||||
m_modf = 1;
|
m_modf = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(rom.data() + n, stbl->buf, stbl->len);
|
memcpy(rom.mutable_data() + n, stbl->buf, stbl->len);
|
||||||
n += stbl->len;
|
n += stbl->len;
|
||||||
free(stbl->relocs);
|
free(stbl->relocs);
|
||||||
free(stbl->buf);
|
free(stbl->buf);
|
||||||
@@ -1248,13 +1248,13 @@ void Tracker::SaveSongs(Rom &rom) {
|
|||||||
ssblt[i] = 0;
|
ssblt[i] = 0;
|
||||||
}
|
}
|
||||||
if (n > l + 4) {
|
if (n > l + 4) {
|
||||||
*(short *)(rom.data() + l) = n - l - 4;
|
*(short *)(rom.mutable_data() + l) = n - l - 4;
|
||||||
*(short *)(rom.data() + l + 2) = o ? bank_lwr[k] : 0xd000;
|
*(short *)(rom.mutable_data() + l + 2) = o ? bank_lwr[k] : 0xd000;
|
||||||
l = n;
|
l = n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(short *)(rom.data() + l) = 0;
|
*(short *)(rom.mutable_data() + l) = 0;
|
||||||
*(short *)(rom.data() + l + 2) = 0x800;
|
*(short *)(rom.mutable_data() + l + 2) = 0x800;
|
||||||
if (k == 1) m = l + 4;
|
if (k == 1) m = l + 4;
|
||||||
}
|
}
|
||||||
free(ssblt);
|
free(ssblt);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ absl::Status Inventory::Create() {
|
|||||||
absl::Status Inventory::BuildTileset() {
|
absl::Status Inventory::BuildTileset() {
|
||||||
tilesheets_.reserve(6 * 0x2000);
|
tilesheets_.reserve(6 * 0x2000);
|
||||||
for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
|
for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
|
||||||
ASSIGN_OR_RETURN(tilesheets_, rom()->Load2BppGraphics())
|
ASSIGN_OR_RETURN(tilesheets_, Load2BppGraphics(*rom()))
|
||||||
std::vector<uint8_t> test;
|
std::vector<uint8_t> test;
|
||||||
for (int i = 0; i < 0x4000; i++) {
|
for (int i = 0; i < 0x4000; i++) {
|
||||||
test_.push_back(tilesheets_[i]);
|
test_.push_back(tilesheets_[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user