Previous 15994 Revisions Next

r5828 Monday 21st September, 2009 at 10:21:46 UTC by Miodrag Milanović
TD0 compressed files support
[src/mess/formats]td0_dsk.c

src/mess/formats/td0_dsk.c
r5827r5828
11/*********************************************************************
22
3   formats/td0_dsk.c
3    formats/td0_dsk.c
44
5   TD0 disk images
5    TD0 disk images
66
77*********************************************************************/
8/*
9 * Based on Japanese version 29-NOV-1988
10 * LZSS coded by Haruhiko OKUMURA
11 * Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI
12 * Edited and translated to English by Kenji RIKITAKE
13 */
814
915#include <string.h>
1016#include "driver.h"
r5827r5828
1925   int tracks;
2026   int sector_size;
2127   UINT64 track_offsets[84*2]; /* offset within data for each track */
28   UINT8 *data;
2229};
2330
2431
r5827r5828
3845   floppy_image_read(floppy, header, 0, 2);
3946   if (header[0]=='T' && header[1]=='D') {
4047      *vote = 100;
48   } else if (header[0]=='t' && header[1]=='d') {
49      *vote = 100;
4150   } else {
4251      *vote = 0;
4352   }
r5827r5828
6271static floperr_t get_offset(floppy_image *floppy, int head, int track, int sector, int sector_is_index, UINT64 *offset)
6372{
6473   UINT64 offs;
65   UINT8 header[8];
66   UINT8 sectors_per_track;   
74   UINT8 *header;
75   UINT8 sectors_per_track;
6776   int i;
6877
6978   if ((head < 0) || (head >= get_tag(floppy)->heads) || (track < 0) || (track >= get_tag(floppy)->tracks)
r5827r5828
7483   offs = td0_get_track_offset(floppy, head, track);
7584
7685   // read track header
77   floppy_image_read(floppy, header, offs - 4, 4);
78   
86   header = get_tag(floppy)->data + offs - 4;
87
7988   // take number of sectors per track
8089   sectors_per_track = header[0];
81   
90
8291   if (!sector_is_index) {
8392      // when taking ID's return seek error if number is over counter
8493      if (sector > sectors_per_track) {
8594         return FLOPPY_ERROR_SEEKERROR;
8695      }
8796   }
88   
97
8998   // move trought sectors
9099   for(i=0;i < sector-1;i++) {
91      floppy_image_read(floppy, header, offs, 6);
100      header = get_tag(floppy)->data + offs;
92101      offs+= 6;
93102      if ((header[4] & 0x30)==0) {
94         floppy_image_read(floppy, header+6, offs, 2);
95         offs+= 2;     
96         offs+= header[6] + (header[7]<<8);           
103         offs+= 2;
104         offs+= header[6] + (header[7]<<8);
97105      }
98   }   
106   }
99107   // read size of sector
100   floppy_image_read(floppy, header, offs, 6);
108   header = get_tag(floppy)->data + offs;
101109   get_tag(floppy)->sector_size = 1 << (header[3] + 7);
102110
103111   if (offset)
r5827r5828
111119{
112120   UINT64 offset;
113121   floperr_t err;
114   UINT8 header[9];
122   UINT8 *header;
115123   int size,realsize,i;
116124   int buff_pos;
117125   int data_pos;
118126   UINT8 *data;
119127   UINT8 *buf;
120   
121   buf = (UINT8*)buffer;   
128
129   buf = (UINT8*)buffer;
122130   // take sector offset
123131   err = get_offset(floppy, head, track, sector, sector_is_index, &offset);
124132   if (err)
125133      return err;
126     
134
127135   // read sector header
128   floppy_image_read(floppy, header, offset, 6);
136   header = get_tag(floppy)->data + offset;
129137   offset+=6;
130138   // if there is no date just jump out
131139   if ((header[4] & 0x30)!=0) return FLOPPY_ERROR_SUCCESS;
132     
133   floppy_image_read(floppy, header+6, offset, 3);
140
134141   offset+=3;
135142   // take data size
136143   size = header[6] + (header[7]<<8)-1;
137144   // take real sector size
138145   realsize =  1 << (header[3] + 7);
139   
140   data = malloc(size);
146
141147   // read sector data
142   floppy_image_read(floppy, data, offset, size);
143   
148   data = get_tag(floppy)->data + offset;
144149   buff_pos = 0;
145150   data_pos = 0;
146   
151
147152   switch(header[8]) {
148      case 0:   
153      case 0:
149154            // encoding type 0
150155            //  - plain data
151156            memcpy(buffer,data,size);
152            break;     
153      case 1:
157            break;
158      case 1:
154159            // encoding type 1
155            //   - 2 bytes size
160            //  - 2 bytes size
156161            //  - 2 bytes of data
157162            //  data is reapeted specified number of times
158163            while(buff_pos<realsize) {
r5827r5828
163168               data_pos+=4;
164169            }
165170            break;
166      case 2:
171      case 2:
167172            // encoding type 2
168            //   - if first byte is zero next byte represent size of
169            //      plain data after it
170            //   - if different then zero when multiply by 2 represent
171            //      size of data that should be reapeted next byte times
173            //  - if first byte is zero next byte represent size of
174            //      plain data after it
175            //  - if different then zero when multiply by 2 represent
176            //      size of data that should be reapeted next byte times
172177            while(buff_pos<realsize) {
173178               if (data[data_pos]==0x00) {
174                  int size = data[data_pos+1];                 
179                  int size = data[data_pos+1];
175180                  memcpy(buf+buff_pos,data + data_pos + 2,size);
176181                  data_pos += 2 + size;
177182                  buff_pos += size;
r5827r5828
179184                  int size   = 2*data[data_pos];
180185                  int repeat = data[data_pos+1];
181186                  data_pos+=2;
182                                   
183                  for (i=0;i<repeat;i++) {                     
187
188                  for (i=0;i<repeat;i++) {
184189                     memcpy(buf + buff_pos,data + data_pos,size);
185190                     buff_pos += size;
186191                  }
r5827r5828
188193               }
189194            }
190195            break;
191      default:
192            free(data);
196      default:
193197            return FLOPPY_ERROR_INTERNAL;
194198            break;
195199   }
196   free(data);
197200   return FLOPPY_ERROR_SUCCESS;
198201}
199202
r5827r5828
215218   if (err)
216219      return err;
217220
218   if (sector_length) {     
221   if (sector_length) {
219222      *sector_length = get_tag(floppy)->sector_size;
220223   }
221224   return FLOPPY_ERROR_SUCCESS;
r5827r5828
225228{
226229   floperr_t retVal;
227230   UINT64 offset;
228   UINT8 sector_info[9];
231   UINT8 *sector_info;
229232
230233   retVal = get_offset(floppy, head, track, sector_index, FALSE, &offset);
231234
232   floppy_image_read(floppy, sector_info, offset, 9);
235   sector_info = get_tag(floppy)->data + offset;
233236   if (cylinder)
234237      *cylinder = sector_info[0];
235238   if (side)
r5827r5828
244247      if (sector_info[4] & 0x02) *flags |= ID_FLAG_CRC_ERROR_IN_DATA_FIELD;
245248      if (sector_info[4] & 0x04) *flags |= ID_FLAG_DELETED_DATA;
246249   }
247     
250
248251   return retVal;
249252}
250253
254static floppy_image *floppy_file;
255static UINT64 floppy_file_offset;
251256
257int data_read(UINT8 *buf,UINT16 size)
258{
259   if (floppy_file_offset + size > floppy_image_size(floppy_file) ) {
260      size = floppy_image_size(floppy_file)- floppy_file_offset;
261   }
262   floppy_image_read(floppy_file,buf,floppy_file_offset,size);
263   floppy_file_offset += size;
264   return size;
265}
266
267#define BUFSZ           512     // new input buffer
268
269static struct tdlzhuf {
270   UINT16 r,
271               bufcnt,bufndx,bufpos,  // string buffer
272          // the following to allow block reads from input in next_word()
273               ibufcnt,ibufndx; // input buffer counters
274   UINT8  inbuf[BUFSZ];    // input buffer
275} tdctl;
276
277
278
279
280/* LZSS Parameters */
281
282#define N        4096    /* Size of string buffer */
283#define F        60    /* Size of look-ahead buffer */
284#define THRESHOLD    2
285#define NIL        N    /* End of tree's node  */
286
287static UINT8 text_buf[N + F - 1];
288
289/* Huffman coding parameters */
290
291#define N_CHAR      (256 - THRESHOLD + F)
292                /* character code (= 0..N_CHAR-1) */
293#define T         (N_CHAR * 2 - 1)    /* Size of table */
294#define R         (T - 1)            /* root position */
295#define MAX_FREQ    0x8000
296                    /* update when cumulative frequency */
297                    /* reaches to this value */
298
299/*
300 * Tables for encoding/decoding upper 6 bits of
301 * sliding dictionary pointer
302 */
303
304/* decoder table */
305static UINT8 d_code[256] = {
306    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
308    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
310    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
311    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
312    0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
313    0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
314    0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
315    0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
316    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
317    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
318    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
319    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
320    0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
321    0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
322    0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
323    0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
324    0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D,
325    0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F,
326    0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11,
327    0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
328    0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
329    0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
330    0x18, 0x18, 0x19, 0x19, 0x1A, 0x1A, 0x1B, 0x1B,
331    0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
332    0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23,
333    0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
334    0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B,
335    0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F,
336    0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
337    0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
338};
339
340static UINT8 d_len[256] = {
341    0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
342    0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
343    0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
344    0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
345    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
346    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
347    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
348    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
349    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
350    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
351    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
352    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
353    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
354    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
355    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
356    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
357    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
358    0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
359    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
360    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
361    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
362    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
363    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
364    0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
365    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
366    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
367    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
368    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
369    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
370    0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
371    0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
372    0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
373};
374
375static UINT16 freq[T + 1];    /* cumulative freq table */
376
377/*
378 * pointing parent nodes.
379 * area [T..(T + N_CHAR - 1)] are pointers for leaves
380 */
381INT16 prnt[T + N_CHAR];
382
383/* pointing children nodes (son[], son[] + 1)*/
384INT16 son[T];
385
386static UINT16 getbuf;
387static UINT8 getlen;
388
389static int next_word(void)
390{
391    if(tdctl.ibufndx >= tdctl.ibufcnt)
392    {
393        tdctl.ibufndx = 0;
394        tdctl.ibufcnt = data_read(tdctl.inbuf,BUFSZ);
395        if(tdctl.ibufcnt <= 0)
396            return(-1);
397    }
398    while (getlen <= 8) { // typically reads a word at a time
399        getbuf |= tdctl.inbuf[tdctl.ibufndx++] << (8 - getlen);
400        getlen += 8;
401    }
402    return(0);
403}
404
405
406static int GetBit(void)    /* get one bit */
407{
408    INT16 i;
409    if(next_word() < 0)
410        return(-1);
411    i = getbuf;
412    getbuf <<= 1;
413    getlen--;
414        if(i < 0)
415        return(1);
416    else
417        return(0);
418}
419
420static int GetByte(void)    /* get a byte */
421{
422    UINT16 i;
423        if(next_word() != 0)
424        return(-1);
425    i = getbuf;
426    getbuf <<= 8;
427    getlen -= 8;
428        i = i >> 8;
429    return((int) i);
430}
431
432
433
434/* initialize freq tree */
435
436static void StartHuff(void)
437{
438    int i, j;
439
440    for (i = 0; i < N_CHAR; i++) {
441        freq[i] = 1;
442        son[i] = i + T;
443        prnt[i + T] = i;
444    }
445    i = 0; j = N_CHAR;
446    while (j <= R) {
447        freq[j] = freq[i] + freq[i + 1];
448        son[j] = i;
449        prnt[i] = prnt[i + 1] = j;
450        i += 2; j++;
451    }
452    freq[T] = 0xffff;
453    prnt[R] = 0;
454}
455
456
457/* reconstruct freq tree */
458
459static void reconst(void)
460{
461    INT16 i, j, k;
462    UINT16 f, l;
463
464    /* halven cumulative freq for leaf nodes */
465    j = 0;
466    for (i = 0; i < T; i++) {
467        if (son[i] >= T) {
468            freq[j] = (freq[i] + 1) / 2;
469            son[j] = son[i];
470            j++;
471        }
472    }
473    /* make a tree : first, connect children nodes */
474    for (i = 0, j = N_CHAR; j < T; i += 2, j++) {
475        k = i + 1;
476        f = freq[j] = freq[i] + freq[k];
477        for (k = j - 1; f < freq[k]; k--);
478        k++;
479        l = (j - k) * 2;
480
481        /* movmem() is Turbo-C dependent
482           rewritten to memmove() by Kenji */
483
484        /* movmem(&freq[k], &freq[k + 1], l); */
485        (void)memmove(&freq[k + 1], &freq[k], l);
486        freq[k] = f;
487        /* movmem(&son[k], &son[k + 1], l); */
488        (void)memmove(&son[k + 1], &son[k], l);
489        son[k] = i;
490    }
491    /* connect parent nodes */
492    for (i = 0; i < T; i++) {
493        if ((k = son[i]) >= T) {
494            prnt[k] = i;
495        } else {
496            prnt[k] = prnt[k + 1] = i;
497        }
498    }
499}
500
501
502/* update freq tree */
503
504static void update(int c)
505{
506    int i, j, k, l;
507
508    if (freq[R] == MAX_FREQ) {
509        reconst();
510    }
511    c = prnt[c + T];
512    do {
513        k = ++freq[c];
514
515        /* swap nodes to keep the tree freq-ordered */
516        if (k > freq[l = c + 1]) {
517            while (k > freq[++l]);
518            l--;
519            freq[c] = freq[l];
520            freq[l] = k;
521
522            i = son[c];
523            prnt[i] = l;
524            if (i < T) prnt[i + 1] = l;
525
526            j = son[l];
527            son[l] = i;
528
529            prnt[j] = c;
530            if (j < T) prnt[j + 1] = c;
531            son[c] = j;
532
533            c = l;
534        }
535    } while ((c = prnt[c]) != 0);    /* do it until reaching the root */
536}
537
538
539static INT16 DecodeChar(void)
540{
541    int ret;
542    UINT16 c;
543
544    c = son[R];
545
546    /*
547     * start searching tree from the root to leaves.
548     * choose node #(son[]) if input bit == 0
549     * else choose #(son[]+1) (input bit == 1)
550     */
551    while (c < T) {
552                if((ret = GetBit()) < 0)
553            return(-1);
554        c += (unsigned) ret;
555        c = son[c];
556    }
557    c -= T;
558    update(c);
559    return c;
560}
561
562static INT16 DecodePosition(void)
563{
564    INT16 bit;
565    UINT16 i, j, c;
566
567    /* decode upper 6 bits from given table */
568        if((bit=GetByte()) < 0)
569        return(-1);
570    i = (UINT16) bit;
571    c = (UINT16)d_code[i] << 6;
572    j = d_len[i];
573
574    /* input lower 6 bits directly */
575    j -= 2;
576    while (j--) {
577                if((bit = GetBit()) < 0)
578                     return(-1);
579        i = (i << 1) + bit;
580    }
581    return(c | (i & 0x3f));
582}
583
584/* DeCompression
585
586split out initialization code to init_Decode()
587
588*/
589
590static void init_Decode(void)
591{
592    int i;
593   getbuf = 0;
594   getlen = 0;
595    tdctl.ibufcnt= tdctl.ibufndx = 0; // input buffer is empty
596    tdctl.bufcnt = 0;
597    StartHuff();
598    for (i = 0; i < N - F; i++)
599        text_buf[i] = ' ';
600    tdctl.r = N - F;
601}
602
603
604static int Decode(UINT8 *buf, int len)  /* Decoding/Uncompressing */
605{
606    INT16 c,pos;
607    int  count;  // was an unsigned long, seems unnecessary
608    for (count = 0; count < len; ) {
609            if(tdctl.bufcnt == 0) {
610                if((c = DecodeChar()) < 0)
611                    return(count); // fatal error
612                if (c < 256) {
613                    *(buf++) = c;
614                    text_buf[tdctl.r++] = c;
615                    tdctl.r &= (N - 1);
616                    count++;
617                }
618                else {
619                    if((pos = DecodePosition()) < 0)
620                           return(count); // fatal error
621                    tdctl.bufpos = (tdctl.r - pos - 1) & (N - 1);
622                    tdctl.bufcnt = c - 255 + THRESHOLD;
623                    tdctl.bufndx = 0;
624                 }
625            }
626            else { // still chars from last string
627                while( tdctl.bufndx < tdctl.bufcnt && count < len ) {
628                    c = text_buf[(tdctl.bufpos + tdctl.bufndx) & (N - 1)];
629                    *(buf++) = c;
630                    tdctl.bufndx++;
631                    text_buf[tdctl.r++] = c;
632                    tdctl.r &= (N - 1);
633                    count++;
634                }
635                // reset bufcnt after copy string from text_buf[]
636                if(tdctl.bufndx >= tdctl.bufcnt)
637                    tdctl.bufndx = tdctl.bufcnt = 0;
638        }
639    }
640    return(count); // count == len, success
641}
642
643
252644FLOPPY_CONSTRUCT( td0_dsk_construct )
253645{
254646   struct FloppyCallbacks *callbacks;
255647   struct td0dsk_tag *tag;
256   UINT8 header[16];
648   UINT8 *header;
257649   int number_of_sectors;
258650   int position;
259651   int i;
r5827r5828
265657      return FLOPPY_ERROR_UNSUPPORTED;
266658   }
267659
268   floppy_image_read(floppy, header, 0, 16);
269
270660   tag = (struct td0dsk_tag *) floppy_create_tag(floppy, TD0_DSK_TAG, sizeof(struct td0dsk_tag));
271661   if (!tag)
272662      return FLOPPY_ERROR_OUTOFMEMORY;
273663
664   tag->data = (UINT8*)malloc(floppy_image_size(floppy));
665   if (tag->data==NULL) {
666      return FLOPPY_ERROR_OUTOFMEMORY;
667   }
668   floppy_image_read(floppy, tag->data, 0, floppy_image_size(floppy));
669   header = tag->data;
670
671   if (header[0]=='t') {
672      UINT8 obuf[BUFSZ];
673      int rd;
674      int off = 12;
675      int size = 0;
676      floppy_file   = floppy;
677      init_Decode();
678      floppy_file_offset =12;
679        do
680        {
681           if((rd = Decode(obuf,BUFSZ)) > 0) size += rd;
682        }  while(rd == BUFSZ);
683      memcpy(obuf,tag->data,12);
684      free(tag->data);
685      tag->data = (UINT8*)malloc(size+12);
686      if (tag->data==NULL) {
687         return FLOPPY_ERROR_OUTOFMEMORY;
688      }
689      memcpy(tag->data,obuf,12);
690      floppy_file_offset =12;
691      init_Decode();
692        do
693        {
694           if((rd = Decode(obuf,BUFSZ)) > 0) {
695            memcpy(tag->data+off,obuf,rd);
696            off += rd;
697         }
698        }  while(rd == BUFSZ);
699   }
700   header = tag->data;
274701   tag->heads   = header[9];
275702   if (tag->heads > 1) {
276703      tag->heads  = 2;
277   }
278   
704   }
705
279706   //  header len + comment header + comment len
280707   position = 12;
281708   if (header[7] & 0x80) {
282709      position += 10 + header[14] + (header[15]<<8);
283710   }
284711   tag->tracks = 0;
285   
286   do {
712   do {
287713      // read track header
288      floppy_image_read(floppy, header, position, 4);
714      header = tag->data + position;
289715      track = header[1];
290716      number_of_sectors = header[0];
291      if (number_of_sectors!=0xff){
717      if (number_of_sectors!=0xff){
292718         position+=4;
293719         tag->track_offsets[(track<<1) + (header[2] & 1)] = position;
294720         for(i=0;i<number_of_sectors;i++) {
295721            // read sector header
296            floppy_image_read(floppy, header, position, 6);
722            header = tag->data + position;
297723            position+=6;
298724            // read sector size
299725            if ((header[4] & 0x30)==0) {
300726               // if there is sector data
301               floppy_image_read(floppy, header, position, 2);
727               header = tag->data + position;
302728               position+=2;
303729               // skip sector data
304730               position+= header[0] + (header[1]<<8);
305731            }
306732         }
307733         tag->tracks++;
308      }     
734      }
309735   } while(number_of_sectors!=0xff);
310736   tag->tracks++;
311737

Previous 15994 Revisions Next


© 1998-2018 The MESS Team