refactor rom interface
This commit is contained in:
@@ -57,15 +57,14 @@ void ROM::LoadFromFile(const std::string &path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<tile8> ROM::ExtractTiles(gfx::TilePreset &preset) {
|
std::vector<tile8> ROM::ExtractTiles(gfx::TilePreset &preset) {
|
||||||
uint filePos = 0;
|
|
||||||
uint size_out = 0;
|
uint size_out = 0;
|
||||||
uint size = preset.length_;
|
uint size = preset.length_;
|
||||||
int tilePos = preset.pc_tiles_location_;
|
int tile_pos = preset.pc_tiles_location_;
|
||||||
std::vector<tile8> rawTiles;
|
std::vector<tile8> rawTiles;
|
||||||
|
|
||||||
// decompress the gfx
|
// decompress the gfx
|
||||||
auto data = (char *)malloc(sizeof(char) * size);
|
auto data = (char *)malloc(sizeof(char) * size);
|
||||||
memcpy(data, (current_rom_ + tilePos), size);
|
memcpy(data, (current_rom_ + tile_pos), size);
|
||||||
data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
data = alttp_decompress_gfx(data, 0, size, &size_out, &compressed_size_);
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
std::cout << alttp_decompression_error << std::endl;
|
std::cout << alttp_decompression_error << std::endl;
|
||||||
@@ -74,9 +73,8 @@ std::vector<tile8> ROM::ExtractTiles(gfx::TilePreset &preset) {
|
|||||||
|
|
||||||
// unpack the tiles based on their depth
|
// unpack the tiles based on their depth
|
||||||
unsigned tileCpt = 0;
|
unsigned tileCpt = 0;
|
||||||
for (unsigned int tilePos = 0; tilePos < size;
|
for (tile_pos = 0; tile_pos < size; tile_pos += preset.bits_per_pixel_ * 8) {
|
||||||
tilePos += preset.bits_per_pixel_ * 8) {
|
tile8 newTile = unpack_bpp_tile(data, tile_pos, preset.bits_per_pixel_);
|
||||||
tile8 newTile = unpack_bpp_tile(data, tilePos, preset.bits_per_pixel_);
|
|
||||||
newTile.id = tileCpt;
|
newTile.id = tileCpt;
|
||||||
rawTiles.push_back(newTile);
|
rawTiles.push_back(newTile);
|
||||||
tileCpt++;
|
tileCpt++;
|
||||||
@@ -194,23 +192,19 @@ uchar *ROM::SNES3bppTo8bppSheet(uchar *buffer_in, int sheet_id,
|
|||||||
{
|
{
|
||||||
//[0] + [1] + [16]
|
//[0] + [1] + [16]
|
||||||
for (int x = 0; x < 8; x++) {
|
for (int x = 0; x < 8; x++) {
|
||||||
unsigned char b1 =
|
auto b1 = (uchar)((buffer_in[(y * 2) + (24 * pos)] & (bitmask[x])));
|
||||||
(unsigned char)((buffer_in[(y * 2) + (24 * pos)] & (bitmask[x])));
|
auto b2 = (uchar)(buffer_in[((y * 2) + (24 * pos)) + 1] & (bitmask[x]));
|
||||||
unsigned char b2 =
|
auto b3 = (uchar)(buffer_in[(16 + y) + (24 * pos)] & (bitmask[x]));
|
||||||
(unsigned char)(buffer_in[((y * 2) + (24 * pos)) + 1] &
|
|
||||||
(bitmask[x]));
|
|
||||||
unsigned char b3 =
|
|
||||||
(unsigned char)(buffer_in[(16 + y) + (24 * pos)] & (bitmask[x]));
|
|
||||||
unsigned char b = 0;
|
unsigned char b = 0;
|
||||||
if (b1 != 0) {
|
if (b1 != 0) {
|
||||||
b |= 1;
|
b |= 1;
|
||||||
};
|
}
|
||||||
if (b2 != 0) {
|
if (b2 != 0) {
|
||||||
b |= 2;
|
b |= 2;
|
||||||
};
|
}
|
||||||
if (b3 != 0) {
|
if (b3 != 0) {
|
||||||
b |= 4;
|
b |= 4;
|
||||||
};
|
}
|
||||||
sheet_buffer_out[x + (xx) + (y * 128) + (yy * 1024)] = b;
|
sheet_buffer_out[x + (xx) + (y * 128) + (yy * 1024)] = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,11 +231,11 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) {
|
|||||||
surface->format->palette->colors[i].b = i * 31;
|
surface->format->palette->colors[i].b = i * 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int snesAddr = 0;
|
uint snesAddr = 0;
|
||||||
unsigned int pcAddr = 0;
|
uint pcAddr = 0;
|
||||||
snesAddr = (unsigned int)((((uchar)(current_rom_[0x4F80 + offset]) << 16) |
|
snesAddr = (uint)((((current_rom_[0x4F80 + offset]) << 16) |
|
||||||
((uchar)(current_rom_[0x505F + offset]) << 8) |
|
((current_rom_[0x505F + offset]) << 8) |
|
||||||
((uchar)(current_rom_[0x513E + offset]))));
|
((current_rom_[0x513E + offset]))));
|
||||||
pcAddr = SnesToPc(snesAddr);
|
pcAddr = SnesToPc(snesAddr);
|
||||||
std::cout << "Decompressing..." << std::endl;
|
std::cout << "Decompressing..." << std::endl;
|
||||||
char *decomp = Decompress(pcAddr);
|
char *decomp = Decompress(pcAddr);
|
||||||
@@ -258,24 +252,24 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) {
|
|||||||
return sheet_texture;
|
return sheet_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ROM::AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) {
|
int ROM::AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) const {
|
||||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ROM::GetPCGfxAddress(uint8_t id) {
|
int ROM::GetPCGfxAddress(uint8_t id) {
|
||||||
int gfxPointer1 =
|
int gfxPtr1 =
|
||||||
SnesToPc((current_rom_[core::constants::gfx_1_pointer + 1] << 8) +
|
SnesToPc((current_rom_[core::constants::gfx_1_pointer + 1] << 8) +
|
||||||
(current_rom_[core::constants::gfx_1_pointer]));
|
(current_rom_[core::constants::gfx_1_pointer]));
|
||||||
int gfxPointer2 =
|
int gfxPtr2 =
|
||||||
SnesToPc((current_rom_[core::constants::gfx_2_pointer + 1] << 8) +
|
SnesToPc((current_rom_[core::constants::gfx_2_pointer + 1] << 8) +
|
||||||
(current_rom_[core::constants::gfx_2_pointer]));
|
(current_rom_[core::constants::gfx_2_pointer]));
|
||||||
int gfxPointer3 =
|
int gfxPtr3 =
|
||||||
SnesToPc((current_rom_[core::constants::gfx_3_pointer + 1] << 8) +
|
SnesToPc((current_rom_[core::constants::gfx_3_pointer + 1] << 8) +
|
||||||
(current_rom_[core::constants::gfx_3_pointer]));
|
(current_rom_[core::constants::gfx_3_pointer]));
|
||||||
|
|
||||||
uint8_t gfxGamePointer1 = current_rom_[gfxPointer1 + id];
|
uint8_t gfxGamePointer1 = current_rom_[gfxPtr1 + id];
|
||||||
uint8_t gfxGamePointer2 = current_rom_[gfxPointer2 + id];
|
uint8_t gfxGamePointer2 = current_rom_[gfxPtr2 + id];
|
||||||
uint8_t gfxGamePointer3 = current_rom_[gfxPointer3 + id];
|
uint8_t gfxGamePointer3 = current_rom_[gfxPtr3 + id];
|
||||||
|
|
||||||
return SnesToPc(
|
return SnesToPc(
|
||||||
AddressFromBytes(gfxGamePointer1, gfxGamePointer2, gfxGamePointer3));
|
AddressFromBytes(gfxGamePointer1, gfxGamePointer2, gfxGamePointer3));
|
||||||
@@ -288,8 +282,8 @@ char *ROM::CreateAllGfxDataRaw() {
|
|||||||
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
|
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
|
||||||
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||||
|
|
||||||
char *buffer = new char[346624];
|
auto *buffer = new char[346624];
|
||||||
char *data = new char[2048];
|
auto *data = new char[2048];
|
||||||
int bufferPos = 0;
|
int bufferPos = 0;
|
||||||
unsigned int uncompressedSize = 0;
|
unsigned int uncompressedSize = 0;
|
||||||
unsigned int compressedSize = 0;
|
unsigned int compressedSize = 0;
|
||||||
@@ -326,19 +320,17 @@ char *ROM::CreateAllGfxDataRaw() {
|
|||||||
|
|
||||||
void ROM::CreateAllGraphicsData(uchar *allGfx16Ptr) {
|
void ROM::CreateAllGraphicsData(uchar *allGfx16Ptr) {
|
||||||
int sheetPosition = 0;
|
int sheetPosition = 0;
|
||||||
char *data = CreateAllGfxDataRaw();
|
char const *data = CreateAllGfxDataRaw();
|
||||||
char *newData = new char[0x6F800];
|
auto *newData = new char[0x6F800];
|
||||||
uchar *mask = new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
uchar const *mask =
|
||||||
|
new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||||
|
|
||||||
// 8x8 tile
|
// 8x8 tile
|
||||||
// Per Sheet
|
// Per Sheet
|
||||||
for (int s = 0; s < core::constants::NumberOfSheets; s++) {
|
for (int s = 0; s < core::constants::NumberOfSheets; s++) {
|
||||||
// Per Tile Line Y
|
for (int j = 0; j < 4; j++) { // Per Tile Line Y
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int i = 0; i < 16; i++) { // Per Tile Line X
|
||||||
// Per Tile Line X
|
for (int y = 0; y < 8; y++) { // Per Pixel Line
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
// Per Pixel Line
|
|
||||||
for (int y = 0; y < 8; y++) {
|
|
||||||
if (isbpp3[s]) {
|
if (isbpp3[s]) {
|
||||||
uchar lineBits0 =
|
uchar lineBits0 =
|
||||||
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||||
@@ -415,7 +407,7 @@ void ROM::CreateAllGraphicsData(uchar *allGfx16Ptr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uchar *allgfx16Data = (uchar *)allGfx16Ptr;
|
auto *allgfx16Data = allGfx16Ptr;
|
||||||
for (int i = 0; i < 0x6F800; i++) {
|
for (int i = 0; i < 0x6F800; i++) {
|
||||||
allgfx16Data[i] = newData[i];
|
allgfx16Data[i] = newData[i];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class ROM {
|
|||||||
uchar* SNES3bppTo8bppSheet(uchar* buffer_in, int sheet_id = 0, int size = 0x1000);
|
uchar* SNES3bppTo8bppSheet(uchar* buffer_in, int sheet_id = 0, int size = 0x1000);
|
||||||
SDL_Texture* DrawGraphicsSheet(int offset);
|
SDL_Texture* DrawGraphicsSheet(int offset);
|
||||||
|
|
||||||
int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3);
|
int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) const;
|
||||||
|
|
||||||
int GetPCGfxAddress(uint8_t id);
|
int GetPCGfxAddress(uint8_t id);
|
||||||
char* CreateAllGfxDataRaw();
|
char* CreateAllGfxDataRaw();
|
||||||
@@ -41,14 +41,15 @@ class ROM {
|
|||||||
|
|
||||||
void LoadBlocksetGraphics(int graphics_id);
|
void LoadBlocksetGraphics(int graphics_id);
|
||||||
|
|
||||||
unsigned int SnesToPc(unsigned int addr) {
|
unsigned int SnesToPc(unsigned int addr) const {
|
||||||
if (addr >= 0x808000) {
|
if (addr >= 0x808000) {
|
||||||
addr -= 0x808000;
|
addr -= 0x808000;
|
||||||
}
|
}
|
||||||
unsigned int temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000);
|
unsigned int temp = (addr & 0x7FFF) + ((addr / 2) & 0xFF8000);
|
||||||
return (temp + 0x0);
|
return (temp + 0x0);
|
||||||
}
|
}
|
||||||
inline uchar* GetRawData() { return current_rom_; }
|
|
||||||
|
inline uchar* data() { return current_rom_; }
|
||||||
inline auto Renderer() { return sdl_renderer_; }
|
inline auto Renderer() { return sdl_renderer_; }
|
||||||
const uchar* getTitle() const { return title; }
|
const uchar* getTitle() const { return title; }
|
||||||
long int getSize() const { return size_; }
|
long int getSize() const { return size_; }
|
||||||
@@ -59,9 +60,7 @@ class ROM {
|
|||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
bool has_header_ = false;
|
bool has_header_ = false;
|
||||||
long int size_;
|
long int size_;
|
||||||
uint uncompressed_size_;
|
|
||||||
uint compressed_size_;
|
uint compressed_size_;
|
||||||
uint compress_size_;
|
|
||||||
uchar* current_rom_;
|
uchar* current_rom_;
|
||||||
uchar version_;
|
uchar version_;
|
||||||
uchar title[21] = "ROM Not Loaded";
|
uchar title[21] = "ROM Not Loaded";
|
||||||
|
|||||||
Reference in New Issue
Block a user