How to check if running in DOSBOX

DOS specific questions.
Post Reply
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

How to check if running in DOSBOX

Post by coderJeff »

This seems fairly stable to check if the DOS program is running in a DOSBOX session.

It reads some strings at the beginning of BIOS memory area and searches for "DOSBOX"

Code: Select all

#include once "dos/sys/movedata.bi"

function IsRunningInDOSBOX() as boolean
	const BIOS_STRING_LENGTH = 128
	dim s as zstring * (BIOS_STRING_LENGTH + 1)
	dim b as ubyte ptr = @s
	dosmemget( &hf000u * 16 + &he000u, BIOS_STRING_LENGTH, @s )  
	for i as integer = 0 to BIOS_STRING_LENGTH-1
		if( b[i] < 32 ) then
			b[i] = asc(".")
		end if
	next
	return cbool(instr( s, "DOSBox" ) > 0)
end function

print "Running in dosbox = "; IsRunningInDOSBOX()
Valeriecrase
Posts: 1
Joined: Jul 25, 2023 6:55

Re: How to check if running in DOSBOX

Post by Valeriecrase »

coderJeff wrote: Mar 26, 2023 12:58 This seems fairly stable to check if the DOS program is running in a DOSBOX session. prepaidgiftbalance

It reads some strings at the beginning of BIOS memory area and searches for "DOSBOX"

Code: Select all

#include once "dos/sys/movedata.bi"

function IsRunningInDOSBOX() as boolean
	const BIOS_STRING_LENGTH = 128
	dim s as zstring * (BIOS_STRING_LENGTH + 1)
	dim b as ubyte ptr = @s
	dosmemget( &hf000u * 16 + &he000u, BIOS_STRING_LENGTH, @s )  
	for i as integer = 0 to BIOS_STRING_LENGTH-1
		if( b[i] < 32 ) then
			b[i] = asc(".")
		end if
	next
	return cbool(instr( s, "DOSBox" ) > 0)
end function

print "Running in dosbox = "; IsRunningInDOSBOX()
Hello,

The provided code attempts to check if the program is running in a DOSBox session by reading the BIOS memory area and searching for the string "DOSBOX." It uses FreeBASIC language and the dosmemget function to access the BIOS memory. The function replaces non-printable characters with periods (".") to make the search more robust. Finally, it returns a boolean value indicating whether "DOSBOX" was found in the BIOS memory, which implies it's running in DOSBox. However, it's important to note that this method may not be foolproof, as future changes to DOSBox or variations in its memory representation could potentially affect the accuracy of the detection.
SARG
Posts: 1756
Joined: May 27, 2005 7:15
Location: FRANCE

Re: How to check if running in DOSBOX

Post by SARG »

Bot ? :twisted:
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: How to check if running in DOSBOX

Post by coderJeff »

An, accurate description of what this function does; no matter who / what wrote it.
A nice reminder that original post could have been better with a description of function.
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: How to check if running in DOSBOX

Post by xlucas »

I don't remember the exact details, but I vaguely remember there was a way to check whether a program was running under DOSBox by calling a function of int 2Fh (multiplex)...
Post Reply