krpalmer: Imagination sold and serviced here: Infocom (infocom)
krpalmer ([personal profile] krpalmer) wrote2024-01-18 06:32 pm
Entry tags:

Grasping the (Electric) Crayon

There are quite a few features in the trs80gp emulator, only some of which I’ve worked out how to use. One that did catch my attention a while ago was a peripheral called the Electric Crayon. It happened to have been described in an 80 Microcomputing article at the beginning of 1981 as a box (not huge, not small) hooked up in between a black-and-white TRS-80 and a colour monitor; by issuing commands from your computer (as if sending them to a regular printer, no less) you could generate colour graphics. After noticing the emulator feature I found the magazine again among the issues I brought from my family home, but never quite got around to typing in the demonstration programs.

Time passed, and the MC-10 and then the Color Computer itself were added to trs80gp, which could have been connected to how the Electric Crayon was an “intelligent peripheral” that used the familiar graphics chip of the “CoCo” with an earlier Motorola CPU. (From an ad I’ve seen, the Electric Crayon would have been cheaper than the Color Computer as introduced, and somewhat preceded it too.) Then, one day not that long ago I happened on the 80 Microcomputing issue again still separate from its fellows, and this time I resolved to start typing in the programs. Before I’d got very far at that, however, in getting a better sense of the relative handful of graphics commands the Electric Crayon offered I did think a bit more about its graphics chip. If it let an original TRS-80 produce graphics equivalent to the Color Computer’s, then it ought to be able to display an RLE image, which is just a series of horizontal lines in two colours fit into the chip’s highest resolution mode.

The trick there seemed to be the BASIC I’d have to work with to read the image file. The Apple II type-in program that had got me started with these images a while ago was able to read the file one character at a time, each character representing a specific number of “on” or “off” pixels. I’d found the same one-character reading ability in the TRS-80 Model 100’s BASIC. When I’d thought about writing a program for the Color Computer itself, though, at first glance my impression was that its Disk Extended Color BASIC could only read the unformatted stream of data in an RLE file with a command that could retrieve one raw slice of a disk at a time but required parsing that disk’s directory structure yourself to chase parts of a file across it. Before I’d sorted that out, I was lucky enough to happen on a RLE-displaying program in a random disk image downloaded years ago. For the original TRS-80, though, my impression was it didn’t even offer that command, and supposed its file input commands would choke two hundred and fifty-five characters into a file unless I sacrificed “cross-platform compatibility” and broke up the data stream into chunks separated by carriage returns or something, reformatting it with great effort.

I took one spin through an established archive of TRS-80 programs and turned up one said to be an RLE printing routine. Examining the code gave me the sense it was working with the characters the way you were supposed to with an RLE file, and offered hints of commands to look up in the TRSDOS and Disk BASIC manual. In the process, though, I realised the program was for the Model III, not the Model I. I turned to the manual for one of the multiple third-party disk operating systems offering additional features and much greater respectability than Radio Shack’s own effort, but found it obtuse. Returning to the simpler system, I began to sort out at last that I could open a file in “random access mode,” grab two hundred and fifty-six bytes of it, and split that into a mere two strings. Once a few experiments had proved repeating that actually stepped through the RLE file without leaving anything out, I started buckling down to using the string-manipulation commands to pick out each character at a time, and then began to link the numbers they represented to the Electric Crayon graphics commands.

Glimpses of my sample image began to appear amid graphic peculiarities. The first thing I sorted out was that I did need to keep from drawing lines “zero pixels long” in between lengthy stretches of all white or all black. After that, I wobbled back and forth about just what drawing lines 256 pixels wide while the screen coordinates went from 0 to 255 meant, then realised my first sample image had been set up to avoid a subtler bug involving not resetting a counter when wrapping a length of pixels along to the next line down. By that point, though, I was realising the program was very slow. Downloading an RLE image at 300 baud would not have been the bottleneck for it. I checked the Apple II type-in program I’d started with and saw that it, as slow as it had seemed before, could draw the same image almost twice as fast as the TRS-80 to Electric Crayon program.

Telling myself I’d at least proved the concept, I picked up a newer issue of 80 Micro (a mere forty years old this month, where the ultimately-infamous Tandy 2000 was introduced) and started leafing through it. An ad for a “BASIC compiler” caught my eye. As much as I understood those programs didn’t offer the performance programming in assembly language yourself provided, I at least wondered what it might have done. Then, I started looking through my own repository of TRS-80 software. The compiler turned up; more importantly, its manual turned up on the Internet Archive. Reading it I did see I’d have to make a few small changes to my BASIC commands.

