Category Archives: Retro Computing

ASCII Kong text data

Just posting this so I can share the link… This was a planning file from my “ASCII Kong” program I am toying with:

  ----------------------------
12345678901234567890123456789012
H H BONUS
H H 3900
H HXXXXXXX
OO H H H
OO.....H H H
XXXXXXXXXXXXXXXXXXXXXXXXXX
H
XXXXXXXXXXXXXXXXXXXXXXXXXX
H H
XXXXXXXXXXXXXXXXXXXXXXXXXX
H H H
XXXXXXXXXXXXXXXXXXXXXXXXXX
H H
XXXXXXXXXXXXXXXXXXXXXXXXXX
U H
XXXXXXXXXXXXXXXXXXXXXXXXXXXX
12345678901234567890123456789012
----------------------------
-----
@
<=>
/ \
-----
@
/=
|\
-----
@
=\
/|
-----

.----------|----------|----------
1....XX.... .XX.......
2....XX.... .XX.......
3..XXXXXX.. ..XXX.....
4.X..XX..X. .X.XXX....
5...X..X... X..X.XX...
6..X....X.. ..XX..XX..

We wanted to licensed PONG in 1993

A few years ago, I wrote a short series about my experiences growing up during the video game revolution that started in the 1970s. I hope to finally publish this series later this year, once I have time to find related video clips and photos.

But before I get to this, I thought I’d set the mood with a bit of video game-related trivia about Sub-Etha Software…

As you may know, Sub-Etha Software was not a gaming company. We mostly did application and utility software. However, we did release a graphical adventure game and a Space Invaders-style game, and did resell some games written by others.

In May 1993, at the 2nd annual “Last” Chicago CoCoFEST!, Sub-Etha Software announced something rather silly: a PONG programming contest. (Yes, Pong — the mother of all video games, released by Atari in 1972.)

According to my Fest report of that event, awards were to be given “based on memory efficiency, speed, originality, special effects, and playability for RS-DOS, OS-9, or OSK”. The winner was to be announced in October that year at the Atlanta CoCoFest.

TODO: link to fest report somewhere

I created a small OS-9 Level 2 demo program that played Pong on a text screen, along with details about the contest.

The winner was GNOP byChris Hawks of HawkSoft. This MM/1 (OS-9/68000) program kept the ball frozen in the center of the screen, while the entire box play area scrolled around it, with the paddles having to be controlled as the whole playfield moved. This was a very original take on Pong. HawkSoft made this program available for $5.

This, alone, makes for a cute story, but there’s another tidbit I do not know if I ever shared.

In 1993, Atari Corporation was still around. Their last home computer, the Atari ST, was being discontinued while the company turned its attention to a new video game system: the Atari Jaguar. The Jaguar would debut in November that year as the first home gaming system to use 64-bit chips (back in the day when the cutting edge gaming systems were all claiming 32-bit). Although the Jaguar never really caught on, it had some phenomenal games and was, at least initially, manufactured in the USA by IBM.

But I digress.

The point is, Atari was kind of between successes at the time (and actually would cease to exist just three years later when it was “reverse merged” with a hard drive manufacturer). For some reason, I thought it might be fun to contact Atari and see if I could get permission to legally use the name “Pong” for an official Color Computer version.

That’s right. I was actually trying to license Pong for the CoCo!

I contacted Atari about this (I don’t remember how, but I expect it was via a telephone call) and I recall whoever I spoke to was open to discussing a proposal, but I never pursued it further. Admittedly, I was really just wanting permission to use the name, as Sub-Etha would not have had any resources to pay any significant licensing fee. (Actually, it’s possible I may have contacted an Atari rep via the GEnie online service since they had an active presence there back then.)

I regret not following up on this silly idea. If I had been able to work something out, the CoCo could have been forever listed on the Wikipedia page as one of the only (if not the only) “official” Pong games that ever existed not done by Atari (or whoever owns them today).

Interestingly enough, Pong did make a comeback in 2012 when Atari released a 40th anniversary “Pong World” game for iOS. This version actually started out as an entry in a Pong Indie Developers Challenge where $100,000 was up for grabs to the best new versions of Pong.

Perhaps if Sub-Etha Software had offered that kind of prize (rather than the $1 we offered the winner), we would have had more entries back in 1993.

So there you have it… Another bit of “almost was” history from Sub-Etha Software. Apparently, we had a good idea, but had it 19 years too soon and without enough money to get people interested ;-)

Somehow, though, I don’t expect even the MM/1 could have pulled off any entries as fancy as some of the finalists did in 2012.

Addendum

1993 wasn’t my last encounter with Pong… While working for RadiSys, the company that bought Microware (creator of OS-9), we were working with a CPU virtualization company on a product that would allow the real-time OS-9 to run concurrently with Linux on a multi-core CPU. The idea would be the OS-9 side could be used for intense real-time operations, while Linux could be used for application level user interfaces and such.

A Pong demo was created, that showed OS-9 running one paddle and Linux running the other. (I do not recall having anything to do with this demo, but I found it amusing enough that I posted a video of it to YouTube back in 2006.)

I don’t know if this product ever came out or was ever used, but maybe the new owners of Microware OS-9 still have some Pong code kicking around their offices somewhere… ;-)

Until next time…

Vaughn Cato’s 3-D vector maze demo source code!

