HMEM BMAlloc ( UINT cb ) { #ifdef BMHANDLES // { HMEM hv; CVEnterCritSection(icsBm); hv = BMFindAvail ( ); if ( hv ) { LPV lpv = _fmalloc ( cb ); if ( LPV == NULL ) { hv = hmemNull; } else { LpvFromHmem ( hv ) = lpv; } } CVLeaveCritSection(icsBm); return hv; #else // } else !BMHANDLES { return (HMEM) _fmalloc(cb); #endif // } }
/* ******************************************************************** */ PFBYTE _ks_malloc(int num_elements, int size) { PFBYTE ptr; # if (defined (RTKBCPP)) ptr = ks_dpmi_alloc((word)(num_elements * size)); # elif (INCLUDE_BGET) ptr = ((PFBYTE)bget(num_elements * size)); # elif (INCLUDE_WINSOCK || INCLUDE_BSDSOCK) ptr = malloc(num_elements * size); # elif (defined(SEG_IAR)) /* protected mode */ ptr = malloc(num_elements * size); # elif ( defined(__BORLANDC__) ) /* real mode */ ptr = _fmalloc(num_elements * size); # else #error: ks_malloc needs to be implemented # endif #if (DISPLAY_MALLOC) DEBUG_ERROR("ks_malloc allocs: ", DINT1, ptr, 0); #endif return(ptr); }
unsigned char _far *SaveWindow(char x1,char y1,char br,char ho) { unsigned char _far *adr,_far *zgr,_far *scrbasis=ScreenAdr(); char x,y; size_t size=(x1+br-x1)*(y1+ho-y1)*2; unsigned offset; x1--; y1--; adr=_fmalloc(size); if (adr!=NULL) { zgr=adr; for (y=y1+ho;y>y1;y--) for (x=x1+br;x>x1;x--) { offset=(y-1)*160+(x-1)*2; *zgr=*(scrbasis+offset); zgr++; *zgr=*(scrbasis+offset+1); zgr++; } } return(adr); }
BOOL BMNewBlock ( int iabl ) { assert ( iabl < cablMax ); assert ( *( rgabl + iabl ) == NULL ); if ( ( *( rgabl + iabl ) = _fmalloc ( clpvMax * sizeof ( LPV ) ) ) == NULL ) { return FALSE; } _fmemset ( *( rgabl + iabl ), 0, clpvMax * sizeof ( LPV ) ); #ifdef DEBUGVER if ( ( *( rglckb + iabl ) = _fmalloc ( clpvMax * sizeof ( BYTE ) ) ) == NULL ) { return FALSE; } _fmemset ( *( rglckb + iabl ), 0, clpvMax * sizeof ( BYTE ) ); #endif return TRUE; }
/****************************************************************************** ** Save a screen rectangle defined by (sx,sy):(dx,dy) to a memory buffer. The ** memory buffer is allocated here and returned to the caller. */ NWGFARBUF NWGFXSaveRect(NWGPOS iSX, NWGPOS iSY, NWGPOS iDX, NWGPOS iDY) { NWGSCNPTR lpScreen; /* Pointer to screen. */ NWGFARBUF lpBuffer, lpSave; /* Pointer the memory save buffer. */ NWGNUM iWidth, iHeight; /* Blit dimensions. */ NWGNUM iOffset; /* Next raster line offset. */ NWGNUM iTmpWidth; /* Temporary width counter. */ #ifdef DEBUG /* Check we have a valid screen address. */ if (!lpScnOrigin) { printf("NWGFXSaveRect(): Screen uninitialised.\n"); exit(1); } /* Validate rectangle corners. */ if ( (iSX < 0) || (iSX >= iScnWidth) || (iDX < 0) || (iDX >= iScnWidth) || (iSY < 0) || (iSY >= iScnHeight) || (iDY < 0) || (iDY >= iScnHeight) ) { NWGFXSetCursorPos(0, 0); printf("NWGFXSaveRect(): Attempt to blit an area outside of the screen."); return (NWGFARBUF) NULL; } #endif /* Allocate far memory buffer. */ lpBuffer = lpSave = _fmalloc( ( (iDX - iSX + 1) * (iDY - iSY + 1) ) * 2 ); if (!lpBuffer) return (NWGFARBUF) NULL; /* Calculate blit origin, dimensions and next raster line offset. */ lpScreen = lpScnOrigin + ( (iScnWidth * 2 * iSY) + (iSX * 2) ); iWidth = (iDX - iSX + 1) * 2; iHeight = iDY - iSY + 1; iOffset = (iScnWidth * 2) - iWidth; /* Perfom the blit. */ while(iHeight--) { /* Fetch the line width in bytes. */ iTmpWidth = iWidth; /* Blit a line. */ while(iTmpWidth--) *lpBuffer++ = *lpScreen++; /* Move to next line. */ lpScreen += iOffset; } /* Return the buffer address. */ return lpSave; }
byte * modexNewPal() { byte *ptr; ptr = _fmalloc(768); /* handle errors */ if(!ptr) { printf("Could not allocate palette.\n"); exit(-1); } return ptr; }
BOOL BMInit ( VOID ) { #ifdef BMHANDLES // { if ( ( rgabl = (ABL FAR *) _fmalloc ( sizeof ( ABL ) * cablMax ) ) == NULL ) { return FALSE; } _fmemset ( rgabl, 0, sizeof ( ABL ) * cablMax ); #ifdef DEBUGVER if ( ( rglckb = (LCKB FAR *) _fmalloc ( sizeof ( LCKB ) * cablMax ) ) == NULL ) { return FALSE; } _fmemset ( rglckb, 0, sizeof ( LCKB ) * cablMax ); #endif // CAV 6583 -- must reset hvCur each time we re-init // (the IDE calls BMInit() each time it starts a debug session, codeview // only calls BMInit() once so hvCur doesn't need to be reset... hvCur = (HMEM) 1; CVInitCritSection(icsBm); return BMNewBlock ( 0 ); #else // } else !BMHANDLES { // We're going to return pointers directly, rather than having our own // handles. So we need to make sure that pointers and handles are the // same size. assert ( sizeof(HMEM) == sizeof(VOID FAR *) ); return TRUE; #endif // } }
void main(void) { char far *dta; dta = getdta(); printf("Current DTA is %lX\n", dta); if (MK_FP(_psp, 0x80) == dta) printf("DTA is at same location as command line\n"); dta = _fmalloc(128); setdta(dta); printf("New DTA is %lX\n", getdta()); }
OLECHAR FAR * ToNewW(char FAR* lpszA) { OLECHAR FAR * szW; UINT cb; cb = strlen(lpszA)+1; szW = (LPOLESTR)_fmalloc(cb * sizeof(OLECHAR)); SideAssert (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszA, cb, szW, cb) != 0); return szW; }
void main() { char *buf; char __far *buf2; buf = (char *) malloc( 80 ); printf( "Size of buffer is %u\n", _msize(buf) ); if( _expand( buf, 100 ) == NULL ) { printf( "Unable to expand buffer\n" ); } printf( "New size of buffer is %u\n", _msize(buf) ); buf2 = (char __far *) _fmalloc( 2000 ); printf( "Size of far buffer is %u\n", _fmsize(buf2) ); if( _fexpand( buf2, 8000 ) == NULL ) { printf( "Unable to expand far buffer\n" ); } printf( "New size of far buffer is %u\n", _fmsize(buf2) ); }
unsigned char dosamp_FAR * convert_rdbuf_get(uint32_t *sz) { if (convert_rdbuf.buffer == NULL) { if (convert_rdbuf.size == 0) convert_rdbuf.size = 4096; #if TARGET_MSDOS == 32 || defined(LINUX) convert_rdbuf.buffer = malloc(convert_rdbuf.size + BOUNDS_EXTRA); #else convert_rdbuf.buffer = _fmalloc(convert_rdbuf.size + BOUNDS_EXTRA); #endif convert_rdbuf.len = 0; convert_rdbuf.pos = 0; #ifdef BOUNDS_CHECK if (convert_rdbuf.buffer != NULL) { convert_rdbuf.buffer += BOUNDS_ADJUST; { unsigned char dosamp_FAR *p = convert_rdbuf.buffer - BOUNDS_ADJUST; register unsigned int i; for (i=0;i < BOUNDS_ADJUST;i++) p[i] = i; } { unsigned char dosamp_FAR *p = convert_rdbuf.buffer + convert_rdbuf.size; register unsigned int i; for (i=0;i < (BOUNDS_EXTRA - BOUNDS_ADJUST);i++) p[i] = i; } } #endif } if (sz != NULL) *sz = convert_rdbuf.size; return convert_rdbuf.buffer; }
HMEM BMRealloc ( HMEM hv, UINT cb ) { #ifdef BMHANDLES // { LPV lpv; UINT cbOld; CVEnterCritSection(icsBm); lpv = LpvFromHmem ( hv ); assert ( LPV ); cbOld = _fmsize ( LPV ); if ( cbOld != cb ) { LPV lpvNew = _fmalloc ( cb ); if ( LPV && lpvNew) { _fmemcpy ( lpvNew, lpv, min ( cb, cbOld ) ); _ffree ( LPV ); LpvFromHmem ( hv ) = lpvNew; } else { hv = hmemNull; } } CVLeaveCritSection(icsBm); return hv; #else // } else !BMHANDLES { return (HMEM) _frealloc((VOID FAR *)hv, cb); #endif // } }
_WCRTLINK void *malloc( size_t amount ) { return( _fmalloc( amount ) ); }
BOOL WriteSecsWithBuf(DWORD dwStart,DWORD dwSize,BYTE btDisk,BYTE *pBuf,BOOL bVerify) { DWORD i,j,k; int nTry; BYTE *pCompBuf; BIOS_DRIVE_PARAM DriveParam; pCompBuf = NULL; if(bVerify) { pCompBuf = (BYTE *) _fmalloc(DATA_BUFFER_SIZE); if(!pBuf) { ErrorMessageBox(NO_MEMORY); return FALSE; } } if(!GetDriveParam(btDisk,&DriveParam)) { if(pCompBuf) free(pCompBuf); ErrorMessageBox(GET_DISK_PARAM_FAIL); return FALSE; } i = dwSize / DATA_BUFFER_SECTOR; j = dwSize % DATA_BUFFER_SECTOR; for (k=0; k<i ; k++) { nTry = 0; TRY_WRITE_LAB1: if(!WriteSector(dwStart+k*DATA_BUFFER_SECTOR,DATA_BUFFER_SECTOR,pBuf,btDisk,&DriveParam)) { if (g_nMaxTry == 0) ErrorMessageBox("Write sector fail."); if (nTry < g_nMaxTry) { nTry ++; SaveVerifyLog(g_chLogDrive,dwStart+k*DATA_BUFFER_SECTOR,DATA_BUFFER_SECTOR,TRUE); goto TRY_WRITE_LAB1; } } else { if(bVerify) { ReadSector(dwStart+k*DATA_BUFFER_SECTOR,DATA_BUFFER_SECTOR,pCompBuf,btDisk,&DriveParam); if(memcmp(pBuf,pCompBuf,DATA_BUFFER_SIZE)) { SaveVerifyLog(g_chLogDrive,dwStart+k*DATA_BUFFER_SECTOR,DATA_BUFFER_SECTOR,FALSE); } } } g_dDeletedSize += DATA_BUFFER_SECTOR; FlushProgressInfo(); } if (j) { nTry = 0; TRY_WRITE_LAB2: if(!WriteSector(dwStart+i*DATA_BUFFER_SECTOR,(WORD)j,pBuf,btDisk,&DriveParam)) { if (g_nMaxTry == 0) ErrorMessageBox("Write sector fail."); if (nTry < g_nMaxTry) { nTry ++; SaveVerifyLog(g_chLogDrive,dwStart+i*DATA_BUFFER_SECTOR,j,TRUE); goto TRY_WRITE_LAB2; } } else { if(bVerify) { ReadSector(dwStart+i*DATA_BUFFER_SECTOR,(WORD)j,pCompBuf,btDisk,&DriveParam); if(memcmp(pBuf,pCompBuf,(int)j*512)) { SaveVerifyLog(g_chLogDrive,dwStart+i*DATA_BUFFER_SECTOR,j,FALSE); } } } g_dDeletedSize += j; FlushProgressInfo(); } if(pCompBuf) free(pCompBuf); return TRUE; }
void DIR_Make (char *name,unsigned attr) { struct DIR_rec ds,_far *zgr; size_t laenge=sizeof(ds); struct find_t fileinfo; char buf[30],drive; int aktdr; DIR_ReleaseAll(); /* LAUFWERKE EINLESEN */ /* Wenn laufwerk anwaehlbar, dann existiert es */ aktdr=_getdrive(); for(drive=1;drive<27;drive++) if(!_chdrive(drive)) { sprintf(ds.name,"[ %c: ]",drive+'A'-1); ds.driveident=1; ds.dirident=0; zgr=_fmalloc(laenge); if (zgr!=NULL) { ds.vorher=DIR_top; DIR_top=zgr; _fmemmove(DIR_top,&ds,laenge); DIR_eintraege++; } } _chdrive(aktdr); /* SUBDIRS EINLESEN EINLESEN */ ds.driveident=0; ds.dirident=1; if (!_dos_findfirst("*.*",_A_SUBDIR,&fileinfo)) do { if(fileinfo.attrib & _A_SUBDIR) { while (strlen(fileinfo.name)<12) strcat(fileinfo.name," "); strcpy(ds.name,"<"); strcat(ds.name,fileinfo.name); strcat(ds.name,">"); zgr=_fmalloc(laenge); if (zgr!=NULL && strcmp(ds.name,"<. >")) { ds.vorher=DIR_top; DIR_top=zgr; _fmemmove(DIR_top,&ds,laenge); DIR_eintraege++; } } } while(!_dos_findnext(&fileinfo)); /* FILES EINLESEN */ ds.driveident=0; ds.dirident=0; if (!_dos_findfirst(name,attr,&fileinfo)) do { if(!(fileinfo.attrib & _A_SUBDIR)) { /* Eintrag */ while (strlen(fileinfo.name)<12) strcat(fileinfo.name," "); strcpy(ds.name," "); strcat(ds.name,fileinfo.name); strcat(ds.name," "); ds.laenge=fileinfo.size; sprintf(buf,"%2.2d/%02.2d/%02.2d",fileinfo.wr_date & 0x1f, (fileinfo.wr_date>>5) & 0x0f,(fileinfo.wr_date>>9)+80); strcpy(ds.datum,buf); zgr=_fmalloc(laenge); if (zgr!=NULL) { ds.vorher=DIR_top; DIR_top=zgr; _fmemmove(DIR_top,&ds,laenge); DIR_eintraege++; } } } while(!_dos_findnext(&fileinfo)); }
// For each library entry, creates a typeinfo in the typelib, // and fills it in. VOID NEAR OutputTypeInfos ( ICreateTypeLib FAR * lpdtlib ) { LPENTRY pEntry; TYPEKIND tkind; HRESULT res; ICreateTypeInfo FAR* lpdtinfo; WORD wTypeFlags; // First allocate an array of ELEMDESCs to hold the max # of // args of any function we need to describe. rgFuncArgs = (ELEMDESC FAR*)_fmalloc(cArgsMax * sizeof(ELEMDESC)); rgszFuncArgNames = (LPOLESTR FAR *)_fmalloc((cArgsMax+1) * sizeof(LPOLESTR)); if (rgFuncArgs == NULL || rgszFuncArgNames == NULL) ParseError(ERR_OM); // pass 1 -- create the typeinfo's pEntry = (LPENTRY)ListFirst(typlib.pEntry); // point to first entry for (;;) { // determine if we are going to create a typeinfo for this guy switch (pEntry->type.tentrykind) { case tTYPEDEF: if (pEntry->attr.fAttr) // create lpdtinfo only if break; // this is a 'PUBLIC' typedef NoTypeInfos: pEntry->lpdtinfo = NULL; // no lpdtinfo for this case tREF: // no typeinfo's made for these case tINTRINSIC: goto Next_Entry1; default: // no typeinfo's made for forward declarations if (pEntry->type.tentrykind & tFORWARD) goto NoTypeInfos; if (pEntry->type.tentrykind & tIMPORTED) goto Next_Entry1; // nothing for imported types break; } // 1. determine kind of typeinfo to create tkind = rgtkind[pEntry->type.tentrykind]; // 2. Create type library entry (TypeInfo) of a given name/and // type, getting a pointer to the ICreateTypeInfo interface SETITEMCUR(pEntry->type.szName); CHECKRESULT(lpdtlib->CreateTypeInfo(ToW(pEntry->type.szName), tkind, &lpdtinfo)); pEntry->lpdtinfo = lpdtinfo; // 3. Set the item's attributes: if (pEntry->attr.fAttr & fUUID) CHECKRESULT(lpdtinfo->SetGuid(*pEntry->attr.lpUuid)); if (pEntry->attr.fAttr & fHELPSTRING) CHECKRESULT(lpdtinfo->SetDocString(ToW(pEntry->attr.lpszHelpString))); if (pEntry->attr.fAttr & fHELPCONTEXT) CHECKRESULT(lpdtinfo->SetHelpContext(pEntry->attr.lHelpContext)); if (pEntry->attr.fAttr & fVERSION) CHECKRESULT(lpdtinfo->SetVersion(pEntry->attr.wVerMajor, pEntry->attr.wVerMinor)); // 4. save lptinfo for this guy in case somebody references it CHECKRESULT(lpdtinfo->QueryInterface(IID_ITypeInfo, (VOID FAR* FAR*)&pEntry->type.lptinfo)); // if this type has a forward declaration if (pEntry->lpEntryForward) { // copy "real" type info over top of forward declaration, // because folks have pointers to the forward declaration pEntry->lpEntryForward->type.tdesc = pEntry->type.tdesc; pEntry->lpEntryForward->type.lptinfo = pEntry->type.lptinfo; // Only need to copy these 2 fields from the type (the // others aren't referenced at type creation time. } Next_Entry1: // advance to next entry if not all done if (pEntry == (LPENTRY)ListLast(typlib.pEntry)) break; // exit if all done pEntry = (LPENTRY)pEntry->type.pNext; } // pass 2 -- process each entry pEntry = (LPENTRY)ListFirst(typlib.pEntry); // point to first entry for (;;) { // 1. Get our lpdtinfo again if we have one switch (pEntry->type.tentrykind) { case tREF: case tINTRINSIC: goto Next_Entry2; // these guys don't have lpdtinfo field default: if (pEntry->type.tentrykind & tIMPORTED) goto Next_Entry2; // no lpdtinfo field break; } lpdtinfo = pEntry->lpdtinfo; if (lpdtinfo == NULL) // skip if no lpdtinfo created goto Next_Entry2; // (forward decl or non-public typedef) // set up for error reporting SETITEMCUR(pEntry->type.szName); // 2. determine kind of typeinfo we're dealing with tkind = rgtkind[pEntry->type.tentrykind]; // 2a. Set the typeinfo flags wTypeFlags = 0; if (tkind == TKIND_COCLASS) { // COCLASSs always have FCANCREATE bit set wTypeFlags |= TYPEFLAG_FCANCREATE; // these are only valid on COCLASSs if (pEntry->attr.fAttr & fAPPOBJECT) wTypeFlags |= (WORD)TYPEFLAG_FAPPOBJECT; if (pEntry->attr.fAttr & fLICENSED) wTypeFlags |= (WORD)TYPEFLAG_FLICENSED; if (pEntry->attr.fAttr & fPREDECLID) wTypeFlags |= (WORD)TYPEFLAG_FPREDECLID; } if (pEntry->attr.fAttr & fHIDDEN) wTypeFlags |= (WORD)TYPEFLAG_FHIDDEN; if (pEntry->attr.fAttr2 & f2CONTROL) wTypeFlags |= (WORD)TYPEFLAG_FCONTROL; if (pEntry->attr.fAttr2 & f2NONEXTENSIBLE) wTypeFlags |= (WORD)TYPEFLAG_FNONEXTENSIBLE; if (pEntry->attr.fAttr2 & f2DUAL) // DUAL implies OLEAUTOMATION wTypeFlags |= (WORD)(TYPEFLAG_FDUAL | TYPEFLAG_FOLEAUTOMATION); if (pEntry->attr.fAttr2 & f2OLEAUTOMATION) wTypeFlags |= (WORD)TYPEFLAG_FOLEAUTOMATION; CHECKRESULT(lpdtinfo->SetTypeFlags(wTypeFlags)); // 3. now process each kind of entry switch (tkind) { case TKIND_ALIAS: OutputAlias(lpdtinfo, pEntry->type.td.ptypeAlias); break; case TKIND_RECORD: // struct's, enum's, and union's are case TKIND_ENUM: // all very similar case TKIND_UNION: OutputElems(lpdtinfo, pEntry->type.structenum.elemList, tkind); break; case TKIND_MODULE: OutputFuncs(lpdtinfo, pEntry, pEntry->module.funcList, tkind); OutputElems(lpdtinfo, pEntry->module.constList, tkind); break; case TKIND_INTERFACE: OutputInterface(lpdtinfo, pEntry); break; case TKIND_DISPATCH: OutputDispinter(lpdtinfo, pEntry); break; case TKIND_COCLASS: OutputClass(lpdtinfo, pEntry); break; #if FV_PROPSET case TKIND_PROPSET: // CONSIDER: (FV_PROPSET) do something with base_propset name OutputElems(lpdtinfo, pEntry->propset.propList, tkind); break; #endif //FV_PROPSET default: Assert(FALSE); }; // 3a. Set the alignment for this TypeInfo. Must be done before // Layout(). CHECKRESULT(lpdtinfo->SetAlignment(iAlignMax)); // 4. Compile this typeinfo we've just created. SETITEMCUR(pEntry->type.szName); CHECKRESULT(lpdtinfo->LayOut()); // 5. Cleanup. All done with lpdtinfo. lpdtinfo->Release(); Next_Entry2: // advance to next entry if not all done if (pEntry == (LPENTRY)ListLast(typlib.pEntry)) break; // exit if all done pEntry = (LPENTRY)pEntry->type.pNext; } // now clean up everything else _ffree(rgFuncArgs); // done with function args we allocated _ffree(rgszFuncArgNames); }
BOOL DoDeleteSectors(DWORD dwStart, DWORD dwSize ,BYTE btDisk) { BYTE *pBuf; int i; BOOL bVerify = FALSE; pBuf = NULL; pBuf = (BYTE *) _fmalloc(DATA_BUFFER_SIZE); if(!pBuf) { ErrorMessageBox(NO_MEMORY); return FALSE; } switch(g_nMethod) { case 0: g_dTotalSize = dwSize; InitDelBuf(pBuf,0,0,0,FALSE,TRUE); bVerify = TRUE; WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify); break; case 1: g_dTotalSize = dwSize; InitDelBuf(pBuf,0xFF,0,0,FALSE,TRUE); bVerify = TRUE; WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify); break; case 2: g_dTotalSize = dwSize; InitDelBuf(pBuf,0,0,0,TRUE,TRUE); bVerify = TRUE; WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify); break; case 3: g_dTotalSize = (double)dwSize*3; for(i=0; i<3; i++) { switch(i) { case 0: case 1: InitDelBuf(pBuf,0,0,0,TRUE,TRUE); break; case 2: bVerify = TRUE; InitDelBuf(pBuf,0,0,0,FALSE,TRUE); break; } if(!WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify)) break; } break; case 4: g_dTotalSize = (double)dwSize*4; for(i=0; i<4; i++) { switch(i) { case 0: case 2: InitDelBuf(pBuf,0,0,0,FALSE,TRUE); break; case 1: InitDelBuf(pBuf,0XFF,0,0,FALSE,TRUE); break; case 3: bVerify = TRUE; InitDelBuf(pBuf,0XFF,0,0,FALSE,TRUE); break; } if(!WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify)) break; } break; case 5: g_dTotalSize = (double)dwSize*3; for(i=0; i<3; i++) { switch(i) { case 0: InitDelBuf(pBuf,0,0,0,FALSE,TRUE); break; case 1: InitDelBuf(pBuf,0XFF,0,0,FALSE,TRUE); break; case 2: bVerify = TRUE; InitDelBuf(pBuf,0X35,0XCA,0X97,FALSE,FALSE); break; } if(!WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify)) break; } break; case 6: g_dTotalSize = (double)dwSize*7; for(i=0; i<7; i++) { switch(i) { case 0: case 2: case 4: InitDelBuf(pBuf,0,0,0,FALSE,TRUE); break; case 1: case 3: case 5: InitDelBuf(pBuf,0XFF,0,0,FALSE,TRUE); break; case 6: bVerify = TRUE; InitDelBuf(pBuf,0X35,0XCA,0X97,FALSE,FALSE); break; } if(!WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify)) break; } break; case 7: g_dTotalSize = (double)dwSize*35; for(i=0; i<35; i++) { switch(i) { case 0: case 1: case 2: case 3: case 31: case 32: case 33: InitDelBuf(pBuf,0,0,0,TRUE,TRUE); break; case 34: bVerify = TRUE; InitDelBuf(pBuf,0,0,0,TRUE,TRUE); break; case 4: InitDelBuf(pBuf,0X55,0,0,FALSE,TRUE); break; case 5: InitDelBuf(pBuf,0XAA,0,0,FALSE,TRUE); break; case 6: case 25: InitDelBuf(pBuf,0X92,0X49,0X24,FALSE,FALSE); break; case 7: case 26: InitDelBuf(pBuf,0X49,0X24,0X92,FALSE,FALSE); break; case 8: case 27: InitDelBuf(pBuf,0X24,0X92,0X49,FALSE,FALSE); break; case 9: InitDelBuf(pBuf,0,0,0,FALSE,TRUE); break; case 10: InitDelBuf(pBuf,0X11,0,0,FALSE,TRUE); break; case 11: InitDelBuf(pBuf,0X22,0,0,FALSE,TRUE); break; case 12: InitDelBuf(pBuf,0X33,0,0,FALSE,TRUE); break; case 13: InitDelBuf(pBuf,0X44,0,0,FALSE,TRUE); break; case 14: InitDelBuf(pBuf,0X55,0,0,FALSE,TRUE); break; case 15: InitDelBuf(pBuf,0X66,0,0,FALSE,TRUE); break; case 16: InitDelBuf(pBuf,0x77,0,0,FALSE,TRUE); break; case 17: InitDelBuf(pBuf,0X88,0,0,FALSE,TRUE); break; case 18: InitDelBuf(pBuf,0X99,0,0,FALSE,TRUE); break; case 19: InitDelBuf(pBuf,0XAA,0,0,FALSE,TRUE); break; case 20: InitDelBuf(pBuf,0XBB,0,0,FALSE,TRUE); break; case 21: InitDelBuf(pBuf,0XCC,0,0,FALSE,TRUE); break; case 22: InitDelBuf(pBuf,0XDD,0,0,FALSE,TRUE); break; case 23: InitDelBuf(pBuf,0XEE,0,0,FALSE,TRUE); break; case 24: InitDelBuf(pBuf,0XFF,0,0,FALSE,TRUE); break; case 28: InitDelBuf(pBuf,0X6D,0XB6,0XDB,FALSE,FALSE); break; case 29: InitDelBuf(pBuf,0XB6,0XDB,0X6D,FALSE,FALSE); break; case 30: InitDelBuf(pBuf,0XDB,0X6D,0XB6,FALSE,FALSE); break; } if(!WriteSecsWithBuf(dwStart,dwSize,btDisk,pBuf,bVerify)) break; } break; } _ffree(pBuf); return TRUE; }
VOID PMfrWriteClipbrdBmp(HAB hab) { HDC hdcClip; /* memory DC and PS to extract from the clipboard */ HPS hpsClip; HBITMAP hbmClip; SIZEL sizl; BITMAPINFOHEADER bmp; ULONG _far *alRGBColors; LONG errorcode; char _far *fp1; char _far *fp2; int i; if (WinOpenClipbrd(hab)) { /* get the memory DC and PS to copy the bitmap */ hdcClip = DevOpenDC (hab, OD_MEMORY, "*", 0L, NULL, NULL) ; sizl.cx = cp.cx; sizl.cy = cp.cy; hpsClip = GpiCreatePS (hab, hdcClip, &sizl, PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC); bmp.cbFix = sizeof bmp; bmp.cx = cp.cx; bmp.cy = cp.cy; bmp.cPlanes = cp.cPlanes; bmp.cBitCount = cp.cBitCount; hbmClip = GpiCreateBitmap (hpsClip, &bmp, 0L, NULL, NULL); GpiSetBitmap(hpsClip, hbmClip); /* initialize and black out the bitmap */ alRGBColors = (ULONG _far *) _fmalloc(sizeof(ULONG) * cp.colors); /* beginning of source array */ fp2 = (char _far *) &cp.pbmiMemory->argbColor[0]; /* beginning of dest array */ fp1 = (char _far *) &alRGBColors[0]; for (i = 0; i < cp.colors; i++) { /* copy base bytes for number of screen colors */ alRGBColors[i] = 0; _fmemcpy(fp1, fp2, sizeof(RGB) ); fp1 += sizeof(ULONG); fp2 += sizeof(RGB); } GpiSetMix ( hpsClip, FM_OVERPAINT) ; GpiSetBackMix (hpsClip, BM_LEAVEALONE) ; GpiCreateLogColorTable(hpsClip, LCOL_RESET | LCOL_REALIZABLE, LCOLF_CONSECRGB, 0L, cp.colors, alRGBColors); /* now copy the bits */ cp.pbmiMemory->cx = cp.cx; cp.pbmiMemory->cy = cp.cy; cp.pbmiMemory->cPlanes = cp.cPlanes; cp.pbmiMemory->cBitCount = cp.cBitCount; errorcode = GpiSetBitmapBits(hpsClip, 0L, (LONG) cp.cy, cp.pixels, cp.pbmiMemory); /* unlink the new bitmap */ GpiSetBitmap(hpsClip, (HBITMAP) NULL); /* write to the clipboard */ WinEmptyClipbrd (hab); WinSetClipbrdData (hab, (ULONG) hbmClip, CF_BITMAP, CFI_HANDLE); /* now clean up */ _ffree(alRGBColors); GpiDestroyPS(hpsClip); DevCloseDC(hdcClip); WinCloseClipbrd(hab); } }
int GptWriteHeader(HGPT hGPT) { int i; int iErr; char far *lpArray = (char far *)NULL; char far *lpc; int iEntryArraySize; int nSect; QWORD qwLBA; #ifdef _DEBUG if (iDebug) printf("GptWriteHeader(hBlockDev=%p)\n", hGPT->hBlockDev); #endif // Compute the entire entry array CRC, and update the header. iEntryArraySize = (int)(hGPT->pGptHdr->NumberOfPartitionEntries) * sizeof(EFI_PARTITION_ENTRY); nSect = (iEntryArraySize + hGPT->iSectorSize - 1) / hGPT->iSectorSize; lpArray = (char far *)_fmalloc(nSect * hGPT->iSectorSize); if (!lpArray) GptWriteHeaderFail(1); for (lpc=lpArray, i=0, qwLBA=hGPT->pGptHdr->PartitionEntryLBA; i<nSect; i++, lpc+=hGPT->iSectorSize, qwLBA++) { iErr = GptBlockRead(hGPT, qwLBA, 1, lpc); if (iErr) GptWriteHeaderFail(2); } hGPT->pGptHdr->PartitionEntryArrayCRC32 = crc32(lpArray, iEntryArraySize); // Write the backup GPT header // Exchange the main and alternate LBA addresses. qwLBA = hGPT->pGptHdr->AlternateLBA; hGPT->pGptHdr->AlternateLBA = hGPT->pGptHdr->MyLBA; hGPT->pGptHdr->MyLBA = qwLBA; // Update the header CRC SetCrc(&(hGPT->pGptHdr->Header)); // Write the backup GPT header iErr = GptBlockWrite(hGPT, hGPT->pGptHdr->MyLBA, 1, hGPT->pGptHdr); if (iErr) { #ifdef _DEBUG if (iVerbose) printf("Error %d writing the GPT backup header.\n", iErr); #endif GptWriteHeaderFail(3); } // Write the main GPT header // Exchange the main and alternate LBA addresses. qwLBA = hGPT->pGptHdr->AlternateLBA; hGPT->pGptHdr->AlternateLBA = hGPT->pGptHdr->MyLBA; hGPT->pGptHdr->MyLBA = qwLBA; // Update the header CRC SetCrc(&(hGPT->pGptHdr->Header)); #ifdef _DEBUG if (iVerbose) DumpBuf(hGPT->pGptHdr, 0, (WORD)hGPT->pGptHdr->Header.HeaderSize); #endif // Write the main GPT header iErr = GptBlockWrite(hGPT, hGPT->pGptHdr->MyLBA, 1, hGPT->pGptHdr); if (iErr) { #ifdef _DEBUG if (iVerbose) printf("Error %d writing the GPT header.\n", iErr); #endif GptWriteHeaderFail(4); } header_return: _ffree(lpArray); return iErr; }
void FAR_PTR *my_alloc( int size ) { return( _fmalloc( size ) ); }