PE-Basic Version 0.16 July 11, 2011
Bean
Posts: 8,129
I've been toying around with making a version of femtoBASIC in PropBasic instead of spin for speed.
Here is my first crack at it.
The hard-coded program has a tight 3 line loop that toggles pin 0. It's pretty fast 300,000 (simple) lines per second. So the pin toggles at 100KHz. [edit speed is quite a bit slower now]
I'm sure when I start fleshing it out, I'll need to switch to LMM so that will make it quite a bit slower (about 75,000 lines per second).
Comments welcome...
[edit]I uploaded a new version that uses LMM, speed is about 57,000 (simple) lines per second. Editing the program now works too.
[edit] July 5, 2010 uploaded a new version. Math works but strictly left-to-right evaluation. No "IF" or "FOR" yet. But it's getting there...
[edit] July 7 2010 uploaded a new version. Simple IF ... THEN line# expressions work now.
[edit] July 12 2010 uploaded new version. Added PEEK, POKE, DEBUG, INKEY, DISPLAY, VARS, NEW
[edit] Dec 22 2010 uploaded new version. Added GOSUB/RETURN, FOR/NEXT, and more.
[edit] Dec 23 2010 uploaded version 0.02 Dec 23, 2010. Added LOAD and SAVE.
[edit] Dec 25, 2010 updated version 0.04. Added multiplie commands per line seperated by ":". And READ DATA RESTORE.
[edit] Jan 9 2011 updated version 0.05. Added NTSC display, PS2 Keyboard input. Added LOCATE command. Allow lowercase.
[edit] Jan 12 2011 update version 0.06. Various fixes. Allow IF...THEN commands.
[edit] Feb 1, 2011 allow 8 character variable names (except FOR..NEXT). PLOT, LINE, etc.
[edit] Feb 4, 2011 Full expression evaluator (Thanks Mike Green). Added system variable CHARS to change the bitmap of characters. POKEB CHARS,255 changes the top line of the space(32) character to a solid line.
[edit] Feb 5, 2011 Fixed pin ranges, RND, ABS, backspace at start of line.
[edit] Mar 9, 2011 Updated to version with color video.
[edit] Mar 11, 2011 Updated. Changed name PEBasic (Propeller Embedded BASIC)
[edit] July 11, 2011 Updated. Posted version 0.16.
Bean
Here is my first crack at it.
The hard-coded program has a tight 3 line loop that toggles pin 0. It's pretty fast 300,000 (simple) lines per second. So the pin toggles at 100KHz. [edit speed is quite a bit slower now]
I'm sure when I start fleshing it out, I'll need to switch to LMM so that will make it quite a bit slower (about 75,000 lines per second).
Comments welcome...
[edit]I uploaded a new version that uses LMM, speed is about 57,000 (simple) lines per second. Editing the program now works too.
[edit] July 5, 2010 uploaded a new version. Math works but strictly left-to-right evaluation. No "IF" or "FOR" yet. But it's getting there...
[edit] July 7 2010 uploaded a new version. Simple IF ... THEN line# expressions work now.
[edit] July 12 2010 uploaded new version. Added PEEK, POKE, DEBUG, INKEY, DISPLAY, VARS, NEW
[edit] Dec 22 2010 uploaded new version. Added GOSUB/RETURN, FOR/NEXT, and more.
[edit] Dec 23 2010 uploaded version 0.02 Dec 23, 2010. Added LOAD and SAVE.
[edit] Dec 25, 2010 updated version 0.04. Added multiplie commands per line seperated by ":". And READ DATA RESTORE.
[edit] Jan 9 2011 updated version 0.05. Added NTSC display, PS2 Keyboard input. Added LOCATE command. Allow lowercase.
[edit] Jan 12 2011 update version 0.06. Various fixes. Allow IF...THEN commands.
[edit] Feb 1, 2011 allow 8 character variable names (except FOR..NEXT). PLOT, LINE, etc.
[edit] Feb 4, 2011 Full expression evaluator (Thanks Mike Green). Added system variable CHARS to change the bitmap of characters. POKEB CHARS,255 changes the top line of the space(32) character to a solid line.
[edit] Feb 5, 2011 Fixed pin ranges, RND, ABS, backspace at start of line.
[edit] Mar 9, 2011 Updated to version with color video.
[edit] Mar 11, 2011 Updated. Changed name PEBasic (Propeller Embedded BASIC)
[edit] July 11, 2011 Updated. Posted version 0.16.
Bean
zip
189K
Comments
Aren't you going to bump into a PBASIC size limitation pretty quick? Femto is a pretty large Spin program.
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Feature Projects: PropellerPowered.com
Visit the: PROPELLERPOWERED SIG forum kindly hosted by Savage Circuits.
Yeah, I'm almost sure it will be a LMM program. That will handle it.
I'm thinking pretty modest, no SD card (EEPROM for program storage). No video (serial terminal). Of couse I'll add commands for the S2 motors, encoders, LED and such.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
If you have any questions about FemtoBasic as you go along, PM me or pose them in this thread and I'll try to help.
BoeBotBasic worked fine over an xBee wireless link. I had preconfigured the xBees (Series 1) storing the destination and source node address assignments in the flash configuration memory using the standard commands so they'd power up all ready to go. I had made my own USB to xBee adapter for the PC end of things, but Parallax now has a nice one.
Could you go into more detail about how to use to two stacks ?
I assume you just push both operators and data, then scan the operator stack and do the operations in precedence order ? I'm I even close ?
If I use LMM then it wouldn't be too hard to implement recursion.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
One stack is the data stack for the intermediate operands. The other stack holds the saved operators and their precedence. You'd have a master table with the operators and their precedences like:
DAT
operators byte
byte 1, "+",0
byte 1, "-",0
byte 2, "*",0
byte 2, "//",0
byte 2, "/",0
byte 3, "<>",0
byte 3, "<=",0
byte 3, "<",0
byte 3, ">=",0
byte 3, ">",0
byte 3, "=",0
This table structure is just an example. You can modify it as needed.
The scanner scans the input line. If it finds a constant or a variable, it pushes the constant or variable value into the data stack. If it finds an operator, it looks to see if the operator stack is empty. If it is, it pushes the operator and its precedence (1, 2, or 3 in this example) into the operator stack. If the operator stack has something in it, the program compares the stacked precedence with the precedence of the new operator. If <=, the stacked operator is popped from the stack and executed (using the data stack for its operands) with the result left on the stack and the process is repeated. If >, the operator and its precedence are pushed onto the stack. Parentheses are treated specially. An opening parenthesis is always pushed into the operator stack and a closing parenthesis causes the operator stack to be popped and the operators executed until an opening parenthesis is popped. Any "end of expression" keyword or punctuation will cause the operator stack to be popped and the operators executed until the operator stack is empty. In a way, there's an implicit opening parenthesis and the "end of expression" acts as a closing parenthesis. You can keep track of nesting level for parentheses and check that a closing parenthesis and the open parenthesis entry in the operator stack match up.
Obviously, you need overflow and underflow checking for the stacks. You also need special handling for unary operators so that you have a flag that's true if the last item scanned is an operator and false if it's an operand like a constant or variable. If the previous item is an operator, then the next item, if an operator, is a unary operator. You'd have different operator table entries for unary and binary operators (like "+", "-"). You would also check that unary-only or binary-only operators are used properly.
Does this make sense? Try a simple example like "a + b * c + d" or "a * (b + c) * d" on paper.
Post Edited (Mike Green) : 7/2/2010 8:36:35 PM GMT
There are several ways to approach infix expression evaluation, the tightest requiring automatic recursion in the host language, but all of which are best contemplated with at least three beers down.
Still no math yet, but you can edit the program now.
I have updated the file in the first post with the new version.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
Math is evaluated strictly left-to-right.
This short program show that a simple assignment is 1872 clocks (23.4uSec @ 80MHz)
10 LET A=CNT
20 LET B=CNT
30 PRINT B-A
Bean
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/forums/default.aspx?f=25&p=1&m=412552
March 2010 Nuts and Volts articlehttp://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [RUSH - Freewill]
'
Cool post, I'm glued
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA
want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___
You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
I updated the program, it now supports IF...THEN line#
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
Post Edited (Bean) : 7/7/2010 1:48:03 PM GMT
'
I see the need for " RENUM ", This would be used when edits exceeded 9 between lines. I see and edit between line 60 and 70 "65 PRINT".
'
I have no idea on how to renumber the lines and the "THEN x", "GOTO x", " GOSUB x", etc. But I think it will need to be addressed.
'
I'm struggling to catch-up with this line of programing. Sorry I can,t be more help. This has Me rethinking alot about whats underneath.
'
This POST just gets better and better.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA
want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___
You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.
·
I'm pretty sure I'll be using the Wifly GSX for my robot (one day)...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm
My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
I have added PEEK, POKE, DEBUG, INKEY, DISPLAY, VARS, NEW
Comment welcome...
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
This just gets Better and Better!
Roll with it Bean, You are the MAN!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA
want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___
You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.
·
This is so fantastic, we can hardly believe it!
AFAIK, the only language that can do both is MBASIC with the Microsoft Bascom compiler from the early 1980s (Bascom morphed into QB which morphed into vb.net) It would be cool to replicate such a program.
Speed is not really the issue for an interpreter. You write a program in an inbuilt IDE editor (on the chip, of course) and type "RUN" and it runs. Who cares if it is only 1000 instructions a second, because what you can do is experiment quickly and easily with each and every instruction. IMHO, instant feedback is the quickest way to learn a language. ('instant' = less than 5 seconds).
But then once a program is working, you run it through a compiler to make it a lot faster. Is this where things are heading? An interpreter and a compiler?
vb.net finally achieves something similar with instant compilation, though it took another decade of 'progress' to get there. (1982 to the early 1990s with QB).
Where is Propbasic up to? I downloaded the latest manual but there are still some instructions mission, eg some string functions. Or maybe the language and the manual are not quite in synch?
My goal is to implement this in the S2 robot to make a stand-alone programmable robot. When the wireless network module is released, I'd like to make my S2 to you can telnet into it and program it from anywhere in the world.
I'd also like it to be at LEAST as fast as spin. And I think it is. A "FOR NEXT" loop of 10,000 takes only 230mSec.
It might also make a cool application for the C3 board too.
Bean
Did my eyes deceive me or did I see support for a "DATA" statement?
Any plans to support strings$ ?
Nice work!!
OBC
Two questions
1 - RENUMBER was spoken of earlier ... is it feasible in this environment? It would be handy, almost necessary.
2 - when do you expect SAVE to be enabled?
Right now I'm changing the memory layout, and that is giving me headaches. (I had numbers as MSB first instead of LSB first, and I'm making the line length a single bytes instead of two bytes to save space).
After I get that straightened out, SAVE and LOAD are next on the list.
As for RENUMBER, that is tricky and will probably require too much code to implement after I get all the S2 commands (or C3 commands) implemented.
Bean
I had some free time this morning so I got the new structure working (I think) and implemented SAVE and LOAD.
If you have a 64K EEPROM you can save 5 programs total.
SAVE or SAVE 0 will save to the default location (is loaded at powerup). SAVE 1 thru SAVE 4 will save to extra 32K EEPROM space.
Any program where the first line is "1 CONT" will auto-run when loaded (or at powerup for default location).
[edit] I found the first bug in 0.02. Keywords inside quotes get tokenized.
Bean
Edit: Never mind. I found it through a web search. Sorry.
Sorry I forgot to upload the .spin files as well.
They are on the first post now.
Bean
This one allows multiple commands per line by seperating with a colon ":" for example LET A=5:LET B=6
It also has READ DATA RESTORE implemented. DATA elements can be full expressions for example DATA 1, 2,3, 2+2, A+6
I think the next step to use a PS/2 keyboard and NTSC monitor to make this truely a stand-alone programable system.
Comments welcome
Bean
Extremely useful stuff for real BASIC programming. Thanks Bean!
This version is truly stand-alone. It uses a PS/2 Keyboard and has a NTSC display (48x19 characters). Run as-is on the demo board.
I will change the video driver later because this one is bitmapped and uses alot of memory and is slow.
I added a LOCATE command to set the print position.
Also you can use lowercase characters now (commands get converted to uppercase).
Comments please...
Bean
I've been toying around with making a version of femtoBASIC in PropBasicinstead of spin for speed.
Bean, is this open source? I looked for the MIT license but didn't see it listed in the code.