1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
|
// dhu.c - DHU11/DHV11/DHQ11 Terminal Controller
//
// Copyright (c) 2002, Timothy M. Stark
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// TIMOTHY M STARK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Except as contained in this notice, the name of Timothy M Stark shall not
// be used in advertising or otherwise to promote the sale, use or other
// dealings in this Software without prior written authorization from
// Timothy M Stark.
#include "emu/defs.h"
#include "dev/dec/dhu.h"
// *************************************************************
#ifdef HAVE_SIGACTION
#include <sys/file.h>
#include <unistd.h>
#include <stropts.h>
#include <signal.h>
#endif /* HAVE_SIGACTION */
// Send initialization codes to make sure that telnet behave correctly.
static int n_telnetInit = 15;
static char telnetInit[] =
{
255, 251, 34, // IAC WILL LINEMODE
255, 251, 3, // IAC WILL SGA
255, 251, 1, // IAC WILL ECHO
255, 251, 0, // IAC WILL BINARY
255, 253, 0, // IAC DO BINARY
};
void dhu_Accept(SOCKET *);
void dhu_Eof(SOCKET *, int, int);
void dhu_Input(SOCKET *, char *, int);
void dhu_TransmitDMA(void *);
void dhu_Transmit(void *);
void dhu_Queue(void *);
// Inline Macro definitions here
inline void dhu_RingRX(DH_DEVICE *dh)
{
MAP_IO *io = &dh->ioMap;
if (dh->csr & CSR_RXIE) {
io->SendInterrupt(io, RXINT);
#ifdef DEBUG
if (dbg_Check(DBG_INTERRUPT))
dbg_Printf("%s: Ring for receive interrupt.\n", dh->Unit.devName);
#endif /* DEBUG */
}
}
inline void dhu_RingTX(DH_DEVICE *dh)
{
MAP_IO *io = &dh->ioMap;
if (dh->csr & CSR_TXIE) {
io->SendInterrupt(io, TXINT);
#ifdef DEBUG
if (dbg_Check(DBG_INTERRUPT))
dbg_Printf("%s: Ring for transmit interrupt.\n", dh->Unit.devName);
#endif /* DEBUG */
}
}
inline void dhu_UpdateStatus(DH_TTY *tty, uint16 set, uint16 clr)
{
DH_DEVICE *dh = tty->Device;
uint16 rx;
// Update line status register.
STAT = (STAT | set) & ~clr;
// If a link type is set, put that in receiving FIFO.
if (LNC & LNC_LINK) {
rx = (RBUF_VALID|RBUF_STATUS) | ((tty->idPort) << 8) |
((STAT >> 8) & ~1);
dh->rbuf[dh->idxIn++] = rx;
if (dh->idxIn >= LEN_RBUF)
dh->idxIn = 0;
}
// Finally, ring host for receive interrupt.
dhu_RingRX(dh);
}
// Initialize DHx11 Server
SOCKET *dhu_InitServer(DH_DEVICE *dh)
{
SOCKET *newServer = NULL;
// Set up the listing socket for CTY device.
if (newServer = sock_Open(dh->Unit.keyName, TTY_PORT, NET_SERVER)) {
newServer->maxConns = dh->nPorts;
newServer->nConns = 0;
newServer->Accept = dhu_Accept;
newServer->Eof = NULL;
newServer->Process = NULL;
newServer->Device = dh;
dh->Server = newServer;
// Now accept incoming connections;
sock_Listen(newServer, 5);
// Tell operator that.
printf("Activating %s: (%s) on TCP port %d.\n",
dh->Unit.devName, dh->Unit.keyName, TTY_PORT);
} else {
printf("Can't activate %s: (%s) - Aborted.\n",
dh->Unit.devName, dh->Unit.keyName);
}
return newServer;
}
// Initialize TTY lines
void dhu_InitLines(DH_DEVICE *dh)
{
DH_TTY *tty;
CLK_QUEUE *timer;
int idx;
// Initialize Ports
for (idx = 0; idx < dh->nPorts; idx++) {
tty = &dh->Ports[idx];
tty->Device = dh;
tty->idPort = idx;
timer = &tty->dmaTimer;
timer->Next = NULL;
timer->Name = "DHV11 Transmit DMA Timer";
timer->Flags = 0;
timer->outTimer = TTY_TBDELAY;
timer->nxtTimer = TTY_TBDELAY;
timer->Device = tty;
timer->Execute = dhu_TransmitDMA;
timer = &tty->txTimer;
timer->Next = NULL;
timer->Name = "DHV11 Transmit Timer";
timer->Flags = 0;
timer->outTimer = TTY_TXDELAY;
timer->nxtTimer = TTY_TXDELAY;
timer->Device = tty;
timer->Execute = dhu_Transmit;
timer = &tty->qTimer;
timer->Next = NULL;
timer->Name = "DHV11 Queue Timer";
timer->Flags = 0;
timer->outTimer = TTY_QDELAY;
timer->nxtTimer = TTY_QDELAY;
timer->Device = tty;
timer->Execute = dhu_Queue;
}
// Mark ports as non-existant.
for (; idx < DH_NPORTS; idx++)
dh->Ports[idx].idPort = -1;
}
void dhu_Cleanup(DH_DEVICE *dh)
{
}
void dhu_Accept(SOCKET *srvSocket)
{
DH_DEVICE *dh = (DH_DEVICE *)srvSocket->Device;
DH_TTY *tty = NULL;
SOCKET *newSocket;
uint32 idx;
if (newSocket = sock_Accept(srvSocket)) {
// Find a free tty line to assign.
for (idx = 0; idx < dh->nPorts; idx++) {
if (dh->Ports[idx].Socket == NULL) {
tty = &dh->Ports[idx];
break;
}
}
// If a tty line not found, tell user that.
if (tty == NULL) {
sock_Print(newSocket, "All circuits are busy. Try again later.\r\n", 0);
sock_Print(newSocket, "\r\nTerminated.\r\n", 0);
sock_Close(newSocket);
return;
}
// Set up the CTY socket connection.
newSocket->Accept = NULL;
newSocket->Eof = dhu_Eof;
newSocket->Process = dhu_Input;
newSocket->Device = tty;
tty->Socket = newSocket;
// Reset all buffer for this new connection.
tty->idxInQueue = 0;
tty->idxOutQueue = 0;
tty->idxOutBuffer = 0;
// Send initialization codes and welcome messages
sock_Print(newSocket, telnetInit, n_telnetInit);
sock_Print(newSocket, "Welcome to TS10 Emulator\r\n\r\n", 0);
sock_Print(newSocket, "Please press RETURN to enter.\r\n", 0);
// dbg_SetMode(DBG_TRACE|DBG_DATA|DBG_PAGEFAULT|DBG_INTERRUPT);
// Initially, Set DSR, DCD and CTS bits and ring host.
dhu_UpdateStatus(tty, STAT_DSR|STAT_DCD|STAT_CTS, 0);
}
}
void dhu_Eof(SOCKET *Socket, int rc, int nError)
{
DH_TTY *tty = (DH_TTY *)Socket->Device;
// Drop CTS, DCD and DSR bit to sign off.
dhu_UpdateStatus(tty, 0, STAT_DCD|STAT_DSR|STAT_CTS);
sock_Close(Socket);
tty->Socket = NULL;
}
void dhu_Input(SOCKET *Socket, char *keyBuffer, int len)
{
DH_TTY *tty = (DH_TTY *)Socket->Device;
DH_DEVICE *dh = tty->Device;
boolean okSend = FALSE;
uint16 rx;
uchar ch;
int idx;
// Process telnet codes and filter them out of data stream.
if (len > 1) {
if ((len = sock_ProcessTelnet(keyBuffer, len)) == 0)
return;
}
for (idx = 0; idx < len; idx++) {
ch = keyBuffer[idx];
// Press ^\ twice to disconnect.
if (ch == TTY_ESCAPE) {
if (tty->lastSeen == TTY_ESCAPE) {
dhu_Eof(Socket, 0, 0);
return;
}
tty->lastSeen = ch;
continue;
}
// Convert CR NL to CR line.
if ((ch == 012) && (tty->lastSeen == 015))
continue;
tty->lastSeen = ch;
okSend = TRUE;
tty->inBuffer[tty->idxInQueue] = ch;
if (++tty->idxInQueue == TTY_BUFFER)
tty->idxInQueue = 0;
if (tty->idxInQueue == tty->idxOutQueue) {
// When data overrun occurs, rest of input buffer is lost.
// Also tell VAX system that it is data overrun.
break;
}
}
if (okSend) {
// Dequeue a oldest character from internal receive buffer.
ch = tty->inBuffer[tty->idxOutQueue++];
if (tty->idxOutQueue == TTY_BUFFER)
tty->idxOutQueue = 0;
// Put that in receiving FIFO buffer and
// ring host for receive interrupt.
rx = RBUF_VALID | ((tty->idPort) << 8) | ch;
dh->rbuf[dh->idxIn++] = rx;
if (dh->idxIn >= LEN_RBUF)
dh->idxIn = 0;
dh->csr |= CSR_RXAVAIL;
dhu_RingRX(dh);
}
// Activate queue timer if any characters still are
// remaining in their input queue.
if (tty->idxOutQueue != tty->idxInQueue)
ts10_SetTimer(&tty->qTimer);
}
// Transmit DMA Process
void dhu_TransmitDMA(void *dev)
{
DH_TTY *tty = (DH_TTY *)dev;
DH_DEVICE *dh = tty->Device;
uint32 cntBytes = TBCNT;
uint32 errFlag = 0;
if (cntBytes > 0) {
UQ_CALL *call = dh->Callback;
uint32 hstAddr = ((TBAD2 & TBAD2_ADDR) << 16) | TBAD1;
uint32 len = (cntBytes > 256) ? 256 : cntBytes;
uchar bufData[256];
uint32 txBytes;
// Attempts transfer data from host.
if (txBytes = call->ReadBlock(dh->System, hstAddr, bufData, len, 0)) {
errFlag = CSR_TXERR;
len -= txBytes;
}
// Send good data to outside.
if (len) {
sock_Print(tty->Socket, bufData, len);
hstAddr += len;
cntBytes -= len;
}
// Update registers
TBAD1 = hstAddr;
TBAD2 = ((hstAddr >> 16) & TBAD2_ADDR) | (TBAD2 & ~TBAD2_ADDR);
TBCNT = errFlag ? 0 : cntBytes;
if ((errFlag == 0) && (cntBytes > 0)) {
ts10_SetTimer(&tty->dmaTimer);
return;
}
}
// Transmit DMA Completed
TBAD2 &= ~TBAD2_START;
if ((CSR & CSR_TXACT) == 0)
CSR |= (tty->idPort << 8) | errFlag | CSR_TXACT;
else {
TBUF[dh->idxTxIn++] = (tty->idPort << 8) | errFlag | CSR_TXACT;
if (dh->idxTxIn >= LEN_TBUF)
dh->idxTxIn = 0;
}
dhu_RingTX(dh);
}
void dhu_AbortDMA(DH_TTY *tty)
{
DH_DEVICE *dh = tty->Device;
// Abort all DMA transfers for this TTY line.
if (tty->dmaTimer.Flags & CLK_PENDING)
ts10_CancelTimer(&tty->dmaTimer);
// Abort DMA Done.
if ((CSR & CSR_TXACT) == 0)
CSR |= (tty->idPort << 8) | CSR_TXACT;
else {
TBUF[dh->idxTxIn++] = (tty->idPort << 8) | CSR_TXACT;
if (dh->idxTxIn >= LEN_TBUF)
dh->idxTxIn = 0;
}
dhu_RingTX(dh);
}
void dhu_Transmit(void *dev)
{
DH_TTY *tty = (DH_TTY *)dev;
DH_DEVICE *dh = tty->Device;
uchar ch;
if (tty->Socket && (TXCH & TXCH_VALID)) {
ch = TXCH;
sock_Print(tty->Socket, &ch, 1);
// Done, ring host for next transmit.
TXCH &= ~TXCH_VALID;
if ((CSR & CSR_TXACT) == 0)
CSR |= (tty->idPort << 8) | CSR_TXACT;
else {
TBUF[dh->idxTxIn++] = (tty->idPort << 8) | CSR_TXACT;
if (dh->idxTxIn >= LEN_TBUF)
dh->idxTxIn = 0;
}
dhu_RingTX(dh);
#if 0
// Log a character into a log file.
if (ch == '\n') {
tty->outBuffer[tty->idxOutBuffer++] = ch;
tty->outBuffer[tty->idxOutBuffer++] = '\0';
// Implement: Log session here.
tty->idxOutBuffer = 0;
} else {
if (ch == '\b' || ch == 127) {
if (tty->idxOutBuffer > 0)
tty->idxOutBuffer--;
} else if (ch != '\r' && ch != '\0') {
if (tty->idxOutBuffer < TTY_BUFFER-1)
tty->outBuffer[tty->idxOutBuffer++] = ch;
}
}
#endif
}
}
// Check Queue for this TTY line.
void dhu_Queue(void *dev)
{
DH_TTY *tty = (DH_TTY *)dev;
DH_DEVICE *dh = tty->Device;
uint16 rx;
uchar ch;
if (tty->idxOutQueue != tty->idxInQueue) {
// Dequeue a oldest character from internal receive buffer.
ch = tty->inBuffer[tty->idxOutQueue++];
if (tty->idxOutQueue == TTY_BUFFER)
tty->idxOutQueue = 0;
// Finally, put data into FIFO receive buffer and
// ring host for receive interrupt.
rx = RBUF_VALID | ((tty->idPort) << 8) | ch;
dh->rbuf[dh->idxIn++] = rx;
if (dh->idxIn >= LEN_RBUF)
dh->idxIn = 0;
dh->csr |= CSR_RXAVAIL;
dhu_RingRX(dh);
// Reactivate queue timer if characters still are
// remaining in their input queue.
if (tty->idxOutQueue != tty->idxInQueue)
ts10_SetTimer(&tty->qTimer);
}
}
// *************************************************************
#ifdef DEBUG
static cchar *regNameR[] =
{
"CSR", // Control and Status Register
"RBUF", // Receive Buffer
"LPR", // Line Parameter Register
"STAT", // Line Status Register
"LNCTRL", // Line Control Register
"TBUFFAD1", // Transmit Buffer Address 1
"TBUFFAD2", // Transmit Buffer Address 2
"TBUFFCT" // Transmit Buffer Count
};
static cchar *regNameW[] =
{
"CSR", // Control and Status Register
"TXCHAR", // Transmit Character
"LPR", // Line Parameter Register
"STAT", // Line Status Register (Read-Only)
"LNCTRL", // Line Control Register
"TBUFFAD1", // Transmit Buffer Address 1
"TBUFFAD2", // Teansmit Buffer Address 2
"TBUFFCT" // Transmit Buffer Count
};
#endif /* DEBUG */
void dhu_MasterReset(DH_DEVICE *dh)
{
DH_TTY *tty;
uint32 idx;
uint16 rx;
// Initialize Registers
dh->csr = (dh->csr | CSR_RXAVAIL) & ~CSR_TXACT;
for (idx = 0; idx < dh->nPorts; idx++) {
tty = &dh->Ports[idx];
// Disconnect sockets if online.
if (tty->Socket) {
// Close existing socket on this TTY line.
sock_Close(tty->Socket);
tty->Socket = NULL;
}
// Initialize line registers.
LPR = PUT_TXSP(BAUD_9600) | PUT_RXSP(BAUD_9600)
| PUT_CHLEN(BIT_8);
STAT = 0;
LNC = 0;
TBAD1 = 0;
TBAD2 = TBAD2_TXEN;
TBCNT = 0;
}
// Initialize and put diagnostic codes
// into FIFO receive buffer.
rx = (RBUF_VALID|RBUF_STATUS);
dh->idxIn = 0;
dh->idxOut = 0;
for (idx = 0; idx < 6; idx++)
dh->rbuf[dh->idxIn++] = rx | 0203; // Self-test skipped code.
dh->rbuf[dh->idxIn++] = rx | 0001; // Two ROM Version Codes.
dh->rbuf[dh->idxIn++] = rx | 0003;
dh->idxTxIn = 0;
dh->idxTxOut = 0;
// When Master Reset is done, clear it.
dh->csr &= ~CSR_RESET;
}
// Bus Initialization
void dhu_ResetDevice(DH_DEVICE *dh)
{
MAP_IO *io = &dh->ioMap;
// Reset Control/Status Register
dh->csr = (dh->csr | CSR_RESET) & ~(CSR_RXIE|CSR_TXIE);
if (io->CancelInterrupt) {
io->CancelInterrupt(io, RXINT);
io->CancelInterrupt(io, TXINT);
}
dhu_MasterReset(dh);
}
int dhu_ReadIO(void *dptr, uint32 pAddr, uint16 *data, uint32 acc)
{
DH_DEVICE *dh = (DH_DEVICE *)dptr;
DH_TTY *tty;
uint32 reg = (pAddr - (dh->csrAddr & 0x1FFF)) >> 1;
if (reg == DH_CSR) {
// Control and Status Register
*data = dh->csr;
// Clear TX.ACTION bit after each read.
dh->csr &= ~(CSR_TXACT|CSR_TXLINE);
if (dh->idxTxIn != dh->idxTxOut) {
CSR |= TBUF[dh->idxTxOut++];
if (dh->idxTxOut >= LEN_TBUF)
dh->idxTxOut = 0;
dhu_RingTX(dh);
}
} else if (reg == DH_RBUF) {
// Receive Buffer Register
if (dh->idxIn != dh->idxOut) {
// Dequeue oldest character in RBUF queue.
*data = dh->rbuf[dh->idxOut++];
if (dh->idxOut >= LEN_RBUF)
dh->idxOut = 0;
// When FIFO is empty, clear RX.DATA.AVAIL bit.
if (dh->idxOut == dh->idxIn)
dh->csr &= ~CSR_RXAVAIL;
} else
*data = 0;
} else {
tty = &dh->Ports[dh->csr & CSR_LINE];
*data = MREG(reg);
}
#ifdef DEBUG
if (dbg_Check(DBG_IOREGS))
dbg_Printf("%s: (R) %s (%o) => %06o (%04X) (Size: %d bytes)\n",
dh->Unit.devName, regNameR[reg], pAddr, *data, *data, acc);
#endif /* DEBUG */
return UQ_OK;
}
int dhu_WriteIO(void *dptr, uint32 pAddr, uint16 data, uint32 acc)
{
DH_DEVICE *dh = (DH_DEVICE *)dptr;
DH_TTY *tty;
uint32 reg = (pAddr - (dh->csrAddr & 0x1FFF)) >> 1;
if (reg == DH_CSR) {
MAP_IO *io = &dh->ioMap;
if (acc == ACC_BYTE) // If access is byte, merge data with CSR.
data = (pAddr & 1) ? ((data << 8) | (dh->csr & 0377)) :
((data & 0377) | (dh->csr & ~0377));
// If set, execute master reset.
if (data & CSR_RESET) {
data &= ~CSR_RESET; // Temp. patch
dhu_MasterReset(dh);
}
// Check Receive Interrupt Enable
if ((data & CSR_RXIE) == 0)
io->CancelInterrupt(io, RXINT);
else if (dh->csr & CSR_RXAVAIL)
io->SendInterrupt(io, RXINT);
// Check Transmit Interrupt Enable
if ((data & CSR_TXIE) == 0)
io->CancelInterrupt(io, TXINT);
else if (dh->csr & CSR_TXACT)
io->SendInterrupt(io, TXINT);
dh->csr = (data & CSR_RW) | (dh->csr & ~CSR_RW);
} else {
tty = &dh->Ports[dh->csr & CSR_LINE];
switch (reg) {
case DH_TXCHAR: // Transmit Character
if (acc == ACC_BYTE) // If access is byte, merge with TXCH.
data = (pAddr & 1) ? ((data << 8) | (TXCH & 0377)) :
((data & 0377) | (TXCH & ~0377));
TXCH = data & TXCH_RW;
if (TXCH & TXCH_VALID)
ts10_SetTimer(&tty->txTimer);
break;
case DH_LPR: // Line Parameter Register
if (acc == ACC_BYTE) // if access is byte, merge with LPR.
data = (pAddr & 1) ? ((data << 8) | (LPR & 0377)) :
((data & 0377) | (LPR & ~0377));
LPR = data & LPR_RW;
break;
case DH_STAT: // Line Status Register (Read-Only)
break;
case DH_LNCTRL: // Line Control Register
if (acc == ACC_BYTE) // if access is byte, merge with LNC.
data = (pAddr & 1) ? ((data << 8) | (LNC & 0377)) :
((data & 0377) | (LNC & ~0377));
LNC = data & LNC_RW;
if (data & LNC_ABORT)
dhu_AbortDMA(tty);
break;
case DH_TBUFFAD1: // Transmit Buffer Address #1 Register
if (acc == ACC_BYTE) // if access is byte, merge with TBAD1.
data = (pAddr & 1) ? ((data << 8) | (TBAD1 & 0377)) :
((data & 0377) | (TBAD1 & ~0377));
TBAD1 = data;
break;
case DH_TBUFFAD2: // Transmit Buffer Address #2 Register
if (acc == ACC_BYTE) // if access is byte, merge with TBAD2.
data = (pAddr & 1) ? ((data << 8) | (TBAD2 & 0377)) :
((data & 0377) | (TBAD2 & ~0377));
TBAD2 = data & TBAD2_RW;
// Start transmit DMA if request.
if (TBAD2 & TBAD2_START)
ts10_SetTimer(&tty->dmaTimer);
break;
case DH_TBUFFCT: // Transmit Buffer Count Register
if (acc == ACC_BYTE) // if access is byte, merge with TBCNT.
data = (pAddr & 1) ? ((data << 8) | (TBCNT & 0377)) :
((data & 0377) | (TBCNT & ~0377));
TBCNT = data;
break;
#ifdef DEBUG
default:
dbg_Printf("%s: *** Undefined Register %d (%06o) at line %d in file %s\n",
dh->Unit.devName, reg, pAddr & 0x1FFF, __LINE__, __FILE__);
return UQ_NXM;
#endif /* DEBUG */
}
}
#ifdef DEBUG
if (dbg_Check(DBG_IOREGS))
dbg_Printf("%s: (W) %s (%o) <= %06o (%04X) (Size: %d bytes)\n",
dh->Unit.devName, regNameW[reg], pAddr, data, data, acc);
#endif /* DEBUG */
return UQ_OK;
}
// Bus Initialization
void dhu_ResetIO(void *dptr)
{
dhu_ResetDevice(dptr);
#ifdef DEBUG
if (dbg_Check(DBG_IOREGS))
dbg_Printf("Done.\n");
#endif /* DEBUG */
}
// **************************************************************
void *dhu_Create(MAP_DEVICE *newMap, int argc, char **argv)
{
DH_DEVICE *dh = NULL;
MAP_IO *io;
if (dh = (DH_DEVICE *)calloc(1, sizeof(DH_DEVICE))) {
// First, set up its description and
// link it to its parent device.
dh->Unit.devName = newMap->devName;
dh->Unit.keyName = newMap->keyName;
dh->Unit.emuName = newMap->emuName;
dh->Unit.emuVersion = newMap->emuVersion;
dh->Device = newMap->devParent->Device;
dh->Callback = newMap->devParent->Callback;
dh->System = newMap->devParent->sysDevice;
// Recognize which model - DHU11, DHV11, or DHQ11.
if (!strcmp(dh->Unit.keyName, DHU_KEY)) {
dh->Flags = CFLG_DHU;
dh->nPorts = DHU_PORTS; // 16 ports
} else if (!strcmp(dh->Unit.keyName, DHV_KEY)) {
dh->Flags = CFLG_DHV;
dh->nPorts = DHV_PORTS; // 8 ports
} else if (!strcmp(dh->Unit.keyName, DHQ_KEY)) {
dh->Flags = CFLG_DHQ;
dh->nPorts = DHQ_PORTS; // 8 ports
} else {
printf("%s: *** Bug Check: Unknown device name - %s\n",
dh->Unit.devName, dh->Unit.keyName);
free(dh);
return NULL;
}
dh->csrAddr = DH_CSRADDR;
// Initialize Server, TTY lines, etc.
if (dhu_InitServer(dh) == NULL) {
free(dh);
return NULL;
}
dhu_InitLines(dh);
dhu_ResetDevice(dh);
// Set up an I/O space.
io = &dh->ioMap;
io->devName = dh->Unit.devName;
io->keyName = dh->Unit.keyName;
io->emuName = dh->Unit.emuName;
io->emuVersion = dh->Unit.emuVersion;
io->Device = dh;
io->csrAddr = dh->csrAddr;
io->nRegs = DH_NREGS;
io->intIPL = DH_IPL;
io->nVectors = DH_NVECS;
io->intLevel[0] = DH_RXINT;
io->intMask[0] = (1u << DH_RXINT);
io->intVector[0] = DH_RXVEC;
io->intLevel[1] = DH_TXINT;
io->intMask[1] = (1u << DH_TXINT);
io->intVector[1] = DH_TXVEC;
io->ReadIO = dhu_ReadIO;
io->WriteIO = dhu_WriteIO;
io->ResetIO = dhu_ResetIO;
// Assign that registers to QBA's I/O space.
dh->Callback->SetMap(dh->Device, io);
// Finally, link it to its mapping device and return.
newMap->Device = dh;
}
return dh;
}
//int dhu_Reset(MAP_DEVICE *map)
int dhu_Reset(void *dptr)
{
// DH_DEVICE *dh = (DH_DEVICE *)map->Device;
DH_DEVICE *dh = (DH_DEVICE *)dptr;
dhu_ResetDevice(dh);
}
DEVLIST dhu_List[] =
{
{ 1, DHU_KEY, DH_NAME, DH_VERSION }, // DHU11 (Unibus)
{ 2, DHV_KEY, DH_NAME, DH_VERSION }, // DHV11 (QBus)
{ 3, DHQ_KEY, DH_NAME, DH_VERSION }, // DHQ11 (QBus)
{ 0, NULL, NULL, NULL }, // Terminator
};
DEVICE dhu_Device =
{
DHU_KEY, // Key Name
DH_NAME, // Emulator Name
DH_VERSION, // Emulator Version
NULL, // Listing of slave devices
DF_SYSMAP, // Device Flags
DT_TERMINAL, // Device Type
// Device Commands
NULL, // Commands
NULL, // Set Commands
NULL, // Show Commands
// Function Calls
dhu_Create, // Create Routine
NULL, // Configure Routine
NULL, // Delete Routine
dhu_Reset, // Reset Routine
NULL, // Attach Routine
NULL, // Detach Routine
NULL, // Info Device
NULL, // Boot Routine
NULL, // Execute Routine
#ifdef DEBUG
NULL, // Debug Routine
#endif /* DEBUG */
};
DEVICE dhv_Device =
{
DHV_KEY, // Key Name
DH_NAME, // Emulator Name
DH_VERSION, // Emulator Version
NULL, // Listing of slave devices
DF_SYSMAP, // Device Flags
DT_TERMINAL, // Device Type
// Device Commands
NULL, // Commands
NULL, // Set Commands
NULL, // Show Commands
// Function Calls
dhu_Create, // Create Routine
NULL, // Configure Routine
NULL, // Delete Routine
dhu_Reset, // Reset Routine
NULL, // Attach Routine
NULL, // Detach Routine
NULL, // Info Device
NULL, // Boot Routine
NULL, // Execute Routine
#ifdef DEBUG
NULL, // Debug Routine
#endif /* DEBUG */
};
DEVICE dhq_Device =
{
DHQ_KEY, // Key Name
DH_NAME, // Emulator Name
DH_VERSION, // Emulator Version
NULL, // Listing of slave devices
DF_SYSMAP, // Device Flags
DT_TERMINAL, // Device Type
// Device Commands
NULL, // Commands
NULL, // Set Commands
NULL, // Show Commands
// Function Calls
dhu_Create, // Create Routine
NULL, // Configure Routine
NULL, // Delete Routine
dhu_Reset, // Reset Routine
NULL, // Attach Routine
NULL, // Detach Routine
NULL, // Info Device
NULL, // Boot Routine
NULL, // Execute Routine
#ifdef DEBUG
NULL, // Debug Routine
#endif /* DEBUG */
};
|