_IMPLEMENTING GAMES FOR WINDOWS_ by James Finnegan Example 1: (a) xor ax,ax mov ah,80h add ax, ax ;;Will o/flow in 16 bits jc short &n&_fix_cs (b) mov bx,cs ... mov es,ax mov di.sp mov ax,000Bh int 31h ;;; DPMI: Get the CS descr ;;; change the following to USE32 or byte ptr es:[di+6],40h mov ax,000Ch int 31h ;;; DPMI. Set the CS descr (c) xor eax,eax mov ah,80h add eax,eax ;; Doesn't overflow in 32 bits jc short &n&_fix_cs Example 2: (a) WinGRecommendDIB Format((BITMAPINFO far*)&WinGDIBHeader.bmiHeader); (b) for(iColorIndex = 10;iColorIndex < 246;iColorIndex++) { WinGDIBHeader.bmiColors[iColorIndex].rgbRed = LogicalPalette.palEntries[iColorIndex].peRed = pColorTable[icolorIndex].rgbRed; WinGDIBHeader.bmiColors[iColorIndexl.rgbGreen = LogicalPalette.palEntries[iColorIndex].peGreen = pColorTable[iColorIndex].rgbGreen; WinGDIBHeader.bmiColors[iColorIndex].rgbBlue = LogicalPdlette.palEntries[iColorIndex].peBlue = pColorTable[icolorIndexl.rgbBlue: WinGDIBHeader.bmiColors[!ColorIndexj.rgbReserved = 0; // This flag includes PC_NOCOLLAPSE LogicalPalette.palEntries[iColorlndexl.peFlags = PC_RESERVED; } (c) // Get the 20 static colors hDC = GetDC(O); GetSystemPaletteEntries(hDC,0,10,LogicalPalette.palEntries); GetSystemPaletteEntries(hDC,246,10,LogicalPalette.palEntries + 246): ReleaseDC(0,hDC); (d) ghMSJIdentityPalette = CreatePalette((LOGPALETTE far*) &LogicalPalette): (e) SelectPalette(hDC,ghMSJldentityPalette,FALSE); RealizePalette(hDC); Example 3: (a) ghWinGBackgroundDC = WinGCreateDC(): (b) hBitmap = WinGCreateBitmap(ghWinGBackgroundDC, (BITMAPINFO far*)&WinGBackgroundDIBHeader, (void far*)&ghpWinGBackgroundBitmap); (c) gbm0ldBackgroundBitmap=(HBITMAP)SelectObject(ghWinGBackgroundDC,hBitmap); (d) StretchDIBits(ghWinGBackgroundDC,0,0,giWindowX,giWindowY,0,0, DibWidth(gpdibBackgroundBitmap),DibHeight(gpdibBackgroundBitmap), DibPtr(gpdibBackgroundBitmap),DibInfo(gpdibBackgroundBitmap), DIB_RGB_COLORS,SRCCOPY); (e) ghWinGDC = WinGCreateDC(); hBitmap = WinGCreateBitmap(ghWinGDC,(BITMAPINFO far*)&WinGDIBHeader, (void far *)&ghpWinGBitmap): gbm0ldBitmap = (HBITMAP)SelectObject(ghWinGDC,hbitmap); (f) BitBlt(ghWinGDC,0,0,0,giWindowX,giWindowY,ghWinGBackgroundDC,0,0,SRCCOPY); (g) hDC = BeginPaint(hWnd,&ps); SelectPalette(hDC,ghMSJldentityPalette,FALSE); RealizePalette(hDC); WinGBitBlt(hDC,0,0,giWindowX,giWindowY,ghWinGDC,0,0); EndPaint(hWnd,&ps); Example 4: (a) mcConfig.wSize = sizeof(MIXCONFIG); mcConfig.dwFlags = WMIX_CONFIG_CHANNELS; mcConfig.wChannels = 2: // Start up Wavemix ghMixSession = WaveMixConfigureInit(&mcConfig); (b) glpMixl=WaveMixOpenWave(ghMixSession,"1.wav",NULL,WMIX_FILE); glpMix2=WaveMixOpenWave(ghMixSession,"2.wav",NULL,WMIX_FILE); glpMix3=WaveMixOpenWave(ghMixSession,"3.wav",NULL.WMIX_FILE); glpMix4=WaveMixOpenWave(ghMixSession,"4.wav",NULL,WMIX_FILE); (c) WaveMixOpenChannel(ghMixSession,4,WHIX_OPENCOUNT): (d) case WM_ACTIVATE: // WA_INACTIVE == FALSE; WaveMixActivate(ghMixSession, wparam); break; (e) MixPlayParams.wSize = sizeof(MIXPLAYPARAMS); MixPlayParams.hMixSession = ghMixSession; MixPlayParams.hWndNotify = NULL: MixP]ayParams.dwFlags=WMIX_HIPRIORITY; MixPlayParams.wLoops=0; MixPlayParams.iChannel=3; MixPlayParams.lpMixWave=glpMix4; WaveMixPlay(&MixPlayParams);