
Donkey – A computer game included with early versions of PC DOS - mondaine
https://github.com/coding-horror/donkey.bas/blob/master/donkey.bas
======
screensquid
Playable here:
[http://www.pcjs.org/devices/pcx86/machine/5150/cga/64kb/donk...](http://www.pcjs.org/devices/pcx86/machine/5150/cga/64kb/donkey/)

"The above simulation is configured for a clock speed of 4.77Mhz, with 64Kb of
RAM and a CGA display, using the original IBM PC Model 5150 ROM BIOS and CGA
font ROM. This configuration also includes a predefined state, with PC-DOS 1.0
already booted and DONKEY.BAS ready to run.

And now that PCx86 automatically saves all your changes (subject to the limits
of your browser’s local storage), you can even close the browser in the middle
of a game of DONKEY, and the next time you load this page, your progress (and
the donkey) will be perfectly restored."

~~~
godzillabrennus
I'm disappointed that my iPhone can't drive the car because Apple didn't put
directional keys on the onscreen keyboard.

~~~
an_account
spacebar works (it's the only key needed).

~~~
hyperpallium
The "any" key also works, as well as the onscreen keys (e.g. F1)

It's not surprising that this simulation of a 36 year old 4.77Mhz desktop runs
fine in javascript on my 1.3GHz quadcore $40 phone... but in a way, it is.

~~~
voltagex_
This makes me wonder how accurate the timing is. I've been looking at the
Gameboy Link Cable, which seems to need very low latency. Are we there yet, in
the browser?

~~~
TazeTSchnitzel
It doesn't necessarily need accurate timing under emulation. The emulator is
god: it can play with time as it likes.

~~~
voltagex_
More interesting to me is to connect a real Gameboy to an emulator, probably
with the BGB protocol -
[http://bgb.bircd.org/bgblink.html](http://bgb.bircd.org/bgblink.html)

------
segmondy
Why are people complaining that the game is bad? Really? Can we see what you
wrote in 1982? Games like this were quickly hacked together to show the
capabilities of the machine. It was done in BASIC for owner's of those
machines to play with. If this was a commercial product, it would be written
in assembly.

If anything, this was likely a demo of Microsoft BASIC, let's not forget that
Bill Gate's first product was not an OS, but rather a BASIC interpreter
written in 1975 for the Altair 8800, written in assembly on paper tape,
without the actual hardware! This was written a good 5-7 years later.

While some may not like Bill Gates, he was probably a better programmer than
most of you in his youth and this was before the Internet where it's now easy
to get access to books, screencasts and lots of sample code via github. Give
the man his respect.

~~~
madaxe_again
This was the progenitor of other such classics as gorilla.bas. I liked that it
was "poorly" written, as it made it accessible - and I made the leap from
c64/amiga/acorn to ms-dos because I knew there was at least one language
(basic) on there that I could use.

Promptly after switching I learned c and never looked back, but there's a lot
to be said for what these early open-source (ykwim) games unlocked.

Hell, I started coding because I wanted to play games, and could only do so by
copying them into a micro from a magazine (storage media was prohibited) - and
fairly promptly wanted to cheat - and before I even really realised, was
writing my own games and finding holes in the micro's interpreter that could
cause entertaining crashes (I still fondly remember the look of panic on the
geography (that was the nearest thing to computers, I guess?) teacher's face
on coming into a lab (air raid shelter) full of vdus displaying a garbled
mess).

So yeah, "bad" code can be great to learn from at an early level.

Comment complete, please proceed to downvote.

~~~
sdegutis
Holy nested parenthetical expressions, Batman!

------
Jerry2
Andy Hertzfeld recollects how Macintosh team dissected the new IBM PC and what
they thought of donkey.bas:

[http://www.folklore.org/StoryView.py?project=Macintosh&story...](http://www.folklore.org/StoryView.py?project=Macintosh&story=Donkey.txt)

~~~
dingo_bat
Wow, that's a salty article!

~~~
ebbv
I don't think salty is the right word. Salt implies some kind of frustration
and I don't think that's accurate here.

I'd call it an honest, judgmental article.

~~~
segmondy
salty is slang for "envious"

~~~
o0-0o
"Throwing salt" can also be used to mean "casting dispersions", as it were. I
think the article tosses a bunch of salt towards Bill Gates, but who knows
what the motivation was. I'm guess when properly confused, you might just
throw some salt for luck, and end up looking salty yourself. :)

Edit: I'm talking about the author throwing salt, not any of the posters here.

~~~
HeyLaughingBoy
I have to do this! I believe you mean "casting aspersions."

------
pyromine
Here's a wiki link[0] for anyone else that didn't know what they were looking
at.

0:
[https://en.wikipedia.org/wiki/DONKEY.BAS](https://en.wikipedia.org/wiki/DONKEY.BAS)

~~~
vmarsy
> "We were surprised to see that the comments at the top of the game proudly
> proclaimed the authors: Bill Gates and Neil Konzen."

This is odd that these comments aren't in the github source code, is it
missing something? Why does it starts at line 940?

    
    
      940 REM The IBM Personal Computer Donkey
      950 REM Version 1.10 (C)Copyright IBM Corp 1981, 1982
      960 REM Licensed Material - Program Property of IBM

~~~
pythonistah
The line numbers in BASIC were arbitrary. People often started at higher
numbers and jumped by 10 in case they had to put code or comments before or
between lines.

~~~
colejohnson66
Could line numbers be out of order? Like, if I did this:

    
    
        10 PRINT "1"
        30 PRINT "2"
        20 GOTO 10
    

What would print out? Just a bunch of "1"s or "12"s?

~~~
allenu
It gets run in the correct order. Think of each line as a command that stores
the instruction immediately at that line number. You could actually "re-type"
a line later by reusing the same line number but replacing it with new
contents.

~~~
kqr
"Correct" order is ambiguous to someone asking that question in the first
place.

~~~
colejohnson66
It sounds like he's saying the "line number" is just the index to a tokenized
list (i.e. line 15 is at `lines[15]') where unused lines are just nops. So my
"program" would be tokenized and the lines stored like:

    
    
        char** lines = malloc(...);
        lines[10] = &line1;
        lines[30] = &line2;
        lines[20] = &line3;
    

Then when executing, it starts at `lines[0]', sees nops, gets to `lines[10]'
and runs it, sees more nops, gets to `lines[20]' and jumps to `lines[10]'. All
the while ignoring `lines[21]' and up.

~~~
abecedarius
Usually in 8-bit BASICs the lines would be stored consecutively (not in
separate malloced segments) with each line starting with its line number. Yes,
this meant that GOTO required a search. Memory was a really central design
constraint on these systems. I don't know how closely MS's BASICA on the PC
followed this model, but the PC's starting configuration had 16k bytes of RAM.

~~~
david-given
Here's a description of the file format used by BBC Basic:

[http://xania.org/200711/bbc-basic-v-format](http://xania.org/200711/bbc-
basic-v-format)

That's Basic V, which was the variant used on the ARM-based Archimedes, but
it's the same file format as the 6502 machine Basics.

Note that the line numbers used by GOTO and GOSUB were specially flagged ---
this was so the RENUMBER command could find them. It also meant that computed
gotos _weren 't_ renumbered...

(Of course, BBC Basic had proper named procedures and functions with local
variables, but all self-respecting Basics had to support GOTO and GOSUB.)

------
adrianratnapala
I never played or even saw Donkey. Too young.

But I learned to program by playing and modifying Microsoft Nibbles -- which
is still my favourite snake game. And possibly my favourite Microsoft product.

And QBasic is still the only IDE that I ever really _liked_. Although there
are some newer ones that I _respect_.

~~~
mbrock
Same here, and GORILLAS.BAS too. QBASIC was brilliant.

There's something about an immersive fullscreen coding tool with offline
documentation built in.

The other environments I've really loved were Lisp in Emacs and Java in
IDEA...

------
cosenal
Context here (Jeff Atwood's blog post dated 2007):
[https://blog.codinghorror.com/bill-gates-and-donkey-
bas/](https://blog.codinghorror.com/bill-gates-and-donkey-bas/)

~~~
arviewer
I love that right rear view mirror attached to the left front wheel! ;-)

~~~
ricklamers
Now I want to see what Donkey .NET is like ^^

~~~
userbinator
I believe this is the link:
[http://download.microsoft.com/download/4/b/4/4b400bf9-f71d-4...](http://download.microsoft.com/download/4/b/4/4b400bf9-f71d-4269-9338-63ac52856e91/Donkey.exe)

Found from some rather more shady-looking sites, but it points back to
download.microsoft.com, so I suppose it's legit.

------
32bitkid
My father bought the first family computer, an IBM PCjr, when I was 4 or 5.
Donkey.BAS made a huge impact on me, although its easy to overlook as a crap
game these days. Sure, there were "better" games that I played on that system:
my older brother purchased Sierra's Black Cauldron–which I played the shit out
of. My uncle wanted me to grow up to be a pilot, so MS Flight Simulator was in
order, too. Jordan Mechner's Karateka is still, to this day, mind blowing to
me. And lest we forget some Broderbund and Microprose classics.

But donkey.BAS was, which all those other things weren't, is my _first_, real
introduction to programming. I was too young at the time to really recognize
the value in being able to not only consume, but read the code, change it,
learn from it. Unlike more polished games, I learned way more about
programming from changing, breaking, and subverting donkey.bas than anything
else on the PCjr. Sure, it wasn't _the best_, but it was the first time that
someone pulled back the curtain and I was afforded a glimpse at what was
possible, and what computers could _do_. Between that, pouring through the
"Hands On Basic" book[0], and typing in basic programs COMPUTE magazine, I'm
not sure that I'd be a programmer today, as hyperbolous as that sounds...

And some overly nostalgic part of me kind of misses doing PEEKs and POKEs in
physical memory and the summer I spent learning binary math because I didn't
understand the relationship between the AH and AL registers of my 286 years
later. Then I go back to writing CRUD applications in whatever javascript
library is the flavor of the month.

I just hope that kids today have the same access to shitty, but accessible,
chunks of code to help inspire them and show them what the machines they
interact with everyday are really capable of.

[0]: [http://www.brutman.com/BasementCleanout/IBM_Hands-
On_BASIC/H...](http://www.brutman.com/BasementCleanout/IBM_Hands-
On_BASIC/Hands-On_BASIC_front.jpg)

~~~
dahart
Ha! I was 9 or 10 when my dad bought us a PC jr. It was awesome. Having the
code samples like Donkey.bas was what really allowed you to experiment, see
what was possible, and write longer programs. There was no online
documentation then.

There's a lot of shitty but accessible examples now, and a lot more ways to
get them easily. If anything, it's harder now to pick a
platform/device/language because there are so many choices. My kids won't put
down their iPhone games long enough to read code examples, even though they
talk about wanting to program.

------
donkeyd
This reminds me about my time writing games in Basic on my calculator during
math class. I suck at math because of this, but at least I'm an ok programmer.

~~~
doc_holliday
Yes! TI Basic on my Texas Instruments graphics calculator was how I spent
downtime during math class.

So much so, I remember writing program for solving quadratic equations.

They were supposed to clear the calculators memory during exmas, but the exam
invigilators had no idea what calculators could do, so they didn't.

I'd like to think it wasn't cheating... as writing quadratic solver in TI
basic is harder than solving simple quadratic equations. And I did do them all
by hand anyway in the exams...

~~~
hnal943
I have the same story, but my first program was for solving systems of
equations using a variety of methods and showing its work each step of the
way. Same as you, I learned the material far more thoroughly than had I
studied it in a conventional way.

------
mads
[https://www.youtube.com/watch?v=Ah_1HDf_tSU](https://www.youtube.com/watch?v=Ah_1HDf_tSU)

------
dragonbonheur
People forget that the intention of some programming demos is to explain some
concepts simply. The intended audience of that code wasn't some expert
programmer - it was for those who wanted to see how things worked so that they
could see how the game sucked and once they learned enough they could improve
upon it.

For expert BASIC code see Nibbles.BAS:

[http://stanislavs.org/OldPages/stanislavs/src/nibbles.bas](http://stanislavs.org/OldPages/stanislavs/src/nibbles.bas)

~~~
spydum
true enough, and I agree, it was just a demo hacked together, but i think the
difference you are seeing is both a consequence of nibbles requiring qbasic,
and nibbles being developed nearly 10 years later after basic has become quite
popular.

~~~
dragonbonheur
There are plenty of magazines on Archive.org where one could also find GW-
BASIC or BASICA code.

------
kobayashi
Relevant to the mention of 4 AM:
[https://www.youtube.com/watch?v=ORYKKNoRcDc](https://www.youtube.com/watch?v=ORYKKNoRcDc)

------
cdevs
36 years ago they wrote every popular iPhone game ever.

------
amelius
"2 lanes ought to be enough for anybody"

------
ernestbro
GORILLAS.BAS for the win

~~~
zamalek
My 386 didn't have a color graphics adapter, which required using a program
called "Phix" \- a terminate-stay-resident that emulated VGA on monochrome.
Sadly this completely broke QBASIC (the editor was just a black screen), so I
had to reboot the machine (to remove the TSR) in order to hack on
GORILLAS.BAS. Compilation times nowadays are still longer than that rigmarole.

~~~
pantulis
But it should have some kind of display adapter, what was it, Hercules? I
didn't know of any 386-class computers that didn't carry EGA or higher.

~~~
zamalek
Hercules definitely rings a bell. The Wikipedia page[1] actually explains how
the TSR [probably] worked, which seems to not be much as the Hercules seems to
be quite elegantly designed.

[1]:
[https://en.wikipedia.org/wiki/Hercules_Graphics_Card#CGA_Emu...](https://en.wikipedia.org/wiki/Hercules_Graphics_Card#CGA_Emulation)

~~~
pantulis
Well I clearly remember using an _Hercules emulator_ with my SuperVGA card so
that it could run some old DOS games, so the other way around also worked.

------
max_
How old was gates when he wrote this thing??

~~~
nekopa
Ah, programmers. I love how we can show the logic behind 3 correct ages for
Bill when he wrote this :)

~~~
homingbrain
However, since only one age value can be actually correct in this case, the
use of logic looks less like a feature of the programmer's mind and more like
a bug.

~~~
mikeash
One of them is a case of GIGO, using "36 years ago" as input when the correct
value is 35. Fixing that reduces it to two values, and the discrepancy is down
to day versus year granularity.

------
dkhenry
This reminds me of the first computer games I ever wrote. I remember being
able to get something so satisfying together in BASIC, with graphics, user
input, and sounds. Then I remember moving to C and asking how I could draw a
simple line, only to be told that it would require a few pages of boilerplate
to set up, and that all my programs should just be text prompts.

------
Kenji
Is anyone else impressed that it's only 131 lines long?? I have to do more
work to set up a plain empty window and OpenGL when I create my games these
days!

------
lucisferre
Wow, This is actually one of the first games I remember playing. I was
probably 4 or 5 and visiting my Dad at work. To keep me busy their IT guy
showed me this game. I think it was also the only time I played it.

Shortly after that we got a PC at home and it came with a demo copy of EGA
Golf which I think only had Pebble Beach. Sound quality was similar.

------
nickhalfasleep
The first code I ever wrote was modifying this in a few different ways on my
parent's IBM XT to say inappropriate things and change the game dynamics.

------
stefanix
You could say the frustration of interaction is already apparent. The fact I
cannot cut in right after a cow is so lame yet so familiar as a Windows user
of the 90s.

~~~
jeena
It might be because it is a donkey.

------
restalis
36 years ago? That would mean 1980, but the code says "1981, 1982" in its
copyright info.

------
avodonosov
It's pretty short

------
bane
This has as much interaction as many mobile mega hits.

------
frnhr
Try hitting the donkey with the side of the car :)

------
hclivess
imagine how many hours do you need to spend studying basic to be able to write
that

------
kragen
[https://robhagemans.github.io/pcbasic/](https://robhagemans.github.io/pcbasic/)
is a GPL3-licensed implementation of the BASIC language this game is written
in. PC-BASIC is written in Python. Supposedly it can run this game, although I
haven't tried it.

A couple of interesting features of the game (quotidian to those of us around
at the time, but...)

1\. The "PLAY" statement is barely used; the sounds are mostly done with the
SOUND statement, maybe in part because they are being generated randomly. In
fact it seems to be used only to verify that the program is being run on a
BASIC interpreter that supports "advanced" features like DRAW.

2\. The "DRAW" statement, which has its own mini-language similar to that of
the "PLAY" statement. Later these were dubbed "Graphics Macro Language" and
"Music Macro Language", even though neither one allows you to define macros.
This is used to include vector graphics of the donkey and the racecar in the
program, in the subroutines on lines 1940 and 1780, respectively. But the
interpretive rendering of these vector graphics (and especially the flood
fills, lines 1900 and 2010) was too slow to want to do it every frame; instead
it's done at program startup (into an on-screen buffer, since that's the only
way to do it in GW-BASIC or BASICA; you can see the painting happen briefly
before the game starts) and stored in the arrays CAR% and DNK% with GET
statements, later to be PUT onto the screen in the right place each frame.
There's a bit of sloppiness there: CAR% is DIMmed right there in the
subroutine on line 1910, while DNK% is DIMmed up at the top on line 1470. (And
the sprites for the halves of the donkey and car are dimmed there too, along
with a planned sprite called Q% which is never used.)

3\. There's actually an additional sprite, B%, which isn't set up with a GET
statement; it's filled in "by hand" to a simple fill pattern on lines
1510–1530. My memory was saying that the data format of this array was
undocumented, but it does seem to be documented in
[http://www.antonis.de/qbebooks/gwbasman/](http://www.antonis.de/qbebooks/gwbasman/),
which I'm pretty sure is the actual GW-BASIC manual from Microsoft. Anyway, B%
is a vertical line that's getting XORed into the framebuffer (the default PUT
raster op was to XOR into the framebuffer, violating patent 4,197,590 if you
use it for a cursor) to make the stripes down the middle of the road "move".

4\. See how AND is being used as a bitwise operator? That's why true was -1 in
MBASIC.

I think there are some important lessons in GW-BASIC/BASICA about how to
design user interfaces for end-user programming, and the DRAW and PLAY
statements in particular. Also, I can't have been the only person who never
figured out how to use the vi-like line editor in BASIC-80 but who edited
existing code all the time in Z-BASIC/GW-BASIC/BASICA because I could just use
the arrow keys.

~~~
johansch
PC-BASIC is a great re-implementation of GWBASIC. I tried it on some of my old
gems from the late 80s and they still worked. :)

~~~
kragen
Are you going to put them on Github?

~~~
johansch
Sorry, that would be deeply embarrassing. I was 10-12. :)

~~~
kragen
Use a nym! Just be sure to generate a separate ssh key for it.

------
grhmc
Could we fix the title?

~~~
gus_massa
(I agree.)

If you see a submission with a very bad title in the front page, you can ask
the mods to change it with an email to hn@ycombinator.com

It's usually faster to use the email because sometimes the comments are
unnoticed.

------
FoeNyx
So 3 decades ago the autopilot could already keep the car in the current lane
but was not able to avoid the unicorn^W donkey? Drivers need to remain engaged
and aware!

