/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.

Command line

I store all my Windows environment scripts in a gitlab directory cloned to %USERPROFILE%\scripts and I add the following line in my doskey configuration like this:

doskey db=%USERPFROFILE%\scripts\dosbox.bat $*

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 = <your_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 hereafter.
You can grab the latest version from dosbox.bat
The latest configuration I use is available in dosbox.conf

@echo off

REM ---------------------------------------------------------------------------
REM dosbox launcher
REM
REM the DOSBOX environment variable shall be set to the dosbox.exe full path
REM ---------------------------------------------------------------------------

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

if not exist "%DOSBOX%" goto :DOSBOXERR

set filepath="%1"

REM for /F "delims="      means no delimiter, process the entire string
REM %%~dpi                expand %%i to drive letter (d) with path (p)
REM %%~nxi                expand %%i to a file name (n) with extension (x) 

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

"%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 DOSBOS is currently set to "%DOSBOX%"
echo[
goto :END

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

:END