Frequency of screen refresh
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 236 from 2003/7/26
    From: Wroclaw/Poland
    Could someone tell me if I am able to get frequency of a screen refresh (time between each refresh screen)? In age of LCD monitors usually it equals 60Hz but I would like to get the value from system API instead of use ugly hardcode.
  • »31.07.19 - 17:49
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    KennyR
    Posts: 657 from 2003/3/4
    From: #AmigaZeux, Gu...
    I'm not sure there is a system-legal way of doing this on MorphOS. I've looked through the includes and there are no calls involving monitor refresh rate... at least that I can see.

    Bigfoot or cyfm are the experts here.

    Edit: I spoke too soon. Look at includes/graphics/monitor.h.

    [ Edited by KennyR 31.07.2019 - 22:19 ]
  • »31.07.19 - 22:13
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 348 from 2003/2/25
    From: Berlin
    Here is an old AmigaOberon source of mine, which lists all screens and windows, and also show the Hz value of a screen:
    Code:

    MODULE Wins;
    (* $StackChk- $RangeChk- $CaseChk- $OvflChk- $ReturnChk- $TypeChk- $NilChk- *)
    IMPORT
    (* NoGuru, *)
    y := SYSTEM,
    d := Dos, e := Exec, I := Intuition, G := Graphics, u := Utility,
    tb:= ToolBox;
    TYPE
    LS = LONGSET;
    VAR
    scr: I.ScreenPtr;
    win: I.WindowPtr;

    monInfo : G.MonitorInfo;
    nameInfo: G.NameInfo;

    idStr : ARRAY G.displayNameLen OF CHAR;

    ID,
    scan, fps,
    l : LONGINT;

    BEGIN
    (* (* $IFNOT Debug *) l := I.LockIBase(0); (* $END *) *)
    scr := I.base.firstScreen;
    REPEAT
    ID := G.GetVPModeID(y.ADR(scr.viewPort));
    IF G.GetDisplayInfoData (NIL, monInfo, SIZE(G.MonitorInfo), G.dtagMntr,ID) > 0 THEN
    (* $RangeChk- *)
    fps := ABS(1000000000 DIV (I.UIntToLong(monInfo.mspc.totalRows)*I.UIntToLong(monInfo.mspc.totalColorclocks)*280));
    (* $RangeChk= *)
    scan := fps * monInfo.mspc.totalRows;
    (* d.PrintF ("scan = %ld, fps = %ldn",scan,fps); *)
    ELSE
    scan := 0; fps := 0
    END;

    IF G.GetDisplayInfoData (NIL, nameInfo, SIZE(G.NameInfo), G.dtagName, ID) > 0 THEN
    COPY(nameInfo.name,idStr)
    ELSE
    tb.Format (idStr,'Mode not found (%ld)!',ID);
    END;

    d.PrintF ('nSCREEN [1m"%s"[m %s [%lDkHz/%02ldHz] (%1ld,%1ld,%1ldx%1ldx%1ld):n',
    (* scr.defaultTitle, y.ADR(idStr), scan(* DIV 1000, (scan MOD 1000)*10*), fps, *)
    scr.defaultTitle, y.ADR(idStr), scan DIV 1000, fps,
    scr.leftEdge,scr.topEdge, scr.width,scr.height,scr.bitMap.depth);

    win := scr.firstWindow;
    WHILE win # NIL DO
    d.PrintF ('tWINDOW [1m"%s"[m (%1ld,%1ld,%1ldx%1ld)n',
    win.title, win.leftEdge,win.topEdge, win.width,win.height);
    win := win.nextWindow
    END;

    scr := scr.nextScreen
    UNTIL scr = NIL;
    CLOSE
    (* (* $IFNOT Debug *) I.UnlockIBase (l); (* $END *) *)
    END Wins.
  • »31.07.19 - 22:15
    Profile Visit Website
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 236 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    KennyR wrote:
    Look at includes/graphics/monitor.h.

    It could be good idea. Thank you very much!

    I have checked it but in MonitorSpec struct (got from GfxBase->current_monitor) I don't see value which could be helped to get/calculate max screen refresh frequency. Unfortunately not each variable is descripted in documentation (I have checked in AROS' documentation too).

    [ Edited by MDW 01.08.2019 - 22:21 ]
  • »01.08.19 - 14:00
    Profile Visit Website
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 236 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    igracki wrote:
    Here is an old AmigaOberon source of mine...

    I am not familiar with Pascal but the code is quite readable and can be helpful. Thank you! 👍
  • »01.08.19 - 14:02
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 348 from 2003/2/25
    From: Berlin
    Its not Pascal, its AmigaOberon;)

    I forgot to show a possible output of this program:

    SCREEN "OWB" RadeonX800: 24Bit 1920 x 1080 [68.625 kHz, 61 Hz] (0,0,2500x1080x8):
    WINDOW "OWB: MorphZone" (0,22,1468x1058)
  • »01.08.19 - 21:46
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    KennyR
    Posts: 657 from 2003/3/4
    From: #AmigaZeux, Gu...
    Thomas' AmigaOberon code is interesting, as it uses GetDisplayInfoData() from the graphics.library. The MorphOS autodocs say that only returns

    Code:
     size   - buffer size in bytes
    tagID - data chunk type
    DTAG_DISP (DisplayInfo)
    DTAG_DIMS (DimensionInfo)
    DTAG_MNTR (MonitorInfo)


    The data is coming from struct MonitorInfo, namely the UWORD totalRows.

    It obviously works, but that's a really, really unclear way to fetch horizontal refresh in Hz! (For MorphOS I mean, not Thomas.)

    [ Edited by KennyR 01.08.2019 - 22:58 ]
  • »01.08.19 - 22:57
    Profile
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 236 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    igracki wrote:
    I forgot to show a possible output of this program:

    SCREEN "OWB" RadeonX800: 24Bit 1920 x 1080 [68.625 kHz, 61 Hz] (0,0,2500x1080x8):
    WINDOW "OWB: MorphZone" (0,22,1468x1058)



    Thank you. I am trying to calculate value of fps variable according to your example. However result not equal about 60... :)

    There I have found similar example:

    Code:

    if( currmonitor ){
    rows = currmonitor->total_rows;
    clks = currmonitor->total_colorclocks;
    }
    if( rows && clks )
    fps = abs(1000000000/(rows*clks*280));
    else
    fps = 0;
    scan = fps*rows;


    So we have confirmation of the way of calculate kHz/Hz. Unfortunately I still have wrong result.
    On my PowerBookG4 (1440x960, 58,767 KHz, 60 Hz) current_monitor structure returns these values:

    Code:
    gfxBase->current_monitor->total_rows = 48879
    gfxBase->current_monitor->total_colorclocks = 57005


    So calculated value of fps won't equal about 60. No way... :)
  • »01.08.19 - 23:10
    Profile Visit Website
  • MorphOS Developer
    Piru
    Posts: 402 from 2003/2/24
    From: finland, the l...
    Quote:

    MDW wrote:
    Could someone tell me if I am able to get frequency of a screen refresh (time between each refresh screen)? In age of LCD monitors usually it equals 60Hz but I would like to get the value from system API instead of use ugly hardcode.

    https://sintonen.fi/src/misc/getmodeidrate.c

    It's not 100% accurate due to TotalColorClocks and TotalRows being UWORD (16-bit).
  • »02.08.19 - 12:00
    Profile
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 236 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    Piru wrote:
    https://sintonen.fi/src/misc/getmodeidrate.c

    It's not 100% accurate due to TotalColorClocks and TotalRows being UWORD (16-bit).



    Thank you. Calculated values look strange:
    Code:
    vfreq = 363, vfreqk = 0, hfreq = 67, hfreqk = 0


    However if I build your example, I got:
    Scanrate: 60.86 Hz
    Scanline: 59.52 kHz
    So... very close to truth. Values good enough for me.

    I am thinking why in previous cases I had wrong values. Reason of the problem is in provided values of TotalColorClocks and TotalRows. These values got from MonitorSpec struct (gfxBase->current_monitor) are different than values got from MonitorInfo struct (GetDisplayInfoData). Why? Does current_monitor is not real current monitor? :)

    Thank you for the solution! 👍

    [ Edited by MDW 02.08.2019 - 14:15 ]
  • »02.08.19 - 12:18
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    KennyR
    Posts: 657 from 2003/3/4
    From: #AmigaZeux, Gu...
    Don't forget too that a single monitor has multiple screenmodes, each of which can have a different refresh rate. You don't really see that on TFT, but it was a thing on CRT.

    A very annoying thing.
  • »02.08.19 - 15:34
    Profile
  • MDW
  • Order of the Butterfly
    Order of the Butterfly
    MDW
    Posts: 236 from 2003/7/26
    From: Wroclaw/Poland
    Quote:

    KennyR wrote:
    Don't forget too that a single monitor has multiple screenmodes, each of which can have a different refresh rate. You don't really see that on TFT, but it was a thing on CRT.

    A very annoying thing.

    You are right. In age of LCD, smartphones, tablets and laptops we a bit forget about screen modes.
    I of course will get these values for selected screen mode.
  • »02.08.19 - 18:20
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    Korni
    Posts: 430 from 2006/2/23
    From: the Planet of ...
    Quote:

    KennyR wrote:
    Don't forget too that a single monitor has multiple screenmodes, each of which can have a different refresh rate. You don't really see that on TFT, but it was a thing on CRT.

    A very annoying thing.


    Not really as on MorphOS you can't have two or more screenmodes with the same width,height,depth and a different refresh. You see that on pretty much every monitor in its EDID data.
    http://korni.ppa.pl/modkowypaczek/ | My Rifle, My Bunny, and Me
  • »02.08.19 - 19:17
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    KennyR
    Posts: 657 from 2003/3/4
    From: #AmigaZeux, Gu...
    Quote:

    Korni wrote:
    Quote:

    KennyR wrote:
    Don't forget too that a single monitor has multiple screenmodes, each of which can have a different refresh rate. You don't really see that on TFT, but it was a thing on CRT.

    A very annoying thing.


    Not really as on MorphOS you can't have two or more screenmodes with the same width,height,depth and a different refresh. You see that on pretty much every monitor in its EDID data.


    No, but you can still have 1024x768 @ 75Hz, 1600x1200 @ 60 Hz, 800x600 @ 85Hz, etc.

    CRT were a pain. No native resolution, and generally refresh rate had to be compromised as you went up in res.
  • »02.08.19 - 20:48
    Profile