Patrick Georgi | 3b77b72 | 2011-07-07 15:41:53 +0200 | [diff] [blame] | 1 | /* Public Domain Curses */ |
| 2 | |
| 3 | #include "pdcdos.h" |
| 4 | |
| 5 | RCSID("$Id: pdcutil.c,v 1.24 2008/07/13 16:08:17 wmcbrine Exp $") |
| 6 | |
| 7 | void PDC_beep(void) |
| 8 | { |
| 9 | PDCREGS regs; |
| 10 | |
| 11 | PDC_LOG(("PDC_beep() - called\n")); |
| 12 | |
| 13 | regs.W.ax = 0x0e07; /* Write ^G in TTY fashion */ |
| 14 | regs.W.bx = 0; |
| 15 | PDCINT(0x10, regs); |
| 16 | } |
| 17 | |
| 18 | void PDC_napms(int ms) |
| 19 | { |
| 20 | PDCREGS regs; |
| 21 | long goal, start, current; |
| 22 | |
| 23 | PDC_LOG(("PDC_napms() - called: ms=%d\n", ms)); |
| 24 | |
| 25 | goal = DIVROUND((long)ms, 50); |
| 26 | if (!goal) |
| 27 | goal++; |
| 28 | |
| 29 | start = getdosmemdword(0x46c); |
| 30 | |
| 31 | goal += start; |
| 32 | |
| 33 | while (goal > (current = getdosmemdword(0x46c))) |
| 34 | { |
| 35 | if (current < start) /* in case of midnight reset */ |
| 36 | return; |
| 37 | |
| 38 | regs.W.ax = 0x1680; |
| 39 | PDCINT(0x2f, regs); |
| 40 | PDCINT(0x28, regs); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | const char *PDC_sysname(void) |
| 45 | { |
| 46 | return "DOS"; |
| 47 | } |
| 48 | |
| 49 | #ifdef __DJGPP__ |
| 50 | |
| 51 | unsigned char getdosmembyte(int offset) |
| 52 | { |
| 53 | unsigned char b; |
| 54 | |
| 55 | dosmemget(offset, sizeof(unsigned char), &b); |
| 56 | return b; |
| 57 | } |
| 58 | |
| 59 | unsigned short getdosmemword(int offset) |
| 60 | { |
| 61 | unsigned short w; |
| 62 | |
| 63 | dosmemget(offset, sizeof(unsigned short), &w); |
| 64 | return w; |
| 65 | } |
| 66 | |
| 67 | unsigned long getdosmemdword(int offset) |
| 68 | { |
| 69 | unsigned long dw; |
| 70 | |
| 71 | dosmemget(offset, sizeof(unsigned long), &dw); |
| 72 | return dw; |
| 73 | } |
| 74 | |
| 75 | void setdosmembyte(int offset, unsigned char b) |
| 76 | { |
| 77 | dosmemput(&b, sizeof(unsigned char), offset); |
| 78 | } |
| 79 | |
| 80 | void setdosmemword(int offset, unsigned short w) |
| 81 | { |
| 82 | dosmemput(&w, sizeof(unsigned short), offset); |
| 83 | } |
| 84 | |
| 85 | #endif |
| 86 | |
| 87 | #if defined(__WATCOMC__) && defined(__386__) |
| 88 | |
| 89 | void PDC_dpmi_int(int vector, pdc_dpmi_regs *rmregs) |
| 90 | { |
| 91 | union REGPACK regs = {0}; |
| 92 | |
| 93 | rmregs->w.ss = 0; |
| 94 | rmregs->w.sp = 0; |
| 95 | rmregs->w.flags = 0; |
| 96 | |
| 97 | regs.w.ax = 0x300; |
| 98 | regs.h.bl = vector; |
| 99 | regs.x.edi = FP_OFF(rmregs); |
| 100 | regs.x.es = FP_SEG(rmregs); |
| 101 | |
| 102 | intr(0x31, ®s); |
| 103 | } |
| 104 | |
| 105 | #endif |