The Joys of PCjr Programming

May 1st, 2009

p-pcjr-basic

Recently I’ve been getting my new project, “Twittjr” (a mashup of Twitter and an IBM PCjr), ready to attract people to the CSH booth at GCCIS for ImagineRIT. Coding in Cartridge BASIC on a PCjr is simultaneously a fascinating and frustrating experience. On the one hand, it’s kind of annoying to not have any modern conveniences like, say, functions. But on the other hand, it’s sometimes fun to go through the weird brain contortions required to actually do things with Cartridge BASIC.

One of the interesting things about BASIC (at least in this ancient incarnation) is that it’s much more relaxed than modern languages regarding where you can send its thread of execution. Of course, you only have one thread, so you have to make the most of it. For example:

10 ON TIMER(30) GOSUB 1000: TIMER ON
20 WHILE 1
30 ' Do something continuously
40 WEND
...
1000 ' Do another thing
1010 RETURN

Initially this will just go straight into the WHILE loop and do its thing. But every 30 seconds, code execution will hop right out of that loop and jump over to line 1000 for the subroutine. If you’re doing something really important in the loop and you don’t want to be interrupted, just TIMER STOP before the important bit and TIMER ON afterward. It’s an extremely simplistic way of doing things, and doesn’t take much effort to write, but it also has a number of obvious issues that wouldn’t come up in a threaded environment (e.g. stalling in the subroutine will make the entire program lock up).

Of course, the vast majority of things you might try to do in BASIC are just plain unreasonably difficult. Subroutines don’t take parameters, so global variables are the only way to pass data between different parts of your program (not that there’s any variable type other than global). String manipulation is really fun because literally all you can do is A) Find the position of the first occurrence of a substring within a string, B) Extract a substring from a string based on character offsets, and C) Get the length of a string. Technically you can do everything with those operations that you could do with, say, regular expressions, but try anything more complex than splitting a string into an array and your code starts to look like spaghetti.

At any rate, Twittjr is almost ready for the innovation fair tomorrow; all it needs is some better word wrapping and I can probably call it v1.0. The full project write-up will be posted soon, and I’ll add the code itself a bit later.

No comments yet.