Category Archives: CoCo

Tandy/Radio Shack TRS-80 Color Computer (CoCo)

CoCo bouncing BASIC ball, part 1

See also: part 1, part 2, part 3, part 4 and part 5.

The prolific Jim Gerrie recently posted a video of an MC-10 bouncing ball demo he wrote in BASIC:

Jim Gerrie’s BASIC bouncing ball for the MC-10.

Thanks to Jim, the MC-10 joins a long list of 80’s home computers that thought bouncing a ball around the screen was a good demo.

Seeing his demo inspired me to revisit my Benchmarking BASIC series and see if we can expand on this.

I begin with the excellent (and free) Xroar Emulator. For those that want to play along, there is now a web browser version you can try without installing anything, or you can try the original JS Mocha emulator. Both should be more than enough for this experiment.

First, I load up my BENCH.BAS framework so I can do some speed tests. It looks like this:

0 REM BENCH.BAS
5 DIM TE,TM,B,A,TT
10 FORA=0TO3:TIMER=0:TM=TIMER
20 FORB=0TO1000
70 NEXT
80 TE=TIMER-TM:PRINTA,TE
90 TT=TT+TE:NEXT:PRINTTT/A:END

The above sample code will run four tests (0 to 3) and each time it will do “something” 1001 times (0 to 1000) and report the results in CoCo TIMER values (where each number represents 1/60th of a second, give or take). The benchmark code would go between lines 20 and 70.

Let’s see how big of an object we want to display. Using Jim’s video as a reference (where he shows some of the BASIC source code), it looks like 8 characters wide by 9 characters tall:

Based on him using substrings going up to 6, it looks like he may have 7 frames of animation (0-6). Impressive. But let’s just start with displaying 8×9 characters in various ways to see how fast we can do it.

The fastest way in BASIC is to use a PRINT@ statement, so my first test is to see how long it takes to print these characters 1001 times. I will hard-code the location for each line starting with 0 (the top left of the screen). It looks like this:

30 PRINT@0,"12345678";:
   PRINT@32,"12345678";:
   PRINT@64,"12345678";:
   PRINT@96,"12345678";:
   PRINT@128,"12345678";:
   PRINT@160,"12345678";:
   PRINT@192,"12345678";:
   PRINT@224,"12345678";:
   PRINT@256,"12345678";

Running that in the benchmark program results in 3986.

Using decimal values is slow, so next I changed them to hex:

30 PRINT@&H0,"12345678";:
   PRINT@&H20,"12345678";:
   PRINT@&H40,"12345678";:
   PRINT@&H60,"12345678";:
   PRINT@&H80,"12345678";:
   PRINT@&HA0,"12345678";:
   PRINT@&HC0,"12345678";:
   PRINT@&HE0,"12345678";:
   PRINT@&H100,"12345678";

Parsing a hex value is much faster, so this results in 3018. That’s about 25% faster.

And, using variables is even faster, since no parsing is required. A quick test that sets variables I-Q to each value, then does a PRINT@I through PRINT@Q produces 2940. Not a huge gain, but every little bit helps. That’s probably the fastest one can print something like this in BASIC.

The problem with using multiple variables is you have to update each one every time the object moves. If you just use one variable, and do math for all the other lines, you are doing the same math for each line that would have been done for the variable.

At this point, we need to see which way of doing math is faster. Or, perhaps, maybe we can do it without using math. . .

To be continued…

Marc Andreessen (Netscape) was a CoCo user!

Over in the Facebook Color Computer group, Jerry Stratton discovered that Marc Andreessen, co-founder of Netscape, was a CoCo user! Jerry ran across an April 1987 issue where Marc wrote in looking for CoCo pen-pals!

April 1987 Rainbow Magazine.

Here’s that issue, scanned and searchable, if you want to see who else might have been writing in:

http://www.colorcomputerarchive.com/coco/Documents/Magazines/Rainbow%2C%20The%20%28Searchable%20image%29/The%20Rainbow%20Vol.%2006%20No.%2009%20-%20April%201987.pdf

BASIC REM memory savings

Over in the CoCo Facebook group, Diego Barzio just posted a note about discovering some BASIC program line comments that had left out the REM keyword at the start. Because those lines were never the target of a GOTO, there was no error. This had the side effect of saving a byte (or two, since most do “REM ” at the start) for comment lines.

