Managed to get loading the ROM and graphics decompression/overworld tile building stuff to compile, now it's just a matter of translating that data into the Bitmap to display properly.
This commit is contained in:
@@ -9,6 +9,20 @@ namespace Data {
|
||||
using namespace Core;
|
||||
using namespace Graphics;
|
||||
|
||||
Overworld::~Overworld() {
|
||||
for (int i = 0; i < tiles32.size(); i++) {
|
||||
free(allmapsTilesLW[i]);
|
||||
free(allmapsTilesDW[i]);
|
||||
free(allmapsTilesSP[i]);
|
||||
}
|
||||
free(allmapsTilesLW);
|
||||
free(allmapsTilesDW);
|
||||
free(allmapsTilesSP);
|
||||
|
||||
delete overworldMapPointer;
|
||||
delete owactualMapPointer;
|
||||
}
|
||||
|
||||
static TileInfo GetTilesInfo(ushort tile) {
|
||||
// vhopppcc cccccccc
|
||||
ushort o = 0;
|
||||
@@ -24,12 +38,13 @@ static TileInfo GetTilesInfo(ushort tile) {
|
||||
return TileInfo(tid, p, v, h, o);
|
||||
}
|
||||
|
||||
Overworld::Overworld(Utils::ROM rom) : rom_(rom) {
|
||||
void Overworld::Load(Utils::ROM rom) {
|
||||
rom_ = rom;
|
||||
for (int i = 0; i < 0x2B; i++) {
|
||||
tileLeftEntrance[i] = (ushort)rom_.ReadShort(
|
||||
Constants::overworldEntranceAllowedTilesLeft + (i * 2));
|
||||
tileRightEntrance[i] = (ushort)rom_.ReadShort(
|
||||
Constants::overworldEntranceAllowedTilesRight + (i * 2));
|
||||
tileLeftEntrance.push_back(
|
||||
rom_.ReadShort(Constants::overworldEntranceAllowedTilesLeft + (i * 2)));
|
||||
tileRightEntrance.push_back(rom_.ReadShort(
|
||||
Constants::overworldEntranceAllowedTilesRight + (i * 2)));
|
||||
}
|
||||
|
||||
AssembleMap32Tiles();
|
||||
@@ -38,21 +53,20 @@ Overworld::Overworld(Utils::ROM rom) : rom_(rom) {
|
||||
|
||||
// Map Initialization :
|
||||
for (int i = 0; i < 160; i++) {
|
||||
allmaps.push_back(OverworldMap(rom_, (byte)i));
|
||||
allmaps.push_back(OverworldMap(rom_, tiles16, (byte)i));
|
||||
}
|
||||
FetchLargeMaps();
|
||||
LoadOverworldMap();
|
||||
|
||||
auto size = tiles16.size();
|
||||
for (int i = 0; i < 160; i++) {
|
||||
allmaps[i].BuildMap(mapParent, size, gameState);
|
||||
allmaps[i].BuildMap(mapParent, size, gameState, allmapsTilesLW,
|
||||
allmapsTilesDW, allmapsTilesSP);
|
||||
}
|
||||
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
void Overworld::Load(Utils::ROM rom) {}
|
||||
|
||||
ushort Overworld::GenerateTile32(int i, int k, int dimension) {
|
||||
return (ushort)(rom_.GetRawData()[map32address[dimension] + k + (i)] +
|
||||
(((rom_.GetRawData()[map32address[dimension] + (i) +
|
||||
@@ -73,6 +87,18 @@ void Overworld::AssembleMap32Tiles() {
|
||||
tiles32.push_back(Tile32(tl, tr, bl, br));
|
||||
}
|
||||
}
|
||||
|
||||
allmapsTilesLW = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
|
||||
for (int i = 0; i < tiles32.size(); i++)
|
||||
allmapsTilesLW[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
|
||||
|
||||
allmapsTilesDW = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
|
||||
for (int i = 0; i < tiles32.size(); i++)
|
||||
allmapsTilesDW[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
|
||||
|
||||
allmapsTilesSP = (ushort**)malloc(tiles32.size() * sizeof(ushort*));
|
||||
for (int i = 0; i < tiles32.size(); i++)
|
||||
allmapsTilesSP[i] = (ushort*)malloc(tiles32.size() * sizeof(ushort));
|
||||
}
|
||||
|
||||
void Overworld::AssembleMap16Tiles() {
|
||||
@@ -94,11 +120,9 @@ void Overworld::AssembleMap16Tiles() {
|
||||
void Overworld::DecompressAllMapTiles() {
|
||||
int lowest = 0x0FFFFF;
|
||||
int highest = 0x0F8000;
|
||||
// int npos = 0;
|
||||
int sx = 0;
|
||||
int sy = 0;
|
||||
int c = 0;
|
||||
// int furthestPtr = 0;
|
||||
for (int i = 0; i < 160; i++) {
|
||||
int p1 = (rom_.GetRawData()[(Constants::compressedAllMap32PointersHigh) +
|
||||
2 + (int)(3 * i)]
|
||||
@@ -155,9 +179,6 @@ void Overworld::DecompressAllMapTiles() {
|
||||
|
||||
int tpos = tidD;
|
||||
if (tpos < tiles32.size()) {
|
||||
// map16tiles[npos] = new Tile32(tiles32[tpos].tile0,
|
||||
// tiles32[tpos].tile1, tiles32[tpos].tile2, tiles32[tpos].tile3);
|
||||
|
||||
if (i < 64) {
|
||||
allmapsTilesLW[(x * 2) + (sx * 32)][(y * 2) + (sy * 32)] =
|
||||
tiles32[tpos].tile0_;
|
||||
@@ -268,13 +289,13 @@ void Overworld::FetchLargeMaps() {
|
||||
}
|
||||
|
||||
void Overworld::LoadOverworldMap() {
|
||||
// GFX.overworldMapBitmap = new Bitmap(
|
||||
// 128, 128, 128, PixelFormat.Format8bppIndexed, GFX.overworldMapPointer);
|
||||
// GFX.owactualMapBitmap = new Bitmap(
|
||||
// 512, 512, 512, PixelFormat.Format8bppIndexed, GFX.owactualMapPointer);
|
||||
overworldMapBitmap = new Bitmap(128, 128, overworldMapPointer);
|
||||
overworldMapBitmap->Create(&overworldMapTexture);
|
||||
owactualMapBitmap = new Bitmap(512, 512, owactualMapPointer);
|
||||
owactualMapBitmap->Create(&owactualMapTexture);
|
||||
|
||||
// Mode 7
|
||||
byte* ptr = (byte*)overworldMapPointer.get();
|
||||
byte* ptr = overworldMapPointer;
|
||||
|
||||
int pos = 0;
|
||||
for (int sy = 0; sy < 16; sy++) {
|
||||
|
||||
@@ -15,25 +15,33 @@ namespace yaze {
|
||||
namespace Application {
|
||||
namespace Data {
|
||||
|
||||
using ushort = ushort;
|
||||
using ushort = unsigned short;
|
||||
using byte = unsigned char;
|
||||
|
||||
class Overworld {
|
||||
public:
|
||||
Overworld() = default;
|
||||
Overworld(Utils::ROM rom);
|
||||
~Overworld();
|
||||
|
||||
void Load(Utils::ROM rom);
|
||||
|
||||
byte* overworldMapPointer = new byte[0x40000];
|
||||
Graphics::Bitmap* overworldMapBitmap;
|
||||
GLuint overworldMapTexture;
|
||||
|
||||
byte* owactualMapPointer = new byte[0x40000];
|
||||
Graphics::Bitmap* owactualMapBitmap;
|
||||
GLuint owactualMapTexture;
|
||||
|
||||
private:
|
||||
Utils::ROM rom_;
|
||||
Utils::ALTTPCompression alttp_compressor_;
|
||||
int gameState = 1;
|
||||
byte mapParent[160];
|
||||
|
||||
unsigned short **allmapsTilesLW;
|
||||
std::vector<std::vector<ushort>> allmapsTilesDW; // 64 maps * (32*32 tiles)
|
||||
std::vector<std::vector<ushort>> allmapsTilesSP; // 32 maps * (32*32 tiles)
|
||||
ushort **allmapsTilesLW; // 64 maps * (32*32 tiles)
|
||||
ushort **allmapsTilesDW; // 64 maps * (32*32 tiles)
|
||||
ushort **allmapsTilesSP; // 32 maps * (32*32 tiles)
|
||||
|
||||
std::vector<Graphics::Tile16> tiles16;
|
||||
std::vector<Graphics::Tile32> tiles32;
|
||||
@@ -50,11 +58,6 @@ class Overworld {
|
||||
Core::Constants::map32TilesTL, Core::Constants::map32TilesTR,
|
||||
Core::Constants::map32TilesBL, Core::Constants::map32TilesBR};
|
||||
|
||||
std::unique_ptr<int> overworldMapPointer;
|
||||
Graphics::Bitmap overworldMapBitmap;
|
||||
|
||||
std::unique_ptr<int> owactualMapPointer;
|
||||
Graphics::Bitmap owactualMapBitmap;
|
||||
|
||||
enum Dimension {
|
||||
map32TilesTL = 0,
|
||||
|
||||
@@ -7,12 +7,10 @@ namespace Data {
|
||||
using namespace Core;
|
||||
using namespace Graphics;
|
||||
|
||||
OverworldMap::OverworldMap(Utils::ROM rom, byte index)
|
||||
: rom_(rom), index(index), parent(index) {
|
||||
// gfxBitmap = new Bitmap(512, 512, 512, PixelFormat.Format8bppIndexed,
|
||||
// gfxPtr); messageID = (short)ROM.ReadShort(Constants::overworldMessages +
|
||||
// (parent * 2));
|
||||
|
||||
OverworldMap::OverworldMap(Utils::ROM rom,
|
||||
const std::vector<Graphics::Tile16> tiles16,
|
||||
byte index)
|
||||
: rom_(rom), index(index), tiles16_(tiles16), parent(index) {
|
||||
if (index != 0x80) {
|
||||
if (index <= 150) {
|
||||
if (rom_.GetRawData()[Constants::overworldMapSize + (index & 0x3F)] !=
|
||||
@@ -105,15 +103,16 @@ OverworldMap::OverworldMap(Utils::ROM rom, byte index)
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::BuildMap(byte* mapParent, int count, int gameState) {
|
||||
void OverworldMap::BuildMap(byte* mapParent, int count, int gameState,
|
||||
ushort** allmapsTilesLW, ushort** allmapsTilesDW,
|
||||
ushort** allmapsTilesSP) {
|
||||
tilesUsed = new ushort*[32];
|
||||
for (int i = 0; i < 32; i++) tilesUsed[i] = new ushort;
|
||||
|
||||
if (largeMap) {
|
||||
this->parent = mapParent[index];
|
||||
|
||||
if (parent != index) {
|
||||
// sprgfx[0] = rom_.GetRawData()[Constants::overworldSpriteset + parent];
|
||||
// sprgfx[1] = rom_.GetRawData()[Constants::overworldSpriteset + parent +
|
||||
// 64]; sprgfx[2] = rom_.GetRawData()[Constants::overworldSpriteset +
|
||||
// parent + 128];
|
||||
if (!firstLoad) {
|
||||
gfx = rom_.GetRawData()[Constants::mapGfx + parent];
|
||||
palette = rom_.GetRawData()[Constants::overworldMapPalette + parent];
|
||||
@@ -124,21 +123,19 @@ void OverworldMap::BuildMap(byte* mapParent, int count, int gameState) {
|
||||
|
||||
BuildTileset(gameState);
|
||||
BuildTiles16Gfx(count); // build on GFX.mapgfx16Ptr
|
||||
//LoadPalette();
|
||||
// LoadPalette();
|
||||
|
||||
int world = 0;
|
||||
|
||||
// fix !!
|
||||
/* if (index < 64) {
|
||||
tilesUsed = ow_.allmapsTilesLW;
|
||||
}
|
||||
else if (index < 128 && index >= 64) {
|
||||
tilesUsed = ow_.allmapsTilesDW.data();
|
||||
if (index < 64) {
|
||||
tilesUsed = allmapsTilesLW;
|
||||
} else if (index < 128 && index >= 64) {
|
||||
tilesUsed = allmapsTilesDW;
|
||||
world = 1;
|
||||
} else {
|
||||
tilesUsed = ow_.allmapsTilesSP.data();
|
||||
tilesUsed = allmapsTilesSP;
|
||||
world = 2;
|
||||
} */
|
||||
}
|
||||
|
||||
int superY = ((index - (world * 64)) / 8);
|
||||
int superX = index - (world * 64) - (superY * 8);
|
||||
@@ -146,15 +143,13 @@ void OverworldMap::BuildMap(byte* mapParent, int count, int gameState) {
|
||||
for (int y = 0; y < 32; y++) {
|
||||
for (int x = 0; x < 32; x++) {
|
||||
CopyTile8bpp16((x * 16), (y * 16),
|
||||
tilesUsed[x + (superX * 32)][y + (superY * 32)],
|
||||
gfxPtr.get(), // fix
|
||||
mapblockset16.get()); // fix
|
||||
tilesUsed[x + (superX * 32)][y + (superY * 32)], gfxPtr,
|
||||
mapblockset16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile8bpp16(int x, int y, int tile,
|
||||
int* destbmpPtr,
|
||||
void OverworldMap::CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
int* sourcebmpPtr) {
|
||||
int sourceY = (tile / 8);
|
||||
int sourceX = (tile) - ((sourceY)*8);
|
||||
@@ -163,7 +158,7 @@ void OverworldMap::CopyTile8bpp16(int x, int y, int tile,
|
||||
byte* sourcePtr = (byte*)sourcebmpPtr;
|
||||
|
||||
int destPtrPos = (x + (y * 512));
|
||||
byte* destPtr = (byte*) destbmpPtr;
|
||||
byte* destPtr = (byte*)destbmpPtr;
|
||||
|
||||
for (int ystrip = 0; ystrip < 16; ystrip++) {
|
||||
for (int xstrip = 0; xstrip < 16; xstrip++) {
|
||||
@@ -174,22 +169,17 @@ void OverworldMap::CopyTile8bpp16(int x, int y, int tile,
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID,
|
||||
int* destbmpPtr,
|
||||
int* sourcebmpPtr) {
|
||||
auto gfx16Data = (byte*) destbmpPtr;
|
||||
int* destbmpPtr, int* sourcebmpPtr) {
|
||||
auto gfx16Data = (byte*)destbmpPtr;
|
||||
|
||||
auto gfx8Data = new byte[(128 * 512) / 2];
|
||||
// (byte*)
|
||||
// GFX.currentOWgfx16Ptr.ToPointer()
|
||||
auto gfx8Data = currentOWgfx16Ptr;
|
||||
|
||||
int offsets[] = {0, 8, 4096, 4104};
|
||||
|
||||
//auto tiles = ow_.tiles16[tileID];
|
||||
auto tiles = nullptr;
|
||||
auto tiles = tiles16_[tileID];
|
||||
|
||||
for (auto tile = 0; tile < 4; tile++) {
|
||||
//TileInfo info = tiles.tiles_info[tile];
|
||||
TileInfo info;
|
||||
TileInfo info = tiles.tiles_info[tile];
|
||||
int offset = offsets[tile];
|
||||
|
||||
for (auto y = 0; y < 8; y++) {
|
||||
@@ -201,11 +191,9 @@ void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID,
|
||||
}
|
||||
|
||||
void OverworldMap::BuildTiles16Gfx(int count) {
|
||||
auto gfx16Data = new byte[1024];
|
||||
// (byte*)GFX.mapblockset16.get(); //(byte*)allgfx8Ptr.ToPointer();
|
||||
auto gfx8Data = new byte [1024];
|
||||
// (byte*)
|
||||
// GFX.currentOWgfx16Ptr.get(); //(byte*)allgfx16Ptr.ToPointer();
|
||||
byte* gfx16Data = (byte*)mapblockset16;
|
||||
byte* gfx8Data = currentOWgfx16Ptr;
|
||||
|
||||
int offsets[] = {0, 8, 1024, 1032};
|
||||
auto yy = 0;
|
||||
auto xx = 0;
|
||||
@@ -213,12 +201,11 @@ void OverworldMap::BuildTiles16Gfx(int count) {
|
||||
for (auto i = 0; i < count; i++) // number of tiles16 3748?
|
||||
{
|
||||
// 8x8 tile draw
|
||||
// gfx8 = 4bpp so everyting is /2
|
||||
// auto tiles = ow_.tiles16[i];
|
||||
// gfx8 = 4bpp so everyting is /2F
|
||||
auto tiles = tiles16_[i];
|
||||
|
||||
for (auto tile = 0; tile < 4; tile++) {
|
||||
//TileInfo info = ow_.tiles16[i].tiles_info[tile];
|
||||
TileInfo info;
|
||||
TileInfo info = tiles16_[i].tiles_info[tile];
|
||||
int offset = offsets[tile];
|
||||
|
||||
for (auto y = 0; y < 8; y++) {
|
||||
@@ -286,7 +273,7 @@ void OverworldMap::CopyTileToMap(int x, int y, int xx, int yy, int offset,
|
||||
gfx16Pointer[index + r] = (byte)(((pixel >> 4) & 0x0F) + tile.palette_ * 16);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
void OverworldMap::LoadPalette() {
|
||||
int previousPalId = 0;
|
||||
int previousSprPalId = 0;
|
||||
@@ -615,12 +602,12 @@ void OverworldMap::BuildTileset(int gameState) {
|
||||
staticgfx[7] = 91;
|
||||
}
|
||||
|
||||
byte* currentmapgfx8Data = new byte [1024];
|
||||
// (byte*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current
|
||||
// // map (empty at this point)
|
||||
byte* allgfxData = new byte [1024];
|
||||
// (byte*)GFX.allgfx16Ptr
|
||||
// .ToPointer(); // all gfx of the game pack of 2048 bytes (4bpp)
|
||||
byte* currentmapgfx8Data = new byte[(128 * 512) / 2];
|
||||
// (byte*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current
|
||||
// // map (empty at this point)
|
||||
byte* allgfxData = new byte[(128 * 7136) / 2];
|
||||
// (byte*)GFX.allgfx16Ptr
|
||||
// .ToPointer(); // all gfx of the game pack of 2048 bytes (4bpp)
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 2048; j++) {
|
||||
|
||||
@@ -26,19 +26,22 @@ class OverworldMap {
|
||||
byte sprpalette[3];
|
||||
byte musics[4];
|
||||
|
||||
// 512 * 512
|
||||
std::unique_ptr<int> gfxPtr;
|
||||
std::unique_ptr<int> mapblockset16;
|
||||
// Bitmap gfxBitmap; // Needs to be removed
|
||||
int* gfxPtr = new int[512 * 512];
|
||||
int* mapblockset16 = new int[1048576];
|
||||
Graphics::Bitmap mapblockset16Bitmap;
|
||||
Graphics::Bitmap gfxBitmap;
|
||||
|
||||
byte staticgfx[16]; // Need to be used to display map and not pre render it!
|
||||
byte* staticgfx = new byte[16]; // Need to be used to display map and not pre render it!
|
||||
ushort** tilesUsed;
|
||||
|
||||
bool needRefresh = false;
|
||||
Utils::ROM rom_;
|
||||
|
||||
OverworldMap(Utils::ROM rom, byte index);
|
||||
void BuildMap(byte* mapParent, int count, int gameState);
|
||||
byte *currentOWgfx16Ptr = new byte[(128 * 512) / 2];
|
||||
std::vector<Graphics::Tile16> tiles16_;
|
||||
|
||||
OverworldMap(Utils::ROM rom, const std::vector<Graphics::Tile16> tiles16, byte index);
|
||||
void BuildMap(byte* mapParent, int count, int gameState, ushort** allmapsTilesLW, ushort** allmapsTilesDW, ushort** allmapsTilesSP);
|
||||
void CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
int* sourcebmpPtr);
|
||||
void CopyTile8bpp16From8(int xP, int yP, int tileID, int* destbmpPtr,
|
||||
@@ -50,16 +53,15 @@ class OverworldMap {
|
||||
|
||||
void CopyTile(int x, int y, int xx, int yy, int offset,
|
||||
Graphics::TileInfo tile, byte* gfx16Pointer, byte* gfx8Pointer);
|
||||
|
||||
void CopyTileToMap(int x, int y, int xx, int yy, int offset,
|
||||
Graphics::TileInfo tile, byte* gfx16Pointer,
|
||||
byte* gfx8Pointer);
|
||||
|
||||
/* void LoadPalette();
|
||||
void LoadPalette();
|
||||
|
||||
void SetColorsPalette(int index, ImVec4 main, ImVec4 animated, ImVec4 aux1,
|
||||
ImVec4 aux2, ImVec4 hud, ImVec4 bgrcolor, ImVec4 spr,
|
||||
ImVec4 spr2); */
|
||||
ImVec4 spr2);
|
||||
|
||||
void BuildTileset(int gameState);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user