mamedev / mame

MAME
https://www.mamedev.org/
Other
8.06k stars 2.01k forks source link

Power-off callback on MAME exit #728

Open happppp opened 8 years ago

happppp commented 8 years ago

Power-off callback on MAME exit

In practice, we already have a power-on callback. This, in combination with a power-off callback will be useful to automatically power on/off the emulated machine on machines that have soft-power buttons.

Scenario: Texas Instruments CC40(cc40.cpp) has battery-backed RAM(SRAM). The machine power button is not hardwired to the power brick, but handled by software. In the real world, a user would press this button, then the BIOS would clean-up and handle whatever needs to be saved to SRAM, and then power-off.

In MAME, you currently need to press this power button before actually exiting MAME. Otherwise the emulated CC40 SRAM is invalid. It is not intuitive and I would like that this is done automatically, such as: user presses ESC to exit MAME -> MAME core checks and handles power-off before exiting. Obviously within limited time, eg. if power-off handler hasn't finished by 1 second it exits anyway.

Another scenario is seen in machines with a CMOS CPU/MCU, where the unit actually keeps running in lowpower mode while the power is 'off'. Take Nintendo Game & Watch for example. These handhelds don't have an RTC but manage to keep time anyway.

mahlemiut commented 8 years ago

The X68000 would benefit from this sort of option, too. Its power switch generates an interrupt so that the system can clean things up before shutting down. Probably not as critical as what you've described though.

Another useful, related idea, would be to support auto-shutdown, for those various PC (and similar) systems that have OSes that will switch the system off for you after logging out.

happppp commented 8 years ago

For reference, here's TI CC40 (cc40.cpp, cc40) in MAME whining about amnesia if the user exited MAME and didn't press the emulated OFF button before that. http://tsk-tsk.net/net/temp/cc40_memlost_crop.png TI74 and TI95 in ti74.cpp give a similar error. And I believe TI's later programmable calculators were designed the same way.

Neo Geo Pocket in ngp.cpp also relies on the user to turn off the machine before exiting MAME. IIRC its BIOS shutdown includes NVRAM management, MAMEdev Judge will know for sure.

In X68k case, is there a chance of data loss with harddisk write cache and such? Like on modern PCs.

On Sat, Mar 19, 2016 at 11:10 AM, mahlemiut notifications@github.com wrote:

The X68000 would benefit from this sort of option, too. Its power switch generates an interrupt so that the system can clean things up before shutting down. Probably not as critical as what you've described though.

Another useful, related idea, would be to support auto-shutdown, for those various PC (and similar) systems that have OSes that will switch the system off for you after logging out.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/mamedev/mame/issues/728#issuecomment-198679159

stilett0 commented 8 years ago

@wilbertpol re: Neo Geo Pocket? :smile:

Bavarese commented 8 years ago

Probably related: i would like to disable RESET altogether, or query the user via OSD before doing it.

There is an OSD configuration option for ESC / quit, but no way to inhibit RESET within the driver.

Scenario: when an inexperienced user presses F3 (wired to a vital 'Setup Mode' on a real machine) within the Rainbow-100 driver - which happens to be in partial key emu mode - the emulation performs a reset instead.

There was no built-in reset button on real hardware.

Reassigning keys seems impossible for ESC, F3, ScrollLock and would also be counter-intuitive either for the MAME/MESS or the Rainbow user.

angelosa commented 8 years ago

Best idea I could come up with this is to make a delegate for ESC input pressed, just like F3 actually calls machine_reset. Assuming that an output is sent to a port you would join the two events together (so you shut-off MAME after the event is actually triggered). Oh, and I guess you need a "panic" button mechanism (another ESC button press?), in case that machine fails to actually shut off!