bug: fix tile16 issue with toint16 method

This commit is contained in:
Justin Scofield
2022-09-05 13:03:05 -05:00
parent 32f287d89c
commit 7daeeea14e
4 changed files with 20 additions and 16 deletions

View File

@@ -11,15 +11,15 @@ namespace gfx {
TileInfo GetTilesInfo(ushort tile) { TileInfo GetTilesInfo(ushort tile) {
// vhopppcc cccccccc // vhopppcc cccccccc
ushort o = 0; bool o = false;
ushort v = 0; bool v = false;
ushort h = 0; bool h = false;
auto tid = (ushort)(tile & 0x3FF); auto tid = (ushort)(tile & core::TileNameMask);
auto p = (uchar)((tile >> 10) & 0x07); auto p = (uchar)((tile >> 10) & 0x07);
o = (ushort)((tile & 0x2000) >> 13); o = ((tile & core::TilePriorityBit) == core::TilePriorityBit);
h = (ushort)((tile & 0x4000) >> 14); h = ((tile & core::TileHFlipBit) == core::TileHFlipBit);
v = (ushort)((tile & 0x8000) >> 15); v = ((tile & core::TileVFlipBit) == core::TileVFlipBit);
return TileInfo(tid, p, v, h, o); return TileInfo(tid, p, v, h, o);
} }

View File

@@ -23,12 +23,12 @@ using tile8 = struct tile8;
class TileInfo { class TileInfo {
public: public:
ushort id_; ushort id_;
ushort over_; bool over_;
ushort vertical_mirror_; bool vertical_mirror_;
ushort horizontal_mirror_; bool horizontal_mirror_;
uchar palette_; uchar palette_;
TileInfo() = default; TileInfo() = default;
TileInfo(ushort id, uchar palette, ushort v, ushort h, ushort o) TileInfo(ushort id, uchar palette, bool v, bool h, bool o)
: id_(id), : id_(id),
over_(o), over_(o),
vertical_mirror_(v), vertical_mirror_(v),

View File

@@ -77,7 +77,7 @@ class ROM {
absl::StatusOr<Bytes> DecompressOverworld(int pos, int size); absl::StatusOr<Bytes> DecompressOverworld(int pos, int size);
absl::Status LoadAllGraphicsData(); absl::Status LoadAllGraphicsData();
absl::StatusOr<Bytes> CreateAllGfxDataRaw(); absl::StatusOr<Bytes> CreateAllGfxDataRaw();
absl::Status CreateAllGraphicsData(); absl::Status CreateAllGraphicsData();
@@ -117,6 +117,10 @@ class ROM {
} }
const uchar* operator&() { return rom_data_.data(); } const uchar* operator&() { return rom_data_.data(); }
ushort toint16(int offset) {
return (ushort)((rom_data_[offset + 1]) << 8) | rom_data_[offset];
}
private: private:
long size_ = 0; long size_ = 0;
uchar title[21] = "ROM Not Loaded"; uchar title[21] = "ROM Not Loaded";

View File

@@ -88,13 +88,13 @@ void Overworld::AssembleMap32Tiles() {
void Overworld::AssembleMap16Tiles() { void Overworld::AssembleMap16Tiles() {
int tpos = core::map16Tiles; int tpos = core::map16Tiles;
for (int i = 0; i < 4096; i += 1) { for (int i = 0; i < 4096; i += 1) {
auto t0 = gfx::GetTilesInfo((uintptr_t)(rom_ + tpos)); auto t0 = gfx::GetTilesInfo((rom_.toint16(tpos)));
tpos += 2; tpos += 2;
auto t1 = gfx::GetTilesInfo((uintptr_t)(rom_ + tpos)); auto t1 = gfx::GetTilesInfo((rom_.toint16(tpos)));
tpos += 2; tpos += 2;
auto t2 = gfx::GetTilesInfo((uintptr_t)(rom_ + tpos)); auto t2 = gfx::GetTilesInfo((rom_.toint16(tpos)));
tpos += 2; tpos += 2;
auto t3 = gfx::GetTilesInfo((uintptr_t)(rom_ + tpos)); auto t3 = gfx::GetTilesInfo((rom_.toint16(tpos)));
tpos += 2; tpos += 2;
tiles16.emplace_back(t0, t1, t2, t3); tiles16.emplace_back(t0, t1, t2, t3);
} }