@echo off ::quit if not Windows NT: IF "%OS%"=="" goto BADVER SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS :retry ::initialize various variables set ASMFILELIST= set CFILELIST= set OBJFILELIST= set DEFCODEOFFSET=04000H set DEFDATAOFFSET=00400H set DEFSTACKOFFSET=07000H set DEFPOWEROFFSET=02000H set ASMARGS=m1 ep set LNKARGS= set LOCARGS= set LOCSEGS= set PREVOPT= set ASM86=asm86 set LINK86=link86 set LOC86=loc86 set OUTPUT= set CODELOC= set DATALOC= set STACKLOC= set NOMAGIC= set CODE=CODE set DATA=DATA set STACK=STACK set STOP= set DEBUG=db set RES= set CLIBS= set CARGS=extend mod186 small optimize(0) rom si(c:\ic86\) debug ::process arguments: loop through args and set various variables for %%A in (%*) do ( if /I "%%~xA"==".asm" ( set asmfilelist=!asmfilelist! %%A set objfilelist=!objfilelist! %%~nA.obj if "!OUTPUT!"=="" set OUTPUT=%%~nA ) if /I "%%~xA"==".c" ( set cfilelist=!cfilelist! %%A set objfilelist=!objfilelist! %%~nA.obj set CLIBS=,sclib.lib,ic86.lib ) if /I "%%~xA"==".obj" set objfilelist=!objfilelist! %%A if /I "%%~xA"==".lib" set objfilelist=!objfilelist! %%A if "%%A"=="-m" set NOMAGIC=1 if "%%A"=="-h" goto usage if "%%A"=="-asm" set STOP=asm if "%%A"=="-lnk" set STOP=lnk if "%%A"=="-nodb" set DEBUG= if "!PREVOPT!"=="-c" ( ::set DEFCODEOFFSET for magic and CODELOC for nonmagic set DEFCODEOFFSET=%%A set CODELOC=%%A ) if "!PREVOPT!"=="-d" ( set DEFDATAOFFSET=%%A set DATALOC=%%A ) if "!PREVOPT!"=="-s" ( set DEFSTACKOFFSET=%%A set STACKLOC=%%A ) if "!PREVOPT!"=="-A" ( set ASMARGS=%%~A set DEBUG= ) if "!PREVOPT!"=="-L" set LNKARGS=%%~A if "!PREVOPT!"=="-T" set LOCARGS=%%~A if "!PREVOPT!"=="-o" set OUTPUT=%%~nA if "!PREVOPT!"=="-C" set CODE=%%A if "!PREVOPT!"=="-D" set DATA=%%A if "!PREVOPT!"=="-S" set STACK=%%A set PREVOPT=%%A ) ::check if no files were specified: if "%OBJFILELIST%"=="" ( echo Error: no input files specified. goto :EOF ) ::get rid of leading comma-space: :set OBJFILELIST=%OBJFILELIST:~2% ::assemble each .asm file for %%A in (%ASMFILELIST%) do ( echo. echo asm86 %%A %ASMARGS% %DEBUG% %ASM86% %%A %ASMARGS% %DEBUG% && find "NO ERRORS FOUND" %%~nA.LST > nul 2>&1 if ERRORLEVEL 1 ( set /P RES="Errors found assembling %%A. Continue? [y/n/r] " if /I "!RES!"=="r" goto retry if /I "!RES!" NEQ "Y" goto :EOF ) ) for %%A in (%CFILELIST%) do ( echo. echo ic86 %%A !CARGS! ic86 %%A !CARGS! && find "0 ERRORS" %%~nA.LST > nul 2>&1 if ERRORLEVEL 1 ( set /P RES="Errors found compiling %%A. Continue? [y/n/r] " if /I "!RES!"=="r" goto retry if /I "!RES!" NEQ "Y" goto :EOF ) find "0 WARNINGS" %%~nA.LST > nul 2>&1 if ERRORLEVEL 1 ( set /P RES="Warning compiling %%A. Continue? [y/n/r] " if /I "!RES!"=="r" goto retry if /I "!RES!" NEQ "Y" goto :EOF ) ) ::stop if we only wanted if "%STOP%"=="asm" goto :EOF echo. echo link86 %OBJFILELIST% %LNKARGS% to %OUTPUT%.lnk echo ^& > linkargs.tmp set OBJFILE= ^& for %%a in (%OBJFILELIST%) do ( echo !OBJFILE! >> linkargs.tmp set OBJFILE=%%a, ^& ) echo %OBJFILE:~,-3% ^&>> linkargs.tmp echo %CLIBS% %LNKARGS% to %OUTPUT%.lnk >> linkargs.tmp ::echo %OBJFILELIST% %LNKARGS% to %OUTPUT%.lnk > linkargs.tmp %LINK86% ^&< linkargs.tmp del linkargs.tmp if "%STOP%"=="lnk" goto :EOF find "WARNING" %OUTPUT%.MP1 > nul if "%ERRORLEVEL%"=="0" ( type %OUTPUT%.MP1 set /P RES="Linker warning encountered. Continue? [y/n/r] " if /I "!RES!"=="r" goto retry if /I "!RES!" NEQ "Y" goto :EOF ) find "UNRESOLVED" %OUTPUT%.MP1 > nul if "%ERRORLEVEL%"=="0" ( type %OUTPUT%.MP1 set /P RES="Unresolved symbols. Continue? [y/n/r] " if /I "!RES!"=="r" goto retry if /I "!RES!" NEQ "Y" goto :EOF ) ::automagically figure out which segments your stuff actually has before locating: if "%NOMAGIC%"=="1" goto nomagic echo. set SCANNING= set CODELOC= set DATALOC= set STACKLOC= for /f "tokens=1,4,5" %%a in (%OUTPUT%.MP1) do ( if "%%a"=="LENGTH" if "%%c"=="CLASS" set SCANNING=1 if "!SCANNING!" NEQ "" ( if "%%c"=="CODE" ( echo Found code segment: %%b set CODE=%%b set CODELOC=%DEFCODEOFFSET% ) if "%%c"=="POWER_ON" ( echo Found power segment: %%b set POWER=%%b set POWERLOC=%DEFPOWEROFFSET% ) if "%%c"=="DATA" ( echo Found data segment: %%b set DATA=%%b set DATALOC=%DEFDATAOFFSET% ) if "%%c"=="STACK" ( echo Found stack segment: %%b set STACK=%%b set STACKLOC=%DEFSTACKOFFSET% ) ) ) :nomagic if "%CODELOC%%DATALOC%%STACKLOC%"=="" ( echo. echo No code, data, or stack segment found. Did you use -m and not specify -c, -s echo or -d? goto :EOF ) if "%CODELOC%" NEQ "" set LOCSEGS=%LOCSEGS%, %CODE%(%CODELOC%) if "%DATALOC%" NEQ "" set LOCSEGS=%LOCSEGS%, %DATA%(%DATALOC%) if "%STACKLOC%" NEQ "" set LOCSEGS=%LOCSEGS%, %STACK%(%STACKLOC%) if "%POWERLOC%" NEQ "" set LOCSEGS=%LOCSEGS%, %POWER%(%POWERLOC%) echo. set LOCARGS=%OUTPUT%.lnk to %OUTPUT% noic ad(sm(%LOCSEGS:~2%)) %LOCARGS% echo loc86 %LOCARGS% %LOC86% %LOCARGS% echo oh86 %OUTPUT% to %OUTPUT%.hex oh86 %OUTPUT% to %OUTPUT%.hex ENDLOCAL goto :EOF :usage set tempfile=%TEMP%\build%RANDOM%.tmp echo Build: automagically assemble, link, and locate for EE 5x>%tempfile% echo Usage: build filelist [options]>>%tempfile% echo.>>%tempfile% echo Options:>>%tempfile% echo -A "args" List of extra arguments to be passed to the assembler>>%tempfile% echo -L "args" List of extra arguments to be passed to the linker>>%tempfile% echo -T "args" List of extra arguments to be passed to the locater>>%tempfile% echo -o outfile Name of output file; default is first item in filelist>>%tempfile% echo -m Disable automagic segment name/presence detection>>%tempfile% echo -c offset Offset of code segment; default is 4000H>>%tempfile% echo -d offset Offset of data segment; default is 1000H>>%tempfile% echo -s offset Offset of stack segment; default is 2000H>>%tempfile% echo -C name Name of code segment; default is CODE>>%tempfile% echo -D name Name of data segment; default is DATA>>%tempfile% echo -S name Name of stack segment; default is STACK>>%tempfile% echo -asm Assemble only>>%tempfile% echo -lnk Assemble (if applicable) and link only>>%tempfile% echo -nodb Do not include debugging symbols in output>>%tempfile% echo.>>%tempfile% echo If you use -m, you must specify offsets for the code, data, and/or stack>>%tempfile% echo segments; the default segment names are CODE, DATA, and STACK. The -c, -d,>>%tempfile% echo and -s options do NOT imply -m. If -m is not specified, -c, -d, and -s may>>%tempfile% echo still be used, but -C, -D, and -S are ignored.>>%tempfile% echo.>>%tempfile% echo By default, the controls m1 (186/188 mode), ep (print errors), and db>>%tempfile% echo (include symbols) are passed to the assembler. Use nodb to remove debug>>%tempfile% echo symbols, -A "" to prevent any arguments from being passed.>>%tempfile% echo.>>%tempfile% echo Examples:>>%tempfile% echo.>>%tempfile% echo build foo.asm>>%tempfile% echo Assembles, links, and locates the file foo.asm to FOO.>>%tempfile% echo.>>%tempfile% echo build *.asm>>%tempfile% echo Assembles, links, and locates all .asm files in directory>>%tempfile% echo.>>%tempfile% echo build foo.asm bar.obj>>%tempfile% echo Assembles foo.asm and links it with bar.obj, then locates. The>>%tempfile% echo resulting file will be named FOO.>>%tempfile% more %tempfile% del %tempfile% goto :EOF :BADVER echo "Sorry...build is not compatible with Windows 9x or earlier."