Friday 11 March 2011

DNA Source Code

Today, should have been Douglas Noel Adams' 59th birthday.

It's a real pisser that we can't all clog up his @mentions column on Twitter with our best wishes, as it's fairly safe assumption that Douglas would have had a twitter account before Stephen Fry.

It is an important and popular fact that things are not always what they seem. For instance, Douglas is often quoted as being the first European to own an Apple Macintosh computer. (Narrowly pipping Stephen Fry to this momentous milestone). This may well be true, however, the highly frustrating Hitch Hikers Guide to the Galaxy computer game (did you ever get that bloody Babel fish out of the dispenser?) written by Douglas and Steve Meretzky first appeared in 1984 on a number of platforms including the Macintosh's humble predecessor, the Apple II.

By a strange coincidence I started my working life in 1984 as a computer programmer on the Apple II (actually it was an Apple IIe 32K with twin 5 1/4 inch floppy drives), not unlike this bad boy here:

It's now been well over 25 years since I last attempted to write a program for the Apple II, but I recently rediscovered this Applesoft BASIC reference manual, a copy of which used to adorn my desk as
it had already supplanted the great MITS Altair BASIC Reference Manual as the standard repository of all knowledge and wisdom.

Others of my age, who learnt to program on the Acorn BBC micro may notice a similarity as both machines were based on the 6502 microprocessor.

Looking back at this reference manual now, its seems frustratingly devoid of even the simplest language constructs. In fact, I recall that due to the lack of a simple boolean variable type, I frequently peppered my code with memory wasting statements like IF PINK$ = "FLOYD" THEN GOSUB X, for want of a simple binary switch.

Curiously, an edition of the Applesoft BASIC Reference manual which conveniently fell through a rift in the time-space continuum from 25 years in the past describes the manual as "frustratingly devoid of even the simplest language constructs."

Anyway, on the slight off-chance that I'm not the only DNA fanboy who also eked out a living in the early 1980's as a dodgy AppleSoft BASIC programmer, here's some utterly pointless and inefficient pieces of source code that I quickly cobbled together last night to remind you of both Apple's great advancements and literary's immense loss.




>LIST

10 TEXT
20 HOME
30 PRINT "I am at a rough estimate thirty billion times more intelligent than you."
40 PRINT "Let me give you an example."
50 PRINT "Think of a number, any number. ";
40 INPUT A$
50 PRINT
60 PRINT "Wrong. You see?"



>LIST

10 TEXT
20 HOME
30 PRINT "Enter 24 hour time in format (hh.mm): ";
40 INPUT T$
50 H$ = LEFT$(T$,2)
60 PRINT "Time is an illusion ";
70 REM double if lunchtime
80 IF H$ >=12 AND H$ <13 br="" print="" then="">


>LIST

10 REM Vogan Grandmother attack checklist
20 TEXT
30 HOME
40 PRINT "Do you have orders to save your Grandmother from the ravenous Bug-Blatter Beast of Traal? (Y/N): ";
50 GOSUB 300
60 PRINT "Have the orders been signed in triplicate? (Y/N)";
70 GOSUB 300
80 PRINT "Have the orders been sent in? (Y/N)";
90 GOSUB 300
100 PRINT "Have the orders been sent back? (Y/N)";
110 GOSUB 300
120 PRINT "Have the orders been queried? (Y/N)";
130 GOSUB 300
140 PRINT "Have the orders been lost? (Y/N)";
150 GOSUB 300
160 PRINT "Have the orders been found? (Y/N)";
170 GOSUB 300
180 PRINT "Have the orders been subjected to public inquiry? (Y/N)";
190 GOSUB 300
200 PRINT "Have the orders been lost again? (Y/N)";
210 GOSUB 300
220 PRINT "Have the orders been buried in soft peat for three months? (Y/N)";
230 GOSUB 300
240 PRINT "Have the orders been recycled as firelighters? (Y/N)";
250 GOSUB 300

260 PRINT "Resistance is useless"
270 END

300 INPUT A$
310 IF A$ <> "Y" THEN GOTO 400
320 RETURN

400 PRINT "You are not authorised to lift a finger to save her"
410 END



>LIST

10 DIM A$(3)
20 A$(0) = "Anything that happens, happens."
30 A$(1) = "Anything, in happening, that causes something else to happen, causes something else to happen. "
40 A$(2) = "Anything that, in happening, causes itself to happen again, happens again."

50 TEXT
60 HOME

65 REM It doesn't necessarily do it in chronological order, though.
70 REM set x to a random value between 0 and 2
80 x = INT (3 * RND (1))
90 PRINT A$(x)

100 REM Set y to a random value between 0 and 2 other than the value of x
110 y = INT (3 * RND (1))
120 IF y = x GOTO 110
130 PRINT A$(y)

