• Please review our updated Terms and Rules here

Level I BASIC interactive input

gp2000

Experienced Member
Joined
Jun 8, 2010
Messages
468
Location
Vancouver, BC, Canada
Level I BASIC doesn't have INKEY$ nor does it have PEEK. INPUT waits for input. There's no obvious way to write a game or other interactive software that needs to poll the keyboard. I happened to glance through "Some of the Best from Kilobaud Microcomputing" and saw where some clever soul figured out a way using pure Level I BASIC. That is, nothing tricky like loading an assembly language program that somehow extends BASIC (geez, if that is even possible).

If you like, try and figure it out yourself. Chances are it will be the most obsolete technique you find this month.

No need to write Breakout or Tetris, just take this simple program and have it do D=-D when a key is pressed so the dot changes direction. Just make sure the dot keeps moving when no key is pressed.

Code:
10 CLS
20 D=1:X=0
30 RESET(X,24):X=X+D
40 IF X > 127 THEN X = 0
50 IF X < 0 THEN X = 127
60 SET(X,24)
70 GOTO 30

For bonus internet points distinguish between two different keys (you can pick which pair). Can you do 3 different keys? 4?
 
Are you sure about this? The program above doesn't have any interaction with the keyboard. Did you forget something?
 
Are you sure about this? The program above doesn't have any interaction with the keyboard. Did you forget something?

Ah, the puzzle is for you to add some Level I BASIC code so it has non-blocking keyboard interaction.

So far mo stalwart adventurers have volunteered to climb Mt. Useless. I'll post a hint later and a solution a bit after that if there are no takers.
 
I'll post a hint later and a solution a bit after that if there are no takers.

I'm not sure if I'm on the right track, but I assume it's got something to do with a Level I program pausing while you press a key? Does it take advantage of a bug in Level I, or is it a legit use of it?
 
Last edited:
I'm not sure if I'm on the right track, but I assume it's got something to do with a Level I program pausing while you press a key? Does it take advantage of a bug in Level I, or is it a legit use of it?
You need to take advantage of how the level I input routine works. It's not fully documented, but it's not a bug, and you can learn all you need to know with a little experimentation.

That said, it still takes a stroke of genius to figure out the trick. I only know it from having read about it.


Hmm, it seems this forum has no SPOILER tag for hiding text. I'll put some spoiler space, then switch to COLOR #FFFFFF.
















A hint: you somehow make use of the POINT function

Here's a full 4-key solution:
Code:
10 CLS:X=64:Y=24:D=1:E=0
20 P.AT1;:S.(0,0):S.(2,0):S.(4,0):S.(6,0)
30 V=X:W=Y:X=X+D:Y=Y+E
40 X=X+128*((X<0)-(X>127))
50 Y=Y+47*((Y<1)-(Y>47))
60 S.(X,Y):R.(V,W)
70 J=P.(0,0)+2*P.(4,0)+P.(6,0)
80 IFJ=4T.30
90 D=0:E=-1:IFJ=0T.20
100 E=1:IFJ=1T.20
110 D=-1:E=0:IFJ=3T.20
120 D=1:IFJ=2T.20
Instructions:
Use CLEAR, ENTER, left arrow, or space, to change the moving dot's direction to up, down, left, or right. Any other ordinary key is taken as a space. Two ordinary keys in rapid succession will sometimes be mistaken for an ENTER.

Say, George, I figured out how to copy text from the trs80gp screen using Record/Text VRAM, but how do I paste text into the emulator?
 
Last edited:
Ah ok, I'd noticed that it printed the key to the screen but quickly dismissed making use of that because there was no PEEK. However I didn't think about using SET/POINT.

So, here's the simple one key version (added lines 25 and 65 to original code).

Code:
10 CLS
20 D=1:X=0
25 PRINT AT 0;:SET(0,0)
30 RESET(X,24):X=X+D
40 IF X > 127 THEN X = 0
50 IF X < 0 THEN X = 127
60 SET(X,24)
65 IF POINT(0,0)=0 THEN D=-D:GOTO 25
70 GOTO 30
 
