On AVRs, each 8-bit/pin port consists of three registers: DDx, PORTx, and PINx. DDx sets the direction, PORTx the output state (if output) or pull-up (if input), and PINx reflects the actual pin states. A trick is that writing to PINx toggles the corresponding bits in PORTx.
This leads to a surprising way to control unipolar stepper motors, when all four pins are in the same port. You need two byte variables: one with the bits corresponding to the four pins set (say pins), and the other (say next) initialized to the bits connected to the same coil, i.e. A1+A2. At initialization time, the output pins are initialized to one end of each coil, i.e. A1+B1 for example.
The trick is that to advance the motor in the current direction, you do just
PINx = next;
next ^= pins;
To reverse the direction, you simply do an extra next ^= pins;.
Funky, eh? The same trick is available on ARM cores with toggle registers. But the AVR version certainly leads to obscure code hard to fathom what it does, unless one knows about this trick beforehand.
(If we start with pins=0b1111, next=0b1100, and PORTx=0b1010, the sequence the above generates in PORTx is 0b1010, 0b0110, 0b0101, 0b1001, repeating; this works for a pin order A1 A2 B1 B2 as OP uses.)