COSMAC 1802 Tiny BASIC Software


Last updated June 26 2020. Edited by Herb Johnson, (c) Herb Johnson.

Introduction

This page is about Tiny BASIC, software for Lee Hart's COSMAC 1802 "Membership Card". This links to other software for that card. This link is to the home Web page for the "Membership Card" history, development, current status, and links to other documents. Thanks to Lee Hart, Chuck Yakym and Loren Christiansen for their help and support on this software and documents. - Herb

TMSI/RCA/Pittman Tiny BASIC, fixes by Loren Christiansen and others

Summary: Tom Pittman wrote Tiny BASIC in 1976, for several microprocessors including the COSMAC 1802. Lee Hart distributed a Tiny BASIC with the IDIOT ROM monitor many years ago. It was originally provided by RCA with their UT4 ROM monitor. The TMSI version became available as a digital file in 2010; the 1802 code was rewritten for the A18 cross-assembler; it was poked at by a few people since, as described on this Web page. The most recent version for the 1802 Membership Card, is described in this section. IN June 2020, Robert Coward provided a correct RCA version based on disassembly of an RCA ROM. All this stuff, plus RCA documentation, is below.

In March 2018, Loren Christensen reported fixing, assembling and loading TMSI Tiny BASIC with the IDIOT monitor above it, into RAM for testing and some improvements. Christensen added: "The main changes are; (1) making the SEEKROM block a conditional assembly, (with a monitor ROM up high, the BASIC-from-ROM feature was causing problems), and (2) changing the logic level sense of EF3 and Q to suit our El-Cheapo serial/USB interface." - Loren. After a few months of discussion with Loren, Lee Hart, Chuck Yakym and Herb Johnson, I (Herb) tested and release here the results.

Here's Loren's fixes to TMSI Tiny BASIC, ASM and LST files. SEEKROM is a routine to look through ROM to find a Tiny BASIC program "source" as part of the ROM above BASIC. Loren, with assists from myself (Herb Johnson) and Lee Hart and Chuck Yakym, developed a simplified SEEKROM to find that BASIC program. The "hooks" in TB to process that program, were already part of TB from TMSI - they used it for "embedded BASIC" 1802 controllers.

Here's a link to Tom Pittman's Tiny BASIC Web site's copy of his Tiny BASIC User Manual.

Use of TB on the 1802 Membership Card

Nov 2019: I had a report that TB failed, when the binary was loaded into an RAM only system. TB in my version, tests for available RAM and uses as much as available. However, tests by Loren confirm that TB performs correctly if loaded into a 64K RAM, 1802 MC (simulated by EMMA 02). Apparently the failure was likely due to an incorrect use of EF3 and Q; the user was given some other version of Tiny BASIC that was properly configured, all by someone else. See below for more EF3 and Q discussion.

July 2018: I've used Loren's version of Tiny BASIC on the 1802 Membership Card, Rev J CPU and Rev J front panel. The front-panel has a TTL and power "port" which mates with various USB/TTL "dongles". Here's the USB dongle I'm using, with an FTDI brand USB/serial chip.

