--- os2sdk/demos/apps/chaser/chaser.c 2018/08/09 12:25:13 1.1.1.1 +++ os2sdk/demos/apps/chaser/chaser.c 2018/08/09 12:25:59 1.1.1.2 @@ -1,4 +1,7 @@ -/* SWARM - the idea behind this game is as follows: +/* SWARM + * Created by Microsoft Corp. 1986 + * + * the idea behind this game is as follows: * * You have a collection of objects in the center of the playing field * that you are trying to protect (just one object in current version). You @@ -26,7 +29,7 @@ * resources. The programmer can think of the problem as only one attacker. * The system handles multiple instances of the thread. * - * As the main loop launched threads it puts an ID code into the threads + * As the main loop launches threads it puts an ID code into the thread's * stack. The code is used to index into the universe data. * * A ram semaphore is used to control access to global data. @@ -35,16 +38,21 @@ * * Tasking: VIO API: Mouse API: * - * DOSSEMREQUEST() VIOSCROLLUP() MOUOPEN() - * DOSSEMCLEAR() VIOWRTCELLSTR() MOUSETPTRPOS() - * DOSCREATETHREAD() VIOSETCURTYPE() MOUREADEVENTQUE() - * DOSEXIT() VIOSETMODE() - * DOSSLEEP() + * DosSemRequest() VioScrollUp() MouOpen() + * DosSemClear() VioWrtCellStr() MouSetPtrPos() + * DosCreateThread() VioSetCurType() MouReadEventQue() + * DosExit() VioSetMode() + * DosSleep() */ +#include +#define INCL_DOSPROCESS +#define INCL_DOSSEMAPHORES +#include +#define INCL_SUB +#include #include +#undef NULL #include -#include -#include #define STACKSIZE 200 @@ -81,16 +89,16 @@ struct { /* Universe structure a short ScreenHeight, /* Screen attributes */ ScreenWidth; -unsigned short Mouse; /* place for mouse handle */ -unsigned long Shortnap; /* Sleep times for chasers */ -unsigned long Longnap; -unsigned long far Semaphore = 0; /* Ram semaphore */ +HMOU Mouse; /* place for mouse handle */ +ULONG Shortnap; /* Sleep times for chasers */ +ULONG Longnap; +ULONG Semaphore = 0; /* Ram semaphore */ -struct CursorData NewCur; /* struct for setting cursor type */ -struct CursorData OldCur; +struct _VIOCURSORINFO NewCur; /* struct for setting cursor type */ +struct _VIOCURSORINFO OldCur; -struct ModeData modedata; /* Data saves for VIO mode */ -struct ModeData OldVioMode; +struct _VIOMODEINFO modedata; /* Data saves for VIO mode */ +struct _VIOMODEINFO OldVioMode; /* * Define all procedures before main. @@ -115,12 +123,12 @@ char *av[]; */ if (ParseCmdLine(ac,av)) { printf("usage: %s [24|43] [F|M|S]\n",av[0]); - DOSEXIT(0,1); + DosExit(EXIT_THREAD,1); } if (InitGame()) /* Init game, exit if some problem */ - DOSEXIT(1,1); + DosExit(EXIT_PROCESS,1); - Defender(); /* Run mouse loop (defend against the swarm */ + Defender(); /* Run mouse loop (defend against the swarm) */ CleanUp(); } @@ -137,50 +145,48 @@ char *av[]; */ void Defender() { - unsigned ReadType = 1, /* Wait for mouse events */ - alive, - i; - struct EventInfo MouInfo; /* mouse event packet structure */ + USHORT ReadType = 1, /* Wait for mouse events */ + alive, + i; + struct _MOUEVENTINFO MouInfo; /* mouse event packet structure */ alive = CHASER; do { - MOUREADEVENTQUE( (struct EventInfo far *)&MouInfo, - (unsigned far *)&ReadType, - Mouse ); /* read where mouse is */ - - DOSSEMREQUEST((unsigned long)&Semaphore, WAIT); - - if( MouInfo.Mask & 1) { /* If the mouse has moved */ - MOUSE.row = MouInfo.Row; - MOUSE.col = MouInfo.Col; + MouReadEventQue( &MouInfo, &ReadType, Mouse); /* read where mouse is */ + + DosSemRequest( &Semaphore, WAIT); + + if( MouInfo.fs & 1) { /* If the mouse has moved */ + MOUSE.row = MouInfo.row; + MOUSE.col = MouInfo.col; } - if( MouInfo.Mask & 4 ) { /* if left button pressed, */ + if( MouInfo.fs & 4 ) { /* if left button pressed, */ for (i = 0; i < CHASER; i++ ) { if( ( MOUSE.row == univ[i].row ) && ( MOUSE.col == univ[i].col ) && /* see if we hit one */ ( univ[i].state == ALIVE) ) { univ[i].state = DEAD; - DOSBEEP(300,75); /* make a dying sound */ - DOSBEEP(600,75); - DOSBEEP(300,85); + DosBeep(300,75); /* make a dying sound */ + DosBeep(600,75); + DosBeep(300,85); - alive--; /* Decrease number of alive */ + alive--; /* Decrease number alive */ break; /* Can only kill one at a time */ } } } - if( MouInfo.Mask & 16 ) /* If right button pressed... */ + if( MouInfo.fs & 16 ) /* If right button pressed... */ break; /* End game, clean up */ - DOSSEMCLEAR((unsigned long)&Semaphore); + DosSemClear(&Semaphore); } while (GOAL.state == ALIVE && alive); /* loop till all are dead */ } /* - * This thread manages the individule attackers. It is spun off as + * This thread manages the individual attackers. It is spun off as * many times as needed for a game. * * The interaction of the mouse cursor and the chaser character is sort @@ -201,7 +207,7 @@ int ID; /* Print out the initial chaser character */ - VIOWRTCELLSTR( (char far *)Chaser, 2, ME.row, ME.col, 0 ); + VioWrtCellStr( Chaser, 2, ME.row, ME.col, 0 ); /* * Keep running as long as the goal and myself haven't been killed. @@ -215,10 +221,10 @@ int ID; * the player some time to kill the chaser */ if ((MOUSE.row == row) && (MOUSE.col == col)) { - DOSSLEEP( 1L ); + DosSleep( 1L ); continue; } - DOSSEMREQUEST((unsigned long)&Semaphore, WAIT); + DosSemRequest(&Semaphore, WAIT); /* * If either the GOAL or Myself is dead, exit loop and clean up. * This wasn't tested in the for loop since we don't want to exit @@ -272,10 +278,10 @@ int ID; * Zap the old chaser and print the new. Release the semaphore * after this, there can be no undesirable interactions now. */ - VIOWRTCELLSTR( (char far *)Blank, 2, ME.row, ME.col, 0 ); - VIOWRTCELLSTR( (char far *)Chaser, 2, row, col, 0 ); + VioWrtCellStr( Blank, 2, ME.row, ME.col, 0 ); + VioWrtCellStr( Chaser, 2, row, col, 0 ); - DOSSEMCLEAR((unsigned long)&Semaphore); + DosSemClear(&Semaphore); /* * Update the current location */ @@ -285,12 +291,12 @@ int ID; * See if we have reached the GOAL, if so eat it and exit */ if ((row == GOAL.row) && (col == GOAL.col)) { - VIOWRTCELLSTR( (char far *)Blank, 2, row, col, 0 ); - DOSBEEP(600,175); - DOSBEEP(1200,175); /* if we reach the prize, let out a yell */ - DOSBEEP(600,185); /* paint the screen red and end the game */ - DOSBEEP(1200,175); - VIOSCROLLUP( 0, 0, -1, -1, -1, (char far *)Blood, 0 ); + VioWrtCellStr( Blank, 2, row, col, 0 ); + DosBeep(600,175); + DosBeep(1200,175); /* if we reach the prize, let out a yell */ + DosBeep(600,185); /* paint the screen red and end the game */ + DosBeep(1200,175); + VioScrollUp( 0, 0, -1, -1, -1, Blood, 0 ); GOAL.state = DEAD; } /* @@ -298,21 +304,21 @@ int ID; * upon the danger level */ if( danger ) - DOSSLEEP(Shortnap); + DosSleep(Shortnap); else - DOSSLEEP(Longnap); + DosSleep(Longnap); } /* * chaser is now dead or the game is over. * Erase its body and terminate the thread. Release the semaphore. */ - DOSSEMCLEAR((unsigned long)&Semaphore); + DosSemClear(&Semaphore); if (GOAL.state == ALIVE) { - VIOWRTCELLSTR( (char far *)Blank, 2, ME.row, ME.col, 0 ); + VioWrtCellStr(Blank, 2, ME.row, ME.col, 0 ); } - DOSEXIT(0,0); + DosExit( EXIT_THREAD ,0); } /* @@ -324,30 +330,30 @@ int ID; */ int InitGame() { - struct PtrLoc InitMouPos; + struct _PTRLOC InitMouPos; void far chasethread(); /* code to control chasers */ - unsigned far *Tstack; /* stack for new threads */ + PBYTE Tstack; /* stack for new threads */ unsigned chaseID; int i, rc; /* * Clear the screen. */ - VIOSCROLLUP( 0, 0, -1, -1, -1, (char far *)Blank, 0 ); + VioScrollUp( 0, 0, -1, -1, -1, Blank, 0 ); /* * Draw the prize */ GOAL.row = ScreenHeight/2; GOAL.col = ScreenWidth /2; GOAL.state = ALIVE; - VIOWRTCELLSTR((char far *)Prize, 2, GOAL.row, GOAL.col, 0 ); + VioWrtCellStr(Prize, 2, GOAL.row, GOAL.col, 0 ); /* * Open the mouse pointer device and set it's location. */ - MOUOPEN( 0L, (unsigned far *)&Mouse ); - InitMouPos.RowPos = GOAL.row; - InitMouPos.ColPos = GOAL.col; - MOUSETPTRPOS((struct PtrLoc far *)&InitMouPos, Mouse); - MOUDRAWPTR(Mouse); + MouOpen( 0L, &Mouse ); + InitMouPos.row = GOAL.row; + InitMouPos.col = GOAL.col; + MouSetPtrPos( &InitMouPos, Mouse); + MouDrawPtr(Mouse); /* * A simple minded initialization for the start of each chaser. * Some sort of random placement (based upon system time?) would @@ -364,26 +370,26 @@ int InitGame() /* * Grab the semaphore to prevent chaser from running until we are done. */ - DOSSEMREQUEST((unsigned long)&Semaphore, WAIT); + DosSemRequest(&Semaphore, WAIT); for( i = 0; i < CHASER; i++ ) { /* for each of our threads... */ univ[i].state = ALIVE; /* Set each one alive */ - Tstack = (int *)malloc(sizeof(int) * STACKSIZE); + Tstack = (PBYTE)malloc(sizeof(int) * STACKSIZE); if (Tstack == NULL ) { /* Create a stack */ printf( "thread %d stack malloc failed\n", i ); return(1); } - Tstack += STACKSIZE; /* set stack pointer to correct end */ - *--Tstack = i; /* Push the ID on as a parameter */ + Tstack += sizeof(int)*STACKSIZE; /* set stack pointer to correct end */ + *--Tstack = HIBYTE(i); + *--Tstack = LOBYTE(i); /* Push the ID on as a parameter */ - rc = DOSCREATETHREAD(chasethread, (unsigned far *)&chaseID, - (char far *)Tstack); + rc = DosCreateThread(chasethread, &chaseID, Tstack); if(rc) { printf( "create of thread %d failed, error: %d\n", i, rc ); return (1); } } - DOSSEMCLEAR((unsigned long)&Semaphore); + DosSemClear(&Semaphore); return (0); } @@ -398,15 +404,15 @@ void CleanUp() { char blank[2]; - DOSSLEEP(1L); /* Yeild the machine so attacker can clean up */ - VIOSETMODE((struct ModeData far *)&OldVioMode, 0); + DosSleep(1L); /* Yield the machine so attacker can clean up */ + VioSetMode( &OldVioMode, 0); /* blank[0] = ' '; blank[1] = OldVioMode.color; - VIOSCROLLUP( 0, 0, -1, -1, -1, (char far *)blank, 0 ); + VioScrollUp( 0, 0, -1, -1, -1, blank, 0 ); */ - VIOSETCURTYPE(&OldCur, 0); - DOSEXIT(1,0); /* Exit and terminate all threads. */ + VioSetCurType( &OldCur, 0); + DosExit(EXIT_PROCESS,0); /* Exit and terminate all threads. */ } /* @@ -419,7 +425,7 @@ int ParseCmdLine(ac,av) int ac; char **av; { - struct ModeData modedata; + struct _VIOMODEINFO modedata; int VioMode; Longnap = LONGNAP; @@ -461,20 +467,20 @@ char **av; } } - VIOGETCURTYPE(&OldCur, 0); /* Save old cursor */ + VioGetCurType(&OldCur, 0); /* Save old cursor */ - modedata.length = sizeof(modedata); /* change mode as needed */ - VIOGETMODE((struct ModeData far *)&modedata, 0); + modedata.cb = sizeof(modedata); /* change mode as needed */ + VioGetMode( &modedata, 0); OldVioMode = modedata; modedata.row = VioMode; - VIOSETMODE((struct ModeData far *)&modedata, 0); + VioSetMode( &modedata, 0); - NewCur.cur_start = 0; - NewCur.cur_end = 0; - NewCur.cur_width = 1; - NewCur.cur_attribute = -1; + NewCur.yStart = 0; + NewCur.cEnd = 0; + NewCur.cx = 1; + NewCur.attr = -1; - VIOSETCURTYPE(&NewCur, 0 ); /* make cursor go away */ + VioSetCurType( &NewCur, 0 ); /* make cursor go away */ return (0); }