Block I/O: The Fastest Way to Talk to Hardware
The Z80 features a unique set of block I/O instructions designed to quickly move data between a memory block and a single, fixed I/O port. These are crucial for fast operations like dumping screen memory to a display controller or quickly reading keyboard buffers.
The Register Setup: Block I/O relies on the following registers for definition:
Register Pair | Purpose in Block I/O |
---|---|
HL | Memory Address (Source or Destination) |
B | Counter (Number of transfers to perform) |
C | I/O Port Address (The fixed hardware port) |
Input Block Commands (Reading from Port)
The INIR
(Input, Increment, Repeat) and INDR
(Input, Decrement, Repeat) commands read data from the port specified by C and store it into memory pointed to by HL.
Instruction | Action Sequence | Description |
---|---|---|
INIR |
1. (HL) ← (C) (Input) #2. HL++ (Increment) #3. B-- (Decrement) #4. Repeat until B = 0 . |
Reads B bytes from port C into memory, starting at HL and moving forward. |
INDR |
Same as INIR, but HL-- (Decrement) in step 2. |
Reads B bytes from port C into memory, starting at HL and moving backward. |
Example: Reading 256 bytes from a Status Port
LD HL, BUFFER_START ; Memory buffer start
LD C, 40H ; I/O Port 40H
LD B, 256 ; Transfer 256 bytes
INIR ; High-speed read operation
Output Block Commands (Writing to Port)
The OTIR
(Output, Increment, Repeat) and OTDR
(Output, Decrement, Repeat) commands write data from the memory pointed to by HL to the fixed port specified by C.
Instruction | Action Sequence | Description |
---|---|---|
OTIR |
1. (C) ← (HL) (Output) #2. HL++ (Increment) #3. B-- (Decrement) #4. Repeat until B = 0 . |
Writes B bytes from memory (starting at HL) to port C. |
`OTDR&grave |