src/emu/machine/8257dma.c
| r6331 | r6332 | |
| 33 | 33 | #include "memconv.h" |
| 34 | 34 | #include "8257dma.h" |
| 35 | 35 | |
| 36 | | typedef struct _dma8257_t dma8257_t; |
| 36 | #define I8257_STATUS_UPDATE 0x10 |
| 37 | #define I8257_STATUS_TC_CH3 0x08 |
| 38 | #define I8257_STATUS_TC_CH2 0x04 |
| 39 | #define I8257_STATUS_TC_CH1 0x02 |
| 40 | #define I8257_STATUS_TC_CH0 0x01 |
| 41 | |
| 42 | |
| 43 | typedef struct _dma8257_t i8257_t; |
| 37 | 44 | struct _dma8257_t |
| 38 | 45 | { |
| 39 | | const dma8257_interface *intf; |
| 46 | devcb_resolved_write_line out_hrq_func; |
| 47 | devcb_resolved_write_line out_tc_func; |
| 48 | devcb_resolved_write_line out_mark_func; |
| 49 | devcb_resolved_read8 in_memr_func; |
| 50 | devcb_resolved_write8 out_memw_func; |
| 51 | devcb_resolved_read8 in_ior_func[I8257_NUM_CHANNELS]; |
| 52 | devcb_resolved_write8 out_iow_func[I8257_NUM_CHANNELS]; |
| 53 | |
| 40 | 54 | emu_timer *timer; |
| 41 | 55 | emu_timer *msbflip_timer; |
| 42 | 56 | |
| 43 | | UINT16 registers[DMA8257_NUM_CHANNELS*2]; |
| 57 | UINT16 registers[I8257_NUM_CHANNELS*2]; |
| 44 | 58 | |
| 45 | | UINT16 address[DMA8257_NUM_CHANNELS]; |
| 46 | | UINT16 count[DMA8257_NUM_CHANNELS]; |
| 47 | | UINT8 rwmode[DMA8257_NUM_CHANNELS]; |
| 59 | UINT16 address[I8257_NUM_CHANNELS]; |
| 60 | UINT16 count[I8257_NUM_CHANNELS]; |
| 61 | UINT8 rwmode[I8257_NUM_CHANNELS]; |
| 48 | 62 | |
| 49 | 63 | UINT8 mode; |
| 50 | 64 | UINT8 rr; |
| r6331 | r6332 | |
| 69 | 83 | |
| 70 | 84 | /* ----------------------------------------------------------------------- */ |
| 71 | 85 | |
| 72 | | INLINE dma8257_t *get_safe_token(const device_config *device) { |
| 86 | INLINE i8257_t *get_safe_token(const device_config *device) { |
| 73 | 87 | assert( device != NULL ); |
| 74 | 88 | assert( device->token != NULL ); |
| 75 | | assert( device->type == DMA8257 ); |
| 76 | | return ( dma8257_t * ) device->token; |
| 89 | assert( device->type == I8257 ); |
| 90 | return ( i8257_t * ) device->token; |
| 77 | 91 | } |
| 78 | 92 | |
| 79 | 93 | static int dma8257_do_operation(const device_config *device, int channel) |
| 80 | 94 | { |
| 81 | | dma8257_t *dma8257 = get_safe_token(device); |
| 95 | i8257_t *i8257 = get_safe_token(device); |
| 82 | 96 | int done; |
| 83 | 97 | UINT8 data; |
| 84 | 98 | UINT8 mode; |
| 85 | 99 | |
| 86 | | mode = dma8257->rwmode[channel]; |
| 87 | | if (dma8257->count[channel] == 0x0000) |
| 100 | mode = i8257->rwmode[channel]; |
| 101 | if (i8257->count[channel] == 0x0000) |
| 88 | 102 | { |
| 89 | | dma8257->status |= (0x01 << channel); |
| 90 | | if (dma8257->intf->out_tc[channel]) |
| 91 | | dma8257->intf->out_tc[channel](device, 0, ASSERT_LINE); |
| 103 | i8257->status |= (0x01 << channel); |
| 104 | |
| 105 | devcb_call_write_line(&i8257->out_tc_func, ASSERT_LINE); |
| 92 | 106 | } |
| 93 | 107 | switch(mode) { |
| 94 | 108 | case 1: |
| 95 | | if (dma8257->intf->memory_read!=NULL) { |
| 96 | | data = dma8257->intf->memory_read(device, dma8257->address[channel]); |
| 109 | if (&i8257->in_memr_func.target != NULL) { |
| 110 | data = devcb_call_read8(&i8257->in_memr_func, i8257->address[channel]); |
| 97 | 111 | } else { |
| 98 | 112 | data = 0; |
| 99 | 113 | logerror("8257: No memory read function defined.\n"); |
| 100 | 114 | } |
| 101 | | if (dma8257->intf->channel_write[channel]!=NULL) { |
| 102 | | dma8257->intf->channel_write[channel](device, 0, data); |
| 115 | if (&i8257->out_iow_func[channel].target != NULL) { |
| 116 | devcb_call_write8(&i8257->out_iow_func[channel], 0, data); |
| 103 | 117 | } else { |
| 104 | 118 | logerror("8257: No channel write function for channel %d defined.\n",channel); |
| 105 | 119 | } |
| 106 | 120 | |
| 107 | | dma8257->address[channel]++; |
| 108 | | dma8257->count[channel]--; |
| 109 | | done = (dma8257->count[channel] == 0xFFFF); |
| 121 | i8257->address[channel]++; |
| 122 | i8257->count[channel]--; |
| 123 | done = (i8257->count[channel] == 0xFFFF); |
| 110 | 124 | break; |
| 111 | 125 | |
| 112 | 126 | case 2: |
| 113 | | if (dma8257->intf->channel_read[channel]!=NULL) { |
| 114 | | data = dma8257->intf->channel_read[channel](device, 0); |
| 127 | if (&i8257->in_ior_func[channel].target != NULL) { |
| 128 | data = devcb_call_read8(&i8257->in_ior_func[channel], 0); |
| 115 | 129 | } else { |
| 116 | 130 | data = 0; |
| 117 | 131 | logerror("8257: No channel read function for channel %d defined.\n",channel); |
| 118 | 132 | } |
| 119 | 133 | |
| 120 | | if (dma8257->intf->memory_write!=NULL) { |
| 121 | | dma8257->intf->memory_write(device, dma8257->address[channel], data); |
| 134 | if (&i8257->out_memw_func.target != NULL) { |
| 135 | devcb_call_write8(&i8257->out_memw_func, i8257->address[channel], data); |
| 122 | 136 | } else { |
| 123 | 137 | logerror("8257: No memory write function defined.\n"); |
| 124 | 138 | } |
| 125 | | dma8257->address[channel]++; |
| 126 | | dma8257->count[channel]--; |
| 127 | | done = (dma8257->count[channel] == 0xFFFF); |
| 139 | i8257->address[channel]++; |
| 140 | i8257->count[channel]--; |
| 141 | done = (i8257->count[channel] == 0xFFFF); |
| 128 | 142 | break; |
| 129 | 143 | case 0: /* verify */ |
| 130 | | dma8257->address[channel]++; |
| 131 | | dma8257->count[channel]--; |
| 132 | | done = (dma8257->count[channel] == 0xFFFF); |
| 144 | i8257->address[channel]++; |
| 145 | i8257->count[channel]--; |
| 146 | done = (i8257->count[channel] == 0xFFFF); |
| 133 | 147 | break; |
| 134 | 148 | default: |
| 135 | 149 | fatalerror("dma8257_do_operation: invalid mode!\n"); |
| r6331 | r6332 | |
| 137 | 151 | } |
| 138 | 152 | if (done) |
| 139 | 153 | { |
| 140 | | if ((channel==2) && DMA_MODE_AUTOLOAD(dma8257->mode)) { |
| 154 | if ((channel==2) && DMA_MODE_AUTOLOAD(i8257->mode)) { |
| 141 | 155 | /* in case of autoload at the end channel 3 info is */ |
| 142 | 156 | /* copied to channel 2 info */ |
| 143 | | dma8257->registers[4] = dma8257->registers[6]; |
| 144 | | dma8257->registers[5] = dma8257->registers[7]; |
| 157 | i8257->registers[4] = i8257->registers[6]; |
| 158 | i8257->registers[5] = i8257->registers[7]; |
| 145 | 159 | } |
| 146 | | if (dma8257->intf->out_tc[channel]) |
| 147 | | dma8257->intf->out_tc[channel](device, 0, CLEAR_LINE); |
| 160 | |
| 161 | devcb_call_write_line(&i8257->out_tc_func, CLEAR_LINE); |
| 148 | 162 | } |
| 149 | 163 | return done; |
| 150 | 164 | } |
| r6331 | r6332 | |
| 154 | 168 | static TIMER_CALLBACK( dma8257_timerproc ) |
| 155 | 169 | { |
| 156 | 170 | const device_config *device = (const device_config *)ptr; |
| 157 | | dma8257_t *dma8257 = get_safe_token(device); |
| 171 | i8257_t *i8257 = get_safe_token(device); |
| 158 | 172 | int i, channel = 0, rr; |
| 159 | 173 | int done; |
| 160 | 174 | |
| 161 | | rr = DMA_MODE_ROTPRIO(dma8257->mode) ? dma8257->rr : 0; |
| 162 | | for (i = 0; i < DMA8257_NUM_CHANNELS; i++) |
| 175 | rr = DMA_MODE_ROTPRIO(i8257->mode) ? i8257->rr : 0; |
| 176 | for (i = 0; i < I8257_NUM_CHANNELS; i++) |
| 163 | 177 | { |
| 164 | | channel = (i + rr) % DMA8257_NUM_CHANNELS; |
| 165 | | if ((dma8257->status & (1 << channel)) == 0) |
| 166 | | if (dma8257->mode & dma8257->drq & (1 << channel)) |
| 178 | channel = (i + rr) % I8257_NUM_CHANNELS; |
| 179 | if ((i8257->status & (1 << channel)) == 0) |
| 180 | if (i8257->mode & i8257->drq & (1 << channel)) |
| 167 | 181 | break; |
| 168 | 182 | } |
| 169 | 183 | done = dma8257_do_operation(device, channel); |
| 170 | 184 | |
| 171 | | dma8257->rr = (channel + 1) & 0x03; |
| 185 | i8257->rr = (channel + 1) & 0x03; |
| 172 | 186 | |
| 173 | 187 | if (done) |
| 174 | 188 | { |
| 175 | | dma8257->drq &= ~(0x01 << channel); |
| 189 | i8257->drq &= ~(0x01 << channel); |
| 176 | 190 | dma8257_update_status(device); |
| 177 | | if (!(DMA_MODE_AUTOLOAD(dma8257->mode) && channel==2)) { |
| 178 | | if (DMA_MODE_TCSTOP(dma8257->mode)) { |
| 179 | | dma8257->mode &= ~(0x01 << channel); |
| 191 | if (!(DMA_MODE_AUTOLOAD(i8257->mode) && channel==2)) { |
| 192 | if (DMA_MODE_TCSTOP(i8257->mode)) { |
| 193 | i8257->mode &= ~(0x01 << channel); |
| 180 | 194 | } |
| 181 | 195 | } |
| 182 | 196 | } |
| r6331 | r6332 | |
| 187 | 201 | static TIMER_CALLBACK( dma8257_msbflip_timerproc ) |
| 188 | 202 | { |
| 189 | 203 | const device_config *device = (const device_config *)ptr; |
| 190 | | dma8257_t *dma8257 = get_safe_token(device); |
| 191 | | dma8257->msb ^= 1; |
| 204 | i8257_t *i8257 = get_safe_token(device); |
| 205 | i8257->msb ^= 1; |
| 192 | 206 | } |
| 193 | 207 | |
| 194 | 208 | |
| 195 | 209 | |
| 196 | 210 | static void dma8257_update_status(const device_config *device) |
| 197 | 211 | { |
| 198 | | dma8257_t *dma8257 = get_safe_token(device); |
| 212 | i8257_t *i8257 = get_safe_token(device); |
| 199 | 213 | UINT16 pending_transfer; |
| 200 | 214 | attotime next; |
| 201 | 215 | |
| 202 | 216 | /* no transfer is active right now; is there a transfer pending right now? */ |
| 203 | | pending_transfer = dma8257->drq & (dma8257->mode & 0x0F); |
| 217 | pending_transfer = i8257->drq & (i8257->mode & 0x0F); |
| 204 | 218 | |
| 205 | 219 | if (pending_transfer) |
| 206 | 220 | { |
| 207 | 221 | next = ATTOTIME_IN_HZ(device->clock / 4 ); |
| 208 | | timer_adjust_periodic(dma8257->timer, |
| 222 | timer_adjust_periodic(i8257->timer, |
| 209 | 223 | attotime_zero, |
| 210 | 224 | 0, |
| 211 | 225 | /* 1 byte transferred in 4 clock cycles */ |
| r6331 | r6332 | |
| 214 | 228 | else |
| 215 | 229 | { |
| 216 | 230 | /* no transfers active right now */ |
| 217 | | timer_reset(dma8257->timer, attotime_never); |
| 231 | timer_reset(i8257->timer, attotime_never); |
| 218 | 232 | } |
| 219 | 233 | |
| 220 | 234 | /* set the halt line */ |
| 221 | | if (dma8257->intf && dma8257->intf->cputag != NULL) |
| 222 | | { |
| 223 | | cputag_set_input_line(device->machine, dma8257->intf->cputag, INPUT_LINE_HALT, |
| 224 | | pending_transfer ? ASSERT_LINE : CLEAR_LINE); |
| 225 | | } |
| 226 | | |
| 235 | devcb_call_write_line(&i8257->out_hrq_func, pending_transfer ? ASSERT_LINE : CLEAR_LINE); |
| 227 | 236 | } |
| 228 | 237 | |
| 229 | 238 | |
| 230 | 239 | |
| 231 | 240 | /* ----------------------------------------------------------------------- */ |
| 232 | 241 | |
| 233 | | static void prepare_msb_flip(dma8257_t *dma8257) |
| 242 | static void prepare_msb_flip(i8257_t *i8257) |
| 234 | 243 | { |
| 235 | | timer_adjust_oneshot(dma8257->msbflip_timer, attotime_zero, 0); |
| 244 | timer_adjust_oneshot(i8257->msbflip_timer, attotime_zero, 0); |
| 236 | 245 | } |
| 237 | 246 | |
| 238 | 247 | |
| 239 | 248 | |
| 240 | | READ8_DEVICE_HANDLER( dma8257_r ) |
| 249 | READ8_DEVICE_HANDLER( i8257_r ) |
| 241 | 250 | { |
| 242 | | dma8257_t *dma8257 = get_safe_token(device); |
| 251 | i8257_t *i8257 = get_safe_token(device); |
| 243 | 252 | UINT8 data = 0xFF; |
| 244 | 253 | |
| 245 | 254 | switch(offset) { |
| r6331 | r6332 | |
| 252 | 261 | case 6: |
| 253 | 262 | case 7: |
| 254 | 263 | /* DMA address/count register */ |
| 255 | | data = ( dma8257->registers[offset] >> (dma8257->msb ? 8 : 0) ) & 0xFF; |
| 256 | | prepare_msb_flip(dma8257); |
| 264 | data = ( i8257->registers[offset] >> (i8257->msb ? 8 : 0) ) & 0xFF; |
| 265 | prepare_msb_flip(i8257); |
| 257 | 266 | break; |
| 258 | 267 | |
| 259 | 268 | case 8: |
| 260 | 269 | /* DMA status register */ |
| 261 | | data = (UINT8) dma8257->status; |
| 270 | data = (UINT8) i8257->status; |
| 262 | 271 | /* read resets status ! */ |
| 263 | | dma8257->status &= 0xF0; |
| 272 | i8257->status &= 0xF0; |
| 264 | 273 | |
| 265 | 274 | break; |
| 266 | 275 | |
| r6331 | r6332 | |
| 274 | 283 | |
| 275 | 284 | |
| 276 | 285 | |
| 277 | | WRITE8_DEVICE_HANDLER( dma8257_w ) |
| 286 | WRITE8_DEVICE_HANDLER( i8257_w ) |
| 278 | 287 | { |
| 279 | | dma8257_t *dma8257 = get_safe_token(device); |
| 288 | i8257_t *i8257 = get_safe_token(device); |
| 280 | 289 | |
| 281 | 290 | switch(offset) { |
| 282 | 291 | case 0: |
| r6331 | r6332 | |
| 288 | 297 | case 6: |
| 289 | 298 | case 7: |
| 290 | 299 | /* DMA address/count register */ |
| 291 | | if (dma8257->msb) |
| 292 | | dma8257->registers[offset] |= ((UINT16) data) << 8; |
| 300 | if (i8257->msb) |
| 301 | i8257->registers[offset] |= ((UINT16) data) << 8; |
| 293 | 302 | else |
| 294 | | dma8257->registers[offset] = data; |
| 303 | i8257->registers[offset] = data; |
| 295 | 304 | |
| 296 | | if (DMA_MODE_AUTOLOAD(dma8257->mode)) { |
| 305 | if (DMA_MODE_AUTOLOAD(i8257->mode)) { |
| 297 | 306 | /* in case of autoload when inserting channel 2 info */ |
| 298 | 307 | /* it is automaticaly copied to channel 3 info */ |
| 299 | 308 | switch(offset) { |
| 300 | 309 | case 4: |
| 301 | 310 | case 5: |
| 302 | | if (dma8257->msb) |
| 303 | | dma8257->registers[offset+2] |= ((UINT16) data) << 8; |
| 311 | if (i8257->msb) |
| 312 | i8257->registers[offset+2] |= ((UINT16) data) << 8; |
| 304 | 313 | else |
| 305 | | dma8257->registers[offset+2] = data; |
| 314 | i8257->registers[offset+2] = data; |
| 306 | 315 | } |
| 307 | 316 | } |
| 308 | 317 | |
| 309 | | prepare_msb_flip(dma8257); |
| 318 | prepare_msb_flip(i8257); |
| 310 | 319 | break; |
| 311 | 320 | |
| 312 | 321 | case 8: |
| 313 | 322 | /* DMA mode register */ |
| 314 | | dma8257->mode = data; |
| 323 | i8257->mode = data; |
| 315 | 324 | break; |
| 316 | 325 | |
| 317 | 326 | default: |
| r6331 | r6332 | |
| 325 | 334 | static TIMER_CALLBACK( dma8257_drq_write_callback ) |
| 326 | 335 | { |
| 327 | 336 | const device_config *device = (const device_config *)ptr; |
| 328 | | dma8257_t *dma8257 = get_safe_token(device); |
| 337 | i8257_t *i8257 = get_safe_token(device); |
| 329 | 338 | int channel = param >> 1; |
| 330 | 339 | int state = param & 0x01; |
| 331 | 340 | |
| 332 | 341 | /* normalize state */ |
| 333 | 342 | if (state) |
| 334 | 343 | { |
| 335 | | dma8257->drq |= 0x01 << channel; |
| 336 | | dma8257->address[channel] = dma8257->registers[channel * 2]; |
| 337 | | dma8257->count[channel] = dma8257->registers[channel * 2 + 1] & 0x3FFF; |
| 338 | | dma8257->rwmode[channel] = dma8257->registers[channel * 2 + 1] >> 14; |
| 344 | i8257->drq |= 0x01 << channel; |
| 345 | i8257->address[channel] = i8257->registers[channel * 2]; |
| 346 | i8257->count[channel] = i8257->registers[channel * 2 + 1] & 0x3FFF; |
| 347 | i8257->rwmode[channel] = i8257->registers[channel * 2 + 1] >> 14; |
| 339 | 348 | /* clear channel TC */ |
| 340 | | dma8257->status &= ~(0x01 << channel); |
| 349 | i8257->status &= ~(0x01 << channel); |
| 341 | 350 | } |
| 342 | 351 | else |
| 343 | | dma8257->drq &= ~(0x01 << channel); |
| 352 | i8257->drq &= ~(0x01 << channel); |
| 344 | 353 | |
| 345 | 354 | dma8257_update_status(device); |
| 346 | 355 | } |
| 347 | 356 | |
| 348 | 357 | |
| 349 | 358 | |
| 350 | | WRITE8_DEVICE_HANDLER( dma8257_drq_w ) |
| 359 | static WRITE8_DEVICE_HANDLER( dma8257_drq_w ) |
| 351 | 360 | { |
| 352 | 361 | int param = (offset << 1) | (data ? 1 : 0); |
| 353 | 362 | |
| 354 | 363 | timer_call_after_resynch(device->machine, (void *) device, param, dma8257_drq_write_callback); |
| 355 | 364 | } |
| 356 | 365 | |
| 366 | WRITE_LINE_DEVICE_HANDLER( i8257_hlda_w ) |
| 367 | { |
| 368 | } |
| 357 | 369 | |
| 370 | WRITE_LINE_DEVICE_HANDLER( i8257_ready_w ) |
| 371 | { |
| 372 | } |
| 373 | |
| 374 | WRITE_LINE_DEVICE_HANDLER( i8257_drq0_w ) { dma8257_drq_w(device, 0, state); } |
| 375 | WRITE_LINE_DEVICE_HANDLER( i8257_drq1_w ) { dma8257_drq_w(device, 1, state); } |
| 376 | WRITE_LINE_DEVICE_HANDLER( i8257_drq2_w ) { dma8257_drq_w(device, 2, state); } |
| 377 | WRITE_LINE_DEVICE_HANDLER( i8257_drq3_w ) { dma8257_drq_w(device, 3, state); } |
| 378 | |
| 379 | |
| 358 | 380 | /* ----------------------------------------------------------------------- */ |
| 359 | 381 | |
| 360 | 382 | /* device interface */ |
| 361 | 383 | |
| 362 | | static DEVICE_START( dma8257 ) |
| 384 | static DEVICE_START( i8257 ) |
| 363 | 385 | { |
| 364 | | dma8257_t *dma8257 = get_safe_token(device); |
| 386 | i8257_t *i8257 = get_safe_token(device); |
| 387 | i8257_interface *intf = (i8257_interface *)device->static_config; |
| 388 | int i; |
| 365 | 389 | |
| 366 | 390 | /* validate arguments */ |
| 367 | 391 | assert(device != NULL); |
| 368 | 392 | assert(device->tag != NULL); |
| 369 | 393 | |
| 370 | | //dma8257->device_type = device_type; |
| 371 | | dma8257->intf = (dma8257_interface *)device->static_config; |
| 394 | /* resolve callbacks */ |
| 395 | devcb_resolve_write_line(&i8257->out_hrq_func, &intf->out_hrq_func, device); |
| 396 | devcb_resolve_write_line(&i8257->out_tc_func, &intf->out_tc_func, device); |
| 397 | devcb_resolve_write_line(&i8257->out_mark_func, &intf->out_mark_func, device); |
| 398 | devcb_resolve_read8(&i8257->in_memr_func, &intf->in_memr_func, device); |
| 399 | devcb_resolve_write8(&i8257->out_memw_func, &intf->out_memw_func, device); |
| 372 | 400 | |
| 373 | | dma8257->status = 0x0f; |
| 374 | | dma8257->timer = timer_alloc(device->machine, dma8257_timerproc, (void *) device); |
| 375 | | dma8257->msbflip_timer = timer_alloc(device->machine, dma8257_msbflip_timerproc, (void *) device); |
| 401 | for (i = 0; i < I8257_NUM_CHANNELS; i++) |
| 402 | { |
| 403 | devcb_resolve_read8(&i8257->in_ior_func[i], &intf->in_ior_func[i], device); |
| 404 | devcb_resolve_write8(&i8257->out_iow_func[i], &intf->out_iow_func[i], device); |
| 405 | } |
| 376 | 406 | |
| 377 | | state_save_register_device_item_array(device, 0, dma8257->address); |
| 378 | | state_save_register_device_item_array(device, 0, dma8257->count); |
| 379 | | state_save_register_device_item_array(device, 0, dma8257->rwmode); |
| 380 | | state_save_register_device_item_array(device, 0, dma8257->registers); |
| 407 | /* set initial values */ |
| 408 | i8257->status = 0x0f; |
| 409 | i8257->timer = timer_alloc(device->machine, dma8257_timerproc, (void *) device); |
| 410 | i8257->msbflip_timer = timer_alloc(device->machine, dma8257_msbflip_timerproc, (void *) device); |
| 381 | 411 | |
| 382 | | state_save_register_device_item(device, 0, dma8257->mode); |
| 383 | | state_save_register_device_item(device, 0, dma8257->rr); |
| 384 | | state_save_register_device_item(device, 0, dma8257->msb); |
| 385 | | state_save_register_device_item(device, 0, dma8257->drq); |
| 386 | | state_save_register_device_item(device, 0, dma8257->status); |
| 412 | /* register for state saving */ |
| 413 | state_save_register_device_item_array(device, 0, i8257->address); |
| 414 | state_save_register_device_item_array(device, 0, i8257->count); |
| 415 | state_save_register_device_item_array(device, 0, i8257->rwmode); |
| 416 | state_save_register_device_item_array(device, 0, i8257->registers); |
| 417 | state_save_register_device_item(device, 0, i8257->mode); |
| 418 | state_save_register_device_item(device, 0, i8257->rr); |
| 419 | state_save_register_device_item(device, 0, i8257->msb); |
| 420 | state_save_register_device_item(device, 0, i8257->drq); |
| 421 | state_save_register_device_item(device, 0, i8257->status); |
| 387 | 422 | } |
| 388 | 423 | |
| 389 | 424 | |
| 390 | | static DEVICE_RESET( dma8257 ) |
| 425 | static DEVICE_RESET( i8257 ) |
| 391 | 426 | { |
| 392 | | dma8257_t *dma8257 = get_safe_token(device); |
| 427 | i8257_t *i8257 = get_safe_token(device); |
| 393 | 428 | |
| 394 | | dma8257->status &= 0xf0; |
| 395 | | dma8257->mode = 0; |
| 429 | i8257->status &= 0xf0; |
| 430 | i8257->mode = 0; |
| 396 | 431 | dma8257_update_status(device); |
| 397 | 432 | } |
| 398 | 433 | |
| 399 | 434 | |
| 400 | | DEVICE_GET_INFO( dma8257 ) |
| 435 | DEVICE_GET_INFO( i8257 ) |
| 401 | 436 | { |
| 402 | 437 | switch (state) |
| 403 | 438 | { |
| 404 | 439 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 405 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(dma8257_t); break; |
| 440 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8257_t); break; |
| 406 | 441 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 407 | 442 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 408 | 443 | |
| 409 | 444 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 410 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(dma8257);break; |
| 445 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8257);break; |
| 411 | 446 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 412 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(dma8257);break; |
| 447 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8257);break; |
| 413 | 448 | |
| 414 | 449 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 415 | 450 | case DEVINFO_STR_NAME: strcpy(info->s, "DMA8257"); break; |
src/emu/machine/8257dma.h
| r6331 | r6332 | |
| 1 | | /********************************************************************** |
| 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | | 8257 DMA interface and emulation |
| 3 | Intel 8257 Programmable DMA Controller emulation |
| 4 | 4 | |
| 5 | | **********************************************************************/ |
| 5 | Copyright Nicola Salmoria and the MAME Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 6 | 7 | |
| 7 | | #ifndef DMA8257_H |
| 8 | | #define DMA8257_H |
| 8 | **************************************************************************** |
| 9 | _____ _____ |
| 10 | _I/OR 1 |* \_/ | 40 A7 |
| 11 | _I/OW 2 | | 39 A6 |
| 12 | _MEMR 3 | | 38 A5 |
| 13 | _MEMW 4 | | 37 A4 |
| 14 | MARK 5 | | 36 TC |
| 15 | READY 6 | | 35 A3 |
| 16 | HLDA 7 | | 34 A2 |
| 17 | ADSTB 8 | | 33 A1 |
| 18 | AEN 9 | | 32 A0 |
| 19 | HRQ 10 | 8257 | 31 Vcc |
| 20 | _CS 11 | | 30 D0 |
| 21 | CLK 12 | | 29 D1 |
| 22 | RESET 13 | | 28 D2 |
| 23 | _DACK2 14 | | 27 D3 |
| 24 | _DACK3 15 | | 26 D4 |
| 25 | DRQ3 16 | | 25 _DACK0 |
| 26 | DRQ2 17 | | 24 _DACK1 |
| 27 | DRQ1 18 | | 23 D5 |
| 28 | DRQ0 19 | | 22 D6 |
| 29 | GND 20 |_____________| 21 D7 |
| 9 | 30 | |
| 10 | | #define DMA8257 DEVICE_GET_INFO_NAME(dma8257) |
| 31 | ***************************************************************************/ |
| 11 | 32 | |
| 12 | | #define MDRV_DMA8257_ADD(_tag, _clock, _config) \ |
| 13 | | MDRV_DEVICE_ADD(_tag, DMA8257, _clock) \ |
| 33 | #ifndef __I8257__ |
| 34 | #define __I8257__ |
| 35 | |
| 36 | #include "devcb.h" |
| 37 | |
| 38 | /*************************************************************************** |
| 39 | MACROS / CONSTANTS |
| 40 | ***************************************************************************/ |
| 41 | |
| 42 | #define I8257 DEVICE_GET_INFO_NAME(i8257) |
| 43 | |
| 44 | #define MDRV_I8257_ADD(_tag, _clock, _config) \ |
| 45 | MDRV_DEVICE_ADD(_tag, I8257, _clock) \ |
| 14 | 46 | MDRV_DEVICE_CONFIG(_config) |
| 15 | 47 | |
| 48 | #define I8257_INTERFACE(_name) \ |
| 49 | const i8257_interface (_name) = |
| 16 | 50 | |
| 17 | | #define DMA8257_STATUS_UPDATE 0x10 |
| 18 | | #define DMA8257_STATUS_TC_CH3 0x08 |
| 19 | | #define DMA8257_STATUS_TC_CH2 0x04 |
| 20 | | #define DMA8257_STATUS_TC_CH1 0x02 |
| 21 | | #define DMA8257_STATUS_TC_CH0 0x01 |
| 51 | #define I8257_NUM_CHANNELS (4) |
| 22 | 52 | |
| 23 | | #define DMA8257_NUM_CHANNELS (4) |
| 53 | /*************************************************************************** |
| 54 | TYPE DEFINITIONS |
| 55 | ***************************************************************************/ |
| 24 | 56 | |
| 25 | | |
| 26 | | typedef struct _dma8257_interface dma8257_interface; |
| 27 | | struct _dma8257_interface |
| 57 | typedef struct _i8257_interface i8257_interface; |
| 58 | struct _i8257_interface |
| 28 | 59 | { |
| 29 | | /* CPU to halt when DMA is active */ |
| 30 | | const char *cputag; |
| 60 | devcb_write_line out_hrq_func; |
| 61 | devcb_write_line out_tc_func; |
| 62 | devcb_write_line out_mark_func; |
| 31 | 63 | |
| 32 | 64 | /* accessors to main memory */ |
| 33 | | read8_device_func memory_read; |
| 34 | | write8_device_func memory_write; |
| 65 | devcb_read8 in_memr_func; |
| 66 | devcb_write8 out_memw_func; |
| 35 | 67 | |
| 36 | 68 | /* channel accesors */ |
| 37 | | read8_device_func channel_read[DMA8257_NUM_CHANNELS]; |
| 38 | | write8_device_func channel_write[DMA8257_NUM_CHANNELS]; |
| 39 | | |
| 40 | | /* function to call when DMA completes */ |
| 41 | | write8_device_func out_tc[DMA8257_NUM_CHANNELS]; |
| 69 | devcb_read8 in_ior_func[I8257_NUM_CHANNELS]; |
| 70 | devcb_write8 out_iow_func[I8257_NUM_CHANNELS]; |
| 42 | 71 | }; |
| 43 | 72 | |
| 44 | | /* device interface */ |
| 45 | | DEVICE_GET_INFO( dma8257 ); |
| 73 | /*************************************************************************** |
| 74 | PROTOTYPES |
| 75 | ***************************************************************************/ |
| 46 | 76 | |
| 47 | | READ8_DEVICE_HANDLER( dma8257_r); |
| 48 | | WRITE8_DEVICE_HANDLER( dma8257_w); |
| 77 | /* register access */ |
| 78 | READ8_DEVICE_HANDLER( i8257_r ); |
| 79 | WRITE8_DEVICE_HANDLER( i8257_w ); |
| 49 | 80 | |
| 50 | | WRITE8_DEVICE_HANDLER( dma8257_drq_w ); /* offset spceifies channel! */ |
| 81 | /* hold acknowledge */ |
| 82 | WRITE_LINE_DEVICE_HANDLER( i8257_hlda_w ); |
| 51 | 83 | |
| 52 | | #endif /* DMA8257_H */ |
| 84 | /* ready */ |
| 85 | WRITE_LINE_DEVICE_HANDLER( i8257_ready_w ); |
| 86 | |
| 87 | /* data request */ |
| 88 | WRITE_LINE_DEVICE_HANDLER( i8257_drq0_w ); |
| 89 | WRITE_LINE_DEVICE_HANDLER( i8257_drq1_w ); |
| 90 | WRITE_LINE_DEVICE_HANDLER( i8257_drq2_w ); |
| 91 | WRITE_LINE_DEVICE_HANDLER( i8257_drq3_w ); |
| 92 | |
| 93 | DEVICE_GET_INFO( i8257 ); |
| 94 | |
| 95 | #endif |
src/mess/drivers/radio86.c
| r6331 | r6332 | |
| 24 | 24 | AM_RANGE( 0x8000, 0x8003 ) AM_DEVREADWRITE("ppi8255_1", i8255a_r, i8255a_w) AM_MIRROR(0x1ffc) |
| 25 | 25 | //AM_RANGE( 0xa000, 0xa003 ) AM_DEVREADWRITE("ppi8255_2", i8255a_r, i8255a_w) AM_MIRROR(0x1ffc) |
| 26 | 26 | AM_RANGE( 0xc000, 0xc001 ) AM_DEVREADWRITE("i8275", i8275_r, i8275_w) AM_MIRROR(0x1ffe) // video |
| 27 | | AM_RANGE( 0xe000, 0xffff ) AM_DEVWRITE("dma8257", dma8257_w) // DMA |
| 27 | AM_RANGE( 0xe000, 0xffff ) AM_DEVWRITE("dma8257", i8257_w) // DMA |
| 28 | 28 | AM_RANGE( 0xf000, 0xffff ) AM_ROM // System ROM |
| 29 | 29 | ADDRESS_MAP_END |
| 30 | 30 | |
| r6331 | r6332 | |
| 44 | 44 | AM_RANGE( 0x8000, 0x8003 ) AM_DEVREADWRITE("ppi8255_1", i8255a_r, i8255a_w) AM_MIRROR(0x1ffc) |
| 45 | 45 | AM_RANGE( 0xa000, 0xa003 ) AM_DEVREADWRITE("ppi8255_2", i8255a_r, i8255a_w) AM_MIRROR(0x1ffc) |
| 46 | 46 | AM_RANGE( 0xc000, 0xc001 ) AM_DEVREADWRITE("i8275", i8275_r, i8275_w) AM_MIRROR(0x1ffe) // video |
| 47 | | AM_RANGE( 0xe000, 0xffff ) AM_DEVWRITE("dma8257", dma8257_w) // DMA |
| 47 | AM_RANGE( 0xe000, 0xffff ) AM_DEVWRITE("dma8257", i8257_w) // DMA |
| 48 | 48 | AM_RANGE( 0xf000, 0xffff ) AM_ROM // System ROM |
| 49 | 49 | ADDRESS_MAP_END |
| 50 | 50 | |
| r6331 | r6332 | |
| 57 | 57 | AM_RANGE( 0xf780, 0xf7bf ) AM_DEVREADWRITE("i8275", i8275_r, i8275_w) // video |
| 58 | 58 | AM_RANGE( 0xf684, 0xf687 ) AM_DEVREADWRITE("ppi8255_2", i8255a_r, i8255a_w) |
| 59 | 59 | AM_RANGE( 0xf688, 0xf688 ) AM_WRITE( radio86_pagesel ) |
| 60 | | AM_RANGE( 0xf800, 0xffff ) AM_DEVWRITE("dma8257", dma8257_w) // DMA |
| 60 | AM_RANGE( 0xf800, 0xffff ) AM_DEVWRITE("dma8257", i8257_w) // DMA |
| 61 | 61 | AM_RANGE( 0xf800, 0xffff ) AM_ROM // System ROM page 1 |
| 62 | 62 | ADDRESS_MAP_END |
| 63 | 63 | |
| r6331 | r6332 | |
| 69 | 69 | AM_RANGE( 0x8000, 0x8003 ) AM_DEVREADWRITE("ppi8255_1", i8255a_r, i8255a_w) AM_MIRROR(0x1ffc) |
| 70 | 70 | //AM_RANGE( 0xa000, 0xa003 ) AM_DEVREADWRITE("ppi8255_2", i8255a_r, i8255a_w) AM_MIRROR(0x1ffc) |
| 71 | 71 | AM_RANGE( 0xc000, 0xc001 ) AM_DEVREADWRITE("i8275", i8275_r, i8275_w) AM_MIRROR(0x1ffe) // video |
| 72 | | AM_RANGE( 0xe000, 0xffff ) AM_DEVWRITE("dma8257", dma8257_w) // DMA |
| 72 | AM_RANGE( 0xe000, 0xffff ) AM_DEVWRITE("dma8257", i8257_w) // DMA |
| 73 | 73 | AM_RANGE( 0xf000, 0xffff ) AM_ROM // System ROM |
| 74 | 74 | ADDRESS_MAP_END |
| 75 | 75 | |
| r6331 | r6332 | |
| 80 | 80 | AM_RANGE( 0xc000, 0xc003 ) AM_DEVREADWRITE("ppi8255_1", i8255a_r, i8255a_w) AM_MIRROR(0x00fc) |
| 81 | 81 | //AM_RANGE( 0xc100, 0xc103 ) AM_DEVREADWRITE("ppi8255_2", i8255a_r, i8255a_w) AM_MIRROR(0x00fc) |
| 82 | 82 | AM_RANGE( 0xc200, 0xc201 ) AM_DEVREADWRITE("i8275", i8275_r, i8275_w) AM_MIRROR(0x00fe) // video |
| 83 | | AM_RANGE( 0xc300, 0xc3ff ) AM_DEVWRITE("dma8257", dma8257_w) // DMA |
| 83 | AM_RANGE( 0xc300, 0xc3ff ) AM_DEVWRITE("dma8257", i8257_w) // DMA |
| 84 | 84 | AM_RANGE( 0xf000, 0xffff ) AM_ROM // System ROM |
| 85 | 85 | ADDRESS_MAP_END |
| 86 | 86 | |
| r6331 | r6332 | |
| 342 | 342 | MDRV_SOUND_WAVE_ADD("wave", "cassette") |
| 343 | 343 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) |
| 344 | 344 | |
| 345 | | MDRV_DMA8257_ADD("dma8257", XTAL_16MHz / 9, radio86_dma) |
| 345 | MDRV_I8257_ADD("dma8257", XTAL_16MHz / 9, radio86_dma) |
| 346 | 346 | |
| 347 | 347 | MDRV_CASSETTE_ADD( "cassette", radio86_cassette_config ) |
| 348 | 348 | MACHINE_DRIVER_END |