More type in goodness…Half-Byte Tiny Basic type in game, Zapp the Moon Man, take 2

zappthemoonmanRelease three of Half-Byte Tiny Basic ate up about eight more bytes of memory than the previous release, so there are now 938 bytes free for user code to reside.  My last version of Zapp the Moon Man—previously unpublished—featured the Moon man’s ability to move down the screen and attack as well as the user’s ability to move the cannon back and forth.  Sadly, for this release, I’ve had to remove the downward mobility of the Moon Man, but I have left in the user’s ability to move and also made the ‘hit box’ better, resulting in a somewhat easier game play.

This game shows off just how versatile Tiny Basic can be, how speedy the ATMega 328 is and how quickly Tiny Basic can interpret your code.

At any one time in the game, both your cannon and the Moon Man can be moving as well as the torpedo you are shooting at the moon man.  Three objects to track on the screen. In interpreted BASIC. Running on a microcontroller that was meant for turning relays on and off, not playing video games. And, it does it rather smoothly.  The jerkiness that is there is there by design, to mimmick those games from the 1970’s.

The game is pretty primitive. It resembles Space Invaders, but there is only one ‘invader’, the Moon Man, and there are no protective shields…heck, the Moon Man does not even shoot at you…yet.  It does feature some primitive, character based, animated graphics.  The Moon Man sort of looks like a Space Invader. As it moves back and forth, its antennae move and its ‘feet’ swivel side to side.  You use a Wii Nunchuck’s thumb stick to move and the Z button to fire your torpedo. The game keeps a score…10 points for every Moon Man you destroy.  You hear a launch tone when you fire and, when you hit a Moon Man, you see a little explosion like effect. And…that’s it.  Simple and not earth shattering (that will be in a future update.)

So, with out any further delay…(One note: when typing in the code, do not put in extra spaces.  Use one space between the line number and the code, and one space before line numbers in things like GOTO or GOSUB.  The listing below inserted additional spacing, you can ignore it.)

100 CLS:ECHO 0
110 A=0:B=0:O=75
120 X=10:Y=10:Z=5:F=0:D=1:S=0
140 LINE 0,48,80,48,1
150 GOSUB 700
160 GOSUB 900
170 P=PAD(3):Q=PAD(0)
180 IF P=1 F=1:TONE 200,100
190 IF F=1 GOSUB 1000
192 IF Q>200 GOSUB 600
194 IF Q<100 GOSUB 600
200 A=A+D
210 IF A>15 D=-1
220 IF A<3 D=1
230 GOSUB 1200
290 GOTO 140
600 CURSOR X,Y:?”  “;
610 IF Q>200 I=1
620 IF Q<200 I=-1
630 X=X+I
640 IF X<2 X=2
650 IF X>17 X=17
660 GOSUB 900
690 RETURN
700 IF D=1 CURSOR A,B:?CHR(152);:DELAY O:CURSOR A,B:?CHR(153);:DELAY O:CURSOR A,B:?”  “;
710 IF D=-1 CURSOR A,B:?CHR(153);:DELAY O:CURSOR A,B:?CHR(152);:DELAY O:CURSOR A,B:?”  “;
790 RETURN
900 CURSOR X,Y:?CHR(150);
990 RETURN
1000 CURSOR X,Z:?”|”;:DELAY 20:CURSOR X,Z:?” “;:DELAY 20
1050 Z=Z-1
1060 IF Z=0 IF A=X Z=5: GOTO 1100
1070 IF Z=0 IF A=X+1 Z=5: GOTO 1100
1080 IF Z=0 Z=5:F=0
1090 RETURN
1100 CURSOR A,B
1110 ?”***”;:DELAY 180:CURSOR A,B:?”XXX”;:DELAY 170:CURSOR A,B:?”   “;:A=0:B=0:F=0
1190 S=S+10
1200 CURSOR 0,5:?”SCORE:”,S;
1290 RETURN

 

If you come up with any improvements, optimization, etc., please let us know.

Oh, one big caveat…as it does use up all but 15 bytes of RAM, your keyboard buffer is limited to 15 bytes…Tiny Basic does not set aside a dedicate memory for keyboard input. It dwindles as you use up memory.  So, keep in mind that you may have to delete a long line and split it up—which will use at least three bytes plus the content of the line.

UPDATE:  Since this was posted, I have made a few improvements to the game AND saved even more RAM, about 90 bytes total.  Among the improvements: a random speed for the moon man, the ability of the moon man to descend on you and…you can lose the game.

The updated code is below.

