src/mess/devices/appldriv.c
| r14905 | r14906 | |
| 10 | 10 | #include "imagedev/flopdrv.h" |
| 11 | 11 | #include "formats/ap2_dsk.h" |
| 12 | 12 | |
| 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 | |
| 13 | 20 | struct apple525_disk |
| 14 | 21 | { |
| 15 | 22 | unsigned int state : 4; /* bits 0-3 are the phase */ |
| r14905 | r14906 | |
| 31 | 38 | |
| 32 | 39 | static int apple525_enable_mask = 1; |
| 33 | 40 | |
| 41 | device_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 | |
| 52 | device_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 | |
| 34 | 68 | void apple525_set_enable_lines(device_t *device,int enable_mask) |
| 35 | 69 | { |
| 36 | 70 | apple525_enable_mask = enable_mask; |
| r14905 | r14906 | |
| 135 | 169 | } |
| 136 | 170 | } |
| 137 | 171 | |
| 138 | | int apple525_get_count(running_machine &machine) { |
| 172 | int apple525_get_count(device_t *device) |
| 173 | { |
| 139 | 174 | 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; |
| 145 | 182 | } |
| 146 | 183 | |
| 147 | | void apple525_set_lines(device_t *device,UINT8 lines) |
| 184 | void apple525_set_lines(device_t *device, UINT8 lines) |
| 148 | 185 | { |
| 149 | 186 | int i, count; |
| 150 | 187 | device_t *image; |
| 151 | 188 | |
| 152 | | count = apple525_get_count(device->machine()); |
| 189 | count = apple525_get_count(device); |
| 153 | 190 | for (i = 0; i < count; i++) |
| 154 | 191 | { |
| 155 | 192 | if (apple525_enable_mask & (1 << i)) |
| 156 | 193 | { |
| 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); |
| 158 | 195 | if (image) |
| 159 | 196 | apple525_disk_set_lines(device,image, lines); |
| 160 | 197 | } |
| r14905 | r14906 | |
| 212 | 249 | return read_value; |
| 213 | 250 | } |
| 214 | 251 | |
| 215 | | static device_t *apple525_selected_image(running_machine &machine) |
| 252 | static device_t *apple525_selected_image(device_t *device) |
| 216 | 253 | { |
| 217 | 254 | int i,count; |
| 218 | 255 | |
| 219 | | count = apple525_get_count(machine); |
| 256 | count = apple525_get_count(device); |
| 220 | 257 | |
| 221 | 258 | for (i = 0; i < count; i++) |
| 222 | 259 | { |
| 223 | 260 | 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); |
| 225 | 262 | } |
| 226 | 263 | return NULL; |
| 227 | 264 | } |
| r14905 | r14906 | |
| 229 | 266 | UINT8 apple525_read_data(device_t *device) |
| 230 | 267 | { |
| 231 | 268 | device_t *image; |
| 232 | | image = apple525_selected_image(device->machine()); |
| 269 | image = apple525_selected_image(device); |
| 233 | 270 | return image ? apple525_process_byte(image, -1) : 0xFF; |
| 234 | 271 | } |
| 235 | 272 | |
| 236 | 273 | void apple525_write_data(device_t *device,UINT8 data) |
| 237 | 274 | { |
| 238 | 275 | device_t *image; |
| 239 | | image = apple525_selected_image(device->machine()); |
| 276 | image = apple525_selected_image(device); |
| 240 | 277 | if (image) |
| 241 | 278 | apple525_process_byte(image, data); |
| 242 | 279 | } |
| r14905 | r14906 | |
| 246 | 283 | int i, count, result = 0; |
| 247 | 284 | device_image_interface *image; |
| 248 | 285 | |
| 249 | | count = apple525_get_count(device->machine()); |
| 286 | count = apple525_get_count(device); |
| 250 | 287 | |
| 251 | 288 | for (i = 0; i < count; i++) |
| 252 | 289 | { |
| 253 | 290 | if (apple525_enable_mask & (1 << i)) |
| 254 | 291 | { |
| 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)); |
| 256 | 293 | if (image && image->is_readonly()) |
| 257 | 294 | result = 1; |
| 258 | 295 | } |
| r14905 | r14906 | |
| 268 | 305 | //------------------------------------------------- |
| 269 | 306 | |
| 270 | 307 | apple525_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) |
| 272 | 309 | { |
| 273 | 310 | } |
| 274 | 311 | |