First post, by Zirias
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:
voidticker_wait(void){while (uclock() < nextTick);nextTick += tickTime;}
giving the following assembly:
L10:call _uclockmovl _nextTick+4, %ebxmovl _nextTick, %ecxcmpl %ebx, %edxjle L14L8:addl _tickTime, %ecxadcl _tickTime+4, %ebxmovl %ecx, _nextTickmovl %ebx, _nextTick+4retL14:jl L10cmpl %ecx, %eaxjb L10jmp 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:
voidticker_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 _uclockmovl _nextTick+4, %ebxmovl _nextTick, %ecxcmpl %ebx, %edxjl L9jle L14L11:addl _tickTime, %ecxadcl _tickTime+4, %ebxmovl %ecx, _nextTickmovl %ebx, _nextTick+4retL14:cmpl %ecx, %eaxjnb L11L9:hltjmp 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