digitalWriteFast change for Atmega1284P / Bobuino pinout

What do I need to add to the digitalWriteFast library to give it Atmega1284P support?
It compiles in 1.8.5 with the Mightycore 1284 and Bobuino pinout, but I don't think it's actually doing anything since there's no section like this
#if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
for the 1284P in it.
I'd got it added to the Stepper.h library to replace the digitalWrite() statements.

If something better has become available since 2010 to replace this, I could use that instead.

Thanks

PA0 to PA7 are D21, 20, 19, 18, 17, 16, 15, 14
PB0 to PB7 are D4, 5, 6, 7, 10, 11, 12, 13
PC0 to PC7 are D22, 23, 24, 25, 26, 27, 28, 29
PD0 to PD7 are D0, 1, 2, 3, 30 ,8 ,9 ,31

I commented out the first 2 lines to get it to compile.
https://code.google.com/archive/p/digitalwritefast/downloads
(forum may stick extra characters at start and end of that, hover over it to check)

// #include "WProgram.h" 
// #include <wiring.h>


#define BIT_READ(value, bit) (((value) >> (bit)) & 0x01)
#define BIT_SET(value, bit) ((value) |= (1UL << (bit)))
#define BIT_CLEAR(value, bit) ((value) &= ~(1UL << (bit)))
#define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit))


#if !defined(digitalPinToPortReg)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Arduino Mega Pins
#define digitalPinToPortReg(P) \
(((P) >= 22 && (P) <= 29) ? &PORTA : \
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
(((P) >= 30 && (P) <= 37) ? &PORTC : \
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \
(((P) >= 54 && (P) <= 61) ? &PORTF : \
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
(((P) == 14 || (P) == 15) ? &PORTJ : \
(((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL))))))))))


#define digitalPinToDDRReg(P) \
(((P) >= 22 && (P) <= 29) ? &DDRA : \
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
(((P) >= 30 && (P) <= 37) ? &DDRC : \
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \
(((P) >= 54 && (P) <= 61) ? &DDRF : \
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
(((P) == 14 || (P) == 15) ? &DDRJ : \
(((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL))))))))))


#define digitalPinToPINReg(P) \
(((P) >= 22 && (P) <= 29) ? &PINA : \
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
(((P) >= 30 && (P) <= 37) ? &PINC : \
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \
(((P) >= 54 && (P) <= 61) ? &PINF : \
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
(((P) == 14 || (P) == 15) ? &PINJ : \
(((P) >= 62 && (P) <= 69) ? &PINK : &PINL))))))))))