100 CLS
110 A=0:B=0:O=RND(100)
120 X=10:Y=8:Z=5:F=0:D=1:S=0
140 LINE 0,48,80,48,1
150 GOSUB 700
160 GOSUB 900
170 P=PAD(3):Q=PAD(0)
180 IF P=1 F=1:TONE 200,100
190 IF F=1 GOSUB 1000
192 IF Q>200 I=1:GOSUB 600
194 IF Q<100 I=-1:GOSUB 600
200 A=A+D
210 IF A>16 D=-1:B=B+1:if b>=Y CLS:?”You lose!”:Delay 3000:goto 100
220 IF A<1 D=1
230 GOSUB 1200
290 GOTO 140
600 CURSOR X,Y:?”  “;:X=X+I
640 IF X<2 X=2
650 IF X>17 X=17
660 GOSUB 900
690 RETURN
700 CURSOR A,B:?CHR(152);:DELAY O:CURSOR A,B:?CHR(153);:DELAY O:CURSOR A,B:?”  “;
790 RETURN
900 CURSOR X,Y:?CHR(150);
990 RETURN
1000 CURSOR X,Z:?”|”;:DELAY 20:CURSOR X,Z:?” “;:DELAY 20
1010 Z=Z-1
1060 IF X=A IF Z=B GOTO 1100
1070 IF X=A+1 IF Z=B GOTO 1100
1080 IF Z=0 Z=5:F=0
1090 RETURN
1100 CURSOR A,B
1110 ?”***”;:DELAY 180:CURSOR A,B:?”XXX”;:DELAY 170:CURSOR A,B:?”   “;:A=0:B=0:F=0
1120 Z=5
1190 S=S+10:O=RND(100)
1200 CURSOR 0,5:?”SCORE:”,S;
1290 RETURN

Advertisements

More type in goodness…Half-Byte Tiny Basic type in game, Zapp the Moon Man, take 2

zappthemoonmanRelease three of Half-Byte Tiny Basic ate up about eight more bytes of memory than the previous release, so there are now 938 bytes free for user code to reside.  My last version of Zapp the Moon Man—previously unpublished—featured the Moon man’s ability to move down the screen and attack as well as the user’s ability to move the cannon back and forth.  Sadly, for this release, I’ve had to remove the downward mobility of the Moon Man, but I have left in the user’s ability to move and also made the ‘hit box’ better, resulting in a somewhat easier game play.

This game shows off just how versatile Tiny Basic can be, how speedy the ATMega 328 is and how quickly Tiny Basic can interpret your code.

At any one time in the game, both your cannon and the Moon Man can be moving as well as the torpedo you are shooting at the moon man.  Three objects to track on the screen. In interpreted BASIC. Running on a microcontroller that was meant for turning relays on and off, not playing video games. And, it does it rather smoothly.  The jerkiness that is there is there by design, to mimmick those games from the 1970’s.

The game is pretty primitive. It resembles Space Invaders, but there is only one ‘invader’, the Moon Man, and there are no protective shields…heck, the Moon Man does not even shoot at you…yet.  It does feature some primitive, character based, animated graphics.  The Moon Man sort of looks like a Space Invader. As it moves back and forth, its antennae move and its ‘feet’ swivel side to side.  You use a Wii Nunchuck’s thumb stick to move and the Z button to fire your torpedo. The game keeps a score…10 points for every Moon Man you destroy.  You hear a launch tone when you fire and, when you hit a Moon Man, you see a little explosion like effect. And…that’s it.  Simple and not earth shattering (that will be in a future update.)

So, with out any further delay…(One note: when typing in the code, do not put in extra spaces.  Use one space between the line number and the code, and one space before line numbers in things like GOTO or GOSUB.  The listing below inserted additional spacing, you can ignore it.)

100 CLS:ECHO 0
110 A=0:B=0:O=75
120 X=10:Y=10:Z=5:F=0:D=1:S=0
140 LINE 0,48,80,48,1
150 GOSUB 700
160 GOSUB 900
170 P=PAD(3):Q=PAD(0)
180 IF P=1 F=1:TONE 200,100
190 IF F=1 GOSUB 1000
192 IF Q>200 GOSUB 600
194 IF Q<100 GOSUB 600
200 A=A+D
210 IF A>15 D=-1
220 IF A<3 D=1
230 GOSUB 1200
290 GOTO 140
600 CURSOR X,Y:?”  “;
610 IF Q>200 I=1
620 IF Q<200 I=-1
630 X=X+I
640 IF X<2 X=2
650 IF X>17 X=17
660 GOSUB 900
690 RETURN
700 IF D=1 CURSOR A,B:?CHR(152);:DELAY O:CURSOR A,B:?CHR(153);:DELAY O:CURSOR A,B:?”  “;
710 IF D=-1 CURSOR A,B:?CHR(153);:DELAY O:CURSOR A,B:?CHR(152);:DELAY O:CURSOR A,B:?”  “;
790 RETURN
900 CURSOR X,Y:?CHR(150);
990 RETURN
1000 CURSOR X,Z:?”|”;:DELAY 20:CURSOR X,Z:?” “;:DELAY 20
1050 Z=Z-1
1060 IF Z=0 IF A=X Z=5: GOTO 1100
1070 IF Z=0 IF A=X+1 Z=5: GOTO 1100
1080 IF Z=0 Z=5:F=0
1090 RETURN
1100 CURSOR A,B
1110 ?”***”;:DELAY 180:CURSOR A,B:?”XXX”;:DELAY 170:CURSOR A,B:?”   “;:A=0:B=0:F=0
1190 S=S+10
1200 CURSOR 0,5:?”SCORE:”,S;
1290 RETURN

 

