Shop OBEX P1 Docs P2 Docs Learn Events
Update for FemtoBasic - Page 2 — Parallax Forums

Update for FemtoBasic

2

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-19 04:04
    Oldbitcollector,
    First I want to add support for a mouse to the current keyboard I/O driver so that it wouldn't need yet another cog since the VGA cursor support takes a cog. That will take a while to get done. At that point I'll make it a configurable option.

    Have a look at the BOE-BOT Basic I posted to see examples for adding commands (in this case for servo, PING, compass, and IR ranging with a serial command link instead of the keyboard/display). It's posted here: http://forums.parallax.com/showthread.php?p=635533.

    Post Edited (Mike Green) : 3/19/2007 4:09:59 AM GMT
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-03-19 05:07
    Yes, I've already begun hacking into the code itself. Thanks for the additional examples!
    I'm a little disappointed with INPUTs current inability to handle variables, so I've begun seeing what I can do to deal with that. Useful example (based on another message in this thread)

    <EXAMPLE DOES NOT WORK, yet>

    1 FILES
    5 INPUT "Pick a file to view";A$
    10 OPEN A$,R
    20 C=FILE
    30 IF c<1 THEN GOTO 100
    40 IF C<>10 THEN DISPLAY C
    50 GOTO 20
    100 PRINT " "
    110 INPUT "End of file: <1 & ENTER>";a

    {Posted for the benefit of someone looking for working code}
    <THIS WORKS>

    10 OPEN "FILE.TXT",R
    20 C=FILE
    30 IF c<1 THEN GOTO 100
    40 IF C<>10 THEN DISPLAY C
    50 GOTO 20
    100 PRINT " "
    110 INPUT "End of file: <1 & ENTER>";a


    QUESTIONS:

    Also, if I use the SPIN "file.spin":RUN command, does it currently run on unused cogs leaving FemtoBasic intact? I haven't been able to test this yet, as I haven't figured out how to create a file.spin.binary file on the PC. (Or do I have to download the binary back down from the chip itself somehow?

    Again, sorry about the newbieness questions, but I think I'll continue to get up to speed quickly at the rate I'm going...

    (A few more Femtobasic commands and I'll be able to create the old text version of Startrek with LED's for alerts) smilewinkgrin.gif

    Oldbit
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-19 05:30
    1) The INPUT statement can actually handle arbitrary expressions including current variable values on the input line.
    What it won't handle is any kind of string value. FemtoBasic has no string variables or functions at present and no
    immediate plans to add them.

    2) The SPIN command basically "throws away" the entire contents of RAM. The Spin interpreter normally provides for
    only one program in memory. There is apparently a way to make the Spin interpreter use a different area than the
    beginning of memory (locations 0-15) for its critical pointers, but I haven't tried yet to get that to work. The loader
    for the SPIN command runs in its own cog and, when the program is being loaded, only references these critical
    pointers. FemtoBasic is GONE at that point.

    3) To save a binary file in the Propeller Tool, use the Save Binary File button in the Hex View window that comes up
    when you use the F8 key or Ctrl-F8 key or the View Info item in the Run menu.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-03-21 02:46
    Mike, Would you mind showing a couple Femtobasic examples for INA and OUTA?

    Something along the lines of
    {Note: I'm pretty sure this code is INCORRECT. *pseudo-code*}

    10 if INA(4) = 1 then print "Button pushed on pin 4": REM Button pushed on pin 4
    20 if INA(4) = 0 then print "Push a button already!!": REM No button pushed on pin 4

    and

    10 OUTA(9) = 1 : REM Turn on LED on pin 9
    20 PAUSE
    30 OUTA(9) = 0 : REM Turn off LED on pin 9


    Thanks
    Oldbitcollector
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-21 02:49
    If you change the parentheses to square brackets, the examples should work (although you do need a time after PAUSE)
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-03-21 02:59
    Unbelievable! The code off the top of my head was "almost" perfect. smilewinkgrin.gif

    Yes, it did work perfectly. My Atari joystick port for Femto is almost complete.
    (Now if I can just get the random detections in .spin to go away..)

    Thanks again Mike

    Oldbitcollector
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-03-21 03:23
    Now that opens up some new Femto possibilities...

    Like sound..

    1 REM Simple Tone Generator for FemtoBASIC
    2 REM Time to make FemtoBASIC go faster.
    10 input a
    20 for x = 1 to 100
    30 outa[noparse][[/noparse]10]=1
    40 pause a
    50 outa[noparse][[/noparse]10]=0
    60 next x
    70 goto 10


    Would anyone else playing with FemtoBASIC care to join me
    in starting a little code swapping thread? Perhaps we can develop
    some additional documentation in the process.

    Oldbitcollector
  • hinvhinv Posts: 1,253
    edited 2007-07-17 03:08
    Hi Mikes,

    I am trying to get FemtoBasic_SERIAL_MJC to talk. I am able to Load EEPROM, but after that, I can't get it to talk.
    I am using COM6 as where my PropPlug is connected. After I download to eeprom, I start up HyperTerm (I know, there are way better, but it is there and free) and connect to COM6 at 9600 8N1 no flow controll.
    Am I doing this right, or should I be connecting through other pins of the propeller with a MAX232 chip?
    I just can't get it to talk.
    My typing flickers the little blue light on the prop plug, but nothing on the little red light.

    Any guesses?


    Thanks,
    Doug
  • hinvhinv Posts: 1,253
    edited 2007-07-17 03:09
    P.S. Since I purchased the 5 pack of protoboards, I tried it on another one with exactly the same results.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-17 04:44
    hinv,
    It sounds like you're trying to use the version that comes with the Hydra. I can't help you with that one. Please download and use the version that you can download from the Propeller Object Exchange. The versions of FemtoBasic in the Object Exchange work with the PS/2 keyboard and either a VGA or TV display. There's a special version of FemtoBasic called BoeBotBasic, also in the Object Exchange, that uses the programming serial port for its console. It can also be compiled to use a different pair of pins for the serial port (and is used this way with an xBee adapter).

    Both versions from the Object Exchange work fine with the ProtoBoard. I have a ProtoBoard based BoeBot and use BoeBotBasic with it.

    Post Edited (Mike Green) : 7/17/2007 4:49:03 AM GMT
  • hinvhinv Posts: 1,253
    edited 2007-07-19 09:34
    Hi Mike,

    Thanks for the tip. I have BeoBotBasic working on my proto board now.
    I did have to change the console lines to talk to booTx and bootRx.

    I also had to fix dump as it was broken. That is when I found a serious limitation in SPIN: ALL LOCAL VARIABLES ARE LONGS! ugh!
    There is also not out of bounds checking, or sigsegv to tell you that you are writing out of bounds.
    I know you already know all of this, I just wanted to express my frustration after the frustration with fixing dumpMemory.
    Anyway, I think it is done.
    It does need a "buf[noparse][[/noparse]16]" in the var block on the byte line. Let me know what you think. I did make it 16 bytes /line to use the space on most 80 column terminals.
    PUB dumpMemory(addr,size) | i, c, p, first
    '' This routine dumps a portion of the RAM to the display.
    '' The format is 8 bytes wide with hexadecimal and ASCII.
      addr &= $7FFF
      if addr + size > $7FFF               ' truncate to end of code space
        size := $8000 - addr
      first := true
      p := addr & $7FF8
      repeat while p < (addr + size)
        if first
          ser.hex(addr,4)
          first := false
        else
          ser.hex(p,4)
        ser.tx(" ")
        repeat i from 0 to 15            'If you want to display just 8 bytes/line, change the 15 to a 7
          if p => addr and p < (addr + size)
            c := byte[noparse][[/noparse]p]
            ser.hex(c,2)
            if c => " " and c =< "~"
              buf[i] := c
            else
              buf[i] := " "
          else
            ser.tx(" ")
            ser.tx(" ")
          ser.tx(" ")
          p++
        buf[i] := 0     'terminate string
        ser.tx("|")
        ser.str(@buf)
        ser.tx("|")
        ser.tx(def#Cr)
        ser.tx(def#Lf)
    [/i][/i][/i]
    



    Thanks,
    Doug
  • hinvhinv Posts: 1,253
    edited 2007-07-19 09:40
    oops, change the comment to
    '' The format is 16 bytes wide with hexadecimal and ASCII.
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-19 13:47
    Can you describe what was broken about DumpMemory? I've had several versions of this between FemtoBasic, BoeBotBasic, and the Propeller OS and the different versions of each. I know a couple of versions were buggy, but I thought I fixed the bugs.

    Mike
  • hinvhinv Posts: 1,253
    edited 2007-07-19 14:49
    This is what it looks like now:
    dump 215,350
    00D8 49 46 00 54 48 45 4E 00 49 4E 50 55 54 00 50 52 |IF THEN INPUT PR|
    00E8 49 4E 54 00 47 4F 54 4F 00 47 4F 53 55 42 00 52 |INT GOTO GOSUB R|
    00F8 45 54 55 52 4E 00 52 45 4D 00 4E 45 57 00 4C 49 |ETURN REM NEW LI|
    0108 53 54 00 52 55 4E 00 52 4E 44 00 4F 50 45 4E 00 |ST RUN RND OPEN |
    0118 52 45 41 44 00 57 52 49 54 45 00 43 4C 4F 53 45 |READ WRITE CLOSE|
    0128 00 44 45 4C 45 54 45 00 52 45 4E 41 4D 45 00 46 | DELETE RENAME F|
    0138 49 4C 45 53 00 53 41 56 45 00 4C 4F 41 44 00 4E |ILES SAVE LOAD N|
    0148 4F 54 00 41 4E 44 00 4F 52 00 53 48 4C 00 53 48 |OT AND OR SHL SH|
    0158 52 00 46 4F 52 00 54 4F 00 53 54 45 50 00 4E 45 |R FOR TO STEP NE|
    0168 58 54 00 49 4E 41 00 4F 55 54 41 00 50 41 55 53 |XT INA OUTA PAUS|
    0178 45 00 55 53 49 4E 47 00 52 4F 4C 00 52 4F 52 00 |E USING ROL ROR |
    0188 53 41 52 00 52 45 56 00 42 59 54 45 00 57 4F 52 |SAR REV BYTE WOR|
    0198 44 00 4C 4F 4E 47 00 43 4E 54 00 50 48 53 41 00 |D LONG CNT PHSA |
    01A8 50 48 53 42 00 46 52 51 41 00 46 52 51 42 00 43 |PHSB FRQA FRQB C|
    01B8 54 52 41 00 43 54 52 42 00 44 49 53 50 4C 41 59 |TRA CTRB DISPLAY|
    01C8 00 4B 45 59 43 4F 44 45 00 4C 45 54 00 53 54 4F | KEYCODE LET STO|
    01D8 50 00 45 4E 44 00 45 45 50 52 4F 4D 00 46 49 4C |P END EEPROM FIL|
    01E8 45 00 4D 45 4D 00 53 50 49 4E 00 43 4F 50 59 00 |E MEM SPIN COPY |
    01F8 44 55 4D 50 00 53 52 56 4C 45 46 54 00 53 52 56 |DUMP SRVLEFT SRV|
    0208 52 49 47 48 54 00 53 52 56 50 49 4E 47 00 43 4F |RIGHT SRVPING CO|
    0218 4D 50 41 53 53 00 49 52 5A 4F 4E 45 00 50 49 4E |MPASS IRZONE PIN|
    0228 47 00 45 58 50 41 4E 44 00 00 C8 00 CB 00       |G EXPAND      IN|
    OK
    


    and this is what it looked like before:
    dump 216,176
    00D849 46 00 54 48 45 4E 00 |I|
    00E049 4E 50 55 54 00 50 52 |I|
    00E849 4E 54 00 47 4F 54 4F |I|
    00F000 47 4F 53 55 42 00 52 | |
    00F845 54 55 52 4E 00 52 45 |E|
    01004D 00 4E 45 57 00 4C 49 |M|
    010853 54 00 52 55 4E 00 52 |S|
    01104E 44 00 4F 50 45 4E 00 |N|
    011852 45 41 44 00 57 52 49 |R|
    012054 45 00 43 4C 4F 53 45 |T|
    012800 44 45 4C 45 54 45 00 | |
    013052 45 4E 41 4D 45 00 46 |R|
    013849 4C 45 53 00 53 41 56 |I|
    014045 00 4C 4F 41 44 00 4E |E|
    01484F 54 00 41 4E 44 00 4F |O|
    015052 00 53 48 4C 00 53 48 |R|
    015852 00 46 4F 52 00 54 4F |R|
    016000 53 54 45 50 00 4E 45 | |
    016858 54 00 49 4E 41 00 4F |X|
    017055 54 41 00 50 41 55 53 |U|
    017845 00 55 53 49 4E 47 00 |E|
    018052 4F 4C 00 52 4F 52 00 |R|
    OK
    



    This was from BOE-BOT_Basic 2007-04-08
    The code assumes that buf0, buf1, and buf2 are allocated sequentially, and that writing to buf0 will flow into buf1's space. Apparently, this doesn't work as expected.

    Thanks,
    Doug
  • hinvhinv Posts: 1,253
    edited 2007-07-19 14:51
    Well, that didn't show up as planned.
    The last line should read:
    The code assumes that buf0, buf1, and buf2 are allocated sequentially, and that writing to buf0 will flow into buf1's space. Apparently, this doesn't work as expected.
    
    
  • hinvhinv Posts: 1,253
    edited 2007-07-19 14:55
    Well that didn't work either

    I meant writing to buf0\[noparse][[/noparse]4\] doesn't mean that you are automatically writing to buf1 space.

    Well anyway, I can't seem to protect the brackets above without showing the backspaces, but you get the picture.
  • hinvhinv Posts: 1,253
    edited 2007-07-23 03:38
    Hi Mike,

    On BoeBotBasic, I also am not able to load or save my program
    load give error "Invalid program size" even though I just did a save.
    files gives the error "Can't mount SD card"
    I couldn't find the pin numbers for the SDCard port.
    Is it in there somewhere?

    Thanks,
    Doug
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-23 05:43
    Doug,
    I would need more information on just what you entered and what you're trying to do with the "Invalid program size" message. The LOAD command checks the validity of the saved program size. The SAVE command computes the amount of space taken by the partially tokenized Basic program and saves this as the first 16-bit word in the area set aside in EEPROM. The LOAD command makes sure this isn't too small (<4 bytes including the count) or too large (larger than the area set aside) before trying to load it. You'd get this message if you re-downloaded the BoeBotBasic interpreter after saving the Basic program (because the download wipes out the saved program).

    The "FemtoBasic Manual" that's included in the Object Exchange zip file has a description of the SD Card wiring. Do make sure you have that version since it's the latest.
  • hinvhinv Posts: 1,253
    edited 2007-11-02 04:22
    Hi Mike,

    I don't remember what the "invalid program size" error was about, but I fixed the dumpMemory subroutine again, this time in DongleBasic.
    I stuck with your 8 byte format, but I had to take out buf0, buf1, and buf2 again as it was just not displaying the ascii characters past the first of the 8.
    Instead of posting it in a code block, and having the brackets taken out, I am attaching the whole file.

    Thanks,
    Doug
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-02 04:59
    Thanks Doug. I'll fix it properly in the next release (3.006), probably over the weekend. I forgot to use "byte[noparse][[/noparse] @b0 ][noparse][[/noparse] i ]".
    The Invalid Program Size message is due to a problem with EEPROM page write boundaries that I've now fixed. There are
    a couple of other minor improvements as well ... like being able to SAVE / LOAD Basic programs to other EEPROM areas.
    I'll be updating all the FemtoBasic derivatives.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-03 15:16
    All of the FemtoBasic derivatives have been updated to 3.006. Please let me know of any problems / bugs / etc.

    Changes:

    1) The documentation has been updated including for a version for the Hitt Consulting's Overlay Display
    board that's not quite working properly yet.

    2) The DUMP bug has been fixed properly and DUMP can display the contents of EEPROM as well as RAM.

    3) LOAD and SAVE have been fixed and can now store the Basic program in arbitrary locations in EEPROM.
    For those boards with EEPROM > 32K, this makes it possible to create libraries of Basic programs in EEPROM.
    Note that the statements adjust the address upwards so that the program is stored starting two bytes before
    the next 64 byte boundary (to make use of paged writes). The rest of the initial 64 byte page is untouched
    and could be used to store a program name and other information, but FemtoBasic doesn't do this for you.

    4) The uOLED version has support for a 5x7 font as well as the previous 8x8 font thanks to Duffer's new driver
    version. A simple circle and arc drawing routine with a fill option have also been added (courtesy of Paul Sr.)
  • BeanBean Posts: 8,129
    edited 2007-11-03 15:34
    Mike,
    I would like to thank you for all your hard work on the femtobasic version.
    I can't wait to try them.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-11-03 17:11
    Mike Green said...
    All of the FemtoBasic derivatives have been updated to 3.006. Please let me know of any problems / bugs / etc.

    Mike, Where is the update? (It doesn't seem to be in this thread -- no edit stamp on the first message)
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-03 17:15
    FemtoBasic and its derivatives (BoeBotBasic, DongleBasic, uOLED-96-Prop Basic) are all posted in the Propeller Object Exchange.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-11-03 17:23
    [noparse]:)[/noparse] Glad I asked. I found FermtoB and BoeBot but the other two hid from me.
  • JoJo Posts: 55
    edited 2007-11-06 03:49
    Mike:

    many thanks for FemtoBasic: this is a language my kids can play with right on the Propeller without delving into the complexities of Spin and assembly.
    And since I have kids typing at it, needed some command line editing capability.
    Fairly simple stuff, but I've found it useful. Here it is (replacement for GetLine in FemtoBasic.spin)


    PRI getline | cp, ep, c
       cp := 0 ' current cursor position
       ep := cp ' last (end) cursor position this line
       repeat
          c := key.getkey
          if c == bspKey
             if cp > 0
                if cp == ep
                   dsp.str(string(backspace," ",backspace))
                   cp--
                   ep--
                else
                   ' probably would be better to remove 1 char from line
                   ' but for now just overwrite with a space
                   tline[noparse][[/noparse]cp--] := " "
                   dsp.str(string(backspace, " ", backspace))
          elseif c == fReturn
             if cp <> ep   ' erase anything from cursor to end of line
                repeat ep - cp
                   dsp.out(32)
             dsp.out(c)
             tline[noparse][[/noparse]cp] := 0
             tp := @tline
             return
          elseif ((c == $DD) OR (c == $DE) OR (c == $DF))
            'scroll lock, caps lock and numlock keys should be ignored as keystrokes
            next
          elseif (c == $C0)
            ' cursor left, but only if cursor not already at beginning of line
            if cp > 0
              if (cp <> ep)
                dsp.out(tline[noparse][[/noparse]cp])
                dsp.out($3)
              cp--
              dsp.str(string(dsp#CursLt, dsp#Color, $8))  ' cursor back, invert color
              dsp.out(tline[noparse][[/noparse]cp])
              dsp.str(string(dsp#CursLt, dsp#Color, dsp#Alt00))      ' put color back to normal
          elseif (c == $C1)
            ' cursor right, but only up to last typed character
            if cp < ep
              dsp.out(tline[noparse][[/noparse]cp])
              cp++
              if cp < ep 
                dsp.str(string(dsp#Color, $8)) ' cursor back, invert color, write character
                dsp.out(tline[noparse][[/noparse]cp])
                dsp.str(string(dsp#CursLt, dsp#Color, dsp#Alt00))    ' put color back to normal
          elseif cp < linelen-1
             dsp.out(c)
             tline[noparse][[/noparse]cp++] := c
             ep := cp
    
    




    Comments welcome
    (edited because even inside a code section the square bracket characters cause formatting: variable i changed to cp)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    Jo
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-06 04:11
    Very nice. If you feel like expanding it, you could even add an insert function which would insert a blank at the current column by shifting the right side of the line further to the right and a delete function that would delete the current character by shifting the right side of the line to the left.

    Have a look at the screen buffer editor module in the Propeller OS on Graham Stabler's Good Thread Index in one of the sticky threads at the top of the forum.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-11-06 04:13
    This looks great.. I'll try it myself in the morning..

    Question: Which text driver were you using? VGA or Composite?

    Thanks
    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.

    — Calvin, of 'Calvin and Hobbes.
  • JoJo Posts: 55
    edited 2007-11-06 04:25
    Oldbitcollector:

    I am using the Composite (TV) aka tv_wtext driver.

    I very definitely miss being able to have conditional compilation when programming the Propeller.
    Commenting things in and out is not quite the same...

    Joao

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    Jo
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-11-07 00:09
    Nice routine! I've noticed that it doesn't seem to want to cursor back right once I've gone left.
    That might make an interesting upgrade. Combine this with an EDIT # command and you'd
    have a very solid feature for troubleshooting a bad line entry.

    I'll have to see if I can find a way to incorporate this into my copy that uses the 8x8 font.

    Oldbitcollector

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.

    — Calvin, of 'Calvin and Hobbes.
Sign In or Register to comment.