S100 Computers

Home S-100 Boards History New Boards Software Boards For Sale
Forum Other Web Sites News Index    

A Z80 Monitor Program
My first computer was centered around the TDL system monitor board. This very useful S-100 board had a wonderful Z80 monitor in its custom 4K ROM. It was called "Zapple". It was an extension of an 8080 monitor program written by Roger Amidon called "Apple" back in the mid 70's. It had all the basic requirements such as allowing the user to examine/modify RAM or IO ports. Output to a console, printer, punch, tape reader (these were the Teletype days) or cassette recorder.  It was really the first to do the obvious, namely have all jump calls at the start of the program - for easy access by other programs and allow redirection of output by changing an "IOBYTE" stored in an IO port.

SMB Board

Over the years this monitor code has been copied and modified many times over by others. I too have extensively modified it to incorporate things like booting the first sector of a floppy disk to load CPM. Or doing the same thing for my hard disk. I even have code in there to direct output to my speech synthesizer, run a date/clock chip etc.  I no longer use the original SMB, instead the monitor now resides in the EEPROM of the S100Computers Z80 CPU Board.
I am enclosing the complete source code for the monitor (see Below).


The above ROM based monitor normally resides at 0F000H. However for testing purposes it can be assembled to run at 100H where it should run in a CPM system with no conflicts. The monitor is really split into two 2K sections. The first section contains a table for  all the "normal" monitor jump options like displaying or modifying memory or ports.  The second section at 0F800H contains a jump table for CPM BIOS routines. Some of my older (pre-CPM3) software counts on these locations being there.  The monitor resided in a 2732 PROM chip on a Intersystems Z80 CPU board. As with any such monitor there are some extremely hardware specific sections. Major sections consist of the following:-

  Master Monitor ON LCD