If you come up with any improvements, optimization, etc., please let us know.

Oh, one big caveat…as it does use up all but 15 bytes of RAM, your keyboard buffer is limited to 15 bytes…Tiny Basic does not set aside a dedicate memory for keyboard input. It dwindles as you use up memory.  So, keep in mind that you may have to delete a long line and split it up—which will use at least three bytes plus the content of the line.

IT’s HERE! Half-Byte Tiny Basic 3!

randomdotsOne of the things I have really enjoyed since embarking on my Arduino journey and this blog, is seeing others take things I’ve worked on or created and expand upon it. This is especially true with Half-Byte Tiny Basic, something that started out as the work of Mike Field, who, himself used the work of another person. HB Tiny Basic is an iterative work, built on the work of others as well as myself.  For HB Tiny Basic 3, I have incorporated the work of others to make it better.  I would love to take credit for these changes, but, I cannot.  This release is strictly due to Hill Satoshi of the Hirosaki University Faculty of Education and someone named ‘Koyama’.  A Big thanks to them.

Please visit Hill Satoshi’s page. There are a lot of great ideas, basic electronics information and some code snippets…be careful, some features of the basic there were not incorporated in HB Tiny Basic, like the motor control and PLOT (which is the same as Set and Reset.)

Among the additions and changes are an auto load and auto run feature (requested by many of you) and a better eSave and eLoad feature.  In fact, I like much of what was done to the language and may incorporate more at a later date.

So, what’s new?

Two new statements have been added: NUMLED and BMP.  A new function, TREAD.  The aforementioned auto load and auto save feature.  Three new operators: %, & and |. % returns the remainder of a division, & is logical AND and | is a logical OR.

What’s changed?

The code to do a eSave or eLoad has changed and should be more reliable.  The startup code has changed a little, dynamically calculating the amount of ram that is available.  Ability to read in characters from the serial input as if it were the keyboard. This means you can connect to a serial terminal and enter and run Tiny Basic code without a PS/2 Keyboard attached. And a few minor tweaks here and there.

New Statements

The first new statement is NUMLED.  If you connect a seven segment LED directly to the device you are running HB Tiny Basic on, you can output directly to the LED.  The syntax is:

NUMLED x  where x is a digit from 0 to 9.

EXAMPLE:

20 for I=0 to 9

30 numled I

40 delay 1000

50 next I

60 goto 20

BMP

BMP allows you to draw a bitmap on the screen.  It is very much like the DRAW statement in old Microsoft Basics. It feature its own mini design language for you to draw on the screen. A minimum of three parameters are required: x,y,string.  Where x and y are the start points and string is the definition.

Table of Commands for Mini Language:

CMD

Pattern
(0 is black;
1 is white)

CMD

PATTERN
(0 is black;
1 is white)

0
1
2
3
4
5
6
7

0000
0001
0010
0011
0100
0101
0110
0111

8
9
A
B
C
D
E
F

1000
1001
1010
1011
1100
1101
1110
1111

 

EXAMPLE:

10 cls 
20 bmp0,0,"ffffc00000007fff","ffffc00000001fff", "fffe0000000003ff","fffc0000000000ff", "fff80000000000ff","fff000000000007f", "ffe000000000003f","ff0000000000003f" 
30 bmp0,8,"ff0000000000001f","ff2f00000000000f", "ff1fc0000000000f","ff000c000000000f", "ff003f000000000f","ff0020400000000f", "fc0000fc1800000f","fc00000f7f3c000f" 
40 bmp0,16,"f80000037f7e000f","f8000000007e0003", "f01c00c0001cf7c3","f03e03c00000efcf", "f03e07c00e00000f","c03f1ff01f000003", "c03ffff03f800003","cf3ffff87fc380c3" 
50 bmp0,24,"ce3fffffffc3c0c3","c03fc03fffe7f1cf", "c03f003ffffff3c0","ff3fff3fff0fff88", "ff1ffffffc0fff1c","ff9ffffff043ff3c", "ff8fffc03ff3ff38","ff8fffc03ff3fe00" 
60 bmp0,32,"ffcfffff3ffffc01","ffc7fffffffffcff", "ffc3fffffffff8ff","fff3ff007ffff1ff", "fff1ff0c7fffc3ff","fff0ff0c7fffc7ff", "fffc7f0c7fff8fff","fffe3f807ffe1fff"
70 bmp0,40,"ffff3fc0fffe3fff","ffff07c3fff07fff", "fff023ffffe1ffff","ffe0203fff83ffff", "ff07e00000003fff","fc0fe3ffff8f0fff", "fc3fe3ffff8f0fff","f0ffe3ffff8fc1ff" 
80 shift 1,3:delay 99:goto 80

 

