FemtoBasic for the Demo Board and TV

I've been enhancing the "SimpleBasic" which was a variation of the "Tandy Color Basic" copy for the Propeller posted some months ago by Radical Eye Software (Rokicki). It's now at a point where it's quite useful. Extensions include support for Rokicki's SD card FAT file system drivers for saving programs and data.
INPUT {"prompt";} <var>{,<var>} An optional prompt and a list of variables. The comma separated values may be arbitrary expressions all on one line.
OPEN "file",a/r/w Mode is Append/Read/Write. Only one file can be open at a time.
READ <var>{,<var>} The comma separated values may be arbitrary expressions all on one line. Each READ reads a line.
WRITE ... Works like PRINT, but writes to the open file
CLOSE Closes any open file
DELETE "file" Deletes the file
FILES Displays a list of the files in the root directory of the card
SAVE {"file"} Saves the program to the end of the boot EEPROM or to the specified file
LOAD {"file"} Loads the program from the end of the boot EEPROM or from the specified file
FOR <var> = <expr> TO <expr> {STEP <expr>}
NEXT <var> Note: FOR/NEXT variables must match. There's no checking for nesting errors
STOP Stops the program (END is treated the same)
DISPLAY <expr> {,<expr>} Displays the characters whose values are given (this uses the OS display drivers so those control codes are accepted)
PAUSE <expr> {,<expr>} The first value is in ms, the second is optional and in us (and they're added together). Minimum is 50us
Pseudo variables include: PHSA, PHSB, FRQA, FRQB, CTRA, CTRB which can be used like variables. CNT is read-only.
KEYCODE is zero if no keys have been pressed or the first keycode if there's one present. The keypress is removed from the buffer.
INA and OUTA use the same notation as in Spin for single bits and bit ranges, but set the I/O direction as needed for the operation.
OUTA is write-only. Only single I/O pins and I/O pin ranges are allowed, not the whole register.
BYTE, WORD, and LONG use the same notation as in Spin for addresses and can be on either side of an assignment.
Additional operators: SHL, SHR, ROL, ROR, SAR, REV are <<, >>, <-, ->, ~>, >< respectively. //, AND, OR, NOT, &, |, ^, ! are all allowed
Hexadecimal and binary numbers as well as character values are allowed as in Spin, but without the underline character.
Note: The SD card driver uses I/O pins 0 through 3 with the definitions at the beginning of the "SimpleBasic.spin" source file. If you don't use the file I/O,
you don't have to have the SD card socket. This program will work with the plain Propeller Demo Board and, with a change to the constants in "OS_loader",
can be recompiled for the Hydra although the SD card I/O pins will have to be relocated, probably to the expansion card I/O pins.
Currently, the program is too large to use with the VGA drivers. Eventually this will be addressed.
This is still buggy, but well enough tested to be useful. A sample program that works is:
Pressing the Esc key while a program is executing causes the program to stop, closes any open file and resets the I/O pins.
Post Edited (Mike Green) : 1/9/2007 6:32:37 AM GMT
INPUT {"prompt";} <var>{,<var>} An optional prompt and a list of variables. The comma separated values may be arbitrary expressions all on one line.
OPEN "file",a/r/w Mode is Append/Read/Write. Only one file can be open at a time.
READ <var>{,<var>} The comma separated values may be arbitrary expressions all on one line. Each READ reads a line.
WRITE ... Works like PRINT, but writes to the open file
CLOSE Closes any open file
DELETE "file" Deletes the file
FILES Displays a list of the files in the root directory of the card
SAVE {"file"} Saves the program to the end of the boot EEPROM or to the specified file
LOAD {"file"} Loads the program from the end of the boot EEPROM or from the specified file
FOR <var> = <expr> TO <expr> {STEP <expr>}
NEXT <var> Note: FOR/NEXT variables must match. There's no checking for nesting errors
STOP Stops the program (END is treated the same)
DISPLAY <expr> {,<expr>} Displays the characters whose values are given (this uses the OS display drivers so those control codes are accepted)
PAUSE <expr> {,<expr>} The first value is in ms, the second is optional and in us (and they're added together). Minimum is 50us
Pseudo variables include: PHSA, PHSB, FRQA, FRQB, CTRA, CTRB which can be used like variables. CNT is read-only.
KEYCODE is zero if no keys have been pressed or the first keycode if there's one present. The keypress is removed from the buffer.
INA and OUTA use the same notation as in Spin for single bits and bit ranges, but set the I/O direction as needed for the operation.
OUTA is write-only. Only single I/O pins and I/O pin ranges are allowed, not the whole register.
BYTE, WORD, and LONG use the same notation as in Spin for addresses and can be on either side of an assignment.
Additional operators: SHL, SHR, ROL, ROR, SAR, REV are <<, >>, <-, ->, ~>, >< respectively. //, AND, OR, NOT, &, |, ^, ! are all allowed
Hexadecimal and binary numbers as well as character values are allowed as in Spin, but without the underline character.
Note: The SD card driver uses I/O pins 0 through 3 with the definitions at the beginning of the "SimpleBasic.spin" source file. If you don't use the file I/O,
you don't have to have the SD card socket. This program will work with the plain Propeller Demo Board and, with a change to the constants in "OS_loader",
can be recompiled for the Hydra although the SD card I/O pins will have to be relocated, probably to the expansion card I/O pins.
Currently, the program is too large to use with the VGA drivers. Eventually this will be addressed.
This is still buggy, but well enough tested to be useful. A sample program that works is:
100 rem Blink some LEDs 110 for i = 0 to 7 120 gosub 200 130 next i 140 stop 200 rem Make an LED blink 210 outa[noparse][[/noparse]16+i]=1 220 pause 500 230 outa[noparse][[/noparse]16+i]=0 240 pause 500 250 return
Pressing the Esc key while a program is executing causes the program to stop, closes any open file and resets the I/O pins.
Post Edited (Mike Green) : 1/9/2007 6:32:37 AM GMT
zip

90K
Comments
I downloaded it, will play with it tomorrow.
There are now TWO ways of programming a propeller by itself:
- Cliff's Forth
- Rokicki's port of CoCo basic with your extensions!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com - a new blog about microcontrollers
One bug: if you hit any key while a program is running, escape no longer works.
Because the BASIC I wrote is so slow (it's an interpreted basic run by another interpreter) it's pretty
slow (but still very useful!) Here's some things we should consider doing:
1. Make it target spin bytecodes instead of interpreting everything itself. This way it would be
(nearly) as fast as SPIN!
2. Make it load and run external spin objects! We can do this by defining a symbol table format
for spin binaries and storing the spin binaries on the SD card. This way you could put all the
custom code in native spin/assembly, and play with it in BASIC using a very nice REPL
environment.
Hehe, this right here is very nearly my prototype for a retro microcomputer replacement. You
could put this on one of the new cheap protoboards with an SD socket and an RCA plug or two
and make a microcomputer pretty cheap.
my 0.95.1 would not compile the program) so if you haven't already done it, you will need to download
the latest propeller tool. Since I've heard some people are having troubles when they install newer
FTDI drivers, I told it *not* to install the new drivers, and everything works here for me.
Thanks for pointing out the problem with using the ESC code. I'm not sure what to do about that since I want to allow the user to read the keyboard input
yet the interpreter has to look for some way to interrupt the program and the keyboard driver is buffered. What's needed is a keycode that clears the keyboard
buffer when it's entered, maybe the SysRq or Break keys. I'll figure out something. Suggestions are welcome.
Mike
I remember programming my first programs in basic on the c64.
Andre'
If you don't need the SD card stuff, you can just recompile it as I mentioned. In the OS_loader.spin object, there are two constant declarations (for Parallax and TV). As described in the comments, you set Parallax to false and leave TV true, then recompile. The reason I haven't done it yet is that the SD driver will attempt to access an SD card via I/O pins 0-3. I haven't decided how to connect the SD card to the Hydra expansion slot and I need to experiment a bit. I don't want to use the VGA pins if I can avoid it since I want a VGA version to be available. I need to see what other pins I could use (like the HydraNet lines, maybe the I2C SDA line without a clock, etc.)
Mike
Andre'
I havn't tried this program yet, but to me it seems like the fullest version of basic for the prop todate.
Just don't use the FILES/OPEN/READ/WRITE/CLOSE statements and don't use the LOAD/SAVE commands with a file name included.
The LOAD/SAVE commands work otherwise (saving to the boot EEPROM).
I just ordered it last night after months of waiting.
Mike
- Earl
·
In the case of the Demo Board, you just have to wire 6 of the SD card pins to +3.3V-Vcc, Gnd-Gnd, DO-I/OPin0, Clk-I/OPin1, DI-I/OPin2, CS-I/OPin3. In the case of the Hydra, you'll have to use a memory expansion or I/O expansion card and wire up a cable (I used the two ends of a 3-pin servo cable and cut it in half) with +3.3V-33VCC, Gnd-Gnd, DO-I/O_0, Clk-I/O_1, DI-I/O_2, CS-I/O_3.
I added another statement that's quite useful for the Hydra and will probably be similarly useful for the Proto Board.
EEPROM[noparse][[/noparse] <addr> ] This is a pseudo-variable that can be referenced and set. The address can range from $00000 to $7FFFF. The upper 3 bits are used to select which EEPROM while the lower 16 bits are used to address within a particular 64K address space. For the Demo Board, the only valid addresses are $0000 to $7FFF. Others will cause an error. The Basic interpreter uses the last 8210 bytes of the EEPROM to store the user's program with SAVE/LOAD with the exception of the last 16 bytes ($7FF0-$7FFF). These and the space before the program storage area are available for experimentation. The Hydra has EEPROM from $00000 to $1FFFF using just the main board and from $00000 to $3FFFF when using an expansion card. The Proto Board will have EEPROM from $0000 to $FFFF.
This current version uses slow routines for both I2C and SD card access written in Spin. After some testing, I will post a version with assembly routines for both that'll be much faster.
Addendum: There was a bug in the input routine such that it didn't handle backspace from the keyboard properly. This is fixed.
Post Edited (Mike Green) : 1/11/2007 10:07:58 PM GMT
My problem with the Femtobasic is in the SAVE command.
When I try to save a program to the builtin eeprom I get many EEPROM timeout messages.
When I do not get an error it only seems to save a few bytes, scrambles some and then writes some more
Any thoughts about this problem?
P.S. It seems to me that much of the code written for the Propeller here has poor memory allocation.
I see lots of stuf thrown in upper memory without the compiler doing the allocation.(video drivers especialy)
In trying to figure out this problem I changed your code to allocate the program as I thought it should be done.
Seems to work Ok , but it still won't save properly. Do eeprom writes need to be on boundries?
Post Edited (Perry) : 1/31/2007 11:17:20 PM GMT
I think I have that fixed.· I'll see if I can get an update posted sometime this evening.· I've been trying to get the SD routines integrated into the Propeller OS and that's taking a lot more time than I expected.· I'm actually using FemtoBasic as a testbed.· It's very helpful to be able to write little test programs in Basic and, in my testbed version, I've got·a bunch of additional statements and pseudo-variables that let me call low level routines and display internal variables as I try to debug the stuff.
Mike
I've included a brief description of some of the Basic extensions in a FemtoBasic Notes file.
This now uses both the Combined Demo Board/Hydra Keyboard Driver and the Basic I2C Driver now in the Propeller Object Exchange along with Tomas Rokicki's SD card driver also in the Propeller Object Exchange.
I compiled your FemtoBasic and it works on my system with no changes
the save function seems to work OK now but I still get som EEPROM errors on writing
I have the HM55B on pins 1,2,3 , the TriAxisAccelometer on 5,4,3, and a LM1881 on 6,7
been trying to get a heads up display with overlay working. succesfully integrated your code and the HITT overlay
but I really want to use more robust graphic functions. It's probably be 30 years since i did any serious assembly programing
(RCA COSMAC, and Z80)
I would like to see a automatic load and run on the FemtoBasic
if it finds something in eeprom and ignore not haveing any keyboard?
also I changed the LIST in "texec", your going to want this if you have long basic programs
I have added HELP too
also in "factor" i added MEM to show available space in basic code store
i'll try to get BRANCH working next
keep up the good work
Perry
Post Edited (Perry) : 2/4/2007 4:26:52 AM GMT
Biggest change is that multiple statements on a line works. This allows you to do chaining by using something like 'LOAD "overlay":RUN' or 'LOAD "overlay":GOTO 100'. It may also make for a more compact listing with the limited display space on a TV.
Could you please post the hydra version over on the hydra forum.
Thanks,Brian
Nice job Mike!
I was able to write some minimal programs without even reading the RTF [noparse]:)[/noparse]
One question though, is there a way to delete a single line? For example, I was playing around and typed 8888 / (meaningless) and I couldn't get rid of it without starting over.
I would recommend that you find a single upload location and keep the current version there. Maybe SourceForge?
It can get a little hard to keep up with all the changes when you're attaching new versions throughout the thread. Just a thought.
Thanks for the update,
Rich
You're supposed to be able to type just the line number (as in most Basics) and that should delete the line. Let me know if that doesn't work. This implementation doesn't allow you to delete multiple lines at a time (you have to do each one separately).
In the next week or two, after I test it some more, I plan to upload it to the Object Exchange. I already have another bug or two fixed and I want it to stabilize a bit more. I know it can get a bit hard to keep up, but it's still evolving. With the current features, I think it's time to pause. I have a slightly different version for use with the BOE-BOT. It runs on the Spin Stamp, but I'll convert it over to use the Propeller Proto Board once that comes out. It supports 3 servos, a PING, HM-55B compass, an IR emitter/detector and uses an xBee for wireless programming/control. I'll upload that as well once the Proto Board version is working.
Cool, that makes sense. I should have tried that.
That's an impressive feature list!
Rich
It makes a circular something that resembles a cross-section of the Earth, with a core of zeros and higher numbers as you go out in layers.
You can add the following lines to add a little color:
Note that these use the control codes for the windowed text display routines
by Phil Pilgrim (http://forums.parallax.com/showthread.php?p=590631).
Edit: You get a real neat effect with the color using "165 DISPLAY 7, e/2"
If you use "165 DISPLAY y, e/2", it crashes Femtobasic!
Post Edited (Dennis Ferron) : 2/5/2007 5:13:14 AM GMT