This made me think about what was going on. BASIC will allow you to type in anything, and will try to parse it (to tokenize the line) and produce an error (?SN ERROR, etc.) if there is a problem. But, when you are typing in a line, this BASIC doesn’t check anything until that line is actually ran in the program. (Other versions of BASIC will check when you hit enter. Didn’t the Apple 2 do that?)

REM

In an earlier article, I mentioned that “REM” tokenized into one byte, and the apostrophe (‘) turned into two bytes because it was “:REM(space)” allowing you do do something like this:

10 REM This is a comment.
20 'This is a comment

Since most folks type “REM(space)”, using the apostrophe without a space after it takes the same room. But if you include the space:

10 REM This is a comment
20 ' This is a comment

…that would make line 10 take one byte less (REM + space is two bytes, versus ‘ + space which is three bytes).

Now, if you do not include REM or apostrophe, you can save a byte or two for each comment. If you program has 50 lines of comments, that’s 50-100 bytes.

BASIC Keywords

However, this made me realize that leaving out the REM would cause it to try to tokenize the line, and turn any BASIC keyword into a token, saving even more memory. If your comment included words like PRINT, OR, ELSE, etc., you’d save even more room!

Leaving our REM can save memory? Thanks, Diego Barizo!

As you can see, because this comment uses the word PRINT (five characters), the version without the REM appears to save six bytes — it saves the apostrophe (two bytes, or would save “REM(space)” for two bytes) plus tokenizes the PRINT keyword down from five bytes to one (saving four more bytes).

Interesting BASIC interpreter abuse, isn’t it? As long as you never run this line, you might save memory by leaving our REM (depending on if you use any keywords). I could imaging comments saying “SHOW THE USER NAME” changed to “PRINT THE USR NAME” to tokenize two words (PRINT and USR).

You would still need REM at the start of the code for any initial comments, and during the code, but for subroutines you could do this:

10 REM THIS IS MY PROGRAM
20 A$="HELLO, WORLD!":GOSUB 1010
999 END
1000 PRINT THE MESSAGE
1010 PRINT A$:RETURN

The GOSUB jumps to 1010 and can find it, and since the program would END before reaching 1000, that would work.

With great power comes great responsibility. Use this wisely :) and thanks, Diego, for noticing this.

Until next time…

Play CoCo’s “Donkey King” in a web browser.

One of the all-time best ports of Donkey Kong on a 1980s home computer was a clone called Donkey King (later renamed to The King). Although we didn’t know this until years later, it was authored by Chris Latham, who also created the first CoCo game to require 64K – The Sailor Man (a clone of Popeye).

Last week, the gang over at CoCoTalk (the weekly video chat/interview show) started a game contest where everyone is invited to try to set a high score on some CoCo game. The first game chosen was Donkey King, which is quite fitting since it’s one of the greatest CoCo games ever. Unlike most (all?) other versions of the day, it features all four levels as well as the intermissions (see the Donkey King link above for screen shots). It also plays amazing well and is as frustratingly difficult as the arcade game it was based on.

For those interested in trying it out, you can go to the JS Mocha CoCo Emulator webpage (the Java Script version of Mocha, which was original a Java CoCo emulator). It is one of the games available there.

You will find it in the second column. Just select it then click Load Bin. It uses the right joystick, I believe, so you can select “Dual Key R” from the Joystick config and that will map that to the keyboard – Arrow Keys and Space Bar (to jump).

If you want to hear the sound effects, you have to checkbox the “Sound” option in the lower right of this screen.

Give it a try and see what you think.

Until next time…

CoCoFEST! Challenge: An AI camera project?

John Linville recently announced a CoCoFEST! Challenge on the CoCo Crew Podcast Facebook page. The idea is to start and complete a new CoCo project between February 15, 2020 and April 1, 2020 (day after Valentine’s Day through April Fools Day). The project doesn’t even have to be technical (he uses the example of designing a dust cover for a Multi-Pak).

I’ve been thinking about this since I have dozens of past experiments that could easily turn into new projects. But I also thought it might be an excuse to start “yet another” experiment specifically for this challenge.

