Inaccurate vertical blank timing (VBL)
Posted: Fri Apr 13, 2012 1:32 am
I am currently programming a simple game for OS4 (non-commercial, just for fun), and are now working on a screen with 2D scrolling.
I have no problems making a glitch-free scrolltext, as long as it's far down on the screen.
However, if I put my scrolltext on the upper part of the screen (especially at the upper position 0), it doesn't scroll smooth anymore (graphics glitches and occasional 1-frame freezes now and then).
The program is made in C, and I use Intuition & Graphics library (no SDL, MiniGL or similar).
Scrolling is made by using the Graphics library "BltBitMapRastPort"/"BltBitMap"-procedures.
It's "single buffered", but the graphics are so light, that this shouldn't be a problem.
The graphics I "blit" is very small (672x32 pixels, 32 colours).
The screen resolution is 640x512 pixels, and of course fullscreen mode on a separate screen.
On my system, I have the following issues:
1) Graphics glitches when my program scrolls an object on the screen, using a loop with WaitTOF() in it:
=> See description of the issue above.
2) The Graphics.library function "VBeamPos" increases by 1 position for each vertical blank (after each WaitTOF-call).
=> See the output I got below. It's consistently +1 compared to the previous VBL. This is strange, as I would expect the value to be approximately fixed.
This must either be a bug in the VBeamPos-function, or it indicates a VBL synchronization issue that leads to the issue described in 1) above and 3) below.
3) Graphics glitches when my program scrolls an object upwards on the screen, using a VBL-interrupt containing a "BltBitMapRastPort"-call (through Exec's "AddIntServer"-function):
=> The glitches are different than for case 1). The scrolling runs smooth, except for a few fixed intervals (a horizontal stripe moving upwards on the screen).
---
Here is parts of the code I used to find the vertical beam position:
while (!done)
{
IGraphics->WaitTOF();
pos = IGraphics->VBeamPos();
IDOS->Printf("%ld ",pos);
.
.
}
...and the result (it's strange it's so consistent...):
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
My system:
HW: Sam440ep (mini-ITX) w/512MB RAM and onboard Radeon M9 Graphics card. The monitor is a CRT type, synced at 60 Hz (Vertical).
OS: OS 4.1 update 4.
Thanks in advance for your assistance.
I have no problems making a glitch-free scrolltext, as long as it's far down on the screen.
However, if I put my scrolltext on the upper part of the screen (especially at the upper position 0), it doesn't scroll smooth anymore (graphics glitches and occasional 1-frame freezes now and then).
The program is made in C, and I use Intuition & Graphics library (no SDL, MiniGL or similar).
Scrolling is made by using the Graphics library "BltBitMapRastPort"/"BltBitMap"-procedures.
It's "single buffered", but the graphics are so light, that this shouldn't be a problem.
The graphics I "blit" is very small (672x32 pixels, 32 colours).
The screen resolution is 640x512 pixels, and of course fullscreen mode on a separate screen.
On my system, I have the following issues:
1) Graphics glitches when my program scrolls an object on the screen, using a loop with WaitTOF() in it:
=> See description of the issue above.
2) The Graphics.library function "VBeamPos" increases by 1 position for each vertical blank (after each WaitTOF-call).
=> See the output I got below. It's consistently +1 compared to the previous VBL. This is strange, as I would expect the value to be approximately fixed.
This must either be a bug in the VBeamPos-function, or it indicates a VBL synchronization issue that leads to the issue described in 1) above and 3) below.
3) Graphics glitches when my program scrolls an object upwards on the screen, using a VBL-interrupt containing a "BltBitMapRastPort"-call (through Exec's "AddIntServer"-function):
=> The glitches are different than for case 1). The scrolling runs smooth, except for a few fixed intervals (a horizontal stripe moving upwards on the screen).
---
Here is parts of the code I used to find the vertical beam position:
while (!done)
{
IGraphics->WaitTOF();
pos = IGraphics->VBeamPos();
IDOS->Printf("%ld ",pos);
.
.
}
...and the result (it's strange it's so consistent...):
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
My system:
HW: Sam440ep (mini-ITX) w/512MB RAM and onboard Radeon M9 Graphics card. The monitor is a CRT type, synced at 60 Hz (Vertical).
OS: OS 4.1 update 4.
Thanks in advance for your assistance.