While the first version of the compiler I could get to load at all “spontaneously rebooted” back to DOS READY when I tried actually compiling with it, the fact of there being numerous copies of many things in the software repository meant I was able to find another variant of it that did work. The compiled version ran about seven times as fast as the interpreted BASIC; it still took minutes to draw an image, but not over ten minutes any more. After that I did reconsider one bit of program logic, but only shaved seconds off execution time.

As ever, the point might be the pointlessness of it all. Supposing this would have been useful someone who’d bought themselves an Electric Crayon and kept it alongside their TRS-80 until RLE images began showing up on CompuServe a few years later is one hypothetical case among many. I am conscious of how many of the other people who still fiddle around with computers of this age seem able to program in assembly. Still, I did get to the point of looking back into the Color Computer disk manuals and noticing it actually supported the disk access mode I used; it’s just called “direct access” there.

5 REM RLE FOR MODEL I AND ELECTRIC CRAYON
10 CLEAR 300:DEFINT A-Z:H$=CHR$(27)+CHR$(71)+CHR$(72)
20 INPUT"FILE TO OPEN (ENCLOSE IN QUOTES)";F$
30 OPEN"R",1,F$
40 FIELD 1,128 AS A$,128 AS B$
50 GET 1
55 REM CHECK FOR RLE HEADER
60 IF LEFT$(A$,3)=H$ THEN 80
70 CLOSE:PRINT"FILE DOESN'T BEGIN WITH RLE HEADER":END
80 X=0:Y=0:P=4:C=0
85 REM INITIALIZE ELECTRIC CRAYON
90 LPRINT"M9 ERS I"
95 REM A STRING LOOP
100 E$=MID$(A$,P,1)
105 REM CALCULATE NUMBER OF PIXELS
110 L=ASC(E$)-32
115 REM ZERO PIXELS IN NEXT COLOUR?
120 IF L=0 THEN 250
125 REM END OF CHARACTER STREAM?
130 IF L<0 THEN 500
135 REM ADVANCE DISTANCE ALONG LINE
140 D=X+L
145 REM PAST EDGE OF SCREEN?
150 IF D<=256 THEN 200
155 REM PLOT TO EDGE OF SCREEN
160 Z=L-(D-256)
170 LPRINT"C ";ABS(C);"H ";X;Y;Z
175 REM MOVE TO NEXT LINE
180 Y=Y+1:X=0:L=D-256:D=L
185 REM PAST BOTTOM OF SCREEN?
190 IF Y>=192 THEN 500
195 PLOT LINE
200 LPRINT"C ";ABS(C);"H ";X;Y;L
205 REM NOT AT END OF LINE?
210 IF D<256 THEN 230
220 D=0:Y=Y+1
230 X=D
235 PAST BOTTOM OF SCREEN?
240 IF Y>=192 THEN 500
245 REM CHANGE COLOUR
250 C=NOT C
255 REM PREPARE TO GET NEXT CHARACTER
260 P=P+1:IF P<=128 THEN 100
270 P=1
295 REM B STRING LOOP
300 E$=MID$(B$,P,1)
305 REM CALCULATE NUMBER OF PIXELS
310 L=ASC(E$)-32
315 REM ZERO PIXELS IN NEXT COLOUR?
320 IF L=0 THEN 450
325 REM END OF CHARACTER STREAM?
330 IF L<0 THEN 500
335 REM ADVANCE DISTANCE ALONG LINE
340 D=X+L
345 REM PAST EDGE OF SCREEN?
350 IF D<=256 THEN 400
355 REM PLOT TO EDGE OF SCREEN
360 Z=L-(D-256)
370 LPRINT"C ";ABS(C);"H ";X;Y;Z
375 REM MOVE TO NEXT LINE
380 Y=Y+1:X=0:L=D-256:D=L
385 REM PAST BOTTOM OF SCREEN?
390 IF Y>=192 THEN 500
395 PLOT LINE
400 LPRINT"C ";ABS(C);"H ";X;Y;L
405 REM NOT AT END OF LINE?
410 IF D<256 THEN 430
420 D=0:Y=Y+1
430 X=D
435 PAST BOTTOM OF SCREEN?
440 IF Y>=192 THEN 500
445 REM CHANGE COLOUR
450 C=NOT C
455 REM PREPARE TO GET NEXT CHARACTER
460 P=P+1:IF P<=128 THEN 300
470 P=1
480 GET 1:GOTO 100
500 CLOSE:END

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting