summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-04-30 02:08:33 +0300
committerOxore <oxore@protonmail.com>2023-04-30 02:08:33 +0300
commit49958226104c17792ff61d664a4fc06e595ee5a5 (patch)
treed84d88333b2e915e11aa9d28393611aed3a8bbae
parent97118ecb195356650a4def44ba36d026634f3f95 (diff)
Impl STOP just for the sake of implementing it
-rw-r--r--disasm.cpp33
-rw-r--r--test.bash5
2 files changed, 26 insertions, 12 deletions
diff --git a/disasm.cpp b/disasm.cpp
index d0424eb..5fe5632 100644
--- a/disasm.cpp
+++ b/disasm.cpp
@@ -420,38 +420,47 @@ static void chunk_mf000_v3000(DisasmNode& n, uint16_t i, const DataBuffer &c, co
return disasm_verbatim(n, i, c, s);
}
-static void chunk_mf000_v4000(DisasmNode& node, uint16_t i, const DataBuffer &c, const Settings &s)
+static void chunk_mf000_v4000(
+ DisasmNode& node, uint16_t instr, const DataBuffer &code, const Settings &s)
{
- if (i == 0x4e70) {
+ if (instr == 0x4e70) {
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "reset");
return;
- } else if (i == 0x4e71) {
+ } else if (instr == 0x4e71) {
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "nop");
return;
- } else if (i == 0x4e73) {
+ } else if (instr == 0x4e72) {
+ if (node.offset + kInstructionSizeStepBytes < code.occupied_size) {
+ node.size = kInstructionSizeStepBytes * 2;
+ snprintf(node.mnemonic, kMnemonicBufferSize, "stop");
+ const uint16_t sr_imm = GetU16BE(code.buffer + node.offset + kInstructionSizeStepBytes);
+ snprintf(node.arguments, kArgsBufferSize, "#0x%x:w", sr_imm);
+ return;
+ }
+ } else if (instr == 0x4e73) {
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "rte");
return;
- } else if (i == 0x4e75) {
+ } else if (instr == 0x4e75) {
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "rts");
return;
- } else if (i == 0x4e76) {
+ } else if (instr == 0x4e76) {
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "trapv");
return;
- } else if (i == 0x4e77) {
+ } else if (instr == 0x4e77) {
node.size = kInstructionSizeStepBytes;
snprintf(node.mnemonic, kMnemonicBufferSize, "rtr");
return;
- } else if ((i & 0xffc0) == 0x4e80) {
- return disasm_jsr(node, i, c, s);
- } else if ((i & 0xffc0) == 0x4ec0) {
- return disasm_jmp(node, i, c, s);
+ } else if ((instr & 0xffc0) == 0x4e80) {
+ return disasm_jsr(node, instr, code, s);
+ } else if ((instr & 0xffc0) == 0x4ec0) {
+ return disasm_jmp(node, instr, code, s);
}
- return disasm_verbatim(node, i, c, s);
+ return disasm_verbatim(node, instr, code, s);
}
enum class OpSize {
diff --git a/test.bash b/test.bash
index a065465..0a429c6 100644
--- a/test.bash
+++ b/test.bash
@@ -205,6 +205,11 @@ run_test_simple "reset" "\x4e\x70"
# nop
run_test_simple "nop" "\x4e\x71"
+# 4e72 xxxx
+#
+run_test_simple "stop #8:w" "\x4e\x72\x00\x08"
+run_test_simple "stop #ffff:w" "\x4e\x72\xff\xff"
+
# 4e73
#
# rte