#define __digitalPinToBit(P) \
(((P) >=  7 && (P) <=  9) ? (P) - 3 : \
(((P) >= 10 && (P) <= 13) ? (P) - 6 : \
(((P) >= 22 && (P) <= 29) ? (P) - 22 : \
(((P) >= 30 && (P) <= 37) ? 37 - (P) : \
(((P) >= 39 && (P) <= 41) ? 41 - (P) : \
(((P) >= 42 && (P) <= 49) ? 49 - (P) : \
(((P) >= 50 && (P) <= 53) ? 53 - (P) : \
(((P) >= 54 && (P) <= 61) ? (P) - 54 : \
(((P) >= 62 && (P) <= 69) ? (P) - 62 : \
(((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \
(((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \
(((P) == 19) ? 2 : \
(((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \
(((P) == 2) ? 4 : \
(((P) == 3 || (P) == 4) ? 5 : 7)))))))))))))))


// 15 PWM
#define __digitalPinToTimer(P) \
(((P) == 13 || (P) ==  4) ? &TCCR0A : \
(((P) == 11 || (P) == 12) ? &TCCR1A : \
(((P) == 10 || (P) ==  9) ? &TCCR2A : \
(((P) ==  5 || (P) ==  2 || (P) ==  3) ? &TCCR3A : \
(((P) ==  6 || (P) ==  7 || (P) ==  8) ? &TCCR4A : \
(((P) == 46 || (P) == 45 || (P) == 44) ? &TCCR5A : 0))))))
#define __digitalPinToTimerBit(P) \
(((P) == 13) ? COM0A1 : (((P) ==  4) ? COM0B1 : \
(((P) == 11) ? COM1A1 : (((P) == 12) ? COM1B1 : \
(((P) == 10) ? COM2A1 : (((P) ==  9) ? COM2B1 : \
(((P) ==  5) ? COM3A1 : (((P) ==  2) ? COM3B1 : (((P) ==  3) ? COM3C1 : \
(((P) ==  6) ? COM4A1 : (((P) ==  7) ? COM4B1 : (((P) ==  8) ? COM4C1 : \
(((P) == 46) ? COM5A1 : (((P) == 45) ? COM5B1 : COM5C1))))))))))))))


#else


// Standard Arduino Pins
#define digitalPinToPortReg(P) \
(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
#define digitalPinToDDRReg(P) \
(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
#define digitalPinToPINReg(P) \
(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
#define __digitalPinToBit(P) \
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))


#if defined(__AVR_ATmega8__)
// 3 PWM
#define __digitalPinToTimer(P) \
(((P) ==  9 || (P) == 10) ? &TCCR1A : (((P) == 11) ? &TCCR2 : 0))
#define __digitalPinToTimerBit(P) \
(((P) ==  9) ? COM1A1 : (((P) == 10) ? COM1B1 : COM21))
#else  //168,328


// 6 PWM
#define __digitalPinToTimer(P) \
(((P) ==  6 || (P) ==  5) ? &TCCR0A : \
(((P) ==  9 || (P) == 10) ? &TCCR1A : \
(((P) == 11 || (P) ==  3) ? &TCCR2A : 0)))
#define __digitalPinToTimerBit(P) \
(((P) ==  6) ? COM0A1 : (((P) ==  5) ? COM0B1 : \
(((P) ==  9) ? COM1A1 : (((P) == 10) ? COM1B1 : \
(((P) == 11) ? COM2A1 : COM2B1)))))
#endif  //defined(__AVR_ATmega8__)

#endif  //mega
#endif  //#if !defined(digitalPinToPortReg)

#define __atomicWrite__(A,P,V) \
if ( (int)(A) < 0x40) { bitWrite(*(A), __digitalPinToBit(P), (V) );}  \
else {                                                         \
uint8_t register saveSreg = SREG;                          \
cli();                                                     \
bitWrite(*(A), __digitalPinToBit(P), (V) );                   \
SREG=saveSreg;                                             \
} 

#ifndef digitalWriteFast
#define digitalWriteFast(P, V) \
do {                       \
if (__builtin_constant_p(P) && __builtin_constant_p(V))   __atomicWrite__((uint8_t*) digitalPinToPortReg(P),P,V) \
else  digitalWrite((P), (V));         \
}while (0)
#endif  //#ifndef digitalWriteFast2


#if !defined(pinModeFast)
#define pinModeFast(P, V) \
do {if (__builtin_constant_p(P) && __builtin_constant_p(V)) __atomicWrite__((uint8_t*) digitalPinToDDRReg(P),P,V) \
else pinMode((P), (V)); \
} while (0)
#endif

#ifndef noAnalogWrite
#define noAnalogWrite(P) \
	do {if (__builtin_constant_p(P) )  __atomicWrite((uint8_t*) __digitalPinToTimer(P),P,0) \
		else turnOffPWM((P));   \
} while (0)
#endif		

#ifndef digitalReadFast
	#define digitalReadFast(P) ( (int) _digitalReadFast_((P)) )
	#define _digitalReadFast_(P ) \
	(__builtin_constant_p(P) ) ? ( \
	( BIT_READ(*digitalPinToPINReg(P), __digitalPinToBit(P))) ) : \
	digitalRead((P))
#endif

You could try the one at Duino-hacks/fastdigitalIO.h at master · WestfW/Duino-hacks · GitHub
I don’t think I’ve tried it on a 1284, and I’m not near a computer at the moment, but it’s designed to be much more portable than previous methods...

Thanks. Here's what I came up with for the first digitalWriteFast.h I found as I was 3/4 thru that already.
There are a few lines in the original with a bunch of )))) to end them, I don't know what's up with that. I couldn't see what the quantity was based on, so I just left them off the added 1284P sections.

I took out the Atmega8 stuff also to fit here.
Compiles ok, runs, I don't know if it actually improves anything, need to pull out a 'scope & check I guess.

// #include "WProgram.h" 
// #include <wiring.h>
/* 1284P pins for Bobuino
PA0 to PA7 are D21, 20, 19, 18, 17, 16, 15, 14
PB0 to PB7 are D4, 5, 6, 7, 10, 11, 12, 13
PC0 to PC7 are D22, 23, 24, 25, 26, 27, 28, 29
PD0 to PD7 are D0, 1, 2, 3, 30 ,8 ,9 ,31
*/

#define BIT_READ(value, bit) (((value) >> (bit)) & 0x01)
#define BIT_SET(value, bit) ((value) |= (1UL << (bit)))
#define BIT_CLEAR(value, bit) ((value) &= ~(1UL << (bit)))
#define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit))

#if !defined(digitalPinToPortReg)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Arduino Mega Pins
#define digitalPinToPortReg(P) \
(((P) >= 22 && (P) <= 29) ? &PORTA : \
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
(((P) >= 30 && (P) <= 37) ? &PORTC : \
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \
(((P) >= 54 && (P) <= 61) ? &PORTF : \
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
(((P) == 14 || (P) == 15) ? &PORTJ : \
(((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL))))))))))

