.MEMSWAP
 #
 #                         Makefile for CMON
 #
 #	COMMAND: make -f makefile.dos <board>.<hx0|ram>
 #
 #	Example: make -f makefile.dos sf641ed.hx0
 #		 make -f makefile.dos gx32ed.ram
 #

CC	 = nmcc
NASM     = nasm
NMELD    = nmeld
NBURN	 = nburn
CFLOW	 = ncflow
MAKEDEFS = makedefs 

MON	 = $(BOARD)
BOARD_DEF= $(BOARD).h

DIAG_SRC = $(DIAG_SRC1) $(DIAG_SRC2)
DIAG_OBJ = $(DIAG_OBJ1) $(DIAG_OBJ2)

    #
    #	Compilation Flags
    #
MLDFLAGS = -lc -lctp -e _reset__ -m

    #
    #   Definitions files
    #
CDEF      = cc_def.h  global.h  global_f.h $(BOARD_DEF) device.h 
ADEF      = global.h device.h fpu_e.h cpu_e.h reset.h $(BOARD_DEF)
C_DEF_INC = global.h cpu_e.h cpu_d.h fpu_e.h fpu_d.h device.h
BPT_INC   = cmd.h cpu_d.h exec.h fpu_d.h mem.h io.h reset.h traps.h
CMD_INC   = bpt.h cpu.h exec.h io.h mem.h misc.h user_cmd.h sio_d.h
EXEC_INC  = bpt.h cpu_d.h io.h mem.h traps.h reset.h
TRAPS_INC = bpt.h cmd.h cpu_d.h exec.h io.h mem.h reset.h 
ALL_DEFS  = $(CDEF) bpt.h cmd.h cpu_d.h exec.h io.h mem.h reset.h \
	  cpu_e.h fpu_e.h misc.h user_cmd.h traps.h fpu_d.h cpu.h \
	  lan_d.h sio_d.h svc.h 
DIAG_DEF  = $(CDEF) diag.h

    #
    #   Monitor files
    #

    #	C Files
CSRC    = cc_def.c global_f.c board_d.c bpt.c cmd.c cpu.c cpu_d.c exec.c \
	  fpu_d.c io.c lan_d.c mem.c misc.c sio_d.c svc.c traps.c user_cmd.c

    #	Asm Files
ASRC    = $(PREFIX)cpu_e.s $(PREFIX)reset.s $(PREFIX)fpu_e.s

    #
    # Obj Files
    # NOTE: reset.o must be the first .o file in the list!!!!!
    #
AOBJ  = $(PREFIX)reset.o  $(PREFIX)cpu_e.o $(PREFIX)fpu_e.o
COBJ1 = date.o cc_def.o global_f.o board_d.o bpt.o cmd.o cpu.o cpu_d.o exec.o
COBJ2 = fpu_d.o io.o lan_d.o mem.o misc.o sio_d.o svc.o traps.o user_cmd.o 
COBJ  = $(COBJ1) $(COBJ2)
OBJ   = $(AOBJ) $(COBJ)

    #
    # General rules.
    #

.SUFFIXES: .o .s .h .c

.c.o:
	$(CC) $(CFLAGS) $(CONFIG_FLAGS) -I./ "-DBOARD_FILE=<$(BOARD_DEF)>" $*.c

.s.o:
	$(NASM) $(ASFLAGS) $(CONFIG_FLAGS) -I./ "-DBOARD_FILE=<$(BOARD_DEF)>" \
        -o $*.o $*.s

    #
    # Target definitions
    #

ROM: 	MON DIAG $(LINKFILE)
	echo $(AOBJ) > link.tmp	
	echo $(COBJ1) >> link.tmp
	echo $(COBJ2) >> link.tmp
	echo $(DIAG_OBJ) >> link.tmp
	echo $(MLDFLAGS) >> link.tmp
	$(NMELD) @link.tmp -i -o $(MON).rom -d $(LINKFILE) > $(MON).map

HX0:	ROM
	$(NBURN) $(MON).rom $(BFLAGS) -i -n -b0 -o $(MON).hx0
	@ echo
	@ echo $(MON).hx0 ---- done
	@ echo

HX1:	ROM
	$(NBURN) $(MON).rom $(BFLAGS) -i -n -b1 -o $(MON).hx1
	@ echo
	@ echo $(MON).hx1 ---- done 
	@ echo

HEX:	HX0 HX1

