src/mess/machine/i8257.c
| r11186 | r11187 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | Intel 8257 Programmable DMA Controller emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | ***************************************************************************/ |
| 9 | | |
| 10 | | /* |
| 11 | | |
| 12 | | TODO: |
| 13 | | |
| 14 | | - use cr/ar directly |
| 15 | | |
| 16 | | */ |
| 17 | | |
| 18 | | #include "emu.h" |
| 19 | | #include "i8257.h" |
| 20 | | |
| 21 | | /*************************************************************************** |
| 22 | | CONSTANTS |
| 23 | | ***************************************************************************/ |
| 24 | | |
| 25 | | #define LOG 0 |
| 26 | | |
| 27 | | #define I8257_STATUS_TC0 0x01 |
| 28 | | #define I8257_STATUS_TC1 0x02 |
| 29 | | #define I8257_STATUS_TC2 0x04 |
| 30 | | #define I8257_STATUS_TC3 0x08 |
| 31 | | #define I8257_STATUS_UP 0x10 |
| 32 | | |
| 33 | | #define I8257_MODE_EN0 0x01 |
| 34 | | #define I8257_MODE_EN1 0x02 |
| 35 | | #define I8257_MODE_EN2 0x04 |
| 36 | | #define I8257_MODE_EN3 0x08 |
| 37 | | #define I8257_MODE_RP 0x10 |
| 38 | | #define I8257_MODE_EW 0x20 |
| 39 | | #define I8257_MODE_TCS 0x40 |
| 40 | | #define I8257_MODE_AL 0x80 |
| 41 | | |
| 42 | | enum |
| 43 | | { |
| 44 | | STATE_SI, |
| 45 | | STATE_S0, |
| 46 | | STATE_S1, |
| 47 | | STATE_S2, |
| 48 | | STATE_S3, |
| 49 | | STATE_SW, |
| 50 | | STATE_SU, |
| 51 | | STATE_S4 |
| 52 | | }; |
| 53 | | |
| 54 | | enum |
| 55 | | { |
| 56 | | MODE_VERIFY = 0, |
| 57 | | MODE_WRITE, |
| 58 | | MODE_READ, |
| 59 | | MODE_ILLEGAL |
| 60 | | }; |
| 61 | | |
| 62 | | /*************************************************************************** |
| 63 | | TYPE DEFINITIONS |
| 64 | | ***************************************************************************/ |
| 65 | | |
| 66 | | typedef struct _dma8257_t i8257_t; |
| 67 | | struct _dma8257_t |
| 68 | | { |
| 69 | | devcb_resolved_write_line out_hrq_func; |
| 70 | | devcb_resolved_write_line out_tc_func; |
| 71 | | devcb_resolved_write_line out_mark_func; |
| 72 | | devcb_resolved_read8 in_memr_func[I8257_CHANNELS]; |
| 73 | | devcb_resolved_write8 out_memw_func[I8257_CHANNELS]; |
| 74 | | devcb_resolved_read8 in_ior_func[I8257_CHANNELS]; |
| 75 | | devcb_resolved_write8 out_iow_func[I8257_CHANNELS]; |
| 76 | | devcb_resolved_write_line out_dack_func[I8257_CHANNELS]; |
| 77 | | |
| 78 | | /* registers */ |
| 79 | | UINT8 mr; /* mode register */ |
| 80 | | UINT8 sr; /* status register */ |
| 81 | | UINT16 ar[I8257_CHANNELS]; /* address register */ |
| 82 | | UINT16 cr[I8257_CHANNELS]; /* count register */ |
| 83 | | int fl; /* first/last flip-flop */ |
| 84 | | |
| 85 | | /* inputs */ |
| 86 | | int drq[I8257_CHANNELS]; /* data request */ |
| 87 | | int hlda; /* hold acknowledge */ |
| 88 | | int ready; /* ready */ |
| 89 | | |
| 90 | | /* outputs */ |
| 91 | | int tc; /* terminal count */ |
| 92 | | int mark; /* mark */ |
| 93 | | |
| 94 | | /* transfer */ |
| 95 | | int state; /* DMA state */ |
| 96 | | int channel; /* current channel being serviced */ |
| 97 | | int priority; /* highest priority channel */ |
| 98 | | UINT8 data; /* DMA data */ |
| 99 | | UINT16 address; /* DMA address */ |
| 100 | | UINT16 count; /* DMA counter */ |
| 101 | | int mode; /* DMA transfer type */ |
| 102 | | |
| 103 | | /* timers */ |
| 104 | | emu_timer *dma_timer; |
| 105 | | }; |
| 106 | | |
| 107 | | /*************************************************************************** |
| 108 | | INLINE FUNCTIONS |
| 109 | | ***************************************************************************/ |
| 110 | | |
| 111 | | INLINE i8257_t *get_safe_token(device_t *device) |
| 112 | | { |
| 113 | | assert(device != NULL); |
| 114 | | assert(device->type() == I8257); |
| 115 | | return (i8257_t *) downcast<legacy_device_base *>(device)->token(); |
| 116 | | } |
| 117 | | |
| 118 | | INLINE const i8257_interface *get_interface(device_t *device) |
| 119 | | { |
| 120 | | assert(device != NULL); |
| 121 | | assert((device->type() == I8257)); |
| 122 | | return (const i8257_interface *) device->baseconfig().static_config(); |
| 123 | | } |
| 124 | | |
| 125 | | /*************************************************************************** |
| 126 | | IMPLEMENTATION |
| 127 | | ***************************************************************************/ |
| 128 | | |
| 129 | | static void set_hrq(device_t *device, int state) |
| 130 | | { |
| 131 | | i8257_t *i8257 = get_safe_token(device); |
| 132 | | |
| 133 | | if (LOG) logerror("I8257 '%s' Hold Request: %u\n", device->tag(), state); |
| 134 | | |
| 135 | | devcb_call_write_line(&i8257->out_hrq_func, state); |
| 136 | | } |
| 137 | | |
| 138 | | static void set_tc(device_t *device, int state) |
| 139 | | { |
| 140 | | i8257_t *i8257 = get_safe_token(device); |
| 141 | | |
| 142 | | if (i8257->tc != state) |
| 143 | | { |
| 144 | | if (LOG) logerror("I8257 '%s' Terminal Count: %u\n", device->tag(), state); |
| 145 | | i8257->tc = state; |
| 146 | | devcb_call_write_line(&i8257->out_tc_func, state); |
| 147 | | } |
| 148 | | } |
| 149 | | |
| 150 | | static void set_mark(device_t *device, int state) |
| 151 | | { |
| 152 | | i8257_t *i8257 = get_safe_token(device); |
| 153 | | |
| 154 | | if (i8257->mark != state) |
| 155 | | { |
| 156 | | if (LOG) logerror("I8257 '%s' Mark: %u\n", device->tag(), state); |
| 157 | | i8257->mark = state; |
| 158 | | devcb_call_write_line(&i8257->out_mark_func, state); |
| 159 | | } |
| 160 | | } |
| 161 | | |
| 162 | | static void set_dack(device_t *device, int active_channel) |
| 163 | | { |
| 164 | | i8257_t *i8257 = get_safe_token(device); |
| 165 | | int ch; |
| 166 | | |
| 167 | | for (ch = 0; ch < I8257_CHANNELS; ch++) |
| 168 | | { |
| 169 | | int state = (ch != active_channel); |
| 170 | | |
| 171 | | if (LOG) logerror("I8257 '%s' DMA Acknowledge %u: %u\n", device->tag(), ch, state); |
| 172 | | |
| 173 | | devcb_call_write_line(&i8257->out_dack_func[ch], state); |
| 174 | | } |
| 175 | | } |
| 176 | | |
| 177 | | static int sample_drq(device_t *device) |
| 178 | | { |
| 179 | | i8257_t *i8257 = get_safe_token(device); |
| 180 | | int ch; |
| 181 | | |
| 182 | | for (ch = 0; ch < I8257_CHANNELS; ch++) |
| 183 | | { |
| 184 | | if (i8257->drq[ch] && BIT(i8257->mr, ch)) |
| 185 | | { |
| 186 | | return 1; |
| 187 | | } |
| 188 | | } |
| 189 | | |
| 190 | | return 0; |
| 191 | | } |
| 192 | | |
| 193 | | static void resolve_priorities(device_t *device) |
| 194 | | { |
| 195 | | i8257_t *i8257 = get_safe_token(device); |
| 196 | | int i; |
| 197 | | |
| 198 | | for (i = 0; i < I8257_CHANNELS; i++) |
| 199 | | { |
| 200 | | int ch = (i + i8257->priority) % I8257_CHANNELS; |
| 201 | | |
| 202 | | if (i8257->drq[ch] && BIT(i8257->mr, ch)) |
| 203 | | { |
| 204 | | i8257->channel = ch; |
| 205 | | i8257->address = i8257->ar[ch]; |
| 206 | | i8257->count = i8257->cr[ch] & 0x3fff; |
| 207 | | i8257->mode = i8257->cr[ch] >> 14; |
| 208 | | break; |
| 209 | | } |
| 210 | | } |
| 211 | | } |
| 212 | | |
| 213 | | static void dma_read(device_t *device) |
| 214 | | { |
| 215 | | i8257_t *i8257 = get_safe_token(device); |
| 216 | | |
| 217 | | switch (i8257->mode) |
| 218 | | { |
| 219 | | case MODE_VERIFY: |
| 220 | | break; |
| 221 | | |
| 222 | | case MODE_WRITE: |
| 223 | | i8257->data = devcb_call_read8(&i8257->in_memr_func[i8257->channel], i8257->address); |
| 224 | | if (LOG) logerror("I8257 '%s' DMA Memory Read %04x: %02x\n", device->tag(), i8257->address, i8257->data); |
| 225 | | break; |
| 226 | | |
| 227 | | case MODE_READ: |
| 228 | | i8257->data = devcb_call_read8(&i8257->in_ior_func[i8257->channel], i8257->address); |
| 229 | | if (LOG) logerror("I8257 '%s' DMA I/O Read %04x: %02x\n", device->tag(), i8257->address, i8257->data); |
| 230 | | break; |
| 231 | | |
| 232 | | case MODE_ILLEGAL: |
| 233 | | break; |
| 234 | | } |
| 235 | | } |
| 236 | | |
| 237 | | static void dma_write(device_t *device) |
| 238 | | { |
| 239 | | i8257_t *i8257 = get_safe_token(device); |
| 240 | | |
| 241 | | switch (i8257->mode) |
| 242 | | { |
| 243 | | case MODE_VERIFY: |
| 244 | | break; |
| 245 | | |
| 246 | | case MODE_WRITE: |
| 247 | | devcb_call_write8(&i8257->out_iow_func[i8257->channel], i8257->address, i8257->data); |
| 248 | | if (LOG) logerror("I8257 '%s' DMA I/O Write %04x: %02x\n", device->tag(), i8257->address, i8257->data); |
| 249 | | break; |
| 250 | | |
| 251 | | case MODE_READ: |
| 252 | | devcb_call_write8(&i8257->out_memw_func[i8257->channel], i8257->address, i8257->data); |
| 253 | | if (LOG) logerror("I8257 '%s' DMA Memory Write %04x: %02x\n", device->tag(), i8257->address, i8257->data); |
| 254 | | break; |
| 255 | | |
| 256 | | case MODE_ILLEGAL: |
| 257 | | break; |
| 258 | | } |
| 259 | | } |
| 260 | | |
| 261 | | /*------------------------------------------------- |
| 262 | | TIMER_CALLBACK( dma_tick ) |
| 263 | | -------------------------------------------------*/ |
| 264 | | |
| 265 | | static TIMER_CALLBACK( dma_tick ) |
| 266 | | { |
| 267 | | device_t *device = (device_t *)ptr; |
| 268 | | i8257_t *i8257 = get_safe_token(device); |
| 269 | | int drq = 0; |
| 270 | | |
| 271 | | switch (i8257->state) |
| 272 | | { |
| 273 | | case STATE_SI: |
| 274 | | /* sample DRQn lines */ |
| 275 | | drq = sample_drq(device); |
| 276 | | |
| 277 | | /* set HRQ if DRQn = 1 */ |
| 278 | | if (drq) |
| 279 | | { |
| 280 | | set_hrq(device, 1); |
| 281 | | i8257->state = STATE_S0; |
| 282 | | } |
| 283 | | break; |
| 284 | | |
| 285 | | case STATE_S0: |
| 286 | | /* sample HLDA */ |
| 287 | | if (i8257->hlda) |
| 288 | | { |
| 289 | | i8257->state = STATE_S1; |
| 290 | | } |
| 291 | | |
| 292 | | /* resolve DRQ priorities */ |
| 293 | | resolve_priorities(device); |
| 294 | | break; |
| 295 | | |
| 296 | | case STATE_S1: |
| 297 | | /* present and data upper address */ |
| 298 | | /* present lower address */ |
| 299 | | i8257->state = STATE_S2; |
| 300 | | break; |
| 301 | | |
| 302 | | case STATE_S2: |
| 303 | | /* activate DACKn */ |
| 304 | | set_dack(device, i8257->channel); |
| 305 | | |
| 306 | | /* activate read command */ |
| 307 | | dma_read(device); |
| 308 | | |
| 309 | | /* advanced write command */ |
| 310 | | if (i8257->mr & I8257_MODE_EW) |
| 311 | | { |
| 312 | | dma_write(device); |
| 313 | | } |
| 314 | | |
| 315 | | i8257->state = STATE_S3; |
| 316 | | break; |
| 317 | | |
| 318 | | case STATE_S3: |
| 319 | | /* activate write command */ |
| 320 | | if (!(i8257->mr & I8257_MODE_EW)) |
| 321 | | { |
| 322 | | dma_write(device); |
| 323 | | } |
| 324 | | |
| 325 | | i8257->address++; |
| 326 | | i8257->count--; |
| 327 | | |
| 328 | | /* activate MARK */ |
| 329 | | switch (i8257->count & 0xff) |
| 330 | | { |
| 331 | | case 0: case 0x80: |
| 332 | | set_mark(device, 1); |
| 333 | | break; |
| 334 | | } |
| 335 | | |
| 336 | | /* activate TC */ |
| 337 | | if (i8257->count == 0) |
| 338 | | { |
| 339 | | set_tc(device, 1); |
| 340 | | } |
| 341 | | |
| 342 | | if (!i8257->ready) |
| 343 | | { |
| 344 | | i8257->state = STATE_SW; |
| 345 | | } |
| 346 | | else if (i8257->tc && (i8257->channel == 2) && (i8257->mr & I8257_MODE_AL)) |
| 347 | | { |
| 348 | | i8257->state = STATE_SU; |
| 349 | | } |
| 350 | | else |
| 351 | | { |
| 352 | | i8257->state = STATE_S4; |
| 353 | | } |
| 354 | | break; |
| 355 | | |
| 356 | | case STATE_SW: |
| 357 | | /* sample READY line */ |
| 358 | | if (i8257->ready) |
| 359 | | { |
| 360 | | if (i8257->tc && (i8257->channel == 2) && (i8257->mr & I8257_MODE_AL)) |
| 361 | | { |
| 362 | | i8257->state = STATE_SU; |
| 363 | | } |
| 364 | | else |
| 365 | | { |
| 366 | | i8257->state = STATE_S4; |
| 367 | | } |
| 368 | | } |
| 369 | | break; |
| 370 | | |
| 371 | | case STATE_SU: |
| 372 | | i8257->sr |= I8257_STATUS_UP; |
| 373 | | |
| 374 | | /* auto load channel 2 parameters */ |
| 375 | | i8257->ar[2] = i8257->ar[3]; |
| 376 | | i8257->cr[2] = i8257->cr[3]; |
| 377 | | |
| 378 | | if (LOG) |
| 379 | | { |
| 380 | | logerror("I8257 '%s' DMA Channel 2 Address Register: %04x\n", device->tag(), i8257->ar[2]); |
| 381 | | logerror("I8257 '%s' DMA Channel 2 Count Register: %04x\n", device->tag(), i8257->cr[2] & 0x3fff); |
| 382 | | logerror("I8257 '%s' DMA Channel 2 Mode: %u\n", device->tag(), i8257->cr[2] >> 14); |
| 383 | | } |
| 384 | | |
| 385 | | i8257->state = STATE_S4; |
| 386 | | break; |
| 387 | | |
| 388 | | case STATE_S4: |
| 389 | | i8257->sr &= ~I8257_STATUS_UP; |
| 390 | | |
| 391 | | if (i8257->tc) |
| 392 | | { |
| 393 | | /* reset enable for channel n if TC stop and TC are active */ |
| 394 | | if ((i8257->mr & I8257_MODE_TCS) && |
| 395 | | !((i8257->channel == 2) && (i8257->mr & I8257_MODE_AL))) |
| 396 | | { |
| 397 | | i8257->mr &= ~(1 << i8257->channel); |
| 398 | | if (LOG) logerror("I8257 '%s' DMA Channel %u: disabled\n", device->tag(), i8257->channel); |
| 399 | | } |
| 400 | | |
| 401 | | if (i8257->mr & I8257_MODE_RP) |
| 402 | | { |
| 403 | | i8257->priority = (i8257->channel + 1) % I8257_CHANNELS; |
| 404 | | } |
| 405 | | |
| 406 | | /* resolve DRQ priorities */ |
| 407 | | resolve_priorities(device); |
| 408 | | } |
| 409 | | |
| 410 | | /* deactivate DACKn, MARK and TC */ |
| 411 | | set_dack(device, -1); |
| 412 | | set_mark(device, 0); |
| 413 | | set_tc(device, 0); |
| 414 | | |
| 415 | | /* sample DRQn */ |
| 416 | | drq = sample_drq(device); |
| 417 | | |
| 418 | | /* reset HRQ if HLDA = 0 or DRQ = 0 */ |
| 419 | | if (!i8257->hlda || !drq) |
| 420 | | { |
| 421 | | set_hrq(device, 0); |
| 422 | | i8257->state = STATE_SI; |
| 423 | | i8257->dma_timer->enable(0); |
| 424 | | } |
| 425 | | else |
| 426 | | { |
| 427 | | i8257->state = STATE_S1; |
| 428 | | } |
| 429 | | break; |
| 430 | | } |
| 431 | | } |
| 432 | | |
| 433 | | READ8_DEVICE_HANDLER( i8257_r ) |
| 434 | | { |
| 435 | | i8257_t *i8257 = get_safe_token(device); |
| 436 | | UINT8 data = 0; |
| 437 | | int ch; |
| 438 | | |
| 439 | | switch (offset & 0x0f) |
| 440 | | { |
| 441 | | case 0: |
| 442 | | case 2: |
| 443 | | case 4: |
| 444 | | case 6: |
| 445 | | ch = offset / 2; |
| 446 | | |
| 447 | | if (i8257->fl) |
| 448 | | { |
| 449 | | data = i8257->ar[ch] >> 8; |
| 450 | | } |
| 451 | | else |
| 452 | | { |
| 453 | | data = i8257->ar[ch] & 0xff; |
| 454 | | } |
| 455 | | |
| 456 | | i8257->fl = !i8257->fl; |
| 457 | | break; |
| 458 | | |
| 459 | | case 1: |
| 460 | | case 3: |
| 461 | | case 5: |
| 462 | | case 7: |
| 463 | | ch = (offset - 1) / 2; |
| 464 | | |
| 465 | | if (i8257->fl) |
| 466 | | { |
| 467 | | data = i8257->cr[ch] >> 8; |
| 468 | | } |
| 469 | | else |
| 470 | | { |
| 471 | | data = i8257->cr[ch] & 0xff; |
| 472 | | } |
| 473 | | |
| 474 | | i8257->fl = !i8257->fl; |
| 475 | | break; |
| 476 | | |
| 477 | | case 8: |
| 478 | | data = i8257->sr; |
| 479 | | i8257->sr &= ~(I8257_STATUS_TC3 | I8257_STATUS_TC2 | I8257_STATUS_TC1 | I8257_STATUS_TC0); |
| 480 | | break; |
| 481 | | } |
| 482 | | |
| 483 | | return data; |
| 484 | | } |
| 485 | | |
| 486 | | WRITE8_DEVICE_HANDLER( i8257_w ) |
| 487 | | { |
| 488 | | i8257_t *i8257 = get_safe_token(device); |
| 489 | | int ch; |
| 490 | | |
| 491 | | switch (offset & 0x0f) |
| 492 | | { |
| 493 | | case 0: |
| 494 | | case 2: |
| 495 | | case 4: |
| 496 | | case 6: |
| 497 | | ch = offset / 2; |
| 498 | | |
| 499 | | if (i8257->fl) |
| 500 | | { |
| 501 | | i8257->ar[ch] = (data << 8) | (i8257->ar[ch] & 0xff); |
| 502 | | if (LOG) logerror("I8257 '%s' DMA Channel %u Address Register: %04x\n", device->tag(), ch, i8257->ar[ch]); |
| 503 | | } |
| 504 | | else |
| 505 | | { |
| 506 | | i8257->ar[ch] = (i8257->ar[ch] & 0xff00) | data; |
| 507 | | } |
| 508 | | |
| 509 | | if ((i8257->mr & I8257_MODE_AL) && (ch == 2)) |
| 510 | | { |
| 511 | | i8257->ar[3] = i8257->ar[2]; |
| 512 | | } |
| 513 | | |
| 514 | | i8257->fl = !i8257->fl; |
| 515 | | break; |
| 516 | | |
| 517 | | case 1: |
| 518 | | case 3: |
| 519 | | case 5: |
| 520 | | case 7: |
| 521 | | ch = (offset - 1) / 2; |
| 522 | | |
| 523 | | if (i8257->fl) |
| 524 | | { |
| 525 | | i8257->cr[ch] = (data << 8) | (i8257->cr[ch] & 0xff); |
| 526 | | if (LOG) logerror("I8257 '%s' DMA Channel %u Count Register: %04x\n", device->tag(), ch, i8257->cr[ch] & 0x3fff); |
| 527 | | if (LOG) logerror("I8257 '%s' DMA Channel %u Mode: %u\n", device->tag(), ch, i8257->cr[ch] >> 14); |
| 528 | | } |
| 529 | | else |
| 530 | | { |
| 531 | | i8257->cr[ch] = (i8257->cr[ch] & 0xff00) | data; |
| 532 | | } |
| 533 | | |
| 534 | | if ((i8257->mr & I8257_MODE_AL) && (ch == 2)) |
| 535 | | { |
| 536 | | i8257->cr[3] = i8257->cr[2]; |
| 537 | | } |
| 538 | | |
| 539 | | i8257->fl = !i8257->fl; |
| 540 | | break; |
| 541 | | |
| 542 | | case 8: |
| 543 | | i8257->mr = data; |
| 544 | | i8257->fl = 0; |
| 545 | | |
| 546 | | if ((i8257->state == STATE_SI) && sample_drq(device)) |
| 547 | | { |
| 548 | | i8257->dma_timer->enable(1); |
| 549 | | } |
| 550 | | |
| 551 | | if (LOG) |
| 552 | | { |
| 553 | | logerror("I8257 '%s' DMA Channel 0: %s\n", device->tag(), BIT(i8257->mr, 0) ? "enabled" : "disabled"); |
| 554 | | logerror("I8257 '%s' DMA Channel 1: %s\n", device->tag(), BIT(i8257->mr, 1) ? "enabled" : "disabled"); |
| 555 | | logerror("I8257 '%s' DMA Channel 2: %s\n", device->tag(), BIT(i8257->mr, 2) ? "enabled" : "disabled"); |
| 556 | | logerror("I8257 '%s' DMA Channel 3: %s\n", device->tag(), BIT(i8257->mr, 3) ? "enabled" : "disabled"); |
| 557 | | if (BIT(i8257->mr, 4)) logerror("I8257 '%s' Rotating Priority\n", device->tag()); |
| 558 | | if (BIT(i8257->mr, 5)) logerror("I8257 '%s' Extended Write\n", device->tag()); |
| 559 | | if (BIT(i8257->mr, 6)) logerror("I8257 '%s' TC Stop\n", device->tag()); |
| 560 | | if (BIT(i8257->mr, 7)) logerror("I8257 '%s' Auto Load\n", device->tag()); |
| 561 | | } |
| 562 | | break; |
| 563 | | } |
| 564 | | } |
| 565 | | |
| 566 | | WRITE_LINE_DEVICE_HANDLER( i8257_hlda_w ) |
| 567 | | { |
| 568 | | i8257_t *i8257 = get_safe_token(device); |
| 569 | | |
| 570 | | i8257->hlda = state; |
| 571 | | |
| 572 | | if (LOG) logerror("I8257 '%s' Hold Acknowledge: %u\n", device->tag(), state); |
| 573 | | } |
| 574 | | |
| 575 | | WRITE_LINE_DEVICE_HANDLER( i8257_ready_w ) |
| 576 | | { |
| 577 | | i8257_t *i8257 = get_safe_token(device); |
| 578 | | |
| 579 | | i8257->ready = state; |
| 580 | | |
| 581 | | if (LOG) logerror("I8257 '%s' Ready: %u\n", device->tag(), state); |
| 582 | | } |
| 583 | | |
| 584 | | static void drq_w(device_t *device, int ch, int state) |
| 585 | | { |
| 586 | | i8257_t *i8257 = get_safe_token(device); |
| 587 | | |
| 588 | | i8257->drq[ch] = state; |
| 589 | | |
| 590 | | if (LOG) logerror("I8257 '%s' Data Request %u: %u\n", device->tag(), ch, state); |
| 591 | | |
| 592 | | if (state && (i8257->state == STATE_SI)) |
| 593 | | { |
| 594 | | i8257->dma_timer->enable(1); |
| 595 | | } |
| 596 | | } |
| 597 | | |
| 598 | | WRITE_LINE_DEVICE_HANDLER( i8257_drq0_w ) { drq_w(device, 0, state); } |
| 599 | | WRITE_LINE_DEVICE_HANDLER( i8257_drq1_w ) { drq_w(device, 1, state); } |
| 600 | | WRITE_LINE_DEVICE_HANDLER( i8257_drq2_w ) { drq_w(device, 2, state); } |
| 601 | | WRITE_LINE_DEVICE_HANDLER( i8257_drq3_w ) { drq_w(device, 3, state); } |
| 602 | | |
| 603 | | /*------------------------------------------------- |
| 604 | | DEVICE_START( i8257 ) |
| 605 | | -------------------------------------------------*/ |
| 606 | | |
| 607 | | static DEVICE_START( i8257 ) |
| 608 | | { |
| 609 | | i8257_t *i8257 = get_safe_token(device); |
| 610 | | i8257_interface *intf = (i8257_interface *)device->baseconfig().static_config(); |
| 611 | | int ch; |
| 612 | | |
| 613 | | /* resolve callbacks */ |
| 614 | | devcb_resolve_write_line(&i8257->out_hrq_func, &intf->out_hrq_func, device); |
| 615 | | devcb_resolve_write_line(&i8257->out_tc_func, &intf->out_tc_func, device); |
| 616 | | devcb_resolve_write_line(&i8257->out_mark_func, &intf->out_mark_func, device); |
| 617 | | |
| 618 | | for (ch = 0; ch < I8257_CHANNELS; ch++) |
| 619 | | { |
| 620 | | devcb_resolve_read8(&i8257->in_memr_func[ch], &intf->in_memr_func[ch], device); |
| 621 | | devcb_resolve_write8(&i8257->out_memw_func[ch], &intf->out_memw_func[ch], device); |
| 622 | | devcb_resolve_read8(&i8257->in_ior_func[ch], &intf->in_ior_func[ch], device); |
| 623 | | devcb_resolve_write8(&i8257->out_iow_func[ch], &intf->out_iow_func[ch], device); |
| 624 | | devcb_resolve_write_line(&i8257->out_dack_func[ch], &intf->out_dack_func[ch], device); |
| 625 | | } |
| 626 | | |
| 627 | | /* create the DMA timer */ |
| 628 | | i8257->dma_timer = device->machine().scheduler().timer_alloc(FUNC(dma_tick), (void *)device); |
| 629 | | i8257->dma_timer->adjust(attotime::zero, 0, attotime::from_hz(device->clock())); |
| 630 | | |
| 631 | | /* register for state saving */ |
| 632 | | device->save_item(NAME(i8257->mr)); |
| 633 | | device->save_item(NAME(i8257->sr)); |
| 634 | | device->save_item(NAME(i8257->ar)); |
| 635 | | device->save_item(NAME(i8257->cr)); |
| 636 | | device->save_item(NAME(i8257->fl)); |
| 637 | | device->save_item(NAME(i8257->drq)); |
| 638 | | device->save_item(NAME(i8257->hlda)); |
| 639 | | device->save_item(NAME(i8257->ready)); |
| 640 | | device->save_item(NAME(i8257->tc)); |
| 641 | | device->save_item(NAME(i8257->mark)); |
| 642 | | device->save_item(NAME(i8257->state)); |
| 643 | | device->save_item(NAME(i8257->channel)); |
| 644 | | device->save_item(NAME(i8257->priority)); |
| 645 | | device->save_item(NAME(i8257->data)); |
| 646 | | device->save_item(NAME(i8257->address)); |
| 647 | | device->save_item(NAME(i8257->count)); |
| 648 | | device->save_item(NAME(i8257->mode)); |
| 649 | | } |
| 650 | | |
| 651 | | /*------------------------------------------------- |
| 652 | | DEVICE_RESET( i8257 ) |
| 653 | | -------------------------------------------------*/ |
| 654 | | |
| 655 | | static DEVICE_RESET( i8257 ) |
| 656 | | { |
| 657 | | i8257_t *i8257 = get_safe_token(device); |
| 658 | | |
| 659 | | i8257->fl = 0; |
| 660 | | i8257->mr = 0; |
| 661 | | i8257->sr = 0; |
| 662 | | i8257->state = STATE_SI; |
| 663 | | i8257->priority = 0; |
| 664 | | i8257->ready = 1; |
| 665 | | |
| 666 | | set_hrq(device, 0); |
| 667 | | set_mark(device, 0); |
| 668 | | set_tc(device, 0); |
| 669 | | set_dack(device, -1); |
| 670 | | |
| 671 | | i8257->dma_timer->enable(0); |
| 672 | | } |
| 673 | | |
| 674 | | /*------------------------------------------------- |
| 675 | | DEVICE_GET_INFO( i8257 ) |
| 676 | | -------------------------------------------------*/ |
| 677 | | |
| 678 | | DEVICE_GET_INFO( i8257 ) |
| 679 | | { |
| 680 | | switch (state) |
| 681 | | { |
| 682 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 683 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8257_t); break; |
| 684 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 685 | | |
| 686 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 687 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8257); break; |
| 688 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 689 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8257); break; |
| 690 | | |
| 691 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 692 | | case DEVINFO_STR_NAME: strcpy(info->s, "Intel 8257"); break; |
| 693 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Intel 8085"); break; |
| 694 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 695 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 696 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 697 | | } |
| 698 | | } |
| 699 | | |
| 700 | | DEFINE_LEGACY_DEVICE(I8257, i8257); |
src/mess/drivers/pc8001.c
| r11186 | r11187 | |
| 442 | 442 | i8257_hlda_w(m_dma, state); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | | static UINT8 memory_read_byte(address_space *space, offs_t address) { return space->read_byte(address); } |
| 446 | | static void memory_write_byte(address_space *space, offs_t address, UINT8 data) { space->write_byte(address, data); } |
| 445 | WRITE8_MEMBER( pc8001_state::dma_mem_w ) |
| 446 | { |
| 447 | //if (channel == 2) |
| 448 | { |
| 449 | m_crtc->dack_w(space, offset, data); |
| 450 | } |
| 451 | } |
| 447 | 452 | |
| 448 | | static I8257_INTERFACE( pc8001_8257_intf ) |
| 453 | READ8_MEMBER( pc8001_state::dma_io_r ) |
| 449 | 454 | { |
| 455 | address_space *program = m_maincpu->memory().space(AS_PROGRAM); |
| 456 | |
| 457 | return program->read_byte(offset); |
| 458 | } |
| 459 | |
| 460 | WRITE8_MEMBER( pc8001_state::dma_io_w ) |
| 461 | { |
| 462 | address_space *program = m_maincpu->memory().space(AS_PROGRAM); |
| 463 | |
| 464 | program->write_byte(offset, data); |
| 465 | } |
| 466 | |
| 467 | static I8257_INTERFACE( dmac_intf ) |
| 468 | { |
| 450 | 469 | DEVCB_DRIVER_LINE_MEMBER(pc8001_state, hrq_w), |
| 451 | 470 | DEVCB_NULL, |
| 452 | 471 | DEVCB_NULL, |
| 453 | | { DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL }, |
| 454 | | { DEVCB_NULL, DEVCB_NULL, DEVCB_DEVICE_MEMBER(UPD3301_TAG, upd3301_device, dack_w), DEVCB_NULL }, |
| 455 | | I8257_MEMORY_HANDLER(Z80_TAG, PROGRAM, memory_read_byte), |
| 456 | | I8257_MEMORY_HANDLER(Z80_TAG, PROGRAM, memory_write_byte), |
| 457 | | { DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL } |
| 472 | DEVCB_NULL, |
| 473 | DEVCB_DRIVER_MEMBER(pc8001_state, dma_mem_w), |
| 474 | { DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_r), DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_r), DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_r), DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_r) }, |
| 475 | { DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_w), DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_w), DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_w), DEVCB_DRIVER_MEMBER(pc8001_state, dma_io_w) }, |
| 458 | 476 | }; |
| 459 | 477 | |
| 460 | 478 | /* uPD1990A Interface */ |
| r11186 | r11187 | |
| 556 | 574 | /* devices */ |
| 557 | 575 | MCFG_MSM8251_ADD(I8251_TAG, uart_intf) |
| 558 | 576 | MCFG_I8255A_ADD(I8255A_TAG, ppi_intf) |
| 559 | | MCFG_I8257_ADD(I8257_TAG, 4000000, pc8001_8257_intf) |
| 577 | MCFG_I8257_ADD(I8257_TAG, 4000000, dmac_intf) |
| 560 | 578 | MCFG_UPD1990A_ADD(UPD1990A_TAG, XTAL_32_768kHz, pc8001_upd1990a_intf) |
| 561 | 579 | MCFG_UPD3301_ADD(UPD3301_TAG, 14318180, pc8001_upd3301_intf) |
| 562 | 580 | |
| r11186 | r11187 | |
| 593 | 611 | /* devices */ |
| 594 | 612 | MCFG_MSM8251_ADD(I8251_TAG, uart_intf) |
| 595 | 613 | MCFG_I8255A_ADD(I8255A_TAG, ppi_intf) |
| 596 | | MCFG_I8257_ADD(I8257_TAG, 4000000, pc8001_8257_intf) |
| 614 | MCFG_I8257_ADD(I8257_TAG, 4000000, dmac_intf) |
| 597 | 615 | MCFG_UPD1990A_ADD(UPD1990A_TAG, XTAL_32_768kHz, pc8001_upd1990a_intf) |
| 598 | 616 | MCFG_UPD3301_ADD(UPD3301_TAG, 14318180, pc8001_upd3301_intf) |
| 599 | 617 | |