1802UNO
An RCA COSMAC 1802 simulation for the Arduino mostly aimed at the KIM UNO hardware. Will work without it though.
Install / Use
/learn @wd5gnr/1802UNOREADME
1802 UNO v25
Starting with Oscar's KIM-UNO code, I changed out the 6502 for an 1802. See: http://obsolescence.wixsite.com/obsolescence/kim-uno-summary-c1uuh for more details.
What's New
V25:
- Early integration of OSCAR's PIXIE code -- must define OLED in 1802config.h to enable. This isn't really an 1861 because there is no interrupt or EF1 output. It just dumps things starting at the location in R(0) from time to time. However, that works ok. If you don't have the OLED you MUST NOT define OLED. If you do have it, you should. Note that the display is off until you do input or output to I/O 1 (this relocates the serial port to I/O 7, by the way). Once on, it stays on (unlike the real thing). We may add a simulated interrupt and EF input if there is interest, but otherwise, this is it... V24:
- Improved BIOS
- Minor monitor fixes v23:
- Fixed instruction coding for ADCI
- Fixed corner case for branch instructions
- Altered BIOS to allow ROM strings in FF12 (lightly tested)
v22:
- Faster execution due to Oscar's patch (set NICE_VALUE in 1802config.h)
- You can create multiple non-overlapping ROMs (see 1802rom.h for details)
- All 3 demos now in ROM (Idiot at 8000, Etops at 9000, and Hi Lo at C000)
Configuration
You have 1K of RAM at 0000 and no interrupts. There is a small ROM at 8000 To set the ROM you must reflash the Arduino The various commands to save and read memory only operate on RAM You can "Load" through the ROM but it won't change the contents
There are three demo ROMs:
- IDIOT/4 at location 8000 (see below)
- ETOPS monitor (see http://www.elf-emulation.com/software/rctops.html and below) at location 9000 (see below)
- A HiLo game is at C000 (see below)
To run it put C0 XX 00 at location 0 to jump to it (where XX is 80 for for IDIOT/4, 90 for ETOPS, and C0 for Hi lo). On power up (but not reset) the first 3 bytes of RAM initialize to C0 80 00.
The file 1802rom.h only includes other files (1802idiot.h, 1802hilo.h, or 1802etops.h) so it is reasonably easy to flip different ROM images around and change where they load. Note that 1802 code is not always relocatable, so be sure you put ROM code where it will run correctly.
General Operation Overview
Nominally, you can operate the entire device via the built-in keypad and display. It works (at least externally) like a regular ELF. To enter data, select Load mode (DA), input hex bytes followed by the In key (+). Pres ST or RS (stop or Reset) to exit load mode.
Pres Go to execute the program at 0000 after reset or from where it left off if stopped. You can use ST or RS here depending of if you want to halt execution or reset.
To examine memory, press memory protect (PC) and then use load mode which will ignore any hex input you provide (just keep pressing + to advance through memory).
Serial Terminal Front Panel
If you have a serial terminal (e.g., a PC running a terminal program) you can use it in one of three modes. First--the default--is front panel mode. Keys on the terminal map to keys on the keyboard (e.g., G is GO, R is RS). There are also commands for dumping memory, loading memory, etc. Because the terminal can do everything the front panel can, you shouldn't need a front panel to operate 1802UNO. It should run on a plain Arduino Pro Mini or similar.
Serial Terminal Mode
If you use the | command from front panel mode, the serial terminal will become a normal serial terminal your program can read and will no longer operate as a front panel. This will continue until the Arduino resets (an 1802 reset isn't sufficient) or until a power cycle. This is useful for terminal-oriented programs like IDIOT/4.
Meta Monitor
While in front panel mode you can also press \ to enter the meta-monitor. This allows you to perform a lot of functions from the terminal. Note that while front panel commands don't work while in this mode, you can send the front panel a command using the "." command (that is, .R is reset, .? dumps memory, etc.).
Loading Programs
Using the keypad to load programs is a bit tedious. If you have a program already entered you can save it to EEPROM and later restore it using the keyboard or the terminal. In addition, the terminal can read a simplified hex format or Intel hex format files. It can also dump memory in both of those formats. To save RAM to EEPROM hold down SST for one second or use the > terminal command. Reverse the operation by holding down AD for 1 second or using the < command.
Keyboard
The keyboard is mapped like this:
- Go - Run
- ST - Stop running or stop load mode
- RS - Reset
- AD - Copy extended data register to load address
- + - EF4 (Input key for program or load mode enter)
- DA - While idle, enter load mode
- PC - Protect memory toggle so that load mode displays data
- SST - Single step
- 0-F - Build up hex number. Accumulates 16-bits although you can only see the lower 8. For load mode, the lower 8 is used. For AD all 16-bits are used.
- DA - Hold down for one second to save RAM to EEPROM
- AD - Hold down for one second when not running and not memory protected to read RAM from EEPROM
Serial Port
On a terminal (9600 8 N 1) you can use normal keys like 0-9 A-F a-f and these additional keys:
- ST=S
- RS=R
- AD=Equal sign (=)
- DA=L
- GO=G
- PC=P
- SST=/
- DA (1 sec)=<
- AD (1 sec)=>
Note: + does not act as Enter from the terminal; use $ to toggle EF4 instead.
That means that like KIM UNO, you don't need the hardware to run it (well, you do need the Arduino).
Other Serial Commands
- | - Go into serial terminal mode (until power cycle)
- ; - Toggle trace mode (warning: makes execution slow). Prints address, opcode, and D on each instruction execution
- * - Dump registers and state
- ! - Dump address and data displays to terminal
- ? - Dump 1K of RAM in 1802UNO Format (see below)
- $ - Set EF4 on/off (overrides HW keyboard)
- @ - Load RAM in 1802UNO Format (see below and examples directory; also see binto1802.c)
- X - Load RAM from Intel hex file
- Y - Write 1K RAM to Intel hex file (hint, you can delete all the zero lines and keep the last EOF line using a text editor)
- \ - Enter monitor mode. This is a meta-monitor running in the host Arduino. See section below for more details
Using the Serial Port from an 1802 Program
In addition, you can write to the terminal from 1802 code at port 1. If you want to read from the terminal, you can enter a | character. Once you do, the terminal will not act as a front panel anymore.
The 1802 code can control that mode by writing a 1 to port 7 to disable the serial front panel. A zero will reenable it.
There is a simple terminal program in the examples directory called Echo.txt. Remember to turn the terminal front panel off with | before you try this.
Loading and Saving RAM
With a serial port connected, you can send the ? command to get a dump of all 1K of memory.
You can also set memory by sending back the string returned by the ? command. You can also make your own string using the following format:
@address:byte byte byte byte .
Everything is in ASCII, so "@0000:7A 7B ." is 13 bytes. Note that you don't need all the digits (e.g., "@0:5 2 1 FF ." is OK. Also you must have a space betwween bytes and before the period which ends the transmission. The only characters that matter are the @ sign, the period, and the hex digits (upper or lower case). So you could just as well say "@0000=7a,7b&." if you wanted to.
You can also read and write Intel hex files with X and Y commands. Note that Y writes out all 1K of RAM. The last line is an EOF record and you can delete any lines you don't care about. So if you dump a simple program that takes, say, 30 bytes, you can keep the first two lines and the last line and delete the rest using a text editor.
LEDs
+--------+--------+--------+---------+---+---------+-------+
| LED1 | LED2 | LED3 | LED4 | | LED5 | LED6 |
+--------+--------+--------+---------+---+---------+-------+
| . Q | . LOAD| . RUN | . EF4 | | . PROT| |
| | STATE| STATE | | | MEM | |
+--------+--------+--------+---------+---+---------+-------+
(Thanks for the graphic Oscar)
Known Problems
- There were two issues in v22 that are now fixed (see above)
- The BIOS is lightly tested and may not have all the same private semantics as compatible BIOS
Future Plans
- All done for now. (However, see Branch Pixie for Oscar's OLED 1861 Pixie chip simulation)
Hackaday
http://hackaday.com/2017/07/25/kim-1-to-cosmac-elf-conversion-sort-of/
Port Summary
- Port 1 - Serial port
- Port 2 - LSD of address display (if enabled)
- Port 3 - MSD of address display (if enabled)
- Port 4 - Switch/Data LED
- Port 7 - Control port. Set bit 0 to disable serial front panel. Set bit 1 to put address displays under program control (see port 2,3).
BIOS
There is experimental support for a small number of BIOS function when BIOS=1 (see 1802config.h). These BIOS calls are not written in 1802 but are handled by the Arduino host. The baud rate is fixed so any BIOS function that in the "standard" BIOS that takes a baud rate value will ignore it.
At present, there are two BIOS functions tested, and two non-standard support functions.
- 0xFF3F - Set up SCRT. Put a return address in R6 and do a LBR to this address. On return, P=3 at your return address. R4 will be set up to do an SCRT call and R5 will be set up to do an SCRT return.
- 0xFF66 - Print the string after the call to the terminal until a zero byte. So to print ABC<CR><LF> you would use the following code: D5 FF 66 41 42 43 0D 0A 00
In addition, the SCRT routines use the non-standard addresses 0xFF01 and 0xFF02. Since this is set up by 0xFF3F, even if they change, you should not notice.
There is an example of using SCRT in the examples directory called BIOS.TXT. Note that when stepping "through" a BIOS call, you will see a bogus instruction fetch
