/home

DOSBox launcher

Mon, 18 Nov 2024

With this simple dosbox.bat script, it is now easy to lanch DOSBox onto built executables from the command line, from a makefile or from VSCode.

Watcom makefile

I typically add the following lines in my Watcom makefiles:

!ifdef __DOS__
LAUNCHER =              # launch the real .exe under MS-DOS
!else                       
LAUNCHER = dosbox.bat   # launch dosbox under Windows
!endif

.NOCHECK
run: $(TARGET).exe          # Of course, TARGET = <you_own>.exe ...
    $(LAUNCHER) $(TARGET).exe

Of course, it is supposed to have the TARGET set to your targeted executable.

dosbox.bat

The script code for easy reading purpose:

@echo off

REM dosbox launcher

if "%~1"=="" goto :BLANK

if not exist "%DOSBOX%" goto :DOSBOXERR

set filepath="%1"

for /F "delims=" %%i in (%filepath%) do set dirname=%%~dpi
for /F "delims=" %%i in (%filepath%) do set filename=%%~nxi
for /F "delims=" %%i in (%filepath%) do set basename=%%~ni

"%DOSBOX%" -noconsole -conf "%~dp0\dosbox.conf" -c "mount Y '%dirname%'" -c "Y:" -c "%filename%" -c "pause"  -c "exit"
goto :END

:DOSBOXERR
echo[
echo dosbox.exe not found using the DOSBOX env var
echo DOSBOX shall be set to <path_to_dos_box>\dosbox.exe
echo[
goto :END

:BLANK
echo[
echo Missing DOS executable to launch
echo %0 "<path/to/file.exe>"
echo[

:END