Reduced-Flicker in dos batch. It's possible?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Anti-Flicker in dos batch.

#16 Post by einstein1969 » 19 May 2017 12:19

I probed this thesis and work well on my windows 7 and 8.1.

The SNAKE game already uses the timer coalescing tecnic. It wait for time elasped(changed) then clear the screen and fast write.

This program I used for test anti flicker and run at 64 frames at second (64Hz). This probe the 15,6ms and the anti-flicker.

Disable AERO (COMPOSITING DESKTOP) and run with all application closed (browser, media player etc.)

Code: Select all

@echo off 
setlocal EnableDelayedExpansion

pause

call :task_new

goto :eof

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:task_new

setlocal

call :Font

mode 48,6

set t0=!time!

(
 for /F "delims==" %%v in ('set') do if not %%v lss 5 set "%%v="

 set AF=1 %anti flikering. Keep redraw near timer coalescing for windows 7 and up%
 set /a t=100000, rn=0, n=t

 for /L %%N in (!t!,1,199999) do (
  set /a "n=%%N , p1=!n:~1,1!*3, p2=!n:~2,1!*3, p3=!n:~3,1!*3, p4=!n:~4,1!*3, p5=!n:~5,1!*3"
  for /f "tokens=1-5" %%p in ("!p1! !p2! !p3! !p4! !p5!") do (
   if defined AF For /L %%L in (0,3,27) do (
          if not "!OT!"=="!time:~10,1!" (
            cls & for %%R in (0 1 2 3 4) do echo(             !%%R:~%%p,3! !%%R:~%%q,3! !%%R:~%%r,3! !%%R:~%%s,3! !%%R:~%%t,3! !%%R:~%%L,3!
            set /a rn+=1
            set OT=!time:~10,1!
          )
        ) else For /L %%L in (0,3,27) do cls & for %%R in (0 1 2 3 4) do echo(           !%%R:~%%p,3! !%%R:~%%q,3! !%%R:~%%r,3! !%%R:~%%s,3! !%%R:~%%t,3! !%%R:~%%L,3!
  )
  if %%N gtr !t! (
    for /F "tokens=1-8 delims=:.," %%a in ("%t0: =0%:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
    if defined AF (set /a "FPS=rn*100/a, t+=(FPS+100)") else set /a "FPS=(%%N-100000)*100*10/a, t+=(FPS+800)"
    title %2 FPS=!FPS!
    set a=&set FPS=
  )

 ) %_END for /L %%N_%

) %_END BLOCK_%

endlocal

mode 80,25

goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Font

Set "F=F6DE49279F3F3CFB793E73FCF7F249F7DFEF3C" % 3x5 Binary Font%

:: Decompact Font (This code is good for fonts with large number of characters. Leave for code snip)
For %%h in (0 1 2 3 4 5 6 7 8 9 A B C D E F
) do (
  set /a "r=10000+(0x%%h&8)/8*1000+(0x%%h&4)/4*100+(0x%%h&2)/2*10+(0x%%h&1)"
  For %%r in (!r:~1!) do set "F=!F:%%h=%%r!"
)

set F=!F:0=°!&set "F=!F:1=Û!" %ALT+0176 & ALT+0219%
rem set F=!F:0= !&set "F=!F:1=*!" %ASCII%

for /L %%i in (0,15,135) do for /L %%R in (0,1,4) do (
  set /a p=%%i+%%R*3
  for %%a in (!p!) do set %%R=!%%R!!F:~%%a,3!
)

goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


On my machine this not flicker for many and many seconds.

I'm working on a version that not use the timer coalescing for probe the anti-flicker functionality.

Einstein1969

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Anti-Flicker in dos batch.

#17 Post by Aacini » 19 May 2017 23:13

Ok. I copied your last code in my computer, disabled Compositing Desktop, closed all applications excepting a cmd.exe session used to run your Batch file, and executed it. In my opinion, a very marked flicker was visible, so I wanted to show it to you. However, I had a problem to do that: if I use any software to record the screen such a sofware could increase the flicker, so I opted for the easy solution: I used the video camera of my cell phone, changed the video quality to the lowest possible one and recorded about 14 seconds of video. I did not modified the video in any way; I just comprised it in a .zip file and posted it here.

VID_20170520_000058.zip
(1.32 MiB) Downloaded 949 times


Although the video quality is very low, the important details are clearly visible. In the video you may see the cmd.exe window at the bottom of the screen as a prove that no other application was active. My computer use Windows 8.1 Spanish...

Antonio

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Anti-Flicker in dos batch.

#18 Post by aGerman » 20 May 2017 03:44

Looks quite the same on my Win10, Antonio.

Steffen

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Anti-Flicker in dos batch.

#19 Post by misol101 » 20 May 2017 05:41

Perhaps it's Windows version related. It looks pretty good on my Win7 Machine, there are a few frames of flickering about every 1.5 seconds. So it's not flicker free, but not bad

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Anti-Flicker in dos batch.

#20 Post by einstein1969 » 20 May 2017 13:49

OK. The flicker on Antonio's machine is high :(

Peraph i'm on monocore machine ? on monocore machine the timer colescing work well ?

Antonio, can you try even the script that use the CLS+SET for draw? (It's the fastest method to draw on screen)

For better result use the native screen resolution.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Anti-Flicker in dos batch.

#21 Post by penpen » 21 May 2017 14:10

On my win10 it depends on the core which is used to execute it:
On one core there is flickering (and a frame rate of ~68fps), on the other i have ~96 fps and only rare flicker.

penpen

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Anti-Flicker in dos batch.

#22 Post by Aacini » 22 May 2017 15:24

misol101 wrote:Perhaps it's Windows version related. It looks pretty good on my Win7 Machine, there are a few frames of flickering about every 1.5 seconds. So it's not flicker free, but not bad


Precisely: the original thesis is that this anti-flicker method use the "timer coalescing" feature introduced on Windows 7, so it should work the same way on any Windows version from 7 on...

einstein1969 wrote:Peraph i'm on monocore machine ? on monocore machine the timer colescing work well ?


penpen wrote:On my win10 it depends on the core which is used to execute it:
On one core there is flickering (and a frame rate of ~68fps), on the other i have ~96 fps and only rare flicker.

penpen


Are you suggesting that the "timer coalescing" Windows feature changes its beaviour depending on the CPU core used to run the code? If this would be true, all applications that use a timer (in Windows 7 or +) should check the CPU core used in order to perform its own adjustments; otherwise they would use very inaccurate timers!

I think that the opposite point is true: the system always keep the "timer coalescing" feature into the given specifications (For example, a scheduled timer that has a period of 200 ms may specify a tolerance of 20 ms), and this feature should always work in the same way independently of other factors, like the CPU speed or number of cores, etc. In this way, the system must internally adjust the parameters used in the "timer coalescing", so the same result be obtained in all computers...

Antonio

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Anti-Flicker in dos batch.

#23 Post by penpen » 23 May 2017 04:12

Aacini wrote:Are you suggesting that the...
I didn't suggest anything, i only described what has happened on my pc as a result of the following steps.

Add this just before the first pause:

Code: Select all

title CPU Core %~n1

Then create files "0.txt" and "1.txt", and drag and drop single text files on the batch.

After that open the Task-Manager, make sure to show the "command lines", right click the cmd tasks, and set the cpu core that should be used to execute each process.

Finally hit a key for each cmd shell, and view the result.


penpen

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Anti-Flicker in dos batch.

#24 Post by einstein1969 » 23 May 2017 07:47

The "start" command can use the /AFFINITY switch for assign to a specified core/node. I can't test this on my monocore machine, but I think that is possible switch core with a key pressed.

TSnake41
Posts: 12
Joined: 17 Dec 2016 12:49

Re: Anti-Flicker in dos batch.

#25 Post by TSnake41 » 23 May 2017 11:21

Hmm, I think the flickering is mostly due to cls redraws.
So, in case to avoid this flickering, the best idea is to move the cursor to (1;1) and overwrite previous stuff to avoid erasing&drawing which probably is what causes flickering.
Many solutions exists to do this, but most are external commands :mrgreen:.

Others solutions exists however...

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Anti-Flicker in dos batch.

#26 Post by Aacini » 23 May 2017 19:15

penpen wrote:
Aacini wrote:Are you suggesting that the...
I didn't suggest anything, i only described what has happened on my pc as a result of the following steps.

. . .

penpen


Let me clear a couple points:

  1. Of course, there are a lot of other details we could test, like use native screen resolutions, or use different CPU cores (via Task-Manager or "start" /AFFINITY), and a long et cetera... However, all these "Different methods to decrease the screen flicker" are NOT the matter of this thread!
  2. This topic was created by einstein1969 in order to publish an antiflicker method devised by him, that is based on the following points:
    • Fact: Windows 7 featured a new method "to group multiple software timer expirations into a single period of processing", that MS called "timer coalescing".
    • Hypothesis: The timer used to update the %time% cmd.exe dynamic variable have a resolution of about 15.6 ms because it uses Windows 7 timer coalescing feature. The method used by cmd.exe to show characters in the window screen also use timer coalescing. In this way, if the display of characters in the screen is delayed until the %time% variable change, the screen flicker should decrease. This is called the "timer coalescing" antiflicker method.

I replied with my point that the Windows 7 "timer coalescing" feature have no relation with %time% variable nor with the display of characters on the screen, but that any decrease in the screen refresh rate (like a wait for a change on %time% variable) will decrease the flicker.

Although a test proved that this method don't works on my computer (nor in aGerman's one), einstein1969 insisted on his theory and diverged the cause of the flicker to other factors ("Peraph on monocore machine the timer colescing work well ?"; as corollary: the timer coalescing dont work on multicore machines). After this reply, @penpen posted this:

penpen wrote:On my win10 it depends on the core which is used to execute it:
On one core there is flickering (and a frame rate of ~68fps), on the other i have ~96 fps and only rare flicker.

penpen


How could I know that this reply is not about the "timer coalescing" antiflicker method, but about an entirely different matter?

IMHO the replies that are unrelated to the topic should include some kind of advice, in order to avoid confusions...

Antonio

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Anti-Flicker in dos batch.

#27 Post by einstein1969 » 24 May 2017 09:06

@penpen

on the previous condition , can you try this tools http://technet.microsoft.com/en-us/sysi ... 97568.aspx that show the system timer?

on my system is the default of 15,6ms.

Code: Select all

C:\Users\ACER\Desktop\tools>clockres

Clockres v2.1 - Clock resolution display utility
Copyright (C) 2016 Mark Russinovich
Sysinternals

Maximum timer interval: 15.600 ms
Minimum timer interval: 0.500 ms
Current timer interval: 15.600 ms

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Reduced-Flicker in dos batch. It possible?

#28 Post by einstein1969 » 24 May 2017 09:16

@Antonio.
I have changed the title of the thread and have added your comment at first page. Thanks.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Reduced-Flicker in dos batch. It's possible?

#29 Post by penpen » 31 May 2017 15:35

Sorry for beeing busi for some days.

@Antonio
In my eyes my above post should be kind of obvious:
1) If you limit a process to a single core, then its behaviour is the same as on a monocore processor,
because it doesn't use any multicore extensions (all needed infos should be somewhere within "Intel 64 and IA-32 Architectures Developer's Manual: Vol 1 - Basic Architecture").
2) I never heard that Microsoft functions differ between monocore and multicore (as far as i know multicore usage should be transparent to a process).
3) The test code leads to flickering and not flickering result.
=> Doesn't (reliably) work on monocore machines (although the above is no hard proof, because "point 2)" might be wrong.)

