How do I read the Arduino Mega Ports?

I hate to be asking this but Iam having a hard time finding good documentation.

I want to be able to set PORT A on my Mega to open collector OUTPUT.
What is the command to do so? Where is the Mega Port commands listed?

Once set to Output, I think I can then read back the output value, yes? I have a pull up resistor.

“I hate to be asking this but Iam having a hard time finding good documentation.”
The data sheet for the Atmega2560 is chock full of info:

You could also look at Direct Port Manipulation.
https://www.arduino.cc/en/Reference/PortManipulation
which is also in the datasheet.

“open collector” would imply BJT transistors.
The Mega is made from CMOS, so if anything it would be “open drain”.

I don’t think the Mega supports open drain on pins except SCL & SDA for I2C operation.

Once set to OUTPUT, the levels will be 0/5V. No point reading them back as you would have written them, yes?

You can sort of fake open drain by leaving the port as an INPUT, and then changing to OUTPUT when you want to control it as an output, then changing the port back to an input.

I didn't get the answer I was seeking.

How do I read a port? Is it.. x = PORTD; or do I use a digital read command like digitalread(PORTD) or what.

Specifically, what is the command the read port D as a byte?

Do I have to setup Port D as output ? HOw is this done?