Stop the crashes at least.

master
sigonasr2 8 months ago
parent 15e8df7c01
commit 6db778d6a8
  1. 25
      EarthboundBattleBackgrounds/EarthboundBattleBackgrounds/main.cpp
  2. BIN
      EarthboundBattleBackgrounds/x64/Debug/EarthboundBattleBackgrounds.exe

@ -60,17 +60,17 @@ struct Rom{
int32_t bpos2{}; int32_t bpos2{};
while(data[pos]!=0xFF){ while(data[pos]!=0xFF){
if(pos>=data.length())throw std::runtime_error{"Unexpected end of data."}; if(pos>=data.length())throw std::runtime_error{"Unexpected end of data."};
char commandType{data[pos]>>5}; int commandType{data[pos]>>5};
char length{(data[pos]&0x1F)+1}; int length{(data[pos]&0x1F)+1};
if(commandType==7){ if(commandType==7){
commandType=(data[pos]&0x1C)>>2; commandType=(data[pos]&0x1C)>>2;
length=((data[pos]&3)<<8)+(data[pos+1])+1; length=((int(data[pos])&3)<<8)+int(data[pos+1])+1;
++pos; ++pos;
} }
if(bpos+length<0)throw std::runtime_error("Length ended up negative."); if(bpos+length<0)throw std::runtime_error("Length ended up negative.");
pos++; pos++;
if(commandType>=4){ if(commandType>=4){
bpos2=(data[pos]<<8)+data[pos+1]; bpos2=(int(data[pos])<<8)+int(data[pos+1]);
if(bpos2<0)throw std::runtime_error("Reading negative data."); if(bpos2<0)throw std::runtime_error("Reading negative data.");
pos+=2; pos+=2;
} }
@ -127,17 +127,17 @@ struct Rom{
int read{}; int read{};
while(data[pos]!=0xFF){ while(data[pos]!=0xFF){
if (pos >= data.length())return; if (pos >= data.length())return;
char commandType{data[pos]>>5}; int commandType{data[pos]>>5};
char len{data[pos]&0x1F+1}; int len{data[pos]&0x1F+1};
if(commandType==7){ if(commandType==7){
commandType=(data[pos]&0x1C)>>2; commandType=(int(data[pos])&0x1C)>>2;
len=((data[pos]&3)<<8)+data[pos+1]+1; len=((int(data[pos])&3)<<8)+int(data[pos+1])+1;
++pos; ++pos;
} }
if(bpos+len>maxLength||bpos+len<0)return; if(bpos+len>maxLength||bpos+len<0)return;
++pos; ++pos;
if(commandType>=4) { if(commandType>=4) {
bpos2=(data[pos]<<8)+data[pos+1]; bpos2=(int(data[pos])<<8)+data[pos+1];
if(bpos2>=maxLength||bpos2<0)return; if(bpos2>=maxLength||bpos2<0)return;
pos+=2; pos+=2;
} }
@ -336,11 +336,16 @@ public:
} }
} }
void GraphicsDisplayTest(){
}
int yOffset{0}; int yOffset{0};
bool OnUserUpdate(float fElapsedTime) override bool OnUserUpdate(float fElapsedTime) override
{ {
PaletteDisplayTest(); //PaletteDisplayTest();
GraphicsDisplayTest();
return true; return true;
} }
}; };

Loading…
Cancel
Save