From cbad8aabbc82efbe7a49572a2da74224ae9c9f85 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sun, 1 Dec 2019 17:40:41 -0500 Subject: Added the ability to disable the prefix byte. Any instructions that either have a register size of 8 bits, use implied addressing, or branch can save a byte by disabling the prefix byte. It does this by checking if the first three bits are all set to 1. If true, then it will treat it as a prefix byte, otherwise, it will treat it as an opcode. --- asmmon.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 19 deletions(-) (limited to 'asmmon.c') diff --git a/asmmon.c b/asmmon.c index fd7c636..1a41214 100644 --- a/asmmon.c +++ b/asmmon.c @@ -103,7 +103,7 @@ int asmmon() { char *cmd; char *tmp = malloc(sizeof(char *)*128); size_t size; - done &= ~6; + done &= ~14; getline(&buf, &size, stdin); cmd = strtok_r(buf, "\n", &tmp); if (cmd != NULL) { @@ -213,28 +213,79 @@ int asmmon() { } } } - if (postfix != NULL && !(done & 6)) { - if (strcasecmp(postfix, "w") == 0) { - addr[address++] = 1; - } else if (strcasecmp(postfix, "d") == 0) { - addr[address++] = 2; - } else if (strcasecmp(postfix, "q") == 0) { - addr[address++] = 3; - } else { - addr[address++] = 0; - } - } else if (postfix == NULL && !(done & 6)) { - addr[address++] = 0; - } if (ins != NULL && !(done & 6)) { uint8_t i; for (i = 0; i < 77; i++) { if (strcasecmp(opcodes[i].mnemonic, ins) == 0) { + if (addrmode == 0 && (opcodes[i].impl || opcodes[i].impl == CPS)) { + done |= 8; + } else if (addrmode == 1) { + switch (opcodes[i].imm) { + case PHP: + case PHA: + case PHY: + case PHX: + case PLP: + case PLA: + case PLY: + case PLX: + case STT: + case LSL: + case LSR: + case ROL: + case ROR: + case ENT: + done |= 8; + break; + } + } else { + if (strcasecmp(ins, "JMP") == 0) + done |=8; + if (strcasecmp(ins, "JSR") == 0) + done |=8; + if (strcasecmp(ins, "JSL") == 0) + done |=8; + if (strcasecmp(ins, "INC") == 0) + done |=8; + if (strcasecmp(ins, "BPO") == 0) + done |=8; + if (strcasecmp(ins, "BNG") == 0) + done |=8; + if (strcasecmp(ins, "BCS") == 0) + done |=8; + if (strcasecmp(ins, "BCC") == 0) + done |=8; + if (strcasecmp(ins, "BEQ") == 0) + done |=8; + if (strcasecmp(ins, "BNE") == 0) + done |=8; + if (strcasecmp(ins, "BVS") == 0) + done |=8; + if (strcasecmp(ins, "BVC") == 0) + done |=8; + } op = opcodes[i]; break; } } - uint8_t r = addr[address-1] & 3; + if (postfix != NULL && !(done & 8)) { + if (strcasecmp(postfix, "w") == 0) { + addr[address++] = 0x17; + } else if (strcasecmp(postfix, "d") == 0) { + addr[address++] = 0x27; + } else if (strcasecmp(postfix, "q") == 0) { + addr[address++] = 0x37; + } else { + done |=8; + } + } else if (postfix == NULL && !(done & 8)) { + done |=8; + } + uint8_t r; + if (!(done & 8)) + r = addr[address-1]; + else + r = 0; switch (addrmode) { case 0: if (op.impl || op.impl == CPS) { @@ -266,18 +317,18 @@ int asmmon() { break; default: addr[address] = value & 0xFF; - if (r & 1) + if (r & 0x10) addr[address+1] = value >> 8; - if (r & 2) + if (r & 0x20) addr[address+2] = value >> 16; addr[address+3] = value >> 24; - if (r & 3) + if (r & 0x30) addr[address+4] = value >> 32; addr[address+5] = value >> 40; addr[address+6] = value >> 48; addr[address+7] = value >> 56; - address+=(1 << (r & 3)); + address+=(1 << ((r & 0x30) >> 4)); break; } -- cgit v1.2.3-13-gbd6f