You're absolutely correct! The CIAPDDRA register (Data Direction Register A of the CIA-B chip) is used to control the input/output direction of the parallel port lines on the Amiga. This allows the parallel port to operate in bidirectional mode for custom hardware or peripherals. Let’s break this down:
CIAPDDRA and Parallel Port Direction Control
Parallel Port Pin Mapping (DB25 Female, Amiga Side)
The parallel port pins are mapped to CIA-B’s Data Register A (DDRA) at $D004 and CIAPDDRA at $D010. Here’s how they correspond:
| Amiga Parallel Port Pin | CIA-B DDRA Bit | Signal Name | Typical Use |
|---|
| D0 (Pin 2) | Bit 0 | Data Bit 0 | Bidirectional data line |
| D1 (Pin 3) | Bit 1 | Data Bit 1 | Bidirectional data line |
| D2 (Pin 4) | Bit 2 | Data Bit 2 | Bidirectional data line |
| D3 (Pin 5) | Bit 3 | Data Bit 3 | Bidirectional data line |
| D4 (Pin 6) | Bit 4 | Data Bit 4 | Bidirectional data line |
| D5 (Pin 7) | Bit 5 | Data Bit 5 | Bidirectional data line |
| D6 (Pin 8) | Bit 6 | Data Bit 6 | Bidirectional data line |
| D7 (Pin 9) | Bit 7 | Data Bit 7 | Bidirectional data line |
| STROBE (Pin 14) | Bit 0 (shared?) | Strobe (output) | Printer data strobe |
| SELECT (Pin 1) | Bit 7 (shared?) | Printer Select (input) | Peripheral selection status |
Note: Some pins (e.g., STROBE, SELECT) share bits with the data lines, depending on the Amiga model and hardware configuration. This can lead to conflicts if not managed carefully.
Example: Setting Parallel Port to Input Mode
To read from the parallel port (e.g., for custom hardware), you must set the corresponding bits in CIAPDDRA to 0 (input). For example, to read from all 8 data lines (D0-D7):
#include <exec/io.h>
#include <devices/parallel.h>
#define CIAPDDRA 0xD010
void set_parallel_to_input(void) {
// Set all data lines (D0-D7) as inputs (0)
// Write $00 to CIAPDDRA (all bits 0 = input)
WriteWord(CIAPDDRA, 0x00);
}
After setting the direction, you can read the data from the parallel port using DDRA at $D004:
unsigned char data;
// Read from parallel port data lines (D0-D7)
data = ReadWord(0xD004); // 0xD004 = CIAB's Data Register A
Important Considerations
-
Shared Pins:
- Pins like STROBE (Pin 14) and SELECT (Pin 1) may share bits with data lines. Setting these as inputs could interfere with standard printer operations.
- Always check the Amiga model’s hardware documentation (e.g., Amiga Technical Manual).
-
Bidirectional Conflicts:
- If a pin is set as an input but the peripheral drives it as an output, a short circuit could occur. Ensure the peripheral is designed for bidirectional operation.
-
AmigaOS Device Drivers:
- Using
parport.device may override direct register access. For low-level control, you might need to disable the driver or use cam.library for direct hardware access.
-
Hardware Variations:
- The A500, A1000, and A1200 have slightly different parallel port implementations. For example, the A1200 uses a PC-compatible parallel port, which may behave differently.
Practical Use Case
A common example of bidirectional use is interfacing with parallel port dongles or custom sensors. For instance, to read from a custom sensor connected to D0-D7:
- Set
CIAPDDRA to 0x00 (all inputs).
- Read the value from
DDRA ($D004) to get the sensor data.
- Set
CIAPDDRA back to 0xFF (all outputs) if resuming normal printer operations.
Summary
CIAPDDRA ($D010) controls the direction of the parallel port lines.
- 1 = Output, 0 = Input for each bit.
- Use this register to enable bidirectional communication for custom hardware.
- Always account for shared pins and hardware-specific quirks in your code.
This level of control makes the Amiga’s parallel port highly flexible for retrocomputing projects! 🚀