Then the help file has a bug.
The first parameter is a port number. As the processor has 16 address lines for ports, the range is from 0 to 65535.
"WAIT X, bitmask" checks if the bits in the bitmask are set, if not it just halts the execution. WAIT &H3DA waits until bit 3 of port &H3DA is set.
"WAIT X, bitmask1, bitmask2" does exactly the opposite if bitmask1=bitmaks2, i.e. WAIT &H3DA waits until bit 3 of port &H3DA is reset.
To understand the logics, it works in the same way as the typical "wait for a keypress" subroutine:
Code:
WHILE INKEY$<>"": WEND
WHILE INKEY$="": WEND
The first line assures that the keyboard buffer is empty. The second one waits for the first keypress to happen.
The graphics card sets a bit 3 in port &H3DA when the electron beam has drawn the whole image on your monitor screen, then resets it when it starts the next one. With the two instructions, you first assure that the Vsync has not yet started, then you wait until it ends (or the way around, it doesn't matter very much
).
The VSync subroutine is not used to measure time, but to provide a constant framerate and to prevent flickering on screen, as it is used so the new frame is rendered to the VGA memory in the gap of time which is between the screen has been output to your monitor and the begin of the next "redrawing", i.e., while the electron beam is going back from the bottom right side of the screen to the top left one to start again with the next frame. That way stuff won't be "visible" while it's being drawn. It's some kind of "drawing while the monitor doesn't notice".
As the redrawing happens 60 times a second, you know that your main loop will run exactly 60 times a second (as long as the loop
can run in less than 1/60 seconds, of course), so it's perfect for timing in games.
---
About the DEFSEG thingo, I can assure you that it won't slow your program.