The Hackaday BASIC interpreter is based on the uBASIC project by Adam Dunkels. This provided a tokenizer and the most rudimentary words needed for the language to operate. From there, Jaromir Sukuba greatly expanded the word set to take advantage of the best the badge hardware has to offer.
We are also testing out an advancement in the tokenizer written by @ziggurat29 which shows a speed-up of as much as 40x!
The reference for all of the words is listed below. You may also see examples of these words in use by viewing the example code project log.
Of Note:
- Code in the program buffer can be viewed one page at a time by typing
more
. You can overwrite lines just by typing the line number at the prompt along with your new commands. It is recommended that you number every 10 lines or more so that you can add commands in between them as you develop your code. - The
memclr
word will clear the code currently in the program buffer. - Always save before running in case you have to reset the badge.
save 0
will save to the first of 16 slots,load 0
will load the saved code. - Press the BRK key to break out of a running program
- Typing a line number without anything after it will delete that line from your program
- There are two print commands.
print
will not include a line feed,println
will include a line feed
BASIC Word List:
Standard Words:
print
println
if
goto
gosub
return
for
next
end
let
rem
Badge Custom Words
led X,Y
- control LED, X[0..2] RGB, Y[0..1] on/offtune A,B,C,D
- plays tones A, B, C for duration Dclrscr
- clear screensetxy X,Y
- set cursor at X,Ywait X
- wait for X mscolor X,Y
- X=Foreground, Y=Background using EGA 16-color palettechr X
- prints character with ASCII representation Xtermt X
- sets VT100 terminal on or off (1-on, 0-off)termup
- forces screen refresh, if VT100 terminal is offrnd X
- function to return random number 0..Xein X
- function to return value of expansion pin Xeout X,Y
- control expansion pin, X[0..3], Y[0..1] on/off (pin 0 is labelled "G2", 1="G3", 2="B0", 3="B1")edr X,Y
- sets expansion pin function X[0..3], Y[0..1] output/inputuin X
- function to return received byte from serial port, if X=0, function is non-blocking, if X=1, function is blockinguout X
- outputs value X to serial port as single byteinput "string"
- prints string and returns user entered valuepeek X
- returns value from memory location Xpoke X,Y
- write value Y into memory, on location Xcursor X
- turns cursor on (X=1) or off (X=0)kin X
- function to return byte from keyboard, if X=0, function is non-blocking, if X=1, function is blocking
BASIC CLI commands
run
- runs programsave X
- Save program buffer to flash. There are 16 slots: X[0..15]load X
- Load program into buffer from flash. There are 16 slots: X[0..15]list
- list whole programmore
- list program by pagesmemclr
- clears all code from the program bufferfree
- prints amount of free program buffersload
- load new program into buffer from serial portssave
- output program buffer via serial porthelp
- short help
Aliases
In order to save you some typing, we defined some aliases for functions
print
-pnt
println
-ptl
clrscr
-cls
,clr
input
-inp
setxy
-sxy
return
-ret
cursor
-cur
Gotchas
There are a few gotchas that you may run into if really go wild with your BASIC program. Here's a few to keep in mind for those who care to read them:
- There is a line limit of about 70 characters (just shy of two lines on the badge's scree). If you type more characters than this, your command will be truncated.
- If you're using the GPIO pins and you press the power button while your program is running, you will need to reinitialize the IO pins after you turn the badge back on. You can work around this by making sure you re-initialize the direction and pin values frequently in your looping programs and not just at the beginning.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
This is rad, can't wait to try it out! I grew up with my Dad's IBM work computer, and the Radio Shack something-or-other we had in 1985, but never had a C64, or ZX type computer, so it will be really neat to have a dedicated retro-computer to try programming for :) Can't wait to see what people will do with these before the conference is over!
Are you sure? yes | no