Shop OBEX P1 Docs P2 Docs Learn Events
FemtoBasic for the Demo Board and TV — Parallax Forums

FemtoBasic for the Demo Board and TV

Mike GreenMike Green Posts: 23,101
edited 2007-02-20 18:24 in Propeller 1
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:
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
«1

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2007-01-07 07:42
    Way to go!

    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
  • rokickirokicki Posts: 1,000
    edited 2007-01-07 08:10
    Wow, that's awesome! This is so fun. It's now the default program on my demo board!

    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.
  • rokickirokicki Posts: 1,000
    edited 2007-01-07 08:11
    Note that this program uses the new "ifnot" construct in SPIN (I wasn't aware of this construct, but
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-07 15:08
    Rokicki,
    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
  • Ym2413aYm2413a Posts: 630
    edited 2007-01-07 18:39
    Oh my! That's so cool!!!
    I remember programming my first programs in basic on the c64.
  • AndreLAndreL Posts: 1,004
    edited 2007-01-08 00:55
    Hey where's the HYDRA version of it!

    Andre'
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-08 01:33
    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
  • AndreLAndreL Posts: 1,004
    edited 2007-01-08 03:43
    The hydra net lines are good candidates since you don't need them, and you could probably steel a line from the i2c or the usb lines that go to the serial interface that wont make a diff once the prop is running.

    Andre'
  • Ym2413aYm2413a Posts: 630
    edited 2007-01-08 03:57
    I agree. I feel that this should really be ported to the Hydra!
    I havn't tried this program yet, but to me it seems like the fullest version of basic for the prop todate.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-08 07:21
    Here's a copy recompiled for the Hydra. The SD card FAT stuff DOESN'T WORK at the moment on the Hydra and will do strange things.
    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).
  • Ym2413aYm2413a Posts: 630
    edited 2007-01-08 14:59
    Awesome, I'm trying this out once my Hydra comes in.
    I just ordered it last night after months of waiting.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-09 06:38
    I've updated the archive at the beginning of the thread. The only change is that the Demo Board and Hydra keyboard drivers have been combined. This reduces the amount of code that has to be loaded. For those interested, the start routine takes the starting pin # for a group of 2 pins for the Demo Board or the starting pin# + 1 for a group of 4 pins for the Hydra. I've included binaries for both the Demo Board and the Hydra. As before, the SD card I/O doesn't work on the Hydra for some reason that I don't understand as yet.

    Mike
  • RetrobitsRetrobits Posts: 46
    edited 2007-01-09 19:11
    Can't wait to try this.· I have a SparkFun·SD card breakout board on the way (hope my fledgling soldering skills are at least decent enough to hook up the break-away header).· I've had·some existing·plans for a project using rokicki's SD routines, but now I've got a new language to play around with as well!· Great stuff.

    - Earl
    ·
  • Ym2413aYm2413a Posts: 630
    edited 2007-01-09 19:56
    Who knows, this might become the next Quick-Basic only propellerized! *grins*
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-11 21:22
    Attached is a new version of FemtoBasic for the Demo Board and the Hydra. There are some constants at the beginning that have to be set properly and some lines that are different for the Demo Board and the Hydra versions with the opposite lines commented out. I've precompiled versions for the Demo Board and the Hydra. The SD card routines work now on both.

    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
  • PerryPerry Posts: 253
    edited 2007-01-31 19:40
    I have been working with the Propeller for about a month now. It's a great little machine.

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-31 21:16
    Perry,

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-01 03:25
    Here's the corrected version of FemtoBasic with pre-compiled binaries for both the Demo Board and the Hydra. I've added two statements, one for doing a formatted dump of a portion of Hub memory and the other to allow reading and writing of a file on an SD card character by character.

    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.
  • PerryPerry Posts: 253
    edited 2007-02-02 22:20
    Thanks for the update, Mike
    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
      137: ' LIST {<expr>} {,<expr>}
                    beginList := 0
                    endList := 65535                        
                    nt := spaces
                    if nt <> 0
                        beginList := expr            ' begin value
                        if spaces == ","              
                         skipspaces
                         endlist := expr           ' end value 
                   a := long[noparse][[/noparse]userPtr]
                   repeat while a+2 < eop
                      if wordat(a) => beginList
                        if wordat(a) =< endList
                          dsp.dec(wordat(a))
                          dsp.out(" ")
                          putlinet(a+2)
                      a += 3 + strsize(a+2)
    
    


    I have added HELP too
    183: ' HELP                                       
                   repeat ip from 0 to constant(ntoks-1)
                     dsp.str(@@toks[noparse][[/noparse]ip])
                     dsp.out(" ")
                   dsp.out(fReturn)
                   dsp.out(flinefeed) 
    
    



    also in "factor" i added MEM to show available space in basic code store
    182: ' MEM
             return progsize - (eop  - long[noparse][[/noparse]userPtr] ) + 2
    
    


    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-03 21:33
    Here's the latest version of FemtoBasic. I've substituted the assembly I2C and SPI driver for the ones in Spin. You should see better speed for access to EEPROM and SD cards. I'm not completely sure it works right and I'd like feedback. I've added Perry's MEM value and LIST changes. I didn't put in HELP because I'm not sure a list of keywords is that helpful by itself. Perry, please recheck the EEPROM error on writing. I think it's fixed.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-04 05:45
    Tomas Rokicki pointed out an error in the SD card write routine that would occasionally cause an error. Hopefully it's fixed in this version.
  • Brian_BBrian_B Posts: 841
    edited 2007-02-04 05:50
    Mike,
    Could you please post the hydra version over on the hydra forum.

    Thanks,Brian
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-04 06:18
    Sorry folks. I posted the wrong copy. This one does LOAD/SAVE and EEPROM properly. This version will compiler for either the Demo Board or the Hydra and both binaries are included.
  • KeeblerKeebler Posts: 58
    edited 2007-02-04 19:21
    (Duplicate post from Hydra thread)

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-04 19:36
    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.
  • rokickirokicki Posts: 1,000
    edited 2007-02-04 22:52
    To delete a line, just type the line number and hit return.
  • KeeblerKeebler Posts: 58
    edited 2007-02-04 23:04
    Mike Green said...
    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
  • Dennis FerronDennis Ferron Posts: 480
    edited 2007-02-05 02:40
    
    100 FOR y = 0 TO 10
    105 PRINT " |";
    110 FOR x = 0 TO 30
    120 a = (x / 2) - 7
    160 e = a * a + (y-5) * (y-5)
    170 IF e < 20 THEN PRINT (e / 2);
    180 IF e > 20 THEN PRINT " ";
    190 IF e = 20 THEN PRINT "X";
    200 NEXT x
    210 PRINT "|"
    220 NEXT y
    
    
    



    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-05 03:46
    Dennis,
    You can add the following lines to add a little color:
    165 display 7,2
    175 display 7,13
    185 display 7,7
    195 display 7,1
    
    


    Note that these use the control codes for the windowed text display routines
    by Phil Pilgrim (http://forums.parallax.com/showthread.php?p=590631).
  • Dennis FerronDennis Ferron Posts: 480
    edited 2007-02-05 04:07
    Neat! When I got done with the program, I thought, this would be nicer in color...

    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
Sign In or Register to comment.