// Micheal H. McCabe // October 8, 2022 // Hexadecimal Dump of card / tape files // Part of the Retrochallenge 2022/10 #include #include #include using namespace std; string Hex="0123456789ABCDEF"; string PrintHex4(int V); string PrintHex2(int V); int main(int argc,char *argv[]) { if (argc > 0) { cout << "HexDump Version 2" << endl; cout << "\nFilename: " << argv[1] << endl << endl; streampos size; char * memblock; ifstream infile(argv[1], 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; return 0; } 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) << ": "; string TextLine = " /* "; for (int addr2=0; addr2<16; addr2++) { int byte; int vector=address+addr2; if (vector<=size) { byte=int(memblock[vector]); if ((byte>32) && (byte<127)) { TextLine=TextLine+memblock[vector]; } else TextLine=TextLine+"."; } else { byte = 0; TextLine=TextLine+"."; } cout << PrintHex2(byte) << " "; } cout << TextLine << " */" << 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; }