summaryrefslogtreecommitdiff
path: root/asmmon.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-04-02 19:04:12 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-04-02 19:04:12 -0400
commit59dc46ca8fe1eb6f98abb98fe8579aeaedd2ff15 (patch)
tree4a762bad3013693c8640a36fa626042cfaa13d83 /asmmon.c
parent6bad8fa605f5011cadab428156c18b4067922185 (diff)
Made the emulator less bloated, and faster.
Diffstat (limited to 'asmmon.c')
-rw-r--r--asmmon.c151
1 files changed, 126 insertions, 25 deletions
diff --git a/asmmon.c b/asmmon.c
index 8b896cf..3f715ac 100644
--- a/asmmon.c
+++ b/asmmon.c
@@ -88,22 +88,22 @@ void reslv_fixups(void) {
addr[f->adr+7] = f->l->adr >> 56;
}
} else {
- printf("oof, undefined reference to '%s', at $%016llx.\n", f->l->name, f->adr);
+ printf("oof, undefined reference to '%s', at $%016llX.\n", f->l->name, f->adr);
}
}
}
void viewmem(uint64_t address) {
printf("\t\t\t");
for (int ind = 0; ind < 0x10; ind++) {
- printf("%02x", ind);
+ printf("%02X", ind);
if (ind < 0x0F)
printf(" ");
}
printf("\n\n");
for (int hi = 0; hi < 0x10; hi++) {
- printf("%016llx:\t", (address & ~0xF)+(hi*0x10));
+ printf("%016llX:\t", (address & ~0xF)+(hi*0x10));
for (int lo = 0; lo < 0x10; lo++) {
- printf("%02x", addr[(address & ~0xF)+lo+(hi*0x10)]);
+ printf("%02X", addr[(address & ~0xF)+lo+(hi*0x10)]);
if (lo < 0x0F)
printf(" ");
}
@@ -310,6 +310,7 @@ int asmmon(const char *fn) {
}
uint8_t done = 0;
uint64_t address = 0x0000;
+ uint64_t bytecount = 0;
uint64_t start, end;
uint8_t prefix, opcode;
while (!(done & 1)) {
@@ -321,6 +322,7 @@ int asmmon(const char *fn) {
uint8_t addrmode = IMPL;
uint8_t addrtok = 0;
uint64_t value = 0;
+ uint64_t val2 = 0;
char *oprand;
char *oprand2;
char *cmd;
@@ -386,6 +388,7 @@ int asmmon(const char *fn) {
}
}
if (!strcasecmp(cmd, "quit") || !strcasecmp(cmd, "q")) {
+ printf("The total size of the program code is, %llu bytes in decimal, and $%llX bytes in hex.\n", bytecount, bytecount);
return 2;
}
if (!strcasecmp(cmd, "viewmem") || !strcasecmp(cmd, "vm") || !strcasecmp(cmd, "v")) {
@@ -588,6 +591,9 @@ int asmmon(const char *fn) {
done |= 6;
break;
}
+ if (i && ins[i] == '=') {
+ /*ins = strtok_r(oprand2)*/
+ }
if (ins[i] == ';') {
if (i && (ins[i-1] == ' ' || ins[i-1] == '\t'))
ins[i] = '\0';
@@ -797,8 +803,16 @@ int asmmon(const char *fn) {
mode[0] = oprand[0];
mode[1] = oprand[1];
strtok_r(oprand, "+-", &oprand2);
- if (ir[0] == 'x' || ir[0] == 'y')
+ if (ir[0] == 'x' || ir[0] == 'y') {
oprand2 = strtok_r(oprand2, ",)", &tmp2);
+ }
+ if (oprand2 != NULL) {
+ int i = 0;
+ for (; (oprand2[i] == '$' || oprand2[i] == '%') || isxdigit(oprand2[i]); i++);
+ if (i) {
+ oprand2[i] = '\0';
+ }
+ }
uint8_t isimm = oprand[0] == '#';
/* This flag is used for checking if there is a secondary token. */
uint8_t issectok = (oprand[1] == '$' || oprand[1] == '%' || isdigit(oprand[1]));
@@ -821,10 +835,15 @@ int asmmon(const char *fn) {
else
value = strtoull(oprand, NULL, 10);
if (mode[0] != '(') {
- if ((value & 0xFF0000 || value & 0xFFFF00000000 || value & 0xFFFF0000 || !(value & 0xFF00)))
+ if ((value & 0xFF0000 || value & 0xFFFF00000000 || value & 0xFFFF0000 || !(value & 0xFF00))) {
addrmode = ZM;
- else if (value & 0xFF00000000 || value & 0xFF000000000000 || value & 0xFF00000000000000 || (value & 0xFF00))
- addrmode = ABS;
+ } else if (value & 0xFF00000000 || value & 0xFF000000000000 || value & 0xFF00000000000000 || (value & 0xFF00)) {
+ if (ir[0] == 'x' || ir[0] == 'y') {
+ addrmode = ZM;
+ } else {
+ addrmode = ABS;
+ }
+ }
}
if (addrmode == ZM || addrmode == IND) {
if (value & 0xFFFF00)
@@ -879,10 +898,15 @@ int asmmon(const char *fn) {
value = use_label(oprand, address);
if (!isimm) {
if (mode[0] != '(') {
- if ((value & 0xFF0000 || value & 0xFFFF00000000 || value & 0xFFFF0000 || !(value & 0xFF00)))
+ if ((value & 0xFF0000 || value & 0xFFFF00000000 || value & 0xFFFF0000 || !(value & 0xFF00))) {
addrmode = ZM;
- else if (value & 0xFF00000000 || value & 0xFF000000000000 || value & 0xFF00000000000000 || (value & 0xFF00))
- addrmode = ABS;
+ } else if (value & 0xFF00000000 || value & 0xFF000000000000 || value & 0xFF00000000000000 || (value & 0xFF00)) {
+ if (ir[0] == 'x' || ir[0] == 'y') {
+ addrmode = ZM;
+ } else {
+ addrmode = ABS;
+ }
+ }
}
if (addrmode == ZM || addrmode == IND) {
if (value & 0xFFFF00)
@@ -926,15 +950,21 @@ int asmmon(const char *fn) {
}
}
if (oprand2 != NULL && (addrtok == 1 || addrtok == 2)) {
- uint64_t val2 = 0;
mode[0] = oprand2[0];
- oprand2 = strtok(oprand2, "$%");
- if (mode[0] == '$')
- val2 = strtoull(oprand2, NULL, 16);
- else if (mode[0] == '%')
- val2 = strtoull(oprand2, NULL, 2);
- else
+ if (mode[0] == '$' || mode[0] == '%') {
+ oprand2++;
+ printf("mode[0]: %i, oprand2: %s\n", mode[0], oprand2);
+ switch (mode[0]) {
+ case '$':
+ val2 = strtoull(oprand2, NULL, 16);
+ break;
+ case '%':
+ val2 = strtoull(oprand2, NULL, 2);
+ break;
+ }
+ } else {
val2 = strtoull(oprand2, NULL, 10);
+ }
switch (addrtok) {
case 1:
value += val2;
@@ -1023,6 +1053,7 @@ int asmmon(const char *fn) {
r = prefix;
addr[address] = prefix;
address += 1;
+ bytecount+=1;
} else {
r = 0;
}
@@ -1031,6 +1062,7 @@ int asmmon(const char *fn) {
case IMPL:
if (op.impl || op.impl == CPS) {
addr[address++] = op.impl;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s requires an operand.\n", op.mnemonic);
@@ -1041,6 +1073,7 @@ int asmmon(const char *fn) {
if ((prefix & 0x30) == 0x10 && op.imm == TXS)
r = prefix;
addr[address++] = op.imm;
+ bytecount+=1;
switch (op.imm) {
case PHP:
case PHA:
@@ -1058,12 +1091,14 @@ int asmmon(const char *fn) {
case ASR:
case ENT:
addr[address++] = value & 0xFF;
+ bytecount+=1;
break;
case TXS:
if ((r & 0x30) == 0x10) {
addr[address] = value & 0xFF;
addr[address+2] = value >> 8;
address+=2;
+ bytecount+=2;
}
break;
default:
@@ -1083,6 +1118,7 @@ int asmmon(const char *fn) {
}
address+=r2;
+ bytecount+=r2;
break;
}
break;
@@ -1093,21 +1129,26 @@ int asmmon(const char *fn) {
case ZM:
if (op.zm) {
addr[address++] = op.zm;
+ bytecount+=1;
addr[address] = value & 0xFF;
switch ((r & 0x0C) >> 2) {
case 2:
addr[address+5] = (uint64_t)value >> 40;
addr[address+4] = (uint64_t)value >> 32;
address += 2;
+ bytecount+=2;
case 3:
addr[address+3] = value >> 24;
address += 1;
+ bytecount+=1;
case 1:
addr[address+2] = value >> 16;
addr[address+1] = value >> 8;
address += 2;
+ bytecount+=2;
}
address += 1;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s does not use Zero Matrix.\n", op.mnemonic);
@@ -1116,21 +1157,26 @@ int asmmon(const char *fn) {
case ZMX:
if (op.zmx) {
addr[address++] = op.zmx;
+ bytecount+=1;
addr[address] = value & 0xFF;
switch ((r & 0x0C) >> 2) {
case 2:
addr[address+5] = (uint64_t)value >> 40;
addr[address+4] = (uint64_t)value >> 32;
address += 2;
+ bytecount+=2;
case 3:
addr[address+3] = value >> 24;
address += 1;
+ bytecount+=1;
case 1:
addr[address+2] = value >> 16;
addr[address+1] = value >> 8;
address += 2;
+ bytecount+=2;
}
address += 1;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s does not use Zero Matrix, indexed with x.\n", op.mnemonic);
@@ -1139,21 +1185,26 @@ int asmmon(const char *fn) {
case ZMY:
if (op.zmy) {
addr[address++] = op.zmy;
+ bytecount+=1;
addr[address] = value & 0xFF;
switch ((r & 0x0C) >> 2) {
case 2:
addr[address+5] = (uint64_t)value >> 40;
addr[address+4] = (uint64_t)value >> 32;
address += 2;
+ bytecount+=2;
case 3:
addr[address+3] = value >> 24;
address += 1;
+ bytecount+=1;
case 1:
addr[address+2] = value >> 16;
addr[address+1] = value >> 8;
address += 2;
+ bytecount+=2;
}
address += 1;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s does not use Zero Matrix, indexed with y.\n", op.mnemonic);
@@ -1162,23 +1213,28 @@ int asmmon(const char *fn) {
case ABS:
if (op.abs) {
addr[address++] = op.abs;
+ bytecount+=1;
addr[address] = value & 0xFF;
addr[address+1] = value >> 8;
switch ((r & 0x0C) >> 2) {
case 3:
addr[address+7] = value >> 56;
address += 1;
+ bytecount+=1;
case 2:
addr[address+6] = (uint64_t)value >> 48;
addr[address+5] = (uint64_t)value >> 40;
address += 2;
+ bytecount+=2;
case 1:
addr[address+4] = (uint64_t)value >> 32;
addr[address+3] = value >> 24;
addr[address+2] = value >> 16;
address += 3;
+ bytecount+=3;
}
address += 2;
+ bytecount+=2;
break;
} else {
fprintf(stderr, "oof, %s cannot be an absolute dictator.\n", op.mnemonic);
@@ -1187,21 +1243,26 @@ int asmmon(const char *fn) {
case IND:
if (op.ind) {
addr[address++] = op.ind;
+ bytecount+=1;
addr[address] = value & 0xFF;
switch ((r & 0x0C) >> 2) {
case 2:
addr[address+5] = (uint64_t)value >> 40;
addr[address+4] = (uint64_t)value >> 32;
address += 2;
+ bytecount+=2;
case 3:
addr[address+3] = value >> 24;
address += 1;
+ bytecount+=1;
case 1:
addr[address+2] = value >> 16;
addr[address+1] = value >> 8;
address += 2;
+ bytecount+=2;
}
address += 1;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s cannot use pointers.\n", op.mnemonic);
@@ -1210,21 +1271,26 @@ int asmmon(const char *fn) {
case INDX:
if (op.inx) {
addr[address++] = op.inx;
+ bytecount+=1;
addr[address] = value & 0xFF;
switch ((r & 0x0C) >> 2) {
case 2:
addr[address+5] = (uint64_t)value >> 40;
addr[address+4] = (uint64_t)value >> 32;
address += 2;
+ bytecount+=2;
case 3:
addr[address+3] = value >> 24;
address += 1;
+ bytecount+=1;
case 1:
addr[address+2] = value >> 16;
addr[address+1] = value >> 8;
address += 2;
+ bytecount+=2;
}
address += 1;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s does not use Indexed Indirect.\n", op.mnemonic);
@@ -1233,21 +1299,26 @@ int asmmon(const char *fn) {
case INDY:
if (op.iny) {
addr[address++] = op.iny;
+ bytecount+=1;
addr[address] = value & 0xFF;
switch ((r & 0x0C) >> 2) {
case 2:
addr[address+5] = (uint64_t)value >> 40;
addr[address+4] = (uint64_t)value >> 32;
address += 2;
+ bytecount+=2;
case 3:
addr[address+3] = value >> 24;
address += 1;
+ bytecount+=1;
case 1:
addr[address+2] = value >> 16;
addr[address+1] = value >> 8;
address += 2;
+ bytecount+=2;
}
address += 1;
+ bytecount+=1;
break;
} else {
fprintf(stderr, "oof, %s does not use Indirect Indexed.\n", op.mnemonic);
@@ -1256,16 +1327,46 @@ int asmmon(const char *fn) {
}
#if debug
if (!(done & 6)) {
- printf("instruction: %s, ", ins);
- printf("addrmode: %s, ", adrmode[addrmode]);
+ printf("Instruction: %s, ", ins);
+ printf("Addressing Mode: %s,", adrmode[addrmode]);
+ switch (addrmode) {
+ case ZM:
+ printf(" ");
+ break;
+ case IMM:
+ case ABS:
+ case ZMX:
+ case ZMY:
+ case IND:
+ printf(" ");
+ break;
+ case IMPL:
+ case INDX:
+ case INDY:
+ printf(" ");
+ break;
+ }
+ printf("Address: $%llX", address);
#if (!__GLIBC__) || (__TINYC__)
- printf("Postfix: %s, ", (postfix != NULL) ? postfix : "none");
+ if (postfix != NULL) {
#else
- printf("Postfix: %s, ", (postfix[0] != '\0') ? postfix : "none");
+ if (postfix[0] != '\0') {
#endif
- printf("Operand: %s, ", (oprand != NULL && !(done & 16)) ? oprand : "none");
- printf("Index Register: %s, ", (ir != NULL && !(done & 32)) ? ir : "none");
- printf("Address: $%llx\n", address);
+ printf(", Suffix: %s", postfix);
+ }
+ if (prefix) {
+ printf(", Prefix: $%02X", prefix);
+ }
+ if (oprand != NULL && !(done & 16)) {
+ printf(", Operand: %s", oprand);
+ }
+ if (addrtok) {
+ printf(",\tArithmetic mode, and operand: %s, $%llX", (addrtok == 1) ? "+" : "-", val2);
+ }
+ if (ir[0] != '\0' && !(done & 32)) {
+ printf(",\tIndex Register: %s", ir);
+ }
+ puts("");
}
#endif
}