HuskyLens and case from DFRobot.

Recently I took possession of a HuskyLens from DFRobot. It is an AI camera device that started out as a Kickstarter project last year. The tiny gadget includes a camera, touch screen, and AI software that can do things like:

  • Object Tracking – teach it what an object looks like, and it will track its position when it is in front of the camera.
  • Face Recognition – teach it a face and it will identify when it sees that face.
  • Object Recognition – identify built in objects (dog, cat, etc.) or teach it to recognize new ones.
  • Line Tracking – identify a line (useful for a line following robot).
  • Color Recognition – teach and identify specific colors.
  • Tag Recognition – identify low-resolution QR-code style tags.

I acquired a HuskyLens specifically for Halloween projects, but since it communicates to a host computer over serial, it could be interfaced to a CoCo using a cheap TTL-to-RS232 adapter like my CoCoWiFi and SirSound projects use.

HuskyLens in case, attached to mount.

Since the slowest speed the HuskyLens firmware communicates with is 9600 baud, I’d have to do this using an RS-232 Pak under NitrOS-9 (so I could easily do it in BASIC09 or C), else I’d have to resort to assembly language under RS-DOS. If I go the assembly route, I’d have to see what code I could find to handle 9600 baud via bitbanger, else the RS-232 Pak would still be required.

Bitbanger is quite out of my wellhouse, since the only bitbanger code I’ve ever worked with was a remote terminal driver published in Rainbow that I modified to add features to. The RS-232 Pak I could probably handle since my first commercial program was a MIDI Librarian for a CoCo MIDI Pak and I wrote code for a much faster baud rate (31,500).

It wouldn’t be pretty, but I think I could make it work.

The question is … what does one do with an AI camera hooked to the CoCo? Perhaps…

  • CoCo Face ID – auto-log in to NitrOS-9 by face. (Not a security feature, since a photo would also work, but still neat.)
  • Visual Game Launcher – hold up a ROM-Pak and have it launch the program off of a CoCoSDC drive image.
  • Gestures Game – use gestures (rather than a keyboard/joystick) to interact with a game.

What can you think of? Ideas are appreciated…

Microsoft Visual Studio Code (PC/Mac/Linux) for CoCo cross development.

Microsoft Visual Studio Code for Mac (left) with extension to color code BASIC code for easy loading into Xroar emulator (right).

As mentioned elsewhere, there are some CoCo-related extensions available for the Microsoft Visual Studio Code editor. I did not realize that MS released this editor for Mac and Linux as well as Windows.

Here is the free editor:

https://code.visualstudio.com

Once installed, you can download (from within the editor) extensions.

Here are two extensions by Tandy UK — one for COLOUR BASIC and the other for 6309/6809 assembly:

https://marketplace.visualstudio.com/publishers/Tandy

There is another 6809 assembly extension available:

https://marketplace.visualstudio.com/items…

It colorizes files ending in .a or .asm. 

I don’t see many details about the Tandy UK ones, but I am indeed getting colorized BASIC keywords when I have a .bas file.

Modern monitors that work with the CoCo 3!?!

In the 1980s and 1990s, there were many computers made that used a 15Khz analog RGB signal. These included the CoCo 3, Commodore Amiga, Atari ST, etc. There were a number of monitors to choose from to use on the CoCo 3, with one of the most popular being the Magnovox (remember them?) 8CM515. It supported RGB-A but also had composite audio/video so you could get the old CoCo 1/2 artifact colors when needed.

I thought the days of 15Khz was long gone. We have had a few solutions for hooking up a monitor to the CoCo 3, including an FPGA project, Cloud-9’s VGA converter, and the Switch-a-roo cable with a SCART converter box.

But Alexandre Souza on Facebook let me know they use all kinds of LCD monitors in Brazil, and pointed me to this list of modern monitors that still support 15Khz analog RGB:

http://15khz.wikidot.com/?fbclid=IwAR3S-JRwwEau0WsJsRTBXaNrgXIX92pYfdGPvt0D-CJpYPGnat2nD4A3h4k

One of the highly recommended monitors on the list is on Amazon for $139. It might take just as a cable to make it work with the CoCo, or possibly a bit of signal inversion (just like the old days).

Anyone know more on this?