/[projet1]/public/pc/tools/osdk/main/makedisk/Floppy.cpp
Defence Force logotype

Diff of /public/pc/tools/osdk/main/makedisk/Floppy.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1013 by dbug, Thu Dec 12 19:35:12 2013 UTC revision 1014 by dbug, Thu Dec 12 20:50:14 2013 UTC
# Line 94  FileEntry::~FileEntry() Line 94  FileEntry::~FileEntry()
94  Floppy::Floppy() :  Floppy::Floppy() :
95    m_Buffer(0),    m_Buffer(0),
96    m_BufferSize(0),    m_BufferSize(0),
   m_Offset(0),  
97    m_TrackNumber(0),    m_TrackNumber(0),
98    m_SectorNumber(0)    m_SectorNumber(0),
99      m_CurrentTrack(0),
100      m_CurrentSector(1)
101  {  {
   fileCount=0;  
102  }  }
103    
104    
# Line 110  Floppy::~Floppy() Line 110  Floppy::~Floppy()
110    
111  bool Floppy::LoadDisk(const char* fileName)  bool Floppy::LoadDisk(const char* fileName)
112  {  {
   m_Offset=0;  
113    if (LoadFile(fileName,m_Buffer,m_BufferSize))    if (LoadFile(fileName,m_Buffer,m_BufferSize))
114    {    {
115      const FloppyHeader& header(*((FloppyHeader*)m_Buffer));      const FloppyHeader& header(*((FloppyHeader*)m_Buffer));
# Line 159  remplacée par un octet #F7. Comme on le Line 158  remplacée par un octet #F7. Comme on le
158  15, 16 or 17 sectors: gap1=72; gap2=34; gap3=50;  15, 16 or 17 sectors: gap1=72; gap2=34; gap3=50;
159            18 sectors: gap1=12; gap2=34; gap3=46;            18 sectors: gap1=12; gap2=34; gap3=46;
160  */  */
161  unsigned int Floppy::ComputeOffset(int track,int sector)  unsigned int Floppy::GetDskImageOffset()
162  {  {
163    unsigned int offset=256+156;     // on ajoute le header    unsigned int offset=256+156;     // Add the header
164    offset+=track*6400;     // On avance à la bonne piste    offset+=m_CurrentTrack*6400;     // And move to the correct track
165    offset+=(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(sector-1);    offset+=(taille_secteur+nb_oct_after_sector+nb_oct_before_sector)*(m_CurrentSector-1);
166    return offset;    return offset;
167  }  }
168    
169    
170  // 0x0319 -> 793  // 0x0319 -> 793
171  void Floppy::WriteSector(int track,int sector,const char *fileName)  void Floppy::WriteSector(const char *fileName)
172  {  {
173    std::string filteredFileName(StringTrim(fileName," \t\f\v\n\r"));    std::string filteredFileName(StringTrim(fileName," \t\f\v\n\r"));
174    
# Line 183  void Floppy::WriteSector(int track,int s Line 182  void Floppy::WriteSector(int track,int s
182        ShowError("File for sector is too large. %d bytes (%d too many)",bufferSize,bufferSize-256);        ShowError("File for sector is too large. %d bytes (%d too many)",bufferSize,bufferSize-256);
183      }      }
184    
185      unsigned int bootSectorOffset=ComputeOffset(track,sector);      unsigned int sectorOffset=GetDskImageOffset();
186      if (m_BufferSize>bootSectorOffset+256)      if (m_BufferSize>sectorOffset+256)
187      {      {
188        memcpy((char*)m_Buffer+bootSectorOffset,buffer,bufferSize);        memcpy((char*)m_Buffer+sectorOffset,buffer,bufferSize);
189      }      }
190      printf("Boot sector '%s' installed, %d free bytes remaining in this sector.\n",filteredFileName.c_str(),256-bufferSize);      printf("Boot sector '%s' installed, %d free bytes remaining in this sector.\n",filteredFileName.c_str(),256-bufferSize);
191    
192        MoveToNextSector();
193    }    }
194    else    else
195    {    {
# Line 196  void Floppy::WriteSector(int track,int s Line 197  void Floppy::WriteSector(int track,int s
197    }    }
198  }  }
199    
200  int Floppy::WriteFile(const char *fileName,int& currentTrack,int& currentSector,int loadAddress)  int Floppy::WriteFile(const char *fileName,int loadAddress)
201  {  {
202    FileEntry fileEntry;    FileEntry fileEntry;
203    fileEntry.m_FloppyNumber=0;     // 0 for a single floppy program    fileEntry.m_FloppyNumber=0;     // 0 for a single floppy program
204    
205    if (fileCount)    if (!m_FileEntries.empty())
206    {    {
207      code_adress_low  << ",";      code_adress_low  << ",";
208      code_adress_high << ",";      code_adress_high << ",";
# Line 213  int Floppy::WriteFile(const char *fileNa Line 214  int Floppy::WriteFile(const char *fileNa
214    code_adress_low  << "<" << loadAddress;    code_adress_low  << "<" << loadAddress;
215    code_adress_high << ">" << loadAddress;    code_adress_high << ">" << loadAddress;
216    
217    if (currentTrack>41) // face 2    if (m_CurrentTrack>41) // face 2
218    {    {
219      fileEntry.m_StartSide=1;      fileEntry.m_StartSide=1;
220      code_track << currentTrack-42+128;      code_track << m_CurrentTrack-42+128;
221    }    }
222    else    else
223    {    {
224      fileEntry.m_StartSide=0;      fileEntry.m_StartSide=0;
225      code_track << currentTrack;      code_track << m_CurrentTrack;
226    }    }
227    code_sector << currentSector;    code_sector << m_CurrentSector;
228    
229    void*      fileBuffer;    void*      fileBuffer;
230    size_t     fileSize;    size_t     fileSize;
# Line 234  int Floppy::WriteFile(const char *fileNa Line 235  int Floppy::WriteFile(const char *fileNa
235    
236    int nb_sectors_by_files=(fileSize+255)/256;    int nb_sectors_by_files=(fileSize+255)/256;
237    
238    fileEntry.m_StartTrack =currentTrack;           // 0 to 42 (80...)    fileEntry.m_StartTrack =m_CurrentTrack;           // 0 to 42 (80...)
239    fileEntry.m_StartSector=currentSector;          // 1 to 17 (or 16 or 18...)    fileEntry.m_StartSector=m_CurrentSector;          // 1 to 17 (or 16 or 18...)
240    fileEntry.m_SectorCount=nb_sectors_by_files;    // Should probably be the real length    fileEntry.m_SectorCount=nb_sectors_by_files;      // Should probably be the real length
241    fileEntry.m_LoadAddress=loadAddress;    fileEntry.m_LoadAddress=loadAddress;
242    fileEntry.m_TotalSize=fileSize;    fileEntry.m_TotalSize=fileSize;
243    fileEntry.m_FilePath   =fileName;    fileEntry.m_FilePath   =fileName;
# Line 244  int Floppy::WriteFile(const char *fileNa Line 245  int Floppy::WriteFile(const char *fileNa
245    unsigned char* fileData=(unsigned char*)fileBuffer;    unsigned char* fileData=(unsigned char*)fileBuffer;
246    while (fileSize)    while (fileSize)
247    {    {
248      SetOffset(currentTrack,currentSector);      unsigned int offset=SetPosition(m_CurrentTrack,m_CurrentSector);
249    
250      int sizeToWrite=256;      int sizeToWrite=256;
251      if (fileSize<256)      if (fileSize<256)
# Line 253  int Floppy::WriteFile(const char *fileNa Line 254  int Floppy::WriteFile(const char *fileNa
254      }      }
255      fileSize-=sizeToWrite;      fileSize-=sizeToWrite;
256    
257      memset((char*)m_Buffer+m_Offset,0,256);      memset((char*)m_Buffer+offset,0,256);
258      memcpy((char*)m_Buffer+m_Offset,fileData,sizeToWrite);      memcpy((char*)m_Buffer+offset,fileData,sizeToWrite);
259      fileData+=sizeToWrite;      fileData+=sizeToWrite;
260    
261      currentSector++;      MoveToNextSector();
   
     if (currentSector==taille_piste+1) // We reached the end of the track!  
     {  
       currentSector=1;  
       currentTrack++;  
       if (currentTrack==m_TrackNumber)  
       {  
         // Next side is following on the floppy in the DSK format, so technically we should have nothing to do  
         // All the hard work is in the loader  
       }  
     }  
262    }    }
263    free(fileBuffer);    free(fileBuffer);
264    
265    code_nombre_secteur << nb_sectors_by_files;    code_nombre_secteur << nb_sectors_by_files;
266    
   ++fileCount;  
   
267    m_FileEntries.push_back(fileEntry);    m_FileEntries.push_back(fileEntry);
268    
269    return nb_sectors_by_files;    return nb_sectors_by_files;

Legend:
Removed from v.1013  
changed lines
  Added in v.1014

  ViewVC Help
Powered by ViewVC 1.1.26