Aviary Photo_131159334768733501

The example code above produces this bitmap.

New Function:

TREAD is an alternate method for reading a temperature sensor. It does not require any additional libraries and reads the sensor directly. Usage is: Var=TREAD(pin)  where pin is A0 to A7.

EXAMPLE:

100 a=TREAD(A3)

The example reads in a value between –30 and 50 degrees Celsius.

Auto Load and Auto Save

HB Tiny Basic will now load the saved program in EEPROM.  You have three seconds to press a key or the loaded program will auto run.  If you press a key in those three seconds, you will get the normal prompt as in the past.  This feature is useful if you want to use HB Tiny Basic for embedded use or simply to restart if the device loses power.  There are a lot of uses for this feature.

Other small changes have been made, but are not worth discussing as they are mostly cosmetic or code optimizations.

In reviewing my code, I see just how sloppy it has become. I am going to clean it up, but, until I do, please feel free to offer up any suggestions you may have for features or changes.  As always, the code is free and open.  I ask that you leave the regular header intact, at the top of the code. I want all involved to be recognized.

Thanks and let us know what you do with Half-Byte Tiny Basic.

Download Link: Half-Byte Tiny Basic 3

It’s here! Half-Byte Tiny Basic 2 for Arduino and compatibles

It’s back! Better than ever. Yes, that’s right, Half-Byte Tiny Basic 2 for Arduino.  The first was so good, there just had to be a follow up.  And this version has even more fun stuff like new graphics functionality like ARC and CROSSHAIRS.  New math in SIN and COS.  Enhanced LIST statement and more.  Read on for more on the new goodies.

Tiny Basic weather?

WP_20140826_22_20_46_ProWell, yes and no. Yes in that support for the DHT-11 temperature and humidity sensor has been included. No, it won’t generate satellite images or predict snow storms. But, if you have a project where you need to capture the temperature and/or humidity, this will work.  Temperature is returned in either Celsius or Fahrenheit.  TEMP( 0 ) will return the temperature in Celsius and TEMP( 1 ) will return it in Fahrenheit. HUMIDITY with any value parameter will return the relative humidity.

EXAMPLE:

100 CLS
110 PRINT “Temperature: “, TEMP( 0 ),”C”
120 PRINT “Relative Humidity: “,HUMIDITY( 0 ),”%”
130 DELAY 4000
140 GOTO 100

New Graphics Functions

POLY

Poly will draw an abnormal circle. It is abnormal because the sides will not be ‘normal’. They will be straight lines IF the radius is small. As the radius gets larger, the circle looks more normal, then it begins to ‘explode’. Poly gives nice random like patterns or explosions for games.

POLY start_x, start_y, radius, points, color
Where start_x and start_y are the screen position to draw the poly;
Radius is width of the circle;
Points is the size of the ‘sides’ of the circle;
Color is black or white
100 CLS: CENTER: PRINT “EXPLODING”
110 R=RND(20): P=RND(15)
120 POLY 40,20,R,P,1
130 DELAY 100
150 POLY 40,20,R,P,0
160 DELAY 100
170 GOTO 110

 

INVERT

One thing you can do to get a user’s attention is to flash the screen. Tiny Basic allows you to do this quickly, by using the INVERT statement. It takes no parameters and its syntax is simply:

INVERT
100 CLS
110 CURSOR 3,2
120 PRINT “TO CONTINUE WITH”
130 CURSOR 3,3
140 PRINT “PROCESSING, PRESS C”;
150 A=INKEY(0)
160 IF A=67 GOTO 210
170 INVERT
180 DELAY 500
190 GOTO 150

210 #CONTINUE…

Starting at line 150, we wait for a key to be pressed. If it is C, goto 210 else, we invert the screen, wait a half second and do it again. If there is no delay, the screen would be just obnoxious. Inserting a delay slows it down a bit.

 

CROSSHAIRS

Crosshairs draws a graphical ‘t’ on screen. The ‘t’ can be controlled to be tight and small or apart and big. This is useful for creating crosshairs on screen for shoot them up game, driving game or some other type of game. Or, use it for art.

 

ARC