#define digitalPinToDDRReg(P) \
(((P) >= 22 && (P) <= 29) ? &DDRA : \
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
(((P) >= 30 && (P) <= 37) ? &DDRC : \
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \
(((P) >= 54 && (P) <= 61) ? &DDRF : \
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
(((P) == 14 || (P) == 15) ? &DDRJ : \
(((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL))))))))))

#define digitalPinToPINReg(P) \
(((P) >= 22 && (P) <= 29) ? &PINA : \
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
(((P) >= 30 && (P) <= 37) ? &PINC : \
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \
(((P) >= 54 && (P) <= 61) ? &PINF : \
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
(((P) == 14 || (P) == 15) ? &PINJ : \
(((P) >= 62 && (P) <= 69) ? &PINK : &PINL))))))))))

#define __digitalPinToBit(P) \
(((P) >=  7 && (P) <=  9) ? (P) - 3 : \
(((P) >= 10 && (P) <= 13) ? (P) - 6 : \
(((P) >= 22 && (P) <= 29) ? (P) - 22 : \
(((P) >= 30 && (P) <= 37) ? 37 - (P) : \
(((P) >= 39 && (P) <= 41) ? 41 - (P) : \
(((P) >= 42 && (P) <= 49) ? 49 - (P) : \
(((P) >= 50 && (P) <= 53) ? 53 - (P) : \
(((P) >= 54 && (P) <= 61) ? (P) - 54 : \
(((P) >= 62 && (P) <= 69) ? (P) - 62 : \
(((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \
(((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \
(((P) == 19) ? 2 : \
(((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \
(((P) == 2) ? 4 : \
(((P) == 3 || (P) == 4) ? 5 : 7)))))))))))))))

// 15 PWM
#define __digitalPinToTimer(P) \
(((P) == 13 || (P) ==  4) ? &TCCR0A : \
(((P) == 11 || (P) == 12) ? &TCCR1A : \
(((P) == 10 || (P) ==  9) ? &TCCR2A : \
(((P) ==  5 || (P) ==  2 || (P) ==  3) ? &TCCR3A : \
(((P) ==  6 || (P) ==  7 || (P) ==  8) ? &TCCR4A : \
(((P) == 46 || (P) == 45 || (P) == 44) ? &TCCR5A : 0))))))

#define __digitalPinToTimerBit(P) \
(((P) == 13) ? COM0A1 : (((P) ==  4) ? COM0B1 : \
(((P) == 11) ? COM1A1 : (((P) == 12) ? COM1B1 : \
(((P) == 10) ? COM2A1 : (((P) ==  9) ? COM2B1 : \
(((P) ==  5) ? COM3A1 : (((P) ==  2) ? COM3B1 : (((P) ==  3) ? COM3C1 : \
(((P) ==  6) ? COM4A1 : (((P) ==  7) ? COM4B1 : (((P) ==  8) ? COM4C1 : \
(((P) == 46) ? COM5A1 : (((P) == 45) ? COM5B1 : COM5C1))))))))))))))

#else

// Standard Arduino Pins
#define digitalPinToPortReg(P) \
(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
#define digitalPinToDDRReg(P) \
(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
#define digitalPinToPINReg(P) \
(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
#define __digitalPinToBit(P) \
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))

#if defined (__AVR_ATMEGA1284P__)
#define digitalPinToPortReg(P) \
(((P) >= 14 && (P) <= 21) ? &PORTA : \
(((P) >= 4 && (P) <= 7) ? &PORTB : \
(((P) >= 10 && (P) <= 13) ? &PORTB : \
(((P) >= 22 && (P) <= 28) ? &PORTC : \
(((P) >= 0 && (P) <= 3) ? &PORTD : \
(((P) >= 8 && (P) <= 9) ? &PORTD : \
(((P) >= 4 && (P) <= 7) ? &PORTD : \
(((P) >= 30 && (P) <= 31) ? &PORTD : \

#define digitalPinToDDRReg(P) \
(((P) >= 14 && (P) <= 21) ? &DDRA : \
(((P) >= 4 && (P) <= 7) ? &DDRB : \
(((P) >= 10 && (P) <= 13) ? &DDRB : \
(((P) >= 22 && (P) <= 28) ? &DDRC : \
(((P) >= 0 && (P) <= 3) ? &DDRD : \
(((P) >= 8 && (P) <= 9) ? &DDRD : \
(((P) >= 4 && (P) <= 7) ? &DDRD : \
(((P) >= 30 && (P) <= 31) ? &DDRD : \

#define digitalPinToPINReg(P) \
(((P) >= 14 && (P) <= 21) ? &PINA : \
(((P) >= 4 && (P) <= 7) ? &PINB : \
(((P) >= 10 && (P) <= 13) ? &PINB : \
(((P) >= 22 && (P) <= 28) ? &PINC : \
(((P) >= 0 && (P) <= 3) ? &PIND : \
(((P) >= 8 && (P) <= 9) ? &PIND : \
(((P) >= 4 && (P) <= 7) ? &PIND : \
(((P) >= 30 && (P) <= 31) ? &PIND : \

#define __digitalPinToBit(P) \
((P) == 21) ? (P) = 0 : \
((P) == 20) ? (P) = 1 : \
((P) == 19) ? (P) = 2 : \
((P) == 18) ? (P) = 3 : \
((P) == 17) ? (P) = 4 : \
((P) == 16) ? (P) = 5 : \
((P) == 15) ? (P) = 6 : \
((P) == 14) ? (P) = 7 : \
((P) == 13) ? (P) = 7 : \
((P) == 12) ? (P) = 6 : \
((P) == 11) ? (P) = 5 : \
((P) == 10) ? (P) = 4 : \
((P) == 7) ? (P) = 3 : \
((P) == 6) ? (P) = 2 : \
((P) == 5) ? (P) = 1 : \
((P) == 4) ? (P) = 0 : \
((P) == 29) ? (P) = 7 : \
((P) == 28) ? (P) = 6 : \
((P) == 27) ? (P) = 5 : \
((P) == 26) ? (P) = 4 : \
((P) == 25) ? (P) = 3 : \
((P) == 24) ? (P) = 2 : \
((P) == 23) ? (P) = 1 : \
((P) == 22) ? (P) = 0 : \
((P) == 31) ? (P) = 7 : \
((P) == 9) ? (P) = 6 : \
((P) == 8) ? (P) = 5 : \
((P) == 30) ? (P) = 4 : \
((P) == 3) ? (P) = 3 : \
((P) == 2) ? (P) = 2 : \
((P) == 1) ? (P) = 1 : \
((P) == 0) ? (P) = 0 : \

// 8 PWM
/*
  	TIMER0A, 	  // D7 - PB3
	TIMER0B, 	  // D10 - PB4
  	TIMER1A, 	  // D8 - PD5
	TIMER1B, 	  // D30 - PD4
	TIMER2A, 	  // D31 - PD7
  	TIMER2B, 	  // D9 - PD6
  	TIMER3A, 	  // D12 - PB6
  	TIMER3B, 	  // D13 - PB7
	*/
#define __digitalPinToTimer(P) \
(((P) == 7 || (P) ==  10) ? &TCCR0A : \
(((P) == 8 || (P) ==  30) ? &TCCR1A : \
(((P) == 31 || (P) ==  9) ? &TCCR2A : \
(((P) == 12 || (P) ==  13) ? &TCCR3A : \

#define __digitalPinToTimerBit(P) \
(((P) == 7) ? COM0A1 : (((P) ==  10) ? COM0B1 : \
(((P) == 12) ? COM3A1 : (((P) == 12) ? COM3B1 : \
(((P) == 30) ? COM2A1 : (((P) ==  8) ? COM2B1 : \
(((P) == 9) ? COM2B1 : (((P) == 31) ? COM2A1 : \
#endif  //ATmega1284P)

#endif

#endif  //mega
#endif  //#if !defined(digitalPinToPortReg)

#define __atomicWrite__(A,P,V) \
if ( (int)(A) < 0x40) { bitWrite(*(A), __digitalPinToBit(P), (V) );}  \
else {                                                         \
uint8_t register saveSreg = SREG;                          \
cli();                                                     \
bitWrite(*(A), __digitalPinToBit(P), (V) );                   \
SREG=saveSreg;                                             \
} 

#ifndef digitalWriteFast
#define digitalWriteFast(P, V) \
do {                       \
if (__builtin_constant_p(P) && __builtin_constant_p(V))   __atomicWrite__((uint8_t*) digitalPinToPortReg(P),P,V) \
else  digitalWrite((P), (V));         \
}while (0)
#endif  //#ifndef digitalWriteFast2

#if !defined(pinModeFast)
#define pinModeFast(P, V) \
do {if (__builtin_constant_p(P) && __builtin_constant_p(V)) __atomicWrite__((uint8_t*) digitalPinToDDRReg(P),P,V) \
else pinMode((P), (V)); \
} while (0)
#endif

#ifndef noAnalogWrite
#define noAnalogWrite(P) \
	do {if (__builtin_constant_p(P) )  __atomicWrite((uint8_t*) __digitalPinToTimer(P),P,0) \
		else turnOffPWM((P));   \
} while (0)
#endif		

#ifndef digitalReadFast
	#define digitalReadFast(P) ( (int) _digitalReadFast_((P)) )
	#define _digitalReadFast_(P ) \
	(__builtin_constant_p(P) ) ? ( \
	( BIT_READ(*digitalPinToPINReg(P), __digitalPinToBit(P))) ) : \
	digitalRead((P))
#endif