As you can see, my post is related to the topic and the post, but not in a way you expected.
I guess that means that my post was anything but "as obvious as i thought", so
i admit that i should have written some more info to my post:
Sorry for this.


@einstein1969
My values are:

Code: Select all

Z:\>Clockres.exe

Clockres v2.1 - Clock resolution display utility
Copyright (C) 2016 Mark Russinovich
Sysinternals

Maximum timer interval: 15.625 ms
Minimum timer interval: 0.500 ms
Current timer interval: 0.500 ms


penpen

neorobin
Posts: 47
Joined: 01 May 2012 12:18

Re: Reduced-Flicker in dos batch. It's possible?

#30 Post by neorobin » 02 Jun 2017 09:02

I did a clock.

This time I increased the display accuracy to one hundredth of a second.

But I did not test the frame rate.

I do not know how high its frame rate can be.

Please replace the ★ in the code with TAB(ASCII 9)

The frame rate of the GIF picture below is below the actual running frame rate on my Chinese Win7 SP1 64bit environment ( only test on this ).
Image

Code: Select all

:: Fifteen-segment display clock
::
:: neorobin @ 20161007_205515
::

@echo off

    set "_A="A = !!(x-1)""
    set "_B="B = (!!(x-1) ^& !!(x-4))""
    set "_C="C = 1""
    set "_D="D = (!(x^&3) ^| !!(x^&~3)) ^& !!(x-7)""
