Closing ZSNES from another process? (ie frontends)

Found a bug? Please report it, but remember to follow the bug reporting guidelines.
Missing a sane feature? Let us know!
But please do NOT request ports to other systems.

Moderator: ZSNES Mods

Post Reply
chmmr
New Member
Posts: 5
Joined: Sun Mar 12, 2006 8:48 pm

Closing ZSNES from another process? (ie frontends)

Post by chmmr »

I'm writing a multi-emulator frontend for use with joystick-only setups (eg arcade cabinets and HTPCs). Most emulators require a keyboard input of some sort to exit the program, usually ALT-F4 or ESC, and I've had to solve this in a joystick-friendly way.

My frontend allows the user to select a ROM and an emulator to play it with, boots up the emulator, and sits in the background waiting for a certain multi-button "escape sequence" on the joystick/gamepad. When this sequence is entered, I close down the emulator process and return focus to the frontend, allowing the user to select a new ROM and emulator, and so on.

My first attempt at this functionality used the Win32 API method TerminateProcess. This shuts down the emulator rather abruptly, and in the case of some emulators can cause data loss - I've noticed ZSNES doesn't finish writing to (and presumably close the file handle of) SRM save data files until it successfully exits. So the user might use the escape sequence, kill ZSNES and lose a few hours of progress in Super Metroid :(((

This wouldn't do, so I implemented the more "polite" way of closing down the process: sending a WM_CLOSE message to the emulator's main window. Most emulators respond well to this, finishing up writes they have to do and closing down nicely. ZSNES doesn't seem to respond to the WM_CLOSE, however, and the only way to shut it down is via TerminateProcess.

So my question for the developers is, is this intentional? Is it perhaps something that can be changed, something not fundamental to ZSNES's (slim, speedy, optimized) architecture? Do you know of any other frontends that provide this sort of functionality, and if so how do they pull it off with ZSNES?
byuu

Post by byuu »

WM_CLOSE usually refers to one window in an application. I realize ZSNESW only has one window, but try sending it WM_QUIT and see what it does.
chmmr
New Member
Posts: 5
Joined: Sun Mar 12, 2006 8:48 pm

Post by chmmr »

Good idea, but it has the same effect. The process always seems to return WAIT_TIMEOUT - which is to say it doesn't respond to any such messages I send.
Hyos
Regular
Posts: 207
Joined: Mon Aug 15, 2005 2:15 pm

Post by Hyos »

Realize you can configure ZSNES to use a joystick for controlling the GUI. You can just use the joystick to exit the emulator in anatural way.
chmmr
New Member
Posts: 5
Joined: Sun Mar 12, 2006 8:48 pm

Post by chmmr »

The same joystick, controlling both the game and the UI?
I see options to set joystick buttons to UI commands, but nothing like what I'm talking about - combinations of buttons to UI commands.
Besides, binding a single easy-to-accidentally-press button to "Quit ZSNES" is not very good UI design.
Hyos
Regular
Posts: 207
Joined: Mon Aug 15, 2005 2:15 pm

Post by Hyos »

No, it's more like: press specific button, then you can use the stick to navigate the gui and use buttons to activate functions. You can find this under Misc/Gui Options. I realize this is probably not what you want unless the joypad you use has at least 7 buttons - 6 for SNES buttons and one to enter the GUI.
adventure_of_link
Locksmith of Hyrule
Posts: 3634
Joined: Sun Aug 08, 2004 7:49 am
Location: 255.255.255.255
Contact:

Post by adventure_of_link »

Hyos: 9 buttons buddy...

A, B, X, Y, Select, Start, L, R, then one for the UI.

;)
<Nach> so why don't the two of you get your own room and leave us alone with this stupidity of yours?
NSRT here.
Hyos
Regular
Posts: 207
Joined: Mon Aug 15, 2005 2:15 pm

Post by Hyos »

adventure_of_link wrote:Hyos: 9 buttons buddy...

A, B, X, Y, Select, Start, L, R, then one for the UI.

;)
:roll:
Post Reply