Announcing a new language <drumroll> - BCX Basic on the Propeller.
BCX is a free Basic to C converter that has been around for years and has a huge range of Basic language commands http://www.bcxgurus.com/help/index.html
Couple this with the Catalina C compiler and it is possible to write programs as small as 900 bytes, or as large as 512k (soon to be 32Mb).
A simple led flasher:
Or more complex code, using strings, huge string arrays, serial ports, the VGA display, Keyboard input, sd card file load/save and full floating point maths. You can even add inline C code into your program.
High(0) ' bit 0 high (pin 1 on physical chip)
Sleep(1000) ' sleep this number of milliseconds
Low(0) ' bit 0 low
Sleep(1000) ' sleep
The simple idea was to just feed some code into BCX - but it turns out that BCX runs C99, and Catalina runs in C89, so there are multiple fixes behind the scenes. This is no problem for the user though, as compilation and download is still as simple as hitting the "Compile" button.
You can even save your program to an sd card and run it later using KyeDOS.
This is a beta release and there will be some instructions that don't work. This is a test program (which is messy, sorry!) which has many of the instructions tested so far:
Because this tests so many functions, the C libraries fill up the memory so this entire program needs a board with external memory (Dracblade, C3, Gadget Gangster 32Mb etc). But it is certainly possible to test parts of this on a Demo board. The VGA and Keyboard fills up a demo board to about 25k leaving maybe 5k of code space.
' Big Basic for external memory on the Propeller using BCX Basic to C converter and Catalina
' mathconst.h upsets tinyc
catalina -lcx -lm -x5 -M 128k -D DRACBLADE -D VGA_HIRES
' library cx, library maths (slow, doesn't use a cog), memory size, board, high res vga, mouse, keyboard
dim a as integer
dim i as integer
for a=1 to 3
print "hello world";
' file test copied from bcx examples - files work - commented out for speed
print "Opening file for output"
DIM MyFileHandle@ ' BCX Reserves @ for "C" FILE* data types
OPEN "new.txt" FOR OUTPUT AS FP1
MyFileHandle@ = FP1
FPRINT MyFileHandle@, "This is a test"
print "Closing file"
' ASC function
DIM Mystring$ as string * 80 ' 80 characters
RetVal% = ASC(Mystring$)
'CHR$ function - opposite of ASC
Mystring$=chr$(a) ' declared in asc
print "Character should be A: ";Mystring$
'VAL function - converts string to double number. From the BCX help file
DIM StringNum$ as string * 20
'STR$ function - opposite of VAL. Converts number to string
DIM RetStr$ as string * 20
DoubleNumber# = 1.23456789
RetStr$ = STR$(DoubleNumber#)
' Test some inline C code - pass a value in myarray, C changes it, print the return value
dim myarray as integer ' this can be much bigger if you like, eg 50000
' test some string functions
dim lineoftext1$ as string * 80 ' strings must end in $ otherwise compiler doesn't copy properly
dim lineoftext2$ as string * 80
lineoftext1$="Hello World" ' string name is case sensitive
lineoftext2$=left$(lineoftext1$,4) ' left characters
print "Left$ test ";lineoftext2$
lineoftext2$=mid$(lineoftext1$,5,4) ' mid characters
print "Mid$ test ";lineoftext2$
lineoftext2$=ucase$(lineoftext1$) ' upper case
print "Upper case test ";lineoftext2$
lineoftext2$=right$(lineoftext1$,3) ' right characters
print "Right$ test ";lineoftext2$
concat(lineoftext1$,lineoftext2$) ' add two strings - same as + or & in vb.net
print "String concat test ";lineoftext1$
lineoftext2$=lcase$(lineoftext1$) ' lower case
print "Lower case test ";lineoftext2$
lineoftext1$=hex$(a) ' hex$ working
dim retval% ' hex2dec = two errors, DWORD (which I think can be changed to unsigned long) and CharLowerA which instr also is unhappy about
retval%=hex2dec("0xFFFF") ' reverse of hex$, can use 0x or &H syntax or even FFFF
print "Hex2Dec test ";retval%
a=instr(lineoftext1$,lineoftext2$,3,0) ' instr search for characters. Last value is needed, use dummy 0 (matches case)
print "Instr test, string is at position ";a
lineoftext1$=bin$(a) ' test binary
lineoftext1$=lpad$(lineoftext1$,32,48) ' test adding leading zeros with lpad so is always 32 char long
print "Binary value is ";lineoftext1$ ' test binary to strings and back again
print "Binary string to decimal ";Bin2dec(lineoftext1$) ' binary
print "String function ";lineoftext1$' n characters of ascii value m
lineoftext1$=" trim test " ' trim off leading zeros, spaces etc
print "Trim test:";lineoftext1$
' test a string array
dim stringarray as string * 80 ' 80 characters
' bitwise operators - there are many more of these but they all seem to work ok without code changes
a=a << 10
print "bitwise shift left";a
a=a >> 4
print "bitwise shift right";a
a=a and 0xFF
print "logical and";a
a=a or 0xFF
print "logical or";a
print "test starting with a binary string and shifting"; bin2dec("00000001") << 4
' test program control loops - FOR is already tested above
loop until a=3
print "Do loop finished"
while a <3
incr(a)' translates to a++ in C
print "Wend loop finished"
select case a
case > 1 and < 6
print "more than 1 and less than six"
print "something else"
' test functions
' test some maths with floating point numbers
dim number1 as double
while(1); // loop instead of finishing
' and exitprocess does not work on the propeller. So don't use END for the moment
' subroutines and functions
function addnumbers(a as integer, b as integer)
dim returnvalue as uint
returnvalue = a + b
// declare the variables:
// now, give a value to them:
nNumber = 15;
pPointer = &nNumber;
// print out the value of nNumber:
printf("nNumber is equal to : %d\n", nNumber);
// now, alter nNumber through pPointer:
*pPointer = 25;
// prove that nNumber has changed as a result of the above
// by printing its value again:
printf("nNumber is equal to : %d\n", nNumber);
Sub WhiteOnBlue() ' white text on blue background
t_setpos(0,0,i); // move cursor to next line
t_color(0,0x08FC); // RRGGBBxx eg dark blue background 00001000 white text 11111100
The IDE also runs TinyC which means you can compile and run a test program in about half a second without having to download to a propeller. Very useful for testing subroutines.
To test, you will need:
1) Download and install Catalina to the default directory c:\program files\catalina http://catalina-c.sourceforge.net/
2) Download and install BCX to the default directory c:\program files\bcx http://www.bcxgurus.com/
3) (optional) Download and install TinyC to the default directory c:\program files\tcc http://bellard.org/tcc/ scroll down a little for the 'download' section.
4) Download and install the Catalina IDE "Compiled" zip below. This is a combined IDE for C and Basic (as well as a few other things, like a tile builder, movie maker and file transfer program).
5) Because this is a beta test, it may help to have the source code IDE running rather than the compiled version (there are still a few program shutdowns that I haven't put "catch ex as exceptions" into. So download the IDE source, and also vb.net. http://www.microsoft.com/express/Downloads/
This program is written in vb.net 2008 which is getting harder to find on the Microsoft website and there is a chance that vb.net 2010 won't run the 2008 version. If this happens to anyone I'll upgrade to 2010.
Suggestions, bugs, improvements all gratefully received.