S100 Computers

Home S-100 Boards History New Boards Software Boards For Sale
Forum Other Web Sites News Index    
A 6502 Monitor
Any 6502 S-100 board needs a built in monitor program to monitor its ability to interact with other S-100 bus boards.   Unlike the Intel family of CPU's the 6502K starts up from a reset at FFFAH in RAM  -- every time, no exceptions.  In the first two bytes of RAM it expects to find the location for its NMI vector pointer.   Next (and most important) in the next two bytes (FFFCH) it will expect to find a pointer to the start or its run time code/monitor. The next two bytes (FFFEH) will contain the interrupt vector pointer.  Before discussing the monitor in detail lets first recap on 6502 programming.

To the Intel/Zilog programmer the 6502 may appear a little strange.  It has a small number of internal registers. The program counter (PC) is 16 bytes wide,  all the rest hold only one byte! The stack pointer (S) points to a byte on "Page 1", whose address is from 100H to 1FFH and where the last two digits are supplied by register "S".  When a byte is pushed onto the stack, it is written at the address in S, and then S is decremented. Popping a byte from the stack is done in exactly the reverse order, S is incremented, and the byte there is read.

The accumulator "A" holds one of the operands in every operation, and most of the processing instructions refer to it. The two index registers "X" and "Y" hold auxiliary numbers used in addressing, and can also serve as temporary storage when necessary. There is also the flags register "P", whose contents are used in making comparisons. The programmer works principally with A, X and Y, and does not usually handle the others (P, S, PC) explicitly.  That's all there is!  Interestingly the original 6502 there in no unconditional branch. You have to use:-      

   BCC   Somewhere

The good news is the 65C02 has a Branch Always (BRA) opcode.   In fact all in all, the 6502 had a rather limited number of instructions. Here is a table of the available opcodes for the 6502 and 65C02:-
  65C02 OpCodes

We will use the 65C02 in all our discussions here.  BTW, you also have to be careful about the carry flag with move instructions - it changes with some!

The interrupt disable flag, I, is bit 2 in the flags register. Clearing it, with CLI (Hex code 3AH), permits the processor to recognize interrupts (the opposite to Intel terminology). Setting it, with SEI (Hex code 4EH) causes the processor to ignore the state of the IRQ pin. 

Somewhat unusual from an Intel prospective, the decimal flag, D, is bit 3 in the flags register. Clearing it, with CLD (Hex code D8H) means the processor will do arithmetic normally, but if you set it, with SED (Hex code F8H), you will get BCD arithmetic.

You must clear the carry flag with CLC (Hex code 12H) before doing an add, and set it with SEC (Hex code 38H) before doing a subtraction, since these instructions normally either add carry, or borrow from carry, automatically. These three flags are the only ones you can both set and clear independently.

The 6502 uses the first 255 bytes of RAM as registers. It is very important you understand the difference between a number, a "page zero" RAM location and a pointer to 16 bit memory in Page zero when programming the 6502.

Before you do any serious assembly programming for the 6502 you should read cover to cover the book by Lance Leventhal that describes how to program the 6502. It seen and downloaded here.   

Now you could place a ROM monitor anywhere in RAM but there has to be  ROM based jump to it at FFFCH.  Consequently a monitor is normally placed in the top 1K of the 6502 64K address space (F100-FFFFH).  The reason we don't use F000-FFFFH is the 6502 does not have separate opcodes & pins for hardware port IO.  For simplicity we will set aside the first 100H bytes of the ROM space as a "hole" for port I/O.  Our S-100 6502 boards are set to recognize these and convert them in hardware into Intel style I/O signals for the S-100 bus.  Note the original 6502 S-100 boards requires this "hole" to be the first 100 bytes of the ROM.  The second master/slave 6502 board allows the "hole" to be placed anywhere in the ROM space, though only the first 100H bytes make much sense.  Finally remember the hardware will actually assign addresses in the 0 to 0FFFFFH range on the S-100 bus the upper address lines, A16-A23, always set to 0H.

Assembling 68K Programs.
There are a few good assemblers for the 6502 CPU.  I have just started using the TASM assembler written some time ago by Thomas Anderson of Squak Valley Software. Its excellent. The manual can be obtained here. The assembler itself can be downloaded here. It even runs in 64 bit Windows 7.

Having read up on the 6502, the next step was to write a simple 6502 specific ROM monitor just to get the hardware going.  My goal was to model it after the 8086 monitor I wrote.  I wanted to use all the same menu options -- to keep life simple. I should point out that there are a number of excellent well tested 6502 monitor programs, check the web. The 6502 Monitor program can be seen here and downloaded here.  I have set the board settings so the I/O address space starts at F000H-F0FFH and the ROM code starts at F100H to FFFFH.

Here is a list of the main functions within the 6502 monitor I have written so far:-

Setup all equates for ports and memory locations
Initialization of serial and parallel ports
The A-Z command jump table

Display memory map for 0 to FFFFH
Display RAM in ASCII and HEX
Echo a keyboard character on console
Fill RAM with a HEX value
Move and verify memory
Substitute values in RAM
GoTo a RAM location
Do HEX math
Switch back to Z80 CPU
Query and set ports
Display menu on console
Interrupt vector routines
Consol output routine
Keyboard input routine
Consol status routine
Speech output routine
Printer output routine
Support routines

Table pointers to routines within the monitor

The links below will contain the most recent versions of the above software.
Note, it may change over time and may not correlate exactly with the text in the article above.

TASM Assembler  (08/04/2012)

PDF FILE OF THE 6502 MONITOR   (V1.0 08/04/2012)

This page was last modified on 05/14/2016