src/mess/machine/tms5501.c
| r15385 | r15386 | |
| 29 | 29 | |
| 30 | 30 | #define DEBUG_TMS5501 0 |
| 31 | 31 | |
| 32 | | #define LOG_TMS5501(device, message, data) do { if (DEBUG_TMS5501) logerror ("\nTMS5501 %s: %s %02x", device->tag(), message, data); } while (0) |
| 32 | #define LOG_TMS5501(message, data) do { if (DEBUG_TMS5501) logerror ("\nTMS5501 %s: %s %02x", tag(), message, data); } while (0) |
| 33 | 33 | |
| 34 | 34 | /* status register */ |
| 35 | 35 | #define TMS5501_FRAME_ERROR 0x01 |
| r15385 | r15386 | |
| 63 | 63 | |
| 64 | 64 | #define TMS5501_PIO_INT_7 0x80 |
| 65 | 65 | |
| 66 | // device type definition |
| 67 | const device_type TMS5501 = &device_creator<tms5501_device>; |
| 66 | 68 | |
| 67 | | /*************************************************************************** |
| 68 | | TYPE DEFINITIONS |
| 69 | | ***************************************************************************/ |
| 70 | 69 | |
| 71 | | typedef struct _tms5501_t tms5501_t; |
| 72 | | struct _tms5501_t |
| 73 | | { |
| 74 | | /* internal registers */ |
| 75 | | UINT8 status; /* status register */ |
| 76 | | UINT8 command; /* command register, bits 1-5 are latched */ |
| 70 | static const UINT8 timer_name[] = { TMS5501_TIMER_0_INT, TMS5501_TIMER_1_INT, TMS5501_TIMER_2_INT, TMS5501_TIMER_3_INT, TMS5501_TIMER_4_INT }; |
| 77 | 71 | |
| 78 | | UINT8 sio_rate; /* SIO configuration register */ |
| 79 | | UINT8 sio_input_buffer; /* SIO input buffer */ |
| 80 | | UINT8 sio_output_buffer; /* SIO output buffer */ |
| 81 | | |
| 82 | | UINT8 pio_input_buffer; /* PIO input buffer */ |
| 83 | | UINT8 pio_output_buffer; /* PIO output buffer */ |
| 84 | | |
| 85 | | UINT8 interrupt_mask; /* interrupt mask register */ |
| 86 | | UINT8 pending_interrupts; /* pending interrupts register */ |
| 87 | | UINT8 interrupt_address; /* interrupt vector register */ |
| 88 | | |
| 89 | | UINT8 sensor; /* sensor input */ |
| 90 | | |
| 91 | | /* internal timers */ |
| 92 | | UINT8 timer_counter[5]; |
| 93 | | emu_timer * timer[5]; |
| 94 | | }; |
| 95 | | |
| 96 | | |
| 97 | | |
| 98 | 72 | /*************************************************************************** |
| 99 | | INLINE FUNCTIONS |
| 73 | IMPLEMENTATION |
| 100 | 74 | ***************************************************************************/ |
| 101 | 75 | |
| 102 | | INLINE tms5501_t *get_token(device_t *device) |
| 76 | //------------------------------------------------- |
| 77 | // tms5501_device - constructor |
| 78 | //------------------------------------------------- |
| 79 | |
| 80 | tms5501_device::tms5501_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 81 | : device_t(mconfig, TMS5501, "TMS5501", tag, owner, clock) |
| 103 | 82 | { |
| 104 | | assert(device != NULL); |
| 105 | | assert(device->type() == TMS5501); |
| 106 | | return (tms5501_t *) downcast<legacy_device_base *>(device)->token(); |
| 107 | 83 | } |
| 108 | 84 | |
| 109 | 85 | |
| 110 | | INLINE const tms5501_interface *get_interface(device_t *device) |
| 86 | //------------------------------------------------- |
| 87 | // device_config_complete - perform any |
| 88 | // operations now that the configuration is |
| 89 | // complete |
| 90 | //------------------------------------------------- |
| 91 | |
| 92 | void tms5501_device::device_config_complete() |
| 111 | 93 | { |
| 112 | | assert(device != NULL); |
| 113 | | assert(device->type() == TMS5501); |
| 114 | | return (const tms5501_interface *) device->static_config(); |
| 94 | // inherit a copy of the static data |
| 95 | const tms5501_interface *intf = reinterpret_cast<const tms5501_interface *>(static_config()); |
| 96 | if (intf != NULL) |
| 97 | { |
| 98 | *static_cast<tms5501_interface *>(this) = *intf; |
| 99 | } |
| 100 | // or initialize to defaults if none provided |
| 101 | else |
| 102 | { |
| 103 | m_interrupt_cb = NULL; |
| 104 | memset(&m_pio_read_cb, 0, sizeof(m_pio_read_cb)); |
| 105 | memset(&m_pio_write_cb, 0, sizeof(m_pio_write_cb)); |
| 106 | } |
| 115 | 107 | } |
| 116 | 108 | |
| 117 | | static const UINT8 timer_name[] = { TMS5501_TIMER_0_INT, TMS5501_TIMER_1_INT, TMS5501_TIMER_2_INT, TMS5501_TIMER_3_INT, TMS5501_TIMER_4_INT }; |
| 118 | | |
| 119 | | /*************************************************************************** |
| 120 | | IMPLEMENTATION |
| 121 | | ***************************************************************************/ |
| 122 | | |
| 123 | 109 | /*------------------------------------------------- |
| 124 | 110 | find_first_bit |
| 125 | 111 | -------------------------------------------------*/ |
| 126 | 112 | |
| 127 | | static int find_first_bit(int value) |
| 113 | int tms5501_device::find_first_bit(int value) |
| 128 | 114 | { |
| 129 | 115 | int bit = 0; |
| 130 | 116 | |
| r15385 | r15386 | |
| 140 | 126 | } |
| 141 | 127 | |
| 142 | 128 | |
| 143 | | |
| 144 | 129 | /*------------------------------------------------- |
| 145 | | tms5501_field_interrupts |
| 130 | tms5501_device::field_interrupts() |
| 146 | 131 | -------------------------------------------------*/ |
| 147 | 132 | |
| 148 | | static void tms5501_field_interrupts(device_t *device) |
| 133 | void tms5501_device::field_interrupts() |
| 149 | 134 | { |
| 150 | 135 | static const UINT8 int_vectors[] = { 0xc7, 0xcf, 0xd7, 0xdf, 0xe7, 0xef, 0xf7, 0xff }; |
| 136 | UINT8 current_ints = m_pending_interrupts; |
| 151 | 137 | |
| 152 | | tms5501_t *tms = get_token(device); |
| 153 | | const tms5501_interface *intf = get_interface(device); |
| 154 | | UINT8 current_ints = tms->pending_interrupts; |
| 155 | | |
| 156 | 138 | /* disabling masked interrupts */ |
| 157 | | current_ints &= tms->interrupt_mask; |
| 139 | current_ints &= m_interrupt_mask; |
| 158 | 140 | |
| 159 | | LOG_TMS5501(device, "Pending interrupts", tms->pending_interrupts); |
| 160 | | LOG_TMS5501(device, "Interrupt mask", tms->interrupt_mask); |
| 161 | | LOG_TMS5501(device, "Current interrupts", current_ints); |
| 141 | LOG_TMS5501("Pending interrupts", m_pending_interrupts); |
| 142 | LOG_TMS5501("Interrupt mask", m_interrupt_mask); |
| 143 | LOG_TMS5501("Current interrupts", current_ints); |
| 162 | 144 | |
| 163 | 145 | if (current_ints) |
| 164 | 146 | { |
| 165 | 147 | /* selecting interrupt with highest priority */ |
| 166 | 148 | int level = find_first_bit(current_ints); |
| 167 | | LOG_TMS5501(device, "Interrupt level", level); |
| 149 | LOG_TMS5501("Interrupt level", level); |
| 168 | 150 | |
| 169 | 151 | /* resetting proper bit in pending interrupts register */ |
| 170 | | tms->pending_interrupts &= ~(1<<level); |
| 152 | m_pending_interrupts &= ~(1<<level); |
| 171 | 153 | |
| 172 | 154 | /* selecting interrupt vector */ |
| 173 | | tms->interrupt_address = int_vectors[level]; |
| 174 | | LOG_TMS5501(device, "Interrupt vector", int_vectors[level]); |
| 155 | m_interrupt_address = int_vectors[level]; |
| 156 | LOG_TMS5501("Interrupt vector", int_vectors[level]); |
| 175 | 157 | |
| 176 | | if ((tms->command & TMS5501_INT_ACK_ENABLE)) |
| 158 | if ((m_command & TMS5501_INT_ACK_ENABLE)) |
| 177 | 159 | { |
| 178 | | if (intf->interrupt_callback) |
| 179 | | (*intf->interrupt_callback)(device, 1, int_vectors[level]); |
| 160 | if (m_interrupt_cb) |
| 161 | (m_interrupt_cb)(*this, 1, int_vectors[level]); |
| 180 | 162 | } |
| 181 | 163 | else |
| 182 | | tms->status |= TMS5501_INTERRUPT_PENDING; |
| 164 | m_status |= TMS5501_INTERRUPT_PENDING; |
| 183 | 165 | } |
| 184 | 166 | else |
| 185 | 167 | { |
| 186 | | if ((tms->command & TMS5501_INT_ACK_ENABLE)) |
| 168 | if ((m_command & TMS5501_INT_ACK_ENABLE)) |
| 187 | 169 | { |
| 188 | | if (intf->interrupt_callback) |
| 189 | | (*intf->interrupt_callback)(device, 0, 0); |
| 170 | if (m_interrupt_cb) |
| 171 | (m_interrupt_cb)(*this, 0, 0); |
| 190 | 172 | } |
| 191 | 173 | else |
| 192 | | tms->status &= ~TMS5501_INTERRUPT_PENDING; |
| 174 | m_status &= ~TMS5501_INTERRUPT_PENDING; |
| 193 | 175 | } |
| 194 | 176 | } |
| 195 | 177 | |
| 196 | 178 | |
| 197 | 179 | /*------------------------------------------------- |
| 198 | | tms5501_timer_decrementer |
| 180 | tms5501_device::timer_decrementer |
| 199 | 181 | -------------------------------------------------*/ |
| 200 | 182 | |
| 201 | | static void tms5501_timer_decrementer(device_t *device, UINT8 mask) |
| 183 | void tms5501_device::timer_decrementer(UINT8 mask) |
| 202 | 184 | { |
| 203 | | tms5501_t *tms = get_token(device); |
| 185 | if ((mask != TMS5501_TIMER_4_INT) || ((mask == TMS5501_TIMER_4_INT) && (!(m_command & TMS5501_INT_7_SELECT)))) |
| 186 | m_pending_interrupts |= mask; |
| 204 | 187 | |
| 205 | | if ((mask != TMS5501_TIMER_4_INT) || ((mask == TMS5501_TIMER_4_INT) && (!(tms->command & TMS5501_INT_7_SELECT)))) |
| 206 | | tms->pending_interrupts |= mask; |
| 207 | | |
| 208 | | tms5501_field_interrupts(device); |
| 188 | field_interrupts(); |
| 209 | 189 | } |
| 210 | 190 | |
| 211 | 191 | |
| 212 | 192 | /*------------------------------------------------- |
| 213 | | TIMER_CALLBACK(tms5501_timer_decrementer_callback) |
| 193 | tms5501_device::timer_reload |
| 214 | 194 | -------------------------------------------------*/ |
| 215 | 195 | |
| 216 | | static TIMER_CALLBACK(tms5501_timer_decrementer_callback) |
| 196 | void tms5501_device::timer_reload(int timer) |
| 217 | 197 | { |
| 218 | | device_t *device = (device_t *) ptr; |
| 219 | | UINT8 mask = param; |
| 220 | | |
| 221 | | tms5501_timer_decrementer(device, mask); |
| 222 | | } |
| 223 | | |
| 224 | | |
| 225 | | /*------------------------------------------------- |
| 226 | | tms5501_timer_reload |
| 227 | | -------------------------------------------------*/ |
| 228 | | |
| 229 | | static void tms5501_timer_reload(device_t *device, int timer) |
| 230 | | { |
| 231 | | tms5501_t *tms = get_token(device); |
| 232 | | const tms5501_interface *intf = get_interface(device); |
| 233 | | |
| 234 | | if (tms->timer_counter[timer]) |
| 198 | if (m_timer_counter[timer]) |
| 235 | 199 | { /* reset clock interval */ |
| 236 | | tms->timer[timer]->adjust(attotime::from_double((double) tms->timer_counter[timer] / (intf->clock_rate / 128.)), timer_name[timer], attotime::from_double((double) tms->timer_counter[timer] / (intf->clock_rate / 128.))); |
| 200 | m_timer[timer]->adjust(attotime::from_double((double) m_timer_counter[timer] / (clock() / 128.)), timer_name[timer], attotime::from_double((double) m_timer_counter[timer] / (clock() / 128.))); |
| 237 | 201 | } |
| 238 | 202 | else |
| 239 | 203 | { /* clock interval == 0 -> no timer */ |
| 240 | 204 | switch (timer) |
| 241 | 205 | { |
| 242 | | case 0: tms5501_timer_decrementer(device, TMS5501_TIMER_0_INT); break; |
| 243 | | case 1: tms5501_timer_decrementer(device, TMS5501_TIMER_1_INT); break; |
| 244 | | case 2: tms5501_timer_decrementer(device, TMS5501_TIMER_2_INT); break; |
| 245 | | case 3: tms5501_timer_decrementer(device, TMS5501_TIMER_3_INT); break; |
| 246 | | case 4: tms5501_timer_decrementer(device, TMS5501_TIMER_4_INT); break; |
| 206 | case 0: timer_decrementer(TMS5501_TIMER_0_INT); break; |
| 207 | case 1: timer_decrementer(TMS5501_TIMER_1_INT); break; |
| 208 | case 2: timer_decrementer(TMS5501_TIMER_2_INT); break; |
| 209 | case 3: timer_decrementer(TMS5501_TIMER_3_INT); break; |
| 210 | case 4: timer_decrementer(TMS5501_TIMER_4_INT); break; |
| 247 | 211 | } |
| 248 | | tms->timer[timer]->enable(0); |
| 212 | m_timer[timer]->enable(0); |
| 249 | 213 | } |
| 250 | 214 | } |
| 251 | 215 | |
| r15385 | r15386 | |
| 254 | 218 | DEVICE_RESET( tms5501 ) |
| 255 | 219 | -------------------------------------------------*/ |
| 256 | 220 | |
| 257 | | static DEVICE_RESET( tms5501 ) |
| 221 | void tms5501_device::device_reset() |
| 258 | 222 | { |
| 259 | | tms5501_t *tms = get_token(device); |
| 260 | | int i; |
| 223 | m_status &= ~(TMS5501_RCV_BUFFER_LOADED|TMS5501_FULL_BIT_DETECT|TMS5501_START_BIT_DETECT|TMS5501_OVERRUN_ERROR); |
| 224 | m_status |= TMS5501_XMIT_BUFFER_EMPTY|TMS5501_SERIAL_RCVD; |
| 261 | 225 | |
| 262 | | tms->status &= ~(TMS5501_RCV_BUFFER_LOADED|TMS5501_FULL_BIT_DETECT|TMS5501_START_BIT_DETECT|TMS5501_OVERRUN_ERROR); |
| 263 | | tms->status |= TMS5501_XMIT_BUFFER_EMPTY|TMS5501_SERIAL_RCVD; |
| 226 | m_pending_interrupts = TMS5501_SERIAL_XMIT_EMPTY_INT; |
| 264 | 227 | |
| 265 | | tms->pending_interrupts = TMS5501_SERIAL_XMIT_EMPTY_INT; |
| 266 | | |
| 267 | | for (i=0; i<5; i++) |
| 228 | for (int i=0; i<5; i++) |
| 268 | 229 | { |
| 269 | | tms->timer_counter[i] = 0; |
| 270 | | tms->timer[i]->enable(0); |
| 230 | m_timer_counter[i] = 0; |
| 231 | m_timer[i]->enable(0); |
| 271 | 232 | } |
| 272 | 233 | |
| 273 | | LOG_TMS5501(device, "Reset", 0); |
| 234 | LOG_TMS5501("Reset", 0); |
| 274 | 235 | } |
| 275 | 236 | |
| 276 | 237 | |
| r15385 | r15386 | |
| 278 | 239 | DEVICE_START( tms5501 ) |
| 279 | 240 | -------------------------------------------------*/ |
| 280 | 241 | |
| 281 | | static DEVICE_START( tms5501 ) |
| 242 | void tms5501_device::device_start() |
| 282 | 243 | { |
| 283 | | int i; |
| 284 | | tms5501_t *tms = get_token(device); |
| 244 | // resolve callbacks |
| 245 | m_pio_read_func.resolve(m_pio_read_cb, *this); |
| 246 | m_pio_write_func.resolve(m_pio_write_cb, *this); |
| 285 | 247 | |
| 286 | | for (i = 0; i < 5; i++) |
| 248 | // allocate timers |
| 249 | for (int i = 0; i < 5; i++) |
| 287 | 250 | { |
| 288 | | tms->timer[i] = device->machine().scheduler().timer_alloc(FUNC(tms5501_timer_decrementer_callback), (void *) device); |
| 289 | | tms->timer[i]->set_param(i); |
| 251 | m_timer[i] = timer_alloc(TIMER_DECREMENTER); |
| 252 | m_timer[i]->set_param(i); |
| 290 | 253 | } |
| 291 | 254 | |
| 292 | | tms->interrupt_mask = 0; |
| 293 | | tms->interrupt_address = 0; |
| 255 | m_interrupt_mask = 0; |
| 256 | m_interrupt_address = 0; |
| 294 | 257 | |
| 295 | | tms->sensor = 0; |
| 296 | | tms->sio_rate = 0; |
| 297 | | tms->sio_input_buffer = 0; |
| 298 | | tms->sio_output_buffer = 0; |
| 299 | | tms->pio_input_buffer = 0; |
| 300 | | tms->pio_output_buffer = 0; |
| 258 | m_sensor = 0; |
| 259 | m_sio_rate = 0; |
| 260 | m_sio_input_buffer = 0; |
| 261 | m_sio_output_buffer = 0; |
| 262 | m_pio_input_buffer = 0; |
| 263 | m_pio_output_buffer = 0; |
| 301 | 264 | |
| 302 | | tms->command = 0; |
| 303 | | LOG_TMS5501(device, "Init", 0); |
| 265 | m_command = 0; |
| 266 | LOG_TMS5501("Init", 0); |
| 304 | 267 | } |
| 305 | 268 | |
| 306 | 269 | |
| 270 | //------------------------------------------------- |
| 271 | // device_timer - handler timer events |
| 272 | //------------------------------------------------- |
| 273 | |
| 274 | void tms5501_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 275 | { |
| 276 | switch (id) |
| 277 | { |
| 278 | case TIMER_DECREMENTER: |
| 279 | timer_decrementer((UINT8)param); |
| 280 | break; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | |
| 307 | 285 | /*------------------------------------------------- |
| 308 | | tms5501_set_pio_bit_7 |
| 286 | tms5501_device::set_pio_bit_7 |
| 309 | 287 | -------------------------------------------------*/ |
| 310 | 288 | |
| 311 | | void tms5501_set_pio_bit_7 (device_t *device, UINT8 data) |
| 289 | DECLARE_WRITE_LINE_MEMBER( tms5501_device::set_pio_bit_7 ) |
| 312 | 290 | { |
| 313 | | tms5501_t *tms = get_token(device); |
| 314 | | |
| 315 | | if (tms->command & TMS5501_INT_7_SELECT) |
| 291 | if (m_command & TMS5501_INT_7_SELECT) |
| 316 | 292 | { |
| 317 | | if (!(tms->pio_input_buffer & TMS5501_PIO_INT_7) && data) |
| 318 | | tms->pending_interrupts |= TMS5501_INT_7_INT; |
| 293 | if (!(m_pio_input_buffer & TMS5501_PIO_INT_7) && state) |
| 294 | m_pending_interrupts |= TMS5501_INT_7_INT; |
| 319 | 295 | else |
| 320 | | tms->pending_interrupts &= ~TMS5501_INT_7_INT; |
| 296 | m_pending_interrupts &= ~TMS5501_INT_7_INT; |
| 321 | 297 | } |
| 322 | 298 | |
| 323 | | tms->pio_input_buffer &= ~TMS5501_PIO_INT_7; |
| 324 | | if (data) |
| 325 | | tms->pio_input_buffer |= TMS5501_PIO_INT_7; |
| 299 | m_pio_input_buffer &= ~TMS5501_PIO_INT_7; |
| 300 | if (state) |
| 301 | m_pio_input_buffer |= TMS5501_PIO_INT_7; |
| 326 | 302 | |
| 327 | | if (tms->pending_interrupts & TMS5501_INT_7_INT) |
| 328 | | tms5501_field_interrupts(device); |
| 303 | if (m_pending_interrupts & TMS5501_INT_7_INT) |
| 304 | field_interrupts(); |
| 329 | 305 | } |
| 330 | 306 | |
| 331 | 307 | |
| 332 | 308 | /*------------------------------------------------- |
| 333 | | tms5501_sensor |
| 309 | tms5501_device::set_sensor |
| 334 | 310 | -------------------------------------------------*/ |
| 335 | 311 | |
| 336 | | void tms5501_sensor (device_t *device, UINT8 data) |
| 312 | WRITE_LINE_MEMBER(tms5501_device::set_sensor) |
| 337 | 313 | { |
| 338 | | tms5501_t *tms = get_token(device); |
| 339 | | |
| 340 | | if (!(tms->sensor) && data) |
| 341 | | tms->pending_interrupts |= TMS5501_SENSOR_INT; |
| 314 | if (!(m_sensor) && state) |
| 315 | m_pending_interrupts |= TMS5501_SENSOR_INT; |
| 342 | 316 | else |
| 343 | | tms->pending_interrupts &= ~TMS5501_SENSOR_INT; |
| 317 | m_pending_interrupts &= ~TMS5501_SENSOR_INT; |
| 344 | 318 | |
| 345 | | tms->sensor = data; |
| 319 | m_sensor = state; |
| 346 | 320 | |
| 347 | | if (tms->pending_interrupts &= TMS5501_SENSOR_INT) |
| 348 | | tms5501_field_interrupts(device); |
| 321 | if (m_pending_interrupts &= TMS5501_SENSOR_INT) |
| 322 | field_interrupts(); |
| 349 | 323 | } |
| 350 | 324 | |
| 351 | 325 | |
| r15385 | r15386 | |
| 353 | 327 | READ8_DEVICE_HANDLER( tms5501_r ) |
| 354 | 328 | -------------------------------------------------*/ |
| 355 | 329 | |
| 356 | | READ8_DEVICE_HANDLER( tms5501_r ) |
| 330 | READ8_MEMBER( tms5501_device::read ) |
| 357 | 331 | { |
| 358 | | tms5501_t *tms = get_token(device); |
| 359 | | const tms5501_interface *intf = get_interface(device); |
| 360 | | |
| 361 | 332 | UINT8 data = 0x00; |
| 362 | 333 | offset &= 0x0f; |
| 363 | 334 | |
| 364 | 335 | switch (offset) |
| 365 | 336 | { |
| 366 | 337 | case 0x00: /* Serial input buffer */ |
| 367 | | data = tms->sio_input_buffer; |
| 368 | | tms->status &= ~TMS5501_RCV_BUFFER_LOADED; |
| 369 | | LOG_TMS5501(device, "Reading from serial input buffer", data); |
| 338 | data = m_sio_input_buffer; |
| 339 | m_status &= ~TMS5501_RCV_BUFFER_LOADED; |
| 340 | LOG_TMS5501("Reading from serial input buffer", data); |
| 370 | 341 | break; |
| 371 | 342 | case 0x01: /* PIO input port */ |
| 372 | | if (intf->pio_read_callback) |
| 373 | | data = (*intf->pio_read_callback)(device); |
| 374 | | LOG_TMS5501(device, "Reading from PIO", data); |
| 343 | if (!m_pio_read_func.isnull()) |
| 344 | data = m_pio_read_func(0); |
| 345 | LOG_TMS5501("Reading from PIO", data); |
| 375 | 346 | break; |
| 376 | 347 | case 0x02: /* Interrupt address register */ |
| 377 | | data = tms->interrupt_address; |
| 378 | | tms->status &= ~TMS5501_INTERRUPT_PENDING; |
| 348 | data = m_interrupt_address; |
| 349 | m_status &= ~TMS5501_INTERRUPT_PENDING; |
| 379 | 350 | break; |
| 380 | 351 | case 0x03: /* Status register */ |
| 381 | | data = tms->status; |
| 352 | data = m_status; |
| 382 | 353 | break; |
| 383 | 354 | case 0x04: /* Command register */ |
| 384 | | data = tms->command; |
| 385 | | LOG_TMS5501(device, "Command register read", data); |
| 355 | data = m_command; |
| 356 | LOG_TMS5501("Command register read", data); |
| 386 | 357 | break; |
| 387 | 358 | case 0x05: /* Serial rate register */ |
| 388 | | data = tms->sio_rate; |
| 389 | | LOG_TMS5501(device, "Serial rate read", data); |
| 359 | data = m_sio_rate; |
| 360 | LOG_TMS5501("Serial rate read", data); |
| 390 | 361 | break; |
| 391 | 362 | case 0x06: /* Serial output buffer */ |
| 392 | 363 | case 0x07: /* PIO output */ |
| 393 | 364 | break; |
| 394 | 365 | case 0x08: /* Interrupt mask register */ |
| 395 | | data = tms->interrupt_mask; |
| 396 | | LOG_TMS5501(device, "Interrupt mask read", data); |
| 366 | data = m_interrupt_mask; |
| 367 | LOG_TMS5501("Interrupt mask read", data); |
| 397 | 368 | break; |
| 398 | 369 | case 0x09: /* Timer 0 address */ |
| 399 | 370 | case 0x0a: /* Timer 1 address */ |
| r15385 | r15386 | |
| 410 | 381 | WRITE8_DEVICE_HANDLER( tms5501_w ) |
| 411 | 382 | -------------------------------------------------*/ |
| 412 | 383 | |
| 413 | | WRITE8_DEVICE_HANDLER( tms5501_w ) |
| 384 | WRITE8_MEMBER( tms5501_device::write ) |
| 414 | 385 | { |
| 415 | | tms5501_t *tms = get_token(device); |
| 416 | | const tms5501_interface *intf = get_interface(device); |
| 417 | 386 | offset &= 0x0f; |
| 418 | 387 | |
| 419 | 388 | switch (offset) |
| r15385 | r15386 | |
| 422 | 391 | case 0x01: /* Keyboard input port, Page blanking signal */ |
| 423 | 392 | case 0x02: /* Interrupt address register */ |
| 424 | 393 | case 0x03: /* Status register */ |
| 425 | | LOG_TMS5501(device, "Writing to read only port", offset&0x000f); |
| 426 | | LOG_TMS5501(device, "Data", data); |
| 394 | LOG_TMS5501("Writing to read only port", offset&0x000f); |
| 395 | LOG_TMS5501("Data", data); |
| 427 | 396 | break; |
| 428 | 397 | case 0x04: |
| 429 | 398 | /* Command register |
| r15385 | r15386 | |
| 435 | 404 | bits 6-7: not used, normally '0' |
| 436 | 405 | bits 1-5 are latched */ |
| 437 | 406 | |
| 438 | | tms->command = data & TMS5501_COMMAND_LATCHED_BITS; |
| 439 | | LOG_TMS5501(device, "Command register write", data); |
| 407 | m_command = data & TMS5501_COMMAND_LATCHED_BITS; |
| 408 | LOG_TMS5501("Command register write", data); |
| 440 | 409 | |
| 441 | 410 | if (data & TMS5501_RESET) |
| 442 | | device->reset(); |
| 411 | reset(); |
| 443 | 412 | break; |
| 444 | 413 | case 0x05: |
| 445 | 414 | /* Serial rate register |
| r15385 | r15386 | |
| 452 | 421 | bit 6: 9600 baud |
| 453 | 422 | bit 7: '0' - two stop bits, '1' - one stop bit */ |
| 454 | 423 | |
| 455 | | tms->sio_rate = data; |
| 456 | | LOG_TMS5501(device, "Serial rate write", data); |
| 424 | m_sio_rate = data; |
| 425 | LOG_TMS5501("Serial rate write", data); |
| 457 | 426 | break; |
| 458 | 427 | case 0x06: /* Serial output buffer */ |
| 459 | | tms->sio_output_buffer = data; |
| 460 | | LOG_TMS5501(device, "Serial output data", data); |
| 428 | m_sio_output_buffer = data; |
| 429 | LOG_TMS5501("Serial output data", data); |
| 461 | 430 | break; |
| 462 | 431 | case 0x07: /* PIO output */ |
| 463 | | tms->pio_output_buffer = data; |
| 464 | | if (intf->pio_write_callback) |
| 465 | | (*intf->pio_write_callback)(device, tms->pio_output_buffer); |
| 466 | | LOG_TMS5501(device, "Writing to PIO", data); |
| 432 | m_pio_output_buffer = data; |
| 433 | if (!m_pio_write_func.isnull()) |
| 434 | m_pio_write_func(0, m_pio_output_buffer); |
| 435 | LOG_TMS5501("Writing to PIO", data); |
| 467 | 436 | break; |
| 468 | 437 | case 0x08: |
| 469 | 438 | /* Interrupt mask register |
| r15385 | r15386 | |
| 476 | 445 | bit 6: Timer 4 has expired (KBIM) |
| 477 | 446 | bit 7: Timer 5 has expired or IN7 (CLKIM) */ |
| 478 | 447 | |
| 479 | | tms->interrupt_mask = data; |
| 480 | | LOG_TMS5501(device, "Interrupt mask write", data); |
| 448 | m_interrupt_mask = data; |
| 449 | LOG_TMS5501("Interrupt mask write", data); |
| 481 | 450 | break; |
| 482 | 451 | case 0x09: /* Timer 0 counter */ |
| 483 | 452 | case 0x0a: /* Timer 1 counter */ |
| r15385 | r15386 | |
| 485 | 454 | case 0x0c: /* Timer 3 counter */ |
| 486 | 455 | case 0x0d: /* Timer 4 counter */ |
| 487 | 456 | offset -= 9; |
| 488 | | tms->timer_counter[offset] = data; |
| 489 | | tms5501_timer_reload(device, offset); |
| 490 | | LOG_TMS5501(device, "Write timer", offset); |
| 491 | | LOG_TMS5501(device, "Timer counter set", data); |
| 457 | m_timer_counter[offset] = data; |
| 458 | timer_reload(offset); |
| 459 | LOG_TMS5501("Write timer", offset); |
| 460 | LOG_TMS5501("Timer counter set", data); |
| 492 | 461 | break; |
| 493 | 462 | } |
| 494 | 463 | } |
| 495 | | |
| 496 | | |
| 497 | | /*------------------------------------------------- |
| 498 | | DEVICE_GET_INFO( tms5501 ) |
| 499 | | -------------------------------------------------*/ |
| 500 | | |
| 501 | | DEVICE_GET_INFO( tms5501 ) |
| 502 | | { |
| 503 | | switch (state) |
| 504 | | { |
| 505 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 506 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(tms5501_t); break; |
| 507 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 508 | | |
| 509 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 510 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(tms5501); break; |
| 511 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 512 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(tms5501); break; |
| 513 | | |
| 514 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 515 | | case DEVINFO_STR_NAME: strcpy(info->s, "TMS5501"); break; |
| 516 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "TMS5501"); break; |
| 517 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 518 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 519 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 520 | | } |
| 521 | | } |
| 522 | | |
| 523 | | DEFINE_LEGACY_DEVICE(TMS5501, tms5501); |
src/mess/machine/tms5501.h
| r15385 | r15386 | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | /*************************************************************************** |
| 14 | | MACROS |
| 14 | DEVICE CONFIGURATION MACROS |
| 15 | 15 | ***************************************************************************/ |
| 16 | 16 | |
| 17 | | DECLARE_LEGACY_DEVICE(TMS5501, tms5501); |
| 17 | #define MCFG_TMS5501_ADD(_tag, _clock, _intrf) \ |
| 18 | MCFG_DEVICE_ADD(_tag, TMS5501, _clock) \ |
| 19 | MCFG_DEVICE_CONFIG(_intrf) |
| 18 | 20 | |
| 21 | #define TMS5501_INTERFACE(name) \ |
| 22 | const tms5501_interface (name) = |
| 19 | 23 | |
| 20 | 24 | |
| 21 | 25 | /*************************************************************************** |
| 22 | 26 | TYPE DEFINITIONS |
| 23 | 27 | ***************************************************************************/ |
| 24 | 28 | |
| 25 | | /* TMS5501 timer and interrupt controller */ |
| 26 | | typedef struct _tms5501_interface tms5501_interface; |
| 27 | | struct _tms5501_interface |
| 29 | typedef void (*tms5501_interrupt_cb)(device_t &device, int intreq, UINT8 vector); |
| 30 | #define TMS5501_IRQ_CALLBACK(name) void name(device_t &device, int intreq, UINT8 vector) |
| 31 | |
| 32 | |
| 33 | // ======================> tms5501_interface |
| 34 | |
| 35 | struct tms5501_interface |
| 28 | 36 | { |
| 29 | | UINT8 (*pio_read_callback)(device_t *device); |
| 30 | | void (*pio_write_callback)(device_t *device, UINT8); |
| 31 | | void (*interrupt_callback)(device_t *device, int intreq, UINT8 vector); |
| 32 | | double clock_rate; |
| 37 | devcb_read8 m_pio_read_cb; // PIO read |
| 38 | devcb_write8 m_pio_write_cb; // PIO write |
| 39 | tms5501_interrupt_cb m_interrupt_cb; // interrupt callback |
| 33 | 40 | }; |
| 34 | 41 | |
| 42 | // ======================> tms5501_device |
| 35 | 43 | |
| 44 | class tms5501_device : public device_t, |
| 45 | public tms5501_interface |
| 46 | { |
| 47 | public: |
| 48 | // construction/destruction |
| 49 | tms5501_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 36 | 50 | |
| 37 | | /*************************************************************************** |
| 38 | | DEVICE CONFIGURATION MACROS |
| 39 | | ***************************************************************************/ |
| 51 | DECLARE_READ8_MEMBER( read ); |
| 52 | DECLARE_WRITE8_MEMBER( write ); |
| 53 | DECLARE_WRITE_LINE_MEMBER( set_pio_bit_7 ); |
| 54 | DECLARE_WRITE_LINE_MEMBER( set_sensor ); |
| 40 | 55 | |
| 41 | | #define MCFG_TMS5501_ADD(_tag, _intrf) \ |
| 42 | | MCFG_DEVICE_ADD(_tag, TMS5501, 0) \ |
| 43 | | MCFG_DEVICE_CONFIG(_intrf) |
| 56 | protected: |
| 57 | // device-level overrides |
| 58 | virtual void device_config_complete(); |
| 59 | virtual void device_start(); |
| 60 | virtual void device_reset(); |
| 61 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 44 | 62 | |
| 63 | public: |
| 64 | int find_first_bit(int value); |
| 65 | void field_interrupts(); |
| 66 | void timer_decrementer(UINT8 mask); |
| 67 | void timer_reload(int timer); |
| 45 | 68 | |
| 69 | static const device_timer_id TIMER_DECREMENTER = 0; |
| 46 | 70 | |
| 47 | | /*************************************************************************** |
| 48 | | FUNCTION PROTOTYPES |
| 49 | | ***************************************************************************/ |
| 71 | // internal registers |
| 72 | UINT8 m_status; // status register |
| 73 | UINT8 m_command; // command register, bits 1-5 are latched |
| 50 | 74 | |
| 51 | | READ8_DEVICE_HANDLER( tms5501_r ); |
| 52 | | WRITE8_DEVICE_HANDLER( tms5501_w ); |
| 75 | UINT8 m_sio_rate; // SIO configuration register |
| 76 | UINT8 m_sio_input_buffer; // SIO input buffer |
| 77 | UINT8 m_sio_output_buffer; // SIO output buffer |
| 53 | 78 | |
| 54 | | void tms5501_set_pio_bit_7 (device_t *device, UINT8 data); |
| 55 | | void tms5501_sensor (device_t *device, UINT8 data); |
| 79 | UINT8 m_pio_input_buffer; // PIO input buffer |
| 80 | UINT8 m_pio_output_buffer; // PIO output buffer |
| 56 | 81 | |
| 82 | UINT8 m_interrupt_mask; // interrupt mask register |
| 83 | UINT8 m_pending_interrupts; // pending interrupts register |
| 84 | UINT8 m_interrupt_address; // interrupt vector register |
| 85 | |
| 86 | int m_sensor; // sensor input |
| 87 | |
| 88 | // internal timers |
| 89 | UINT8 m_timer_counter[5]; |
| 90 | emu_timer * m_timer[5]; |
| 91 | |
| 92 | // PIO callbacks |
| 93 | devcb_resolved_read8 m_pio_read_func; |
| 94 | devcb_resolved_write8 m_pio_write_func; |
| 95 | }; |
| 96 | |
| 97 | |
| 98 | // device type definition |
| 99 | extern const device_type TMS5501; |
| 100 | |
| 57 | 101 | #endif /* __TMS5501_H__ */ |