You're absolutely correct! I should have mentioned that capability. Yes, on the Amiga, you can change the direction of the parallel port data lines by programming the CIA chip directly.
CIA Port Direction Control
The Amiga's parallel port data lines (D0-D7) are connected to Port A of CIA-A (on most models). The direction of these lines is controlled by the CIAPRA direction register (CIAPDDRA).
- CIAPDDRA (Port A Data Direction Register)
- Bit = 1: Pin is output
- Bit = 0: Pin is input
Default Configuration
By default, CIAPDDRA is set to $FF (all bits = 1), making all 8 data lines outputs:
CIAPDDRA = %11111111 (binary) = $FF (hex)
Changing to Input Mode
To use the data lines for input, you would set the corresponding bits to 0:
// Set all data lines as inputs
*CIAPDDRA = 0x00; // All pins = input
// Set some as input, some as output
*CIAPDDRA = 0xF0; // D7-D4 = output, D3-D0 = input
Reading the Data
Once configured as input, you read the actual data from CIAPRA (Port A Data Register):
UBYTE inputData;
*CIAPDDRA = 0x00; // Set as input
inputData = *CIAPRA; // Read the data
Hardware Considerations
However, there are important caveats:
-
External Pull-ups: The data lines may need external pull-up resistors when used as inputs, as the CIA inputs are not internally pulled up.
-
Bus Contention: If you're connecting to a device that also drives these lines (like a printer), you need to be careful about bus contention.
-
Signal Levels: Ensure voltage levels are compatible (TTL 0-5V).
Integration with parallel.device
The standard parallel.device doesn't typically change the port direction - it assumes output mode. To use input mode, you would either:
- Direct CIA programming (bypassing parallel.device)
- Custom device driver that manages direction switching
- Hardware adapter that handles bidirectional communication
Example Code Snippet
// Assuming CIA-A base address
#define CIAAPRA 0xBFE001
#define CIAPDDRA 0xBFE201
// Set data lines as input
*(volatile UBYTE*)CIAPDDRA = 0x00;
// Read data from parallel port
UBYTE data = *(volatile UBYTE*)CIAAPRA;
Why This Isn't Common
- Risk of hardware damage if not done carefully
- Standard peripherals (printers) don't expect bidirectional data lines
- Other I/O options (serial, joystick ports) are safer for input
- OS assumes output mode for parallel port
So yes, you're absolutely right - the Amiga hardware supports bidirectional parallel port data lines through CIA programming, though it's not commonly used due to the risks and limitations involved.