CC65_HOME=/usr/local/share/cc65/
CC65_INC=/usr/local/share/cc65/include/
CC65_ASMINC=/usr/local/share/cc65/asminc/
CC65_LIB=/usr/local/share/cc65/lib/
CC65_CFG=/usr/local/share/cc65/cfg/
FRANNY=/usr/local/franny/bin/franny
XXD=/usr/bin/xxd

.PHONY: all clean run run-xex

all:	hiworld.atr

clean:
	-rm hiworld.atr
	-rm hiworld.xex
	-rm hiworld.o
	-rm hiworld.s
	-rm sound.o
	-rm sound.s
	-rm hiworld.atr.in1
	-rm hiworld.atr.in

hiworld.xex:	hiworld.s sound.s
	cl65 \
		-I "${CC65_INC}" \
		--asm-include-dir "${CC65_ASMINC}" \
		--cfg-path "${CC65_CFG}" \
		-L "${CC65_LIB}" \
		-o hiworld.xex \
		-t atari \
		hiworld.s \
		sound.s

hiworld.s:	hiworld.c sound.h
	cc65 -I "${CC65_INC}" -t atari hiworld.c

sound.s:	sound.c sound.h
	cc65 -I "${CC65_INC}" -t atari sound.c

hiworld.atr:	hiworld.atr.in hiworld.xex
	cp hiworld.atr.in hiworld.atr
	${FRANNY} -A hiworld.atr -i hiworld.xex -o HIWORLD.AR0

run:	hiworld.atr
	atari800 -audio16 -nobasic hiworld.atr

run-xex:	hiworld.xex
	atari800 -audio16 -nobasic -run hiworld.xex

hiworld.atr.in:	mydos/dos.sys mydos/dup.sys mydos/sd_mydos.xxd
	${FRANNY} -C hiworld.atr.in1 -d s -f a
	${FRANNY} -F hiworld.atr.in1
	${FRANNY} -A hiworld.atr.in1 -i mydos/dos.sys -o DOS.SYS
	${FRANNY} -A hiworld.atr.in1 -i mydos/dup.sys -o DUP.SYS
	( cat mydos/sd_mydos.xxd ; \
	  ${XXD} -s 0x180 hiworld.atr.in1 ) | \
		${XXD} -r > hiworld.atr.in
