src/emu/machine/timekpr.c
| r8910 | r8911 | |
| 1 | | /* |
| 2 | | * STmicroelectronics TIMEKEEPER SRAM |
| 3 | | * |
| 4 | | * Supports: |
| 5 | | * M48T02 |
| 6 | | * M48T35 |
| 7 | | * M48T58 |
| 8 | | * MK48T08 |
| 9 | | * |
| 10 | | */ |
| 1 | /*************************************************************************** |
| 11 | 2 | |
| 3 | timekpr.h |
| 4 | |
| 5 | Various ST Microelectronics timekeeper SRAM implementations: |
| 6 | - M48T02 |
| 7 | - M48T35 |
| 8 | - M48T58 |
| 9 | - MK48T08 |
| 10 | |
| 11 | ***************************************************************************/ |
| 12 | |
| 12 | 13 | #include "emu.h" |
| 13 | 14 | #include "machine/timekpr.h" |
| 14 | 15 | |
| 15 | | typedef struct |
| 16 | | { |
| 17 | | UINT8 control; |
| 18 | | UINT8 seconds; |
| 19 | | UINT8 minutes; |
| 20 | | UINT8 hours; |
| 21 | | UINT8 day; |
| 22 | | UINT8 date; |
| 23 | | UINT8 month; |
| 24 | | UINT8 year; |
| 25 | | UINT8 century; |
| 26 | | UINT8 *data; |
| 27 | | UINT8 *default_data; |
| 28 | | running_device *device; |
| 29 | | int size; |
| 30 | | int offset_control; |
| 31 | | int offset_seconds; |
| 32 | | int offset_minutes; |
| 33 | | int offset_hours; |
| 34 | | int offset_day; |
| 35 | | int offset_date; |
| 36 | | int offset_month; |
| 37 | | int offset_year; |
| 38 | | int offset_century; |
| 39 | | int offset_flags; |
| 40 | | } timekeeper_state; |
| 41 | 16 | |
| 17 | /*************************************************************************** |
| 18 | MACROS |
| 19 | ***************************************************************************/ |
| 20 | |
| 42 | 21 | #define MASK_SECONDS ( 0x7f ) |
| 43 | 22 | #define MASK_MINUTES ( 0x7f ) |
| 44 | 23 | #define MASK_HOURS ( 0x3f ) |
| r8910 | r8911 | |
| 64 | 43 | |
| 65 | 44 | #define FLAGS_BL ( 0x10 ) /* MK48T08: not emulated */ |
| 66 | 45 | |
| 46 | #define TIMEKPR_DEV_DERIVED_CTOR(devtype) \ |
| 47 | devtype##_device::devtype##_device(running_machine &_machine, const devtype##_device_config &config) \ |
| 48 | : timekeeper_device(_machine, config) \ |
| 49 | { } |
| 50 | |
| 51 | #define TIMEKPR_DEVCFG_DERIVED_CTOR(devtype, name) \ |
| 52 | devtype##_device_config::devtype##_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \ |
| 53 | : timekeeper_device_config(mconfig, name, tag, owner, clock) \ |
| 54 | { } |
| 55 | |
| 56 | #define TIMEKPR_DEVCFG_DERIVED_STATIC_ALLOC(devtype) \ |
| 57 | device_config *devtype##_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \ |
| 58 | { return global_alloc(devtype##_device_config(mconfig, tag, owner, clock)); } |
| 59 | |
| 60 | #define TIMEKPR_DEVCFG_DERIVED_DEV_ALLOC(devtype) \ |
| 61 | device_t *devtype##_device_config::alloc_device(running_machine &machine) const \ |
| 62 | { return auto_alloc(&machine, devtype##_device(machine, *this)); } |
| 63 | |
| 64 | #define TIMEKPR_DERIVE(devtype, name) \ |
| 65 | TIMEKPR_DEV_DERIVED_CTOR(devtype) \ |
| 66 | TIMEKPR_DEVCFG_DERIVED_CTOR(devtype, name) \ |
| 67 | TIMEKPR_DEVCFG_DERIVED_STATIC_ALLOC(devtype) \ |
| 68 | TIMEKPR_DEVCFG_DERIVED_DEV_ALLOC(devtype) |
| 69 | |
| 70 | //************************************************************************** |
| 71 | // STATIC DATA |
| 72 | //************************************************************************** |
| 73 | |
| 74 | //************************************************************************** |
| 75 | // DEVICE CONFIGURATION |
| 76 | //************************************************************************** |
| 77 | |
| 78 | //------------------------------------------------- |
| 79 | // timekeeper_device_config - constructor |
| 80 | //------------------------------------------------- |
| 81 | |
| 82 | timekeeper_device_config::timekeeper_device_config(const machine_config &mconfig, const char *type, const char *tag, const device_config *owner, UINT32 clock) |
| 83 | : device_config(mconfig, static_alloc_device_config, type, tag, owner, clock), |
| 84 | device_config_nvram_interface(mconfig, *this) |
| 85 | { |
| 86 | |
| 87 | } |
| 88 | |
| 89 | |
| 90 | //------------------------------------------------- |
| 91 | // static_alloc_device_config - allocate a new |
| 92 | // configuration object |
| 93 | //------------------------------------------------- |
| 94 | |
| 95 | device_config *timekeeper_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 96 | { |
| 97 | return global_alloc(timekeeper_device_config(mconfig, "TIMEKEEPER", tag, owner, clock)); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | //------------------------------------------------- |
| 102 | // alloc_device - allocate a new device object |
| 103 | //------------------------------------------------- |
| 104 | |
| 105 | device_t *timekeeper_device_config::alloc_device(running_machine &machine) const |
| 106 | { |
| 107 | return auto_alloc(&machine, timekeeper_device(machine, *this)); |
| 108 | } |
| 109 | |
| 110 | /*************************************************************************** |
| 111 | INLINE FUNCTIONS |
| 112 | ***************************************************************************/ |
| 113 | |
| 67 | 114 | INLINE UINT8 make_bcd(UINT8 data) |
| 68 | 115 | { |
| 69 | 116 | return ( ( ( data / 10 ) % 10 ) << 4 ) + ( data % 10 ); |
| r8910 | r8911 | |
| 105 | 152 | } |
| 106 | 153 | } |
| 107 | 154 | |
| 108 | | static void counters_to_ram( timekeeper_state *c ) |
| 109 | | { |
| 110 | | counter_to_ram( c->data, c->offset_control, c->control ); |
| 111 | | counter_to_ram( c->data, c->offset_seconds, c->seconds ); |
| 112 | | counter_to_ram( c->data, c->offset_minutes, c->minutes ); |
| 113 | | counter_to_ram( c->data, c->offset_hours, c->hours ); |
| 114 | | counter_to_ram( c->data, c->offset_day, c->day ); |
| 115 | | counter_to_ram( c->data, c->offset_date, c->date ); |
| 116 | | counter_to_ram( c->data, c->offset_month, c->month ); |
| 117 | | counter_to_ram( c->data, c->offset_year, c->year ); |
| 118 | | counter_to_ram( c->data, c->offset_century, c->century ); |
| 119 | | } |
| 120 | | |
| 121 | 155 | static int counter_from_ram( UINT8 *data, int offset ) |
| 122 | 156 | { |
| 123 | 157 | if( offset >= 0 ) |
| r8910 | r8911 | |
| 127 | 161 | return 0; |
| 128 | 162 | } |
| 129 | 163 | |
| 130 | | static void counters_from_ram( timekeeper_state *c ) |
| 164 | //************************************************************************** |
| 165 | // LIVE DEVICE |
| 166 | //************************************************************************** |
| 167 | |
| 168 | const device_type M48T02 = m48t02_device_config::static_alloc_device_config; |
| 169 | const device_type M48T35 = m48t35_device_config::static_alloc_device_config; |
| 170 | const device_type M48T58 = m48t58_device_config::static_alloc_device_config; |
| 171 | const device_type MK48T08 = mk48t08_device_config::static_alloc_device_config; |
| 172 | |
| 173 | TIMEKPR_DERIVE(m48t02, "M48T02") |
| 174 | TIMEKPR_DERIVE(m48t35, "M48T35") |
| 175 | TIMEKPR_DERIVE(m48t58, "M48T58") |
| 176 | TIMEKPR_DERIVE(mk48t08, "MK48T08") |
| 177 | |
| 178 | //------------------------------------------------- |
| 179 | // timekeeper_device - constructor |
| 180 | //------------------------------------------------- |
| 181 | |
| 182 | timekeeper_device::timekeeper_device(running_machine &_machine, const timekeeper_device_config &config) |
| 183 | : device_t(_machine, config), |
| 184 | device_nvram_interface(_machine, config, *this), |
| 185 | m_config(config) |
| 131 | 186 | { |
| 132 | | c->control = counter_from_ram( c->data, c->offset_control ); |
| 133 | | c->seconds = counter_from_ram( c->data, c->offset_seconds ); |
| 134 | | c->minutes = counter_from_ram( c->data, c->offset_minutes ); |
| 135 | | c->hours = counter_from_ram( c->data, c->offset_hours ); |
| 136 | | c->day = counter_from_ram( c->data, c->offset_day ); |
| 137 | | c->date = counter_from_ram( c->data, c->offset_date ); |
| 138 | | c->month = counter_from_ram( c->data, c->offset_month ); |
| 139 | | c->year = counter_from_ram( c->data, c->offset_year ); |
| 140 | | c->century = counter_from_ram( c->data, c->offset_century ); |
| 187 | |
| 141 | 188 | } |
| 142 | 189 | |
| 143 | | static TIMER_CALLBACK( timekeeper_tick ) |
| 190 | //------------------------------------------------- |
| 191 | // device_start - device-specific startup |
| 192 | //------------------------------------------------- |
| 193 | |
| 194 | void timekeeper_device::device_start() |
| 144 | 195 | { |
| 145 | | timekeeper_state *c = (timekeeper_state *) ptr; |
| 196 | emu_timer *timer; |
| 197 | attotime duration; |
| 198 | system_time systime; |
| 146 | 199 | |
| 147 | | int carry; |
| 200 | /* validate some basic stuff */ |
| 201 | assert(this != NULL); |
| 148 | 202 | |
| 149 | | if( ( c->seconds & SECONDS_ST ) != 0 || |
| 150 | | ( c->control & CONTROL_W ) != 0 ) |
| 203 | m_machine.base_datetime(systime); |
| 204 | |
| 205 | m_control = 0; |
| 206 | m_seconds = make_bcd( systime.local_time.second ); |
| 207 | m_minutes = make_bcd( systime.local_time.minute ); |
| 208 | m_hours = make_bcd( systime.local_time.hour ); |
| 209 | m_day = make_bcd( systime.local_time.weekday + 1 ); |
| 210 | m_date = make_bcd( systime.local_time.mday ); |
| 211 | m_month = make_bcd( systime.local_time.month + 1 ); |
| 212 | m_year = make_bcd( systime.local_time.year % 100 ); |
| 213 | m_century = make_bcd( systime.local_time.year / 100 ); |
| 214 | m_data = auto_alloc_array( &m_machine, UINT8, m_size ); |
| 215 | |
| 216 | m_default_data = *region(); |
| 217 | if (m_default_data) |
| 151 | 218 | { |
| 219 | assert( region()->bytes() == m_size ); |
| 220 | } |
| 221 | |
| 222 | state_save_register_device_item( this, 0, m_control ); |
| 223 | state_save_register_device_item( this, 0, m_seconds ); |
| 224 | state_save_register_device_item( this, 0, m_minutes ); |
| 225 | state_save_register_device_item( this, 0, m_hours ); |
| 226 | state_save_register_device_item( this, 0, m_day ); |
| 227 | state_save_register_device_item( this, 0, m_date ); |
| 228 | state_save_register_device_item( this, 0, m_month ); |
| 229 | state_save_register_device_item( this, 0, m_year ); |
| 230 | state_save_register_device_item( this, 0, m_century ); |
| 231 | state_save_register_device_item_pointer( this, 0, m_data, m_size ); |
| 232 | |
| 233 | timer = timer_alloc( &m_machine, timekeeper_tick_callback, (void *)this ); |
| 234 | duration = ATTOTIME_IN_SEC(1); |
| 235 | timer_adjust_periodic( timer, duration, 0, duration ); |
| 236 | } |
| 237 | |
| 238 | void m48t02_device::device_start() |
| 239 | { |
| 240 | m_offset_control = 0x7f8; |
| 241 | m_offset_seconds = 0x7f9; |
| 242 | m_offset_minutes = 0x7fa; |
| 243 | m_offset_hours = 0x7fb; |
| 244 | m_offset_day = 0x7fc; |
| 245 | m_offset_date = 0x7fd; |
| 246 | m_offset_month = 0x7fe; |
| 247 | m_offset_year = 0x7ff; |
| 248 | m_offset_century = -1; |
| 249 | m_offset_flags = -1; |
| 250 | m_size = 0x800; |
| 251 | |
| 252 | timekeeper_device::device_start(); |
| 253 | } |
| 254 | |
| 255 | void m48t35_device::device_start() |
| 256 | { |
| 257 | m_offset_control = 0x7ff8; |
| 258 | m_offset_seconds = 0x7ff9; |
| 259 | m_offset_minutes = 0x7ffa; |
| 260 | m_offset_hours = 0x7ffb; |
| 261 | m_offset_day = 0x7ffc; |
| 262 | m_offset_date = 0x7ffd; |
| 263 | m_offset_month = 0x7ffe; |
| 264 | m_offset_year = 0x7fff; |
| 265 | m_offset_century = -1; |
| 266 | m_offset_flags = -1; |
| 267 | m_size = 0x8000; |
| 268 | |
| 269 | timekeeper_device::device_start(); |
| 270 | } |
| 271 | |
| 272 | void m48t58_device::device_start() |
| 273 | { |
| 274 | m_offset_control = 0x1ff8; |
| 275 | m_offset_seconds = 0x1ff9; |
| 276 | m_offset_minutes = 0x1ffa; |
| 277 | m_offset_hours = 0x1ffb; |
| 278 | m_offset_day = 0x1ffc; |
| 279 | m_offset_date = 0x1ffd; |
| 280 | m_offset_month = 0x1ffe; |
| 281 | m_offset_year = 0x1fff; |
| 282 | m_offset_century = -1; |
| 283 | m_offset_flags = -1; |
| 284 | m_size = 0x2000; |
| 285 | |
| 286 | timekeeper_device::device_start(); |
| 287 | } |
| 288 | |
| 289 | void mk48t08_device::device_start() |
| 290 | { |
| 291 | m_offset_control = 0x1ff8; |
| 292 | m_offset_seconds = 0x1ff9; |
| 293 | m_offset_minutes = 0x1ffa; |
| 294 | m_offset_hours = 0x1ffb; |
| 295 | m_offset_day = 0x1ffc; |
| 296 | m_offset_date = 0x1ffd; |
| 297 | m_offset_month = 0x1ffe; |
| 298 | m_offset_year = 0x1fff; |
| 299 | m_offset_century = 0x1ff1; |
| 300 | m_offset_flags = 0x1ff0; |
| 301 | m_size = 0x2000; |
| 302 | |
| 303 | timekeeper_device::device_start(); |
| 304 | } |
| 305 | |
| 306 | //------------------------------------------------- |
| 307 | // device_reset - device-specific reset |
| 308 | //------------------------------------------------- |
| 309 | |
| 310 | void timekeeper_device::device_reset() |
| 311 | { |
| 312 | |
| 313 | } |
| 314 | |
| 315 | |
| 316 | void timekeeper_device::counters_to_ram() |
| 317 | { |
| 318 | counter_to_ram( m_data, m_offset_control, m_control ); |
| 319 | counter_to_ram( m_data, m_offset_seconds, m_seconds ); |
| 320 | counter_to_ram( m_data, m_offset_minutes, m_minutes ); |
| 321 | counter_to_ram( m_data, m_offset_hours, m_hours ); |
| 322 | counter_to_ram( m_data, m_offset_day, m_day ); |
| 323 | counter_to_ram( m_data, m_offset_date, m_date ); |
| 324 | counter_to_ram( m_data, m_offset_month, m_month ); |
| 325 | counter_to_ram( m_data, m_offset_year, m_year ); |
| 326 | counter_to_ram( m_data, m_offset_century, m_century ); |
| 327 | } |
| 328 | |
| 329 | void timekeeper_device::counters_from_ram() |
| 330 | { |
| 331 | m_control = counter_from_ram( m_data, m_offset_control ); |
| 332 | m_seconds = counter_from_ram( m_data, m_offset_seconds ); |
| 333 | m_minutes = counter_from_ram( m_data, m_offset_minutes ); |
| 334 | m_hours = counter_from_ram( m_data, m_offset_hours ); |
| 335 | m_day = counter_from_ram( m_data, m_offset_day ); |
| 336 | m_date = counter_from_ram( m_data, m_offset_date ); |
| 337 | m_month = counter_from_ram( m_data, m_offset_month ); |
| 338 | m_year = counter_from_ram( m_data, m_offset_year ); |
| 339 | m_century = counter_from_ram( m_data, m_offset_century ); |
| 340 | } |
| 341 | |
| 342 | TIMER_CALLBACK( timekeeper_device::timekeeper_tick_callback ) |
| 343 | { |
| 344 | reinterpret_cast<timekeeper_device *>(ptr)->timekeeper_tick(); |
| 345 | } |
| 346 | |
| 347 | void timekeeper_device::timekeeper_tick() |
| 348 | { |
| 349 | if( ( m_seconds & SECONDS_ST ) != 0 || |
| 350 | ( m_control & CONTROL_W ) != 0 ) |
| 351 | { |
| 152 | 352 | return; |
| 153 | 353 | } |
| 154 | 354 | |
| 155 | | carry = inc_bcd( &c->seconds, MASK_SECONDS, 0x00, 0x59 ); |
| 355 | int carry = inc_bcd( &m_seconds, MASK_SECONDS, 0x00, 0x59 ); |
| 156 | 356 | if( carry ) |
| 157 | 357 | { |
| 158 | | carry = inc_bcd( &c->minutes, MASK_MINUTES, 0x00, 0x59 ); |
| 358 | carry = inc_bcd( &m_minutes, MASK_MINUTES, 0x00, 0x59 ); |
| 159 | 359 | } |
| 160 | 360 | if( carry ) |
| 161 | 361 | { |
| 162 | | carry = inc_bcd( &c->hours, MASK_HOURS, 0x00, 0x23 ); |
| 362 | carry = inc_bcd( &m_hours, MASK_HOURS, 0x00, 0x23 ); |
| 163 | 363 | } |
| 164 | 364 | |
| 165 | 365 | if( carry ) |
| 166 | 366 | { |
| 167 | | UINT8 month; |
| 168 | | UINT8 year; |
| 169 | 367 | UINT8 maxdays; |
| 170 | 368 | static const UINT8 daysinmonth[] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 }; |
| 171 | 369 | |
| 172 | | inc_bcd( &c->day, MASK_DAY, 0x01, 0x07 ); |
| 370 | inc_bcd( &m_day, MASK_DAY, 0x01, 0x07 ); |
| 173 | 371 | |
| 174 | | month = from_bcd( c->month ); |
| 175 | | year = from_bcd( c->year ); |
| 372 | UINT8 month = from_bcd( m_month ); |
| 373 | UINT8 year = from_bcd( m_year ); |
| 176 | 374 | |
| 177 | 375 | if( month == 2 && ( year % 4 ) == 0 ) |
| 178 | 376 | { |
| r8910 | r8911 | |
| 187 | 385 | maxdays = 0x31; |
| 188 | 386 | } |
| 189 | 387 | |
| 190 | | carry = inc_bcd( &c->date, MASK_DATE, 0x01, maxdays ); |
| 388 | carry = inc_bcd( &m_date, MASK_DATE, 0x01, maxdays ); |
| 191 | 389 | } |
| 192 | 390 | if( carry ) |
| 193 | 391 | { |
| 194 | | carry = inc_bcd( &c->month, MASK_MONTH, 0x01, 0x12 ); |
| 392 | carry = inc_bcd( &m_month, MASK_MONTH, 0x01, 0x12 ); |
| 195 | 393 | } |
| 196 | 394 | if( carry ) |
| 197 | 395 | { |
| 198 | | carry = inc_bcd( &c->year, MASK_YEAR, 0x00, 0x99 ); |
| 396 | carry = inc_bcd( &m_year, MASK_YEAR, 0x00, 0x99 ); |
| 199 | 397 | } |
| 200 | 398 | if( carry ) |
| 201 | 399 | { |
| 202 | | carry = inc_bcd( &c->century, MASK_CENTURY, 0x00, 0x99 ); |
| 400 | carry = inc_bcd( &m_century, MASK_CENTURY, 0x00, 0x99 ); |
| 203 | 401 | |
| 204 | | if( c->device->type() == M48T35 || |
| 205 | | c->device->type() == M48T58 ) |
| 402 | if( type() == M48T35 || |
| 403 | type() == M48T58 ) |
| 206 | 404 | { |
| 207 | | if( ( c->day & DAY_CEB ) != 0 ) |
| 405 | if( ( m_day & DAY_CEB ) != 0 ) |
| 208 | 406 | { |
| 209 | | c->day ^= DAY_CB; |
| 407 | m_day ^= DAY_CB; |
| 210 | 408 | } |
| 211 | 409 | } |
| 212 | 410 | } |
| 213 | 411 | |
| 214 | | if( ( c->control & CONTROL_R ) == 0 ) |
| 412 | if( ( m_control & CONTROL_R ) == 0 ) |
| 215 | 413 | { |
| 216 | | counters_to_ram( c ); |
| 414 | counters_to_ram(); |
| 217 | 415 | } |
| 218 | 416 | } |
| 219 | 417 | |
| 220 | | /*------------------------------------------------- |
| 221 | | get_safe_token - makes sure that the passed |
| 222 | | in device is the right type |
| 223 | | -------------------------------------------------*/ |
| 224 | | |
| 225 | | INLINE timekeeper_state *get_safe_token(running_device *device) |
| 418 | void timekeeper_device::write(UINT16 offset, UINT8 data) |
| 226 | 419 | { |
| 227 | | assert(device != NULL); |
| 228 | | assert((device->type() == M48T02) || |
| 229 | | (device->type() == M48T35) || |
| 230 | | (device->type() == M48T58) || |
| 231 | | (device->type() == MK48T08)); |
| 232 | | |
| 233 | | return (timekeeper_state *)downcast<legacy_device_base *>(device)->token(); |
| 234 | | } |
| 235 | | |
| 236 | | /* memory handlers */ |
| 237 | | |
| 238 | | WRITE8_DEVICE_HANDLER( timekeeper_w ) |
| 239 | | { |
| 240 | | timekeeper_state *c = get_safe_token(device); |
| 241 | | |
| 242 | | if( offset == c->offset_control ) |
| 420 | if( offset == m_offset_control ) |
| 243 | 421 | { |
| 244 | | if( ( c->control & CONTROL_W ) != 0 && |
| 422 | if( ( m_control & CONTROL_W ) != 0 && |
| 245 | 423 | ( data & CONTROL_W ) == 0 ) |
| 246 | 424 | { |
| 247 | | counters_from_ram( c ); |
| 425 | counters_from_ram(); |
| 248 | 426 | } |
| 249 | | c->control = data; |
| 427 | m_control = data; |
| 250 | 428 | } |
| 251 | | else if( offset == c->offset_day ) |
| 429 | else if( offset == m_offset_day ) |
| 252 | 430 | { |
| 253 | | if( c->device->type() == M48T35 || |
| 254 | | c->device->type() == M48T58 ) |
| 431 | if( type() == M48T35 || |
| 432 | type() == M48T58 ) |
| 255 | 433 | { |
| 256 | | c->day = ( c->day & ~DAY_CEB ) | ( data & DAY_CEB ); |
| 434 | m_day = ( m_day & ~DAY_CEB ) | ( data & DAY_CEB ); |
| 257 | 435 | } |
| 258 | 436 | } |
| 259 | | else if( offset == c->offset_date && c->device->type() == M48T58 ) |
| 437 | else if( offset == m_offset_date && type() == M48T58 ) |
| 260 | 438 | { |
| 261 | 439 | data &= ~DATE_BL; |
| 262 | 440 | } |
| 263 | | else if( offset == c->offset_flags && c->device->type() == MK48T08 ) |
| 441 | else if( offset == m_offset_flags && type() == MK48T08 ) |
| 264 | 442 | { |
| 265 | 443 | data &= ~FLAGS_BL; |
| 266 | 444 | } |
| 267 | 445 | |
| 268 | | // logerror( "%s: timekeeper_write( %s, %04x, %02x )\n", cpuexec_describe_context(machine), c->device->tag, offset, data ); |
| 269 | | c->data[ offset ] = data; |
| 446 | m_data[ offset ] = data; |
| 270 | 447 | } |
| 271 | 448 | |
| 272 | | READ8_DEVICE_HANDLER( timekeeper_r ) |
| 449 | UINT8 timekeeper_device::read(UINT16 offset) |
| 273 | 450 | { |
| 274 | | timekeeper_state *c = get_safe_token(device); |
| 275 | | UINT8 data = c->data[ offset ]; |
| 276 | | // logerror( "%s: timekeeper_read( %s, %04x ) %02x\n", cpuexec_describe_context(machine), c->device->tag, offset, data ); |
| 277 | | return data; |
| 451 | return m_data[ offset ]; |
| 278 | 452 | } |
| 279 | 453 | |
| 280 | | /*------------------------------------------------- |
| 281 | | device start callback |
| 282 | | -------------------------------------------------*/ |
| 454 | //------------------------------------------------- |
| 455 | // nvram_default - called to initialize NVRAM to |
| 456 | // its default state |
| 457 | //------------------------------------------------- |
| 283 | 458 | |
| 284 | | static DEVICE_START(timekeeper) |
| 459 | void timekeeper_device::nvram_default() |
| 285 | 460 | { |
| 286 | | timekeeper_state *c = get_safe_token(device); |
| 287 | | emu_timer *timer; |
| 288 | | attotime duration; |
| 289 | | system_time systime; |
| 290 | | |
| 291 | | /* validate some basic stuff */ |
| 292 | | assert(device != NULL); |
| 293 | | // assert(device->baseconfig().static_config() != NULL); |
| 294 | | assert(downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config() == NULL); |
| 295 | | assert(device->machine != NULL); |
| 296 | | assert(device->machine->config != NULL); |
| 297 | | |
| 298 | | device->machine->base_datetime(systime); |
| 299 | | |
| 300 | | c->device = device; |
| 301 | | c->control = 0; |
| 302 | | c->seconds = make_bcd( systime.local_time.second ); |
| 303 | | c->minutes = make_bcd( systime.local_time.minute ); |
| 304 | | c->hours = make_bcd( systime.local_time.hour ); |
| 305 | | c->day = make_bcd( systime.local_time.weekday + 1 ); |
| 306 | | c->date = make_bcd( systime.local_time.mday ); |
| 307 | | c->month = make_bcd( systime.local_time.month + 1 ); |
| 308 | | c->year = make_bcd( systime.local_time.year % 100 ); |
| 309 | | c->century = make_bcd( systime.local_time.year / 100 ); |
| 310 | | c->data = auto_alloc_array( device->machine, UINT8, c->size ); |
| 311 | | |
| 312 | | c->default_data = *device->region(); |
| 313 | | if (c->default_data) |
| 314 | | assert( device->region()->bytes() == c->size ); |
| 315 | | |
| 316 | | state_save_register_device_item( device, 0, c->control ); |
| 317 | | state_save_register_device_item( device, 0, c->seconds ); |
| 318 | | state_save_register_device_item( device, 0, c->minutes ); |
| 319 | | state_save_register_device_item( device, 0, c->hours ); |
| 320 | | state_save_register_device_item( device, 0, c->day ); |
| 321 | | state_save_register_device_item( device, 0, c->date ); |
| 322 | | state_save_register_device_item( device, 0, c->month ); |
| 323 | | state_save_register_device_item( device, 0, c->year ); |
| 324 | | state_save_register_device_item( device, 0, c->century ); |
| 325 | | state_save_register_device_item_pointer( device, 0, c->data, c->size ); |
| 326 | | |
| 327 | | timer = timer_alloc( device->machine, timekeeper_tick, c ); |
| 328 | | duration = ATTOTIME_IN_SEC(1); |
| 329 | | timer_adjust_periodic( timer, duration, 0, duration ); |
| 330 | | } |
| 331 | | |
| 332 | | static DEVICE_START(m48t02) |
| 333 | | { |
| 334 | | timekeeper_state *c = get_safe_token(device); |
| 335 | | |
| 336 | | c->offset_control = 0x7f8; |
| 337 | | c->offset_seconds = 0x7f9; |
| 338 | | c->offset_minutes = 0x7fa; |
| 339 | | c->offset_hours = 0x7fb; |
| 340 | | c->offset_day = 0x7fc; |
| 341 | | c->offset_date = 0x7fd; |
| 342 | | c->offset_month = 0x7fe; |
| 343 | | c->offset_year = 0x7ff; |
| 344 | | c->offset_century = -1; |
| 345 | | c->offset_flags = -1; |
| 346 | | c->size = 0x800; |
| 347 | | |
| 348 | | DEVICE_START_CALL( timekeeper ); |
| 349 | | } |
| 350 | | |
| 351 | | static DEVICE_START(m48t35) |
| 352 | | { |
| 353 | | timekeeper_state *c = get_safe_token(device); |
| 354 | | |
| 355 | | c->offset_control = 0x7ff8; |
| 356 | | c->offset_seconds = 0x7ff9; |
| 357 | | c->offset_minutes = 0x7ffa; |
| 358 | | c->offset_hours = 0x7ffb; |
| 359 | | c->offset_day = 0x7ffc; |
| 360 | | c->offset_date = 0x7ffd; |
| 361 | | c->offset_month = 0x7ffe; |
| 362 | | c->offset_year = 0x7fff; |
| 363 | | c->offset_century = -1; |
| 364 | | c->offset_flags = -1; |
| 365 | | c->size = 0x8000; |
| 366 | | |
| 367 | | DEVICE_START_CALL( timekeeper ); |
| 368 | | } |
| 369 | | |
| 370 | | static DEVICE_START(m48t58) |
| 371 | | { |
| 372 | | timekeeper_state *c = get_safe_token(device); |
| 373 | | |
| 374 | | c->offset_control = 0x1ff8; |
| 375 | | c->offset_seconds = 0x1ff9; |
| 376 | | c->offset_minutes = 0x1ffa; |
| 377 | | c->offset_hours = 0x1ffb; |
| 378 | | c->offset_day = 0x1ffc; |
| 379 | | c->offset_date = 0x1ffd; |
| 380 | | c->offset_month = 0x1ffe; |
| 381 | | c->offset_year = 0x1fff; |
| 382 | | c->offset_century = -1; |
| 383 | | c->offset_flags = -1; |
| 384 | | c->size = 0x2000; |
| 385 | | |
| 386 | | DEVICE_START_CALL( timekeeper ); |
| 387 | | } |
| 388 | | |
| 389 | | static DEVICE_START(mk48t08) |
| 390 | | { |
| 391 | | timekeeper_state *c = get_safe_token(device); |
| 392 | | |
| 393 | | c->offset_control = 0x1ff8; |
| 394 | | c->offset_seconds = 0x1ff9; |
| 395 | | c->offset_minutes = 0x1ffa; |
| 396 | | c->offset_hours = 0x1ffb; |
| 397 | | c->offset_day = 0x1ffc; |
| 398 | | c->offset_date = 0x1ffd; |
| 399 | | c->offset_month = 0x1ffe; |
| 400 | | c->offset_year = 0x1fff; |
| 401 | | c->offset_century = 0x1ff1; |
| 402 | | c->offset_flags = 0x1ff0; |
| 403 | | c->size = 0x2000; |
| 404 | | |
| 405 | | DEVICE_START_CALL( timekeeper ); |
| 406 | | } |
| 407 | | |
| 408 | | /*------------------------------------------------- |
| 409 | | device reset callback |
| 410 | | -------------------------------------------------*/ |
| 411 | | |
| 412 | | static DEVICE_RESET(timekeeper) |
| 413 | | { |
| 414 | | } |
| 415 | | |
| 416 | | static DEVICE_NVRAM(timekeeper) |
| 417 | | { |
| 418 | | timekeeper_state *c = get_safe_token(device); |
| 419 | | |
| 420 | | if( read_or_write ) |
| 461 | if( m_default_data != NULL ) |
| 421 | 462 | { |
| 422 | | mame_fwrite( file, c->data, c->size ); |
| 463 | memcpy( m_data, m_default_data, m_size ); |
| 423 | 464 | } |
| 424 | 465 | else |
| 425 | 466 | { |
| 426 | | if( file ) |
| 427 | | { |
| 428 | | mame_fread( file, c->data, c->size ); |
| 429 | | } |
| 430 | | else |
| 431 | | { |
| 432 | | if( c->default_data != NULL ) |
| 433 | | { |
| 434 | | memcpy( c->data, c->default_data, c->size ); |
| 435 | | } |
| 436 | | else |
| 437 | | { |
| 438 | | memset( c->data, 0xff, c->size ); |
| 439 | | } |
| 440 | | } |
| 441 | | |
| 442 | | counters_to_ram( c ); |
| 467 | memset( m_data, 0xff, m_size ); |
| 443 | 468 | } |
| 444 | 469 | } |
| 445 | 470 | |
| 446 | | /*------------------------------------------------- |
| 447 | | device get info callback |
| 448 | | -------------------------------------------------*/ |
| 449 | 471 | |
| 450 | | static DEVICE_GET_INFO(timekeeper) |
| 451 | | { |
| 452 | | switch (state) |
| 453 | | { |
| 454 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 455 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(timekeeper_state); break; |
| 456 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; // sizeof(timekeeper_config) |
| 472 | //------------------------------------------------- |
| 473 | // nvram_read - called to read NVRAM from the |
| 474 | // .nv file |
| 475 | //------------------------------------------------- |
| 457 | 476 | |
| 458 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 459 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(timekeeper); break; |
| 460 | | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 461 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(timekeeper); break; |
| 462 | | case DEVINFO_FCT_NVRAM: info->nvram = DEVICE_NVRAM_NAME(timekeeper); break; |
| 463 | | |
| 464 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 465 | | case DEVINFO_STR_NAME: strcpy(info->s, "Timekeeper"); break; |
| 466 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "EEPROM"); break; |
| 467 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 468 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 469 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 470 | | } |
| 471 | | } |
| 472 | | |
| 473 | | DEVICE_GET_INFO( m48t02 ) |
| 477 | void timekeeper_device::nvram_read(mame_file &file) |
| 474 | 478 | { |
| 475 | | switch (state) |
| 476 | | { |
| 477 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 478 | | case DEVINFO_STR_NAME: strcpy(info->s, "M48T02"); break; |
| 479 | mame_fread( &file, m_data, m_size ); |
| 479 | 480 | |
| 480 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 481 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(m48t02); break; |
| 482 | | |
| 483 | | default: DEVICE_GET_INFO_CALL(timekeeper); break; |
| 484 | | } |
| 481 | counters_to_ram(); |
| 485 | 482 | } |
| 486 | 483 | |
| 487 | | DEVICE_GET_INFO( m48t35 ) |
| 488 | | { |
| 489 | | switch (state) |
| 490 | | { |
| 491 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 492 | | case DEVINFO_STR_NAME: strcpy(info->s, "M48T35"); break; |
| 493 | 484 | |
| 494 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 495 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(m48t35); break; |
| 485 | //------------------------------------------------- |
| 486 | // nvram_write - called to write NVRAM to the |
| 487 | // .nv file |
| 488 | //------------------------------------------------- |
| 496 | 489 | |
| 497 | | default: DEVICE_GET_INFO_CALL(timekeeper); break; |
| 498 | | } |
| 499 | | } |
| 500 | | |
| 501 | | DEVICE_GET_INFO( m48t58 ) |
| 490 | void timekeeper_device::nvram_write(mame_file &file) |
| 502 | 491 | { |
| 503 | | switch (state) |
| 504 | | { |
| 505 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 506 | | case DEVINFO_STR_NAME: strcpy(info->s, "M48T58"); break; |
| 507 | | |
| 508 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 509 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(m48t58); break; |
| 510 | | |
| 511 | | default: DEVICE_GET_INFO_CALL(timekeeper); break; |
| 512 | | } |
| 492 | mame_fwrite( &file, m_data, m_size ); |
| 513 | 493 | } |
| 514 | 494 | |
| 515 | | DEVICE_GET_INFO( mk48t08 ) |
| 516 | | { |
| 517 | | switch (state) |
| 518 | | { |
| 519 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 520 | | case DEVINFO_STR_NAME: strcpy(info->s, "MK48T08"); break; |
| 521 | 495 | |
| 522 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 523 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mk48t08); break; |
| 524 | 496 | |
| 525 | | default: DEVICE_GET_INFO_CALL(timekeeper); break; |
| 526 | | } |
| 527 | | } |
| 497 | /*************************************************************************** |
| 498 | TRAMPOLINES |
| 499 | ***************************************************************************/ |
| 528 | 500 | |
| 501 | WRITE8_DEVICE_HANDLER( timekeeper_w ) { downcast<timekeeper_device *>(device)->write(offset, data); } |
| 502 | READ8_DEVICE_HANDLER( timekeeper_r ) { return downcast<timekeeper_device*>(device)->read(offset); } |
| 529 | 503 | |
| 530 | | DEFINE_LEGACY_NVRAM_DEVICE(M48T02, m48t02); |
| 531 | | DEFINE_LEGACY_NVRAM_DEVICE(M48T35, m48t35); |
| 532 | | DEFINE_LEGACY_NVRAM_DEVICE(M48T58, m48t58); |
| 533 | | DEFINE_LEGACY_NVRAM_DEVICE(MK48T08, mk48t08); |
src/emu/machine/74123.c
| r8910 | r8911 | |
| 23 | 23 | //------------------------------------------------- |
| 24 | 24 | |
| 25 | 25 | ttl74123_device_config::ttl74123_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 26 | | : device_config(mconfig, static_alloc_device_config, "TTL74123", tag, owner, clock) |
| 26 | : device_config(mconfig, static_alloc_device_config, "TTL74123", tag, owner, clock) |
| 27 | 27 | { |
| 28 | 28 | } |
| 29 | 29 | |
| r8910 | r8911 | |
| 35 | 35 | |
| 36 | 36 | device_config *ttl74123_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 37 | 37 | { |
| 38 | | return global_alloc(ttl74123_device_config(mconfig, tag, owner, clock)); |
| 38 | return global_alloc(ttl74123_device_config(mconfig, tag, owner, clock)); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
| r8910 | r8911 | |
| 45 | 45 | |
| 46 | 46 | device_t *ttl74123_device_config::alloc_device(running_machine &machine) const |
| 47 | 47 | { |
| 48 | | return auto_alloc(&machine, ttl74123_device(machine, *this)); |
| 48 | return auto_alloc(&machine, ttl74123_device(machine, *this)); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
| r8910 | r8911 | |
| 57 | 57 | |
| 58 | 58 | void ttl74123_device_config::device_config_complete() |
| 59 | 59 | { |
| 60 | // inherit a copy of the static data |
| 61 | const ttl74123_interface *intf = reinterpret_cast<const ttl74123_interface *>(static_config()); |
| 62 | if (intf != NULL) |
| 63 | *static_cast<ttl74123_interface *>(this) = *intf; |
| 60 | 64 | |
| 65 | // or initialize to defaults if none provided |
| 66 | else |
| 67 | { |
| 68 | m_connection_type = TTL74123_NOT_GROUNDED_NO_DIODE; |
| 69 | m_res = 1.0; |
| 70 | m_cap = 1.0; |
| 71 | m_a = 0; |
| 72 | m_b = 0; |
| 73 | m_clear = 0; |
| 74 | memset(&m_output_changed_cb, 0, sizeof(m_output_changed_cb)); |
| 75 | } |
| 61 | 76 | } |
| 62 | 77 | |
| 63 | 78 | |
| r8910 | r8911 | |
| 71 | 86 | //------------------------------------------------- |
| 72 | 87 | |
| 73 | 88 | ttl74123_device::ttl74123_device(running_machine &_machine, const ttl74123_device_config &config) |
| 74 | | : device_t(_machine, config), |
| 75 | | m_config(config) |
| 89 | : device_t(_machine, config), |
| 90 | m_config(config) |
| 76 | 91 | { |
| 77 | 92 | |
| 78 | 93 | } |
| r8910 | r8911 | |
| 84 | 99 | |
| 85 | 100 | void ttl74123_device::device_start() |
| 86 | 101 | { |
| 87 | | m_timer = timer_alloc(&m_machine, clear_callback, (void *)this); |
| 102 | m_timer = timer_alloc(&m_machine, clear_callback, (void *)this); |
| 88 | 103 | |
| 89 | 104 | /* start with the defaults */ |
| 90 | | m_a = m_config.m_a; |
| 91 | | m_b = m_config.m_b; |
| 92 | | m_clear = m_config.m_clear; |
| 105 | m_a = m_config.m_a; |
| 106 | m_b = m_config.m_b; |
| 107 | m_clear = m_config.m_clear; |
| 93 | 108 | |
| 94 | 109 | /* register for state saving */ |
| 95 | | state_save_register_device_item(this, 0, m_a); |
| 96 | | state_save_register_device_item(this, 0, m_b); |
| 97 | | state_save_register_device_item(this, 0, m_clear); |
| 110 | state_save_register_device_item(this, 0, m_a); |
| 111 | state_save_register_device_item(this, 0, m_b); |
| 112 | state_save_register_device_item(this, 0, m_clear); |
| 98 | 113 | } |
| 99 | 114 | |
| 100 | 115 | |
| r8910 | r8911 | |
| 109 | 124 | |
| 110 | 125 | |
| 111 | 126 | |
| 112 | | /*------------------------------------------------- |
| 113 | | compute_duration |
| 114 | | -------------------------------------------------*/ |
| 127 | //------------------------------------------------- |
| 128 | // compute_duration - compute timer duration |
| 129 | //------------------------------------------------- |
| 115 | 130 | |
| 116 | 131 | attotime ttl74123_device::compute_duration() |
| 117 | 132 | { |
| 118 | | double duration; |
| 133 | double duration; |
| 119 | 134 | |
| 120 | | switch (m_config.m_connection_type) |
| 121 | | { |
| 122 | | case TTL74123_NOT_GROUNDED_NO_DIODE: |
| 123 | | duration = 0.28 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res)); |
| 124 | | break; |
| 135 | switch (m_config.m_connection_type) |
| 136 | { |
| 137 | case TTL74123_NOT_GROUNDED_NO_DIODE: |
| 138 | duration = 0.28 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res)); |
| 139 | break; |
| 125 | 140 | |
| 126 | | case TTL74123_NOT_GROUNDED_DIODE: |
| 127 | | duration = 0.25 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res)); |
| 128 | | break; |
| 141 | case TTL74123_NOT_GROUNDED_DIODE: |
| 142 | duration = 0.25 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res)); |
| 143 | break; |
| 129 | 144 | |
| 130 | | case TTL74123_GROUNDED: |
| 131 | | default: |
| 132 | | if (m_config.m_cap < CAP_U(0.1)) |
| 133 | | { |
| 134 | | /* this is really a curve - a very flat one in the 0.1uF-.01uF range */ |
| 135 | | duration = 0.32 * m_config.m_res * m_config.m_cap; |
| 136 | | } |
| 137 | | else |
| 138 | | { |
| 139 | | duration = 0.33 * m_config.m_res * m_config.m_cap; |
| 140 | | } |
| 141 | | break; |
| 142 | | } |
| 145 | case TTL74123_GROUNDED: |
| 146 | default: |
| 147 | if (m_config.m_cap < CAP_U(0.1)) |
| 148 | { |
| 149 | /* this is really a curve - a very flat one in the 0.1uF-.01uF range */ |
| 150 | duration = 0.32 * m_config.m_res * m_config.m_cap; |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | duration = 0.33 * m_config.m_res * m_config.m_cap; |
| 155 | } |
| 156 | break; |
| 157 | } |
| 143 | 158 | |
| 144 | | return double_to_attotime(duration); |
| 159 | return double_to_attotime(duration); |
| 145 | 160 | } |
| 146 | 161 | |
| 147 | 162 | |
| 148 | | /*------------------------------------------------- |
| 149 | | timer_running |
| 150 | | -------------------------------------------------*/ |
| 163 | //------------------------------------------------- |
| 164 | // timer_running - is the timer running? |
| 165 | //------------------------------------------------- |
| 151 | 166 | |
| 152 | 167 | int ttl74123_device::timer_running() |
| 153 | 168 | { |
| 154 | | return (attotime_compare(timer_timeleft(m_timer), attotime_zero) > 0) && |
| 155 | | (attotime_compare(timer_timeleft(m_timer), attotime_never) != 0); |
| 169 | return (attotime_compare(timer_timeleft(m_timer), attotime_zero) > 0) && |
| 170 | (attotime_compare(timer_timeleft(m_timer), attotime_never) != 0); |
| 156 | 171 | } |
| 157 | 172 | |
| 158 | 173 | |
| 159 | 174 | /*------------------------------------------------- |
| 160 | | TIMER_CALLBACK( output_callback ) |
| 175 | TIMER_CALLBACK( output_callback ) |
| 161 | 176 | -------------------------------------------------*/ |
| 162 | 177 | |
| 163 | 178 | TIMER_CALLBACK( ttl74123_device::output_callback ) |
| 164 | 179 | { |
| 165 | | ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr); |
| 166 | | dev->output(param); |
| 180 | ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr); |
| 181 | dev->output(param); |
| 167 | 182 | } |
| 168 | 183 | |
| 169 | 184 | void ttl74123_device::output(INT32 param) |
| 170 | 185 | { |
| 171 | | m_config.m_output_changed_cb(this, 0, param); |
| 186 | m_config.m_output_changed_cb(this, 0, param); |
| 172 | 187 | } |
| 173 | 188 | |
| 174 | 189 | |
| 190 | //------------------------------------------------- |
| 191 | // set_output - set the output line state |
| 192 | //------------------------------------------------- |
| 193 | |
| 175 | 194 | void ttl74123_device::set_output() |
| 176 | 195 | { |
| 177 | | int output = timer_running(); |
| 196 | int output = timer_running(); |
| 178 | 197 | |
| 179 | | timer_set( &m_machine, attotime_zero, (void *)this, output, output_callback ); |
| 198 | timer_set( &m_machine, attotime_zero, (void *)this, output, output_callback ); |
| 180 | 199 | |
| 181 | | if (LOG) logerror("74123 %s: Output: %d\n", tag(), output); |
| 200 | if (LOG) logerror("74123 %s: Output: %d\n", tag(), output); |
| 182 | 201 | } |
| 183 | 202 | |
| 184 | 203 | |
| 204 | /*------------------------------------------------- |
| 205 | TIMER_CALLBACK( clear_callback ) |
| 206 | -------------------------------------------------*/ |
| 207 | |
| 185 | 208 | TIMER_CALLBACK( ttl74123_device::clear_callback ) |
| 186 | 209 | { |
| 187 | | ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr); |
| 188 | | dev->clear(); |
| 210 | ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr); |
| 211 | dev->clear(); |
| 189 | 212 | } |
| 190 | 213 | |
| 191 | 214 | void ttl74123_device::clear() |
| 192 | 215 | { |
| 193 | | int output = timer_running(); |
| 216 | int output = timer_running(); |
| 194 | 217 | |
| 195 | | m_config.m_output_changed_cb(this, 0, output); |
| 218 | m_config.m_output_changed_cb(this, 0, output); |
| 196 | 219 | } |
| 197 | 220 | |
| 198 | 221 | |
| 222 | //------------------------------------------------- |
| 223 | // start_pulse - begin timing |
| 224 | //------------------------------------------------- |
| 225 | |
| 199 | 226 | void ttl74123_device::start_pulse() |
| 200 | 227 | { |
| 201 | | attotime duration = compute_duration(); |
| 228 | attotime duration = compute_duration(); |
| 202 | 229 | |
| 203 | | if(timer_running()) |
| 204 | | { |
| 205 | | /* retriggering, but not if we are called to quickly */ |
| 206 | | attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * m_config.m_cap * 220); |
| 230 | if(timer_running()) |
| 231 | { |
| 232 | /* retriggering, but not if we are called to quickly */ |
| 233 | attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * m_config.m_cap * 220); |
| 207 | 234 | |
| 208 | | if(attotime_compare(timer_timeelapsed(m_timer), delay_time) >= 0) |
| 209 | | { |
| 210 | | timer_adjust_oneshot(m_timer, duration, 0); |
| 235 | if(attotime_compare(timer_timeelapsed(m_timer), delay_time) >= 0) |
| 236 | { |
| 237 | timer_adjust_oneshot(m_timer, duration, 0); |
| 211 | 238 | |
| 212 | | if (LOG) logerror("74123 %s: Retriggering pulse. Duration: %f\n", tag(), attotime_to_double(duration)); |
| 213 | | } |
| 214 | | else |
| 215 | | { |
| 216 | | if (LOG) logerror("74123 %s: Retriggering failed.\n", tag()); |
| 217 | | } |
| 218 | | } |
| 219 | | else |
| 220 | | { |
| 221 | | /* starting */ |
| 222 | | timer_adjust_oneshot(m_timer, duration, 0); |
| 239 | if (LOG) logerror("74123 %s: Retriggering pulse. Duration: %f\n", tag(), attotime_to_double(duration)); |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | if (LOG) logerror("74123 %s: Retriggering failed.\n", tag()); |
| 244 | } |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | /* starting */ |
| 249 | timer_adjust_oneshot(m_timer, duration, 0); |
| 223 | 250 | |
| 224 | | set_output(); |
| 251 | set_output(); |
| 225 | 252 | |
| 226 | | if (LOG) logerror("74123 %s: Starting pulse. Duration: %f\n", tag(), attotime_to_double(duration)); |
| 227 | | } |
| 253 | if (LOG) logerror("74123 %s: Starting pulse. Duration: %f\n", tag(), attotime_to_double(duration)); |
| 254 | } |
| 228 | 255 | } |
| 229 | 256 | |
| 230 | 257 | |
| 258 | //------------------------------------------------- |
| 259 | // a_w - write register a data |
| 260 | //------------------------------------------------- |
| 261 | |
| 231 | 262 | WRITE8_DEVICE_HANDLER( ttl74123_a_w ) |
| 232 | 263 | { |
| 233 | | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 234 | | dev->a_w(data); |
| 264 | ttl74123_device *dev = downcast<ttl74123_device *>(device); |
| 265 | dev->a_w(data); |
| 235 | 266 | } |
| 236 | 267 | |
| 237 | 268 | void ttl74123_device::a_w(UINT8 data) |
| 238 | 269 | { |
| 239 | | /* start/regtrigger pulse if B=HI and falling edge on A (while clear is HI) */ |
| 240 | | if (!data && m_a && m_b && m_clear) |
| 241 | | { |
| 242 | | start_pulse(); |
| 243 | | } |
| 270 | /* start/regtrigger pulse if B=HI and falling edge on A (while clear is HI) */ |
| 271 | if (!data && m_a && m_b && m_clear) |
| 272 | { |
| 273 | start_pulse(); |
| 274 | } |
| 244 | 275 | |
| 245 | | m_a = data; |
| 276 | m_a = data; |
| 246 | 277 | } |
| 247 | 278 | |
| 248 | 279 | |
| 280 | //------------------------------------------------- |
| 281 | // b_w - write register b data |
| 282 | //------------------------------------------------- |
| 283 | |
| 249 | 284 | WRITE8_DEVICE_HANDLER( ttl74123_b_w ) |
| 250 | 285 | { |
| 251 | | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 252 | | dev->b_w(data); |
| 286 | ttl74123_device *dev = downcast<ttl74123_device *>(device); |
| 287 | dev->b_w(data); |
| 253 | 288 | } |
| 254 | 289 | |
| 255 | 290 | void ttl74123_device::b_w(UINT8 data) |
| 256 | 291 | { |
| 257 | | /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */ |
| 258 | | if (data && !m_b && !m_a && m_clear) |
| 259 | | { |
| 260 | | start_pulse(); |
| 261 | | } |
| 292 | /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */ |
| 293 | if (data && !m_b && !m_a && m_clear) |
| 294 | { |
| 295 | start_pulse(); |
| 296 | } |
| 262 | 297 | |
| 263 | | m_b = data; |
| 298 | m_b = data; |
| 264 | 299 | } |
| 265 | 300 | |
| 266 | 301 | |
| 302 | //------------------------------------------------- |
| 303 | // clear_w - write register clear data |
| 304 | //------------------------------------------------- |
| 305 | |
| 267 | 306 | WRITE8_DEVICE_HANDLER( ttl74123_clear_w ) |
| 268 | 307 | { |
| 269 | | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 270 | | dev->clear_w(data); |
| 308 | ttl74123_device *dev = downcast<ttl74123_device *>(device); |
| 309 | dev->clear_w(data); |
| 271 | 310 | } |
| 272 | 311 | |
| 273 | 312 | void ttl74123_device::clear_w(UINT8 data) |
| 274 | 313 | { |
| 275 | | /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */ |
| 276 | | if (data && !m_a && m_b && !m_clear) |
| 277 | | { |
| 278 | | start_pulse(); |
| 279 | | } |
| 280 | | else if (!data) /* clear the output */ |
| 281 | | { |
| 282 | | timer_adjust_oneshot(m_timer, attotime_zero, 0); |
| 314 | /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */ |
| 315 | if (data && !m_a && m_b && !m_clear) |
| 316 | { |
| 317 | start_pulse(); |
| 318 | } |
| 319 | else if (!data) /* clear the output */ |
| 320 | { |
| 321 | timer_adjust_oneshot(m_timer, attotime_zero, 0); |
| 283 | 322 | |
| 284 | | if (LOG) logerror("74123 #%s: Cleared\n", tag() ); |
| 285 | | } |
| 286 | | m_clear = data; |
| 323 | if (LOG) logerror("74123 #%s: Cleared\n", tag() ); |
| 324 | } |
| 325 | m_clear = data; |
| 287 | 326 | } |
| 288 | 327 | |
| 328 | |
| 329 | //------------------------------------------------- |
| 330 | // reset_w - reset device |
| 331 | //------------------------------------------------- |
| 332 | |
| 289 | 333 | WRITE8_DEVICE_HANDLER( ttl74123_reset_w ) |
| 290 | 334 | { |
| 291 | | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 292 | | dev->reset_w(); |
| 335 | ttl74123_device *dev = downcast<ttl74123_device *>(device); |
| 336 | dev->reset_w(); |
| 293 | 337 | } |
| 294 | 338 | |
| 295 | 339 | void ttl74123_device::reset_w() |
| 296 | 340 | { |
| 297 | | set_output(); |
| 341 | set_output(); |
| 298 | 342 | } |
| 299 | 343 | |
| 300 | 344 | const device_type TTL74123 = ttl74123_device_config::static_alloc_device_config; |
src/emu/machine/timekpr.h
| r8910 | r8911 | |
| 1 | | /* |
| 2 | | * STmicroelectronics TIMEKEEPER SRAM |
| 3 | | * |
| 4 | | * Supports: |
| 5 | | * M48T02 |
| 6 | | * M48T35 |
| 7 | | * M48T58 |
| 8 | | * MK48T08 |
| 9 | | * |
| 10 | | */ |
| 1 | /*************************************************************************** |
| 11 | 2 | |
| 12 | | #if !defined( TIMEKPR_H ) |
| 13 | | #define TIMEKPR_H ( 1 ) |
| 3 | timekpr.h |
| 14 | 4 | |
| 15 | | #include "devlegcy.h" |
| 5 | Various ST Microelectronics timekeeper SRAM implementations: |
| 6 | - M48T02 |
| 7 | - M48T35 |
| 8 | - M48T58 |
| 9 | - MK48T08 |
| 16 | 10 | |
| 17 | | typedef struct _timekeeper_config timekeeper_config; |
| 18 | | struct _timekeeper_config |
| 19 | | { |
| 20 | | const char *data; |
| 21 | | }; |
| 11 | ***************************************************************************/ |
| 22 | 12 | |
| 23 | | DECLARE_LEGACY_NVRAM_DEVICE(M48T02, m48t02); |
| 13 | #pragma once |
| 24 | 14 | |
| 15 | #ifndef __TIMEKPR_H__ |
| 16 | #define __TIMEKPR_H__ |
| 17 | |
| 18 | #include "emu.h" |
| 19 | |
| 20 | |
| 21 | |
| 22 | //************************************************************************** |
| 23 | // INTERFACE CONFIGURATION MACROS |
| 24 | //************************************************************************** |
| 25 | |
| 25 | 26 | #define MDRV_M48T02_ADD(_tag) \ |
| 26 | 27 | MDRV_DEVICE_ADD(_tag, M48T02, 0) |
| 27 | 28 | |
| 28 | | |
| 29 | | DECLARE_LEGACY_NVRAM_DEVICE(M48T35, m48t35); |
| 30 | | |
| 31 | 29 | #define MDRV_M48T35_ADD(_tag) \ |
| 32 | 30 | MDRV_DEVICE_ADD(_tag, M48T35, 0) |
| 33 | 31 | |
| 34 | | |
| 35 | | DECLARE_LEGACY_NVRAM_DEVICE(M48T58, m48t58); |
| 36 | | |
| 37 | 32 | #define MDRV_M48T58_ADD(_tag) \ |
| 38 | 33 | MDRV_DEVICE_ADD(_tag, M48T58, 0) |
| 39 | 34 | |
| 40 | | |
| 41 | | DECLARE_LEGACY_NVRAM_DEVICE(MK48T08, mk48t08); |
| 42 | | |
| 43 | 35 | #define MDRV_MK48T08_ADD(_tag) \ |
| 44 | 36 | MDRV_DEVICE_ADD(_tag, MK48T08, 0) |
| 45 | 37 | |
| 46 | 38 | |
| 47 | | /* memory handlers */ |
| 48 | 39 | |
| 40 | //************************************************************************** |
| 41 | // TYPE DEFINITIONS |
| 42 | //************************************************************************** |
| 43 | |
| 44 | |
| 45 | // ======================> timekeeper_config |
| 46 | |
| 47 | struct timekeeper_config |
| 48 | { |
| 49 | const UINT8 *m_data; |
| 50 | }; |
| 51 | |
| 52 | // ======================> timekeeper_device_config |
| 53 | |
| 54 | class timekeeper_device_config : public device_config, |
| 55 | public device_config_nvram_interface, |
| 56 | public timekeeper_config |
| 57 | { |
| 58 | friend class timekeeper_device; |
| 59 | friend class m48t02_device_config; |
| 60 | friend class m48t35_device_config; |
| 61 | friend class m48t58_device_config; |
| 62 | friend class mk48t08_device_config; |
| 63 | |
| 64 | protected: |
| 65 | // construction/destruction |
| 66 | timekeeper_device_config(const machine_config &mconfig, const char *type, const char *tag, const device_config *owner, UINT32 clock); |
| 67 | |
| 68 | public: |
| 69 | // allocators |
| 70 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 71 | virtual device_t *alloc_device(running_machine &machine) const; |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | // ======================> timekeeper_device |
| 76 | |
| 77 | class timekeeper_device : public device_t, |
| 78 | public device_nvram_interface |
| 79 | { |
| 80 | friend class timekeeper_device_config; |
| 81 | friend class m48t02_device; |
| 82 | friend class m48t35_device; |
| 83 | friend class m48t58_device; |
| 84 | friend class mk48t08_device; |
| 85 | |
| 86 | // construction/destruction |
| 87 | timekeeper_device(running_machine &_machine, const timekeeper_device_config &config); |
| 88 | |
| 89 | public: |
| 90 | void timekeeper_tick(); |
| 91 | |
| 92 | void write(UINT16 offset, UINT8 data); |
| 93 | UINT8 read(UINT16 offset); |
| 94 | |
| 95 | protected: |
| 96 | // device-level overrides |
| 97 | virtual void device_start(); |
| 98 | virtual void device_reset(); |
| 99 | |
| 100 | // device_nvram_interface overrides |
| 101 | virtual void nvram_default(); |
| 102 | virtual void nvram_read(mame_file &file); |
| 103 | virtual void nvram_write(mame_file &file); |
| 104 | |
| 105 | // internal state |
| 106 | const timekeeper_device_config &m_config; |
| 107 | |
| 108 | static TIMER_CALLBACK( timekeeper_tick_callback ); |
| 109 | |
| 110 | private: |
| 111 | void counters_to_ram(); |
| 112 | void counters_from_ram(); |
| 113 | |
| 114 | UINT8 m_control; |
| 115 | UINT8 m_seconds; |
| 116 | UINT8 m_minutes; |
| 117 | UINT8 m_hours; |
| 118 | UINT8 m_day; |
| 119 | UINT8 m_date; |
| 120 | UINT8 m_month; |
| 121 | UINT8 m_year; |
| 122 | UINT8 m_century; |
| 123 | |
| 124 | UINT8 *m_data; |
| 125 | UINT8 *m_default_data; |
| 126 | |
| 127 | int m_size; |
| 128 | int m_offset_control; |
| 129 | int m_offset_seconds; |
| 130 | int m_offset_minutes; |
| 131 | int m_offset_hours; |
| 132 | int m_offset_day; |
| 133 | int m_offset_date; |
| 134 | int m_offset_month; |
| 135 | int m_offset_year; |
| 136 | int m_offset_century; |
| 137 | int m_offset_flags; |
| 138 | }; |
| 139 | |
| 140 | |
| 141 | // ======================> m48t02_device_config |
| 142 | |
| 143 | class m48t02_device_config : public timekeeper_device_config |
| 144 | { |
| 145 | friend class mt48t02_device; |
| 146 | |
| 147 | m48t02_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 148 | |
| 149 | public: |
| 150 | // allocators |
| 151 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 152 | virtual device_t *alloc_device(running_machine &machine) const; |
| 153 | }; |
| 154 | |
| 155 | |
| 156 | // ======================> m48t02_device |
| 157 | |
| 158 | class m48t02_device : public timekeeper_device |
| 159 | { |
| 160 | friend class timekeeper_device; |
| 161 | friend class m48t02_device_config; |
| 162 | |
| 163 | // construction/destruction |
| 164 | m48t02_device(running_machine &_machine, const m48t02_device_config &config); |
| 165 | |
| 166 | protected: |
| 167 | // device-level overrides |
| 168 | virtual void device_start(); |
| 169 | }; |
| 170 | |
| 171 | |
| 172 | // ======================> m48t35_device_config |
| 173 | |
| 174 | class m48t35_device_config : public timekeeper_device_config |
| 175 | { |
| 176 | friend class m48t35_device; |
| 177 | friend class timekeeper_device_config; |
| 178 | |
| 179 | m48t35_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 180 | |
| 181 | public: |
| 182 | // allocators |
| 183 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 184 | virtual device_t *alloc_device(running_machine &machine) const; |
| 185 | }; |
| 186 | |
| 187 | |
| 188 | // ======================> m48t35_device |
| 189 | |
| 190 | class m48t35_device : public timekeeper_device |
| 191 | { |
| 192 | friend class m48t35_device_config; |
| 193 | |
| 194 | // construction/destruction |
| 195 | m48t35_device(running_machine &_machine, const m48t35_device_config &config); |
| 196 | |
| 197 | protected: |
| 198 | // device-level overrides |
| 199 | virtual void device_start(); |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | // ======================> m48t58_device_config |
| 204 | |
| 205 | class m48t58_device_config : public timekeeper_device_config |
| 206 | { |
| 207 | friend class m48t58_device; |
| 208 | friend class timekeeper_device_config; |
| 209 | |
| 210 | m48t58_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 211 | |
| 212 | public: |
| 213 | // allocators |
| 214 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 215 | virtual device_t *alloc_device(running_machine &machine) const; |
| 216 | }; |
| 217 | |
| 218 | |
| 219 | // ======================> m48t58_device |
| 220 | |
| 221 | class m48t58_device : public timekeeper_device |
| 222 | { |
| 223 | friend class m48t58_device_config; |
| 224 | |
| 225 | // construction/destruction |
| 226 | m48t58_device(running_machine &_machine, const m48t58_device_config &config); |
| 227 | |
| 228 | protected: |
| 229 | // device-level overrides |
| 230 | virtual void device_start(); |
| 231 | }; |
| 232 | |
| 233 | |
| 234 | // ======================> mk48t08_device_config |
| 235 | |
| 236 | class mk48t08_device_config : public timekeeper_device_config |
| 237 | { |
| 238 | friend class mk48t08_device; |
| 239 | friend class timekeeper_device_config; |
| 240 | |
| 241 | mk48t08_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 242 | |
| 243 | public: |
| 244 | // allocators |
| 245 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 246 | virtual device_t *alloc_device(running_machine &machine) const; |
| 247 | }; |
| 248 | |
| 249 | |
| 250 | // ======================> mk48t08_device |
| 251 | |
| 252 | class mk48t08_device : public timekeeper_device |
| 253 | { |
| 254 | friend class mk48t08_device_config; |
| 255 | |
| 256 | // construction/destruction |
| 257 | mk48t08_device(running_machine &_machine, const mk48t08_device_config &config); |
| 258 | |
| 259 | protected: |
| 260 | // device-level overrides |
| 261 | virtual void device_start(); |
| 262 | }; |
| 263 | |
| 264 | |
| 265 | // device type definition |
| 266 | extern const device_type M48T02; |
| 267 | extern const device_type M48T35; |
| 268 | extern const device_type M48T58; |
| 269 | extern const device_type MK48T08; |
| 270 | |
| 271 | |
| 272 | |
| 273 | //************************************************************************** |
| 274 | // READ/WRITE HANDLERS |
| 275 | //************************************************************************** |
| 276 | |
| 49 | 277 | WRITE8_DEVICE_HANDLER( timekeeper_w ); |
| 50 | 278 | READ8_DEVICE_HANDLER( timekeeper_r ); |
| 51 | 279 | |
| 52 | | #endif |
| 280 | #endif // __TIMEKPR_H__ |
src/emu/machine/6532riot.c
| r8910 | r8911 | |
| 40 | 40 | //------------------------------------------------- |
| 41 | 41 | |
| 42 | 42 | riot6532_device_config::riot6532_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 43 | | : device_config(mconfig, static_alloc_device_config, "RIOT6532", tag, owner, clock) |
| 43 | : device_config(mconfig, static_alloc_device_config, "RIOT6532", tag, owner, clock) |
| 44 | 44 | { |
| 45 | 45 | } |
| 46 | 46 | |
| r8910 | r8911 | |
| 52 | 52 | |
| 53 | 53 | device_config *riot6532_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 54 | 54 | { |
| 55 | | return global_alloc(riot6532_device_config(mconfig, tag, owner, clock)); |
| 55 | return global_alloc(riot6532_device_config(mconfig, tag, owner, clock)); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
| r8910 | r8911 | |
| 62 | 62 | |
| 63 | 63 | device_t *riot6532_device_config::alloc_device(running_machine &machine) const |
| 64 | 64 | { |
| 65 | | return auto_alloc(&machine, riot6532_device(machine, *this)); |
| 65 | return auto_alloc(&machine, riot6532_device(machine, *this)); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
| r8910 | r8911 | |
| 74 | 74 | |
| 75 | 75 | void riot6532_device_config::device_config_complete() |
| 76 | 76 | { |
| 77 | | // inherit a copy of the static data |
| 78 | | const riot6532_interface *intf = reinterpret_cast<const riot6532_interface *>(static_config()); |
| 79 | | if (intf != NULL) |
| 80 | | { |
| 81 | | *static_cast<riot6532_interface *>(this) = *intf; |
| 82 | | } |
| 77 | // inherit a copy of the static data |
| 78 | const riot6532_interface *intf = reinterpret_cast<const riot6532_interface *>(static_config()); |
| 79 | if (intf != NULL) |
| 80 | { |
| 81 | *static_cast<riot6532_interface *>(this) = *intf; |
| 82 | } |
| 83 | 83 | |
| 84 | | // or initialize to defaults if none provided |
| 85 | | else |
| 86 | | { |
| 87 | | memset(&m_in_a_func, 0, sizeof(m_in_a_func)); |
| 88 | | memset(&m_in_b_func, 0, sizeof(m_in_b_func)); |
| 89 | | memset(&m_out_a_func, 0, sizeof(m_out_a_func)); |
| 90 | | memset(&m_out_b_func, 0, sizeof(m_out_b_func)); |
| 91 | | memset(&m_irq_func, 0, sizeof(m_irq_func)); |
| 92 | | } |
| 84 | // or initialize to defaults if none provided |
| 85 | else |
| 86 | { |
| 87 | memset(&m_in_a_func, 0, sizeof(m_in_a_func)); |
| 88 | memset(&m_in_b_func, 0, sizeof(m_in_b_func)); |
| 89 | memset(&m_out_a_func, 0, sizeof(m_out_a_func)); |
| 90 | memset(&m_out_b_func, 0, sizeof(m_out_b_func)); |
| 91 | memset(&m_irq_func, 0, sizeof(m_irq_func)); |
| 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| r8910 | r8911 | |
| 108 | 108 | int state = (m_irqstate & m_irqenable); |
| 109 | 109 | |
| 110 | 110 | if (m_irq_func.write != NULL) |
| 111 | | { |
| 111 | { |
| 112 | 112 | devcb_call_write_line(&m_irq_func, (state != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 113 | | } |
| 113 | } |
| 114 | 114 | else |
| 115 | | { |
| 115 | { |
| 116 | 116 | logerror("%s:6532RIOT chip #%d: no irq callback function\n", cpuexec_describe_context(&m_machine), m_index); |
| 117 | | } |
| 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
| r8910 | r8911 | |
| 156 | 156 | { |
| 157 | 157 | /* if idle, return 0 */ |
| 158 | 158 | if (m_timerstate == TIMER_IDLE) |
| 159 | | { |
| 159 | { |
| 160 | 160 | return 0; |
| 161 | | } |
| 161 | } |
| 162 | 162 | |
| 163 | 163 | /* if counting, return the number of ticks remaining */ |
| 164 | 164 | else if (m_timerstate == TIMER_COUNTING) |
| 165 | | { |
| 165 | { |
| 166 | 166 | return attotime_to_ticks(timer_timeleft(m_timer), clock()) >> m_timershift; |
| 167 | | } |
| 167 | } |
| 168 | 168 | |
| 169 | 169 | /* if finishing, return the number of ticks without the shift */ |
| 170 | 170 | else |
| 171 | | { |
| 171 | { |
| 172 | 172 | return attotime_to_ticks(timer_timeleft(m_timer), clock()); |
| 173 | | } |
| 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
| r8910 | r8911 | |
| 182 | 182 | |
| 183 | 183 | TIMER_CALLBACK( riot6532_device::timer_end_callback ) |
| 184 | 184 | { |
| 185 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(ptr); |
| 186 | | via->timer_end(); |
| 185 | riot6532_device *via = reinterpret_cast<riot6532_device *>(ptr); |
| 186 | via->timer_end(); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | void riot6532_device::timer_end() |
| r8910 | r8911 | |
| 220 | 220 | |
| 221 | 221 | WRITE8_DEVICE_HANDLER( riot6532_w ) |
| 222 | 222 | { |
| 223 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 224 | | via->reg_w(offset, data); |
| 223 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 224 | via->reg_w(offset, data); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | void riot6532_device::reg_w(UINT8 offset, UINT8 data) |
| r8910 | r8911 | |
| 244 | 244 | |
| 245 | 245 | /* writes here clear the timer flag */ |
| 246 | 246 | if (m_timerstate != TIMER_FINISHING || get_timer() != 0xff) |
| 247 | | { |
| 247 | { |
| 248 | 248 | m_irqstate &= ~TIMER_FLAG; |
| 249 | | } |
| 249 | } |
| 250 | 250 | update_irqstate(); |
| 251 | 251 | |
| 252 | 252 | /* update the timer */ |
| r8910 | r8911 | |
| 260 | 260 | { |
| 261 | 261 | /* A1 contains the A7 IRQ enable */ |
| 262 | 262 | if (offset & 2) |
| 263 | | { |
| 263 | { |
| 264 | 264 | m_irqenable |= PA7_FLAG; |
| 265 | | } |
| 265 | } |
| 266 | 266 | else |
| 267 | | { |
| 267 | { |
| 268 | 268 | m_irqenable &= ~PA7_FLAG; |
| 269 | | } |
| 269 | } |
| 270 | 270 | |
| 271 | 271 | /* A0 specifies the edge detect direction: 0=negative, 1=positive */ |
| 272 | 272 | m_pa7dir = (offset & 1) << 7; |
| r8910 | r8911 | |
| 280 | 280 | |
| 281 | 281 | /* if A0 == 1, we are writing to the port's DDR */ |
| 282 | 282 | if (offset & 1) |
| 283 | | { |
| 283 | { |
| 284 | 284 | port->m_ddr = data; |
| 285 | | } |
| 285 | } |
| 286 | 286 | |
| 287 | 287 | /* if A0 == 0, we are writing to the port's output */ |
| 288 | 288 | else |
| 289 | 289 | { |
| 290 | 290 | port->m_out = data; |
| 291 | 291 | if (port->m_out_func.write != NULL) |
| 292 | | { |
| 292 | { |
| 293 | 293 | devcb_call_write8(&port->m_out_func, 0, data); |
| 294 | | } |
| 294 | } |
| 295 | 295 | else |
| 296 | | { |
| 296 | { |
| 297 | 297 | logerror("%s:6532RIOT chip %s: Port %c is being written to but has no handler. %02X\n", cpuexec_describe_context(&m_machine), tag(), 'A' + (offset & 1), data); |
| 298 | | } |
| 298 | } |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /* writes to port A need to update the PA7 state */ |
| 302 | 302 | if (port == &m_port[0]) |
| 303 | | { |
| 303 | { |
| 304 | 304 | update_pa7_state(); |
| 305 | | } |
| 305 | } |
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| r8910 | r8911 | |
| 313 | 313 | |
| 314 | 314 | READ8_DEVICE_HANDLER( riot6532_r ) |
| 315 | 315 | { |
| 316 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 317 | | return via->reg_r(offset); |
| 316 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 317 | return via->reg_r(offset); |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | UINT8 riot6532_device::reg_r(UINT8 offset) |
| r8910 | r8911 | |
| 338 | 338 | |
| 339 | 339 | /* A3 contains the timer IRQ enable */ |
| 340 | 340 | if (offset & 8) |
| 341 | | { |
| 341 | { |
| 342 | 342 | m_irqenable |= TIMER_FLAG; |
| 343 | | } |
| 343 | } |
| 344 | 344 | else |
| 345 | | { |
| 345 | { |
| 346 | 346 | m_irqenable &= ~TIMER_FLAG; |
| 347 | | } |
| 347 | } |
| 348 | 348 | |
| 349 | 349 | /* implicitly clears the timer flag */ |
| 350 | 350 | if (m_timerstate != TIMER_FINISHING || val != 0xff) |
| 351 | | { |
| 351 | { |
| 352 | 352 | m_irqstate &= ~TIMER_FLAG; |
| 353 | | } |
| 353 | } |
| 354 | 354 | update_irqstate(); |
| 355 | 355 | } |
| 356 | 356 | |
| r8910 | r8911 | |
| 362 | 362 | |
| 363 | 363 | /* if A0 == 1, we are reading the port's DDR */ |
| 364 | 364 | if (offset & 1) |
| 365 | | { |
| 365 | { |
| 366 | 366 | val = port->m_ddr; |
| 367 | | } |
| 367 | } |
| 368 | 368 | |
| 369 | 369 | /* if A0 == 0, we are reading the port as an input */ |
| 370 | 370 | else |
| r8910 | r8911 | |
| 376 | 376 | |
| 377 | 377 | /* changes to port A need to update the PA7 state */ |
| 378 | 378 | if (port == &m_port[0]) |
| 379 | | { |
| 379 | { |
| 380 | 380 | update_pa7_state(); |
| 381 | | } |
| 381 | } |
| 382 | 382 | } |
| 383 | 383 | else |
| 384 | | { |
| 384 | { |
| 385 | 385 | logerror("%s:6532RIOT chip %s: Port %c is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag(), 'A' + (offset & 1)); |
| 386 | | } |
| 386 | } |
| 387 | 387 | |
| 388 | 388 | /* apply the DDR to the result */ |
| 389 | 389 | val = apply_ddr(port); |
| r8910 | r8911 | |
| 399 | 399 | |
| 400 | 400 | void riot6532_porta_in_set(running_device *device, UINT8 data, UINT8 mask) |
| 401 | 401 | { |
| 402 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 403 | | via->porta_in_set(data, mask); |
| 402 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 403 | via->porta_in_set(data, mask); |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | void riot6532_device::porta_in_set(UINT8 data, UINT8 mask) |
| r8910 | r8911 | |
| 416 | 416 | |
| 417 | 417 | void riot6532_portb_in_set(running_device *device, UINT8 data, UINT8 mask) |
| 418 | 418 | { |
| 419 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 420 | | via->portb_in_set(data, mask); |
| 419 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 420 | via->portb_in_set(data, mask); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | void riot6532_device::portb_in_set(UINT8 data, UINT8 mask) |
| r8910 | r8911 | |
| 432 | 432 | |
| 433 | 433 | UINT8 riot6532_porta_in_get(running_device *device) |
| 434 | 434 | { |
| 435 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 436 | | return via->porta_in_get(); |
| 435 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 436 | return via->porta_in_get(); |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | UINT8 riot6532_device::porta_in_get() |
| r8910 | r8911 | |
| 448 | 448 | |
| 449 | 449 | UINT8 riot6532_portb_in_get(running_device *device) |
| 450 | 450 | { |
| 451 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 452 | | return via->portb_in_get(); |
| 451 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 452 | return via->portb_in_get(); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | UINT8 riot6532_device::portb_in_get() |
| r8910 | r8911 | |
| 464 | 464 | |
| 465 | 465 | UINT8 riot6532_porta_out_get(running_device *device) |
| 466 | 466 | { |
| 467 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 468 | | return via->porta_out_get(); |
| 467 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 468 | return via->porta_out_get(); |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | UINT8 riot6532_device::porta_out_get() |
| r8910 | r8911 | |
| 480 | 480 | |
| 481 | 481 | UINT8 riot6532_portb_out_get(running_device *device) |
| 482 | 482 | { |
| 483 | | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 484 | | return via->portb_out_get(); |
| 483 | riot6532_device *via = downcast<riot6532_device *>(device); |
| 484 | return via->portb_out_get(); |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | UINT8 riot6532_device::portb_out_get() |
| r8910 | r8911 | |
| 499 | 499 | //------------------------------------------------- |
| 500 | 500 | |
| 501 | 501 | riot6532_device::riot6532_device(running_machine &_machine, const riot6532_device_config &config) |
| 502 | | : device_t(_machine, config), |
| 503 | | m_config(config) |
| 502 | : device_t(_machine, config), |
| 503 | m_config(config) |
| 504 | 504 | { |
| 505 | 505 | } |
| 506 | 506 | |
| r8910 | r8911 | |
| 517 | 517 | m_index = m_machine.m_devicelist.index(RIOT6532, tag()); |
| 518 | 518 | |
| 519 | 519 | /* configure the ports */ |
| 520 | | devcb_resolve_read8(&m_port[0].m_in_func, &m_config.m_in_a_func, this); |
| 521 | | devcb_resolve_write8(&m_port[0].m_out_func, &m_config.m_out_a_func, this); |
| 522 | | devcb_resolve_read8(&m_port[1].m_in_func, &m_config.m_in_b_func, this); |
| 523 | | devcb_resolve_write8(&m_port[1].m_out_func, &m_config.m_out_b_func, this); |
| 520 | devcb_resolve_read8(&m_port[0].m_in_func, &m_config.m_in_a_func, this); |
| 521 | devcb_resolve_write8(&m_port[0].m_out_func, &m_config.m_out_a_func, this); |
| 522 | devcb_resolve_read8(&m_port[1].m_in_func, &m_config.m_in_b_func, this); |
| 523 | devcb_resolve_write8(&m_port[1].m_out_func, &m_config.m_out_b_func, this); |
| 524 | 524 | |
| 525 | 525 | /* resolve irq func */ |
| 526 | | devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this); |
| 526 | devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this); |
| 527 | 527 | |
| 528 | 528 | /* allocate timers */ |
| 529 | | m_timer = timer_alloc(&m_machine, timer_end_callback, (void *)this); |
| 529 | m_timer = timer_alloc(&m_machine, timer_end_callback, (void *)this); |
| 530 | 530 | |
| 531 | 531 | /* register for save states */ |
| 532 | | state_save_register_device_item(this, 0, m_port[0].m_in); |
| 533 | | state_save_register_device_item(this, 0, m_port[0].m_out); |
| 534 | | state_save_register_device_item(this, 0, m_port[0].m_ddr); |
| 535 | | state_save_register_device_item(this, 0, m_port[1].m_in); |
| 536 | | state_save_register_device_item(this, 0, m_port[1].m_out); |
| 537 | | state_save_register_device_item(this, 0, m_port[1].m_ddr); |
| 532 | state_save_register_device_item(this, 0, m_port[0].m_in); |
| 533 | state_save_register_device_item(this, 0, m_port[0].m_out); |
| 534 | state_save_register_device_item(this, 0, m_port[0].m_ddr); |
| 535 | state_save_register_device_item(this, 0, m_port[1].m_in); |
| 536 | state_save_register_device_item(this, 0, m_port[1].m_out); |
| 537 | state_save_register_device_item(this, 0, m_port[1].m_ddr); |
| 538 | 538 | |
| 539 | | state_save_register_device_item(this, 0, m_irqstate); |
| 540 | | state_save_register_device_item(this, 0, m_irqenable); |
| 539 | state_save_register_device_item(this, 0, m_irqstate); |
| 540 | state_save_register_device_item(this, 0, m_irqenable); |
| 541 | 541 | |
| 542 | | state_save_register_device_item(this, 0, m_pa7dir); |
| 543 | | state_save_register_device_item(this, 0, m_pa7prev); |
| 542 | state_save_register_device_item(this, 0, m_pa7dir); |
| 543 | state_save_register_device_item(this, 0, m_pa7prev); |
| 544 | 544 | |
| 545 | | state_save_register_device_item(this, 0, m_timershift); |
| 546 | | state_save_register_device_item(this, 0, m_timerstate); |
| 545 | state_save_register_device_item(this, 0, m_timershift); |
| 546 | state_save_register_device_item(this, 0, m_timerstate); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | |
src/emu/machine/6840ptm.c
| r8910 | r8911 | |
| 35 | 35 | |
| 36 | 36 | #include "emu.h" |
| 37 | 37 | #include "6840ptm.h" |
| 38 | #include "devhelpr.h" |
| 38 | 39 | |
| 39 | 40 | |
| 40 | 41 | #define PTMVERBOSE 0 |
| 41 | 42 | #define PLOG(x) do { if (PTMVERBOSE) logerror x; } while (0) |
| 42 | 43 | |
| 43 | 44 | /*************************************************************************** |
| 44 | | PARAMETERS / PROTOTYPES |
| 45 | LOCAL VARIABLES |
| 45 | 46 | ***************************************************************************/ |
| 46 | 47 | |
| 47 | | enum |
| 48 | const char *const ptm6840_device::opmode[] = |
| 48 | 49 | { |
| 49 | | PTM_6840_CTRL1 = 0, |
| 50 | | PTM_6840_CTRL2 = 1, |
| 51 | | PTM_6840_STATUS = 1, |
| 52 | | PTM_6840_MSBBUF1 = 2, |
| 53 | | PTM_6840_LSB1 = 3, |
| 54 | | PTM_6840_MSBBUF2 = 4, |
| 55 | | PTM_6840_LSB2 = 5, |
| 56 | | PTM_6840_MSBBUF3 = 6, |
| 57 | | PTM_6840_LSB3 = 7, |
| 58 | | }; |
| 59 | | |
| 60 | | static const char *const opmode[] = |
| 61 | | { |
| 62 | 50 | "000 continuous mode", |
| 63 | 51 | "001 freq comparison mode", |
| 64 | 52 | "010 continuous mode", |
| r8910 | r8911 | |
| 69 | 57 | "111 pulse width comparison mode" |
| 70 | 58 | }; |
| 71 | 59 | |
| 72 | | static void ptm6840_timeout(running_device *device, int idx); |
| 73 | | |
| 74 | 60 | /*************************************************************************** |
| 75 | | TYPE DEFINITIONS |
| 61 | IMPLEMENTATION |
| 76 | 62 | ***************************************************************************/ |
| 77 | 63 | |
| 78 | | typedef struct _ptm6840_state ptm6840_state; |
| 79 | | struct _ptm6840_state |
| 64 | GENERIC_DEVICE_CONFIG_SETUP(ptm6840, "PTM6840") |
| 65 | |
| 66 | const device_type PTM6840 = ptm6840_device_config::static_alloc_device_config; |
| 67 | |
| 68 | //------------------------------------------------- |
| 69 | // device_config_complete - perform any |
| 70 | // operations now that the configuration is |
| 71 | // complete |
| 72 | //------------------------------------------------- |
| 73 | |
| 74 | void ptm6840_device_config::device_config_complete() |
| 80 | 75 | { |
| 81 | | double internal_clock; |
| 82 | | double external_clock[3]; |
| 83 | | devcb_resolved_write8 out_func[3]; // function to call when output[idx] changes |
| 84 | | devcb_resolved_write_line irq_func; // function called if IRQ line changes |
| 76 | // inherit a copy of the static data |
| 77 | const ptm6840_interface *intf = reinterpret_cast<const ptm6840_interface *>(static_config()); |
| 78 | if (intf != NULL) |
| 79 | { |
| 80 | *static_cast<ptm6840_interface *>(this) = *intf; |
| 81 | } |
| 85 | 82 | |
| 86 | | UINT8 control_reg[3]; |
| 87 | | UINT8 output[3]; /* Output states */ |
| 88 | | UINT8 gate[3]; /* Input gate states */ |
| 89 | | UINT8 clock[3]; /* Clock states */ |
| 90 | | UINT8 enabled[3]; |
| 91 | | UINT8 mode[3]; |
| 92 | | UINT8 fired[3]; |
| 93 | | UINT8 t3_divisor; |
| 94 | | UINT8 t3_scaler; |
| 95 | | UINT8 IRQ; |
| 96 | | UINT8 status_reg; |
| 97 | | UINT8 status_read_since_int; |
| 98 | | UINT8 lsb_buffer; |
| 99 | | UINT8 msb_buffer; |
| 83 | // or initialize to defaults if none provided |
| 84 | else |
| 85 | { |
| 86 | m_internal_clock = 0.0; |
| 87 | m_external_clock[0] = 0.0; |
| 88 | m_external_clock[1] = 0.0; |
| 89 | m_external_clock[2] = 0.0; |
| 90 | memset(&m_irq_func, 0, sizeof(m_irq_func)); |
| 91 | memset(&m_out_func[0], 0, sizeof(m_out_func[0])); |
| 92 | memset(&m_out_func[1], 0, sizeof(m_out_func[1])); |
| 93 | memset(&m_out_func[2], 0, sizeof(m_out_func[2])); |
| 94 | } |
| 95 | } |
| 100 | 96 | |
| 101 | | /* Each PTM has 3 timers */ |
| 102 | | emu_timer *timer[3]; |
| 103 | 97 | |
| 104 | | UINT16 latch[3]; |
| 105 | | UINT16 counter[3]; |
| 106 | | }; |
| 98 | //------------------------------------------------- |
| 99 | // ptm6840_device - constructor |
| 100 | //------------------------------------------------- |
| 107 | 101 | |
| 102 | ptm6840_device::ptm6840_device(running_machine &_machine, const ptm6840_device_config &config) |
| 103 | : device_t(_machine, config), |
| 104 | m_config(config) |
| 105 | { |
| 108 | 106 | |
| 109 | | /*************************************************************************** |
| 110 | | INLINE FUNCTIONS |
| 111 | | ***************************************************************************/ |
| 107 | } |
| 112 | 108 | |
| 113 | | INLINE ptm6840_state *get_safe_token(running_device *device) |
| 109 | |
| 110 | //------------------------------------------------- |
| 111 | // device_start - device-specific startup |
| 112 | //------------------------------------------------- |
| 113 | |
| 114 | void ptm6840_device::device_start() |
| 114 | 115 | { |
| 115 | | assert(device != NULL); |
| 116 | | assert((device->type() == PTM6840)); |
| 117 | | return (ptm6840_state *)downcast<legacy_device_base *>(device)->token(); |
| 116 | m_internal_clock = m_config.m_internal_clock; |
| 117 | |
| 118 | /* resolve callbacks */ |
| 119 | for (int i = 0; i < 3; i++) |
| 120 | { |
| 121 | devcb_resolve_write8(&m_out_func[i], &m_config.m_out_func[i], this); |
| 122 | } |
| 123 | |
| 124 | for (int i = 0; i < 3; i++) |
| 125 | { |
| 126 | if ( m_config.m_external_clock[i] ) |
| 127 | { |
| 128 | m_external_clock[i] = m_config.m_external_clock[i]; |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | m_external_clock[i] = 1; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
| 137 | m_timer[0] = timer_alloc(&m_machine, ptm6840_timer1_cb, (void *)this); |
| 138 | m_timer[1] = timer_alloc(&m_machine, ptm6840_timer2_cb, (void *)this); |
| 139 | m_timer[2] = timer_alloc(&m_machine, ptm6840_timer3_cb, (void *)this); |
| 140 | |
| 141 | for (int i = 0; i < 3; i++) |
| 142 | { |
| 143 | timer_enable(m_timer[i], FALSE); |
| 144 | } |
| 145 | |
| 146 | devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this); |
| 147 | |
| 148 | /* register for state saving */ |
| 149 | state_save_register_device_item(this, 0, m_lsb_buffer); |
| 150 | state_save_register_device_item(this, 0, m_msb_buffer); |
| 151 | state_save_register_device_item(this, 0, m_status_read_since_int); |
| 152 | state_save_register_device_item(this, 0, m_status_reg); |
| 153 | state_save_register_device_item(this, 0, m_t3_divisor); |
| 154 | state_save_register_device_item(this, 0, m_t3_scaler); |
| 155 | state_save_register_device_item(this, 0, m_internal_clock); |
| 156 | state_save_register_device_item(this, 0, m_IRQ); |
| 157 | |
| 158 | state_save_register_device_item_array(this, 0, m_control_reg); |
| 159 | state_save_register_device_item_array(this, 0, m_output); |
| 160 | state_save_register_device_item_array(this, 0, m_gate); |
| 161 | state_save_register_device_item_array(this, 0, m_clk); |
| 162 | state_save_register_device_item_array(this, 0, m_mode); |
| 163 | state_save_register_device_item_array(this, 0, m_fired); |
| 164 | state_save_register_device_item_array(this, 0, m_enabled); |
| 165 | state_save_register_device_item_array(this, 0, m_external_clock); |
| 166 | state_save_register_device_item_array(this, 0, m_counter); |
| 167 | state_save_register_device_item_array(this, 0, m_latch); |
| 118 | 168 | } |
| 119 | 169 | |
| 120 | | INLINE const ptm6840_interface *get_interface(running_device *device) |
| 170 | |
| 171 | //------------------------------------------------- |
| 172 | // device_reset - device-specific reset |
| 173 | //------------------------------------------------- |
| 174 | |
| 175 | void ptm6840_device::device_reset() |
| 121 | 176 | { |
| 122 | | assert(device != NULL); |
| 123 | | assert((device->type() == PTM6840)); |
| 124 | | return (const ptm6840_interface *) device->baseconfig().static_config(); |
| 177 | m_control_reg[2] = 0; |
| 178 | m_control_reg[1] = 0; |
| 179 | m_control_reg[0] = 1; |
| 180 | m_status_reg = 0; |
| 181 | m_t3_divisor = 1; |
| 182 | m_status_read_since_int = 0; |
| 183 | m_IRQ = 0; |
| 184 | |
| 185 | for (int i = 0; i < 3; i++) |
| 186 | { |
| 187 | m_counter[i] = 0xffff; |
| 188 | m_latch[i] = 0xffff; |
| 189 | m_output[i] = 0; |
| 190 | m_fired[i] = 0; |
| 191 | } |
| 125 | 192 | } |
| 126 | 193 | |
| 127 | 194 | |
| 128 | | /*************************************************************************** |
| 129 | | IMPLEMENTATION |
| 130 | | ***************************************************************************/ |
| 131 | 195 | |
| 132 | 196 | /*------------------------------------------------- |
| 133 | 197 | ptm6840_get_status - Get enabled status |
| r8910 | r8911 | |
| 135 | 199 | |
| 136 | 200 | int ptm6840_get_status( running_device *device, int clock ) |
| 137 | 201 | { |
| 138 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 139 | | return ptm6840->enabled[clock - 1]; |
| 202 | return downcast<ptm6840_device*>(device)->ptm6840_get_status(clock); |
| 140 | 203 | } |
| 141 | 204 | |
| 205 | int ptm6840_device::ptm6840_get_status( int clock ) |
| 206 | { |
| 207 | return m_enabled[clock - 1]; |
| 208 | } |
| 209 | |
| 210 | |
| 211 | |
| 142 | 212 | /*------------------------------------------------- |
| 143 | 213 | ptm6840_get_irq - Get IRQ state |
| 144 | 214 | -------------------------------------------------*/ |
| 145 | 215 | |
| 146 | 216 | int ptm6840_get_irq( running_device *device ) |
| 147 | 217 | { |
| 148 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 149 | | return ptm6840->IRQ; |
| 218 | return downcast<ptm6840_device*>(device)->ptm6840_get_irq(); |
| 150 | 219 | } |
| 151 | 220 | |
| 221 | int ptm6840_device::ptm6840_get_irq() |
| 222 | { |
| 223 | return m_IRQ; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | |
| 152 | 228 | /*------------------------------------------------- |
| 153 | 229 | subtract_from_counter - Subtract from Counter |
| 154 | 230 | -------------------------------------------------*/ |
| 155 | 231 | |
| 156 | | static void subtract_from_counter( running_device *device, int counter, int count ) |
| 232 | void ptm6840_device::subtract_from_counter(int counter, int count) |
| 157 | 233 | { |
| 158 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 159 | 234 | double clock; |
| 160 | | attotime duration; |
| 161 | 235 | |
| 162 | 236 | /* Determine the clock frequency for this timer */ |
| 163 | | if (ptm6840->control_reg[counter] & 0x02) |
| 164 | | clock = ptm6840->internal_clock; |
| 237 | if (m_control_reg[counter] & 0x02) |
| 238 | { |
| 239 | clock = m_internal_clock; |
| 240 | } |
| 165 | 241 | else |
| 166 | | clock = ptm6840->external_clock[counter]; |
| 242 | { |
| 243 | clock = m_external_clock[counter]; |
| 244 | } |
| 167 | 245 | |
| 168 | 246 | /* Dual-byte mode */ |
| 169 | | if (ptm6840->control_reg[counter] & 0x04) |
| 247 | if (m_control_reg[counter] & 0x04) |
| 170 | 248 | { |
| 171 | | int lsb = ptm6840->counter[counter] & 0xff; |
| 172 | | int msb = ptm6840->counter[counter] >> 8; |
| 249 | int lsb = m_counter[counter] & 0xff; |
| 250 | int msb = m_counter[counter] >> 8; |
| 173 | 251 | |
| 174 | 252 | /* Count the clocks */ |
| 175 | 253 | lsb -= count; |
| r8910 | r8911 | |
| 178 | 256 | while (lsb < 0) |
| 179 | 257 | { |
| 180 | 258 | /* Borrow from the MSB */ |
| 181 | | lsb += (ptm6840->latch[counter] & 0xff) + 1; |
| 259 | lsb += (m_latch[counter] & 0xff) + 1; |
| 182 | 260 | msb--; |
| 183 | 261 | |
| 184 | 262 | /* If MSB goes less than zero, we've expired */ |
| 185 | 263 | if (msb < 0) |
| 186 | 264 | { |
| 187 | | ptm6840_timeout(device, counter); |
| 188 | | msb = (ptm6840->latch[counter] >> 8) + 1; |
| 265 | ptm6840_timeout(counter); |
| 266 | msb = (m_latch[counter] >> 8) + 1; |
| 189 | 267 | } |
| 190 | 268 | } |
| 191 | 269 | |
| 192 | 270 | /* Store the result */ |
| 193 | | ptm6840->counter[counter] = (msb << 8) | lsb; |
| 271 | m_counter[counter] = (msb << 8) | lsb; |
| 194 | 272 | } |
| 195 | 273 | |
| 196 | 274 | /* Word mode */ |
| 197 | 275 | else |
| 198 | 276 | { |
| 199 | | int word = ptm6840->counter[counter]; |
| 277 | int word = m_counter[counter]; |
| 200 | 278 | |
| 201 | 279 | /* Count the clocks */ |
| 202 | 280 | word -= count; |
| r8910 | r8911 | |
| 205 | 283 | while (word < 0) |
| 206 | 284 | { |
| 207 | 285 | /* Borrow from the MSB */ |
| 208 | | word += ptm6840->latch[counter] + 1; |
| 286 | word += m_latch[counter] + 1; |
| 209 | 287 | |
| 210 | 288 | /* We've expired */ |
| 211 | | ptm6840_timeout(device, counter); |
| 289 | ptm6840_timeout(counter); |
| 212 | 290 | } |
| 213 | 291 | |
| 214 | 292 | /* Store the result */ |
| 215 | | ptm6840->counter[counter] = word; |
| 293 | m_counter[counter] = word; |
| 216 | 294 | } |
| 217 | 295 | |
| 218 | | if (ptm6840->enabled[counter]) |
| 296 | if (m_enabled[counter]) |
| 219 | 297 | { |
| 220 | | duration = attotime_mul(ATTOTIME_IN_HZ(clock), ptm6840->counter[counter]); |
| 298 | attotime duration = attotime_mul(ATTOTIME_IN_HZ(clock), m_counter[counter]); |
| 221 | 299 | |
| 222 | 300 | if (counter == 2) |
| 223 | | duration = attotime_mul(duration, ptm6840->t3_divisor); |
| 301 | { |
| 302 | duration = attotime_mul(duration, m_t3_divisor); |
| 303 | } |
| 224 | 304 | |
| 225 | | timer_adjust_oneshot(ptm6840->timer[counter], duration, 0); |
| 305 | timer_adjust_oneshot(m_timer[counter], duration, 0); |
| 226 | 306 | } |
| 227 | 307 | } |
| 228 | 308 | |
| 309 | |
| 310 | |
| 229 | 311 | /*------------------------------------------------- |
| 230 | 312 | ptm_tick |
| 231 | 313 | -------------------------------------------------*/ |
| 232 | 314 | |
| 233 | | static void ptm_tick( running_device *device, int counter, int count ) |
| 315 | void ptm6840_device::ptm_tick(int counter, int count) |
| 234 | 316 | { |
| 235 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 236 | | |
| 237 | 317 | if (counter == 2) |
| 238 | 318 | { |
| 239 | | ptm6840->t3_scaler += count; |
| 319 | m_t3_scaler += count; |
| 240 | 320 | |
| 241 | | if ( ptm6840->t3_scaler > ptm6840->t3_divisor - 1) |
| 321 | if ( m_t3_scaler > m_t3_divisor - 1) |
| 242 | 322 | { |
| 243 | | subtract_from_counter(device, counter, 1); |
| 244 | | ptm6840->t3_scaler = 0; |
| 323 | subtract_from_counter(counter, 1); |
| 324 | m_t3_scaler = 0; |
| 245 | 325 | } |
| 246 | 326 | } |
| 247 | 327 | else |
| 248 | 328 | { |
| 249 | | subtract_from_counter(device, counter, count); |
| 329 | subtract_from_counter(counter, count); |
| 250 | 330 | } |
| 251 | 331 | } |
| 252 | 332 | |
| 333 | |
| 334 | |
| 253 | 335 | /*------------------------------------------------- |
| 254 | 336 | update_interrupts - Update Internal Interrupts |
| 255 | 337 | -------------------------------------------------*/ |
| 256 | 338 | |
| 257 | | INLINE void update_interrupts( running_device *device ) |
| 339 | void update_interrupts( running_device *device ) |
| 258 | 340 | { |
| 259 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 260 | | int new_state; |
| 341 | downcast<ptm6840_device*>(device)->update_interrupts(); |
| 342 | } |
| 261 | 343 | |
| 262 | | new_state = ((ptm6840->status_reg & 0x01) && (ptm6840->control_reg[0] & 0x40)) || |
| 263 | | ((ptm6840->status_reg & 0x02) && (ptm6840->control_reg[1] & 0x40)) || |
| 264 | | ((ptm6840->status_reg & 0x04) && (ptm6840->control_reg[2] & 0x40)); |
| 344 | void ptm6840_device::update_interrupts() |
| 345 | { |
| 346 | int new_state = ((m_status_reg & 0x01) && (m_control_reg[0] & 0x40)) || |
| 347 | ((m_status_reg & 0x02) && (m_control_reg[1] & 0x40)) || |
| 348 | ((m_status_reg & 0x04) && (m_control_reg[2] & 0x40)); |
| 265 | 349 | |
| 266 | | if (new_state != ptm6840->IRQ) |
| 350 | if (new_state != m_IRQ) |
| 267 | 351 | { |
| 268 | | ptm6840->IRQ = new_state; |
| 352 | m_IRQ = new_state; |
| 269 | 353 | |
| 270 | | if (ptm6840->IRQ) |
| 271 | | ptm6840->status_reg |= 0x80; |
| 354 | if (m_IRQ) |
| 355 | { |
| 356 | m_status_reg |= 0x80; |
| 357 | } |
| 272 | 358 | else |
| 273 | | ptm6840->status_reg &= ~0x80; |
| 359 | { |
| 360 | m_status_reg &= ~0x80; |
| 361 | } |
| 274 | 362 | |
| 275 | | devcb_call_write_line(&ptm6840->irq_func, ptm6840->IRQ); |
| 363 | devcb_call_write_line(&m_irq_func, m_IRQ); |
| 276 | 364 | } |
| 277 | 365 | } |
| 278 | 366 | |
| 367 | |
| 368 | |
| 279 | 369 | /*------------------------------------------------- |
| 280 | 370 | compute_counter - Compute Counter |
| 281 | 371 | -------------------------------------------------*/ |
| 282 | 372 | |
| 283 | | static UINT16 compute_counter( running_device *device, int counter ) |
| 373 | UINT16 ptm6840_device::compute_counter( int counter ) |
| 284 | 374 | { |
| 285 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 286 | 375 | double clock; |
| 287 | | int remaining = 0; |
| 288 | 376 | |
| 289 | 377 | /* If there's no timer, return the count */ |
| 290 | | if (!ptm6840->enabled[counter]) |
| 378 | if (!m_enabled[counter]) |
| 291 | 379 | { |
| 292 | | PLOG(("MC6840 #%s: read counter(%d): %d\n", device->tag(), counter, ptm6840->counter[counter])); |
| 293 | | return ptm6840->counter[counter]; |
| 380 | PLOG(("MC6840 #%s: read counter(%d): %d\n", tag(), counter, m_counter[counter])); |
| 381 | return m_counter[counter]; |
| 294 | 382 | } |
| 295 | 383 | |
| 296 | 384 | /* determine the clock frequency for this timer */ |
| 297 | | if (ptm6840->control_reg[counter] & 0x02) |
| 385 | if (m_control_reg[counter] & 0x02) |
| 298 | 386 | { |
| 299 | | clock = ptm6840->internal_clock; |
| 300 | | PLOG(("MC6840 #%s: %d internal clock freq %f \n", device->tag(), counter, clock)); |
| 387 | clock = m_internal_clock; |
| 388 | PLOG(("MC6840 #%s: %d internal clock freq %f \n", tag(), counter, clock)); |
| 301 | 389 | } |
| 302 | 390 | else |
| 303 | 391 | { |
| 304 | | clock = ptm6840->external_clock[counter]; |
| 305 | | PLOG(("MC6840 #%s: %d external clock freq %f \n", device->tag(), counter, clock)); |
| 392 | clock = m_external_clock[counter]; |
| 393 | PLOG(("MC6840 #%s: %d external clock freq %f \n", tag(), counter, clock)); |
| 306 | 394 | } |
| 307 | 395 | /* See how many are left */ |
| 308 | | remaining = attotime_to_double(attotime_mul(timer_timeleft(ptm6840->timer[counter]), clock)); |
| 396 | int remaining = attotime_to_double(attotime_mul(timer_timeleft(m_timer[counter]), clock)); |
| 309 | 397 | |
| 310 | 398 | /* Adjust the count for dual byte mode */ |
| 311 | | if (ptm6840->control_reg[counter] & 0x04) |
| 399 | if (m_control_reg[counter] & 0x04) |
| 312 | 400 | { |
| 313 | | int divisor = (ptm6840->counter[counter] & 0xff) + 1; |
| 401 | int divisor = (m_counter[counter] & 0xff) + 1; |
| 314 | 402 | int msb = remaining / divisor; |
| 315 | 403 | int lsb = remaining % divisor; |
| 316 | 404 | remaining = (msb << 8) | lsb; |
| 317 | 405 | } |
| 318 | | PLOG(("MC6840 #%s: read counter(%d): %d\n", device->tag(), counter, remaining)); |
| 406 | PLOG(("MC6840 #%s: read counter(%d): %d\n", tag(), counter, remaining)); |
| 319 | 407 | return remaining; |
| 320 | 408 | } |
| 321 | 409 | |
| 410 | |
| 411 | |
| 322 | 412 | /*------------------------------------------------- |
| 323 | 413 | reload_count - Reload Counter |
| 324 | 414 | -------------------------------------------------*/ |
| 325 | 415 | |
| 326 | | static void reload_count( running_device *device, int idx ) |
| 416 | void ptm6840_device::reload_count(int idx) |
| 327 | 417 | { |
| 328 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 329 | 418 | double clock; |
| 330 | | int count; |
| 331 | | attotime duration; |
| 332 | 419 | |
| 333 | 420 | /* Copy the latched value in */ |
| 334 | | ptm6840->counter[idx] = ptm6840->latch[idx]; |
| 421 | m_counter[idx] = m_latch[idx]; |
| 335 | 422 | |
| 336 | 423 | /* Determine the clock frequency for this timer */ |
| 337 | | if (ptm6840->control_reg[idx] & 0x02) |
| 424 | if (m_control_reg[idx] & 0x02) |
| 338 | 425 | { |
| 339 | | clock = ptm6840->internal_clock; |
| 340 | | PLOG(("MC6840 #%s: %d internal clock freq %f \n", device->tag(), idx, clock)); |
| 426 | clock = m_internal_clock; |
| 427 | PLOG(("MC6840 #%s: %d internal clock freq %f \n", tag(), idx, clock)); |
| 341 | 428 | } |
| 342 | 429 | else |
| 343 | 430 | { |
| 344 | | clock = ptm6840->external_clock[idx]; |
| 345 | | PLOG(("MC6840 #%s: %d external clock freq %f \n", device->tag(), idx, clock)); |
| 431 | clock = m_external_clock[idx]; |
| 432 | PLOG(("MC6840 #%s: %d external clock freq %f \n", tag(), idx, clock)); |
| 346 | 433 | } |
| 347 | 434 | |
| 348 | 435 | /* Determine the number of clock periods before we expire */ |
| 349 | | count = ptm6840->counter[idx]; |
| 350 | | if (ptm6840->control_reg[idx] & 0x04) |
| 436 | int count = m_counter[idx]; |
| 437 | if (m_control_reg[idx] & 0x04) |
| 438 | { |
| 351 | 439 | count = ((count >> 8) + 1) * ((count & 0xff) + 1); |
| 440 | } |
| 352 | 441 | else |
| 442 | { |
| 353 | 443 | count = count + 1; |
| 444 | } |
| 354 | 445 | |
| 355 | | ptm6840->fired[idx] = 0; |
| 446 | m_fired[idx] = 0; |
| 356 | 447 | |
| 357 | | if ((ptm6840->mode[idx] == 4) || (ptm6840->mode[idx] == 6)) |
| 448 | if ((m_mode[idx] == 4) || (m_mode[idx] == 6)) |
| 358 | 449 | { |
| 359 | | ptm6840->output[idx] = 1; |
| 360 | | if (ptm6840->out_func[idx].write != NULL) |
| 361 | | devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]); |
| 450 | m_output[idx] = 1; |
| 451 | if (m_out_func[idx].write != NULL) |
| 452 | { |
| 453 | devcb_call_write8(&m_out_func[idx], 0, m_output[idx]); |
| 454 | } |
| 362 | 455 | } |
| 363 | 456 | |
| 364 | 457 | /* Set the timer */ |
| 365 | | PLOG(("MC6840 #%s: reload_count(%d): clock = %f count = %d\n", device->tag(), idx, clock, count)); |
| 458 | PLOG(("MC6840 #%s: reload_count(%d): clock = %f count = %d\n", tag(), idx, clock, count)); |
| 366 | 459 | |
| 367 | | duration = attotime_mul(ATTOTIME_IN_HZ(clock), count); |
| 460 | attotime duration = attotime_mul(ATTOTIME_IN_HZ(clock), count); |
| 368 | 461 | if (idx == 2) |
| 369 | | duration = attotime_mul(duration, ptm6840->t3_divisor); |
| 462 | { |
| 463 | duration = attotime_mul(duration, m_t3_divisor); |
| 464 | } |
| 370 | 465 | |
| 371 | | PLOG(("MC6840 #%s: reload_count(%d): output = %lf\n", device->tag(), idx, attotime_to_double(duration))); |
| 466 | PLOG(("MC6840 #%s: reload_count(%d): output = %lf\n", tag(), idx, attotime_to_double(duration))); |
| 372 | 467 | |
| 373 | 468 | #if 0 |
| 374 | | if (!(ptm6840->control_reg[idx] & 0x02)) |
| 469 | if (!(m_control_reg[idx] & 0x02)) |
| 375 | 470 | { |
| 376 | | if (!ptm6840->external_clock[idx]) |
| 471 | if (!m_external_clock[idx]) |
| 377 | 472 | { |
| 378 | | ptm6840->enabled[idx] = 0; |
| 379 | | timer_enable(ptm6840->timer[idx],FALSE); |
| 473 | m_enabled[idx] = 0; |
| 474 | timer_enable(m_timer[idx],FALSE); |
| 380 | 475 | } |
| 381 | 476 | } |
| 382 | 477 | else |
| 383 | 478 | #endif |
| 384 | 479 | { |
| 385 | | ptm6840->enabled[idx] = 1; |
| 386 | | timer_adjust_oneshot(ptm6840->timer[idx], duration, 0); |
| 387 | | timer_enable(ptm6840->timer[idx], TRUE); |
| 480 | m_enabled[idx] = 1; |
| 481 | timer_adjust_oneshot(m_timer[idx], duration, 0); |
| 482 | timer_enable(m_timer[idx], TRUE); |
| 388 | 483 | } |
| 389 | 484 | } |
| 390 | 485 | |
| 391 | 486 | |
| 487 | |
| 392 | 488 | /*------------------------------------------------- |
| 393 | 489 | ptm6840_read - Read Timer |
| 394 | 490 | -------------------------------------------------*/ |
| 395 | 491 | |
| 396 | | READ8_DEVICE_HANDLER( ptm6840_read ) |
| 492 | READ8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_read) |
| 397 | 493 | { |
| 398 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 399 | 494 | int val; |
| 400 | 495 | |
| 401 | 496 | switch ( offset ) |
| r8910 | r8911 | |
| 408 | 503 | |
| 409 | 504 | case PTM_6840_STATUS: |
| 410 | 505 | { |
| 411 | | PLOG(("%s: MC6840 #%s: Status read = %04X\n", cpuexec_describe_context(device->machine), device->tag(), ptm6840->status_reg)); |
| 412 | | ptm6840->status_read_since_int |= ptm6840->status_reg & 0x07; |
| 413 | | val = ptm6840->status_reg; |
| 506 | PLOG(("%s: MC6840 #%s: Status read = %04X\n", cpuexec_describe_context(&m_machine), tag(), m_status_reg)); |
| 507 | m_status_read_since_int |= m_status_reg & 0x07; |
| 508 | val = m_status_reg; |
| 414 | 509 | break; |
| 415 | 510 | } |
| 416 | 511 | |
| r8910 | r8911 | |
| 419 | 514 | case PTM_6840_MSBBUF3: |
| 420 | 515 | { |
| 421 | 516 | int idx = (offset - 2) / 2; |
| 422 | | int result = compute_counter(device, idx); |
| 517 | int result = compute_counter(idx); |
| 423 | 518 | |
| 424 | 519 | /* Clear the interrupt if the status has been read */ |
| 425 | | if (ptm6840->status_read_since_int & (1 << idx)) |
| 520 | if (m_status_read_since_int & (1 << idx)) |
| 426 | 521 | { |
| 427 | | ptm6840->status_reg &= ~(1 << idx); |
| 428 | | update_interrupts(device); |
| 522 | m_status_reg &= ~(1 << idx); |
| 523 | update_interrupts(); |
| 429 | 524 | } |
| 430 | 525 | |
| 431 | | ptm6840->lsb_buffer = result & 0xff; |
| 526 | m_lsb_buffer = result & 0xff; |
| 432 | 527 | |
| 433 | | PLOG(("%s: MC6840 #%s: Counter %d read = %04X\n", cpuexec_describe_context(device->machine), device->tag(), idx, result >> 8)); |
| 528 | PLOG(("%s: MC6840 #%s: Counter %d read = %04X\n", cpuexec_describe_context(&m_machine), tag(), idx, result >> 8)); |
| 434 | 529 | val = result >> 8; |
| 435 | 530 | break; |
| 436 | 531 | } |
| r8910 | r8911 | |
| 439 | 534 | case PTM_6840_LSB2: |
| 440 | 535 | case PTM_6840_LSB3: |
| 441 | 536 | { |
| 442 | | val = ptm6840->lsb_buffer; |
| 537 | val = m_lsb_buffer; |
| 443 | 538 | break; |
| 444 | 539 | } |
| 445 | 540 | |
| r8910 | r8911 | |
| 453 | 548 | return val; |
| 454 | 549 | } |
| 455 | 550 | |
| 551 | |
| 456 | 552 | /*------------------------------------------------- |
| 457 | 553 | ptm6840_write - Write Timer |
| 458 | 554 | -------------------------------------------------*/ |
| 459 | 555 | |
| 460 | | WRITE8_DEVICE_HANDLER( ptm6840_write ) |
| 556 | WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) |
| 461 | 557 | { |
| 462 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 463 | | int idx; |
| 464 | | int i; |
| 465 | | UINT8 diffs; |
| 466 | | |
| 467 | 558 | switch ( offset ) |
| 468 | 559 | { |
| 469 | 560 | case PTM_6840_CTRL1: |
| 470 | 561 | case PTM_6840_CTRL2: |
| 471 | 562 | { |
| 472 | | idx = (offset == 1) ? 1 : (ptm6840->control_reg[1] & 0x01) ? 0 : 2; |
| 473 | | diffs = data ^ ptm6840->control_reg[idx]; |
| 474 | | ptm6840->t3_divisor = (ptm6840->control_reg[2] & 0x01) ? 8 : 1; |
| 475 | | ptm6840->mode[idx] = (data >> 3) & 0x07; |
| 476 | | ptm6840->control_reg[idx] = data; |
| 563 | int idx = (offset == 1) ? 1 : (m_control_reg[1] & 0x01) ? 0 : 2; |
| 564 | UINT8 diffs = data ^ m_control_reg[idx]; |
| 565 | m_t3_divisor = (m_control_reg[2] & 0x01) ? 8 : 1; |
| 566 | m_mode[idx] = (data >> 3) & 0x07; |
| 567 | m_control_reg[idx] = data; |
| 477 | 568 | |
| 478 | | PLOG(("MC6840 #%s : Control register %d selected\n", device->tag(), idx)); |
| 479 | | PLOG(("operation mode = %s\n", opmode[ ptm6840->mode[idx] ])); |
| 480 | | PLOG(("value = %04X\n", ptm6840->control_reg[idx])); |
| 481 | | PLOG(("t3divisor = %d\n", ptm6840->t3_divisor)); |
| 569 | PLOG(("MC6840 #%s : Control register %d selected\n", tag(), idx)); |
| 570 | PLOG(("operation mode = %s\n", opmode[ m_mode[idx] ])); |
| 571 | PLOG(("value = %04X\n", m_control_reg[idx])); |
| 572 | PLOG(("t3divisor = %d\n", m_t3_divisor)); |
| 482 | 573 | |
| 483 | | if (!(ptm6840->control_reg[idx] & 0x80 )) |
| 574 | if (!(m_control_reg[idx] & 0x80 )) |
| 484 | 575 | { |
| 485 | 576 | /* Output cleared */ |
| 486 | | if (ptm6840->out_func[idx].write != NULL) |
| 487 | | devcb_call_write8(&ptm6840->out_func[idx], 0, 0); |
| 577 | devcb_call_write8(&m_out_func[idx], 0, 0); |
| 488 | 578 | } |
| 489 | 579 | /* Reset? */ |
| 490 | 580 | if (idx == 0 && (diffs & 0x01)) |
| r8910 | r8911 | |
| 492 | 582 | /* Holding reset down */ |
| 493 | 583 | if (data & 0x01) |
| 494 | 584 | { |
| 495 | | PLOG(("MC6840 #%s : Timer reset\n", device->tag())); |
| 496 | | for (i = 0; i < 3; i++) |
| 585 | PLOG(("MC6840 #%s : Timer reset\n", tag())); |
| 586 | for (int i = 0; i < 3; i++) |
| 497 | 587 | { |
| 498 | | timer_enable(ptm6840->timer[i], FALSE); |
| 499 | | ptm6840->enabled[i] = 0; |
| 588 | timer_enable(m_timer[i], FALSE); |
| 589 | m_enabled[i] = 0; |
| 500 | 590 | } |
| 501 | 591 | } |
| 502 | 592 | /* Releasing reset */ |
| 503 | 593 | else |
| 504 | 594 | { |
| 505 | | for (i = 0; i < 3; i++) |
| 506 | | reload_count(device, i); |
| 595 | for (int i = 0; i < 3; i++) |
| 596 | { |
| 597 | reload_count(i); |
| 598 | } |
| 507 | 599 | } |
| 508 | 600 | |
| 509 | | ptm6840->status_reg = 0; |
| 510 | | update_interrupts(device); |
| 601 | m_status_reg = 0; |
| 602 | update_interrupts(); |
| 511 | 603 | |
| 512 | 604 | /* Changing the clock source? (e.g. Zwackery) */ |
| 513 | 605 | if (diffs & 0x02) |
| 514 | | reload_count(device, idx); |
| 606 | { |
| 607 | reload_count(idx); |
| 608 | } |
| 515 | 609 | } |
| 516 | 610 | break; |
| 517 | 611 | } |
| r8910 | r8911 | |
| 520 | 614 | case PTM_6840_MSBBUF2: |
| 521 | 615 | case PTM_6840_MSBBUF3: |
| 522 | 616 | { |
| 523 | | PLOG(("MC6840 #%s msbbuf%d = %02X\n", device->tag(), offset / 2, data)); |
| 524 | | ptm6840->msb_buffer = data; |
| 617 | PLOG(("MC6840 #%s msbbuf%d = %02X\n", tag(), offset / 2, data)); |
| 618 | m_msb_buffer = data; |
| 525 | 619 | break; |
| 526 | 620 | } |
| 527 | 621 | |
| r8910 | r8911 | |
| 529 | 623 | case PTM_6840_LSB2: |
| 530 | 624 | case PTM_6840_LSB3: |
| 531 | 625 | { |
| 532 | | idx = (offset - 3) / 2; |
| 533 | | ptm6840->latch[idx] = (ptm6840->msb_buffer << 8) | (data & 0xff); |
| 626 | int idx = (offset - 3) / 2; |
| 627 | m_latch[idx] = (m_msb_buffer << 8) | (data & 0xff); |
| 534 | 628 | |
| 535 | 629 | /* Clear the interrupt */ |
| 536 | | ptm6840->status_reg &= ~(1 << idx); |
| 537 | | update_interrupts(device); |
| 630 | m_status_reg &= ~(1 << idx); |
| 631 | update_interrupts(); |
| 538 | 632 | |
| 539 | 633 | /* Reload the count if in an appropriate mode */ |
| 540 | | if (!(ptm6840->control_reg[idx] & 0x10)) |
| 541 | | reload_count(device,idx); |
| 634 | if (!(m_control_reg[idx] & 0x10)) |
| 635 | { |
| 636 | reload_count(idx); |
| 637 | } |
| 542 | 638 | |
| 543 | | PLOG(("%s:MC6840 #%s: Counter %d latch = %04X\n", cpuexec_describe_context(device->machine), device->tag(), idx, ptm6840->latch[idx])); |
| 639 | PLOG(("%s:MC6840 #%s: Counter %d latch = %04X\n", cpuexec_describe_context(&m_machine), tag(), idx, m_latch[idx])); |
| 544 | 640 | break; |
| 545 | 641 | } |
| 546 | 642 | } |
| 547 | 643 | } |
| 548 | 644 | |
| 645 | |
| 549 | 646 | /*------------------------------------------------- |
| 550 | 647 | ptm6840_timeout - Called if timer is mature |
| 551 | 648 | -------------------------------------------------*/ |
| 552 | 649 | |
| 553 | | static void ptm6840_timeout( running_device *device, int idx ) |
| 650 | void ptm6840_device::ptm6840_timeout(int idx) |
| 554 | 651 | { |
| 555 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 652 | PLOG(("**ptm6840 %s t%d timeout**\n", tag(), idx + 1)); |
| 556 | 653 | |
| 557 | | PLOG(("**ptm6840 %s t%d timeout**\n", device->tag(), idx + 1)); |
| 558 | | |
| 559 | 654 | /* Set the interrupt flag */ |
| 560 | | ptm6840->status_reg |= (1 << idx); |
| 561 | | ptm6840->status_read_since_int &= ~(1 << idx); |
| 562 | | update_interrupts(device); |
| 655 | m_status_reg |= (1 << idx); |
| 656 | m_status_read_since_int &= ~(1 << idx); |
| 657 | update_interrupts(); |
| 563 | 658 | |
| 564 | | if ( ptm6840->control_reg[idx] & 0x80 ) |
| 659 | if ( m_control_reg[idx] & 0x80 ) |
| 565 | 660 | { |
| 566 | | if ((ptm6840->mode[idx] == 0)||(ptm6840->mode[idx] == 2)) |
| 661 | if ((m_mode[idx] == 0)||(m_mode[idx] == 2)) |
| 567 | 662 | { |
| 568 | | ptm6840->output[idx] = ptm6840->output[idx] ? 0 : 1; |
| 569 | | PLOG(("**ptm6840 %s t%d output %d **\n", device->tag(), idx + 1, ptm6840->output[idx])); |
| 663 | m_output[idx] = m_output[idx] ? 0 : 1; |
| 664 | PLOG(("**ptm6840 %s t%d output %d **\n", tag(), idx + 1, m_output[idx])); |
| 570 | 665 | |
| 571 | | if (ptm6840->out_func[idx].write != NULL) |
| 572 | | devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]); |
| 666 | devcb_call_write8(&m_out_func[idx], 0, m_output[idx]); |
| 573 | 667 | } |
| 574 | | if ((ptm6840->mode[idx] == 4)||(ptm6840->mode[idx] == 6)) |
| 668 | if ((m_mode[idx] == 4)||(m_mode[idx] == 6)) |
| 575 | 669 | { |
| 576 | | if (!ptm6840->fired[idx]) |
| 670 | if (!m_fired[idx]) |
| 577 | 671 | { |
| 578 | | ptm6840->output[idx] = 1; |
| 579 | | PLOG(("**ptm6840 %s t%d output %d **\n", device->tag(), idx + 1, ptm6840->output[idx])); |
| 672 | m_output[idx] = 1; |
| 673 | PLOG(("**ptm6840 %s t%d output %d **\n", tag(), idx + 1, m_output[idx])); |
| 580 | 674 | |
| 581 | | if (ptm6840->out_func[idx].write != NULL) |
| 582 | | devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]); |
| 675 | devcb_call_write8(&m_out_func[idx], 0, m_output[idx]); |
| 583 | 676 | |
| 584 | 677 | /* No changes in output until reinit */ |
| 585 | | ptm6840->fired[idx] = 1; |
| 678 | m_fired[idx] = 1; |
| 586 | 679 | } |
| 587 | 680 | } |
| 588 | 681 | } |
| 589 | | ptm6840->enabled[idx]= 0; |
| 590 | | reload_count(device, idx); |
| 682 | m_enabled[idx]= 0; |
| 683 | reload_count(idx); |
| 591 | 684 | } |
| 592 | 685 | |
| 686 | |
| 593 | 687 | /*------------------------------------------------- |
| 594 | 688 | TIMER_CALLBACKs for Timer 1, 2 & 3 |
| 595 | 689 | -------------------------------------------------*/ |
| 596 | 690 | |
| 597 | | static TIMER_CALLBACK( ptm6840_timer1_cb ) |
| 691 | TIMER_CALLBACK( ptm6840_device::ptm6840_timer1_cb ) |
| 598 | 692 | { |
| 599 | | running_device *device = (running_device *)ptr; |
| 600 | | ptm6840_timeout(device, 0); |
| 693 | reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(0); |
| 601 | 694 | } |
| 602 | 695 | |
| 603 | | static TIMER_CALLBACK( ptm6840_timer2_cb ) |
| 696 | TIMER_CALLBACK( ptm6840_device::ptm6840_timer2_cb ) |
| 604 | 697 | { |
| 605 | | running_device *device = (running_device *)ptr; |
| 606 | | ptm6840_timeout(device, 1); |
| 698 | reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(1); |
| 607 | 699 | } |
| 608 | 700 | |
| 609 | | static TIMER_CALLBACK( ptm6840_timer3_cb ) |
| 701 | TIMER_CALLBACK( ptm6840_device::ptm6840_timer3_cb ) |
| 610 | 702 | { |
| 611 | | running_device *device = (running_device *)ptr; |
| 612 | | ptm6840_timeout(device, 2); |
| 703 | reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(2); |
| 613 | 704 | } |
| 614 | 705 | |
| 615 | 706 | |
| r8910 | r8911 | |
| 617 | 708 | ptm6840_set_gate - set gate status (0 or 1) |
| 618 | 709 | -------------------------------------------------*/ |
| 619 | 710 | |
| 620 | | INLINE void ptm6840_set_gate( running_device *device, int state, int idx ) |
| 711 | void ptm6840_device::ptm6840_set_gate(int state, int idx) |
| 621 | 712 | { |
| 622 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 623 | | |
| 624 | | if ( (ptm6840->mode[idx] == 0) || (ptm6840->mode[idx] == 2) || (ptm6840->mode[0] == 4) || (ptm6840->mode[idx] == 6) ) |
| 713 | if ( (m_mode[idx] == 0) || (m_mode[idx] == 2) || (m_mode[0] == 4) || (m_mode[idx] == 6) ) |
| 625 | 714 | { |
| 626 | | if (state == 0 && ptm6840->gate[idx]) |
| 627 | | reload_count(device,idx); |
| 715 | if (state == 0 && m_gate[idx]) |
| 716 | { |
| 717 | reload_count(idx); |
| 718 | } |
| 628 | 719 | } |
| 629 | | ptm6840->gate[idx] = state; |
| 720 | m_gate[idx] = state; |
| 630 | 721 | } |
| 631 | 722 | |
| 723 | |
| 632 | 724 | /*------------------------------------------------- |
| 633 | 725 | WRITE8_DEVICE_HANDLERs for Gate 1, 2 & 3 |
| 634 | 726 | -------------------------------------------------*/ |
| 635 | 727 | |
| 636 | 728 | WRITE8_DEVICE_HANDLER( ptm6840_set_g1 ) |
| 637 | 729 | { |
| 638 | | ptm6840_set_gate(device, data, 0); |
| 730 | downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 0); |
| 639 | 731 | } |
| 640 | 732 | |
| 641 | 733 | WRITE8_DEVICE_HANDLER( ptm6840_set_g2 ) |
| 642 | 734 | { |
| 643 | | ptm6840_set_gate(device, data, 1); |
| 735 | downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 1); |
| 644 | 736 | } |
| 645 | 737 | |
| 646 | 738 | WRITE8_DEVICE_HANDLER( ptm6840_set_g3 ) |
| 647 | 739 | { |
| 648 | | ptm6840_set_gate(device, data, 2); |
| 740 | downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 2); |
| 649 | 741 | } |
| 650 | 742 | |
| 743 | |
| 651 | 744 | /*------------------------------------------------- |
| 652 | 745 | ptm6840_set_clock - set clock status (0 or 1) |
| 653 | 746 | -------------------------------------------------*/ |
| 654 | 747 | |
| 655 | | INLINE void ptm6840_set_clock( running_device *device, int state, int idx ) |
| 748 | void ptm6840_device::ptm6840_set_clock(int state, int idx) |
| 656 | 749 | { |
| 657 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 750 | m_clk[idx] = state; |
| 658 | 751 | |
| 659 | | ptm6840->clock[idx] = state; |
| 660 | | |
| 661 | | if (!(ptm6840->control_reg[idx] & 0x02)) |
| 752 | if (!(m_control_reg[idx] & 0x02)) |
| 662 | 753 | { |
| 663 | 754 | if (state) |
| 664 | | ptm_tick(device, idx, 1); |
| 755 | { |
| 756 | ptm_tick(idx, 1); |
| 757 | } |
| 665 | 758 | } |
| 666 | 759 | } |
| 667 | 760 | |
| 761 | |
| 668 | 762 | /*------------------------------------------------- |
| 669 | 763 | WRITE8_DEVICE_HANDLERs for Clock 1, 2 & 3 |
| 670 | 764 | -------------------------------------------------*/ |
| 671 | 765 | |
| 672 | 766 | WRITE8_DEVICE_HANDLER( ptm6840_set_c1 ) |
| 673 | 767 | { |
| 674 | | ptm6840_set_clock(device, data, 0); |
| 768 | downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 0); |
| 675 | 769 | } |
| 676 | 770 | |
| 677 | 771 | WRITE8_DEVICE_HANDLER( ptm6840_set_c2 ) |
| 678 | 772 | { |
| 679 | | ptm6840_set_clock(device, data, 1); |
| 773 | downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 1); |
| 680 | 774 | } |
| 681 | 775 | |
| 682 | 776 | WRITE8_DEVICE_HANDLER( ptm6840_set_c3 ) |
| 683 | 777 | { |
| 684 | | ptm6840_set_clock(device, data, 2); |
| 778 | downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 2); |
| 685 | 779 | } |
| 686 | 780 | |
| 687 | 781 | |
| r8910 | r8911 | |
| 689 | 783 | ptm6840_get_count - get count value |
| 690 | 784 | -------------------------------------------------*/ |
| 691 | 785 | |
| 692 | | UINT16 ptm6840_get_count( running_device *device, int counter ) |
| 786 | UINT16 ptm6840_get_count(running_device *device, int counter) |
| 693 | 787 | { |
| 694 | | return compute_counter(device, counter); |
| 788 | return downcast<ptm6840_device*>(device)->ptm6840_get_count(counter); |
| 695 | 789 | } |
| 696 | 790 | |
| 791 | UINT16 ptm6840_device::ptm6840_get_count(int counter) |
| 792 | { |
| 793 | return compute_counter(counter); |
| 794 | } |
| 795 | |
| 796 | |
| 697 | 797 | /*------------------------------------------------------------ |
| 698 | 798 | ptm6840_set_ext_clock - set external clock frequency |
| 699 | 799 | ------------------------------------------------------------*/ |
| 700 | 800 | |
| 701 | | void ptm6840_set_ext_clock( running_device *device, int counter, double clock ) |
| 801 | void ptm6840_set_ext_clock(running_device *device, int counter, double clock) |
| 702 | 802 | { |
| 703 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 803 | downcast<ptm6840_device*>(device)->ptm6840_set_ext_clock(counter, clock); |
| 804 | } |
| 704 | 805 | |
| 705 | | ptm6840->external_clock[counter] = clock; |
| 806 | void ptm6840_device::ptm6840_set_ext_clock(int counter, double clock) |
| 807 | { |
| 808 | m_external_clock[counter] = clock; |
| 706 | 809 | |
| 707 | | if (!(ptm6840->control_reg[counter] & 0x02)) |
| 810 | if (!(m_control_reg[counter] & 0x02)) |
| 708 | 811 | { |
| 709 | | if (!ptm6840->external_clock[counter]) |
| 812 | if (!m_external_clock[counter]) |
| 710 | 813 | { |
| 711 | | ptm6840->enabled[counter] = 0; |
| 712 | | timer_enable(ptm6840->timer[counter], FALSE); |
| 814 | m_enabled[counter] = 0; |
| 815 | timer_enable(m_timer[counter], FALSE); |
| 713 | 816 | } |
| 714 | 817 | } |
| 715 | 818 | else |
| r8910 | r8911 | |
| 718 | 821 | attotime duration; |
| 719 | 822 | |
| 720 | 823 | /* Determine the number of clock periods before we expire */ |
| 721 | | count = ptm6840->counter[counter]; |
| 824 | count = m_counter[counter]; |
| 722 | 825 | |
| 723 | | if (ptm6840->control_reg[counter] & 0x04) |
| 826 | if (m_control_reg[counter] & 0x04) |
| 827 | { |
| 724 | 828 | count = ((count >> 8) + 1) * ((count & 0xff) + 1); |
| 829 | } |
| 725 | 830 | else |
| 831 | { |
| 726 | 832 | count = count + 1; |
| 833 | } |
| 727 | 834 | |
| 728 | 835 | duration = attotime_mul(ATTOTIME_IN_HZ(clock), count); |
| 729 | 836 | |
| 730 | 837 | if (counter == 2) |
| 731 | | duration = attotime_mul(duration, ptm6840->t3_divisor); |
| 838 | { |
| 839 | duration = attotime_mul(duration, m_t3_divisor); |
| 840 | } |
| 732 | 841 | |
| 733 | | ptm6840->enabled[counter] = 1; |
| 734 | | timer_adjust_oneshot(ptm6840->timer[counter], duration, 0); |
| 735 | | timer_enable(ptm6840->timer[counter], TRUE); |
| 842 | m_enabled[counter] = 1; |
| 843 | timer_adjust_oneshot(m_timer[counter], duration, 0); |
| 844 | timer_enable(m_timer[counter], TRUE); |
| 736 | 845 | } |
| 737 | 846 | } |
| 738 | 847 | |
| 848 | |
| 739 | 849 | /*------------------------------------------------------------ |
| 740 | 850 | ptm6840_get_ext_clock - get external clock frequency |
| 741 | 851 | ------------------------------------------------------------*/ |
| 742 | 852 | |
| 743 | 853 | int ptm6840_get_ext_clock( running_device *device, int counter ) |
| 744 | 854 | { |
| 745 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 746 | | return ptm6840->external_clock[counter]; |
| 855 | return downcast<ptm6840_device*>(device)->ptm6840_get_ext_clock(counter); |
| 747 | 856 | } |
| 748 | 857 | |
| 749 | | |
| 750 | | /*------------------------------------------------- |
| 751 | | DEVICE_START( ptm6840 ) |
| 752 | | -------------------------------------------------*/ |
| 753 | | |
| 754 | | static DEVICE_START( ptm6840 ) |
| 858 | int ptm6840_device::ptm6840_get_ext_clock(int counter) |
| 755 | 859 | { |
| 756 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 757 | | const ptm6840_interface *intf = get_interface(device); |
| 758 | | int i; |
| 759 | | |
| 760 | | ptm6840->internal_clock = intf->internal_clock; |
| 761 | | |
| 762 | | /* resolve callbacks */ |
| 763 | | for (i = 0; i < 3; i++) |
| 764 | | { |
| 765 | | devcb_resolve_write8(&ptm6840->out_func[i], &intf->out_func[i], device); |
| 766 | | } |
| 767 | | |
| 768 | | for (i = 0; i < 3; i++) |
| 769 | | { |
| 770 | | if ( intf->external_clock[i] ) |
| 771 | | ptm6840->external_clock[i] = intf->external_clock[i]; |
| 772 | | else |
| 773 | | ptm6840->external_clock[i] = 1; |
| 774 | | } |
| 775 | | |
| 776 | | |
| 777 | | ptm6840->timer[0] = timer_alloc(device->machine, ptm6840_timer1_cb, (void *)device); |
| 778 | | ptm6840->timer[1] = timer_alloc(device->machine, ptm6840_timer2_cb, (void *)device); |
| 779 | | ptm6840->timer[2] = timer_alloc(device->machine, ptm6840_timer3_cb, (void *)device); |
| 780 | | |
| 781 | | for (i = 0; i < 3; i++) |
| 782 | | { |
| 783 | | timer_enable(ptm6840->timer[i], FALSE); |
| 784 | | } |
| 785 | | |
| 786 | | devcb_resolve_write_line(&ptm6840->irq_func, &intf->irq_func, device); |
| 787 | | |
| 788 | | /* register for state saving */ |
| 789 | | state_save_register_device_item(device, 0, ptm6840->lsb_buffer); |
| 790 | | state_save_register_device_item(device, 0, ptm6840->msb_buffer); |
| 791 | | state_save_register_device_item(device, 0, ptm6840->status_read_since_int); |
| 792 | | state_save_register_device_item(device, 0, ptm6840->status_reg); |
| 793 | | state_save_register_device_item(device, 0, ptm6840->t3_divisor); |
| 794 | | state_save_register_device_item(device, 0, ptm6840->t3_scaler); |
| 795 | | state_save_register_device_item(device, 0, ptm6840->internal_clock); |
| 796 | | state_save_register_device_item(device, 0, ptm6840->IRQ); |
| 797 | | |
| 798 | | state_save_register_device_item_array(device, 0, ptm6840->control_reg); |
| 799 | | state_save_register_device_item_array(device, 0, ptm6840->output); |
| 800 | | state_save_register_device_item_array(device, 0, ptm6840->gate); |
| 801 | | state_save_register_device_item_array(device, 0, ptm6840->clock); |
| 802 | | state_save_register_device_item_array(device, 0, ptm6840->mode); |
| 803 | | state_save_register_device_item_array(device, 0, ptm6840->fired); |
| 804 | | state_save_register_device_item_array(device, 0, ptm6840->enabled); |
| 805 | | state_save_register_device_item_array(device, 0, ptm6840->external_clock); |
| 806 | | state_save_register_device_item_array(device, 0, ptm6840->counter); |
| 807 | | state_save_register_device_item_array(device, 0, ptm6840->latch); |
| 860 | return m_external_clock[counter]; |
| 808 | 861 | } |
| 809 | | |
| 810 | | /*------------------------------------------------- |
| 811 | | DEVICE_RESET( ptm6840 ) |
| 812 | | -------------------------------------------------*/ |
| 813 | | |
| 814 | | static DEVICE_RESET( ptm6840 ) |
| 815 | | { |
| 816 | | ptm6840_state *ptm6840 = get_safe_token(device); |
| 817 | | int i; |
| 818 | | |
| 819 | | ptm6840->control_reg[2] = 0; |
| 820 | | ptm6840->control_reg[1] = 0; |
| 821 | | ptm6840->control_reg[0] = 1; |
| 822 | | ptm6840->status_reg = 0; |
| 823 | | ptm6840->t3_divisor = 1; |
| 824 | | ptm6840->status_read_since_int = 0; |
| 825 | | ptm6840->IRQ = 0; |
| 826 | | |
| 827 | | for (i = 0; i < 3; i++) |
| 828 | | { |
| 829 | | ptm6840->counter[i] = 0xffff; |
| 830 | | ptm6840->latch[i] = 0xffff; |
| 831 | | ptm6840->output[i] = 0; |
| 832 | | ptm6840->fired[i] = 0; |
| 833 | | } |
| 834 | | } |
| 835 | | |
| 836 | | /*------------------------------------------------- |
| 837 | | device definition |
| 838 | | -------------------------------------------------*/ |
| 839 | | |
| 840 | | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |
| 841 | | |
| 842 | | #define DEVTEMPLATE_ID(p,s) p##ptm6840##s |
| 843 | | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 844 | | #define DEVTEMPLATE_NAME "6840 PTM" |
| 845 | | #include "devtempl.h" |
| 846 | | |
| 847 | | DEFINE_LEGACY_DEVICE(PTM6840, ptm6840); |
src/emu/machine/8255ppi.c
| r8910 | r8911 | |
| 92 | 92 | |
| 93 | 93 | #include "emu.h" |
| 94 | 94 | #include "8255ppi.h" |
| 95 | #include "devhelpr.h" |
| 95 | 96 | |
| 96 | | typedef struct _ppi8255 ppi8255_t; |
| 97 | //************************************************************************** |
| 98 | // DEVICE CONFIGURATION |
| 99 | //************************************************************************** |
| 97 | 100 | |
| 98 | | struct _ppi8255 |
| 101 | GENERIC_DEVICE_CONFIG_SETUP(ppi8255, "PPI8255") |
| 102 | |
| 103 | //------------------------------------------------- |
| 104 | // device_config_complete - perform any |
| 105 | // operations now that the configuration is |
| 106 | // complete |
| 107 | //------------------------------------------------- |
| 108 | |
| 109 | void ppi8255_device_config::device_config_complete() |
| 99 | 110 | { |
| 100 | | const ppi8255_interface *intf; |
| 111 | // inherit a copy of the static data |
| 112 | const ppi8255_interface *intf = reinterpret_cast<const ppi8255_interface *>(static_config()); |
| 113 | if (intf != NULL) |
| 114 | { |
| 115 | *static_cast<ppi8255_interface *>(this) = *intf; |
| 116 | } |
| 101 | 117 | |
| 102 | | devcb_resolved_read8 port_read[3]; |
| 103 | | devcb_resolved_write8 port_write[3]; |
| 118 | // or initialize to defaults if none provided |
| 119 | else |
| 120 | { |
| 121 | memset(&m_port_a_read, 0, sizeof(m_port_a_read)); |
| 122 | memset(&m_port_b_read, 0, sizeof(m_port_b_read)); |
| 123 | memset(&m_port_c_read, 0, sizeof(m_port_c_read)); |
| 124 | memset(&m_port_a_write, 0, sizeof(m_port_a_write)); |
| 125 | memset(&m_port_b_write, 0, sizeof(m_port_b_write)); |
| 126 | memset(&m_port_c_write, 0, sizeof(m_port_c_write)); |
| 127 | } |
| 128 | } |
| 104 | 129 | |
| 105 | | /* mode flags */ |
| 106 | | UINT8 group_a_mode; |
| 107 | | UINT8 group_b_mode; |
| 108 | | UINT8 port_a_dir; |
| 109 | | UINT8 port_b_dir; |
| 110 | | UINT8 port_ch_dir; |
| 111 | | UINT8 port_cl_dir; |
| 112 | 130 | |
| 113 | | /* handshake signals (1=asserted; 0=non-asserted) */ |
| 114 | | UINT8 obf_a; |
| 115 | | UINT8 obf_b; |
| 116 | | UINT8 ibf_a; |
| 117 | | UINT8 ibf_b; |
| 118 | | UINT8 inte_a; |
| 119 | | UINT8 inte_b; |
| 120 | | UINT8 inte_1; |
| 121 | | UINT8 inte_2; |
| 122 | 131 | |
| 123 | | UINT8 in_mask[3]; /* input mask */ |
| 124 | | UINT8 out_mask[3]; /* output mask */ |
| 125 | | UINT8 read[3]; /* data read from ports */ |
| 126 | | UINT8 latch[3]; /* data written to ports */ |
| 127 | | UINT8 output[3]; /* actual output data */ |
| 128 | | UINT8 control; /* mode control word */ |
| 129 | | }; |
| 132 | //************************************************************************** |
| 133 | // LIVE DEVICE |
| 134 | //************************************************************************** |
| 130 | 135 | |
| 136 | const device_type PPI8255 = ppi8255_device_config::static_alloc_device_config; |
| 131 | 137 | |
| 132 | | static void set_mode(running_device *device, int data, int call_handlers); |
| 133 | | static void ppi8255_write_port(running_device *device, int port); |
| 138 | //------------------------------------------------- |
| 139 | // ppi8255_device - constructor |
| 140 | //------------------------------------------------- |
| 134 | 141 | |
| 142 | ppi8255_device::ppi8255_device(running_machine &_machine, const ppi8255_device_config &config) |
| 143 | : device_t(_machine, config), |
| 144 | m_config(config) |
| 145 | { |
| 135 | 146 | |
| 136 | | INLINE ppi8255_t *get_safe_token(running_device *device) { |
| 137 | | assert( device != NULL ); |
| 138 | | assert( device->type() == PPI8255 ); |
| 139 | | return ( ppi8255_t * ) downcast<legacy_device_base *>(device)->token(); |
| 140 | 147 | } |
| 141 | 148 | |
| 149 | //------------------------------------------------- |
| 150 | // device_start - device-specific startup |
| 151 | //------------------------------------------------- |
| 142 | 152 | |
| 143 | | INLINE void ppi8255_get_handshake_signals(ppi8255_t *ppi8255, int is_read, UINT8 *result) |
| 153 | void ppi8255_device::device_start() |
| 144 | 154 | { |
| 155 | devcb_resolve_read8(&m_port_read[0], &m_config.m_port_a_read, this); |
| 156 | devcb_resolve_read8(&m_port_read[1], &m_config.m_port_b_read, this); |
| 157 | devcb_resolve_read8(&m_port_read[2], &m_config.m_port_c_read, this); |
| 158 | |
| 159 | devcb_resolve_write8(&m_port_write[0], &m_config.m_port_a_write, this); |
| 160 | devcb_resolve_write8(&m_port_write[1], &m_config.m_port_b_write, this); |
| 161 | devcb_resolve_write8(&m_port_write[2], &m_config.m_port_c_write, this); |
| 162 | |
| 163 | /* register for state saving */ |
| 164 | state_save_register_device_item(this, 0, m_group_a_mode); |
| 165 | state_save_register_device_item(this, 0, m_group_b_mode); |
| 166 | state_save_register_device_item(this, 0, m_port_a_dir); |
| 167 | state_save_register_device_item(this, 0, m_port_b_dir); |
| 168 | state_save_register_device_item(this, 0, m_port_ch_dir); |
| 169 | state_save_register_device_item(this, 0, m_port_cl_dir); |
| 170 | state_save_register_device_item(this, 0, m_obf_a); |
| 171 | state_save_register_device_item(this, 0, m_obf_b); |
| 172 | state_save_register_device_item(this, 0, m_ibf_a); |
| 173 | state_save_register_device_item(this, 0, m_ibf_b); |
| 174 | state_save_register_device_item(this, 0, m_inte_a); |
| 175 | state_save_register_device_item(this, 0, m_inte_b); |
| 176 | state_save_register_device_item(this, 0, m_inte_1); |
| 177 | state_save_register_device_item(this, 0, m_inte_2); |
| 178 | state_save_register_device_item_array(this, 0, m_in_mask); |
| 179 | state_save_register_device_item_array(this, 0, m_out_mask); |
| 180 | state_save_register_device_item_array(this, 0, m_read); |
| 181 | state_save_register_device_item_array(this, 0, m_latch); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | //------------------------------------------------- |
| 186 | // device_reset - device-specific reset |
| 187 | //------------------------------------------------- |
| 188 | |
| 189 | void ppi8255_device::device_reset() |
| 190 | { |
| 191 | m_group_a_mode = 0; |
| 192 | m_group_b_mode = 0; |
| 193 | m_port_a_dir = 0; |
| 194 | m_port_b_dir = 0; |
| 195 | m_port_ch_dir = 0; |
| 196 | m_port_cl_dir = 0; |
| 197 | m_obf_a = m_ibf_a = 0; |
| 198 | m_obf_b = m_ibf_b = 0; |
| 199 | m_inte_a = m_inte_b = m_inte_1 = m_inte_2 = 0; |
| 200 | |
| 201 | for (int i = 0; i < 3; i++) |
| 202 | { |
| 203 | m_in_mask[i] = m_out_mask[i] = m_read[i] = m_latch[i] = m_output[i] = 0; |
| 204 | } |
| 205 | |
| 206 | set_mode(0x9b, 0); /* Mode 0, all ports set to input */ |
| 207 | } |
| 208 | |
| 209 | |
| 210 | void ppi8255_device::ppi8255_get_handshake_signals(int is_read, UINT8 *result) |
| 211 | { |
| 145 | 212 | UINT8 handshake = 0x00; |
| 146 | 213 | UINT8 mask = 0x00; |
| 147 | 214 | |
| 148 | 215 | /* group A */ |
| 149 | | if (ppi8255->group_a_mode == 1) |
| 216 | if (m_group_a_mode == 1) |
| 150 | 217 | { |
| 151 | | if (ppi8255->port_a_dir) |
| 218 | if (m_port_a_dir) |
| 152 | 219 | { |
| 153 | | handshake |= ppi8255->ibf_a ? 0x20 : 0x00; |
| 154 | | handshake |= (ppi8255->ibf_a && ppi8255->inte_a) ? 0x08 : 0x00; |
| 220 | handshake |= m_ibf_a ? 0x20 : 0x00; |
| 221 | handshake |= (m_ibf_a && m_inte_a) ? 0x08 : 0x00; |
| 155 | 222 | mask |= 0x28; |
| 156 | 223 | } |
| 157 | 224 | else |
| 158 | 225 | { |
| 159 | | handshake |= ppi8255->obf_a ? 0x00 : 0x80; |
| 160 | | handshake |= (ppi8255->obf_a && ppi8255->inte_a) ? 0x08 : 0x00; |
| 226 | handshake |= m_obf_a ? 0x00 : 0x80; |
| 227 | handshake |= (m_obf_a && m_inte_a) ? 0x08 : 0x00; |
| 161 | 228 | mask |= 0x88; |
| 162 | 229 | } |
| 163 | 230 | } |
| 164 | | else if (ppi8255->group_a_mode == 2) |
| 231 | else if (m_group_a_mode == 2) |
| 165 | 232 | { |
| 166 | | handshake |= ppi8255->obf_a ? 0x00 : 0x80; |
| 167 | | handshake |= ppi8255->ibf_a ? 0x20 : 0x00; |
| 168 | | handshake |= ((ppi8255->obf_a && ppi8255->inte_1) || (ppi8255->ibf_a && ppi8255->inte_2)) ? 0x08 : 0x00; |
| 233 | handshake |= m_obf_a ? 0x00 : 0x80; |
| 234 | handshake |= m_ibf_a ? 0x20 : 0x00; |
| 235 | handshake |= ((m_obf_a && m_inte_1) || (m_ibf_a && m_inte_2)) ? 0x08 : 0x00; |
| 169 | 236 | mask |= 0xA8; |
| 170 | 237 | } |
| 171 | 238 | |
| 172 | 239 | /* group B */ |
| 173 | | if (ppi8255->group_b_mode == 1) |
| 240 | if (m_group_b_mode == 1) |
| 174 | 241 | { |
| 175 | | if (ppi8255->port_b_dir) |
| 242 | if (m_port_b_dir) |
| 176 | 243 | { |
| 177 | | handshake |= ppi8255->ibf_b ? 0x02 : 0x00; |
| 178 | | handshake |= (ppi8255->ibf_b && ppi8255->inte_b) ? 0x01 : 0x00; |
| 244 | handshake |= m_ibf_b ? 0x02 : 0x00; |
| 245 | handshake |= (m_ibf_b && m_inte_b) ? 0x01 : 0x00; |
| 179 | 246 | mask |= 0x03; |
| 180 | 247 | } |
| 181 | 248 | else |
| 182 | 249 | { |
| 183 | | handshake |= ppi8255->obf_b ? 0x00 : 0x02; |
| 184 | | handshake |= (ppi8255->obf_b && ppi8255->inte_b) ? 0x01 : 0x00; |
| 250 | handshake |= m_obf_b ? 0x00 : 0x02; |
| 251 | handshake |= (m_obf_b && m_inte_b) ? 0x01 : 0x00; |
| 185 | 252 | mask |= 0x03; |
| 186 | 253 | } |
| 187 | 254 | } |
| r8910 | r8911 | |
| 192 | 259 | |
| 193 | 260 | |
| 194 | 261 | |
| 195 | | static void ppi8255_input(running_device *device, int port, UINT8 data) |
| 262 | void ppi8255_device::ppi8255_input(int port, UINT8 data) |
| 196 | 263 | { |
| 197 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 198 | 264 | int changed = 0; |
| 199 | 265 | |
| 200 | | ppi8255->read[port] = data; |
| 266 | m_read[port] = data; |
| 201 | 267 | |
| 202 | 268 | /* port C is special */ |
| 203 | 269 | if (port == 2) |
| 204 | 270 | { |
| 205 | | if (((ppi8255->group_a_mode == 1) && (ppi8255->port_a_dir == 0)) || (ppi8255->group_a_mode == 2)) |
| 271 | if (((m_group_a_mode == 1) && (m_port_a_dir == 0)) || (m_group_a_mode == 2)) |
| 206 | 272 | { |
| 207 | 273 | /* is !ACKA asserted? */ |
| 208 | | if (ppi8255->obf_a && !(data & 0x40)) |
| 274 | if (m_obf_a && !(data & 0x40)) |
| 209 | 275 | { |
| 210 | | ppi8255->obf_a = 0; |
| 276 | m_obf_a = 0; |
| 211 | 277 | changed = 1; |
| 212 | 278 | } |
| 213 | 279 | } |
| 214 | 280 | |
| 215 | | if (((ppi8255->group_a_mode == 1) && (ppi8255->port_a_dir == 1)) || (ppi8255->group_a_mode == 2)) |
| 281 | if (((m_group_a_mode == 1) && (m_port_a_dir == 1)) || (m_group_a_mode == 2)) |
| 216 | 282 | { |
| 217 | 283 | /* is !STBA asserted? */ |
| 218 | | if (!ppi8255->ibf_a && !(data & 0x10)) |
| 284 | if (!m_ibf_a && !(data & 0x10)) |
| 219 | 285 | { |
| 220 | | ppi8255->ibf_a = 1; |
| 286 | m_ibf_a = 1; |
| 221 | 287 | changed = 1; |
| 222 | 288 | } |
| 223 | 289 | } |
| 224 | 290 | |
| 225 | | if ((ppi8255->group_b_mode == 1) && (ppi8255->port_b_dir == 0)) |
| 291 | if ((m_group_b_mode == 1) && (m_port_b_dir == 0)) |
| 226 | 292 | { |
| 227 | 293 | /* is !ACKB asserted? */ |
| 228 | | if (ppi8255->obf_b && !(data & 0x04)) |
| 294 | if (m_obf_b && !(data & 0x04)) |
| 229 | 295 | { |
| 230 | | ppi8255->obf_b = 0; |
| 296 | m_obf_b = 0; |
| 231 | 297 | changed = 1; |
| 232 | 298 | } |
| 233 | 299 | } |
| 234 | 300 | |
| 235 | | if ((ppi8255->group_b_mode == 1) && (ppi8255->port_b_dir == 1)) |
| 301 | if ((m_group_b_mode == 1) && (m_port_b_dir == 1)) |
| 236 | 302 | { |
| 237 | 303 | /* is !STBB asserted? */ |
| 238 | | if (!ppi8255->ibf_b && !(data & 0x04)) |
| 304 | if (!m_ibf_b && !(data & 0x04)) |
| 239 | 305 | { |
| 240 | | ppi8255->ibf_b = 1; |
| 306 | m_ibf_b = 1; |
| 241 | 307 | changed = 1; |
| 242 | 308 | } |
| 243 | 309 | } |
| 244 | 310 | |
| 245 | 311 | if (changed) |
| 246 | | ppi8255_write_port(device, 2); |
| 312 | { |
| 313 | ppi8255_write_port(2); |
| 314 | } |
| 247 | 315 | } |
| 248 | 316 | } |
| 249 | 317 | |
| 250 | 318 | |
| 251 | 319 | |
| 252 | | static UINT8 ppi8255_read_port(running_device *device, int port) |
| 320 | UINT8 ppi8255_device::ppi8255_read_port(int port) |
| 253 | 321 | { |
| 254 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 255 | 322 | UINT8 result = 0x00; |
| 256 | 323 | |
| 257 | | if (ppi8255->in_mask[port]) |
| 324 | if (m_in_mask[port]) |
| 258 | 325 | { |
| 259 | | if (ppi8255->port_read[port].read != NULL) |
| 260 | | ppi8255_input(device, port, devcb_call_read8(&ppi8255->port_read[port], 0)); |
| 261 | | |
| 262 | | result |= ppi8255->read[port] & ppi8255->in_mask[port]; |
| 326 | ppi8255_input(port, devcb_call_read8(&m_port_read[port], 0)); |
| 327 | result |= m_read[port] & m_in_mask[port]; |
| 263 | 328 | } |
| 264 | | result |= ppi8255->latch[port] & ppi8255->out_mask[port]; |
| 329 | result |= m_latch[port] & m_out_mask[port]; |
| 265 | 330 | |
| 266 | 331 | switch (port) |
| 267 | 332 | { |
| 268 | 333 | case 0: |
| 269 | 334 | /* clear input buffer full flag */ |
| 270 | | ppi8255->ibf_a = 0; |
| 335 | m_ibf_a = 0; |
| 271 | 336 | break; |
| 272 | 337 | |
| 273 | 338 | case 1: |
| 274 | 339 | /* clear input buffer full flag */ |
| 275 | | ppi8255->ibf_b = 0; |
| 340 | m_ibf_b = 0; |
| 276 | 341 | break; |
| 277 | 342 | |
| 278 | 343 | case 2: |
| 279 | 344 | /* read special port 2 signals */ |
| 280 | | ppi8255_get_handshake_signals(ppi8255, 1, &result); |
| 345 | ppi8255_get_handshake_signals(1, &result); |
| 281 | 346 | break; |
| 282 | 347 | } |
| 283 | 348 | |
| r8910 | r8911 | |
| 286 | 351 | |
| 287 | 352 | |
| 288 | 353 | |
| 289 | | READ8_DEVICE_HANDLER( ppi8255_r ) |
| 354 | READ8_DEVICE_HANDLER_TRAMPOLINE(ppi8255, ppi8255_r) |
| 290 | 355 | { |
| 291 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 292 | 356 | UINT8 result = 0; |
| 293 | 357 | |
| 294 | 358 | offset %= 4; |
| r8910 | r8911 | |
| 298 | 362 | case 0: /* Port A read */ |
| 299 | 363 | case 1: /* Port B read */ |
| 300 | 364 | case 2: /* Port C read */ |
| 301 | | result = ppi8255_read_port(device, offset); |
| 365 | result = ppi8255_read_port(offset); |
| 302 | 366 | break; |
| 303 | 367 | |
| 304 | 368 | case 3: /* Control word */ |
| 305 | | result = ppi8255->control; |
| 369 | result = m_control; |
| 306 | 370 | break; |
| 307 | 371 | } |
| 308 | 372 | |
| r8910 | r8911 | |
| 311 | 375 | |
| 312 | 376 | |
| 313 | 377 | |
| 314 | | static void ppi8255_write_port(running_device *device, int port) |
| 378 | void ppi8255_device::ppi8255_write_port(int port) |
| 315 | 379 | { |
| 316 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 317 | | UINT8 write_data; |
| 380 | UINT8 write_data = m_latch[port] & m_out_mask[port]; |
| 381 | write_data |= 0xFF & ~m_out_mask[port]; |
| 318 | 382 | |
| 319 | | write_data = ppi8255->latch[port] & ppi8255->out_mask[port]; |
| 320 | | write_data |= 0xFF & ~ppi8255->out_mask[port]; |
| 321 | | |
| 322 | 383 | /* write out special port 2 signals */ |
| 323 | 384 | if (port == 2) |
| 324 | | ppi8255_get_handshake_signals(ppi8255, 0, &write_data); |
| 385 | { |
| 386 | ppi8255_get_handshake_signals(0, &write_data); |
| 387 | } |
| 325 | 388 | |
| 326 | | ppi8255->output[port] = write_data; |
| 327 | | if (ppi8255->port_write[port].write != NULL) |
| 328 | | devcb_call_write8(&ppi8255->port_write[port], 0, write_data); |
| 389 | m_output[port] = write_data; |
| 390 | devcb_call_write8(&m_port_write[port], 0, write_data); |
| 329 | 391 | } |
| 330 | 392 | |
| 331 | 393 | |
| 332 | 394 | |
| 333 | | WRITE8_DEVICE_HANDLER( ppi8255_w ) |
| 395 | WRITE8_DEVICE_HANDLER_TRAMPOLINE(ppi8255, ppi8255_w) |
| 334 | 396 | { |
| 335 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 336 | | |
| 337 | 397 | offset %= 4; |
| 338 | 398 | |
| 339 | 399 | switch( offset ) |
| r8910 | r8911 | |
| 341 | 401 | case 0: /* Port A write */ |
| 342 | 402 | case 1: /* Port B write */ |
| 343 | 403 | case 2: /* Port C write */ |
| 344 | | ppi8255->latch[offset] = data; |
| 345 | | ppi8255_write_port(device, offset); |
| 404 | m_latch[offset] = data; |
| 405 | ppi8255_write_port(offset); |
| 346 | 406 | |
| 347 | 407 | switch(offset) |
| 348 | 408 | { |
| 349 | 409 | case 0: |
| 350 | | if (!ppi8255->port_a_dir && (ppi8255->group_a_mode != 0)) |
| 410 | if (!m_port_a_dir && (m_group_a_mode != 0)) |
| 351 | 411 | { |
| 352 | | ppi8255->obf_a = 1; |
| 353 | | ppi8255_write_port(device, 2); |
| 412 | m_obf_a = 1; |
| 413 | ppi8255_write_port(2); |
| 354 | 414 | } |
| 355 | 415 | break; |
| 356 | 416 | |
| 357 | 417 | case 1: |
| 358 | | if (!ppi8255->port_b_dir && (ppi8255->group_b_mode != 0)) |
| 418 | if (!m_port_b_dir && (m_group_b_mode != 0)) |
| 359 | 419 | { |
| 360 | | ppi8255->obf_b = 1; |
| 361 | | ppi8255_write_port(device, 2); |
| 420 | m_obf_b = 1; |
| 421 | ppi8255_write_port(2); |
| 362 | 422 | } |
| 363 | 423 | break; |
| 364 | 424 | } |
| r8910 | r8911 | |
| 367 | 427 | case 3: /* Control word */ |
| 368 | 428 | if (data & 0x80) |
| 369 | 429 | { |
| 370 | | set_mode(device, data & 0x7f, 1); |
| 430 | set_mode(data & 0x7f, 1); |
| 371 | 431 | } |
| 372 | 432 | else |
| 373 | 433 | { |
| 374 | 434 | /* bit set/reset */ |
| 375 | | int bit; |
| 435 | int bit = (data >> 1) & 0x07; |
| 376 | 436 | |
| 377 | | bit = (data >> 1) & 0x07; |
| 378 | | |
| 379 | 437 | if (data & 1) |
| 380 | | ppi8255->latch[2] |= (1<<bit); /* set bit */ |
| 438 | { |
| 439 | m_latch[2] |= (1 << bit); /* set bit */ |
| 440 | } |
| 381 | 441 | else |
| 382 | | ppi8255->latch[2] &= ~(1<<bit); /* reset bit */ |
| 442 | { |
| 443 | m_latch[2] &= ~(1 << bit); /* reset bit */ |
| 444 | } |
| 383 | 445 | |
| 384 | | if (ppi8255->group_b_mode == 1) |
| 446 | if (m_group_b_mode == 1) |
| 385 | 447 | { |
| 386 | | if (bit == 2) ppi8255->inte_b = data & 1; |
| 448 | if (bit == 2) |
| 449 | { |
| 450 | m_inte_b = data & 1; |
| 451 | } |
| 387 | 452 | } |
| 388 | 453 | |
| 389 | | if (ppi8255->group_a_mode == 1) |
| 454 | if (m_group_a_mode == 1) |
| 390 | 455 | { |
| 391 | | if (bit == 4 && ppi8255->port_a_dir) ppi8255->inte_a = data & 1; |
| 392 | | if (bit == 6 && !ppi8255->port_a_dir) ppi8255->inte_a = data & 1; |
| 456 | if (bit == 4 && m_port_a_dir) |
| 457 | { |
| 458 | m_inte_a = data & 1; |
| 459 | } |
| 460 | if (bit == 6 && !m_port_a_dir) |
| 461 | { |
| 462 | m_inte_a = data & 1; |
| 463 | } |
| 393 | 464 | } |
| 394 | 465 | |
| 395 | | if (ppi8255->group_a_mode == 2) |
| 466 | if (m_group_a_mode == 2) |
| 396 | 467 | { |
| 397 | | if (bit == 4) ppi8255->inte_2 = data & 1; |
| 398 | | if (bit == 6) ppi8255->inte_1 = data & 1; |
| 468 | if (bit == 4) |
| 469 | { |
| 470 | m_inte_2 = data & 1; |
| 471 | } |
| 472 | if (bit == 6) |
| 473 | { |
| 474 | m_inte_1 = data & 1; |
| 475 | } |
| 399 | 476 | } |
| 400 | 477 | |
| 401 | | ppi8255_write_port(device, 2); |
| 478 | ppi8255_write_port(2); |
| 402 | 479 | } |
| 403 | 480 | break; |
| 404 | 481 | } |
| 405 | 482 | } |
| 406 | 483 | |
| 407 | 484 | |
| 408 | | void ppi8255_set_port_a_read(running_device *device, const devcb_read8 *config) |
| 485 | void ppi8255_device::set_mode(int data, int call_handlers) |
| 409 | 486 | { |
| 410 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 411 | | devcb_resolve_read8(&ppi8255->port_read[0], config, device); |
| 412 | | } |
| 413 | | |
| 414 | | void ppi8255_set_port_b_read(running_device *device, const devcb_read8 *config) |
| 415 | | { |
| 416 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 417 | | devcb_resolve_read8(&ppi8255->port_read[1], config, device); |
| 418 | | } |
| 419 | | |
| 420 | | void ppi8255_set_port_c_read(running_device *device, const devcb_read8 *config) |
| 421 | | { |
| 422 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 423 | | devcb_resolve_read8(&ppi8255->port_read[2], config, device); |
| 424 | | } |
| 425 | | |
| 426 | | |
| 427 | | void ppi8255_set_port_a_write(running_device *device, const devcb_write8 *config) |
| 428 | | { |
| 429 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 430 | | devcb_resolve_write8(&ppi8255->port_write[0], config, device); |
| 431 | | } |
| 432 | | |
| 433 | | void ppi8255_set_port_b_write(running_device *device, const devcb_write8 *config) |
| 434 | | { |
| 435 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 436 | | devcb_resolve_write8(&ppi8255->port_write[1], config, device); |
| 437 | | } |
| 438 | | |
| 439 | | void ppi8255_set_port_c_write(running_device *device, const devcb_write8 *config) |
| 440 | | { |
| 441 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 442 | | devcb_resolve_write8(&ppi8255->port_write[2], config, device); |
| 443 | | } |
| 444 | | |
| 445 | | |
| 446 | | static void set_mode(running_device *device, int data, int call_handlers) |
| 447 | | { |
| 448 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 449 | | int i; |
| 450 | | |
| 451 | 487 | /* parse out mode */ |
| 452 | | ppi8255->group_a_mode = (data >> 5) & 3; |
| 453 | | ppi8255->group_b_mode = (data >> 2) & 1; |
| 454 | | ppi8255->port_a_dir = (data >> 4) & 1; |
| 455 | | ppi8255->port_b_dir = (data >> 1) & 1; |
| 456 | | ppi8255->port_ch_dir = (data >> 3) & 1; |
| 457 | | ppi8255->port_cl_dir = (data >> 0) & 1; |
| 488 | m_group_a_mode = (data >> 5) & 3; |
| 489 | m_group_b_mode = (data >> 2) & 1; |
| 490 | m_port_a_dir = (data >> 4) & 1; |
| 491 | m_port_b_dir = (data >> 1) & 1; |
| 492 | m_port_ch_dir = (data >> 3) & 1; |
| 493 | m_port_cl_dir = (data >> 0) & 1; |
| 458 | 494 | |
| 459 | 495 | /* normalize group_a_mode */ |
| 460 | | if (ppi8255->group_a_mode == 3) |
| 461 | | ppi8255->group_a_mode = 2; |
| 496 | if (m_group_a_mode == 3) |
| 497 | { |
| 498 | m_group_a_mode = 2; |
| 499 | } |
| 462 | 500 | |
| 463 | 501 | /* Port A direction */ |
| 464 | | if (ppi8255->group_a_mode == 2) |
| 465 | | ppi8255->in_mask[0] = 0xFF, ppi8255->out_mask[0] = 0xFF; /* bidirectional */ |
| 502 | if (m_group_a_mode == 2) |
| 503 | { |
| 504 | m_in_mask[0] = 0xFF; |
| 505 | m_out_mask[0] = 0xFF; /* bidirectional */ |
| 506 | } |
| 466 | 507 | else |
| 467 | | if (ppi8255->port_a_dir) |
| 468 | | ppi8255->in_mask[0] = 0xFF, ppi8255->out_mask[0] = 0x00; /* input */ |
| 508 | { |
| 509 | if (m_port_a_dir) |
| 510 | { |
| 511 | m_in_mask[0] = 0xFF; |
| 512 | m_out_mask[0] = 0x00; /* input */ |
| 513 | } |
| 469 | 514 | else |
| 470 | | ppi8255->in_mask[0] = 0x00, ppi8255->out_mask[0] = 0xFF; /* output */ |
| 515 | { |
| 516 | m_in_mask[0] = 0x00; |
| 517 | m_out_mask[0] = 0xFF; /* output */ |
| 518 | } |
| 519 | } |
| 471 | 520 | |
| 472 | 521 | /* Port B direction */ |
| 473 | | if (ppi8255->port_b_dir) |
| 474 | | ppi8255->in_mask[1] = 0xFF, ppi8255->out_mask[1] = 0x00; /* input */ |
| 522 | if (m_port_b_dir) |
| 523 | { |
| 524 | m_in_mask[1] = 0xFF; |
| 525 | m_out_mask[1] = 0x00; /* input */ |
| 526 | } |
| 475 | 527 | else |
| 476 | | ppi8255->in_mask[1] = 0x00, ppi8255->out_mask[1] = 0xFF; /* output */ |
| 528 | { |
| 529 | m_in_mask[1] = 0x00; |
| 530 | m_out_mask[1] = 0xFF; /* output */ |
| 531 | } |
| 477 | 532 | |
| 478 | 533 | /* Port C upper direction */ |
| 479 | | if (ppi8255->port_ch_dir) |
| 480 | | ppi8255->in_mask[2] = 0xF0, ppi8255->out_mask[2] = 0x00; /* input */ |
| 534 | if (m_port_ch_dir) |
| 535 | { |
| 536 | m_in_mask[2] = 0xF0; |
| 537 | m_out_mask[2] = 0x00; /* input */ |
| 538 | } |
| 481 | 539 | else |
| 482 | | ppi8255->in_mask[2] = 0x00, ppi8255->out_mask[2] = 0xF0; /* output */ |
| 540 | { |
| 541 | m_in_mask[2] = 0x00; |
| 542 | m_out_mask[2] = 0xF0; /* output */ |
| 543 | } |
| 483 | 544 | |
| 484 | 545 | /* Port C lower direction */ |
| 485 | | if (ppi8255->port_cl_dir) |
| 486 | | ppi8255->in_mask[2] |= 0x0F; /* input */ |
| 546 | if (m_port_cl_dir) |
| 547 | { |
| 548 | m_in_mask[2] |= 0x0F; /* input */ |
| 549 | } |
| 487 | 550 | else |
| 488 | | ppi8255->out_mask[2] |= 0x0F; /* output */ |
| 551 | { |
| 552 | m_out_mask[2] |= 0x0F; /* output */ |
| 553 | } |
| 489 | 554 | |
| 490 | 555 | /* now depending on the group modes, certain Port C lines may be replaced |
| 491 | 556 | * with varying control signals */ |
| 492 | | switch(ppi8255->group_a_mode) |
| 557 | switch(m_group_a_mode) |
| 493 | 558 | { |
| 494 | 559 | case 0: /* Group A mode 0 */ |
| 495 | 560 | /* no changes */ |
| r8910 | r8911 | |
| 497 | 562 | |
| 498 | 563 | case 1: /* Group A mode 1 */ |
| 499 | 564 | /* bits 5-3 are reserved by Group A mode 1 */ |
| 500 | | ppi8255->in_mask[2] &= ~0x38; |
| 501 | | ppi8255->out_mask[2] &= ~0x38; |
| 565 | m_in_mask[2] &= ~0x38; |
| 566 | m_out_mask[2] &= ~0x38; |
| 502 | 567 | break; |
| 503 | 568 | |
| 504 | 569 | case 2: /* Group A mode 2 */ |
| 505 | 570 | /* bits 7-3 are reserved by Group A mode 2 */ |
| 506 | | ppi8255->in_mask[2] &= ~0xF8; |
| 507 | | ppi8255->out_mask[2] &= ~0xF8; |
| 571 | m_in_mask[2] &= ~0xF8; |
| 572 | m_out_mask[2] &= ~0xF8; |
| 508 | 573 | break; |
| 509 | 574 | } |
| 510 | 575 | |
| 511 | | switch(ppi8255->group_b_mode) |
| 576 | switch(m_group_b_mode) |
| 512 | 577 | { |
| 513 | 578 | case 0: /* Group B mode 0 */ |
| 514 | 579 | /* no changes */ |
| r8910 | r8911 | |
| 516 | 581 | |
| 517 | 582 | case 1: /* Group B mode 1 */ |
| 518 | 583 | /* bits 2-0 are reserved by Group B mode 1 */ |
| 519 | | ppi8255->in_mask[2] &= ~0x07; |
| 520 | | ppi8255->out_mask[2] &= ~0x07; |
| 584 | m_in_mask[2] &= ~0x07; |
| 585 | m_out_mask[2] &= ~0x07; |
| 521 | 586 | break; |
| 522 | 587 | } |
| 523 | 588 | |
| 524 | 589 | /* KT: 25-Dec-99 - 8255 resets latches when mode set */ |
| 525 | | ppi8255->latch[0] = ppi8255->latch[1] = ppi8255->latch[2] = 0; |
| 590 | m_latch[0] = m_latch[1] = m_latch[2] = 0; |
| 526 | 591 | |
| 527 | 592 | if (call_handlers) |
| 528 | 593 | { |
| 529 | | for (i = 0; i < 3; i++) |
| 530 | | ppi8255_write_port(device, i); |
| 594 | for (int i = 0; i < 3; i++) |
| 595 | { |
| 596 | ppi8255_write_port(i); |
| 597 | } |
| 531 | 598 | } |
| 532 | 599 | |
| 533 | 600 | /* reset flip-flops */ |
| 534 | | ppi8255->obf_a = ppi8255->ibf_a = 0; |
| 535 | | ppi8255->obf_b = ppi8255->ibf_b = 0; |
| 536 | | ppi8255->inte_a = ppi8255->inte_b = ppi8255->inte_1 = ppi8255->inte_2 = 0; |
| 601 | m_obf_a = m_ibf_a = 0; |
| 602 | m_obf_b = m_ibf_b = 0; |
| 603 | m_inte_a = m_inte_b = m_inte_1 = m_inte_2 = 0; |
| 537 | 604 | |
| 538 | 605 | /* store control word */ |
| 539 | | ppi8255->control = data; |
| 606 | m_control = data; |
| 540 | 607 | } |
| 541 | 608 | |
| 609 | void ppi8255_set_port_a_read(running_device *device, const devcb_read8 *config) |
| 610 | { |
| 611 | downcast<ppi8255_device*>(device)->ppi8255_set_port_read(0, config); |
| 612 | } |
| 542 | 613 | |
| 543 | | void ppi8255_set_port_a( running_device *device, UINT8 data ) { ppi8255_input(device, 0, data); } |
| 544 | | void ppi8255_set_port_b( running_device *device, UINT8 data ) { ppi8255_input(device, 1, data); } |
| 545 | | void ppi8255_set_port_c( running_device *device, UINT8 data ) { ppi8255_input(device, 2, data); } |
| 614 | void ppi8255_set_port_b_read(running_device *device, const devcb_read8 *config) |
| 615 | { |
| 616 | downcast<ppi8255_device*>(device)->ppi8255_set_port_read(1, config); |
| 617 | } |
| 546 | 618 | |
| 547 | | UINT8 ppi8255_get_port_a( running_device *device ) { |
| 548 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 549 | | |
| 550 | | return ppi8255->output[0]; |
| 619 | void ppi8255_set_port_c_read(running_device *device, const devcb_read8 *config) |
| 620 | { |
| 621 | downcast<ppi8255_device*>(device)->ppi8255_set_port_read(2, config); |
| 551 | 622 | } |
| 552 | 623 | |
| 553 | | UINT8 ppi8255_get_port_b( running_device *device ) { |
| 554 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 555 | 624 | |
| 556 | | return ppi8255->output[1]; |
| 625 | void ppi8255_set_port_a_write(running_device *device, const devcb_write8 *config) |
| 626 | { |
| 627 | downcast<ppi8255_device*>(device)->ppi8255_set_port_write(0, config); |
| 557 | 628 | } |
| 558 | 629 | |
| 559 | | UINT8 ppi8255_get_port_c( running_device *device ) { |
| 560 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 630 | void ppi8255_set_port_b_write(running_device *device, const devcb_write8 *config) |
| 631 | { |
| 632 | downcast<ppi8255_device*>(device)->ppi8255_set_port_write(1, config); |
| 633 | } |
| 561 | 634 | |
| 562 | | return ppi8255->output[2]; |
| 635 | void ppi8255_set_port_c_write(running_device *device, const devcb_write8 *config) |
| 636 | { |
| 637 | downcast<ppi8255_device*>(device)->ppi8255_set_port_write(2, config); |
| 563 | 638 | } |
| 564 | 639 | |
| 565 | 640 | |
| 566 | | static DEVICE_START( ppi8255 ) { |
| 567 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 641 | void ppi8255_set_port_a( running_device *device, UINT8 data ) |
| 642 | { |
| 643 | downcast<ppi8255_device*>(device)->ppi8255_set_port(0, data); |
| 644 | } |
| 568 | 645 | |
| 569 | | ppi8255->intf = (const ppi8255_interface *)device->baseconfig().static_config(); |
| 646 | void ppi8255_set_port_b( running_device *device, UINT8 data ) |
| 647 | { |
| 648 | downcast<ppi8255_device*>(device)->ppi8255_set_port(1, data); |
| 649 | } |
| 570 | 650 | |
| 571 | | devcb_resolve_read8(&ppi8255->port_read[0], &ppi8255->intf->port_a_read, device); |
| 572 | | devcb_resolve_read8(&ppi8255->port_read[1], &ppi8255->intf->port_b_read, device); |
| 573 | | devcb_resolve_read8(&ppi8255->port_read[2], &ppi8255->intf->port_c_read, device); |
| 651 | void ppi8255_set_port_c( running_device *device, UINT8 data ) |
| 652 | { |
| 653 | downcast<ppi8255_device*>(device)->ppi8255_set_port(2, data); |
| 654 | } |
| 574 | 655 | |
| 575 | | devcb_resolve_write8(&ppi8255->port_write[0], &ppi8255->intf->port_a_write, device); |
| 576 | | devcb_resolve_write8(&ppi8255->port_write[1], &ppi8255->intf->port_b_write, device); |
| 577 | | devcb_resolve_write8(&ppi8255->port_write[2], &ppi8255->intf->port_c_write, device); |
| 578 | 656 | |
| 579 | | /* register for state saving */ |
| 580 | | state_save_register_device_item(device, 0, ppi8255->group_a_mode); |
| 581 | | state_save_register_device_item(device, 0, ppi8255->group_b_mode); |
| 582 | | state_save_register_device_item(device, 0, ppi8255->port_a_dir); |
| 583 | | state_save_register_device_item(device, 0, ppi8255->port_b_dir); |
| 584 | | state_save_register_device_item(device, 0, ppi8255->port_ch_dir); |
| 585 | | state_save_register_device_item(device, 0, ppi8255->port_cl_dir); |
| 586 | | state_save_register_device_item(device, 0, ppi8255->obf_a); |
| 587 | | state_save_register_device_item(device, 0, ppi8255->obf_b); |
| 588 | | state_save_register_device_item(device, 0, ppi8255->ibf_a); |
| 589 | | state_save_register_device_item(device, 0, ppi8255->ibf_b); |
| 590 | | state_save_register_device_item(device, 0, ppi8255->inte_a); |
| 591 | | state_save_register_device_item(device, 0, ppi8255->inte_b); |
| 592 | | state_save_register_device_item(device, 0, ppi8255->inte_1); |
| 593 | | state_save_register_device_item(device, 0, ppi8255->inte_2); |
| 594 | | state_save_register_device_item_array(device, 0, ppi8255->in_mask); |
| 595 | | state_save_register_device_item_array(device, 0, ppi8255->out_mask); |
| 596 | | state_save_register_device_item_array(device, 0, ppi8255->read); |
| 597 | | state_save_register_device_item_array(device, 0, ppi8255->latch); |
| 657 | UINT8 ppi8255_get_port_a( running_device *device ) |
| 658 | { |
| 659 | return downcast<ppi8255_device*>(device)->ppi8255_get_port(0); |
| 598 | 660 | } |
| 599 | 661 | |
| 600 | | |
| 601 | | static DEVICE_RESET( ppi8255 ) { |
| 602 | | ppi8255_t *ppi8255 = get_safe_token(device); |
| 603 | | int i; |
| 604 | | |
| 605 | | ppi8255->group_a_mode = 0; |
| 606 | | ppi8255->group_b_mode = 0; |
| 607 | | ppi8255->port_a_dir = 0; |
| 608 | | ppi8255->port_b_dir = 0; |
| 609 | | ppi8255->port_ch_dir = 0; |
| 610 | | ppi8255->port_cl_dir = 0; |
| 611 | | ppi8255->obf_a = ppi8255->ibf_a = 0; |
| 612 | | ppi8255->obf_b = ppi8255->ibf_b = 0; |
| 613 | | ppi8255->inte_a = ppi8255->inte_b = ppi8255->inte_1 = ppi8255->inte_2 = 0; |
| 614 | | |
| 615 | | for ( i = 0; i < 3; i++ ) { |
| 616 | | ppi8255->in_mask[i] = ppi8255->out_mask[i] = ppi8255->read[i] = ppi8255->latch[i] = ppi8255->output[i] = 0; |
| 617 | | } |
| 618 | | |
| 619 | | set_mode(device, 0x9b, 0); /* Mode 0, all ports set to input */ |
| 662 | UINT8 ppi8255_get_port_b( running_device *device ) |
| 663 | { |
| 664 | return downcast<ppi8255_device*>(device)->ppi8255_get_port(1); |
| 620 | 665 | } |
| 621 | 666 | |
| 622 | | |
| 623 | | DEVICE_GET_INFO(ppi8255) { |
| 624 | | switch ( state ) { |
| 625 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 626 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ppi8255_t); break; |
| 627 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 628 | | |
| 629 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 630 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ppi8255); break; |
| 631 | | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 632 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(ppi8255); break; |
| 633 | | |
| 634 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 635 | | case DEVINFO_STR_NAME: strcpy(info->s, "Intel PPI8255"); break; |
| 636 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "PPI8255"); break; |
| 637 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.00"); break; |
| 638 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 639 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MAME and MESS Teams"); break; |
| 640 | | } |
| 667 | UINT8 ppi8255_get_port_c( running_device *device ) |
| 668 | { |
| 669 | return downcast<ppi8255_device*>(device)->ppi8255_get_port(2); |
| 641 | 670 | } |
| 642 | | |
| 643 | | |
| 644 | | DEFINE_LEGACY_DEVICE(PPI8255, ppi8255); |
src/emu/machine/6850acia.c
| r8910 | r8911 | |
| 8 | 8 | |
| 9 | 9 | #include "emu.h" |
| 10 | 10 | #include "6850acia.h" |
| 11 | #include "devhelpr.h" |
| 11 | 12 | |
| 12 | 13 | |
| 13 | 14 | /*************************************************************************** |
| r8910 | r8911 | |
| 20 | 21 | #define CR7 0x80 |
| 21 | 22 | |
| 22 | 23 | #define TXD(_data) \ |
| 23 | | devcb_call_write_line(&acia_p->out_tx_func, _data) |
| 24 | devcb_call_write_line(&m_out_tx_func, _data) |
| 24 | 25 | |
| 25 | 26 | #define RTS(_data) \ |
| 26 | | devcb_call_write_line(&acia_p->out_rts_func, _data) |
| 27 | devcb_call_write_line(&m_out_rts_func, _data) |
| 27 | 28 | |
| 28 | | static void acia6850_check_interrupts(running_device *device); |
| 29 | | |
| 30 | 29 | /*************************************************************************** |
| 31 | | TYPE DEFINITIONS |
| 32 | | ***************************************************************************/ |
| 33 | | |
| 34 | | enum serial_state |
| 35 | | { |
| 36 | | START, |
| 37 | | DATA, |
| 38 | | PARITY, |
| 39 | | STOP, |
| 40 | | STOP2, |
| 41 | | }; |
| 42 | | |
| 43 | | enum _parity_type |
| 44 | | { |
| 45 | | NONE, |
| 46 | | ODD, |
| 47 | | EVEN |
| 48 | | }; |
| 49 | | typedef enum _parity_type parity_type; |
| 50 | | |
| 51 | | typedef struct _acia6850_t acia6850_t; |
| 52 | | struct _acia6850_t |
| 53 | | { |
| 54 | | devcb_resolved_read_line in_rx_func; |
| 55 | | devcb_resolved_write_line out_tx_func; |
| 56 | | devcb_resolved_read_line in_cts_func; |
| 57 | | devcb_resolved_write_line out_rts_func; |
| 58 | | devcb_resolved_read_line in_dcd_func; |
| 59 | | devcb_resolved_write_line out_irq_func; |
| 60 | | |
| 61 | | UINT8 ctrl; |
| 62 | | UINT8 status; |
| 63 | | |
| 64 | | UINT8 tdr; |
| 65 | | UINT8 rdr; |
| 66 | | UINT8 rx_shift; |
| 67 | | UINT8 tx_shift; |
| 68 | | |
| 69 | | UINT8 rx_counter; |
| 70 | | UINT8 tx_counter; |
| 71 | | |
| 72 | | int rx_clock; |
| 73 | | int tx_clock; |
| 74 | | |
| 75 | | int divide; |
| 76 | | |
| 77 | | /* Counters */ |
| 78 | | int tx_bits; |
| 79 | | int rx_bits; |
| 80 | | int tx_parity; |
| 81 | | int rx_parity; |
| 82 | | |
| 83 | | /* TX/RX state */ |
| 84 | | int bits; |
| 85 | | parity_type parity; |
| 86 | | int stopbits; |
| 87 | | int tx_int; |
| 88 | | |
| 89 | | /* Signals */ |
| 90 | | int overrun; |
| 91 | | int reset; |
| 92 | | int rts; |
| 93 | | int brk; |
| 94 | | int first_reset; |
| 95 | | int status_read; |
| 96 | | enum serial_state rx_state; |
| 97 | | enum serial_state tx_state; |
| 98 | | int irq; |
| 99 | | |
| 100 | | emu_timer *rx_timer; |
| 101 | | emu_timer *tx_timer; |
| 102 | | }; |
| 103 | | |
| 104 | | |
| 105 | | /*************************************************************************** |
| 106 | 30 | LOCAL VARIABLES |
| 107 | 31 | ***************************************************************************/ |
| 108 | 32 | |
| 109 | | static const int ACIA6850_DIVIDE[3] = { 1, 16, 64 }; |
| 33 | const int acia6850_device::ACIA6850_DIVIDE[3] = { 1, 16, 64 }; |
| 110 | 34 | |
| 111 | | static const int ACIA6850_WORD[8][3] = |
| 35 | const int acia6850_device::ACIA6850_WORD[8][3] = |
| 112 | 36 | { |
| 113 | 37 | { 7, EVEN, 2 }, |
| 114 | 38 | { 7, ODD, 2 }, |
| r8910 | r8911 | |
| 121 | 45 | }; |
| 122 | 46 | |
| 123 | 47 | |
| 48 | |
| 124 | 49 | /*************************************************************************** |
| 125 | | PROTOTYPES |
| 50 | LIVE DEVICE |
| 126 | 51 | ***************************************************************************/ |
| 127 | 52 | |
| 128 | | static TIMER_CALLBACK( receive_event ); |
| 129 | | static TIMER_CALLBACK( transmit_event ); |
| 53 | const device_type ACIA6850 = acia6850_device_config::static_alloc_device_config; |
| 130 | 54 | |
| 55 | GENERIC_DEVICE_CONFIG_SETUP(acia6850, "ACIA6850") |
| 131 | 56 | |
| 132 | | /*************************************************************************** |
| 133 | | INLINE FUNCTIONS |
| 134 | | ***************************************************************************/ |
| 57 | //------------------------------------------------- |
| 58 | // device_config_complete - perform any |
| 59 | // operations now that the configuration is |
| 60 | // complete |
| 61 | //------------------------------------------------- |
| 135 | 62 | |
| 136 | | INLINE acia6850_t *get_token(running_device *device) |
| 63 | void acia6850_device_config::device_config_complete() |
| 137 | 64 | { |
| 138 | | assert(device != NULL); |
| 139 | | assert(device->type() == ACIA6850); |
| 140 | | return (acia6850_t *) downcast<legacy_device_base *>(device)->token(); |
| 65 | // inherit a copy of the static data |
| 66 | const acia6850_interface *intf = reinterpret_cast<const acia6850_interface *>(static_config()); |
| 67 | if (intf != NULL) |
| 68 | { |
| 69 | *static_cast<acia6850_interface *>(this) = *intf; |
| 70 | } |
| 71 | |
| 72 | // or initialize to defaults if none provided |
| 73 | else |
| 74 | { |
| 75 | m_tx_clock = 0; |
| 76 | m_rx_clock = 0; |
| 77 | memset(&m_in_rx_func, 0, sizeof(m_in_rx_func)); |
| 78 | memset(&m_out_tx_func, 0, sizeof(m_out_tx_func)); |
| 79 | memset(&m_in_cts_func, 0, sizeof(m_in_cts_func)); |
| 80 | memset(&m_out_rts_func, 0, sizeof(m_out_rts_func)); |
| 81 | memset(&m_in_dcd_func, 0, sizeof(m_in_dcd_func)); |
| 82 | memset(&m_out_irq_func, 0, sizeof(m_out_irq_func)); |
| 83 | } |
| 141 | 84 | } |
| 142 | 85 | |
| 143 | 86 | |
| 144 | | INLINE acia6850_interface *get_interface(running_device *device) |
| 87 | //------------------------------------------------- |
| 88 | // acia6850_device - constructor |
| 89 | //------------------------------------------------- |
| 90 | |
| 91 | acia6850_device::acia6850_device(running_machine &_machine, const acia6850_device_config &config) |
| 92 | : device_t(_machine, config), |
| 93 | m_config(config) |
| 145 | 94 | { |
| 146 | | assert(device != NULL); |
| 147 | | assert(device->type() == ACIA6850); |
| 148 | | return (acia6850_interface *) device->baseconfig().static_config(); |
| 95 | |
| 149 | 96 | } |
| 150 | 97 | |
| 151 | 98 | |
| 152 | | /*************************************************************************** |
| 153 | | IMPLEMENTATION |
| 154 | | ***************************************************************************/ |
| 99 | //------------------------------------------------- |
| 100 | // device_start - device-specific startup |
| 101 | //------------------------------------------------- |
| 155 | 102 | |
| 156 | | /*------------------------------------------------- |
| 157 | | DEVICE_RESET( acia6850 ) |
| 158 | | -------------------------------------------------*/ |
| 159 | | |
| 160 | | static DEVICE_RESET( acia6850 ) |
| 103 | void acia6850_device::device_start() |
| 161 | 104 | { |
| 162 | | acia6850_t *acia_p = get_token(device); |
| 105 | /* resolve callbacks */ |
| 106 | devcb_resolve_read_line(&m_in_rx_func, &m_config.m_in_rx_func, this); |
| 107 | devcb_resolve_write_line(&m_out_tx_func, &m_config.m_out_tx_func, this); |
| 108 | devcb_resolve_read_line(&m_in_cts_func, &m_config.m_in_cts_func, this); |
| 109 | devcb_resolve_write_line(&m_out_rts_func, &m_config.m_out_rts_func, this); |
| 110 | devcb_resolve_read_line(&m_in_dcd_func, &m_config.m_in_dcd_func, this); |
| 111 | devcb_resolve_write_line(&m_out_irq_func, &m_config.m_out_irq_func, this); |
| 163 | 112 | |
| 164 | | int cts = devcb_call_read_line(&acia_p->in_cts_func); |
| 165 | | int dcd = devcb_call_read_line(&acia_p->in_dcd_func); |
| 113 | m_rx_clock = m_config.m_rx_clock; |
| 114 | m_tx_clock = m_config.m_tx_clock; |
| 115 | m_tx_counter = 0; |
| 116 | m_rx_counter = 0; |
| 117 | m_rx_timer = timer_alloc(&m_machine, receive_event_callback, (void *)this); |
| 118 | m_tx_timer = timer_alloc(&m_machine, transmit_event_callback, (void *)this); |
| 119 | m_first_reset = 1; |
| 120 | m_status_read = 0; |
| 121 | m_brk = 0; |
| 166 | 122 | |
| 167 | | acia_p->status = (cts << 3) | (dcd << 2) | ACIA6850_STATUS_TDRE; |
| 168 | | acia_p->tdr = 0; |
| 169 | | acia_p->rdr = 0; |
| 170 | | acia_p->tx_shift = 0; |
| 171 | | acia_p->rx_shift = 0; |
| 172 | | acia_p->tx_counter = 0; |
| 173 | | acia_p->rx_counter = 0; |
| 123 | timer_reset(m_rx_timer, attotime_never); |
| 124 | timer_reset(m_tx_timer, attotime_never); |
| 174 | 125 | |
| 126 | state_save_register_device_item(this, 0, m_ctrl); |
| 127 | state_save_register_device_item(this, 0, m_status); |
| 128 | state_save_register_device_item(this, 0, m_rx_clock); |
| 129 | state_save_register_device_item(this, 0, m_tx_clock); |
| 130 | state_save_register_device_item(this, 0, m_rx_counter); |
| 131 | state_save_register_device_item(this, 0, m_tx_counter); |
| 132 | state_save_register_device_item(this, 0, m_rx_shift); |
| 133 | state_save_register_device_item(this, 0, m_tx_shift); |
| 134 | state_save_register_device_item(this, 0, m_rdr); |
| 135 | state_save_register_device_item(this, 0, m_tdr); |
| 136 | state_save_register_device_item(this, 0, m_rx_bits); |
| 137 | state_save_register_device_item(this, 0, m_tx_bits); |
| 138 | state_save_register_device_item(this, 0, m_rx_parity); |
| 139 | state_save_register_device_item(this, 0, m_tx_parity); |
| 140 | state_save_register_device_item(this, 0, m_tx_int); |
| 141 | |
| 142 | state_save_register_device_item(this, 0, m_divide); |
| 143 | state_save_register_device_item(this, 0, m_overrun); |
| 144 | state_save_register_device_item(this, 0, m_reset); |
| 145 | state_save_register_device_item(this, 0, m_first_reset); |
| 146 | state_save_register_device_item(this, 0, m_rts); |
| 147 | state_save_register_device_item(this, 0, m_brk); |
| 148 | state_save_register_device_item(this, 0, m_status_read); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | //------------------------------------------------- |
| 153 | // device_reset - device-specific reset |
| 154 | //------------------------------------------------- |
| 155 | |
| 156 | void acia6850_device::device_reset() |
| 157 | { |
| 158 | int cts = devcb_call_read_line(&m_in_cts_func); |
| 159 | int dcd = devcb_call_read_line(&m_in_dcd_func); |
| 160 | |
| 161 | m_status = (cts << 3) | (dcd << 2) | ACIA6850_STATUS_TDRE; |
| 162 | m_tdr = 0; |
| 163 | m_rdr = 0; |
| 164 | m_tx_shift = 0; |
| 165 | m_rx_shift = 0; |
| 166 | m_tx_counter = 0; |
| 167 | m_rx_counter = 0; |
| 168 | |
| 175 | 169 | TXD(1); |
| 176 | | acia_p->overrun = 0; |
| 177 | | acia_p->status_read = 0; |
| 178 | | acia_p->brk = 0; |
| 170 | m_overrun = 0; |
| 171 | m_status_read = 0; |
| 172 | m_brk = 0; |
| 179 | 173 | |
| 180 | | acia_p->rx_state = START; |
| 181 | | acia_p->tx_state = START; |
| 182 | | acia_p->irq = 0; |
| 174 | m_rx_state = START; |
| 175 | m_tx_state = START; |
| 176 | m_irq = 0; |
| 183 | 177 | |
| 184 | | devcb_call_write_line(&acia_p->out_irq_func, 1); |
| 178 | devcb_call_write_line(&m_out_irq_func, 1); |
| 185 | 179 | |
| 186 | | if (acia_p->first_reset) |
| 180 | if (m_first_reset) |
| 187 | 181 | { |
| 188 | | acia_p->first_reset = 0; |
| 182 | m_first_reset = 0; |
| 189 | 183 | |
| 190 | 184 | RTS(1); |
| 191 | 185 | } |
| 192 | 186 | else |
| 193 | 187 | { |
| 194 | | RTS(acia_p->rts); |
| 188 | RTS(m_rts); |
| 195 | 189 | } |
| 196 | 190 | } |
| 197 | 191 | |
| 198 | 192 | |
| 199 | 193 | |
| 200 | 194 | /*------------------------------------------------- |
| 201 | | DEVICE_START( acia6850 ) |
| 202 | | -------------------------------------------------*/ |
| 203 | | |
| 204 | | static DEVICE_START( acia6850 ) |
| 205 | | { |
| 206 | | acia6850_t *acia_p = get_token(device); |
| 207 | | acia6850_interface *intf = get_interface(device); |
| 208 | | |
| 209 | | /* resolve callbacks */ |
| 210 | | devcb_resolve_read_line(&acia_p->in_rx_func, &intf->in_rx_func, device); |
| 211 | | devcb_resolve_write_line(&acia_p->out_tx_func, &intf->out_tx_func, device); |
| 212 | | devcb_resolve_read_line(&acia_p->in_cts_func, &intf->in_cts_func, device); |
| 213 | | devcb_resolve_write_line(&acia_p->out_rts_func, &intf->out_rts_func, device); |
| 214 | | devcb_resolve_read_line(&acia_p->in_dcd_func, &intf->in_dcd_func, device); |
| 215 | | devcb_resolve_write_line(&acia_p->out_irq_func, &intf->out_irq_func, device); |
| 216 | | |
| 217 | | acia_p->rx_clock = intf->rx_clock; |
| 218 | | acia_p->tx_clock = intf->tx_clock; |
| 219 | | acia_p->tx_counter = 0; |
| 220 | | acia_p->rx_counter = 0; |
| 221 | | acia_p->rx_timer = timer_alloc(device->machine, receive_event, (void *) device); |
| 222 | | acia_p->tx_timer = timer_alloc(device->machine, transmit_event, (void *) device); |
| 223 | | acia_p->first_reset = 1; |
| 224 | | acia_p->status_read = 0; |
| 225 | | acia_p->brk = 0; |
| 226 | | |
| 227 | | timer_reset(acia_p->rx_timer, attotime_never); |
| 228 | | timer_reset(acia_p->tx_timer, attotime_never); |
| 229 | | |
| 230 | | state_save_register_device_item(device, 0, acia_p->ctrl); |
| 231 | | state_save_register_device_item(device, 0, acia_p->status); |
| 232 | | state_save_register_device_item(device, 0, acia_p->rx_clock); |
| 233 | | state_save_register_device_item(device, 0, acia_p->tx_clock); |
| 234 | | state_save_register_device_item(device, 0, acia_p->rx_counter); |
| 235 | | state_save_register_device_item(device, 0, acia_p->tx_counter); |
| 236 | | state_save_register_device_item(device, 0, acia_p->rx_shift); |
| 237 | | state_save_register_device_item(device, 0, acia_p->tx_shift); |
| 238 | | state_save_register_device_item(device, 0, acia_p->rdr); |
| 239 | | state_save_register_device_item(device, 0, acia_p->tdr); |
| 240 | | state_save_register_device_item(device, 0, acia_p->rx_bits); |
| 241 | | state_save_register_device_item(device, 0, acia_p->tx_bits); |
| 242 | | state_save_register_device_item(device, 0, acia_p->rx_parity); |
| 243 | | state_save_register_device_item(device, 0, acia_p->tx_parity); |
| 244 | | state_save_register_device_item(device, 0, acia_p->tx_int); |
| 245 | | |
| 246 | | state_save_register_device_item(device, 0, acia_p->divide); |
| 247 | | state_save_register_device_item(device, 0, acia_p->overrun); |
| 248 | | state_save_register_device_item(device, 0, acia_p->reset); |
| 249 | | state_save_register_device_item(device, 0, acia_p->first_reset); |
| 250 | | state_save_register_device_item(device, 0, acia_p->rts); |
| 251 | | state_save_register_device_item(device, 0, acia_p->brk); |
| 252 | | state_save_register_device_item(device, 0, acia_p->status_read); |
| 253 | | } |
| 254 | | |
| 255 | | |
| 256 | | /*------------------------------------------------- |
| 257 | 195 | acia6850_stat_r - Read Status Register |
| 258 | 196 | -------------------------------------------------*/ |
| 259 | 197 | |
| 260 | | READ8_DEVICE_HANDLER( acia6850_stat_r ) |
| 198 | READ8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_stat_r) |
| 261 | 199 | { |
| 262 | 200 | UINT8 status; |
| 263 | 201 | |
| 264 | | acia6850_t *acia_p = get_token(device); |
| 202 | m_status_read = 1; |
| 203 | status = m_status; |
| 265 | 204 | |
| 266 | | acia_p->status_read = 1; |
| 267 | | status = acia_p->status; |
| 268 | | |
| 269 | 205 | if (status & ACIA6850_STATUS_CTS) |
| 206 | { |
| 270 | 207 | status &= ~ACIA6850_STATUS_TDRE; |
| 208 | } |
| 271 | 209 | |
| 272 | 210 | return status; |
| 273 | 211 | } |
| r8910 | r8911 | |
| 277 | 215 | acia6850_ctrl_w - Write Control Register |
| 278 | 216 | -------------------------------------------------*/ |
| 279 | 217 | |
| 280 | | WRITE8_DEVICE_HANDLER( acia6850_ctrl_w ) |
| 218 | WRITE8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_ctrl_w ) |
| 281 | 219 | { |
| 282 | | acia6850_t *acia_p = get_token(device); |
| 283 | | |
| 284 | 220 | int wordsel; |
| 285 | 221 | int divide; |
| 286 | 222 | |
| r8910 | r8911 | |
| 290 | 226 | |
| 291 | 227 | if (divide == 3) |
| 292 | 228 | { |
| 293 | | acia_p->reset = 1; |
| 294 | | device->reset(); |
| 229 | m_reset = 1; |
| 230 | device_reset(); |
| 295 | 231 | } |
| 296 | 232 | else |
| 297 | 233 | { |
| 298 | | acia_p->reset = 0; |
| 299 | | acia_p->divide = ACIA6850_DIVIDE[divide]; |
| 234 | m_reset = 0; |
| 235 | m_divide = ACIA6850_DIVIDE[divide]; |
| 300 | 236 | } |
| 301 | 237 | |
| 302 | 238 | // Word Select Bits |
| 303 | 239 | |
| 304 | 240 | wordsel = (data & CR4_2) >> 2; |
| 305 | 241 | |
| 306 | | acia_p->bits = ACIA6850_WORD[wordsel][0]; |
| 307 | | acia_p->parity = (parity_type)ACIA6850_WORD[wordsel][1]; |
| 308 | | acia_p->stopbits = ACIA6850_WORD[wordsel][2]; |
| 242 | m_bits = ACIA6850_WORD[wordsel][0]; |
| 243 | m_parity = (parity_type)ACIA6850_WORD[wordsel][1]; |
| 244 | m_stopbits = ACIA6850_WORD[wordsel][2]; |
| 309 | 245 | |
| 310 | 246 | // Transmitter Control Bits |
| 311 | 247 | |
| 312 | 248 | switch ((data & CR6_5) >> 5) |
| 313 | 249 | { |
| 314 | 250 | case 0: |
| 315 | | acia_p->rts = 0; |
| 316 | | RTS(acia_p->rts); |
| 251 | m_rts = 0; |
| 252 | RTS(m_rts); |
| 317 | 253 | |
| 318 | | acia_p->tx_int = 0; |
| 319 | | acia_p->brk = 0; |
| 254 | m_tx_int = 0; |
| 255 | m_brk = 0; |
| 320 | 256 | break; |
| 321 | 257 | |
| 322 | 258 | case 1: |
| 323 | | acia_p->rts = 0; |
| 324 | | RTS(acia_p->rts); |
| 259 | m_rts = 0; |
| 260 | RTS(m_rts); |
| 325 | 261 | |
| 326 | | acia_p->tx_int = 1; |
| 327 | | acia_p->brk = 0; |
| 262 | m_tx_int = 1; |
| 263 | m_brk = 0; |
| 328 | 264 | break; |
| 329 | 265 | |
| 330 | 266 | case 2: |
| 331 | | acia_p->rts = 1; |
| 332 | | RTS(acia_p->rts); |
| 267 | m_rts = 1; |
| 268 | RTS(m_rts); |
| 333 | 269 | |
| 334 | | acia_p->tx_int = 0; |
| 335 | | acia_p->brk = 0; |
| 270 | m_tx_int = 0; |
| 271 | m_brk = 0; |
| 336 | 272 | break; |
| 337 | 273 | |
| 338 | 274 | case 3: |
| 339 | | acia_p->rts = 0; |
| 340 | | RTS(acia_p->rts); |
| 275 | m_rts = 0; |
| 276 | RTS(m_rts); |
| 341 | 277 | |
| 342 | | acia_p->tx_int = 0; |
| 343 | | acia_p->brk = 1; |
| 278 | m_tx_int = 0; |
| 279 | m_brk = 1; |
| 344 | 280 | break; |
| 345 | 281 | } |
| 346 | 282 | |
| 347 | | acia6850_check_interrupts(device); |
| 283 | check_interrupts(); |
| 348 | 284 | |
| 349 | 285 | // After writing the word type, set the rx/tx clocks (provided the divide values have changed) |
| 350 | 286 | |
| 351 | | if ((acia_p->ctrl ^ data) & CR1_0) |
| 287 | if ((m_ctrl ^ data) & CR1_0) |
| 352 | 288 | { |
| 353 | | if (!acia_p->reset) |
| 289 | if (!m_reset) |
| 354 | 290 | { |
| 355 | | if (acia_p->rx_clock) |
| 291 | if (m_rx_clock) |
| 356 | 292 | { |
| 357 | | attotime rx_period = attotime_mul(ATTOTIME_IN_HZ(acia_p->rx_clock), acia_p->divide); |
| 358 | | timer_adjust_periodic(acia_p->rx_timer, rx_period, 0, rx_period); |
| 293 | attotime rx_period = attotime_mul(ATTOTIME_IN_HZ(m_rx_clock), m_divide); |
| 294 | timer_adjust_periodic(m_rx_timer, rx_period, 0, rx_period); |
| 359 | 295 | } |
| 360 | 296 | |
| 361 | | if (acia_p->tx_clock) |
| 297 | if (m_tx_clock) |
| 362 | 298 | { |
| 363 | | attotime tx_period = attotime_mul(ATTOTIME_IN_HZ(acia_p->tx_clock), acia_p->divide); |
| 364 | | timer_adjust_periodic(acia_p->tx_timer, tx_period, 0, tx_period); |
| 299 | attotime tx_period = attotime_mul(ATTOTIME_IN_HZ(m_tx_clock), m_divide); |
| 300 | timer_adjust_periodic(m_tx_timer, tx_period, 0, tx_period); |
| 365 | 301 | } |
| 366 | 302 | } |
| 367 | 303 | } |
| 368 | | acia_p->ctrl = data; |
| 304 | m_ctrl = data; |
| 369 | 305 | } |
| 370 | 306 | |
| 371 | 307 | |
| 372 | 308 | /*------------------------------------------------- |
| 373 | | acia6850_check_interrupts |
| 309 | check_interrupts |
| 374 | 310 | -------------------------------------------------*/ |
| 375 | 311 | |
| 376 | | static void acia6850_check_interrupts(running_device *device) |
| 312 | void acia6850_device::check_interrupts() |
| 377 | 313 | { |
| 378 | | acia6850_t *acia_p = get_token(device); |
| 314 | int irq = (m_tx_int && (m_status & ACIA6850_STATUS_TDRE) && (~m_status & ACIA6850_STATUS_CTS)) || |
| 315 | ((m_ctrl & 0x80) && ((m_status & (ACIA6850_STATUS_RDRF|ACIA6850_STATUS_DCD)) || m_overrun)); |
| 379 | 316 | |
| 380 | | int irq = (acia_p->tx_int && (acia_p->status & ACIA6850_STATUS_TDRE) && (~acia_p->status & ACIA6850_STATUS_CTS)) || |
| 381 | | ((acia_p->ctrl & 0x80) && ((acia_p->status & (ACIA6850_STATUS_RDRF|ACIA6850_STATUS_DCD)) || acia_p->overrun)); |
| 382 | | |
| 383 | | if (irq != acia_p->irq) |
| 317 | if (irq != m_irq) |
| 384 | 318 | { |
| 385 | | acia_p->irq = irq; |
| 319 | m_irq = irq; |
| 386 | 320 | |
| 387 | 321 | if (irq) |
| 388 | 322 | { |
| 389 | | acia_p->status |= ACIA6850_STATUS_IRQ; |
| 390 | | devcb_call_write_line(&acia_p->out_irq_func, 0); |
| 323 | m_status |= ACIA6850_STATUS_IRQ; |
| 324 | devcb_call_write_line(&m_out_irq_func, 0); |
| 391 | 325 | } |
| 392 | 326 | else |
| 393 | 327 | { |
| 394 | | acia_p->status &= ~ACIA6850_STATUS_IRQ; |
| 395 | | devcb_call_write_line(&acia_p->out_irq_func, 1); |
| 328 | m_status &= ~ACIA6850_STATUS_IRQ; |
| 329 | devcb_call_write_line(&m_out_irq_func, 1); |
| 396 | 330 | } |
| 397 | 331 | } |
| 398 | 332 | } |
| r8910 | r8911 | |
| 402 | 336 | acia6850_data_w - Write transmit register |
| 403 | 337 | -------------------------------------------------*/ |
| 404 | 338 | |
| 405 | | WRITE8_DEVICE_HANDLER( acia6850_data_w ) |
| 339 | WRITE8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_data_w) |
| 406 | 340 | { |
| 407 | | acia6850_t *acia_p = get_token(device); |
| 408 | | |
| 409 | | if (!acia_p->reset) |
| 341 | if (!m_reset) |
| 410 | 342 | { |
| 411 | | acia_p->tdr = data; |
| 412 | | acia_p->status &= ~ACIA6850_STATUS_TDRE; |
| 413 | | acia6850_check_interrupts(device); |
| 343 | m_tdr = data; |
| 344 | m_status &= ~ACIA6850_STATUS_TDRE; |
| 345 | check_interrupts(); |
| 414 | 346 | } |
| 415 | 347 | else |
| 416 | 348 | { |
| 417 | | logerror("%s:ACIA %p: Data write while in reset!\n", cpuexec_describe_context(device->machine), device); |
| 349 | logerror("%s:ACIA %p: Data write while in reset!\n", cpuexec_describe_context(&m_machine), this); |
| 418 | 350 | } |
| 419 | 351 | } |
| 420 | 352 | |
| r8910 | r8911 | |
| 423 | 355 | acia6850_data_r - Read character |
| 424 | 356 | -------------------------------------------------*/ |
| 425 | 357 | |
| 426 | | READ8_DEVICE_HANDLER( acia6850_data_r ) |
| 358 | READ8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_data_r) |
| 427 | 359 | { |
| 428 | | acia6850_t *acia_p = get_token(device); |
| 360 | m_status &= ~(ACIA6850_STATUS_RDRF | ACIA6850_STATUS_IRQ | ACIA6850_STATUS_PE); |
| 429 | 361 | |
| 430 | | acia_p->status &= ~(ACIA6850_STATUS_RDRF | ACIA6850_STATUS_IRQ | ACIA6850_STATUS_PE); |
| 431 | | |
| 432 | | if (acia_p->status_read) |
| 362 | if (m_status_read) |
| 433 | 363 | { |
| 434 | | int dcd = devcb_call_read_line(&acia_p->in_dcd_func); |
| 364 | int dcd = devcb_call_read_line(&m_in_dcd_func); |
| 435 | 365 | |
| 436 | | acia_p->status_read = 0; |
| 437 | | acia_p->status &= ~(ACIA6850_STATUS_OVRN | ACIA6850_STATUS_DCD); |
| 366 | m_status_read = 0; |
| 367 | m_status &= ~(ACIA6850_STATUS_OVRN | ACIA6850_STATUS_DCD); |
| 438 | 368 | |
| 439 | 369 | if (dcd) |
| 440 | 370 | { |
| 441 | | acia_p->status |= ACIA6850_STATUS_DCD; |
| 371 | m_status |= ACIA6850_STATUS_DCD; |
| 442 | 372 | } |
| 443 | 373 | } |
| 444 | 374 | |
| 445 | | if (acia_p->overrun == 1) |
| 375 | if (m_overrun == 1) |
| 446 | 376 | { |
| 447 | | acia_p->status |= ACIA6850_STATUS_OVRN; |
| 448 | | acia_p->overrun = 0; |
| 377 | m_status |= ACIA6850_STATUS_OVRN; |
| 378 | m_overrun = 0; |
| 449 | 379 | } |
| 450 | 380 | |
| 451 | | acia6850_check_interrupts(device); |
| 381 | check_interrupts(); |
| 452 | 382 | |
| 453 | | return acia_p->rdr; |
| 383 | return m_rdr; |
| 454 | 384 | } |
| 455 | 385 | |
| 456 | 386 | |
| r8910 | r8911 | |
| 458 | 388 | tx_tick - Transmit a bit |
| 459 | 389 | -------------------------------------------------*/ |
| 460 | 390 | |
| 461 | | static void tx_tick(running_device *device) |
| 391 | void acia6850_device::tx_tick() |
| 462 | 392 | { |
| 463 | | acia6850_t *acia_p = get_token(device); |
| 464 | | |
| 465 | | switch (acia_p->tx_state) |
| 393 | switch (m_tx_state) |
| 466 | 394 | { |
| 467 | 395 | case START: |
| 468 | 396 | { |
| 469 | | if (acia_p->brk) |
| 397 | if (m_brk) |
| 470 | 398 | { |
| 471 | 399 | // transmit break |
| 472 | 400 | |
| r8910 | r8911 | |
| 474 | 402 | } |
| 475 | 403 | else |
| 476 | 404 | { |
| 477 | | int _cts = devcb_call_read_line(&acia_p->in_cts_func); |
| 405 | int _cts = devcb_call_read_line(&m_in_cts_func); |
| 478 | 406 | |
| 479 | 407 | if (_cts) |
| 480 | | acia_p->status |= ACIA6850_STATUS_CTS; |
| 408 | { |
| 409 | m_status |= ACIA6850_STATUS_CTS; |
| 410 | } |
| 481 | 411 | else |
| 482 | | acia_p->status &= ~ACIA6850_STATUS_CTS; |
| 412 | { |
| 413 | m_status &= ~ACIA6850_STATUS_CTS; |
| 414 | } |
| 483 | 415 | |
| 484 | | acia6850_check_interrupts(device); |
| 416 | check_interrupts(); |
| 485 | 417 | |
| 486 | | if (acia_p->status & ACIA6850_STATUS_TDRE) |
| 418 | if (m_status & ACIA6850_STATUS_TDRE) |
| 487 | 419 | { |
| 488 | 420 | // transmitter idle |
| 489 | 421 | TXD(1); |
| r8910 | r8911 | |
| 492 | 424 | { |
| 493 | 425 | // transmit character |
| 494 | 426 | |
| 495 | | //logerror("ACIA6850 #%u: TX DATA %x\n", which, acia_p->tdr); |
| 427 | //logerror("ACIA6850 #%u: TX DATA %x\n", which, m_tdr); |
| 496 | 428 | //logerror("ACIA6850 #%u: TX START BIT\n", which); |
| 497 | 429 | |
| 498 | 430 | TXD(0); |
| 499 | 431 | |
| 500 | | acia_p->tx_bits = acia_p->bits; |
| 501 | | acia_p->tx_shift = acia_p->tdr; |
| 502 | | acia_p->tx_parity = 0; |
| 503 | | acia_p->tx_state = DATA; |
| 432 | m_tx_bits = m_bits; |
| 433 | m_tx_shift = m_tdr; |
| 434 | m_tx_parity = 0; |
| 435 | m_tx_state = DATA; |
| 504 | 436 | } |
| 505 | 437 | } |
| 506 | 438 | break; |
| 507 | 439 | } |
| 508 | 440 | case DATA: |
| 509 | 441 | { |
| 510 | | int val = acia_p->tx_shift & 1; |
| 442 | int val = m_tx_shift & 1; |
| 511 | 443 | //logerror("ACIA6850 #%u: TX DATA BIT %x\n", which, val); |
| 512 | 444 | |
| 513 | 445 | TXD(val); |
| 514 | | acia_p->tx_parity ^= val; |
| 515 | | acia_p->tx_shift >>= 1; |
| 446 | m_tx_parity ^= val; |
| 447 | m_tx_shift >>= 1; |
| 516 | 448 | |
| 517 | | if (--(acia_p->tx_bits) == 0) |
| 518 | | acia_p->tx_state = (acia_p->parity == NONE) ? STOP : PARITY; |
| 449 | if (--(m_tx_bits) == 0) |
| 450 | { |
| 451 | m_tx_state = (m_parity == NONE) ? STOP : PARITY; |
| 452 | } |
| 519 | 453 | |
| 520 | 454 | break; |
| 521 | 455 | } |
| 522 | 456 | case PARITY: |
| 523 | 457 | { |
| 524 | | if (acia_p->parity == EVEN) |
| 525 | | TXD((acia_p->tx_parity & 1) ? 1 : 0); |
| 458 | if (m_parity == EVEN) |
| 459 | { |
| 460 | TXD((m_tx_parity & 1) ? 1 : 0); |
| 461 | } |
| 526 | 462 | else |
| 527 | | TXD((acia_p->tx_parity & 1) ? 0 : 1); |
| 463 | { |
| 464 | TXD((m_tx_parity & 1) ? 0 : 1); |
| 465 | } |
| 528 | 466 | |
| 529 | | //logerror("ACIA6850 #%u: TX PARITY BIT %x\n", which, *acia_p->tx_pin); |
| 530 | | acia_p->tx_state = STOP; |
| 467 | //logerror("ACIA6850 #%u: TX PARITY BIT %x\n", which, *m_tx_pin); |
| 468 | m_tx_state = STOP; |
| 531 | 469 | break; |
| 532 | 470 | } |
| 533 | 471 | case STOP: |
| r8910 | r8911 | |
| 535 | 473 | //logerror("ACIA6850 #%u: TX STOP BIT\n", which); |
| 536 | 474 | TXD(1); |
| 537 | 475 | |
| 538 | | if (acia_p->stopbits == 1) |
| 476 | if (m_stopbits == 1) |
| 539 | 477 | { |
| 540 | | acia_p->tx_state = START; |
| 541 | | acia_p->status |= ACIA6850_STATUS_TDRE; |
| 478 | m_tx_state = START; |
| 479 | m_status |= ACIA6850_STATUS_TDRE; |
| 542 | 480 | } |
| 543 | 481 | else |
| 544 | 482 | { |
| 545 | | acia_p->tx_state = STOP2; |
| 483 | m_tx_state = STOP2; |
| 546 | 484 | } |
| 547 | 485 | break; |
| 548 | 486 | } |
| r8910 | r8911 | |
| 550 | 488 | { |
| 551 | 489 | //logerror("ACIA6850 #%u: TX STOP BIT\n", which); |
| 552 | 490 | TXD(1); |
| 553 | | acia_p->tx_state = START; |
| 554 | | acia_p->status |= ACIA6850_STATUS_TDRE; |
| 491 | m_tx_state = START; |
| 492 | m_status |= ACIA6850_STATUS_TDRE; |
| 555 | 493 | break; |
| 556 | 494 | } |
| 557 | 495 | } |
| r8910 | r8911 | |
| 559 | 497 | |
| 560 | 498 | |
| 561 | 499 | /*------------------------------------------------- |
| 562 | | TIMER_CALLBACK( transmit_event ) |
| 500 | transmit_event |
| 563 | 501 | -------------------------------------------------*/ |
| 564 | 502 | |
| 565 | | static TIMER_CALLBACK( transmit_event ) |
| 503 | TIMER_CALLBACK( acia6850_device::transmit_event_callback ) { reinterpret_cast<acia6850_device *>(ptr)->transmit_event(); } |
| 504 | |
| 505 | void acia6850_device::transmit_event() |
| 566 | 506 | { |
| 567 | | running_device *device = (running_device *)ptr; |
| 568 | | acia6850_t *acia_p = get_token(device); |
| 569 | | tx_tick(device); |
| 570 | | acia_p->tx_counter = 0; |
| 507 | tx_tick(); |
| 508 | m_tx_counter = 0; |
| 571 | 509 | } |
| 572 | 510 | |
| 573 | 511 | |
| 574 | 512 | /*------------------------------------------------- |
| 575 | | acia6850_tx_clock_in - As above, but using the tx pin |
| 513 | tx_clock_in - As above, but using the tx pin |
| 576 | 514 | -------------------------------------------------*/ |
| 577 | 515 | |
| 578 | | void acia6850_tx_clock_in(running_device *device) |
| 516 | void acia6850_tx_clock_in(running_device *device) { downcast<acia6850_device*>(device)->tx_clock_in(); } |
| 517 | |
| 518 | void acia6850_device::tx_clock_in() |
| 579 | 519 | { |
| 580 | | acia6850_t *acia_p = get_token(device); |
| 520 | int _cts = devcb_call_read_line(&m_in_cts_func); |
| 581 | 521 | |
| 582 | | int _cts = devcb_call_read_line(&acia_p->in_cts_func); |
| 583 | | |
| 584 | 522 | if (_cts) |
| 585 | | acia_p->status |= ACIA6850_STATUS_CTS; |
| 523 | { |
| 524 | m_status |= ACIA6850_STATUS_CTS; |
| 525 | } |
| 586 | 526 | else |
| 587 | | acia_p->status &= ~ACIA6850_STATUS_CTS; |
| 527 | { |
| 528 | m_status &= ~ACIA6850_STATUS_CTS; |
| 529 | } |
| 588 | 530 | |
| 589 | | acia_p->tx_counter ++; |
| 531 | m_tx_counter ++; |
| 590 | 532 | |
| 591 | | if ( acia_p->tx_counter > acia_p->divide-1) |
| 533 | if ( m_tx_counter > m_divide - 1) |
| 592 | 534 | { |
| 593 | | tx_tick(device); |
| 594 | | acia_p->tx_counter = 0; |
| 535 | tx_tick(); |
| 536 | m_tx_counter = 0; |
| 595 | 537 | } |
| 596 | 538 | |
| 597 | 539 | } |
| r8910 | r8911 | |
| 601 | 543 | rx_tick - Receive a bit |
| 602 | 544 | -------------------------------------------------*/ |
| 603 | 545 | |
| 604 | | static void rx_tick(running_device *device) |
| 546 | void acia6850_device::rx_tick() |
| 605 | 547 | { |
| 606 | | acia6850_t *acia_p = get_token(device); |
| 548 | int dcd = devcb_call_read_line(&m_in_dcd_func); |
| 607 | 549 | |
| 608 | | int dcd = devcb_call_read_line(&acia_p->in_dcd_func); |
| 609 | | |
| 610 | 550 | if (dcd) |
| 611 | 551 | { |
| 612 | | acia_p->status |= ACIA6850_STATUS_DCD; |
| 613 | | acia6850_check_interrupts(device); |
| 552 | m_status |= ACIA6850_STATUS_DCD; |
| 553 | check_interrupts(); |
| 614 | 554 | } |
| 615 | | else if ((acia_p->status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD) |
| 555 | else if ((m_status & (ACIA6850_STATUS_DCD | ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD) |
| 616 | 556 | { |
| 617 | | acia_p->status &= ~ACIA6850_STATUS_DCD; |
| 557 | m_status &= ~ACIA6850_STATUS_DCD; |
| 618 | 558 | } |
| 619 | 559 | |
| 620 | | if (acia_p->status & ACIA6850_STATUS_DCD) |
| 560 | if (m_status & ACIA6850_STATUS_DCD) |
| 621 | 561 | { |
| 622 | | acia_p->rx_state = START; |
| 562 | m_rx_state = START; |
| 623 | 563 | } |
| 624 | 564 | else |
| 625 | 565 | { |
| 626 | | int rxd = devcb_call_read_line(&acia_p->in_rx_func); |
| 566 | int rxd = devcb_call_read_line(&m_in_rx_func); |
| 627 | 567 | |
| 628 | | switch (acia_p->rx_state) |
| 568 | switch (m_rx_state) |
| 629 | 569 | { |
| 630 | 570 | case START: |
| 631 | 571 | { |
| 632 | 572 | if (rxd == 0) |
| 633 | 573 | { |
| 634 | 574 | //logerror("ACIA6850 #%u: RX START BIT\n", which); |
| 635 | | acia_p->rx_shift = 0; |
| 636 | | acia_p->rx_parity = 0; |
| 637 | | acia_p->rx_bits = acia_p->bits; |
| 638 | | acia_p->rx_state = DATA; |
| 575 | m_rx_shift = 0; |
| 576 | m_rx_parity = 0; |
| 577 | m_rx_bits = m_bits; |
| 578 | m_rx_state = DATA; |
| 639 | 579 | } |
| 640 | 580 | break; |
| 641 | 581 | } |
| 642 | 582 | case DATA: |
| 643 | 583 | { |
| 644 | 584 | //logerror("ACIA6850 #%u: RX DATA BIT %x\n", which, rxd); |
| 645 | | acia_p->rx_shift |= rxd ? 0x80 : 0; |
| 646 | | acia_p->rx_parity ^= rxd; |
| 585 | m_rx_shift |= rxd ? 0x80 : 0; |
| 586 | m_rx_parity ^= rxd; |
| 647 | 587 | |
| 648 | | if (--acia_p->rx_bits == 0) |
| 588 | if (--m_rx_bits == 0) |
| 649 | 589 | { |
| 650 | | if (acia_p->status & ACIA6850_STATUS_RDRF) |
| 590 | if (m_status & ACIA6850_STATUS_RDRF) |
| 651 | 591 | { |
| 652 | | acia_p->overrun = 1; |
| 653 | | acia6850_check_interrupts(device); |
| 592 | m_overrun = 1; |
| 593 | check_interrupts(); |
| 654 | 594 | } |
| 655 | 595 | |
| 656 | | acia_p->rx_state = acia_p->parity == NONE ? STOP : PARITY; |
| 596 | m_rx_state = m_parity == NONE ? STOP : PARITY; |
| 657 | 597 | } |
| 658 | 598 | else |
| 659 | 599 | { |
| 660 | | acia_p->rx_shift >>= 1; |
| 600 | m_rx_shift >>= 1; |
| 661 | 601 | } |
| 662 | 602 | break; |
| 663 | 603 | } |
| 664 | 604 | case PARITY: |
| 665 | 605 | { |
| 666 | 606 | //logerror("ACIA6850 #%u: RX PARITY BIT %x\n", which, rxd); |
| 667 | | acia_p->rx_parity ^= rxd; |
| 607 | m_rx_parity ^= rxd; |
| 668 | 608 | |
| 669 | | if (acia_p->parity == EVEN) |
| 609 | if (m_parity == EVEN) |
| 670 | 610 | { |
| 671 | | if (acia_p->rx_parity) |
| 611 | if (m_rx_parity) |
| 672 | 612 | { |
| 673 | | acia_p->status |= ACIA6850_STATUS_PE; |
| 613 | m_status |= ACIA6850_STATUS_PE; |
| 674 | 614 | } |
| 675 | 615 | } |
| 676 | 616 | else |
| 677 | 617 | { |
| 678 | | if (!acia_p->rx_parity) |
| 618 | if (!m_rx_parity) |
| 679 | 619 | { |
| 680 | | acia_p->status |= ACIA6850_STATUS_PE; |
| 620 | m_status |= ACIA6850_STATUS_PE; |
| 681 | 621 | } |
| 682 | 622 | } |
| 683 | 623 | |
| 684 | | acia_p->rx_state = STOP; |
| 624 | m_rx_state = STOP; |
| 685 | 625 | break; |
| 686 | 626 | } |
| 687 | 627 | case STOP: |
| r8910 | r8911 | |
| 689 | 629 | if (rxd == 1) |
| 690 | 630 | { |
| 691 | 631 | //logerror("ACIA6850 #%u: RX STOP BIT\n", which); |
| 692 | | if (acia_p->stopbits == 1) |
| 632 | if (m_stopbits == 1) |
| 693 | 633 | { |
| 694 | | acia_p->status &= ~ACIA6850_STATUS_FE; |
| 634 | m_status &= ~ACIA6850_STATUS_FE; |
| 695 | 635 | |
| 696 | | if (!(acia_p->status & ACIA6850_STATUS_RDRF)) |
| 636 | if (!(m_status & ACIA6850_STATUS_RDRF)) |
| 697 | 637 | { |
| 698 | | //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift); |
| 699 | | acia_p->rdr = acia_p->rx_shift; |
| 700 | | acia_p->status |= ACIA6850_STATUS_RDRF; |
| 701 | | acia6850_check_interrupts(device); |
| 638 | //logerror("ACIA6850 #%u: RX DATA %x\n", which, m_rx_shift); |
| 639 | m_rdr = m_rx_shift; |
| 640 | m_status |= ACIA6850_STATUS_RDRF; |
| 641 | check_interrupts(); |
| 702 | 642 | } |
| 703 | 643 | |
| 704 | | acia_p->rx_state = START; |
| 644 | m_rx_state = START; |
| 705 | 645 | } |
| 706 | 646 | else |
| 707 | 647 | { |
| 708 | | acia_p->rx_state = STOP2; |
| 648 | m_rx_state = STOP2; |
| 709 | 649 | } |
| 710 | 650 | } |
| 711 | 651 | else |
| 712 | 652 | { |
| 713 | | acia_p->status |= ACIA6850_STATUS_FE; |
| 714 | | acia_p->rx_state = START; |
| 653 | m_status |= ACIA6850_STATUS_FE; |
| 654 | m_rx_state = START; |
| 715 | 655 | } |
| 716 | 656 | break; |
| 717 | 657 | } |
| r8910 | r8911 | |
| 720 | 660 | if (rxd == 1) |
| 721 | 661 | { |
| 722 | 662 | //logerror("ACIA6850 #%u: RX STOP BIT\n", which); |
| 723 | | acia_p->status &= ~ACIA6850_STATUS_FE; |
| 663 | m_status &= ~ACIA6850_STATUS_FE; |
| 724 | 664 | |
| 725 | | if (!(acia_p->status & ACIA6850_STATUS_RDRF)) |
| 665 | if (!(m_status & ACIA6850_STATUS_RDRF)) |
| 726 | 666 | { |
| 727 | | //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift); |
| 728 | | acia_p->rdr = acia_p->rx_shift; |
| 729 | | acia_p->status |= ACIA6850_STATUS_RDRF; |
| 730 | | acia6850_check_interrupts(device); |
| 667 | //logerror("ACIA6850 #%u: RX DATA %x\n", which, m_rx_shift); |
| 668 | m_rdr = m_rx_shift; |
| 669 | m_status |= ACIA6850_STATUS_RDRF; |
| 670 | check_interrupts(); |
| 731 | 671 | } |
| 732 | 672 | |
| 733 | | acia_p->rx_state = START; |
| 673 | m_rx_state = START; |
| 734 | 674 | } |
| 735 | 675 | else |
| 736 | 676 | { |
| 737 | | acia_p->status |= ACIA6850_STATUS_FE; |
| 738 | | acia_p->rx_state = START; |
| 677 | m_status |= ACIA6850_STATUS_FE; |
| 678 | m_rx_state = START; |
| 739 | 679 | } |
| 740 | 680 | break; |
| 741 | 681 | } |
| r8910 | r8911 | |
| 745 | 685 | |
| 746 | 686 | |
| 747 | 687 | /*------------------------------------------------- |
| 748 | | TIMER_CALLBACK( receive_event ) - Called on |
| 749 | | receive timer event |
| 688 | TIMER_CALLBACK( receive_event_callback ) - |
| 689 | Called on receive timer event |
| 750 | 690 | -------------------------------------------------*/ |
| 751 | 691 | |
| 752 | | static TIMER_CALLBACK( receive_event ) |
| 692 | TIMER_CALLBACK( acia6850_device::receive_event_callback ) { reinterpret_cast<acia6850_device *>(ptr)->receive_event(); } |
| 693 | |
| 694 | void acia6850_device::receive_event() |
| 753 | 695 | { |
| 754 | | running_device *device = (running_device *)ptr; |
| 755 | | acia6850_t *acia_p = get_token(device); |
| 756 | | rx_tick(device); |
| 757 | | acia_p->rx_counter = 0; |
| 696 | rx_tick(); |
| 697 | m_rx_counter = 0; |
| 758 | 698 | } |
| 759 | 699 | |
| 760 | 700 | |
| 761 | 701 | /*------------------------------------------------- |
| 762 | | acia6850_rx_clock_in - As above, but using the rx pin |
| 702 | rx_clock_in - As above, but using the rx pin |
| 763 | 703 | -------------------------------------------------*/ |
| 764 | 704 | |
| 765 | | void acia6850_rx_clock_in(running_device *device) |
| 705 | void acia6850_rx_clock_in(running_device *device) { downcast<acia6850_device*>(device)->rx_clock_in(); } |
| 706 | |
| 707 | void acia6850_device::rx_clock_in() |
| 766 | 708 | { |
| 767 | | acia6850_t *acia_p = get_token(device); |
| 709 | int dcd = devcb_call_read_line(&m_in_dcd_func); |
| 768 | 710 | |
| 769 | | int dcd = devcb_call_read_line(&acia_p->in_dcd_func); |
| 770 | | |
| 771 | 711 | if (dcd) |
| 772 | 712 | { |
| 773 | | acia_p->status |= ACIA6850_STATUS_DCD; |
| 774 | | acia6850_check_interrupts(device); |
| 713 | m_status |= ACIA6850_STATUS_DCD; |
| 714 | check_interrupts(); |
| 775 | 715 | } |
| 776 | | else if ((acia_p->status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD) |
| 716 | else if ((m_status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD) |
| 777 | 717 | { |
| 778 | | acia_p->status &= ~ACIA6850_STATUS_DCD; |
| 718 | m_status &= ~ACIA6850_STATUS_DCD; |
| 779 | 719 | } |
| 780 | 720 | |
| 781 | | acia_p->rx_counter ++; |
| 721 | m_rx_counter ++; |
| 782 | 722 | |
| 783 | | if ( acia_p->rx_counter > acia_p->divide-1) |
| 723 | if ( m_rx_counter > m_divide - 1) |
| 784 | 724 | { |
| 785 | | rx_tick(device); |
| 786 | | acia_p->rx_counter = 0; |
| 725 | rx_tick(); |
| 726 | m_rx_counter = 0; |
| 787 | 727 | } |
| 788 | 728 | } |
| 789 | 729 | |
| r8910 | r8911 | |
| 795 | 735 | |
| 796 | 736 | void acia6850_set_rx_clock(running_device *device, int clock) |
| 797 | 737 | { |
| 798 | | acia6850_t *acia_p = get_token(device); |
| 799 | | acia_p->rx_clock = clock; |
| 738 | downcast<acia6850_device*>(device)->set_rx_clock(clock); |
| 800 | 739 | } |
| 801 | 740 | |
| 802 | 741 | |
| r8910 | r8911 | |
| 807 | 746 | |
| 808 | 747 | void acia6850_set_tx_clock(running_device *device, int clock) |
| 809 | 748 | { |
| 810 | | acia6850_t *acia_p = get_token(device); |
| 811 | | acia_p->tx_clock = clock; |
| 749 | downcast<acia6850_device*>(device)->set_tx_clock(clock); |
| 812 | 750 | } |
| 813 | | |
| 814 | | |
| 815 | | /*------------------------------------------------- |
| 816 | | DEVICE_GET_INFO( acia6850 ) |
| 817 | | -------------------------------------------------*/ |
| 818 | | |
| 819 | | DEVICE_GET_INFO( acia6850 ) |
| 820 | | { |
| 821 | | switch (state) |
| 822 | | { |
| 823 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 824 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(acia6850_t); break; |
| 825 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 826 | | |
| 827 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 828 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(acia6850); break; |
| 829 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 830 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(acia6850); break; |
| 831 | | |
| 832 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 833 | | case DEVINFO_STR_NAME: strcpy(info->s, "6850 ACIA"); break; |
| 834 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "6850 ACIA"); break; |
| 835 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 836 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 837 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 838 | | } |
| 839 | | } |
| 840 | | |
| 841 | | DEFINE_LEGACY_DEVICE(ACIA6850, acia6850); |
src/emu/machine/8237dma.c
| r8910 | r8911 | |
| 21 | 21 | #include "emu.h" |
| 22 | 22 | #include "memconv.h" |
| 23 | 23 | #include "8237dma.h" |
| 24 | #include "devhelpr.h" |
| 24 | 25 | |
| 26 | /*************************************************************************** |
| 27 | MACROS |
| 28 | ***************************************************************************/ |
| 25 | 29 | |
| 26 | | /* States that the i8237 device can be in */ |
| 27 | | typedef enum { |
| 28 | | DMA8237_SI, /* Idle state */ |
| 29 | | DMA8237_S0, /* HRQ has been triggered, waiting to receive HLDA */ |
| 30 | | // DMA8237_SW, /* Wait state */ |
| 31 | | |
| 32 | | /* Normal transfer states */ |
| 33 | | DMA8237_S1, /* Output A8-A15; only used when A8-A15 really needs to be output */ |
| 34 | | DMA8237_S2, /* Output A0-A7 */ |
| 35 | | DMA8237_S3, /* Initiate read; skipped in compressed timing. On the S2->S3 transition DACK is set. */ |
| 36 | | DMA8237_S4, /* Perform read/write */ |
| 37 | | |
| 38 | | /* Memory to memory transfer states */ |
| 39 | | DMA8237_S11, /* Output A8-A15 */ |
| 40 | | // DMA8237_S12, /* Output A0-A7 */ |
| 41 | | // DMA8237_S13, /* Initiate read */ |
| 42 | | // DMA8237_S14, /* Perform read/write */ |
| 43 | | // DMA8237_S21, /* Output A8-A15 */ |
| 44 | | // DMA8237_S22, /* Output A0-A7 */ |
| 45 | | // DMA8237_S23, /* Initiate read */ |
| 46 | | // DMA8237_S24, /* Perform read/write */ |
| 47 | | } dma8237_state; |
| 48 | | |
| 49 | | |
| 50 | | typedef struct _i8237_t i8237_t; |
| 51 | | struct _i8237_t |
| 52 | | { |
| 53 | | devcb_resolved_write_line out_hrq_func; |
| 54 | | devcb_resolved_write_line out_eop_func; |
| 55 | | devcb_resolved_read8 in_memr_func; |
| 56 | | devcb_resolved_write8 out_memw_func; |
| 57 | | |
| 58 | | emu_timer *timer; |
| 59 | | |
| 60 | | struct |
| 61 | | { |
| 62 | | devcb_resolved_read8 in_ior_func; |
| 63 | | devcb_resolved_write8 out_iow_func; |
| 64 | | devcb_resolved_write_line out_dack_func; |
| 65 | | UINT16 base_address; |
| 66 | | UINT16 base_count; |
| 67 | | UINT16 address; |
| 68 | | UINT16 count; |
| 69 | | UINT8 mode; |
| 70 | | int high_address_changed; |
| 71 | | } chan[4]; |
| 72 | | |
| 73 | | UINT32 msb : 1; |
| 74 | | UINT32 eop : 1; |
| 75 | | UINT8 temp; |
| 76 | | UINT8 temporary_data; |
| 77 | | UINT8 command; |
| 78 | | UINT8 drq; |
| 79 | | UINT8 mask; |
| 80 | | UINT8 hrq; |
| 81 | | UINT8 hlda; |
| 82 | | |
| 83 | | /* bits 0- 3 : Terminal count for channels 0-3 |
| 84 | | * bits 4- 7 : Transfer in progress for channels 0-3 */ |
| 85 | | UINT8 status; |
| 86 | | |
| 87 | | dma8237_state state; /* State the device is currently in */ |
| 88 | | int service_channel; /* Channel we will be servicing */ |
| 89 | | int last_service_channel; /* Previous channel we serviced; used to determine channel priority. */ |
| 90 | | }; |
| 91 | | |
| 92 | | |
| 93 | 30 | #define DMA_MODE_CHANNEL(mode) ((mode) & 0x03) |
| 94 | 31 | #define DMA_MODE_OPERATION(mode) ((mode) & 0x0c) |
| 95 | 32 | #define DMA_MODE_AUTO_INIT(mode) ((mode) & 0x10) |
| r8910 | r8911 | |
| 107 | 44 | #define DMA8237_CASCADE_MODE 0xc0 |
| 108 | 45 | |
| 109 | 46 | |
| 110 | | /* ----------------------------------------------------------------------- */ |
| 47 | //************************************************************************** |
| 48 | // DEVICE CONFIGURATION |
| 49 | //************************************************************************** |
| 111 | 50 | |
| 112 | | INLINE i8237_t *get_safe_token(running_device *device) { |
| 113 | | assert( device != NULL ); |
| 114 | | assert( device->type() == I8237 ); |
| 115 | | return ( i8237_t *) downcast<legacy_device_base *>(device)->token(); |
| 51 | GENERIC_DEVICE_CONFIG_SETUP(i8237, "I8237") |
| 52 | |
| 53 | //------------------------------------------------- |
| 54 | // device_config_complete - perform any |
| 55 | // operations now that the configuration is |
| 56 | // complete |
| 57 | //------------------------------------------------- |
| 58 | |
| 59 | void i8237_device_config::device_config_complete() |
| 60 | { |
| 61 | // inherit a copy of the static data |
| 62 | const i8237_interface *intf = reinterpret_cast<const i8237_interface *>(static_config()); |
| 63 | if (intf != NULL) |
| 64 | { |
| 65 | *static_cast<i8237_interface *>(this) = *intf; |
| 66 | } |
| 67 | |
| 68 | // or initialize to defaults if none provided |
| 69 | else |
| 70 | { |
| 71 | memset(&m_out_hrq_func, 0, sizeof(m_out_hrq_func)); |
| 72 | memset(&m_out_eop_func, 0, sizeof(m_out_eop_func)); |
| 73 | memset(&m_in_memr_func, 0, sizeof(m_in_memr_func)); |
| 74 | memset(&m_out_memw_func, 0, sizeof(m_out_memw_func)); |
| 75 | memset(&m_in_ior_func[0], 0, sizeof(m_in_ior_func[0])); |
| 76 | memset(&m_in_ior_func[1], 0, sizeof(m_in_ior_func[1])); |
| 77 | memset(&m_in_ior_func[2], 0, sizeof(m_in_ior_func[2])); |
| 78 | memset(&m_in_ior_func[3], 0, sizeof(m_in_ior_func[3])); |
| 79 | memset(&m_out_iow_func[0], 0, sizeof(m_out_iow_func[0])); |
| 80 | memset(&m_out_iow_func[1], 0, sizeof(m_out_iow_func[1])); |
| 81 | memset(&m_out_iow_func[2], 0, sizeof(m_out_iow_func[2])); |
| 82 | memset(&m_out_iow_func[3], 0, sizeof(m_out_iow_func[3])); |
| 83 | memset(&m_out_dack_func[0], 0, sizeof(m_out_dack_func[0])); |
| 84 | memset(&m_out_dack_func[1], 0, sizeof(m_out_dack_func[1])); |
| 85 | memset(&m_out_dack_func[2], 0, sizeof(m_out_dack_func[2])); |
| 86 | memset(&m_out_dack_func[3], 0, sizeof(m_out_dack_func[3])); |
| 87 | } |
| 116 | 88 | } |
| 117 | 89 | |
| 118 | 90 | |
| 119 | | /* ----------------------------------------------------------------------- */ |
| 120 | 91 | |
| 92 | //************************************************************************** |
| 93 | // LIVE DEVICE |
| 94 | //************************************************************************** |
| 121 | 95 | |
| 122 | | INLINE void dma8237_do_read( running_device *device ) |
| 96 | const device_type I8237 = i8237_device_config::static_alloc_device_config; |
| 97 | |
| 98 | //------------------------------------------------- |
| 99 | // i8237_device - constructor |
| 100 | //------------------------------------------------- |
| 101 | |
| 102 | i8237_device::i8237_device(running_machine &_machine, const i8237_device_config &config) |
| 103 | : device_t(_machine, config), |
| 104 | m_config(config) |
| 123 | 105 | { |
| 124 | | i8237_t *i8237 = get_safe_token( device ); |
| 125 | | int channel = i8237->service_channel; |
| 126 | 106 | |
| 127 | | switch( DMA_MODE_OPERATION( i8237->chan[ channel ].mode ) ) |
| 107 | } |
| 108 | |
| 109 | //------------------------------------------------- |
| 110 | // device_start - device-specific startup |
| 111 | //------------------------------------------------- |
| 112 | |
| 113 | void i8237_device::device_start() |
| 114 | { |
| 115 | /* resolve callbacks */ |
| 116 | devcb_resolve_write_line(&m_out_hrq_func, &m_config.m_out_hrq_func, this); |
| 117 | devcb_resolve_write_line(&m_out_eop_func, &m_config.m_out_eop_func, this); |
| 118 | devcb_resolve_read8(&m_in_memr_func, &m_config.m_in_memr_func, this); |
| 119 | devcb_resolve_write8(&m_out_memw_func, &m_config.m_out_memw_func, this); |
| 120 | |
| 121 | for (int i = 0; i < 4; i++) |
| 128 | 122 | { |
| 123 | devcb_resolve_read8(&m_chan[i].m_in_ior_func, &m_config.m_in_ior_func[i], this); |
| 124 | devcb_resolve_write8(&m_chan[i].m_out_iow_func, &m_config.m_out_iow_func[i], this); |
| 125 | devcb_resolve_write_line(&m_chan[i].m_out_dack_func, &m_config.m_out_dack_func[i], this); |
| 126 | } |
| 127 | |
| 128 | m_timer = timer_alloc(&m_machine, i8237_timerproc_callback, (void *)this); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | //------------------------------------------------- |
| 133 | // device_reset - device-specific reset |
| 134 | //------------------------------------------------- |
| 135 | |
| 136 | void i8237_device::device_reset() |
| 137 | { |
| 138 | m_status = 0x0F; |
| 139 | m_eop = 1; |
| 140 | m_state = DMA8237_SI; |
| 141 | m_last_service_channel = 3; |
| 142 | |
| 143 | m_mask = 0x00; |
| 144 | m_status = 0x0F; |
| 145 | m_hrq = 0; |
| 146 | m_hlda = 0; |
| 147 | m_chan[0].m_mode = 0; |
| 148 | m_chan[1].m_mode = 0; |
| 149 | m_chan[2].m_mode = 0; |
| 150 | m_chan[3].m_mode = 0; |
| 151 | |
| 152 | timer_adjust_periodic(m_timer, ATTOTIME_IN_HZ(clock()), 0, ATTOTIME_IN_HZ(clock())); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | void i8237_device::i8237_do_read() |
| 157 | { |
| 158 | int channel = m_service_channel; |
| 159 | |
| 160 | switch( DMA_MODE_OPERATION( m_chan[ channel ].m_mode ) ) |
| 161 | { |
| 129 | 162 | case DMA8237_WRITE_TRANSFER: |
| 130 | | i8237->temporary_data = devcb_call_read8(&i8237->chan[channel].in_ior_func, 0); |
| 163 | m_temporary_data = devcb_call_read8(&m_chan[channel].m_in_ior_func, 0); |
| 131 | 164 | break; |
| 132 | 165 | case DMA8237_READ_TRANSFER: |
| 133 | | i8237->temporary_data = devcb_call_read8(&i8237->in_memr_func, i8237->chan[ channel ].address); |
| 166 | m_temporary_data = devcb_call_read8(&m_in_memr_func, m_chan[ channel ].m_address); |
| 134 | 167 | break; |
| 135 | 168 | case DMA8237_VERIFY_TRANSFER: |
| 136 | 169 | case DMA8237_ILLEGAL_TRANSFER: |
| r8910 | r8911 | |
| 139 | 172 | } |
| 140 | 173 | |
| 141 | 174 | |
| 142 | | INLINE void dma8237_do_write( running_device *device ) |
| 175 | void i8237_device::i8237_do_write() |
| 143 | 176 | { |
| 144 | | i8237_t *i8237 = get_safe_token( device ); |
| 145 | | int channel = i8237->service_channel; |
| 177 | int channel = m_service_channel; |
| 146 | 178 | |
| 147 | | switch( DMA_MODE_OPERATION( i8237->chan[ channel ].mode ) ) |
| 179 | switch( DMA_MODE_OPERATION( m_chan[ channel ].m_mode ) ) |
| 148 | 180 | { |
| 149 | 181 | case DMA8237_WRITE_TRANSFER: |
| 150 | | devcb_call_write8(&i8237->out_memw_func, i8237->chan[ channel ].address, i8237->temporary_data); |
| 182 | devcb_call_write8(&m_out_memw_func, m_chan[ channel ].m_address, m_temporary_data); |
| 151 | 183 | break; |
| 152 | 184 | case DMA8237_READ_TRANSFER: |
| 153 | | devcb_call_write8(&i8237->chan[channel].out_iow_func, 0, i8237->temporary_data); |
| 185 | devcb_call_write8(&m_chan[channel].m_out_iow_func, 0, m_temporary_data); |
| 154 | 186 | break; |
| 155 | 187 | case DMA8237_VERIFY_TRANSFER: |
| 156 | 188 | case DMA8237_ILLEGAL_TRANSFER: |
| r8910 | r8911 | |
| 159 | 191 | } |
| 160 | 192 | |
| 161 | 193 | |
| 162 | | INLINE void dma8237_advance( running_device *device ) |
| 194 | void i8237_device::i8237_advance() |
| 163 | 195 | { |
| 164 | | i8237_t *i8237 = get_safe_token( device ); |
| 165 | | int channel = i8237->service_channel; |
| 166 | | int mode = i8237->chan[channel].mode; |
| 196 | int channel = m_service_channel; |
| 197 | int mode = m_chan[channel].m_mode; |
| 167 | 198 | |
| 168 | 199 | switch ( DMA_MODE_OPERATION( mode ) ) |
| 169 | 200 | { |
| 170 | 201 | case DMA8237_VERIFY_TRANSFER: |
| 171 | 202 | case DMA8237_WRITE_TRANSFER: |
| 172 | 203 | case DMA8237_READ_TRANSFER: |
| 173 | | i8237->chan[channel].high_address_changed = 0; |
| 204 | m_chan[channel].m_high_address_changed = 0; |
| 174 | 205 | |
| 175 | 206 | if ( DMA_MODE_DIRECTION( mode ) ) |
| 176 | 207 | { |
| 177 | | i8237->chan[channel].address -= 1; |
| 178 | | if ( ( i8237->chan[channel].address & 0xFF ) == 0xFF ) |
| 179 | | i8237->chan[channel].high_address_changed = 1; |
| 208 | m_chan[channel].m_address -= 1; |
| 209 | if ( ( m_chan[channel].m_address & 0xFF ) == 0xFF ) |
| 210 | { |
| 211 | m_chan[channel].m_high_address_changed = 1; |
| 212 | } |
| 180 | 213 | } |
| 181 | 214 | else |
| 182 | 215 | { |
| 183 | | i8237->chan[channel].address += 1; |
| 184 | | if ( ( i8237->chan[channel].address & 0xFF ) == 0x00 ) |
| 185 | | i8237->chan[channel].high_address_changed = 1; |
| 216 | m_chan[channel].m_address += 1; |
| 217 | if ( ( m_chan[channel].m_address & 0xFF ) == 0x00 ) |
| 218 | { |
| 219 | m_chan[channel].m_high_address_changed = 1; |
| 220 | } |
| 186 | 221 | } |
| 187 | 222 | |
| 188 | | i8237->chan[channel].count--; |
| 223 | m_chan[channel].m_count--; |
| 189 | 224 | |
| 190 | | if ( i8237->chan[channel].count == 0xFFFF ) |
| 225 | if ( m_chan[channel].m_count == 0xFFFF ) |
| 191 | 226 | { |
| 192 | 227 | /* Set TC bit for this channel */ |
| 193 | | i8237->status |= ( 0x01 << channel ); |
| 228 | m_status |= ( 0x01 << channel ); |
| 194 | 229 | |
| 195 | 230 | if ( DMA_MODE_AUTO_INIT( mode ) ) |
| 196 | 231 | { |
| 197 | | i8237->chan[channel].address = i8237->chan[channel].base_address; |
| 198 | | i8237->chan[channel].count = i8237->chan[channel].base_count; |
| 199 | | i8237->chan[channel].high_address_changed = 1; |
| 232 | m_chan[channel].m_address = m_chan[channel].m_base_address; |
| 233 | m_chan[channel].m_count = m_chan[channel].m_base_count; |
| 234 | m_chan[channel].m_high_address_changed = 1; |
| 200 | 235 | } |
| 201 | 236 | else |
| 202 | 237 | { |
| 203 | | i8237->mask |= ( 0x01 << channel ); |
| 238 | m_mask |= ( 0x01 << channel ); |
| 204 | 239 | } |
| 205 | 240 | } |
| 206 | 241 | break; |
| 207 | 242 | case DMA8237_ILLEGAL_TRANSFER: |
| 208 | 243 | break; |
| 209 | 244 | } |
| 210 | | |
| 211 | 245 | } |
| 212 | 246 | |
| 213 | | static void set_dack(i8237_t *i8237, int channel) |
| 214 | | { |
| 215 | | int i; |
| 216 | 247 | |
| 217 | | for (i = 0; i < 4; i++) |
| 248 | void i8237_device::set_dack(int channel) |
| 249 | { |
| 250 | for (int i = 0; i < 4; i++) |
| 218 | 251 | { |
| 219 | | int state = (i == channel) ^ !BIT(i8237->command, 7); |
| 252 | int state = (i == channel) ^ !BIT(m_command, 7); |
| 220 | 253 | |
| 221 | | devcb_call_write_line(&i8237->chan[i].out_dack_func, state); |
| 254 | devcb_call_write_line(&m_chan[i].m_out_dack_func, state); |
| 222 | 255 | } |
| 223 | 256 | } |
| 224 | 257 | |
| 225 | | static TIMER_CALLBACK( dma8237_timerproc ) |
| 258 | |
| 259 | TIMER_CALLBACK( i8237_device::i8237_timerproc_callback ) |
| 226 | 260 | { |
| 227 | | running_device *device = (running_device *)ptr; |
| 228 | | i8237_t *i8237 = get_safe_token(device); |
| 261 | reinterpret_cast<i8237_device*>(ptr)->i8237_timerproc(); |
| 262 | } |
| 229 | 263 | |
| 264 | |
| 265 | void i8237_device::i8237_timerproc() |
| 266 | { |
| 230 | 267 | /* Check if operation is disabled */ |
| 231 | | if ( i8237->command & 0x04 ) |
| 268 | if ( m_command & 0x04 ) |
| 269 | { |
| 232 | 270 | return; |
| 271 | } |
| 233 | 272 | |
| 234 | | switch ( i8237->state ) { |
| 273 | switch ( m_state ) |
| 274 | { |
| 235 | 275 | |
| 236 | 276 | case DMA8237_SI: |
| 277 | { |
| 237 | 278 | /* Make sure EOP is high */ |
| 238 | | if ( ! i8237->eop ) |
| 279 | if ( !m_eop ) |
| 239 | 280 | { |
| 240 | | i8237->eop = 1; |
| 241 | | devcb_call_write_line(&i8237->out_eop_func, i8237->eop ? ASSERT_LINE : CLEAR_LINE); |
| 281 | m_eop = 1; |
| 282 | devcb_call_write_line(&m_out_eop_func, m_eop ? ASSERT_LINE : CLEAR_LINE); |
| 242 | 283 | } |
| 243 | 284 | |
| 244 | 285 | /* Check if a new DMA request has been received. */ |
| 286 | /* Bit 6 of the command register determines whether the DREQ signals are active |
| 287 | high or active low. */ |
| 288 | UINT16 pending_request = ( ( m_command & 0x40 ) ? ~m_drq : m_drq ) & ~m_mask; |
| 289 | |
| 290 | if ( pending_request & 0x0f ) |
| 245 | 291 | { |
| 246 | | /* Bit 6 of the command register determines whether the DREQ signals are active |
| 247 | | high or active low. */ |
| 248 | | UINT16 pending_request = ( ( i8237->command & 0x40 ) ? ~i8237->drq : i8237->drq ) & ~i8237->mask; |
| 292 | int prio_channel = 0; |
| 249 | 293 | |
| 250 | | if ( pending_request & 0x0f ) |
| 294 | /* Determine the channel that should be serviced */ |
| 295 | int channel = ( m_command & 0x10 ) ? m_last_service_channel : 3; |
| 296 | for ( int i = 0; i < 4; i++ ) |
| 251 | 297 | { |
| 252 | | int i, channel, prio_channel = 0; |
| 253 | | |
| 254 | | /* Determine the channel that should be serviced */ |
| 255 | | channel = ( i8237->command & 0x10 ) ? i8237->last_service_channel : 3; |
| 256 | | for ( i = 0; i < 4; i++ ) |
| 298 | if ( pending_request & ( 1 << channel ) ) |
| 257 | 299 | { |
| 258 | | if ( pending_request & ( 1 << channel ) ) |
| 259 | | prio_channel = channel; |
| 260 | | channel = ( channel - 1 ) & 0x03; |
| 300 | prio_channel = channel; |
| 261 | 301 | } |
| 302 | channel = ( channel - 1 ) & 0x03; |
| 303 | } |
| 262 | 304 | |
| 263 | | /* Store the channel we will be servicing and go to the next state */ |
| 264 | | i8237->service_channel = prio_channel; |
| 265 | | i8237->last_service_channel = prio_channel; |
| 266 | | i8237->hrq = 1; |
| 267 | | devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq); |
| 268 | | i8237->state = DMA8237_S0; |
| 305 | /* Store the channel we will be servicing and go to the next state */ |
| 306 | m_service_channel = prio_channel; |
| 307 | m_last_service_channel = prio_channel; |
| 308 | m_hrq = 1; |
| 309 | devcb_call_write_line(&m_out_hrq_func, m_hrq); |
| 310 | m_state = DMA8237_S0; |
| 269 | 311 | |
| 270 | | timer_enable( i8237->timer, 1 ); |
| 271 | | } |
| 272 | | else |
| 273 | | { |
| 274 | | timer_enable( i8237->timer, 0 ); |
| 275 | | } |
| 312 | timer_enable( m_timer, 1 ); |
| 276 | 313 | } |
| 314 | else |
| 315 | { |
| 316 | timer_enable( m_timer, 0 ); |
| 317 | } |
| 277 | 318 | break; |
| 319 | } |
| 278 | 320 | |
| 279 | 321 | case DMA8237_S0: |
| 280 | 322 | /* S0 is the first of the DMA service. We have requested a hold but are waiting |
| 281 | 323 | for confirmation. */ |
| 282 | | if ( i8237->hlda ) |
| 324 | if ( m_hlda ) |
| 283 | 325 | { |
| 284 | | if ( i8237->command & 0x01 ) |
| 326 | if ( m_command & 0x01 ) |
| 285 | 327 | { |
| 286 | 328 | /* Memory-to-memory transfers */ |
| 287 | | i8237->state = DMA8237_S11; |
| 329 | m_state = DMA8237_S11; |
| 288 | 330 | } |
| 289 | 331 | else |
| 290 | 332 | { |
| 291 | 333 | /* Regular transfers */ |
| 292 | | i8237->state = DMA8237_S1; |
| 334 | m_state = DMA8237_S1; |
| 293 | 335 | } |
| 294 | 336 | } |
| 295 | 337 | break; |
| 296 | 338 | |
| 297 | 339 | case DMA8237_S1: /* Output A8-A15 */ |
| 298 | | i8237->state = DMA8237_S2; |
| 340 | m_state = DMA8237_S2; |
| 299 | 341 | break; |
| 300 | 342 | |
| 301 | 343 | case DMA8237_S2: /* Output A7-A0 */ |
| 302 | 344 | /* set DACK */ |
| 303 | | set_dack(i8237, i8237->service_channel); |
| 345 | set_dack(m_service_channel); |
| 304 | 346 | |
| 305 | 347 | /* Check for compressed timing */ |
| 306 | | if ( i8237->command & 0x08 ) |
| 307 | | i8237->state = DMA8237_S4; |
| 348 | if ( m_command & 0x08 ) |
| 349 | { |
| 350 | m_state = DMA8237_S4; |
| 351 | } |
| 308 | 352 | else |
| 309 | | i8237->state = DMA8237_S3; |
| 353 | { |
| 354 | m_state = DMA8237_S3; |
| 355 | } |
| 310 | 356 | break; |
| 311 | 357 | |
| 312 | 358 | case DMA8237_S3: /* Initiate read */ |
| 313 | | dma8237_do_read( device ); |
| 314 | | i8237->state = DMA8237_S4; |
| 359 | i8237_do_read(); |
| 360 | m_state = DMA8237_S4; |
| 315 | 361 | break; |
| 316 | 362 | |
| 317 | 363 | case DMA8237_S4: /* Perform read/write */ |
| 318 | 364 | /* Perform read when in compressed timing mode */ |
| 319 | | if ( i8237->command & 0x08 ) |
| 320 | | dma8237_do_read( device ); |
| 365 | if ( m_command & 0x08 ) |
| 366 | { |
| 367 | i8237_do_read(); |
| 368 | } |
| 321 | 369 | |
| 322 | 370 | /* Perform write */ |
| 323 | | dma8237_do_write( device ); |
| 371 | i8237_do_write(); |
| 324 | 372 | |
| 373 | |
| 325 | 374 | /* Advance */ |
| 326 | | dma8237_advance( device ); |
| 375 | i8237_advance(); |
| 327 | 376 | |
| 328 | 377 | { |
| 329 | | int channel = i8237->service_channel; |
| 378 | int channel = m_service_channel; |
| 330 | 379 | |
| 331 | | switch( DMA_MODE_TRANSFERMODE( i8237->chan[channel].mode ) ) |
| 380 | switch( DMA_MODE_TRANSFERMODE( m_chan[channel].m_mode ) ) |
| 332 | 381 | { |
| 333 | 382 | case DMA8237_DEMAND_MODE: |
| 334 | 383 | /* Check for terminal count or EOP signal or DREQ begin de-asserted */ |
| 335 | | if ( ( i8237->status & ( 0x01 << channel ) ) || ! i8237->eop || ! ( i8237->drq & ( 0x01 << channel ) ) ) |
| 384 | if ( ( m_status & ( 0x01 << channel ) ) || !m_eop || !( m_drq & ( 0x01 << channel ) ) ) |
| 336 | 385 | { |
| 337 | | i8237->hrq = 0; |
| 338 | | i8237->hlda = 0; |
| 339 | | devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq); |
| 340 | | i8237->state = DMA8237_SI; |
| 386 | m_hrq = 0; |
| 387 | m_hlda = 0; |
| 388 | devcb_call_write_line(&m_out_hrq_func, m_hrq); |
| 389 | m_state = DMA8237_SI; |
| 341 | 390 | } |
| 342 | 391 | else |
| 343 | 392 | { |
| 344 | | i8237->state = i8237->chan[channel].high_address_changed ? DMA8237_S1 : DMA8237_S2; |
| 393 | m_state = m_chan[channel].m_high_address_changed ? DMA8237_S1 : DMA8237_S2; |
| 345 | 394 | } |
| 346 | 395 | break; |
| 347 | 396 | |
| 348 | 397 | case DMA8237_SINGLE_MODE: |
| 349 | | i8237->hrq = 0; |
| 350 | | i8237->hlda = 0; |
| 351 | | devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq); |
| 352 | | i8237->state = DMA8237_SI; |
| 398 | m_hrq = 0; |
| 399 | m_hlda = 0; |
| 400 | devcb_call_write_line(&m_out_hrq_func, m_hrq); |
| 401 | m_state = DMA8237_SI; |
| 353 | 402 | break; |
| 354 | 403 | |
| 355 | 404 | case DMA8237_BLOCK_MODE: |
| 356 | 405 | /* Check for terminal count or EOP signal */ |
| 357 | | if ( ( i8237->status & ( 0x01 << channel ) ) || ! i8237->eop ) |
| 406 | if ( ( m_status & ( 0x01 << channel ) ) || !m_eop ) |
| 358 | 407 | { |
| 359 | | i8237->hrq = 0; |
| 360 | | i8237->hlda = 0; |
| 361 | | devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq); |
| 362 | | i8237->state = DMA8237_SI; |
| 408 | m_hrq = 0; |
| 409 | m_hlda = 0; |
| 410 | devcb_call_write_line(&m_out_hrq_func, m_hrq); |
| 411 | m_state = DMA8237_SI; |
| 363 | 412 | } |
| 364 | 413 | else |
| 365 | 414 | { |
| 366 | | i8237->state = i8237->chan[channel].high_address_changed ? DMA8237_S1 : DMA8237_S2; |
| 415 | m_state = m_chan[channel].m_high_address_changed ? DMA8237_S1 : DMA8237_S2; |
| 367 | 416 | } |
| 368 | 417 | break; |
| 369 | 418 | |
| 370 | 419 | case DMA8237_CASCADE_MODE: |
| 371 | | if ( ! ( i8237->drq & ( 0x01 << channel ) ) ) |
| 420 | if ( ! ( m_drq & ( 0x01 << channel ) ) ) |
| 372 | 421 | { |
| 373 | | i8237->hrq = 0; |
| 374 | | i8237->hlda = 0; |
| 375 | | devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq); |
| 376 | | i8237->state = DMA8237_SI; |
| 422 | m_hrq = 0; |
| 423 | m_hlda = 0; |
| 424 | devcb_call_write_line(&m_out_hrq_func, m_hrq); |
| 425 | m_state = DMA8237_SI; |
| 377 | 426 | } |
| 378 | 427 | break; |
| 379 | 428 | } |
| 380 | 429 | |
| 381 | 430 | /* Check if EOP output needs to be asserted */ |
| 382 | | if ( i8237->status & ( 0x01 << channel ) ) |
| 431 | if ( m_status & ( 0x01 << channel ) ) |
| 383 | 432 | { |
| 384 | | i8237->eop = 0; |
| 385 | | devcb_call_write_line(&i8237->out_eop_func, i8237->eop ? ASSERT_LINE : CLEAR_LINE); |
| 433 | m_eop = 0; |
| 434 | devcb_call_write_line(&m_out_eop_func, m_eop ? ASSERT_LINE : CLEAR_LINE); |
| 386 | 435 | } |
| 387 | 436 | } |
| 388 | 437 | |
| 389 | 438 | /* clear DACK */ |
| 390 | | set_dack(i8237, -1); |
| 439 | set_dack(-1); |
| 391 | 440 | break; |
| 392 | 441 | |
| 393 | 442 | case DMA8237_S11: /* Output A8-A15 */ |
| r8910 | r8911 | |
| 396 | 445 | } |
| 397 | 446 | |
| 398 | 447 | |
| 399 | | |
| 400 | | |
| 401 | | /* ----------------------------------------------------------------------- */ |
| 402 | | |
| 403 | | |
| 404 | | READ8_DEVICE_HANDLER( i8237_r ) |
| 448 | READ8_DEVICE_HANDLER_TRAMPOLINE(i8237, i8237_r) |
| 405 | 449 | { |
| 406 | | i8237_t *i8237 = get_safe_token(device); |
| 407 | 450 | UINT8 data = 0xFF; |
| 408 | 451 | |
| 409 | 452 | offset &= 0x0F; |
| r8910 | r8911 | |
| 414 | 457 | case 4: |
| 415 | 458 | case 6: |
| 416 | 459 | /* DMA address register */ |
| 417 | | data = i8237->chan[offset / 2].address >> (i8237->msb ? 8 : 0); |
| 418 | | i8237->msb ^= 1; |
| 460 | data = m_chan[offset / 2].m_address >> (m_msb ? 8 : 0); |
| 461 | m_msb ^= 1; |
| 419 | 462 | break; |
| 420 | 463 | |
| 421 | 464 | case 1: |
| r8910 | r8911 | |
| 423 | 466 | case 5: |
| 424 | 467 | case 7: |
| 425 | 468 | /* DMA count register */ |
| 426 | | data = i8237->chan[offset / 2].count >> (i8237->msb ? 8 : 0); |
| 427 | | i8237->msb ^= 1; |
| 469 | data = m_chan[offset / 2].m_count >> (m_msb ? 8 : 0); |
| 470 | m_msb ^= 1; |
| 428 | 471 | break; |
| 429 | 472 | |
| 430 | 473 | case 8: |
| 431 | 474 | /* DMA status register */ |
| 432 | | data = (UINT8) i8237->status; |
| 475 | data = (UINT8) m_status; |
| 433 | 476 | |
| 434 | 477 | /* TC bits are cleared on a status read */ |
| 435 | | i8237->status &= 0xF0; |
| 478 | m_status &= 0xF0; |
| 436 | 479 | break; |
| 437 | 480 | |
| 438 | 481 | case 10: |
| 439 | 482 | /* DMA mask register */ |
| 440 | | data = i8237->mask; |
| 483 | data = m_mask; |
| 441 | 484 | break; |
| 442 | 485 | |
| 443 | 486 | case 13: |
| 444 | 487 | /* DMA master clear */ |
| 445 | | data = i8237->temp; |
| 488 | data = m_temp; |
| 446 | 489 | break; |
| 447 | 490 | |
| 448 | 491 | case 9: /* DMA write request register */ |
| r8910 | r8911 | |
| 458 | 501 | } |
| 459 | 502 | |
| 460 | 503 | |
| 461 | | |
| 462 | | WRITE8_DEVICE_HANDLER( i8237_w ) |
| 504 | WRITE8_DEVICE_HANDLER_TRAMPOLINE(i8237, i8237_w) |
| 463 | 505 | { |
| 464 | | i8237_t *i8237 = get_safe_token(device); |
| 465 | | int channel; |
| 466 | | |
| 467 | 506 | offset &= 0x0F; |
| 468 | 507 | |
| 469 | 508 | logerror("i8237_w: offset = %02x, data = %02x\n", offset, data ); |
| r8910 | r8911 | |
| 473 | 512 | case 2: |
| 474 | 513 | case 4: |
| 475 | 514 | case 6: |
| 515 | { |
| 476 | 516 | /* DMA address register */ |
| 477 | | channel = offset / 2; |
| 478 | | if (i8237->msb) |
| 517 | int channel = offset / 2; |
| 518 | if (m_msb) |
| 479 | 519 | { |
| 480 | | i8237->chan[channel].base_address = ( i8237->chan[channel].base_address & 0x00FF ) | ( data << 8 ); |
| 481 | | i8237->chan[channel].address = ( i8237->chan[channel].address & 0x00FF ) | ( data << 8 ); |
| 520 | m_chan[channel].m_base_address = ( m_chan[channel].m_base_address & 0x00FF ) | ( data << 8 ); |
| 521 | m_chan[channel].m_address = ( m_chan[channel].m_address & 0x00FF ) | ( data << 8 ); |
| 482 | 522 | } |
| 483 | 523 | else |
| 484 | 524 | { |
| 485 | | i8237->chan[channel].base_address = ( i8237->chan[channel].base_address & 0xFF00 ) | data; |
| 486 | | i8237->chan[channel].address = ( i8237->chan[channel].address & 0xFF00 ) | data; |
| 525 | m_chan[channel].m_base_address = ( m_chan[channel].m_base_address & 0xFF00 ) | data; |
| 526 | m_chan[channel].m_address = ( m_chan[channel].m_address & 0xFF00 ) | data; |
| 487 | 527 | } |
| 488 | | i8237->msb ^= 1; |
| 528 | m_msb ^= 1; |
| 489 | 529 | break; |
| 530 | } |
| 490 | 531 | |
| 491 | 532 | case 1: |
| 492 | 533 | case 3: |
| 493 | 534 | case 5: |
| 494 | 535 | case 7: |
| 536 | { |
| 495 | 537 | /* DMA count register */ |
| 496 | | channel = offset / 2; |
| 497 | | if (i8237->msb) |
| 538 | int channel = offset / 2; |
| 539 | if (m_msb) |
| 498 | 540 | { |
| 499 | | i8237->chan[channel].base_count = ( i8237->chan[channel].base_count & 0x00FF ) | ( data << 8 ); |
| 500 | | i8237->chan[channel].count = ( i8237->chan[channel].count & 0x00FF ) | ( data << 8 ); |
| 541 | m_chan[channel].m_base_count = ( m_chan[channel].m_base_count & 0x00FF ) | ( data << 8 ); |
| 542 | m_chan[channel].m_count = ( m_chan[channel].m_count & 0x00FF ) | ( data << 8 ); |
| 501 | 543 | } |
| 502 | 544 | else |
| 503 | 545 | { |
| 504 | | i8237->chan[channel].base_count = ( i8237->chan[channel].base_count & 0xFF00 ) | data; |
| 505 | | i8237->chan[channel].count = ( i8237->chan[channel].count & 0xFF00 ) | data; |
| 546 | m_chan[channel].m_base_count = ( m_chan[channel].m_base_count & 0xFF00 ) | data; |
| 547 | m_chan[channel].m_count = ( m_chan[channel].m_count & 0xFF00 ) | data; |
| 506 | 548 | } |
| 507 | | i8237->msb ^= 1; |
| 549 | m_msb ^= 1; |
| 508 | 550 | break; |
| 551 | } |
| 509 | 552 | |
| 510 | 553 | case 8: |
| 511 | 554 | /* DMA command register */ |
| 512 | | i8237->command = data; |
| 513 | | timer_enable( i8237->timer, ( i8237->command & 0x04 ) ? 0 : 1 ); |
| 555 | m_command = data; |
| 556 | timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 ); |
| 514 | 557 | break; |
| 515 | 558 | |
| 516 | 559 | case 9: |
| 560 | { |
| 517 | 561 | /* DMA request register */ |
| 518 | | channel = DMA_MODE_CHANNEL(data); |
| 562 | int channel = DMA_MODE_CHANNEL(data); |
| 519 | 563 | if ( data & 0x04 ) |
| 520 | 564 | { |
| 521 | | i8237->drq |= 0x01 << channel; |
| 522 | | timer_enable( i8237->timer, ( i8237->command & 0x04 ) ? 0 : 1 ); |
| 565 | m_drq |= 0x01 << channel; |
| 566 | timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 ); |
| 523 | 567 | } |
| 524 | 568 | else |
| 525 | 569 | { |
| 526 | | i8237->status &= ~ ( 0x10 << channel ); |
| 527 | | i8237->drq &= ~ ( 0x01 << channel ); |
| 570 | m_status &= ~ ( 0x10 << channel ); |
| 571 | m_drq &= ~ ( 0x01 << channel ); |
| 528 | 572 | } |
| 529 | 573 | break; |
| 574 | } |
| 530 | 575 | |
| 531 | 576 | case 10: |
| 577 | { |
| 532 | 578 | /* DMA mask register */ |
| 533 | | channel = DMA_MODE_CHANNEL(data); |
| 579 | int channel = DMA_MODE_CHANNEL(data); |
| 534 | 580 | if (data & 0x04) |
| 535 | | i8237->mask |= 0x11 << channel; |
| 581 | { |
| 582 | m_mask |= 0x11 << channel; |
| 583 | } |
| 536 | 584 | else |
| 537 | | i8237->mask &= ~(0x11 << channel); |
| 585 | { |
| 586 | m_mask &= ~(0x11 << channel); |
| 587 | } |
| 538 | 588 | break; |
| 589 | } |
| 539 | 590 | |
| 540 | 591 | case 11: |
| 592 | { |
| 541 | 593 | /* DMA mode register */ |
| 542 | | channel = DMA_MODE_CHANNEL(data); |
| 543 | | i8237->chan[channel].mode = data; |
| 594 | int channel = DMA_MODE_CHANNEL(data); |
| 595 | m_chan[channel].m_mode = data; |
| 544 | 596 | /* Apparently mode writes also clear the TC bit(?) */ |
| 545 | | i8237->status &= ~ ( 1 << channel ); |
| 597 | m_status &= ~ ( 1 << channel ); |
| 546 | 598 | break; |
| 599 | } |
| 547 | 600 | |
| 548 | 601 | case 12: |
| 549 | 602 | /* DMA clear byte pointer flip-flop */ |
| 550 | | i8237->temp = data; |
| 551 | | i8237->msb = 0; |
| 603 | m_temp = data; |
| 604 | m_msb = 0; |
| 552 | 605 | break; |
| 553 | 606 | |
| 554 | 607 | case 13: |
| 555 | 608 | /* DMA master clear */ |
| 556 | | i8237->msb = 0; |
| 557 | | i8237->mask = 0x0f; |
| 558 | | i8237->state = DMA8237_SI; |
| 559 | | i8237->status &= 0xF0; |
| 609 | m_msb = 0; |
| 610 | m_mask = 0x0f; |
| 611 | m_state = DMA8237_SI; |
| 612 | m_status &= 0xF0; |
| 560 | 613 | break; |
| 561 | 614 | |
| 562 | 615 | case 14: |
| 563 | 616 | /* DMA clear mask register */ |
| 564 | | i8237->mask &= ~data; |
| 565 | | i8237->mask = 0; |
| 617 | m_mask &= ~data; |
| 618 | m_mask = 0; |
| 566 | 619 | break; |
| 567 | 620 | |
| 568 | 621 | case 15: |
| 569 | 622 | /* DMA write mask register */ |
| 570 | | i8237->mask = data & 0x0f; |
| 623 | m_mask = data & 0x0f; |
| 571 | 624 | break; |
| 572 | 625 | } |
| 573 | 626 | } |
| 574 | 627 | |
| 575 | 628 | |
| 576 | | |
| 577 | | static void dma8237_drq_write(running_device *device, int channel, int state) |
| 629 | void i8237_device::i8237_drq_write(int channel, int state) |
| 578 | 630 | { |
| 579 | | i8237_t *i8237 = get_safe_token( device ); |
| 580 | | |
| 581 | 631 | if (state) |
| 582 | | i8237->drq |= ( 0x01 << channel ); |
| 632 | { |
| 633 | m_drq |= ( 0x01 << channel ); |
| 634 | } |
| 583 | 635 | else |
| 584 | | i8237->drq &= ~( 0x01 << channel ); |
| 585 | | |
| 586 | | timer_enable( i8237->timer, ( i8237->command & 0x04 ) ? 0 : 1 ); |
| 587 | | } |
| 588 | | |
| 589 | | WRITE_LINE_DEVICE_HANDLER( i8237_hlda_w ) |
| 590 | | { |
| 591 | | i8237_t *i8237 = get_safe_token( device ); |
| 592 | | |
| 593 | | i8237->hlda = state; |
| 594 | | } |
| 595 | | |
| 596 | | WRITE_LINE_DEVICE_HANDLER( i8237_ready_w ) |
| 597 | | { |
| 598 | | } |
| 599 | | |
| 600 | | WRITE_LINE_DEVICE_HANDLER( i8237_dreq0_w ) { dma8237_drq_write(device, 0, state); } |
| 601 | | WRITE_LINE_DEVICE_HANDLER( i8237_dreq1_w ) { dma8237_drq_write(device, 1, state); } |
| 602 | | WRITE_LINE_DEVICE_HANDLER( i8237_dreq2_w ) { dma8237_drq_write(device, 2, state); } |
| 603 | | WRITE_LINE_DEVICE_HANDLER( i8237_dreq3_w ) { dma8237_drq_write(device, 3, state); } |
| 604 | | |
| 605 | | WRITE_LINE_DEVICE_HANDLER( i8237_eop_w ) |
| 606 | | { |
| 607 | | } |
| 608 | | |
| 609 | | |
| 610 | | static DEVICE_START( i8237 ) { |
| 611 | | i8237_t *i8237 = get_safe_token(device); |
| 612 | | i8237_interface *intf = (i8237_interface *)device->baseconfig().static_config(); |
| 613 | | int i; |
| 614 | | |
| 615 | | /* resolve callbacks */ |
| 616 | | devcb_resolve_write_line(&i8237->out_hrq_func, &intf->out_hrq_func, device); |
| 617 | | devcb_resolve_write_line(&i8237->out_eop_func, &intf->out_eop_func, device); |
| 618 | | devcb_resolve_read8(&i8237->in_memr_func, &intf->in_memr_func, device); |
| 619 | | devcb_resolve_write8(&i8237->out_memw_func, &intf->out_memw_func, device); |
| 620 | | |
| 621 | | for (i = 0; i < 4; i++) |
| 622 | 636 | { |
| 623 | | devcb_resolve_read8(&i8237->chan[i].in_ior_func, &intf->in_ior_func[i], device); |
| 624 | | devcb_resolve_write8(&i8237->chan[i].out_iow_func, &intf->out_iow_func[i], device); |
| 625 | | devcb_resolve_write_line(&i8237->chan[i].out_dack_func, &intf->out_dack_func[i], device); |
| 637 | m_drq &= ~( 0x01 << channel ); |
| 626 | 638 | } |
| 627 | 639 | |
| 628 | | i8237->timer = timer_alloc(device->machine, dma8237_timerproc, (void *)device); |
| 640 | timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 ); |
| 629 | 641 | } |
| 630 | 642 | |
| 631 | 643 | |
| 632 | | static DEVICE_RESET( i8237 ) { |
| 633 | | i8237_t *i8237 = get_safe_token(device); |
| 634 | 644 | |
| 635 | | i8237->status = 0x0F; |
| 636 | | i8237->eop = 1; |
| 637 | | i8237->state = DMA8237_SI; |
| 638 | | i8237->last_service_channel = 3; |
| 645 | /*************************************************************************** |
| 646 | TRAMPOLINES |
| 647 | ***************************************************************************/ |
| 639 | 648 | |
| 640 | | i8237->mask = 0x00; |
| 641 | | i8237->status = 0x0F; |
| 642 | | i8237->hrq = 0; |
| 643 | | i8237->hlda = 0; |
| 644 | | i8237->chan[0].mode = 0; |
| 645 | | i8237->chan[1].mode = 0; |
| 646 | | i8237->chan[2].mode = 0; |
| 647 | | i8237->chan[3].mode = 0; |
| 648 | | |
| 649 | | timer_adjust_periodic(i8237->timer, |
| 650 | | ATTOTIME_IN_HZ(device->clock()), |
| 651 | | 0, |
| 652 | | ATTOTIME_IN_HZ(device->clock())); |
| 653 | | } |
| 654 | | |
| 655 | | |
| 656 | | DEVICE_GET_INFO( i8237 ) { |
| 657 | | switch ( state ) { |
| 658 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 659 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(i8237_t); break; |
| 660 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 661 | | |
| 662 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 663 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(i8237); break; |
| 664 | | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 665 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(i8237); break; |
| 666 | | |
| 667 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 668 | | case DEVINFO_STR_NAME: strcpy(info->s, "Intel 8237"); break; |
| 669 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Intel 8080"); break; |
| 670 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.01"); break; |
| 671 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 672 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MAME and MESS Teams"); break; |
| 673 | | } |
| 674 | | } |
| 675 | | |
| 676 | | |
| 677 | | DEFINE_LEGACY_DEVICE(I8237, i8237); |
| 649 | WRITE_LINE_DEVICE_HANDLER( i8237_hlda_w ) { downcast<i8237_device*>(device)->i8237_hlda_w(state); } |
| 650 | WRITE_LINE_DEVICE_HANDLER( i8237_ready_w ) { } |
| 651 | WRITE_LINE_DEVICE_HANDLER( i8237_dreq0_w ) { downcast<i8237_device*>(device)->i8237_drq_write(0, state); } |
| 652 | WRITE_LINE_DEVICE_HANDLER( i8237_dreq1_w ) { downcast<i8237_device*>(device)->i8237_drq_write(1, state); } |
| 653 | WRITE_LINE_DEVICE_HANDLER( i8237_dreq2_w ) { downcast<i8237_device*>(device)->i8237_drq_write(2, state); } |
| 654 | WRITE_LINE_DEVICE_HANDLER( i8237_dreq3_w ) { downcast<i8237_device*>(device)->i8237_drq_write(3, state); } |
| 655 | WRITE_LINE_DEVICE_HANDLER( i8237_eop_w ) { } |
src/emu/mconfig.c
| r8910 | r8911 | |
| 49 | 49 | // machine_config - constructor |
| 50 | 50 | //------------------------------------------------- |
| 51 | 51 | |
| 52 | | machine_config::machine_config(const machine_config_token *tokens) |
| 52 | machine_config::machine_config(machine_config_constructor constructor) |
| 53 | 53 | : m_driver_data_alloc(NULL), |
| 54 | 54 | m_minimum_quantum(attotime_zero), |
| 55 | 55 | m_perfect_cpu_quantum(NULL), |
| r8910 | r8911 | |
| 72 | 72 | m_sound_reset(NULL), |
| 73 | 73 | m_parse_level(0) |
| 74 | 74 | { |
| 75 | | // parse tokens into the config |
| 76 | | detokenize(tokens); |
| 75 | // construct the config |
| 76 | (*constructor)(*this, NULL); |
| 77 | |
| 78 | // process any device-specific machine configurations |
| 79 | for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) |
| 80 | if (!devconfig->m_config_complete) |
| 81 | { |
| 82 | machine_config_constructor additions = devconfig->machine_config_additions(); |
| 83 | if (additions != NULL) |
| 84 | (*additions)(*this, devconfig); |
| 85 | } |
| 86 | |
| 87 | // then notify all devices that their configuration is complete |
| 88 | for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) |
| 89 | if (!devconfig->m_config_complete) |
| 90 | { |
| 91 | devconfig->config_complete(); |
| 92 | devconfig->m_config_complete = true; |
| 93 | } |
| 77 | 94 | } |
| 78 | 95 | |
| 79 | 96 | |
| r8910 | r8911 | |
| 87 | 104 | |
| 88 | 105 | |
| 89 | 106 | //------------------------------------------------- |
| 90 | | // detokenize - detokenize a machine config |
| 107 | // device_add - configuration helper to add a |
| 108 | // new device |
| 91 | 109 | //------------------------------------------------- |
| 92 | 110 | |
| 93 | | void machine_config::detokenize(const machine_config_token *tokens, const device_config *owner) |
| 111 | device_config *machine_config::device_add(device_config *owner, const char *tag, device_type type, UINT32 clock) |
| 94 | 112 | { |
| 95 | | device_config *device = NULL; |
| 96 | 113 | astring tempstring; |
| 114 | const char *fulltag = owner->subtag(tempstring, tag); |
| 115 | return m_devicelist.append(fulltag, (*type)(*this, fulltag, owner, clock)); |
| 116 | } |
| 97 | 117 | |
| 98 | | // increase the parse level |
| 99 | | m_parse_level++; |
| 100 | 118 | |
| 101 | | // loop over tokens until we hit the end |
| 102 | | UINT32 entrytype = MCONFIG_TOKEN_INVALID; |
| 103 | | while (entrytype != MCONFIG_TOKEN_END) |
| 104 | | { |
| 105 | | device_type devtype; |
| 106 | | const char *tag; |
| 107 | | UINT64 data64; |
| 108 | | UINT32 clock; |
| 119 | //------------------------------------------------- |
| 120 | // device_replace - configuration helper to |
| 121 | // replace one device with a new device |
| 122 | //------------------------------------------------- |
| 109 | 123 | |
| 110 | | // unpack the token from the first entry |
| 111 | | TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8); |
| 112 | | switch (entrytype) |
| 113 | | { |
| 114 | | // end |
| 115 | | case MCONFIG_TOKEN_END: |
| 116 | | break; |
| 124 | device_config *machine_config::device_replace(device_config *owner, const char *tag, device_type type, UINT32 clock) |
| 125 | { |
| 126 | astring tempstring; |
| 127 | const char *fulltag = owner->subtag(tempstring, tag); |
| 128 | return m_devicelist.replace(fulltag, (*type)(*this, fulltag, owner, clock)); |
| 129 | } |
| 117 | 130 | |
| 118 | | // including |
| 119 | | case MCONFIG_TOKEN_INCLUDE: |
| 120 | | detokenize(TOKEN_GET_PTR(tokens, tokenptr), owner); |
| 121 | | break; |
| 122 | 131 | |
| 123 | | // device management |
| 124 | | case MCONFIG_TOKEN_DEVICE_ADD: |
| 125 | | TOKEN_UNGET_UINT32(tokens); |
| 126 | | TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); |
| 127 | | devtype = TOKEN_GET_PTR(tokens, devtype); |
| 128 | | tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens)); |
| 129 | | device = m_devicelist.append(tag, (*devtype)(*this, tag, owner, clock)); |
| 130 | | break; |
| 132 | //------------------------------------------------- |
| 133 | // device_remove - configuration helper to |
| 134 | // remove a device |
| 135 | //------------------------------------------------- |
| 131 | 136 | |
| 132 | | case MCONFIG_TOKEN_DEVICE_REPLACE: |
| 133 | | TOKEN_UNGET_UINT32(tokens); |
| 134 | | TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); |
| 135 | | devtype = TOKEN_GET_PTR(tokens, devtype); |
| 136 | | tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens)); |
| 137 | | device = m_devicelist.replace(tag, (*devtype)(*this, tag, owner, clock)); |
| 138 | | break; |
| 137 | device_config *machine_config::device_remove(device_config *owner, const char *tag) |
| 138 | { |
| 139 | astring tempstring; |
| 140 | const char *fulltag = owner->subtag(tempstring, tag); |
| 141 | m_devicelist.remove(fulltag); |
| 142 | return NULL; |
| 143 | } |
| 139 | 144 | |
| 140 | | case MCONFIG_TOKEN_DEVICE_REMOVE: |
| 141 | | tag = TOKEN_GET_STRING(tokens); |
| 142 | | m_devicelist.remove(owner->subtag(tempstring, tag)); |
| 143 | | device = NULL; |
| 144 | | break; |
| 145 | 145 | |
| 146 | | case MCONFIG_TOKEN_DEVICE_MODIFY: |
| 147 | | tag = TOKEN_GET_STRING(tokens); |
| 148 | | device = m_devicelist.find(owner->subtag(tempstring, tag).cstr()); |
| 149 | | if (device == NULL) |
| 150 | | fatalerror("Unable to find device: tag=%s\n", tempstring.cstr()); |
| 151 | | break; |
| 146 | //------------------------------------------------- |
| 147 | // device_find - configuration helper to |
| 148 | // locate a device |
| 149 | //------------------------------------------------- |
| 152 | 150 | |
| 153 | | case MCONFIG_TOKEN_DEVICE_CLOCK: |
| 154 | | case MCONFIG_TOKEN_DEVICE_CONFIG: |
| 155 | | case MCONFIG_TOKEN_DEVICE_INLINE_DATA16: |
| 156 | | case MCONFIG_TOKEN_DEVICE_INLINE_DATA32: |
| 157 | | case MCONFIG_TOKEN_DEVICE_INLINE_DATA64: |
| 158 | | |
| 159 | | case MCONFIG_TOKEN_DIEXEC_DISABLE: |
| 160 | | case MCONFIG_TOKEN_DIEXEC_VBLANK_INT: |
| 161 | | case MCONFIG_TOKEN_DIEXEC_PERIODIC_INT: |
| 162 | | |
| 163 | | case MCONFIG_TOKEN_DIMEMORY_MAP: |
| 164 | | |
| 165 | | case MCONFIG_TOKEN_DISOUND_ROUTE: |
| 166 | | case MCONFIG_TOKEN_DISOUND_RESET: |
| 167 | | |
| 168 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1: |
| 169 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_2: |
| 170 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_3: |
| 171 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_4: |
| 172 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_5: |
| 173 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_6: |
| 174 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_7: |
| 175 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_8: |
| 176 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_9: |
| 177 | | case MCONFIG_TOKEN_DEVICE_CONFIG_DATA32: |
| 178 | | case MCONFIG_TOKEN_DEVICE_CONFIG_DATA64: |
| 179 | | case MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32: |
| 180 | | case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE: |
| 181 | | assert(device != NULL); |
| 182 | | device->process_token(entrytype, tokens); |
| 183 | | break; |
| 184 | | |
| 185 | | |
| 186 | | // core parameters |
| 187 | | case MCONFIG_TOKEN_DRIVER_DATA: |
| 188 | | m_driver_data_alloc = TOKEN_GET_PTR(tokens, driver_data_alloc); |
| 189 | | break; |
| 190 | | |
| 191 | | case MCONFIG_TOKEN_QUANTUM_TIME: |
| 192 | | TOKEN_EXTRACT_UINT64(tokens, data64); |
| 193 | | m_minimum_quantum = UINT64_ATTOTIME_TO_ATTOTIME(data64); |
| 194 | | break; |
| 195 | | |
| 196 | | case MCONFIG_TOKEN_QUANTUM_PERFECT_CPU: |
| 197 | | m_perfect_cpu_quantum = TOKEN_GET_STRING(tokens); |
| 198 | | break; |
| 199 | | |
| 200 | | case MCONFIG_TOKEN_WATCHDOG_VBLANK: |
| 201 | | TOKEN_UNGET_UINT32(tokens); |
| 202 | | TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_watchdog_vblank_count, 24); |
| 203 | | break; |
| 204 | | |
| 205 | | case MCONFIG_TOKEN_WATCHDOG_TIME: |
| 206 | | TOKEN_EXTRACT_UINT64(tokens, data64); |
| 207 | | m_watchdog_time = UINT64_ATTOTIME_TO_ATTOTIME(data64); |
| 208 | | break; |
| 209 | | |
| 210 | | // core functions |
| 211 | | case MCONFIG_TOKEN_MACHINE_START: |
| 212 | | m_machine_start = TOKEN_GET_PTR(tokens, machine_start); |
| 213 | | break; |
| 214 | | |
| 215 | | case MCONFIG_TOKEN_MACHINE_RESET: |
| 216 | | m_machine_reset = TOKEN_GET_PTR(tokens, machine_reset); |
| 217 | | break; |
| 218 | | |
| 219 | | case MCONFIG_TOKEN_NVRAM_HANDLER: |
| 220 | | m_nvram_handler = TOKEN_GET_PTR(tokens, nvram_handler); |
| 221 | | break; |
| 222 | | |
| 223 | | case MCONFIG_TOKEN_MEMCARD_HANDLER: |
| 224 | | m_memcard_handler = TOKEN_GET_PTR(tokens, memcard_handler); |
| 225 | | break; |
| 226 | | |
| 227 | | // core video parameters |
| 228 | | case MCONFIG_TOKEN_VIDEO_ATTRIBUTES: |
| 229 | | TOKEN_UNGET_UINT32(tokens); |
| 230 | | TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_video_attributes, 24); |
| 231 | | break; |
| 232 | | |
| 233 | | case MCONFIG_TOKEN_GFXDECODE: |
| 234 | | m_gfxdecodeinfo = TOKEN_GET_PTR(tokens, gfxdecode); |
| 235 | | break; |
| 236 | | |
| 237 | | case MCONFIG_TOKEN_PALETTE_LENGTH: |
| 238 | | TOKEN_UNGET_UINT32(tokens); |
| 239 | | TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_total_colors, 24); |
| 240 | | break; |
| 241 | | |
| 242 | | case MCONFIG_TOKEN_DEFAULT_LAYOUT: |
| 243 | | m_default_layout = TOKEN_GET_STRING(tokens); |
| 244 | | break; |
| 245 | | |
| 246 | | // core video functions |
| 247 | | case MCONFIG_TOKEN_PALETTE_INIT: |
| 248 | | m_init_palette = TOKEN_GET_PTR(tokens, palette_init); |
| 249 | | break; |
| 250 | | |
| 251 | | case MCONFIG_TOKEN_VIDEO_START: |
| 252 | | m_video_start = TOKEN_GET_PTR(tokens, video_start); |
| 253 | | break; |
| 254 | | |
| 255 | | case MCONFIG_TOKEN_VIDEO_RESET: |
| 256 | | m_video_reset = TOKEN_GET_PTR(tokens, video_reset); |
| 257 | | break; |
| 258 | | |
| 259 | | case MCONFIG_TOKEN_VIDEO_EOF: |
| 260 | | m_video_eof = TOKEN_GET_PTR(tokens, video_eof); |
| 261 | | break; |
| 262 | | |
| 263 | | case MCONFIG_TOKEN_VIDEO_UPDATE: |
| 264 | | m_video_update = TOKEN_GET_PTR(tokens, video_update); |
| 265 | | break; |
| 266 | | |
| 267 | | // core sound functions |
| 268 | | case MCONFIG_TOKEN_SOUND_START: |
| 269 | | m_sound_start = TOKEN_GET_PTR(tokens, sound_start); |
| 270 | | break; |
| 271 | | |
| 272 | | case MCONFIG_TOKEN_SOUND_RESET: |
| 273 | | m_sound_reset = TOKEN_GET_PTR(tokens, sound_reset); |
| 274 | | break; |
| 275 | | |
| 276 | | default: |
| 277 | | fatalerror("Invalid token %d in machine config\n", entrytype); |
| 278 | | break; |
| 279 | | } |
| 280 | | } |
| 281 | | |
| 282 | | // if we started at parse level 0 (and are thus at level 1), do post-processing |
| 283 | | if (m_parse_level == 1) |
| 284 | | { |
| 285 | | // process any device-specific machine configurations |
| 286 | | for (const device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) |
| 287 | | if (!devconfig->m_config_complete) |
| 288 | | { |
| 289 | | tokens = devconfig->machine_config_tokens(); |
| 290 | | if (tokens != NULL) |
| 291 | | detokenize(tokens, devconfig); |
| 292 | | } |
| 293 | | |
| 294 | | // then notify all devices that their configuration is complete |
| 295 | | for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) |
| 296 | | if (!devconfig->m_config_complete) |
| 297 | | { |
| 298 | | devconfig->config_complete(); |
| 299 | | devconfig->m_config_complete = true; |
| 300 | | } |
| 301 | | } |
| 302 | | |
| 303 | | // bump down the parse level |
| 304 | | m_parse_level--; |
| 151 | device_config *machine_config::device_find(device_config *owner, const char *tag) |
| 152 | { |
| 153 | astring tempstring; |
| 154 | const char *fulltag = owner->subtag(tempstring, tag); |
| 155 | device_config *device = m_devicelist.find(fulltag); |
| 156 | if (device == NULL) |
| 157 | throw emu_fatalerror("Unable to find device: tag=%s\n", fulltag); |
| 158 | return device; |
| 305 | 159 | } |
src/emu/mconfig.h
| r8910 | r8911 | |
| 47 | 47 | #define __MCONFIG_H__ |
| 48 | 48 | |
| 49 | 49 | |
| 50 | //************************************************************************** |
| 51 | // CONSTANTS |
| 52 | //************************************************************************** |
| 53 | |
| 54 | // by convention, tags should all lowercase and between 2-15 characters |
| 55 | #define MIN_TAG_LENGTH 2 |
| 56 | #define MAX_TAG_LENGTH 15 |
| 57 | |
| 58 | |
| 59 | |
| 60 | // ----- flags for video_attributes ----- |
| 61 | |
| 62 | // should VIDEO_UPDATE by called at the start of VBLANK or at the end? |
| 63 | #define VIDEO_UPDATE_BEFORE_VBLANK 0x0000 |
| 64 | #define VIDEO_UPDATE_AFTER_VBLANK 0x0004 |
| 65 | |
| 66 | // indicates VIDEO_UPDATE will add container bits its |
| 67 | #define VIDEO_SELF_RENDER 0x0008 |
| 68 | |
| 69 | // automatically extend the palette creating a darker copy for shadows |
| 70 | #define VIDEO_HAS_SHADOWS 0x0010 |
| 71 | |
| 72 | // automatically extend the palette creating a brighter copy for highlights |
| 73 | #define VIDEO_HAS_HIGHLIGHTS 0x0020 |
| 74 | |
| 75 | // Mish 181099: See comments in video/generic.c for details |
| 76 | #define VIDEO_BUFFERS_SPRITERAM 0x0040 |
| 77 | |
| 78 | // force VIDEO_UPDATE to be called even for skipped frames |
| 79 | #define VIDEO_ALWAYS_UPDATE 0x0080 |
| 80 | |
| 81 | // calls VIDEO_UPDATE for every visible scanline, even for skipped frames |
| 82 | #define VIDEO_UPDATE_SCANLINE 0x0100 |
| 83 | |
| 84 | |
| 85 | |
| 50 | 86 | #define NVRAM_HANDLER_NAME(name) nvram_handler_##name |
| 51 | 87 | #define NVRAM_HANDLER(name) void NVRAM_HANDLER_NAME(name)(running_machine *machine, mame_file *file, int read_or_write) |
| 52 | 88 | #define NVRAM_HANDLER_CALL(name) NVRAM_HANDLER_NAME(name)(machine, file, read_or_write) |
| r8910 | r8911 | |
| 106 | 142 | #define video_update_0 NULL |
| 107 | 143 | |
| 108 | 144 | |
| 145 | |
| 146 | //************************************************************************** |
| 147 | // TYPE DEFINITIONS |
| 148 | //************************************************************************** |
| 149 | |
| 150 | // forward references |
| 151 | struct gfx_decode_entry; |
| 109 | 152 | class driver_data_t; |
| 110 | 153 | |
| 154 | |
| 155 | |
| 156 | // various callback functions |
| 111 | 157 | typedef void (*nvram_handler_func)(running_machine *machine, mame_file *file, int read_or_write); |
| 112 | 158 | typedef void (*memcard_handler_func)(running_machine *machine, mame_file *file, int action); |
| 113 | 159 | typedef void (*machine_start_func)(running_machine *machine); |
| r8910 | r8911 | |
| 118 | 164 | typedef void (*video_reset_func)(running_machine *machine); |
| 119 | 165 | typedef void (*palette_init_func)(running_machine *machine, const UINT8 *color_prom); |
| 120 | 166 | typedef void (*video_eof_func)(running_machine *machine); |
| 121 | | typedef UINT32 (*video_update_func)(device_t *screen, bitmap_t *bitmap, const rectangle *cliprect); |
| 167 | typedef UINT32 (*video_update_func)(screen_device *screen, bitmap_t *bitmap, const rectangle *cliprect); |
| 122 | 168 | typedef driver_data_t *(*driver_data_alloc_func)(running_machine &machine); |
| 123 | 169 | |
| 124 | 170 | |
| 125 | 171 | |
| 126 | | /*************************************************************************** |
| 127 | | CONSTANTS |
| 128 | | ***************************************************************************/ |
| 172 | // ======================> address_map_entry |
| 129 | 173 | |
| 130 | | // by convention, tags should all lowercase and between 2-15 characters |
| 131 | | #define MIN_TAG_LENGTH 2 |
| 132 | | #define MAX_TAG_LENGTH 15 |
| 133 | | |
| 134 | | |
| 135 | | // token types |
| 136 | | enum |
| 137 | | { |
| 138 | | MCONFIG_TOKEN_INVALID, |
| 139 | | MCONFIG_TOKEN_END, |
| 140 | | MCONFIG_TOKEN_INCLUDE, |
| 141 | | |
| 142 | | MCONFIG_TOKEN_DRIVER_DATA, |
| 143 | | MCONFIG_TOKEN_QUANTUM_TIME, |
| 144 | | MCONFIG_TOKEN_QUANTUM_PERFECT_CPU, |
| 145 | | MCONFIG_TOKEN_WATCHDOG_VBLANK, |
| 146 | | MCONFIG_TOKEN_WATCHDOG_TIME, |
| 147 | | |
| 148 | | MCONFIG_TOKEN_MACHINE_START, |
| 149 | | MCONFIG_TOKEN_MACHINE_RESET, |
| 150 | | MCONFIG_TOKEN_NVRAM_HANDLER, |
| 151 | | MCONFIG_TOKEN_MEMCARD_HANDLER, |
| 152 | | |
| 153 | | MCONFIG_TOKEN_VIDEO_ATTRIBUTES, |
| 154 | | MCONFIG_TOKEN_GFXDECODE, |
| 155 | | MCONFIG_TOKEN_PALETTE_LENGTH, |
| 156 | | MCONFIG_TOKEN_DEFAULT_LAYOUT, |
| 157 | | |
| 158 | | MCONFIG_TOKEN_PALETTE_INIT, |
| 159 | | MCONFIG_TOKEN_VIDEO_START, |
| 160 | | MCONFIG_TOKEN_VIDEO_RESET, |
| 161 | | MCONFIG_TOKEN_VIDEO_EOF, |
| 162 | | MCONFIG_TOKEN_VIDEO_UPDATE, |
| 163 | | |
| 164 | | MCONFIG_TOKEN_SOUND_START, |
| 165 | | MCONFIG_TOKEN_SOUND_RESET, |
| 166 | | |
| 167 | | MCONFIG_TOKEN_DEVICE_ADD, |
| 168 | | MCONFIG_TOKEN_DEVICE_REPLACE, |
| 169 | | MCONFIG_TOKEN_DEVICE_REMOVE, |
| 170 | | MCONFIG_TOKEN_DEVICE_MODIFY, |
| 171 | | |
| 172 | | // device-specific tokens |
| 173 | | MCONFIG_TOKEN_DEVICE_CLOCK, |
| 174 | | MCONFIG_TOKEN_DEVICE_CONFIG, |
| 175 | | MCONFIG_TOKEN_DEVICE_INLINE_DATA16, |
| 176 | | MCONFIG_TOKEN_DEVICE_INLINE_DATA32, |
| 177 | | MCONFIG_TOKEN_DEVICE_INLINE_DATA64, |
| 178 | | |
| 179 | | // execute interface-specific tokens |
| 180 | | MCONFIG_TOKEN_DIEXEC_DISABLE, |
| 181 | | MCONFIG_TOKEN_DIEXEC_VBLANK_INT, |
| 182 | | MCONFIG_TOKEN_DIEXEC_PERIODIC_INT, |
| 183 | | |
| 184 | | // memory interface-specific tokens |
| 185 | | MCONFIG_TOKEN_DIMEMORY_MAP, |
| 186 | | |
| 187 | | // sound interface-specific tokens |
| 188 | | MCONFIG_TOKEN_DISOUND_ROUTE, |
| 189 | | MCONFIG_TOKEN_DISOUND_RESET, |
| 190 | | |
| 191 | | // legacy custom tokens |
| 192 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1, |
| 193 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_2, |
| 194 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_3, |
| 195 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_4, |
| 196 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_5, |
| 197 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_6, |
| 198 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_7, |
| 199 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_8, |
| 200 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_9, |
| 201 | | |
| 202 | | MCONFIG_TOKEN_DEVICE_CONFIG_DATA32, |
| 203 | | MCONFIG_TOKEN_DEVICE_CONFIG_DATA64, |
| 204 | | MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32, |
| 205 | | MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE, |
| 206 | | }; |
| 207 | | |
| 208 | | |
| 209 | | // ----- flags for video_attributes ----- |
| 210 | | |
| 211 | | // should VIDEO_UPDATE by called at the start of VBLANK or at the end? |
| 212 | | #define VIDEO_UPDATE_BEFORE_VBLANK 0x0000 |
| 213 | | #define VIDEO_UPDATE_AFTER_VBLANK 0x0004 |
| 214 | | |
| 215 | | // indicates VIDEO_UPDATE will add container bits its |
| 216 | | #define VIDEO_SELF_RENDER 0x0008 |
| 217 | | |
| 218 | | // automatically extend the palette creating a darker copy for shadows |
| 219 | | #define VIDEO_HAS_SHADOWS 0x0010 |
| 220 | | |
| 221 | | // automatically extend the palette creating a brighter copy for highlights |
| 222 | | #define VIDEO_HAS_HIGHLIGHTS 0x0020 |
| 223 | | |
| 224 | | // Mish 181099: See comments in video/generic.c for details |
| 225 | | #define VIDEO_BUFFERS_SPRITERAM 0x0040 |
| 226 | | |
| 227 | | // force VIDEO_UPDATE to be called even for skipped frames |
| 228 | | #define VIDEO_ALWAYS_UPDATE 0x0080 |
| 229 | | |
| 230 | | // calls VIDEO_UPDATE for every visible scanline, even for skipped frames |
| 231 | | #define VIDEO_UPDATE_SCANLINE 0x0100 |
| 232 | | |
| 233 | | |
| 234 | | |
| 235 | | /*************************************************************************** |
| 236 | | TYPE DEFINITIONS |
| 237 | | ***************************************************************************/ |
| 238 | | |
| 239 | | // forward references |
| 240 | | struct gfx_decode_entry; |
| 241 | | |
| 242 | | |
| 174 | // machine configuration definition |
| 243 | 175 | class machine_config |
| 244 | 176 | { |
| 245 | 177 | DISABLE_COPYING(machine_config); |
| r8910 | r8911 | |
| 247 | 179 | friend class running_machine; |
| 248 | 180 | |
| 249 | 181 | public: |
| 250 | | machine_config(const machine_config_token *tokens); |
| 182 | machine_config(machine_config_constructor constructor); |
| 251 | 183 | ~machine_config(); |
| 252 | 184 | |
| 253 | | void detokenize(const machine_config_token *tokens, const device_config *owner = NULL); |
| 254 | | |
| 255 | 185 | driver_data_alloc_func m_driver_data_alloc; // allocator for driver data |
| 256 | 186 | |
| 257 | 187 | attotime m_minimum_quantum; // minimum scheduling quantum |
| r8910 | r8911 | |
| 281 | 211 | |
| 282 | 212 | device_config_list m_devicelist; // list of device configs |
| 283 | 213 | |
| 214 | // helpers during configuration; not for general use |
| 215 | device_config *device_add(device_config *owner, const char *tag, device_type type, UINT32 clock); |
| 216 | device_config *device_replace(device_config *owner, const char *tag, device_type type, UINT32 clock); |
| 217 | device_config *device_remove(device_config *owner, const char *tag); |
| 218 | device_config *device_find(device_config *owner, const char *tag); |
| 219 | |
| 284 | 220 | private: |
| 285 | 221 | int m_parse_level; // nested parsing level |
| 286 | 222 | }; |
| 287 | 223 | |
| 288 | 224 | |
| 289 | 225 | |
| 290 | | /*************************************************************************** |
| 291 | | MACROS FOR BUILDING MACHINE DRIVERS |
| 292 | | ***************************************************************************/ |
| 226 | //************************************************************************** |
| 227 | // MACHINE CONFIG MACROS |
| 228 | //************************************************************************** |
| 293 | 229 | |
| 294 | | // this type is used to encode machine configuration definitions |
| 295 | | union machine_config_token |
| 296 | | { |
| 297 | | TOKEN_COMMON_FIELDS |
| 298 | | const machine_config_token *tokenptr; |
| 299 | | const gfx_decode_entry *gfxdecode; |
| 300 | | address_map_constructor addrmap; |
| 301 | | device_type devtype; |
| 302 | | nvram_handler_func nvram_handler; |
| 303 | | memcard_handler_func memcard_handler; |
| 304 | | machine_start_func machine_start; |
| 305 | | machine_reset_func machine_reset; |
| 306 | | sound_start_func sound_start; |
| 307 | | sound_reset_func sound_reset; |
| 308 | | video_start_func video_start; |
| 309 | | video_reset_func video_reset; |
| 310 | | palette_init_func palette_init; |
| 311 | | video_eof_func video_eof; |
| 312 | | video_update_func video_update; |
| 313 | | device_interrupt_func cpu_interrupt; |
| 314 | | driver_data_alloc_func driver_data_alloc; |
| 315 | | }; |
| 316 | | |
| 317 | | |
| 318 | | // helper macro for returning the size of a field within a struct; similar to offsetof() |
| 319 | | #define structsizeof(_struct, _field) sizeof(((_struct *)NULL)->_field) |
| 320 | | |
| 321 | | #define DEVCONFIG_OFFSETOF(_class, _member) \ |
| 322 | | ((FPTR)&static_cast<_class *>(reinterpret_cast<device_config *>(1000000))->_member - 1000000) |
| 323 | | |
| 324 | | #define DEVCONFIG_SIZEOF(_class, _member) \ |
| 325 | | sizeof(reinterpret_cast<_class *>(NULL)->_member) |
| 326 | | |
| 327 | | |
| 328 | 230 | // start/end tags for the machine driver |
| 329 | | #define MACHINE_DRIVER_NAME(_name) \ |
| 330 | | machine_config_##_name |
| 231 | #define MACHINE_DRIVER_NAME(_name) construct_machine_config_##_name |
| 331 | 232 | |
| 332 | 233 | #define MACHINE_DRIVER_START(_name) \ |
| 333 | | const machine_config_token MACHINE_DRIVER_NAME(_name)[] = { |
| 234 | void MACHINE_DRIVER_NAME(_name)(machine_config &config, device_config *owner) \ |
| 235 | { \ |
| 236 | device_config *device = NULL; \ |
| 237 | const char *tag; \ |
| 238 | astring tempstring; \ |
| 239 | (void)device; \ |
| 240 | (void)tag; \ |
| 334 | 241 | |
| 335 | 242 | #define MACHINE_DRIVER_END \ |
| 336 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_END, 8) }; |
| 243 | } |
| 337 | 244 | |
| 338 | 245 | // use this to declare external references to a machine driver |
| 339 | 246 | #define MACHINE_DRIVER_EXTERN(_name) \ |
| 340 | | extern const machine_config_token MACHINE_DRIVER_NAME(_name)[] |
| 247 | extern void MACHINE_DRIVER_NAME(_name)(machine_config &config, device_config *owner) |
| 341 | 248 | |
| 342 | 249 | |
| 343 | 250 | // importing data from other machine drivers |
| 344 | 251 | #define MDRV_IMPORT_FROM(_name) \ |
| 345 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_INCLUDE, 8), \ |
| 346 | | TOKEN_PTR(tokenptr, MACHINE_DRIVER_NAME(_name)), |
| 252 | MACHINE_DRIVER_NAME(_name)(config, owner); |
| 347 | 253 | |
| 348 | 254 | |
| 349 | 255 | // core parameters |
| 350 | 256 | #define MDRV_DRIVER_DATA(_class) \ |
| 351 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DRIVER_DATA, 8), \ |
| 352 | | TOKEN_PTR(m_driver_data_alloc, _class::alloc), |
| 257 | config.m_driver_data_alloc = &_class::alloc; \ |
| 353 | 258 | |
| 354 | 259 | #define MDRV_QUANTUM_TIME(_time) \ |
| 355 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_QUANTUM_TIME, 8), \ |
| 356 | | TOKEN_UINT64(UINT64_ATTOTIME_IN_##_time), |
| 260 | config.m_minimum_quantum = ATTOTIME_IN_##_time; \ |
| 357 | 261 | |
| 358 | 262 | #define MDRV_QUANTUM_PERFECT_CPU(_cputag) \ |
| 359 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_QUANTUM_PERFECT_CPU, 8), \ |
| 360 | | TOKEN_STRING(_cputag), |
| 263 | config.m_perfect_cpu_quantum = _cputag; \ |
| 361 | 264 | |
| 362 | 265 | #define MDRV_WATCHDOG_VBLANK_INIT(_count) \ |
| 363 | | TOKEN_UINT32_PACK2(MCONFIG_TOKEN_WATCHDOG_VBLANK, 8, _count, 24), |
| 266 | config.m_watchdog_vblank_count = _count; \ |
| 364 | 267 | |
| 365 | 268 | #define MDRV_WATCHDOG_TIME_INIT(_time) \ |
| 366 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_WATCHDOG_TIME, 8), \ |
| 367 | | TOKEN_UINT64(UINT64_ATTOTIME_IN_##_time), |
| 269 | config.m_watchdog_time = ATTOTIME_IN_##_time; \ |
| 368 | 270 | |
| 369 | 271 | |
| 370 | 272 | // core functions |
| 371 | 273 | #define MDRV_MACHINE_START(_func) \ |
| 372 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MACHINE_START, 8), \ |
| 373 | | TOKEN_PTR(machine_start, MACHINE_START_NAME(_func)), |
| 274 | config.m_machine_start = MACHINE_START_NAME(_func); \ |
| 374 | 275 | |
| 375 | 276 | #define MDRV_MACHINE_RESET(_func) \ |
| 376 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MACHINE_RESET, 8), \ |
| 377 | | TOKEN_PTR(machine_reset, MACHINE_RESET_NAME(_func)), |
| 277 | config.m_machine_reset = MACHINE_RESET_NAME(_func); \ |
| 378 | 278 | |
| 379 | 279 | #define MDRV_NVRAM_HANDLER(_func) \ |
| 380 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_NVRAM_HANDLER, 8), \ |
| 381 | | TOKEN_PTR(nvram_handler, NVRAM_HANDLER_NAME(_func)), |
| 280 | config.m_nvram_handler = NVRAM_HANDLER_NAME(_func); \ |
| 382 | 281 | |
| 383 | 282 | #define MDRV_MEMCARD_HANDLER(_func) \ |
| 384 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MEMCARD_HANDLER, 8), \ |
| 385 | | TOKEN_PTR(memcard_handler, MEMCARD_HANDLER_NAME(_func)), |
| 283 | config.m_memcard_handler = MEMCARD_HANDLER_NAME(_func); \ |
| 386 | 284 | |
| 387 | 285 | |
| 388 | 286 | // core video parameters |
| 389 | 287 | #define MDRV_VIDEO_ATTRIBUTES(_flags) \ |
| 390 | | TOKEN_UINT32_PACK2(MCONFIG_TOKEN_VIDEO_ATTRIBUTES, 8, _flags, 24), |
| 288 | config.m_video_attributes = _flags; \ |
| 391 | 289 | |
| 392 | 290 | #define MDRV_GFXDECODE(_gfx) \ |
| 393 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_GFXDECODE, 8), \ |
| 394 | | TOKEN_PTR(gfxdecode, GFXDECODE_NAME(_gfx)), |
| 291 | config.m_gfxdecodeinfo = GFXDECODE_NAME(_gfx); \ |
| 395 | 292 | |
| 396 | 293 | #define MDRV_PALETTE_LENGTH(_length) \ |
| 397 | | TOKEN_UINT32_PACK2(MCONFIG_TOKEN_PALETTE_LENGTH, 8, _length, 24), |
| 294 | config.m_total_colors = _length; \ |
| 398 | 295 | |
| 399 | 296 | #define MDRV_DEFAULT_LAYOUT(_layout) \ |
| 400 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEFAULT_LAYOUT, 8), \ |
| 401 | | TOKEN_STRING(&(_layout)[0]), |
| 297 | config.m_default_layout = &(_layout)[0]; \ |
| 402 | 298 | |
| 403 | 299 | |
| 404 | 300 | // core video functions |
| 405 | 301 | #define MDRV_PALETTE_INIT(_func) \ |
| 406 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_PALETTE_INIT, 8), \ |
| 407 | | TOKEN_PTR(palette_init, PALETTE_INIT_NAME(_func)), |
| 302 | config.m_init_palette = PALETTE_INIT_NAME(_func); \ |
| 408 | 303 | |
| 409 | 304 | #define MDRV_VIDEO_START(_func) \ |
| 410 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_START, 8), \ |
| 411 | | TOKEN_PTR(video_start, VIDEO_START_NAME(_func)), |
| 305 | config.m_video_start = VIDEO_START_NAME(_func); \ |
| 412 | 306 | |
| 413 | 307 | #define MDRV_VIDEO_RESET(_func) \ |
| 414 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_RESET, 8), \ |
| 415 | | TOKEN_PTR(video_reset, VIDEO_RESET_NAME(_func)), |
| 308 | config.m_video_reset = VIDEO_RESET_NAME(_func); \ |
| 416 | 309 | |
| 417 | 310 | #define MDRV_VIDEO_EOF(_func) \ |
| 418 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_EOF, 8), \ |
| 419 | | TOKEN_PTR(video_eof, VIDEO_EOF_NAME(_func)), |
| 311 | config.m_video_eof = VIDEO_EOF_NAME(_func); \ |
| 420 | 312 | |
| 421 | 313 | #define MDRV_VIDEO_UPDATE(_func) \ |
| 422 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_UPDATE, 8), \ |
| 423 | | TOKEN_PTR(video_update, VIDEO_UPDATE_NAME(_func)), |
| 314 | config.m_video_update = VIDEO_UPDATE_NAME(_func); \ |
| 424 | 315 | |
| 425 | 316 | |
| 426 | 317 | // core sound functions |
| 427 | 318 | #define MDRV_SOUND_START(_func) \ |
| 428 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_START, 8), \ |
| 429 | | TOKEN_PTR(sound_start, SOUND_START_NAME(_func)), |
| 319 | config.m_sound_start = SOUND_START_NAME(_func); \ |
| 430 | 320 | |
| 431 | 321 | #define MDRV_SOUND_RESET(_func) \ |
| 432 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_RESET, 8), \ |
| 433 | | TOKEN_PTR(sound_reset, SOUND_RESET_NAME(_func)), |
| 322 | config.m_sound_reset = SOUND_RESET_NAME(_func); \ |
| 434 | 323 | |
| 435 | 324 | |
| 436 | 325 | // add/remove devices |
| 437 | 326 | #define MDRV_DEVICE_ADD(_tag, _type, _clock) \ |
| 438 | | TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_ADD, 8, _clock, 32), \ |
| 439 | | TOKEN_PTR(devtype, _type), \ |
| 440 | | TOKEN_STRING(_tag), |
| 327 | device = config.device_add(owner, _tag, _type, _clock); \ |
| 441 | 328 | |
| 442 | 329 | #define MDRV_DEVICE_REPLACE(_tag, _type, _clock) \ |
| 443 | | TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_REPLACE, 8, _clock, 32), \ |
| 444 | | TOKEN_PTR(devtype, _type), \ |
| 445 | | TOKEN_STRING(_tag), |
| 330 | device = config.device_replace(owner, _tag, _type, _clock); \ |
| 446 | 331 | |
| 447 | 332 | #define MDRV_DEVICE_REMOVE(_tag) \ |
| 448 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_REMOVE, 8), \ |
| 449 | | TOKEN_STRING(_tag), |
| 333 | device = config.device_remove(owner, _tag); \ |
| 450 | 334 | |
| 451 | 335 | #define MDRV_DEVICE_MODIFY(_tag) \ |
| 452 | | TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_MODIFY, 8), \ |
| 453 | | TOKEN_STRING(_tag), |
| 336 | device = config.device_find(owner, _tag); \ |
| 454 | 337 | |
| 455 | 338 | |
| 456 | 339 | #endif /* __MCONFIG_H__ */ |