Add LoadFontGraphics function and update Load2BppGraphics sheet IDs
- Introduced LoadFontGraphics function to handle font graphics loading from ROM data. - Updated Load2BppGraphics to use hex sheet IDs.
This commit is contained in:
@@ -39,8 +39,7 @@ uint32_t GetGraphicsAddress(const uint8_t *data, uint8_t addr, uint32_t ptr1,
|
||||
|
||||
absl::StatusOr<std::vector<uint8_t>> Load2BppGraphics(const Rom &rom) {
|
||||
std::vector<uint8_t> sheet;
|
||||
const uint8_t sheets[] = {113, 114, 218, 219, 220, 221};
|
||||
|
||||
const uint8_t sheets[] = {0x71, 0x72, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE};
|
||||
for (const auto &sheet_id : sheets) {
|
||||
auto offset = GetGraphicsAddress(rom.data(), sheet_id,
|
||||
rom.version_constants().kOverworldGfxPtr1,
|
||||
@@ -75,6 +74,64 @@ absl::StatusOr<std::array<gfx::Bitmap, kNumLinkSheets>> LoadLinkGraphics(
|
||||
return link_graphics;
|
||||
}
|
||||
|
||||
absl::StatusOr<gfx::Bitmap> LoadFontGraphics(const Rom &rom) {
|
||||
std::vector<uint8_t> data(0x2000);
|
||||
for (int i = 0; i < 0x2000; i++) {
|
||||
data[i] = rom.data()[0x70000 + i];
|
||||
}
|
||||
|
||||
std::vector<uint8_t> new_data(0x4000);
|
||||
std::vector<uint8_t> mask = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
int sheet_position = 0;
|
||||
|
||||
// 8x8 tile
|
||||
for (int s = 0; s < 4; 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
|
||||
uint8_t line_bits0 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + sheet_position];
|
||||
uint8_t line_bits1 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheet_position];
|
||||
|
||||
for (int x = 0; x < 4; x++) { // Per Pixel X
|
||||
uint8_t pixdata = 0;
|
||||
uint8_t pixdata2 = 0;
|
||||
|
||||
if ((line_bits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((line_bits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
|
||||
if ((line_bits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((line_bits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
|
||||
new_data[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(uint8_t)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sheet_position += 0x400;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> fontgfx16_data(0x4000);
|
||||
for (int i = 0; i < 0x4000; i++) {
|
||||
fontgfx16_data[i] = new_data[i];
|
||||
}
|
||||
|
||||
gfx::Bitmap font_gfx;
|
||||
font_gfx.Create(128, 128, 64, fontgfx16_data);
|
||||
return font_gfx;
|
||||
}
|
||||
|
||||
absl::StatusOr<std::array<gfx::Bitmap, kNumGfxSheets>> LoadAllGraphicsData(
|
||||
Rom &rom, bool defer_render) {
|
||||
std::array<gfx::Bitmap, kNumGfxSheets> graphics_sheets;
|
||||
|
||||
Reference in New Issue
Block a user