msxbuild/lib/openmsx/share/scripts/headless.tcl
Willem Cazander 779138daca
All checks were successful
Run test asserts / Test-Asserts (push) Successful in -10s
Fixed missed renames.
2024-06-30 23:24:15 +02:00

89 lines
2.3 KiB
Tcl

# headless -- Controls the boot mode config of openMSX from environment variables.
#
# Typically used in automation tools which run openMSX without human interaction.
#
# Adds the following command to openMSX;
#
# 'headless_exit'
# A normal exit of the openMSX emulator.
#
# 'headless_show_gui'
# Enables the renderer and throttle from the inside.
#
# Supported environment variables by this script;
#
# HEADLESS=on|off
# Override video output from command line.
#
# RENDERER=SDL
# Select video renderer type for GUI mode or in none headless mode.
#
# SCALE_FACTOR=3
# Override video scale factor for the renderer.
#
# THROTTLE=off
# Disables MSX speed emulation.
#
# SPEED=333
# Sets CPU speed to relative from normal but only when throttle is on.
#
set headless_renderer_type 0
set headless_renderer_done 0
proc headless_exit {} {
after time 1 "exit 0"
return "Shutdown openMSX"
}
proc headless_show_gui {} {
global renderer
global throttle
global headless_renderer_type
global headless_renderer_done
if {$headless_renderer_done != 0} {
return "Requested GUI already showing"
}
if {$headless_renderer_type != 0} {
after time 1 "set renderer $headless_renderer_type"
set throttle on
set headless_renderer_done 1
} else {
puts stderr "error: Requested show gui but env.RENDERER is missing."
exit 1
}
return "Requested GUI with $headless_renderer_type"
}
if {[info exists ::env(RENDERER)] && ([string trim $::env(RENDERER)] != "")} {
set headless_renderer_type [string trim $::env(RENDERER)]
}
if {[info exists ::env(HEADLESS)] && ([string trim $::env(HEADLESS)] != "on")} {
if {[catch {set renderer $headless_renderer_type} err_msg]} {
puts stderr "error: env.HEADLESS value $err_msg"
exit 1
}
}
if {[info exists ::env(SCALE_FACTOR)] && ([string trim $::env(SCALE_FACTOR)] != "")} {
if {[catch {set scale_factor [string trim $::env(SCALE_FACTOR)]} err_msg]} {
puts stderr "error: env.SCALE_FACTOR value $err_msg"
exit 1
}
}
if {[info exists ::env(THROTTLE)] && ([string trim $::env(THROTTLE)] != "")} {
if {[catch {set throttle [string trim $::env(THROTTLE)]} err_msg]} {
puts stderr "error: env.THROTTLE value $err_msg"
exit 1
}
}
if {[info exists ::env(SPEED)] && ([string trim $::env(SPEED)] != "")} {
if {[catch {set speed [string trim $::env(SPEED)]} err_msg]} {
puts stderr "error: env.SPEED value $err_msg"
exit 1
}
}