Working on tile16 blockset
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
#include "bitmap.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <rommapping.h>
|
||||
|
||||
#include "app/core/constants.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace gfx {
|
||||
|
||||
Bitmap::Bitmap(int width, int height, int depth, char *data)
|
||||
Bitmap::Bitmap(int width, int height, int depth, uchar *data)
|
||||
: width_(width), height_(height), depth_(depth), pixel_data_(data) {
|
||||
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
|
||||
SDL_PIXELFORMAT_INDEX8);
|
||||
@@ -27,7 +26,7 @@ void Bitmap::Create(int width, int height, int depth, uchar *data) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
depth_ = depth;
|
||||
pixel_data_ = (char *)data;
|
||||
pixel_data_ = data;
|
||||
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
|
||||
SDL_PIXELFORMAT_INDEX8);
|
||||
// Default grayscale palette
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
#define YAZE_APP_UTILS_BITMAP_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <rommapping.h>
|
||||
|
||||
#include "app/core/constants.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
@@ -14,7 +13,7 @@ namespace gfx {
|
||||
class Bitmap {
|
||||
public:
|
||||
Bitmap() = default;
|
||||
Bitmap(int width, int height, int depth, char *data);
|
||||
Bitmap(int width, int height, int depth, uchar *data);
|
||||
|
||||
void Create(int width, int height, int depth, uchar *data);
|
||||
int GetWidth() const { return width_; }
|
||||
@@ -26,9 +25,10 @@ class Bitmap {
|
||||
int width_;
|
||||
int height_;
|
||||
int depth_;
|
||||
char *pixel_data_;
|
||||
uchar *pixel_data_;
|
||||
SDL_Surface *surface_;
|
||||
SDL_Texture *texture_;
|
||||
SNESPalette palette_;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef YAZE_APP_GFX_TILE_H
|
||||
#define YAZE_APP_GFX_TILE_H
|
||||
|
||||
#include <rommapping.h>
|
||||
#include <tile.h>
|
||||
|
||||
#include <cassert>
|
||||
@@ -73,11 +74,6 @@ class Tile16 {
|
||||
}
|
||||
};
|
||||
|
||||
static bool isbpp3[core::constants::NumberOfSheets];
|
||||
|
||||
int GetPCGfxAddress(char* romData, char id);
|
||||
char* CreateAllGfxDataRaw(char* romData);
|
||||
void CreateAllGfxData(char* romData, char* allgfx16Ptr);
|
||||
void BuildTiles16Gfx(uchar* mapblockset16, uchar* currentOWgfx16Ptr,
|
||||
std::vector<Tile16>& allTiles);
|
||||
void CopyTile16(int x, int y, int xx, int yy, int offset, TileInfo tile,
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#include <compressions/alttpcompression.h>
|
||||
#include <rommapping.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -8,176 +11,10 @@ namespace yaze {
|
||||
namespace app {
|
||||
namespace gfx {
|
||||
|
||||
int GetPCGfxAddress(char *romData, char id) {
|
||||
char **info1 = new char *[255];
|
||||
int gfxPointer1 =
|
||||
lorom_snes_to_pc((romData[core::constants::gfx_1_pointer + 1] << 8) +
|
||||
(romData[core::constants::gfx_1_pointer]),
|
||||
info1);
|
||||
int gfxPointer2 =
|
||||
lorom_snes_to_pc((romData[core::constants::gfx_2_pointer + 1] << 8) +
|
||||
(romData[core::constants::gfx_2_pointer]),
|
||||
info1);
|
||||
int gfxPointer3 =
|
||||
lorom_snes_to_pc((romData[core::constants::gfx_3_pointer + 1] << 8) +
|
||||
(romData[core::constants::gfx_3_pointer]),
|
||||
info1);
|
||||
|
||||
char gfxGamePointer1 = romData[gfxPointer1 + id];
|
||||
char gfxGamePointer2 = romData[gfxPointer2 + id];
|
||||
char gfxGamePointer3 = romData[gfxPointer3 + id];
|
||||
|
||||
return lorom_snes_to_pc(
|
||||
yaze::app::rom::AddressFromBytes(gfxGamePointer1, gfxGamePointer2,
|
||||
gfxGamePointer3),
|
||||
info1);
|
||||
}
|
||||
|
||||
char *CreateAllGfxDataRaw(char *romData) {
|
||||
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
|
||||
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
|
||||
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
|
||||
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
|
||||
char *buffer = new char[346624];
|
||||
int bufferPos = 0;
|
||||
char *data = new char[2048];
|
||||
unsigned int uncompressedSize = 0;
|
||||
unsigned int compressedSize = 0;
|
||||
|
||||
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
|
||||
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
|
||||
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
|
||||
(i >= 127 && i <= 217) // Compressed 3bpp sprites
|
||||
);
|
||||
|
||||
// uncompressed sheets
|
||||
if (i >= 115 && i <= 126) {
|
||||
data = new char[core::constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(romData, (char)i);
|
||||
for (int j = 0; j < core::constants::Uncompressed3BPPSize; j++) {
|
||||
data[j] = romData[j + startAddress];
|
||||
}
|
||||
} else {
|
||||
data = alttp_decompress_gfx((char *)romData,
|
||||
GetPCGfxAddress(romData, (char)i),
|
||||
core::constants::UncompressedSheetSize,
|
||||
&uncompressedSize, &compressedSize);
|
||||
}
|
||||
|
||||
for (int j = 0; j < sizeof(data); j++) {
|
||||
buffer[j + bufferPos] = data[j];
|
||||
}
|
||||
|
||||
bufferPos += sizeof(data);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void CreateAllGfxData(char *romData, char *allgfx16Ptr) {
|
||||
char *data = CreateAllGfxDataRaw(romData);
|
||||
char *newData = new char[0x6F800];
|
||||
uchar *mask = new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
int sheetPosition = 0;
|
||||
|
||||
// 8x8 tile
|
||||
for (int s = 0; s < core::constants::NumberOfSheets; 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
|
||||
{
|
||||
if (isbpp3[s]) {
|
||||
char lineBits0 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||
char lineBits1 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
|
||||
char lineBits2 =
|
||||
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
char pixdata = 0;
|
||||
char pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 4;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 4;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
} else {
|
||||
char lineBits0 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
|
||||
char lineBits1 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
char pixdata = 0;
|
||||
char pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isbpp3[s]) {
|
||||
sheetPosition += core::constants::Uncompressed3BPPSize;
|
||||
} else {
|
||||
sheetPosition += core::constants::UncompressedSheetSize;
|
||||
}
|
||||
}
|
||||
|
||||
char *allgfx16Data = (char *)allgfx16Ptr;
|
||||
|
||||
for (int i = 0; i < 0x6F800; i++) {
|
||||
allgfx16Data[i] = newData[i];
|
||||
}
|
||||
}
|
||||
|
||||
void BuildTiles16Gfx(uchar* mapblockset16, uchar* currentOWgfx16Ptr,
|
||||
std::vector<Tile16>& allTiles) {
|
||||
uchar* gfx16Data = mapblockset16;
|
||||
uchar* gfx8Data = currentOWgfx16Ptr;
|
||||
void BuildTiles16Gfx(uchar *mapblockset16, uchar *currentOWgfx16Ptr,
|
||||
std::vector<Tile16> &allTiles) {
|
||||
uchar *gfx16Data = mapblockset16;
|
||||
uchar *gfx8Data = currentOWgfx16Ptr;
|
||||
const int offsets[4] = {0, 8, 1024, 1032};
|
||||
auto yy = 0;
|
||||
auto xx = 0;
|
||||
@@ -208,7 +45,7 @@ void BuildTiles16Gfx(uchar* mapblockset16, uchar* currentOWgfx16Ptr,
|
||||
}
|
||||
|
||||
void CopyTile16(int x, int y, int xx, int yy, int offset, TileInfo tile,
|
||||
uchar* gfx16Pointer, uchar* gfx8Pointer) // map,current
|
||||
uchar *gfx16Pointer, uchar *gfx8Pointer) // map,current
|
||||
{
|
||||
int mx = x;
|
||||
int my = y;
|
||||
|
||||
168
src/app/rom.cc
168
src/app/rom.cc
@@ -19,9 +19,6 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace rom {
|
||||
int AddressFromBytes(uchar addr1, uchar addr2, uchar addr3) {
|
||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||
}
|
||||
|
||||
void ROM::Close() {
|
||||
if (loaded) {
|
||||
@@ -282,6 +279,171 @@ SDL_Texture *ROM::DrawGraphicsSheet(int offset) {
|
||||
}
|
||||
return sheet_texture;
|
||||
}
|
||||
|
||||
int ROM::AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3) {
|
||||
return (addr1 << 16) | (addr2 << 8) | addr3;
|
||||
}
|
||||
|
||||
int ROM::GetPCGfxAddress(uint8_t id) {
|
||||
int gfxPointer1 =
|
||||
SnesToPc((current_rom_[core::constants::gfx_1_pointer + 1] << 8) +
|
||||
(current_rom_[core::constants::gfx_1_pointer]));
|
||||
int gfxPointer2 =
|
||||
SnesToPc((current_rom_[core::constants::gfx_2_pointer + 1] << 8) +
|
||||
(current_rom_[core::constants::gfx_2_pointer]));
|
||||
int gfxPointer3 =
|
||||
SnesToPc((current_rom_[core::constants::gfx_3_pointer + 1] << 8) +
|
||||
(current_rom_[core::constants::gfx_3_pointer]));
|
||||
|
||||
uint8_t gfxGamePointer1 = current_rom_[gfxPointer1 + id];
|
||||
uint8_t gfxGamePointer2 = current_rom_[gfxPointer2 + id];
|
||||
uint8_t gfxGamePointer3 = current_rom_[gfxPointer3 + id];
|
||||
|
||||
return SnesToPc(
|
||||
AddressFromBytes(gfxGamePointer1, gfxGamePointer2, gfxGamePointer3));
|
||||
}
|
||||
|
||||
char *ROM::CreateAllGfxDataRaw() {
|
||||
// 0-112 -> compressed 3bpp bgr -> (decompressed each) 0x600 chars
|
||||
// 113-114 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
// 115-126 -> uncompressed 3bpp sprites -> (each) 0x600 chars
|
||||
// 127-217 -> compressed 3bpp sprites -> (decompressed each) 0x600 chars
|
||||
// 218-222 -> compressed 2bpp -> (decompressed each) 0x800 chars
|
||||
|
||||
char *buffer = new char[346624];
|
||||
char *data = new char[2048];
|
||||
int bufferPos = 0;
|
||||
unsigned int uncompressedSize = 0;
|
||||
unsigned int compressedSize = 0;
|
||||
|
||||
for (int i = 0; i < core::constants::NumberOfSheets; i++) {
|
||||
isbpp3[i] = ((i >= 0 && i <= 112) || // Compressed 3bpp bg
|
||||
(i >= 115 && i <= 126) || // Uncompressed 3bpp sprites
|
||||
(i >= 127 && i <= 217) // Compressed 3bpp sprites
|
||||
);
|
||||
|
||||
// uncompressed sheets
|
||||
if (i >= 115 && i <= 126) {
|
||||
data = new char[core::constants::Uncompressed3BPPSize];
|
||||
int startAddress = GetPCGfxAddress(i);
|
||||
for (int j = 0; j < core::constants::Uncompressed3BPPSize; j++) {
|
||||
data[j] = current_rom_[j + startAddress];
|
||||
}
|
||||
} else {
|
||||
data =
|
||||
alttp_decompress_gfx((char *)current_rom_, GetPCGfxAddress((char)i),
|
||||
core::constants::UncompressedSheetSize,
|
||||
&uncompressedSize, &compressedSize);
|
||||
}
|
||||
|
||||
for (int j = 0; j < sizeof(data); j++) {
|
||||
buffer[j + bufferPos] = data[j];
|
||||
}
|
||||
|
||||
bufferPos += sizeof(data);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void ROM::CreateAllGraphicsData(uchar *allGfx16Ptr) {
|
||||
char *data = CreateAllGfxDataRaw();
|
||||
char *newData = new char[0x6F800];
|
||||
uchar *mask = new uchar[]{0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
|
||||
int sheetPosition = 0;
|
||||
|
||||
// 8x8 tile
|
||||
for (int s = 0; s < core::constants::NumberOfSheets; 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
|
||||
{
|
||||
if (isbpp3[s]) {
|
||||
uchar lineBits0 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + sheetPosition];
|
||||
uchar lineBits1 =
|
||||
data[(y * 2) + (i * 24) + (j * 384) + 1 + sheetPosition];
|
||||
uchar lineBits2 =
|
||||
data[(y) + (i * 24) + (j * 384) + 16 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
uchar pixdata = 0;
|
||||
uchar pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 4;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
if ((lineBits2 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 4;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(char)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
} else {
|
||||
uchar lineBits0 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + sheetPosition];
|
||||
uchar lineBits1 =
|
||||
data[(y * 2) + (i * 16) + (j * 256) + 1 + sheetPosition];
|
||||
|
||||
for (int x = 0; x < 4; x++) // Per Pixel X
|
||||
{
|
||||
uchar pixdata = 0;
|
||||
uchar pixdata2 = 0;
|
||||
|
||||
if ((lineBits0 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2)]) == mask[(x * 2)]) {
|
||||
pixdata += 2;
|
||||
}
|
||||
|
||||
if ((lineBits0 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 1;
|
||||
}
|
||||
if ((lineBits1 & mask[(x * 2) + 1]) == mask[(x * 2) + 1]) {
|
||||
pixdata2 += 2;
|
||||
}
|
||||
|
||||
newData[(y * 64) + (x) + (i * 4) + (j * 512) + (s * 2048)] =
|
||||
(uchar)((pixdata << 4) | pixdata2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isbpp3[s]) {
|
||||
sheetPosition += core::constants::Uncompressed3BPPSize;
|
||||
} else {
|
||||
sheetPosition += core::constants::UncompressedSheetSize;
|
||||
}
|
||||
}
|
||||
|
||||
uchar *allgfx16Data = (uchar *)allGfx16Ptr;
|
||||
|
||||
for (int i = 0; i < 0x6F800; i++) {
|
||||
allgfx16Data[i] = newData[i];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rom
|
||||
} // namespace app
|
||||
} // namespace yaze
|
||||
@@ -20,7 +20,6 @@
|
||||
namespace yaze {
|
||||
namespace app {
|
||||
namespace rom {
|
||||
int AddressFromBytes(uchar addr1, uchar addr2, uchar addr3);
|
||||
|
||||
class ROM {
|
||||
public:
|
||||
@@ -35,6 +34,11 @@ class ROM {
|
||||
uchar* SNES3bppTo8bppSheet(uchar* buffer_in, int sheet_id = 0);
|
||||
SDL_Texture* DrawGraphicsSheet(int offset);
|
||||
|
||||
int AddressFromBytes(uint8_t addr1, uint8_t addr2, uint8_t addr3);
|
||||
|
||||
int GetPCGfxAddress(uint8_t id);
|
||||
char* CreateAllGfxDataRaw();
|
||||
void CreateAllGraphicsData(uchar* allGfx16Ptr);
|
||||
|
||||
unsigned int SnesToPc(unsigned int addr) {
|
||||
if (addr >= 0x808000) {
|
||||
@@ -61,6 +65,7 @@ class ROM {
|
||||
uchar version_;
|
||||
uchar title[21] = "ROM Not Loaded";
|
||||
enum rom_type type_ = LoROM;
|
||||
bool isbpp3[core::constants::NumberOfSheets];
|
||||
|
||||
std::shared_ptr<uchar> rom_ptr_;
|
||||
std::vector<char*> decompressed_graphic_sheets_;
|
||||
|
||||
@@ -40,8 +40,9 @@ static TileInfo GetTilesInfo(ushort tile) {
|
||||
return TileInfo(tid, p, v, h, o);
|
||||
}
|
||||
|
||||
void Overworld::Load(app::rom::ROM& rom) {
|
||||
void Overworld::Load(app::rom::ROM& rom, uchar* allGfxPtr) {
|
||||
rom_ = rom;
|
||||
allGfx16Ptr = allGfxPtr;
|
||||
for (int i = 0; i < 0x2B; i++) {
|
||||
tileLeftEntrance.push_back(constants::overworldEntranceAllowedTilesLeft +
|
||||
(i * 2));
|
||||
@@ -54,8 +55,8 @@ void Overworld::Load(app::rom::ROM& rom) {
|
||||
DecompressAllMapTiles();
|
||||
|
||||
// Map Initialization
|
||||
for (int i = 0; i < 160; i++) {
|
||||
overworld_maps_.push_back(OverworldMap(rom_, tiles16, (uchar)i));
|
||||
for (int i = 0; i < constants::NumberOfOWMaps; i++) {
|
||||
overworld_maps_.push_back(OverworldMap(rom_, tiles16, i));
|
||||
}
|
||||
FetchLargeMaps();
|
||||
LoadOverworldMap();
|
||||
@@ -64,7 +65,7 @@ void Overworld::Load(app::rom::ROM& rom) {
|
||||
for (int i = 0; i < 160; i++) {
|
||||
overworld_maps_[i].BuildMap(mapParent, size, gameState, allmapsTilesLW,
|
||||
allmapsTilesDW, allmapsTilesSP,
|
||||
currentOWgfx16Ptr);
|
||||
currentOWgfx16Ptr, allGfx16Ptr, mapblockset16);
|
||||
}
|
||||
|
||||
isLoaded = true;
|
||||
@@ -298,9 +299,9 @@ void Overworld::FetchLargeMaps() {
|
||||
}
|
||||
|
||||
void Overworld::LoadOverworldMap() {
|
||||
overworldMapBitmap = new Bitmap(128, 128, 8, overworldMapPointer);
|
||||
overworldMapBitmap.Create(128, 128, 8, overworldMapPointer);
|
||||
|
||||
char* ptr = overworldMapPointer;
|
||||
auto ptr = overworldMapPointer;
|
||||
|
||||
int pos = 0;
|
||||
for (int sy = 0; sy < 16; sy++) {
|
||||
@@ -315,7 +316,8 @@ void Overworld::LoadOverworldMap() {
|
||||
}
|
||||
}
|
||||
|
||||
// overworld_map_texture = overworldMapBitmap->CreateTexture(rom_.Renderer());
|
||||
auto renderer = rom_.Renderer();
|
||||
overworldMapBitmap.CreateTexture(renderer);
|
||||
}
|
||||
|
||||
} // namespace zelda3
|
||||
|
||||
@@ -22,13 +22,13 @@ class Overworld {
|
||||
Overworld() = default;
|
||||
~Overworld();
|
||||
|
||||
void Load(app::rom::ROM& rom);
|
||||
void Load(app::rom::ROM& rom, uchar* allGfxPtr);
|
||||
inline auto GetTiles16() const { return tiles16; }
|
||||
inline auto GetCurrentGfxSetPtr() { return currentOWgfx16Ptr; }
|
||||
inline auto GetMapBlockset16Ptr() { return mapblockset16; }
|
||||
|
||||
char* overworldMapPointer = new char[0x40000];
|
||||
gfx::Bitmap* overworldMapBitmap;
|
||||
uchar* overworldMapPointer = new uchar[0x40000];
|
||||
gfx::Bitmap overworldMapBitmap;
|
||||
|
||||
private:
|
||||
ushort GenerateTile32(int i, int k, int dimension);
|
||||
@@ -50,6 +50,7 @@ class Overworld {
|
||||
std::vector<ushort> tileLeftEntrance;
|
||||
std::vector<ushort> tileRightEntrance;
|
||||
|
||||
uchar* allGfx16Ptr = nullptr;
|
||||
uchar* mapblockset16 = new uchar[1048576];
|
||||
uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2];
|
||||
SDL_Texture* overworld_map_texture;
|
||||
|
||||
@@ -15,7 +15,7 @@ using namespace core;
|
||||
using namespace gfx;
|
||||
|
||||
OverworldMap::OverworldMap(app::rom::ROM& rom,
|
||||
const std::vector<gfx::Tile16> tiles16, uchar index)
|
||||
const std::vector<gfx::Tile16> tiles16, int index)
|
||||
: rom_(rom), index(index), tiles16_(tiles16), parent(index) {
|
||||
if (index != 0x80) {
|
||||
if (index <= 150) {
|
||||
@@ -111,9 +111,12 @@ OverworldMap::OverworldMap(app::rom::ROM& rom,
|
||||
|
||||
void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState,
|
||||
ushort** allmapsTilesLW, ushort** allmapsTilesDW,
|
||||
ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr) {
|
||||
ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr,
|
||||
uchar* allGfxPtr, uchar* mapblockset16) {
|
||||
tilesUsed = new ushort*[32];
|
||||
currentOWgfx16Ptr_ = currentOWgfx16Ptr;
|
||||
allGfx16Ptr_ = allGfxPtr;
|
||||
mapblockset16_ = mapblockset16;
|
||||
for (int i = 0; i < 32; i++) tilesUsed[i] = new ushort;
|
||||
|
||||
if (largeMap) {
|
||||
@@ -121,8 +124,20 @@ void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState,
|
||||
|
||||
if (parent != index) {
|
||||
if (!firstLoad) {
|
||||
gfx = rom_.GetRawData()[constants::mapGfx + parent];
|
||||
palette = rom_.GetRawData()[constants::overworldMapPalette + parent];
|
||||
if (index >= 0x80 && index <= 0x8A && index != 0x88) {
|
||||
gfx = rom_.GetRawData()[core::constants::overworldSpecialGFXGroup +
|
||||
(parent - 128)];
|
||||
palette =
|
||||
rom_.GetRawData()[core::constants::overworldSpecialPALGroup + 1];
|
||||
} else if (index == 0x88) {
|
||||
gfx = 81;
|
||||
palette = 0;
|
||||
} else {
|
||||
gfx = rom_.GetRawData()[core::constants::mapGfx + parent];
|
||||
palette =
|
||||
rom_.GetRawData()[core::constants::overworldMapPalette + parent];
|
||||
}
|
||||
|
||||
firstLoad = true;
|
||||
}
|
||||
}
|
||||
@@ -155,16 +170,16 @@ void OverworldMap::BuildMap(uchar* mapParent, int count, int gameState,
|
||||
}
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
int* sourcebmpPtr) {
|
||||
void OverworldMap::CopyTile8bpp16(int x, int y, int tile, uchar* destbmpPtr,
|
||||
uchar* sourcebmpPtr) {
|
||||
int sourceY = (tile / 8);
|
||||
int sourceX = (tile) - ((sourceY)*8);
|
||||
int sourcePtrPos = ((tile - ((tile / 8) * 8)) * 16) +
|
||||
((tile / 8) * 2048); //(sourceX * 16) + (sourceY * 128);
|
||||
uchar* sourcePtr = (uchar*)sourcebmpPtr;
|
||||
auto sourcePtr = sourcebmpPtr;
|
||||
|
||||
int destPtrPos = (x + (y * 512));
|
||||
uchar* destPtr = (uchar*)destbmpPtr;
|
||||
auto destPtr = destbmpPtr;
|
||||
|
||||
for (int ystrip = 0; ystrip < 16; ystrip++) {
|
||||
for (int xstrip = 0; xstrip < 16; xstrip++) {
|
||||
@@ -175,10 +190,9 @@ void OverworldMap::CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
}
|
||||
|
||||
void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID,
|
||||
int* destbmpPtr, int* sourcebmpPtr) {
|
||||
auto gfx16Data = (uchar*)destbmpPtr;
|
||||
|
||||
auto gfx8Data = currentOWgfx16Ptr;
|
||||
uchar* destbmpPtr, uchar* sourcebmpPtr) {
|
||||
auto gfx16Data = destbmpPtr;
|
||||
auto gfx8Data = currentOWgfx16Ptr_;
|
||||
|
||||
int offsets[] = {0, 8, 4096, 4104};
|
||||
|
||||
@@ -197,8 +211,8 @@ void OverworldMap::CopyTile8bpp16From8(int xP, int yP, int tileID,
|
||||
}
|
||||
|
||||
void OverworldMap::BuildTiles16Gfx(int count) {
|
||||
uchar* gfx16Data = (uchar*)mapblockset16;
|
||||
uchar* gfx8Data = currentOWgfx16Ptr;
|
||||
auto gfx16Data = mapblockset16_;
|
||||
auto gfx8Data = currentOWgfx16Ptr_;
|
||||
|
||||
int offsets[] = {0, 8, 1024, 1032};
|
||||
auto yy = 0;
|
||||
@@ -335,11 +349,7 @@ void OverworldMap::BuildTileset(int gameState) {
|
||||
}
|
||||
|
||||
uchar* currentmapgfx8Data = currentOWgfx16Ptr_;
|
||||
// (uchar*)GFX.currentOWgfx16Ptr.ToPointer(); // loaded gfx for the current
|
||||
// // map (empty at this point)
|
||||
uchar* allgfxData = new uchar[(128 * 7136) / 2];
|
||||
// (uchar*)GFX.allgfx16Ptr
|
||||
// .ToPointer(); // all gfx of the game pack of 2048 uchars (4bpp)
|
||||
uchar* allgfxData = allGfx16Ptr_;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 2048; j++) {
|
||||
|
||||
@@ -16,41 +16,40 @@ using ushort = unsigned short;
|
||||
class OverworldMap {
|
||||
public:
|
||||
uchar parent = 0;
|
||||
uchar index = 0;
|
||||
int index = 0;
|
||||
uchar gfx = 0;
|
||||
uchar palette = 0;
|
||||
bool firstLoad = false;
|
||||
short messageID = 0;
|
||||
bool largeMap = false;
|
||||
bool needRefresh = false;
|
||||
|
||||
uchar sprgfx[3];
|
||||
uchar sprpalette[3];
|
||||
uchar musics[4];
|
||||
app::rom::ROM rom_;
|
||||
|
||||
int* gfxPtr = new int[512 * 512];
|
||||
int* mapblockset16 = new int[1048576];
|
||||
uchar* gfxPtr = new uchar[512 * 512];
|
||||
uchar* mapblockset16_ = nullptr;
|
||||
uchar* currentOWgfx16Ptr_ = nullptr;
|
||||
uchar* allGfx16Ptr_ = nullptr;
|
||||
gfx::Bitmap gfxBitmap;
|
||||
std::vector<gfx::Tile16> tiles16_;
|
||||
|
||||
uchar* staticgfx =
|
||||
new uchar[16]; // Need to be used to display map and not pre render it!
|
||||
ushort** tilesUsed;
|
||||
|
||||
bool needRefresh = false;
|
||||
app::rom::ROM rom_;
|
||||
|
||||
uchar* currentOWgfx16Ptr = new uchar[(128 * 512) / 2];
|
||||
std::vector<gfx::Tile16> tiles16_;
|
||||
|
||||
OverworldMap(app::rom::ROM& rom, const std::vector<gfx::Tile16> tiles16,
|
||||
uchar index);
|
||||
int index);
|
||||
void BuildMap(uchar* mapParent, int count, int gameState,
|
||||
ushort** allmapsTilesLW, ushort** allmapsTilesDW,
|
||||
ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr);
|
||||
void CopyTile8bpp16(int x, int y, int tile, int* destbmpPtr,
|
||||
int* sourcebmpPtr);
|
||||
void CopyTile8bpp16From8(int xP, int yP, int tileID, int* destbmpPtr,
|
||||
int* sourcebmpPtr);
|
||||
ushort** allmapsTilesSP, uchar* currentOWgfx16Ptr,
|
||||
uchar* allGfxPtr, uchar* mapblockset16);
|
||||
void CopyTile8bpp16(int x, int y, int tile, uchar* destbmpPtr,
|
||||
uchar* sourcebmpPtr);
|
||||
void CopyTile8bpp16From8(int xP, int yP, int tileID, uchar* destbmpPtr,
|
||||
uchar* sourcebmpPtr);
|
||||
|
||||
private:
|
||||
void BuildTiles16Gfx(int count);
|
||||
|
||||
Reference in New Issue
Block a user