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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Anti-Flicker in dos batch.

#31 Post by einstein1969 » 29 Jul 2024 17:41

Aacini wrote:
23 May 2017 19:15

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.
after many years i revisited this to see if i could reduce the flickering somehow.

Well this sentence made me think about the fact that if i draw 500 times per second on the screen i have much more flickering than when i write at 100 times per second.

Obviously the test on the time variable lowers my writing frequency to 64 then and to 100 now on my new multicore machine.

i wanted to try not to do any tests on the time and reduce the frequency to values ​​around 80.

Well on my machine placing an echo next to the time change does not generate much flickering.

If instead i draw at any time at a low frequency the flickering is very pronounced.

So even if it does not eliminate the flickering completely you have a notable reduction.

Now i don't want to say that flickering it is related to the timers coalescing but i can say that it EDIT:could be related to the time variable in some way.

save how UTF8

Code: Select all

@echo off 
setlocal EnableDelayedExpansion
chcp 65001

title CPU Core %~n1

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=" %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,19999999) 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 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!

  set /a rn+=1

  for /l %%L in (1,1,10000) do rem 

  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"
    set /a "FPS=rn*100/a, t+=100"
    title %2 FPS=!FPS! !time! !rn! !a!
    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
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
change in this line:

Code: Select all

for /l %%L in (1,1,10000) do rem 
and reduce or increase the 10000 for keep the framerate at 50..100 FPS for compare the flickering produced

the old code that write on %time% change:

save to utf8:

Code: Select all

@echo off 
setlocal EnableDelayedExpansion
chcp 65001

title CPU Core %~n1

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,19999999) 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
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Last edited by einstein1969 on 30 Jul 2024 09:25, edited 2 times in total.

miskox
Posts: 610
Joined: 28 Jun 2010 03:46

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

#32 Post by miskox » 30 Jul 2024 01:46

What happens if you remove CLS (only one CLS at the beginning) and move cursor with escape sequences?

Saso

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

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

#33 Post by IcarusLives » 30 Jul 2024 11:21

miskox wrote:
30 Jul 2024 01:46
What happens if you remove CLS (only one CLS at the beginning) and move cursor with escape sequences?

Saso
It would probably help you if you read his code. It's not for windows 10.

miskox
Posts: 610
Joined: 28 Jun 2010 03:46

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

#34 Post by miskox » 30 Jul 2024 11:40

IcarusLives wrote:
30 Jul 2024 11:21
miskox wrote:
30 Jul 2024 01:46
What happens if you remove CLS (only one CLS at the beginning) and move cursor with escape sequences?

Saso
It would probably help you if you read his code. It's not for windows 10.
If I need glasses then you need them too:
set "AF=1" %anti flikering. Keep redraw near timer coalescing for windows 7 and up%
Saso

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

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

#35 Post by IcarusLives » 30 Jul 2024 11:53

He is more than well aware of vt100 and escape sequences. If he was trying to use them to avoid flicker in window *7*, then it just *wouldn't work*. Why would he bother writing "for windows *7* or later" if he planned on using vt100?

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

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

#36 Post by einstein1969 » 30 Jul 2024 17:11

be good don't argue.

The issue has been in limbo for a long time.

Actually that code was written when windows 10 didn't have escape sequences yet.

So that code was developed when escape sequences didn't exist so it didn't include the use of windows 10 sequences.

At the time other mechanisms were used to avoid or reduce flickering. Either programs or ansi drivers etc.

I copied this last code you find from the 2015 version and that comment remained which can be misleading. Sorry!!!!! :cry:

So consider it as a reworking to be brought back to that time for the case in which flickering exists.

Since flickering certainly exists for cls I wanted to do a test to see if writing at the same time as changing the !time! variable still gave the same result.

I was also following aacini's comment which said that the flickering was due to the way the program was written.

Actually he could have been right and I rewrote it to avoid running into that error.

But once that error was removed the issue seems to persist. that is, if I write on the screen when the variable "time" changes the flickering decreases.

However I want to add some information.

I am aware of the methods offered by Windows 10 with escape sequences and I generally avoid the cls or csi 2J.

But there are times that the flickering occurs, even if minimal, even with the classic csi H.

Furthermore there are cases in which it is not possible to eliminate the clear screen without revolutionizing the application.

I also add that the timer coalescing still exists in Windows 10 and has undergone updates in Windows 8 as well.

Furthermore this mechanism is not only for application timers as Aacini wrote at the time but it is also for drivers timers, so the graphics card also has the same restriction. Even if the tolerance is different.

So the Windows system accumulates everything at certain times to save energy. Driver timers and application timers.

Now on my PC which is a laptop I see some differences, even if I don't know what's behind it if it works I'll try to use it.

now what i wrote is now also written in the documentation that is in the thread. Just read it.

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

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

#37 Post by einstein1969 » 30 Jul 2024 17:25

I also wanted to tell Antonio that when he said that cmd couldn't postpone writing and did it right away, he was right.

But it's exactly because of that way that the flickering could be created.

Instead, if we ask it to write when everything is updated and maybe the "time" variable is also updated.

In that case, if the video card driver is doing a refresh of the video, we're lucky.

Now the issue is not so simple.

There are many parameters that make it very difficult to do.

But if we don't follow the path, we won't know if there is a solution.

miskox
Posts: 610
Joined: 28 Jun 2010 03:46

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

#38 Post by miskox » 30 Jul 2024 21:57

2icarius and 2einstein: I don't want to argue. I just thought that it was obvious to use ESC sequences for Win10+ without writting this (maybe somebody has Win10 only so this would look better). Or to have two different codes or one code with a check if OS WIN10+ or not.

Saso

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

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

#39 Post by aGerman » 31 Jul 2024 11:00

No attempt happened to work for me so far. Not even the most recent code. And it doesn't matter what settings I update, what processes are running or not running, whether I test in terminal or console ... So, I doubt it being worth investigating any further as also Win 8.1 is now a walking dead since Jan. 2023.

(OT: Thinking about that we are discussing this mainly because we want to draw some kind of video - only a few days ago the support of sixel graphics has been merged into the terminal source code. https://github.com/microsoft/terminal/pull/17581 I'm expecting to find it as soon as version 1.22 will be released.
It's also already in the open console source. https://github.com/microsoft/terminal/pull/17421 But this may take longer to become part of a conhost update.
The author added some video sequences to demonstrate the capabilities https://github.com/microsoft/terminal/p ... 2177165191 )

Steffen

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

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

#40 Post by einstein1969 » 31 Jul 2024 12:32

miskox wrote:
30 Jul 2024 21:57
2icarius and 2einstein: I don't want to argue. I just thought that it was obvious to use ESC sequences for Win10+ without writting this (maybe somebody has Win10 only so this would look better). Or to have two different codes or one code with a check if OS WIN10+ or not.

Saso
yes yes it's better to use the escaped version.

shodan
Posts: 89
Joined: 01 May 2023 01:49

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

#41 Post by shodan » 01 Aug 2024 20:50

Hello,

Would it work to use

CreateConsoleScreenBuffer

To create a console text buffer, write to this back buffer and then flip the buffers with SetConsoleActiveScreenBuffer instantly (or possibly along with vsyncs ?)

Post Reply