bool resize(int new_size) // Return false if we couldn't resize. { if (m_read_only) return false; m_.resize(new_size); // Hm, does this make sense? We're truncating the file, so clamping the cursor. // Alternative would be to disallow resize, but that doesn't seem good either. if (m_position > m_.size()) { m_position = m_.size(); } return true; }
int decodeSmdRom(void*data,int size,membuf&out,int dn,int&ns) { char*romdata=(char*)data; ns=0; if(size<(16*KB+0x200)) { return 0; } if(size%(16*KB)!=0x200) { return 0; } size-=0x200; if(dn==0) { dn=size; } if(dn>size) { return 0; } if(!out.resize(size)) { return 0; } int dp; const int tb=size/(16*KB); dp=0; for(int i=0;i<tb&&dp<dn;i++) { for(int j=0;j<8*KB&&dp<dn;j++) { out[i*16*KB+j*2+0]=romdata[0x200+i*16*KB+0*KB+j]; out[i*16*KB+j*2+1]=romdata[0x200+i*16*KB+8*KB+j]; dp+=2; } } ns=dp; if(memcmp(out+0x100,"SEGA",4)==0||memcmp(out+0x101,"SEGA",4)==0) { return 1; } dp=0; for(int i=0;i<tb&&dp<dn;i++) { for(int j=0;j<8*KB&&dp<dn;j++) { out[i*16*KB+j*2+1]=romdata[0x200+i*16*KB+0*KB+j]; out[i*16*KB+j*2+0]=romdata[0x200+i*16*KB+8*KB+j]; dp+=2; } } ns=dp; if(memcmp(out+0x100,"SEGA",4)==0||memcmp(out+0x101,"SEGA",4)==0) { return 1; } return 0; }
bool membuf::operator!=(const membuf& buf) const { if (size() != buf.size()) { return false; } return memcmp(m_data, buf.m_data, size()) == 0 ? false : true; }
void convertSave2n64(int savetype,const BYTE*data_in,membuf&data_out,int&size) { if(savetype==st_n64eep4k) { data_out.resize(st_n64eep4k); memset(data_out,0,st_n64eep4k); size=Min(size,st_n64eep4k*16); neo2n64(data_in,data_out,size); size=st_n64eep4k; } if(savetype==st_n64eep16k) { data_out.resize(st_n64eep16k); memset(data_out,0,st_n64eep16k); size=Min(size,st_n64eep16k*16); neo2n64(data_in,data_out,size); size=st_n64eep16k; } if(savetype==st_n64sram) { data_out.resize(st_n64sram); memset(data_out,0,st_n64sram); size=Min(size,st_n64sram); memcpy(data_out,data_in,size); wswap((BYTE*)(char*)data_out,size); size=st_n64sram; } if(savetype==st_n64flash) { data_out.resize(st_n64flash); memset(data_out,0,st_n64flash); size=Min(size,st_n64flash); memcpy(data_out,data_in,size); wswap((BYTE*)(char*)data_out,size); size=st_n64flash; } }
unsigned char* get_cursor() { return ((unsigned char*) m_.data()) + m_position; }
bool is_valid() { return m_position >= 0 && m_position <= m_.size(); }
void membuf::operator=(const membuf& buf) { resize(buf.size()); memcpy(m_data, buf.m_data, size()); m_read_only = buf.m_read_only; }
void membuf::append(const membuf& buf) { append(buf.data(), buf.size()); }