A special thanks to Vaughn Cato for allowing me to share the source code to his “toast” 3-D vector maze test program, as well as his “mapgraph” bitmap scaling test program.

I have placed all of the files on my GitHub site, including the two compiled executables (“toast” and “mapgraph”) as well as the source code he sent me and his last readme. The “toast.ar” file should be the file he sent me back in 1994 that includes all of these files.

You can find them here:

https://github.com/allenhuffman/Toast

Thanks, Vaughn!

And if you are curious to what Vaughn has been up to since 1994, he apparently continues to work with computers to make things appear on screen … Check out his Internet Movie Database entry:

https://www.imdb.com/name/nm1401781

…and be sure to look for his name when watching movies like Avatar and Lord of the Rings and such ;-)

Until next time…

Vaughn Cato’s bitmap scaling demo.

In a follow-up to my recent post about Vaughn Cato’s 3-D vector maze test for the Radio Shack Color Computer 3, there was another bit of code he sent me: a bitmap scaling test. He created a routine that would take a bitmap graphic then render it on the screen at a different width and/or height. I forget why I was interested in this topic back then, but I do know I have blogged about “scaling” on the CoCo in recent years on this site.

Here is a video of his mapgraph test program running:

The routine appears to use 6809 assembly language and C code. The idea would be you could have a bitmap image then place it on the screen at different sizes. This demo just loops “stretching” a test pattern image, but the graphic could have been anything.

One more post to come…

The last time I saw Steve Bjork…

On this date (4/10) in 2023, Steve Bjork passed away. I still haven’t quite come to grips with him being gone. The last time I saw him was during a visit to California in 2018. He and his wife joined us for the day at Knott’s Berry Farm. I regret not visiting again when I was in California in 2022 — but I guess I am not the only one that lost touch with folks during the Covid era.

Steve was not real fond of being in photos, which may be why I cannot find any of him from that visit … but he is in this one ;-)

Regrets are easy to accomplish.

I miss my friend. Now that there has been some time since I learned of his passing, I will try to share some stories of my Adventures with Steve.

Until then…

CLS 100 CoCo 3 easter egg explored.

The most famous CoCo easter egg has to be the hidden photo of the CoCo 3 programmers that shows up if you hold down CTRL-ALT while turning the machine on. (Alternatively, you can hold down CTRL-ALT and hit the reset button on the back of the machine to also display it.)

But, there’s another, which I’d bet came first, since it followed in the footsteps of a pre-existing easter egg that was in the original 1980 Color BASIC 1.0 ROM.

CLS 100

The CLS command is used to clear the screen. On the 32-column text screen, specifying a number from 0-8 will fill the screen with color blocks. That functionality was extended on the CoCo 3’s 40 and 80 column text screens, except there it could clear the screen to a true background color.

For the original CoCos, Microware included an easter egg in the CLS command. If you used a number greater than 8, instead of filling the screen with colored blocks it would display the word “MICROSOFT”.

CLS 9 through 255 present a Microsoft easter egg.

When Microware (not Microsoft) did the BASIC enhancements for the CoCo 3, they included a similar easter egg for the 40 and 80 column screens. If you did a CLS number outside of the range of 0-8, it would display “Microware Systems Corp.”

BUT, they added one special easter egg that you can only see once, then it disables itself (until the next power cycle or cold start). By typing CLS 100 you get to see the names of two of the programmers that worked on the project;

From that point on, if you type CLS 100 again you will only see the “Microware Systems Corp.” message.

In addition to making this easter egg a “one shot”, the programmers also took steps to hide their names so they would not be easily found by looking at the ROM code.

From Super Extended BASIC Unravelled, this note can be found in the memory map:

On startup, the ROMs are copied in to RAM, and these zero bytes will be in RAM at that range.

Then, during the CoCo 3 initialization code, there is a routine that copies the author names to that location. BUT, the data it copies is not the authors’ names — it’s an encoded version of the authors’ names:

Each of those bytes has its bits flipped. If the value in binary was 11110000, it would be encoded as 00001111. That effectively hides what those bytes represent from anyone just PEEKing around memory looking for text. There is a routine in the ROM that will start copying those bytes in to the other location, inverting the bits as it does so. It looks like this:

Here is the CLS code, which has special check for the value of 100 that will branch to a different routine:

The routine that is called when 100 is specified will display the easter egg and then wipe out the “Branch If Equal” instruction that calls it by replacing it with the NOP (no operation) instruction. Below is the code that does displays the egg and then disables it:

LF730 gets a pointer to the decoded author name message and displays it, then it starts in memory at F6F4 and stores a NOP byte there, and after it. That changes the two bytes the start out being “BEQ LF730” to “NOP NOP” effectively making the “CMP #100” useless since there is no longer an operation after it to make use of the results of that compare.

After those two bytes are changed to NOP, there is a loop that starts at memory location where AUTHORMS (F71B) is located and starts putting NOP bytes there until it gets to F74D. That destroys the evidence :) by wiping out everything in this table…

and everything after it (the code) up to the LF74D label:

Thus, after CLS 100, the code that would have jumped to the routine is gone, the routine it would have jumped to is gone, and the data that the now gone routine would have displayed is also gone.

Nice.

Here is a short BASIC program that will dump the hex values of the name bytes on up through the code that displays them, then prints the name bytes out as text.

