--- os2sdk/demos/apps/mandel/mdraw.c 2018/08/09 12:25:13 1.1.1.1 +++ os2sdk/demos/apps/mandel/mdraw.c 2018/08/09 12:25:59 1.1.1.2 @@ -1,5 +1,6 @@ /* mdraw.c - display Mandelbrot set on EGA - * R. A. Garmoe 86/12/15 + * + * Created by Microsoft Corp. 1986 */ @@ -62,13 +63,14 @@ * -int int The first value is the run length and * second value is the run value */ +#define INCL_SUB +#define INCL_DOSMEMMGR +#define INCL_DOSPROCESS +#define INCL_DOSSEMAPHORES - - +#include #include -#include -#include -#include +#include #include "mdraw.h" /* The routines that are in the IOPL segment must be declared @@ -88,15 +90,15 @@ * in the EXPORTS statements in the mdraw.def linker definitions file. */ -extern void far pascal SetDVideo (); -extern void far pascal SetEVideo (); -extern void far pascal SetScanClear (); -extern void far pascal SetScan (int, int, char *); -extern void far pascal SetScanSave (unsigned far *); -extern void far pascal SetScanSFont (unsigned); -extern void far pascal SetScanRFont (unsigned); -extern void far pascal SetScanRestore (unsigned far *); -extern void far pascal SetCursor (char far *); +extern void APIENTRY SetDVideo (); +extern void APIENTRY SetEVideo (); +extern void APIENTRY SetScanClear (); +extern void APIENTRY SetScan (int, int, char *); +extern void APIENTRY SetScanSave (unsigned far *); +extern void APIENTRY SetScanSFont (unsigned); +extern void APIENTRY SetScanRFont (unsigned); +extern void APIENTRY SetScanRestore (unsigned far *); +extern void APIENTRY SetCursor (char far *); void far mode_wait (void); /* starting address for a thread */ @@ -106,13 +108,35 @@ void far redraw_wait (void); /* starting /* Structures for VIO calls */ -struct ConfigData config; /* Display configuration data */ -struct ModeData mode; /* Display mode data */ -struct ModeData grmode; /* graphics display mode data */ -struct PhysBufData physbuf; /* Physical buffer data */ -struct CursorData cursor; /* Cursor data structure */ -struct KeyData key; /* Keystroke data */ -struct VIOSTATE vstate; /* Set vio state */ +struct VIOSTATE { + unsigned length; + unsigned req_type; + unsigned double_defined; + unsigned palette0; + unsigned palette1; + unsigned palette2; + unsigned palette3; + unsigned palette4; + unsigned palette5; + unsigned palette6; + unsigned palette7; + unsigned palette8; + unsigned palette9; + unsigned palette10; + unsigned palette11; + unsigned palette12; + unsigned palette13; + unsigned palette14; + unsigned palette15; + }; + + VIOCONFIGINFO config; /* Display configuration data */ + VIOMODEINFO mode; /* Display mode data */ + VIOMODEINFO grmode; /* graphics display mode data */ + VIOPHYSBUF physbuf; /* Physical buffer data */ + VIOCURSORINFO cursor; /* Cursor data structure */ + KBDKEYINFO key; /* Keystroke data */ +struct VIOSTATE vstate; /* Set vio state */ @@ -151,13 +175,13 @@ struct ilist *head = NULL; /* pointer to struct ilist *curr = NULL; /* pointer to current ilist */ struct ilist *tail = NULL; /* pointer to tail of ilist */ -unsigned curcol; /* cursor column position */ -unsigned currow; /* cursor row position */ -unsigned descsel; /* selector for image structure */ -unsigned fontsel; /* selectors for font saves */ +USHORT curcol; /* cursor column position */ +USHORT currow; /* cursor row position */ +SEL descsel; /* selector for image structure */ +SEL fontsel; /* selectors for font saves */ unsigned dpoffset = 0; /* display page offset 0x0000 or 0x8000 */ -unsigned *psel; /* display memory selector */ -unsigned screenlen; /* length of screen buffer */ +SEL *psel; /* display memory selector */ +USHORT screenlen; /* length of screen buffer */ main (argc, argv) int argc; @@ -167,27 +191,27 @@ char **argv; int i; int temp; int pal; - unsigned char *stack1, /* stack for mode_wait thread */ - *stack2; /* stack for redraw_wait thread */ - unsigned ThreadID; + UCHAR *stack1, /* stack for mode_wait thread */ + *stack2; /* stack for redraw_wait thread */ + TID ThreadID; /* Validate the display configuration. It must be an EGA on an * EGA adapter with at least 128k of memory. */ - config.length = 10; - if ((temp = VIOGETCONFIG (0, (struct ConfigData far *)&config, 0)) != 0) { + config.cb = 10; + if ((temp = VioGetConfig (0, &config, 0)) != 0) { printf ("Unable to get display configuration data - %d\n", temp); exit (1); } - if ((config.adapter_type != 2) || (config.display_type != 2) || - config.memory_size < 0x20000) { + if ((config.adapter != 2) || (config.display != 2) || + config.cbMemory < 0x20000) { printf ("Display is not EGA on 128k EGA adapter %d %d %ld\n", - config.adapter_type, config.display_type, config.memory_size); + config.adapter,config.display, config.cbMemory); exit (1); } - if (config.memory_size == 0x40000) + if (config.cbMemory == 0x40000) flip = TRUE; /* Save information about the current display mode. This includes @@ -195,16 +219,16 @@ char **argv; * current cursor position and the text screen data. */ - mode.length = sizeof (struct ModeData); - if ((temp = VIOGETMODE ((struct ModeData far *)&mode, 0)) != 0) { + mode.cb = sizeof (VIOMODEINFO); + if ((temp = VioGetMode (&mode, 0)) != 0) { printf ("Unable to get display mode data - %d\n", temp); exit (1); } - if (VIOGETCURTYPE ((struct CursorData *)&cursor, 0) != 0) { + if (VioGetCurType (&cursor, 0) != 0) { printf ("Unable to get current cursor data\n"); exit (1); } - if (VIOGETCURPOS ((unsigned far *)&currow, (unsigned far *)&curcol, 0) != 0) { + if (VioGetCurPos (&currow, &curcol, 0) != 0) { printf ("Unable to get current cursor position\n"); exit (1); } @@ -218,7 +242,7 @@ char **argv; printf ("Unable to allocate memory for text screen buffer\n"); exit (1); } - if (VIOREADCELLSTR ((char far *)screenbuf, (unsigned far *)&screenlen, + if (VioReadCellStr (screenbuf, &screenlen, 0, 0, 0) != 0) { printf ("Unable to read text screen data\n"); exit (1); @@ -226,13 +250,13 @@ char **argv; /* Obtain selectors to the display memory */ - physbuf.buf_start = 0xa0000; - physbuf.buf_length = 0x20000; - if ((temp = VIOGETPHYSBUF ((struct PhysBufData far *)&physbuf, 0)) != 0) { + physbuf.pBuf = (PBYTE)0xa0000; + physbuf.cb = 0x20000; + if ((temp = VioGetPhysBuf (&physbuf, 0)) != 0) { printf ("Unable to get physical buffer mapping - %d\n", temp); exit (1); } - if (DOSALLOCSEG (0,(unsigned far *)&fontsel, 0) != 0) { + if (DosAllocSeg (0,&fontsel, 0) != 0) { printf ("Unable to allocate text font save segment\n"); exit (1); } @@ -249,18 +273,18 @@ char **argv; /* create thread to execute the mode wait */ - DOSCREATETHREAD (mode_wait, &ThreadID, stack1); + DosCreateThread (mode_wait, &ThreadID, stack1); /* create thread that will execute the redraw_wait () */ - DOSCREATETHREAD (redraw_wait, &ThreadID, stack2); + DosCreateThread (redraw_wait, &ThreadID, stack2); /* Pass pointer to the selectors for display memory and the * selector to the font save segment to the ring 2 IOPL code. */ - psel = physbuf.selectors; + psel = physbuf.asel; /* Save the font tables */ @@ -269,13 +293,13 @@ char **argv; /* Set the EGA to 640 x 350 graphics mode */ grmode = mode; - grmode.type = grmode.type | 0x02; + grmode.fbType = grmode.fbType | 0x02; grmode.hres = 640; grmode.vres = 350; - VIOSETMODE ((struct ModeData far *)&grmode, 0); - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + VioSetMode (&grmode, 0); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); /* Set the file name if specified and open the file for reading */ @@ -318,9 +342,9 @@ char **argv; /* reinitialize palette registers */ for (i = 0; i < 16; i++) palette[i] = initpal[i]; - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); break; case 'n': @@ -371,14 +395,14 @@ char **argv; /* delay to prevent CPU bound loop */ if (delay == 0) - DOSSLEEP ((long)100); + DosSleep (100L); else if (delay > 0) { ripple (RIPPLE_UP); - DOSSLEEP (delay); + DosSleep (delay); } else { ripple (RIPPLE_DN); - DOSSLEEP ((long)(-delay)); + DosSleep ((long)(-delay)); } } } @@ -399,14 +423,14 @@ struct image far *im; { int i; int ni; /* scan row counter */ - int temp; + BYTE temp; int len; char *pmapped; - VIOSCRLOCK (1, (char far *)&temp, 0); - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + VioScrLock (1, &temp, 0); + DosSemRequest ((HSEM)&drawsem, -1L); SetScanClear (); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); for (ni = 0; ni < im->lni; ni++) { pmapped = mapped; @@ -429,18 +453,18 @@ struct image far *im; * the redraw-wait routine can save and restore the screen */ - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); SetScan (ni, im->lnr, mapped); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); } /* Save screen image and unlock the screen */ - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); SetScanSave (curr->desc->savesel); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); - VIOSCRUNLOCK (0); + VioScrUnLock (0); } @@ -487,16 +511,13 @@ int *p; void mode_wait () { - unsigned NotifyType; + USHORT NotifyType; while (TRUE) { /* wait for notification to restore mode */ - VIOMODEWAIT (0, &NotifyType, 0); + VioModeWait (0, &NotifyType, 0); if (NotifyType == 0 && graphics) - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); - VIOSETMODE ((struct ModeData far *)&grmode, 0); - SetScanClear (); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + VioSetMode (&grmode,0); } } @@ -518,14 +539,13 @@ void mode_wait () void redraw_wait () { - unsigned NotifyType; + USHORT NotifyType; while (TRUE) { - VIOSAVREDRAWWAIT (0, &NotifyType, 0); + VioSavRedrawWait (0, &NotifyType, 0); if (graphics) { if (NotifyType == 0) { /* save graphics screen */ - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); SetScanSave (curr->desc->savesel); SetScanClear (); continue; @@ -533,12 +553,11 @@ void redraw_wait () else if (NotifyType == 1) { /* restore graphics screen */ dpoffset = 0; - VIOSETMODE ((struct ModeData far *)&grmode, 0); + VioSetMode (&grmode, 0); SetScanClear (); SetDVideo (); SetScanRestore (curr->desc->savesel); SetEVideo (); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); } } } @@ -567,14 +586,14 @@ readimage () printf ("Unable to allocate memory for ilist structure\n"); exit (1); } - if (DOSALLOCSEG (sizeof (struct image),(unsigned far *)&descsel, 0) != 0) { + if (DosAllocSeg (sizeof (struct image),&descsel, 0) != 0) { cleandisplay (); printf ("Unable to allocate image descriptor segment of %d bytes\n", sizeof (struct image)); exit (1); } - FP_SEG (tlist->desc) = descsel; - FP_OFF (tlist->desc) = 0; + SELECTOROF(tlist->desc) = descsel; + OFFSETOF (tlist->desc) = 0; /* Read description of the computed Mandelbrot set from the file * and perform simple validation checks. Limit the display rows and @@ -644,7 +663,7 @@ readimage () */ for ( i = 0; i < 2; i++) { - if (DOSALLOCSEG (56020, (unsigned far *)&timage.savesel[i], 0) != 0) { + if (DosAllocSeg (56020, (PSEL)&timage.savesel[i], 0) != 0) { cleandisplay (); printf ("Unable to allocate screen save segments\n"); exit (1); @@ -653,7 +672,7 @@ readimage () /* Link image to chain of images */ - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); /* copy structure to far segment */ *(tlist->desc) = timage; tlist->next = NULL; @@ -665,7 +684,7 @@ readimage () tail = tlist; curr = tlist; - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); /* Lock the screen, set the display to graphics mode * and draw the Mandelbrot set @@ -686,8 +705,8 @@ cleandisplay () { /* cancel mode wait and redraw wait threads */ - VIOMODEUNDO (GIVEUPOWNER, KILLTHREAD, RESERVED); - VIOSAVREDRAWUNDO (GIVEUPOWNER, KILLTHREAD, RESERVED); + VioModeUndo (GIVEUPOWNER, KILLTHREAD, RESERVED); + VioSavRedrawUndo (GIVEUPOWNER, KILLTHREAD, RESERVED); /* Return the EGA adapter to a default mode that hopefully * matches the mode that was present when we went into graphics @@ -706,16 +725,16 @@ cleandisplay () SetScanRFont (fontsel); } SetEVideo (); - VIOSETMODE ((struct ModeData far *)&mode, 0); - if (VIOWRTCELLSTR ((char far *)screenbuf, screenlen, 0, 0, 0) != 0) { + VioSetMode (&mode, 0); + if (VioWrtCellStr (screenbuf, screenlen, 0, 0, 0) != 0) { printf ("Unable to write text screen data\n"); exit (1); } - if (VIOSETCURPOS (currow, curcol, 0) != 0) { + if (VioSetCurPos (currow, curcol, 0) != 0) { printf ("Unable to set current cursor position\n"); exit (1); } - if (VIOSETCURTYPE ((struct CursorData *)&cursor, 0) != 0) { + if (VioSetCurType (&cursor, 0) != 0) { printf ("Unable to set current cursor data\n"); exit (1); } @@ -733,7 +752,7 @@ nextimage () int temp; if (head != tail) { - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); if (curr->next == NULL) curr = head; else @@ -741,7 +760,7 @@ nextimage () if (flip) dpoffset ^= PAGESIZE; SetScanRestore (curr->desc->savesel); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); } } @@ -754,11 +773,11 @@ nextimage () previmage () { - int temp; + BYTE temp; if (head != tail) { - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); - VIOSCRLOCK (1, (char far *)&temp, 0); + DosSemRequest ((HSEM)&drawsem, -1L); + VioScrLock (1, &temp, 0); if (curr->prev == NULL) curr = tail; else @@ -766,8 +785,8 @@ previmage () if (flip) dpoffset ^= PAGESIZE; SetScanRestore (curr->desc->savesel); - VIOSCRUNLOCK (0); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + VioScrUnLock (0); + DosSemClear ((HSEM)&drawsem); } } @@ -806,9 +825,9 @@ int dir; palette[0x0f] = temp; break; } - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); } @@ -835,15 +854,15 @@ int pal; temp = palette[pal]; while (!nextchar (&c, 1)) { palette[pal] = BLACK; - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); - DOSSLEEP ((long)100); + DosSemClear ((HSEM)&drawsem); + DosSleep (100L); palette[pal] = temp; - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); - DOSSLEEP ((long)100); + DosSemClear ((HSEM)&drawsem); + DosSleep (100L); } ungetchar (); } @@ -888,17 +907,17 @@ paledit () case RIGHT: if (++palette[pal] > 0x3f) palette[pal] = 1; - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); break; case LEFT: if (--palette[pal] == 0) palette[pal] = 0x3f; - DOSSEMREQUEST ((unsigned long)(long far *)&drawsem, (long)-1); + DosSemRequest ((HSEM)&drawsem, -1L); setpalette (palette); - DOSSEMCLEAR ((unsigned long)(long far *)&drawsem); + DosSemClear ((HSEM)&drawsem); break; default: @@ -932,21 +951,21 @@ int wait; int ret; if (!chvalid) { - if ((ret = KBDCHARIN ((struct KeyData far *)&key, wait, 0)) != 0) { + if ((ret = KbdCharIn (&key, wait, 0)) != 0) { cleandisplay (); - printf ("Error %d return from KBDCHARIN\n", ret); + printf ("Error %d return from KbdCharIn\n", ret); exit (1); } firstread = TRUE; - if ((key.status & 0x40) != 0x40) + if ((key.fbStatus & 0x40) != 0x40) return (FALSE); } chvalid = FALSE; - if (key.char_code == 0x00) + if (key.chChar == 0x00) /* process extended ASCII character */ - *pchar = -(int)key.scan_code; + *pchar = -(int)key.chScan; else - *pchar = (int)key.char_code; + *pchar = (int)key.chChar; return (TRUE); } @@ -993,7 +1012,7 @@ char *p; vstate.double_defined = 0; for (ip = &vstate.palette0; ip <= &vstate.palette15; ) *ip++ = *p++; - if (VIOSETSTATE ((struct VIOSTATE far *)&vstate, 0) != 0) { + if (VioSetState ((PVIOPALSTATE)&vstate, 0) != 0) { cleandisplay (); printf ("Unable to set palette registers\n"); exit (1);