#TEST		=	foyer
ALNFLAGS	=	-w -l -a 6000 a0000 100000
OBFILES		=	demo.o td.o init.o sys.o objlist3.o joy.o gpufix.o
OBFILES2	=	blit.o mkmat.o trig.o lattice.o
TOOLOBS	=	polyinp.o input2.o mktp.o alloc.o end.o
IPATH	=	..\include
CFLAGS	=	-m0 -v -b0 -w -z2 -r0

DSINC = 3dds.inc car.inc bndhead.inc

.SUFFIXES: .bnd .asc .mdl
.PHONY: test.inc

.asc.mdl:
	mkbnd $*.asc city.clr -l jag.lyt -t 128
	findbg -bground 128000 -cpdelta 256000 $*.bnd $*.bnd
	bnd2mdl $*.bnd $*.mdl

#	mkbnd $*.asc house.clr -l jag.lyt -t 100
#	findbg $*.bnd $*.bnd
#	bnd2mdl -sky $*.bnd $*.mdl

#	mkbnd $*.asc west.clr -l jag.lyt
#	findbg $*.bnd $*.bnd
#	bnd2mdl -sky $*.bnd $*.mdl

.bnd.mdl:
	bnd2mdl -sky $*.bnd $*.mdl

polytool: polytool.abs
polytool.db: polytool.abs

car3.mdl: car3.bnd
	bnd2mdl -flip $*.bnd $*.mdl

polytool.abs: $(OBFILES) $(OBFILES2) 3d.bin 3dend.bin 3dbeg.bin comp.bin ren.bin $(TOOLOBS)
	aln -o polytool.abs $(ALNFLAGS) $(OBFILES) $(OBFILES2) \
	-i 3dbeg.bin bgpprog -i 3dend.bin egpprog -i comp.bin cgpprog -i ren.bin rgpprog -i 3d.bin gpprog $(TOOLOBS)
	filefix polytool.abs


init.o:		init.s 3dds.inc car.inc floor.dat car.dat $(TEST).mdl
	mkinc $(TEST)
	mac -i$(IPATH) init.s

end.o:	end.s
	mac end.s
demo.o:		demo.s data.s video.inc $(DSINC)
	mac -i$(IPATH) demo.s
sys.o:		sys.s video.inc $(DSINC)
	mac -i$(IPATH) sys.s
objlist3.o: objlist3.s video.inc
	mac -i$(IPATH) objlist3.s
trig.o:		trig.s trig.h
	mac trig.s
polyinp.o:		polyinp.s $(DSINC)
	mac -i$(IPATH) polyinp.s
td.o:		td.s 3dds.inc car.inc 
	mac -i$(IPATH) td.s
mkmat.o:		mkmat.s
	mac -i$(IPATH) mkmat.s
blit.o:		blit.s $(DSINC)
	mac -i$(IPATH) blit.s
joy.o:		joy.s $(IPATH)\joypad.inc
	mac -i$(IPATH) joy.s
gpufix.o:	gpufix.s
	mac	gpufix.s

mktp.o:		mktp.c bndhead.h
	lc $(CFLAGS) mktp.c
alloc.o:	alloc.c
	lc $(CFLAGS) alloc.c
input2.o:	input2.c bndhead.h
	lc $(CFLAGS) input2.c
lattice.o:	lattice.s
	mac lattice.s
#68kequ.inc: $(OBFILES) $(OBFILES2) symlist mktp.o
#	aln $(ALNFLAGS) $(OBFILES) $(OBFILES2) -i 3dbeg.bin bgpprog -i 3dend.bin egpprog -i comp.bin cgpprog -i ren.bin rgpprog -i 3d.bin gpprog mktp.o
#	filefix demo.abs
#	gpusym demo.sym symlist

comp.bin:	comp.gas rot.gas clp.gas 3to2.gas edge.gas bf.gas subscomp.gas 68kequ.inc close.gas crash.gas 3d.inc time.gas $(DSINC)
	gasm -I$(IPATH) -R2 -o -c comp.gas
	ltxconv -a comp
	align comp.bin
ren.bin:	ren.gas surf.gas 68kequ.inc tree.gas marktree.gas tree.inc 3d.inc time.gas $(DSINC)
	gasm -I$(IPATH) -R2 -o -c ren.gas
	ltxconv -a ren
	align ren.bin
3dbeg.bin:	3dbeg.gas sky1.gas 68kequ.inc 3d.inc time.gas $(DSINC)
	gasm -I$(IPATH) -R2 -o -c 3dbeg.gas
	ltxconv -a 3dbeg
	align 3dbeg.bin
3dend.bin:	3dend.gas turt.gas 68kequ.inc subsend.gas 3d.inc time.gas $(DSINC)
	gasm -I$(IPATH) -R2 -o -c 3dend.gas
	ltxconv -a 3dend
	align 3dend.bin
3d.bin:		3d.gas 68kequ.inc $(DSINC)
	gasm -I$(IPATH) -R2 -o -c 3d.gas
	ltxconv -a 3d
	align 3d.bin

demo.o sys.o td.o input.o 3d.bin 3dm.bin: $(IPATH)\jaguar.inc
