Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BASIC script cannot be interrupted #146

Open
PSLLSP opened this issue Aug 9, 2020 · 1 comment
Open

BASIC script cannot be interrupted #146

PSLLSP opened this issue Aug 9, 2020 · 1 comment

Comments

@PSLLSP
Copy link

PSLLSP commented Aug 9, 2020

Programmers are humans and they do mistakes. One of them is that they write a code that runs, by a mistake, in never ending loop. BusPirate BASIC doesn't allow user to exit from never ending loop. When BASIC programs runs the never ending loop, BusPirate device has to be disconnected and BASIC script is lost. Find an error, type script and try again.. ;-)

This was my favorite BASIC program in the past century when I played with ZX-Spectrum (the first program in ZX-Spectrum BASIC tutorial?):

HiZ(BASIC)>list

10  PRINT "*";
20  GOTO 10
65535  END 
17 bytes.
Ready
HiZ(BASIC)>

Type RUN and try to break the loop back to the command prompt... ;-)

Another example, less crude program, try to break the loop before it reach 10000:

HiZ(BASIC)>list

10  FOR I=1 TO 10000
20  PRINT I
30  NEXT I
65535  END 
25 bytes.
Ready
HiZ(BASIC)>

BASIC at BusPirate has other interesting features, the simplest way to crash BASIC script:

HiZ(BASIC)>list

10  PRINT 42
65535  END 
9 bytes.
Ready
HiZ(BASIC)>run

Yes, there is no output and you have to reconnect your BusPirate device to reach command prompt... I have found several bugs like this that valid commands crash BASIC script and program is lost... That makes scripting PirateBus in BASIC script very difficult and time consuming.

It is not easy to type BASIC scripts to terminal but I have found that Python project to run scripts on BusPirate makes my life easier. It is here https://github.com/clvLabs/BusPirate

Script to upload simple BASIC script to BP:

$ cat test1.bp 
s
new
10 FOR I=1 TO 10
20 PRINT I
30 NEXT I
40 PRINT "Hello World!"
list
exit
$ python3 buspirate.py -c /dev/ttyUSB2 test1.bp
***[ Bus Pirate scripting tool ]********************************************************************
Script file                             test1.bp
COM port                                /dev/ttyUSB2
- Opening serial port
[OK] Serial port open
- Resetting board
>>> ------------------------------------| # 
<<< #
<<< RE
<<< Bus Pirate v3.b clone w/different PIC
<<< Firmware v6.3-beta1 r2151  Bootloader v4.4
<<< DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
<<< http://dangerousprototypes.com
<<< HiZ>
- Sending script file (test1.bp) - 8 lines
>>> ------------------------------------| s 
<<< s
<<< HiZ(BASIC)>
>>> ------------------------------------| new 
<<< new
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 10 FOR I=1 TO 10 
<<< 10 FOR I=1 TO 10
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 20 PRINT I 
<<< 20 PRINT I
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 30 NEXT I 
<<< 30 NEXT I
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 40 PRINT "Hello World!" 
<<< 40 PRINT "Hello World!"
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| list 
<<< list
<<< 
<<< 10  FOR I=1 TO 10
<<< 20  PRINT I
<<< 30  NEXT I
<<< 40  PRINT "HELLO WORLD!"
<<< 65535  END 
<<< 41 bytes.
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| exit 
<<< exit
<<< Ready
<<< HiZ>
- Closing serial port

WARNING, buspirate.py starts communication with RESET command #, script at BP device is deleted during reset... And I added new command to my script too, it is needed in the case that BP is already in BASIC mode and # command doesn't work...

Note. To enter BASIC mode, enter s command from BP modes, to exit from BASIC back to command interface, use type exit. Program is not lost after exit and you can return to BASIC mode with s command and continue your scripting.

HiZ>s
HiZ(BASIC)>
Syntax error
Ready
HiZ(BASIC)>10 print "Hello World!"
Ready
HiZ(BASIC)>list

10  PRINT "HELLO WORLD!"
65535  END 
21 bytes.
Ready
HiZ(BASIC)>run
HELLO WORLD!

Ready
HiZ(BASIC)>exit
Ready
HiZ>
HiZ>s
HiZ(BASIC)>list

10  PRINT "HELLO WORLD!"
65535  END 
21 bytes.
Ready
HiZ(BASIC)>exit
Ready
HiZ>

Note that pressing ENTER with no command in BASIC mode results in "Syntax error". This is a bug from my point if view...
Other interesting feature of this micro BASIC is that it doesn't like lower case strings, it converts them to uppercase strings. That was a feature of BASIC at ZX-81 because there were no lowercase characters on the keyboard and no space for lowercase characters in character generator for the screen. We have year 2020 and we are back, that is called evolution... ;-)

My BusPirate is from eBay, small cute box with two LEDs.

HiZ>i
Bus Pirate v3.b clone w/different PIC
Firmware v6.3-beta1 r2151  Bootloader v4.4
DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
http://dangerousprototypes.com
@rchyla
Copy link

rchyla commented Feb 10, 2024

Hello!

It's been 4 years, but if anyone want to prevent their basic code from being lost, write it in notepad and then send the file using terminal (if possible), Terra Term have a file>send file... option that works in this fashion, it allows to paste content from clipboard too or just log your activity from which you can retrieve eventually what you lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants