toaplan1.c: fix and cleanup palette handling [Alex Jackson]