Back in the early 1980s I had a Video Genie (which was a clone of the Radio Shack/Tandy TRS-80 Model I Level II).
I set myself a challenge of writing a program using a single line of BASIC code. After writing a few simple programs I wondered if it was possible to write a game in one line of code?
It turns out it was possible. I wrote "Missile Dodge", where a player at the top of the screen has to move left or right to dodge missiles being fired at him from the bottom of the screen.
Although my original code was long since passed into the ether, I was reminded of the challenge recently. I decided to dig out a TRS-80 emulator and try to re-create Missile Dodge.
It turns out all the old programming tricks came flooding back to me, and I'm pretty confident that this code is faithful to my original program:
0 IFI=0THENCLS:PRINT"MISSILE DODGE: Z=LEFT, X=RIGHT":PRINT"DIFFICULTY";:INPUTD:CLS:I=1:GOTOELSEFORX=1TOD:PRINT@959+RND(64),"!";:NEXT:PRINT:P=P+(PEEK(14344)=4ANDP>0)-(PEEK(14344)=1ANDP<63):IFPEEK(15360+P)=33THENPRINT"SCORE";SELSEPRINT@P,"*";:S=S+1:GOTO
I wrote the program on this emulator: [ Ссылка ]
But I also tested them on TRS32: [ Ссылка ] so it should work on almost anything. (Although I have been told that some emulators run too fast for the game to be playable - the two emulators I mention seem to simulate the clock speed of the original TRS-80, so the game plays fine.)
A few notes:
(1) the maximum line length for a BASIC program on these is 254 characters, but the standard input buffer for entering commands isn't that big, so you have to input part of the line, then edit the line to complete it! To edit a line do "EDIT 0". Then "x" will take you to the end to append more.
(2) in this basic the parser doesn't require spaces to correctly identify commands, so there is a saving there. Doesn't make it very readable though!
(3) the screen is 64 characters across by 16 rows down. The PRINT @ command allows you to place output anywhere on the screen, with position 0 at the top left and 1023 at the bottom right
(4) PEEK(X) allows you to read memory address X. Address 14344 is part of the keyboard memory map and allows me to see if a key is pressed or not. I don't use the built in INKEY$ function in BASIC because that doesn't allow you to hold down a key, you'd have to stab the key repeatedly to move.
(5) the 1024 characters of the screen memory are from 15360 to 16363, so I can PEEK at that to see if there is a missile at the point where I'm about to draw the player to detect a missile collision
(6) PRINT moves the cursor to a new line unless you terminate it with a ";". If you PRINT on the last line of the screen and don't use ";" then the screen will scroll. I use this functionality to scroll the screen and therefore animate the game. Because the player is on the top line it disappears so I don't need to blank it out before I draw it at the new position. Both of these give me very cheap animation! If I'd had it scrolling the opposite way (missiles coming down at you) then it would have been much harder - and indeed I wouldn't have been able to do it without using machine code. I know - I tried. Back in the day I ended up writing some machine code libraries to scroll the screen in an arbitrary direction, and it still wasn't quite as fast.
Anyone else want to have a go writing a game in this severely limited medium?
Here's a guide to the BASIC: [ Ссылка ]
These give details of that keyboard map:
[ Ссылка ]
[ Ссылка ]
[ Ссылка ]
And some other useful technical stuff:
[ Ссылка ]
Tips for beginners (1) write the program on multiple lines and only condense it when it works! (2) using the emulators you can copy the code out of the emulator, edit it in your favourite editor, and then copy it back - although I kinda like the clunky editor in the BASIC, it takes me back to my youth!
Have fun :-)
Ещё видео!