more or less copy/paste 6502 from my old project