Arduino PORTx/PINx defines

I am modifying a driver (Panstamp) for CC110L radio module to be able to use it on Mega as well. I as thinking to send the PORTx/PINx values as arguments to the init function as it uses them directly. This did not work though because the driver sees another value of PIND than what Arduino gives...

Printed directly before and inside the init function:

Arduino PIND:3
Arduino PORTD:0
Arduino PINB:13
Arduino PORTB:4
PIND: 1
PORTD: 0
PINB: 13
PORTB: 4

The value 1 of PIND (digital pin 2, interrupt 0 on Uno) is what works in the driver, but where does Arduino get 3?

those aren't defines. Those are hardware registers (well, technically pointers to them) - the values you get when you look at PINx registers depend on the values of the pins (digitalRead() converts pin number to port and bit number, and then looks at the appropriate PINx register, and masks off the other bits). PORTx registers are what you write to to set whether to output a high or low, DDRx registers set whether pin is input or output, etc (digitalWrite(), pinMode() etc wrap these)

PIND will be 3 if D0 and D1 are high. Since those two pins are the UART pins, this should be the case when the UART is enabled and no bit is currently being sent down the UART. If PIND=1, then D0 is high, D1 is low. Since D1 is the UART TX pin, if a bit is currently being sent by the UART, ie, making it go low, that would do it.

In your example, if you touch the +5v pin with one finger, and other PD pins with another finger while reading PIND you'll see other values (in this context, your body is acting as a high value resistor, and since the pins are high impedance (inputs) at this point, that's enough to pull them up to 5v)

OK yes I just realized the register address cant be that low, so it is somewhat "dumbed down"...

Actually - the addresses of the registers are almost that low.

The first 256 bytes in the address space are reserved for registers; the first 32 bytes are those "32 x 8 General Purpose Working Registers" on the feature list, and right after that, the PINx/PORTx/DDRx registers start. The SRAM starts at 0x0100. See fig 8.3 on pg19 of datasheet, and the register summary on pages 612 ~ 615.

But it's very rare that you care what the actual address of a register is.

at that address you add offset, 0x20, now for direct memory write at portb, bit 6 (Arduino uno D13)

(*(volatile byte*)(0x25)) |= 0x20;

I have somewhat of a problem with these still, the code has these macros defined:
(PORT_CC_SS as redefines of PORTB etc).

// Select (SPI) CC1101
//#define cc1101_Select() bitClear(*port_ss, bit_ss)
#define cc1101_Select() bitClear(PORT_CC_SS, BIT_CC_SS)
// Deselect (SPI) CC1101
//#define cc1101_Deselect() bitSet(*port_ss, bit_ss)
#define cc1101_Deselect() bitSet(PORT_CC_SS, BIT_CC_SS)

But this does not work when I send the port addresses down as (volatile uint8_t *)&PORTB, verified that the addresses print the same as the PORTx macro.
Obviously I cannot manipulate the register as value of the pointer in this way. How can it work with the Arduino macros?
Need to write own bitSet/Clear functions that operate on references?

If you pass a pointer you have to explicitly dereference to see/set the register values.

Don't ask us how it works(!), you can ask the source code - since its
an open source platform - wiring_digital.c and wiring_analog.c are the relevant files for
this stuff. Once you understand how digitalRead, digitalWrite and pinMode work, you'll be
in a position to roll your own variants. The main complication is that these functions have
to work in interrupt routines as well as the main body of the sketch, meaning interrupts are
briefly disabled in digitalWrite and pinMode to make them atomic.