ARC draws a partial circle, a PIE piece.
ARC has eight parameters:
Start x, start y, radius, angle, end radius, color, pie, fill
Start x and y are center point
Radius is just that
Angle is the angle of the arc
End radius is the end point
Color is 0 or 1 for black or white
Pie is 0 or 1
Fill is 0 or 1 and will fill the arc or leave it open

WP_20140930_22_18_20_Pro

CENTER

CENTER will start PRINTing at the center point of a line

LIST

The LIST statement has been enhanced.  You can now list a single line, five lines or the entire program.

LIST by itself lists the whole program
LIST number- will list the program starting at number and go for five lines
LIST number. will list just that line.

MATH

COSine and SINe have been added.

a=COS( x )
b=SIN( y )
The functions were contributed by reader Jim F – Calgary Alberta Canada , thanks Jim!

OTHER STUFF

The overall interpreter is a bit speedier as there have been some optimizations and I was able to cut a lot of redundant code out. Because the functions added some RAM overhead, I lost about 30 bytes, so usable memory is around 970 or so bytes.  This is plenty for small games, control applications and for learning. It is also enough for great demos too.  If you use this on a Mega, then you will have a lot more memory. Just remember, you will need to change the pins used at the top of the code (for nunchuck, TV OUT, sound and the DHT-11 if you use that.)

To run Tiny Basic on your Arduino, download the package below. Put the Half-Byte Tiny Basic files in your Arduino directory. The TV OUT and DHT-11 libraries need to be imported into your IDE. Please follow the procedure for importing libraries. The Fonts need to go in the the TVOut font directory.  Next, open the Half-Byte Tiny Basic in your IDE and then compile and upload to your Arduino.

DOWNLOAD IT

You can download all files to install Tiny Basic 2 on your Arduino here. Tiny Basic 2  manual is here.

101_3353

Happy Birthday, BASIC, you wonderful language you!

I remember when I was ten or so years old. I asked my father a question that changed both of our lives. My Dad was an engineer. He was also what we would consider now to be a nerd. A geek.  Above all, though, he was very smart and he was MY Dad.  He could build anything out of what seemed to be random little bits of stuff.  To a ten year old, it was akin to magic.

So, what was that question?

“Dad, what’s a computer and how does it work?”

He didn’t give me a whole answer right away. If I remember, it was something like ‘a machine that can think, sort of.’ ‘Lets find out.’

Weeks later, he started getting packages. Those packages contained the magic wand, magic dust and … paper. Manuals, to be specific.

Out of those packages, my Dad built the Mark IV Mini-Computer, as written about in Radio-Electronics Magazine.  Now, this computer was primitive, even then. Something like 128 bytes of memory, which he expanded to 1K or something like that.  Anyway, that computer didn’t  answer our question.

So, he built another. And another.  That third computer, based on the Signetics 2650 microprocessor, was THE ticket.  This computer, had lots of memory (4K?) and, most importantly, had a keyboard and tv like screen. Oh, this thing called ‘Tiny Basic’.

I was hooked.  I eagerly soaked in all I could about this ‘Tiny Basic.’  I quickly learned that there were LOTS of Tiny Basics and even something just called ‘BASIC.’  So, what was this ‘BASIC’?

Simply put, BASIC was (well, IS) a computer programming language. And, during the 1970’s, it was pretty much the only way someone like myself could interact with the computer. It was easy to learn and use. I was typing in programs from my Dad’s books and magazine, having to alter them to work with the primitive version I had to use.  One day, I decided to start writing my own.  Finally, we had our answer. Collectively, we figured out what these computers were and what one could do with them. My Dad tackled the hardware, I tackled the software and, in the process, laid the foundation for my career.

And, it was all because of BASIC.

BASIC, developed in 1964 at Dartmouth University by John Kemeny and Thomas Kurtz. BASIC was designed for teaching the fundamentals of programming and to make the computer more accessible to non-programmer types.  It slowly grew out of Dartmouth and, by 1970, had spread all over the country.  It gained so much popularity, that it caught the eye and wrath of many professional who held it high in disdain. No matter, the genie was out of the bottle.

In the early 1970’s, when microprocessors became affordable and home computers took off, others were writing dialects of the language to run on these tiny machines.  The most notable being Micro-Soft Basic, co-developed by Bill Gates and Paul Allen and sold by MITS for the Altair computer. Unfortunately, it was priced so high that a black market for the language began, prompting a whiny ‘don’t copy our software’ letter from Bill Gates.  Whiny, but necessary. Software piracy was a huge deal at the time.

