-
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
- 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 to port z80ctrl to another microcontroller simply by modifying the macros here (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.h contains the pin definitions for the SPI functions and macros for controlling the SPI chip selects.
- 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 implements an interrupt-driven buffered UART driver. The
USART0_RX_vect
ISR writes received data to the RX ring buffer and theUSART0_UDRE_vect
ISR transmits data written to the TX ring buffer. Theuart_getc
anduart_putc
insert and remove characters from RX and TX ring buffers. These low-level functions are wrapped in a higher level "cooked" terminal mode implementation inuart_getchar
anduart_putchar
. The UART is initialized to a particular baud rate usinguart_init
.
- 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 original Altair disk images and the format used by the SIMH AltairZ80 emulator. Each disk format requires a different bootloader running on the Z80.
- dbl.h contains Z80 machine code for the Altair Disk Boot Loader that I found on the Altair Clone Project's site.
- simhboot.h contains Z80 machine code for the SIMH bootloader, the source for which was found in the DISKBOOT.MAC file on the SIMH CP/M 2.2 disk image on the AltairZ80 website.
-
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 the Z80 machine code for the Altair 1K Monitor, which 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 initializes UART, Z80 bus, and starts the command-line monitor interface.