0 ' COCO3NAMES.BAS
10 WIDTH 40
20 FOR L=&HF71B TO &HF74C
30 PRINT HEX$(PEEK(L));" ";
40 NEXT
50 PRINT
60 FOR L=&HF71B TO &HF72F
70 PRINT CHR$(PEEK(L));
80 NEXT

If you boot a CoCo 3 and run this program, you will see it contains the bytes for the name text and the 6809 code:

Then if you type CLS 100 and run the program again you will see that those bytes are now all the NOP byte (&H12). Since this is not a printable character, nothing is printed after the hex values:

And that is more than we probably ever wanted to know about how the CLS 100 CoCo 3 Easter Egg works.

So let’s do a bit more…

Restoring (and customizing) the egg

Just for fun, I wrote this short BASIC program that does three things:

  1. Restore the easter egg text to the memory from &HF71B-&HF72F.
  2. Restore the display routine at &HF730 that prints the easter egg text and then deletes the easter egg text and the routine.
  3. Restore the “branch if equal” that is supposed to happen after comparing the value of CLS to be 100.

And, as an added bonus, there is a line that will insert a “return from subroutine” RTS instruction in the display routine so it will not run the code that wipes out the easter egg text and display routine.

If you have already done a CLS 100, this code would restore the easter egg and let you run it again:

10 ' COCO3EGG.BAS
20 WIDTH 40
30 ' RESTORE EGG TEXT
40 EG$="T.Harris & T.Earles"
50 ' ROOM FOR UP TO 19 CHARS
60 LN=LEN(EG$)
70 IF LN>19 THEN LN=19
80 ' STORE THE EGG TEXT
90 FOR I=0 TO LN-1
100 POKE &HF71B+I,ASC(MID$(EG$,I+1))
110 NEXT
120 ' ADD CR and 0 BYTES
130 POKE &HF71B+I,13
140 POKE &HF71B+I+1,0
150 ' RESTORE DISPLAY ROUTINE
160 FOR L=&HF730 TO &HF756
170 READ V$:POKE L,VAL("&H"+V$)
180 NEXT
190 ' RESTORE CMP #100 "BEQ"
200 POKE &HF6F4,&H27:POKE &HF6F5,&H3A
210 ' DISABLE EGG KILL (RTS)
220 'POKE &HF73D,57
230 END
240 ' DISPLAY ROUTINE DATA
250 DATA 8D,40
260 DATA 17,FF,57
270 DATA 8D,41
280 DATA 8E,F7,1A
290 DATA BD,B9,9C
300 DATA 34,10
310 DATA 30,8D,FF,B1
320 DATA 86,12
330 DATA A7,80
340 DATA A7,84
350 DATA 30,8D,FF,CE
360 DATA A7,80
370 DATA 8C,F7,4D
380 DATA 25,F9
390 DATA 35,10
400 DATA 39

The DATA statements are organized like that to match the bytes shown in the Unravelled book’s listing of this routine. This helped me find and fix typos.

Line 220 is commented out, but that would place an RTS after the “JSR STRINOUT” in the LF730 display routine, causing it to return rather than do all the code that replaces stuff with the NOP bytes.

And, as an added bonus on top of the added bonus, you can change the easter egg string in line 40 to be anything you want, provided it is 19 characters or less. (Anything longer will just be cropped to the first 19 characters.) I changed mine to read “Sub-Etha Software” and had that message as my CLS 100 easter egg.

Until next time…

EXEC versus USR: Who called me?

NOTE: I originally started writing this in November 2025, but kept thinking I’d do more work on it. I haven’t gotten around to it, so here you go…


Here is a Color BASIC 6809 assembly quickie… (That ended up not being very quick by the time I finished working through all of this…)

Recently I began working on an assembly language Color BASIC extension that makes certain characters move the cursor around the screen rather than just printing those characters (similar to what my VIC-20 could do). Initially, I created the 6809 assembly routine you could load into memory and EXEC. Next I decided to let it be called from DEF USR so I could pass in parameters and return a status code like A=USR0(-1). Next next I decided I wanted it to still work with EXEC so the user could use it either way–just use defaults with EXEC, or customize things using USR.

Then I ran into a snag…

USRx(n) or EXEC?

If the USR routine ONLY expected a number parameter, the code to handle both USR and EXEC seems easy. When calling a routine with EXEC, the D register will be zero (it seems). If it wasn’t zero, I could then do the JSR INTCNV call which would process the parameter in BASIC and put it in the D register.

My startup code looked something like this:

; lwasm execdreg.asm -fbasic -oexecdreg.bas --map
; decb copy -2 execdreg.bin drive0.dsk,EXECDREG.BIN

; Show if routine is being called with USRx(n) or EXEC

ORGADDR equ $3e00 ; Where program loads in memory.

; Absolute addresses of ROM calls.
CHROUT equ $A002
INTCNV equ $B3ED
GIVABF equ $B4F4

org ORGADDR

; This code expects to have been called by USRx(x) or EXEC xxxx.
start cmpd #0 ; called from EXEC?
beq fromexec ; if yes, goto fromexec
fromusr jsr INTCNV ; else, get USR number parameter in D
pshs d ; save D
leax usrmsg,pcr ; display "called from USR" message
bsr print
puls d ; restore D
addd #1 ; add one to D
jmp GIVABF ; return back to USR call.

fromexec leax execmsg,pcr ; display "called from EXEC" message
bsr print
rts

