src/mess/machine/uart8250.c
| r2435 | r2436 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | National Semiconductor 8250 UART interface and emulation |
| 4 | | |
| 5 | | More information on the different models can be found in |
| 6 | | section 1.6 at this location: |
| 7 | | http://www.freebsd.org/doc/en_US.ISO8859-1/articles/serial-uart/ |
| 8 | | |
| 9 | | Model overview (from page above): |
| 10 | | |
| 11 | | INS8250 |
| 12 | | This part was used in the original IBM PC and IBM PC/XT. The original name |
| 13 | | for this part was the INS8250 ACE (Asynchronous Communications Element) and |
| 14 | | it is made from NMOS technology. |
| 15 | | |
| 16 | | The 8250 uses eight I/O ports and has a one-byte send and a one-byte receive |
| 17 | | buffer. This original UART has several race conditions and other flaws. The |
| 18 | | original IBM BIOS includes code to work around these flaws, but this made |
| 19 | | the BIOS dependent on the flaws being present, so subsequent parts like the |
| 20 | | 8250A, 16450 or 16550 could not be used in the original IBM PC or IBM PC/XT. |
| 21 | | |
| 22 | | INS8250-B |
| 23 | | This is the slower speed of the INS8250 made from NMOS technology. It contains |
| 24 | | the same problems as the original INS8250. |
| 25 | | |
| 26 | | INS8250A |
| 27 | | An improved version of the INS8250 using XMOS technology with various functional |
| 28 | | flaws corrected. The INS8250A was used initially in PC clone computers by vendors |
| 29 | | who used “clean” BIOS designs. Because of the corrections in the chip, this part |
| 30 | | could not be used with a BIOS compatible with the INS8250 or INS8250B. |
| 31 | | |
| 32 | | INS82C50A |
| 33 | | This is a CMOS version (low power consumption) of the INS8250A and has similar |
| 34 | | functional characteristics. |
| 35 | | |
| 36 | | NS16450 |
| 37 | | Same as NS8250A with improvements so it can be used with faster CPU bus designs. |
| 38 | | IBM used this part in the IBM AT and updated the IBM BIOS to no longer rely on |
| 39 | | the bugs in the INS8250. |
| 40 | | |
| 41 | | NS16C450 |
| 42 | | This is a CMOS version (low power consumption) of the NS16450. |
| 43 | | |
| 44 | | NS16550 |
| 45 | | Same as NS16450 with a 16-byte send and receive buffer but the buffer design |
| 46 | | was flawed and could not be reliably be used. |
| 47 | | |
| 48 | | NS16550A |
| 49 | | Same as NS16550 with the buffer flaws corrected. The 16550A and its successors |
| 50 | | have become the most popular UART design in the PC industry, mainly due to |
| 51 | | its ability to reliably handle higher data rates on operating systems with |
| 52 | | sluggish interrupt response times. |
| 53 | | |
| 54 | | NS16C552 |
| 55 | | This component consists of two NS16C550A CMOS UARTs in a single package. |
| 56 | | |
| 57 | | PC16550D |
| 58 | | Same as NS16550A with subtle flaws corrected. This is revision D of the |
| 59 | | 16550 family and is the latest design available from National Semiconductor. |
| 60 | | |
| 61 | | |
| 62 | | Known issues: |
| 63 | | - MESS does currently not handle all these model specific features. |
| 64 | | |
| 65 | | |
| 66 | | History: |
| 67 | | KT - 14-Jun-2000 - Improved Interrupt setting/clearing |
| 68 | | KT - moved into seperate file so it can be used in Super I/O emulation and |
| 69 | | any other system which uses a PC type COM port |
| 70 | | KT - 24-Jun-2000 - removed pc specific input port tests. More compatible |
| 71 | | with PCW16 and PCW16 doesn't requre the PC input port definitions |
| 72 | | which are not required by the PCW16 hardware |
| 73 | | |
| 74 | | **********************************************************************/ |
| 75 | | |
| 76 | | #include "driver.h" |
| 77 | | #include "machine/uart8250.h" |
| 78 | | #include "includes/pc_mouse.h" |
| 79 | | #include "memconv.h" |
| 80 | | |
| 81 | | |
| 82 | | #define LOG(LEVEL,N,M,A) \ |
| 83 | | if( M )logerror("%11.6f: %-24s",attotime_to_double(timer_get_time()),(char*)M ); logerror A; |
| 84 | | |
| 85 | | |
| 86 | | /* device types */ |
| 87 | | enum { |
| 88 | | TYPE_INS8250 = 0, |
| 89 | | TYPE_INS8250A, |
| 90 | | TYPE_NS16450, |
| 91 | | TYPE_NS16550, |
| 92 | | TYPE_NS16550A, |
| 93 | | TYPE_PC16550D, |
| 94 | | |
| 95 | | NUM_TYPES |
| 96 | | }; |
| 97 | | |
| 98 | | |
| 99 | | /* device tags */ |
| 100 | | static const char * const device_tags[NUM_TYPES] = { "ins8250", "ins8250a", "ns16450", "ns16550", "ns16550a", "pc16550d" }; |
| 101 | | |
| 102 | | |
| 103 | | #define VERBOSE_COM 0 |
| 104 | | #define COM_LOG(n,m,a) LOG(VERBOSE_COM,n,m,a) |
| 105 | | |
| 106 | | typedef struct { |
| 107 | | const ins8250_interface *interface; |
| 108 | | int device_type; |
| 109 | | |
| 110 | | UINT8 thr; /* 0 -W transmitter holding register */ |
| 111 | | UINT8 rbr; /* 0 R- receiver buffer register */ |
| 112 | | UINT8 ier; /* 1 RW interrupt enable register */ |
| 113 | | UINT8 dll; /* 0 RW divisor latch lsb (if DLAB = 1) */ |
| 114 | | UINT8 dlm; /* 1 RW divisor latch msb (if DLAB = 1) */ |
| 115 | | UINT8 iir; /* 2 R- interrupt identification register */ |
| 116 | | UINT8 lcr; /* 3 RW line control register (bit 7: DLAB) */ |
| 117 | | UINT8 mcr; /* 4 RW modem control register */ |
| 118 | | UINT8 lsr; /* 5 R- line status register */ |
| 119 | | UINT8 msr; /* 6 R- modem status register */ |
| 120 | | UINT8 scr; /* 7 RW scratch register */ |
| 121 | | |
| 122 | | /* holds int pending state for com */ |
| 123 | | UINT8 int_pending; |
| 124 | | |
| 125 | | // sending circuit |
| 126 | | struct { |
| 127 | | int active; |
| 128 | | UINT8 data; |
| 129 | | double time; |
| 130 | | } send; |
| 131 | | } ins8250_t; |
| 132 | | |
| 133 | | /* int's pending */ |
| 134 | | #define COM_INT_PENDING_RECEIVED_DATA_AVAILABLE 0x0001 |
| 135 | | #define COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY 0x0002 |
| 136 | | #define COM_INT_PENDING_RECEIVER_LINE_STATUS 0x0004 |
| 137 | | #define COM_INT_PENDING_MODEM_STATUS_REGISTER 0x0008 |
| 138 | | |
| 139 | | #define DLAB(n) (uart[n].lcr&0x80) //divisor latch access bit |
| 140 | | #define LOOP(n) (ins8250->mcr&0x10) |
| 141 | | |
| 142 | | |
| 143 | | |
| 144 | | INLINE ins8250_t *get_safe_token(const device_config *device) { |
| 145 | | assert( device != NULL ); |
| 146 | | assert( device->token != NULL ); |
| 147 | | assert( ( device->type == DEVICE_GET_INFO_NAME(ins8250) ) || |
| 148 | | ( device->type == DEVICE_GET_INFO_NAME(ins8250a) ) || |
| 149 | | ( device->type == DEVICE_GET_INFO_NAME(ns16450) ) || |
| 150 | | ( device->type == DEVICE_GET_INFO_NAME(ns16550) ) || |
| 151 | | ( device->type == DEVICE_GET_INFO_NAME(ns16550a) ) || |
| 152 | | ( device->type == DEVICE_GET_INFO_NAME(pc16550d) ) ); |
| 153 | | return ( ins8250_t *) device->token; |
| 154 | | } |
| 155 | | |
| 156 | | |
| 157 | | /* setup iir with the priority id */ |
| 158 | | static void ins8250_setup_iir(const device_config *device) |
| 159 | | { |
| 160 | | ins8250_t *ins8250 = get_safe_token(device); |
| 161 | | |
| 162 | | ins8250->iir &= ~(0x04|0x02); |
| 163 | | |
| 164 | | /* highest to lowest */ |
| 165 | | if (ins8250->int_pending & COM_INT_PENDING_RECEIVER_LINE_STATUS) |
| 166 | | { |
| 167 | | ins8250->iir |=0x04|0x02; |
| 168 | | return; |
| 169 | | } |
| 170 | | |
| 171 | | if (ins8250->int_pending & COM_INT_PENDING_RECEIVED_DATA_AVAILABLE) |
| 172 | | { |
| 173 | | ins8250->iir |=0x04; |
| 174 | | return; |
| 175 | | } |
| 176 | | |
| 177 | | if (ins8250->int_pending & COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY) |
| 178 | | { |
| 179 | | ins8250->iir |=0x02; |
| 180 | | return; |
| 181 | | } |
| 182 | | |
| 183 | | /* modem status has both bits clear */ |
| 184 | | } |
| 185 | | |
| 186 | | |
| 187 | | /* ints will continue to be set for as long as there are ints pending */ |
| 188 | | static void ins8250_update_interrupt(const device_config *device) |
| 189 | | { |
| 190 | | ins8250_t *ins8250 = get_safe_token(device); |
| 191 | | int state; |
| 192 | | |
| 193 | | /* disable int output? */ |
| 194 | | if ((ins8250->mcr & 0x08) == 0) |
| 195 | | return; |
| 196 | | |
| 197 | | /* if any bits are set and are enabled */ |
| 198 | | if (((ins8250->int_pending&ins8250->ier) & 0x0f) != 0) |
| 199 | | { |
| 200 | | /* trigger next highest priority int */ |
| 201 | | |
| 202 | | /* set int */ |
| 203 | | state = 1; |
| 204 | | |
| 205 | | ins8250_setup_iir(device); |
| 206 | | |
| 207 | | /* int pending */ |
| 208 | | ins8250->iir |= 0x01; |
| 209 | | } |
| 210 | | else |
| 211 | | { |
| 212 | | /* clear int */ |
| 213 | | state = 0; |
| 214 | | |
| 215 | | /* no ints pending */ |
| 216 | | ins8250->iir &= ~0x01; |
| 217 | | /* priority level */ |
| 218 | | ins8250->iir &= ~(0x04|0x02); |
| 219 | | } |
| 220 | | |
| 221 | | |
| 222 | | /* set or clear the int */ |
| 223 | | if (ins8250->interface->interrupt) |
| 224 | | ins8250->interface->interrupt(device, state); |
| 225 | | } |
| 226 | | |
| 227 | | |
| 228 | | |
| 229 | | /* set pending bit and trigger int */ |
| 230 | | static void ins8250_trigger_int(const device_config *device, int flag) |
| 231 | | { |
| 232 | | ins8250_t *ins8250 = get_safe_token(device); |
| 233 | | |
| 234 | | ins8250->int_pending |= flag; |
| 235 | | ins8250_update_interrupt(device); |
| 236 | | } |
| 237 | | |
| 238 | | |
| 239 | | |
| 240 | | /* clear pending bit, if any ints are pending, then int will be triggered, otherwise it |
| 241 | | will be cleared */ |
| 242 | | static void ins8250_clear_int(const device_config *device, int flag) |
| 243 | | { |
| 244 | | ins8250_t *ins8250 = get_safe_token(device); |
| 245 | | |
| 246 | | ins8250->int_pending &= ~flag; |
| 247 | | ins8250_update_interrupt(device); |
| 248 | | } |
| 249 | | |
| 250 | | |
| 251 | | WRITE8_DEVICE_HANDLER( ins8250_w ) |
| 252 | | { |
| 253 | | static const char P[8] = "NONENHNL"; /* names for parity select */ |
| 254 | | ins8250_t *ins8250 = get_safe_token(device); |
| 255 | | int tmp; |
| 256 | | |
| 257 | | switch (offset) |
| 258 | | { |
| 259 | | case 0: |
| 260 | | if (ins8250->lcr & 0x80) |
| 261 | | { |
| 262 | | ins8250->dll = data; |
| 263 | | tmp = ins8250->dlm * 256 + ins8250->dll; |
| 264 | | COM_LOG(1,"COM_dll_w",("COM $%02x: [$%04x = %d baud]\n", |
| 265 | | data, tmp, (tmp)?(int)(ins8250->interface->clockin/16/tmp):0)); |
| 266 | | } |
| 267 | | else |
| 268 | | { |
| 269 | | ins8250->thr = data; |
| 270 | | COM_LOG(2,"COM_thr_w",("COM $%02x\n", data)); |
| 271 | | |
| 272 | | if (LOOP(n)) |
| 273 | | { |
| 274 | | ins8250->lsr |= 1; |
| 275 | | ins8250->rbr = data; |
| 276 | | } |
| 277 | | /* writing to thr will clear the int */ |
| 278 | | ins8250_clear_int(device, COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY); |
| 279 | | } |
| 280 | | break; |
| 281 | | case 1: |
| 282 | | if (ins8250->lcr & 0x80) |
| 283 | | { |
| 284 | | ins8250->dlm = data; |
| 285 | | tmp = ins8250->dlm * 256 + ins8250->dll; |
| 286 | | COM_LOG(1,"COM_dlm_w",("COM $%02x: [$%04x = %d baud]\n", |
| 287 | | data, tmp, (tmp)?(int)(ins8250->interface->clockin/16/tmp):0)); |
| 288 | | } |
| 289 | | else |
| 290 | | { |
| 291 | | ins8250->ier = data; |
| 292 | | COM_LOG(2,"COM_ier_w",("COM $%02x: enable int on RX %d, THRE %d, RLS %d, MS %d\n", |
| 293 | | data, data&1, (data>>1)&1, (data>>2)&1, (data>>3)&1)); |
| 294 | | } |
| 295 | | break; |
| 296 | | case 2: |
| 297 | | COM_LOG(1,"COM_fcr_w",("COM $%02x (16550 only)\n", data)); |
| 298 | | break; |
| 299 | | case 3: |
| 300 | | ins8250->lcr = data; |
| 301 | | COM_LOG(1,"COM_lcr_w",("COM $%02x word length %d, stop bits %d, parity %c, break %d, DLAB %d\n", |
| 302 | | data, 5+(data&3), 1+((data>>2)&1), P[(data>>3)&7], (data>>6)&1, (data>>7)&1)); |
| 303 | | break; |
| 304 | | case 4: |
| 305 | | ins8250->mcr = data; |
| 306 | | COM_LOG(1,"COM_mcr_w",("COM $%02x DTR %d, RTS %d, OUT1 %d, OUT2 %d, loopback %d\n", |
| 307 | | data, data&1, (data>>1)&1, (data>>2)&1, (data>>3)&1, (data>>4)&1)); |
| 308 | | if (ins8250->interface->handshake_out) |
| 309 | | ins8250->interface->handshake_out(device,data); |
| 310 | | break; |
| 311 | | case 5: |
| 312 | | break; |
| 313 | | case 6: |
| 314 | | break; |
| 315 | | case 7: |
| 316 | | ins8250->scr = data; |
| 317 | | COM_LOG(2,"COM_scr_w",("COM $%02x\n", data)); |
| 318 | | break; |
| 319 | | } |
| 320 | | |
| 321 | | if (ins8250->interface->refresh_connected) |
| 322 | | ins8250->interface->refresh_connected(device); |
| 323 | | } |
| 324 | | |
| 325 | | |
| 326 | | |
| 327 | | READ8_DEVICE_HANDLER( ins8250_r ) |
| 328 | | { |
| 329 | | ins8250_t *ins8250 = get_safe_token(device); |
| 330 | | int data = 0x0ff; |
| 331 | | |
| 332 | | switch (offset) |
| 333 | | { |
| 334 | | case 0: |
| 335 | | if (ins8250->lcr & 0x80) |
| 336 | | { |
| 337 | | data = ins8250->dll; |
| 338 | | COM_LOG(1,"COM_dll_r",("COM $%02x\n", data)); |
| 339 | | } |
| 340 | | else |
| 341 | | { |
| 342 | | data = ins8250->rbr; |
| 343 | | if( ins8250->lsr & 0x01 ) |
| 344 | | { |
| 345 | | ins8250->lsr &= ~0x01; /* clear data ready status */ |
| 346 | | COM_LOG(2,"COM_rbr_r",("COM $%02x\n", data)); |
| 347 | | } |
| 348 | | |
| 349 | | ins8250_clear_int(device, COM_INT_PENDING_RECEIVED_DATA_AVAILABLE); |
| 350 | | } |
| 351 | | break; |
| 352 | | case 1: |
| 353 | | if (ins8250->lcr & 0x80) |
| 354 | | { |
| 355 | | data = ins8250->dlm; |
| 356 | | COM_LOG(1,"COM_dlm_r",("COM $%02x\n", data)); |
| 357 | | } |
| 358 | | else |
| 359 | | { |
| 360 | | data = ins8250->ier; |
| 361 | | COM_LOG(2,"COM_ier_r",("COM $%02x\n", data)); |
| 362 | | } |
| 363 | | break; |
| 364 | | case 2: |
| 365 | | data = ins8250->iir; |
| 366 | | COM_LOG(2,"COM_iir_r",("COM $%02x\n", data)); |
| 367 | | /* this may not be correct. It says that reading this register will |
| 368 | | clear the int if this is the source of the int?? */ |
| 369 | | ins8250_clear_int(device, COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY); |
| 370 | | break; |
| 371 | | case 3: |
| 372 | | data = ins8250->lcr; |
| 373 | | COM_LOG(2,"COM_lcr_r",("COM $%02x\n", data)); |
| 374 | | break; |
| 375 | | case 4: |
| 376 | | data = ins8250->mcr; |
| 377 | | COM_LOG(2,"COM_mcr_r",("COM $%02x\n", data)); |
| 378 | | break; |
| 379 | | case 5: |
| 380 | | |
| 381 | | #if 0 |
| 382 | | if (ins8250->send.active && (timer_get_time()-ins8250->send.time>uart_byte_time(n))) |
| 383 | | { |
| 384 | | // currently polling is enough for pc1512 |
| 385 | | ins8250->lsr |= 0x40; /* set TSRE */ |
| 386 | | ins8250->send.active = 0; |
| 387 | | if (LOOP(n)) |
| 388 | | { |
| 389 | | ins8250->lsr |= 1; |
| 390 | | ins8250->rbr = ins8250->send.data; |
| 391 | | } |
| 392 | | } |
| 393 | | #endif |
| 394 | | ins8250->lsr |= 0x20; /* set THRE */ |
| 395 | | data = ins8250->lsr; |
| 396 | | if( ins8250->lsr & 0x1f ) |
| 397 | | { |
| 398 | | ins8250->lsr &= 0xe1; /* clear FE, PE and OE and BREAK bits */ |
| 399 | | COM_LOG(2,"COM_lsr_r",("COM $%02x, DR %d, OE %d, PE %d, FE %d, BREAK %d, THRE %d, TSRE %d\n", |
| 400 | | data, data&1, (data>>1)&1, (data>>2)&1, (data>>3)&1, (data>>4)&1, (data>>5)&1, (data>>6)&1)); |
| 401 | | } |
| 402 | | |
| 403 | | /* reading line status register clears int */ |
| 404 | | ins8250_clear_int(device, COM_INT_PENDING_RECEIVER_LINE_STATUS); |
| 405 | | break; |
| 406 | | case 6: |
| 407 | | if (ins8250->mcr & 0x10) /* loopback test? */ |
| 408 | | { |
| 409 | | data = ins8250->mcr << 4; |
| 410 | | /* build delta values */ |
| 411 | | ins8250->msr = (ins8250->msr ^ data) >> 4; |
| 412 | | ins8250->msr |= data; |
| 413 | | } |
| 414 | | data = ins8250->msr; |
| 415 | | ins8250->msr &= 0xf0; /* reset delta values */ |
| 416 | | COM_LOG(2,"COM_msr_r",("COM $%02x\n", data)); |
| 417 | | |
| 418 | | /* reading msr clears int */ |
| 419 | | ins8250_clear_int(device, COM_INT_PENDING_MODEM_STATUS_REGISTER); |
| 420 | | |
| 421 | | break; |
| 422 | | case 7: |
| 423 | | data = ins8250->scr; |
| 424 | | COM_LOG(2,"COM_scr_r",("COM $%02x\n", data)); |
| 425 | | break; |
| 426 | | } |
| 427 | | |
| 428 | | if (ins8250->interface->refresh_connected) |
| 429 | | ins8250->interface->refresh_connected(device); |
| 430 | | |
| 431 | | return data; |
| 432 | | } |
| 433 | | |
| 434 | | |
| 435 | | |
| 436 | | void ins8250_receive(const device_config *device, int data) |
| 437 | | { |
| 438 | | ins8250_t *ins8250 = get_safe_token(device); |
| 439 | | |
| 440 | | /* check if data rate 1200 baud is set */ |
| 441 | | if( ins8250->dlm != 0x00 || ins8250->dll != 0x60 ) |
| 442 | | ins8250->lsr |= 0x08; /* set framing error */ |
| 443 | | |
| 444 | | /* if data not yet serviced */ |
| 445 | | if( ins8250->lsr & 0x01 ) |
| 446 | | ins8250->lsr |= 0x02; /* set overrun error */ |
| 447 | | |
| 448 | | /* put data into receiver buffer register */ |
| 449 | | ins8250->rbr = data; |
| 450 | | |
| 451 | | /* set data ready status */ |
| 452 | | ins8250->lsr |= 0x01; |
| 453 | | |
| 454 | | /* set pending state for this interrupt. */ |
| 455 | | ins8250_trigger_int(device, COM_INT_PENDING_RECEIVED_DATA_AVAILABLE); |
| 456 | | |
| 457 | | |
| 458 | | // /* OUT2 + received line data avail interrupt enabled? */ |
| 459 | | // if( (COM_mcr[n] & 0x08) && (COM_ier[n] & 0x01) ) |
| 460 | | // { |
| 461 | | // if (com_interface.interrupt) |
| 462 | | // com_interface.interrupt(4-(n&1), 1); |
| 463 | | // |
| 464 | | // } |
| 465 | | } |
| 466 | | |
| 467 | | /************************************************************************** |
| 468 | | * change the modem status register |
| 469 | | **************************************************************************/ |
| 470 | | void ins8250_handshake_in(const device_config *device, int new_msr) |
| 471 | | { |
| 472 | | ins8250_t *ins8250 = get_safe_token(device); |
| 473 | | |
| 474 | | /* no change in modem status bits? */ |
| 475 | | if( ((ins8250->msr ^ new_msr) & 0xf0) == 0 ) |
| 476 | | return; |
| 477 | | |
| 478 | | /* set delta status bits 0..3 and new modem status bits 4..7 */ |
| 479 | | ins8250->msr = (((ins8250->msr ^ new_msr) >> 4) & 0x0f) | (new_msr & 0xf0); |
| 480 | | |
| 481 | | ins8250_trigger_int(device, COM_INT_PENDING_MODEM_STATUS_REGISTER); |
| 482 | | |
| 483 | | // /* set up interrupt information register */ |
| 484 | | // COM_iir[n] &= ~(0x06 | 0x01); |
| 485 | | |
| 486 | | // /* OUT2 + modem status interrupt enabled? */ |
| 487 | | // if( (COM_mcr[n] & 0x08) && (COM_ier[n] & 0x08) ) |
| 488 | | // { |
| 489 | | // if (com_interface.interrupt) |
| 490 | | // com_interface.interrupt(4-(n&1), 1); |
| 491 | | // } |
| 492 | | } |
| 493 | | |
| 494 | | |
| 495 | | static void common_start( const device_config *device, int device_type ) { |
| 496 | | ins8250_t *ins8250 = get_safe_token(device); |
| 497 | | |
| 498 | | ins8250->interface = device->static_config; |
| 499 | | ins8250->device_type = device_type; |
| 500 | | } |
| 501 | | |
| 502 | | |
| 503 | | static DEVICE_START( ins8250 ) { |
| 504 | | common_start( device, TYPE_INS8250 ); |
| 505 | | } |
| 506 | | |
| 507 | | |
| 508 | | static DEVICE_START( ins8250a ) { |
| 509 | | common_start( device, TYPE_INS8250A ); |
| 510 | | } |
| 511 | | |
| 512 | | |
| 513 | | static DEVICE_START( ns16450 ) { |
| 514 | | common_start( device, TYPE_NS16450 ); |
| 515 | | } |
| 516 | | |
| 517 | | |
| 518 | | static DEVICE_START( ns16550 ) { |
| 519 | | common_start( device, TYPE_NS16550 ); |
| 520 | | } |
| 521 | | |
| 522 | | |
| 523 | | static DEVICE_START( ns16550a ) { |
| 524 | | common_start( device, TYPE_NS16550A ); |
| 525 | | } |
| 526 | | |
| 527 | | |
| 528 | | static DEVICE_START( pc16550d ) { |
| 529 | | common_start( device, TYPE_PC16550D ); |
| 530 | | } |
| 531 | | |
| 532 | | |
| 533 | | static DEVICE_RESET( ins8250 ) { |
| 534 | | ins8250_t *ins8250 = get_safe_token(device); |
| 535 | | |
| 536 | | ins8250->ier = 0; |
| 537 | | ins8250->iir = 1; |
| 538 | | ins8250->lcr = 0; |
| 539 | | ins8250->mcr = 0; |
| 540 | | ins8250->lsr = (1<<5) | (1<<6); |
| 541 | | |
| 542 | | ins8250->send.active=0; |
| 543 | | |
| 544 | | /* refresh with reset state of register */ |
| 545 | | if (ins8250->interface->refresh_connected) |
| 546 | | ins8250->interface->refresh_connected(device); |
| 547 | | } |
| 548 | | |
| 549 | | |
| 550 | | static DEVICE_SET_INFO( ins8250 ) { |
| 551 | | switch ( state ) { |
| 552 | | /* no parameters to set */ |
| 553 | | } |
| 554 | | } |
| 555 | | |
| 556 | | |
| 557 | | DEVICE_GET_INFO( ins8250 ) { |
| 558 | | switch ( state ) { |
| 559 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 560 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ins8250_t); break; |
| 561 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 562 | | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 563 | | |
| 564 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 565 | | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(ins8250); break; |
| 566 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ins8250); break; |
| 567 | | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 568 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(ins8250); break; |
| 569 | | |
| 570 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 571 | | case DEVINFO_STR_NAME: info->s = "National Semiconductor INS8250/INS8250B"; break; |
| 572 | | case DEVINFO_STR_FAMILY: info->s = "INS8250"; break; |
| 573 | | case DEVINFO_STR_VERSION: info->s = "1.00"; break; |
| 574 | | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 575 | | case DEVINFO_STR_CREDITS: info->s = "Copyright the MESS Team"; break; |
| 576 | | } |
| 577 | | } |
| 578 | | |
| 579 | | |
| 580 | | DEVICE_GET_INFO( ins8250a ) { |
| 581 | | switch ( state ) { |
| 582 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 583 | | case DEVINFO_STR_NAME: info->s = "National Semiconductor INS8250A/INS82C50A"; break; |
| 584 | | |
| 585 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 586 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ins8250a); break; |
| 587 | | |
| 588 | | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 589 | | } |
| 590 | | } |
| 591 | | |
| 592 | | |
| 593 | | DEVICE_GET_INFO( ns16450 ) { |
| 594 | | switch ( state ) { |
| 595 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 596 | | case DEVINFO_STR_NAME: info->s = "National Semiconductor NS16450/PC16450"; break; |
| 597 | | |
| 598 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 599 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ns16450); break; |
| 600 | | |
| 601 | | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 602 | | } |
| 603 | | } |
| 604 | | |
| 605 | | |
| 606 | | DEVICE_GET_INFO( ns16550 ) { |
| 607 | | switch ( state ) { |
| 608 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 609 | | case DEVINFO_STR_NAME: info->s = "National Semiconductor NS16550/PC16550"; break; |
| 610 | | |
| 611 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 612 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ns16550); break; |
| 613 | | |
| 614 | | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 615 | | } |
| 616 | | } |
| 617 | | |
| 618 | | |
| 619 | | DEVICE_GET_INFO( ns16550a ) { |
| 620 | | switch ( state ) { |
| 621 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 622 | | case DEVINFO_STR_NAME: info->s = "National Semiconductor NS16550A/PC16550A"; break; |
| 623 | | |
| 624 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 625 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ns16550a); break; |
| 626 | | |
| 627 | | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 628 | | } |
| 629 | | } |
| 630 | | |
| 631 | | |
| 632 | | DEVICE_GET_INFO( pc16550d ) { |
| 633 | | switch ( state ) { |
| 634 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 635 | | case DEVINFO_STR_NAME: info->s = "National Semiconductor PC16550D"; break; |
| 636 | | |
| 637 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 638 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(pc16550d); break; |
| 639 | | |
| 640 | | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 641 | | } |
| 642 | | } |
| 643 | | |
src/mess/machine/ins8250.c
| r0 | r2436 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | National Semiconductor 8250 UART interface and emulation |
| 4 | |
| 5 | More information on the different models can be found in |
| 6 | section 1.6 at this location: |
| 7 | http://www.freebsd.org/doc/en_US.ISO8859-1/articles/serial-uart/ |
| 8 | |
| 9 | Model overview (from page above): |
| 10 | |
| 11 | INS8250 |
| 12 | This part was used in the original IBM PC and IBM PC/XT. The original name |
| 13 | for this part was the INS8250 ACE (Asynchronous Communications Element) and |
| 14 | it is made from NMOS technology. |
| 15 | |
| 16 | The 8250 uses eight I/O ports and has a one-byte send and a one-byte receive |
| 17 | buffer. This original UART has several race conditions and other flaws. The |
| 18 | original IBM BIOS includes code to work around these flaws, but this made |
| 19 | the BIOS dependent on the flaws being present, so subsequent parts like the |
| 20 | 8250A, 16450 or 16550 could not be used in the original IBM PC or IBM PC/XT. |
| 21 | |
| 22 | INS8250-B |
| 23 | This is the slower speed of the INS8250 made from NMOS technology. It contains |
| 24 | the same problems as the original INS8250. |
| 25 | |
| 26 | INS8250A |
| 27 | An improved version of the INS8250 using XMOS technology with various functional |
| 28 | flaws corrected. The INS8250A was used initially in PC clone computers by vendors |
| 29 | who used “clean” BIOS designs. Because of the corrections in the chip, this part |
| 30 | could not be used with a BIOS compatible with the INS8250 or INS8250B. |
| 31 | |
| 32 | INS82C50A |
| 33 | This is a CMOS version (low power consumption) of the INS8250A and has similar |
| 34 | functional characteristics. |
| 35 | |
| 36 | NS16450 |
| 37 | Same as NS8250A with improvements so it can be used with faster CPU bus designs. |
| 38 | IBM used this part in the IBM AT and updated the IBM BIOS to no longer rely on |
| 39 | the bugs in the INS8250. |
| 40 | |
| 41 | NS16C450 |
| 42 | This is a CMOS version (low power consumption) of the NS16450. |
| 43 | |
| 44 | NS16550 |
| 45 | Same as NS16450 with a 16-byte send and receive buffer but the buffer design |
| 46 | was flawed and could not be reliably be used. |
| 47 | |
| 48 | NS16550A |
| 49 | Same as NS16550 with the buffer flaws corrected. The 16550A and its successors |
| 50 | have become the most popular UART design in the PC industry, mainly due to |
| 51 | its ability to reliably handle higher data rates on operating systems with |
| 52 | sluggish interrupt response times. |
| 53 | |
| 54 | NS16C552 |
| 55 | This component consists of two NS16C550A CMOS UARTs in a single package. |
| 56 | |
| 57 | PC16550D |
| 58 | Same as NS16550A with subtle flaws corrected. This is revision D of the |
| 59 | 16550 family and is the latest design available from National Semiconductor. |
| 60 | |
| 61 | |
| 62 | Known issues: |
| 63 | - MESS does currently not handle all these model specific features. |
| 64 | |
| 65 | |
| 66 | History: |
| 67 | KT - 14-Jun-2000 - Improved Interrupt setting/clearing |
| 68 | KT - moved into seperate file so it can be used in Super I/O emulation and |
| 69 | any other system which uses a PC type COM port |
| 70 | KT - 24-Jun-2000 - removed pc specific input port tests. More compatible |
| 71 | with PCW16 and PCW16 doesn't requre the PC input port definitions |
| 72 | which are not required by the PCW16 hardware |
| 73 | |
| 74 | **********************************************************************/ |
| 75 | |
| 76 | #include "driver.h" |
| 77 | #include "machine/ins8250.h" |
| 78 | #include "includes/pc_mouse.h" |
| 79 | #include "memconv.h" |
| 80 | |
| 81 | |
| 82 | #define LOG(LEVEL,N,M,A) \ |
| 83 | if( M )logerror("%11.6f: %-24s",attotime_to_double(timer_get_time()),(char*)M ); logerror A; |
| 84 | |
| 85 | |
| 86 | /* device types */ |
| 87 | enum { |
| 88 | TYPE_INS8250 = 0, |
| 89 | TYPE_INS8250A, |
| 90 | TYPE_NS16450, |
| 91 | TYPE_NS16550, |
| 92 | TYPE_NS16550A, |
| 93 | TYPE_PC16550D, |
| 94 | |
| 95 | NUM_TYPES |
| 96 | }; |
| 97 | |
| 98 | |
| 99 | /* device tags */ |
| 100 | static const char * const device_tags[NUM_TYPES] = { "ins8250", "ins8250a", "ns16450", "ns16550", "ns16550a", "pc16550d" }; |
| 101 | |
| 102 | |
| 103 | #define VERBOSE_COM 0 |
| 104 | #define COM_LOG(n,m,a) LOG(VERBOSE_COM,n,m,a) |
| 105 | |
| 106 | typedef struct { |
| 107 | const ins8250_interface *interface; |
| 108 | int device_type; |
| 109 | |
| 110 | UINT8 thr; /* 0 -W transmitter holding register */ |
| 111 | UINT8 rbr; /* 0 R- receiver buffer register */ |
| 112 | UINT8 ier; /* 1 RW interrupt enable register */ |
| 113 | UINT8 dll; /* 0 RW divisor latch lsb (if DLAB = 1) */ |
| 114 | UINT8 dlm; /* 1 RW divisor latch msb (if DLAB = 1) */ |
| 115 | UINT8 iir; /* 2 R- interrupt identification register */ |
| 116 | UINT8 lcr; /* 3 RW line control register (bit 7: DLAB) */ |
| 117 | UINT8 mcr; /* 4 RW modem control register */ |
| 118 | UINT8 lsr; /* 5 R- line status register */ |
| 119 | UINT8 msr; /* 6 R- modem status register */ |
| 120 | UINT8 scr; /* 7 RW scratch register */ |
| 121 | |
| 122 | /* holds int pending state for com */ |
| 123 | UINT8 int_pending; |
| 124 | |
| 125 | // sending circuit |
| 126 | struct { |
| 127 | int active; |
| 128 | UINT8 data; |
| 129 | double time; |
| 130 | } send; |
| 131 | } ins8250_t; |
| 132 | |
| 133 | /* int's pending */ |
| 134 | #define COM_INT_PENDING_RECEIVED_DATA_AVAILABLE 0x0001 |
| 135 | #define COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY 0x0002 |
| 136 | #define COM_INT_PENDING_RECEIVER_LINE_STATUS 0x0004 |
| 137 | #define COM_INT_PENDING_MODEM_STATUS_REGISTER 0x0008 |
| 138 | |
| 139 | #define DLAB(n) (uart[n].lcr&0x80) //divisor latch access bit |
| 140 | #define LOOP(n) (ins8250->mcr&0x10) |
| 141 | |
| 142 | |
| 143 | |
| 144 | INLINE ins8250_t *get_safe_token(const device_config *device) { |
| 145 | assert( device != NULL ); |
| 146 | assert( device->token != NULL ); |
| 147 | assert( ( device->type == DEVICE_GET_INFO_NAME(ins8250) ) || |
| 148 | ( device->type == DEVICE_GET_INFO_NAME(ins8250a) ) || |
| 149 | ( device->type == DEVICE_GET_INFO_NAME(ns16450) ) || |
| 150 | ( device->type == DEVICE_GET_INFO_NAME(ns16550) ) || |
| 151 | ( device->type == DEVICE_GET_INFO_NAME(ns16550a) ) || |
| 152 | ( device->type == DEVICE_GET_INFO_NAME(pc16550d) ) ); |
| 153 | return ( ins8250_t *) device->token; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | /* setup iir with the priority id */ |
| 158 | static void ins8250_setup_iir(const device_config *device) |
| 159 | { |
| 160 | ins8250_t *ins8250 = get_safe_token(device); |
| 161 | |
| 162 | ins8250->iir &= ~(0x04|0x02); |
| 163 | |
| 164 | /* highest to lowest */ |
| 165 | if (ins8250->int_pending & COM_INT_PENDING_RECEIVER_LINE_STATUS) |
| 166 | { |
| 167 | ins8250->iir |=0x04|0x02; |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | if (ins8250->int_pending & COM_INT_PENDING_RECEIVED_DATA_AVAILABLE) |
| 172 | { |
| 173 | ins8250->iir |=0x04; |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | if (ins8250->int_pending & COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY) |
| 178 | { |
| 179 | ins8250->iir |=0x02; |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | /* modem status has both bits clear */ |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /* ints will continue to be set for as long as there are ints pending */ |
| 188 | static void ins8250_update_interrupt(const device_config *device) |
| 189 | { |
| 190 | ins8250_t *ins8250 = get_safe_token(device); |
| 191 | int state; |
| 192 | |
| 193 | /* disable int output? */ |
| 194 | if ((ins8250->mcr & 0x08) == 0) |
| 195 | return; |
| 196 | |
| 197 | /* if any bits are set and are enabled */ |
| 198 | if (((ins8250->int_pending&ins8250->ier) & 0x0f) != 0) |
| 199 | { |
| 200 | /* trigger next highest priority int */ |
| 201 | |
| 202 | /* set int */ |
| 203 | state = 1; |
| 204 | |
| 205 | ins8250_setup_iir(device); |
| 206 | |
| 207 | /* int pending */ |
| 208 | ins8250->iir |= 0x01; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | /* clear int */ |
| 213 | state = 0; |
| 214 | |
| 215 | /* no ints pending */ |
| 216 | ins8250->iir &= ~0x01; |
| 217 | /* priority level */ |
| 218 | ins8250->iir &= ~(0x04|0x02); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | /* set or clear the int */ |
| 223 | if (ins8250->interface->interrupt) |
| 224 | ins8250->interface->interrupt(device, state); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | |
| 229 | /* set pending bit and trigger int */ |
| 230 | static void ins8250_trigger_int(const device_config *device, int flag) |
| 231 | { |
| 232 | ins8250_t *ins8250 = get_safe_token(device); |
| 233 | |
| 234 | ins8250->int_pending |= flag; |
| 235 | ins8250_update_interrupt(device); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | |
| 240 | /* clear pending bit, if any ints are pending, then int will be triggered, otherwise it |
| 241 | will be cleared */ |
| 242 | static void ins8250_clear_int(const device_config *device, int flag) |
| 243 | { |
| 244 | ins8250_t *ins8250 = get_safe_token(device); |
| 245 | |
| 246 | ins8250->int_pending &= ~flag; |
| 247 | ins8250_update_interrupt(device); |
| 248 | } |
| 249 | |
| 250 | |
| 251 | WRITE8_DEVICE_HANDLER( ins8250_w ) |
| 252 | { |
| 253 | static const char P[8] = "NONENHNL"; /* names for parity select */ |
| 254 | ins8250_t *ins8250 = get_safe_token(device); |
| 255 | int tmp; |
| 256 | |
| 257 | switch (offset) |
| 258 | { |
| 259 | case 0: |
| 260 | if (ins8250->lcr & 0x80) |
| 261 | { |
| 262 | ins8250->dll = data; |
| 263 | tmp = ins8250->dlm * 256 + ins8250->dll; |
| 264 | COM_LOG(1,"COM_dll_w",("COM $%02x: [$%04x = %d baud]\n", |
| 265 | data, tmp, (tmp)?(int)(ins8250->interface->clockin/16/tmp):0)); |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | ins8250->thr = data; |
| 270 | COM_LOG(2,"COM_thr_w",("COM $%02x\n", data)); |
| 271 | |
| 272 | if (LOOP(n)) |
| 273 | { |
| 274 | ins8250->lsr |= 1; |
| 275 | ins8250->rbr = data; |
| 276 | } |
| 277 | /* writing to thr will clear the int */ |
| 278 | ins8250_clear_int(device, COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY); |
| 279 | } |
| 280 | break; |
| 281 | case 1: |
| 282 | if (ins8250->lcr & 0x80) |
| 283 | { |
| 284 | ins8250->dlm = data; |
| 285 | tmp = ins8250->dlm * 256 + ins8250->dll; |
| 286 | COM_LOG(1,"COM_dlm_w",("COM $%02x: [$%04x = %d baud]\n", |
| 287 | data, tmp, (tmp)?(int)(ins8250->interface->clockin/16/tmp):0)); |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | ins8250->ier = data; |
| 292 | COM_LOG(2,"COM_ier_w",("COM $%02x: enable int on RX %d, THRE %d, RLS %d, MS %d\n", |
| 293 | data, data&1, (data>>1)&1, (data>>2)&1, (data>>3)&1)); |
| 294 | } |
| 295 | break; |
| 296 | case 2: |
| 297 | COM_LOG(1,"COM_fcr_w",("COM $%02x (16550 only)\n", data)); |
| 298 | break; |
| 299 | case 3: |
| 300 | ins8250->lcr = data; |
| 301 | COM_LOG(1,"COM_lcr_w",("COM $%02x word length %d, stop bits %d, parity %c, break %d, DLAB %d\n", |
| 302 | data, 5+(data&3), 1+((data>>2)&1), P[(data>>3)&7], (data>>6)&1, (data>>7)&1)); |
| 303 | break; |
| 304 | case 4: |
| 305 | ins8250->mcr = data; |
| 306 | COM_LOG(1,"COM_mcr_w",("COM $%02x DTR %d, RTS %d, OUT1 %d, OUT2 %d, loopback %d\n", |
| 307 | data, data&1, (data>>1)&1, (data>>2)&1, (data>>3)&1, (data>>4)&1)); |
| 308 | if (ins8250->interface->handshake_out) |
| 309 | ins8250->interface->handshake_out(device,data); |
| 310 | break; |
| 311 | case 5: |
| 312 | break; |
| 313 | case 6: |
| 314 | break; |
| 315 | case 7: |
| 316 | ins8250->scr = data; |
| 317 | COM_LOG(2,"COM_scr_w",("COM $%02x\n", data)); |
| 318 | break; |
| 319 | } |
| 320 | |
| 321 | if (ins8250->interface->refresh_connected) |
| 322 | ins8250->interface->refresh_connected(device); |
| 323 | } |
| 324 | |
| 325 | |
| 326 | |
| 327 | READ8_DEVICE_HANDLER( ins8250_r ) |
| 328 | { |
| 329 | ins8250_t *ins8250 = get_safe_token(device); |
| 330 | int data = 0x0ff; |
| 331 | |
| 332 | switch (offset) |
| 333 | { |
| 334 | case 0: |
| 335 | if (ins8250->lcr & 0x80) |
| 336 | { |
| 337 | data = ins8250->dll; |
| 338 | COM_LOG(1,"COM_dll_r",("COM $%02x\n", data)); |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | data = ins8250->rbr; |
| 343 | if( ins8250->lsr & 0x01 ) |
| 344 | { |
| 345 | ins8250->lsr &= ~0x01; /* clear data ready status */ |
| 346 | COM_LOG(2,"COM_rbr_r",("COM $%02x\n", data)); |
| 347 | } |
| 348 | |
| 349 | ins8250_clear_int(device, COM_INT_PENDING_RECEIVED_DATA_AVAILABLE); |
| 350 | } |
| 351 | break; |
| 352 | case 1: |
| 353 | if (ins8250->lcr & 0x80) |
| 354 | { |
| 355 | data = ins8250->dlm; |
| 356 | COM_LOG(1,"COM_dlm_r",("COM $%02x\n", data)); |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | data = ins8250->ier; |
| 361 | COM_LOG(2,"COM_ier_r",("COM $%02x\n", data)); |
| 362 | } |
| 363 | break; |
| 364 | case 2: |
| 365 | data = ins8250->iir; |
| 366 | COM_LOG(2,"COM_iir_r",("COM $%02x\n", data)); |
| 367 | /* this may not be correct. It says that reading this register will |
| 368 | clear the int if this is the source of the int?? */ |
| 369 | ins8250_clear_int(device, COM_INT_PENDING_TRANSMITTER_HOLDING_REGISTER_EMPTY); |
| 370 | break; |
| 371 | case 3: |
| 372 | data = ins8250->lcr; |
| 373 | COM_LOG(2,"COM_lcr_r",("COM $%02x\n", data)); |
| 374 | break; |
| 375 | case 4: |
| 376 | data = ins8250->mcr; |
| 377 | COM_LOG(2,"COM_mcr_r",("COM $%02x\n", data)); |
| 378 | break; |
| 379 | case 5: |
| 380 | |
| 381 | #if 0 |
| 382 | if (ins8250->send.active && (timer_get_time()-ins8250->send.time>uart_byte_time(n))) |
| 383 | { |
| 384 | // currently polling is enough for pc1512 |
| 385 | ins8250->lsr |= 0x40; /* set TSRE */ |
| 386 | ins8250->send.active = 0; |
| 387 | if (LOOP(n)) |
| 388 | { |
| 389 | ins8250->lsr |= 1; |
| 390 | ins8250->rbr = ins8250->send.data; |
| 391 | } |
| 392 | } |
| 393 | #endif |
| 394 | ins8250->lsr |= 0x20; /* set THRE */ |
| 395 | data = ins8250->lsr; |
| 396 | if( ins8250->lsr & 0x1f ) |
| 397 | { |
| 398 | ins8250->lsr &= 0xe1; /* clear FE, PE and OE and BREAK bits */ |
| 399 | COM_LOG(2,"COM_lsr_r",("COM $%02x, DR %d, OE %d, PE %d, FE %d, BREAK %d, THRE %d, TSRE %d\n", |
| 400 | data, data&1, (data>>1)&1, (data>>2)&1, (data>>3)&1, (data>>4)&1, (data>>5)&1, (data>>6)&1)); |
| 401 | } |
| 402 | |
| 403 | /* reading line status register clears int */ |
| 404 | ins8250_clear_int(device, COM_INT_PENDING_RECEIVER_LINE_STATUS); |
| 405 | break; |
| 406 | case 6: |
| 407 | if (ins8250->mcr & 0x10) /* loopback test? */ |
| 408 | { |
| 409 | data = ins8250->mcr << 4; |
| 410 | /* build delta values */ |
| 411 | ins8250->msr = (ins8250->msr ^ data) >> 4; |
| 412 | ins8250->msr |= data; |
| 413 | } |
| 414 | data = ins8250->msr; |
| 415 | ins8250->msr &= 0xf0; /* reset delta values */ |
| 416 | COM_LOG(2,"COM_msr_r",("COM $%02x\n", data)); |
| 417 | |
| 418 | /* reading msr clears int */ |
| 419 | ins8250_clear_int(device, COM_INT_PENDING_MODEM_STATUS_REGISTER); |
| 420 | |
| 421 | break; |
| 422 | case 7: |
| 423 | data = ins8250->scr; |
| 424 | COM_LOG(2,"COM_scr_r",("COM $%02x\n", data)); |
| 425 | break; |
| 426 | } |
| 427 | |
| 428 | if (ins8250->interface->refresh_connected) |
| 429 | ins8250->interface->refresh_connected(device); |
| 430 | |
| 431 | return data; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | |
| 436 | void ins8250_receive(const device_config *device, int data) |
| 437 | { |
| 438 | ins8250_t *ins8250 = get_safe_token(device); |
| 439 | |
| 440 | /* check if data rate 1200 baud is set */ |
| 441 | if( ins8250->dlm != 0x00 || ins8250->dll != 0x60 ) |
| 442 | ins8250->lsr |= 0x08; /* set framing error */ |
| 443 | |
| 444 | /* if data not yet serviced */ |
| 445 | if( ins8250->lsr & 0x01 ) |
| 446 | ins8250->lsr |= 0x02; /* set overrun error */ |
| 447 | |
| 448 | /* put data into receiver buffer register */ |
| 449 | ins8250->rbr = data; |
| 450 | |
| 451 | /* set data ready status */ |
| 452 | ins8250->lsr |= 0x01; |
| 453 | |
| 454 | /* set pending state for this interrupt. */ |
| 455 | ins8250_trigger_int(device, COM_INT_PENDING_RECEIVED_DATA_AVAILABLE); |
| 456 | |
| 457 | |
| 458 | // /* OUT2 + received line data avail interrupt enabled? */ |
| 459 | // if( (COM_mcr[n] & 0x08) && (COM_ier[n] & 0x01) ) |
| 460 | // { |
| 461 | // if (com_interface.interrupt) |
| 462 | // com_interface.interrupt(4-(n&1), 1); |
| 463 | // |
| 464 | // } |
| 465 | } |
| 466 | |
| 467 | /************************************************************************** |
| 468 | * change the modem status register |
| 469 | **************************************************************************/ |
| 470 | void ins8250_handshake_in(const device_config *device, int new_msr) |
| 471 | { |
| 472 | ins8250_t *ins8250 = get_safe_token(device); |
| 473 | |
| 474 | /* no change in modem status bits? */ |
| 475 | if( ((ins8250->msr ^ new_msr) & 0xf0) == 0 ) |
| 476 | return; |
| 477 | |
| 478 | /* set delta status bits 0..3 and new modem status bits 4..7 */ |
| 479 | ins8250->msr = (((ins8250->msr ^ new_msr) >> 4) & 0x0f) | (new_msr & 0xf0); |
| 480 | |
| 481 | ins8250_trigger_int(device, COM_INT_PENDING_MODEM_STATUS_REGISTER); |
| 482 | |
| 483 | // /* set up interrupt information register */ |
| 484 | // COM_iir[n] &= ~(0x06 | 0x01); |
| 485 | |
| 486 | // /* OUT2 + modem status interrupt enabled? */ |
| 487 | // if( (COM_mcr[n] & 0x08) && (COM_ier[n] & 0x08) ) |
| 488 | // { |
| 489 | // if (com_interface.interrupt) |
| 490 | // com_interface.interrupt(4-(n&1), 1); |
| 491 | // } |
| 492 | } |
| 493 | |
| 494 | |
| 495 | static void common_start( const device_config *device, int device_type ) { |
| 496 | ins8250_t *ins8250 = get_safe_token(device); |
| 497 | |
| 498 | ins8250->interface = device->static_config; |
| 499 | ins8250->device_type = device_type; |
| 500 | } |
| 501 | |
| 502 | |
| 503 | static DEVICE_START( ins8250 ) { |
| 504 | common_start( device, TYPE_INS8250 ); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | static DEVICE_START( ins8250a ) { |
| 509 | common_start( device, TYPE_INS8250A ); |
| 510 | } |
| 511 | |
| 512 | |
| 513 | static DEVICE_START( ns16450 ) { |
| 514 | common_start( device, TYPE_NS16450 ); |
| 515 | } |
| 516 | |
| 517 | |
| 518 | static DEVICE_START( ns16550 ) { |
| 519 | common_start( device, TYPE_NS16550 ); |
| 520 | } |
| 521 | |
| 522 | |
| 523 | static DEVICE_START( ns16550a ) { |
| 524 | common_start( device, TYPE_NS16550A ); |
| 525 | } |
| 526 | |
| 527 | |
| 528 | static DEVICE_START( pc16550d ) { |
| 529 | common_start( device, TYPE_PC16550D ); |
| 530 | } |
| 531 | |
| 532 | |
| 533 | static DEVICE_RESET( ins8250 ) { |
| 534 | ins8250_t *ins8250 = get_safe_token(device); |
| 535 | |
| 536 | ins8250->ier = 0; |
| 537 | ins8250->iir = 1; |
| 538 | ins8250->lcr = 0; |
| 539 | ins8250->mcr = 0; |
| 540 | ins8250->lsr = (1<<5) | (1<<6); |
| 541 | |
| 542 | ins8250->send.active=0; |
| 543 | |
| 544 | /* refresh with reset state of register */ |
| 545 | if (ins8250->interface->refresh_connected) |
| 546 | ins8250->interface->refresh_connected(device); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | static DEVICE_SET_INFO( ins8250 ) { |
| 551 | switch ( state ) { |
| 552 | /* no parameters to set */ |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | |
| 557 | DEVICE_GET_INFO( ins8250 ) { |
| 558 | switch ( state ) { |
| 559 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 560 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ins8250_t); break; |
| 561 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 562 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 563 | |
| 564 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 565 | case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(ins8250); break; |
| 566 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ins8250); break; |
| 567 | case DEVINFO_FCT_STOP: /* nothing */ break; |
| 568 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(ins8250); break; |
| 569 | |
| 570 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 571 | case DEVINFO_STR_NAME: info->s = "National Semiconductor INS8250/INS8250B"; break; |
| 572 | case DEVINFO_STR_FAMILY: info->s = "INS8250"; break; |
| 573 | case DEVINFO_STR_VERSION: info->s = "1.00"; break; |
| 574 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 575 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MESS Team"; break; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | |
| 580 | DEVICE_GET_INFO( ins8250a ) { |
| 581 | switch ( state ) { |
| 582 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 583 | case DEVINFO_STR_NAME: info->s = "National Semiconductor INS8250A/INS82C50A"; break; |
| 584 | |
| 585 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 586 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ins8250a); break; |
| 587 | |
| 588 | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | |
| 593 | DEVICE_GET_INFO( ns16450 ) { |
| 594 | switch ( state ) { |
| 595 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 596 | case DEVINFO_STR_NAME: info->s = "National Semiconductor NS16450/PC16450"; break; |
| 597 | |
| 598 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 599 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ns16450); break; |
| 600 | |
| 601 | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | |
| 606 | DEVICE_GET_INFO( ns16550 ) { |
| 607 | switch ( state ) { |
| 608 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 609 | case DEVINFO_STR_NAME: info->s = "National Semiconductor NS16550/PC16550"; break; |
| 610 | |
| 611 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 612 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ns16550); break; |
| 613 | |
| 614 | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | |
| 619 | DEVICE_GET_INFO( ns16550a ) { |
| 620 | switch ( state ) { |
| 621 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 622 | case DEVINFO_STR_NAME: info->s = "National Semiconductor NS16550A/PC16550A"; break; |
| 623 | |
| 624 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 625 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ns16550a); break; |
| 626 | |
| 627 | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
| 632 | DEVICE_GET_INFO( pc16550d ) { |
| 633 | switch ( state ) { |
| 634 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 635 | case DEVINFO_STR_NAME: info->s = "National Semiconductor PC16550D"; break; |
| 636 | |
| 637 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 638 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(pc16550d); break; |
| 639 | |
| 640 | default: DEVICE_GET_INFO_CALL(ins8250); break; |
| 641 | } |
| 642 | } |
| 643 | |
src/mess/drivers/at.c
| r2435 | r2436 | |
| 7 | 7 | #include "driver.h" |
| 8 | 8 | #include "sound/3812intf.h" |
| 9 | 9 | #include "machine/8255ppi.h" |
| 10 | | #include "machine/uart8250.h" |
| 10 | #include "machine/ins8250.h" |
| 11 | 11 | #include "machine/mc146818.h" |
| 12 | 12 | #include "machine/pic8259.h" |
| 13 | 13 | #include "devices/printer.h" |
| r2435 | r2436 | |
| 118 | 118 | DEV_READWRITE8TO32LE( at_dma8237_32le, dma8237_r, dma8237_w ) |
| 119 | 119 | DEV_READWRITE8TO32LE( at_pic8259_32le, pic8259_r, pic8259_w ) |
| 120 | 120 | DEV_READWRITE8TO32LE( at_dma8237_1_32le, at_dma8237_1_r, at_dma8237_1_w ) |
| 121 | | DEV_READWRITE8TO32LE( uart8250_32le, ins8250_r, ins8250_w ) |
| 121 | DEV_READWRITE8TO32LE( ins8250_32le, ins8250_r, ins8250_w ) |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | static ADDRESS_MAP_START(at_io, ADDRESS_SPACE_IO, 8) |
| r2435 | r2436 | |
| 172 | 172 | AM_RANGE(0x00a0, 0x00bf) AM_DEVREADWRITE(PIC8259, "pic8259_slave", at_pic8259_32le_r, at_pic8259_32le_w) |
| 173 | 173 | AM_RANGE(0x00c0, 0x00df) AM_DEVREADWRITE(DMA8237, "dma8237_2", at_dma8237_1_32le_r, at_dma8237_1_32le_w) |
| 174 | 174 | AM_RANGE(0x0278, 0x027f) AM_READWRITE(pc32le_parallelport2_r, pc32le_parallelport2_w) |
| 175 | | AM_RANGE(0x02e8, 0x02ef) AM_DEVREADWRITE(NS16450, "ns16450_3", uart8250_32le_r, uart8250_32le_w) |
| 176 | | AM_RANGE(0x02f8, 0x02ff) AM_DEVREADWRITE(NS16450, "ns16450_1", uart8250_32le_r, uart8250_32le_w) |
| 175 | AM_RANGE(0x02e8, 0x02ef) AM_DEVREADWRITE(NS16450, "ns16450_3", ins8250_32le_r, ins8250_32le_w) |
| 176 | AM_RANGE(0x02f8, 0x02ff) AM_DEVREADWRITE(NS16450, "ns16450_1", ins8250_32le_r, ins8250_32le_w) |
| 177 | 177 | AM_RANGE(0x0320, 0x0323) AM_READWRITE(pc32le_HDC1_r, pc32le_HDC1_w) |
| 178 | 178 | AM_RANGE(0x0324, 0x0327) AM_READWRITE(pc32le_HDC2_r, pc32le_HDC2_w) |
| 179 | 179 | AM_RANGE(0x0378, 0x037f) AM_READWRITE(pc32le_parallelport1_r, pc32le_parallelport1_w) |
| 180 | 180 | AM_RANGE(0x03f0, 0x03f7) AM_READWRITE(pc32le_fdc_r, pc32le_fdc_w) |
| 181 | 181 | AM_RANGE(0x03bc, 0x03bf) AM_READWRITE(pc32le_parallelport0_r, pc32le_parallelport0_w) |
| 182 | | AM_RANGE(0x03f8, 0x03ff) AM_DEVREADWRITE(NS16450, "ns16450_0", uart8250_32le_r, uart8250_32le_w) |
| 182 | AM_RANGE(0x03f8, 0x03ff) AM_DEVREADWRITE(NS16450, "ns16450_0", ins8250_32le_r, ins8250_32le_w) |
| 183 | 183 | ADDRESS_MAP_END |
| 184 | 184 | |
| 185 | 185 | |
| r2435 | r2436 | |
| 194 | 194 | AM_RANGE(0x00a0, 0x00bf) AM_DEVREADWRITE(PIC8259, "pic8259_slave", at_pic8259_32le_r, at_pic8259_32le_w) |
| 195 | 195 | AM_RANGE(0x00c0, 0x00df) AM_DEVREADWRITE(DMA8237, "dma8237_2", at_dma8237_1_32le_r, at_dma8237_1_32le_w) |
| 196 | 196 | AM_RANGE(0x0278, 0x027f) AM_READWRITE(pc32le_parallelport2_r, pc32le_parallelport2_w) |
| 197 | | AM_RANGE(0x02e8, 0x02ef) AM_DEVREADWRITE(NS16450, "ns16450_3", uart8250_32le_r, uart8250_32le_w) |
| 198 | | AM_RANGE(0x02f8, 0x02ff) AM_DEVREADWRITE(NS16450, "ns16450_1", uart8250_32le_r, uart8250_32le_w) |
| 197 | AM_RANGE(0x02e8, 0x02ef) AM_DEVREADWRITE(NS16450, "ns16450_3", ins8250_32le_r, ins8250_32le_w) |
| 198 | AM_RANGE(0x02f8, 0x02ff) AM_DEVREADWRITE(NS16450, "ns16450_1", ins8250_32le_r, ins8250_32le_w) |
| 199 | 199 | AM_RANGE(0x0320, 0x0323) AM_READWRITE(pc32le_HDC1_r, pc32le_HDC1_w) |
| 200 | 200 | AM_RANGE(0x0324, 0x0327) AM_READWRITE(pc32le_HDC2_r, pc32le_HDC2_w) |
| 201 | 201 | AM_RANGE(0x0378, 0x037f) AM_READWRITE(pc32le_parallelport1_r, pc32le_parallelport1_w) |
| 202 | 202 | AM_RANGE(0x03f0, 0x03f7) AM_READWRITE(pc32le_fdc_r, pc32le_fdc_w) |
| 203 | 203 | AM_RANGE(0x03bc, 0x03bf) AM_READWRITE(pc32le_parallelport0_r, pc32le_parallelport0_w) |
| 204 | | AM_RANGE(0x03f8, 0x03ff) AM_DEVREADWRITE(NS16450, "ns16450_0", uart8250_32le_r, uart8250_32le_w) |
| 204 | AM_RANGE(0x03f8, 0x03ff) AM_DEVREADWRITE(NS16450, "ns16450_0", ins8250_32le_r, ins8250_32le_w) |
| 205 | 205 | AM_RANGE(0x0cf8, 0x0cff) AM_READWRITE(pci_32le_r, pci_32le_w) |
| 206 | 206 | ADDRESS_MAP_END |
| 207 | 207 | |