Skip to content

Commit

Permalink
CHAIN, RND, RSEED, !=, END added
Browse files Browse the repository at this point in the history
  • Loading branch information
BleuLlama committed Sep 22, 2012
1 parent 42004d1 commit 4ffef42
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 22 deletions.
104 changes: 85 additions & 19 deletions Arduino/TinyBasicPlus.ino
Expand Up @@ -6,7 +6,12 @@
// Scott Lawrence <yorgle@gmail.com> // Scott Lawrence <yorgle@gmail.com>
// //



// v0.05: 2012-09-21
// CHAIN to load and run a second file
// RND,RSEED for random stuff
// Added "!=" for "<>" synonym
// Added "END" for "STOP" synonym (proper name for the functionality anyway)
//
// v0.04: 2012-09-20 // v0.04: 2012-09-20
// DELAY ms - for delaying // DELAY ms - for delaying
// PINMODE <pin>, INPUT|IN|I|OUTPUT|OUT|O // PINMODE <pin>, INPUT|IN|I|OUTPUT|OUT|O
Expand All @@ -16,7 +21,7 @@
// Updated for building desktop command line app (incomplete) // Updated for building desktop command line app (incomplete)
// //
// v0.03: 2012-09-19 // v0.03: 2012-09-19
// Integrated J�rg Wullschleger whitespace,unary fix // Integrated Jurg Wullschleger whitespace,unary fix
// Now available through github // Now available through github
// Project renamed from "Tiny Basic in C" to "TinyBasic Plus" // Project renamed from "Tiny Basic in C" to "TinyBasic Plus"
// //
Expand Down Expand Up @@ -103,7 +108,10 @@ char eliminateCompileErrors = 1; // fix to suppress arduino build errors
static boolean sd_is_initialized = false; static boolean sd_is_initialized = false;
static boolean outToFile = false; static boolean outToFile = false;
static boolean inFromFile = false; static boolean inFromFile = false;
static boolean inhibitOutput = false;
#endif #endif
static boolean runAfterLoad = false;
static boolean triggerRun = false;




//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -163,7 +171,10 @@ static unsigned char keywords[] = {
'D','W','R','I','T','E'+0x80, 'D','W','R','I','T','E'+0x80,
'P','I','N','M','O','D','E'+0x80, 'P','I','N','M','O','D','E'+0x80,
'D','E','L','A','Y'+0x80, 'D','E','L','A','Y'+0x80,
0 'E','N','D'+0x80,
'R','S','E','E','D'+0x80,
'C','H','A','I','N'+0x80,
0
}; };


