Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

static byte_t** CpmTransTable ( struct Image image,
unsigned *  au,
unsigned *  sectors 
) [static]

Generate a CP/M translation table.

Parameters:
image the disk image
au (output) the size of the allocation unit
sectors (output) number of useable sectors
Returns:
the translation table, or NULL on error

Definition at line 1722 of file image.c.

References Image::buf, getGeometry(), trackbuf, and Image::type.

Referenced by ReadCpmImage(), and WriteCpmImage().

{
  byte_t** table = 0;
  byte_t* trackbuf;
  const struct DiskGeometry* geom;

  unsigned track = 1, sector = 10, sectorcount = 2;
  unsigned block;

  if (!image || !au || !image->buf ||
      !(geom = getGeometry (image->type)))
    return 0;

  /* Set the allocation unit size and the number of sectors. */

  switch (geom->blocks) {
  case 683: /* 1541 */
    *au = 8;
    if ((table = calloc (*sectors = 680, sizeof (*table))))
      for (block = 0, trackbuf = image->buf; block < *sectors; block++) {
      table[block] = &trackbuf[sector << 8];
      sector = (sector + 5) % geom->sectors[track];

      if (++sectorcount == geom->sectors[track]) {
        trackbuf += geom->sectors[track++] << 8;

        if (track == geom->dirtrack) {
          sectorcount = 1;
          sector = 5;
        } else {
          sectorcount = 0;
          sector = 0;
        }
      }
      }

    break;
  case 1366: /* 1571 */
    *au = 8;
    if ((table = calloc (*sectors = 1360, sizeof (*table))))
      for (block = 0, trackbuf = image->buf; block < *sectors; block++) {
      table[block] = &trackbuf[sector << 8];
      sector = (sector + 5) % geom->sectors[track];

      if (++sectorcount == geom->sectors[track]) {
        trackbuf += geom->sectors[track++] << 8;

        if (track == 36) {
          sectorcount = 2;
          sector = 10;
        } else if (track % 36 == geom->dirtrack) {
          sectorcount = 1;
          sector = 5;
        } else {
          sectorcount = 0;
          sector = 0;
        }
      }
      }

    break;
  case 3200: /* 1581 */
    *au = 16;
    sector = sectorcount = 0;
    if ((table = calloc (*sectors = 3180, sizeof (*table))))
      for(block = 0, trackbuf = image->buf; block < *sectors; block++) {
      table[block] = &trackbuf[sector << 8];
      sector = (sector + 1) % geom->sectors[track];

      if (++sectorcount == geom->sectors[track]) {
        trackbuf += geom->sectors[track++] << 8;
        sectorcount = sector = (track == geom->dirtrack) ? 20 : 0;
      }
      }
    break;
  }

  return table;
}


Generated by  Doxygen 1.6.0   Back to index