carlos12
Experienced Member
OutRun for PC self adapts the FPS shown depending on the speed of the processor. But, and this really seems stunning to me, it makes it on real time! For example, on DOSBox you can start at a certain speed (let's say, 3000 cycles) and it runs very smooth. But if, during the game play, we gradually reduce the cycles down to 280 (which could be more or less equivalent to an 8088 at 4.77 Mhz), we'll see how the game continues its way, but n frames are being skipped, finally being quite jerky when ~280 is reached. The opposite is also true, starting slow and incrementing the speed makes the game run smoother on real time.
So I'm wondering what technique could be used to achieve this effect.
A less elegant solution I figured out would be calculating the approximate speed of the system, by counting cycles, and after that, skip the frames needed for every speed. I post here the code I wrote for counting cycles, in case it's useful for somebody, or if anybody would like to improve something on it:
I made a table of the values returned by a few systems, emulated via 86Box, so I could use them as a reference. For instance, this code returns 302 for the IBM PC and XT, 291 for the Compaq Portable, 276 for the original Tandy 1000 or 349 for an American XT clone, all of them running at 4.77 (the higher, the slower). I also have values from 8086 to 486 processors, that ranks from 160 to 6. I think this code could not be used for real time speed poling as it takes a time to count the cycles, I would use it once at the beginning to establish the frame skipping.
Another solution would be just asking the user if s/he is using a slow of fast processor (as Blood Money for PC does) and then accordingly skip 1, 2 or whatever the frames needed.
I think the autoskip solution would be fantastic but I have not a clue of how could be accomplished.
Thank you very much!
So I'm wondering what technique could be used to achieve this effect.
A less elegant solution I figured out would be calculating the approximate speed of the system, by counting cycles, and after that, skip the frames needed for every speed. I post here the code I wrote for counting cycles, in case it's useful for somebody, or if anybody would like to improve something on it:
Code:
#include <stdio.h>
#include <time.h>
void count_cpu_cycles (void)
{
clock_t start, stop;
unsigned long t;
asm mov al, 0x34
asm out 0x43, al /* tell the PIT which channel we're setting */
_CX = (int)(1193180L / 1000); /* 1193180L / Frequency in Hz*/
outportb(0x40,_CL); /* Configuring timer 0 with the freq */
outportb(0x40,_CH);
start = clock();
asm mov cx,8000h /* Do it 32768 times */
loopClock:
asm ror al,1
asm sub al,al
asm add al,250 /* Just a few random operations to consume cycles */
asm loop loopClock
stop = clock();
outportb(0x43,0x34);
outportb(0x40,0);
outportb(0x40,0); /* Restoring the timer */
t = stop-start;
printf ("Result = %lu ... %lu = %lu", stop, start, t);
}
I made a table of the values returned by a few systems, emulated via 86Box, so I could use them as a reference. For instance, this code returns 302 for the IBM PC and XT, 291 for the Compaq Portable, 276 for the original Tandy 1000 or 349 for an American XT clone, all of them running at 4.77 (the higher, the slower). I also have values from 8086 to 486 processors, that ranks from 160 to 6. I think this code could not be used for real time speed poling as it takes a time to count the cycles, I would use it once at the beginning to establish the frame skipping.
Another solution would be just asking the user if s/he is using a slow of fast processor (as Blood Money for PC does) and then accordingly skip 1, 2 or whatever the frames needed.
I think the autoskip solution would be fantastic but I have not a clue of how could be accomplished.
Thank you very much!