RAM:	MON DIAG $(LINKFILE)
	echo $(AOBJ) > link.tmp
	echo $(COBJ1) >> link.tmp
	echo $(COBJ2) >> link.tmp
	echo $(DIAG_OBJ) >> link.tmp
	echo $(MLDFLAGS) >> link.tmp
	$(NMELD) @link.tmp -i -o $(MON).ram -d $(LINKFILE) > $(MON).map
	@ echo
	@ echo $(MON).ram ---- done 
	@ echo

BIN: 	HX0
	intlhex2a1bin $(MON).hx0 $(MON).bin
	@ echo
	@ echo $(MON).bin ---- done 
	@ echo

MON: $(OBJ)
DIAG: $(DIAG_OBJ)


date.o:         date.c
cc_def.o:       cc_def.c      cc_def.h      $(C_DEF_INC) 
global_f.o:  global_f.c global_f.h $(CDEF) 
bpt.o:          bpt.c         bpt.h         $(CDEF) $(BPT_INC)
cmd.o:          cmd.c         cmd.h         $(CDEF) $(CMD_INC)
cpu.o:          cpu.c         cpu.h         $(CDEF) cpu_d.h
cpu_d.o:        cpu_d.c       cpu_d.h       $(CDEF)  
exec.o:         exec.c        exec.h        $(CDEF) $(EXEC_INC)
fpu_d.o:        fpu_d.c       fpu_d.h       $(CDEF)  
io.o:           io.c          io.h          $(CDEF) lan_d.h sio_d.h
lan_d.o:        lan_d.c       lan_d.h       $(CDEF) io.h
	$(CC) $(CFLAGS) $(CONFIG_FLAGS) -I./ "-DBOARD_FILE=<$(BOARD_DEF)>" -J1 $*.c
mem.o:          mem.c         mem.h         $(CDEF) io.h
misc.o:         misc.c        misc.h        $(CDEF) 
sio_d.o:        sio_d.c       sio_d.h	    $(CDEF) io.h
svc.o:		svc.c	      svc.h         $(CDEF) io.h traps.h
traps.o:        traps.c       traps.h       $(CDEF) $(TRAPS_INC)
user_cmd.o:   	user_cmd.c    user_cmd.h    $(CDEF) 
uwire_d.o:      uwire_d.c     uwire_d.h     $(CDEF) 
cpu_e.o:      	cpu_e.s       cpu_e.h       $(ADEF)
fpu_e.o:      	fpu_e.s       fpu_e.h       $(ADEF)
reset.o:   	reset.s       reset.h       $(ADEF)
sf_cpu_e.o:   	sf_cpu_e.s    cpu_e.h       $(ADEF)
sf_fpu_e.o:   	sf_fpu_e.s    fpu_e.h       $(ADEF)
sf_reset.o:	sf_reset.s    reset.h       $(ADEF)

sf_diag.o	: sf_diag.c 	$(DIAG_DEF)
diag_ext.o      : diag_ext.s   	$(DIAG_DEF)
diag.o          : diag.c       	$(DIAG_DEF)
icu_diag.o      : icu_diag.c   	$(DIAG_DEF)
sio_diag.o      : sio_diag.c 	$(SERIAL_FILE) $(DIAG_DEF)
ram_diag.o      : ram_diag.c   	$(DIAG_DEF)
epr_diag.o    	: epr_diag.c 	$(DIAG_DEF)
eep_diag.o   	: eep_diag.c 	$(DIAG_DEF)
led_diag.o      : led_diag.c   	$(DIAG_DEF)
lcd_diag.o      : lcd_diag.c   	$(DIAG_DEF)
cpu_diag.o      : cpu_diag.c   	$(DIAG_DEF)
cnt_diag.o     	: cnt_diag.c  	$(DIAG_DEF)
scs_diag.o     	: scs_diag.c 	$(DIAG_DEF)
fpu_diag.o      : fpu_diag.c   	$(DIAG_DEF)

emul.h		: sio_d.h
global.h	: device.h

     #
     # Boards targets.
     #

fx164ed.ram	: fx164ed.rmk FRC
	make -f fx164ed.rmk RAM
fx164ed.rmk	:
	echo BOARD = fx164ed > fx164ed.rmk
	echo CONFIG_FLAGS = -KCfx16 -KFnofpu -KB2 >> fx164ed.rmk
	echo CFLAGS = -c -R -A -DCMON -g -DDEBUG -DDIAG >> fx164ed.rmk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -DDEBUG >> fx164ed.rmk
	echo LINKFILE = fx164ed.dlk >> fx164ed.rmk
	echo SERIAL_FILE = fx200.h >> fx164ed.rmk
	echo DIAG_SRC1 = diag_ext.s diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c cpu_diag.c icu_diag.c >> fx164ed.rmk
	echo DIAG_SRC2 = lcd_diag.c >> fx164ed.rmk
	echo DIAG_OBJ1 = diag_ext.o diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o cpu_diag.o icu_diag.o >> fx164ed.rmk
	echo DIAG_OBJ2 = lcd_diag.o >> fx164ed.rmk
	type makefile.dos >> fx164ed.rmk

