My first attempt at a unified PDC_napms() for DOS. Not ideal yet, but it

doesn't throttle the CPU anymore with any compiler. Also, the stack
registers and flags apparently need to be cleared in PDC_dpmi_int() for
stability -- I dunno why (I copied this from DJGPP), but without it,
worm was locking up pretty regularly.
This commit is contained in:
William McBrine
2006-12-29 21:16:32 +00:00
parent 66dbeafafd
commit 529beaa77c
2 changed files with 32 additions and 28 deletions

View File

@@ -11,7 +11,7 @@
* See the file maintain.er for details of the current maintainer. *
************************************************************************/
/* $Id: pdcdos.h,v 1.25 2006/12/29 18:36:35 wmcbrine Exp $ */
/* $Id: pdcdos.h,v 1.26 2006/12/29 21:16:32 wmcbrine Exp $ */
#include <curspriv.h>
#include <string.h>
@@ -90,6 +90,7 @@ extern unsigned pdc_video_ofs;
# include <sys/movedata.h>
unsigned char getdosmembyte(int offs);
unsigned short getdosmemword(int offs);
unsigned long getdosmemdword(int offs);
void setdosmembyte(int offs, unsigned char b);
void setdosmemword(int offs, unsigned short w);
#else
@@ -102,6 +103,8 @@ void setdosmemword(int offs, unsigned short w);
(*((unsigned char PDC_FAR *) _FAR_POINTER(0,offs)))
# define getdosmemword(offs) \
(*((unsigned short PDC_FAR *) _FAR_POINTER(0,offs)))
# define getdosmemdword(offs) \
(*((unsigned long PDC_FAR *) _FAR_POINTER(0,offs)))
# define setdosmembyte(offs,x) \
(*((unsigned char PDC_FAR *) _FAR_POINTER(0,offs)) = (x))
# define setdosmemword(offs,x) \

View File

@@ -19,7 +19,7 @@
#include <time.h>
RCSID("$Id: pdcutil.c,v 1.16 2006/12/29 18:36:35 wmcbrine Exp $");
RCSID("$Id: pdcutil.c,v 1.17 2006/12/29 21:16:32 wmcbrine Exp $");
void PDC_beep(void)
{
@@ -34,36 +34,25 @@ void PDC_beep(void)
void PDC_napms(int ms)
{
PDCREGS regs;
long goal;
PDC_LOG(("PDC_napms() - called: ms=%d\n", ms));
#if defined(__DJGPP__)
goal = ms / 50;
if (!goal)
goal = 1;
usleep(1000 * ms);
/* get number of ticks since startup from address 0040:006ch
1 sec. = 18.2065 */
#elif defined(DOS)
goal += getdosmemdword(0x46c);
# if defined(__TURBOC__) || defined(__WATCOMC__)
delay(ms);
# elif defined(_MSC_VER) || defined(_QC)
while (goal > getdosmemdword(0x46c))
{
clock_t goal = (ms / 50) + clock();
while (goal > clock())
;
regs.W.ax = 0x1680;
PDCINT(0x2f, regs);
}
# elif defined(__PACIFIC__)
{
/* get number of ticks since startup from address 0040:006ch
1 sec. = 18.2065 */
volatile far long *ticks = MK_FP(0x0040, 0x006c);
long goal = (ms / 50) + *ticks;
while (goal > *ticks)
;
}
# endif
#endif
}
const char *PDC_sysname(void)
@@ -89,6 +78,14 @@ unsigned short getdosmemword(int offset)
return w;
}
unsigned long getdosmemdword(int offset)
{
unsigned long dw;
dosmemget(offset, sizeof(unsigned long), &dw);
return dw;
}
void setdosmembyte(int offset, unsigned char b)
{
dosmemput(&b, sizeof(unsigned char), offset);
@@ -107,10 +104,14 @@ void PDC_dpmi_int(int vector, pdc_dpmi_regs *rmregs)
{
union REGPACK regs = {0};
regs.w.ax = 0x300;
regs.h.bl = vector;
rmregs->w.ss = 0;
rmregs->w.sp = 0;
rmregs->w.flags = 0;
regs.w.ax = 0x300;
regs.h.bl = vector;
regs.x.edi = FP_OFF(rmregs);
regs.x.es = FP_SEG(rmregs);
regs.x.es = FP_SEG(rmregs);
intr(0x31, &regs);
}