Around 1975-76, another dialect of the language came out and this one was affordable. Tiny Basic was a grass roots effort to develop the language so that it would work in very small memory footprints and on pretty much any computer.  Numerous version were released by companies and individuals.  Tom Pittman’s Tiny Basic was probably the most notable, followed by Lawrence Livermore Labs.  Oh, and the one that Steve Wozniak wrote for the Apple ][.

Kemeny and Kurtz hated the versions of their language for microcomputers, especially those of the ‘Tiny’ variety and anything out of Micro-Soft.  See, Micro-Soft, soon to be Microsoft, supplied a version of the language for pretty much all of the big commercial home computers: Apple, Atari, Tandy, Commodore, TI, Mattel and more.  Kemeny and Kurtz wanted to reel it back in with ‘True Basic’. Unfortunately, they discovered it was not that easy to do.

As time went on, however, the language grew and became a powerhouse for professional developers thanks to the efforts of Microsoft.

Microsoft included QBasic in its DOS product. They also had QuickBasic, which could compile code into true executables. For professional development, they had the Professional Development System, sort of a forerunner to todays Visual Studio product, only it was DOS based and character mode.

In the early nineties, they introduced Visual Basic, a Windows programming environment.  Shortly afterwards, Visual Basic for MSDOS was released. I had the opportunity to develop with this version for about two years. It was such a difference from what I was used to: object oriented and event driven. Suddenly, I had to think in terms of USER control of the application and not vice-versa.  It really opened my eyes as to how truly interactive computers could be.  Its overlapping text mode windows, mouse and relational database allowed me to create some really nice front end software for the video rental chain that employed me. It was a treat.

VBDOS didn’t live long.  Time and technology quickly outdated it.  VB for Windows evolved.  VB6 became THE development platform.  VB.NET was the future. Or, so we thought.

Microsoft’s run in with Sun Microsystems over Java led to the creation of C#: a modern programming language that was modeled after java with roots in C.  Interesting combo, but it wasn’t going to go anywhere. Microsoft was just trying to rattle Sun’s chains. That was my thinking. Boy, was I wrong.  Soon, the call for C# was on the rise while VB waned.

While BASIC no longer has the draw or the need, it is still there.  There’s a growing rank of people who are using as a hobby language again.  VBScript and VBA continue to dominate in the scripting arena. You really cannot beat it to do quick, repetitive tasks. It is great for automating mundane things.

And, Tiny Basic has made a come back of sorts. It is used on microcontrollers like the BasicStamp, Arduino and the PIC family of controllers.

While many probably wished it had died fifty years ago on May 1, it is far from death. In fact, this post is a celebration of not only its birthday, but the life it gave to an entire industry and its active future. 

I can’t say how much I owe this terrific language, it is truly immense. My life has been driven by many things, but I’d say BASIC was right up there with my parents and family as the most influential thing in my life.

Happy Birthday, BASIC!

Write your own BASIC programs on your XGS PIC

Since rediscovering the XGS PIC Gamestation board, I’ve been doing some developing for the kit. One of the things I’d wanted to be able to do is actually do some coding ON the device. However, there are currently no development tools that actually RUN ON the device, so…I have adapted a dialect of Tiny Basic to run on the board.

IMG_2184This exercise, however, has reminded me of why I dislike the C programming language. In a nutshell, POINTERS. Oh my. These things are horrid.  The rest of the language is fine, even cool at times. But…those bloody pointers.

Rather than setting about writing the dialect from scratch, I searched the Internet for an open source variation and, boy, are there plenty.  Most, however, did not lend themselves to the kinds of changes I’d need to do to make it work. Since the XGS PIC has no operating system (whatever code that runs on it BECOMES the ‘OS’, providing all I/O.

Fortunately, Nurve Networks provided a few very well documented API’s and demos that I could use to supply all of the I/O I’d need.

The XGS PIC is a really funky, game oriented device and, as such, has very minimal specs.  VGA or Composite video out, really simple audio, SD card interface, Serial communications, two Atari style controller ports and PS/2 keyboard/mouse interface.  Talking to each is rather laborious to code, but the API set eases the pain a bit.

The graphical ability is somewhat between an Atari 7800 and the original NES in appearance.

Also, memory is tight: 16k RAM and 256k Flash. Well, 256k is more than enough for the Tiny Basic code and the API libraries, it’s the 16k RAM that makes it tight as this memory is shared between the video and your program.

So, after some searching and pouring through code, I found something for the Arduino. Called Nanode Basic, it was a modification of a Tiny Basic someone (Mike Field – hamster@snap.net.nz) crammed into an Arduino.  The Nanode modification added some features for real world interfacing to temperature sensors and a few other things. The architecture of the interpreter is smart and was easily adaptable to the XGS PIC. Mr. Field allowed for serial I/O to a terminal OR for use on an Arduino with keyboard and screen.  He left the I/O generic enough for me to, quite literally, plug in the calls to the keyboard and graphic driver API’s that Nurve supplied.

Now, the XGS PIC has two graphical modes: bitmap and tile.  IMG_2185Text rendering is done via the tile mode, which has, for now, precluded the inclusion of any graphical statement additions to the Basic (which I named ArdBasic, short for Arduino Basic.) 

The original Arduino Basic did not include the ability to save or load programs nor did it have any control over the screen.  I have extended it to include these features.

Tiny Basic, for those who may not know, came into being in the mid 1970’s for use in very low power microcomputers. Flavors of Tiny Basic were available for wide range of chips (some of which even had the language burned into them) from the Intel 4004 (quite a challenge since its entire address range is 16k) to the Z80 and oddball chips like the RCA 1802, Signetics 2650 and the National Semiconductor SC/MP.  The TRS-80 Model 1 even came with an enhanced version (4k) of the language.  Most implementations used about 2k of RAM for the entire package: line editor and interpreter. Some of these flavors even introduced some advanced constructs that are common today, but not then. Most of them had the ability to interact, at some level, with the hardware that they ran on, doing things like turning relays on or off or collecting data from some kind of sensor.

IMG_2158Back to our XGS.

I examined the Nanode Tiny Basic source and began removing the Arduino/Nanode specific code. Next, I figured out all of the places in code I would need to add the XGS specific stuff. My biggest headache was trying to debug the keyboard code while, unknowingly, having a faulty keyboard. That was fun.  Getting the timing correct, between reading the keyboard and displaying text on screen was the next biggest issue.  Once I got those issues resolved, I began adding my enhancements.

Before discussing the enhancements, lets talk about what was already there.  Standard features include:

Commands:

  • LIST
  • LOAD
  • NEW
  • RUN
  • SAVE
  • FILES

Functions:

  • PEEK(address)
  • ABS(number)
  • RND(dummy)

New:

  • LOCATE x,y – puts cursor at location x,y on screen
  • ? short for PRINT
  • MEM – displays free memory
  • PLAY x-plays a sound (PLAY 0 turns it off)
  • CLS – clears the screen
  • FILES – displays a list of files on the SD card

Other:

  • Integer math
  • 26 integer variables
  • No strings
  • Line Numbers, no textual labels
  • 20 characters by 16 lines
  • Old School

Statements:

  • NEXT
  • LET
  • IF
  • GOTO
  • GOSUB
  • RETURN
  • REM
  • FOR
  • INPUT
  • PRINT or ?
  • POKE* (not fully implemented)
  • STOP
  • BYE
  • SLEEP
  • CLS
  • LOCATE
  • MEM
  • PLAY
  • FILES

Operators:

  • +, –, *, /
  • <,>,<>,=
  • (,)
  • comma, ‘, “”
  • colon for multi-statement

 

The standard stuff, like PRINT, GOTO and such are implemented straightforwardly.  In this dialect, however, the only abbreviation that is allowed is the question mark, short for PRINT. I may, at some point, add the other shortcuts (PR for PRint, INput, etc.) but, for now, I am concentrating on core functionality.

As memory is at a premium, I removed code from the Graphics driver that was not necessary. This included all of the bitmap and tile graphics code, except for code that was necessary for the text console handling, clipping code and the initialization code. The other API’s are stock from Nurve or Microchip (the SD file handling API.)

I also developed a new font, using the C64 font supplied by Nurve (the old Commodore 64 font was too fat, but, now I have too much spacing between characters, I’ll add it to my to do list.)

Currently, the interpreter still has a few bugs, chiefly the line editor is wonky and randomly will reset the board.  The SAVE code is also buggy.  Once these bugs are squashed, I plan to do some code optimizing.  Fortunately, the originally code base was pretty tight, so most of the optimizing will be from my own sloppy coding.

Stay tuned for more.

Sample ArdBasic ‘guess my number’ code:

100 REM ** Sample ArdBasic Code
110 CLS
120 LOCATE 6,10
130 PRINT "GUESS THE NUMBER"
140 N=RND(1)
150 C=1
160 PRINT "GUESS #",C
170 PRINT "ENTER YOUR GUESS:",
180 INPUT G
190 IF G=N GOTO 250
200 PRINT "SORRY, TOO ",
210 IF G>N PRINT "HIGH": PLAY 9
220 IF G<N PRINT "LOW": PLAY 2
230 C=C+1:PLAY 0
240 GOTO 160
250 PRINT "YOU GUESSED MY NUMBER!"

To-Do:

  • Fix bugs
  • Add ability to chain programs
  • Add file deletion
  • Add rudimentary text files to the language
  • Font
  • Code optimizing
  • Graphics?

For more information:

From patch cords and punch cards to GUI’s and Mice: how programming evolved

Software development has come a very long way since the early days of 1946 when Eniac was programmed via patch cords.  When more modern computers, such as Univac, hit the market, programming them was better, but still required skills that were just impossible to come by. The problem was so bad, that it nearly derailed the whole industry before it really got going.

IBM704That changed, though, in 1954 when John Backus of IBM developed the FORTRAN language.  Considered the first successful high level language, FORTRAN, short for FORmula TRANslator, was, initially, greeted with a bit of skepticism, but that was satiated with the optimizing compiler. There was a fear that the code it generated would not be as tight as the previously hand assembled code, so the optimizing compiler was developed to quell those fears.

The first FORTRAN was released in 1957, followed up the next year with FORTRAN II, which contained enhancements including the addition of procedural programming. Functions and subroutines allow the developer to create their own functions for the first time.

FORTRAN was a big step forward, but it had its limitations. Primarily, it was not very good with business uses. The solution would come from a committee that formed in 1959.  The committee was formed by people from the government and private industry.

FLOW-MATIC, a language developed by Grace Hopper, was used as the foundation for COBOL, or COmmon Business Oriented Language. FLOW-MATIC was drawn from more than other language specs mainly because it was the only one that had actually been deployed and used. COBOL gained wide acceptance in business and enjoyed a run that continues today, though it use has dramatically declined over the last couple of decades. 

Both FORTRAN and COBOL served both the science, research and business communities, but they were not all that easy to master. FORTRAN more than COBOL, but were still out of reach for many.  In 1962, John Kemeny and Thomas Kurtz developed the Beginners All-purpose Symbolic Instruction Code, or BASIC.  Panned by most ‘professional’ programmers and purists, BASIC, nonetheless, gained wide acceptance in the 1970’s with the advent of the microcomputer.

Initially, BASIC was both the operating system and language of many homebrew and early retail microcomputers. However, those machines were very limited in memory and power. The version of BASIC that was generally in use was called Tiny BASIC. These ‘tiny’ languages truly were tiny: most took only 2.5 to 4K of memory. They generally only handled integer numbers, limited or no string handling and only the ‘basic’ of statements (like IF-THEN, GOTO, PRINT, INPUT, etc.) were included. 

Things looked up, however, when the ALTAIR computer was introduced. Two kids decided they would supply a BASIC language for the computer. Paul Allen and Bill Gates set up shop in New Mexico and began Micro-Soft. Gates delivered the final bits of code the day they were supposed to meet with Ed Roberts, the owner of the MITS company, the producer of the Altair.  Micro-Soft Basic became the defacto ‘standard’ for microcomputer Basic for years to come. It was also one of the most pirated pieces of software.

Micro-soft, later changed to Microsoft, continually enhanced the language, adding low-res, monochrome graphics statements, then hi-res color, disk file handling and more. In 1991, the company introduced Visual Basic, a Windows based development environment. For the first time, Windows applications could be developed, quickly and without having to know ‘C’ or how the innards of Windows worked. It enabled companies, large and small, to embrace Windows without having spend lots of money developing or purchasing specialty applications. The company also continued to develop its DOS versions with the Professional Development System and a DOS version of Visual Basic called Visual Basic for DOS or VBDOS for short. I, personally, developed several applications with VBDOS and it was, by far, my favorite text based version other than NI/BL, a variation of Tiny Basic for the National Semiconductor SC/MP in the ‘70s.

Microsoft held VB in such high regard, that it became the built in scripting language of its Office Suite, a second scripting language in its browsers, and for Windows itself. VBScript, while it no longer is being developed by the company, is a highly versatile language and is under appreciated.

No discussion of programming languages would be complete without talking about C.

C was developed between 1969 and 1973 by Dennis Ritchie at Bell Labs. C is probably the most widely used language. It is used to develop everything from games to operating systems (such as Unix and Windows.) While it generally is considered a high level language, C more closely resembles cross between BASIC and Assembler. It requires knowledge of how the CPU works, things like pointers and other lower level objects than, say a BASIC or even COBOL.  It does, however, generate smaller and more efficient code.

C gained popularity in the 1980’s but it, too, had ‘Tiny’’ versions, but they did not catch on quite like Tiny Basic did. However, it did spawn a more powerful version called C++. C++ is an object oriented language that did catch on…like wildfire. C++ is a true modern language and was the inspiration for other modern languages like JAVA and C Sharp (C#).

Gone are the days of punch cards, magnetic tape and printouts. With our graphical development environments, mice, touch screens and languages like C Sharp, VB and web development technologies, programming has definitely come a long way. And, that shortage of programmers? Gone.

I must say, those days in the 1970’s and 80’s, and the underpowered computers, were a blast. For geeks like me, Tiny Basic was a godsend. I was able to learn something that, later, would provide a career. I got to experience, first hand, the birth of the modern computer era. I can remember, eagerly, getting a computer magazine and tediously entering BASIC code and then having to ‘fix’ it to work with my particular flavor of BASIC. But, I did. I got just about everything I entered to work. Yeah, I missed things like Prom and high school football, but I would not trade it for anything. I think the way I felt was pretty close to those early pioneers in the early ‘50s.  Amazing, that sums it up.