src/mess/machine/z80sti.c
| r4946 | r4947 | |
| 2 | 2 | |
| 3 | 3 | Mostek Z80STI Serial Timer Interrupt Controller emulation |
| 4 | 4 | |
| 5 | | Copyright (c) 2008, The MESS Team. |
| 5 | Copyright (c) 2009, The MESS Team. |
| 6 | 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | 7 | |
| 8 | 8 | ***************************************************************************/ |
| r4946 | r4947 | |
| 48 | 48 | Z80STI_REGISTER_UDR |
| 49 | 49 | }; |
| 50 | 50 | |
| 51 | enum |
| 52 | { |
| 53 | Z80STI_TIMER_A = 0, |
| 54 | Z80STI_TIMER_B, |
| 55 | Z80STI_TIMER_C, |
| 56 | Z80STI_TIMER_D, |
| 57 | Z80STI_MAX_TIMERS |
| 58 | }; |
| 59 | |
| 51 | 60 | /*************************************************************************** |
| 52 | 61 | TYPE DEFINITIONS |
| 53 | 62 | ***************************************************************************/ |
| r4946 | r4947 | |
| 63 | 72 | devcb_resolved_write_line out_tbo_func; |
| 64 | 73 | devcb_resolved_write_line out_tco_func; |
| 65 | 74 | devcb_resolved_write_line out_tdo_func; |
| 66 | | devcb_resolved_write_line out_irq_func; |
| 75 | devcb_resolved_write_line out_int_func; |
| 76 | |
| 77 | /* I/O state */ |
| 78 | UINT8 gpip; /* general purpose I/O register */ |
| 79 | UINT8 aer; /* active edge register */ |
| 80 | UINT8 ddr; /* data direction register */ |
| 81 | |
| 82 | /* interrupt state */ |
| 83 | UINT16 ier; /* interrupt enable register */ |
| 84 | UINT16 ipr; /* interrupt pending register */ |
| 85 | UINT16 isr; /* interrupt in-service register */ |
| 86 | UINT16 imr; /* interrupt mask register */ |
| 87 | UINT8 pvr; /* */ |
| 88 | |
| 89 | /* timer state */ |
| 90 | UINT8 tabc; /* */ |
| 91 | UINT8 tcdc; /* */ |
| 92 | UINT8 tdr[Z80STI_MAX_TIMERS]; /* timer data registers */ |
| 93 | UINT8 tmc[Z80STI_MAX_TIMERS]; /* timer main counters */ |
| 94 | |
| 95 | /* serial state */ |
| 96 | UINT8 scr; /* synchronous character register */ |
| 97 | UINT8 ucr; /* USART control register */ |
| 98 | UINT8 tsr; /* transmitter status register */ |
| 99 | UINT8 rsr; /* receiver status register */ |
| 100 | UINT8 udr; /* USART data register */ |
| 101 | |
| 102 | /* timers */ |
| 103 | emu_timer *timer[Z80STI_MAX_TIMERS]; /* counter timers */ |
| 104 | emu_timer *rx_timer; /* serial receive timer */ |
| 105 | emu_timer *tx_timer; /* serial transmit timer */ |
| 67 | 106 | }; |
| 68 | 107 | |
| 69 | 108 | /*************************************************************************** |
| r4946 | r4947 | |
| 97 | 136 | ***************************************************************************/ |
| 98 | 137 | |
| 99 | 138 | /*------------------------------------------------- |
| 139 | check_interrupts - set the interrupt request |
| 140 | line state |
| 141 | -------------------------------------------------*/ |
| 142 | #ifdef UNUSED_CODE |
| 143 | static void check_interrupts(const device_config *device) |
| 144 | { |
| 145 | z80sti_t *z80sti = get_safe_token(device); |
| 146 | |
| 147 | if (z80sti->ipr & z80sti->imr) |
| 148 | { |
| 149 | devcb_call_write_line(&z80sti->out_int_func, ASSERT_LINE); |
| 150 | } |
| 151 | else |
| 152 | { |
| 153 | devcb_call_write_line(&z80sti->out_int_func, CLEAR_LINE); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /*------------------------------------------------- |
| 158 | take_interrupt - mark an interrupt pending |
| 159 | -------------------------------------------------*/ |
| 160 | |
| 161 | static void take_interrupt(const device_config *device, UINT16 mask) |
| 162 | { |
| 163 | z80sti_t *z80sti = get_safe_token(device); |
| 164 | |
| 165 | z80sti->ipr |= mask; |
| 166 | |
| 167 | check_interrupts(device); |
| 168 | } |
| 169 | #endif |
| 170 | /*------------------------------------------------- |
| 171 | serial_receive - receive serial bit |
| 172 | -------------------------------------------------*/ |
| 173 | |
| 174 | static void serial_receive(z80sti_t *z80sti) |
| 175 | { |
| 176 | } |
| 177 | |
| 178 | /*------------------------------------------------- |
| 179 | TIMER_CALLBACK( rx_tick ) |
| 180 | -------------------------------------------------*/ |
| 181 | |
| 182 | static TIMER_CALLBACK( rx_tick ) |
| 183 | { |
| 184 | const device_config *device = ptr; |
| 185 | z80sti_t *z80sti = get_safe_token(device); |
| 186 | |
| 187 | serial_receive(z80sti); |
| 188 | } |
| 189 | |
| 190 | /*------------------------------------------------- |
| 191 | serial_transmit - transmit serial bit |
| 192 | -------------------------------------------------*/ |
| 193 | |
| 194 | static void serial_transmit(z80sti_t *z80sti) |
| 195 | { |
| 196 | } |
| 197 | |
| 198 | /*------------------------------------------------- |
| 199 | TIMER_CALLBACK( tx_tick ) |
| 200 | -------------------------------------------------*/ |
| 201 | |
| 202 | static TIMER_CALLBACK( tx_tick ) |
| 203 | { |
| 204 | const device_config *device = ptr; |
| 205 | z80sti_t *z80sti = get_safe_token(device); |
| 206 | |
| 207 | serial_transmit(z80sti); |
| 208 | } |
| 209 | |
| 210 | /*------------------------------------------------- |
| 100 | 211 | z80sti_r - register read |
| 101 | 212 | -------------------------------------------------*/ |
| 102 | 213 | |
| r4946 | r4947 | |
| 119 | 230 | |
| 120 | 231 | WRITE_LINE_DEVICE_HANDLER( z80sti_rc_w ) |
| 121 | 232 | { |
| 233 | z80sti_t *z80sti = get_safe_token(device); |
| 234 | |
| 235 | if (state) |
| 236 | { |
| 237 | serial_receive(z80sti); |
| 238 | } |
| 122 | 239 | } |
| 123 | 240 | |
| 124 | 241 | /*------------------------------------------------- |
| r4946 | r4947 | |
| 127 | 244 | |
| 128 | 245 | WRITE_LINE_DEVICE_HANDLER( z80sti_tc_w ) |
| 129 | 246 | { |
| 247 | z80sti_t *z80sti = get_safe_token(device); |
| 248 | |
| 249 | if (state) |
| 250 | { |
| 251 | serial_transmit(z80sti); |
| 252 | } |
| 130 | 253 | } |
| 131 | 254 | |
| 132 | 255 | /*------------------------------------------------- |
| 256 | timer_count - timer count down |
| 257 | -------------------------------------------------*/ |
| 258 | |
| 259 | static void timer_count(z80sti_t *z80sti, int index) |
| 260 | { |
| 261 | } |
| 262 | |
| 263 | /*------------------------------------------------- |
| 264 | TIMER_CALLBACK( timer_a ) |
| 265 | -------------------------------------------------*/ |
| 266 | |
| 267 | static TIMER_CALLBACK( timer_a ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_A); } |
| 268 | static TIMER_CALLBACK( timer_b ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_B); } |
| 269 | static TIMER_CALLBACK( timer_c ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_C); } |
| 270 | static TIMER_CALLBACK( timer_d ) { z80sti_t *z80sti = get_safe_token(ptr); timer_count(z80sti, Z80STI_TIMER_D); } |
| 271 | |
| 272 | /*------------------------------------------------- |
| 133 | 273 | z80sti_i0_w - input 0 write |
| 134 | 274 | -------------------------------------------------*/ |
| 135 | 275 | |
| r4946 | r4947 | |
| 237 | 377 | devcb_resolve_write_line(&z80sti->out_tbo_func, &intf->out_tbo_func, device); |
| 238 | 378 | devcb_resolve_write_line(&z80sti->out_tco_func, &intf->out_tco_func, device); |
| 239 | 379 | devcb_resolve_write_line(&z80sti->out_tdo_func, &intf->out_tdo_func, device); |
| 240 | | devcb_resolve_write_line(&z80sti->out_irq_func, &intf->out_irq_func, device); |
| 380 | devcb_resolve_write_line(&z80sti->out_int_func, &intf->out_int_func, device); |
| 381 | |
| 382 | /* create the counter timers */ |
| 383 | z80sti->timer[Z80STI_TIMER_A] = timer_alloc(device->machine, timer_a, (void *)device); |
| 384 | z80sti->timer[Z80STI_TIMER_B] = timer_alloc(device->machine, timer_b, (void *)device); |
| 385 | z80sti->timer[Z80STI_TIMER_C] = timer_alloc(device->machine, timer_c, (void *)device); |
| 386 | z80sti->timer[Z80STI_TIMER_D] = timer_alloc(device->machine, timer_d, (void *)device); |
| 387 | |
| 388 | /* create serial receive clock timer */ |
| 389 | if (intf->rx_clock > 0) |
| 390 | { |
| 391 | z80sti->rx_timer = timer_alloc(device->machine, rx_tick, (void *)device); |
| 392 | timer_adjust_periodic(z80sti->rx_timer, attotime_zero, 0, ATTOTIME_IN_HZ(intf->rx_clock)); |
| 393 | } |
| 394 | |
| 395 | /* create serial transmit clock timer */ |
| 396 | if (intf->tx_clock > 0) |
| 397 | { |
| 398 | z80sti->tx_timer = timer_alloc(device->machine, tx_tick, (void *)device); |
| 399 | timer_adjust_periodic(z80sti->tx_timer, attotime_zero, 0, ATTOTIME_IN_HZ(intf->tx_clock)); |
| 400 | } |
| 401 | |
| 402 | /* register for state saving */ |
| 403 | state_save_register_device_item(device, 0, z80sti->gpip); |
| 404 | state_save_register_device_item(device, 0, z80sti->aer); |
| 405 | state_save_register_device_item(device, 0, z80sti->ddr); |
| 406 | state_save_register_device_item(device, 0, z80sti->ier); |
| 407 | state_save_register_device_item(device, 0, z80sti->ipr); |
| 408 | state_save_register_device_item(device, 0, z80sti->isr); |
| 409 | state_save_register_device_item(device, 0, z80sti->imr); |
| 410 | state_save_register_device_item(device, 0, z80sti->pvr); |
| 411 | state_save_register_device_item(device, 0, z80sti->tabc); |
| 412 | state_save_register_device_item(device, 0, z80sti->tcdc); |
| 413 | state_save_register_device_item_array(device, 0, z80sti->tdr); |
| 414 | state_save_register_device_item_array(device, 0, z80sti->tmc); |
| 415 | state_save_register_device_item(device, 0, z80sti->scr); |
| 416 | state_save_register_device_item(device, 0, z80sti->ucr); |
| 417 | state_save_register_device_item(device, 0, z80sti->rsr); |
| 418 | state_save_register_device_item(device, 0, z80sti->tsr); |
| 419 | state_save_register_device_item(device, 0, z80sti->udr); |
| 241 | 420 | } |
| 242 | 421 | |
| 243 | 422 | /*------------------------------------------------- |