; PRINT subroutine. Prints the 0-terminated string pointed to by X plus CR.
print lda ,x+
beq printdone
jsr [CHROUT]
bra print
printdone lda #13
jsr [CHROUT]
rts

usrmsg fcc "CALLED FROM USR"
fcb 0

execmsg fcc "CALLED FROM EXEC"
fcb 0

end

When the routine starts, it checks to see what D is set to. If 0, it assumes it was called from EXEC and jumps to code that just prints “FROM EXEC” then ends.

If not 0, it assumes it was called from USR and the code calls the ROM INTCVT routine to parse the parameter and place it in D, then it prints “FROM USR”, increments D (just so we can verify it passed something back), and returns it back to BASIC.

Here it is in operation:

And all was right in the world… Until I tried just using EXEC by itself. After using it first with the address (“EXEC &H3E00”) BASIC will remembers that address so when you just type “EXEC” next it uses the previous address:

EXEC &H3E00
FROM EXEC

EXEC
?TM ERROR

Making the user always have to provide the EXEC address each time is not optimal. My solution was clearly not a solution.

But wait! There’s more…

I also learned about Sean Conner documenting how USR can also take a string parameter instead of just a number. If you are interested in USR, be sure to check out that link. He also has a cool 6809 compiler (“a09”) I just started playing with. It has some unique features not available in other compilers I have tried.

USRx(n) or USRx(“STRING”)

With this new knowledge, I had an idea to make my USR routine also be able to take a string for a special configuration function. I could let the user specify the four characters that will move the cursor by doing something like A=USR0(“udlr”). But, if you pass in a string and it calls INTCNV, that routine will check the parameter type and, if not a number, return with a ?TM ERROR (type mismatch).

This required me to learn how to tell whether USR was being called with a number or a string.

Under Extended Color BASIC (the original Color BASIC did things differently, see Sean’s page for details), the ROM code sets up some registers when calling the USR function. Sean documented these in his excellent blog post on USR. Basically, register A would be 0 if the USR parameter was a number, or 255 if it was a string. If it was a string, register X would have the address of the string descriptor (the location in memory that VARPTR returns) and register B would be the length of the string.

That is really convenient. Now you can have code that detects if it is being called from USR with a number or a string. My test code looked like this:

; lwasm execdreg2.asm -fbasic -oexecdreg2.bas --map
; decb copy -2 execdreg2.bin drive0.dsk,EXECDRG2.BIN

; Show if USR is being called with a number or a string.

ORGADDR equ $3e00 ; Where program loads in memory.

; Absolute addresses of ROM calls.
CHROUT equ $A002
INTCNV equ $B3ED
GIVABF equ $B4F4

org ORGADDR

; This code expects to have been called by USRx(x) or USRx("STRING")
start tsta ; A=0 is USR(0), A=255 is USR("...")
bne usrstring ; if not 0, goto usrstring
usrnumber pshs d,x ; save D and X
leax numbermsg,pcr ; display "number" message
bsr print
puls d,x ; restore D and X
jsr INTCNV ; else, get USR number parameter in D
addd #1 ; add one to D
jmp GIVABF ; return back to USR call.

usrstring leax stringmsg,pcr ; display "string" message
bsr print
ldd #123 ; load D with return value
jmp GIVABF ; return back to USR call.

; PRINT subroutine. Prints the 0-terminated string pointed to by X plus CR.
print lda ,x+
beq printdone
jsr [CHROUT]
bra print
printdone lda #13
jsr [CHROUT]
rts

stringmsg fcc "STRING"
fcb 0

numbermsg fcc "NUMBER"
fcb 0

end

And here it is in operation:

Now I know how to detect a USRx(number) versus EXEC, and how to detect a USRx(number) versus a USRx(string). But, this has the same problem if called by EXEC with no address:

EXEC &3E00
NUMBER

EXEC
NUMBER
?TM ERROR

It appears that using EXEC with the address after it sets registers up differently than using EXEC with no address (where it uses the last address EXEC used). While both end up at the code path for USRx(number), is seems that plain EXEC thinks it is returning an invalid type and the ?TM ERROR is displayed.

EXEC or EXEC xxxx or USRx(n) or USRx(“STRING”)

Can both routines be combined? On the CoCo mailing list, this all started when I asked: Is there a way to tell if a routine was called from USR versus EXEC? It was Sean’s reply that got me going down this rabbit hole:

Maybe.

Address $9D contains the address EXEC uses to jump to your code, so that
should be called address.  Also, X will also be this address (implementation
detail).

For Color BASIC, you need to know you are running under Color BASIC. 
Address $112 is the address for USR, so this should point to your code. 
Also, upon calling, X should be equal to $AA2F and B should be 6 (both are
implementation details).

For Extended Color BASIC, you need to know you are running under Extended
Color BASIC (16 bits at $8000 are $4558).  Addresses $013E through $0150
contain the USRn addresses, so one of these 10 addresses should point to
your code.  Also, A will equal the contents of address $06.  If A=0, then
X=$4F; if A=255, then X is pointing elsewhere (the string descriptor).

For Disk Extended Color BASIC, you need to know you are running under Disk
Extended BASIC (16 bits at $C000 are $444B).  The USRn addresses are now
$095F through $0971, but other than that, it’s the same as Extended Color
BASIC.

Based on all that, I think the best method might be (completely untested):

mycode cmpx #mycode
beq called_by_exec
; otherwise, assume called by USR/USRn

