From 9362980e82190a9c56e2503d135e2ebee657d14c Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 3 Jan 2017 22:13:32 -0500 Subject: [PATCH] fix instruction mode bugs --- disassembler.cpp | 12 +++++++----- dumpobj.cpp | 6 +++--- samples/instructions.asm | 8 +++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/disassembler.cpp b/disassembler.cpp index 078ef46..dc0c8d0 100644 --- a/disassembler.cpp +++ b/disassembler.cpp @@ -134,7 +134,7 @@ static constexpr const int modes[] = 2 | mBlockMove, // 44 mvp x,x 1 | mDP, // 45 eor dp 1 | mDP, // 46 lsr dp - 1 | mDPIL | m_Y, // 47 eor [dp],y + 1 | mDPIL, // 47 eor [dp] 0 | mImplied, // 48 pha 1 | mImmediate | m_M, // 49 eor #imm 0 | mImplied, // 4a lsr a @@ -326,7 +326,7 @@ static constexpr const int modes[] = 2 | mAbsolute | m_Y, // f9 sbc |abs,y 0 | mImplied, // fa plx 0 | mImplied, // fb xce - 2 | mAbsoluteI, // fc jsr (abs) + 2 | mAbsoluteI | m_X, // fc jsr (abs,x) 2 | mAbsolute | m_X, // fd sbc |abs,x 2 | mAbsolute | m_X, // fe inc |abs,x 3 | mAbsoluteLong | m_X, // ff sbc >abs,x @@ -339,9 +339,9 @@ static std::string to_x(uint32_t x, unsigned bytes, char prefix = 0) { char buffer[16]; if (prefix) s.push_back(prefix); - if (x >= 0xff && bytes < 4) bytes = 4; - if (x >= 0xffff && bytes < 6) bytes = 6; - if (x >= 0xffffff && bytes < 8) bytes = 8; + if (x > 0xff && bytes < 4) bytes = 4; + if (x > 0xffff && bytes < 6) bytes = 6; + if (x > 0xffffff && bytes < 8) bytes = 8; memset(buffer, '0', sizeof(buffer)); int i = 16; @@ -509,6 +509,7 @@ void disassembler::print_prefix() { case mDP: printf("\t<"); break; case mDPI: printf("\t(<"); break; case mDPIL: printf("\t[<"); break; + case mAbsoluteIL: printf("\t["); break; case mRelative: case mBlockMove: @@ -534,6 +535,7 @@ std::string disassembler::prefix() { case mDP: tmp = "<"; break; case mDPI: tmp = "(<"; break; case mDPIL: tmp = "[<"; break; + case mAbsoluteIL: tmp = "["; break; case mRelative: case mBlockMove: diff --git a/dumpobj.cpp b/dumpobj.cpp index 3159b2a..7f01919 100644 --- a/dumpobj.cpp +++ b/dumpobj.cpp @@ -302,9 +302,9 @@ static std::string to_x(uint32_t x, unsigned bytes, char prefix = 0) { char buffer[16]; if (prefix) s.push_back(prefix); - if (x >= 0xff && bytes < 4) bytes = 4; - if (x >= 0xffff && bytes < 6) bytes = 6; - if (x >= 0xffffff && bytes < 8) bytes = 8; + if (x > 0xff && bytes < 4) bytes = 4; + if (x > 0xffff && bytes < 6) bytes = 6; + if (x > 0xffffff && bytes < 8) bytes = 8; memset(buffer, '0', sizeof(buffer)); int i = 16; diff --git a/samples/instructions.asm b/samples/instructions.asm index b5658d9..1eb9d8e 100644 --- a/samples/instructions.asm +++ b/samples/instructions.asm @@ -204,7 +204,7 @@ ; cpy #$1234 cmp (<$12,x) - rep #$1234 + rep #$00 cmp <$12,s cpy <$12 cmp <$12 @@ -231,14 +231,16 @@ cmp |$1234,y phx stp - jml [|$1234] + jml ($1234) ; was jml [$1234] + ;jmp [$1234] ; ok! + ;jml [$1234] ; error! cmp |$1234,x dec |$1234,x cmp >$123456,x ; cpx #$1234 sbc (<$12,x) - sep #$1234 + sep #$00 sbc <$12,s cpx <$12 sbc <$12