RCA COSMAC SCRT, Interrupts, and RCABUG


Introduction:

Last updated Nov 19 2021. Edited by Herb Johnson, (c) Herb Johnson, except for content written by others. Contact Herb at www.retrotechnology.com, an email address is on that page..

This Web page discusses 1802 code which supports the RCA COSMAC Standard Call and Return or SCRT routines. This page also discusses 1802 interrupt instructions and a sample interrupt service routine or handler. Early RCA 1802 documents, such as "COSMAC User's Manual MPM-201B", introduced SCRT to provide subroutine support and also interrupt handling. It's reasonable to turn off interrupts when passing control to and from a subroutine. The details of interrupt use are not discussed here. RCA use SCRT in some ROM moinitor programs, like UT71.

These SCRT routines became part of a monitor program called RCABUG, developed decades ago by Tom Crawford and published in Ipso Facto, a COSMAC support group newsletter. RCABUG was revived in 2016 by Bernard Murphy and Greg Simmons, as discussed in cosmacelf groups.io group and available from their file archive. cosmacelf.com has PDF's of Ipso Facto. I obtained permission to extract out the SCRT and register-save routines. I discussed these with Greg Simmons, and got permission from Tom Crawford. Those were my introduction to RCA's SCRT.

A18 is an 1802 cross-assembler. It's part of support for the COSMAC 1802 "Membership Card" created by Lee Hart. Other 1802 software for the Membership Card is available at the linked Web page.

Elf/OS is an 1802 operating system developed by Mike Riley and his associates. He revived it in 2020-21. A Web search will find more information about it. I reference it here for a SCRT macro versus 1805 within elf/OS, in the cosmacelf groups.io discussion list. in Sept 2021.

A version of SCRT was provided to support Lee Hart's IDIOT monitor, a version of RCA's UT4 ROM monitor.

- Herb Johnson

Files and links

Here's an exerpt of UT71 SCRT routines with an example subroutine. For more details of what UT71 does, here's a UT71 Web page with code and links to documents.

Here's my exerpt of RCABUG's SCRT routines plus interrupt handling. From RCABUG there's code for SCRT; routines to save and restore registers available for user programs and not dedicated to SCRT or other use. I've added code for support of an interrupt handler, from the User's manual.

Here's my exerpts from RCA's COSMAC User's manual MPM-201B, which describes interrupt handling with DIS and RET. The manual also describes SCRT and many other COSMAC 1802 features and coding suggesstions.

A18 is an 1802 cross-assembler. It supports "common" 8-bit assembler syntax, not RCA's earliest assembly syntax which has unique features. Most of my Web page with 1802 code, provide 1802 sources consistent with A18. Programmers of other 8-bit 1970's microprocessors should find most of these features familiar. - Herb Johnson

RCABUG and recent history

RCABUG was revived in 2016 by Bernard Murphy and Greg Simmons, as discussed in cosmacelf Yahoo group and available from their file archive. cosmacelf.com has PDF's of Ipso Facto, with permission of the publisher.

In discussion in groups.io group cosmacelf, Bernard Murphy posted in Feb 2016 that he had a COSMAC monitor in ROM but no source. Several people responded and the monitor was identified as RCABUG. Greg Simmons offered to dump the PROMS. RCABUG was written by Tom Crawford, and published in Ipso Facto Issue 10, Feb. 1979. Tom is still active and discussed his work with Bernie and later with Greg, and permitted Greg's efforts.

In Feb 2016, Greg Simmons extracted out the RCABUG source and produced an assembly language source, which he made available Feb 20th. Greg also provided the ROM dump from Bernie's PROM. Greg modified the RCABUG source to assemble within the A18 cross assembler, by expanding a few macros as A18 doesn't support macros. I obtained permission to extract out the SCRT and register-save routines. I discussed these with Greg Simmons, and got permission from Tom Crawford. Those were my introduction to RCA's SCRT.

RCABUG

The RCABUG source and PROM dump are available from the groups.io cosmacelf discussion group files area. RCABUG was published in Ipso Facto: Copies of Ipso Facto are available from the cosmacelf.com Web site, as permitted by the publishers. A copy of RCA's COSMAC User's Manual MPM-201B, is also on the cosmacelf.com Web site. The cosmacelf groups.io (former Yahoo) discussion group is at this Web link.

Thanks