Good luck.

-spc

– Sean Conner via the CoCo Mailing List

This gave me a lot of think about. I did some tests to see what register X looked like when being called by EXEC with or without an address, as well as looking at what was stored in the $9D memory location which is the address EXEC (with no address after it) will use. I created a simple program that would print the value of the X register and the value of $9D so I could test it and see what the pattern was. This code uses an undocumented ROM call that will print the value of the D register. (I learned about this call from Sean’s pages.)

; lwasm showstuff.asm -fbasic -oshowstuff.bas --map
; decb copy -2 showstuff.bin drive0.dsk,SHOWSTUF.BIN

ORGADDR equ $3e00 ; Where program loads in memory.

; Absolute addresses of items in RAM variables.
EXECJP equ $9d location of jump address for EXEC

; Absolute addresses of ROM calls.
REGDOUT EQU $BDCC ; Convert the value in ACCD into a decimal
; number and send it to CONSOLE OUT.

org ORGADDR

start tfr x,d ; X=D
jsr REGDOUT
lda #32 ; space
jsr [CHROUT]
ldd EXECJP ; load D with EXEC address
jsr REGDOUT
rts

end

Now I could load this into memory, set up a DEFUSR0=&H3E00 and do some tests:

15872 ($3E00) is the start of my user program. EXEC with that address will have both X and the $9D memory location containing that value.

EXEC without an address will have 43947 ($ABAB) in X, and 15872 ($3E00) as the address of the last EXEC address specified. But what is $ABAB? Looking at the Color BASIC Unravelled book, that address is where the EXEC token is:

ABAB     FDB EXEC

I did not dive into this, but I expect X was is used for the token scanning and since that was the last thing it found (no address after it to parse) that is what was in the register when it jumps to the user code.

When I tested A=USR0(0), I got a 79 in register X, and $9D still had the last EXEC address used. It then errored out with a ?TM ERROR due to this code not setting up a clean return back to a USR call.

And lastly, A=USR0(“STRING”) put 425 in register X, and $9D was still the last EXEC address used.

Now, had I done the USR calls first, that $9D would not be set up yet and it would look like this:

46154 ($B44A) appears to be the default value EXEC will use. By default, EXEC points to the routine that prints ?FC ERROR:

B44A     FDB LB44A   ARGUMENT OF EXEC COMMAND - SET TO ‘FC’ ERROR

So on a power cycle, typing EXEC is the same as typing EXEC &HB44A:

EXEC &HB44A
?FC ERROR

Having this value there is not useful for any of my checks since all that means is that the user has not done an EXEC with an address yet.

BUT, now that I see what happens with register X, I should be able to check it, and the $9D exec location and determine if I am being called by EXEC, EXEC xxxx, or a USRx command. Here is my test program:

; lwasm whocalled.asm -fbasic -owhocalled.bas --map
; decb copy -2 whocalled.bin drive0.dsk,WHOCALLD.BIN

ORGADDR equ $3e00 ; Where program loads in memory.

; Absolute addresses of items in RAM variables.
EXECJP equ $9d location of jump address for EXEC

; Absolute addresses of ROM calls.
CHROUT equ $A002

org ORGADDR

; This code expects to have been called by USRx(x).
start cmpx #start ; called by "EXEC xxxx"?
beq fromexec ; if yes, goto fromexec
cmpx #$abab ; called by "EXEC"?
bne fromusr ; if no, must be USR. goto fromusr
ldx EXECJP ; get EXEC address
cmpx #start ; called by "EXEC xxxx"?
beq fromexec ; if yes, goto from exec
fromusr leax usrmsg,pcr
lbsr print
rts
fromexec leax execmsg,pcr
lbsr print
rts

; PRINT subroutine. Prints the 0-terminated string pointed to by X plus CR.
print lda ,x+
beq printdone
jsr [CHROUT]
bra print
printdone lda #13
jsr [CHROUT]
rts

usrmsg fcc "FROM USR"
fcb 0

execmsg fcc "FROM EXEC"
fcb 0

end

And here is what it does:

I now have code that can properly (?) detect if it was called from EXEC xxxx, EXEC, or USR. This demo does not handle detecting a string parameter to USR, but … I think it proves it is possible to do it.

With a few more lines of assembly, I came up with this test program:

; lwasm whocalled2.asm -fbasic -owhocalled2.bas --map
; decb copy -2 whocalled2.bin drive0.dsk,WHOCALL2.BIN

ORGADDR equ $3e00 ; Where program loads in memory.

; Absolute addresses of items in RAM variables.
EXECJP equ $9d location of jump address for EXEC

; Absolute addresses of ROM calls.
CHROUT equ $A002
INTCNV equ $B3ED
GIVABF equ $B4F4

org ORGADDR

; This code can be called by USRx(n), USRx("STRING"), EXEC addr or EXEC.
start cmpx #start ; called by "EXEC xxxx"?
beq fromexec ; if yes, goto fromexec
cmpx #$abab ; called by "EXEC"?
bne fromusr ; if no, must be USR. goto fromusr
ldx EXECJP ; get EXEC address
cmpx #start ; called by "EXEC"?
beq fromexec ; if yes, goto from exec
fromusr tsta ; A=0?
beq donumber ; if yes, number passed in. goto donumber.
inca ; inc A so if 255 (string) it will be 0 now.
beq dostring ; if A=0 (was 255), string. goto dostring.
bra unknown ; else, goto unknown (this should never happen).

