implemented hexstrings, implemented MOVE, PUTCOLOR, GETCHAR, GETCOLOR, modified PUTCHAR, several fixes.

This commit is contained in:
2017-02-09 19:03:20 +01:00
parent be539b1591
commit 3f1f9451ca
10 changed files with 219 additions and 298 deletions

View File

@@ -12,6 +12,7 @@ static bool streq(const char* a, const char* b) {
static const char* ptr;
static t_tokentype current_token = TOKEN_ERROR;
static char identifier[255];
static unsigned char array[255];
static int value;
static int line = 0;
static int row = 0;
@@ -54,9 +55,13 @@ t_token_op tkn_tokens[] = {
{ "setsprite", TOKEN_SETSPRITE },
{ "putsprite", TOKEN_PUTSPRITE },
{ "locate", TOKEN_LOCATE },
{ "move", TOKEN_MOVE },
{ "print", TOKEN_PRINT },
{ "putchar", TOKEN_PUTCHAR },
{ "setchar", TOKEN_SETCHAR },
{ "putchar", TOKEN_PUTCHAR },
{ "getchar", TOKEN_GETCHAR },
{ "putcolor", TOKEN_PUTCOLOR },
{ "getcolor", TOKEN_GETCOLOR },
{ "keypressed", TOKEN_KEYPRESSED },
{ "anykey", TOKEN_ANYKEY },
{ "updatescr", TOKEN_UPDATESCR },
@@ -86,6 +91,17 @@ static void tkn_do_next() {
if (CCHR == 0) { current_token = TOKEN_ENDFILE; return; }
// if 13, we are at the end of the line
if (CCHR == 10) { NEXT; current_token = TOKEN_ENDLINE; return; }
// If '!' grab the hexstring
if (CCHR == '!') {
NEXT; int i = 0;
while ((CCHR >= 48 && CCHR <= 57) || (CCHR >= 'A' && CCHR <= 'F') || (CCHR >= 'a' && CCHR <= 'f')) {
array[++i] = hex_digit(CCHR) << 4; NEXT;
if (!((CCHR >= 48 && CCHR <= 57) || (CCHR >= 'A' && CCHR <= 'F') || (CCHR >= 'a' && CCHR <= 'f'))) { current_token = TOKEN_ERROR; error_raise("Invalid hexstring."); return; }
array[i] += hex_digit(CCHR); NEXT;
}
array[0] = i;
current_token = TOKEN_HEXSTRING; return;
}
// if 34, grab the string
if (CCHR == 34) {
NEXT;
@@ -161,13 +177,14 @@ void tkn_init(const char* buffer) {
ptr = buffer;
current_token = TOKEN_ERROR;
value = line = row = current_tokenline = current_tokenrow = 0;
identifier[0] = 0;
identifier[0] = 0; array[0] = 0;
}
void tkn_next() { do { tkn_do_next(); } while (current_token == TOKEN_REM || current_token == TOKEN_ENDLINE); }
t_tokentype tkn_get_token() { return current_token; }
char* tkn_get_string() { return identifier; }
unsigned char* tkn_get_array() { return array; }
int tkn_get_value() { return value; }
int tkn_get_line() { return current_tokenline; }
int tkn_get_row() { return current_tokenrow; }