Extended Color BASIC to Arduino Sketch, part 3

See also: Part 1Part 2, Part 3, Part 4 and full source.

Just because something can be done, doesn’t mean it should.

“Why are you converting thirty year old BASIC programs to C?” you might ask… Well, mostly just to see how easily it could be done, but I admit, nostalgia has a big part in this. I am not quite sure what led me to looking in to my 1983 BBS program, but once I saw it running on the XRoar CoCo emulator, it brought back all kinds of fond memories of sitting in front of a TV set typing in lines of BASIC code.

I believe I got in to computers at the very best time. A few years earlier, and it was punch cards and flip switches. A decade or so later, and computers were becoming appliances. There was a bit of time in between when owning a computer primarily meant programming a computer. I got in to it late enough that I didn’t have to be a hardware guy to build my own computer, and early enough that I was still compelled to figure out what to do at the blinking cursor after the “OK” prompt. There just wasn’t nearly as much off-the-shelf software to buy back then, you see. Especially on my allowance.

I realized tonight that there were many like myself who once wrote their own programs and experimented. As time moved on, most of us ended up with a PC or Mac or even Linux machine, and do little more than run software written by others. Thirty years ago, if we wanted to print up a sheet of return address mailing labels, we would type in a few lines of BASIC and be done.

10 FOR I=1 TO 25
20 PRINT #-2, "Allen C. Huffman"
30 PRINT #-2, "PO Box 22031"
40 PRINT #-2, "Clive IA 50325-94014"
50 PRINT #-2

Today, if we don’t have a template for MS-Word, we might end up Googling to find some freeware or shareware offering. (I suppose we have also passed up the pre-Internet times when folks had to go to a computer store like Babbages or CompUSA to look for something on the shelf to buy.)

But what about all those BASIC coders that perhaps haven’t ever written even the simplest line of code for a Windows PC? Did they all just decide they no longer liked it? Or did the environment change enough that programming just wasn’t as accessible?

32K CoCo BASIC memory.Certainly, modern computers no longer power up instantly and present you with a place to type and run a program…

My recent exposure to the Arduino has made me want to program for fun again. Just like my TRS-80 Color Computer, I purchased my Arduino UNO R3 at a nearby Radio Shack. But unlike my CoCo, the Arduino required a host PC/Mac/Linux machine to make it do anything, and then you had to know C/C++. Fortunately, I do… I learned it on my CoCo under OS-9 back in the late 1980s! But what about all those non-OS-9 CoCo owners who stuck with Disk Extended Color BASIC? For them, an Arduino would present quite a learning curve.

But could someone who knows BASIC learn enough to write (very poor) C and actually use an Arduino? I think they could.

void program()
  for (i=0; i< =25; i++)
    Serial.println("Allen C. Huffman");
    Serial.println("P.O. Box 22031");
    Serial.println("Clive IA 50325-9401");

Tonight, my *ALL RAM* BBS system is fully functional on my Arduino. The code I originally wrote thirty years ago in BASIC was well structured, with subroutines for items like input and output which translated easily to C functions. Program logic was a mess of if statements and gotos, but since C supports both, it was fairly easy to make the jump. But, it wasn’t pretty. Instead of line numbers, I created C lables in the format of “lineXXX:” where XXX was the desired line number:

//120 KY=KY+1:IFKY>200THENPRINT"Sorry, your time on-line is up.":GOTO210ELSEIFKY>180THENPRINT"Please complete your call soon."
 ky = ky + 1;
 if (ky>200)
   Serial.println("Sorry, your time on-line is up.");
   goto line210;
 else if (ky>180)
   Serial.println("Please complete your call soon.");

And, to make things flow a bit better, I created C functions to replicate some of the BASIC keywords:

//130 LN=INSTR("?CGRSPU%",A$):IFLN=0THENPRINT"*Invalid Command*":GOTO120
 ln = instr("?CGRSPU%", aStr);
 if (ln==0)
   print("*Invalid Command*");
   goto line120;

Some things did not have a direct equivalent in C, but could be done in a simple, brute-force manner:

//140 ONLN GOTO105,155,205,405,455,305,255,505
 if (ln==1) goto line105;
 if (ln==2) goto line155;
 if (ln==3) goto line205;
 if (ln==4) goto line405;
 if (ln==5) goto line455;
 if (ln==6) goto line305;
 if (ln==7) goto line255;
 if (ln==8) goto line505;

I was surprised at how well one could program C as if it were BASIC.

As of tonight, *ALL RAM* BBS runs on my Arduino, complete with userlog and message base. Due to limited memory, there is only room for a few users and a few TINY (Twitter-sized) messages, but it all works. I had to do some Arduino tricks to get strings and such moved in to Flash to free up precious RAM, and once I did that, I even had room to use some SD memory card routines for replacing the original cassette tape load/save routines. (Yes, I realize this is rather silly. There’s no reason to run a RAM-based BBS if you have access to disk storage, but I never said this was a practical experiment.)

I even managed to use my Arduino Ethernet shield and telnet in to the micro BBS. The quick modifications I made to allow this weren’t fully baked — once the connection was broken I had to reset the Arduino — but I believe I will work on that next. (Though probably not with SD card support. I just don’t think there’s enough RAM for both.)

So, in coming days or weeks, I will try to find time to share the code, or at least examples of how I created BASIC-like functions in C.

Until then…

*ALL RAM* BBS Logoff ScreenP.S. – For the younger ones of you out there, yes, there was a time when lowercase was not available. The original TRS-80 Color Computer presented inverse letters to represent lowercase. It wasn’t until the later model “Tandy” Color Computer 2s that the machine got true lowercase. (My CoCo 1 had an aftermarket lowercase board installed in it…) I feel so old.