summaryrefslogtreecommitdiff
path: root/asmmon.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2019-12-01 17:40:41 -0500
committermrb0nk500 <b0nk@b0nk.xyz>2019-12-02 18:10:41 -0500
commitcbad8aabbc82efbe7a49572a2da74224ae9c9f85 (patch)
treee97b1ab35208bc3e4d633f235d875fd4c69d039f /asmmon.c
parentca89989d057a19b647514656d96d00ff23be9640 (diff)
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.
Diffstat (limited to 'asmmon.c')
-rw-r--r--asmmon.c89
1 files changed, 70 insertions, 19 deletions
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;
}