Working on tile16 blockset
This commit is contained in:
168
src/app/rom.cc
168
src/app/rom.cc
@@ -19,9 +19,6 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace rom {
|
||||
int AddressFromBytes(uchar addr1, uchar addr2, uchar addr3) {
|
||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||
}
|
||||
|
||||
void ROM::Close() {
|
||||
if (loaded) {
|
||||
@@ -282,6 +279,171 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) {
|
||||
}
|
||||
return sheet_texture;
|
||||
}
|
||||
|
||||
int ROM::AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) {
|
||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||
}
|
||||
|
||||
int ROM::GetPCGfxAddress(uint8_t id) {
|
||||
int gfxPointer1 =
|
||||
SnesToPc((current_rom_[core::constants::gfx_1_pointer + 1] << 8) +
|
||||
(current_rom_[core::constants::gfx_1_pointer]));
|
||||
int gfxPointer2 =
|
||||
SnesToPc((current_rom_[core::constants::gfx_2_pointer + 1] << 8) +
|
||||
(current_rom_[core::constants::gfx_2_pointer]));
|
||||
int gfxPointer3 =
|
||||
SnesToPc((current_rom_[core::constants::gfx_3_pointer + 1] << 8) +
|
||||
(current_rom_[core::constants::gfx_3_pointer]));
|
||||
|
||||
uint8_t gfxGamePointer1 = current_rom_[gfxPointer1 + id];
|
||||
uint8_t gfxGamePointer2 = current_rom_[gfxPointer2 + id];
|
||||
uint8_t gfxGamePointer3 = current_rom_[gfxPointer3 + id];
|
||||
|
||||
return SnesToPc(
|
||||
AddressFromBytes(gfxGamePointer1, gfxGamePointer2, gfxGamePointer3));
|
||||
}
|
||||
|
||||
char *ROM::CreateAllGfxDataRaw() {
|
||||
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
|
||||
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
|
||||
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
|
||||
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
|
||||
char *buffer = new char[346624];
|
||||
char *data = new char[2048];
|
||||
int bufferPos = 0;
|
||||
unsigned int uncompressedSize = 0;
|
||||
unsigned int compressedSize = 0;
|
||||
|
||||
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
|
||||
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
|
||||
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
|
||||
(i >= 127 && i <= 217) // Compressed 3bpp sprites
|
||||
);
|
||||
|
||||
// uncompressed sheets
|
||||
if (i >= 115 && i <= 126) {
|
||||
data = new char[core::constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(i);
|
||||
for (int j = 0; j < core::constants::Uncompressed3BPPSize; j++) {
|
||||
data[j] = current_rom_[j + startAddress];
|
||||
}
|
||||
} else {
|
||||
data =
|
||||
alttp_decompress_gfx((char *)current_rom_, GetPCGfxAddress((char)i),
|
||||
core::constants::UncompressedSheetSize,
|
||||
&uncompressedSize, &compressedSize);
|
||||
}
|
||||
|
||||
for (int j = 0; j < sizeof(data); j++) {
|
||||
buffer[j + bufferPos] = data[j];
|
||||
}
|
||||
|
||||
bufferPos += sizeof(data);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void ROM::CreateAllGraphicsData(uchar *allGfx16Ptr) {
|
||||
char *data = CreateAllGfxDataRaw();
|
||||
char *newData = new char[0x6F800];
|
||||
uchar *mask = new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
int sheetPosition = 0;
|
||||
|
||||
// 8x8 tile
|
||||
for (int s = 0; s < core::constants::NumberOfSheets; s++) // Per Sheet
|
||||
{
|
||||
for (int j = 0; j < 4; j++) // Per Tile Line Y
|
||||
{
|
||||
for (int i = 0; i < 16; i++) // Per Tile Line X
|
||||
{
|
||||
for (int y = 0; y < 8; y++) // Per Pixel Line
|
||||
{
|
||||
if (isbpp3[s]) {
|
||||
uchar lineBits0 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||
uchar lineBits1 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
|
||||
uchar lineBits2 =
|
||||
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
uchar pixdata = 0;
|
||||
uchar pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 4;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 4;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
} else {
|
||||
uchar lineBits0 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
|
||||
uchar lineBits1 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
uchar pixdata = 0;
|
||||
uchar pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(uchar)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isbpp3[s]) {
|
||||
sheetPosition += core::constants::Uncompressed3BPPSize;
|
||||
} else {
|
||||
sheetPosition += core::constants::UncompressedSheetSize;
|
||||
}
|
||||
}
|
||||
|
||||
uchar *allgfx16Data = (uchar *)allGfx16Ptr;
|
||||
|
||||
for (int i = 0; i < 0x6F800; i++) {
|
||||
allgfx16Data[i] = newData[i];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rom
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
Reference in New Issue
Block a user