Skip to content

Commit

Permalink
Improve transition from Frontend to emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
10yard committed Jul 21, 2021
1 parent 616a64f commit b952a09
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ sudo cp COPYING dist
# copy rpi4 specific settings
sudo cp rpi4/settings.txt dist
sudo cp rpi4/dkafe_start.sh dist
sudo cp rpi4/fs.sh dist
sudo cp rpi4/w_enter.sh dist
sudo cp rpi4/w_exit.sh dist

# create empty roms folder
sudo mkdir dist/roms
Expand Down
2 changes: 1 addition & 1 deletion dk_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def build_launch_command(info, basic_mode):
if script:
# An interface script is available
competing = True
launch_command += f' -noconsole -autoboot_script {os.path.join(ROOT_DIR, "interface", script)}'
launch_command += f' -console -autoboot_script {os.path.join(ROOT_DIR, "interface", script)}'

return launch_command, launch_directory, competing

Expand Down
7 changes: 3 additions & 4 deletions launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,11 @@ def launch_rom(info, override_emu=None):
os.chdir(launch_directory)
if EMU_ENTER:
# Optional command to issue before launching the emulator
Popen(EMU_ENTER.replace("<ROOT>", ROOT_DIR), shell=False)
Popen(EMU_ENTER, shell=False)
if EMU_EXIT:
# Optional command to issue when exiting emulator
launch_command += f"; {EMU_EXIT} "
launch_command += f"; {EMU_EXIT}"
os.system(launch_command)
# clear_screen(and_reset_display=True)
pygame.time.delay(50) # debounce
_g.lastexit = _g.timer.duration
os.chdir(ROOT_DIR)
Expand Down Expand Up @@ -756,7 +755,7 @@ def process_interrupts():
ticks = pygame.time.get_ticks()

# Start up messages from Pauline
if not _g.lastmove:
if not _g.lastmove and not display_icons(detect_only=True):
message = (COIN_INFO, FREE_INFO)[int(FREE_PLAY or BASIC_MODE)]
write_text(message[int(_g.timer.duration) % len(message)], x=108, y=37, fg=WHITE, bg=MAGENTA, bubble=True)
show_score()
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Allow roms in ROM_DIR to be overwritten. Set to 1 when using an emulator that d
Optional system command to issue before launching emulator

`EMU_EXIT`
Optional system command to issue after exiting emulator e.g. using `wmctrl -Fa DKAFE` to return focus to the frontend on Raspberry Pi.
Optional system command to issue after exiting emulator


### DK Interface Settings
Expand Down
4 changes: 2 additions & 2 deletions rpi4/rpi4_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ MAME launches much faster in window mode (-window argument)
To take advantage we launch with -window and switch to full screen using the provided fs.sh
bash script.
The script runs after emulator starts and is specified in settings:
EMU_ENTER = nohup ./fs.sh
EMU_ENTER = <ROOT>/w_enter.sh

To ensure safe switching back to DKAFE when emulator exits we specify in settings:
EMU_EXIT = wmctrl -Fa DKAFE
EMU_EXIT = nohup <ROOT>/w_exit.sh > /dev/null 2>&1 & wmctrl -Fa DKAFE > /dev/null 2>&1


Scan line generator
Expand Down
10 changes: 5 additions & 5 deletions rpi4/settings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Front End Features
FREE_PLAY = 0
UNLOCK_MODE = 1
FREE_PLAY = 1
UNLOCK_MODE = 0
BASIC_MODE = 0
INACTIVE_TIME = 20
SHOW_SPLASHSCREEN = 1
Expand All @@ -16,13 +16,13 @@ ROM_DIR = <ROOT>/roms
ALLOW_ROM_OVERWRITE = 0

# Emulator Settings for Raspberry Pi4
OPTIONS = -window -rompath <ROM_DIR> -view "Pixel Aspect (7:8)"
OPTIONS = -rompath <ROM_DIR> -view "Pixel Aspect (7:8)" -w -max
EMU_1 = <ROOT>/dkwolf/dkwolfrpi <OPTIONS>
EMU_2 = <ROOT>/dkwolf/dkwolfrpi <OPTIONS> -nvram_directory /dev/null -record <RECORD_ID>

# Window Management
EMU_ENTER = <ROOT>/fs.sh
EMU_EXIT = wmctrl -Fa DKAFE
EMU_ENTER = <ROOT>/w_enter.sh
EMU_EXIT = nohup <ROOT>/w_exit.sh > /dev/null 2>&1 & wmctrl -Fa DKAFE > /dev/null 2>&1

# Interface Settings
CREDITS = 1
Expand Down
15 changes: 7 additions & 8 deletions rpi4/fs.sh → rpi4/w_enter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
# DKAFE by Jon Wilson
# Switch to fullscreen when wmctrl detects MAME window.
# Use this line in your settings.txt to enable it i.e.
# EMU_ENTER = <ROOT>/fs.sh
# EMU_ENTER = <ROOT>/w_enter.sh

i=0
while [ $i -lt 20 ]
for i in {1..20}
do
# Keep focus on DKAFE until MAME starts
wmctrl -Fa DKAFE
if wmctrl -l | grep -q MAME:; then
# Switch focus to MAME
sleep 0.25
# Wait for MAME to start up then switch focus
sleep 0.6
wmctrl -a MAME: -b add,fullscreen
break
exit
fi
sleep 0.1
i=$[$i+1]
sleep 0.2
done
exit
13 changes: 13 additions & 0 deletions rpi4/w_exit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# DKAFE by Jon Wilson
# Switch focus back to DKAFE.
# Use this line in your settings.txt to enable it i.e.
# EMU_EXIT = <ROOT>/w_exit.sh

# Switch focus back to DKAFE
for i in {1..6}
do
wmctrl -Fa DKAFE
sleep 0.1
done
exit

0 comments on commit b952a09

Please sign in to comment.