Previous 15994 Revisions Next

r13155 Tuesday 1st November, 2011 at 11:09:46 UTC by Olivier Galibert
amigafdc: Upgrade [O. Galibert]
[src/emu]emu.mak
[src/emu/imagedev]floppy.c
[src/emu/machine]amigafdc.c* amigafdc.h*
[src/mame/drivers]alg.c arcadia.c cd32.c mquake.c upscope.c
[src/mame/includes]amiga.h
[src/mame/machine]amiga.c
[src/mess]mess.mak
[src/mess/drivers]ami1200.c amiga.c
[src/mess/machine]amigafdc.c amigafdc.h
[src/mess/tools/floptool]main.c

src/mame/machine/amiga.c
r13154r13155
1212#include "includes/amiga.h"
1313#include "cpu/m68000/m68000.h"
1414#include "machine/6526cia.h"
15#include "machine/amigafdc.h"
1516
16
1717/*************************************
1818 *
1919 *  Debugging
r13154r13155
11811181            return (*state->m_intf->joy1dat_r)(space->machine());
11821182         return input_port_read_safe(space->machine(), "JOY1DAT", 0xffff);
11831183
1184      case REG_ADKCONR:
1185         return CUSTOM_REG(REG_ADKCON);
1186
11871184      case REG_POTGOR:
11881185         return input_port_read_safe(space->machine(), "POTGO", 0x5500);
11891186
r13154r13155
11941191         return input_port_read_safe(space->machine(), "POT1DAT", 0x0000);
11951192
11961193      case REG_DSKBYTR:
1197         if (state->m_intf->dskbytr_r != NULL)
1198            return (*state->m_intf->dskbytr_r)(space->machine());
1199         return 0x0000;
1194         return space->machine().device<amiga_fdc>("fdc")->dskbytr_r();
12001195
12011196      case REG_INTENAR:
12021197         return CUSTOM_REG(REG_INTENA);
r13154r13155
12191214
12201215      case REG_DENISEID:
12211216         return CUSTOM_REG(REG_DENISEID);
1217
1218      case REG_DSKPTH:
1219         return space->machine().device<amiga_fdc>("fdc")->dskpth_r();
1220
1221      case REG_DSKPTL:
1222         return space->machine().device<amiga_fdc>("fdc")->dskptl_r();
12221223   }
12231224
12241225   if (LOG_CUSTOM)
r13154r13155
12671268         /* read-only registers */
12681269         break;
12691270
1271      case REG_DSKSYNC:
1272         space->machine().device<amiga_fdc>("fdc")->dsksync_w(data);
1273         break;
1274
1275      case REG_DSKPTH:
1276         space->machine().device<amiga_fdc>("fdc")->dskpth_w(data);
1277         break;
1278
1279      case REG_DSKPTL:
1280         space->machine().device<amiga_fdc>("fdc")->dskptl_w(data);
1281         break;
1282
12701283      case REG_DSKLEN:
1271         if (state->m_intf->dsklen_w != NULL)
1272            (*state->m_intf->dsklen_w)(space->machine(), data);
1284         space->machine().device<amiga_fdc>("fdc")->dsklen_w(data);
12731285         break;
12741286
12751287      case REG_POTGO:
r13154r13155
13721384         /* bits BBUSY (14) and BZERO (13) are read-only */
13731385         data &= 0x9fff;
13741386         data = (data & 0x8000) ? (CUSTOM_REG(offset) | (data & 0x7fff)) : (CUSTOM_REG(offset) & ~(data & 0x7fff));
1375
1387         space->machine().device<amiga_fdc>("fdc")->dmacon_set(data);
1388         
13761389         /* if 'blitter-nasty' has been turned on and we have a blit pending, reschedule it */
13771390         if ( ( data & 0x400 ) && ( CUSTOM_REG(REG_DMACON) & 0x4000 ) )
13781391            state->m_blitter_timer->adjust( downcast<cpu_device *>(&space->device())->cycles_to_attotime( BLITTER_NASTY_DELAY ));
r13154r13155
14131426      case REG_ADKCON:
14141427         amiga_audio_update(state->m_sound_device);
14151428         data = (data & 0x8000) ? (CUSTOM_REG(offset) | (data & 0x7fff)) : (CUSTOM_REG(offset) & ~(data & 0x7fff));
1429         space->machine().device<amiga_fdc>("fdc")->adkcon_set(data);
14161430         break;
14171431
14181432      case REG_AUD0LCL:   case REG_AUD0LCH:   case REG_AUD0LEN:   case REG_AUD0PER:   case REG_AUD0VOL:
src/mame/includes/amiga.h
r13154r13155
9797#define REG_BLTBDAT      (0x072/2)   /* W  A      Blitter source B data reglster */
9898#define REG_BLTADAT      (0x074/2)   /* W  A      Blitter source A data register */
9999#define REG_DENISEID   (0x07C/2)   /* R    D    Denise ID: OCS = 0xFF, ECS = 0xFC, AGA = 0xF8 */
100#define REG_DSRSYNC      (0x07E/2)   /* W      P  Disk sync pattern register for disk read */
100#define REG_DSKSYNC      (0x07E/2)   /* W      P  Disk sync pattern register for disk read */
101101#define REG_COP1LCH      (0x080/2)   /* W  A      Coprocessor first location register (high 3 bits) */
102102#define REG_COP1LCL      (0x082/2)   /* W  A      Coprocessor first location register (low 15 bits) */
103103#define REG_COP2LCH      (0x084/2)   /* W  A      Coprocessor second location register (high 3 bits) */
r13154r13155
329329   UINT16 (*joy1dat_r)(running_machine &machine);
330330   void (*potgo_w)(running_machine &machine, UINT16 data);
331331
332   UINT16 (*dskbytr_r)(running_machine &machine);
333   void (*dsklen_w)(running_machine &machine, UINT16 data);
334
335332   void (*serdat_w)(running_machine &machine, UINT16 data);
336333
337334   void (*scanline0_callback)(running_machine &machine);
src/mame/drivers/arcadia.c
r13154r13155
793793   {
794794      ANGUS_CHIP_RAM_MASK,
795795      NULL, NULL, NULL,
796      NULL, NULL, NULL,
796      NULL,
797797      NULL,  arcadia_reset_coins,
798798      NULL,
799799      0
src/mame/drivers/cd32.c
r13154r13155
834834   {
835835      AGA_CHIP_RAM_MASK,
836836      NULL, NULL, cd32_potgo_w,
837      NULL, NULL, NULL,
837      NULL,
838838      NULL, NULL,
839839      NULL,
840840      FLAGS_AGA_CHIPSET
r13154r13155
14541454   {
14551455      AGA_CHIP_RAM_MASK,
14561456      NULL, NULL, cd32_potgo_w,
1457      NULL, NULL, serial_w,
1457      serial_w,
14581458      NULL, NULL,
14591459      NULL,
14601460      FLAGS_AGA_CHIPSET
src/mame/drivers/alg.c
r13154r13155
685685   {
686686      ANGUS_CHIP_RAM_MASK,
687687      NULL, NULL, alg_potgo_w,
688      NULL, NULL, serial_w,
688      serial_w,
689689
690690      vsync_callback,
691691      NULL,
src/mame/drivers/upscope.c
r13154r13155
390390   {
391391      ANGUS_CHIP_RAM_MASK,
392392      NULL, NULL, NULL,
393      NULL, NULL, NULL,
393      NULL,
394394      NULL, upscope_reset,
395395      NULL,
396396      0
src/mame/drivers/mquake.c
r13154r13155
433433   {
434434      ANGUS_CHIP_RAM_MASK,
435435      NULL, NULL, NULL,
436      NULL, NULL, NULL,
436      NULL,
437437      NULL, NULL,
438438      NULL,
439439      0
src/emu/imagedev/floppy.c
r13154r13155
269269         } else {
270270            if ( cyl < tracks-1 ) cyl++;
271271         }
272
272273         /* Update disk detection if applicable */
273274         if (exists())
274275         {
r13154r13155
286287   step >>= 1;
287288
288289   for(;;) {
289#if 0
290      fprintf(stderr, "%09d - %09d / %09d  -- %6d %6d %6d\n",
291            position,
292            spos < 0 ? 0 : spos >= buf_size ? 200000000 :buf[spos] & floppy_image::TIME_MASK,
293            spos < 0 ? 0 : spos >= buf_size-1 ? 200000000 : buf[spos+1] & floppy_image::TIME_MASK,
294            spos, step, buf_size);
295#endif
296
297290      if(spos >= buf_size || (spos > 0 && (buf[spos] & floppy_image::TIME_MASK) > position)) {
298291         spos -= step;
299292         step >>= 1;
r13154r13155
328321   const UINT32 *buf = image->get_buffer(cyl, ss);
329322   int index = find_position(position, buf, cells);
330323
331   //  fprintf(stderr, "position=%9d, index=%d\n", position, index);
332324   if(index == -1)
333325      return attotime::never;
334326
r13154r13155
340332   else
341333      next_position = 200000000 + (buf[1] & floppy_image::TIME_MASK);
342334
343   //  printf("next_pos=%d, delta=%d\n", next_position, next_position-position);
344335   return base + attotime::from_nsec(next_position*(300/rpm));
345336}
src/emu/emu.mak
r13154r13155
164164   $(EMUMACHINE)/adc1213x.o   \
165165   $(EMUMACHINE)/am53cf96.o   \
166166   $(EMUMACHINE)/am8530h.o      \
167   $(EMUMACHINE)/amigafdc.o   \
167168   $(EMUMACHINE)/at28c16.o      \
168169   $(EMUMACHINE)/cdp1852.o      \
169170   $(EMUMACHINE)/cdp1871.o      \
src/emu/machine/amigafdc.c
r0r13155
1/****************************************************f***********************
2
3    Amiga floppy disk controller emulation
4
5***************************************************************************/
6
7
8#include "emu.h"
9#include "includes/amiga.h"
10#include "formats/ami_dsk.h"
11#include "formats/hxcmfm_dsk.h"
12#include "formats/ipf_dsk.h"
13#include "formats/mfi_dsk.h"
14#include "amigafdc.h"
15#include "machine/6526cia.h"
16
17const device_type AMIGA_FDC = &device_creator<amiga_fdc>;
18
19const floppy_format_type amiga_fdc::floppy_formats[] = {
20   FLOPPY_ADF_FORMAT, FLOPPY_MFM_FORMAT, FLOPPY_IPF_FORMAT, FLOPPY_MFI_FORMAT,
21   NULL
22};
23
24
25amiga_fdc::amiga_fdc(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
26   device_t(mconfig, AMIGA_FDC, "Amiga FDC", tag, owner, clock)
27{
28}
29
30void amiga_fdc::device_start()
31{
32   floppy_devices[0] = machine().device<floppy_image_device>("fd0");
33   floppy_devices[1] = machine().device<floppy_image_device>("fd1");
34   floppy_devices[2] = machine().device<floppy_image_device>("fd2");
35   floppy_devices[3] = machine().device<floppy_image_device>("fd3");
36   floppy = 0;
37
38   t_gen = timer_alloc(0);
39}
40
41
42void amiga_fdc::device_reset()
43{
44   floppy = 0;
45   dsklen = 0x4000;
46   dsksync = 0x4489;
47   adkcon = 0;
48   dmacon = 0;
49   dskpt = 0;
50   dsklen = 0x4000;
51   pre_dsklen = 0x4000;
52   dma_value = 0;
53   dma_state = DMA_IDLE;
54
55   live_abort();
56}
57
58void amiga_fdc::live_start()
59{
60   cur_live.tm = machine().time();
61   cur_live.state = RUNNING;
62   cur_live.next_state = -1;
63   cur_live.shift_reg = 0;
64   cur_live.bit_counter = 0;
65   cur_live.pll.reset(cur_live.tm);
66   cur_live.pll.set_clock(clocks_to_attotime(1));
67   checkpoint_live = cur_live;
68
69   live_run();
70}
71
72void amiga_fdc::checkpoint()
73{
74   checkpoint_live = cur_live;
75}
76
77void amiga_fdc::rollback()
78{
79   cur_live = checkpoint_live;
80}
81
82void amiga_fdc::live_delay(int state)
83{
84   cur_live.next_state = state;
85   t_gen->adjust(cur_live.tm - machine().time());
86}
87
88void amiga_fdc::live_sync()
89{
90   if(!cur_live.tm.is_never()) {
91      if(cur_live.tm > machine().time()) {
92         rollback();
93         live_run(machine().time());
94      } else {
95         if(cur_live.next_state != -1)
96            cur_live.state = cur_live.next_state;
97         if(cur_live.state == IDLE)
98            cur_live.tm = attotime::never;
99      }
100      cur_live.next_state = -1;
101      checkpoint();
102   }
103}
104
105void amiga_fdc::live_abort()
106{
107   cur_live.tm = attotime::never;
108   cur_live.state = IDLE;
109   cur_live.next_state = -1;
110}
111
112void amiga_fdc::live_run(attotime limit)
113{
114   if(cur_live.state == IDLE || cur_live.next_state != -1)
115      return;
116
117   for(;;) {
118      switch(cur_live.state) {
119      case RUNNING: {
120         int bit = cur_live.pll.get_next_bit(cur_live.tm, floppy, limit);
121         if(bit < 0)
122            return;
123         cur_live.shift_reg = (cur_live.shift_reg << 1) | bit;
124         cur_live.bit_counter++;
125
126         if((adkcon & 0x0200) && !(cur_live.shift_reg & 0x80))
127            cur_live.bit_counter--;
128
129         if(cur_live.bit_counter == 8) {
130            live_delay(RUNNING_SYNCPOINT);
131            return;
132         }
133         if(dskbyt & 0x0400) {
134            if(cur_live.shift_reg != dsksync) {
135               live_delay(RUNNING_SYNCPOINT);
136               return;
137            }
138         } else {
139            if(cur_live.shift_reg == dsksync) {
140               live_delay(RUNNING_SYNCPOINT);
141               return;
142            }
143         }
144         break;
145      }
146
147      case RUNNING_SYNCPOINT: {
148         if(cur_live.shift_reg == dsksync) {
149            if(adkcon & 0x0400) {
150               if(dma_state == DMA_WAIT_START)
151                  dma_state = DMA_RUNNING_BYTE_0;
152
153               cur_live.bit_counter = 0;
154            }
155            dskbyt |= 0x0400;
156            address_space *space = machine().device("maincpu")->memory().space(AS_PROGRAM);
157            amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKSYN, 0xffff);
158         } else
159            dskbyt &= ~0x0400;
160         
161         if(cur_live.bit_counter == 8) {
162            dskbyt = (dskbyt & 0xff00) | 0x8000 | (cur_live.shift_reg & 0xff);
163            cur_live.bit_counter = 0;
164
165            switch(dma_state) {
166            case DMA_IDLE:
167            case DMA_WAIT_START:
168               break;
169
170            case DMA_RUNNING_BYTE_0:
171               dma_value = (cur_live.shift_reg & 0xff) << 8;
172               dma_state = DMA_RUNNING_BYTE_1;
173               break;
174
175            case DMA_RUNNING_BYTE_1: {
176               dma_value |= cur_live.shift_reg & 0xff;
177
178               amiga_state *state = machine().driver_data<amiga_state>();
179               (*state->m_chip_ram_w)(state, dskpt, dma_value);
180
181               dskpt += 2;
182               dsklen--;
183               if(dsklen & 0x3fff)
184                  dma_state = DMA_RUNNING_BYTE_0;
185               else {
186                  dma_state = DMA_IDLE;
187                  address_space *space = machine().device("maincpu")->memory().space(AS_PROGRAM);
188                  amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
189               }
190               break;
191            }
192            }
193         }
194
195         cur_live.state = RUNNING;
196         checkpoint();
197         break;
198      }
199      }
200   }
201}
202
203bool amiga_fdc::dma_enabled()
204{
205   return (dsklen & 0x8000) && ((dmacon & 0x0210) == 0x0210);
206}
207
208void amiga_fdc::dma_check()
209{
210   if(dma_enabled() && (dsklen & 0x3fff)) {
211      if(dma_state == IDLE)
212         dma_state = adkcon & 0x0400 ? DMA_WAIT_START : DMA_RUNNING_BYTE_0;
213   } else
214      dma_state = IDLE;
215}
216
217void amiga_fdc::adkcon_set(UINT16 data)
218{
219   live_sync();
220   adkcon = data;
221}
222
223void amiga_fdc::dsklen_w(UINT16 data)
224{
225   live_sync();
226   if(!(data & 0x8000) || (data == pre_dsklen)) {
227      dsklen = pre_dsklen = data;
228      dma_check();
229
230      dskbyt = dskbyt & 0x9fff;
231      if(data & 0x4000)
232         dskbyt |= 0x2000;
233      if(dma_state != DMA_IDLE)
234         dskbyt |= 0x4000;
235   } else
236      pre_dsklen = data;
237}
238
239void amiga_fdc::dskpth_w(UINT16 data)
240{
241   live_sync();
242   dskpt = (dskpt & 0xffff) | (data << 16);
243}
244
245void amiga_fdc::dskptl_w(UINT16 data)
246{
247   live_sync();
248   dskpt = (dskpt & 0xffff0000) | data;
249}
250
251UINT16 amiga_fdc::dskpth_r()
252{
253   return dskpt >> 16;
254}
255
256UINT16 amiga_fdc::dskptl_r()
257{
258   return dskpt;
259}
260
261void amiga_fdc::dsksync_w(UINT16 data)
262{
263   live_sync();
264   dsksync = data;
265}
266
267void amiga_fdc::dmacon_set(UINT16 data)
268{
269   live_sync();
270   dmacon = data;
271   dma_check();
272   dskbyt = dskbyt & 0xbfff;
273   if(dma_state != DMA_IDLE)
274      dskbyt |= 0x4000;
275}
276
277UINT16 amiga_fdc::dskbytr_r()
278{
279   return dskbyt;
280}
281
282void amiga_fdc::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
283{
284   live_sync();
285   live_run();
286}
287
288void amiga_fdc::setup_leds()
289{
290   if(floppy) {
291      int drive =
292         floppy == floppy_devices[0] ? 0 :
293         floppy == floppy_devices[1] ? 1 :
294         floppy == floppy_devices[2] ? 2 :
295         3;
296
297      output_set_value("drive_0_led", drive == 0);
298      output_set_value("drive_1_led", drive == 1);
299      output_set_value("drive_2_led", drive == 2);
300      output_set_value("drive_3_led", drive == 3);
301
302      set_led_status(machine(), 1, drive == 0); /* update internal drive led */
303      set_led_status(machine(), 2, drive == 1); /* update external drive led */
304   }
305}
306
307WRITE8_MEMBER( amiga_fdc::ciaaprb_w )
308{
309   live_sync();
310
311   if(!(data & 0x08))
312      floppy = floppy_devices[0];
313   else if(!(data & 0x10))
314      floppy = floppy_devices[1];
315   else if(!(data & 0x20))
316      floppy = floppy_devices[2];
317   else if(!(data & 0x40))
318      floppy = floppy_devices[3];
319   else
320      floppy = 0;
321
322   if(floppy) {
323      floppy->ss_w(!((data >> 2) & 1));
324      floppy->dir_w((data >> 1) & 1);
325      floppy->stp_w(data & 1);
326      floppy->mon_w((data >> 7) & 1);
327   }
328
329   if(floppy) {
330      if(cur_live.state == IDLE)
331         live_start();
332   } else
333      live_abort();
334
335   setup_leds();
336}
337
338UINT8 amiga_fdc::ciaapra_r()
339{
340   UINT8 ret = 0x3c;
341   if(floppy) {
342      // fixit
343      ret &= ~0x20;
344
345      if(!floppy->trk00_r())
346         ret &= ~0x10;
347      if(!floppy->wpt_r())
348         ret &= ~0x08;
349      if(!floppy->dskchg_r())
350         ret &= ~0x04;
351   }
352   return ret;
353}
354
355void amiga_fdc::index_callback(floppy_image_device *floppy, int state)
356{
357   /* Issue a index pulse when a disk revolution completes */
358   device_t *cia = machine().device("cia_1");
359   mos6526_flag_w(cia, state);
360}
361
362void amiga_fdc::pll_t::set_clock(attotime period)
363{
364   for(int i=0; i<38; i++)
365      delays[i] = period*(i+1);
366}
367
368void amiga_fdc::pll_t::reset(attotime when)
369{
370   counter = 0;
371   increment = 146;
372   transition_time = 0xffff;
373   history = 0x80;
374   slot = 0;
375   ctime = when;
376   phase_add = 0x00;
377   phase_sub = 0x00;
378   freq_add  = 0x00;
379   freq_sub  = 0x00;
380}
381
382int amiga_fdc::pll_t::get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit)
383{
384   attotime when = floppy ? floppy->get_next_transition(ctime) : attotime::never;
385
386   for(;;) {
387      attotime etime = ctime+delays[slot];
388      if(etime > limit)
389         return -1;
390      if(transition_time == 0xffff && !when.is_never() && etime >= when)
391         transition_time = counter;
392      if(slot < 8) {
393         UINT8 mask = 1 << slot;
394         if(phase_add & mask)
395            counter += 258;
396         else if(phase_sub & mask)
397            counter += 34;
398         else
399            counter += increment;
400
401         if((freq_add & mask) && increment < 159)
402            increment++;
403         else if((freq_sub & mask) && increment > 134)
404            increment--;
405      } else
406         counter += increment;
407
408      slot++;
409      tm = etime;
410      if(counter & 0x800)
411         break;
412   }
413
414   int bit = transition_time != 0xffff;
415
416   if(transition_time != 0xffff) {
417      static const UINT8 pha[8] = { 0xf, 0x7, 0x3, 0x1, 0, 0, 0, 0 };
418      static const UINT8 phs[8] = { 0, 0, 0, 0, 0x1, 0x3, 0x7, 0xf };
419      static const UINT8 freqa[4][8] = {
420         { 0xf, 0x7, 0x3, 0x1, 0, 0, 0, 0 },
421         { 0x7, 0x3, 0x1, 0, 0, 0, 0, 0 },
422         { 0x7, 0x3, 0x1, 0, 0, 0, 0, 0 },
423         { 0, 0, 0, 0, 0, 0, 0, 0 }
424      };
425      static const UINT8 freqs[4][8] = {
426         { 0, 0, 0, 0, 0, 0, 0, 0 },
427         { 0, 0, 0, 0, 0, 0x1, 0x3, 0x7 },
428         { 0, 0, 0, 0, 0, 0x1, 0x3, 0x7 },
429         { 0, 0, 0, 0, 0x1, 0x3, 0x7, 0xf },
430      };
431
432      int cslot = transition_time >> 8;
433      phase_add = pha[cslot];
434      phase_sub = phs[cslot];
435      int way = transition_time & 0x400 ? 1 : 0;
436      if(history & 0x80)
437         history = way ? 0x80 : 0x83;
438      else if(history & 0x40)
439         history = way ? history & 2 : (history & 2) | 1;
440      freq_add = freqa[history & 3][cslot];
441      freq_sub = freqs[history & 3][cslot];
442      history = way ? (history >> 1) | 2 : history >> 1;
443
444   } else
445      phase_add = phase_sub = freq_add = freq_sub = 0;
446
447   counter &= 0x7ff;
448
449   ctime = tm;
450   transition_time = 0xffff;
451   slot = 0;
452
453   return bit;
454}
src/emu/machine/amigafdc.h
r0r13155
1#ifndef AMIGAFDC_H
2#define AMIGAFDC_H
3
4#include "emu.h"
5#include "imagedev/floppy.h"
6
7#define MCFG_AMIGA_FDC_ADD(_tag, _clock)   \
8   MCFG_DEVICE_ADD(_tag, AMIGA_FDC, _clock)
9
10class amiga_fdc : public device_t {
11public:
12   amiga_fdc(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
13
14   DECLARE_WRITE8_MEMBER(ciaaprb_w);
15
16   UINT8 ciaapra_r();
17   UINT16 dskbytr_r();
18   UINT16 dskpth_r();
19   UINT16 dskptl_r();
20
21   void dsksync_w(UINT16 data);
22   void dskpth_w(UINT16 data);
23   void dskptl_w(UINT16 data);
24   void dsklen_w(UINT16 data);
25   void adkcon_set(UINT16 data);
26   void dmacon_set(UINT16 data);
27
28   static const floppy_format_type floppy_formats[];
29
30protected:
31    virtual void device_start();
32    virtual void device_reset();
33   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
34
35private:
36   // Running states
37   enum {
38      IDLE,
39      RUNNING,
40      RUNNING_SYNCPOINT
41   };
42
43   // DMA states
44   enum {
45      DMA_IDLE,
46      DMA_WAIT_START,
47      DMA_RUNNING_BYTE_0,
48      DMA_RUNNING_BYTE_1
49   };
50
51   struct pll_t {
52      UINT16 counter;
53      UINT16 increment;
54      UINT16 transition_time;
55      UINT8 history;
56      UINT8 slot;
57      UINT8 phase_add, phase_sub, freq_add, freq_sub;
58      attotime ctime;
59
60      attotime delays[38];
61
62      void set_clock(attotime period);
63      void reset(attotime when);
64      int get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit);
65   };
66
67   struct live_info {
68      attotime tm;
69      int state, next_state;
70      UINT16 shift_reg;
71      int bit_counter;
72      pll_t pll;
73   };
74
75   floppy_image_device *floppy;
76   floppy_image_device *floppy_devices[4];
77
78   live_info cur_live, checkpoint_live;
79
80   emu_timer *t_gen;
81   UINT16 dsklen, pre_dsklen, dsksync, dskbyt, adkcon, dmacon;
82   UINT32 dskpt;
83   UINT16 dma_value;
84
85   int dma_state;
86
87   void setup_leds();
88   void index_callback(floppy_image_device *floppy, int state);
89   bool dma_enabled();
90   void dma_check();
91
92   void live_start();
93   void checkpoint();
94   void rollback();
95   void live_delay(int state);
96   void live_sync();
97   void live_abort();
98   void live_run(attotime limit = attotime::never);
99};
100
101extern const device_type AMIGA_FDC;
102
103#endif /* AMIGAFDC_H */
src/mess/tools/floptool/main.c
r13154r13155
1818#include "corestr.h"
1919
2020#include "formats/mfi_dsk.h"
21#include "formats/ipf_dsk.h"
22
2123#include "formats/hxcmfm_dsk.h"
2224#include "formats/ami_dsk.h"
2325#include "formats/st_dsk.h"
r13154r13155
2527
2628static floppy_format_type floppy_formats[] = {
2729   FLOPPY_MFI_FORMAT,
30   FLOPPY_IPF_FORMAT,
2831
2932   FLOPPY_MFM_FORMAT,
3033   FLOPPY_ADF_FORMAT,
src/mess/machine/amigafdc.c
r13154r13155
1/****************************************************f***********************
2
3    Amiga floppy disk controller emulation
4
5    - The drive spins at 300 RPM = 1 Rev every 200ms
6    - At 2usec per bit, that's 12500 bytes per track, or 6250 words per track
7    - At 4usec per bit, that's 6250 bytes per track, or 3125 words per track
8    - Each standard amiga sector has 544 words per sector, and 11 sectors per track = 11968 bytes
9    - ( 12500(max) - 11968(actual) ) = 532 per track gap bytes
10
11***************************************************************************/
12
13
14#include "emu.h"
15#include "includes/amiga.h"
16#include "formats/ami_dsk.h"
17#include "formats/hxcmfm_dsk.h"
18#include "formats/ipf_dsk.h"
19#include "formats/mfi_dsk.h"
20#include "amigafdc.h"
21#include "machine/6526cia.h"
22
23const device_type AMIGA_FDC = &device_creator<amiga_fdc>;
24
25const floppy_format_type amiga_fdc::floppy_formats[] = {
26   FLOPPY_ADF_FORMAT, FLOPPY_MFM_FORMAT, FLOPPY_IPF_FORMAT, FLOPPY_MFI_FORMAT,
27   NULL
28};
29
30
31amiga_fdc::amiga_fdc(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
32   device_t(mconfig, AMIGA_FDC, "Amiga FDC", tag, owner, clock)
33{
34}
35
36int amiga_fdc::get_drive(floppy_image_device *floppy)
37{
38   for(int id=0; id< NUM_DRIVES; id++)
39      if(floppy == fdc_status[id].f)
40         return id;
41   return -1;
42}
43
44int amiga_fdc::load_proc(floppy_image_device *floppy)
45{
46   int id = get_drive(floppy);
47   fdc_status[id].dma_timer->reset();
48   fdc_rdy = 0;
49
50   return IMAGE_INIT_PASS;
51}
52
53void amiga_fdc::unload_proc(floppy_image_device *floppy)
54{
55   int id = get_drive(floppy);
56   fdc_status[id].dma_timer->reset();
57   fdc_rdy = 0;
58}
59
60void amiga_fdc::device_start()
61{
62   for(int id=0; id< NUM_DRIVES; id++)
63   {
64      fdc_status[id].dma_timer = timer_alloc(id);
65      fdc_status[id].pos = 0;
66      fdc_status[id].len = 0;
67      fdc_status[id].ptr = 0;
68      fdc_status[id].f = downcast<floppy_image_device *>(subdevice(id ? "fd1" : "fd0"));
69      fdc_status[id].f->setup_load_cb(floppy_image_device::load_cb(FUNC(amiga_fdc::load_proc), this));
70      fdc_status[id].f->setup_unload_cb(floppy_image_device::unload_cb(FUNC(amiga_fdc::unload_proc), this));
71      fdc_status[id].f->setup_index_pulse_cb(floppy_image_device::index_pulse_cb(FUNC(amiga_fdc::index_callback), this));
72      fdc_status[id].tracklen = MAX_TRACK_BYTES;
73   }
74   fdc_sel = 0x0f;
75   fdc_rdy = 0;
76}
77
78
79void amiga_fdc::device_reset()
80{
81}
82
83int amiga_fdc::get_curpos(int drive)
84{
85   amiga_state *state = machine().driver_data<amiga_state>();
86   double elapsed;
87   int speed;
88   int   bytes;
89   int pos;
90
91   elapsed = fdc_status[drive].f->get_pos();
92   speed = ( CUSTOM_REG(REG_ADKCON) & 0x100 ) ? 2 : 4;
93
94   bytes = elapsed /  attotime::from_usec( speed * 8 ).as_double();
95   pos = bytes % ( fdc_status[drive].tracklen );
96
97   return pos;
98}
99
100UINT16 amiga_fdc::get_byte()
101{
102   amiga_state *state = machine().driver_data<amiga_state>();
103   int pos;
104   int i, drive = -1;
105   UINT16 ret;
106
107   ret = ( ( CUSTOM_REG(REG_DSKLEN) >> 1 ) & 0x4000 ) & ( ( CUSTOM_REG(REG_DMACON) << 10 ) & 0x4000 );
108   ret |= ( CUSTOM_REG(REG_DSKLEN) >> 1 ) & 0x2000;
109
110   for ( i = 0; i < NUM_DRIVES; i++ ) {
111      if ( !( fdc_sel & ( 1 << i ) ) )
112         drive = i;
113   }
114
115   if ( drive == -1 )
116      return ret;
117
118   setup_fdc_buffer(drive);
119
120   pos = get_curpos(drive);
121   if ( fdc_status[drive].mfm[pos] == ( CUSTOM_REG(REG_DSRSYNC) >> 8 ) &&
122       fdc_status[drive].mfm[pos+1] == ( CUSTOM_REG(REG_DSRSYNC) & 0xff ) )
123         ret |= 0x1000;
124
125   if ( pos != fdc_status[drive].pos ) {
126      ret |= 0x8000;
127      fdc_status[drive].pos = pos;
128   }
129
130   ret |= fdc_status[drive].mfm[pos];
131
132   return ret;
133}
134
135void amiga_fdc::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
136{
137
138   amiga_state *state = machine().driver_data<amiga_state>();
139   int drive = id;
140
141   /* if DMA got disabled by the time we got here, stop operations */
142   if ( ( CUSTOM_REG(REG_DSKLEN) & 0x8000 ) == 0 )
143      goto bail;
144
145   if ( ( CUSTOM_REG(REG_DMACON) & 0x0210 ) == 0 )
146      goto bail;
147
148   /* if floppy got ejected, also stop */
149   if ( fdc_status[drive].f->ready_r()==1)
150      goto bail;
151
152   setup_fdc_buffer(drive);
153
154   if ( CUSTOM_REG(REG_DSKLEN) & 0x4000 ) /* disk write case, unsupported yet */
155   {
156      if ( fdc_status[drive].len > 0 )
157      {
158         address_space *space = machine().device("maincpu")->memory().space(AS_PROGRAM);
159
160         logerror("Write to disk unsupported yet\n" );
161
162         amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
163      }
164   }
165   else
166   {
167      offs_t offset = fdc_status[drive].ptr;
168      int cur_pos = fdc_status[drive].pos;
169      int len = fdc_status[drive].len;
170
171      if ( len > MAX_WORDS_PER_DMA_CYCLE ) len = MAX_WORDS_PER_DMA_CYCLE;
172
173      fdc_status[drive].len -= len;
174
175      while ( len-- )
176      {
177         int dat = ( fdc_status[drive].mfm[cur_pos++] ) << 8;
178
179         cur_pos %= ( fdc_status[drive].tracklen );
180
181         dat |= fdc_status[drive].mfm[cur_pos++];
182
183         cur_pos %= ( fdc_status[drive].tracklen );
184
185         (*state->m_chip_ram_w)(state, offset, dat);
186
187         offset += 2;
188      }
189
190      fdc_status[drive].ptr = offset;
191      fdc_status[drive].pos = cur_pos;
192
193      if ( fdc_status[drive].len <= 0 )
194      {
195         address_space *space = machine().device("maincpu")->memory().space(AS_PROGRAM);
196
197         amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
198      }
199      else
200      {
201         int time;
202         double   len_words = fdc_status[drive].len;
203         if ( len_words > MAX_WORDS_PER_DMA_CYCLE ) len_words = MAX_WORDS_PER_DMA_CYCLE;
204
205         time = len_words * 2;
206         time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
207         time *= 8;
208         fdc_status[drive].dma_timer->adjust(attotime::from_usec( time ));
209         return;
210      }
211   }
212
213bail:
214   fdc_status[drive].dma_timer->reset();
215}
216
217void amiga_fdc::setup_dma()
218{
219   amiga_state *state = machine().driver_data<amiga_state>();
220   int i, cur_pos, drive = -1, len_words = 0;
221   int time = 0;
222
223   for ( i = 0; i < NUM_DRIVES; i++ ) {
224      if ( !( fdc_sel & ( 1 << i ) ) )
225         drive = i;
226   }
227
228   if ( drive == -1 ) {
229      address_space *space = machine().device("maincpu")->memory().space(AS_PROGRAM);
230
231      logerror("Disk DMA started with no drive selected!\n" );
232      amiga_custom_w(space, REG_INTREQ, 0x8000 | INTENA_DSKBLK, 0xffff);
233      return;
234   }
235
236   if ( ( CUSTOM_REG(REG_DSKLEN) & 0x8000 ) == 0 )
237      goto bail;
238
239   if ( ( CUSTOM_REG(REG_DMACON) & 0x0210 ) == 0 )
240      goto bail;
241
242   setup_fdc_buffer(drive);
243
244   fdc_status[drive].len = CUSTOM_REG(REG_DSKLEN) & 0x3fff;
245   fdc_status[drive].ptr = CUSTOM_REG_LONG(REG_DSKPTH);
246   fdc_status[drive].pos = cur_pos = get_curpos(drive);
247
248   /* we'll do a set amount at a time */
249   len_words = fdc_status[drive].len;
250   if ( len_words > MAX_WORDS_PER_DMA_CYCLE ) len_words = MAX_WORDS_PER_DMA_CYCLE;
251
252   if ( CUSTOM_REG(REG_ADKCON) & 0x0400 ) { /* Wait for sync */
253      if ( CUSTOM_REG(REG_DSRSYNC) != 0x4489 ) {
254         logerror("Attempting to read a non-standard SYNC\n" );
255      }
256
257      i = cur_pos;
258      do {
259         if ( fdc_status[drive].mfm[i] == ( CUSTOM_REG(REG_DSRSYNC) >> 8 ) &&
260             fdc_status[drive].mfm[i+1] == ( CUSTOM_REG(REG_DSRSYNC) & 0xff ) )
261               break;
262
263         i++;
264         i %= ( fdc_status[drive].tracklen );
265         time++;
266      } while( i != cur_pos );
267
268      if ( i == cur_pos && time != 0 ) {
269         logerror("SYNC not found on track!\n" );
270         return;
271      } else {
272         fdc_status[drive].pos = i + 2;
273         time += 2;
274      }
275   }
276
277   time += len_words * 2;
278   time *= ( CUSTOM_REG(REG_ADKCON) & 0x0100 ) ? 2 : 4;
279   time *= 8;
280   fdc_status[drive].dma_timer->adjust(attotime::from_usec(time));
281
282   return;
283
284bail:
285   fdc_status[drive].dma_timer->reset();
286}
287
288void amiga_fdc::advance(const UINT32 *trackbuf, UINT32 &cur_cell, UINT32 cell_count, UINT32 time)
289{
290   if(time >= 200000000) {
291      cur_cell = cell_count;
292      return;
293   }
294
295   while(cur_cell != cell_count-1 && (trackbuf[cur_cell+1] & floppy_image::TIME_MASK) < time)
296      cur_cell++;
297}
298
299UINT32 amiga_fdc::get_next_edge(const UINT32 *trackbuf, UINT32 cur_cell, UINT32 cell_count)
300{
301   if(cur_cell == cell_count)
302      return 200000000;
303   UINT32 cur_bit = trackbuf[cur_cell] & floppy_image::MG_MASK;
304   cur_cell++;
305   while(cur_cell != cell_count) {
306      UINT32 next_bit = trackbuf[cur_cell] & floppy_image::MG_MASK;
307      if(next_bit != cur_bit)
308         break;
309   }
310   return cur_cell == cell_count ? 200000000 : trackbuf[cur_cell] & floppy_image::TIME_MASK;
311}
312
313void amiga_fdc::setup_fdc_buffer(int drive)
314{
315   UINT8 *mfm = fdc_status[drive].mfm;
316   const UINT32 *trackbuf = fdc_status[drive].f->get_buffer();
317
318   UINT32 cur_cell = 0;
319   UINT32 cell_count = fdc_status[drive].f->get_len();
320   UINT32 pll_period = 2000;
321   UINT32 pll_phase = 0;
322   int bit = 0;
323   memset(mfm, 0, MAX_MFM_TRACK_LEN);
324
325   for(;;) {
326      advance(trackbuf, cur_cell, cell_count, pll_phase);
327      if(cur_cell == cell_count)
328         break;
329
330#if 0
331      printf("%09d: (%d, %09d) - (%d, %09d) - (%d, %09d)\n",
332            pll_phase,
333            trackbuf[cur_cell] >> floppy_image::MG_SHIFT, trackbuf[cur_cell] & floppy_image::TIME_MASK,
334            trackbuf[cur_cell+1] >> floppy_image::MG_SHIFT, trackbuf[cur_cell+1] & floppy_image::TIME_MASK,
335            trackbuf[cur_cell+2] >> floppy_image::MG_SHIFT, trackbuf[cur_cell+2] & floppy_image::TIME_MASK);
336#endif
337
338      UINT32 next_edge = get_next_edge(trackbuf, cur_cell, cell_count);
339
340      if(next_edge > pll_phase + pll_period) {
341         // free run, zero bit
342         // printf("%09d: %4d - Free run\n", pll_phase, pll_period);
343         pll_phase += pll_period;
344      } else {
345         // Transition in the window, one bit, adjust the period
346
347         mfm[bit >> 3] |= 0x80 >> (bit & 7);
348
349         INT32 delta = next_edge - (pll_phase + pll_period/2);
350         // printf("%09d: %4d - Delta = %d\n", pll_phase, pll_period, delta);
351
352         // The deltas should be lowpassed, the amplification factor tuned...
353         pll_period += delta/2;
354         pll_phase += pll_period;
355      }
356
357      bit++;
358   }
359   fdc_status[drive].tracklen = (bit+7)/8;
360}
361
362
363void amiga_fdc::setup_leds(int drive)
364{
365   char portname[12];
366   sprintf(portname, "drive_%d_led", drive);
367   int val = fdc_status[drive].f->ready_r() == 0 ? 0 : 1;
368   output_set_value(portname, val);
369
370   if ( drive == 0 )
371      set_led_status(machine(), 1, val); /* update internal drive led */
372
373   if ( drive == 1 )
374      set_led_status(machine(), 2, val); /* update external drive led */
375}
376
377WRITE8_MEMBER( amiga_fdc::control_w )
378{
379   int drive;
380
381   if ( fdc_sel != ( ( data >> 3 ) & 15 ) )
382      fdc_rdy = 0;
383   fdc_sel = ( data >> 3 ) & 15;
384
385   for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
386      if ( !( fdc_sel & ( 1 << drive ) ) ) {
387         fdc_status[drive].f->ss_w(( data >> 2 ) & 1);
388         fdc_status[drive].f->dir_w(( data >> 1 ) & 1);
389         fdc_status[drive].f->stp_w(data & 1);
390
391         fdc_status[drive].f->mon_w((( data >> 7 ) & 1)  );
392         setup_leds(drive);
393      }
394    }
395}
396
397UINT8 amiga_fdc::status_r()
398{
399   int drive = -1, ret = 0x3c;
400   for ( drive = 0; drive < NUM_DRIVES; drive++ ) {
401      if ( !(fdc_sel & ( 1 << drive ) ) ) {
402
403         if ( fdc_status[drive].f->ready_r()==0) {
404            if ( fdc_rdy ) ret &= ~0x20;
405            fdc_rdy = 1;
406         } else {
407            /* return drive id */
408            ret &= ~0x20;
409         }
410
411         if ( fdc_status[drive].f->trk00_r() == 0 )
412            ret &= ~0x10;
413
414         if ( fdc_status[drive].f->wpt_r()==0 )
415            ret &= ~0x08;
416
417         if ( fdc_status[drive].f->dskchg_r() == 0)
418            ret &= ~0x04;
419
420         return ret;
421      }
422   }
423
424   return ret;
425}
426
427void amiga_fdc::index_callback(floppy_image_device *floppy, int state)
428{
429   /* Issue a index pulse when a disk revolution completes */
430   device_t *cia = machine().device("cia_1");
431   mos6526_flag_w(cia, state);
432}
433
434static MACHINE_CONFIG_FRAGMENT( amiga_fdc )
435   MCFG_FLOPPY_DRIVE_ADD("fd0", floppy_image_device::TYPE_35_DD, 82, 2, amiga_fdc::floppy_formats)
436   MCFG_FLOPPY_DRIVE_ADD("fd1", floppy_image_device::TYPE_35_DD, 82, 2, amiga_fdc::floppy_formats)
437MACHINE_CONFIG_END
438
439machine_config_constructor amiga_fdc::device_mconfig_additions() const
440{
441   return MACHINE_CONFIG_NAME(amiga_fdc);
442}
src/mess/machine/amigafdc.h
r13154r13155
1#ifndef AMIGAFDC_H
2#define AMIGAFDC_H
3
4#include "emu.h"
5#include "imagedev/floppy.h"
6
7#define MCFG_AMIGA_FDC_ADD(_tag)   \
8   MCFG_DEVICE_ADD(_tag,  AMIGA_FDC, 0)
9
10class amiga_fdc : public device_t {
11public:
12   amiga_fdc(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
13
14   DECLARE_WRITE8_MEMBER( control_w );
15
16   UINT8 status_r();
17   UINT16 get_byte();
18   void setup_dma();
19
20   static const floppy_format_type floppy_formats[];
21
22protected:
23    virtual void device_start();
24    virtual void device_reset();
25   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
26   virtual machine_config_constructor device_mconfig_additions() const;
27
28private:
29   enum {
30      MAX_TRACK_BYTES         = 12500,
31      ACTUAL_TRACK_BYTES      = 11968,
32      GAP_TRACK_BYTES         = MAX_TRACK_BYTES - ACTUAL_TRACK_BYTES,
33      ONE_SECTOR_BYTES        = 544*2,
34      ONE_REV_TIME            = 200, /* ms */
35      MAX_WORDS_PER_DMA_CYCLE = 32, /* 64 bytes per dma cycle */
36      DISK_DETECT_DELAY       = 1,
37      MAX_TRACKS              = 160,
38      MAX_MFM_TRACK_LEN       = 16384,
39      NUM_DRIVES              = 2
40   };
41
42   struct fdc_def {
43      floppy_image_device *f;
44      int tracklen;
45      UINT8 mfm[MAX_MFM_TRACK_LEN];
46      emu_timer *dma_timer;
47      int pos;
48      int len;
49      offs_t ptr;
50   };
51
52   fdc_def fdc_status[NUM_DRIVES];
53
54   /* signals */
55   int fdc_sel;
56   int fdc_rdy;
57
58   void setup_fdc_buffer(int drive);
59   void setup_leds(int drive);
60   int get_drive(floppy_image_device *floppy);
61   int get_curpos(int drive);
62
63   int load_proc(floppy_image_device *floppy);
64   void unload_proc(floppy_image_device *floppy);
65   void index_callback(floppy_image_device *floppy, int state);
66   void advance(const UINT32 *trackbuf, UINT32 &cur_cell, UINT32 cell_count, UINT32 time);
67   UINT32 get_next_edge(const UINT32 *trackbuf, UINT32 cur_cell, UINT32 cell_count);
68};
69
70extern const device_type AMIGA_FDC;
71
72#endif /* AMIGAFDC_H */
src/mess/mess.mak
r13154r13155
599599   $(MESS_DRIVERS)/victor9k.o   \
600600
601601$(MESSOBJ)/amiga.a:            \
602   $(MESS_MACHINE)/amigafdc.o   \
603602   $(MESS_MACHINE)/amigacrt.o   \
604603   $(MESS_MACHINE)/amigacd.o   \
605604   $(MESS_MACHINE)/amigakbd.o   \
src/mess/drivers/amiga.c
r13154r13155
317317   DEVCB_DEVICE_HANDLER("centronics", amiga_cia_1_porta_r),
318318   DEVCB_NULL,                                    /* port A */
319319   DEVCB_NULL,
320   DEVCB_DEVICE_MEMBER("fdc", amiga_fdc, control_w)      /* port B */
320   DEVCB_DEVICE_MEMBER("fdc", amiga_fdc, ciaaprb_w)      /* port B */
321321};
322322
323323static const mos6526_interface cia_0_cdtv_intf =
r13154r13155
409409   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_NTSC_CLOCK / 10, cia_0_ntsc_intf)
410410   MCFG_MOS8520_ADD("cia_1", AMIGA_68000_NTSC_CLOCK, cia_1_intf)
411411
412   MCFG_AMIGA_FDC_ADD("fdc")
412   /* fdc */
413   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68000_NTSC_CLOCK)
414   MCFG_FLOPPY_DRIVE_ADD("fd0", floppy_image_device::TYPE_35_DD, 82, 2, amiga_fdc::floppy_formats)
415   MCFG_FLOPPY_DRIVE_ADD("fd1", floppy_image_device::TYPE_35_DD, 82, 2, amiga_fdc::floppy_formats)
413416MACHINE_CONFIG_END
414417
415418static MACHINE_CONFIG_DERIVED( a1000n, ntsc )
r13154r13155
460463   MCFG_DEVICE_REMOVE("cia_1")
461464   MCFG_MOS8520_ADD("cia_0", CDTV_CLOCK_X1 / 40, cia_0_cdtv_intf)
462465   MCFG_MOS8520_ADD("cia_1", CDTV_CLOCK_X1 / 4, cia_1_cdtv_intf)
466
467   /* fdc */
468   MCFG_DEVICE_MODIFY("fdc")
469   MCFG_DEVICE_CLOCK(CDTV_CLOCK_X1 / 4)
463470MACHINE_CONFIG_END
464471
465472
r13154r13155
469476   MCFG_CPU_MODIFY("maincpu")
470477   MCFG_CPU_CLOCK( AMIGA_68000_PAL_CLOCK)
471478
479   // Change the FDC clock too?
480
472481   MCFG_SCREEN_MODIFY("screen")
473482   MCFG_SCREEN_REFRESH_RATE(50)
474483   MCFG_SCREEN_SIZE(228*4, 312)
r13154r13155
477486   /* cia */
478487   MCFG_DEVICE_REMOVE("cia_0")
479488   MCFG_MOS8520_ADD("cia_0", AMIGA_68000_PAL_CLOCK / 10, cia_0_pal_intf)
489
490   /* fdc */
491   MCFG_DEVICE_MODIFY("fdc")
492   MCFG_DEVICE_CLOCK(AMIGA_68000_PAL_CLOCK)
480493MACHINE_CONFIG_END
481494
482495static MACHINE_CONFIG_DERIVED( a500p, pal )
r13154r13155
498511static READ8_DEVICE_HANDLER( amiga_cia_0_portA_r )
499512{
500513   UINT8 ret = input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
501   ret |= device->machine().device<amiga_fdc>("fdc")->status_r();
514   ret |= device->machine().device<amiga_fdc>("fdc")->ciaapra_r();
502515   return ret;
503516}
504517
r13154r13155
566579   }
567580}
568581
569static UINT16 amiga_read_dskbytr(running_machine &machine)
570{
571   return machine.device<amiga_fdc>("fdc")->get_byte();
572}
573
574static void amiga_write_dsklen(running_machine &machine, UINT16 data)
575{
576   amiga_state *state = machine.driver_data<amiga_state>();
577   if ( data & 0x8000 ) {
578      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
579         machine.device<amiga_fdc>("fdc")->setup_dma();
580   }
581}
582
583
584582static void amiga_reset(running_machine &machine)
585583{
586584   if (input_port_read(machine, "hardware") & 0x08)
r13154r13155
603601      ANGUS_CHIP_RAM_MASK,
604602      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
605603      NULL,                                    /* potgo_w */
606      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
607604      NULL,                                    /* serdat_w */
608605      NULL,                                    /* scanline0_callback */
609606      amiga_reset,                             /* reset_callback */
r13154r13155
636633      NULL, amiga_fdc_control_w,               /* CIA1 port A & B write */
637634      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
638635      NULL,                                    /* potgo_w */
639      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
640636      NULL,                                    /* serdat_w */
641637      NULL,                                    /* scanline0_callback */
642638      amiga_reset,                             /* reset_callback */
r13154r13155
666662      ECS_CHIP_RAM_MASK,
667663      amiga_read_joy0dat,   amiga_read_joy1dat,  /* joy0dat_r & joy1dat_r */
668664      NULL,                                    /* potgo_w */
669      amiga_read_dskbytr,   amiga_write_dsklen,  /* dskbytr_r & dsklen_w */
670665      NULL,                                    /* serdat_w */
671666      NULL,                                    /* scanline0_callback */
672667      NULL,                                    /* reset_callback */
src/mess/drivers/ami1200.c
r13154r13155
247247static READ8_DEVICE_HANDLER( a1200_cia_0_portA_r )
248248{
249249   UINT8 ret = input_port_read(device->machine(), "CIA0PORTA") & 0xc0;   /* Gameport 1 and 0 buttons */
250   ret |= device->machine().device<amiga_fdc>("fdc")->status_r();
250   ret |= device->machine().device<amiga_fdc>("fdc")->ciaapra_r();
251251   return ret;
252252}
253253
r13154r13155
275275   DEVCB_NULL,
276276   DEVCB_NULL,                           /* port A */
277277   DEVCB_NULL,
278   DEVCB_DEVICE_MEMBER("fdc", amiga_fdc, control_w)         /* port B */
278   DEVCB_DEVICE_MEMBER("fdc", amiga_fdc, ciaaprb_w)         /* port B */
279279};
280280
281281
r13154r13155
315315   MCFG_MOS8520_ADD("cia_0", AMIGA_68EC020_NTSC_CLOCK / 10, a1200_cia_0_intf)
316316   MCFG_MOS8520_ADD("cia_1", AMIGA_68EC020_NTSC_CLOCK / 10, a1200_cia_1_intf)
317317
318   MCFG_AMIGA_FDC_ADD("fdc")
318   /* fdc */
319   MCFG_AMIGA_FDC_ADD("fdc", AMIGA_68EC020_NTSC_CLOCK/2)
320   MCFG_FLOPPY_DRIVE_ADD("fd0", floppy_image_device::TYPE_35_DD, 82, 2, amiga_fdc::floppy_formats)
321   MCFG_FLOPPY_DRIVE_ADD("fd1", floppy_image_device::TYPE_35_DD, 82, 2, amiga_fdc::floppy_formats)
319322MACHINE_CONFIG_END
320323
321324static MACHINE_CONFIG_DERIVED( a1200p, a1200n )
r13154r13155
337340   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/20)
338341   MCFG_DEVICE_MODIFY("cia_1")
339342   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/20)
343
344   /* fdc */
345   MCFG_DEVICE_MODIFY("fdc")
346   MCFG_DEVICE_CLOCK(A1200PAL_XTAL_X1/4)
340347MACHINE_CONFIG_END
341348
342349
r13154r13155
368375
369376/***************************************************************************************************/
370377
371// these come directly from amiga.c
372
373static UINT16 a1200_read_dskbytr(running_machine &machine)
374{
375   return machine.device<amiga_fdc>("fdc")->get_byte();
376}
377
378static void a1200_write_dsklen(running_machine &machine, UINT16 data)
379{
380   cd32_state *state = machine.driver_data<cd32_state>();
381   if ( data & 0x8000 )
382   {
383      if ( CUSTOM_REG(REG_DSKLEN) & 0x8000 )
384         machine.device<amiga_fdc>("fdc")->setup_dma();
385   }
386}
387
388
389378static DRIVER_INIT( a1200 )
390379{
391380   cd32_state *state = machine.driver_data<cd32_state>();
r13154r13155
394383      AGA_CHIP_RAM_MASK,
395384      NULL, NULL,         /* joy0dat_r & joy1dat_r */
396385      cd32_potgo_w,      /* potgo_w */
397      a1200_read_dskbytr, a1200_write_dsklen, /* dskbytr_r & dsklen_w */
398386      NULL,            /* serdat_w */
399387      NULL,            /* scanline0_callback */
400388      NULL,            /* reset_callback */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team