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_));
|
||||
status_ = temp_rom_.LoadFromFile(col_file_path_,
|
||||
/*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) {
|
||||
col_file_palette_group_.clear();
|
||||
}
|
||||
@@ -757,7 +757,8 @@ absl::Status GraphicsEditor::DrawMemoryEditor() {
|
||||
std::string title = "Memory Editor";
|
||||
if (is_open_) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -336,9 +336,10 @@ void MessageEditor::ReadAllTextDataV2() {
|
||||
current_raw_message.append("]");
|
||||
|
||||
uint32_t address = core::Get24LocalFromPC(
|
||||
rom()->data(), kPointersDictionaries + (dictionary * 2));
|
||||
rom()->mutable_data(), kPointersDictionaries + (dictionary * 2));
|
||||
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++) {
|
||||
parsed_message.push_back(rom()->data()[i]);
|
||||
@@ -435,9 +436,9 @@ void MessageEditor::ReadAllTextData() {
|
||||
current_message_raw.append("]");
|
||||
|
||||
uint32_t address = core::Get24LocalFromPC(
|
||||
rom()->data(), kPointersDictionaries + (dictionary * 2));
|
||||
rom()->mutable_data(), kPointersDictionaries + (dictionary * 2));
|
||||
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++) {
|
||||
temp_bytes_parsed.push_back(rom()->data()[i]);
|
||||
|
||||
@@ -34,17 +34,17 @@ int GetGraphicsAddress(const uchar *data, uint8_t addr, uint32_t ptr1,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
absl::StatusOr<std::vector<uint8_t>> Rom::Load2BppGraphics() {
|
||||
absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom &rom) {
|
||||
std::vector<uint8_t> sheet;
|
||||
const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
|
||||
|
||||
for (const auto &sheet_id : sheets) {
|
||||
auto offset = GetGraphicsAddress(data(), sheet_id,
|
||||
version_constants().kOverworldGfxPtr1,
|
||||
version_constants().kOverworldGfxPtr2,
|
||||
version_constants().kOverworldGfxPtr3);
|
||||
auto offset = GetGraphicsAddress(rom.data(), sheet_id,
|
||||
rom.version_constants().kOverworldGfxPtr1,
|
||||
rom.version_constants().kOverworldGfxPtr2,
|
||||
rom.version_constants().kOverworldGfxPtr3);
|
||||
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);
|
||||
for (const auto &each_pixel : converted_sheet) {
|
||||
sheet.push_back(each_pixel);
|
||||
|
||||
@@ -133,16 +133,6 @@ constexpr uint32_t kMaxGraphics = 0xC3FB5;
|
||||
*/
|
||||
class Rom : public core::ExperimentFlags {
|
||||
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.
|
||||
*/
|
||||
@@ -456,9 +446,12 @@ class Rom : public core::ExperimentFlags {
|
||||
|
||||
auto title() const { return title_; }
|
||||
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 end() { return rom_data_.end(); }
|
||||
auto data() { return rom_data_.data(); }
|
||||
|
||||
auto vector() const { return rom_data_; }
|
||||
auto version() const { return version_; }
|
||||
auto filename() const { return filename_; }
|
||||
@@ -568,6 +561,16 @@ class Rom : public core::ExperimentFlags {
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -64,7 +64,7 @@ unsigned char *Tracker::GetSpcAddr(Rom &rom, unsigned short addr, short bank) {
|
||||
spcbank = bank + 1;
|
||||
|
||||
again:
|
||||
rom_ptr = rom.data() + sbank_ofs[spcbank];
|
||||
rom_ptr = rom.mutable_data() + sbank_ofs[spcbank];
|
||||
|
||||
for (;;) {
|
||||
a = *(unsigned short *)rom_ptr;
|
||||
@@ -424,7 +424,7 @@ void Tracker::LoadSongs(Rom &rom) {
|
||||
srsize = 0;
|
||||
song_range_ = 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[3] = (b[0x93a] << 15) + ((b[0x936] & 127) << 8) + b[0x932];
|
||||
@@ -550,7 +550,7 @@ void Tracker::LoadSongs(Rom &rom) {
|
||||
numinst = spclen / 6;
|
||||
|
||||
b = GetSpcAddr(rom, 0x3e00, 0);
|
||||
m_ofs = b - rom.data() + spclen;
|
||||
m_ofs = b - rom.mutable_data() + spclen;
|
||||
sndinsts = (ZeldaSfxInstrument *)malloc(spclen);
|
||||
memcpy(sndinsts, b, spclen);
|
||||
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 limit) {
|
||||
unsigned char *rom_data = rom.data();
|
||||
unsigned char *rom_data = rom.mutable_data();
|
||||
|
||||
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)
|
||||
m_modf = 0;
|
||||
rom_data = rom.data();
|
||||
rom_data = rom.mutable_data();
|
||||
|
||||
// SetCursor(wait_cursor);
|
||||
|
||||
@@ -1240,7 +1240,7 @@ void Tracker::SaveSongs(Rom &rom) {
|
||||
m_modf = 1;
|
||||
return;
|
||||
}
|
||||
memcpy(rom.data() + n, stbl->buf, stbl->len);
|
||||
memcpy(rom.mutable_data() + n, stbl->buf, stbl->len);
|
||||
n += stbl->len;
|
||||
free(stbl->relocs);
|
||||
free(stbl->buf);
|
||||
@@ -1248,13 +1248,13 @@ void Tracker::SaveSongs(Rom &rom) {
|
||||
ssblt[i] = 0;
|
||||
}
|
||||
if (n > l + 4) {
|
||||
*(short *)(rom.data() + l) = n - l - 4;
|
||||
*(short *)(rom.data() + l + 2) = o ? bank_lwr[k] : 0xd000;
|
||||
*(short *)(rom.mutable_data() + l) = n - l - 4;
|
||||
*(short *)(rom.mutable_data() + l + 2) = o ? bank_lwr[k] : 0xd000;
|
||||
l = n;
|
||||
}
|
||||
}
|
||||
*(short *)(rom.data() + l) = 0;
|
||||
*(short *)(rom.data() + l + 2) = 0x800;
|
||||
*(short *)(rom.mutable_data() + l) = 0;
|
||||
*(short *)(rom.mutable_data() + l + 2) = 0x800;
|
||||
if (k == 1) m = l + 4;
|
||||
}
|
||||
free(ssblt);
|
||||
|
||||
@@ -74,7 +74,7 @@ absl::Status Inventory::Create() {
|
||||
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())
|
||||
ASSIGN_OR_RETURN(tilesheets_, Load2BppGraphics(*rom()))
|
||||
std::vector<uint8_t> test;
|
||||
for (int i = 0; i < 0x4000; i++) {
|
||||
test_.push_back(tilesheets_[i]);
|
||||
|
||||
Reference in New Issue
Block a user