Setup all equates for ports and memory locations
The main Jump table to routines within the monitor
The A-Z command jump table
Initialization of serial and parallel ports (LED's on a IMSAI PIO board light up one by one as sections are completed)
Send a text string to consol.  String in [HL]
Get highest RAM location available to Z80
Various parameter processing routines
Keyboard input routine
Console output routine
CONSOL status routine
Printer status and output
Boot CPM from hard disk (8255 driven IDE Drives or CF Cards)
Display a memory map of 64K
Display memory map for any segment up to 1 MG.
Query ports
Display all active ports from (0 to FFH)
Test RAM
Move and verify memory
Switch in another CPU (8086, 80286 or 68000 etc.)

At F800H, A jump table for CPM BIOS
Boot CPM from a floppy
CPM required BIOS routines
Get Time from a 58167 or DS12887 clock chip
Hex math routines
Display ASCII in RAM
Send an ASCII  string to a speech chip
I/O from a serial port/modem
Download code from another Computer/PC over a serial/USB port and place it in RAM at any location (0H to 0FFFFFH) using the XMODEM protocol.
Jump to code in RAM.

As you can see the program is written in Z80 code. It should assemble with almost any Z80 assembler. In the past I used the SD Systems assembler simply because that's what I started with. It has a slight quirk in that the data fields "DB", "DW" require "DEFB" and "DEFW". The good news is that strings can be written with "DEFM".  I also used the Cromemco Assembler, but that one has a quirk in that it will not accept names with "$" or "_" character.  

I have now switched over all my stuff to the SLR Z80 assembler. Kicking myself i did not do this earlier!  It is extremely fast and produces .COM or .HEX files directly.   To review and download a CPM based assembler go here.

Z80 Monitor Software For The V2 Z80 CPU Board.
This ability to flip 4K "pages" within the ROM in the V2 Z80 CPU Board effectively allows one to almost double the effective size of the code in your Z80 monitor.  The only thing to watch out for is that the actual code used for the switch reside in EXACTLY the same place in both 4K pages.   I have modified the above well tested Master.Z80 monitor to have Floppy disk/CPM booting code in the lower 4K and the ability to download a XModem formatted file directly to RAM from a PC (via a serial port) in the upper 4K.  You can actually do a lot with 8K of ROM with a Z80 -- just be careful about the common code used during the switch.

Here is a Video of the V2-Z80 Board Monitor with the file transfer command running:-

Z80 Monitor Software V5.5 for theV2 Z80 CPU Board.
This ability to flip 4K "pages" within the ROM in the V2 Z80 CPU Board as described above works fine, however it is very inefficient in terms of ROM bytes utilized.  It is essentially a duplication of the lower page in the upper page with a few lower routines replaced with the XModem menu option in the upper page.  The menu text for example is in both pages and one has to enter a menu option "XH" or "XL" to switch pages. 

While working on a similar arrangement for our PDP11 CPU monitor it became apparent that a much more efficient approach is to have the upper menu items call a "PAGE SWITCH" routine, switching the page themselves, do their thing and then switch back to the main menu/lower page.  Only essential support routines (console I/O etc.) need be duplicate in the upper page.  This approach allows for a much more compact/efficient monitor with well over 1K of free ROM space currently available for expansion.  Let's go through the theory and code in detail.

On the V2 Z80 CPU Board  if we jumper P39  to 7-8,  outputting to port D3H with bit 1 high, will raise the A12 line thereby selecting the top 4K of the EEPROM. Outputting to port D3H with bit 1 low, will bring back. While this complicates the Monitor code (see below) it allows one to almost double the amount of code you can get into a 4K address space. All versions of the MASTER Monitor from V5.4  onwards have this capability/code.  The most current version can be download from the bottom of this page.   Programming the onboard  EEPROM is a bit tricky however.  First, here is a diagram of the layout:
  ROM layout
The actual MASTER monitor assembly language code is split into two completely separate files, MASTER0.Z80  and MASTER1.Z80.  It is very important to understand that the code in either file knows nothing about the code in the other.  The vast majority of the monitor code (currently) resides in the MASTER0.Z80 file. In fact you can use this code/file alone to run the monitor just as you did for the earlier "single page" monitor e.g. the V4.7 monitor.  It will for example run fine in the original S100Computers Z80 CPU board.  Currently only one menu option, the "X" (XModem) command, resides in the High Page for the MASTER V5.4 and later versions.  Any further new code will probably also reside there. 

How do we switch the Address Line LA13 on the ROM without blowing the running Z80 CPU out of the water?   We do this by having a small "Switch Address Line" routine in exactly the same location in both the LOW and HIGH ROM code sections.  In both files (and so pages of the ROM) the relevant code is:-

ACTIVATE_HIGH_PAGE:                          ; SWITCH TO HIGH PAGE of ROM
LD      A,06H                    ; 04H for MEMORY MANAGEMENT TO OVERLAP + Bit 1 = HIGH PAGE
OUT     (Z80PORT+3),A
            JP      NoHighPageError          ; Will arrive here only IF no address line switch.

JP      START                    ; <---- Switching back to LOW page will arrive here

ACTIVATE_HIGH_PAGE:                          ; SWITCH TO HIGH PAGE of ROM

LD         A,04H                 ; 04H for MEMORY MANAGEMENT TO OVERLAP + Bit 1 = HIGH PAGE
OUT       (Z80PORT+3),A
            JP NoHighPageError               ; Will arrive here only IF no address line switch.
            LD         A,D                    ; HIGH PAGE code with 1 in [D] for XMODEM
            CP         A,1
            JP         Z,HIGH_XMODEM
            JP         INVALID_MENU_ERROR     ; The only menu option so far

The trick is that when we input (anything) from the port Z80PORT+3 the Z80 board circuit recognizes this event and switches the address line LA13 from LOW to HIGH going to the  EEPROM.   The yellow text code above moves (unknown to the CPU) from the lower to the upper ROM page.  This common code is the link between both pages.  We load a menu option number into the [D] register, jump to the "Switching Routine", it is picked up in the HIGH page and processed in the normal way depending on the [D] menu number passed to it. 

When done, we jump to the ACTIVETE_LOW PAGE which lowers the LA13 line  and again, unknown to the CPU it  ends up in the LOW PAGE.  This code is in purple above. It takes a little time to really understand this process.  Remember the CPU does not know anything about this process. After the port input is done,  the CPU does whatever the next opcode in that ROM (page) requires.    

This facility allows us plenty of future space to write quite elaborate functions in the 4K (now 8K) ROM space between F000H and FFFFH on the V2 CPU board.

There is however one catch, programming the ROMs is quite tricky.  You have to place the 2 segments of code exactly as shown in the above diagram.   You are already familiar by now I assume of burning a ROM.   The added twist here is we need to place two files in the ROM. MASTER0.HEX in the lower page  and MASTER1.HEX in the upper page.  You have to be careful when you load up the second file you don't overwrite the first file.

Different PROM Burners probably have different ways of doing this. Here is the process for a  Wellon VP-290 (or VP299) with 28C64's EEPROMS :-

Assemble and make two .HEX files, MASTER0.HEX and MASTER1.HEX.  
Load the file MASTER0.HEX with the following settings:

For File Mode use "Normal" and Clear Buffer Options = Enable
Leave the "To Buffer Address (HEX) as 0000
Set the "File Address(Hex) as F000 and the
For "Auto Format Detect" use Intel
Leave the File size (for a 28C64) to 2000

Load the file MASTER1.HEX with the following settings:

For File Mode use "Normal" and Clear Buffer Options = Disable
Set the "To Buffer Address (HEX) as 1000
Set the "File Address(Hex) as F000
For "Auto Format Detect" use Intel
Set the File size (for a 28C64) to 1000

Program ("Burn" ) the above ROM code.
With this dual page feature you can extended list of Monitor options. The HIGH PAGE option currently only uses the "X" XModem command.  Obviously if you are using the V1 Z80 CPU Board or only burn in the MASTER0.HEX they will not be available.  The monitor code will detect this and warn you.  Here is how the monitor menu looks:-
  Master menu V5.4

One subtle point, The CPM program HEXCOM (which converts a .HEX file to a .com) file behaves unexpectedly.  If you set a our MASTER0.Z80 program assembly org  at say 100H the program will generate a .com (.bin) file correctly and you can use XModem to load it to RAM at 100H and run it with the Monitor "G" command.  This is very useful for testing monitor changes -- instead of burning a new ROM each time.   If however you set the org to 1000H,  you have to subtract 100H bytes from the load location of the .com file. So to run such a program at 1000H you would load it at F00H in RAM with XModem.

Rich Camarda noticed that when using the Serial Board as the Console, (with the I/O Byte set as 11011111), and no Propeller Board in the system, you get a constant scrolling cursor. The Serial Board functions well in all other aspects. If you have the Propeller Video board in the system along with the Serial Board, the output to the console goes to both, and the Serial terminal works fine. Rich modified the console I/O routines to fix theis bug. The patched version of the Master Z80 can be obtained below. Basically he added 3 lines to the beginning of each console routine, and put some of the serial calls at the bottom.  

Versions 5.3 or later of Master.Z80 has corrected the above error.  Now, if bit 5 of the IOBYTE port is 0 the monitor will assume the Serial port on our Serial-IO board is the console. If no IOBYTE port is present or bit 5 of the IOBYTE port is 1 then the monitor will assume that our Propeller driven Console IO board is the Console.
PDF FILE OF THE MASTER Z80 MONITOR (Using MM58167 Clock Chip)   (V4.57   1/5/2013)
MASTER Z80 MONITOR SOFTWARE (Using MM58167 Clock Chip)  (V4.57   1/5/2013)

PDF FILE OF THE MASTER Z80 MONITOR  V4.7  (Using DS12887 Clock Chip)    (V4.7   3/28/2012)
"MASTER.Z80" MONITOR SOFTWARE   V4.7  (V4.7, FINAL, 11/07/2011)

MOST CURRENT VERSION PDF FILE OF THE MASTER Z80 MONITOR  V5.2 (Using two 4K Pages)    (V5.2  12/17/2016)
MOST CURRENT "MASTER.Z80" MONITOR V5.2 SOFTWARE  (Using two 4K pages)  (V5.2 12/17/2016)

MASTER.Z80 MONITOR with Serial only Console I/O routines  (V1.0     6/2/2016)

TEXT FILE OF THE MASTER Z80 MONITOR  V5.3  (Using DS12887 Clock Chip)    (V5.3   12/4/2017)
   (V5.3, 12/4/2017)

TEXT FILE OF THE MASTER0 Z80 MONITOR  V5.4  (Using DS12887 Clock Chip & LOW/HIGH PAGES)    (V5.4   12/20/2017)
TEXT FILE OF THE MASTER1 Z80 MONITOR  V5.4  (Using DS12887 Clock Chip & LOW/HIGH PAGES)    (V5.4   12/20/2017)
    (V5.4, 12/20/2017)

This page was last modified on 12/30/2017