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 lib/sound.o
	-rm lib/sound.s
	-rm hiworld.atr.in1
	-rm hiworld.atr.in
	-rm hiworld.map

hiworld.xex:	hiworld.o lib/sound.o atari.cfg
	ld65 \
		--cfg-path "." \
		--lib-path "${CC65_LIB}" \
		-o hiworld.xex \
		-t atari \
		-m hiworld.map \
		hiworld.o \
		lib/sound.o \
		atari.lib

hiworld.o:	hiworld.s
	ca65 -I "${CC65_ASMINC}" -t atari hiworld.s

lib/sound.o:	lib/sound.s
	ca65 -I "${CC65_ASMINC}" -t atari lib/sound.s

hiworld.s:	hiworld.c \
		font.h \
		lib/sound.h \
		extended_headers/antic.h extended_headers/gtia.h \
		extended_headers/pbi.h extended_headers/pia.h \
		extended_headers/pokey.h \
		extended_headers/page0.h extended_headers/page2.h
	cc65 -I "${CC65_INC}" -t atari hiworld.c

lib/sound.s:	lib/sound.c \
		lib/sound.h \
		extended_headers/pokey.h
	cc65 -I "${CC65_INC}" -t atari lib/sound.c

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

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
