#
# Mixflash
# Mixerton flash prommer for HS8
#
TOOLS=$(HOME)/d310/h8tools
TOOLS=/usr/groups/han/h8s/h8tools_old
AS=$(TOOLS)/h8-as
CC=$(TOOLS)/h8-cc-c 
LD=$(TOOLS)/cbgld/cbgld

all: mflo mfhi
#misctest
# flashbootproms
# mixflash_download
# squirt
# 
# 

#
# To generate a decent mfhi, it is best to alter the ISR tables.
#


OBJS=  mixflash.o  mylinein.o prlibc.o mymon.o



squirt:squirter.c
	gcc -Wall -o squirt squirter.c

flashbootproms:mfshim_lo.o mixflashass.o $(OBJS) mixflash.h mixflash_statics.o
	$(LD) -T0x0 mfshim_lo.o mixflashass.o $(OBJS) -T0xFFEC00 mixflash_statics.o  -T0
 
# for testing, download to RAM at 10000 or 10800 for flashing
mixflash_download:mixflashass.o mfshim_lo.o $(OBJS) mixflash.h mixflash_statics.o
	$(LD) -download  -T0x0000 mfshim_lo.o mixflashass.o $(OBJS) -T0xFFEC00 mixflash_statics.o -T0x10800
	cat dump.hex > /dev/ttyS2

MFHIA= -T0x70000
# Hi Download under odette.
mfhi:mfshim_lo.o $(OBJS) mfshim_hi.o mixflashass.o  mixflash.h mixflash_statics.o
	$(LD) -ihex32  $(MFHIA) mfshim_hi.o mixflashass.o  $(OBJS) -T0xFFEC00 mixflash_statics.o $(MFHIA)
	mv image.hex mfhi.hex


# Normal build
mflo:mfshim_lo.o $(OBJS) mixflashass.o  mixflash.h mixflash_statics.o
	$(LD) -ihex32 -T0x00000 mfshim_lo.o mixflashass.o $(OBJS) -T0xFFEC00 mixflash_statics.o -T0x00000
	mv image.hex mflo.hex

#
# Odette is a bootstrap to reflash the flash loader.
odette:odshim.o mixflash.h mixflash_statics.o odette.o
	$(LD) -download  -T0xFFF400 odshim.o  odette.o -T0xFFEC00 mixflash_statics.o  -T0xFFF400
	cp dump.hex odette.hex



mixflash_statics.o:mixflash_statics.c mixflash.h
	$(CC) mixflash_statics 


mixflash.o:mixflash.c mixflash.h
	$(CC) mixflash

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

mymon.o:mymon.c prstdio.h
	$(CC) mymon

prlibc.o:prlibc.c prstdio.h
	$(CC) prlibc

mylinein.o:mylinein.c prstdio.h
	$(CC) mylinein

mfshim_lo.o:mfshim_lo.S
	$(AS) -o mfshim_lo.o -a mfshim_lo.S

mfshim_hi.o:mfshim_hi.S
	$(AS) -o mfshim_hi.o -a mfshim_hi.S

mixflashass.o:mixflashass.S
	$(AS) -o mixflashass.o -a mixflashass.S

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

#-----------------------
misctest:
	$(AS) -o misctest.o -a misctest.S
	$(LD) -download  -T0xFFED00 misctest.o
	cat dump.hex > /dev/ttyS0
#-----------------------

zip:
	rm -rf mixflash.zip
	zip mixflash.zip *.S *.c *.h makefile todo README *.txt mixbug/mixbug.zip 
#	cp mixflash.zip $(HOME)/.upback


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


