diff --git a/src/app/rom.cc b/src/app/rom.cc index 7f3c155f..0f4ca398 100644 --- a/src/app/rom.cc +++ b/src/app/rom.cc @@ -39,8 +39,7 @@ uint32_t GetGraphicsAddress(const uint8_t *data, uint8_t addr, uint32_t ptr1, absl::StatusOr> Load2BppGraphics(const Rom &rom) { std::vector 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> LoadLinkGraphics( return link_graphics; } +absl::StatusOr LoadFontGraphics(const Rom &rom) { + std::vector data(0x2000); + for (int i = 0; i < 0x2000; i++) { + data[i] = rom.data()[0x70000 + i]; + } + + std::vector new_data(0x4000); + std::vector 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 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> LoadAllGraphicsData( Rom &rom, bool defer_render) { std::array graphics_sheets; diff --git a/src/app/rom.h b/src/app/rom.h index 1bd6cb10..3f00d209 100644 --- a/src/app/rom.h +++ b/src/app/rom.h @@ -264,6 +264,8 @@ absl::StatusOr> Load2BppGraphics(const Rom& rom); absl::StatusOr> LoadLinkGraphics( const Rom& rom); +absl::StatusOr LoadFontGraphics(const Rom& rom); + /** * @brief A class to hold a shared pointer to a Rom object. */