more cleanup, case sensitivity, removing unused code, etc
This commit is contained in:
@@ -13,6 +13,7 @@ ROM::~ROM() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check if the rom has a header on load
|
||||
void ROM::LoadFromFile(const std::string &path) {
|
||||
type_ = LoROM;
|
||||
size_ = std::filesystem::file_size(path.c_str());
|
||||
@@ -21,6 +22,7 @@ void ROM::LoadFromFile(const std::string &path) {
|
||||
std::cout << "Error: Could not open ROM file " << path << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
current_rom_ = new unsigned char[size_];
|
||||
data_ = new char[size_];
|
||||
for (unsigned int i = 0; i < size_; i++) {
|
||||
@@ -36,24 +38,23 @@ void ROM::LoadFromFile(const std::string &path) {
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
std::vector<tile8> ROM::ExtractTiles(TilePreset &preset) {
|
||||
std::vector<tile8> ROM::ExtractTiles(Graphics::TilePreset &preset) {
|
||||
std::cout << "Extracting tiles..." << std::endl;
|
||||
uint filePos = 0;
|
||||
uint size_out = 0;
|
||||
uint size = preset.length;
|
||||
int tilePos = preset.pcTilesLocation;
|
||||
std::vector<tile8> rawTiles;
|
||||
filePos = getRomPosition(preset, tilePos, preset.SNESTilesLocation);
|
||||
filePos = GetRomPosition(preset, tilePos, preset.SNESTilesLocation);
|
||||
std::cout << "ROM Position: " << filePos << " from "
|
||||
<< preset.SNESTilesLocation << std::endl;
|
||||
|
||||
// decompress the graphics
|
||||
char *data = (char *)malloc(sizeof(char) * size);
|
||||
memcpy(data, (data_ + filePos), size);
|
||||
// data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
||||
// std::cout << "size: " << size << std::endl;
|
||||
// std::cout << "lastCompressedSize: " << compressed_size_ << std::endl;
|
||||
data = Decompress(filePos);
|
||||
data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
||||
std::cout << "size: " << size << std::endl;
|
||||
std::cout << "lastCompressedSize: " << compressed_size_ << std::endl;
|
||||
if (data == NULL) {
|
||||
std::cout << alttp_decompression_error << std::endl;
|
||||
return rawTiles;
|
||||
@@ -74,8 +75,8 @@ std::vector<tile8> ROM::ExtractTiles(TilePreset &preset) {
|
||||
return rawTiles;
|
||||
}
|
||||
|
||||
SNESPalette ROM::ExtractPalette(TilePreset &preset) {
|
||||
unsigned int filePos = getRomPosition(preset, preset.pcPaletteLocation,
|
||||
Graphics::SNESPalette ROM::ExtractPalette(Graphics::TilePreset &preset) {
|
||||
unsigned int filePos = GetRomPosition(preset, preset.pcPaletteLocation,
|
||||
preset.SNESPaletteLocation);
|
||||
std::cout << "Palette pos : " << filePos << std::endl; // TODO: make this hex
|
||||
unsigned int palette_size = pow(2, preset.bpp); // - 1;
|
||||
@@ -88,9 +89,9 @@ SNESPalette ROM::ExtractPalette(TilePreset &preset) {
|
||||
std::cout << std::endl;
|
||||
|
||||
const char *data = ab;
|
||||
SNESPalette pal(ab);
|
||||
Graphics::SNESPalette pal(ab);
|
||||
if (preset.paletteNoZeroColor) {
|
||||
SNESColor col;
|
||||
Graphics::SNESColor col;
|
||||
|
||||
col.setRgb(ImVec4(153, 153, 153, 255));
|
||||
pal.colors.push_back(col);
|
||||
@@ -100,19 +101,18 @@ SNESPalette ROM::ExtractPalette(TilePreset &preset) {
|
||||
return pal;
|
||||
}
|
||||
|
||||
unsigned int ROM::getRomPosition(const TilePreset &preset, int directAddr,
|
||||
unsigned int snesAddr) {
|
||||
bool romHasHeader = false; // romInfo.hasHeader
|
||||
uint32_t ROM::GetRomPosition(const Graphics::TilePreset &preset, int directAddr,
|
||||
unsigned int snesAddr) {
|
||||
unsigned int filePos = -1;
|
||||
enum rom_type rType = LoROM;
|
||||
std::cout << "ROM::getRomPosition: directAddr:" << directAddr << std::endl;
|
||||
std::cout << "directAddr:" << directAddr << std::endl;
|
||||
if (directAddr == -1) {
|
||||
filePos = rommapping_snes_to_pc(snesAddr, rType, romHasHeader);
|
||||
filePos = rommapping_snes_to_pc(snesAddr, rType, rom_has_header_);
|
||||
} else {
|
||||
filePos = directAddr;
|
||||
if (romHasHeader) filePos += 0x200;
|
||||
if (rom_has_header_) filePos += 0x200;
|
||||
}
|
||||
std::cout << "ROM::getRomPosition: filePos:" << filePos << std::endl;
|
||||
std::cout << "filePos:" << filePos << std::endl;
|
||||
return filePos;
|
||||
}
|
||||
|
||||
@@ -120,83 +120,6 @@ int AddressFromBytes(byte addr1, byte addr2, byte addr3) {
|
||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||
}
|
||||
|
||||
short ROM::AddressFromBytes(byte addr1, byte addr2) {
|
||||
return (short)((addr1 << 8) | (addr2));
|
||||
}
|
||||
|
||||
char *ROM::Decompress(int pos, bool reversed) {
|
||||
char *buffer = new char[0x600];
|
||||
for (int i = 0; i < 0x600; i++) {
|
||||
buffer[i] = 0;
|
||||
}
|
||||
unsigned int bufferPos = 0;
|
||||
unsigned char cmd = 0;
|
||||
unsigned int length = 0;
|
||||
unsigned char databyte = (unsigned char)data_[pos];
|
||||
while (true) {
|
||||
databyte = (unsigned char)data_[pos];
|
||||
if (databyte == 0xFF) // End of decompression
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if ((databyte & 0xE0) == 0xE0) // Expanded Command
|
||||
{
|
||||
cmd = (unsigned char)((databyte >> 2) & 0x07);
|
||||
length = (unsigned short)(((data_[pos] << 8) | data_[pos + 1]) & 0x3FF);
|
||||
pos += 2; // Advance 2 bytes in ROM
|
||||
} else // Normal Command
|
||||
{
|
||||
cmd = (unsigned char)((databyte >> 5) & 0x07);
|
||||
length = (unsigned char)(databyte & 0x1F);
|
||||
pos += 1; // Advance 1 byte in ROM
|
||||
}
|
||||
length += 1; // Every commands are at least 1 size even if 00
|
||||
switch (cmd) {
|
||||
case 00: // Direct Copy (Could be replaced with a MEMCPY)
|
||||
for (int i = 0; i < length; i++) {
|
||||
buffer[bufferPos++] = (unsigned char)data_[pos++];
|
||||
}
|
||||
// Do not advance in the ROM
|
||||
break;
|
||||
case 01: // Byte Fill
|
||||
for (int i = 0; i < length; i++) {
|
||||
buffer[bufferPos++] = (unsigned char)data_[pos];
|
||||
}
|
||||
pos += 1; // Advance 1 byte in the ROM
|
||||
break;
|
||||
case 02: // Word Fill
|
||||
for (int i = 0; i < length; i++) {
|
||||
buffer[bufferPos++] = (unsigned char)data_[pos];
|
||||
buffer[bufferPos++] = (unsigned char)data_[pos + 1];
|
||||
}
|
||||
pos += 2; // Advance 2 byte in the ROM
|
||||
break;
|
||||
case 03: // Increasing Fill
|
||||
{
|
||||
unsigned char incByte = (unsigned char)data_[pos];
|
||||
for (int i = 0; i < (unsigned int)length; i++) {
|
||||
buffer[bufferPos++] = (unsigned char)incByte++;
|
||||
}
|
||||
pos += 1; // Advance 1 byte in the ROM
|
||||
} break;
|
||||
case 04: // Repeat (Reversed byte order for maps)
|
||||
{
|
||||
unsigned short s1 = ((data_[pos + 1] & 0xFF) << 8);
|
||||
unsigned short s2 = ((data_[pos] & 0xFF));
|
||||
unsigned short Addr = (unsigned short)(s1 | s2);
|
||||
printf("Repeat Address : %4X", Addr);
|
||||
for (int i = 0; i < length; i++) {
|
||||
buffer[bufferPos] = (unsigned char)buffer[Addr + i];
|
||||
bufferPos++;
|
||||
}
|
||||
pos += 2; // Advance 2 bytes in the ROM
|
||||
} break;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
} // namespace Application
|
||||
} // namespace yaze
|
||||
@@ -21,9 +21,6 @@ namespace Application {
|
||||
namespace Data {
|
||||
|
||||
using byte = unsigned char;
|
||||
using ushort = unsigned short;
|
||||
|
||||
using namespace Graphics;
|
||||
|
||||
int AddressFromBytes(byte addr1, byte addr2, byte addr3);
|
||||
|
||||
@@ -32,21 +29,19 @@ class ROM {
|
||||
~ROM();
|
||||
|
||||
void LoadFromFile(const std::string& path);
|
||||
std::vector<tile8> ExtractTiles(TilePreset& preset);
|
||||
SNESPalette ExtractPalette(TilePreset& preset);
|
||||
unsigned int getRomPosition(const TilePreset& preset, int directAddr,
|
||||
unsigned int snesAddr);
|
||||
short AddressFromBytes(byte addr1, byte addr2);
|
||||
char* Decompress(int pos, bool reversed = false);
|
||||
|
||||
std::vector<tile8> ExtractTiles(Graphics::TilePreset& preset);
|
||||
Graphics::SNESPalette ExtractPalette(Graphics::TilePreset& preset);
|
||||
uint32_t GetRomPosition(const Graphics::TilePreset& preset,
|
||||
int directAddr, unsigned int snesAddr);
|
||||
inline byte* GetRawData() { return current_rom_; }
|
||||
const unsigned char* getTitle() const { return title; }
|
||||
unsigned int getSize() const { return size_; }
|
||||
long int getSize() const { return size_; }
|
||||
char getVersion() const { return version_; }
|
||||
bool isLoaded() const { return loaded; }
|
||||
|
||||
private:
|
||||
bool loaded = false;
|
||||
bool rom_has_header_ = false;
|
||||
|
||||
byte* current_rom_;
|
||||
char* data_;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "Bitmap.h"
|
||||
#include "bitmap.h"
|
||||
|
||||
#include "data/rom.h"
|
||||
#include "rommapping.h"
|
||||
#include <rommapping.h>
|
||||
|
||||
#include "Data/rom.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace Application {
|
||||
@@ -182,36 +183,38 @@ int Bitmap::GetHeight() { return height_; }
|
||||
|
||||
// Simple helper function to load an image into a OpenGL texture with common
|
||||
// settings
|
||||
bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data,
|
||||
int *out_width, int *out_height) {
|
||||
// // Load from file
|
||||
// int image_width = 0;
|
||||
// int image_height = 0;
|
||||
// if (texture_data == NULL) return false;
|
||||
bool Bitmap::LoadBitmapFromROM(unsigned char *texture_data, int *out_width,
|
||||
int *out_height) {
|
||||
// // Load from file
|
||||
// int image_width = 0;
|
||||
// int image_height = 0;
|
||||
// if (texture_data == NULL) return false;
|
||||
|
||||
// // Create a OpenGL texture identifier
|
||||
// GLuint image_texture;
|
||||
// glGenTextures(1, &image_texture);
|
||||
// glBindTexture(GL_TEXTURE_2D, image_texture);
|
||||
// // Create a OpenGL texture identifier
|
||||
// GLuint image_texture;
|
||||
// glGenTextures(1, &image_texture);
|
||||
// glBindTexture(GL_TEXTURE_2D, image_texture);
|
||||
|
||||
// // Setup filtering parameters for display
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||
// GL_CLAMP_TO_EDGE); // This is required on WebGL for non
|
||||
// // power-of-two textures
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Same
|
||||
// // Setup filtering parameters for display
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
|
||||
// GL_CLAMP_TO_EDGE); // This is required on WebGL for non
|
||||
// // power-of-two textures
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //
|
||||
// Same
|
||||
|
||||
// // Upload pixels into texture
|
||||
// #if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
||||
// glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
// #endif
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA,
|
||||
// GL_UNSIGNED_BYTE, texture_data);
|
||||
// // Upload pixels into texture
|
||||
// #if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
|
||||
// glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
// #endif
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0,
|
||||
// GL_RGBA,
|
||||
// GL_UNSIGNED_BYTE, texture_data);
|
||||
|
||||
// *out_texture = image_texture;
|
||||
// *out_width = image_width;
|
||||
// *out_height = image_height;
|
||||
// *out_texture = image_texture;
|
||||
// *out_width = image_width;
|
||||
// *out_height = image_height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ class Bitmap {
|
||||
int GetWidth();
|
||||
int GetHeight();
|
||||
|
||||
bool LoadBitmapFromROM(unsigned char *texture_data,
|
||||
int *out_width, int *out_height);
|
||||
bool LoadBitmapFromROM(unsigned char *texture_data, int *out_width,
|
||||
int *out_height);
|
||||
|
||||
private:
|
||||
int width_;
|
||||
|
||||
Reference in New Issue
Block a user