Raspberry BASIC

Recent Posts

Pages: 1 2 [3] 4
21
ScriptBasic / RPi GPIO Support
« Last post by John Spikowski on April 25, 2019, 10:35:00 AM »
I have the GPIO extension module built with limited testing. I'm assuming the gpio argument is a 0 or 1 indicating the physical hardware or an emuator. It would be sweet if I can access the Python based Sense HAT emulator.

* Unzip to a tmp directory.
* Copy the gpio.so file to your /usr/local/lib/scriba/ directory.
* Copy the gpio.bas file to your /usr/local/include/scriba/ directory.

Simple Test

Code: Script BASIC
  1. ' Test GPIO
  2.  
  3. IMPORT gpio.bas
  4.  
  5. status = GPIO::Setup()
  6. PRINT status,"\n"
  7. GPIO::Cleanup
  8.  

pi@RPi3B:~/sbrpi/examples $ scriba testgpio.sb
0
pi@RPi3B:~/sbrpi/examples $

gpio.bas (extension module include file)
Code: Script BASIC
  1. 'GPIO Extension Mondule
  2.  
  3. GLOBAL CONST SETUP_OK           = 0
  4. GLOBAL CONST SETUP_DEVMEM_FAIL  = 1
  5. GLOBAL CONST SETUP_MALLOC_FAIL  = 2
  6. GLOBAL CONST SETUP_MMAP_FAIL    = 3
  7. GLOBAL CONST SETUP_CPUINFO_FAIL = 4
  8. GLOBAL CONST SETUP_NOT_RPI_FAIL = 5
  9.  
  10. ' Is really 0 for control register!
  11. GLOBAL CONST IN   = 1
  12. ' Is really 1 for control register!
  13. GLOBAL CONST OUT  = 0
  14. GLOBAL CONST ALT0 = 4
  15.  
  16. GLOBAL CONST HIGH    = 1
  17. GLOBAL CONST LOW     = 0
  18.  
  19. GLOBAL CONST PUD_OFF  = 0
  20. GLOBAL CONST PUD_DOWN = 1
  21. GLOBAL CONST PUD_UP   = 2
  22.  
  23.  
  24. MODULE GPIO
  25.  
  26. DECLARE SUB    ::Setup             ALIAS     "sb_setup"                 LIB "gpio"
  27. DECLARE SUB    ::ClearEventDetect  ALIAS     "sb_clear_event_detect"    LIB "gpio"
  28. DECLARE SUB    ::EventDetected     ALIAS     "sb_eventdetected"         LIB "gpio"
  29. DECLARE SUB    ::SetRisingEvent    ALIAS     "sb_set_rising_event"      LIB "gpio"
  30. DECLARE SUB    ::SetFallingEvent   ALIAS     "sb_set_falling_event"     LIB "gpio"
  31. DECLARE SUB    ::SetHighEvent      ALIAS     "sb_set_high_event"        LIB "gpio"
  32. DECLARE SUB    ::SetLowEvent       ALIAS     "sb_set_low_event"         LIB "gpio"
  33. DECLARE SUB    ::SetPullUpDn       ALIAS     "sb_set_pullupdn"          LIB "gpio"
  34. DECLARE SUB    ::SetupGPIO         ALIAS     "sb_setup_gpio"            LIB "gpio"
  35. DECLARE SUB    ::GPIOFunction      ALIAS     "sb_gpio_function"         LIB "gpio"
  36. DECLARE SUB    ::OutputGPIO        ALIAS     "sb_output_gpio"           LIB "gpio"
  37. DECLARE SUB    ::InputGPIO         ALIAS     "sb_input_gpio"            LIB "gpio"
  38. DECLARE SUB    ::Cleanup           ALIAS     "sb_cleanup"               LIB "gpio"
  39. DECLARE SUB    ::ShortWait         ALIAS     "sb_short_wait"            LIB "gpio"
  40.  
  41. END MODULE
  42.  

c_gpio.h (function declarations)
Code: C
  1. int setup(void);
  2. void setup_gpio(int gpio, int direction, int pud);
  3. int gpio_function(int gpio);
  4. void output_gpio(int gpio, int value);
  5. int input_gpio(int gpio);
  6. void set_rising_event(int gpio, int enable);
  7. void set_falling_event(int gpio, int enable);
  8. void set_high_event(int gpio, int enable);
  9. void set_low_event(int gpio, int enable);
  10. int eventdetected(int gpio);
  11. void cleanup(void)
  12. void short_wait(void) // wait 150 cycles
  13.  

