Move SnesTo8bppSheet to gfx namespace
This commit is contained in:
@@ -9,6 +9,53 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
|
Bytes SnesTo8bppSheet(Bytes sheet, int bpp) {
|
||||||
|
int xx = 0; // positions where we are at on the sheet
|
||||||
|
int yy = 0;
|
||||||
|
int pos = 0;
|
||||||
|
int ypos = 0;
|
||||||
|
int num_tiles = 64;
|
||||||
|
int buffer_size = 0x1000;
|
||||||
|
if (bpp == 2) {
|
||||||
|
bpp = 16;
|
||||||
|
num_tiles = 128;
|
||||||
|
buffer_size = 0x2000;
|
||||||
|
} else if (bpp == 3) {
|
||||||
|
bpp = 24;
|
||||||
|
}
|
||||||
|
Bytes sheet_buffer_out(buffer_size);
|
||||||
|
|
||||||
|
for (int i = 0; i < num_tiles; i++) { // for each tiles, 16 per line
|
||||||
|
for (int y = 0; y < 8; y++) { // for each line
|
||||||
|
for (int x = 0; x < 8; x++) { //[0] + [1] + [16]
|
||||||
|
auto b1 = (sheet[(y * 2) + (bpp * pos)] & (kGraphicsBitmap[x]));
|
||||||
|
auto b2 = (sheet[((y * 2) + (bpp * pos)) + 1] & (kGraphicsBitmap[x]));
|
||||||
|
auto b3 = (sheet[(16 + y) + (bpp * pos)] & (kGraphicsBitmap[x]));
|
||||||
|
unsigned char b = 0;
|
||||||
|
if (b1 != 0) {
|
||||||
|
b |= 1;
|
||||||
|
}
|
||||||
|
if (b2 != 0) {
|
||||||
|
b |= 2;
|
||||||
|
}
|
||||||
|
if (b3 != 0 && bpp != 16) {
|
||||||
|
b |= 4;
|
||||||
|
}
|
||||||
|
sheet_buffer_out[x + xx + (y * 128) + (yy * 1024)] = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
|
ypos++;
|
||||||
|
xx += 8;
|
||||||
|
if (ypos >= 16) {
|
||||||
|
yy++;
|
||||||
|
xx = 0;
|
||||||
|
ypos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sheet_buffer_out;
|
||||||
|
}
|
||||||
|
|
||||||
TileInfo GetTilesInfo(ushort tile) {
|
TileInfo GetTilesInfo(ushort tile) {
|
||||||
// vhopppcc cccccccc
|
// vhopppcc cccccccc
|
||||||
bool o = false;
|
bool o = false;
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
|
||||||
|
constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
|
||||||
|
0x08, 0x04, 0x02, 0x01};
|
||||||
|
|
||||||
|
Bytes SnesTo8bppSheet(Bytes sheet, int bpp);
|
||||||
|
|
||||||
struct tile8 {
|
struct tile8 {
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
char data[64];
|
char data[64];
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "app/core/common.h"
|
#include "app/core/common.h"
|
||||||
#include "app/core/constants.h"
|
#include "app/core/constants.h"
|
||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
|
#include "app/gfx/snes_tile.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace app {
|
namespace app {
|
||||||
@@ -352,53 +353,6 @@ int GetGraphicsAddress(const uchar* data, uint8_t offset) {
|
|||||||
return core::SnesToPc(snes_addr);
|
return core::SnesToPc(snes_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bytes SnesTo8bppSheet(Bytes sheet, int bpp) {
|
|
||||||
int xx = 0; // positions where we are at on the sheet
|
|
||||||
int yy = 0;
|
|
||||||
int pos = 0;
|
|
||||||
int ypos = 0;
|
|
||||||
int num_tiles = 64;
|
|
||||||
int buffer_size = 0x1000;
|
|
||||||
if (bpp == 2) {
|
|
||||||
bpp = 16;
|
|
||||||
num_tiles = 128;
|
|
||||||
buffer_size = 0x2000;
|
|
||||||
} else if (bpp == 3) {
|
|
||||||
bpp = 24;
|
|
||||||
}
|
|
||||||
Bytes sheet_buffer_out(buffer_size);
|
|
||||||
|
|
||||||
for (int i = 0; i < num_tiles; i++) { // for each tiles, 16 per line
|
|
||||||
for (int y = 0; y < 8; y++) { // for each line
|
|
||||||
for (int x = 0; x < 8; x++) { //[0] + [1] + [16]
|
|
||||||
auto b1 = (sheet[(y * 2) + (bpp * pos)] & (kGraphicsBitmap[x]));
|
|
||||||
auto b2 = (sheet[((y * 2) + (bpp * pos)) + 1] & (kGraphicsBitmap[x]));
|
|
||||||
auto b3 = (sheet[(16 + y) + (bpp * pos)] & (kGraphicsBitmap[x]));
|
|
||||||
unsigned char b = 0;
|
|
||||||
if (b1 != 0) {
|
|
||||||
b |= 1;
|
|
||||||
}
|
|
||||||
if (b2 != 0) {
|
|
||||||
b |= 2;
|
|
||||||
}
|
|
||||||
if (b3 != 0 && bpp != 16) {
|
|
||||||
b |= 4;
|
|
||||||
}
|
|
||||||
sheet_buffer_out[x + xx + (y * 128) + (yy * 1024)] = b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pos++;
|
|
||||||
ypos++;
|
|
||||||
xx += 8;
|
|
||||||
if (ypos >= 16) {
|
|
||||||
yy++;
|
|
||||||
xx = 0;
|
|
||||||
ypos = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sheet_buffer_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// TODO TEST compressed data border for each cmd
|
// TODO TEST compressed data border for each cmd
|
||||||
@@ -588,7 +542,7 @@ absl::StatusOr<Bytes> ROM::Load2bppGraphics() {
|
|||||||
for (const auto& sheet_id : sheets) {
|
for (const auto& sheet_id : sheets) {
|
||||||
auto offset = GetGraphicsAddress(rom_data_.data(), sheet_id);
|
auto offset = GetGraphicsAddress(rom_data_.data(), sheet_id);
|
||||||
ASSIGN_OR_RETURN(auto decomp_sheet, Decompress(offset))
|
ASSIGN_OR_RETURN(auto decomp_sheet, Decompress(offset))
|
||||||
auto converted_sheet = SnesTo8bppSheet(decomp_sheet, 2);
|
auto converted_sheet = gfx::SnesTo8bppSheet(decomp_sheet, 2);
|
||||||
for (const auto& each_pixel : converted_sheet) {
|
for (const auto& each_pixel : converted_sheet) {
|
||||||
sheet.push_back(each_pixel);
|
sheet.push_back(each_pixel);
|
||||||
}
|
}
|
||||||
@@ -624,7 +578,7 @@ absl::Status ROM::LoadAllGraphicsData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bpp3) {
|
if (bpp3) {
|
||||||
auto converted_sheet = SnesTo8bppSheet(sheet, 3);
|
auto converted_sheet = gfx::SnesTo8bppSheet(sheet, 3);
|
||||||
graphics_bin_[i] =
|
graphics_bin_[i] =
|
||||||
gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight,
|
gfx::Bitmap(core::kTilesheetWidth, core::kTilesheetHeight,
|
||||||
core::kTilesheetDepth, converted_sheet.data(), 0x1000);
|
core::kTilesheetDepth, converted_sheet.data(), 0x1000);
|
||||||
|
|||||||
@@ -55,8 +55,6 @@ constexpr int kExpandedMod = 0xE0;
|
|||||||
constexpr int kExpandedLengthMod = 0x3FF;
|
constexpr int kExpandedLengthMod = 0x3FF;
|
||||||
constexpr int kNormalLengthMod = 0x1F;
|
constexpr int kNormalLengthMod = 0x1F;
|
||||||
constexpr int kCompressionStringMod = 7 << 5;
|
constexpr int kCompressionStringMod = 7 << 5;
|
||||||
constexpr uchar kGraphicsBitmap[8] = {0x80, 0x40, 0x20, 0x10,
|
|
||||||
0x08, 0x04, 0x02, 0x01};
|
|
||||||
|
|
||||||
const std::string kMosaicChangeOffset = "$02AADB";
|
const std::string kMosaicChangeOffset = "$02AADB";
|
||||||
constexpr int kSNESToPCOffset = 0x138000;
|
constexpr int kSNESToPCOffset = 0x138000;
|
||||||
|
|||||||
Reference in New Issue
Block a user