btuduri / steem-engine

Automatically exported from code.google.com/p/steem-engine
0 stars 0 forks source link

Improving floppy image creation in Steem #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I observed long time ago that floppy images created by Steem disk manager 
missing correct second FAT init. It is likely harmless bug, as TOS is tolerant 
on. Still, I like to see it done properly, especially as those images may be 
used with DOS, Windows, which are not so tolerant.
The fixing, in diskman.cpp :

bool TDiskManager::CreateDiskImage(char *STName,int Sectors,int 
SecsPerTrack,int Sides)
{
  FILE *f=fopen(STName,"wb");
  if (f){
    char zeros[512];
    ZeroMemory(zeros,sizeof(zeros));
    for (int n=0;n<Sectors;n++) fwrite(zeros,1,512,f);
//LITTLE-ENDIAN ONLY             
******************************************************
    int buf;
    fseek(f,0,SEEK_SET);
    fputc(0xeb,f);fputc(0x30,f);
    fseek(f,8,SEEK_SET); // Skip loader
    fputc(BYTE(rand()),f);fputc(BYTE(rand()),f);fputc(BYTE(rand()),f); //Serial number
    buf=512;                          fwrite(&buf,2,1,f); //Bytes Per Sector
    buf=2;                            fwrite(&buf,1,1,f); //Sectors Per Cluster
    buf=1;                            fwrite(&buf,2,1,f); //RES
    buf=2;                            fwrite(&buf,1,1,f); //FATs
    buf=112;                          fwrite(&buf,2,1,f); //Dir Entries
    buf=Sectors;                      fwrite(&buf,2,1,f);
    buf=249;                          fwrite(&buf,1,1,f); //Unused - MSDOS signo in fact

// 3 sectors per FAT is enough up to 1MB disk capacity
// 5 sectors per FAT up to 1700 KB - so HD, 20 sectors per track too

     if (Sectors<2000)     buf=3;                           
     else      buf=5;   
    fwrite(&buf,2,1,f);    //Sectors Per FAT

    buf=SecsPerTrack;                 fwrite(&buf,2,1,f);
    buf=Sides;                        fwrite(&buf,2,1,f);
    buf=0;                            fwrite(&buf,2,1,f); //Hidden Sectors

    fseek(f,510,SEEK_SET);
    fputc(0x97,f);fputc(0xc7,f);  // dummy ?
    fputc(0xf0,f);fputc(0xff,f);fputc(0xff,f);  // First FAT begin

// Second FAT too ! :

   if (Sectors<2000)    fseek(f,2048,SEEK_SET);
   else  fseek(f,3072,SEEK_SET);
   fputc(0xf0,f);fputc(0xff,f);fputc(0xff,f);  // Second FAT begin

    fclose(f);

    DeleteFile(Str(STName)+".steembpb");

    return true;
  }
  return 0;
}

Original issue reported on code.google.com by pet...@8bitchip.info on 21 Dec 2011 at 9:48

Attachments: