Home computer · 1982
The Dragon 32, in your browser
The Dragon 32 came out of Wales in 1982: 32 kilobytes of memory, a keyboard that plugged into the family TV, and a cassette recorder instead of a disk drive. Here it is rebuilt in your browser, in the style of the time. Plug in a cartridge and play, load a program from cassette, or type your own BASIC. Everything here was written from scratch; there is no original Dragon code or ROM.
This is the guide. The computer itself opens with "Back to the computer". You can also install it as an app: on a phone, "Add to Home Screen"; on a computer, the install icon in the address bar.
How to start
- Switch it on. On a computer it powers up by itself. On a phone, tap "Power on".
- Type and press Enter. For example
PRINT "HELLO". On a phone, use the Dragon's own keyboard on screen (the "Keyboard" tab), or switch to the phone keyboard. - Rather not type? The "Commands" tab has ready-made commands: pick one and press "Try it now".
- To play: the "Shelf" tab has cartridges (action games) and cassettes (BASIC games).
- To stop: the "Stop" button on the screen, or Esc. After a drawing, "Back to text".
- Stuck? There is a helper you can ask, in the "Helper" tab (on a computer, in the side column).
The computer
Cartridge slot: action games with graphics. Pick a cartridge and it goes into the computer
Cassette shelf: pick a cassette, and it loads and starts
TYPE-IN PROGRAM · 1983
DRAGON DERBY
A program from a magazine. In the 1980s computer magazines printed whole programs, and kids spent hours typing them in, character by character. One tiny slip and the computer answered ?SN ERROR. This one is our own, written in the style of the time: a little horse race. Bet on a horse and see who gets there first.
How: on the computer type AUTO, then the lines (without the numbers; AUTO adds them). Finish with RUN. Or let the computer type it for you.
Show the code (18 lines)
10 CLS 6
20 PRINT "DRAGON DERBY"
30 INPUT "BET ON HORSE (1-3)";B
40 X=0:Y=0:Z=0
50 X=X+RND(3):Y=Y+RND(3):Z=Z+RND(3)
60 CLS 6
70 FOR I=1 TO X:PRINT "-";:NEXT I:PRINT "1"
80 FOR I=1 TO Y:PRINT "-";:NEXT I:PRINT "2"
90 FOR I=1 TO Z:PRINT "-";:NEXT I:PRINT "3"
100 SOUND 60+X+Y+Z,1
110 FOR T=1 TO 150:NEXT T
120 IF X<25 AND Y<25 AND Z<25 THEN 50
130 W=1:M=X
140 IF Y>M THEN W=2:M=Y
150 IF Z>M THEN W=3
160 PRINT "HORSE";W;"WINS!"
170 IF W=B THEN PRINT "YOU WIN!":FOR I=1 TO 5:SOUND 150+I*20,1:NEXT I:END
180 PRINT "BETTER LUCK NEXT TIME"
Look at line 110: FOR T=1 TO 150:NEXT T is a loop that does nothing but count. That was how you "waited" back then, so the horses don't run too fast.
You can also copy it, go back to the computer and paste (⌘V or Ctrl+V): the computer types every line by itself.
What here is original?
Nothing from the original Dragon: there is no Microsoft / Dragon Data ROM and no games from 1982. Every part was written anew:
| Part | Written in | What it is |
|---|---|---|
| The BASIC (the computer itself) | JavaScript | An interpreter we wrote that behaves like Dragon BASIC in most things. Not identical in every detail. |
| Screen, keyboard and sound | JavaScript | Redrawn in the browser, in the colours and font of the time. |
| The 4 cartridges | JavaScript | New games we wrote in the spirit of the time. Original cartridges were written in machine code. |
| The 6 cassettes and the magazine program | BASIC | Programs we wrote in Dragon BASIC. After loading, LIST shows the code. |
| The helper | Claude | Today's AI, which knows this BASIC. |
🧪 Trial: the real machine. Separately from the app, we are building a Dragon 32 emulated at chip level (the XRoar emulator), with a new BASIC we wrote in 6809 machine code instead of the protected ROM. Try the real machine, and tell us what differs from the original.
Then and now: what I'd write to Claude today
Back then you had to know exactly how to write every line. Today it's enough to explain what you want.
10 PRINT "GONEN ";
20 GOTO 10
"Fill the screen with my name, over and over, until I say stop."
10 FOR I=1 TO 12
20 SOUND I*20,2
30 NEXT I
"Play me a scale, from low to high."
30 N=RND(100):T=0
40 INPUT "YOUR GUESS";G
50 T=T+1
60 IF G<N THEN PRINT "HIGHER!":GOTO 40
70 IF G>N THEN PRINT "LOWER!":GOTO 40
80 PRINT "YES! IT WAS";N
"Make me a little game: the computer picks a number from 1 to 100, I guess, and it tells me to go higher or lower. At the end, tell me how many tries it took."
Hall of Fame
The high scores for each cartridge, with three initials, just like the arcade machines. World: the top ten of all players. Home: your own top five, in this browser. Only the three initials and the score are stored, nothing personal.
The short manual
Cassettes and cartridges. The Dragon had two ways to load a game. A cassette was slow: a BASIC program that loaded gradually, sometimes for minutes, and you could look at its code. A cartridge went into the slot on the side of the computer and worked at once. Its games were written in machine code, so they ran smoothly, with graphics and movement. The cartridges here are new games we wrote in the spirit of the games of the time.
With a cartridge you play with the arrow keys and Space, and on a phone with the buttons under the screen. Esc or "Eject cartridge" takes you back to BASIC.
In BASIC you type and send each line with Enter. This is the short version of the manual:
The basics
- PRINT "HELLO"
- Prints on the screen. Sums too:
PRINT 7*6. - 10 PRINT "HI"
- A line with a number doesn't run straight away. It is stored in the program, in number order.
- RUN
- Runs the program.
- LIST
- Shows the program. After loading a game, you can look at its code.
- AUTO
- Numbers the lines for you: 10, 20, 30. An empty line ends it.
- NEW
- Wipes the program and starts again.
- BREAK / Esc
- Stops a running program. There is also a "Stop" button on the screen.
- CLS 3
- Clears the screen and colours it. A number from 0 to 8.
- SOUND 100,4
- A beep: the pitch, then the length.
- INKEY$
- The key being pressed right now, without waiting for Enter. That's how games were written:
IF INKEY$="" THEN 100waits for a key.
Cassettes
- CLOAD "LANDER"
- Loads a game from cassette. With no name, "Guess the number" loads.
- CSAVE "SHIR"
- Saves the program you wrote to a "cassette" in this browser. It appears on the cassette shelf, and
CLOAD "SHIR"brings it back tomorrow too. Up to 8 letters or digits, and up to 6 cassettes. - ✕
- The small button on "My cassette" deletes a cassette you saved. The first click asks "Delete?", and only the second one deletes.
Programs
- IF A>5 THEN 100 ELSE 200
- If the condition is true, do what follows
THEN. Otherwise, what followsELSE. - GOSUB 100 … RETURN
- Jumps to line 100, and
RETURNcomes back to the statement after theGOSUB. That's how you write a part you use several times. - ON X GOTO 100,200
- If X is 1, jumps to 100; if 2, to 200. Works with
GOSUBtoo. - DIM A(20)
- A list (array) of 21 numbers:
A(0)toA(20). With$it's a list of words, and it can be a table too:DIM B(5,5). - READ A$ : DATA DOG,CAT
READtakes the next value from the program'sDATAlines, in order.RESTOREgoes back to the start.- INPUT "AGE";A
- Asks and waits for an answer.
INPUT A,Basks for two values separated by a comma, and if one is missing the computer asks again with??. - LINE INPUT N$
- Takes a whole line, commas included.
- DEF FNA(X)=X*X
- A formula of your own. Then
PRINT FNA(3)prints 9. - STOP … CONT
STOPhalts the program midway, so you can check variables withPRINT.CONTcarries on from the same place (afterBREAKtoo).- TRON / TROFF
TRONshows each line in brackets as it runs, to find where the program goes wrong.TROFFturns it off.- CLEAR
- Resets all variables and lists.
Fixing and tidying
- EDIT 20
- Brings line 20 up to the typing line. Fix it and press Enter.
- DEL 20-50
- Deletes lines 20 to 50. Also
DEL 20for a single line. - RENUM
- Renumbers: 10, 20, 30, and fixes every
GOTOandGOSUBthat points at the lines.
Words and numbers
- LEFT$ MID$ RIGHT$
- Parts of a word. From the start:
LEFT$("DRAGON",3) = DRA. From the middle:MID$("DRAGON",2,3) = RAG. From the end:RIGHT$("DRAGON",2) = ON. - LEN INSTR ASC CHR$
- Length of a word:
LEN("DOG") = 3. Where a letter appears:INSTR("HELLO","L") = 3. A letter's code:ASC("A") = 65, and back again:CHR$(65) = A. - STR$ VAL HEX$ STRING$
- Number to word:
STR$(5). Word to number:VAL("12") = 12. In base 16:HEX$(255) = FF. A repeated letter:STRING$(5,"*") = *****. - INT RND ABS SGN FIX
- A random number from 1 to 6:
RND(6). Without the part after the point:INTandFIX. Without the minus:ABS. The sign of a number:SGN(1, 0 or minus 1). - SQR SIN COS TAN ATN LOG EXP
- Square root, trigonometry (in radians), logarithm and exponent.
- TIMER
- A clock that counts 50 times a second.
TIMER=0resets it; handy for timing a game. - PRINT TAB(10);"X"
- Starts writing at column 10.
- PRINT USING "##.##";A
- Aligned numbers:
#a digit,$a dollar sign,,thousands commas.!the first letter of a word. - PRINT @ 240,"HI"
- Writes at a set place on the screen. Each row is 32 places: 0 at the top corner, 32 at the start of the second row.
Graphics and sound
- PMODE 3,1 : SCREEN 1,0
- Switches to the graphics screen (4 colours).
PCLS 3paints all of it blue. - PMODE 0 … PMODE 4
- Levels of detail: 4 is the sharpest with 2 colours, 3 has 4 colours, and 0 to 2 are coarser.
- COLOR 4
- Picks a drawing colour: 1 green, 2 yellow, 3 blue, 4 red. With
SCREEN 1,1: buff, cyan, magenta, orange. - PSET(128,96)
- A dot. The screen is 256 by 192, and (0,0) is the top left corner.
- LINE(0,0)-(255,191),PSET
- A line. With
,Bat the end: a box; with,BF: a filled box. - CIRCLE(128,96),40
- A circle: centre and radius.
- PAINT(128,96),3,4
- Fills a closed shape: from the point outwards, in blue (3), until it meets a red line (4). That's how you fill a circle.
- DRAW "U20R20D20L20"
- Draws with moves:
Uup,Ddown,Lleft,Rright, andE F G Hdiagonally.BM10,20moves without drawing,C2changes colour,S8doubles the size. - PPOINT(10,10)
- Which colour is at a point. That's how a game knows you touched a wall.
- GET(0,0)-(15,15),S
- Stores a square of the drawing in the list
S(firstDIM S(10)).PUT(100,50)-(115,65),Spastes it somewhere else. That's how you move a character. - PCOPY 1 TO 2
- Copies a whole graphics page.
PMODE 3,2shows page 2. - SET(10,5,3)
- A chunky coloured block on the text screen (64 by 30).
RESETturns it off, andPOINT(10,5)checks which colour is there. - JOYSTK(0) JOYSTK(1)
- The joystick: 0 to 63, up-down and left-right. On a computer with the arrow keys, and on a phone by touching the screen.
- PLAY "CDEFGAB"
- Plays notes.
#after a note raises it a semitone,O3a higher octave,L8short notes,T6a faster tempo,P4a pause.
Also allowed: INPUT, IF … THEN, GOTO, FOR … NEXT, variables like A or N$, and several statements on one line with colons. And if you type my name, it will answer.