src/mess/machine/micropolis.c
| r15332 | r15333 | |
| 12 | 12 | |
| 13 | 13 | ToDo: |
| 14 | 14 | - Rewrite to be a standard device able to be used in a general way |
| 15 | | - Support the ability to write to disk. |
| 15 | - Fix bug where if you run a program on drive B,C,D then exit, you |
| 16 | get a disk error. |
| 17 | - Enable the ability to write to disk when above bug gets fixed. |
| 18 | - When the controller is reset via command 5, what exactly gets reset? |
| 16 | 19 | |
| 17 | 20 | |
| 18 | 21 | Ports: |
| 19 | 22 | BE00 and BE01 can be used as command registers (they are identical), |
| 20 | 23 | and they are also used as status registers (different). |
| 21 | 24 | |
| 22 | | BE02 - read data |
| 23 | | BE03 - unknown |
| 25 | BE02 and BE03 - read data, write data |
| 24 | 26 | |
| 25 | | Write data is unknown but could either be BE02 or BE03. |
| 26 | | |
| 27 | 27 | ***************************************************************************/ |
| 28 | 28 | |
| 29 | 29 | |
| r15332 | r15333 | |
| 37 | 37 | ***************************************************************************/ |
| 38 | 38 | |
| 39 | 39 | |
| 40 | | #define STAT_MOTOR_ON 0x20 |
| 40 | #define STAT_RFC 0x20 |
| 41 | 41 | #define STAT_TRACK0 0x08 |
| 42 | 42 | #define STAT_READY 0x80 |
| 43 | 43 | |
| r15332 | r15333 | |
| 158 | 158 | INTERFACE |
| 159 | 159 | ***************************************************************************/ |
| 160 | 160 | |
| 161 | | /* use this to determine which drive is controlled by WD */ |
| 161 | /* select a drive */ |
| 162 | 162 | void micropolis_set_drive(device_t *device, UINT8 drive) |
| 163 | 163 | { |
| 164 | 164 | micropolis_state *w = get_safe_token(device); |
| r15332 | r15333 | |
| 166 | 166 | if (VERBOSE) |
| 167 | 167 | logerror("micropolis_set_drive: $%02x\n", drive); |
| 168 | 168 | |
| 169 | | if (w->intf->floppy_drive_tags[drive] != NULL) |
| 170 | | { |
| 171 | | if (device->owner() != NULL) { |
| 172 | | w->drive = device->owner()->subdevice(w->intf->floppy_drive_tags[drive]); |
| 173 | | if (w->drive == NULL) { |
| 174 | | w->drive = device->machine().device(w->intf->floppy_drive_tags[drive]); |
| 175 | | } |
| 176 | | } |
| 177 | | else |
| 178 | | w->drive = device->machine().device(w->intf->floppy_drive_tags[drive]); |
| 179 | | } |
| 169 | if (w->intf->floppy_drive_tags[drive]) |
| 170 | w->drive = device->siblingdevice(w->intf->floppy_drive_tags[drive]); |
| 180 | 171 | } |
| 181 | 172 | |
| 182 | 173 | |
| r15332 | r15333 | |
| 195 | 186 | return w->status | w->drive_num; |
| 196 | 187 | else |
| 197 | 188 | { |
| 189 | // FIXME - find out what controls current sector |
| 198 | 190 | w->sector = (w->sector + 3 + inv) & 15; |
| 199 | 191 | micropolis_read_sector(device); |
| 200 | 192 | inv ^= 1; |
| r15332 | r15333 | |
| 217 | 209 | /* write the FDC command register */ |
| 218 | 210 | WRITE8_DEVICE_HANDLER( micropolis_command_w ) |
| 219 | 211 | { |
| 212 | /* List of commands: |
| 213 | Command (bits 5,6,7) Options (bits 0,1,2,3,4) |
| 214 | 0 Not used |
| 215 | 1 Drive/head select bits 0,1 select drive 0-3; bit 4 chooses a side |
| 216 | 2 INT sector control bit 0 LO = disable; HI = enable |
| 217 | 3 Step bit 0 LO step out; HI = step in (increment track number) |
| 218 | 4 Set Write |
| 219 | 5 Reset controller |
| 220 | 6 Not used |
| 221 | 7 Not used */ |
| 222 | |
| 220 | 223 | micropolis_state *w = get_safe_token(device); |
| 221 | 224 | int direction = 0; |
| 222 | 225 | |
| 223 | | if ((data & 0x60)==0x20) |
| 226 | switch (data >> 5) |
| 224 | 227 | { |
| 228 | case 1: |
| 225 | 229 | w->drive_num = data & 3; |
| 226 | | floppy_mon_w(w->drive, ASSERT_LINE); // turn off the old drive |
| 230 | floppy_mon_w(w->drive, 1); // turn off the old drive |
| 227 | 231 | micropolis_set_drive(device, w->drive_num); // select new drive |
| 228 | | floppy_mon_w(w->drive, CLEAR_LINE); // turn it on |
| 232 | floppy_mon_w(w->drive, 0); // turn it on |
| 233 | break; |
| 234 | case 2: // not emulated, not used in sorcerer |
| 235 | break; |
| 236 | case 3: |
| 237 | if (BIT(data, 0)) |
| 238 | { |
| 239 | if (w->track < 77) |
| 240 | { |
| 241 | w->track++; |
| 242 | direction = 1; |
| 243 | } |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | if (w->track) |
| 248 | { |
| 249 | w->track--; |
| 250 | direction = -1; |
| 251 | } |
| 252 | } |
| 253 | break; |
| 254 | case 4: // not emulated, to be done |
| 255 | break; |
| 256 | case 5: // not emulated, to be done |
| 257 | break; |
| 229 | 258 | } |
| 230 | 259 | |
| 231 | | w->status = 0; |
| 232 | 260 | |
| 261 | w->status = STAT_RFC; |
| 262 | |
| 233 | 263 | if (BIT(data, 5)) |
| 234 | | w->status = STAT_MOTOR_ON | STAT_READY; |
| 264 | w->status |= STAT_READY; |
| 235 | 265 | |
| 236 | 266 | floppy_drive_set_ready_state(w->drive, 1,0); |
| 237 | 267 | |
| 238 | | if ((data & 0x41) == 0x41) |
| 239 | | { |
| 240 | | if (w->track < 77) |
| 241 | | { |
| 242 | | w->track++; |
| 243 | | direction = 1; |
| 244 | | } |
| 245 | | } |
| 246 | | else |
| 247 | | if ((data & 0x41) == 0x40) |
| 248 | | { |
| 249 | | if (w->track) |
| 250 | | { |
| 251 | | w->track--; |
| 252 | | direction = -1; |
| 253 | | } |
| 254 | | } |
| 255 | 268 | |
| 256 | 269 | if (!w->track) |
| 257 | 270 | w->status |= STAT_TRACK0; |
| r15332 | r15333 | |
| 296 | 309 | { |
| 297 | 310 | case 0: data = micropolis_status_r(device, 0); break; |
| 298 | 311 | case 1: data = micropolis_status_r(device, 1); break; |
| 299 | | case 2: data = micropolis_data_r(device, 0); break; |
| 300 | | case 3: data = 0; break; |
| 312 | case 2: |
| 313 | case 3: data = micropolis_data_r(device, 0); break; |
| 301 | 314 | } |
| 302 | 315 | |
| 303 | 316 | return data; |
| r15332 | r15333 | |
| 307 | 320 | { |
| 308 | 321 | switch (offset & 0x03) |
| 309 | 322 | { |
| 310 | | case 0: micropolis_command_w(device, 0, data); break; |
| 311 | | case 1: micropolis_command_w(device, 1, data); break; |
| 312 | | case 2: break; |
| 323 | case 0: |
| 324 | case 1: micropolis_command_w(device, 0, data); break; |
| 325 | case 2: |
| 313 | 326 | case 3: micropolis_data_w(device, 0, data); break; |
| 314 | 327 | } |
| 315 | 328 | } |
| r15332 | r15333 | |
| 333 | 346 | micropolis_state *w = get_safe_token(device); |
| 334 | 347 | int i; |
| 335 | 348 | |
| 336 | | /* set the default state of some input lines */ |
| 337 | 349 | for (i = 0; i < 4; i++) |
| 338 | 350 | { |
| 339 | | if(w->intf->floppy_drive_tags[i]!=NULL) { |
| 351 | if(w->intf->floppy_drive_tags[i]) |
| 352 | { |
| 340 | 353 | device_t *img = NULL; |
| 341 | 354 | |
| 342 | | if (device->owner() != NULL) |
| 343 | | img = device->owner()->subdevice(w->intf->floppy_drive_tags[i]); |
| 344 | | if (img == NULL) { |
| 345 | | img = device->machine().device(w->intf->floppy_drive_tags[i]); |
| 346 | | } |
| 355 | img = device->siblingdevice(w->intf->floppy_drive_tags[i]); |
| 347 | 356 | |
| 348 | | else |
| 349 | | img = device->machine().device(w->intf->floppy_drive_tags[i]); |
| 350 | | |
| 351 | | if (img!=NULL) { |
| 357 | if (img) |
| 358 | { |
| 352 | 359 | floppy_drive_set_controller(img,device); |
| 360 | //floppy_drive_set_index_pulse_callback(img, wd17xx_index_pulse_callback); |
| 353 | 361 | floppy_drive_set_rpm( img, 300.); |
| 354 | 362 | } |
| 355 | 363 | } |
| r15332 | r15333 | |
| 361 | 369 | w->sector = 0; |
| 362 | 370 | w->track = 0; |
| 363 | 371 | w->sector_length = 270; |
| 364 | | w->status = 0; |
| 372 | w->status = STAT_TRACK0; |
| 365 | 373 | } |
| 366 | 374 | |
| 367 | 375 | void micropolis_reset(device_t *device) |