Thanks to Greg Simmons for all his hard work. He dumped the 2708 EPROM, extracted the source code from Ipso Facto documents, added useful comments and mods. He discussed and reviewed my comments and later my exerpted code, in detail: thanks. Thanks to Tom Crawford for his interest and for further permission for my use of portions of his RCABUG code. Thanks to Bernard Murphy who got this thing started with his PROM, and for his discussions with Tom.

Greg told me that Tom said "No problem, you may post the RCABUG source with comments and mods as you see fit. I'd appreciate any reference as the original developer, although it has been a long time.... !" Greg also said "Tom would be happy to answer any questions we might have about his code; however, after 37 years, he may need to go back and dust off some old papers."

- Herb Johnson

RCA's SCRT and interrupt code

I discussed with Greg by email his edited work on the RCABUG code, and use of A18 and its features. The RCABUG monitor is well documented, and in particular shows the use of RCA's recommened COSMAC standard call and return or SCRT.

Greg and I discussed adding CALL and RETRN to A18. It had been on my mind to do so, as pseudo-ops. But without supporting code they would not be useful. RCABUG provided a strongly-impemented version of those routines which was consistent (not identical) to RCA's recommendations, which appear in the COSMAC User's Manual. Tom also supported a save/restore routine pair, for registers not dedicated to call/return or other typical 1802 use - again, reasonably consistent with RCA COSMAC recommendations. Also: Tom's code included some "hooks" for interrupt operation, which caught my attention as few COSMAC programs seem to support the 1802 interrupt hardware or interrupt instructions.

I decided to extract the RCABUG code supporting SCRT, user-register save/restore, and register inits. Then A18 users would have code in hand to support CALL and RETRN. But there was no code in RCABUG to actually process an interrupt, only to enable or disable them.

IN March 2018, Loren Christensen implemented CALL and RTRN in his copy of A18; I accepted his changes and they will be part of my A18 distribution. I decided to document UT70's simpler implementation of SCRT. Here's an edited version of UT71's support of CALL and RTRN. I hope it's not "broken" so contact me if there's notable errors. - Herb

Interrupts

While Tom's code included some support for interrupt and DMA initialization code, it did not include an interrupt handler. Curiously, the call and return routines had bits of code to enable and disable interrupts with DIS and RETN, and a register reserved as an interrupt hander program-counter. But there was no interrupt hander. And unclear to me, was how Tom modified operation of DIS and RETN.

This led me back to the RCA COSMAC User's Manual MPM-201B. The manual describes CALL and RETRN as supported with a pair of code segments to manage program registers and a subroutine address stack, and how to pass values to a subroutine. These were similar to Tom's code. The User's manual provided a sample interrupt hander to accept an interrupt, and to later restore program operation after handling. And notes in the manual, show how setting the X register to the same as the program counter will modify the execution of DIS and RETRN, as Tom's CALL and RETRN

Here's my notes of exerpts from the MPM-201B User's Manual, which describe how DIS and RETRN are modified when preceeded by a SEX instruction which sets the X pointer to the same as the P pointer (program counter). Those operations occur during Tom's CALL and RETRN routines because he disables interrupts during those routines.

IN March 2018, Loren Christensen wrote to me: "MPM-241 Manual has pretty good description of SCRT initialization, on page 86. They actually had startup code vectors, INIT1 and INIT2 in the monitor EPROM that the program could call first (not a bad idea...). The code for these and the CALL/EXIT routines is in the Appendix G, the UT71 monitor listing." Here's my (Herb's) Web page on UT71 with source.

Interrupts are not discussed often in cosmacelf discussion. But here's some notes about interrupts versus program execution from Lee Hart.

Other implementations of CALL, RETURN

The RCA COSMAC User's Manual MPM-201B, and Tom's RCABUG code, show one means of implementing CALL and RETURN. Other COSMAC programmers have produced code with other ways to support CALL and RETURN. Sometimes different register pairs are used - other than R4 for the CALL and R5 for the RETRN. Sometimes there's different means of passing values, or returning from the subroutine. I'll show some examples as I can. Look to other available COSMAC 1802 code for other complete examples. Carefully read the code you have on hand, and these examples, and the RCA manuals, to understand how CALL and RETRN are supported. - Herb