raspberry-gpio-python (wrapped C interface as an ext. module))

BCM2835-ARM-Peripherals.pdf

Note: This was compiled on my RPi 3B. I will compile a Zero version after this is tested.

I have a Raspberry Pi Sense HAT board and a KooKye Smart Home IoT Sensor Kit.

Looking forward to your test scripts!
22
Liberty BASIC / About Liberty BASIC
« Last post by CarlGundel on April 20, 2019, 11:23:52 PM »
You can find the Liberty BASIC website at http://www.libertybasic.com and our community forum at http://libertybasiccom.proboards.com

Liberty BASIC was developed starting back in 1991 and was first released in 1992 for Microsoft Windows.  A version for OS/2 was also in the works and was released as a beta version but cancelled when IBM discontinued OS/2.

Liberty BASIC is inspired by the BASIC interpreters of the 1970s and 1980s in terms of it's simplicity.  It is similar to Microsoft BASICs of that time but it adds modern language features such as named functions and subroutines, structured programming and it drops the requirement of using line numbers.  This is similar to QBASIC in its format.  Liberty BASIC also includes an easy way to make GUIs from windows, buttons, lists, checkboxes, menus, etc.  It can call out to operating system APIs and can use external DLLs.

Other features include:

-A syntax coloring editor
-Debugger with stepping and breakpoints
-Graphics and sprite animation
-WAV file sound and MIDI support
-Joystick reading

We are currently shipping Liberty BASIC v4.5.1 and now actively alpha testing a completely new implementation of Liberty BASIC v5.0 which is our first Liberty BASIC for multiple operating systems including Windows, MacOS, x86 and 64-bit Linux and the Raspberry Pi.
23
Liberty BASIC / Liberty BASIC v5.0 for the Raspberry Pi - testing begins
« Last post by CarlGundel on April 19, 2019, 07:36:52 PM »
Hey all,

This is a very exciting time for us!  We recently began alpha testing for Liberty BASIC v5.0 and this includes a native ARM version for the Raspberry Pi!

If you're interested in BASIC and can brave the thorns and briars of alpha testing please check out our announcement here.

  http://libertybasiccom.proboards.com/board/12/liberty-basic-v5

Hope to see you!  :-)

-Carl Gundel, author of Liberty BASIC
24
C BASIC / Hello C BASIC
« Last post by John Spikowski on April 19, 2019, 07:30:38 PM »
Code: C
  1. #include <stdio.h>
  2. #include "cbasic.h"
  3.  
  4. MAIN
  5. BEGIN_FUNCTION
  6.   PRINT("Hello, World!\n");
  7. END_FUNCTION
  8.  


$ gcc hello.c -o hello
$ ./hello
Hello, World!
$

25
BBC BASIC / Re: BBC BASIC Compiler?
« Last post by Richard Russell on April 19, 2019, 04:37:25 PM »
On Windows, Charles Pegge (OxygenBasic author) wrote an extension module that provides a dynamic FFI definition and full use of the O2.JIT compiler to create virtual DLLs and code in ASM.
It's a shame it's Windows only.  I want to discourage platform-specific extensions to BBC BASIC for SDL 2.0, especially as one of its great strengths is the cross-platform compatibility.  So although the assembler is invaluable for debugging (notably the profiler, list variables and trace features rely on it) I generally don't use it in application programs.

