nesdev.com
http://forums.nesdev.com/

Important screensaver tip for Windows emulator authors
http://forums.nesdev.com/viewtopic.php?f=3&t=10517
Page 2 of 3

Author:  cpow [ Thu Oct 03, 2013 1:57 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

tepples wrote:
Then send something innocent like the down arrow or the spacebar or the X key, as that's what players would already be pressing when playing an NES game with a keyboard.

In any case, Windows Vista didn't exist 8 years ago, and your product requires it or newer.


Would the same effect be achieved by sending a mouse wheel event with delta of 0?

Author:  James [ Thu Oct 03, 2013 2:15 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

cpow wrote:
Would the same effect be achieved by sending a mouse wheel event with delta of 0?

I just tested that and it does appear to work as well. Good call!

Author:  cpow [ Thu Oct 03, 2013 7:12 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

James wrote:
cpow wrote:
Would the same effect be achieved by sending a mouse wheel event with delta of 0?

I just tested that and it does appear to work as well. Good call!

Nice! I knew I still had a few good ideas in me. :lol:

Author:  koitsu [ Sun Oct 06, 2013 9:38 pm ]
Post subject:  Re: An important tip for Windows emulator authors

Quietust wrote:
There's actually two minor flaws in the sample code you posted on the Steam forums:
1. wParam needs to be ANDed with 0xFFF0 first.
MSDN wrote:
In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.


You're right -- thanks, I've updated my post on Steam. I believe this also means the Nestopia code is wrong too (lacking & 0xfff0), but the updated unofficial version in git has it fixed.

Author:  Drag [ Mon Oct 07, 2013 11:58 am ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

SDL2 has functions for disabling the screensaver, but does anyone know how it does it? Hopefully, it's the way mentioned in this thread and not by changing the power profile.

Author:  James [ Mon Oct 07, 2013 12:15 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

Drag wrote:
SDL2 has functions for disabling the screensaver, but does anyone know how it does it?

Code:
    case WM_SYSCOMMAND:
        {
            /* Don't start the screensaver or blank the monitor in fullscreen apps */
            if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
                (wParam & 0xFFF0) == SC_MONITORPOWER) {
                if (SDL_GetVideoDevice()->suspend_screensaver) {
                    return (0);
                }
            }
        }
        break;

Author:  Drag [ Mon Oct 07, 2013 11:40 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

Ah, excellent. Thanks for digging that up. It's only after this post that I remember that SDL is open source and I could've looked it up myself. D'oh!

Author:  darkhog [ Thu Nov 14, 2013 3:59 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

Who still use screensavers anyway?

Author:  rainwarrior [ Thu Nov 14, 2013 4:02 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

It's not just for screen savers anymore, darkhog, that's just what we call it now. It's about a timer on inactive input, and lots of computers are set to turn the monitor off or go to sleep after a certain time.

Author:  blargg [ Thu Nov 14, 2013 4:14 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

Aren't these things like a mouse wheel movement of 0 just hacks, i.e. they will break at some point in the future? It's a sad situation that the OS would suspend a system even though a USB HID was generating input.

Author:  tepples [ Thu Nov 14, 2013 4:21 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

Expanding on what rainwarrior wrote: The effort formerly put into screensavers has forked into two areas.

Screensaver as art: The display hacks common in the screensaver era appear to have folded into the demoscene.

Screensaver as blanking: With CRTs and plasma planels giving way to LCDs that have less of a burn-in problem, and with an increased focus on conserving electric power, it's not quite as necessary to waste computing cycles on rendering visual effects. But it's still common to have the system blank the screen when a terminal has become idle, lock the input devices, and possibly show a simple moving image to show that the computer is still in use. This improves security, as eavesdroppers have less of a chance to read sensitive information from the screen. It also gracefully leads into lower-power states: in monitor power save, the graphics processor cuts off the signal and the monitor turns off, and in suspend, everything but the DRAM refresh and the keyboard controller turns off.

Author:  colinvella [ Fri Jul 01, 2016 7:00 am ]
Post subject:  Windows Forms implementation in C#

The only change needed to adapt it for your implementation is the condition:
Quote:
if (gameState == GameState.Running)


(edited - constant for invalid handle value added)

Code:
        /// <summary>
        /// Windows message handler
        /// </summary>
        /// <param name="message">Windows message to process</param>
        protected override void WndProc(ref Message message)
        {
            // check if screen saver message dispatched
            if (message.Msg == WM_SYSCOMMAND && (int)message.WParam == SC_SCREENSAVE)
            {
                // if game is running, suppress screen saver request
                if (gameState == GameState.Running)
                {
                    message.Result = INVALID_HANDLE_VALUE;
                    return;
                }
            }

            // fall back to default message processor
            base.WndProc(ref message);
        }

        // window message processing
        private static readonly int SC_SCREENSAVE = 0xF140;
        private static readonly int WM_SYSCOMMAND = 0x0112;
        private static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);

Author:  3gengames [ Fri Jul 01, 2016 12:23 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

Hardcoding the NULL Pointer to -1 instead of just using NULL? I've seen it all, as long as that isn't how Microsoft tells you how to do it.

Author:  colinvella [ Fri Jul 01, 2016 12:53 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

3gengames wrote:
Hardcoding the NULL Pointer to -1 instead of just using NULL? I've seen it all, as long as that isn't how Microsoft tells you how to do it.


Apparently it's the managed code equivalent of the Win32 C++ constant INVALID_HANDLE_VALUE. It serves a different purpose than NULL.

Author:  koitsu [ Fri Jul 01, 2016 1:55 pm ]
Post subject:  Re: Important screensaver tip for Windows emulator authors

I should note there's also a "newer" way to to this (Windows 7 and up only; older Windows releases need to use the methodology already described) through Windows' Power Management API. Specifically I'm referring to PowerCreateRequest() and PowerSetRequest() for the PowerRequestDisplayRequired RequestType.

The reason I mention this is that use of this API to inhibit display blanking/power-down/sleep allows a user to do powercfg.exe -requests from the CLI and see which applications and/or drivers are inhibiting said condition.

Page 2 of 3 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/