-
Notifications
You must be signed in to change notification settings - Fork 14
Software Design Notes
J.B. Langston edited this page May 20, 2018
·
18 revisions
defines.h contains various compile-time configuration options:
- GPIO ports and pin numbers for various bus signals.
- A few others such as baud rate and number of emulated drives are also configured here.
-
bus.h provides macros to set the address and data bus and read or toggle the various control lines. This abstracts control of these signals away from the specific hardware implementation. It should be possible, for example, to port this code to another microcontroller simply by modifying
bus.h
anddefines.h
(for example ATmega2560 without an IO expander). - bus.c builds on top of these macros to provide functions to intialize the bus, control the clock, and enter and exit bus-master mode.
- memory.c contains functions to read and write to the external SRAM that is shared with the Z80. For now, it also contains several higher-level memory related functions such as memory hex dump that probably belong elsewhere.
- z80.c contains the Z80 real-time debugger and the run loop for the Z80 that handles IO requests.
- spi.c contains a few simple functions for initializing the SPI bus and transferring data. These functions are used by higher-level functions specific to the IO expander and SD card.
- iox.h contains register definitions for the MCP23S17 I/O expander that were taken from its datasheet. iox.c provides some simple utility functions to make reading and writing these registers a little easier.
- mmc_avr_spi.c contains the low-level SPI interface with the SD card that is used by FatFS. This code comes from the FatFS example project.
-
uart.c contains
uart_putc
anduart_getc
functions that store data to be sent or received in ring buffers. Receive and transmit interrupt service routines write and read data to and from these buffers. The implementation of the ring buffers comes from the FatFS AVR demo project. These low-level functions are wrapped in a higher level line editing function borrowed from the avr-libc stdio demo.
- I use the FatFS library to provide access to a FAT32-formatted SD-card containing ROM and disk images for the Z80. FatFS comprises the files
ff.c
,ffsystem.c
,ffunicode.c
, andmmc_avr_spi.c
.
- diskemu.c emulates an Altair 88-DISK controller and is based on code from the SIMH AltairZ80 emulator. IORQs to the standard 88-DISK registers select sectors, check status, and cause bytes to be read or written to the file that has been mounted on the emulated drive.
- The emulated drive is compatible with disk images from both SIMH and the Altair Clone project. Each disk format requires a different bootloader.
- The
dboot
command uses the Altair Disk Boot Loader that I found on the Altair Clone Project's site. - The
sboot
command uses the bootloader from the Altair Z80 emulator, the source for which was found in the DISKBOOT.MAC file on the CP/M 2.2 disk image distributed on Peter Schorn's website.
- The
-
cli.c contains the command-line monitor interface. The
cli_loop
function reads a line from the UART and tokenizes the command. It looks the command names up in a table and calls the corresponding function via a function pointer. The main loop passes parameters to all the functions via a standard argc/argv mechanism. It is up to each function to parse and interpret the individual parameters. -
disasm.c contains the
disasm
function that disassembles a single instruction. It uses a large if-else tree to decode general classes of instructions, and then uses lookup tables for specific registers, condition codes, ALU operations, etc.disasm
pulls in bytes as needed via a function pointer that is passed to it, allowing it to receive instructions from different sources. This file also containsdisasm_mem
function which reads data from the external SRAM into a buffer and callsdisasm
to disassemble each instruction.disasm
is also called by the debugger inz80.c
to perform real-time disassembly of instructions as they execute. -
ihex.c contains functions to read and write individual Intel HEX records. Driver functions in
cli.c
that read records from either the terminal or a file and call these functions on each one. -
altmon.h
contains an embedded copy of the Altair 1K Monitor that can be loaded into external RAM and launched by the z80ctrl monitor. I found the source on the Altair Clone Project's download site. The comments say that it is based on the 2.0c Monitor by Vector Graphic. I may remove it at some point once all its functionality has been duplicated by the z80ctrl monitor. -
z80ctrl.c
contains the main function that starts initializes the bus and starts the command-line monitor interface.