Previous 199869 Revisions Next

r20219 Saturday 12th January, 2013 at 13:51:35 UTC by Curt Coder
(MESS) Refactored the Commodore 1581 floppy disk drive to use the modern floppy system. Supports read-only access to D81 images. [Curt Coder]

wd_fdc: Controller remains busy until the last DRQ has been served, and the sector register can now be written more than once. [Curt Coder]
[src/emu/machine]wd_fdc.c
[src/lib/formats]d81_dsk.c d81_dsk.h
[src/mess/machine]c1581.c

trunk/src/emu/machine/wd_fdc.c
r20218r20219
202202void wd_fdc_t::command_end()
203203{
204204   main_state = sub_state = IDLE;
205   status &= ~S_BUSY;
206   intrq = true;
207205   motor_timeout = 0;
208   if(!intrq_cb.isnull())
209      intrq_cb(intrq);
206
207   if (!drq) {
208      status &= ~S_BUSY;
209      intrq = true;
210      if(!intrq_cb.isnull())
211         intrq_cb(intrq);
212   }
210213}
211214
212215void wd_fdc_t::seek_start(int state)
r20218r20219
9991002   if (inverted_bus) val ^= 0xff;
10001003
10011004   // No more than one write in flight
1002   if(sector_buffer != -1)
1003      return;
1005   // C1581 accesses this register with an INC opcode,
1006   // i.e. write old value, write new value, and the new value gets ignored by this
1007   //if(sector_buffer != -1)
1008   //   return;
10041009
10051010   sector_buffer = val;
10061011   delay_cycles(t_sector, dden ? delay_register_commit*2 : delay_register_commit);
r20218r20219
19021907      drq = false;
19031908      if(!drq_cb.isnull())
19041909         drq_cb(false);
1910      if (main_state == IDLE) {
1911         status &= ~S_BUSY;
1912         intrq = true;
1913         if(!intrq_cb.isnull())
1914            intrq_cb(intrq);
1915      }
19051916   }
19061917}
19071918
trunk/src/lib/formats/d81_dsk.c
r20218r20219
135135   {}
136136};
137137
138bool d81_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
138floppy_image_format_t::desc_e* d81_format::get_desc_mfm(const format &f, int &current_size, int &end_gap_index)
139139{
140   int type = find_size(io, form_factor);
141   if(type == -1)
142      return false;
140  static floppy_image_format_t::desc_e desc[25] = {
141    /* 00 */ { MFM, 0x4e, f.gap_1 },
142    /* 01 */ { SECTOR_LOOP_START, 0, f.sector_count-1 },
143    /* 02 */ {   MFM, 0x00, 12 },
144    /* 03 */ {   CRC_CCITT_START, 1 },
145    /* 04 */ {     RAW, 0x4489, 3 },
146    /* 05 */ {     MFM, 0xfe, 1 },
147    /* 06 */ {     TRACK_ID },
148    /* 07 */ {     HEAD_ID_SWAP },
149    /* 08 */ {     SECTOR_ID },
150    /* 09 */ {     SIZE_ID },
151    /* 10 */ {   CRC_END, 1 },
152    /* 11 */ {   CRC, 1 },
153    /* 12 */ {   MFM, 0x4e, f.gap_2 },
154    /* 13 */ {   MFM, 0x00, 12 },
155    /* 14 */ {   CRC_CCITT_START, 2 },
156    /* 15 */ {     RAW, 0x4489, 3 },
157    /* 16 */ {     MFM, 0xfb, 1 },
158    /* 17 */ {     SECTOR_DATA, -1 },
159    /* 18 */ {   CRC_END, 2 },
160    /* 19 */ {   CRC, 2 },
161    /* 20 */ {   MFM, 0x4e, f.gap_3 },
162    /* 21 */ { SECTOR_LOOP_END },
163    /* 22 */ { MFM, 0x4e, 0 },
164    /* 23 */ { RAWBITS, 0x9254, 0 },
165    /* 24 */ { END }
166  };
143167
144   const format &f = formats[type];
168  current_size = f.gap_1*16;
169  if(f.sector_base_size)
170    current_size += f.sector_base_size * f.sector_count * 16;
171  else {
172    for(int j=0; j != f.sector_count; j++)
173      current_size += f.per_sector_size[j] * 16;
174  }
175  current_size += (12+3+1+4+2+f.gap_2+12+3+1+2+f.gap_3) * f.sector_count * 16;
145176
146   floppy_image_format_t::desc_e desc[] = {
147      /* 00 */ { MFM, 0x4e, f.gap_1 },
148      /* 01 */ { SECTOR_LOOP_START, 0, f.sector_count-1 },
149      /* 02 */ {   MFM, 0x00, 12 },
150      /* 03 */ {   CRC_CCITT_START, 1 },
151      /* 04 */ {     RAW, 0x4489, 3 },
152      /* 05 */ {     MFM, 0xfe, 1 },
153      /* 06 */ {     TRACK_ID },
154      /* 07 */ {     HEAD_ID_SWAP },
155      /* 08 */ {     SECTOR_ID },
156      /* 09 */ {     SIZE_ID },
157      /* 10 */ {   CRC_END, 1 },
158      /* 11 */ {   CRC, 1 },
159      /* 12 */ {   MFM, 0x4e, f.gap_2 },
160      /* 13 */ {   MFM, 0x00, 12 },
161      /* 14 */ {   CRC_CCITT_START, 2 },
162      /* 15 */ {     RAW, 0x4489, 3 },
163      /* 16 */ {     MFM, 0xfb, 1 },
164      /* 17 */ {     SECTOR_DATA, -1 },
165      /* 18 */ {   CRC_END, 2 },
166      /* 19 */ {   CRC, 2 },
167      /* 20 */ {   MFM, 0x4e, f.gap_3 },
168      /* 21 */ { SECTOR_LOOP_END },
169      /* 22 */ { MFM, 0x4e, 0 },
170      /* 23 */ { RAWBITS, 0x9254, 0 },
171      /* 24 */ { END }
172   };
177  end_gap_index = 22;
173178
174   int current_size = f.gap_1*16;
175   if(f.sector_base_size)
176      current_size += f.sector_base_size * f.sector_count * 16;
177   else {
178      for(int j=0; j != f.sector_count; j++)
179         current_size += f.per_sector_size[j] * 16;
180   }
181   current_size += (12+3+1+4+2+f.gap_2+12+3+1+2+f.gap_3) * f.sector_count * 16;
182
183   int total_size = 200000000/f.cell_size;
184   int remaining_size = total_size - current_size;
185   if(remaining_size < 0)
186      throw emu_fatalerror("d81_format: Incorrect track layout, max_size=%d, current_size=%d", total_size, current_size);
187
188   // Fixup the end gap
189   desc[22].p2 = remaining_size / 16;
190   desc[23].p2 = remaining_size & 15;
191   desc[23].p1 >>= 16-(remaining_size & 15);
192
193   int track_size = compute_track_size(f);
194
195   UINT8 sectdata[40*512];
196   desc_s sectors[40];
197   build_sector_description(f, sectdata, sectors);
198
199   for(int track=0; track < f.track_count; track++)
200      for(int head=0; head < f.head_count; head++) {
201         io_generic_read(io, sectdata, (track*f.head_count + !head)*track_size, track_size);
202         generate_track(desc, track, head, sectors, f.sector_count, total_size, image);
203      }
204
205   image->set_variant(f.variant);
206
207   return true;
179  return desc;
208180}
209181
210182const floppy_format_type FLOPPY_D81_FORMAT = &floppy_image_format_creator<d81_format>;
trunk/src/lib/formats/d81_dsk.h
r20218r20219
1919   virtual const char *description() const;
2020   virtual const char *extensions() const;
2121
22   virtual bool load(io_generic *io, UINT32 form_factor, floppy_image *image);
22   virtual floppy_image_format_t::desc_e* get_desc_mfm(const format &f, int &current_size, int &end_gap_index);
2323
2424private:
2525   static const format formats[];
trunk/src/mess/machine/c1581.c
r20218r20219
1111
1212    TODO:
1313
14    - wd_fdc drops the busy bit too soon, c1581 aborts reading the sector ID after the first CRC byte @CD17
14   - drive not ready if ready_r() is connected to CIA
15   - format fails (seeks to directory track and reports BAD DISK error)
16    - save fails (no error message, but no file added to directory either)
1517
1618*/
1719
r20218r20219
117119//-------------------------------------------------
118120
119121static ADDRESS_MAP_START( c1581_mem, AS_PROGRAM, 8, base_c1581_device )
120   AM_RANGE(0x0000, 0x1fff) AM_RAM
122   AM_RANGE(0x0000, 0x1fff) AM_MIRROR(0x2000) AM_RAM
121123   AM_RANGE(0x4000, 0x400f) AM_MIRROR(0x1ff0) AM_DEVREADWRITE(M8520_TAG, mos8520_device, read, write)
122124   AM_RANGE(0x6000, 0x6003) AM_MIRROR(0x1ffc) AM_DEVREADWRITE(WD1772_TAG, wd1772_t, read, write)
123125   AM_RANGE(0x8000, 0xffff) AM_ROM AM_REGION(M6502_TAG, 0)
r20218r20219
162164   UINT8 data = 0;
163165
164166   // ready
165   data |= !m_floppy->ready_r() << 1;
167   //data |= !m_floppy->ready_r() << 1;
166168
167169   // device number
168170   data |= (m_address - 8) << 3;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team