Banking Z80 Systems Copyright 1994, Softaid, Inc. -------------------------------------------------------------------------- Abstract A lot of Z80 systems are still around, and are running out of address space. One alternative is to switch to Zilog's Z180, which has a 1 Mb address range. Another is to add banking to your Z80. Here's a way to debug if you select the second option. -------------------------------------------------------------------------- Most Z80/Z180 compilers support bank switching on either a Z80 or a Z180, though few users ever use this feature on a Z80. In this example we'll look at bank switching with the Software Development Systems C compiler. Note that Softaid supports bank-switching with other compilers as well - call for more information. SDSI's compiler vectors all banked calls through a short routine they provide that sits in the non-banked ROM. This routine looks like: _call: push af ; bank part of ret address push hl ld hl,_ret ex (sp),hl jp (iy) ; ret _ret: pop bc ; b is return bank ret SLD needs a little more information about your program to properly track banking on a Z80. In particular, you must provide 3 numbers: * SLD_BANK - Address lines A16-A19 * SLD_BSTART - Start address of banked area in the processor's logical space * SLD_BEND - End address of banked area in the processor's logical space. For example, suppose any reference to logical addresses between 8000 and BFFF are remapped to your hardware to point to an extended address (i.e., your hardware asserts A16-A19). Then, set SLD_BSTART to 8000 and SLD_BEND to 0C000, and make sure your code always keeps the current A16-A19 values in SLD_BANK. Do this by modifying the above code as follows: SLD_BANK: db 0 ; active bank SLD_BSTART: dw xxx ; base address of banked area SLD_BEND: dw xxx ; end address (not inclusive) of banked area _call: push af ; bank part of ret address push hl ld a,c ; a=bank number (from linker) out (port),a ; remap - do what ever your hardware needs ld (SLD_BANK),a; save bank ld hl,_ret ex (sp),hl jp (iy) ; ret _ret: pop bc ; b is return bank ld a,b out (port),a ; remap hardware ret If you compile with the "-s ptrf=4" option the compiler vectors all function calls through _call. _call is invoked with C=bank number and IY=address of the function being called. Bank numbers are assigned at link time in the linker specification file. To handle larger address spaces with the UEM-Z80, connect the extra address lines to the Z80 pod (A0-23 are brought to the pod, even though only A0-15 are used for most Z80 systems). SLD uses physical address to set breakpoints; the SDSI compiler provides SLD with this information. So, if you set a breakpoint on a routine that is not even mapped in, SLD uses the always-valid physical address. However, when you hit a breakpoint we read the PC, which is only 16 bits, to determine the breakpoint address. This is true if you stop emulation at any random point as well. 16 bits is not enough to tell us where the break was in physical address space. Therefore, SLD will read the bank number from RAM (from the LD (SLD_BANK),A) shown in the code above. This will let SLD correlate physical and logical addresses. Note that SLD defaults to no banking in Z80 systems. Invoke it with the -BANKZ80 command line option to enable banking. Do this by clicking on the SLDW icon, then selecting FILE:PROPERTIES:COMMAND LINE when in the Windows Program Manager. Return to application note list. -------------------------------------------------------------------------- Softaid, Inc., 8310 Guilford Road, Columbia, MD USA. Phone: (410) 290-7760, Fax: (410) 381-3253, e-mail: info@softaid.net