Author Topic: run program before and after emulator  (Read 17552 times)

slydog43

  • Full Member
  • ***
  • Posts: 66
    • View Profile
run program before and after emulator
« on: February 09, 2016, 02:51:46 PM »
Is there a way to run a program before an emulator is launched and another program when finished before going back to AM?

krypstocken

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: run program before and after emulator
« Reply #1 on: February 10, 2016, 04:53:24 AM »
Yes...
Instead of pointing AM to the binary for ( as an example) MAME point it towards a script that launches your SW then MAME and finale the last SW

K

hermine.potter

  • Hero Member
  • *****
  • Posts: 767
    • View Profile
Re: run program before and after emulator
« Reply #2 on: February 10, 2016, 05:14:22 AM »
With autoit
e.g. this order :
start first program : ping-command > if ping-command not available: start notepad > start second program : calculator > start third programm, if second programm is closed : waits till calculator is closed and starts paint > exit program

Code: [Select]
;Starts first program
Run("ping 127.0.0.1 -n 10", "", @SW_SHOWMAXIMIZED)

;Starts another program if special task isn't found
If Not ProcessExists("PING.exe") Then
Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
EndIf

;Starts second program
Run("calc.exe", "", @SW_SHOWMAXIMIZED)

;Wait that second programm ends; starts third program
While 1
If Not ProcessExists("calc.exe") Then
Run("mspaint.exe", "", @SW_SHOWMAXIMIZED)
Exit
EndIf
WEnd
AM Version : 2.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM

slydog43

  • Full Member
  • ***
  • Posts: 66
    • View Profile
Re: run program before and after emulator
« Reply #3 on: February 10, 2016, 05:20:02 AM »
Not sure how to pass all the parameters to final emulator program after launching my first program.

hermine.potter

  • Hero Member
  • *****
  • Posts: 767
    • View Profile
Re: run program before and after emulator
« Reply #4 on: February 10, 2016, 07:10:22 AM »
An example with zsnes:

You can start the emulator system zsnes in AM this way:

path_to_your_emulator_system\emulator_system.exe -parameters_that_starts_a_rom path_to_your_roms\romfile.rom_extension

this command-line starts a specific snes-game directly:
C:\attract\EMU\zsnes\zsnesw.exe -m C:\attract\EMU\zsnes\roms\my_snes_game.smc

In AM use this config:
executable           C:\attract\EMU\zsnes\zsnesw.exe
args                 -m "[romfilename]"
rompath              C:\attract\EMU\zsnes\roms
romext               .smc

An example script:
You want showing the controls of a specific game (they're are stored in a text-file calles Game123 (E).txt); this script opens the text-file of Game123, waits 5 seconds and starts Game123;
you play some minutes, have a look to text-file, play some minutes and so on (you switch between game and text-file).
After exits zsnes, text-file closes too.

Code: [Select]
;starts first program
Run("notepad.exe " & '"C:\attract\EMU\zsnes\controls\Game123 (E).txt"', "", @SW_MAXIMIZE )

;waits five seconds till second program starts
sleep("5000")
Run('"C:\attract\EMU\zsnes\zsnesw.exe" -m "C:\attract\EMU\zsnes\roms\Game123 (E).smc"')

;waits till second program ends and starts third program (in this case : kills task notepad )
While 1
If Not ProcessExists("zsnesw.exe") Then
ProcessClose("notepad.exe")
Exit
EndIf
WEnd
« Last Edit: February 10, 2016, 07:13:06 AM by hermine.potter »
AM Version : 2.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: run program before and after emulator
« Reply #5 on: February 15, 2016, 10:25:28 PM »
You can also create a plugin  to achieve this, Attract-Mode's Ultrastik360 plugin is an example of how this can be done: https://github.com/mickelson/attract/blob/master/config/plugins/UltraStik360.nut


Edit: and the command for running a program from a script is described here: https://github.com/mickelson/attract/blob/master/Layouts.md#plugin_command
« Last Edit: February 15, 2016, 10:27:47 PM by raygun »

slydog43

  • Full Member
  • ***
  • Posts: 66
    • View Profile
Re: run program before and after emulator
« Reply #6 on: July 13, 2017, 04:21:24 PM »
Has anyone created a pluging to run before/run after functionallity?

hermine.potter

  • Hero Member
  • *****
  • Posts: 767
    • View Profile
Re: run program before and after emulator
« Reply #7 on: August 08, 2020, 02:35:52 AM »
@ slydog43
Now had time. Had vacation.
And again : squirrel language is not my language ^-^

AtBegin.nut and AtExit.nut are based on ResFix.nut
copy them to Your_AM_Folder\plugins and activate them in AM

basically it uses squirrel commands: Transition.ToGame + Transition.FromGame + system

if you start a game, AtBegin.nut starts your stored commands.
if you exit a game, AtExit starts your stored commands.

escape characters are necessary:
start "" "C:\Program Files (x86)\MyEXE.exe"
system( "start \"\" \"C:\\Program Files (x86)\\MyEXE.exe\"" );



An inquiry:
Since AM version 2.2.1, it's possible to add a working directory path in emulator edits (start AM > TAB button > Emulators > your_emulator > Working Directory). Here
Is it possible to add two more input fields there? Like AtBegin and AtExit ?
« Last Edit: August 08, 2020, 02:37:46 AM by hermine.potter »
AM Version : 2.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM

manzarek

  • Sr. Member
  • ****
  • Posts: 156
    • View Profile
    • YouTube
Re: run program before and after emulator
« Reply #8 on: August 28, 2020, 07:07:51 AM »
wau I'll try it thanks
Mame Fighting

hermine.potter

  • Hero Member
  • *****
  • Posts: 767
    • View Profile
AM Version : 2.6.1
Input : Mad Catz Brawlstick; Mouse; Keyboard; Xbox360 Wireless
Cabinet : Yes
OS : Windows10 Pro
System : Dell Precision T3500 ; Intel X5650 ; 12GB RAM