summaryrefslogtreecommitdiff
path: root/opcode-gen.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2020-08-08 10:28:36 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2020-08-08 10:28:36 -0400
commit1ec19679b3db209429b0897f6ccda6d09d018a70 (patch)
treeef17e28b388a04fadeb14982a5332eb647981d8b /opcode-gen.c
parent39081609ec4f1f5d96e15e346eecd09ca2cc9f41 (diff)
Did a ton of stuff.
- Changed the file structure of the SuB Suite, so that all variable declarations, symbols, and constants are in a single file. - Moved the C library functionss into a separate file, and made them use stack frames. - Added support for using the emulator's assembler for realtime debugging, to enter it, get in to stepping mode by pressing Ctrl+s, press any other key, then press F1, The reason for having to press some other key before pressing F1 is because it only allows entering the assembler when the keyboard is not ready. - Added the ".res" directive to the emulator's assembler, the ".res" directive tells the assembler to reserve however many bytes specified by the operand. - Fixed some bugs in the emulator's assembler.
Diffstat (limited to 'opcode-gen.c')
-rw-r--r--opcode-gen.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/opcode-gen.c b/opcode-gen.c
index 3091e05..be0028c 100644
--- a/opcode-gen.c
+++ b/opcode-gen.c
@@ -8,7 +8,7 @@ struct instruction {
char *mne; /* Mnemonic. */
char *desc; /* Description */
char *com; /* Comment. */
- uint8_t op[10]; /* Opcodes. */
+ uint8_t op[11]; /* Opcodes. */
};
struct opcode {
@@ -44,6 +44,7 @@ const char *ams[] = { /* Addressing modes. */
"IY ",
"AB ",
"REL ",
+ "B ",
"IMP "
};
@@ -58,6 +59,7 @@ enum am {
INDY, /* Indirect Indexed. */
ABS, /* Absolute. */
REL, /* Relative to Program Counter. */
+ BREG, /* B Register. */
IMPL, /* Implied. */
/* Part of Base Extension. */
ABSX, /* Absolute, Indexed with X. */
@@ -71,7 +73,7 @@ enum am {
EIND, /* Effective Address Register, Indirect. */
};
-static const char *addrmodes[10] = {
+static const char *addrmodes[11] = {
[IMM ] = "IMM",
[ZM ] = "ZM",
[ZMX ] = "ZMX",
@@ -81,10 +83,11 @@ static const char *addrmodes[10] = {
[INDY] = "INDY",
[ABS ] = "ABS",
[REL ] = "REL",
+ [BREG] = "BREG",
[IMPL] = "IMPL"
};
-static const char *amcom[10] = {
+static const char *amcom[11] = {
[IMM ] = "Immediate.",
[ZM ] = "Zero Matrix.",
[ZMX ] = "Zero Marrix, Indexed with X.",
@@ -94,10 +97,11 @@ static const char *amcom[10] = {
[INDY] = "Indirect Indexed.",
[ABS ] = "Absolute.",
[REL ] = "Relative.",
+ [BREG] = "B Register.",
[IMPL] = "Implied."
};
-static const char *am_tok[10] = {
+static const char *am_tok[11] = {
[IMM ] = "#",
[ZM ] = "zm",
[ZMX ] = "zmx",
@@ -107,6 +111,7 @@ static const char *am_tok[10] = {
[INDY] = "indy",
[ABS ] = "a",
[REL ] = "rel",
+ [BREG] = "B"
};
int get_instcount(list *l) {
@@ -121,7 +126,7 @@ inst *make_inst(opcode *opc, char *mne, char *desc, char *com) {
ins->desc = desc;
ins->com = com;
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < 11; i++) {
ins->op[i] = 0xFF;
}
@@ -170,13 +175,13 @@ void free_opcodes() {
void print_optable(list *l, int maxop) {
int i = 0;
- puts("static const uint8_t opcodes[OPNUM][10] = {");
- puts("\t/*\t IMM\t ZM ZMX ZMY IND INDX INDY ABS REL IMPL*/");
+ puts("static const uint8_t opcodes[OPNUM][11] = {");
+ puts("\t/*\t IMM\t ZM ZMX ZMY IND INDX INDY ABS REL B IMPL*/");
while (l) {
inst *ins = l->inst;
printf("\t[%s] = {", ins->mne);
- for (int j = 0; j < 10; j++) {
- printf("0x%02X%s", ins->op[j], (j < 9) ? ", " : "}");
+ for (int j = 0; j < 11; j++) {
+ printf("0x%02X%s", ins->op[j], (j < 10) ? ", " : "}");
}
putchar((l->next) ? ',' : ' ');
printf(" /* %s */\n", ins->mne);
@@ -212,6 +217,7 @@ opcode *lex_value(char *str, int op) {
case 'A': opc->am = IMPL; break;
case '#': opc->am = IMM ; break;
case 'a': opc->am = ABS ; break;
+ case 'B': opc->am = BREG; break;
case 'r': opc->am = REL ; i += 2; break;
case 'z':
switch (str[i+2]) {
@@ -326,13 +332,13 @@ void print_mneenum(list *l, char *name) {
inst *ins = l->inst;
putchar('\t');
printf("%s = ", ins->mne);
- if (i < 100 && inst_count >= 100) {
+ /*if (i < 100 && inst_count >= 100) {
putchar(' ');
}
if (i < 10 && inst_count >= 10) {
putchar(' ');
- }
- printf("%i", i);
+ }*/
+ printf("%3i", i);
putchar((l->next) ? ',' : ' ');
putchar('\n');
i++;