InstallBootBlock(HWND win, struct Volume *vol, BOOL bNewAdf) { FILE* boot; unsigned char bootcode[1024], szBootPath[MAX_PATH]; char *szWarning = "ADFLib is unable to detect whether or not existing boot code is valid. " "You should display the bootblock to get some idea of whether or not it" "contains reasonable looking code and test bootblock installation on a " "copy of the ADF unless you are sure you want to continue. Overwriting " "many non-standard or proprietry bootblocks will invalidate the ADF." "\n\nDo you still want to install the new bootblock?"; char *szBBMissing = "ADF Opus can't open the bootblock file. Please make sure that the " "bootblock (\"stdboot3.bbk\") is located in a sub-directory called \"Boot\" " "in the directory where ADF Opus is installed. This should automatically be " "the case if you use any of the automated installation methods."; if(bNewAdf || MessageBox(win, szWarning, "ADF Opus Warning!", MB_YESNO|MB_ICONWARNING) == IDYES){ strcpy(szBootPath, dirOpus); strcat(szBootPath, "\\Boot\\stdboot3.bbk"); boot = fopen(szBootPath, "rb"); if (!boot) { MessageBox(win, szBBMissing, "ADF Opus error", MB_OK|MB_ICONERROR); return(1); } fread(bootcode, sizeof(unsigned char), 1024, boot); fclose(boot); if(adfInstallBootBlock(vol, bootcode) != RC_OK) return 1; } return 0; }
int main(int argc, char *argv[]) { struct Device *hd; struct Volume *vol; FILE* boot; unsigned char bootcode[1024]; boot=fopen(argv[1],"rb"); if (!boot) { fprintf(stderr, "can't mount volume\n"); exit(1); } fread(bootcode, sizeof(unsigned char), 1024, boot); fclose(boot); adfEnvInitDefault(); /* create and mount one device */ hd = adfCreateDumpDevice("newdev", 80, 2, 11); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } adfDeviceInfo(hd); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount(hd, 0, FALSE); if (!vol) { adfUnMountDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfInstallBootBlock(vol, bootcode); adfVolumeInfo(vol); adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); return 0; }
int main(int argc, char *argv[]) { struct Device *hd; struct Volume *vol; FILE* boot; unsigned char bootcode[1024]; boot=fopen(argv[1],"rb"); if (!boot) { fprintf(stderr, "can't mount volume\n"); exit(1); } fread(bootcode, sizeof(unsigned char), 1024, boot); fclose(boot); adfEnvInitDefault(); hd = adfMountDev(argv[2],FALSE); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } vol = adfMount(hd, 0, FALSE); if (!vol) { adfUnMountDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfInstallBootBlock(vol, bootcode); adfVolumeInfo(vol); adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); return 0; }
int AMIGADOSFSDK_libLoad_DiskFile(HXCFLOPPYEMULATOR* floppycontext,FLOPPY * floppydisk,char * imgfile,void * parameters) { unsigned int i,j; unsigned int file_offset; struct Device * adfdevice; struct Volume * adfvolume; unsigned char * flatimg; unsigned char * flatimg2; unsigned char * repname; int flatimgsize; int numberoftrack; int numberofsectorpertrack; unsigned short sectorsize; unsigned char gap3len,skew,trackformat,interleave; struct stat repstate; struct tm * ts; struct DateTime reptime; // FILE * debugadf; int rc; CYLINDER* currentcylinder; numberoftrack=80; numberofsectorpertrack=11; floppycontext->hxc_printf(MSG_DEBUG,"AMIGADOSFSDK_libLoad_DiskFile %s",imgfile); stat(imgfile,&repstate); ts=localtime(&repstate.st_ctime); if(repstate.st_mode&S_IFDIR) { global_floppycontext=floppycontext; adfEnvInitDefault(); adfChgEnvProp(PR_EFCT,adlib_printerror); adfChgEnvProp(PR_WFCT,adlib_printwarning); adfChgEnvProp(PR_VFCT,adlib_printdebug); floppycontext->hxc_printf(MSG_DEBUG,"ADFLib %s %s",adfGetVersionNumber(), adfGetVersionDate()); adfdevice = adfCreateMemoryDumpDevice(numberoftrack, 2, numberofsectorpertrack,&flatimg,&flatimgsize); if(adfdevice) { repname=(unsigned char *)malloc(strlen(imgfile)+1); memset(repname,0,strlen(imgfile)+1); i=strlen(imgfile); if( (imgfile[i]=='\\' || imgfile[i]=='/') && i) { imgfile[i]=0; i--; } while(i && (imgfile[i]!='\\' && imgfile[i]!='/')) { i--; } if((imgfile[i]=='\\' || imgfile[i]=='/')) { i++; } sprintf(repname,"%s",&imgfile[i]); if(ts) { reptime.year=ts->tm_year; /* since 1900 */ reptime.mon=ts->tm_mon+1; reptime.day=ts->tm_mday; reptime.hour=ts->tm_hour; reptime.min=ts->tm_min; reptime.sec=ts->tm_sec; } else { reptime.year=0; reptime.mon=0; reptime.day=0; reptime.hour=0; reptime.min=0; reptime.sec=0; } rc=adfCreateFlop(adfdevice, repname, 0,&reptime ); free(repname); if (rc==RC_OK) { adfvolume = adfMount(adfdevice, 0, 0); if(adfvolume) { floppycontext->hxc_printf(MSG_DEBUG,"adfCreateFlop ok"); if(adfInstallBootBlock(adfvolume, stdboot3)!=RC_OK) { floppycontext->hxc_printf(MSG_ERROR,"adflib: adfInstallBootBlock error!"); } if(ScanFile(floppycontext,adfvolume,imgfile,"*.*")) { floppycontext->hxc_printf(MSG_DEBUG,"ScanFile error!"); return LOADER_INTERNALERROR; } flatimg2=(unsigned char*)malloc(flatimgsize); memcpy(flatimg2,flatimg,flatimgsize); adfUnMountDev(adfdevice); /*//////// debugadf=fopen("d:\\debug.adf","wb"); if(debugadf) { fwrite(flatimg2,flatimgsize,1,debugadf); fclose(debugadf); } //////////*/ } else { floppycontext->hxc_printf(MSG_ERROR,"adflib: adfMount error!"); return LOADER_INTERNALERROR; } } else { floppycontext->hxc_printf(MSG_ERROR,"adflib: Error while creating the virtual floppy!"); return LOADER_INTERNALERROR; } } else { floppycontext->hxc_printf(MSG_ERROR,"adflib: adfCreateMemoryDumpDevice error!"); return LOADER_INTERNALERROR; } if(flatimg2) { sectorsize=512; interleave=1; gap3len=0; skew=0; trackformat=AMIGAFORMAT_DD; floppydisk->floppySectorPerTrack=numberofsectorpertrack; floppydisk->floppyNumberOfSide=2; floppydisk->floppyNumberOfTrack=numberoftrack; floppydisk->floppyBitRate=DEFAULT_AMIGA_BITRATE; floppydisk->floppyiftype=AMIGA_DD_FLOPPYMODE; floppydisk->tracks=(CYLINDER**)malloc(sizeof(CYLINDER*)*floppydisk->floppyNumberOfTrack); for(j=0;j<floppydisk->floppyNumberOfTrack;j++) { floppydisk->tracks[j]=allocCylinderEntry(DEFAULT_AMIGA_RPM,floppydisk->floppyNumberOfSide); currentcylinder=floppydisk->tracks[j]; for(i=0;i<floppydisk->floppyNumberOfSide;i++) { file_offset=(sectorsize*(j*floppydisk->floppySectorPerTrack*floppydisk->floppyNumberOfSide))+ (sectorsize*(floppydisk->floppySectorPerTrack)*i); currentcylinder->sides[i]=tg_generatetrack(&flatimg2[file_offset],sectorsize,floppydisk->floppySectorPerTrack,(unsigned char)j,(unsigned char)i,0,interleave,(unsigned char)(((j<<1)|(i&1))*skew),floppydisk->floppyBitRate,currentcylinder->floppyRPM,trackformat,gap3len,2500,-11150); } } free(flatimg2); floppycontext->hxc_printf(MSG_INFO_1,"AMIGADOSFSDK Loader : tracks file successfully loaded and encoded!"); return LOADER_NOERROR; } floppycontext->hxc_printf(MSG_ERROR,"flatimg==0 !?"); return LOADER_INTERNALERROR; } else { floppycontext->hxc_printf(MSG_ERROR,"not a directory !"); return LOADER_BADFILE; } }