Optiboot bootloader, I think it's included with MightyCore.
You can compile a sketch for the mega on the 1284 with some considerations:
* The pin numbers will obviously need to be different, since the 1284p doesn't have the same number of pins, and the PWM pins (and other peripherals) are on different pin numbers.
* If you are using Serial2 or Serial3, that won't work on the 1284, since it only has 2 serial ports, not 4. There are a few other features that the mega2560 has that the 1284 doesnt (most of these aren't things people typically use though)
* If you are doing any direct register manipulation (or using libraries that do), you need to review that and make sure the same registers exist on the 1284p. The first test here would be installing the core and seeing if the sketch compiles. If it complains about undefined variableswith cryptic allcaps names (ex TCCR4A, or UCSRA2), it's probably referring to registers that don't exist on the 1284. Some libraries that directly manipulate registers are smart enough to work with the 1284p without modification (and some will just work without any special measures being taken), while others are not.
* The 1284p has less flash memory - your sketch must fit in 128k instead of 256k.