From 756c606af68be8ccca7aced3b9c3d56fb2d5087f Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 6 Jul 2020 20:04:41 -0400 Subject: - Implemented a new opcode table. - Added a new preifx called the OF prefix, which adds the contents of a specific register to the current operand. - Added a table generator, which parses opcode table csv files. --- lexer.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'lexer.c') diff --git a/lexer.c b/lexer.c index 55eb576..14bf1c4 100644 --- a/lexer.c +++ b/lexer.c @@ -184,6 +184,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { uint8_t k = 0; uint8_t ch = 0; uint8_t rs = 0; + uint8_t of = 0; uint8_t base = 0; uint8_t islocal = 0; @@ -234,6 +235,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { } l->addr = address; while (isdelm(str[i], dbg) != 1) { + uint8_t offset = 0; base = 0; space = 0; tab = 0; @@ -257,8 +259,12 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { for (; isdelm(str[i], dbg) == 16; i++); } uint8_t ptok = get_ptok(str[i], dbg); - if (ptok == PTOK_X || ptok == PTOK_Y) { - switch (get_ptok(str[i+1], dbg)) { + if (ptok == PTOK_X || ptok == PTOK_Y || ptok == PTOK_S || ptok == PTOK_P) { + offset++; + if ((ptok == PTOK_S && toupper(str[i+1]) == 'P') || (ptok == PTOK_P && toupper(str[i+1]) == 'C')) { + offset++; + } + switch (get_ptok(str[i+offset], dbg)) { case PTOK_ALPHA : case PTOK_NUMBER: ptok = PTOK_ALPHA; break; } @@ -425,7 +431,7 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { break; case PTOK_COMMA: i++; - if (lex_type != TOK_IND) { + if (lex_type != TOK_IND && lex_type != TOK_OF) { lex_type = TOK_CSV; } lexeme[j] = ','; @@ -445,6 +451,22 @@ uint64_t lex(char *str, uint64_t address, uint8_t dbg) { case PTOK_Y: l->tok->type = (lex_type == TOK_IND) ? INDY : ZMY; break; } break; + case PTOK_S: + case PTOK_P: + lexeme[j] = str[i++]; + if (str[i] != ',') { + lexeme[j+1] = str[i++]; + } else { + lexeme[j+1] = '\0'; + } + lexeme[j+2] = '\0'; + switch (ptok) { + case PTOK_S: of = 1; break; + case PTOK_P: of = 2; break; + } + lex_type = TOK_OF; + t = make_token(lex_type, of, 0, "", NULL); + break; case PTOK_AT: memset(lexeme, 0, strlen(lexeme)+1); lexeme[j] = '@'; -- cgit v1.2.3-13-gbd6f