C64 palette algo.
Tested with Winzards Lair