|
-
Aug 9th, 2021, 08:07 AM
#1
Thread Starter
Frenzied Member
Re: QBasic/Qb45 high precision timing->
@passel:
I made a simple bouncing ball program using vertical retracing as a timing method:
Code:
DEFINT A-Z
SCREEN 12: CLS
x = 320
y = 240
DirectionX = 1
DirectionY = 1
DO
CIRCLE (x, y), 10, 0
DO
IF INKEY$ = CHR$(27) THEN END
LOOP WHILE (INP(&H3DA) XOR &H8) AND &H8 = &H0 'This part does the same as "WAIT &H3DA, &H8, &H8".
IF x <= 0 OR x >= 639 THEN DirectionX = -DirectionX
IF y <= 0 OR y >= 479 THEN DirectionY = -DirectionY
x = x + DirectionX
y = y + DirectionY
CIRCLE (x, y), 10, 2
LOOP
Whether or not I actually use the WAIT statement I can tell the program's speed increases as I increase the number of cycles in DOSBox. What am I doing wrong?
-
Aug 9th, 2021, 10:03 AM
#2
Re: QBasic/Qb45 high precision timing->
Well, I wonder if testing the &H3DA port is actually valid under DOSBox. Perhaps DOSBox does emulate the VGA correctly to have the games work correctly.
Assuming that is the case, did you get the "equivalent" code for "WAIT" from some source.
It doesn't look like the code should work.
WAIT &H3DA, &H8 should just AND 8 to the port, so will either return True (-1 long) if the result is 8, or 0 otherwise.
Your doing an XOR with 8 will toggle the bit, so if it is a 1, the result will be 0, and then if you AND 0 with 8 it will still be 0.
This seems to be the opposite of what you want.
I would think all you would need is:
LOOP WHILE (INP(&H3DA) AND &H8)
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Aug 9th, 2021, 10:25 AM
#3
Re: QBasic/Qb45 high precision timing->
Looking at the code a bit more, I think you actually need a two step check to sync your loop to the vsync.
You are checking the state of bit 3 (mask 8), but the bit will be 0 while not in the vertical sync period, and it will be 1 while in the vertical sync period, but the point is the vertical sync period is a "period" of time. If you want to sync to the sync, then you want to exit the sync loop on a transition (0 to 1, or 1 to 0), not on the state of the bit.
Something along the lines of:
Code:
DO
IF INKEY$ = CHR$(27) THEN END
LOOP WHILE (INP(&H3DA) AND &H8) = &H0
DO
IF INKEY$ = CHR$(27) THEN END
LOOP WHILE (INP(&H3DA) AND &H8) = &H8
The above will exit the vsync on the 1 to 0 transition.
If the bit is 0, then it will wait in the first loop until it goes to 1, then it will wait in the second loop until it goes back to 0, and then you code will run one cycle, and then come back and wait for the next 1 to 0 transition.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|