Add reversed bytes function.
This commit is contained in:
parent
29f1ac7777
commit
65a4872b06
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
||||
|
||||
/EarthboundBattleBackgrounds/.vs/EarthboundBattleBackgrounds
|
||||
/EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/x64/Debug
|
||||
/.vs/EarthboundBattleBackgrounds/v17
|
||||
|
||||
@ -122,9 +122,57 @@ struct Rom{
|
||||
uint32_t pos{ptrStart};
|
||||
uint32_t bpos{};
|
||||
uint32_t bpos2{};
|
||||
char tmp;
|
||||
int read{};
|
||||
while(data[pos]!=0xFF){
|
||||
if (pos >= data.length())return;
|
||||
char commandType{data[pos]>>5};
|
||||
char len{data[pos]&0x1F+1};
|
||||
if(commandType==7){
|
||||
commandType=(data[pos]&0x1C)>>2;
|
||||
len=((data[pos]&3)<<8)+data[pos+1]+1;
|
||||
++pos;
|
||||
}
|
||||
if(bpos+len>maxLength||bpos+len<0)return;
|
||||
if(commandType>=4) {
|
||||
bpos2=(data[pos]<<8)+data[pos+1];
|
||||
if(bpos2>=maxLength||bpos2<0)return;
|
||||
pos+=2;
|
||||
}
|
||||
switch(commandType) {
|
||||
case UNCOMPRESSED_BLOCK:{
|
||||
while(len--!=0)block[bpos++]=data[pos++];
|
||||
}break;
|
||||
case RUN_LENGTH_ENCODED_BYTE:{
|
||||
while(len--!=0)block[bpos++]=data[pos];
|
||||
++pos;
|
||||
}break;
|
||||
case RUN_LENGTH_ENCODED_SHORT:{
|
||||
if(bpos+2*len>maxLength||bpos<0)return;
|
||||
while(len--!=0){
|
||||
block[bpos++]=data[pos];
|
||||
block[bpos++]=data[pos+1];
|
||||
}
|
||||
}break;
|
||||
case INCREMENTAL_SEQUENCE:{
|
||||
tmp=data[pos++];
|
||||
while(len--!=0)block[bpos++]=tmp++;
|
||||
}break;
|
||||
case REPEAT_PREVIOUS_DATA:{
|
||||
if(bpos+2*len>maxLength||bpos<0)return;
|
||||
for(int i:std::views::iota(0,len))block[bpos++]=block[bpos2+i];
|
||||
}break;
|
||||
case REVERSE_BITS:{
|
||||
if(bpos+2*len>maxLength||bpos<0)return;
|
||||
while(len--!=0)block[bpos++]=Rom::reversedBytes[block[bpos2++]&0xFF];
|
||||
}break;
|
||||
case UNKNOWN_1:{
|
||||
|
||||
}break;
|
||||
case UNKNOWN_2:{
|
||||
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -189,10 +237,24 @@ struct Rom{
|
||||
}
|
||||
};
|
||||
std::string data;
|
||||
inline static std::string reversedBytes;
|
||||
std::vector<BattleBackground>backgrounds;
|
||||
std::vector<BackgroundPalette>palettes;
|
||||
std::vector<BackgroundGraphics>graphics;
|
||||
Rom(){
|
||||
#pragma region Setup Reversed Bytes
|
||||
reversedBytes.resize(256);
|
||||
for(int i:std::views::iota(0U,reversedBytes.size())){
|
||||
uint8_t newNumb{};
|
||||
for(int digit=0;digit<8;digit++){
|
||||
uint8_t digitVal{1U<<digit};
|
||||
if(i&digitVal)newNumb|=1<<(7-digit);
|
||||
}
|
||||
reversedBytes[i]=newNumb;
|
||||
i++;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
std::ifstream dataStream{"truncated_backgrounds.dat",std::ios_base::binary};
|
||||
while(dataStream.good())data+=dataStream.get();
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user