Advertisement
Bisqwit

River City Ransom item name extractor

Sep 30th, 2016
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <cstdio>
  2. #include <vector>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.     std::vector<unsigned char> ROM;
  9.     std::ifstream f(argv[1], std::ios::binary);
  10.     for(; f.good(); ) ROM.push_back(f.get());
  11.     ROM.erase(ROM.begin(),ROM.begin()+16);
  12.  
  13.     std::vector<std::string> names(128);
  14.     for(unsigned n=0; n<128; ++n)
  15.     {
  16.         auto addr = [base = 0x8000](unsigned n) { return base + (n&0x3FFF); };
  17.         unsigned pointer = ROM[addr(0xA4F9+n*2)]+ROM[addr(0xA4FA+n*2)]*256;
  18.         for(std::string& name = names[n]; ROM[addr(pointer)] != 5; )
  19.             switch(unsigned char c = ROM[addr(pointer++)])
  20.             {
  21.                 case 0xC0 ... 0xD9: name += char(c+'A'-0xC0); break;
  22.                 case 0xDA ... 0xF3: name += char(c+'a'-0xDA); break;
  23.                 case 0xF4 ... 0xFD: name += char(c+'0'-0xF4); break;
  24.                 case 0xB0 ... 0xBD: name += u8R"(*"!?-%.:;&,>#…)"[c-0xB0]; break;
  25.                 case 0xFE: name += '$'; break;
  26.                 default: name += ' ';
  27.             }
  28.     }
  29.     for(unsigned n=0; n<16; ++n, std::putchar('\n'))
  30.         for(unsigned c=0; c<8; ++c)
  31.             std::printf("%02X:%-12s", n+c*16, names[n + c*16].c_str());
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement