CC=cl65
AS=ca65
LD=ld65
TARGET=c64
CFLAGS=-Oirs -t $(TARGET)
AFLAGS=
CONFIGAPPNAME=config
VOTEAPPNAME=vote
C1541=c1541


CONFIGOBJS = \
	main.o \
	global.o \
	mainmenu.o \
	filemenu.o \
	sectionmenu.o \
	instructions.o \
	menu.o \
	screen.o \
	fileselector.o \
	dir.o \
	config.o \
	fileio.o \
	inputline.o \
	editsection.o \
	music.o \
	logo.o \
	generate.o \
	colours.o


VOTEOBJS = \
	vote.o \
	gfx.o \
	conf.o \
	msx.o \
	font6x8.o \
	irq.o \
	votemenu.o \
	section.o \
	votedata.o


RESULTSOBJS = \
	results.o \
	openconfig.o \
	menu.o \
	fileselector.o \
	dir.o \
	screen.o \
	config.o \
	global.o \
	votes.o \
	viewresults.o \
	collectvotes.o \
	fileio.o \
	inputline.o


%.o: %.c
	$(CC) -c $(CFLAGS) $<

%.o: %.s
	$(AS) $(AFLAGS) $<


all: cvote.d64


cvote.d64: config vote results
	rm -f cvote.d64
	$(C1541) \
		-format "c-vote,03" d64 cvote.d64 \
		-write config.pu "c-vote config" \
		-write vote "c-vote client" \
		-write results.pu "c-vote results" \
		-write inst.seq "instructions,s" \
		-write lcp2003.koa "lcp2003 logo.koa" \
		-write snood-wyndex.mus "snood/wyndex.mus"
#		-write lcp2002votesheet \
#		-write vote00.dat "vote00.dat,s" \
#		-write vote01.dat "vote01.dat,s" \
#		-write vote02.dat "vote02.dat,s" \
#		-write vote03.dat "vote03.dat,s" \
#		-write vote04.dat "vote04.dat,s"


config: $(CONFIGOBJS)
	$(CC) -o $(CONFIGAPPNAME) -Ln $(CONFIGAPPNAME).lab $(CFLAGS) $(CONFIGOBJS)
	pucrunch $(CONFIGAPPNAME) $(CONFIGAPPNAME).pu

vote: $(VOTEOBJS)
	$(LD) -m vote.map -C vote.cfg -o vote.tmp $(AFLAGS) $(VOTEOBJS)
	cat vote.tmp testdata.bin > vote

results: $(RESULTSOBJS)
	$(CC) -o results $(CFLAGS) $(RESULTSOBJS)
	pucrunch results results.pu


clean:
	rm -f $(CONFIGOBJS) $(VOTEOBJS) $(RESULTSOBJS) \
		vote vote.map vote.tmp \
		config config.pu $(CONFIGAPPNAME).lab \
		results results.pu \
		cvote.d64

distclean: clean
	rm -f *~
