94 lines
2.5 KiB
Python
94 lines
2.5 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import os
|
||
|
import configparser
|
||
|
import logging
|
||
|
import subprocess
|
||
|
|
||
|
# Set up logging
|
||
|
logging.basicConfig(filename='dbgr.log', level=logging.DEBUG)
|
||
|
|
||
|
# Call config editor GUI application
|
||
|
subprocess.run(['python', 'config_editor.py'])
|
||
|
|
||
|
# Load configuration from file
|
||
|
config = configparser.ConfigParser()
|
||
|
if not os.path.exists('dbgr.conf'):
|
||
|
# Create config file with default values
|
||
|
config['DEFAULT'] = {
|
||
|
'dosbox_path': '',
|
||
|
'game_path': '',
|
||
|
'working_directory': '',
|
||
|
'-noconsole': '',
|
||
|
'-conf': 'dbgr.conf',
|
||
|
'-cycles': 'auto',
|
||
|
'-cputype': 'auto',
|
||
|
'-memsize': '16',
|
||
|
'-sblaster': 'sb16',
|
||
|
'-sbbase': '220',
|
||
|
'-irq': '7',
|
||
|
'-dma': '1',
|
||
|
'-ultradir': 'c:\\ultra',
|
||
|
'-mididevice': 'default',
|
||
|
'-mpu401': 'intelligent',
|
||
|
'-uart': '16550A',
|
||
|
'-midi': 'mpu-401',
|
||
|
'-cdrom': '',
|
||
|
'-ioctl': '',
|
||
|
'-serial': 'nullmodem',
|
||
|
'-ipx': 'true',
|
||
|
'-net': 'nic',
|
||
|
'ms_dos_exe': '',
|
||
|
}
|
||
|
with open('dbgr.conf', 'w') as configfile:
|
||
|
config.write(configfile)
|
||
|
else:
|
||
|
config.read('dbgr.conf')
|
||
|
|
||
|
# Detect DOSBox path if not specified in config
|
||
|
if not config['DEFAULT']['dosbox_path']:
|
||
|
dosbox_paths = ['/usr/local/bin/dosbox', '/usr/bin/dosbox', '/usr/bin/dosbox-staging']
|
||
|
for path in dosbox_paths:
|
||
|
if os.path.exists(path):
|
||
|
config['DEFAULT']['dosbox_path'] = path
|
||
|
break
|
||
|
|
||
|
# Set game path and working directory from config
|
||
|
game_path = config['DEFAULT']['game_path']
|
||
|
working_directory = config['DEFAULT']['working_directory']
|
||
|
|
||
|
# Set DOSBox options from config, overriding any defaults set in the script
|
||
|
for switch, value in config['DEFAULT'].items():
|
||
|
if switch.startswith('-') and value:
|
||
|
os.environ[switch] = value
|
||
|
|
||
|
# Set audio and video options with sane defaults
|
||
|
if 'audio' not in config:
|
||
|
config['audio'] = {
|
||
|
'sbtype': 'sb16',
|
||
|
'sbbase': '220',
|
||
|
'irq': '7',
|
||
|
'dma': '1'
|
||
|
}
|
||
|
|
||
|
if 'video' not in config:
|
||
|
config['video'] = {
|
||
|
'output': 'sdl',
|
||
|
'aspect': 'false',
|
||
|
'scaler': 'normal2x',
|
||
|
'fullresolution': 'desktop',
|
||
|
'window_mode': 'true'
|
||
|
}
|
||
|
|
||
|
# Write updated configuration to file
|
||
|
with open('dbgr.conf', 'w') as configfile:
|
||
|
config.write(configfile)
|
||
|
|
||
|
# Run DOSBox with specified game and options
|
||
|
if not os.path.exists(game_path):
|
||
|
raise Exception(f"Game path '{game_path}' does not exist.")
|
||
|
|
||
|
os.chdir(working_directory)
|
||
|
os.system(f'"{config["DEFAULT"]["dosbox_path"]}" -conf dbgr.conf "{game_path}"')
|
||
|
|