Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I'm sure you've all seen this:

KingOfTheWorldKingOfTheWorld Posts: 44Member
Procedure WaitRetrace; assembler;
label
a11,a12;
asm
mov DX, 3dah
a11:
in AL, DX
and AL, 08h
jnz a11
a12:
in AL, DX
and AL, 08h
jz a12
end;


can someone explain to me what is it?

Comments

  • ManningManning Posts: 1,621Member
    As the procedure declaration says, it is assembler code. But I dont know assembler so dont know what it does.

    : Procedure WaitRetrace; assembler;
    : label
    : a11,a12;
    : asm
    : mov DX, 3dah
    : a11:
    : in AL, DX
    : and AL, 08h
    : jnz a11
    : a12:
    : in AL, DX
    : and AL, 08h
    : jz a12
    : end;
    :
    :
    : can someone explain to me what is it?

  • angelusMortisangelusMortis Posts: 141Member
    this procedure is waiting for a retrace.
    its used for screen- synchronization.
    if u let ur programs run without it
    they will run too fast and look ugly.

    the screen is showing u the picture
    by shooting with his cathod- ray
    at the phosphor. it is doing this
    from the left side to the right side,
    row by row.
    [code]
    -------------------------------------------------
    |-----------------------------> |
    |---------------------------> |
    |-------------------------------> |
    |... ... ... |
    | |
    | |
    | |
    | |
    | |
    |... ... ... ... |
    | |
    | |
    | |
    | |
    | |
    |----------------------------------> end here- >|
    -------------------------------------------------
    [/code]
    when the cathod- ray is finished doing this, it
    will return back from the right bottom corner
    to the left upper corner:
    [code]
    -------------------------------------------------
    | _<- return back to first row |
    | | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    | |
    -------------------------------------------------
    [/code]
    this is called the vertical- retrace.
    after this vertical- retrace the screen
    will start his work again and again ... ... .
    during the vertical- retrace no data is read
    from the videomemory. thus if u write
    ur data during the vertical- retrace to the
    videomemeory there will be no conflicts between
    the CPU and the VGA- card.
    all in all the vertical retrace is the best time
    for writing data to Vram.
    if a vertical retrace is occuring the bit #3
    of the register 3DAh is set.
    the register should then look like this in binary
    00001000
    in decemal this equals to the number 8.
    the programmer here is first testing for the bit.
    if it is set then the sceen is finished. if not
    then the screen is displaying data from the
    Vram.
    in the first loop he is waiting for the end
    of the vertical- retrace.
    in the last loop he is waiting for the
    start of the vertical- retrace. so
    after the CPU has left the procedure the
    monitor will be in a vertical- retrace and
    the programmer can write to Vram without
    conflicts with the VGA- hardware.

    in pascal it should be:
    [code]
    repeat until port[$3DA] and 8<>8;
    repeat until port[$3DA] and 8=8;
    [/code]
    i haven't tried it.

  • KingOfTheWorldKingOfTheWorld Posts: 44Member
    what the difference between this procedure and a delay(X)?



    : this procedure is waiting for a retrace.
    : its used for screen- synchronization.
    : if u let ur programs run without it
    : they will run too fast and look ugly.
    :
    : the screen is showing u the picture
    : by shooting with his cathod- ray
    : at the phosphor. it is doing this
    : from the left side to the right side,
    : row by row.
    : [code]
    : -------------------------------------------------
    : |-----------------------------> |
    : |---------------------------> |
    : |-------------------------------> |
    : |... ... ... |
    : | |
    : | |
    : | |
    : | |
    : | |
    : |... ... ... ... |
    : | |
    : | |
    : | |
    : | |
    : | |
    : |----------------------------------> end here- >|
    : -------------------------------------------------
    : [/code]
    : when the cathod- ray is finished doing this, it
    : will return back from the right bottom corner
    : to the left upper corner:
    : [code]
    : -------------------------------------------------
    : | _<- return back to first row |
    : | | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : | |
    : -------------------------------------------------
    : [/code]
    : this is called the vertical- retrace.
    : after this vertical- retrace the screen
    : will start his work again and again ... ... .
    : during the vertical- retrace no data is read
    : from the videomemory. thus if u write
    : ur data during the vertical- retrace to the
    : videomemeory there will be no conflicts between
    : the CPU and the VGA- card.
    : all in all the vertical retrace is the best time
    : for writing data to Vram.
    : if a vertical retrace is occuring the bit #3
    : of the register 3DAh is set.
    : the register should then look like this in binary
    : 00001000
    : in decemal this equals to the number 8.
    : the programmer here is first testing for the bit.
    : if it is set then the sceen is finished. if not
    : then the screen is displaying data from the
    : Vram.
    : in the first loop he is waiting for the end
    : of the vertical- retrace.
    : in the last loop he is waiting for the
    : start of the vertical- retrace. so
    : after the CPU has left the procedure the
    : monitor will be in a vertical- retrace and
    : the programmer can write to Vram without
    : conflicts with the VGA- hardware.
    :
    : in pascal it should be:
    : [code]
    : repeat until port[$3DA] and 8<>8;
    : repeat until port[$3DA] and 8=8;
    : [/code]
    : i haven't tried it.
    :


  • ibyiby Posts: 323Member
    : what the difference between this procedure and a delay(X)?
    :

    Difference is in time delay. DELAY has FIXED (more or less)
    delay. If you call something like:

    [code]
    DELAY(13);
    [/code]

    your PC will wait about 13 miliseconds EVERY time.

    The V_Sync procedure (the code you have posted) will
    wait and wait and wait until vertical sycronization
    pulse is generated. This pulse is generated every
    10-15mSecond depending on the frame rate.
    For example if your graphic card is generating 75fps,
    one frame lasts about 13.33mSecond (1second/75).
    After some work, wiat for V_Sync:
    - If pulse is generated 0.1mSec later, delay is only 0.1mSec.
    - If pulse is generated 10mSec later, delay is 10mSec.

    So the delay ADJUSTS itself to the speed of the computer.
    On a fast computer it will wait longer, on slow it will wait
    shorter.
    Only on really slow computers (or if your program is not
    optimized or designed well) this will exceed frame time.
    If so V_Sync will still wait for sync pulse. However, since
    it missed one, it will wait till following one making
    game run really slow (half of the frame rates since every other
    sync pulse is skipped). Most nowdays games offer option to
    turn off vsync for that purpose (better to run little bit
    too fast than a lot slower).

    Iby

  • angelusMortisangelusMortis Posts: 141Member
    for me the main difference is that if u
    use the vertical- retrace then ur graphics
    animations will look better. thats just my
    experience. as i have already said if u use
    a delay(X) or just no delay then the CPU
    will have conflicts with the VGA and the
    animations will look ugly. for example i
    made a program that just moved a pixel
    across the screen. with vertical- retrace it
    looked smooth, with delay(x) it looked
    like the pixel is being moved and the
    pixel behind it was deleted after it moved
    away, so it looked like there were two pixels
    on screen instead of one.


Sign In or Register to comment.