VERSIONS=a b c d
PROG=numpad

APPS=${VERSIONS:%=${PROG}-%.app}
ASMS=${VERSIONS:%=${PROG}-%.asm} numpad.asm
LSTS=${VERSIONS:%=${PROG}-%.p}
LSTS=${VERSIONS:%=${PROG}-%.lst}
ZAPS=${VERSIONS:%=${PROG}-%.zap}
STAMPS=${VERSIONS:%=${PROG}-%.stamp}
HEX=${APPS:%.app=%.app.hex} ${APPS:%.app=%.zap.app.hex}
ZAPAPPS=${ZAPS:%.zap=%.zap.app}

CROSS=../../../asl/

ZAP2APP=../../tools/zap2app
AFLAGS=-i ../../include/dl150 -cpu datalink
AS=${CROSS}asl ${AFLAGS}
P2BIN=${CROSS}p2bin

default:${STAMPS}

numpad.asm:numpad.zsm
	sed -e 's/^INCLUDE/ INCLUDE/' < $< > $@ || /bin/rm -f $@

numpad-a.asm:numpad.asm
	sed -e '/?C{/,/?C}/d' < $< | sed -e '/?A{/,/?A}/d' > $@ || /bin/rm -f $@

numpad-b.asm:numpad.asm
	sed -e '/?C{/,/?C}/d' < $< > $@ || /bin/rm -f $@

numpad-c.asm:numpad.asm
	sed -e '/?B{/,/?B}/d' < $< > $@ || /bin/rm -f $@

numpad-d.asm:numpad.asm
	sed -e '/?C{/,/?C}/d' < $< | sed -e '/?W{/,/?W}/d' > $@ || /bin/rm -f $@

%.p:%.asm
	${AS} -L ${@:%.p=%.lst} -o $@ $<

%.app:%.p
	${P2BIN} $< $@ -r 0x110-\$$


%.hex:% 
	yes '' | dd bs=272 count=1 | cat - $< | hexdump -C > $@ || /bin/rm -f $@


%.stamp:%.app.hex %.zap.app.hex
	diff  -uN ${@:%.stamp=%.app.hex}  ${@:%.stamp=%.zap.app.hex} && touch $@

%.zap.app:%.zap
	${ZAP2APP} $< $@

.PRECIOUS:${APPS}

clean:
	/bin/rm -f ${APPS} ${PS} ${LSTS} ${HEX} ${STAMPS} ${ZAPAPPS} ${ASMS}