diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-10-12 21:20:31 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-10-12 21:34:40 -0700 |
commit | a7b2a5de68f7fac44bd4d9771616540c54dcdc9d (patch) | |
tree | fd52e682ae19446a962ba8b8adf79726f61e823b /subx | |
parent | 1091118ae55e6492fb5dea455bae408bebe83fec (diff) | |
download | mu-a7b2a5de68f7fac44bd4d9771616540c54dcdc9d.tar.gz |
4038
Diffstat (limited to 'subx')
-rw-r--r-- | subx/010core.cc | 12 | ||||
-rw-r--r-- | subx/011add.cc | 6 |
2 files changed, 10 insertions, 8 deletions
diff --git a/subx/010core.cc b/subx/010core.cc index eba8e00d..2816f559 100644 --- a/subx/010core.cc +++ b/subx/010core.cc @@ -114,7 +114,7 @@ void run_one_instruction() { switch(op2 = next()) { // End Two-Byte Opcodes Starting With 0f default: - cerr << "unrecognized second opcode after 0f: " << std::hex << static_cast<int>(op2) << '\n'; + cerr << "unrecognized second opcode after 0f: " << HEXBYTE << NUM(op2) << '\n'; exit(1); } break; @@ -125,17 +125,17 @@ void run_one_instruction() { switch(op3 = next()) { // End Three-Byte Opcodes Starting With f3 0f default: - cerr << "unrecognized third opcode after f3 0f: " << std::hex << static_cast<int>(op3) << '\n'; + cerr << "unrecognized third opcode after f3 0f: " << HEXBYTE << NUM(op3) << '\n'; exit(1); } break; default: - cerr << "unrecognized second opcode after f3: " << std::hex << static_cast<int>(op2) << '\n'; + cerr << "unrecognized second opcode after f3: " << HEXBYTE << NUM(op2) << '\n'; exit(1); } break; default: - cerr << "unrecognized opcode: " << std::hex << static_cast<int>(op) << '\n'; + cerr << "unrecognized opcode: " << HEXBYTE << NUM(op) << '\n'; exit(1); } } @@ -157,7 +157,7 @@ void load_program(const string& text_bytes) { return; } Mem.at(addr) = to_byte(c1, c2); - trace(99, "load") << addr << " -> " << HEXBYTE << static_cast<int>(Mem.at(addr)) << end(); // ugly that iostream doesn't print uint8_t as an integer + trace(99, "load") << addr << " -> " << HEXBYTE << NUM(Mem.at(addr)) << end(); addr++; } End_of_program = addr; @@ -216,4 +216,6 @@ int32_t imm32() { #include <iomanip> #define HEXBYTE std::hex << std::setw(2) << std::setfill('0') #define HEXWORD std::hex << std::setw(8) << std::setfill('0') +// ugly that iostream doesn't print uint8_t as an integer +#define NUM(X) static_cast<int>(X) #include <stdint.h> diff --git a/subx/011add.cc b/subx/011add.cc index 5ba1e080..355e2f69 100644 --- a/subx/011add.cc +++ b/subx/011add.cc @@ -13,7 +13,7 @@ case 0x01: { // add r32 to r/m32 uint8_t modrm = next(); uint8_t arg2 = (modrm>>3)&0x7; - trace(2, "run") << "add reg " << static_cast<int>(arg2) << " to effective address" << end(); + trace(2, "run") << "add reg " << NUM(arg2) << " to effective address" << end(); int32_t* arg1 = effective_address(modrm); BINARY_ARITHMETIC_OP(+, *arg1, Reg[arg2].i); break; @@ -33,7 +33,7 @@ int32_t* effective_address(uint8_t modrm) { // mod 0 is usually indirect addressing switch (rm) { default: - trace(99, "run") << "effective address is mem at address 0x" << std::hex << Reg[rm].u << " (reg " << static_cast<int>(rm) << ")" << end(); + trace(99, "run") << "effective address is mem at address 0x" << std::hex << Reg[rm].u << " (reg " << NUM(rm) << ")" << end(); assert(Reg[rm].u + sizeof(int32_t) <= Mem.size()); result = reinterpret_cast<int32_t*>(&Mem.at(Reg[rm].u)); // rely on the host itself being in little-endian order break; @@ -42,7 +42,7 @@ int32_t* effective_address(uint8_t modrm) { break; // End Mod Special-Cases default: - cerr << "unrecognized mod bits: " << static_cast<int>(mod) << '\n'; + cerr << "unrecognized mod bits: " << NUM(mod) << '\n'; exit(1); } return result; |