1. Re: [DOS] How to code for a time delay? - AGAIN

Alex Caracatsanis wrote:
> 
> One more question: how would I go about shortening the delay interval (to
> say 0.5 seconds), as sleep(i) accepts only an integer argument? ie:
> <display a star><wait 0.5sec><display another star><wait 0.5sec><...etc>
> 
> Thank you
> 
> Alex Caracatsanis

If you only need a coarse timing (in 1/18ths of second), then a simple solution
is to code a habdler for DOS interrupt 08 (timer), and use get_vector() and
set_vector() to hook it.
The handler only needs:
* a counter, decremennted on each call. When it is 0, print the star and 
reset it for the next wait delay;
* the counter reset value
* a pointer to the former int 08 handler, to chain to it;
* code that would disassemble as
<asm>
dec [my_counter]
jnz the_end ;nothing to do
push eax
mov eax,#0F2A
int #10 -- print a star using current color and location
mov eax,[my_reset]
mov [my_counter],eax
pop eax
:the_end ; chain to previous handler
jmp far [old_handler]
</asm>

Set my_counter and my_reset to the same value before chaining.
Also, since Euphoria asm code is position independent, you must
* allocate the right amount of memory
* poke your machine code there
* then poke the right addresses - doing it beforehand is more complicated.

You can optimize further by noticing that you may hardcode the value of 
[my_reset] (hence the last mov eax, would become a hardcoded constant mov 
and you set that constant as the mov field before call). You may use an
immediate jmp far and use the instruction address field to store the old
vector's address as well.

When done, don't forget to restore the previous handler. Also, 
remember that handlers must be uninstalled in the reverse order of
installation. You can try being smarter, but it is a little bit trickier smile

If you wish finer control, you'd have to use ports #40-43 and program the
timer there.
CChris

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu