Previous 199869 Revisions Next

r26101 Monday 11th November, 2013 at 07:23:54 UTC by Jürgen Buchmüller
Use inline functions for RDBIT and WRBIT and clean up.
[/branches/alto2/src/emu/cpu/alto2]a2drive.c

branches/alto2/src/emu/cpu/alto2/a2drive.c
r26100r26101
2020#define   GUARD_ZONE_BITS   (16*32)
2121
2222/** @brief write a bit into an array of UINT32 */
23#define   WRBIT(bits,dst,bit) do { \
24   if (bit) { \
25      bits[(dst)/32] |= 1 << ((dst) % 32); \
26   } else { \
27      bits[(dst)/32] &= ~(1 << ((dst) % 32)); \
28   } \
29} while (0)
23static inline size_t WRBIT(UINT32* bits, size_t dst, int bit)
24{
25   if (bit) {
26      bits[(dst)/32] |= 1 << ((dst) % 32);
27   } else {
28      bits[(dst)/32] &= ~(1 << ((dst) % 32));
29   }
30   return ++dst;
31}
3032
3133/** @brief read a bit from an array of UINT32 */
32#define   RDBIT(bits,src) ((bits[(src)/32] >> ((src) % 32)) & 1)
34static inline size_t RDBIT(UINT32* bits, size_t src, int& bit)
35{
36   bit = (bits[src/32] >> (src % 32)) & 1;
37   return ++src;
38}
3339
3440/**
3541 * @brief calculate the sector from the logical block address
r26100r26101
7076 */
7177static int cksum(UINT8 *src, size_t size, int start)
7278{
73   size_t offs;
7479   int sum = start;
75   int word;
76
7780   /* compute XOR of all words */
78   for (offs = 0; offs < size; offs += 2) {
79      word = src[size - 2 - offs] + 256 * src[size - 2 - offs + 1];
81   for (size_t offs = 0; offs < size; offs += 2) {
82      int word = src[size - 2 - offs] + 256 * src[size - 2 - offs + 1];
8083      sum ^= word;
8184   }
8285   return sum;
r26100r26101
9295 */
9396static size_t expand_zeroes(UINT32 *bits, size_t dst, size_t size)
9497{
95   size_t offs;
96
97   for (offs = 0; offs < 32 * size; offs += 2) {
98      WRBIT(bits, dst, 1);      // write the clock bit
99      dst++;
100      WRBIT(bits, dst, 0);      // write the 0 data bit
101      dst++;
98   for (size_t offs = 0; offs < 32 * size; offs += 2) {
99      dst = WRBIT(bits, dst, 1);      // write the clock bit
100      dst = WRBIT(bits, dst, 0);      // write the 0 data bit
102101   }
103
104102   return dst;
105103}
106104
r26100r26101
114112 */
115113static size_t expand_sync(UINT32 *bits, size_t dst, size_t size)
116114{
117   size_t offs;
118
119   for (offs = 0; offs < 32 * size - 2; offs += 2) {
120      WRBIT(bits, dst, 1);      // write the clock bit
121      dst++;
122      WRBIT(bits, dst, 0);      // write the 0 data bit
123      dst++;
115   for (size_t offs = 0; offs < 32 * size - 2; offs += 2) {
116      dst = WRBIT(bits, dst, 1);      // write the clock bit
117      dst = WRBIT(bits, dst, 0);      // write the 0 data bit
124118   }
125   WRBIT(bits, dst, 1);   // write the final clock bit
126   dst++;
127   WRBIT(bits, dst, 1);   // write the 1 data bit
128   dst++;
119   dst = WRBIT(bits, dst, 1);   // write the final clock bit
120   dst = WRBIT(bits, dst, 1);   // write the 1 data bit
129121   return dst;
130122}
131123
r26100r26101
140132 */
141133static size_t expand_record(UINT32 *bits, size_t dst, UINT8 *field, size_t size)
142134{
143   size_t offs, bit;
144
145   for (offs = 0; offs < size; offs += 2) {
135   for (size_t offs = 0; offs < size; offs += 2) {
146136      int word = field[size - 2 - offs] + 256 * field[size - 2 - offs + 1];
147      for (bit = 0; bit < 16; bit++) {
148         WRBIT(bits, dst, 1);            // write the clock bit
149         dst++;
150         WRBIT(bits, dst, (word >> 15) & 1);   // write the data bit
151         dst++;
137      for (size_t bit = 0; bit < 16; bit++) {
138         dst = WRBIT(bits, dst, 1);               // write the clock bit
139         dst = WRBIT(bits, dst, (word >> 15) & 1);   // write the data bit
152140         word <<= 1;
153141      }
154142   }
r26100r26101
166154 */
167155static size_t expand_cksum(UINT32 *bits, size_t dst, UINT8 *field, size_t size)
168156{
169   size_t bit;
170157   int word = cksum(field, size, 0521);
171
172   for (bit = 0; bit < 32; bit += 2) {
173      /* write the clock bit */
174      WRBIT(bits, dst, 1);
175      dst++;
176      /* write the data bit */
177      WRBIT(bits, dst, (word >> 15) & 1);
178      dst++;
158   for (size_t bit = 0; bit < 32; bit += 2) {
159      dst = WRBIT(bits, dst, 1);            // write the clock bit
160      dst = WRBIT(bits, dst, (word >> 15) & 1);   // write the data bit
179161      word <<= 1;
180162   }
181163   return dst;
r26100r26101
320302 */
321303size_t alto2_cpu_device::squeeze_sync(UINT32 *bits, size_t src, size_t size)
322304{
323   size_t offs, bitcount;
324305   UINT32 accu = 0;
325
326306   /* hunt for the first 0x0001 word */
327   for (bitcount = 0, offs = 0; offs < size; /* */) {
307   for (size_t bitcount = 0, offs = 0; offs < size; /* */) {
328308      /*
329309       * accumulate clock and data bits until we are
330310       * on the clock bit boundary
331311       */
332      accu = (accu << 1) | RDBIT(bits,src);
333      src++;
312      int bit;
313      src = RDBIT(bits,src,bit);
314      accu = (accu << 1) | bit;
334315      /*
335316       * look for 15 alternating clocks and 0-bits
336317       * and the 16th clock with a 1-bit
r26100r26101
348329}
349330
350331/**
351 * @brief find a 0 bit sequence in an array of clock and data bits
332 * @brief find a 16 x 0 bits sequence in an array of clock and data bits
352333 *
353334 * @param bits pointer to the sector's bits
354335 * @param src source offset into bits (bit number)
r26100r26101
357338 */
358339size_t alto2_cpu_device::squeeze_unsync(UINT32 *bits, size_t src, size_t size)
359340{
360   size_t offs, bitcount;
361341   UINT32 accu = 0;
362
363   /* hunt for the first 0x0000 word */
364   for (bitcount = 0, offs = 0; offs < size; /* */) {
342   /* hunt for the first 0 word (16 x 0 bits) */
343   for (size_t bitcount = 0, offs = 0; offs < size; /* */) {
365344      /*
366345       * accumulate clock and data bits until we are
367346       * on the clock bit boundary
368347       */
369      accu = (accu << 1) | RDBIT(bits,src);
370      src++;
348      int bit;
349      src = RDBIT(bits,src,bit);
350      accu = (accu << 1) | bit;
371351      /*
372       * look for 15 alternating clocks and 0-bits
373       * and the 16th clock with a 1-bit
352       * look for 16 alternating clocks and 0 data bits
374353       */
375354      if (accu == 0xaaaaaaaa)
376355         return src;
r26100r26101
395374 */
396375size_t alto2_cpu_device::squeeze_record(UINT32 *bits, size_t src, UINT8 *field, size_t size)
397376{
398   size_t offs, bitcount;
399377   UINT32 accu = 0;
400
401
402   for (bitcount = 0, offs = 0; offs < size; /* */) {
403      /* skip clock */
404      src++;
405      /* get data bit */
406      accu = (accu << 1) | RDBIT(bits,src);
407      src++;
378   for (size_t bitcount = 0, offs = 0; offs < size; /* */) {
379      int bit;
380      src = RDBIT(bits,src,bit);      // skip clock
381      assert(bit == 1);
382      src = RDBIT(bits,src,bit);      // get data bit
383      accu = (accu << 1) | bit;
408384      bitcount += 2;
409385      if (bitcount == 32) {
410386         /* collected a word */
r26100r26101
427403 */
428404size_t alto2_cpu_device::squeeze_cksum(UINT32 *bits, size_t src, int *cksum)
429405{
430   size_t bitcount;
431406   UINT32 accu = 0;
432407
433
434   for (bitcount = 0; bitcount < 32; bitcount += 2) {
435      /* skip clock */
436      src++;
437      /* get data bit */
438      accu = (accu << 1) | RDBIT(bits,src);
439      src++;
408   for (size_t bitcount = 0; bitcount < 32; bitcount += 2) {
409      int bit;
410      src = RDBIT(bits,src,bit);      // skip clock
411      assert(bit == 1);
412      src = RDBIT(bits,src,bit);      // get data bit
413      accu = (accu << 1) | bit;
440414   }
441415
442416   /* set the cksum to the extracted word */
r26100r26101
10731047   if (-1 == d->rdfirst)
10741048      d->rdfirst = index;
10751049
1076   bit = RDBIT(bits,index);
1050   RDBIT(bits,index,bit);
10771051   LOG((LOG_DRIVE,7,"   read #%d %d/%d/%d bit #%d:%d\n", unit, d->cylinder, d->head, d->sector, index, bit));
10781052   d->rdlast = index;
10791053   return bit;
r26100r26101
11231097   if (index & 1) {
11241098      clk = 0;
11251099   } else {
1126      clk = RDBIT(bits,index);
1100      RDBIT(bits,index,clk);
11271101   }
1128
11291102   LOG((LOG_DRIVE,7,   "   read #%d %d/%d/%d clk #%d:%d\n", unit, d->cylinder, d->head, d->sector, index, clk));
1130
11311103   d->rdlast = index;
11321104   return clk ^ 1;
11331105}
r26100r26101
11441116{
11451117   diablo_drive_t *d = m_drive[unit];
11461118   UINT32 *bits;
1147   UINT32 accu;
11481119
11491120   if (unit < 0 || unit > 1)
11501121      return 0;
r26100r26101
11671138         return 0;
11681139   }
11691140
1170   accu = 0;
1141   UINT32 accu = 0;
11711142   while (offs < 400 * 32) {
1172      accu = (accu << 1) | RDBIT(bits,offs);
1173      offs++;
1143      int bit;
1144      offs = RDBIT(bits,offs,bit);
1145      accu = (accu << 1) | bit;
11741146      if (accu == 0xaaaaaaab)
11751147         break;
11761148   }
r26100r26101
12131185         return 0177777;
12141186   }
12151187
1216   for (i = 0, clks = 0, word = 0; i < 16; i++, offs += 2) {
1217      clks = (clks << 1) | RDBIT(bits,offs);
1218      word = (word << 1) | RDBIT(bits,offs+1);
1188   for (i = 0, clks = 0, word = 0; i < 16; i++) {
1189      int bit;
1190      offs = RDBIT(bits,offs,bit);
1191      clks = (clks << 1) | bit;
1192      offs = RDBIT(bits,offs,bit);
1193      word = (word << 1) | bit;
12191194   }
12201195
12211196   return word;
r26100r26101
13581333   if (unit == DRIVE_MAX)
13591334      return -1;
13601335
1361   d = reinterpret_cast<diablo_drive_t *>(m_drive[unit]);
1336   d = m_drive[unit];
13621337
13631338   snprintf(d->basename, sizeof(d->basename), "%s", basename);
13641339
r26100r26101
14851460         267 * 2, sizeof(diablo_sector_t));
14861461
14871462   for (i = 0; i < DIABLO_DRIVE_MAX; i++) {
1488      // FIXME: use MAME resource system(?)
14891463      diablo_drive_t *d = reinterpret_cast<diablo_drive_t *>(auto_alloc_clear(machine(), diablo_drive_t));
14901464      m_drive[i] = d;
14911465

Previous 199869 Revisions Next


© 1997-2024 The MAME Team