# Makefile - Makefile for NSDEMO with SSI Link&Locate 386 Evaluation
#            version (or retail version)      
#
# targets     all (default) - builds NSDEMO
#             clean         - remove output files
#
# inputs      COMPILER      - MN0200 - Microsoft Visual C++ 2.0
#                             MN0400 - Microsoft Visual C++ 4.0
#                             BD0400 - Borland C++ 4.0
#                             BD0450 - Borland C++ 4.5
#                             WD1000 - Watcom C++ 10.0
#                             WD1050 - Watcom C++ 10.5
#
# Note: this makefile uses an inline response file, which apparantly is
# not supported in the Borland (4.5) make utility.  This makefile works
# well with Microsoft's NMAKE Utility.
#                          
# Note: The MN0400 setting will work with Microsoft Visual C++ 4.1 and 4.2.
# However, an updated linker/locater is required.  Please contact SSI for
# an update for the retail version.  Currently the evaluation version of the
# SSI tools will not work with 4.1 or 4.2 - but contact SSI for the latest
# information.  They can be reached by email at "support@ssi.com" or by
# phone at (714) 844-1700 x400.

# Objects in NSDEMO

OBJS = main.obj cpu.o ica.obj \
       biu.obj dma.obj dmatest.obj dram.obj dramtest.obj i2c.obj \
       lcdbm.obj lcdtest.obj lm75.obj pcmcia.obj pcmtest.obj \
       pic.obj pit.obj pittest.obj rtc.obj rtctest.obj uart.obj \
       wd.obj wdtest.obj

# Name of output OMF file
OUTFILE=nsdemo

# Normally when using Borland compilers, you can modify the bcc32.cfg
# file to include the Link&Locate include files before the Borland
# include files.  However, if you do not want to do that, you can uncomment
# the following define and change the borland compiler options below
# to the commented out version which adds a -I command line option with the
# include directory.  You must modify the following define to point to
# the include files on your system.
#LLINCLOC=c:\ll386eva\inc

# If LL=LL, use full LL386 version to link
# else use evaluation version
!ifndef LL
LL = ELL
!endif

# If no compiler is specified, default to Microsoft (MN0200)
!ifndef COMPILER
COMPILER = MN0200
!endif

# This just determines which link to use
!if "$(LL)" == "LL"
LINK386 = xlink386
!else
LINK386 = elink386
!endif

#rules
!if "$(COMPILER)" == "MN0200" || "$(COMPILER)" == "MN0400"
.c.obj:
	cl /c /W3 /GX- /Z7 /DDEBUG /DSSI /Gs $<
!endif
!if "$(COMPILER)" == "WD1000" || "$(COMPILER)" == "WD1050"
.c.obj:
	wcc386 /ez /w4 /s /zq /mf /fpc /d2 /oi /of /4s /dDEBUG=1 /dSSI=1 /hc $<
!endif
!if "$(COMPILER)" == "BD0400" || "$(COMPILER)" == "BD0450"
.c.obj:
	bcc32 -c -w-pro -x- -v -y -r- -Od -DDEBUG -DSSI $<
#        bcc32 -c -w-pro -x- -I$(LLINCLOC) -v -y -r- -Od -DDEBUG -DSSI $<
!endif

#targets

all: $(OBJS) 
  $(LINK386) @<<$(OUTFILE).cmd
$(OBJS)
$(COMPILER)fd.lib
!if "$(COMPILER)" == "BD0400" || "$(COMPILER)" == "BD0450"
cw32.lib
!endif
-ignorenull                     & ignore zero-length segments
-nowa(33)                       & Disable "UNRESOLVED ..." _warning_
-nowa(315)                      & Disable "DESCRIPTOR NOT ASSIGNED"...
-op($(OUTFILE))                 & generate .OMF and .MAP file
-dosorder
-init
-bf(foo;

createseg
   data_start,                         -- dummy place-holder; start of RAM
   code_start;                         -- dummy place-holder; start of ROM

segment
   data_start(base = 050000h, ro),
   dgroup(rominit);                     -- initialized data is in _DATA

--  ALIAS defination for Borland C 4.0 only.
!if "$(COMPILER)" == "BD0400"
alias
    _FSDATA(_FSALIAS);
!endif

gate
   INT126_GATE(INTERRUPT, DPL=3, ENTRY=_ISR_PIT1_THUNK),
   INT125_GATE(INTERRUPT, DPL=3, ENTRY=_ISR_PIT_WD_THUNK),
   INT120_GATE(INTERRUPT, DPL=3, ENTRY=_ISR_RTC_THUNK),
   INT124_GATE(INTERRUPT, DPL=3, ENTRY=_ISR_PCM_THUNK);

--  Set up a task state segment (TSS), so the debugger knows where to start
--  the application.

task
   init_task(code = ssi_startup, data = dgroup, stacks = (stack));


--  Reserve space in the GDT and the IDT for the debugger's entries
table
   GDT(                                & Global Descriptor Table 
       limit = 17,                     & make room for entry 0 to 16
       entry = (*segments),
       rominit
      ),
   IDT(                                & Interrupt Descriptor Table 
       limit = 256,                    & make room for entry 0 to 0FFh
       entry = (120:INT120_GATE, 124:INT124_GATE, 125:INT125_GATE, 126:INT126_GATE),
       rominit
      ),
   LDT?(                               & Local Descriptor Table
	not created                    & Don't create and output it 
       );

createseg
  SSI_HEAP(limit = 01FFFh);

segsym
  segments(SSI_HEAP);

-- Specify how memory is organized.  All data is ordered to follow the
-- DATA_START segment and all code (and SSI_ROMINIT) is ordered to follow the
-- CODE_START segment.  You should only need to change the base of DATA_START
-- and/or CODE_START.

order
   segments(data_start, ssi_data),
   groups(dgroup),
   tables(GDT, IDT),
   segments(ssi_heap);

order
   segments(code_start),
   tasks(init_task),
   classes(code, rominit);

& include the compiler-dependent definitions defined by STDDEF.MAK

!if "$(COMPILER)" == "BD0400" || "$(COMPILER)" == "BD0450"
segsym segments(_INIT_, _EXIT_);  alias _fsdata(_fsalias);  table gdt(entry = (_fsalias));
!endif

!if "$(COMPILER)" == "MN0200" || "$(COMPILER)" == "MN0400"
order segments(_crt$$xca, _crt$$xcu);
!endif

end;)
<<NOKEEP

  
clean:
	if exist *.obj del *.obj
	if exist *.err del *.err
	if exist *.opt del *.opt
	if exist $(OUTFILE).omf del $(OUTFILE).omf
	if exist $(OUTFILE).map del $(OUTFILE).map
	if exist $(OUTFILE).hex del $(OUTFILE).hex
	if exist $(OUTFILE).bin del $(OUTFILE).bin
	if exist $(OUTFILE).exe del $(OUTFILE).exe
	if exist $(OUTFILE).rtb del $(OUTFILE).rtb
	if exist $(OUTFILE).tds del $(OUTFILE).tds
	if exist $(OUTFILE).loc del $(OUTFILE).loc
	if exist $(OUTFILE).t?2 del $(OUTFILE).t?2
