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