#
# MIXERTON Mixbug recovery.
#
#
#


TOOLS=$(HOME)/d310/h8tools
HAS=$(TOOLS)/h8-as
HCC=$(TOOLS)/h8-cc-c 
HLD=$(TOOLS)/cbgld/cbgld



all:odette-rescue.hex sewing.hex

others:odd.hex rescue-clear.hex odette-rescue.hex sewing.hex
#	cat odette-rescue.hex > /dev/ttyS0
#	cat rescue-clear.hex > /dev/ttyS0


#
# Odette is a bootstrap to reflash the flash loader.
# You need the version that adds 20000 to the download address because
# the flash has been temp repaged there.
odette-rescue.hex:odshim.o mixflash.h mixflash_statics.o odette.o
	$(HLD) -download  -T0xFFF400 odshim.o  odette.o -T0xFFEC00 mixflash_statics.o  -T0xFFF400
	mv dump.hex odette-rescue.hex

odette.o:odette.c mixflash.h
	$(HCC) odette


odshim.o:odshim.S
	$(HAS) -o odshim.o -a odshim.S

mixflash_statics.o:mixflash_statics.c
	$(HCC) mixflash_statics
#-----------------------------------------------
#
#  Load this as a sewing kit into address 80000, so that, with luck, a boot with
# a19 grounded will enter this code and run it as if at zero.
#
# For EPROMs, this also makes even.hex
odd.hex:mixbugshim.o mixbug.o 
	$(HLD) -T0 mixbugshim.o mixbug.o  -T0x80000

sewing.hex:mixbugshim.o mixbug.o 
	$(HLD) -ihex32 -T0 mixbugshim.o mixbug.o  -T0x80000
	mv image.hex sewing.hex

mixbug.o:mixbug.S
	$(HAS) -o mixbug.o -a mixbug.S

mixbugshim.o:mixbugshim.S
	$(HAS) -o mixbugshim.o -a mixbugshim.S



rescue-clear.hex:rescue-clear.S
	$(HAS) -o rescue-clear.o -a rescue-clear.S
	$(HLD) -download -T0xFFF400 rescue-clear.o
	mv dump.hex rescue-clear.hex


zip:
	rm -rf mixbug.zip
	zip mixbug.zip *.S *.c *.h makefile todo README *.txt


clean:
	rm -f *.s *.o *.hex
