VOGONS


First post, by Zirias

User metadata
Rank Newbie
Rank
Newbie

Posting this here, as it is about code i want to run inside dosbox, if I misunderstood the scopes of the forums, please move ...

I developed a little curses game recently and made it to compile for DOS (using djgpp) today. It depends on having a source of constant "timing ticks" -- the main loop waits for the next tick when work for the current tick is finished. The implementation for DOS initially looked like that:

void
ticker_wait(void)
{
while (uclock() < nextTick);
nextTick += tickTime;
}

giving the following assembly:

L10:
call _uclock
movl _nextTick+4, %ebx
movl _nextTick, %ecx
cmpl %ebx, %edx
jle L14
L8:
addl _tickTime, %ecx
adcl _tickTime+4, %ebx
movl %ecx, _nextTick
movl %ebx, _nextTick+4
ret
L14:
jl L10
cmpl %ecx, %eax
jb L10
jmp L8

(I stripped all pseudo opcodes and stack manipulation for readability)

This worked flawlessly in dosbox, but then I wanted to do something more "smart" than just a busy wait, so I changed it to the following:

void
ticker_wait(void)
{
if (haveYield)
{
while (uclock() < nextTick) __dpmi_yield();
}
else
{
while (uclock() < nextTick) __asm__ volatile ("hlt");
}
nextTick += tickTime;
}

The __dpmi_yield() should give up a time slice when running in a multitasking environment. in dosbox, the "else" branch is taken, so showing only the relevant assembly here:

L8:
call _uclock
movl _nextTick+4, %ebx
movl _nextTick, %ecx
cmpl %ebx, %edx
jl L9
jle L14
L11:
addl _tickTime, %ecx
adcl _tickTime+4, %ebx
movl %ecx, _nextTick
movl %ebx, _nextTick+4
ret
L14:
cmpl %ecx, %eax
jnb L11
L9:
hlt
jmp L8

This looks all good, but my game has situations where the ticker is not used and curses (in that case PDcurses) is asked to do a blocking `getch()` (wait for keyboard input) -- e.g. while showing a dialog. As soon as this hlt instruction is there, a subsequent PDcurses blocking getch() will eventually succeed, but slow execution down ridiculously (like, waiting 10 to 20 seconds for ANYTHING to happen).

So I first thought this might somehow interfere with PDcurses' code to implement blocking. To verify, I ran my program in virtualbox, using a real MS-DOS 6.22 installation. It worked perfectly.

Therefore my question: Is this expected behaviour in dosbox?

For reference, the whole code is on github

Last edited by Zirias on 2015-07-26, 09:28. Edited 1 time in total.