Tagged: BINSIC
Tiny BASIC for the Raspberry Pi
A complete Tiny BASIC environment has been ported to the Raspberry Pi.
Only slightly miffed that no one seems to have noticed that I was running BASIC on this platform more than three months ago
Getting booted from Wikipedia
A short article on “Binsic Is Not Sinclair Instruction Code” (BINSIC), my BASIC-like interpreter/DSL for Groovy faces getting deleted from Wikipedia on the grounds of lack-of-notability.
It would not be right or proper for me to intervene to stop this, but if you have been a BINSIC user then a proper third-party reference to it (followed by a clearance of the deletion message in the prescribed manner) would be very much appreciated.
The BINSIC article does not generate much traffic here (perhaps a visit a day), so I admit it is not a particularly important project in the world of computer science, but I hope it has been fun for at least a few people and it is worth keeping as a link to a quick and easy way to get BASIC on your computer.
Related articles
- Wickedpedia: The dark side of Wikipedia (zdnet.com)
- Is Wikipedia going commercial? (salon.com)
- Another time. Another attack to Wikipedia. (jacopobacchi.wordpress.com)
- Wikipedia Is Nearing Completion, in a Sense (theatlantic.com)
- Where Are All the Women of Wikipedia? [Wikipedia] (jezebel.com)
- Requesting open-licensed, open-format recordings of the voices of Wikipedia subjects for Wikimedia Commons (pigsonthewing.org.uk)
More than a game: the Game of Life
Conway’s Game of Life has long fascinated me. Thirty years ago I wrote some Z80 machine code to run it on a Sinclair ZX80 and when I wrote BINSIC, my reimplentation of Sinclair ZX81 BASIC, Life was the obvious choice for a demonstration piece of BASIC (and I had to rewrite it from scratch when I discovered that the version in Basic Computer Games was banjaxed).
But Life is much more than a game – it continues to be the foundation of ongoing research into computability and geometry - as the linked article in the New Scientist reports.
For me, it’s just fun though. When I wrote my first version of it back in 1981 I merely used the rubric in Basic Computer Games – there was no description of gliders or any of the other fascinating patterns that the game throws up – so in a sense I “discovered” them independently, with all the excitement that implies: it is certainly possible to spend hours typing in patterns to see what results they produce and to keep coming back for more.
- “Life.bas” should run on any system that will support the Java SDK – for instance it will run on a Raspberry Pi – follow the instructions on the BINSIC page. A more up to date version may be available in the Github repository at any given time (for instance, at the time of writing, the version in Git supports graphics plotting, the version in the JAR file on the server only supports text plotting). On the other hand, at any given time the version in Git may not work at all: thems the breaks. If you need assistance then just comment here or email me adrianmcmenamin at gmail.
Related articles
- BINSIC plotting working (cartesianproduct.wordpress.com)
- Relive the ZX81 experience on your desktop (cartesianproduct.wordpress.com)
- A glider on an aperiodic cellular automaton exists! (aperiodical.com)
- Running BASIC on the Raspberry Pi (cartesianproduct.wordpress.com)
- Google Hides a “Game of Life” Easter Egg on the Search Page (news.softpedia.com)
BINSIC plotting working
At the risk of being attacked as an enemy of all that is good, I have to confess to being less than riveted by the Olympics, so far. So I have made far more productive use of my time in seeking to recreate the computing experience of 30 years ago – by working some more on BINSIC – Binsic Is Not Sinclair Instruction Code, my reimplementation of Sinclair ZX81 BASIC.
I have finally got PLOT and UNPLOT to work – not on the same screen as ordinary output, but on a separate graphics console.
As the above – from Conway’s Game of Life – shows, this has all the sophistication and élan of the original ZX81 experience!
It’s just in the Git repo now (at Github under mcmenaminadrian) but an executable JAR will follow shortly.
Related articles
- Running BASIC on the Raspberry Pi (cartesianproduct.wordpress.com)
- The expressive power of BASIC (cartesianproduct.wordpress.com)
- Relive the ZX81 experience on your desktop (cartesianproduct.wordpress.com)
Running BASIC on the Raspberry Pi
Actually, I ran BINSIC, my very own dialect of BASIC on the Raspberry Pi – it is very slow (a bit slower even than a ZX81 back in the day) but it does work.
Haven’t had a chance to investigate what happens if I tweak the settings on the thing – possibly I might be able to speed execution up. Could be that Java and Groovy is just too much bloat, could be that BINSIC just demands a lot of computation (I refuse to consider that it might be poorly designed and executed).
Related articles
- Raspbian Linux now available for Raspberry Pi: Up to 40 percent faster than Debian (liliputing.com)
- Raspberry Pi now available for general order (slashgear.com)
- Raspbian: The fastest operating system for the Raspberry Pi (liliputing.com)
- Want to buy more than one Raspberry Pi? Now you can! (raspberrypi.org)
- ODROID-X: The $129 Quad-core Alternative to Raspberry Pi (tomshardware.com)
- Raspberry Pi launched by balloon broadcast images from 40km high (raspberrypi.org)
Some fixes for BINSIC
I have made a few small, but important, fixes to BINSIC, the reimplementation of BASIC I have built using Groovy.
You can download the jar file (which can be run in any standard Java environment) from here: http://88.198.44.150/binsic.jar
Here’s another BASIC “game” (it’s amazing that this sort of thing used to fascinate those of us with these machines), for you to try – it was fixing this up that helped me find the bugs:
10 REM **DICE GAME**SLR/1983** 20 LET A=0 30 LET B=0 40 PRINT "DICE GAME" 60 PRINT "YOUR THROW=" 70 GOSUB 160 80 PRINT "MY THROW=" 90 GOSUB 220 100 IF A>B THEN PRINT "YOU WIN" 110 IF A<B THEN PRINT "I WIN" 120 IF A = B THEN PRINT "TIE" 130 LET X$ = INKEY$ 132 IF X$ = "" THEN GOTO 130 136 CLS 140 IF X$ = "S" THEN STOP 150 GOTO 10 160 FOR G=1 TO 2 170 LET Z=INT (RND*6+1) 180 LET A=A+Z 190 GOSUB 280 195 PRINT 200 NEXT G 210 RETURN 220 FOR G=1 TO 2 230 LET Z=INT (RND*6+1) 240 LET B=B+Z 250 GOSUB 280 260 NEXT G 270 RETURN 280 REM Draw 282 PAUSE 100 285 IF Z = 1 THEN GOSUB 500 290 IF Z = 2 THEN GOSUB 600 300 IF Z = 3 THEN GOSUB 700 310 IF Z = 4 THEN GOSUB 800 320 IF Z = 5 THEN GOSUB 900 330 IF Z = 6 THEN GOSUB 1000 340 RETURN 400 PRINT "[ ][ ][ ]" 410 RETURN 420 PRINT "[*][ ][*]" 430 RETURN 440 PRINT "[ ][*][ ]" 450 RETURN 460 PRINT "[*][ ][ ]" 470 RETURN 480 PRINT "[ ][ ][*]" 490 RETURN 500 REM 1 510 GOSUB 400 520 GOSUB 440 530 GOSUB 400 540 RETURN 600 REM 2 610 GOSUB 460 620 GOSUB 400 630 GOSUB 480 640 RETURN 700 REM 3 710 GOSUB 460 720 GOSUB 440 730 GOSUB 480 740 RETURN 800 REM 4 810 GOSUB 420 820 GOSUB 400 830 GOSUB 420 840 RETURN 900 REM 5 910 GOSUB 420 920 GOSUB 440 930 GOSUB 420 940 RETURN 1000 REM 6 1010 GOSUB 420 1020 GOSUB 420 1030 GOSUB 420 1040 RETURN
The original game can be found here: http://zx81.reids4fun.com/zx81/dice/dice_list.html – I had to change it to cope with the main weakness of BINSIC – that GOTOs to lines inside loops fail.
Raspberry Pi delivered
So, what do I do now?
My original plan was to run my BASIC-as-a-DSL that became BINSIC on it, but I am just not convinced that’s a good use of it now (or that BASIC is, in general, a good educational tool).
Want to do something interesting and out of the ordinary with it though – I only have one, so the other obvious idea: “imagine a Beowulf cluster of those!” is also out for now.
Related articles
- You can now run Arch & Debian Linux on a Raspberry Pi (zdnet.com)
- The MagPi – A Magazine For Raspberry Pi Users – Issue 3 is here! (adafruit.com)
- The MagPi, a magazine for Raspberry Pi users – #piday #raspberrypi @Raspberry_Pi (adafruit.com)
- Raspberry Pi Wireless Display Using a Cheap Parrot LCD Photo Frame #piday #raspberrypi @Raspberry_Pi (adafruit.com)
- Raspberry Pi passes critical test – almost set for sale (zdnet.com)
Life: rewritten
Well, what else was I going to do? This works and that means I think BINSIC does too. It’s not quite a fully functional BASIC – try as I might I cannot get GOTO or even GOSUB to work inside loops (though I might do better if plough on with the GOSUB stuff), but I’ll hopefully launch it all tomorrow evening.
10 REM Game of Life 20 PRINT "Conway's Game of Life" 30 PRINT "Copyright Adrian McMenamin, 2012" 35 PRINT "adrianmcmenamin@gmail.com" 40 PRINT "Licensed under the GPL version 3" 50 DIM A(48, 70) 60 DIM B$(24) 70 PRINT "Please enter your pattern" 75 PRINT " - up to 24 lines of 70 characters" 80 FOR I = 1 TO 24 90 INPUT B$(I) 95 LET T = 0 97 IF B$(I) = "DONE" THEN LET T = 1 98 IF T = 1 THEN LET B$(I) = "" 100 IF T = 1 THEN GOTO 150 110 PRINT B$(I) 120 NEXT I 150 REM Parse Input 160 LET P = 0 170 LET G = 0 175 LET Y = 0 177 LET Q = 0 180 FOR Y = 1 TO 24 190 LET Z = LEN B$(Y) 210 IF Z = 0 THEN NEXT Y 220 FOR Q = 1 TO Z 222 LET A(Y, Q) = 0 225 IF MID$(B$(Y), Q, 1) = " " THEN LET A(Y + 24, Q) = 0 230 IF MID$(B$(Y), Q, 1) <> " " THEN LET A(Y, Q) = 1 232 IF MID$(B$(Y), Q, 1) <> " " THEN LET A(Y + 24, Q) = 1 234 IF MID$(B$(Y), Q, 1) <> " " THEN LET P = P + 1 240 NEXT Q 250 FOR Q = Z + 1 TO 70 260 LET A(Y, Q) = 0 265 LET A(Y + 24, Q) = 0 270 NEXT Q 280 NEXT Y 300 REM Display Map 310 PRINT 320 PRINT 330 PRINT 340 PRINT "Generation ", G, " Population is ", P 350 FOR M = 1 TO 24 355 PRINT 360 FOR N = 1 TO 70 370 IF A(M + 24, N) = 1 THEN PRINT "*"; 375 IF A(M + 24, N) <> 1 THEN PRINT " "; 380 NEXT N 390 NEXT M 400 REM Map next generation 410 FOR M = 1 TO 24 420 FOR N = 1 TO 70 430 LET A(M, N) = 0 440 IF M + 1 < 25 AND A(M + 25, N) = 1 THEN LET A(M, N) = A(M, N) + 1 450 IF M - 1 > 0 AND A(M + 23, N) = 1 THEN LET A(M, N) = A(M, N) + 1 460 IF N + 1 < 71 AND A(M + 24, N + 1) = 1 THEN LET A(M, N) = A(M, N) + 1 470 IF N - 1 > 0 AND A(M + 24, N - 1) = 1 THEN LET A(M, N) = A(M, N) + 1 480 IF M - 1 > 0 AND N - 1 > 0 AND A(M + 23, N - 1) = 1 THEN LET A(M, N) = A(M, N) + 1 490 IF M - 1 > 0 AND N + 1 < 71 AND A(M + 23, N + 1) = 1 THEN LET A(M, N) = A(M, N) + 1 500 IF M + 1 < 25 AND N - 1 > 0 AND A(M + 25, N - 1) = 1 THEN LET A(M, N) = A(M, N) + 1 510 IF M + 1 < 25 AND N + 1 < 71 AND A(M + 25, N + 1) = 1 THEN LET A(M, N) = A(M, N) + 1 520 NEXT N 530 NEXT M 540 LET P = 0 600 FOR M = 1 TO 24 610 FOR N = 1 TO 70 611 LET ZZ = 0 612 LET SC = A(M, N) 612 IF A(M + 24, N) = 1 THEN LET ZZ = 1 613 LET RES = 0 614 IF ZZ = 0 AND SC = 3 THEN LET RES = 1 615 IF ZZ = 1 AND (SC = 2 OR SC = 3) THEN LET RES = 1 616 LET A(M + 24, N) = RES 617 LET P = P + RES 650 NEXT N 660 NEXT M 700 PAUSE 50000 800 LET G = G + 1 900 GOTO 310
A problem with Life