REM set "_E="E = 0""                                    & rem never display
    set "_F="F = !!(x-5)^&!!(x-6)""
    set "_G="G = !!(x-1)^&!!(x-7)""
    set "_H="H = !(!x ^| !(x-1) ^| !(x-7))""
    set "_I="I = 1""
    set "_J="J = ~x ^& 1 ^& !!(x-4)""
REM set "_K="K = 0""                                    & rem never display
    set "_L="L = !!(x-2)""
    set "_M="M = (!!(x-1) ^& !!(x-4) ^& !!(x-7))""
    set "_N="N = (!!(x-1) ^& !!(x-4) ^& !!(x-7))""
    set "_O="O = 1""


@echo off & setlocal enabledelayedexpansion

for /f "tokens=2 delims=[]" %%a in ('ver') do for /f "tokens=2 delims=. " %%a in ("%%a") do (
    set /a "NO_CLS=-((%%a-7)>>31)"
)

set /a "wid=37, hei=6, linesWantBackAbove = hei - 1, cntBS = 2 + (wid + 7) / 8 * linesWantBackAbove"
set "TAB=★" & for /F %%a in ('"prompt $h&for %%b in (1) do rem"')do Set "BS=%%a"
set "BSs=" & for /L %%a in (1 1 !cntBS!) do set "BSs=!BSs!%BS%"

color 0a & mode %wid%,%hei%

set "__=0" & set "_= "
for /l %%i in () do (
    set /a "t=!time:~-1!" & set /a "t ^= z, z ^= t"
    if !t! neq 0 (
        set "S=" & set "zeroOrOne=0"
        for %%L in ("A B C" "D _ F" "G H I" "J _ L" "M N O") do (
            for %%d in (0 _ 1 _ : _ 3 _ 4 _ : _ 6 _ 7 _ : _ 9 _ 10) do (
                if "%%d" geq "0" (
                    set "tm=!time: =0!" & set "x=!tm:~%%d,1!"
                    for %%_ in (%%~L) do set /a !_%%_! & set "S=!S!!%%_!"
                ) else if "!zeroOrOne!%%d"=="1:" (set "S=!S!*") else set "S=!S! "
            )
            set /a "zeroOrOne^=1"
        )
        set "S=!S:1=#!" & set "S=!S:0= !"

        if !NO_CLS!==1 (    (2>nul echo;%TAB%!BSs!) & <nul set /p "=%BS%"
        ) else              CLS

        <nul set /p "=!S!"
    )
)

Post Reply