donumber leax numbermsg,pcr ; show "number" message
bsr print
jsr INTCNV ; get number that was passed in
addd #1 ; add 1 to D
jmp GIVABF ; return new number back to BASIC

dostring leax stringmsg,pcr ; show "string" message
bsr print
ldd #12345 ; load D with a return value
jmp GIVABF ; return that number back to BASIC

fromexec leax execmsg,pcr ; show "from exec" message
lbsr print
rts

unknown leax unknownmsg,pcr ; this should never happen
lbsr print ; show "unknown" message
rts

; PRINT subroutine. Prints the 0-terminated string pointed to by X plus CR.
print lda ,x+
beq printdone
jsr [CHROUT]
bra print
printdone lda #13
jsr [CHROUT]
rts

execmsg fcc "FROM EXEC"
fcb 0

numbermsg fcc "FROM USR(NUMBER)"
fcb 0

stringmsg fcc "FROM USR(STRING)"
fcb 0

unknownmsg fcc "UNKNOWN"
fcb 0

end

And here is what I get after loading this into memory:

DEF USR0=&H3E00
OK

A=USR0(42)
FROM USR(NUMBER)
PRINT A
43

A=USR0("STRING")
FROM USR(STRING)
PRINT A
12345

EXEC &H3E00
FROM EXEC

EXEC
FROM EXEC

I think we may have a winner! The important parts are:

start       cmpx    #start      ; called by "EXEC xxxx"?
beq fromexec ; if yes, goto fromexec
cmpx #$abab ; called by "EXEC"?
bne fromusr ; if no, must be USR. goto fromusr
ldx EXECJP ; get EXEC address
cmpx #start ; called by "EXEC"?
beq fromexec ; if yes, goto from exec
  • If X is the address of the user program, it was called by “EXEC xxx”
  • If not, then if X is NOT $ABAB, it was called by USR
  • Else, it was $ABAB, so the EXECJP ($9D) is checked to see if it is the address of the user program. If it is, it is from EXEC.

I hope that makes sense. If not, think of it like this:

  • X=program start – it was called from EXEC xxxx
  • X=$ABAB and EXECJP=program start – it was called by EXEC.
  • Anything else is USR.

Now what I need from you is to double check my work and tell me if I got this right, and if this method can be relied on.

Comments if ya got ’em!

Until next time…

Color BASIC, Juan Castro and “forbidden” variables

Over the years I have shared many tidbits about Color BASIC.

This is another one.

A recent post by Juan Castro to the Groups.IO Color Computer mailing list caught my attention, mostly because he called me out by name in the subject line:

https://groups.io/g/ColorComputer/message/312

Color BASIC variable name limits

As a reminder, Color BASIC allows 1 or 2 character variable names. They must start with a letter (A-Z) and the second character can be either letter (A-Z) or number (A-0). BUT, the BASIC interpreter does let you type longer names for variables, but it only honors the first two characters. Here is a screenshot from a past blog post here (which I’d link to if I was not so lazy):

Color BASIC variables may be very long, but only the first two characters are used.

This is a reminder that, if you try to use variables longer than two characters, you have to make sure you always keep the first two characters unique since “LONGVARIABLE” and “LOST” and “LO” are all the same variable to BASIC.

…but not all variable name limits are the same.

To break the rule I just said, in Color BASIC, some variable names are forbidden. A forbidden variable is one you cannot use because it is already reserved for a keyword or token. For example, FOR is a keyword:roar

FOR I=1 TO 10
PRINT I
NEXT I

Because of this, even though BASIC only honors the first two characters of a variable name, you still cannot use “FOR” as a variable.

FOR=42
?SN ERROR

But you can use “FO”, since that is not long enough to be recognized as a BASIC token or keyword.

FO=42
PRINT FO
42

