cleanup allocated rom data
This commit is contained in:
@@ -6,22 +6,30 @@ namespace yaze {
|
|||||||
namespace Application {
|
namespace Application {
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
|
ROM::~ROM() {
|
||||||
|
if (loaded) {
|
||||||
|
delete[] current_rom_;
|
||||||
|
delete[] data_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ROM::LoadFromFile(const std::string &path) {
|
void ROM::LoadFromFile(const std::string &path) {
|
||||||
type_ = LoROM;
|
type_ = LoROM;
|
||||||
size_ = std::filesystem::file_size(path.c_str());
|
size_ = std::filesystem::file_size(path.c_str());
|
||||||
std::ifstream file(path.c_str(), std::ios::binary);
|
std::ifstream file(path.c_str(), std::ios::binary);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
std::cout << "Error: Could not open ROM file " << path << std::endl;
|
std::cout << "Error: Could not open ROM file " << path << std::endl;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
current_rom_ = new unsigned char[size_];
|
current_rom_ = new unsigned char[size_];
|
||||||
data_ = new char[size_];
|
data_ = new char[size_];
|
||||||
|
|
||||||
for (unsigned int i = 0; i < size_; i++) {
|
for (unsigned int i = 0; i < size_; i++) {
|
||||||
char byte_read_ = ' ';
|
char byte_read_ = ' ';
|
||||||
file.read(&byte_read_, sizeof(char));
|
file.read(&byte_read_, sizeof(char));
|
||||||
current_rom_[i] = byte_read_;
|
current_rom_[i] = byte_read_;
|
||||||
data_[i] = byte_read_;
|
data_[i] = byte_read_;
|
||||||
}
|
}
|
||||||
|
file.close();
|
||||||
|
|
||||||
memcpy(title, data_ + 32704, 21);
|
memcpy(title, data_ + 32704, 21);
|
||||||
version_ = current_rom_[27];
|
version_ = current_rom_[27];
|
||||||
@@ -42,15 +50,15 @@ std::vector<tile8> ROM::ExtractTiles(TilePreset &preset) {
|
|||||||
// decompress the graphics
|
// decompress the graphics
|
||||||
char *data = (char *)malloc(sizeof(char) * size);
|
char *data = (char *)malloc(sizeof(char) * size);
|
||||||
memcpy(data, (data_ + filePos), size);
|
memcpy(data, (data_ + filePos), size);
|
||||||
//data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
// data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
||||||
// std::cout << "size: " << size << std::endl;
|
// std::cout << "size: " << size << std::endl;
|
||||||
// std::cout << "lastCompressedSize: " << compressed_size_ << std::endl;
|
// std::cout << "lastCompressedSize: " << compressed_size_ << std::endl;
|
||||||
data = Decompress(filePos);
|
data = Decompress(filePos);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
std::cout << alttp_decompression_error << std::endl;
|
std::cout << alttp_decompression_error << std::endl;
|
||||||
return rawTiles;
|
return rawTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unpack the tiles based on their depth
|
// unpack the tiles based on their depth
|
||||||
unsigned tileCpt = 0;
|
unsigned tileCpt = 0;
|
||||||
std::cout << "Unpacking tiles..." << std::endl;
|
std::cout << "Unpacking tiles..." << std::endl;
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ int AddressFromBytes(byte addr1, byte addr2, byte addr3);
|
|||||||
|
|
||||||
class ROM {
|
class ROM {
|
||||||
public:
|
public:
|
||||||
|
~ROM();
|
||||||
|
|
||||||
void LoadFromFile(const std::string& path);
|
void LoadFromFile(const std::string& path);
|
||||||
std::vector<tile8> ExtractTiles(TilePreset& preset);
|
std::vector<tile8> ExtractTiles(TilePreset& preset);
|
||||||
SNESPalette ExtractPalette(TilePreset& preset);
|
SNESPalette ExtractPalette(TilePreset& preset);
|
||||||
|
|||||||
Reference in New Issue
Block a user