is the DDR pinout the same as the PORT pinout?

Right now, I have my computer able to write to the arduino MEGA 2560 pins by sending commands and doing port modification. (PORTA, PORTB, PORTC, etc.)

It works great, and is very, very fast. (will be faster when I create the code to combine multiples changes from the computer.)

I'm trying to get it to do the same with pin modes, and it doesn't quite seem to work the same way. I'm trying to do this using DDRA, DDRB, etc. My code for sending a "change mode" signal is essentially the exact same as my "digital write" code. I only changed which command it does to that pin.

However, I find that it doesn't work in any consistent way at all.

For instance, I have the code to set up pins 30 through 46 as outputs, as these are associated with my relay bank.

However, when cycling through each pin, I get stuff along the lines of: "set pin 31 as output" yields no change, "set pin 43 to output" turns on 6 of the pins, and "set pin 44 to output" turns on the first 8 pins. It's basically a garbled mess.

So does DDR work the same way as PORT?

If not, I might just change out some code to use pinMode() instead of DDR. The nice thing is that the code is currently really clean and straightforward using port modification.

DDRx tells the pins whether they are input pins or output pins. Data Direction Register.
Easy to mess up. I just use pinMode in setup to set INPUT, OUTPUT, or INPUT_PULLUP,
and then use PINx to read a port, and PORTx to write to a port.
PINx can also be used to toggle an output bit.

PIND = 0b00000100; // toggle PORTD bit 2

I usually use
PORTD = PORTD | 0b00000100; // set bit 2, leave rest unchanged
PORTD = PORTD & 0b11111011; // clear bit 2, leave rest unchanged
so I don't have to worry about the bit being in an unknown state when I toggle it.

I might just do that, since data direction isn't exactly time-sensitive, nor does it need to be tightly synced.

I have my set up so the computer sends out 3 bytes: COMMAND-FILTER-VALUE. Then it falls through a switch statement with read, write, and mode commands for each register.

For instance, here's what happens when the command byte is DIGITAL_WRITE_A (which is #defined as 10):

case DIGITAL_WRITE_A:
				while(Serial.available() < 2){}
				portFilter = Serial.read() & portWriteAccess[0];
				portState[0] = (portState[0] & ~portFilter) | (Serial.read() & portFilter);
				PORTA = portState[0];
				break;

The nice thing is how up to 8 pins can be handled all at once via boolean logic. In this case, if my filter is 1, it uses the new state recieved by serial. if the filter is 0, it keeps its current state. The portWriteAccess is a filter I use to prevent writing to IO pins.

DDRx should work in the same way as PORTx in terms of bit orders. If you don't want the pullups to turn on, you should also write the corresponding PORTxn bits to 0.

One little unrelated thing though:
Why this:

portState[0] = (portState[0] & ~portFilter) | (Serial.read() & portFilter);
PORTA = portState[0];

When you can just do:

PORTA = (PORTA & ~portFilter) | (Serial.read() & portFilter);

If you don't want the pullups to turn on, you should also write the corresponding PORTxn bits to 0.

That's lacking some detail:
"If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTxn has to be written logic zero
or the pin has to be configured as an output pin."
(my bolding added)