Bill Gosper’s Glider Gun in action—a variation of Conway’s Game of Life. This image was made by using Life32 v2.15 beta, by Johan G. Bontes. (Photo credit: Wikipedia)
I had hoped to “launch” BINSIC – Binsic Is Not Sinclair Instruction Code – my BASIC-as-a-DSL project built using Groovy, this weekend. For the launch I wanted to publish a jar file (so usable by everyone with Java) that ran the version of Conway’s Game of Life (seemed very appropriate for both general – Life being the ultimate hacker meme – and personal – I once wrote a version of Life in Z80 machine code for the ZX80 – reasons) found in Basic Computer Games – but I don’t think I am going to manage it now
The problem is that the code in the book is totally banjaxxed. It uses variables before they are declared and in general looks as though either some lines have been transposed or some code has been omitted altogether. It is certainly plain that the printout of the running program in the book does not reflect the code found on its pages. In any case hacking at this code reveals the full horror of BASIC and how difficult it is to maintain code that is not even in blocks, never mind any other sort of order.
So I have two choices – refactor the BASIC I have in quite a big way to get it to run, or find some new code instead.
But the exercise has not been completely wasted. While hunting down the bugs in David H Ahl’s code I have found more than a few in BINSIC itself.
Related articles
- Life in Life: Conway’s Game of Life Self-Similarity (adafruit.com)
- Conway’s Game of Life in HD (hackaday.com)
- Life imitates Life (aperiodical.com)
- Hadoop’s Game of Life (datasalt.com)
BINSIC almost done
BINSIC, my BASIC-as-a-DSL, is almost complete now, though I am rather ashamed at the first big program I used to test it – I just grabbed it off an archive of content from the legendary Basic Computer Games and did not look too closely at what it was about.
8 PRINT "You are a pilot in a Second World War bomber." 10 PRINT "Which side -- Italy(1), Allies(2), Japan(3), Germany(4)" 12 INPUT A 20 IF A > 0 AND A < 5 THEN GOTO 25 22 PRINT "TRY AGAIN..." 24 GOTO 10 25 IF A = 1 THEN GOTO 30 26 IF A = 2 THEN GOTO 110 27 IF A = 3 THEN GOTO 200 28 IF A = 4 THEN GOTO 220 30 PRINT "YOUR TARGET -- Albania(1), Greece(2), North Africa(3)" 35 INPUT B 40 IF B>0 AND B<4 THEN GOTO 45 42 PRINT "TRY AGAIN..." 43 GOTO 30 45 PRINT "" 46 IF B = 1 THEN GOTO 50 47 IF B = 2 THEN GOTO 80 48 IF B = 3 THEN GOTO 90 50 PRINT "SHOULD BE EASY -- YOU'RE FLYING A NAZI-MADE PLANE." 60 GOTO 280 80 PRINT "BE CAREFUL!!!" 85 GOTO 280 90 PRINT "Going for the oil, eh?" 95 GOTO 280 110 PRINT "AIRCRAFT -- Liberator(1), B-29(2), B-17(3), Lancaster(4)" 115 INPUT G 120 IF G>0 AND G<5 THEN GOTO 125 122 PRINT "TRY AGAIN..." 123 GOTO 110 125 PRINT "" 126 IF G = 1 THEN GOTO 130 127 IF G = 2 THEN GOTO 150 128 IF G = 3 THEN GOTO 170 129 IF G = 4 THEN GOTO 190 130 PRINT "You have got 2 tons of bombs flying for Ploesti." 135 GOTO 280 150 PRINT "You are dumping the A-bomb on Hiroshima." 155 GOTO 280 170 PRINT "You are chasing the Bismark in the North Atlantic." 175 GOTO 280 190 PRINT "You are targeting the Ruhr." 195 GOTO 280 200 PRINT 201 PRINT "You are flying a KAMIKAZE mission over the USS Lexington." 205 PRINT "Your first Kamikaze mission? (Y OR N)" 206 INPUT F$ 207 IF F$ = "N" THEN LET S = 0 208 IF F$ = "N" THEN GOTO 358 210 PRINT "" 212 IF RND > 0.65 THEN GOTO 325 215 GOTO 380 220 PRINT "A NAZI, EH? Oh well. Are you going for Russia(1)," 230 PRINT "England(2), or France(3)" 231 INPUT M 232 IF M>0 AND M<4 THEN GOTO 235 233 PRINT "TRY AGAIN..." 234 GOTO 220 235 PRINT "" 240 IF M = 1 THEN GOTO 250 242 IF M = 2 THEN GOTO 260 243 IF M = 3 THEN GOTO 270 250 PRINT "YOU'RE NEARING STALINGRAD." 255 GOTO 280 260 PRINT "NEARING LONDON. BE CAREFUL, THEY'VE GOT RADAR." 265 GOTO 280 270 PRINT "NEARING VERSAILLES. DUCK SOUP. THEY'RE NEARLY DEFENSELESS." 280 PRINT 285 PRINT "HOW MANY MISSIONS HAVE YOU FLOWN" 287 INPUT D 290 IF D < 160 THEN GOTO 300 292 PRINT "MISSIONS, NOT MILES..." 295 PRINT "150 missions is high even for old-timers." 297 PRINT "NOW THEN, "; 298 GOTO 285 300 PRINT 302 IF D < 100 THEN GOTO 310 305 PRINT "THAT'S PUSHING THE ODDS!" 307 GOTO 320 310 IF D < 25 THEN PRINT "FRESH OUT OF TRAINING, EH?" 320 PRINT 322 IF D < 160 * RND THEN GOTO 330 325 PRINT "DIRECT HIT!!!! ", INT(100 * RND), " KILLED." 327 PRINT "MISSION SUCCESSFUL." 328 GOTO 390 330 PRINT "MISSED TARGET BY ", INT(2+30 * RND), " MILES!" 335 PRINT "Now you are REALLY in for it !!" 336 PRINT 340 PRINT "Does the enemy have GUNS(1), MISSILES(2), or BOTH(3)" 342 INPUT R 345 IF R > 0 AND R < 4 THEN GOTO 350 347 PRINT "TRY AGAIN..." 348 GOTO 340 350 PRINT 351 LET T=0 352 IF R = 2 THEN GOTO 360 355 PRINT "What's the per cent hit rate of enemy gunners (10 TO 50)?" 356 INPUT S 357 IF S < 10 THEN PRINT "YOU LIE, BUT YOU'LL PAY..." 358 IF S < 10 THEN GOTO 380 359 PRINT 360 PRINT 362 IF R > 1 THEN LET T=35 365 IF S+T > 100 * RND THEN GOTO 380 370 PRINT "You made it through tremendous FLAK!" 375 GOTO 390 380 PRINT "* * * * BOOM * * * *" 384 PRINT "YOU HAVE BEEN SHOT DOWN....." 386 PRINT "Dearly beloved, we are gathered here today to pay our" 387 PRINT "last tribute...." 390 PRINT 391 PRINT 392 PRINT "Another mission? (Y or N)" 393 INPUT U$ 395 IF U$ = "Y" THEN GOTO 8 400 PRINT "CHICKEN !!!" 410 END