There are a number of two-character tokens, such as “TO” in the FOR/NEXT statement (“FOR I=1 TO 10”), and “AS” in the Disk BASIC FIELD statement (“FIELD #1,5 AS A$”), as well as “FN” which is used in DEF FN.

AS=42
?SN ERROR

FN=42
?SN ERROR

TO=42
?SN ERROR

This means if you wrote something for Color BASIC or Extended Color BASIC that uses “AS” as a variable, that would not work under Disk Extended Color BASIC.

BASIC ignores spaces

In recent years, someone pointed me to the fact that when scanning a BASIC line (either type in directly or when parsing a line of code in a program), spaces get ignored by the scanner. This means:

N M = 42
PRINT N M
42

That one surprised me when I learned it. This is probably why, when printing two variables, a semicolon is required between them:

N = 10
M = 20
PRINT N;M
10 20

And if you had done this (remember to CLEAR between these tests so variables are erased each time):

N = 10
M = 20
NM = 30
PRINT N M
30
PRINT N;M;N M
10 20 30

By the way, if you have ever wondered about that space printed in front of numeric variables when you do things like “PRINT X”, I covered why this happens in an earlier blog and included a simple patch to BASIC that removes that feature.

How to turn a forbidden variable into a non-forbidden one for fun and profit

Well, Juan Casto showed that using this “BASIC ignores spaces” quirk as a way to use forbidden variables. From his post:

Now it seems obvious. BASIC’s interpreter looks for keywords like “FOR” and will not recognize “F O R” or “FO R” as that token. The detokenizer honors the spaces.

But when it comes to variables, the spaces are ignored by the parser, so “T O” will not match as a token for “TO”, but will be processed as a variable “TO”.

Go figure.

Admittedly, space in two-character variable names look silly, but now I can finally update my old *ALLRAM* BBS to use the variable “TO$” for who a message is to:

FR$="ALLEN HUFFMAN"
T O$="JUAN CASTRO"
SB$="THAT'S REALLY COOL"

Though why would you want to do that… (Please click on that link. That’s a web domain I own… ;)

Not invented here

I suspect this was discovered by the early pioneers of BASIC, likely soon after the original Color Computer was released in 1980. If you know of a reference to this behavior from some early newsletter or magazine article, please let me know.

And as to Juan … thanks for sending me down a BASIC rabbit hole again…

Until next time…

Interfacing assembly with BASIC via DEFUSR, part 8

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

Just when I thought I was out, they pull me back in.

In part 3 I showed a simple assembly language routine that would uppercase a string.

In part 5, this routine was made more better by contributions from commenters.

Today, I revisit this code and update it to use “what I now know” (thank you, Sean Conner) about being able to pass strings into a USR function without using VARPTR.

First, here is the code from part 5:

* UCASE.ASM v1.01
* by Allen C. Huffman of Sub-Etha Software
* www.subethasoftware.com / alsplace@pobox.com
*
* 1.01 a bit smaller per Simon Jonassen
*
* DEFUSRx() uppercase output function
*
* INPUT: VARPTR of a string
* RETURNS: # chars processed
*
* EXAMPLE:
* CLEAR 200,&H3F00
* DEFUSR0=&H3F00
* A$="Print this in uppercase."
* PRINT A$
* A=USR0(VARPTR(A$))
*
ORGADDR EQU $3f00

GIVABF EQU $B4F4 * 46324
INTCNV EQU $B3ED * 46061
CHROUT EQU $A002

opt 6809 * 6809 instructions only
opt cd * cycle counting

org ORGADDR

start jsr INTCNV * get passed in value in D
tfr d,x * move value (varptr) to X
ldy 2,x * load string addr to Y
beq null * exit if strlen is 0
ldb ,x * load string len to B
ldx #0 * clear X (count of chars conv)

loop lda ,y+ * get next char, inc Y
; lda ,y * load char in A
cmpa #'a * compare to lowercase A
blt nextch * if less, no conv needed
cmpa #'z * compare to lowercase Z
bgt nextch * if greater, no conv needed
lcase suba #32 * subtract 32 to make uppercase
leax 1,x * inc count of chars converted
nextch jsr [CHROUT] * call ROM output character routine
; leay 1,y * increment Y pointer
cont decb * decrement counter
bne loop * not done yet
; beq exit * if 0, go to exit
; bra loop * go to loop

exit tfr x,d * move chars conv count to D
jmp GIVABF * return to caller

null ldd #-1 * load -2 as error
return jmp GIVABF * return to caller

* lwasm --decb -o ucase2.bin ucase2.asm -l
* lwasm --decb -f basic -o ucase2.bas ucase2.asm -l
* lwasm --decb -f ihex -o ucase2.hex ucase2.asm -l
* decb copy -2 -r ucase2.bin ../Xroar/dsk/DRIVE0.DSK,UCASE2.BIN

In the header comment you can see an example of the usage, and that it involved using VARPTR on a string to get the string’s descriptor location in memory, then pass that address into the USR function.

See also: Color BASIC and VARPTR

Now that I know we can just pass a string in directly, I thought it would be fun (?) to update this old code to use that method. Here is what I came up with. Note that I changed the “*” comments to “;” since the a09 assembly does not support those. If you wanted to run this in EDTASM, you would have to change those back.

; UCASE3.ASM v1.02
; by Allen C. Huffman of Sub-Etha Software
; www.subethasoftware.com / alsplace@pobox.com
;
; 1.01 a bit smaller per Simon Jonassen
; 1.02 converted to allow passing a string in to USR
;
; DEFUSRx() uppercase output function
;
; INPUT: string
; RETURNS: # chars converted or -1 if error
;
; EXAMPLE:
; CLEAR 200,&H3F00
; DEFUSR0=&H3F00
; A$="Print this in uppercase."
; PRINT A$
; A=USR0(A$)
; PRINT "CHARS CONVERTED:";A
; A=USR0("This is another test");
; PRINT "CHARS CONVERTED:";A
;
ORGADDR EQU $3f00

CHROUT EQU $A002
CHKSTR EQU $B146 ; Undocumented ROM call
INTCNV EQU $B3ED ; 46061
GIVABF EQU $B4F4 ; 46324

org ORGADDR

start jsr CHKSTR ; ?TM ERROR if not a string.
; X will be VARPTR, B will be string length
tstb
beq reterror ; exit if strlen is 0
ldy 2,x ; load string addr to Y
ldx #0 ; clear X (count of chars conv)

loop lda ,y+ ; get next char, inc Y
cmpa #'a ; compare to lowercase A
blo nextch ; if less, no conv needed
cmpa #'z ; compare to lowercase Z
bhi nextch ; if greater, no conv needed
suba #32 ; subtract 32 to make uppercase
leax 1,x ; inc count of chars converted
nextch jsr [CHROUT] ; call ROM output character routine
decb ; decrement counter
bne loop ; not done yet

tfr x,d ; move chars conv count to D
bra return

reterror ldd #-1 ; load -1 as error
return jmp GIVABF ; return to caller

end

; lwasm --decb -o ucase3.bin ucase3.asm -l -m
; lwasm --decb -f basic -o ucase3.bas ucase3.asm -l -m
; lwasm --decb -f ihex -o ucase3.hex ucase3.asm -l -m
; decb copy -2 -r ucase3.bin ../Xroar/dsk/DRIVE0.DSK,UCASE3.BIN
; a09 -fbasic -oucase3_a09.bas ucase3.asm

Here are the changes… In the original version, I have this:

start       jsr     INTCNV  * get passed in value in D
tfr d,x * move value (varptr) to X
ldy 2,x * load string addr to Y
beq null * exit if strlen is 0
ldb ,x * load string len to B
ldx #0 * clear X (count of chars conv)

That first jsr INTCNV expects a number parameter and, if not a number, it exits with ?TM ERROR. If it gets past that, the number is in the D register and it gets transferred over to X. In this case, the number is the value returned by VARPTR:

A=USR0(VARPTR(A$))

That value is the address of the 5-byte string descriptor that contains the address of the actual string data and the length of that data. Y is loaded with 2 bytes in from wherever X points which makes Y contain the address of the string data.

After this is a bug, I think. Looking at the comments, I think that “beq null” should be one line lower, like this:

start       jsr     INTCNV  * get passed in value in D
tfr d,x * move value (varptr) to X
ldy 2,x * load string addr to Y
ldb ,x * load string len to B
beq null * exit if strlen is 0
ldx #0 * clear X (count of chars conv)

That way, Y is loaded with the address of the string data, then b is loaded with the length of that data, and the branch-if-equal check is now checking B. If the length is 0, it is an empty string so no processing can be done on it. (That’s a bug, right?)

The new code is this:

start       jsr     CHKSTR      ; ?TM ERROR if not a string.
; X will be VARPTR, B will be string length
tstb
beq reterror ; exit if strlen is 0
ldy 2,x ; load string addr to Y
ldx #0 ; clear X (count of chars conv)

The first line is something I learned from Sean Conner‘s excellent writeup on USR. That is an undocumented ROM call which checks is a variable is a string. If it isn’t, it will return back to BASIC with a ?TM ERROR. By having that check there, if the user tries to pass in a number, that error will be seen. As a bonus, if you try to EXEC that code, that, too, will show ?TM ERROR.

After that, B should be the length of the string so tstb checks that to be 0 (empty string) then the rest of the code is similar.

As I write this, I could have altered the order of my new code to do the tstb/beq after the ldy and then it would be closer to how the original worked. But since the original appears buggy, I won’t worry about that.

Now if I load this and set it up, I should see this:

DEF USR0=&H3F00

A=USR0(42)
?TM ERROR

A=USR0("This is a test")
THIS IS A TEST

Also, I notice that the value I return can be -1 if you pass in an empty string…

A=USR0("")
OK
PRINT A
-1

…and if it is non-empty, it is only the count of the characters that had to be converted. So “Hello World” converts the “ello” and “orld” for a return value of 8. It does not touch the uppercase “H” and “W” or the space.

I am not sure that is really useful. The code could be modified to return the length of the string it processed, but at least this way you know that a positive non-zero return value means it did do some work.

Spot any bugs? Comment, if you will.

Until next time…

Did you ever register CoCo software?

In a Discord discussion with Wayne Campbell, the topic of software registrations came up. Did you ever register any CoCo stuff?

Here is the one we sent out with our stuff…

            /) Sub-Etha Software Registration/Information Sheet (\

Information aquired from this questionaire will be used for product
registration, free software drawings, and informational mail outs.


Product ........... ___________________________________ Serial # ___________


Name .............. _________________________________________________________

Address ........... _________________________________________________________

City, State, Zip .. _________________________________________________________

Telephone Number .. ( ______ ) ______ - ________


Computer(s) Memory Storage Monitor
[_] CoCo 1/2 [_] 64K/Less [_] Cassette [_] Television
[_] CoCo 3 [_] 128K [_] Disk Drive [_] Clr Composite
[_] MM/1 [_] 512K [_] Hard Drive [_] RGB Color

Other(s) .......... __________________________________________________________


Expansion
[_] RS-232 Pak [_] MultiPak [_] ______________ [_] ______________


Accessories
[_] Printer ....... ___________________ [_] Modem ......... __________________
(Type) (Baud)


What do you use your computer for?
[_] Word Processing [_] Businesss [_] Games/Fun [_] Telecom
[_] Programming [_] Home Apps. [_] Music/MIDI [_] Graphics

[_] Other(s) ...... __________________________________________________________


Which Operating System/Language(s) do you use?
[_] RS-DOS [_] Basic [_] Assembly [_] 'C'
[_] OS-9/OSK/Etc. [_] Basic09 [_] OS9 Assembly [_] Pascal

[_] Other(s) ...... __________________________________________________________


What type of software would you like to see for the CoCo or OS-9?

______________________________________________________________________________

______________________________________________________________________________

______________________________________________________________________________

Sub-Etha Software -/- P.O. Box 152442 -/- Lufkin, TX 75915 -/- (815) 748-6638

The next time I go through my Sub-Etha Software archives, I am going to see if I can find any of these that folks actually sent in.