fx164ed.hx0 fx164ed.hx1	: fx164ed.mk FRC
	make -f fx164ed.mk HEX
fx164ed.mk:
	echo BOARD = fx164ed > fx164ed.mk
	echo CONFIG_FLAGS = -KCfx16 -KFnofpu -KB2 >> fx164ed.mk
	echo CFLAGS = -c -R -A -DCMON -O -DDIAG >> fx164ed.mk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON >> fx164ed.mk
	echo BFLAGS = -w2 -x0x800000 -l64 >> fx164ed.mk
	echo LINKFILE = fx164ed.lnk >> fx164ed.mk
	echo SERIAL_FILE = fx200.h >> fx164ed.mk
	echo DIAG_SRC1 = diag_ext.s diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c cpu_diag.c >> fx164ed.mk
	echo DIAG_SRC2 = icu_diag.c lcd_diag.c >> fx164ed.mk
	echo DIAG_OBJ1 = diag_ext.o diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o cpu_diag.o >> fx164ed.mk
	echo DIAG_OBJ2 = icu_diag.o lcd_diag.o >> fx164ed.mk
	type makefile.dos >> fx164ed.mk

sf641ed.ram	: sf641ed.rmk FRC
	make -f sf641ed.rmk RAM
sf641ed.rmk	:
	echo BOARD = sf641ed > sf641ed.rmk
	echo CONFIG_FLAGS = -KCsf641 -KB8 >> sf641ed.rmk
	echo CFLAGS = -c -R -A -DCMON -g -DDEBUG -DDIAG -KW5 -Oo >> sf641ed.rmk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -DDEBUG -KW >> sf641ed.rmk
	echo MLDFLAGS = -lc -lctp -e _reset__ -m -lHfp >> sf641ed.rmk
	echo LINKFILE = sf641ed.dlk >> sf641ed.rmk
	echo SERIAL_FILE = z8530.h >> sf641ed.rmk
	echo PREFIX = sf_ >> sf641ed.rmk
	echo DIAG_SRC1 = sf_diag.c diag.c icu_diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c cpu_diag.c >> sf641ed.rmk
	echo DIAG_SRC2 = fpu_diag.c eep_diag.c lcd_diag.c cnt_diag.c scs_diag.c >> sf641ed.rmk
	echo DIAG_OBJ1 = sf_diag.o diag.o icu_diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o cpu_diag.o >> sf641ed.rmk
	echo DIAG_OBJ2 = fpu_diag.o eep_diag.o lcd_diag.o cnt_diag.o scs_diag.o >> sf641ed.rmk
	type makefile.dos | grep -v "^MLDFLAGS"  >> sf641ed.rmk

sf641ed.hx0	: sf641ed.mk FRC
	make -f sf641ed.mk HX0
sf641ed.mk	:
	echo BOARD = sf641ed > sf641ed.mk
	echo CONFIG_FLAGS = -KCsf641 -KB8 >> sf641ed.mk
	echo CFLAGS = -c -R -A -DCMON -O -DDIAG -KW5 -Oo >> sf641ed.mk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -KW >> sf641ed.mk
	echo MLDFLAGS = -lc -lctp -e _reset__ -m -lHfp >> sf641ed.mk
	echo BFLAGS = -w1 -x0x20000000 -l256 >> sf641ed.mk
	echo LINKFILE = sf641ed.lnk >> sf641ed.mk
	echo SERIAL_FILE = z8530.h >> sf641ed.mk
	echo PREFIX = sf_ >> sf641ed.mk
	echo DIAG_SRC1 = sf_diag.c diag.c icu_diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c cpu_diag.c >> sf641ed.mk
	echo DIAG_SRC2 = fpu_diag.c eep_diag.c lcd_diag.c cnt_diag.c scs_diag.c >> sf641ed.mk
	echo DIAG_OBJ1 = sf_diag.o diag.o icu_diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o cpu_diag.o >> sf641ed.mk
	echo DIAG_OBJ2 = fpu_diag.o eep_diag.o lcd_diag.o cnt_diag.o scs_diag.o >> sf641ed.mk
	type makefile.dos | grep -v "^MLDFLAGS" >> sf641ed.mk


