Important screensaver tip for Windows emulator authors

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by cpow »

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?
User avatar
James
Posts: 431
Joined: Sat Jan 22, 2005 8:51 am
Location: Chicago, IL
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by James »

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!
get nemulator
http://nemulator.com
User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by cpow »

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:
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: An important tip for Windows emulator authors

Post by koitsu »

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.
Drag
Posts: 1615
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by Drag »

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.
User avatar
James
Posts: 431
Joined: Sat Jan 22, 2005 8:51 am
Location: Chicago, IL
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by James »

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

Code: Select all

    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;
get nemulator
http://nemulator.com
Drag
Posts: 1615
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by Drag »

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!
darkhog
Posts: 192
Joined: Tue Jun 28, 2011 2:39 pm

Re: Important screensaver tip for Windows emulator authors

Post by darkhog »

Who still use screensavers anyway?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by rainwarrior »

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.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by blargg »

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.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Important screensaver tip for Windows emulator authors

Post by tepples »

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.
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Windows Forms implementation in C#

Post by colinvella »

The only change needed to adapt it for your implementation is the condition:
if (gameState == GameState.Running)
(edited - constant for invalid handle value added)

Code: Select all

        /// <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);
Last edited by colinvella on Sun Jul 03, 2016 2:59 pm, edited 1 time in total.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Re: Important screensaver tip for Windows emulator authors

Post by 3gengames »

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.
User avatar
colinvella
Posts: 74
Joined: Sun Jun 05, 2016 1:41 pm

Re: Important screensaver tip for Windows emulator authors

Post by colinvella »

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.
Tile IDE and tile engine for XNA: http://tide.codeplex.com/
Fancy Fish Mod - Minecraft Mod: http://fancyfishmod.weebly.com/
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Important screensaver tip for Windows emulator authors

Post by koitsu »

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.
Post Reply