The TBASIC assembly-language settings for EF3 and Q (serial input and output are as below, and AUTORUN is set to execute an embedded program on power-up / reset. If you need to determine the EF and Q features of your 1802 MC, consider first operating the IDIOT ROM monitor version which allows you to choose one of FOUR possible conditions for EF3 and Q. That linked Web page explains further.

 EFHI    EQU     0       ; 0=active low EF for serial, (0 = +5V MARK,  0V SPACE).
 QHI     EQU     1       ; 0=active low Q for serial,  (1 =  0V MARK, +5V SPACE).
 AUTORUN EQU     1       ;  Define a Tiny BASIC Autorun program at $0D00.

Also, check the default baud-rate in the source, especially if TB is running a program from reset. If TB starts without a program, it will auto-baud; in that case start with a CR (return, enter) character. Here's the TB code for baud rate, assuming a 2MHz clock:

*; SET DEFAULT BAUD RATE AND HALF/FULL DUPLEX. VALUES SHOWN
;    ARE FOR A 2 MHZ CLOCK. NUMBERS SHOWN FOR FULL DUPLEX:
;    ADD 1 FOR HALF DUPLEX.
                ;   75 BAUD = 0A2H
                ;  110 BAUD = 06CH
;    LDI  26H   ;  300 BAUD = 026H , ; original default.
                ;  600 BAUD = 012H
     LDI  08H   ; 1200 BAUD = 008H 

Again, these features are for the Rev J front-panel card and Rev J CPU, with 2MHz ceramic oscillator, and a FTDI TTL/USB dongle powering and serializing. The TB ROM is at 0000H, 32K RAM at 8000H. TB is also set up, to echo serial output, onto the LED's (OUT 4). I modified Loren's endless-loop demo program, to just count down from 10 to 0 and stop. Look at the TB source (and TB manual) for how to modify that startup program. Or, set AUTORUN EQU 0 and reassemble, and that program will be ignored.

How do you stop a running BASIC program? Tiny BASIC, (and BASIC3), both have a feature where while running a program, they poll the serial input EF line for activity, (looking for space on the serial input, in case the operator wants to break a program. It's not interrupt-driven, so the program has to be sending when the interpreter chooses to look. - Loren

And above all else: Read The Fine Manuals! for details. Manuals and notes with this Tiny BASIC distribution, include Lee Hart's TB manual; a list of TB keywords and features; some notes from me (Herb) on how to hop between TB and IDIOT.

Serial operation issues

There's a problem, in how TinyBASIC's ROM monitor (UT4, IDIOT, UT20) handles 7-bit serial and "parity". These old RCA programs, use "7 bits Mark parity" and so do confusing things with the 8th "parity" bit. So, I had to set the Windows Hyperterminal communications program for "8 bits no parity 1 stop" and also change "settings" under "ASCII setup" to "force incoming data to 7 bit ASCII". Careful and painful oscilloscope work, showed me that IDIOT/UT4/TinyBASIC will "produce" ASCII characters with 7 bits and "mark" parity for the 8th bit, which looks like ordinary 8-bit ASCII. But they "echo" 7 or 8-bit characters with bit 8 "on" and so those look like old-school IBM PC graphics characters. So you need to set your comm program for 8-bit no-parity ASCII *and* ignore the 8th bit on recieve, to avoid this problem. Sorry I did not see this sooner - Herb

Loren pointed out to me, details of serial operation and features of the UT20 ROM monitor, are in this extract of a MPM-216 RCA manual - and UT20 is much like UT4, aka "IDIOT" which is in this flavor of TinyBASIC.

Another serial problem is tuning the 1802 M/S Card clock. The M/S card has a variable clock, set with a trimpot (read your M/S Card manual). If the trimpot is just a little bit off the maximum clock rate, and TB's IDIOT monitor doesn't auto-baud on start; then your serial input and output actual baud rate may be a little "off". If you auto-baud first, IDIOT will reset the baud rate (read the IDIOT manual). The crudest thing you can do, is run a constant BASIC "print" program, and tweak the trimpot in real-time until your terminal displays the right characters! (shudder). - Herb

History of Tiny BASIC and the 1802

Tom Pittman, RCA

History

Tom Pittman wrote a Tiny BASIC in 1976, first for the RCA COSMAC 1802, then for other processors. Here's a link to his Tiny BASIC User Manual. Also on his site is A Short Course in Programming. Check Tom Pittman's TinyBASIC Web page for further history, more TB programs and tools, and some other implementations.

Among the items on Tom's Web page is, his Tiny BASIC Experimenter's Kit, which is compatible with a number of early TB implementations, presumably including the 1802 version. There's a TB implementation of an assembler for IL, the inner interpreter of TB.

Also - because as of 2019 it's not available anywhere else - here's an HTML copy of The First Book of Tiny BASIC by Tom Pittman. This copy was OCR'ed and verified by Lee Hart, Richard Peters, Chuck Yakam and others from a printed copy; with some program listings obtained from Pittman's site as provided by Richard Peters. The other Tiny BASIC documents I've noted may have been processed in a similar fashion, Tom's Web pages may have details.

RCA obtained a license from Tom in 1976 for 1802 Tiny BASIC, and it became one of RCA's COSMAC products. Documentation and a hex-record dump of 1802 Tiny BASIC, was part of some RCA products and manuals. One manual was for RCA's CDP18S020 evaluation board, manual MPM-203 "Evaluation Kit Manual for the RCA CDP1802 COSMAC Microprocessor", dated Sept 1976. (The version MPM-203A does NOT have a hex dump.) A number of copies of MPM-203 are available on Web archives.

RCA published a apparently later version in 1978, MPM-224 "Instruction Manual for the RCA COSMAC Evaluation Kit CDP18S020 and the EK/Assembler-Editor Design Kit CDP18S024". This later version describes Tiny BASIC and has a hex-dump(Chapter X or 10). For some reason, there's an apparent copy of chapter 10 only, at bitsavers.org. OTherwise as of 2020 I could not find a scanned copy of MPM-224.

ROM dumps, disassemblies, documents

In June 2020, Robert Coward edited and verified a source version of Tiny BASIC. He says his source generates a binary quote "absolutely identical to the RCA [hex dump] listing in MPM-203". Here's his source file and hex dumps and explanations. He ran his binary in ROM, with quote "a pristine UT4 ROM" on an RCA 18S020 1802 development board. But the source he edited, was produced previously by several people as follows below.

In Sept 2016, Chuck Yakym produced a JPEG copy of the RCA MPM-203 manual, and I extracted out the sections describing Tiny BASIC. There's a user's manual, and there's two pages of hex-dump. There was no 1802 source PUBLICALLY provided for RCA's Tiny BASIC (they sold source listings). But the hex values of the code, nearly exactly match the hex values of a TMSI 1802 source for Tiny BASIC as described below.

In Sept 2016, I compared the two binary code-sets, disassembled the few differences, and constructed a version of TMSI'S Tiny BASIC (without monitor) which assembled close to the RCA Tiny BASIC code as given in the MPM-203 manual. Here's that reconstructed version of RCA's Tiny BASIC as described here. That ZIP contains the 1802 source, the RCA dump, notes about differences. I've also OCR'd the MPM-202 manual's Tiny BASIC description, and included a RTF and TXT version. (Please check against the PDF of the MPM-203 manual, and let me know of any errors. Thank you.)

A JPEG scan of the MPM-203 manual was provided to cosmacelf by Chuck Yakym, in Sept 2016. He said "it's basically identical to the MPM-224 manual dated 1979". Check with the cosmacelf Yahoo group file archives, in Chuck's "the Eagle" folder, for this very-large sized set of scanned pages. Also: RCA also published a "MPM-203A" version manual, which does NOT have the hex-dump.

The reconstructed TB ZIP file, also includes various "fixes" for Tiny BASIC, which are discussed in the next section.

These Tiny BASIC sources alone will NOT "work", you'll need a ROM monitor. SOme of the "hex dumps" also includes RCA's UT4 monitor; and the original TB source verified by Coward, does run with the UT4 monitor. RCA's UT4 monitor is described on another Web page. However, more attention has gone to TMSI's version as below, which operates with TMSI's IDIOT monitor, a variation of UT4. - Herb

Lee Hart - TMSI TB for the 1802

This version for the 1802 I'm about to describe, was derived from Pittman's work by Lee Hart in 1982 for, the TMSI BASYS card. Lee obtained a license and source code from Tom Pittman. But Lee also worked with RCA's Tiny BASIC, based on the binary code version. Lee added his adaptation of RCA's UT4 monitor, called "IDIOT" to TMSI's Tiny BASIC.

Decades later around year 2010; Lee, with Tom's permission, provided the code to the cosmacelf [then Yahoo, now groups.io] email list group software archive as "TMSI Tiny BASIC". In 2010, I grabbed a copy and re-sourced it into ASM code compatible with the A18 cross assembler. It's for use with the Membership Card, but should not be hard to reuse for the old BASYS card. "My" source is modified, to match the old RCA binary; and it doesn't include the RCA ROM monitor. Meanwhile, Lee Hart's TMSI code includes the IDIOT monitor after Tiny BASIC; and variables for IDIOT are wedged in-between TB's variables and TB's RAM area for BASIC programs. Look hard at the TMSI code, if you work with my RCA code. sorry if this confusing.

A stand-alone version of Lee Hart's "IDIOT" monitor program, is described on another Web page. As of 2014, IDIOT was adapted for and works on the 1802 Membership Card.

Code and text for some of these fixes, are contained in the RCA Tiny BASIC ZIP file.; or as otherwise linked-to. Work before Loren Christiansen's work, is on the older TMSI version of Tiny BASIC with IDIOT monitor. The "RCA version" is static and for reference. Sorry for any confusion, but it's good to keep earlier code around to follow or undo changes.

Other Tiny BASIC work

reading COSMAC Tiny BASIC assembly

Dec 2019 note from Lee Hart: "For example, Tom Pittman's Tiny BASIC frequently set the accumulator to 0 not with "LDI 0" but with a "GHI 7" instruction. Why? When you see his source code, he defined an LDIO macro to do this. The source makes it clear that the high byte of R7 would always be 0. GHI 7 is a single byte, while LDI 0 is 2 bytes -- so every time he used LDIO he saved a byte." - Lee Hart, responding to a cosmacelf groups.io discussion.

Improving input and output

In TMSI Tiny BASIC, the "USR()" Function lets you call assembler routines PEEK and POKE. INP and OUT for I/O are also assembler routined, look for "I/O PORT DRIVER" in the TMSI TB source.Functions like LOAD and SAVE have to be done manually by "listing" or simulated entry through the serial port; or operations through the IDIOT monitor. It would be better, suggests Lee Hart, if these were "real" Tiny BASIC routines.

1802 speed-up patch from Tom Pittman

Lee Hart advised me to check Pittman's book "The First Book of Tiny BASIC Programs". Quoting that book: "I found that execution became excruciatingly slow, simply due to the memory scan for GOTOs, GOSUBs, and RETURNs. A simple patch to the interpreter converts it to a binary search, for about an order of magnitude speedup in execution time. The necessary changes are listed in the Appendix." Lee had a corrupted HTML of a corrupted OCR scan of the book. I extracted out the 1802 patch and produced ASM and LST which seems to replicate the code. Use of the patch "is an exercise for the student." The code is in the RCA TB ZIP file. There's corresponding patches for other processors in the book. - Herb

Chuck Yakym's speedup for cold-start

In Sept 2016, Chuck Yakym advised me of a speed up he implemented, in his version of Tiny BASIC as part of an 1802 monitor he's provided. Chuck's monitor is available in cosmacelf's Yahoo discussion site, in the files area, under "The Eagle" file folder. His patch is included in the RCA TB ZIP file.

Chuck Yakym's notes on relocating TMSI Tiny BASIC

Tiny BASIC as provided by RCA, Pittman, and TMSI, was intended to be loaded at memory 0000H and above. Chuck wanted to make his Tiny BASIC source relocatable, to assemble for use in higher memory. Here's what he said he found in TMSI TB, and what he did about it, quoted with permission. - Herb

"The reason that it isn't relocatable is because the way they used R7 to point to the Fetch subroutine. Understanding that the way TB is written, the high order byte of R7 is ALWAYS = 00h. Now a very clever way that they used this fact that R7.1 is always 00h, then they could (and did) use the "97h" (GHI R7) command to clear the "D" register instead of using the LDI 00h (F8 00) code. They save one memory byte per usage."

[Note: TB assembly source implements this use, not by the "GHI R7" or "GHI PC" assembly instructions, but by defining "LDIO EQU 97H" and use of "DB LDIO". Look at the RCA and TMSI TB sources for details. - Herb]

"To make Tiny Basic completely relocatable, this restriction had to be removed from the code. Below is the ONLY use of the "97h" (GHI R7) command that is used in the Tiny Basic part of my [relocatable] monitor/Tiny Basic program."

 0148   97            DOIT:    GHI  R7     ; TABLE PAGE

All the other uses of the "97h" command had to be changed to the "F8 00" (LDI 00h) to make Tiny Basic "truly" relocatable. There is 18 uses of the "97h" command used in RCA's Tiny Basic that were used to clear the "D" register only. [This explains 18 bytes added to the Tiny BASIC code.]

Peek and poke

Chuck Yakym continues from his "97h" fix above: "[Additionally,] I changed the [TMSI TB's] PEEK subroutine; see below

                ; MEMORY PEEK AND POKE SUBROUTINES
                        ;
0014   f8 00         PEEK:    LDI    00H
0016   30 2c             BR    PEEK1

                        ;PEEK CONTINUES HERE TO MAINTAIN RCA CALL
 				;USR 20 AND 24 ROUTINES VALUES
002c   ba            PEEK1    PHI    AC
002d   48                LDA    XX		;XX is R8
002e   d5                SEP    R5

"The added BR PEEK1 command is the additional two bytes that I had to add because of the original "97h" command was used in address 0014h. This all explains why my Tiny Basic is 20 bytes longer than [Lee's version]". - Chuck Yakym

Herb notes: RCA Tiny BASIC uses a different PEEK location than TMSI's Tiny BASIC; changes to the RCA TB version would be different.

Chuck added: "Understand that the user's BASIC program is usually 100h above the Tiny BASIC "workspace". There should be NO ROM in the system between the "workspace" and "Top of System memory" as found. If there is, and if the user inputs a program that uses up the RAM memory between the user's BASIC program and a ROM which is "lower" than Top of Memory; then the user's program will not be saved/stored correctly in memory."

Lee Hart later added: "The USR functions included routines for PEEK, POKE, INP, and OUT. The addresses for them were simple small numbers when Tiny BASIC was assembled for 0000h. But they become large negative numbers when assembled for 8000h. This made the documentation wrong. [And so,] existing programs that used them won't work, and created other issues (like you can't GOTO a negative number)."

A18 cross assembler

A18 is a C sourced 1802 cross assembler, compiled for 32-bit command-line use such as MS-DOS or Windows command-line programs. Read the Web page for details about that.

More Tiny BASICs

Andy Modla

In Jan 2018, Andy Modla contacted me with this background about his early RCA work with the VIP; he's done far more with the COSMAC in the era. He's reviving documents and surviving software, such as an arcade "coin-op" COSMAC FRED prototype which was field-tested in 1975. - Herb

"When I was at RCA in 1977 I wrote an integer tiny BASIC interpreter independently and published it (hex codes too) as a research technical report for the Sarnoff labs. Unfortunately I threw out my copy long ago. There is a note I wrote about BASIC for one of the computer magazines in 77 or 78 under Andrew A Modla author tiny BASIC referring to my implementation. I never converted it to floating point, but the RCA Lancaster VIP computer group did provide it to VIP board users. Later I found out Tom Pittman also wrote a BASIC interpreter too, that I think the RCA Solid State Division licensed from Pittman ...[For a reference to my BASIC,] See an archived 1980 VIPER magazine volume 2 issue 8 and 9.." - Andy

The VIPER magazine of Mar/Apr 1980, has an article "VIP Tiny BASIC Machine Language Subroutine" by Andy. Since the article references "ML" it's likely he's talking about Pittman/RCA's Tiny BASIC.

Further research on "VIP Tiny BASIC" found a May 28 2017 post on cosmacelf Yahoo discussion group, of a VIP system for private sale. The list of items included "VP-700 VIP Tiny BASIC ROM card" with a 4K ROM. Sure enough, that VIPER magazine of Mar/Apr 1980, had an RCA ad for that very product, from Landcaster PA, at $39. Further searching found reference to that ROM on the MAME arcade simulator Web site (but no ROM image). And, Ed Keefe does have that Tiny BASIC board (c) 1979 and manual.

Cenkar floating-point BASIC VP-701

The VIPER magazine of Mar/Apr 1980, also has an ad for "VP-701 BASIC" from RCA/Landcaster, which is a floating-point BASIC. There's also an article "VIP Tiny BASIC Machine Language Subroutine" by Andy. Since the article references "ML" it's likely he's talking about Pittman/RCA's Tiny BASIC. Ed Keefe has an original VP-701 tape and manual on his VIP site, under his VIP II project. There's VIP Floating Point BASIC on the cosmacelf.com Web site. The VP-701 manual acknowledges "Ron Cenker for his support and cooperation in developing VP-701 BASIC." That "Cenker" floating-point BASIC has since been found and distributed many times.

A Palo Alto Tiny BASIC for the 1802

If "Palo Alto Tiny BASIC" is not familiar to you, do a Web search and read articles publised in Dr Dobb's magazine of the mid-1970's.

The IPSO FACTO magazine, Issue 16, Page 55, has an article "PALO ALTO TINY BASIC INTERPRETER" by Robert Edwards of Oak Ridge TN. He writes: "The Palo Alto Tiny Basic Interpreter for the 1802 is alive and well. Now that its checked out, the subsidy on its distribution is being withdrawn. Thus the current price for a copy of the source listing is $2.00 (US), which just covers expenses." In Web search, I came across the cosmacelf groups.io files area for "BASIC" with folder "ORTB" for Oak Ridge Tiny BASIC.

In that files area, there's several files. The 1802.mac is macros to make some cross assembler assemble 1802 code. There's a basic.asm which is a mix of 1802 code and "bytecodes" in the Palo Alto style to be interpreted. monitor.asm is pure hex codes in an assembler form. A note "README" by John Stewart of Ottawa, Canada, has notes to this effect. There's also two ZIP files. oakorig.zip is "ORTB original source" and oakforse.zip is "ORTB for Super ELF". These are 1802 sources which say "T B I 1802 TINY BASIC INTERPRETER FOR THE COSMAC 1802 VERSION 2 BY ROBERT EDWARDS - Scanned By Dana S. Majors - Typed In And Format Changed By Richard Peters - Changed To QELFASM 2.0 Format".

This is quite a pile of code. But my impression is that the ZIPped sources cover the same code, as the "bytecodes" (1802 code represented as DB statements not ASM mnemonics) from the non-zipped files. Apparently this version includes code for a Motorola 6847 video chip. Someone with time and diligence, could probably resurrect this code for another 1802. In my brief review, "basic.asm" is an incomplete and "bytecode only" version of the "oakforse" listing. basic.asm moved code between "tab1:" to before the start of "tab4:", to a later part of the file. That changes the address-alignment of the following code by only a handful of bytes until it's realigned with an ORG. I would not "trust" basic.asm; I'd start with the full unbytecoded listings and reassemble and test accordingly. "Good luck". - Herb


Contact information:
Herb Johnson
New Jersey, USA

This page and edited content is copyright Herb Johnson (c) 2020. Contact Herb at www.retrotechnology.com, an email address is available on that page..