#define KW_LIST 0 #define KW_LIST 0
Expand Down Expand Up @@ -192,7 +203,11 @@ static unsigned char keywords[] = {
#define KW_DWRITE 23 #define KW_DWRITE 23
#define KW_PINMODE 24 #define KW_PINMODE 24
#define KW_DELAY 25 #define KW_DELAY 25
#define KW_DEFAULT 26 #define KW_END 26
#define KW_RSEED 27
#define KW_CHAIN 28
#define KW_DEFAULT 29



struct stack_for_frame { struct stack_for_frame {
char frame_type; char frame_type;
Expand All @@ -214,13 +229,15 @@ static unsigned char func_tab[] = {
'A','B','S'+0x80, 'A','B','S'+0x80,
'A','R','E','A','D'+0x80, 'A','R','E','A','D'+0x80,
'D','R','E','A','D'+0x80, 'D','R','E','A','D'+0x80,
'R','N','D'+0x80,
0 0
}; };
#define FUNC_PEEK 0 #define FUNC_PEEK 0
#define FUNC_ABS 1 #define FUNC_ABS 1
#define FUNC_AREAD 2 #define FUNC_AREAD 2
#define FUNC_DREAD 3 #define FUNC_DREAD 3
#define FUNC_UNKNOWN 4 #define FUNC_RND 4
#define FUNC_UNKNOWN 5


static unsigned char to_tab[] = { static unsigned char to_tab[] = {
'T','O'+0x80, 'T','O'+0x80,
Expand All @@ -239,6 +256,7 @@ static unsigned char relop_tab[] = {
'='+0x80, '='+0x80,
'<','='+0x80, '<','='+0x80,
'<'+0x80, '<'+0x80,
'!','='+0x80,
0 0
}; };


Expand All @@ -248,7 +266,8 @@ static unsigned char relop_tab[] = {
#define RELOP_EQ 3 #define RELOP_EQ 3
#define RELOP_LE 4 #define RELOP_LE 4
#define RELOP_LT 5 #define RELOP_LT 5
#define RELOP_UNKNOWN 6 #define RELOP_NE_BANG 6
#define RELOP_UNKNOWN 7


static unsigned char highlow_tab[] = { static unsigned char highlow_tab[] = {
'H','I','G','H'+0x80, 'H','I','G','H'+0x80,
Expand Down Expand Up @@ -291,7 +310,7 @@ static const unsigned char okmsg[] = "OK";
static const unsigned char whatmsg[] = "What? "; static const unsigned char whatmsg[] = "What? ";
static const unsigned char howmsg[] = "How?"; static const unsigned char howmsg[] = "How?";
static const unsigned char sorrymsg[] = "Sorry!"; static const unsigned char sorrymsg[] = "Sorry!";
static const unsigned char initmsg[] = "TinyBasic Plus V0.04"; static const unsigned char initmsg[] = "TinyBasic Plus V0.05";
static const unsigned char memorymsg[] = " bytes free."; static const unsigned char memorymsg[] = " bytes free.";
static const unsigned char breakmsg[] = "break!"; static const unsigned char breakmsg[] = "break!";
static const unsigned char unimplimentedmsg[] = "Unimplemented"; static const unsigned char unimplimentedmsg[] = "Unimplemented";
Expand Down Expand Up @@ -463,7 +482,7 @@ void printmsg(const unsigned char *msg)
/***************************************************************************/ /***************************************************************************/
static void getln(char prompt) static void getln(char prompt)
{ {
outchar(prompt); outchar(prompt);
txtpos = program_end+sizeof(LINENUM); txtpos = program_end+sizeof(LINENUM);


while(1) while(1)
Expand All @@ -482,7 +501,8 @@ static void getln(char prompt)
if(txtpos == program_end) if(txtpos == program_end)
break; break;
txtpos--; txtpos--;
printmsg(backspacemsg);
printmsg(backspacemsg);
break; break;
default: default:
// We need to leave at least one space to allow us to shuffle the line into order // We need to leave at least one space to allow us to shuffle the line into order
Expand All @@ -492,9 +512,7 @@ static void getln(char prompt)
{ {
txtpos[0] = c; txtpos[0] = c;
txtpos++; txtpos++;
#if ECHO_CHARS
outchar(c); outchar(c);
#endif
} }
} }
} }
Expand Down Expand Up @@ -614,17 +632,20 @@ static short int expr4(void)
txtpos++; txtpos++;
switch(f) switch(f)
{ {
case FUNC_AREAD:
return analogRead( a );
case FUNC_DREAD:
return digitalRead( a );

case FUNC_PEEK: case FUNC_PEEK:
return program[a]; return program[a];
case FUNC_ABS: case FUNC_ABS:
if(a < 0) if(a < 0)
return -a; return -a;
return a; return a;

case FUNC_AREAD:
return analogRead( a );
case FUNC_DREAD:
return digitalRead( a );

case FUNC_RND:
return( random( a ));
} }
} }


Expand Down Expand Up @@ -726,6 +747,7 @@ static short int expression(void)
if(a >= b) return 1; if(a >= b) return 1;
break; break;
case RELOP_NE: case RELOP_NE:
case RELOP_NE_BANG:
b = expr2(); b = expr2();
if(a != b) return 1; if(a != b) return 1;
break; break;
Expand Down Expand Up @@ -770,10 +792,16 @@ void loop()
warmstart: warmstart:
// this signifies that it is running in 'direct' mode. // this signifies that it is running in 'direct' mode.
current_line = 0; current_line = 0;
sp = program+sizeof(program); sp = program+sizeof(program);
printmsg(okmsg); printmsg(okmsg);


prompt: prompt:
if( triggerRun ){
triggerRun = false;
current_line = program_start;
goto execline;
}

getln('>'); getln('>');
toUppercaseBuffer(); toUppercaseBuffer();


Expand Down Expand Up @@ -952,6 +980,8 @@ interperateAtTxtpos:
goto files; goto files;
case KW_LIST: case KW_LIST:
goto list; goto list;
case KW_CHAIN:
goto chain;
case KW_LOAD: case KW_LOAD:
goto load; goto load;
case KW_MEM: case KW_MEM:
Expand Down Expand Up @@ -1004,6 +1034,7 @@ interperateAtTxtpos:
goto print; goto print;
case KW_POKE: case KW_POKE:
goto poke; goto poke;
case KW_END:
case KW_STOP: case KW_STOP:
// This is the easy way to end - set the current line to the end of program attempt to run it // This is the easy way to end - set the current line to the end of program attempt to run it
if(txtpos[0] != NL) if(txtpos[0] != NL)
Expand All @@ -1022,13 +1053,17 @@ interperateAtTxtpos:
case KW_DWRITE: // DWRITE <pin>, HIGH|LOW case KW_DWRITE: // DWRITE <pin>, HIGH|LOW
isDigital = true; isDigital = true;
goto dwrite; goto dwrite;


case KW_RSEED:
goto rseed;

case KW_DEFAULT: case KW_DEFAULT:
goto assignment; goto assignment;
default: default:
break; break;
} }



