Hi :-)

> I had a few minutes of free time lately and felt the inexplicable need 
> to write a Nibbles clone (remember this game that was shipped with 

Hehe :-D

> The first (best so far) is checking the time in a loop (at 18,2Hz), and 
> performing an int15h AX=5305h at every iteration to notify APM about 
> available CPU. This works very well on a real machine, as well as on 
> VirtualBox (with and without FDAPM). The CPU usage is very low.

I guess the recommended way is to notify DOS and let that do the rest.
Not sure if DOSEMU implements this function. I remember that some VM,
possibly DOSBOX, did not emulate HLT, because they were just happy to
let DOS stuff run faster by making HLT a NOP :-p It is quite possible
that DOSEMU does not do much with APM BIOS, but there is an API to
check exactly that ;-)

> Surprisingly, under both DOSEmu and DOSBox the CPU usage is very high.
> I guess they don't support the APM v1.0 interface...
> 
> The second is about calling the BIOS function int15h AH=86h. This works 
> okay on a real machine, but makes keyboard controls under DOSemy laggy,

This can be because int 15.86 can try to be smart: Use 18.2 Hz ticks
for longer delays and do busy-waiting in a tight loop otherwise. It
is possible that some BIOSes use CMOS 32kHz ticks or other fancy and
energy-friendly waiting methods for shorter delays, but you simply
do not really know.

> and don't work at all with DOSBox. DOSBox keeps crying this:
> 
>   Illegal read from 5820585e, CS:IP     f000:    11c4

Weird. Ask their forum?

> The third one is about using the Turbo C 'delay' function (supposed to 
> provide a millisecond-grade sleep). I don't know what is behind this, 

Typical Borland IDE compilers come with runtime libraries
which implement this as tight loops calibrated when your
app starts. Well-known Error 200 for those where you get
an overflow for fast CPU. Otherwise just CPU cycle waste.

> but it makes CPU usage very high. It works fine under DOSBox (apart form 
> the burning CPU), but not under DOSemu (don't sleep at all, which makes 
> it impossible to play, unless your name is Barry Allen).

Barry Allen? I think the last time I wrote a Snake clone
in 2.5 dimensions in Borland, in Pascal, I updated the
code to use 40:6c aka 18.2 Hz timer ticks at some point.

> I was also wondering about issuing HLT instructions, but it doesn't look 
> like a nice solution to me, since it would require to add some asm into 
> my C project, and it wouldn't work on many platforms (Windows...), and I 
> feel it's not the application's job to issue HLT, this should be taken 
> care of by APM, or the BIOS, or whatever.. But not the application.

In DOS, it was fine to HLT, but you can also tell DOS that
you are idle, then FDAPM will either HLT or call the APM
BIOS function, depending on what is available then :-)

> Another issue I had (still have, in fact) is the timer resolution. The 
> resolution of my APM-aware sleeping routines is of ~55ms (18,2Hz). This 
> makes the game not as smooth as I'd like.

You can change frequency to anything faster, as long as you
put your own int 8 handler which takes care that the original
handler is only called as often as intended. Otherwise, lots
of DOS and BIOS things would suddenly go faster. Programming
the frequency of the timer is easy: Same hardware interface
as what you use for different frequency PC speaker beeps :-)

Regarding PIT programming, you normally just write hex 20
to the PIT port for IRQ ack when you are done, UNLESS you
call the original int 8 handler, in which case that will
do it for you. You want to avoid sending too many ACK but
as you notice, most handlers do not actually take efforts
to do SPECIFIC ACK such as "am done with IRQ 0 aka int 8"
but just send "done with IRQ".

Cheers, Eric



------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user

Reply via email to