140 REM Set z to a random value between 0 and 2 other than the value of x or y
150 z = INT (3 * RND (1))
160 IF z = x GOTO 150
175 IF z = y GOTO 150
180 PRINT A$(z)

190 END


Incidentally, I did originally write this as a series of shorter and catchier snippets of pseudocode, just for shits n' giggles, but I feared a torrent of pedantry if I included any syntax or semantic errors, so I thought it best to ensure my code does actually compile (well, interpret to be precise, I never had the luxury of a compiler).

So I found this excellent little Javascript version of the Applesoft BASIC interpreter which works a treat. If you copy any of the above pieces of source code and paste it over the sample "Hello World" program, and press "run", it will actually work. Although of course, it doesn't actually achieve anything useful.

Feel free to send me your own pieces of DNA AppleSoft BASIC source code in the comments for me to try out. Especially if you know how to multiply 6 by 9 in base 13. I think we all know what the answer to that is.

Oh, and before I go, special thanks to Prof Brian Cox for a stirring Douglas Adams memorial lecture at the Royal Geographical Society last night. Super.



I might send this in to the Readers Digest, I hear they have a page for people like me.

11 comments:

Anonymous said...

80 IF H$ >=12 AND H$ <>LIST
then what?

300 INPUT A$
310 IF A$ <> "Y" THEN GOTO 400
320 RETURN

400 PRINT "You are not authorised to lift a finger to save her"
410 END

Would be better as:
300 INPUT A$
310 IF A$ = "Y" THEN RETURN
400 PRINT "You are not authorised to lift a finger to save her"
410 END

Did you really do stuff like
IF PINK$ = "FLOYD" THEN GOSUB X, for want of a simple binary switch.
Surely, even on BBC basic, an integer is way smaller than a string, and so IF A = 5 THEN GOSUB X is way more memory effective, if perhaps less legible!

N0 "Always a critic" Sheds

Trinoc said...

When is it claimed DNA had his first Mac? I may be able to better the date as I was working for a shop that sold Apple II machines and then imported some of the first Macs. They also had the Mac's short-lived predecessor, the Lisa.

Did your Apple II by any chance have a red comms and/or printer card called "Diplomat"? I designed them, so you can blame me if they were rubbish.

Crispian Jago said...

@Anon,

Fixed line 80, I think HTML mis interpreted the less than sign.

Yeah, your replacment code is better. The last example could use a rewrite too

Neuroskeptic said...

Ah, the BBC Micro. My first computer.

I remember once at the age of maybe 9 being a big fan of Elite, and wondering how hard it must have been to program it in BASIC.

So I opened up the "source code" on the 3.5 inch floppy and was surprised to find it was only about 100 lines! Wow, I thought - programming is so easy!

In retrospect, I guess it must have been the boot logic that loaded the actual binaries from the disk. But if I'd known that at the time I'd probably have decided computers were far too hard, and ended up a non-geek.

Crispian Jago said...

@Trinoc,

Not sure of the source & validity of the claim that Adams had the first Mac.

I do recall "Diplomat", although I never actually had one.

I never mamanged to get my employers to upgrade to the Mac, but they did buy me a "speed card" for the Apple IIe. So I took of the velco fitted lid, and plugged it into one of the expanssion slots. This is probabbly what enabled me to use those inefficient binary switches to relieve the tedium.

I used to buy my Apple peripherals from a shop called "Knowledge Computing" in Chester-le-Street Co. Durham. Don't suppose you worked there?

Just zis Guy, you know? said...

I was at school with Ian Bell but I never owned a copy of Elite (my friend Mike did though). These were the days when you could really find out stuff, rather than just googling where someone else found it out!

Sadly my ancient PC on which I had an email from DNA himself is long gone.

Anonymous said...

u r a little no nonsensical idiot, crispian


say hello to my little friend...


rantsnraves.org/showthread.php?22142-Judgment-Day&p=675374

Colm said...

I graduated from a Spectrum to an Apple IIe, where I wrote a bookkeeping system in Apple Basic, without including the possibility of saving your work. As soon as you pressed the off switch everything was wiped. I thought it was a good idea at the time.

Billysugger said...

I first learned to program on Commodore PETs around 1979, also 6502 machines. My first computer was a home built 6502 board which was wire-wrapped (if you know what that is), and which I programmed by assembling straight into hex with a pencil and paper. Relative jump calculations involved counting up and down in hex, and I got quite good at that after a while! Oh those were the days... And to think what the minimum install size for a Hello World executable is on a PC now! How big is the dotNET framework runtime?

Crispian Jago said...

@Billysugger

I had a work placement at Durham University where I worked wire wrapping their own designed boards from a massive blueprint.

Billysugger said...

So you'll know all about Kynar knitting then! ;-)