Modularise PAL code

Signed-off-by: James Guthrie <james@prodigi.ch>