The "then" isn't optional because it's what indicates a multi-line "if" (for a single command you can include it on the same line as the "if"). But there's certainly room to improve the error messages!
ser.str("We should also be able to do this, I think")
In BASIC there's no need for the `string` operator, things between quotes are always strings. But this means you have to watch out for cases where in Spin you are using a single character. For example, to send one character "X" in BASIC you would do:
I think this can be replaced by a function table, and a call per function pointer.
ON x GOTO would probably be feasible to implement, although I think the "modern" BASIC way to do that is SELECT/CASE (which is partially implemented in fastspin now, as a series of if/then/else, but I really should provide the optimization of turning that into a jump table when the CASEs are contiguous).
ON x GOSUB is a bit more problematic, since we don't support GOSUB in general. I guess it could be made to work for the specific case that all of the labels are actually declared as zero parameter SUBs. Is it worth it? I'm not sure.
I'm still thinking about DATA/READ/RESTORE, but you're right, we do need those in some form.
I suppose with this being a compiler, you could always create aliases such as jmp for GOTO so that some would feel that they are using a real programming language
If you want to, you can send a character in fds.spin like so
ser.tx(chr) ' outputs a byte contained in *chr* . No need to type cast.
In fds.spin you cannot send a string without using a pointer to the string or inserting the word *string* inside
the expression, agreed? So if new prop users comes to flexibasic and uses spin objects in a progam (which, I think, was one of the primary objectives) may wonder why their code fails to compile. Fds.spin is used in other objects which can be down loaded from the OBEX. Maybe there should be a warning in the docs
This works in spin, but not in flexibasic
serial.str(string("Testing the FullDuplexSerial object.")) 'print a test string
I suppose with this being a compiler, you could always create aliases such as jmp for GOTO so that some would feel that they are using a real programming language
You can access labels from inline assembly, so it would be OK to write something like:
var x = 0
start:
if x = 1 then
asm
jmp isone
end asm
end if
print "hello"
x = x + 1
asm
jmp start
end asm
isone:
print "goodbye"
I will add a note to the documentation about the difference between BASIC and Spin strings. I think the BASIC ones are more natural (I hate having to write string("hello") instead of just "hello") but it may trip people up if they use a string where an integer is expected.
I saw this in another thread https://www.b4x.com/
could be useful on a few fronts.
Seems it is Basic -> C, so you could use the emitted C to test your C compiler parts, and there may be bits of the Basic side that can be harvested ?
Frequently asked questions
Q: Is B4R completely free, including for commercial purposes?
A: Yes.
Q: Can I access the C source code and the generated objects?
A: Yes. The code and the compiled objects are available under the Objects folder.
Q: Are the libraries open source?
A: Yes. B4R libraries are open source (MIT license). The code is available in GitHub.
Thanks for the pointer @jmg. Unfortunately it looks like b4x itself is not open source, so there's not much that can be harvested directly from it. We could look at the C code it generates and "reverse engineer" what it's doing for some constructs. If anyone would like to take that on it for DATA/READ/RESTORE it could be helpful.
Eric,
Another nubie question.
I've been playing with BASIC and trying different things to see if they compile. Now I'm actually trying to run programs on the P1 on a QuickStart board (flash LEDs, run multiple cogs) getting ready to try them out on the P2ES.
I am using spin2gui with Windows 7. When I try to use "Compile & Run", I get an error message "Propeller not found on com 1". That makes sense since my Prop 1 is on com 6.
Same thing happens if I just try run binary.
How can I change the binary loading program to use a different com port?
My work around is to associate the PropTool with .binary files, and click on the binary file. Then use the PropTool info screen to load the EEPROM. I'm also using the Parallax Serial Terminal as the print device.
I think you can change the Run command line (under Commands > Configure Commands...) to include a "-p COM6" option to specify the port. I'm surprised proploader would need this, it's usually pretty good at finding propellers automatically. I have been meaning to add a menu option for doing this, because some people have asked about supporting multiple props; but I haven't had a chance yet.
I've been experimenting with spin2gui, and it seems tthat it does not identify the Propeller chip on any of my boards. It works with the Activity Board. So, it can be one or both:
- My boards use a 6MHz crystal instead of a 5MHz one.
- My boards use the !RTS signal AC coupled via a capacitor, without any inverting transistor, for the reset. The Activity Board uses the !DTR signal, AC coupled and inverted via a transistor.
I haven't explored what is going wrong. SimpleIDE works fine with my boards, provided that the correct settings are configured. Does your software allows to to change the frequency and signals, to account for different hardware?
spin2gui doesn't do anything to detect the boards, it relies on the proploader tool (written by @dbetz) to do that. The tool to be used can be configured easily in the spin2gui Commands menu, so if proploader doesn't work but propeller-load does then you could try that.
spin2gui doesn't do anything to detect the boards, it relies on the proploader tool (written by @dbetz) to do that. The tool to be used can be configured easily in the spin2gui Commands menu, so if proploader doesn't work but propeller-load does then you could try that.
Regards,
Eric
The original version of proploader only knew how to load boards with 5mhz crystals because that's what Parallax asked for. I've been working on a new version that uses the same board configuration files as propeller-load and hence can load boards with different clock settings. Until that is ready you can continue to use propeller-load. You only really need to use proploader if you want to load over a wifi connection using a WX module.
Is there some sample code somewhere that shows how to use a couple of smart pins to implement a serial interface? I'm looking for PASM2 code not C or Spin.
Eric,
I tried that and got a compiler error. The message window listed all the compiler switches and -p is eliminate the preprocessor.
Tom
spin2gui has two separate phases: first it compiles the source code into a binary by invoking a compiler (the default is fastspin). Then it loads that binary to the board and runs it there, using proploader by default on P1 and loadp2 on P2.
I think you changed the "Compile command" (the one that invokes fastspin) and not the "Run command" (the one that invokes proploader). The "-p COM6" needs to go after "%D/bin/proploader" in the "Run command", the second command shown in the "Configure commands..." dialog box.
Is there some sample code somewhere that shows how to use a couple of smart pins to implement a serial interface? I'm looking for PASM2 code not C or Spin.
There's a "smartpin_serial_turnaround.spin2" file in the v32i FPGA distribution. I'm not sure if that's exactly what you wanted, but it probably would provide some nice hints.
I think it's from garryj originally, but heavily modified...
You might want this too:
nco_baud =round(fclk / 115_200.0 * 65536.0) & $fffffc00 | 7 'adapted from garryj's V19 USB code
CON 'Serial pin definites and mailboxes
RX_PIN = 63
TX_PIN = 62
'Mailbox for serial commands (right before BmpAddressBackground)
Mailbox1=$FF80
Mailbox2=$FF81
Eric,
I tried that and got a compiler error. The message window listed all the compiler switches and -p is eliminate the preprocessor.
Tom
spin2gui has two separate phases: first it compiles the source code into a binary by invoking a compiler (the default is fastspin). Then it loads that binary to the board and runs it there, using proploader by default on P1 and loadp2 on P2.
I think you changed the "Compile command" (the one that invokes fastspin) and not the "Run command" (the one that invokes proploader). The "-p COM6" needs to go after "%D/bin/proploader" in the "Run command", the second command shown in the "Configure commands..." dialog box.
Regards,
Eric
Eric,
Thanks for the help. I haven't used BASIC in many years. It was fun then. It is also now. Thanks for developing this. I especially like being able to see the resulting PASM.
Thank you for the gui and all. It is just what I was hoping for. I downloaded the version currently in page 1 of this thread.
So I followed your advice to twm and put -p COM33 into the loader command and believe I am now talking to the P2.
Now when I "compile and load" blink1 from the samples (changing ledpin = 56), I see activity on LED P63 and P60 and P61. Then P60 goes out, then P61. But nothing on P56. I'm sure I have some simple error. Can you advise?
Secondly, how do I configure the terminal that comes up to COM33?
Comments
It threw the error, but just was too early in the day for me
Global variables ? Example taking from docs
Throws error on compiling !
I haven't played with this yet but from an earlier post, it would be:
Sorry, that's a bug (an oversight in the type parsing code) that will be fixed in the next release. For now use Mickster's suggestion:
We can do this but
Ron
Just write In BASIC there's no need for the `string` operator, things between quotes are always strings. But this means you have to watch out for cases where in Spin you are using a single character. For example, to send one character "X" in BASIC you would do: or whereas in Spin that would be ser.tx("X").
Eric
ON x GOSUB is a bit more problematic, since we don't support GOSUB in general. I guess it could be made to work for the specific case that all of the labels are actually declared as zero parameter SUBs. Is it worth it? I'm not sure.
I'm still thinking about DATA/READ/RESTORE, but you're right, we do need those in some form.
Thanks,
Eric
If you want to, you can send a character in fds.spin like so
In fds.spin you cannot send a string without using a pointer to the string or inserting the word *string* inside
the expression, agreed? So if new prop users comes to flexibasic and uses spin objects in a progam (which, I think, was one of the primary objectives) may wonder why their code fails to compile. Fds.spin is used in other objects which can be down loaded from the OBEX. Maybe there should be a warning in the docs
This works in spin, but not in flexibasic
I am only a tool user and not a tool maker.
Ron
Eric
You can access labels from inline assembly, so it would be OK to write something like:
I will add a note to the documentation about the difference between BASIC and Spin strings. I think the BASIC ones are more natural (I hate having to write string("hello") instead of just "hello") but it may trip people up if they use a string where an integer is expected.
Thanks,
Eric
https://www.b4x.com/
could be useful on a few fronts.
Seems it is Basic -> C, so you could use the emitted C to test your C compiler parts, and there may be bits of the Basic side that can be harvested ?
Frequently asked questions
Q: Is B4R completely free, including for commercial purposes?
A: Yes.
Q: Can I access the C source code and the generated objects?
A: Yes. The code and the compiled objects are available under the Objects folder.
Q: Are the libraries open source?
A: Yes. B4R libraries are open source (MIT license). The code is available in GitHub.
Docs —▷ http://www.basic-converter.org/doc_frame.html
(...but I don't think, FlexBASIC needs the classic "DATA" and friends from punch card days only storing strings and so wasting a lot of space. YMMV.)
Another nubie question.
I've been playing with BASIC and trying different things to see if they compile. Now I'm actually trying to run programs on the P1 on a QuickStart board (flash LEDs, run multiple cogs) getting ready to try them out on the P2ES.
I am using spin2gui with Windows 7. When I try to use "Compile & Run", I get an error message "Propeller not found on com 1". That makes sense since my Prop 1 is on com 6.
Same thing happens if I just try run binary.
How can I change the binary loading program to use a different com port?
My work around is to associate the PropTool with .binary files, and click on the binary file. Then use the PropTool info screen to load the EEPROM. I'm also using the Parallax Serial Terminal as the print device.
Tom
I think you can change the Run command line (under Commands > Configure Commands...) to include a "-p COM6" option to specify the port. I'm surprised proploader would need this, it's usually pretty good at finding propellers automatically. I have been meaning to add a menu option for doing this, because some people have asked about supporting multiple props; but I haven't had a chance yet.
Regards,
Eric
I've been experimenting with spin2gui, and it seems tthat it does not identify the Propeller chip on any of my boards. It works with the Activity Board. So, it can be one or both:
- My boards use a 6MHz crystal instead of a 5MHz one.
- My boards use the !RTS signal AC coupled via a capacitor, without any inverting transistor, for the reset. The Activity Board uses the !DTR signal, AC coupled and inverted via a transistor.
I haven't explored what is going wrong. SimpleIDE works fine with my boards, provided that the correct settings are configured. Does your software allows to to change the frequency and signals, to account for different hardware?
Kind regards, Samuel Lourenço
spin2gui doesn't do anything to detect the boards, it relies on the proploader tool (written by @dbetz) to do that. The tool to be used can be configured easily in the spin2gui Commands menu, so if proploader doesn't work but propeller-load does then you could try that.
Regards,
Eric
I tried that and got a compiler error. The message window listed all the compiler switches and -p is eliminate the preprocessor.
Tom
spin2gui has two separate phases: first it compiles the source code into a binary by invoking a compiler (the default is fastspin). Then it loads that binary to the board and runs it there, using proploader by default on P1 and loadp2 on P2.
I think you changed the "Compile command" (the one that invokes fastspin) and not the "Run command" (the one that invokes proploader). The "-p COM6" needs to go after "%D/bin/proploader" in the "Run command", the second command shown in the "Configure commands..." dialog box.
Regards,
Eric
There's a "smartpin_serial_turnaround.spin2" file in the v32i FPGA distribution. I'm not sure if that's exactly what you wanted, but it probably would provide some nice hints.
You might want this too:
Eric,
Thanks for the help. I haven't used BASIC in many years. It was fun then. It is also now. Thanks for developing this. I especially like being able to see the resulting PASM.
Tom
So I followed your advice to twm and put -p COM33 into the loader command and believe I am now talking to the P2.
Now when I "compile and load" blink1 from the samples (changing ledpin = 56), I see activity on LED P63 and P60 and P61. Then P60 goes out, then P61. But nothing on P56. I'm sure I have some simple error. Can you advise?
Secondly, how do I configure the terminal that comes up to COM33?
AdThanksVance
Commands->Configure Commands->P2 Defaults
to compile for P2...