diff --git a/bsnes/nall/array.hpp b/bsnes/nall/array.hpp index 9cfe7758..432cbce4 100755 --- a/bsnes/nall/array.hpp +++ b/bsnes/nall/array.hpp @@ -54,6 +54,10 @@ namespace nall { operator[](buffersize) = data; } + void remove() { + if(size > 0) resize(size - 1); //remove last element only + } + template void insert(unsigned index, const U list) { unsigned listsize = container_size(list); resize(buffersize + listsize); diff --git a/bsnes/nall/config.hpp b/bsnes/nall/config.hpp index b8381b16..99aaee08 100755 --- a/bsnes/nall/config.hpp +++ b/bsnes/nall/config.hpp @@ -34,11 +34,11 @@ namespace nall { string get() const { switch(type) { - case boolean_t: return string() << *(bool*)data; - case signed_t: return string() << *(signed*)data; - case unsigned_t: return string() << *(unsigned*)data; - case double_t: return string() << *(double*)data; - case string_t: return string() << "\"" << *(string*)data << "\""; + case boolean_t: return { *(bool*)data }; + case signed_t: return { *(signed*)data }; + case unsigned_t: return { *(unsigned*)data }; + case double_t: return { *(double*)data }; + case string_t: return { "\"", *(string*)data, "\"" }; } return "???"; } @@ -105,9 +105,9 @@ namespace nall { if(fp.open(filename, file::mode::write)) { for(unsigned i = 0; i < list.size(); i++) { string output; - output << list[i].name << " = " << list[i].get(); - if(list[i].desc != "") output << " # " << list[i].desc; - output << "\r\n"; + output.append(list[i].name, " = ", list[i].get()); + if(list[i].desc != "") output.append(" # ", list[i].desc); + output.append("\r\n"); fp.print(output); } diff --git a/bsnes/nall/gameboy/cartridge.hpp b/bsnes/nall/gameboy/cartridge.hpp index 0e1b28d8..3ab00e34 100755 --- a/bsnes/nall/gameboy/cartridge.hpp +++ b/bsnes/nall/gameboy/cartridge.hpp @@ -86,17 +86,17 @@ GameBoyCartridge::GameBoyCartridge(const uint8_t *romdata, unsigned romsize) { if(info.mapper == "MBC2") info.ramsize = 512; //512 x 4-bit - xml << "\n"; + xml.append("\n"); - xml << " \n"; //TODO: trust/check info.romsize? + xml.append(" \n"); //TODO: trust/check info.romsize? if(info.ramsize > 0) - xml << " \n"; + xml.append(" \n"); - xml << "\n"; + xml.append("\n"); xml.transform("'", "\""); } diff --git a/bsnes/nall/input.hpp b/bsnes/nall/input.hpp index 1fd680f4..cd765393 100755 --- a/bsnes/nall/input.hpp +++ b/bsnes/nall/input.hpp @@ -110,7 +110,7 @@ struct Keyboard { break; } } - return string() << "KB" << ID << "::" << KeyboardScancodeName[index]; + return { "KB", ID, "::", KeyboardScancodeName[index] }; } uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } @@ -207,7 +207,7 @@ struct Mouse { break; } } - return string() << "MS" << ID << "::" << MouseScancodeName[index]; + return { "MS", ID, "::", MouseScancodeName[index] }; } uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } @@ -330,7 +330,7 @@ struct Joypad { index = code - (Base + Size * i); } } - return string() << "JP" << ID << "::" << JoypadScancodeName[index]; + return { "JP", ID, "::", JoypadScancodeName[index] }; } uint16_t operator[](Scancode code) const { return Base + ID * Size + code; } diff --git a/bsnes/nall/sha256.hpp b/bsnes/nall/sha256.hpp index 7f41f04e..ff88eda1 100755 --- a/bsnes/nall/sha256.hpp +++ b/bsnes/nall/sha256.hpp @@ -49,7 +49,7 @@ namespace nall { uint64_t len; }; - void sha256_init(sha256_ctx *p) { + inline void sha256_init(sha256_ctx *p) { memset(p, 0, sizeof(sha256_ctx)); memcpy(p->h, T_H, sizeof(T_H)); } @@ -90,7 +90,7 @@ namespace nall { p->inlen = 0; } - void sha256_chunk(sha256_ctx *p, const uint8_t *s, unsigned len) { + inline void sha256_chunk(sha256_ctx *p, const uint8_t *s, unsigned len) { unsigned l; p->len += len; @@ -107,7 +107,7 @@ namespace nall { } } - void sha256_final(sha256_ctx *p) { + inline void sha256_final(sha256_ctx *p) { uint64_t len; p->in[p->inlen++] = 0x80; @@ -124,7 +124,7 @@ namespace nall { sha256_block(p); } - void sha256_hash(sha256_ctx *p, uint8_t *s) { + inline void sha256_hash(sha256_ctx *p, uint8_t *s) { uint32_t *t = (uint32_t*)s; for(unsigned i = 0; i < 8; i++) ST32BE(t++, p->h[i]); } diff --git a/bsnes/nall/snes/cartridge.hpp b/bsnes/nall/snes/cartridge.hpp index 5d84e290..6847ba3a 100755 --- a/bsnes/nall/snes/cartridge.hpp +++ b/bsnes/nall/snes/cartridge.hpp @@ -111,426 +111,426 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) { string xml = "\n"; if(type == TypeBsx) { - xml << ""; + xml.append(""); xmlMemoryMap = xml.transform("'", "\""); return; } if(type == TypeSufamiTurbo) { - xml << ""; + xml.append(""); xmlMemoryMap = xml.transform("'", "\""); return; } if(type == TypeGameBoy) { - xml << "\n"; + xml.append("\n"); if(gameboy_ram_size(data, size) > 0) { - xml << " \n"; + xml.append(" \n"); } - xml << "\n"; + xml.append("\n"); xmlMemoryMap = xml.transform("'", "\""); return; } - xml << "\n"; + xml.append(">\n"); if(type == TypeSuperGameBoy1Bios) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(type == TypeSuperGameBoy2Bios) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(has_cx4) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(has_spc7110) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if(has_spc7110rtc) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(mapper == LoROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if(ram_size > 0) { - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if((rom_size > 0x200000) || (ram_size > 32 * 1024)) { - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); } else { - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); } - xml << " \n"; + xml.append(" \n"); } } else if(mapper == HiROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if(ram_size > 0) { - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if((rom_size > 0x200000) || (ram_size > 32 * 1024)) { - xml << " \n"; + xml.append(" \n"); } else { - xml << " \n"; + xml.append(" \n"); } - xml << " \n"; + xml.append(" \n"); } } else if(mapper == ExLoROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if(ram_size > 0) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } } else if(mapper == ExHiROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if(ram_size > 0) { - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); if((rom_size > 0x200000) || (ram_size > 32 * 1024)) { - xml << " \n"; + xml.append(" \n"); } else { - xml << " \n"; + xml.append(" \n"); } - xml << " \n"; + xml.append(" \n"); } } else if(mapper == SuperFXROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(mapper == SA1ROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(mapper == BSCLoROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(mapper == BSCHiROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(mapper == BSXROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(mapper == STROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_srtc) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_sdd1) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_dsp1) { - xml << " \n"; + xml.append(" \n"); if(dsp1_mapper == DSP1LoROM1MB) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(dsp1_mapper == DSP1LoROM2MB) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } else if(dsp1_mapper == DSP1HiROM) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } - xml << " \n"; + xml.append(" \n"); } if(has_dsp2) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_dsp3) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_dsp4) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_obc1) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_st010) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_st011) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } if(has_st018) { - xml << " \n"; - xml << " \n"; - xml << " \n"; - xml << " \n"; + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); + xml.append(" \n"); } - xml << "\n"; + xml.append("\n"); xmlMemoryMap = xml.transform("'", "\""); } diff --git a/bsnes/nall/stack.hpp b/bsnes/nall/stack.hpp new file mode 100755 index 00000000..005256e3 --- /dev/null +++ b/bsnes/nall/stack.hpp @@ -0,0 +1,66 @@ +#ifndef NALL_STACK_HPP +#define NALL_STACK_HPP + +#include + +namespace nall { + template struct stack_fifo { + T& operator()() { + if(list.size() == 0) throw; + return list[0]; + } + + void reset() { + list.reset(); + } + + unsigned size() const { + return list.size(); + } + + void push(const T &value) { + list.append(value); + } + + T pull() { + if(list.size() == 0) throw; + T value = list[0]; + list.remove(0); + return value; + } + + private: + linear_vector list; + }; + + template struct stack_filo { + T& operator()() { + if(list.size() == 0) throw; + return list[list.size() - 1]; + } + + void reset() { + list.reset(); + } + + unsigned size() const { + return list.size(); + } + + void push(const T &value) { + list.append(value); + } + + T pull() { + if(list.size() == 0) throw; + T value = list[list.size() - 1]; + list.remove(list.size() - 1); + return value; + } + + private: + linear_vector list; + }; +} + +#endif diff --git a/bsnes/nall/string.hpp b/bsnes/nall/string.hpp index 9acc2e9d..d155f79f 100755 --- a/bsnes/nall/string.hpp +++ b/bsnes/nall/string.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/bsnes/nall/string/base.hpp b/bsnes/nall/string/base.hpp index f6172c26..5a5dafa0 100755 --- a/bsnes/nall/string/base.hpp +++ b/bsnes/nall/string/base.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,8 @@ namespace nall { inline string& lower(); inline string& upper(); + inline string& qlower(); + inline string& qupper(); inline string& transform(const char *before, const char *after); template inline string& ltrim(const char *key = " "); @@ -52,9 +55,6 @@ namespace nall { inline optional position(const char *key) const; inline optional qposition(const char *key) const; - template inline string& operator= (T value); - template inline string& operator<<(T value); - inline operator const char*() const; inline char* operator()(); inline char& operator[](int); @@ -110,6 +110,8 @@ namespace nall { //convert.hpp inline char* strlower(char *str); inline char* strupper(char *str); + inline char* qstrlower(char *str); + inline char* qstrupper(char *str); inline char* strtr(char *dest, const char *before, const char *after); inline uintmax_t hex (const char *str); inline intmax_t integer(const char *str); @@ -142,7 +144,8 @@ namespace nall { //utility.hpp inline unsigned strlcpy(string &dest, const char *src, unsigned length); inline unsigned strlcat(string &dest, const char *src, unsigned length); - inline string substr(const char *src, unsigned start = 0, unsigned length = 0); + inline string substr(const char *src, unsigned start = 0, unsigned length = ~0u); + inline string sha256(const uint8_t *data, unsigned size); inline string integer(intmax_t value); template inline string linteger(intmax_t value); diff --git a/bsnes/nall/string/cast.hpp b/bsnes/nall/string/cast.hpp index 9498392c..2d010bfa 100755 --- a/bsnes/nall/string/cast.hpp +++ b/bsnes/nall/string/cast.hpp @@ -15,9 +15,6 @@ template<> inline const char* to_string (const char *v) { return template<> inline const char* to_string (string v) { return v; } template<> inline const char* to_string(const string &v) { return v; } -template string& string::operator= (T value) { return assign(to_string(value)); } -template string& string::operator<<(T value) { return append(to_string(value)); } - template lstring& lstring::operator<<(T value) { operator[](size()).assign(to_string(value)); return *this; diff --git a/bsnes/nall/string/convert.hpp b/bsnes/nall/string/convert.hpp index 603d2e0e..0808cbc6 100755 --- a/bsnes/nall/string/convert.hpp +++ b/bsnes/nall/string/convert.hpp @@ -23,6 +23,26 @@ char* strupper(char *str) { return str; } +char* qstrlower(char *s) { + if(!s) return 0; + bool quoted = false; + while(*s) { + if(*s == '\"') quoted ^= 1; + if(quoted == false && *s >= 'A' && *s <= 'Z') *s += 0x20; + s++; + } +} + +char* qstrupper(char *s) { + if(!s) return 0; + bool quoted = false; + while(*s) { + if(*s == '\"') quoted ^= 1; + if(quoted == false && *s >= 'a' && *s <= 'z') *s -= 0x20; + s++; + } +} + char* strtr(char *dest, const char *before, const char *after) { if(!dest || !before || !after) return dest; int sl = strlen(dest), bsl = strlen(before), asl = strlen(after); diff --git a/bsnes/nall/string/math.hpp b/bsnes/nall/string/math.hpp index ea8b99c8..d4bc9d25 100755 --- a/bsnes/nall/string/math.hpp +++ b/bsnes/nall/string/math.hpp @@ -3,6 +3,8 @@ namespace nall { +static function eval_fallback; + static int eval_integer(const char *&s) { if(!*s) throw "unrecognized_integer"; int value = 0, x = *s, y = *(s + 1); @@ -58,7 +60,7 @@ static int eval_integer(const char *&s) { } static int eval(const char *&s, int depth = 0) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace + while(*s == ' ' || *s == '\t') s++; //trim whitespace if(!*s) throw "unrecognized_token"; int value = 0, x = *s, y = *(s + 1); @@ -74,10 +76,12 @@ static int eval(const char *&s, int depth = 0) { else if((x >= '0' && x <= '9') || x == '\'') value = eval_integer(s); + else if(eval_fallback) value = eval_fallback(s); //optional user-defined syntax parsing + else throw "unrecognized_token"; while(true) { - while(*s == ' ' || *s == '\t') s++; //trim whitespace + while(*s == ' ' || *s == '\t') s++; //trim whitespace if(!*s) break; x = *s, y = *(s + 1); diff --git a/bsnes/nall/string/utility.hpp b/bsnes/nall/string/utility.hpp index 8e6c1005..6906fae4 100755 --- a/bsnes/nall/string/utility.hpp +++ b/bsnes/nall/string/utility.hpp @@ -15,7 +15,7 @@ unsigned strlcat(string &dest, const char *src, unsigned length) { string substr(const char *src, unsigned start, unsigned length) { string dest; - if(length == 0) { + if(length == ~0u) { //copy entire string dest = src + start; } else { @@ -25,6 +25,18 @@ string substr(const char *src, unsigned start, unsigned length) { return dest; } +string sha256(const uint8_t *data, unsigned size) { + sha256_ctx sha; + uint8_t hash[32]; + sha256_init(&sha); + sha256_chunk(&sha, data, size); + sha256_final(&sha); + sha256_hash(&sha, hash); + string result; + foreach(byte, hash) result.append(hex<2>(byte)); + return result; +} + /* arithmetic <> string */ string integer(intmax_t value) { diff --git a/bsnes/nall/string/wrapper.hpp b/bsnes/nall/string/wrapper.hpp index eadf0a10..8bb4cfc5 100755 --- a/bsnes/nall/string/wrapper.hpp +++ b/bsnes/nall/string/wrapper.hpp @@ -19,6 +19,8 @@ bool string::iendswith(const char *str) const { return striend(data, str); } string& string::lower() { nall::strlower(data); return *this; } string& string::upper() { nall::strupper(data); return *this; } +string& string::qlower() { nall::qstrlower(data); return *this; } +string& string::qupper() { nall::qstrupper(data); return *this; } string& string::transform(const char *before, const char *after) { nall::strtr(data, before, after); return *this; } template string& string::ltrim(const char *key) { nall::ltrim(data, key); return *this; } diff --git a/bsnes/nall/string/xml.hpp b/bsnes/nall/string/xml.hpp index 185a89f9..47653786 100755 --- a/bsnes/nall/string/xml.hpp +++ b/bsnes/nall/string/xml.hpp @@ -77,7 +77,7 @@ inline string xml_element::parse() const { if(auto pos = strpos(source, "]]>")) { if(pos() - 9 > 0) { string cdata = substr(source, 9, pos() - 9); - data << cdata; + data.append(cdata); offset += strlen(cdata); } source += 9 + offset + 3; diff --git a/bsnes/snes/cartridge/cartridge.cpp b/bsnes/snes/cartridge/cartridge.cpp index 31bc41ea..66c32123 100755 --- a/bsnes/snes/cartridge/cartridge.cpp +++ b/bsnes/snes/cartridge/cartridge.cpp @@ -54,7 +54,7 @@ void Cartridge::load(Mode cartridge_mode, const lstring &xml_list) { sha256_hash(&sha, shahash); string hash; - foreach(n, shahash) hash << hex<2>(n); + foreach(n, shahash) hash.append(hex<2>(n)); sha256 = hash; system.load(); diff --git a/bsnes/snes/cartridge/xml.cpp b/bsnes/snes/cartridge/xml.cpp index 5202c31a..76cb44ff 100755 --- a/bsnes/snes/cartridge/xml.cpp +++ b/bsnes/snes/cartridge/xml.cpp @@ -284,8 +284,7 @@ void Cartridge::xml_parse_necdsp(xml_element &root) { for(unsigned n = 0; n < 16384; n++) necdsp.programROM[n] = 0x000000; for(unsigned n = 0; n < 2048; n++) necdsp.dataROM[n] = 0x0000; - string program, programhash; - string sha256; + string firmware, sha256; foreach(attr, root.attribute) { if(attr.name == "model") { @@ -293,36 +292,39 @@ void Cartridge::xml_parse_necdsp(xml_element &root) { if(attr.content == "uPD96050") necdsp.revision = NECDSP::Revision::uPD96050; } else if(attr.name == "frequency") { necdsp.frequency = xml_parse_unsigned(attr.content); - } else if(attr.name == "program") { - program = attr.content; + } else if(attr.name == "firmware") { + firmware = attr.content; } else if(attr.name == "sha256") { sha256 = attr.content; } } - string path = { dir(system.interface->path(Slot::Base, ".dsp")), program }; + string path = { dir(system.interface->path(Slot::Base, ".dsp")), firmware }; unsigned promsize = (necdsp.revision == NECDSP::Revision::uPD7725 ? 2048 : 16384); unsigned dromsize = (necdsp.revision == NECDSP::Revision::uPD7725 ? 1024 : 2048); unsigned filesize = promsize * 3 + dromsize * 2; file fp; - if(fp.open(path, file::mode::read)) { - if(fp.size() == filesize) { - for(unsigned n = 0; n < promsize; n++) necdsp.programROM[n] = fp.readm(3); - for(unsigned n = 0; n < dromsize; n++) necdsp.dataROM[n] = fp.readm(2); + if(fp.open(path, file::mode::read) == false) { + system.interface->message({ "Warning: NEC DSP firmware ", firmware, " is missing." }); + } else if(fp.size() != filesize) { + system.interface->message({ "Warning: NEC DSP firmware ", firmware, " is of the wrong file size." }); + fp.close(); + } else { + for(unsigned n = 0; n < promsize; n++) necdsp.programROM[n] = fp.readm(3); + for(unsigned n = 0; n < dromsize; n++) necdsp.dataROM[n] = fp.readm(2); + if(sha256 != "") { + //XML file specified SHA256 sum for program. Verify file matches the hash. fp.seek(0); uint8_t data[filesize]; fp.read(data, filesize); - sha256_ctx sha; - uint8 shahash[32]; - sha256_init(&sha); - sha256_chunk(&sha, data, filesize); - sha256_final(&sha); - sha256_hash(&sha, shahash); - foreach(n, shahash) programhash.append(hex<2>(n)); + if(sha256 != nall::sha256(data, filesize)) { + system.interface->message({ "Warning: Hitachi DSP firmware ", firmware, " SHA256 sum is incorrect." }); + } } + fp.close(); } @@ -359,16 +361,6 @@ void Cartridge::xml_parse_necdsp(xml_element &root) { } } } - - if(programhash == "") { - system.interface->message({ "Warning: NEC DSP program ", program, " is missing." }); - } else if(sha256 != "" && sha256 != programhash) { - system.interface->message({ - "Warning: NEC DSP program ", program, " SHA256 is incorrect.\n\n" - "Expected:\n", sha256, "\n\n" - "Actual:\n", programhash - }); - } } void Cartridge::xml_parse_hitachidsp(xml_element &root) { @@ -377,24 +369,24 @@ void Cartridge::xml_parse_hitachidsp(xml_element &root) { for(unsigned n = 0; n < 1024; n++) hitachidsp.dataROM[n] = 0x000000; - string dataROM, sha256; + string firmware, sha256; foreach(attr, root.attribute) { if(attr.name == "frequency") { hitachidsp.frequency = xml_parse_unsigned(attr.content); - } else if(attr.name == "data") { - dataROM = attr.content; + } else if(attr.name == "firmware") { + firmware = attr.content; } else if(attr.name == "sha256") { sha256 = attr.content; } } - string path = { dir(system.interface->path(Slot::Base, ".dsp")), dataROM }; + string path = { dir(system.interface->path(Slot::Base, ".dsp")), firmware }; file fp; if(fp.open(path, file::mode::read) == false) { - system.interface->message({ "Warning: Hitachi DSP data ", dataROM, " is missing." }); + system.interface->message({ "Warning: Hitachi DSP firmware ", firmware, " is missing." }); } else if(fp.size() != 1024 * 3) { - system.interface->message({ "Warning: Hitachi DSP data ", dataROM, " is of the wrong file size." }); + system.interface->message({ "Warning: Hitachi DSP firmware ", firmware, " is of the wrong file size." }); fp.close(); } else { for(unsigned n = 0; n < 1024; n++) hitachidsp.dataROM[n] = fp.readl(3); @@ -405,18 +397,8 @@ void Cartridge::xml_parse_hitachidsp(xml_element &root) { uint8 data[3072]; fp.read(data, 3072); - sha256_ctx sha; - uint8 hash[32]; - sha256_init(&sha); - sha256_chunk(&sha, data, 3072); - sha256_final(&sha); - sha256_hash(&sha, hash); - - string filehash; - foreach(n, hash) filehash.append(hex<2>(n)); - - if(sha256 != filehash) { - system.interface->message({ "Warning: Hitachi DSP data ", dataROM, " SHA256 sum is incorrect." }); + if(sha256 != nall::sha256(data, 3072)) { + system.interface->message({ "Warning: Hitachi DSP firmware ", firmware, " SHA256 sum is incorrect." }); } } diff --git a/bsnes/snes/cheat/cheat.cpp b/bsnes/snes/cheat/cheat.cpp index ccf25136..695de58a 100755 --- a/bsnes/snes/cheat/cheat.cpp +++ b/bsnes/snes/cheat/cheat.cpp @@ -86,7 +86,7 @@ bool Cheat::decode(const char *s, unsigned &addr, uint8 &data, Type &type) { if(strlen(t) == 8 || (strlen(t) == 9 && t[6] == ':')) { //strip ':' - if(strlen(t) == 9 && t[6] == ':') t = string() << substr(t, 0, 6) << substr(t, 7); + if(strlen(t) == 9 && t[6] == ':') t = { substr(t, 0, 6), substr(t, 7) }; //validate input for(unsigned i = 0; i < 8; i++) if(!ischr(t[i])) return false; @@ -97,7 +97,7 @@ bool Cheat::decode(const char *s, unsigned &addr, uint8 &data, Type &type) { return true; } else if(strlen(t) == 9 && t[4] == '-') { //strip '-' - t = string() << substr(t, 0, 4) << substr(t, 5); + t = { substr(t, 0, 4), substr(t, 5) }; //validate input for(unsigned i = 0; i < 8; i++) if(!ischr(t[i])) return false; diff --git a/bsnes/snes/chip/icd2/interface/interface.cpp b/bsnes/snes/chip/icd2/interface/interface.cpp index 1608037f..7e996b85 100755 --- a/bsnes/snes/chip/icd2/interface/interface.cpp +++ b/bsnes/snes/chip/icd2/interface/interface.cpp @@ -101,7 +101,7 @@ bool ICD2::input_poll(unsigned id) { case 3: data = ~r6007; break; } - switch(id) { + switch((GameBoy::Input)id) { case GameBoy::Input::Start: return data & 0x80; case GameBoy::Input::Select: return data & 0x40; case GameBoy::Input::B: return data & 0x20; diff --git a/bsnes/snes/chip/necdsp/disassembler.cpp b/bsnes/snes/chip/necdsp/disassembler.cpp index 5f77e86c..23a5bb95 100755 --- a/bsnes/snes/chip/necdsp/disassembler.cpp +++ b/bsnes/snes/chip/necdsp/disassembler.cpp @@ -16,114 +16,97 @@ string NECDSP::disassemble(uint14 ip) { uint4 dst = opcode >> 0; switch(alu) { - case 0: output << "nop "; break; - case 1: output << "or "; break; - case 2: output << "and "; break; - case 3: output << "xor "; break; - case 4: output << "sub "; break; - case 5: output << "add "; break; - case 6: output << "sbb "; break; - case 7: output << "adc "; break; - case 8: output << "dec "; break; - case 9: output << "inc "; break; - case 10: output << "cmp "; break; - case 11: output << "shr1 "; break; - case 12: output << "shl1 "; break; - case 13: output << "shl2 "; break; - case 14: output << "shl4 "; break; - case 15: output << "xchg "; break; + case 0: output.append("nop "); break; + case 1: output.append("or "); break; + case 2: output.append("and "); break; + case 3: output.append("xor "); break; + case 4: output.append("sub "); break; + case 5: output.append("add "); break; + case 6: output.append("sbb "); break; + case 7: output.append("adc "); break; + case 8: output.append("dec "); break; + case 9: output.append("inc "); break; + case 10: output.append("cmp "); break; + case 11: output.append("shr1 "); break; + case 12: output.append("shl1 "); break; + case 13: output.append("shl2 "); break; + case 14: output.append("shl4 "); break; + case 15: output.append("xchg "); break; } if(alu < 8) { switch(pselect) { - case 0: output << "ram,"; break; - case 1: output << "idb,"; break; - case 2: output << "m,"; break; - case 3: output << "n,"; break; + case 0: output.append("ram,"); break; + case 1: output.append("idb,"); break; + case 2: output.append("m," ); break; + case 3: output.append("n," ); break; } } switch(asl) { - case 0: output << "a"; break; - case 1: output << "b"; break; + case 0: output.append("a"); break; + case 1: output.append("b"); break; } - output << "\n mov "; + output.append("\n mov "); switch(src) { - case 0: output << "trb,"; break; - case 1: output << "a,"; break; - case 2: output << "b,"; break; - case 3: output << "tr,"; break; - case 4: output << "dp,"; break; - case 5: output << "rp,"; break; - case 6: output << "ro,"; break; - case 7: output << "sgn,"; break; - case 8: output << "dr,"; break; - case 9: output << "drnf,"; break; - case 10: output << "sr,"; break; - case 11: output << "sim,"; break; - case 12: output << "sil,"; break; - case 13: output << "k,"; break; - case 14: output << "l,"; break; - case 15: output << "mem,"; break; + case 0: output.append("trb," ); break; + case 1: output.append("a," ); break; + case 2: output.append("b," ); break; + case 3: output.append("tr," ); break; + case 4: output.append("dp," ); break; + case 5: output.append("rp," ); break; + case 6: output.append("ro," ); break; + case 7: output.append("sgn," ); break; + case 8: output.append("dr," ); break; + case 9: output.append("drnf,"); break; + case 10: output.append("sr," ); break; + case 11: output.append("sim," ); break; + case 12: output.append("sil," ); break; + case 13: output.append("k," ); break; + case 14: output.append("l," ); break; + case 15: output.append("mem," ); break; } switch(dst) { - case 0: output << "non"; break; - case 1: output << "a"; break; - case 2: output << "b"; break; - case 3: output << "tr"; break; - case 4: output << "dp"; break; - case 5: output << "rp"; break; - case 6: output << "dr"; break; - case 7: output << "sr"; break; - case 8: output << "sol"; break; - case 9: output << "som"; break; - case 10: output << "k"; break; - case 11: output << "klr"; break; - case 12: output << "klm"; break; - case 13: output << "l"; break; - case 14: output << "trb"; break; - case 15: output << "mem"; break; + case 0: output.append("non"); break; + case 1: output.append("a" ); break; + case 2: output.append("b" ); break; + case 3: output.append("tr" ); break; + case 4: output.append("dp" ); break; + case 5: output.append("rp" ); break; + case 6: output.append("dr" ); break; + case 7: output.append("sr" ); break; + case 8: output.append("sol"); break; + case 9: output.append("som"); break; + case 10: output.append("k" ); break; + case 11: output.append("klr"); break; + case 12: output.append("klm"); break; + case 13: output.append("l" ); break; + case 14: output.append("trb"); break; + case 15: output.append("mem"); break; } if(dpl) { switch(dpl) { - case 0: output << "\n dpnop"; break; - case 1: output << "\n dpinc"; break; - case 2: output << "\n dpdec"; break; - case 3: output << "\n dpclr"; break; + case 0: output.append("\n dpnop"); break; + case 1: output.append("\n dpinc"); break; + case 2: output.append("\n dpdec"); break; + case 3: output.append("\n dpclr"); break; } } if(dphm) { - switch(dphm) { - case 0: output << "\n m0"; break; - case 1: output << "\n m1"; break; - case 2: output << "\n m2"; break; - case 3: output << "\n m3"; break; - case 4: output << "\n m4"; break; - case 5: output << "\n m5"; break; - case 6: output << "\n m6"; break; - case 7: output << "\n m7"; break; - case 8: output << "\n m8"; break; - case 9: output << "\n m9"; break; - case 10: output << "\n ma"; break; - case 11: output << "\n mb"; break; - case 12: output << "\n mc"; break; - case 13: output << "\n md"; break; - case 14: output << "\n me"; break; - case 15: output << "\n mf"; break; - } + output.append("\n m", hex<1>(dphm)); } if(rpdcr == 1) { - output << "\n rpdec"; + output.append("\n rpdec"); } if(type == 1) { - output << "\n ret"; + output.append("\n ret"); } } @@ -135,75 +118,75 @@ string NECDSP::disassemble(uint14 ip) { uint14 jp = (regs.pc & 0x2000) | (bank << 11) | (na << 0); switch(brch) { - case 0x000: output << "jmpso "; jp = 0; break; - case 0x080: output << "jnca "; break; - case 0x082: output << "jca "; break; - case 0x084: output << "jncb "; break; - case 0x086: output << "jcb "; break; - case 0x088: output << "jnza "; break; - case 0x08a: output << "jza "; break; - case 0x08c: output << "jnzb "; break; - case 0x08e: output << "jzb "; break; - case 0x090: output << "jnova0 "; break; - case 0x092: output << "jova0 "; break; - case 0x094: output << "jnovb0 "; break; - case 0x096: output << "jovb0 "; break; - case 0x098: output << "jnova1 "; break; - case 0x09a: output << "jova1 "; break; - case 0x09c: output << "jnovb1 "; break; - case 0x09e: output << "jovb1 "; break; - case 0x0a0: output << "jnsa0 "; break; - case 0x0a2: output << "jsa0 "; break; - case 0x0a4: output << "jnsb0 "; break; - case 0x0a6: output << "jsb0 "; break; - case 0x0a8: output << "jnsa1 "; break; - case 0x0aa: output << "jsa1 "; break; - case 0x0ac: output << "jnsb1 "; break; - case 0x0ae: output << "jsb1 "; break; - case 0x0b0: output << "jdpl0 "; break; - case 0x0b1: output << "jdpln0 "; break; - case 0x0b2: output << "jdplf "; break; - case 0x0b3: output << "jdplnf "; break; - case 0x0b4: output << "jnsiak "; break; - case 0x0b6: output << "jsiak "; break; - case 0x0b8: output << "jnsoak "; break; - case 0x0ba: output << "jsoak "; break; - case 0x0bc: output << "jnrqm "; break; - case 0x0be: output << "jrqm "; break; - case 0x100: output << "ljmp "; jp &= ~0x2000; break; - case 0x101: output << "hjmp "; jp |= 0x2000; break; - case 0x140: output << "lcall "; jp &= ~0x2000; break; - case 0x141: output << "hcall "; jp |= 0x2000; break; - default: output << "?????? "; break; + case 0x000: output.append("jmpso "); jp = 0; break; + case 0x080: output.append("jnca "); break; + case 0x082: output.append("jca "); break; + case 0x084: output.append("jncb "); break; + case 0x086: output.append("jcb "); break; + case 0x088: output.append("jnza "); break; + case 0x08a: output.append("jza "); break; + case 0x08c: output.append("jnzb "); break; + case 0x08e: output.append("jzb "); break; + case 0x090: output.append("jnova0 "); break; + case 0x092: output.append("jova0 "); break; + case 0x094: output.append("jnovb0 "); break; + case 0x096: output.append("jovb0 "); break; + case 0x098: output.append("jnova1 "); break; + case 0x09a: output.append("jova1 "); break; + case 0x09c: output.append("jnovb1 "); break; + case 0x09e: output.append("jovb1 "); break; + case 0x0a0: output.append("jnsa0 "); break; + case 0x0a2: output.append("jsa0 "); break; + case 0x0a4: output.append("jnsb0 "); break; + case 0x0a6: output.append("jsb0 "); break; + case 0x0a8: output.append("jnsa1 "); break; + case 0x0aa: output.append("jsa1 "); break; + case 0x0ac: output.append("jnsb1 "); break; + case 0x0ae: output.append("jsb1 "); break; + case 0x0b0: output.append("jdpl0 "); break; + case 0x0b1: output.append("jdpln0 "); break; + case 0x0b2: output.append("jdplf "); break; + case 0x0b3: output.append("jdplnf "); break; + case 0x0b4: output.append("jnsiak "); break; + case 0x0b6: output.append("jsiak "); break; + case 0x0b8: output.append("jnsoak "); break; + case 0x0ba: output.append("jsoak "); break; + case 0x0bc: output.append("jnrqm "); break; + case 0x0be: output.append("jrqm "); break; + case 0x100: output.append("ljmp "); jp &= ~0x2000; break; + case 0x101: output.append("hjmp "); jp |= 0x2000; break; + case 0x140: output.append("lcall "); jp &= ~0x2000; break; + case 0x141: output.append("hcall "); jp |= 0x2000; break; + default: output.append("?????? "); break; } - output << "$" << hex<4>(jp); + output.append("$", hex<4>(jp)); } if(type == 3) { //LD - output << "ld "; + output.append("ld "); uint16 id = opcode >> 6; uint4 dst = opcode >> 0; - output << "$" << hex<4>(id) << ","; + output.append("$", hex<4>(id), ","); switch(dst) { - case 0: output << "non"; break; - case 1: output << "a"; break; - case 2: output << "b"; break; - case 3: output << "tr"; break; - case 4: output << "dp"; break; - case 5: output << "rp"; break; - case 6: output << "dr"; break; - case 7: output << "sr"; break; - case 8: output << "sol"; break; - case 9: output << "som"; break; - case 10: output << "k"; break; - case 11: output << "klr"; break; - case 12: output << "klm"; break; - case 13: output << "l"; break; - case 14: output << "trb"; break; - case 15: output << "mem"; break; + case 0: output.append("non"); break; + case 1: output.append("a" ); break; + case 2: output.append("b" ); break; + case 3: output.append("tr" ); break; + case 4: output.append("dp" ); break; + case 5: output.append("rp" ); break; + case 6: output.append("dr" ); break; + case 7: output.append("sr" ); break; + case 8: output.append("sol"); break; + case 9: output.append("som"); break; + case 10: output.append("k" ); break; + case 11: output.append("klr"); break; + case 12: output.append("klm"); break; + case 13: output.append("l" ); break; + case 14: output.append("trb"); break; + case 15: output.append("mem"); break; } } diff --git a/bsnes/snes/interface/interface.hpp b/bsnes/snes/interface/interface.hpp index f7ee5b14..1bd787fd 100755 --- a/bsnes/snes/interface/interface.hpp +++ b/bsnes/snes/interface/interface.hpp @@ -2,7 +2,6 @@ class Interface { public: virtual void video_refresh(const uint16_t *data, bool hires, bool interlace, bool overscan) {} virtual void audio_sample(uint16_t l_sample, uint16_t r_sample) {} - virtual void input_poll() {} virtual int16_t input_poll(bool port, Input::Device device, unsigned index, unsigned id) { return 0; } virtual void message(const string &text) { print(text, "\n"); } diff --git a/bsnes/snes/snes.hpp b/bsnes/snes/snes.hpp index 07ca720c..1af4b3fd 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/snes/snes.hpp @@ -1,7 +1,7 @@ namespace SNES { namespace Info { static const char Name[] = "bsnes"; - static const char Version[] = "080.01"; + static const char Version[] = "080.02"; static const unsigned SerializerVersion = 21; } } diff --git a/bsnes/ui/cartridge/cartridge.cpp b/bsnes/ui/cartridge/cartridge.cpp index 13990302..21633afe 100755 --- a/bsnes/ui/cartridge/cartridge.cpp +++ b/bsnes/ui/cartridge/cartridge.cpp @@ -103,7 +103,7 @@ bool Cartridge::loadCartridge(SNES::MappedRAM &memory, string &XML, const char * if(file::exists(filename) == false) return false; file fp; if(fp.open(filename, file::mode::read) == false) return false; - if(XML.readfile(string(nall::basename(filename), ".xml")) == false) XML = ""; + if(XML.readfile({ nall::basename(filename), ".xml" }) == false) XML = ""; unsigned size = fp.size(); uint8_t *data = new uint8_t[size]; diff --git a/bsnes/ui/debugger/console.cpp b/bsnes/ui/debugger/console.cpp index f0fb71d1..09e75e75 100755 --- a/bsnes/ui/debugger/console.cpp +++ b/bsnes/ui/debugger/console.cpp @@ -47,7 +47,7 @@ void Console::write(const string &text, bool echo) { OS::processEvents(); } if(traceToFile.checked() && logfile.open()) { - logfile.print(string(text, "\n")); + logfile.print(text, "\n"); } } diff --git a/bsnes/ui/general/file-browser.cpp b/bsnes/ui/general/file-browser.cpp index 045e1dd1..07587bf1 100755 --- a/bsnes/ui/general/file-browser.cpp +++ b/bsnes/ui/general/file-browser.cpp @@ -137,7 +137,7 @@ void FileBrowser::fileActivate() { string FileBrowser::cartridgeFolder(const string &pathname) { if(strend(pathname, ".sfc/") == false) return ""; - lstring list = directory::files(string(folder, "/", pathname)); + lstring list = directory::files({ folder, "/", pathname }); string filename; foreach(item, list) { if(strend(item, ".sfc")) { diff --git a/bsnes/ui/interface.cpp b/bsnes/ui/interface.cpp index b6b5debc..50234883 100755 --- a/bsnes/ui/interface.cpp +++ b/bsnes/ui/interface.cpp @@ -129,9 +129,6 @@ void Interface::audio_sample(uint16_t left, uint16_t right) { audio.sample(left, right); } -void Interface::input_poll() { -} - int16_t Interface::input_poll(bool port, SNES::Input::Device device, unsigned index, unsigned id) { if(config.settings.focusPolicy == 1 && mainWindow.focused() == false) return 0; return inputMapper.poll(port, device, index, id); diff --git a/bsnes/ui/interface.hpp b/bsnes/ui/interface.hpp index de3600ef..4ce0b154 100755 --- a/bsnes/ui/interface.hpp +++ b/bsnes/ui/interface.hpp @@ -17,7 +17,6 @@ struct Filter : public library { struct Interface : public SNES::Interface { void video_refresh(const uint16_t *data, bool hires, bool interlace, bool overscan); void audio_sample(uint16_t left, uint16_t right); - void input_poll(); int16_t input_poll(bool port, SNES::Input::Device device, unsigned index, unsigned id); void message(const string &text); diff --git a/bsnes/ui/path/path.cpp b/bsnes/ui/path/path.cpp index 73711338..9799b4ea 100755 --- a/bsnes/ui/path/path.cpp +++ b/bsnes/ui/path/path.cpp @@ -60,10 +60,10 @@ string Path::load(SNES::Cartridge::Slot slot, const string &hint) { if(hint == ".sav" && sav != "") filePath = sav; if(hint == ".rtc" && rtc != "") filePath = rtc; - if(hint.endswith(".dsp") && necdsp != "") filePath = necdsp; - if(hint.endswith(".msu") && msu1 != "") filePath = msu1; - if(hint.endswith(".pcm") && msu1 != "") filePath = msu1; - if(hint.endswith(".so") && serial != "") filePath = serial; + if(hint.endswith(".dsp") && firmware != "") filePath = firmware; + if(hint.endswith(".msu") && msu1 != "") filePath = msu1; + if(hint.endswith(".pcm") && msu1 != "") filePath = msu1; + if(hint.endswith(".so") && serial != "") filePath = serial; if(hint.endswith(".bsa") && bsa != "") filePath = bsa; if(hint.endswith(".bst") && bst != "") filePath = bst; @@ -115,21 +115,21 @@ string Path::decode(const string &filePath, const string &basePath) { if(path.beginswith("user/")) { path.ltrim<1>("user/"); #if defined(PLATFORM_X) || defined(PLATFORM_OSX) - path = string(user, ".config/bsnes/", path); + path = { user, ".config/bsnes/", path }; #else - path = string(user, "bsnes/", path); + path = { user, "bsnes/", path }; #endif } else if(path.beginswith("base/")) { path.ltrim<1>("base/"); - path = string(base, path); + path = { base, path }; } else if(path.beginswith("./")) { path.ltrim<1>("./"); - path = string(dir(basePath), path); + path = { dir(basePath), path }; } else if(path.beginswith("../")) { string base = dir(basePath); base.rtrim<1>("/"); path.ltrim<1>("../"); - path = string(dir(base), path); + path = { dir(base), path }; } return path; @@ -153,7 +153,7 @@ Path::Path() { attach(sufamiTurboBios = "", "sufamiTurboBios"); attach(superGameBoyBios = "", "superGameBoyBios"); - attach(necdsp = "", "necdsp"); + attach(firmware = "", "firmware"); attach(msu1 = "", "msu1"); attach(serial = "", "serial"); diff --git a/bsnes/ui/path/path.hpp b/bsnes/ui/path/path.hpp index d251868c..85940d54 100755 --- a/bsnes/ui/path/path.hpp +++ b/bsnes/ui/path/path.hpp @@ -11,7 +11,7 @@ struct Path : public configuration { string sufamiTurboBios; string superGameBoyBios; - string necdsp; + string firmware; string msu1; string serial; diff --git a/bsnes/ui/tools/cheat-database.cpp b/bsnes/ui/tools/cheat-database.cpp index cc3722d6..a09ddbd9 100755 --- a/bsnes/ui/tools/cheat-database.cpp +++ b/bsnes/ui/tools/cheat-database.cpp @@ -53,7 +53,7 @@ void CheatDatabase::findCodes() { string description, code; foreach(element, node.element) { if(element.name == "description") description = element.parse(); - else if(element.name == "code") code.append(string(element.parse(), "+")); + else if(element.name == "code") code.append(element.parse(), "+"); } code.rtrim<1>("+"); code.append("\t"); diff --git a/bsnes/ui/tools/cheat-editor.cpp b/bsnes/ui/tools/cheat-editor.cpp index ee8edc07..eb76f5d7 100755 --- a/bsnes/ui/tools/cheat-editor.cpp +++ b/bsnes/ui/tools/cheat-editor.cpp @@ -26,7 +26,7 @@ void CheatEditor::load() { } foreach(element, node.element) { if(element.name == "description") description = element.parse(); - else if(element.name == "code") code.append(string(element.parse(), "+")); + else if(element.name == "code") code.append(element.parse(), "+"); } code.rtrim("+"); SNES::cheat[n].enabled = enabled; @@ -59,16 +59,16 @@ void CheatEditor::save() { file fp; if(fp.open(path.load(utility.slotPath(), ".cht"), file::mode::write)) { fp.print("\n"); - fp.print(string("\n")); + fp.print("\n"); for(unsigned i = 0; i <= lastSave; i++) { - fp.print(string(" \n")); - fp.print(string(" \n")); + fp.print(" \n"); + fp.print(" \n"); lstring list; list.split("+", cheatText[i][CheatCode]); foreach(code, list) { - fp.print(string(" ", code, "\n")); + fp.print(" ", code, "\n"); } - fp.print(string(" \n")); + fp.print(" \n"); } fp.print("\n"); fp.close();