I've recently been experimenting with shader programming in BBC BASIC, and that opens up the possibility of using the GPU to provide acceleration.  Of course it isn't ideally suited to 'general purpose' programming, but increasingly GPUs are used in applications other than graphics.  It potentially has the advantage of being fully cross-platform because all GPUs will run the same source code (it even gets around Apple's prohibition on running arbitrary code in iOS!).
26
ScriptBasic / ScriptBasic Keyword List
« Last post by John Spikowski on April 18, 2019, 02:42:02 AM »
This is the ScriptBasic keyword list.

ABS
ACOS
ACOSECANT
ACTAN
ADDDAY
ADDHOUR
ADDMINUTE
ADDMONTH
ADDRESS
ADDSECOND
ADDWEEK
ADDYEAR
ALIAS
AND
AS
ASC
ASECANT
ASIN
ATAN
ATN
BIN
BINMODE
BY
BYVAL
CALL
CHDIR
CHOMP
CHR
CHR$
CINT
CLOSE
CLOSEALL
COMMAND
CONF
CONST
COS
COSECANT
COTAN
COTAN2
CRYPT
CURDIR
CVD
CVI
CVL
CVS
DAY
DECLARE
DELETE
DELTREE
DIRECTORY
DO
ELIF
ELSE
ELSEIF
ELSIF
END
ENDIF
ENVIRON
ENVIRON$
EOD
EOF
ERROR
ERROR$
EVEN
EXECUTE
EXIT
EXP
FALSE
FILE
FILEACCESSTIME
FILECOPY
FILECREATETIME
FILEEXISTS
FILELEN
FILEMODIFYTIME
FILEOWNER
FIX
FOR
FORK
FORMAT
FORMATDATE
FORMATTIME
FRAC
FREEFILE
FROM
FUNCTION
GCD
GLOBAL
GMTIME
GMTIMETOLOCALTIME
GO
GOSUB
GOTO
HCOS
HCOSECANT
HCTAN
HEX
HEX$
HOSTNAME
HOUR
HSECANT
HSIN
HTAN
ICALL
IF
IMAX
IMIN
INPUT
INSTR
INSTRREV
INT
ISARRAY
ISDEFINED
ISDIRECTORY
ISEMPTY
ISFILE
ISINTEGER
ISNUMERIC
ISREAL
ISSTRING
ISUNDEF
JOIN
JOKER
KILL
LBOUND
LCASE
LCASE$
LCM
LEFT
LEFT$
LEN
LET
LIB
LIKE
LINE
LOC
LOCAL
LOCALTIMETOGMTIME
LOCK
LOF
LOG
LOG10
LOOP
LOWER
LOWER$
LTRIM
LTRIM$
MAX
MAXINT
MID
MID$
MIN
MININT
MINUTE
MKD
MKD$
MKDIR
MKI
MKI$
MKL
MKL$
MKS
MKS$
MODULE
MONTH
NAME
NEXT
NEXTFILE
NO
NOT
NOW
NULL
OCT
OCT$
ODD
ON
OPEN
OPTION
OR
OUTPUT
PACK
PATTERN
PAUSE
PI
POP
POW
PRINT
PRINTNL
QUOTE
RANDOMIZE
REF
REGION
REPEAT
REPLACE
RESET
RESUME
RETURN
REWIND
RIGHT
RIGHT$
RND
ROUND
RTRIM
RTRIM$
SEC
SECANT
SEEK
SET
SGN
SIN
SLEEP
SPACE
SPACE$
SPLIT
SPLITA
SPLITAQ
SQR
STEP
STOP
STR
STR$
STRING
STRING$
STRREVERSE
STRREVERSE$
SUB
SWAP
SYSTEM
TAN
TAN2
TEXTMODE
THEN
TIME
TIMEVALUE
TO
TRIM
TRIM$
TRUE
TRUNCATE
TYPE
UBOUND
UCASE
UCASE$
UNDEF
UNPACK
UNTIL
UPPER
UPPER$
VAL
VAR
WAITPID
WEEKDAY
WEND
WHILE
WILD
XOR
YEAR
YEARDAY

Not Implemented
  • BIN - This is a planned function to convert the argument number to binary format. (aka. format as a binary number containing only 0 and 1 characters and return this string)
  • GCD - Mathematical function has become a reserved word, but are not implemented.
  • LCM - Mathematical function has become a reserved word, but are not implemented.
  • ATN - This is a planned function to calculate the arcus tangent of the argument.
  • ATAN - This is a planned function to calculate the arcus tangent of the argument.
  • TAN - This is a planned function to calculate the tangent of the argument.
  • TAN2 - This is a planned function to calculate the tangent of the ratio of the two arguments.
  • COTAN - This is a planned function to calculate the cotangent of the argument.
  • COTAN2 - This is a planned function to calculate the cotangent of the ratio of the two arguments.
  • ACTAN - This is a planned function to calculate the arcus cotangent of the argument.
  • SECANT - This is a planned function to calculate the secant of the argument.
  • COSECANT - This is a planned function to calculate the cosecant of the argument.
  • ASECANT - This is a planned function to calculate the arcus secant of the argument.
  • ACOSECANT - This is a planned function to calculate the arcus cosecant of the argument.
  • HSIN - This is a planned function to calculate the sinus hyperbolicus of the argument.
  • HCOS - This is a planned function to calculate the cosinus hyperbolicus of the argument.
  • HTAN - This is a planned function to calculate the tangent hyperbolicus of the argument.
  • HCTAN - This is a planned function to calculate the cotangent hyperbolicus of the argument.
  • HSECANT - This is a planned function to calculate the secant hyperbolicus of the argument.
  • HCOSECANT - This is a planned function to calculate the cosecant hyperbolicus of the argument.
  • MAX - This is a planned function to select and return the maximum of the arguments.
  • MIN - This is a planned function to select and return the minimum of the arguments.
  • IMAX - This is a planned function to select and return the index of the maximum of the arguments.
  • IMIN - This is a planned function to select and return the index of the minimum of the arguments.
  • CVD - This is a planned function to convert the argument string into a real number. (8 byte)
  • CVI - This is a planned function to convert the argument string into an integer. (2 bytes)
  • CVL - This is a planned function to convert the argument string into an long integer. (4 bytes)
  • CVS - This is a planned function to convert the argument string into an integer. (4 byte)
  • MKD - This is a planned function to convert the argument real number to an 8 byte string. (8 byte)
  • MKI - This is a planned function to convert the argument integer number to a string. (2 byte)
  • MKS - This is a planned function to converts a single-precision number "n" into a  string so it can later be retrieved from a random-access file as a numeric value. (4 byte)
  • MKL - This is a planned function converts a long-integer number "n" into a string so it can later be retrieved from a random-access file as a numeric value. (4-byte)

Valid ScriptBasic Operators

Power operator (^)
Multiplication operator (*)
Division operator (/)
Integer division operator (\)
Modulus operator (%)
Addition and subtraction operators (+, -)
Bit-wise and logical NOT (NOT)
Equality operator (=)
Not equal operator (<>)
Compare operators (<, <=, >, >=)
Logical operators (and, or, xor)
Concatenation operator (&)
ByVal operator
LIKE operator



 Operators that are undefined by default but can be used by external modules are:


?     !     #     `     @
+^    +<    +>    +?    +=    +*    +/    +%    +!    +#    +&    +\    +`    +'   
+@    -^    -<    ->    -?    -=    -*    -/    -%    -!    -#    -&    -\    -`   
-'    -@    ^^    ^<    ^>    ^?    ^=    ^*    ^/    ^%    ^!    ^#    ^&    ^\   
^`    ^'    ^@    <^    <<    <?    <*    </    <%    <!    <#    <&    <\    <`   
<'    <@    >^    ><    >>    >?    >*    >/    >%    >!    >#    >&    >\    >`   
>'    >@    ?^    ?<    ?>    ??    ?=    ?*    ?/    ?%    ?!    ?#    ?&    ?\   
?`    ?'    ?@    =^    =<    =>    =?    ==    =*    =/    =%    =!    =#    =&   
=\    =`    ='    =@    *^    *<    *>    *?    *=    **    */    *%    *!    *#   
*&    *\    *`    *'    *@    /^    /<    />    /?    /=    /*    //    /%    /!   
/#    /&    /\    /`    /'    /@    %^    %<    %>    %?    %=    %*    %/    %%   
%!    %#    %&    %\    %`    %'    %@    !^    !<    !>    !?    !=    !*    !/   
!%    !!    !#    !&    !\    !`    !'    !@    #^    #<    #>    #?    #=    #*   
#/    #%    #!    ##    #&    #\    #`    #'    #@    &^    &<    &>    &?    &=   
&*    &/    &%    &!    &#    &&    &\    &`    &'    &@    \^    \<    \>    \?   


\=    \*    \/    \%    \!    \#    \&    \\    \`    \'    \@    `^    `<    `>   
`?    `=    `*    `/    `%    `!    `#    `&    `\    ``    `'    `@    '^    '<   
'>    '?    '=    '*    '/    '%    '!    '#    '&    '\    '`    ''    '@    @^   
@<    @>    @?    @=    @*    @/    @%    @!    @#    @&    @\    @`    @'    @@

27
BBC BASIC / Re: BBC BASIC Compiler?
« Last post by John Spikowski on April 18, 2019, 02:30:06 AM »
Thanks Richard for the clarification. That is a sweet feature to have in a BASIC. The best ScriptBasic can do is call C extension modules. On Windows, Charles Pegge (OxygenBasic author) wrote an extension module that provides a dynamic FFI definition and full use of the O2.JIT compiler to create virtual DLLs and code in ASM.

I was fortunate that the Brandy author isoated the BBC BASIC graphic primatives in separate SDL 1.2 module. It made making a generic share object usable in most languages that can call a shared object.
28
BBC BASIC / Re: BBC BASIC Compiler?
« Last post by Richard Russell on April 17, 2019, 05:54:18 PM »
This was the reason I thought BBC BASIC was a BASIC to ASM compiler.

An assembler and a compiler are very different things!

Traditionally BBC BASIC has incorporated an assembler as part of its run-time engine, making it easy to include assembly language subroutines in what is otherwise a BASIC program, typically when interpreted BASIC isn't fast enough or to do things that BBC BASIC doesn't support (such as callbacks).

So the original BBC Micro had an integral 6502 assembler, ARM BBC BASIC had an ARM assembler, BBC BASIC for Windows has a 32-bit x86 assembler etc.  The various editions of BBC BASIC for SDL 2.0 have an assembler appropriate to the platform (32-bit x86, 64-bit 86 or 32-bit ARM).

The exception to this rule is Brandy (and its offspring Napoleon Brandy and Matrix Brandy).  Although 'BBC BASIC' they don't include an assembler, and indeed they are generally less extensible and adaptable than most versions of BBC BASIC are.
29
ScriptBasic / Remote Console Debugger
« Last post by John Spikowski on April 16, 2019, 05:10:03 PM »
This is an example of debugging a script with the console mode interactive debugger.

dbgcontest.sb
Code: Script BASIC
  1. a = 1
  2. b = "ScriptBasic"
  3. PRINT a,"\n"
  4. PRINT b,"\n"
  5.  


pi@raspberrypi:~/sbrpi $ scriba dbgcon.sb dbgcontest.sb
Application: ScriptBasic Remote Debugger
Version: 1.0
Source-File-Count: 1
Source-File: dbgcontest.sb
Current-Line: 1
-> l 1-
 [0001] a = 1
 [0002] b = "ScriptBasic"
 [0003] PRINT a,"\n"
 [0004] PRINT b,"\n"
Current-Line: 1
-> s
Current-Line: 2
-> b4
Message: done
Current-Line: 2
-> r
1
Current-Line: 4
-> G
Global-Variable-Name: main::a
Global-Variable-Value: 1
Global-Variable-Name: main::b
Global-Variable-Value: "ScriptBasic"
Current-Line: 4
-> r
ScriptBasic
Debug session closed.
pi@raspberrypi:~/sbrpi $


Place the sdbg.so in your /usr/local/lib/scriba directory.
The dbgcon.sb script should be in the same directory as the script you're debugging.
30
ScriptBasic / Working with cURL
« Last post by John Spikowski on April 15, 2019, 05:06:58 AM »
This thread will be about using ScriptBasic and the cURL extension module. The first example is what I call my Hello Me cURL example. This is also included in the extension module test scripts I posted in the Resources thread.

Code: Script BASIC
  1. ' MyIP
  2.  
  3. IMPORT curl.bas
  4.  
  5. ch = curl::init()
  6. curl::option(ch,"URL","ipinfo.io")
  7. PRINT curl::perform(ch),"\n"
  8.  
  9. curl::finish(ch)
  10.  

Output

pi@RPi3B:~/sbrpi/examples $ time scriba myip.sb
{
  "ip": "#4.#9.#1.#11",
  "hostname": "c-#4-#9-#1-#11.hsd1.wa.comcast.net",
  "city": "Anacortes",
  "region": "Washington",
  "country": "US",
  "loc": "48.5004,-122.6310",
  "postal": "98221",
  "org": "AS33650 Comcast Cable Communications, LLC"
}

real   0m0.334s
user   0m0.049s
sys   0m0.016s
pi@RPi3B:~/sbrpi/examples $


Pages: 1 2 [3] 4