|
|
|
@ -40,8 +40,8 @@ struct Rom{ |
|
|
|
|
|
|
|
|
|
struct DataBlock{ |
|
|
|
|
uint32_t addr,ptr; |
|
|
|
|
std::string_view data; |
|
|
|
|
DataBlock(std::string_view data,uint32_t loc) |
|
|
|
|
std::u8string_view data; |
|
|
|
|
DataBlock(std::u8string_view data,uint32_t loc) |
|
|
|
|
:data(data){ |
|
|
|
|
addr=ptr=loc; |
|
|
|
|
} |
|
|
|
@ -55,9 +55,9 @@ struct Rom{ |
|
|
|
|
return readInt8()|(readInt8()<<8)|(readInt8()<<16)|(readInt8()<<24); |
|
|
|
|
} |
|
|
|
|
uint32_t getCompressedSize(uint32_t pointer){ |
|
|
|
|
uint32_t bpos{}; |
|
|
|
|
uint32_t pos{pointer}; |
|
|
|
|
uint32_t bpos2{}; |
|
|
|
|
int32_t bpos{}; |
|
|
|
|
int32_t pos{int32_t(pointer)}; |
|
|
|
|
int32_t bpos2{}; |
|
|
|
|
while(data[pos]!=0xFF){ |
|
|
|
|
if(pos>=data.length())throw std::runtime_error{"Unexpected end of data."}; |
|
|
|
|
char commandType{data[pos]>>5}; |
|
|
|
@ -120,10 +120,10 @@ struct Rom{ |
|
|
|
|
private: |
|
|
|
|
void decompressBlock(uint32_t ptrStart,std::vector<uint16_t>&block){ |
|
|
|
|
size_t maxLength{block.size()}; |
|
|
|
|
uint32_t pos{ptrStart}; |
|
|
|
|
uint32_t bpos{}; |
|
|
|
|
uint32_t bpos2{}; |
|
|
|
|
char tmp; |
|
|
|
|
int32_t pos{int32_t(ptrStart)}; |
|
|
|
|
int32_t bpos{}; |
|
|
|
|
int32_t bpos2{}; |
|
|
|
|
int tmp; |
|
|
|
|
int read{}; |
|
|
|
|
while(data[pos]!=0xFF){ |
|
|
|
|
if (pos >= data.length())return; |
|
|
|
@ -135,6 +135,7 @@ struct Rom{ |
|
|
|
|
++pos; |
|
|
|
|
} |
|
|
|
|
if(bpos+len>maxLength||bpos+len<0)return; |
|
|
|
|
++pos; |
|
|
|
|
if(commandType>=4) { |
|
|
|
|
bpos2=(data[pos]<<8)+data[pos+1]; |
|
|
|
|
if(bpos2>=maxLength||bpos2<0)return; |
|
|
|
@ -180,7 +181,7 @@ struct Rom{ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct BattleBackground{ |
|
|
|
|
BattleBackground(std::string_view data,uint32_t index){ |
|
|
|
|
BattleBackground(std::u8string_view data,uint32_t index){ |
|
|
|
|
DataBlock readData{data,0xDCA1+index*uint32_t(this->data.size())}; |
|
|
|
|
for(int i=0;i<this->data.size();i++){ |
|
|
|
|
this->data[i]=readData.readInt8(); |
|
|
|
@ -213,7 +214,7 @@ struct Rom{ |
|
|
|
|
std::vector<Pixel>colors; |
|
|
|
|
byte bpp; |
|
|
|
|
uint32_t addr; |
|
|
|
|
BackgroundPalette(std::string_view data,uint16_t index,byte bpp) |
|
|
|
|
BackgroundPalette(std::u8string_view data,uint16_t index,byte bpp) |
|
|
|
|
:bpp(bpp){ |
|
|
|
|
DataBlock pointer{data,0xDAD9U+index*4U}; |
|
|
|
|
uint32_t addr=snesToHex(pointer.readInt32()); |
|
|
|
@ -232,14 +233,41 @@ struct Rom{ |
|
|
|
|
using Tile=std::array<std::array<int,8>,8>; |
|
|
|
|
struct BackgroundGraphics{ |
|
|
|
|
std::vector<uint16_t>graphicsData; |
|
|
|
|
std::vector<uint16_t>arrayGraphicsData; |
|
|
|
|
std::vector<Tile>tiles; |
|
|
|
|
BackgroundGraphics(std::string_view data,uint16_t index,byte bpp){ |
|
|
|
|
byte bpp; |
|
|
|
|
void buildTiles(){ |
|
|
|
|
int n{int(graphicsData.size())/(8*bpp)}; |
|
|
|
|
for(int i{};i<n;i++){ |
|
|
|
|
tiles.emplace_back(); |
|
|
|
|
int o{i*8*bpp}; |
|
|
|
|
for(int x{};x<8;x++){ |
|
|
|
|
for(int y{};y<8;y++){ |
|
|
|
|
int c{}; |
|
|
|
|
for(int bp{};bp<bpp;bp++){ |
|
|
|
|
int halfBp{bp/2}; |
|
|
|
|
int gfx{graphicsData[o+y*2+(halfBp*16+(bp&1))]}; |
|
|
|
|
c+=((gfx&(1<<7-x))>>7-x)<<bp; |
|
|
|
|
} |
|
|
|
|
tiles[i][x][y]=c; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BackgroundGraphics(std::u8string_view data,uint16_t index,byte bpp) |
|
|
|
|
:bpp(bpp){ |
|
|
|
|
DataBlock graphicsPtr{data,0xD7A1U+index*4U}; |
|
|
|
|
DataBlock loadGraphicsPtr{data,snesToHex(graphicsPtr.readInt32())}; |
|
|
|
|
graphicsData=loadGraphicsPtr.decompress(); |
|
|
|
|
buildTiles(); |
|
|
|
|
DataBlock arrayPtrBlock{data,0xD93DU+index*4}; |
|
|
|
|
uint32_t arrayPtr{snesToHex(arrayPtrBlock.readInt32())}; |
|
|
|
|
DataBlock arrayBlock{data,arrayPtr}; |
|
|
|
|
arrayGraphicsData=arrayBlock.decompress(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
std::string data; |
|
|
|
|
std::u8string data; |
|
|
|
|
inline static std::string reversedBytes; |
|
|
|
|
std::vector<BattleBackground>backgrounds; |
|
|
|
|
std::vector<BackgroundPalette>palettes; |
|
|
|
@ -270,7 +298,7 @@ struct Rom{ |
|
|
|
|
palettes.emplace_back(data,i,paletteBits[i]); |
|
|
|
|
} |
|
|
|
|
for(uint16_t i:std::views::iota(0U,graphicsBits.size())){ |
|
|
|
|
|
|
|
|
|
graphics.emplace_back(data,i,graphicsBits[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|