Yep, you both got it. A pretty cute trick. I've noticed a few difficulties. Level I BASIC will stop execution while a key is pressed so that's something the game will have to put up with. I also saw that one can easily manage to type several characters before the BASIC program has time to notice. Could make for a tiny little game where the objective is to see how many key presses you can get in before the program catches up.
 
Say, George, I figured out how to copy text from the trs80gp screen using Record/Text VRAM, but how do I paste text into the emulator?

It doesn't support cut and paste, unfortunately. Thought about it, but I get by with passing in BASIC programs as an ASCII text file on the command line. And if I want to extract a BASIC program, LLIST will do (the output goes to the file trs80-printer.txt).
 
It doesn't support cut and paste, unfortunately. Thought about it, but I get by with passing in BASIC programs as an ASCII text file on the command line. And if I want to extract a BASIC program, LLIST will do (the output goes to the file trs80-printer.txt).
Thanks, I hadn't realized I could get the BASIC source into the emulator like that. As for LLIST, that doesn't exist in Level I, at least not on the Model I, which is what trs80gp was emulating when I wrote this program. Guess now I have a good reason to try out the obscure Model III version next time I play around with Level I BASIC.
 
I happened to glance through "Some of the Best from Kilobaud Microcomputing" and saw where some clever soul figured out a way using pure Level I BASIC.
The whole run of Kilobaud/Microcomputing was added to archive.org a couple years ago, and it's a great resource for coverage of the pre-80-Micro TRS-80 era (i.e., 1978 and 1979).

The book doesn't seem to have ever been scanned, though. Could I trouble you to post a photo of the table of contents?

After a quick search at archive.org, the only relevant article I found is the March 1979 "Keyboard Interrupt for the TRS-80" by Paul Klinger, which only covers the single-key technique. Does the book contain some later article I missed that covers the ENTER, left-arrow, and CLEAR cases? I'm pretty sure a couple years ago I saw some vintage article that covered at least a 2-key technique, but it might not have been in Kilobaud.

By the way, that Level I wizard, Paul Klinger, appears to be the same University of Michigan neuroscientist / PDP-8 user (see January 1980 Softside) / Dixieland cornetist who still performs every Tuesday in Ann Arbor at the Zal Gaz Grotto.

Also, I belatedly noticed Level I actually has ON/GOTO. So, here's a cleaner version of my program that uses it. As before, press CLEAR, ENTER, left arrow, or space, to change the moving dot's direction to up, down, left, or right.
Code:
10 CLS:X=64:Y=24
20 D=0:E=-1:G.60
30 D=0:E=1:G.60
40 D=1:E=0:G.60
50 D=-1:E=0
60 P.A.1;:S.(0,0):S.(2,0):S.(4,0):S.(6,0)
70 V=X:X=X+D:X=X+128*((X<0)-(X>127))
80 W=Y:Y=Y+E:Y=Y+47*((Y<1)-(Y>47))
90 S.(X,Y):R.(V,W)
100 ON P.(0,0)+2*P.(4,0)+P.(6,0)+1 G.20,30,40,50,70
 
Last edited:
After a quick search at archive.org, the only relevant article I found is the March 1979 "Keyboard Interrupt for the TRS-80" by Paul Klinger, which only covers the single-key technique. Does the book contain some later article I missed that covers the ENTER, left-arrow, and CLEAR cases?

That's the one. Once I saw the trick I tried all the keys to see what they did. I don't know of any follow-on articles though I haven't looked. Shift seems to act like a control key in Level 1. shift-C is the same as BREAK, shift-M for ENTER and shift-L for CLEAR -- all the ASCII correspondences you would expect. But other shift combinations appear to have no effect when it comes to special characters.

Could I trouble you to post a photo of the table of contents?

Sure thing; I'll attach it but in case the image is shrunk you can find it here: https://www.dropbox.com/s/u9lx8nexciuzv1j/kilobaud-toc.jpg?dl=0

kilobaud-toc.jpg
 
Back
Top