| 1 | #cxx . . $ `<file>/src/Dasm.cpp`/include "Dasm.h"cxx . . $ `<file>/src/Dasm.h`/ |
| 2 | #include "DasmTables.h"cxx . . $ `<file>/src/DasmTables.h`/ |
| 3 | #include "SymbolTable.h"cxx . . $ `<file>/src/SymbolTable.h`/ |
| 4 | #include <sstream> |
| 5 | #include <iomanip> |
| 6 | |
| 7 | static char signcxx . . $ sign(7dc1da5dee1d64fd).(unsigned char a) |
| 8 | { |
| 9 | return (a & 128) ? '-' : '+'; |
| 10 | } |
| 11 | |
| 12 | static int abscxx . . $ abs(b27dbea426b7b93).(unsigned char a) |
| 13 | { |
| 14 | return (a & 128) ? (256 - a) : a; |
| 15 | } |
| 16 | |
| 17 | static stdcxx . . $ std/::stringcxx . . $ std/string# toHexcxx . . $ toHex(150847338b305901).(unsigned value, unsigned width) |
| 18 | { |
| 19 | stdcxx . . $ std/::ostringstreamcxx . . $ std/ostringstream# scxx . . $ std/__cxx11/basic_ostringstream#basic_ostringstream(49f6e7a06ebc5aa8).; |
| 20 | s <<cxx . . $ std/basic_ostream#`operator<<`(d90e0e305b0e25c2). stdcxx . . $ std/::hexcxx . . $ std/hex(cf36cc481190cd1f). <<cxx . . $ std/`operator<<`(fe9a269018418773). stdcxx . . $ std/::setwcxx . . $ std/setw(f06ce2e9220601fb).(width) <<cxx . . $ std/`operator<<`(47f1cf32aeb3f1a2). stdcxx . . $ std/::setfillcxx . . $ std/setfill(ade351e831a1374a).('0') <<cxx . . $ std/basic_ostream#`operator<<`(b4c055c363850233). value; |
| 21 | return s.strcxx . . $ std/__cxx11/basic_ostringstream#str(d33e1a6fd36255f7).(); |
| 22 | } |
| 23 | |
| 24 | static stdcxx . . $ std/::stringcxx . . $ std/string# translateAddresscxx . . $ translateAddress(3dc6880d72e6f742).( |
| 25 | int address, MemoryLayoutcxx . . $ MemoryLayout#* memLayout, SymbolTablecxx . . $ SymbolTable#* symTable) |
| 26 | { |
| 27 | if (Symbolcxx . . $ Symbol#* label = symTable->getAddressSymbolcxx . . $ SymbolTable#getAddressSymbol(6425489d2f72da67).(address, memLayout)) { |
| 28 | return label->textcxx . . $ Symbol#text(a2fb7a6ce195d51).().toStdStringcxx . . $ QString#toStdString(219584694fe2b248).(); |
| 29 | } else { |
| 30 | return '#' +cxx . . $ std/operator+(b9488864fd6ef941). toHexcxx . . $ toHex(150847338b305901).(address, 4); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | static int get16cxx . . $ get16(87fdc3b2e2b212a8).(const unsigned char* memBuf, int address) |
| 35 | { |
| 36 | return memBuf[address] + 256 * memBuf[address + 1]; |
| 37 | } |
| 38 | |
| 39 | void dasmcxx . . $ dasm(8eaa81ad2a87061c).(const unsigned char* membuf, uint16_tcxx . . $ uint16_t# startAddr, uint16_tcxx . . $ uint16_t# endAddr, |
| 40 | DisasmLinescxx . . $ DisasmLines#& disasm, MemoryLayoutcxx . . $ MemoryLayout#* memLayout, SymbolTablecxx . . $ SymbolTable#* symTable, int currentPC) |
| 41 | { |
| 42 | int pc = startAddr; |
| 43 | int labelCount = 0; |
| 44 | Symbolcxx . . $ Symbol#* symbol = symTable->findFirstAddressSymbolcxx . . $ SymbolTable#findFirstAddressSymbol(6425489d2f72da67).(pc, memLayout); |
| 45 | |
| 46 | disasm.clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 47 | while (pc <= int(endAddr)) { |
| 48 | // check for a label |
| 49 | while (symbol && symbol->valuecxx . . $ Symbol#value(455f465bc33b4cdf).() == pc) { |
| 50 | ++labelCount; |
| 51 | DisasmRowcxx . . $ DisasmRow# destsym; |
| 52 | destsym.rowTypecxx . . $ DisasmRow#rowType. = DisasmRowcxx . . $ DisasmRow#::LABELcxx . . $ DisasmRow#LABEL.; |
| 53 | destsym.numBytescxx . . $ DisasmRow#numBytes. = 0; |
| 54 | destsym.infoLinecxx . . $ DisasmRow#infoLine. = labelCount; |
| 55 | destsym.addrcxx . . $ DisasmRow#addr. = pc; |
| 56 | destsym.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). symbol->textcxx . . $ Symbol#text(a2fb7a6ce195d51).().toStdStringcxx . . $ QString#toStdString(219584694fe2b248).(); |
| 57 | disasm.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(destsym); |
| 58 | symbol = symTable->findNextAddressSymbolcxx . . $ SymbolTable#findNextAddressSymbol(fd05edddcc119593).(memLayout); |
| 59 | } |
| 60 | |
| 61 | labelCount = 0; |
| 62 | DisasmRowcxx . . $ DisasmRow# dest; |
| 63 | dest.rowTypecxx . . $ DisasmRow#rowType. = DisasmRowcxx . . $ DisasmRow#::INSTRUCTIONcxx . . $ DisasmRow#INSTRUCTION.; |
| 64 | dest.addrcxx . . $ DisasmRow#addr. = pc; |
| 65 | dest.numBytescxx . . $ DisasmRow#numBytes. = 0; |
| 66 | dest.infoLinecxx . . $ DisasmRow#infoLine. = 0; |
| 67 | dest.instrcxx . . $ DisasmRow#instr..clearcxx . . $ std/__cxx11/basic_string#clear(ced63f7c635d850d).(); |
| 68 | |
| 69 | const char* s; |
| 70 | const char* r = nullptr; |
| 71 | switch (membuf[pc]) { |
| 72 | case 0xCB: |
| 73 | s = mnemonic_cbcxx . . $ mnemonic_cb.[membuf[pc + 1]]; |
| 74 | dest.numBytescxx . . $ DisasmRow#numBytes. = 2; |
| 75 | break; |
| 76 | case 0xED: |
| 77 | s = mnemonic_edcxx . . $ mnemonic_ed.[membuf[pc + 1]]; |
| 78 | dest.numBytescxx . . $ DisasmRow#numBytes. = 2; |
| 79 | break; |
| 80 | case 0xDD: |
| 81 | case 0xFD: |
| 82 | r = (membuf[pc] == 0xDD) ? "ix" : "iy"; |
| 83 | if (membuf[pc + 1] != 0xcb) { |
| 84 | s = mnemonic_xxcxx . . $ mnemonic_xx.[membuf[pc + 1]]; |
| 85 | dest.numBytescxx . . $ DisasmRow#numBytes. = 2; |
| 86 | } else { |
| 87 | s = mnemonic_xx_cbcxx . . $ mnemonic_xx_cb.[membuf[pc + 3]]; |
| 88 | dest.numBytescxx . . $ DisasmRow#numBytes. = 4; |
| 89 | } |
| 90 | break; |
| 91 | default: |
| 92 | s = mnemonic_maincxx . . $ mnemonic_main.[membuf[pc]]; |
| 93 | dest.numBytescxx . . $ DisasmRow#numBytes. = 1; |
| 94 | } |
| 95 | |
| 96 | for (int j = 0; s[j]; ++j) { |
| 97 | switch (s[j]) { |
| 98 | case 'A': { |
| 99 | int address = get16cxx . . $ get16(87fdc3b2e2b212a8).(membuf, pc + dest.numBytescxx . . $ DisasmRow#numBytes.); |
| 100 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). translateAddresscxx . . $ translateAddress(3dc6880d72e6f742).(address, memLayout, symTable); |
| 101 | dest.numBytescxx . . $ DisasmRow#numBytes. += 2; |
| 102 | break; |
| 103 | } |
| 104 | case 'B': |
| 105 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). '#' +cxx . . $ std/operator+(b9488864fd6ef941). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + dest.numBytescxx . . $ DisasmRow#numBytes.], 2); |
| 106 | dest.numBytescxx . . $ DisasmRow#numBytes. += 1; |
| 107 | break; |
| 108 | case 'R': { |
| 109 | int address = (pc + 2 + (signed char)membuf[pc + dest.numBytescxx . . $ DisasmRow#numBytes.]) & 0xFFFF; |
| 110 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). translateAddresscxx . . $ translateAddress(3dc6880d72e6f742).(address, memLayout, symTable); |
| 111 | dest.numBytescxx . . $ DisasmRow#numBytes. += 1; |
| 112 | break; |
| 113 | } |
| 114 | case 'W': |
| 115 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). '#' +cxx . . $ std/operator+(b9488864fd6ef941). toHexcxx . . $ toHex(150847338b305901).(get16cxx . . $ get16(87fdc3b2e2b212a8).(membuf, pc + dest.numBytescxx . . $ DisasmRow#numBytes.), 4); |
| 116 | dest.numBytescxx . . $ DisasmRow#numBytes. += 2; |
| 117 | break; |
| 118 | case 'X': { |
| 119 | unsigned char offset = membuf[pc + dest.numBytescxx . . $ DisasmRow#numBytes.]; |
| 120 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). '(' +cxx . . $ std/operator+(b9488864fd6ef941). stdcxx . . $ std/::stringcxx . . $ std/string#(r) +cxx . . $ std/operator+(cd4e1e16c2d05e54). signcxx . . $ sign(7dc1da5dee1d64fd).(offset) |
| 121 | +cxx . . $ std/operator+(cd4e1e16c2d05e54). '#' +cxx . . $ std/operator+(aa1c00e85b87da6b). toHexcxx . . $ toHex(150847338b305901).(abscxx . . $ abs(b27dbea426b7b93).(offset), 2) +cxx . . $ std/operator+(cd4e1e16c2d05e54). ')'; |
| 122 | dest.numBytescxx . . $ DisasmRow#numBytes. += 1; |
| 123 | break; |
| 124 | } |
| 125 | case 'Y': { |
| 126 | unsigned char offset = membuf[pc + 2]; |
| 127 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). '(' +cxx . . $ std/operator+(b9488864fd6ef941). stdcxx . . $ std/::stringcxx . . $ std/string#(r) +cxx . . $ std/operator+(cd4e1e16c2d05e54). signcxx . . $ sign(7dc1da5dee1d64fd).(offset) |
| 128 | +cxx . . $ std/operator+(cd4e1e16c2d05e54). '#' +cxx . . $ std/operator+(aa1c00e85b87da6b). toHexcxx . . $ toHex(150847338b305901).(abscxx . . $ abs(b27dbea426b7b93).(offset), 2) +cxx . . $ std/operator+(cd4e1e16c2d05e54). ')'; |
| 129 | break; |
| 130 | } |
| 131 | case 'I': |
| 132 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). r; |
| 133 | break; |
| 134 | case '!': |
| 135 | dest.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "db #ED,#" +cxx . . $ std/operator+(39ed2c165380f78e). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 1], 2); |
| 136 | dest.numBytescxx . . $ DisasmRow#numBytes. = 2; |
| 137 | break; |
| 138 | case '@': |
| 139 | dest.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "db #" +cxx . . $ std/operator+(39ed2c165380f78e). toHexcxx . . $ toHex(150847338b305901).(membuf[pc], 2); |
| 140 | dest.numBytescxx . . $ DisasmRow#numBytes. = 1; |
| 141 | break; |
| 142 | case '#': |
| 143 | dest.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "db #" +cxx . . $ std/operator+(39ed2c165380f78e). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 0], 2) +cxx . . $ std/operator+(900ec9581c410ad9). |
| 144 | "#CB,#" +cxx . . $ std/operator+(aa1c00e85b87da6b). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 2], 2); |
| 145 | dest.numBytescxx . . $ DisasmRow#numBytes. = 2; |
| 146 | break; |
| 147 | case ' ': { |
| 148 | dest.instrcxx . . $ DisasmRow#instr..resizecxx . . $ std/__cxx11/basic_string#resize(cc73ddaffac1a975).(7, ' '); |
| 149 | break; |
| 150 | } |
| 151 | default: |
| 152 | dest.instrcxx . . $ DisasmRow#instr. +=cxx . . $ std/__cxx11/basic_string#`operator+=`(63cc1ae870623930). s[j]; |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // handle overflow at end or label |
| 158 | int dataBytes = 0; |
| 159 | if (symbol && pc + dest.numBytescxx . . $ DisasmRow#numBytes. > symbol->valuecxx . . $ Symbol#value(455f465bc33b4cdf).()) { |
| 160 | dataBytes = symbol->valuecxx . . $ Symbol#value(455f465bc33b4cdf).() - pc; |
| 161 | } else if (pc + dest.numBytescxx . . $ DisasmRow#numBytes. > endAddr) { |
| 162 | dataBytes = endAddr - pc; |
| 163 | } else if (pc + dest.numBytescxx . . $ DisasmRow#numBytes. > currentPC) { |
| 164 | dataBytes = currentPC - pc; |
| 165 | } |
| 166 | |
| 167 | switch (dataBytes) { |
| 168 | case 1: |
| 169 | dest.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "db #" +cxx . . $ std/operator+(39ed2c165380f78e). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 0], 2); |
| 170 | dest.numBytescxx . . $ DisasmRow#numBytes. = 1; |
| 171 | break; |
| 172 | case 2: |
| 173 | dest.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "db #" +cxx . . $ std/operator+(39ed2c165380f78e). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 0], 2) +cxx . . $ std/operator+(900ec9581c410ad9). |
| 174 | ",#" +cxx . . $ std/operator+(aa1c00e85b87da6b). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 1], 2); |
| 175 | dest.numBytescxx . . $ DisasmRow#numBytes. = 2; |
| 176 | break; |
| 177 | case 3: |
| 178 | dest.instrcxx . . $ DisasmRow#instr. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "db #" +cxx . . $ std/operator+(39ed2c165380f78e). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 0], 2) +cxx . . $ std/operator+(900ec9581c410ad9). |
| 179 | ",#" +cxx . . $ std/operator+(aa1c00e85b87da6b). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 1], 2) +cxx . . $ std/operator+(900ec9581c410ad9). |
| 180 | ",#" +cxx . . $ std/operator+(aa1c00e85b87da6b). toHexcxx . . $ toHex(150847338b305901).(membuf[pc + 2], 2); |
| 181 | dest.numBytescxx . . $ DisasmRow#numBytes. = 3; |
| 182 | break; |
| 183 | default: |
| 184 | break; |
| 185 | } |
| 186 | |
| 187 | if (dest.instrcxx . . $ DisasmRow#instr..sizecxx . . $ std/__cxx11/basic_string#size(6f8bd5c0ea8fb29a).() < 8) dest.instrcxx . . $ DisasmRow#instr..resizecxx . . $ std/__cxx11/basic_string#resize(cc73ddaffac1a975).(8, ' '); |
| 188 | disasm.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(dest); |
| 189 | pc += dest.numBytescxx . . $ DisasmRow#numBytes.; |
| 190 | } |
| 191 | } |