gx32ed.ram	: gx32ed.rmk FRC
	make -f gx32ed.rmk RAM
gx32ed.rmk	:
	echo BOARD = gx32ed > gx32ed.rmk
	echo CONFIG_FLAGS = -KCgx32 -KF381 -KB4 >> gx32ed.rmk
	echo CFLAGS = -c -R -A -DCMON -g -DDEBUG -DDIAG >> gx32ed.rmk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -DDEBUG >> gx32ed.rmk
	echo LINKFILE = gx32ed.dlk >> gx32ed.rmk
	echo SERIAL_FILE = ns16550.h >> gx32ed.rmk
	echo DIAG_SRC1 = diag_ext.s diag.c icu_diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c >> gx32ed.rmk
	echo DIAG_SRC2 = cpu_diag.c fpu_diag.c >> gx32ed.rmk
	echo DIAG_OBJ1 = diag_ext.o diag.o icu_diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o >> gx32ed.rmk
	echo DIAG_OBJ2 = cpu_diag.o fpu_diag.o >> gx32ed.rmk
	type makefile.dos >> gx32ed.rmk

gx32ed.hx0	: gx32ed.mk FRC
	make -f gx32ed.mk HX0
gx32ed.mk	:
	echo BOARD = gx32ed > gx32ed.mk
	echo CONFIG_FLAGS = -KCgx32 -KF381 -KB4 >> gx32ed.mk
	echo CFLAGS = -c -R -A -DCMON -O -DDIAG >> gx32ed.mk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON >> gx32ed.mk
	echo BFLAGS = -w1 -x0x10000000 -l64 >> gx32ed.mk
	echo LINKFILE = gx32ed.lnk >> gx32ed.mk
	echo SERIAL_FILE = ns16550.h >> gx32ed.mk
	echo DIAG_SRC1 = diag_ext.s diag.c icu_diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c >> gx32ed.mk
	echo DIAG_SRC2 = cpu_diag.c fpu_diag.c >> gx32ed.mk
	echo DIAG_OBJ1 = diag_ext.o diag.o icu_diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o >> gx32ed.mk
	echo DIAG_OBJ2 = cpu_diag.o fpu_diag.o >> gx32ed.mk
	type makefile.dos >> gx32ed.mk


cg16ed.ram	: cg16ed.rmk FRC
	make -f cg16ed.rmk RAM
cg16ed.rmk	:
	echo BOARD = cg16ed > cg16ed.rmk
	echo CONFIG_FLAGS = -KCcg16 -KF381 -KB2 >> cg16ed.rmk
	echo CFLAGS = -c -R -A -DCMON -g -DDEBUG -DDIAG >> cg16ed.rmk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -DDEBUG >> cg16ed.rmk
	echo LINKFILE = cg16ed.dlk >> cg16ed.rmk
	echo SERIAL_FILE = ns16550.h >> cg16ed.rmk
	echo DIAG_SRC1 = diag_ext.s diag.c icu_diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c >> cg16ed.rmk
	echo DIAG_SRC2 = cpu_diag.c fpu_diag.c >> cg16ed.rmk
	echo DIAG_OBJ1 = diag_ext.o diag.o icu_diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o >> cg16ed.rmk
	echo DIAG_OBJ2 = cpu_diag.o fpu_diag.o >> cg16ed.rmk
	type makefile.dos >> cg16ed.rmk

cg16ed.hx0 cg16ed.hx1	: cg16ed.mk FRC
	make -f cg16ed.mk HEX
cg16ed.mk	:
	echo BOARD = cg16ed > cg16ed.mk
	echo CONFIG_FLAGS = -KCcg16 -KF381 -KB2 >> cg16ed.mk
	echo CFLAGS = -c -R -A -DCMON -O -DDIAG >> cg16ed.mk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON >> cg16ed.mk
	echo BFLAGS = -w2 -x0x800000 -l64 >> cg16ed.mk
	echo LINKFILE = cg16ed.lnk >> cg16ed.mk
	echo SERIAL_FILE = ns16550.h >> cg16ed.mk
	echo DIAG_SRC1 = diag_ext.s diag.c icu_diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c >> cg16ed.mk
	echo DIAG_SRC2 = cpu_diag.c fpu_diag.c >> cg16ed.mk
	echo DIAG_OBJ1 = diag_ext.o diag.o icu_diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o >> cg16ed.mk
	echo DIAG_OBJ2 = cpu_diag.o fpu_diag.o >> cg16ed.mk
	type makefile.dos >> cg16ed.mk


