Close

Reading Keys / Entering a program on the KIM Uno.

A project log for Mystery 6502 program for the Kim Uno #1kBChallenge

The #1kBChallenge inspired me to dust off the Kim-Uno and write an Enigma Z30 simulator. This is a very rare numbers only Enigma Machine.

arduino-enigmaArduino Enigma 12/01/2016 at 04:410 Comments

Before we get too heavy in the details, let's start by describing how to enter and run a program in the KIM Uno. When you first turn it on, the KIM monitor will run and it will display 0000 00. The monitor will let you examine memory, enter values into memory, run a program and single step a program. The contents of CPU registers and flags can be viewed by accessing special memory locations.

Upon power up, the group of 4 digits on the left is the memory location, the group of 2 digits on the right is the value stored at that address. A key pressed will be interpreted as an address or a value depending on which mode the Kim monitor is on. On power up, reset and stop, the monitor goes into Address mode and keys pressed change the memory location field. To change to data mode, press the [DA] key. A value keyed in will be written to memory. To go back to address mode, press the [AD] key.

An address is entered by keying it with the 0..9 and A..F keys. The address will be shifted left one digit at a time and the memory content field will be updated in real time. To see memory location 200, type 0200. Once all four numbers are keyed, you should see A5 on the right. If you forget to key in the first zero, and another address is shown, just type 0200 again.

If you have my clock program, type [AD]0400 and F8 will appear. Some other values will appear on the right as you type 0400.

The listing below shows a program that will read a key and display its value. The first line specifies the starting memory location. The middle column includes labels and program instructions. The numbers on the right are the opcodes for the program.

This program will call the routines at $1F1F, which displays the values of memory locations $FB $FA on the left 4 digits and $F9 on the right two digits. If the program writes 12 34 56 to $FB, $FA, $F9, the display will show 1234 56.

The next routine called is $1F6A, which reads a key and returns it in the A register. If A is 15 or greater, no key was read. The program stays in a loop defined by the label start, $1F1F is called repeatedly to keep the display alive, otherwise it will be turned off and no digits will be shown at all.

To enter the following program, we will go into address mode and select the starting location, then switch over to data mode and key in the program starting the 20, the first and second lines show the starting location and a symbol called THIRD, those do not result in opcodes, the first program line is JSR $1F1F, which is compiled to 20 1F 1F. To accept one byte and move to the next, press the [+] key. If a mistake is made while entering a memory content, just retype it and press [+] when correct.

For example, if we want to enter 20, but 21 was keyed in instead, just type 20 again and then press [+]

To enter the program below, key in

[AD]100[DA]20+1F+1F+20+6A+1F+C9+ .... B0+F1+

To check your work, press [AD]0100 and repeatedly press the [+] key, The numbers on the right will show in order 20, 1F, 1F, 20 ...

You don't need to enter the whole program in one shot. You can stop at any time, change to address mode, examine memory locations with the [+] key and when you reach an empty memory location, press [DA] and continue entering the program.

I like the listing view because it having the addresses on the left helps keep you on track as you enter the program, when entering the program for the first time, after 20+6A+1F, the Kim Uno will show 0106 on the left and you will know that it is the right place to keep typing C9+

* = $0100

0100 THIRD = 00F9

0100 START

0100 JSR $1F1F 20 1F 1F

0103 JSR $1F6A 20 6A 1F

0106 CMP #$15 C9 15

0108 BCS START B0 F6

010A STA *THIRD 85 F9

010C SEC 38

010D BCS START B0 F1

This program uses a small trick that allows it to run in any memory location. Conditional jumps like BCS are always relative. The last instruction at 010D to jump back to start is not a JMP START, which will compile to 4C 00 01 and specifies an absolute memory location of 0100 (represented backwards as 00 01). Instead, the jump used was a conditional jump BCS (branch if carry set), which uses a relative number of bytes to jump back. To force the jump to always happen, the carry is set with the SEC (set carry) instruction.

To execute this program, press [AD]0100[GO]

Start with the bottom row and press either 0, 1, 2 or 3.

The same value will be shown in the display. This will continue until you read C,D,E and F.

The AD, DA, PC, + row will also show values.

On the top row, only [GO] reads a value of 13 (hexadecimal).

If you press ST, RS, or SST, the program stops and the screen may blank out. To get a display back press [ST]. To go back into the program, type [AD]0100[GO] and try typing a number. If the number key changes the address field instead of being shown on the left, you are in Single Step mode, press the [SST] key once and the screen will blink. Then press [AD]0100[GO] again and try pressing a number key. It should be shown on the rightmost digits. To stop the program and go back to monitor mode, press the [ST] key.

This program was entered in RAM, powering off the KIM will delete it. To have it permanently available, it must be entered in EEPROM, addresses 0400 thru 07FF. The clock program is stored from 0400 to 0434. You can use 0450 as a starting location for the test program above. To enter it in EEPROM, type [AD]0450[DA]. Blank EEPROM shows up as FF. You will notice that as you type 20, the display blinks and FF is unchanged. This is because read only mode is enabled.

To remove write protection from EEPROM, press and hold the [RS] key for about a second until the display blinks, then press [DA]20 and it will let you write 20 to EEPROM. Pressing the [RS] key drops you back yo address mode. If you do not press [DA] to go back to data mode, you will find yourself changing the memory address instead of the memory value. Simply press [AD]450[DA] to go back to the starting memory location for the program.

To restore the write protection, press and hold [RS] again for about a second until the display blinks again.

And that is a practical primer on using the KIM Uno monitor to examine, change memory and execute a program.

Below are the key values returned when each key is pressed. The ST, RS and SST key cannot be read by code.

13 xx xx xx

10 11 14 12

0C 0D 0E 0F

08 09 0A 0B

04 05 06 07

00 01 02 03

For further reference, see:

http://www.6502.org/tutorials/6502opcodes.html

The assembler I am using is:

http://www.masswerk.at/6502/assembler.html

Discussions