Previous 15994 Revisions Next

r14906 Friday 13th April, 2012 at 21:31:11 UTC by R. Belmont
Apparently I've been forgetting this file for 3 weeks and nobody bothered to mention it. (nw)
[src/mess/devices]appldriv.c

src/mess/devices/appldriv.c
r14905r14906
1010#include "imagedev/flopdrv.h"
1111#include "formats/ap2_dsk.h"
1212
13// our parent's device is the Disk II card (Apple II) or main driver (Mac, IIgs)
14// either way, get the drive from there.                         
15#define PARENT_FLOPPY_0 "^floppy0"
16#define PARENT_FLOPPY_1 "^floppy1"
17#define PARENT_FLOPPY_2 "^floppy2"
18#define PARENT_FLOPPY_3 "^floppy3"
19
1320struct apple525_disk
1421{
1522   unsigned int state : 4;      /* bits 0-3 are the phase */
r14905r14906
3138
3239static int apple525_enable_mask = 1;
3340
41device_t *apple525_get_subdevice(device_t *device, int drive)
42{
43   switch(drive) {
44      case 0 : return device->subdevice(PARENT_FLOPPY_0);
45      case 1 : return device->subdevice(PARENT_FLOPPY_1);
46      case 2 : return device->subdevice(PARENT_FLOPPY_2);
47      case 3 : return device->subdevice(PARENT_FLOPPY_3);
48   }
49   return NULL;
50}
51
52device_t *apple525_get_device_by_type(device_t *device, int ftype, int drive)
53{
54   int i;
55   int cnt = 0;
56   for (i=0;i<4;i++) {
57      device_t *disk = apple525_get_subdevice(device, i);
58      if (floppy_get_drive_type(disk)==ftype) {
59         if (cnt==drive) {
60            return disk;
61         }
62         cnt++;
63      }
64   }
65   return NULL;
66}
67
3468void apple525_set_enable_lines(device_t *device,int enable_mask)
3569{
3670   apple525_enable_mask = enable_mask;
r14905r14906
135169   }
136170}
137171
138int apple525_get_count(running_machine &machine) {
172int apple525_get_count(device_t *device)
173{
139174   int cnt = 0;
140   if (machine.device(FLOPPY_0)!=NULL && flopimg_get_custom_data(machine.device(FLOPPY_0))!=NULL) cnt++;
141    if (machine.device(FLOPPY_1)!=NULL && flopimg_get_custom_data(machine.device(FLOPPY_1))!=NULL) cnt++;
142    if (machine.device(FLOPPY_2)!=NULL && flopimg_get_custom_data(machine.device(FLOPPY_2))!=NULL) cnt++;
143    if (machine.device(FLOPPY_3)!=NULL && flopimg_get_custom_data(machine.device(FLOPPY_3))!=NULL) cnt++;
144   return cnt;
175   if (device->subdevice("^"FLOPPY_0)!=NULL && flopimg_get_custom_data(device->subdevice(PARENT_FLOPPY_0))!=NULL) cnt++;
176    if (device->subdevice("^"FLOPPY_1)!=NULL && flopimg_get_custom_data(device->subdevice(PARENT_FLOPPY_1))!=NULL) cnt++;
177    if (device->subdevice("^"FLOPPY_2)!=NULL && flopimg_get_custom_data(device->subdevice(PARENT_FLOPPY_2))!=NULL) cnt++;
178    if (device->subdevice("^"FLOPPY_3)!=NULL && flopimg_get_custom_data(device->subdevice(PARENT_FLOPPY_3))!=NULL) cnt++;
179
180//    printf("%d apple525 drives\n", cnt);
181    return cnt;
145182}
146183
147void apple525_set_lines(device_t *device,UINT8 lines)
184void apple525_set_lines(device_t *device, UINT8 lines)
148185{
149186   int i, count;
150187   device_t *image;
151188
152   count = apple525_get_count(device->machine());
189   count = apple525_get_count(device);
153190   for (i = 0; i < count; i++)
154191   {
155192      if (apple525_enable_mask & (1 << i))
156193      {
157         image = floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_APPLE, i);
194         image = apple525_get_device_by_type(device, FLOPPY_TYPE_APPLE, i);
158195         if (image)
159196            apple525_disk_set_lines(device,image, lines);
160197      }
r14905r14906
212249   return read_value;
213250}
214251
215static device_t *apple525_selected_image(running_machine &machine)
252static device_t *apple525_selected_image(device_t *device)
216253{
217254   int i,count;
218255
219   count = apple525_get_count(machine);
256   count = apple525_get_count(device);
220257
221258   for (i = 0; i < count; i++)
222259   {
223260      if (apple525_enable_mask & (1 << i))
224         return floppy_get_device_by_type(machine, FLOPPY_TYPE_APPLE, i);
261         return apple525_get_device_by_type(device, FLOPPY_TYPE_APPLE, i);
225262   }
226263   return NULL;
227264}
r14905r14906
229266UINT8 apple525_read_data(device_t *device)
230267{
231268   device_t *image;
232   image = apple525_selected_image(device->machine());
269   image = apple525_selected_image(device);
233270   return image ? apple525_process_byte(image, -1) : 0xFF;
234271}
235272
236273void apple525_write_data(device_t *device,UINT8 data)
237274{
238275   device_t *image;
239   image = apple525_selected_image(device->machine());
276   image = apple525_selected_image(device);
240277   if (image)
241278      apple525_process_byte(image, data);
242279}
r14905r14906
246283   int i, count, result = 0;
247284   device_image_interface *image;
248285
249   count = apple525_get_count(device->machine());
286   count = apple525_get_count(device);
250287
251288   for (i = 0; i < count; i++)
252289   {
253290      if (apple525_enable_mask & (1 << i))
254291      {
255         image = dynamic_cast<device_image_interface *>(floppy_get_device_by_type(device->machine(), FLOPPY_TYPE_APPLE, i));
292         image = dynamic_cast<device_image_interface *>(apple525_get_device_by_type(device, FLOPPY_TYPE_APPLE, i));
256293         if (image && image->is_readonly())
257294            result = 1;
258295      }
r14905r14906
268305//-------------------------------------------------
269306
270307apple525_floppy_image_device::apple525_floppy_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
271    : legacy_floppy_image_device(mconfig, FLOPPY_APPLE, "Floppy Disk [Apple]", tag, owner, clock)
308    : legacy_floppy_image_device(mconfig, FLOPPY_APPLE, "Apple Disk II", tag, owner, clock)
272309{
273310}
274311

Previous 15994 Revisions Next


© 1998-2018 The MESS Team