Download data/Basic2/Posix/basic.h from introvoyz041/tinybasic: direct link, hf CLI and curl.
- Browser
- Download file 20.3 kB
-
https://huggingface.co/datasets/introvoyz041/tinybasic/resolve/main/data/Basic2/Posix/basic.h
- Command line
-
hf download hf://datasets/introvoyz041/tinybasic/data/Basic2/Posix/basic.h
-
curl -L -o basic.h https://huggingface.co/datasets/introvoyz041/tinybasic/resolve/main/data/Basic2/Posix/basic.h
20.3 kB
| /* | |
| * | |
| * $Id: basic.h,v 1.1 2023/09/27 15:23:20 stefan Exp stefan $ | |
| * | |
| * Stefan's basic interpreter | |
| * | |
| * See the licence file on | |
| * https://github.com/slviajero/tinybasic for copyright/left. | |
| * (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007) | |
| * | |
| * Author: Stefan Lenz, sl001@serverfabrik.de | |
| * | |
| * basic.h are the core defintions and function protypes. | |
| * | |
| */ | |
| /* | |
| * A few of the buffers and vars come from hardware.h. These are | |
| * | |
| * #define BUFSIZE | |
| * #define STACKSIZE | |
| * #define GOSUBDEPTH | |
| * #define FORDEPTH | |
| * #define LINECACHESIZE | |
| * | |
| * They depend on the hardware architecture and are configured there. | |
| * | |
| */ | |
| /* Additional buffers and vars, VARSIZE only needed for Tinybasics */ | |
| /* Default sizes of arrays and strings if they are not DIMed */ | |
| /* the maximum name length */ | |
| /* | |
| * The tokens for the BASIC keywords | |
| * | |
| * All single character operators are their own tokens | |
| * ASCII values above 0x7f are used for tokens of keywords. | |
| * EOL is a token. | |
| * | |
| * The two byte tokens are possible to extend the language beyond | |
| * 127 keywords. | |
| */ | |
| /* multi character tokens - BASEKEYWORD (3) */ | |
| /* this is the Palo Alto Language Set (19) */ | |
| /* this is the Apple 1 language set in addition to Palo Alto (14) */ | |
| /* Stefan's tinybasic additions (14) */ | |
| /* Arduino functions (10) */ | |
| /* the DOS functions (5) */ | |
| /* low level access of internal routines (2) */ | |
| /* mathematical functions (7) */ | |
| /* graphics - rudimentary (7) */ | |
| /* the Dartmouth extensions (6) */ | |
| /* darkarts (3) */ | |
| /* iot extensions (9) */ | |
| /* events and interrupts */ | |
| /* structured commands */ | |
| /* multiline function extension */ | |
| /* these are multibyte token extension, currently unused */ | |
| /* using them would allow over 1000 BASIC keywords */ | |
| /* end of tokens */ | |
| /* constants used for some purposes other than token */ | |
| /* Indentifying a buffer on the heap */ | |
| /* UNKNOWN is not used in the current code, the | |
| * lexer tokenizes everything blindly. There is a UNKNOWN hook | |
| * in statement for a grammar aware lexer */ | |
| /* alternative implementation using positive token values */ | |
| /* The editor and other helpers */ | |
| /* bitwise operations, avoid 10 as a token value */ | |
| /* | |
| * Extension tokens can be in the range from -128 upwards. | |
| * one needs to set HASLONGTOKENS. Currently ony one set of | |
| * extension tokens is implemented ranging from -128 to -255. | |
| * | |
| * **** right now unused and untested **** */ | |
| /* BASEKEYWORD is used by the lexer. From this keyword on it tries to match. */ | |
| /* | |
| * Interpreter states | |
| * SRUN means running from a programm | |
| * SINT means interactive mode | |
| * SERUN means running directly from EEPROM | |
| * (enum would be the right way of doing this.) | |
| */ | |
| /* | |
| * the message catalog | |
| */ | |
| /* | |
| * code for variable numbers and addresses sizes | |
| * the original code was 16 bit but can be extended here | |
| * to arbitrary types | |
| * | |
| * number_t is the type for numerical work - either float or int | |
| * wnumber_t is the type containing the largest printable integer, | |
| * for float keep this int on 32 bit and long on 8 bit unless you | |
| * want to use very long integers, like 64 or 128 bit types. | |
| * address_t is an unsigned type adddressing memory, default 16bit | |
| * mem_t is a SIGNED 8bit character type. | |
| * index_t is a SIGNED minimum 16 bit integer type | |
| * | |
| * works with the tacit assumption that | |
| * sizeof(number_t) >= sizeof(address_t) | |
| * and that the entire memory is smaller than the positive | |
| * part of number type (!!) | |
| * | |
| * we assume that float >= 4 bytes in the following | |
| * | |
| * maxnum: the maximum accurate(!) integer of a | |
| * 32 bit float | |
| * strindexsize: the index size of strings either | |
| * 1 byte or 2 bytes - no other values supported | |
| */ | |
| typedef double number_t; | |
| typedef long long wnumber_t; | |
| typedef float number_t; | |
| typedef long long wnumber_t; | |
| typedef int64_t number_t; | |
| typedef int64_t wnumber_t; | |
| typedef int32_t number_t; | |
| typedef int32_t wnumber_t; | |
| typedef int number_t; | |
| typedef int wnumber_t; | |
| /* default is 16bit addresses and max 64k memory, setting MEMSIZE in hardware.h overrides this */ | |
| typedef uint16_t address_t; /* this type addresses memory */ | |
| /* use this for large memory systems, tested occassionally */ | |
| typedef uint32_t address_t; | |
| typedef int8_t mem_t; /* a signed 8 bit type for the memory */ | |
| typedef int index_t; /* this type counts at least 16 bit */ | |
| typedef int8_t token_t; /* the type of tokens, normally mem_t with a maximum of 127 commands and data types */ | |
| typedef int16_t token_t; /* token type extension, allows more commands and symbols */ | |
| /* the memreader function type, a function accessing memory has to have this shape */ | |
| typedef mem_t (*memreader_t)(address_t); | |
| typedef void (*memwriter_t)(address_t, mem_t); | |
| /* the worker function type - experimental */ | |
| typedef void (*bworkfunction_t)(); | |
| /* the location type, this is the cursor on the actual interpreter location */ | |
| typedef struct { | |
| address_t location; | |
| token_t token; | |
| } blocation_t; | |
| /* the new string type used in the reimplementation of the string functions */ | |
| /* | |
| * stringlength_t is the maximum length of a string, currently only 2 bytes is really tested. | |
| * one byte lengthes may work, will be fixed soon to arbitrary types | |
| * | |
| * string_t says where we can find a string. It is either in BASIC memory and has a valid BASIC memory | |
| * address a, or it is in C memory outside mem[]. Then ir says where the string can be found. | |
| * This is necessary because BASIC can handle different memory layouts, EEPROM models and serial | |
| * memory chips. We cannot simply rely on data to be found in BASIC memory like in old 8 bit | |
| * computers or all in C memory like on modern Linux/Windows/Mac systems. | |
| * | |
| * Components of the string_t: | |
| * - the address of the string in BASIC memory | |
| * - the C memory pointer ir to the string location, if this is 0, the string is somewhere outside C memory | |
| * - the length of the entire string | |
| * - the dimension of the string strdim, this is the length of the memory segment reserved for the string | |
| * - the dimension of the string array, arraydim | |
| */ | |
| typedef uint16_t stringlength_t; | |
| typedef struct { | |
| address_t address; | |
| char* ir; | |
| stringlength_t length; | |
| address_t strdim; | |
| address_t arraydim; | |
| } string_t; | |
| /* | |
| * Two types for identifiying objects and lefthandsides. | |
| * name_t is the type for variable names and types. | |
| * lhsobject_t identifies an assignable object like variables, | |
| * arrays and strings. | |
| * | |
| * Currently name_t only implements two letter objects and lhsobject_t | |
| * only implements two dimensional arrays and one dimensional strings. | |
| */ | |
| typedef struct { | |
| token_t token; | |
| mem_t c[MAXNAME]; | |
| mem_t l; | |
| } name_t; | |
| /* used to identify mostly lefthandsides and some righthandsides with these conventions */ | |
| typedef struct { | |
| name_t name; /* the name of a variable */ | |
| address_t i; /* the start value of a substring or the first index of a number array */ | |
| address_t j; /* the second index of an array */ | |
| address_t i2; /* the second value of a substring string */ | |
| mem_t ps; /* flag to indicate a pure string */ | |
| } lhsobject_t; | |
| /* heap objects have a name a size and a payload address */ | |
| typedef struct { | |
| name_t name; | |
| address_t address; | |
| address_t size; | |
| } heap_t; | |
| /* | |
| * a general loop time, needed for the reimplementation of all loops | |
| * the loop time knows the variable of a for loop or alternatively | |
| * the type of the for loop. For this the token field of the name is | |
| * reused. At also knows the here address of the loops beginning and optinally | |
| * the end and the step | |
| */ | |
| typedef struct { | |
| name_t var; | |
| address_t varaddress; /* experimental to speed up loops */ | |
| address_t here; | |
| number_t to; | |
| number_t step; | |
| } bloop_t; | |
| /* | |
| * The accumulator type, used for the stack and the | |
| * arithmetic operations. | |
| */ | |
| typedef union { | |
| number_t n; | |
| address_t a; | |
| index_t i; | |
| stringlength_t s; | |
| mem_t c[sizeof(number_t)]; | |
| } accu_t; | |
| /* the timer type, knows the linenumber and all the data of the timer */ | |
| typedef struct { | |
| mem_t enabled; | |
| unsigned long last; | |
| unsigned long interval; | |
| mem_t type; | |
| address_t linenumber; | |
| } btimer_t; | |
| /* | |
| * The events API for Arduino with interrupt service routines | |
| * analogous to the timer API. | |
| * | |
| * we use raw modes here | |
| * | |
| * #define CHANGE 1 | |
| * #define FALLING 2 | |
| * #define RISING 3 | |
| * | |
| */ | |
| /* event type for external events */ | |
| typedef struct { | |
| mem_t enabled; | |
| mem_t pin; | |
| mem_t mode; | |
| mem_t type; | |
| address_t linenumber; | |
| mem_t active; | |
| } bevent_t; | |
| /* | |
| * Function prototypes, ordered by layers | |
| * HAL - hardware abstraction | |
| * Layer 0 - memory and I/O | |
| * Layer 1 - Program storage and control | |
| * Layer 2 - Where stuff happens | |
| */ | |
| /* | |
| * Layer 0 functions - I/O and memory management | |
| */ | |
| /* event types and functions */ | |
| void bintroutine0(); | |
| void bintroutine1(); | |
| void bintroutine2(); | |
| void bintroutine3(); | |
| mem_t enableevent(mem_t); | |
| void disableevent(mem_t); | |
| mem_t eventindex(mem_t); | |
| mem_t addevent(mem_t, mem_t, mem_t, address_t); | |
| void deleteevent(mem_t); | |
| volatile bevent_t* findevent(mem_t); | |
| /* make room for BASIC */ | |
| address_t ballocmem(); | |
| /* handle files im EEPROM */ | |
| void eload(); | |
| void esave(); | |
| /* starts programs from the filesystem */ | |
| char autorun(); | |
| /* display a startup banner */ | |
| void displaybanner(); | |
| /* the variable heap from Apple 1 BASIC */ | |
| address_t bmalloc(name_t*, address_t); | |
| address_t bfind(name_t*); | |
| address_t bfree(name_t*); | |
| address_t blength (name_t*); | |
| /* normal variables of number_t */ | |
| number_t getvar(name_t*); | |
| void setvar(name_t*, number_t); | |
| void clrvars(); | |
| /* the new set of functions for memory access */ | |
| number_t getnumber(address_t, memreader_t); | |
| address_t getaddress(address_t, memreader_t); | |
| stringlength_t getstrlength(address_t, memreader_t); | |
| void setnumber(address_t, memwriter_t, number_t); | |
| void setaddress(address_t, memwriter_t, address_t); | |
| void setstrlength(address_t, memwriter_t, stringlength_t); | |
| /* setting names */ | |
| address_t setname_heap(address_t, name_t*); | |
| address_t setname_pgm(address_t, name_t*); | |
| address_t getname(address_t, name_t*, memreader_t); | |
| mem_t cmpname(name_t*, name_t*); | |
| void zeroname(name_t*); | |
| void zeroheap(heap_t*); | |
| /* array and string handling */ | |
| /* the multidim extension is experimental, here only 2 array dimensions implemented as test */ | |
| address_t createarray(name_t*, address_t, address_t); | |
| void array(lhsobject_t*, mem_t, number_t*); | |
| address_t createstring(name_t*, address_t, address_t); | |
| void getstring(string_t*, name_t*, address_t, address_t); | |
| void setstringlength(name_t*, address_t, address_t); | |
| /* the user defined extension functions */ | |
| number_t getusrvar(); | |
| void setusrvar(number_t); | |
| number_t getusrarray(address_t); | |
| void setusrarray(address_t, number_t); | |
| void makeusrstring(); | |
| number_t usrfunction(address_t, number_t); | |
| void usrcall(address_t); | |
| /* get keywords and tokens from PROGMEM */ | |
| char* getkeyword(address_t); | |
| char* getmessage(char); | |
| token_t gettokenvalue(address_t); | |
| void printmessage(char); | |
| /* error handling */ | |
| void error(token_t); | |
| void reseterror(); | |
| void debugtoken(); | |
| void bdebug(const char*); | |
| /* the arithemtic stack */ | |
| void push(number_t); | |
| number_t pop(); | |
| address_t popaddress(); | |
| void drop(); | |
| void clearst(); | |
| /* READ DATA handling */ | |
| void clrdata(); | |
| /* FOR NEXT GOSUB stacks */ | |
| void pushforstack(name_t*, number_t, number_t); | |
| void popforstack(name_t*, number_t*, number_t*); | |
| void dropforstack(); | |
| void clrforstack(); | |
| void pushgosubstack(mem_t); | |
| void popgosubstack(); | |
| void dropgosubstack(); | |
| void clrgosubstack(); | |
| /* handling location rewinds */ | |
| void pushlocation(blocation_t*); | |
| void poplocation(blocation_t*); | |
| /* signal handling */ | |
| void signalon(); | |
| void signaloff(); | |
| void signalhandler(int); | |
| /* output */ | |
| void outcr(); | |
| void outspc(); | |
| void outsc(const char*); | |
| void outscf(const char *, index_t); | |
| /* console logger as external function for runtime */ | |
| void consolelog(char*); | |
| void consolelognum(int); | |
| /* output a name */ | |
| void outname(name_t*); | |
| /* I/O of number_t - floats and integers */ | |
| address_t parsenumber(char*, number_t*); | |
| address_t parsenumbern(char*, number_t*); /* can do hex,oct,bin */ | |
| address_t parsenumber2(char*, number_t*); | |
| address_t writenumber(char*, wnumber_t); | |
| address_t writenumbern(char*, wnumber_t, mem_t); /* can do hex,oct,bin */ | |
| address_t writenumber2(char*, number_t); | |
| address_t tinydtostrf(number_t, index_t, char*); | |
| int innumber(number_t*, char*, address_t); | |
| void outnumber(number_t); | |
| /* | |
| * Layer 1 functions, provide data and do the heavy lifting | |
| * for layer 2 including lexical analysis, storing programs | |
| * and expression evaluation | |
| */ | |
| /* lexical analysis */ | |
| void whitespaces(); | |
| void nexttoken(); | |
| /* storing and retrieving programs */ | |
| char nomemory(number_t); | |
| void storetoken(); | |
| mem_t memread(address_t); | |
| mem_t memread2(address_t); | |
| void memwrite2(address_t, mem_t); | |
| mem_t beread(address_t); | |
| void beupdate(address_t, mem_t); | |
| void gettoken(); | |
| void firstline(); | |
| void nextline(); | |
| void clrlinecache(); | |
| void addlinecache(address_t, address_t); | |
| address_t findinlinecache(address_t); | |
| void findline(address_t); | |
| address_t myline(address_t); | |
| void moveblock(address_t, address_t, address_t); | |
| void zeroblock(address_t, address_t); | |
| void diag(); | |
| void storeline(); | |
| /* read arguments from the token stream and process them */ | |
| char termsymbol(); | |
| char expect(token_t, mem_t); | |
| char expectexpr(); | |
| void parsearguments(); | |
| void parsenarguments(char); | |
| void parsesubscripts(); | |
| void parsefunction(void (*)(), short); | |
| void parseoperator(void (*)()); | |
| void parsesubstring(); | |
| /* mathematics and other functions for int and float */ | |
| void xabs(); | |
| void xsgn(); | |
| void xpeek(); | |
| void xmap(); | |
| number_t rnd(); | |
| void xrnd(); | |
| void sqr(); | |
| void xpow(); | |
| number_t bpow(number_t, number_t); | |
| /* string values and string evaluation */ | |
| void parsestringvar(string_t*, lhsobject_t*); | |
| char stringvalue(string_t*); | |
| void streval(); | |
| /* floating point functions */ | |
| void xsin(); | |
| void xcos(); | |
| void xtan(); | |
| void xatan(); | |
| void xlog(); | |
| void xexp(); | |
| void xint(); | |
| /* expression evaluation */ | |
| void factor(); | |
| void power(); | |
| void term(); | |
| void addexpression(); | |
| void compexpression(); | |
| void notexpression(); | |
| void andexpression(); | |
| void expression(); | |
| /* real time clock string stuff */ | |
| void rtcmkstr(); | |
| /* | |
| * Layer 2 - statements and functions | |
| * use the global variables | |
| */ | |
| /* basic commands of the core language set */ | |
| void xprint(); | |
| void getstringtobuffer(string_t*, char*, stringlength_t); | |
| void lefthandside(lhsobject_t*); | |
| void assignnumber(lhsobject_t, number_t); | |
| void assignstring(string_t*, string_t*, stringlength_t); | |
| void assignment(); | |
| void showprompt(); | |
| void xinput(); | |
| void xgoto(); | |
| void xreturn(); | |
| void xif(); | |
| /* FOR NEXT loops */ | |
| void findnextcmd(); | |
| void findbraket(token_t, token_t); | |
| void xfor(); | |
| void xbreak(); | |
| void xcont(); | |
| void xnext(); | |
| /* WHILE WEND*/ | |
| void xwhile(); | |
| void xwend(); | |
| /* REPEAT UNTIL */ | |
| void xrepeat(); | |
| void xuntil(); | |
| /* control commands and misc */ | |
| void outputtoken(); | |
| void xlist(); | |
| void xrun(); | |
| void xnew(); | |
| void xrem(); | |
| void xclr(); | |
| void xdim(); | |
| void xpoke(); | |
| void xtab(); | |
| void xdump(); | |
| void dumpmem(address_t, address_t, char); | |
| void xlocate(); | |
| /* file access and other i/o */ | |
| void stringtobuffer(char*, string_t*); | |
| void getfilename(char*, char); | |
| void xsave(); | |
| void xload(const char*); | |
| void xget(); | |
| void xput(); | |
| void xset(); | |
| void xnetstat(); | |
| /* Arduino IO control interface */ | |
| void xaread(); | |
| void xdread(); | |
| void xdwrite(); | |
| void xawrite(); | |
| void xpinm(); | |
| void xdelay(); | |
| void xtone(); | |
| void btone(int); | |
| void bpulsein(); | |
| /* graphics commands */ | |
| void xcolor(); | |
| void xplot(); | |
| void xline(); | |
| void xrect(); | |
| void xcircle(); | |
| void xfrect(); | |
| void xfcircle(); | |
| /* the darkarts */ | |
| void xmalloc(); | |
| void xfind(); | |
| void xeval(); | |
| /* IoT commands */ | |
| void xavail(); | |
| void xfsensor(); | |
| void xsleep(); | |
| void xwire(); | |
| void xfwire(); | |
| /* timers */ | |
| void xafter(); | |
| void xevent(); | |
| /* File I/O functions */ | |
| char streq(const char*, char*); | |
| void xcatalog(); | |
| void xdelete(); | |
| void xopen(); | |
| void xfopen(); | |
| void xclose(); | |
| void xfdisk(); | |
| /* low level access functions */ | |
| void xcall(); | |
| void xusr(); | |
| /* the dartmouth stuff */ | |
| void xdata(); | |
| void nextdatarecord(); | |
| void xread(); | |
| void xrestore(); | |
| void xdef(); | |
| void xfn(mem_t); | |
| void xon(); | |
| /* timers and interrupts */ | |
| void xtimer(); | |
| void resettimer(btimer_t*); | |
| /* structured BASIC extensions */ | |
| void xwhile(); | |
| void xwend(); | |
| void xrepeat(); | |
| void xuntil(); | |
| void xswitch(); | |
| void xcase(); | |
| void xendswitch(); | |
| /* the editor */ | |
| void xedit(); | |
| /* the statement loop */ | |
| void statement(); | |
| /* the extension functions */ | |
| void bsetup(); | |
| void bloop(); | |