On March 21, 2016, Robert R. Smith offered another implementation of CALL/RETURN, which is exactly like the RCA manual implementation. In his example, the subroutines are passed a value; and both subroutines and the calling program use R7 to point to a data area which amounts to a rising stack (most stacks push to lower memory, this rises to higher memory). - Herb

In July 2016, in the cosmacelf Yahoo group, there was discussion of the use of MARK to support subroutines. In the RCA document MPM 201B, the CDP 1802 User's Manual (copies in various archives), under "Programming Techniques" there's a sectin "MARK Subroutine Technique", page 58-60 for one edition. The MARK instruction saves X and P in memory as addressed by R2, which is then decremented; P (the register used for program instructions) is moved into X. R2 can be treated as a stack pointer accordingly. If X is set to 2, then the RET instruction will restore X and P; DEC R2 will restore the value of R2. See the User's Manual for discussion and an example.

Elf/OS and SCRT for 1802 macros vs 1805 instructions

A discussion in cosmacelf groups.io brought up the point that the RCA 1805 implementation of CALL and RETURN does not match the RCA 1802 early documents which established SCRT. Specifically the order of high byte low byte pushes (and complimentary pops). There's also some conflict about how an interrupt handler stores and restores registers. The discussion is about conflicts within the elf/OS operating system and BIOS, it's also about assembler's support of 1802 SCRT macros versus 1805 instructions. Conflicts arise where source code (or worse binaries) from different assemblers are mixed.

Bob Armstrong noted "I looked at [RCA's COSMAC document] MPM-201 and [their SCRT definition does] it your way; push the high byte first. So does the UT71 code, so you're in good company. BUT, it appears that the hardware SCRT on the 1804/5/6 does the reverse." David Madole points out how some SCRT routines use RE.0 (low byte) to preserve the D register, and or set the X register to 2 and thus the use of R2 for indexing. Bob replies "Fair enough - the software SCRT has some side effects that the hardware version does not. It's worth pointing out that not all versions of the software SCRT preserve D - neither the MPM-201 nor the UT71 versions do, for example. But preserving D is not a bad thing, and shouldn't be harmful." So another consideration, is whether X (R2) is decremented after a push, thus pointing immediately to an unused location on the stack; some programs exploit that as a temporary memory location.

The groups.io cosmacelf discussion is at this link. Topic "ElfOS BIOS SCRT problem?" for sept 12 2021 starting at message number 36381.

Bugs & fixes

Let me know of any errors or omissions in the code or documents I've provided. Note that CALL and RETRN are pseudo-ops to A18, the 1802 cross assembler I've referenced above. I cannot guarantee them of course. Thank you. - Herb

Notes from Tom Crawford

Tom Crawford recalls his work of the 70's and 80's, in these March 2016 comments. Tom also mentioned, he was recently told that Ipso Facto material led a high school student to a career as a software developer. - Herb

"I recall that we did our first assemblies of 1802 code (after doing a lot by hand, of course!), on a simple assembler one of our group implemented in Fortran, to run on the GE / Honeywell Process Control Computer we had available at the time. IBM Punched card input, and printed output that could be entered into an 1802 RAM via hexpad, or into an EPROM programmer. The one we had access to (a commercial product), required each byte to be entered via 8 toggle switches, then push a button to program that byte. I soon built a 2708 programmer that allowed data to be sent via serial i/o to a collection of hardware that handled timing and address incrementing for each byte. Later, we acquired a PDP-8 minicomputer at work for a development project, complete with paper tape i/o, and the assembler was moved to that machine. It could talk to my programmer!!"

"Will’s mention of the Aztec C compiler is interesting. I also bought a licence to this product after I built a Z80 based “Big Board” computer for my home use. A short while later, I was involved with a massive plant automation system, controlled in part by very large PLCs, whose very large ladder diagram programs were loaded when needed via tape cassette connected to a teletype like console, at 1200 baud! Took an hour or more, and didn’t always work... I took it upon myself to build a storage and loader system at home on my Big Board using Aztec C, to run at a much higher baud rate, worked every time, and gave me an excuse to buy a bunch of “portable” computers (KayPro II) based on the same system. We also sold the loading system back to the PLC supplier (GE). A very nice bonus..." - - Tom Crawford


Contact information:
Herb Johnson
New Jersey, USA

This page and edited content is copyright Herb Johnson (c) 2021. Copyright of other contents beyond brief quotes, is held by those authors. Contact Herb at www.retrotechnology.com, an email address is available on that page..