execnextline: execnextline:
if(current_line == NULL) // Processing direct commands? if(current_line == NULL) // Processing direct commands?
goto prompt; goto prompt;
Expand Down Expand Up @@ -1427,7 +1462,13 @@ files:
#endif #endif




chain:
runAfterLoad = true;

load: load:
// clear the program
program_end = program_start;

// load from a file into memory // load from a file into memory
#if ENABLE_FILEIO #if ENABLE_FILEIO
{ {
Expand All @@ -1448,6 +1489,7 @@ load:


fp = SD.open( (const char *)filename ); fp = SD.open( (const char *)filename );
inFromFile = true; inFromFile = true;
inhibitOutput = true;
#else #else
// Desktop specific // Desktop specific
#endif #endif
Expand All @@ -1459,6 +1501,8 @@ load:
#else #else
goto unimplemented; goto unimplemented;
#endif #endif




save: save:
// save from memory out to a file // save from memory out to a file
Expand Down Expand Up @@ -1499,6 +1543,19 @@ save:
#else #else
goto unimplemented; goto unimplemented;
#endif #endif
rseed:
{
short int value;

//Get the pin number
expression_error = 0;
value = expression();
if(expression_error)
goto qwhat;

randomSeed( value );
goto run_next_statement;
}


} }


Expand Down Expand Up @@ -1591,7 +1648,13 @@ static int inchar()
if( v == NL ) v=CR; // file translate if( v == NL ) v=CR; // file translate
if( !fp.available() ) { if( !fp.available() ) {
inFromFile = false; inFromFile = false;
inhibitOutput = false;
fp.close(); fp.close();

if( runAfterLoad ) {
runAfterLoad = false;
triggerRun = true;
}
} }
return v; return v;
} else { } else {
Expand Down Expand Up @@ -1619,6 +1682,8 @@ static int inchar()
/***********************************************************/ /***********************************************************/
static void outchar(unsigned char c) static void outchar(unsigned char c)
{ {
if( inhibitOutput ) return;

#if ARDUINO #if ARDUINO
#if ENABLE_FILEIO #if ENABLE_FILEIO
if( outToFile ) { if( outToFile ) {
Expand Down Expand Up @@ -1663,6 +1728,7 @@ static int initSD( void )
// and our file redirection flags // and our file redirection flags
outToFile = false; outToFile = false;
inFromFile = false; inFromFile = false;
inhibitOutput = false;


return kSD_OK; return kSD_OK;
} }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -20,19 +20,19 @@ PS2 input devices and LCD output devices.


## Files, System ## Files, System
- BYE - *exits Basic, soft reboot on Arduino* - BYE - *exits Basic, soft reboot on Arduino*
- END - *stops execution from the program, also "STOP"*
- FILES - *lists the files on the SD card* - FILES - *lists the files on the SD card*
- LOAD filename.bas - *loads a file from the SD card* - LOAD filename.bas - *loads a file from the SD card*
- MEM - *displays memory usage statistics* - MEM - *displays memory usage statistics*
- NEW - *clears the current program* - NEW - *clears the current program*
- RUN - *executes the current program* - RUN - *executes the current program*
- SAVE filename.bas - *saves the current program to the SD card, overwriting* - SAVE filename.bas - *saves the current program to the SD card, overwriting*
- STOP - *stops execution from the program (ie "END")*


## IO, Documentation ## IO, Documentation
- PRINT expression - *print out the expression, also "?"*
- REM stuff - *remark/comment, also "'"*
- PEEK( address ) - *set a value in memory* - PEEK( address ) - *set a value in memory*
- POKE - *get a value in memory* - POKE - *get a value in memory*
- PRINT expression - *print out the expression, also "?"*
- REM stuff - *remark/comment, also "'"*


## Expressions, Math ## Expressions, Math
- A=V, LET A=V - *assign value to a variable* - A=V, LET A=V - *assign value to a variable*
Expand Down

0 comments on commit 4ffef42

Please sign in to comment.