am160ed.ram	: am160ed.rmk FRC
	make -f am160ed.rmk RAM
am160ed.rmk	:
	echo BOARD = am160ed > am160ed.rmk
	echo CONFIG_FLAGS = -KCcg160 -KFnofpu -KB2 >> am160ed.rmk
	echo CFLAGS = -c -R -A -DCMON -g -DDEBUG -DDIAG >> am160ed.rmk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -DDEBUG >> am160ed.rmk
	echo LINKFILE = am160ed.dlk >> am160ed.rmk
	echo SERIAL_FILE = ns16550.h >> am160ed.rmk
	echo DIAG_SRC1 = diag_ext.s diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c cpu_diag.c >> am160ed.rmk
	echo DIAG_OBJ1 = diag_ext.o diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o cpu_diag.o >> am160ed.rmk
	type makefile.dos >> am160ed.rmk

am160ed.hx0 am160ed.hx1	: am160ed.mk FRC
	make -f am160ed.mk HEX
am160ed.mk	:
	echo BOARD = am160ed > am160ed.mk
	echo CONFIG_FLAGS = -KCcg160 -KFnofpu -KB2 >> am160ed.mk
	echo CFLAGS = -c -R -A -DCMON -O -DDIAG >> am160ed.mk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON >> am160ed.mk
	echo BFLAGS = -w2 -x0x40000 -l64 >> am160ed.mk
	echo LINKFILE = am160ed.lnk >> am160ed.mk
	echo SERIAL_FILE = ns16550.h >> am160ed.mk
	echo DIAG_SRC1 = diag_ext.s diag.c sio_diag.c ram_diag.c epr_diag.c led_diag.c cpu_diag.c >> am160ed.mk
	echo DIAG_OBJ1 = diag_ext.o diag.o sio_diag.o ram_diag.o epr_diag.o led_diag.o cpu_diag.o >> am160ed.mk
	type makefile.dos >> am160ed.mk


a1d.ram	: a1d.rmk FRC
	make -f a1d.rmk RAM
a1d.rmk	:
	echo BOARD = a1d > a1d.rmk
	echo CONFIG_FLAGS = -KCfx16 -KFnofpu -KB2 >> a1d.rmk
	echo CFLAGS = -c -R -A -DCMON -g -DDEBUG -DDIAG >> a1d.rmk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON -DDEBUG >> a1d.rmk
	echo LINKFILE = a1d.dlk >> a1d.rmk
	echo SERIAL_FILE = ns16550.h >> a1d.rmk
	echo DIAG_SRC1 = diag_ext.s diag.c sio_diag.c ram_diag.c cpu_diag.c icu_diag.c eep_diag.c >> a1d.rmk
	echo DIAG_SRC2 = afe_diag.c uwire_d.c >> a1d.rmk
	echo DIAG_OBJ1 = diag_ext.o diag.o sio_diag.o ram_diag.o cpu_diag.o icu_diag.o eep_diag.o >> a1d.rmk
	echo DIAG_OBJ2 = afe_diag.o uwire_d.o >> a1d.rmk
	type makefile.dos >> a1d.rmk

a1d.bin	: a1d.mk FRC
	make -f a1d.mk BIN
a1d.mk	:
	echo BOARD = a1d > a1d.mk
	echo CONFIG_FLAGS = -KCfx16 -KFnofpu -KB2 >> a1d.mk
	echo CFLAGS = -c -R -A -DCMON -O -DDIAG >> a1d.mk
	echo ASFLAGS = -c -n -g -w -DASEM -DCMON >> a1d.mk
	echo BFLAGS = -w1 -x0x7000 -l64 >> a1d.mk
	echo LINKFILE = a1d.lnk >> a1d.mk
	echo SERIAL_FILE = ns16550.h >> a1d.mk
	echo DIAG_SRC1 = diag_ext.s diag.c sio_diag.c ram_diag.c cpu_diag.c icu_diag.c eep_diag.c >> a1d.mk
	echo DIAG_SRC2 = afe_diag.c uwire_d.c >> a1d.mk
	echo DIAG_OBJ1 = diag_ext.o diag.o sio_diag.o ram_diag.o cpu_diag.o icu_diag.o eep_diag.o >> a1d.mk
	echo DIAG_OBJ2 = afe_diag.o uwire_d.o >> a1d.mk
	type makefile.dos >> a1d.mk


nmeld:
	$(NMELD) -o cmon $(MLDFLAGS) $(OBJ) 

clean:
	del *.o

FRC:

