// Micheal H. McCabe // October 7, 2022 // Hexadecimal Dump of card / tape files // Part of the Retrochallenge 2022/10 #include #include #include using namespace std; #define IFNAME "BinaryDump.cpp" string Hex="0123456789ABCDEF"; string PrintHex4(int V); string PrintHex2(int V); int main() { streampos size; char * memblock; ifstream infile(IFNAME, ios::in|ios::binary|ios::ate); if (infile.is_open()) { size = infile.tellg(); if (size>65535) { cout << "Filesize too large for this program. 64k Maximum exceeded." << endl; } memblock = new char [size]; infile.seekg(0, ios::beg); infile.read(memblock, size); infile.close(); for (int address=0; address<=size; address=address+16) { cout << PrintHex4(address) << ": "; for (int addr2=0; addr2<16; addr2++) { int byte; int vector=address+addr2; if (vector<=size) { byte=int(memblock[vector]); } else { byte = 0; } cout << PrintHex2(byte) << " "; } cout << endl; } } return 0; } string PrintHex4(int v) { int page=v/256; int byte=v-(page*256); string addr = PrintHex2(page)+PrintHex2(byte); return addr; } string PrintHex2(int v) { string Hex="0123456789ABCDEF"; int h=v/16; int l=v-(h*16); string data = Hex.substr(h,1)+Hex.substr(l,1); return data; }