-
Notifications
You must be signed in to change notification settings - Fork 14
Software Design Notes
J.B. Langston edited this page Jun 27, 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, enter and exit bus-master mode, and direct memory access.
- z80.c contains the Z80 real-time debugger and the run loop for the Z80 that handles IO requests.
- iorq.c handles dispatching I/O requests to various other functions based on the port address used. It also controls the handoff of the bus back to the Z80 after the IORQ is done.
- 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
. sioemu.c provides translation functions to allow the UART to simulate the registers on a Motorola ACIA or a Zilog SIO chip. - flash.c provides support for writing and erasing SST parallel flash chips used on the 512K RAM/ROM board.
- tms.c provides basic support for the TMS9918A video chip. It provides methods to transfer data to and from the TMS9918's VRAM and to set the TMS9918's configuration registers. It initializes the TMS9918A to text mode and provides a function to output a character to the TMS9918A, so that it can be used with avr-libc's stdio facilities.
- 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. z80ctrl provides a native bootloader that will load the disk's boot sector directly into memory so a separate boot loader is not required.
- 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. SIMH's CP/M BIOS still expects the SIMH bootloader to be present in memory though, so z80ctrl still loads it when a SIMH disk is booted.
-
cli.c contains the main loop that runs 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. - util.c contains random utility functions that didn't fit anywhere else.