WIP : Eff it, I left the magic memcpy in. Printing mostly works but it's still broken. Calls to _cputs and _cputsf may mysteriously fail due to some kind of memory corruption I haven't tracked down yet. This commit leaves in a bunch of commented testing code, the next commit will rip them out.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
83
src/basic.c
83
src/basic.c
@@ -16,15 +16,14 @@ char _tokenizer_value[BASIC_TOKENIZER_MAX_LENGTH];
|
|||||||
char *_tokenizer_prev;
|
char *_tokenizer_prev;
|
||||||
char *_tokenizer_prev_next;
|
char *_tokenizer_prev_next;
|
||||||
char basic_memory_lines[BASIC_MAX_LINES][BASIC_MAX_LINE_LENGTH];
|
char basic_memory_lines[BASIC_MAX_LINES][BASIC_MAX_LINE_LENGTH];
|
||||||
char decimal[32];
|
|
||||||
char const_string_test[255];
|
char const_string_test[255];
|
||||||
|
|
||||||
void basic_report_error(char *prefix)
|
void basic_report_error(char *prefix)
|
||||||
{
|
{
|
||||||
memset((char *)&decimal, 0x00, 32);
|
|
||||||
_cputs(prefix);
|
_cputs(prefix);
|
||||||
itoa(basic_errno, (char *)&decimal);
|
memset(decimal, 0x00, 32);
|
||||||
_cputs((char *)&decimal);
|
itoa(basic_errno, decimal);
|
||||||
|
_cputs(decimal);
|
||||||
_cputs("\n");
|
_cputs("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,32 +46,25 @@ void basic_cmd_list(void *data)
|
|||||||
char *lineptr = NULL;
|
char *lineptr = NULL;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
/* I don't know why, but somehow, this makes the interspersed _cputs() calls below work.
|
/* I don't know why, but somehow, this memcpy fixes the bug where _cputs and _cputsf stops properly processing
|
||||||
* Take this out, and those lines stop working.
|
* constant character strings passed as the format string. I've tried lots and lots of things and I still don't
|
||||||
*
|
* know why this fixes the bug.
|
||||||
* WHAT. THE. FUCK.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* memcpy((char *)&const_string_test, (char *)" \0", strlen(" \0"));
|
|
||||||
* _cputs((char *)&const_string_test);
|
|
||||||
*/
|
*/
|
||||||
/* 12 characters of nothing? This does the same thing as the cputs above.
|
memcpy(const_string_test, (char *)" \0", strlen(" \0"));
|
||||||
* But cputs is still broken after this. It's the memcpy that is fixing whatever is wrong.
|
|
||||||
*/
|
|
||||||
/*for ( i = 0; i < 12; i++ ) {
|
|
||||||
_putch(' ');
|
|
||||||
advanceCursor();
|
|
||||||
}*/
|
|
||||||
for ( i = 0; i <= limit ; i++ ) {
|
for ( i = 0; i <= limit ; i++ ) {
|
||||||
if ( basic_memory_lines[i][0] != 0 ) {
|
if ( basic_memory_lines[i][0] != 0 ) {
|
||||||
itoa(i+1, (char *)&decimal);
|
_cputsf("%d ", (char *)(i+1));
|
||||||
_cputs((char *)&decimal);
|
/*itoa(i+1, decimal);
|
||||||
|
_cputs(decimal);
|
||||||
_putch(' ');
|
_putch(' ');
|
||||||
advanceCursor();
|
advanceCursor();*/
|
||||||
_cputs(basic_memory_line_address(i));
|
_cputsf("%s\n", basic_memory_lines[i]);
|
||||||
|
/*_cputs(" ");
|
||||||
|
_cputs(basic_memory_lines[i]);
|
||||||
_putch('\n');
|
_putch('\n');
|
||||||
_cursor_x = 80;
|
_cursor_x = 80;
|
||||||
advanceCursor();
|
advanceCursor();
|
||||||
|
_cputs("\n");*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +134,7 @@ char *_tokenize(char *ptr, char *token)
|
|||||||
orig = ptr;
|
orig = ptr;
|
||||||
numtokens = strlen(token);
|
numtokens = strlen(token);
|
||||||
|
|
||||||
memset(&_tokenizer_value, 0x00, BASIC_TOKENIZER_MAX_LENGTH);
|
memset(_tokenizer_value, 0x00, BASIC_TOKENIZER_MAX_LENGTH);
|
||||||
while ( *ptr != 0x0 ) {
|
while ( *ptr != 0x0 ) {
|
||||||
/*for ( tokenptr = token ; *tokenptr != 0x00; tokenptr += 1) {
|
/*for ( tokenptr = token ; *tokenptr != 0x00; tokenptr += 1) {
|
||||||
if ( *ptr == *tokenptr) {
|
if ( *ptr == *tokenptr) {
|
||||||
@@ -163,14 +155,14 @@ _tokenize_copy:
|
|||||||
basic_errno = BASIC_ERR_SYNTAX_TOKEN_LENGTH;
|
basic_errno = BASIC_ERR_SYNTAX_TOKEN_LENGTH;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy((void *)&_tokenizer_value, (void *)orig, len);
|
memcpy(_tokenizer_value, (void *)orig, len);
|
||||||
_tokenizer_prev_next = (ptr + 1);
|
_tokenizer_prev_next = (ptr + 1);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tokenizer_token(void)
|
char *tokenizer_token(void)
|
||||||
{
|
{
|
||||||
return (char *)&_tokenizer_value;
|
return _tokenizer_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
@@ -179,11 +171,6 @@ char *tokenizer_token(void)
|
|||||||
*
|
*
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
|
||||||
char *basic_memory_line_address(int lineno)
|
|
||||||
{
|
|
||||||
return ((char *)&basic_memory_lines) + (lineno * BASIC_MAX_LINE_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
int basic_memory_line_store(char *content, int lineno)
|
int basic_memory_line_store(char *content, int lineno)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -195,7 +182,7 @@ int basic_memory_line_store(char *content, int lineno)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = basic_memory_line_address(lineno);
|
/*dest = basic_memory_line_address(lineno);*/
|
||||||
if ( lineno > basic_last_stored_lineno ) {
|
if ( lineno > basic_last_stored_lineno ) {
|
||||||
/*
|
/*
|
||||||
* basic_last_stored_lineno only every grows upward (even if you go back and edit a line or insert one).
|
* basic_last_stored_lineno only every grows upward (even if you go back and edit a line or insert one).
|
||||||
@@ -208,14 +195,14 @@ int basic_memory_line_store(char *content, int lineno)
|
|||||||
/*ptr = basic_memory_line_address(i);*/
|
/*ptr = basic_memory_line_address(i);*/
|
||||||
/*memset(ptr, 0x00, BASIC_MAX_LINE_LENGTH);*/
|
/*memset(ptr, 0x00, BASIC_MAX_LINE_LENGTH);*/
|
||||||
}
|
}
|
||||||
|
basic_last_stored_lineno = lineno;
|
||||||
}
|
}
|
||||||
lineno -= 1;
|
lineno -= 1;
|
||||||
i = (int) memcpy(basic_memory_line_address(lineno), content, strlen(content));
|
i = (int) memcpy(basic_memory_lines[lineno], content, strlen(content));
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
basic_errno = BASIC_ERR_INTERNAL_NULLPOINTER;
|
basic_errno = BASIC_ERR_INTERNAL_NULLPOINTER;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
basic_last_stored_lineno = lineno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int basic_run_line_v2(char *codeline, int repl_mode)
|
int basic_run_line_v2(char *codeline, int repl_mode)
|
||||||
@@ -238,7 +225,7 @@ int basic_run_line_v2(char *codeline, int repl_mode)
|
|||||||
|
|
||||||
/* is it a line number? If so, store it and do nothing else.*/
|
/* is it a line number? If so, store it and do nothing else.*/
|
||||||
if ( isdigit(*token) ) {
|
if ( isdigit(*token) ) {
|
||||||
memset((char *)&decimal, 0x00, 32);
|
memset(decimal, 0x00, 32);
|
||||||
lineno = atoi(token);
|
lineno = atoi(token);
|
||||||
basic_memory_line_store(buffptr, lineno);
|
basic_memory_line_store(buffptr, lineno);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -258,8 +245,11 @@ int basic_run_line_v2(char *codeline, int repl_mode)
|
|||||||
|
|
||||||
/* Report errors */
|
/* Report errors */
|
||||||
if ( basic_errno != 0 ) {
|
if ( basic_errno != 0 ) {
|
||||||
/*_cputs(token);*/
|
/*_cputs("Last parsed token: ");
|
||||||
basic_report_error("Parsing error: ");
|
_cputs(token);
|
||||||
|
_cputs("\n");*/
|
||||||
|
_cputsf("Parsing error: %d", basic_errno);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move to the next thing in the line and process it */
|
/* Move to the next thing in the line and process it */
|
||||||
@@ -307,12 +297,13 @@ void basic_repl(void)
|
|||||||
blankScreen();
|
blankScreen();
|
||||||
setCursorPosition(0, 0);
|
setCursorPosition(0, 0);
|
||||||
|
|
||||||
basic_repl_mode = 1;
|
/*
|
||||||
basic_memory_line_store("LIST", 10);
|
* basic_repl_mode = 1;
|
||||||
basic_memory_line_store("PRINT HELLO\n", 20);
|
* basic_memory_line_store("LIST", 10);
|
||||||
basic_memory_line_store("PRINT WORLD\n", 30);
|
* basic_memory_line_store("PRINT HELLO\\n", 20);
|
||||||
basic_memory_line_store("PRINT GOODBYE\n", 40);
|
* basic_memory_line_store("PRINT WORLD\\n", 30);
|
||||||
|
* basic_memory_line_store("PRINT GOODBYE\\n", 40);
|
||||||
|
*/
|
||||||
_cputs("Piquant Basic v0.1\n");
|
_cputs("Piquant Basic v0.1\n");
|
||||||
_cputs("READY\n");
|
_cputs("READY\n");
|
||||||
|
|
||||||
@@ -330,9 +321,9 @@ void basic_repl(void)
|
|||||||
ptr = _tokenize((char *)&basic_memory_lines[39], " ");
|
ptr = _tokenize((char *)&basic_memory_lines[39], " ");
|
||||||
token = tokenizer_token();
|
token = tokenizer_token();
|
||||||
basic_cmd_print(ptr);
|
basic_cmd_print(ptr);
|
||||||
basic_run_line_v2((char *)&basic_memory_lines[19], 1);
|
basic_run_line_v2(basic_memory_lines[19], 1);
|
||||||
basic_run_line_v2((char *)&basic_memory_lines[29], 1);
|
basic_run_line_v2(basic_memory_lines[29], 1);
|
||||||
basic_run_line_v2((char *)&basic_memory_lines[39], 1);*/
|
basic_run_line_v2(basic_memory_lines[39], 1);*/
|
||||||
basic_repl_mode = 0;
|
basic_repl_mode = 0;
|
||||||
}
|
}
|
||||||
_cputs("\n> ");
|
_cputs("\n> ");
|
||||||
|
|||||||
64
src/conio.c
64
src/conio.c
@@ -6,6 +6,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char decimal[32];
|
||||||
|
|
||||||
void _putch(char c)
|
void _putch(char c)
|
||||||
{
|
{
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
@@ -32,12 +34,70 @@ void _cputs(char *ptr)
|
|||||||
if ( ptr == NULL ) {
|
if ( ptr == NULL ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while ((char)*ptr != 0x0) {
|
while (*ptr != 0x0) {
|
||||||
_putch((char)*ptr);
|
if (*ptr == '\\') {
|
||||||
|
ptr += 1;
|
||||||
|
switch ( *ptr ) {
|
||||||
|
case 'n':
|
||||||
|
_putch('\n');
|
||||||
|
_cursor_x = 80;
|
||||||
|
advanceCursor();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_putch(*ptr);
|
||||||
if (*ptr == '\n') {
|
if (*ptr == '\n') {
|
||||||
_cursor_x = 80;
|
_cursor_x = 80;
|
||||||
}
|
}
|
||||||
advanceCursor();
|
advanceCursor();
|
||||||
|
}
|
||||||
|
ptr += 1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _cputsf(char *ptr, char *data)
|
||||||
|
{
|
||||||
|
if ( ptr == NULL || data == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*_cputs("_cputsf called with ptr : ");
|
||||||
|
memset(decimal, 0x00, 32);
|
||||||
|
itoa((int)ptr, decimal);
|
||||||
|
_cputs(decimal);
|
||||||
|
_cputs(" (");
|
||||||
|
_cputs(ptr);
|
||||||
|
_cputs(") length ");
|
||||||
|
memset(decimal, 0x00, 32);
|
||||||
|
itoa(strlen(ptr), decimal);
|
||||||
|
_cputs(decimal);
|
||||||
|
_cputs(" data ");
|
||||||
|
memset(decimal, 0x00, 32);
|
||||||
|
itoa((int)data, decimal);
|
||||||
|
_cputs(decimal);
|
||||||
|
_cputs("\n");*/
|
||||||
|
|
||||||
|
while (*ptr != 0) {
|
||||||
|
if ( *ptr == '%' ) {
|
||||||
|
ptr += 1;
|
||||||
|
switch ( *ptr ) {
|
||||||
|
case 'd':
|
||||||
|
memset(decimal, 0x00, 32);
|
||||||
|
itoa((int)data, decimal);
|
||||||
|
_cputs(decimal);
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
_cputs((char *)data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_putch(*ptr);
|
||||||
|
if (*ptr == '\n') {
|
||||||
|
_cursor_x = 80;
|
||||||
|
}
|
||||||
|
advanceCursor();
|
||||||
|
}
|
||||||
ptr += 1;
|
ptr += 1;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
void _putch(char _c);
|
void _putch(char _c);
|
||||||
char *_cgets(char *d);
|
char *_cgets(char *d);
|
||||||
void _cputs(char *d);
|
void _cputs(char *d);
|
||||||
|
void _cputsf(char *d, char *data);
|
||||||
char _getkey(char *dest);
|
char _getkey(char *dest);
|
||||||
|
|
||||||
|
|
||||||
|
extern char decimal[32];
|
||||||
|
|
||||||
#endif /* _CONIO_H_ */
|
#endif /* _CONIO_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user