home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ZSYS / SIMTEL20 / ZCPR3 / SYSIOP.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  33KB  |  1,221 lines

  1. *  SYSTEM SEGMENT:  SYSTEM.IOP
  2. *  SYSTEM:  ARIES-1
  3. *  CUSTOMIZED BY:  RICHARD CONN
  4.  
  5. *  PROGRAM: SYSIOP.ASM
  6. *  AUTHOR:  RICHARD CONN
  7. *  VERSION:  1.0
  8. *  DATE:  22 FEB 84
  9. *  PREVIOUS VERSIONS:  NONE
  10.  
  11. *---- Customize Section ----*
  12. *  Customization Performed Throughout Code
  13. *---- End of Customize Section ----*
  14.  
  15. *****************************************************************
  16. *                                *
  17. *  SYSIO -- Standard Set of Redirectable I/O Drivers        *
  18. *    for ZCPR2 configured for Richard Conn's ARIES-1 System    *
  19. *                                *
  20. *  Feb 2, 1984                            *
  21. *                                *
  22. *  Note on Assembly:                        *
  23. *    This device driver package is to be assembled by MAC    *
  24. * (because of the macros) and configured into a file of type    *
  25. * IO by loading it at 100H via DDT or SID/ZSID and saving the    *
  26. * result as a COM file.  Care should be taken to ensure that    *
  27. * the package is not larger than the device driver area which    *
  28. * is reserved for it in memory.                    *
  29. *                                *
  30. *****************************************************************
  31.  
  32.     MACLIB    Z3BASE    ; Get Addresses
  33.  
  34. IOBYTE    equ    3    ;I/O BYTE
  35. INTIOBY    equ    100$1$1$000B    ;Initial I/O Byte Value
  36.                 ;  LST:=TTY
  37.                 ;  RDR:, PUN:=Clock
  38.                 ;  CON:=CRT
  39.  
  40. *****************************************************************
  41. *                                *
  42. *  Disk Serial, MPU Serial, Quad I/O, and Modem Equates        *
  43. *                                *
  44. *****************************************************************
  45.  
  46. ;  Disk Serial -- Serial Channel on Disk Controller Board (DCE)
  47. ;    Baud Rate is set at 19,200 Baud in Hardware (DIP Switches)
  48. ustat    equ    djeprom+3F9H    ;USART Status Address
  49. ostat    equ    8    ;Output Status Bit (TBE)
  50. istat    equ    4    ;Input Status Bit (RDA)
  51.  
  52. ;  MPU Serial -- Serial Channel on CCS Z80 MPU Board (DCE)
  53. mpubase    equ    20H    ;Base address of 8250 on CCS Z80 MPU Board
  54. mpudata    equ    mpubase        ;Data I/O Registers
  55. mpudll    equ    mpubase        ;Divisor Latch Low
  56. mpudlh    equ    mpubase+1    ;Divisor Latch High
  57. mpuier    equ    mpubase+1    ;Interrupt Enable Register
  58. mpulcr    equ    mpubase+3    ;Line Control Register
  59. mpupcr    equ    mpubase+4    ;Peripheral Control Register
  60. mpustat    equ    mpubase+5    ;Line Status Register
  61. mpupsr    equ    mpubase+6    ;Peripheral Status Register
  62.  
  63. ;  MPU Serial RDA and TBE
  64. mpurda    equ    1    ; Data Available Bit (RDA)
  65. mputbe    equ    20h    ; Transmit Buffer Empty Bit (TBE)
  66.  
  67. ;  MPU Serial Baud Rate Values
  68. bm00050    equ    2304    ;    50   Baud
  69. bm00075    equ    1536    ;    75   Baud
  70. bm00110    equ    1047    ;   110   Baud
  71. bm00134    equ    857    ;   134.5 Baud
  72. bm00150    equ    768    ;   150   Baud
  73. bm00300    equ    384    ;   300   Baud
  74. bm00600    equ    192    ;   600   Baud
  75. bm01200    equ    96    ;  1200   Baud
  76. bm01800    equ    64    ;  1800   Baud
  77. bm02000    equ    58    ;  2000   Baud
  78. bm02400    equ    48    ;  2400   Baud
  79. bm03600    equ    32    ;  3600   Baud
  80. bm04800    equ    24    ;  4800   Baud
  81. bm07200    equ    16    ;  7200   Baud
  82. bm09600    equ    12    ;  9600   Baud
  83. bm19200    equ    6    ; 19200   Baud
  84. bm38400    equ    3    ; 38400   Baud
  85. bm56000    equ    2    ; 56000   Baud
  86.  
  87. ;  MPU Serial Channel Baud Rate
  88. mpbrate    equ    bm09600    ;   9600 Baud for TTY
  89.  
  90. ;  Quad I/O Ports
  91. qbase    equ    80h    ; Base address of Quad RS-232 I/O Board
  92. q0data    equ    qbase        ; USART 0 Data Port (DTE)
  93. q0stat    equ    qbase+1        ; USART 0 Status Port
  94. q1data    equ    qbase+2        ; USART 1 Data Port (DTE)
  95. q1stat    equ    qbase+3        ; USART 1 Status Port
  96. q2data    equ    qbase+4        ; USART 2 Data Port (DTE)
  97. q2stat    equ    qbase+5        ; USART 2 Status Port
  98. q3data    equ    qbase+6        ; USART 3 Data Port (DCE)
  99. q3stat    equ    qbase+7        ; USART 3 Status Port
  100. q0baud    equ    qbase+8        ; USART 0 Baud Rate Port
  101. q1baud    equ    qbase+9        ; USART 1 Baud Rate Port
  102. q2baud    equ    qbase+10    ; USART 2 Baud Rate Port
  103. q3baud    equ    qbase+11    ; USART 3 Baud Rate Port
  104.  
  105. ;  Quad I/O RDA and TBE
  106. qrda    equ    2    ; Read Data Available Bit (RDA)
  107. qtbe    equ    1    ; Transmit Buffer Empty Bit (TBE)
  108.  
  109. *************************************
  110. *  Equate Values for PMMI as Modem  *
  111. *************************************
  112. *  Modem Ports (Special -- 300 or 600 Baud for PMMI)
  113. *mods    equ    0E0H    ; Modem Status Byte
  114. *modd    equ    0E1H    ; Modem Data Byte
  115. *
  116. *  Modem RDA and TBE
  117. *mrda    equ    2    ; Read Data Available Bit (RDA)
  118. *mtbe    equ    1    ; Transmit Buffer Empty Bit (TBE)
  119. *************************************
  120.  
  121. ;  Modem Ports set to QUAD I/O Port 2
  122. mods    equ    q2stat    ; Modem Status Port
  123. modd    equ    q2data    ; Modem Data Port
  124.  
  125. ;  Modem RDA and TBE
  126. mrda    equ    qrda
  127. mtbe    equ    qtbe
  128.  
  129. ;  Baud Rate Values
  130. b00050    equ    0    ;    50   Baud
  131. b00075    equ    1    ;    75   Baud
  132. b00110    equ    2    ;   110   Baud
  133. b00134    equ    3    ;   134.5 Baud
  134. b00150    equ    4    ;   150   Baud
  135. b00300    equ    5    ;   300   Baud
  136. b00600    equ    6    ;   600   Baud
  137. b01200    equ    7    ;  1200   Baud
  138. b01800    equ    8    ;  1800   Baud
  139. b02000    equ    9    ;  2000   Baud
  140. b02400    equ    10    ;  2400   Baud
  141. b03600    equ    11    ;  3600   Baud
  142. b04800    equ    12    ;  4800   Baud
  143. b07200    equ    13    ;  7200   Baud
  144. b09600    equ    14    ;  9600   Baud
  145. b19200    equ    15    ; 19200   Baud
  146.  
  147.  
  148. *****************************************************************
  149. *                                *
  150. *  Baud Rates for Quad I/O Devices                *
  151. *                                *
  152. *****************************************************************
  153.  
  154. q0brate    equ    b09600    ;  9600 Baud for Intersystem
  155. q1brate    equ    b01200    ;  1200 Baud for Clock
  156. q2brate    equ    b01200    ;  1200 Baud for Transmodem
  157. q3brate    equ    b09600    ;  9600 Baud for NEC Printer
  158.  
  159.  
  160. *****************************************************************
  161. *                                *
  162. *  Miscellaneous Constants                    *
  163. *                                *
  164. *****************************************************************
  165. XON    equ    11h    ;X-ON
  166. XOFF    equ    13h    ;X-OFF
  167. CTRLZ    equ    'Z'-'@'    ;^Z
  168. djram    equ    djeprom+400h    ;Base of DJ RAM
  169. djcin    equ    djram+3    ;DJ Console Input
  170. djcout    equ    djram+6    ;DJ Console Output
  171.  
  172. *****************************************************************
  173. *                                *
  174. * The following are the Z80 Macro Definitions which are used to    *
  175. * define the Z80 Mnemonics used to implement the Z80 instruction*
  176. * set extensions employed in CBIOSZ.                *
  177. *                                *
  178. *****************************************************************
  179. ;
  180. ; MACROS TO PROVIDE Z80 EXTENSIONS
  181. ;   MACROS INCLUDE:
  182. ;
  183. $-MACRO         ;FIRST TURN OFF THE EXPANSIONS
  184. ;
  185. ;    JR    - JUMP RELATIVE
  186. ;    JRC    - JUMP RELATIVE IF CARRY
  187. ;    JRNC    - JUMP RELATIVE IF NO CARRY
  188. ;    JRZ    - JUMP RELATIVE IF ZERO
  189. ;    JRNZ    - JUMP RELATIVE IF NO ZERO
  190. ;    DJNZ    - DECREMENT B AND JUMP RELATIVE IF NO ZERO
  191. ;    LDIR    - MOV @HL TO @DE FOR COUNT IN BC
  192. ;    LXXD    - LOAD DOUBLE REG DIRECT
  193. ;    SXXD    - STORE DOUBLE REG DIRECT
  194. ;
  195. ;
  196. ;
  197. ;    @GENDD MACRO USED FOR CHECKING AND GENERATING
  198. ;    8-BIT JUMP RELATIVE DISPLACEMENTS
  199. ;
  200. @GENDD    MACRO    ?DD    ;;USED FOR CHECKING RANGE OF 8-BIT DISPLACEMENTS
  201.     IF (?DD GT 7FH) AND (?DD LT 0FF80H)
  202.     DB    100H    ;Displacement Range Error on Jump Relative
  203.     ELSE
  204.     DB    ?DD
  205.     ENDIF
  206.     ENDM
  207. ;
  208. ; Z80 MACRO EXTENSIONS
  209. ;
  210. JR    MACRO    ?N
  211.     DB    18H
  212.     @GENDD    ?N-$-1
  213.     ENDM
  214. ;
  215. JRC    MACRO    ?N
  216.     DB    38H
  217.     @GENDD    ?N-$-1
  218.     ENDM
  219. ;
  220. JRNC    MACRO    ?N
  221.     DB    30H
  222.     @GENDD    ?N-$-1
  223.     ENDM
  224. ;
  225. JRZ    MACRO    ?N
  226.     DB    28H
  227.     @GENDD    ?N-$-1
  228.     ENDM
  229. ;
  230. JRNZ    MACRO    ?N
  231.     DB    20H
  232.     @GENDD    ?N-$-1
  233.     ENDM
  234. ;
  235. DJNZ    MACRO    ?N
  236.     DB    10H
  237.     @GENDD    ?N-$-1
  238.     ENDM
  239. ;
  240. LDIR    MACRO
  241.     DB    0EDH,0B0H
  242.     ENDM
  243. ;
  244. LDED    MACRO    ?N
  245.     DB    0EDH,05BH
  246.     DW    ?N
  247.     ENDM
  248. ;
  249. LBCD    MACRO    ?N
  250.     DB    0EDH,4BH
  251.     DW    ?N
  252.     ENDM
  253. ;
  254. SDED    MACRO    ?N
  255.     DB    0EDH,53H
  256.     DW    ?N
  257.     ENDM
  258. ;
  259. SBCD    MACRO    ?N
  260.     DB    0EDH,43H
  261.     DW    ?N
  262.     ENDM
  263. ;
  264. ; END OF Z80 MACRO EXTENSIONS
  265. ;
  266.  
  267.  
  268. *****************************************************************
  269. *                                *
  270. * Terminal driver routines. Iobyte is initialized by the cold    *
  271. * boot routine, to modify, change the "intioby" equate.    The    *
  272. * I/O routines that follow all work exactly the same way. Using    *
  273. * iobyte, they obtain the address to jump to in order to execute*
  274. * the desired function. There is a table with four entries for    *
  275. * each of the possible assignments for each device. To modify    *
  276. * the I/O routines for a different I/O configuration, just    *
  277. * change the entries in the tables.                *
  278. *                                *
  279. *****************************************************************
  280.  
  281.     org    iop        ;Base Address of I/O Drivers
  282. offset    equ    100h-iop    ;Offset for load via DDT or ZSID
  283.  
  284.     jmp    status        ;Internal Status Routine
  285.     jmp    select        ;Device Select Routine
  286.     jmp    namer        ;Device Name Routine
  287.  
  288.     jmp    tinit        ;Initialize Terminal
  289.  
  290.     jmp    const        ;Console Input Status
  291.     jmp    conin        ;Console Input Char
  292.     jmp    conout        ;Console Output Char
  293.  
  294.     jmp    list        ;List Output Char
  295.  
  296.     jmp    punch        ;Punch Output Char
  297.  
  298.     jmp    reader        ;Reader Input Char
  299.  
  300.     jmp    listst        ;List Output Status
  301.  
  302.     jmp    newio        ;New I/O Driver Installation Routine
  303.  
  304.     jmp    copen        ;Open CON: Disk File
  305.     jmp    cclose        ;Close CON: Disk File
  306.  
  307.     jmp    lopen        ;Open LST: Disk File
  308.     jmp    lclose        ;Close LST: Disk File
  309.  
  310. *
  311. *  I/O Package Identification
  312. *
  313.     db    'Z3IOP'        ;Read by Z3LOADER
  314.  
  315. *****************************************************************
  316. *                                *
  317. * status: return information on devices supported by this    *
  318. *    I/O Package.  On exit, HL points to a logical device    *
  319. *    table which is structured as follows:            *
  320. *        Device    Count Byte  Current Assignment Byte    *
  321. *        ------    ----------  -----------------------    *
  322. *         CON:         0            1        *
  323. *         RDR:         2            3        *
  324. *         PUN:         4            5        *
  325. *         LST:         6            7        *
  326. *                                *
  327. *    If error or no I/O support, return with Zero Flag Set.    *
  328. *    Also, if no error, A=Driver Module Number        *
  329. *                                *
  330. *****************************************************************
  331. status:
  332.     lxi    h,cnttbl    ;point to table
  333.     mvi    a,81H        ;Module 1 (SYSIO) with Disk Output
  334.     ora    a        ;Set Flags
  335.     ret
  336.  
  337.  
  338. *****************************************************************
  339. *                                *
  340. * select: select devices indicated by B and C.  B is the number    *
  341. *    of the logical device, where CON:=0, RDR:=1, PUN:=2,    *
  342. *    LST:=3, and C is the desired device (range 0 to dev-1).    *
  343. *    Return with Zero Flag Set if Error.            *
  344. *                                *
  345. *****************************************************************
  346. ranger:
  347.     lxi    h,cnttbl-2    ;check for error
  348.     inr    b    ;range of 1 to 4
  349.     mov    a,b    ;Value in A
  350.     cpi    5    ;B out of range?
  351.     jnc    rangerr
  352.     push    b    ;save params
  353. rang:
  354.     inx    h    ;pt to next
  355.     inx    h
  356.     djnz    rang
  357.     mov    b,m    ;get count in b
  358.     mov    a,c    ;get selected device number
  359.     cmp    b    ;compare (C must be less than B)
  360.     pop    b    ;get params
  361.     jrnc    rangerr    ;range error if C >= B
  362. rangok:
  363.     xra    a    ;OK
  364.     dcr    a    ;set flags (0FFH and NZ)
  365.     ret
  366. rangerr:
  367.     xra    a    ;not OK (Z)
  368.     ret
  369. select:
  370.     call    ranger    ;check for range error
  371.     rz        ;abort if error
  372.     inx    h    ;pt to current entry number
  373.     mov    m,c    ;save selected number there
  374.     lxi    h,cfgtbl-2    ;pt to configuration table
  375. sel2:
  376.     inx    h    ;Pt to Entry in Configuration Table
  377.     inx    h
  378.     djnz    sel2
  379.     mov    b,m    ;Get Rotate Count
  380.     inx    h    ;Pt to Select Mask
  381.     mov    d,m    ;Get Select Mask
  382.     mov    a,b    ;Any Rotation to do?
  383.     ora    a
  384.     jz    sel4
  385.     mov    a,c    ;Get Selected Number
  386. sel3:
  387.     rlc        ;Rotate Left 1 Bit
  388.     djnz    sel3
  389.     mov    c,a    ;Place Bit Pattern Back in C
  390. sel4:
  391.     lda    iobyte    ;get I/O byte
  392.     ana    d    ;mask out old selection
  393.     ora    c    ;mask in new selection
  394.     sta    iobyte    ;put I/O byte
  395.     jr    rangok    ;range OK
  396.  
  397. *****************************************************************
  398. *                                *
  399. * namer: return text string of physical device.  Logical device    *
  400. *    number is in B and physical selection is in C.        *
  401. *    HL is returned pointing to the first character of the    *
  402. *    string.  The strings are structured to begin with a    *
  403. *    device name followed by a space and then a description    *
  404. *    string which is terminated by a binary 0.        *
  405. *                                *
  406. *    Return with Zero Flag Set if error.            *
  407. *                                *
  408. *****************************************************************
  409. namer:
  410.     call    ranger    ;check for range error
  411.     rz        ;return if so
  412.     lxi    h,namptbl-2    ;pt to name ptr table
  413.     call    namsel    ;select ptr table entry
  414.     mov    b,c    ;physical selection number in B now
  415.     inr    b    ;Add 1 for Initial Increment
  416.     call    namsel    ;point to string
  417.     jr    rangok    ;return with HL pointing and range OK
  418. ;
  419. ;  Select entry B in table pted to by HL; this entry is itself a pointer,
  420. ;  and return with it in HL
  421. ;
  422. namsel:
  423.     inx    h    ;pt to next entry
  424.     inx    h
  425.     djnz    namsel
  426.     mov    a,m    ;get low
  427.     inx    h
  428.     mov    h,m    ;get high
  429.     mov    l,a    ;HL now points to entry
  430.     ret
  431.  
  432. *****************************************************************
  433. *                                *
  434. * const: get the status for the currently assigned console.    *
  435. *     The I/O Byte is used to select the device.        *
  436. *                                *
  437. *****************************************************************
  438. const:
  439.     lxi    h,cstble    ;Beginning of jump table
  440. conmask:
  441.     lxi    d,cfgtbl    ;Pt to First Entry in Config Table
  442.     jr    seldev        ;Select correct jump
  443.  
  444. *****************************************************************
  445. *                                *
  446. * conin: input a character from the currently assigned console.    *
  447. *     The I/O Byte is used to select the device.        *
  448. *                                *
  449. *****************************************************************
  450. conin:
  451.     lxi    h,citble    ;Beginning of character input table
  452.     jr    conmask        ;Get Console Mask
  453.  
  454. *****************************************************************
  455. *                                *
  456. * conout: output the character in C to the currently assigned    *
  457. *      console.  The I/O Byte is used to select the device.    *
  458. *                                *
  459. *****************************************************************
  460. conout:
  461.     lxi    h,cotble    ;Beginning of the character out table
  462.     call    crout        ;output to console recorder if set
  463.     jr    conmask        ;Get Console Mask
  464.  
  465. *****************************************************************
  466. *                                *
  467. * csreader: get the status of the currently assigned reader.    *
  468. *        The I/O Byte is used to select the device.        *
  469. *                                *
  470. *****************************************************************
  471. csreadr:
  472.     lxi    h,csrtble    ;Beginning of reader status table
  473. rdrmask:
  474.     lxi    d,cfgtbl+2    ;Pt to 2nd Entry in Config Table
  475.     jr    seldev
  476.  
  477. *****************************************************************
  478. *                                *
  479. * reader: input a character from the currently assigned reader.    *
  480. *      The I/O Byte is used to select the device.        *
  481. *                                *
  482. *****************************************************************
  483. reader:
  484.     lxi    h,rtble        ;Beginning of reader input table
  485.     jr    rdrmask        ;Get the Mask and Go
  486.  
  487. *****************************************************************
  488. *                                *
  489. * Entry at seldev will form an offset into the table pointed    *
  490. * to by H&L and then pick up the address and jump there.    *
  491. * The configuration of the physical device assignments is    *
  492. * pointed to by D&E (cfgtbl entry).                *
  493. *                                *
  494. *****************************************************************
  495. seldev:
  496.     push    b        ;Save Possible Char in C
  497.     ldax    d        ;Get Rotate Count
  498.     mov    b,a        ;... in B
  499.     inx    d        ;Pt to Mask
  500.     ldax    d        ;Get Mask
  501.     cma            ;Flip Bits
  502.     mov    c,a        ;... in C
  503.     lda    iobyte        ;Get I/O Byte
  504.     ana    c        ;Mask Out Selection
  505.     inr    b        ;Increment Rotate Count
  506. seld1:
  507.     dcr    b        ;Count down
  508.     jrz    seld2
  509.     rrc            ;Rotate Right one Bit
  510.     jr    seld1
  511. seld2:
  512.     rlc            ;Double Number for Table Offset
  513.     mvi    d,0        ;Form offset
  514.     mov    e,a
  515.     dad    d        ;Add offset
  516.     mov    a,m        ;Pick up low byte
  517.     inx    h
  518.     mov    h,m        ;Pick up high byte
  519.     mov    l,a        ;Form address
  520.     pop    b        ;Get Possible Char in C
  521.     pchl            ;Go there !
  522.  
  523. *****************************************************************
  524. *                                *
  525. * punch: output char in C to the currently assigned punch    *
  526. *     device.  The I/O Byte is used to select the device.    *
  527. *                                *
  528. *****************************************************************
  529. punch:
  530.     lxi    h,ptble        ;Beginning of punch table
  531.     lxi    d,cfgtbl+4    ;Get Mask
  532.     jr    seldev        ;Select Device and Go
  533.  
  534. *****************************************************************
  535. *                                *
  536. * list: output char in C to the currently assigned list device.    *
  537. *    The I/O Byte is used to select the device.        *
  538. *                                *
  539. *****************************************************************
  540. list:
  541.     lxi    h,ltble        ;Beginning of the list device routines
  542.     call    lrout        ;output to list recorder if set
  543. lstmask:
  544.     lxi    d,cfgtbl+6    ;Get Mask
  545.     jr    seldev        ;Select Device and Go
  546.  
  547. *****************************************************************
  548. *                                *
  549. * Listst: get the output status of the currently assigned list    *
  550. *      device.  The I/O Byte is used to select the device.    *
  551. *                                *
  552. *****************************************************************
  553. listst:
  554.     lxi    h,lstble    ;Beginning of the list device status
  555.     jr    lstmask        ;Mask and Go
  556.  
  557. *****************************************************************
  558. *                                *
  559. * If customizing I/O routines is being performed, the tables    *
  560. * below should be modified to reflect the changes. All I/O    *
  561. * devices are decoded out of iobyte and the jump is taken from    *
  562. * the following tables.                        *
  563. *                                *
  564. *****************************************************************
  565.  
  566. *****************************************************************
  567. *                                *
  568. *  I/O Driver Support Specification Tables            *
  569. *                                *
  570. *****************************************************************
  571.  
  572. *
  573. * Device Counts
  574. *    First Byte is Number of Devices, 2nd Byte is Selected Device
  575. *
  576. cnttbl:
  577.     db    6,(intioby AND 7)        ;CON:
  578.     db    2,(intioby AND 08h) SHR 3    ;RDR:
  579.     db    2,(intioby AND 10h) SHR 4    ;PUN:
  580.     db    6,(intioby AND 0E0h) SHR 5    ;LST:
  581.  
  582. *
  583. * Configuration Table
  584. *    First Byte is Rotate Count, 2nd Byte is Mask
  585. *
  586. cfgtbl:
  587.     db    0,111$1$1$000b    ;No Rotate, Mask Out 3 LSB
  588.     db    3,111$1$0$111b    ;3 Rotates, Mask Out Bit 3
  589.     db    4,111$0$1$111b    ;4 Rotates, Mask Out Bit 4
  590.     db    5,000$1$1$111b    ;5 Rotates, Mask Out 3 MSB
  591.  
  592. *
  593. * name text tables
  594. *
  595. namptbl:
  596.     dw    conname-2    ;CON:
  597.     dw    rdrname-2    ;RDR:
  598.     dw    punname-2    ;PUN:
  599.     dw    lstname-2    ;LST:
  600.  
  601. conname:
  602.     dw    namcrt    ;CRT
  603.     dw    namusr    ;CRT and Modem in Parallel
  604.     dw    namusr1    ;CRT Input and CRT/Remote Computer Output
  605.     dw    namusr2    ;CRT Input and CRT/Modem Output
  606.     dw    namcrtt    ;CRT Input and CRT/TTY Printer Output
  607.     dw    namcrtn    ;CRT Input and CRT/NEC Printer Output
  608.  
  609. lstname:
  610.     dw    namtty    ;TTY
  611.     dw    namcrt    ;CRT
  612.     dw    namrem    ;Remote Computer
  613.     dw    nammod    ;Modem
  614.     dw    nammpu    ;MPU
  615.     dw    nammpu8    ;MPU with 8 Bits
  616.  
  617. rdrname:
  618.     dw    nammod    ;Modem
  619.     dw    namclk    ;Clock
  620.  
  621. punname:
  622.     dw    nammod    ;Modem
  623.     dw    namclk    ;Clock
  624.  
  625. nammpu:
  626.     db    'TTY Toshiba P1350 Printer',0
  627. nammpu8:
  628.     db    'TTY8 TTY with 8th Sig Bit',0
  629. namtty:
  630.     db    'NEC NEC 3510 LQ Printer',0
  631. namcrt:
  632.     db    'CRT TVI 950 CRT',0
  633. namcrtn:
  634.     db    'CRTNEC CRT Input and CRT/NEC Printer Output',0
  635. namcrtt:
  636.     db    'CRTTY CRT Input and CRT/TTY Printer Output',0
  637. namusr:
  638.     db    'CRTMOD CRT and Modem in Parallel',0
  639. namusr1:
  640.     db    'CRTREM CRT Input and CRT/Remote Output',0
  641. namusr2:
  642.     db    'CRTMOD2 CRT Input and CRT/Modem Output',0
  643. namrem:
  644.     db    'REMOTE Remote Computer',0
  645. nammod:
  646.     db    'MODEM Transmodem 1200',0
  647. namclk:
  648.     db    'CLOCK DC Hayes Chronograph',0
  649.  
  650. *
  651. * console input table
  652. *
  653. citble:
  654.     dw    cicrt        ;Input from crt (000)
  655.     dw    ciusr        ;Input from crt and modem (001) 
  656.     dw    cicrt        ;Input from crt (010)
  657.     dw    cicrt        ;Input from crt (011)
  658.     dw    cicrt        ;Input from crt (100)
  659.     dw    cicrt        ;Input from crt (101)
  660.  
  661. *
  662. * console output table
  663. *
  664. cotble:
  665.     dw    cocrt        ;Output to crt (000)
  666.     dw    cousr        ;Output to crt and modem (001)
  667.     dw    cousr1        ;Output to crt and remote system (010) 
  668.     dw    cousr        ;Output to crt and modem (011)
  669.     dw    cocrtt        ;Output to crt and TTY printer (100)
  670.     dw    cocrtn        ;Output to crt and NEC printer (101)
  671.  
  672. *
  673. * list device table
  674. *
  675. ltble:
  676.     dw    cotty        ;Output to tty (000) 
  677.     dw    cocrt        ;Output to crt (001)
  678.     dw    corem        ;Output to remote system (010)
  679.     dw    comod        ;Output to modem (011)
  680.     dw    compu        ;Output to mpu (100)
  681.     dw    compu8        ;Output to mpu (101)
  682.  
  683. *
  684. * punch device table
  685. *
  686.  
  687. ptble:
  688.     dw    comod        ;Output to modem (0)
  689.     dw    coclk        ;Output to clock (1) 
  690.  
  691. *
  692. * reader device table
  693. *
  694. rtble:
  695.     dw    cimod        ;Input from modem (0)
  696.     dw    ciclk        ;Input from clock (1)
  697.  
  698. *
  699. * console status table
  700. *
  701. cstble:
  702.     dw    cscrt        ;Status from crt (000)
  703.     dw    csusr        ;Status from crt and modem (001)
  704.     dw    cscrt        ;Status from crt (010)
  705.     dw    cscrt        ;Status from crt (011)
  706.     dw    cscrt        ;Status from crt (100)
  707.     dw    cscrt        ;Status from crt (101)
  708.  
  709. *
  710. * status from reader device
  711. *
  712. csrtble:
  713.     dw    csmod        ;Status from modem (0)
  714.     dw    csclk        ;Status from clock (1)
  715.  
  716. *
  717. * Status from list device
  718. *
  719. lstble:
  720.     dw    costty        ;Status from tty (000)
  721.     dw    coscrt        ;Status from crt (001)
  722.     dw    cosrem        ;Status from remote system (010)
  723.     dw    cosmod        ;Status from modem (011)
  724.     dw    cosmpu        ;Status from mpu (100)
  725.     dw    cosmpu        ;Status from mpu (101)
  726.  
  727.  
  728. *****************************************************************
  729. *                                *
  730. * Tinit can be modified for different I/O setups.        *
  731. *                                *
  732. *****************************************************************
  733. tinit:                ;Initialize the terminal routine
  734.  
  735. ;  Initialize I/O Byte
  736.     mvi    a,intioby    ;Initialize IOBYTE
  737.     sta    iobyte
  738.  
  739. ;  Initialize MPU Serial I/O Channel Characteristics and Baud Rate
  740.     mvi    a,10$00$00$11b    ;Access Divisor:
  741.                 ;  10 -- Set divisor latch, clear break
  742.                 ;  00 -- 0 parity bit, odd parity (N/A)
  743.                 ;  00 -- disable parity, 1 stop bit
  744.                 ;  11 -- 8 Data Bits
  745.     out    mpulcr        ;To Line Control Register
  746.     lxi    h,mpbrate    ;HL = MPU Channel Baud Rate
  747.     mov    a,l        ;Set Low-Byte of Baud Rate
  748.     out    mpudll        ;To Divisor Latch Low
  749.     mov    a,h        ;Set High-Byte of Baud Rate
  750.     out    mpudlh        ;To Divisor Latch High
  751.     mvi    a,00$00$00$11b    ;Reset Divisor Access and Set Characteristics:
  752.                 ;  00 -- Clear divisor latch, clear break
  753.                 ;  00 -- 0 parity bit, odd parity (N/A)
  754.                 ;  00 -- disable parity, 1 stop bit
  755.                 ;  11 -- 8 Data Bits
  756.     out    mpulcr        ;To Line Control Register
  757.     xra    a        ;A=0
  758.     out    mpuier        ;Disable All Interrupts in Interrupt Register
  759.     out    mpustat        ;Clear All Error Flags in Line Status Register
  760.     mvi    a,0000$1111b    ;3 Zeroes, No Loop, 1, Set RLSD, CTS, DSR
  761.     out    mpupcr        ;To Peripheral Control Register
  762.  
  763. ;  Initialize Quad I/O Channel Characteristics
  764.     mvi    a,10$11$01$11b    ;General-Purpose Reset:
  765.                 ;  10 -- 1 1/2 Stop Bits
  766.                 ;  11 -- Even Parity, Enable Parity
  767.                 ;  01 -- 6 Bits/Char
  768.                 ;  11 -- 64x Baud Rate
  769.     call    setquad        ;Set All 4 Quad I/O Ports
  770.     mvi    a,01$11$01$11b    ;General-Purpose Reset:
  771.                 ;  01 -- Disable Hunt, Internal Reset
  772.                 ;  11 -- RTS High, Error Reset
  773.                 ;  01 -- No Break, Enable RxRDY
  774.                 ;  11 -- NOT DTR High, Enable TxEN
  775.     call    setquad        ;Set All 4 Quad I/O Ports
  776.     mvi    a,11$00$11$10b    ;Characteristics Set for All:
  777.                 ;  11 -- 2 Stop Bits
  778.                 ;  00 -- No Parity
  779.                 ;  11 -- 8 Bits/Char
  780.                 ;  10 -- 16x Baud Rate
  781.     call    setquad        ;Set All 4 Quad I/O Ports
  782.     mvi    a,00$11$01$11b    ;Characteristics Set for All:
  783.                 ;  00 -- Disable Hunt, No Internal Reset
  784.                 ;  11 -- RTS High, Error Reset
  785.                 ;  01 -- No Break, Enable RxRDY
  786.                 ;  11 -- NOT DTR High, Enable TxEN
  787.     call    setquad        ;Set All 4 Quad I/O Ports
  788.  
  789. ;  Initialize Quad I/O Baud Rates
  790.     mvi    a,q0brate    ;Set USART 0 Baud Rate
  791.     out    q0baud
  792.     mvi    a,q1brate    ;Set USART 1 Baud Rate
  793.     out    q1baud
  794.     mvi    a,q2brate    ;Set USART 2 Baud Rate
  795.     out    q2baud
  796.     mvi    a,q3brate    ;Set USART 3 Baud Rate
  797.     out    q3baud
  798.  
  799. ;  Set All Recording OFF
  800.     xra    a        ;A=0
  801.     sta    crecord        ;console
  802.     sta    lrecord        ;list device
  803.  
  804. ;  Clear Garbage Char from CRT
  805.     call    cscrt        ;Gobble up unwanted char
  806.     ora    a        ;A=0 if none
  807.     cnz    cicrt        ;Grab character
  808.     ret
  809.  
  810. ;  Set All Quad I/O Control Ports
  811. setquad:
  812.     out    q0stat        ;USART 0
  813.     out    q1stat        ;USART 1
  814.     out    q2stat        ;USART 2
  815.     out    q3stat        ;USART 3
  816.     xthl            ;Long Delay
  817.     xthl
  818.     ret
  819.  
  820.  
  821. *****************************************************************
  822. *                                *
  823. *  NEWIO -- Set UC1: Device to the Device Drivers whose Jump    *
  824. *    Table is Pointed to by HL                *
  825. *                                *
  826. *  This Jump Table is structured as follows:            *
  827. *    JMP ISTAT    <-- Input Status (0=No Char, 0FFH=Char)    *
  828. *    JMP INPUT    <-- Input Character            *
  829. *    JMP OUTPUT    <-- Output Character in C        *
  830. *                                *
  831. *  The Base Address of this Jump Table (JBASE) is passed to    *
  832. *    NEWIO in the HL Register Pair.                *
  833. *                                *
  834. *****************************************************************
  835. newio:
  836.     shld    cstble+6    ;Set UC1: Input Status
  837.     lxi    d,3        ;Prepare for offset to next jump
  838.     dad    d        ;HL points to next jump
  839.     shld    citble+6    ;Set UC1: Input Character
  840.     dad    d        ;HL points to next jump
  841.     shld    cotble+6    ;Set UC1: Output Character
  842.     ret
  843.  
  844.  
  845. *****************************************************************
  846. *                                *
  847. *  Input Status, Input Character, and Output Character        *
  848. *    Subroutines for CP/M                    *
  849. *                                *
  850. *****************************************************************
  851. *                                *
  852. *  Input Status --                        *
  853. *    These routines return 0 in the A Register if no input    *
  854. * data is available, 0FFH if input data is available.        *
  855. *                                *
  856. *  Input Character --                        *
  857. *    These routines return the character (byte) in the A    *
  858. * Register.  MSB is masked off.                    *
  859. *                                *
  860. *  Output Character --                        *
  861. *    These routines output the character (byte) in the C    *
  862. * Register.                            *
  863. *                                *
  864. *****************************************************************
  865.  
  866. *****************************************************************
  867. *                                *
  868. *  CRT Input Status, Input Character, and Output Character    *
  869. *                                *
  870. *****************************************************************
  871.  
  872. cscrt    equ    $    ;CRT Input Status
  873.     lda    ustat    ;Get Status
  874.     cma        ;Inverted Logic
  875.     ani    istat    ;Mask for input status and fall thru to 'STAT'
  876.     jr    stat    ;Set Flags
  877.  
  878. coscrt    equ    $    ;CRT Output Status
  879.     lda    ustat    ;Get USART status
  880.     cma        ;Inverted Logic
  881.     ani    ostat    ;Mask for output status
  882.     jr    stat    ;Return
  883.  
  884. cicrt    equ    $    ;CRT Input
  885.     jmp    djcin    ;Get char
  886.  
  887. cocrt    equ    $    ;CRT Output
  888.     jmp    djcout    ;Put char
  889.  
  890. cocrtt    equ    $    ;CRT and TTY Printer Output
  891.     push    b    ;Save char
  892.     call    djcout    ;CRT Output
  893.     pop    b    ;Get char
  894.     jmp    compu    ;Printer Output
  895.  
  896. cocrtn    equ    $    ;CRT and NEC Printer Output
  897.     push    b    ;Save char
  898.     call    djcout    ;CRT Output
  899.     pop    b    ;Get char
  900.     jmp    cotty    ;Printer Output
  901.  
  902. *****************************************************************
  903. *                                *
  904. *  Modem Input Status, Input Character, and Output Character    *
  905. *                                *
  906. *****************************************************************
  907.  
  908. csmod    equ    $    ;Modem Input Status
  909.     in    mods
  910.     ani    mrda    ;Data available?
  911.     jr    stat
  912.  
  913. cosmod    equ    $    ;Modem Output Status
  914.     in    mods    ;Get status
  915.     ani    mtbe    ;TBE?
  916.     jr    stat
  917.  
  918. cimod    equ    $    ;Modem Input Character
  919.     call    csmod    ;RDA? 
  920.     jrz    cimod
  921.     in    modd    ;Get data
  922.     ani    7fh    ;Mask
  923.     ret
  924.  
  925. comod    equ    $    ;Modem Output
  926.     call    cosmod    ;TBE?
  927.     jrz    comod
  928.     mov    a,c    ;Get char
  929.     out    modd    ;Put data
  930.     ret
  931.  
  932. *****************************************************************
  933. *                                *
  934. *  Clock Input Status, Input Character, and Output Character    *
  935. *                                *
  936. *****************************************************************
  937.  
  938. csclk    equ    $    ;TTY Input Status
  939.     in    q1stat    ;Get Status
  940.     ani    qrda    ;Data available?
  941.     jr    stat
  942.  
  943. cosclk    equ    $    ;TTY Output Status
  944.     in    q1stat    ;Get Status
  945.     ani    qtbe    ;TBE?
  946.     jr    stat
  947.  
  948. ciclk    equ    $    ;TTY Input Character
  949.     call    csclk    ;RDA?
  950.     jrz    ciclk
  951.     in    q1data    ;Get data
  952.     ani    7fh    ;Mask
  953.     ret
  954.  
  955. coclk    equ    $    ;TTY Output Character
  956.     call    cosclk    ;TBE?
  957.     jrz    coclk
  958.     mov    a,c    ;Get data
  959.     out    q1data    ;Put data
  960.     ret
  961.  
  962. *****************************************************************
  963. *                                *
  964. * This is a common return point to correctly set the return     *
  965. *    status flags; it is centrally located for the jump        *
  966. *    relative instructions                    *
  967. *                                *
  968. *****************************************************************
  969. stat:
  970.     rz        ;Nothing found
  971. ready:
  972.     mvi    a,0ffh    ;Set A for negative status
  973.     ret
  974.  
  975. *****************************************************************
  976. *                                *
  977. *  NEC Input Status, Input Character, and Output Character    *
  978. *    X-OFF Processing Added                    *
  979. *                                *
  980. *****************************************************************
  981.  
  982. cstty    equ    $    ;TTY Input Status
  983.     in    q3stat    ;Get Status
  984.     ani    qrda    ;Data available?
  985.     jr    stat
  986.  
  987. costty    equ    $    ;TTY Output Status
  988.     in    q3stat    ;Get Status
  989.     ani    qtbe    ;TBE?
  990.     jr    stat
  991.  
  992. citty    equ    $    ;TTY Input Character
  993.     call    cstty    ;RDA?
  994.     jrz    citty
  995.     in    q3data    ;Get data
  996.     ani    7fh    ;Mask
  997.     ret
  998.  
  999. cotty    equ    $    ;TTY Output Character
  1000.     call    cstty    ;Any character?
  1001.     jrnz    cotty2    ;Process if so
  1002. cotty1:
  1003.     call    costty    ;TBE?
  1004.     jrz    cotty1
  1005.     mov    a,c    ;Get data
  1006.     out    q3data    ;Put data
  1007.     ret
  1008. cotty2:
  1009.     call    citty    ;X-OFF?
  1010.     cpi    XOFF    ;Do nothing if not X-OFF
  1011.     jrnz    cotty1
  1012.     call    citty    ;Wait for next char
  1013.     jr    cotty1
  1014.  
  1015. *****************************************************************
  1016. *                                *
  1017. *  Remote System Input Status, Input Character, and Output    *
  1018. *    Character                        *
  1019. *                                *
  1020. *****************************************************************
  1021.  
  1022. csrem    equ    $    ;TTY Input Status
  1023.     in    q0stat    ;Get Status
  1024.     ani    qrda    ;Data available?
  1025.     jr    stat
  1026.  
  1027. cosrem    equ    $    ;TTY Output Status
  1028.     in    q0stat    ;Get Status
  1029.     ani    qtbe    ;TBE?
  1030.     jr    stat
  1031.  
  1032. cirem    equ    $    ;TTY Input Character
  1033.     call    csrem    ;RDA?
  1034.     jrz    cirem
  1035.     in    q0data    ;Get data
  1036.     ani    7fh    ;Mask
  1037.     ret
  1038.  
  1039. corem    equ    $    ;TTY Output Character
  1040.     call    coxoff    ;Check for XOFF and process
  1041.     call    cosrem    ;TBE?
  1042.     jrz    corem
  1043.     mov    a,c    ;Get data
  1044.     out    q0data    ;Put data
  1045.     ret
  1046.  
  1047. coxoff    equ    $    ;Remote XOFF Check and Processing
  1048.     call    csrem    ;Input Char from LST: Device?
  1049.     rz        ;Zero if none
  1050.     call    cirem    ;Get Char
  1051.     cpi    XOFF    ;XOFF?
  1052.     rnz        ;Return if not
  1053.     call    cirem    ;Wait for Any Other Char
  1054.     ret
  1055.  
  1056. *****************************************************************
  1057. *                                *
  1058. *  TTY Input Status, Input Character, and Output Character    *
  1059. *    X-OFF Processing Added                    *
  1060. *                                *
  1061. *****************************************************************
  1062.  
  1063. csmpu    equ    $    ;TTY Input Status
  1064.     in    mpustat    ;Get Status
  1065.     ani    mpurda    ;Data available?
  1066.     jr    stat
  1067.  
  1068. cosmpu    equ    $    ;TTY Output Status
  1069.     in    mpustat    ;Get Status
  1070.     ani    mputbe    ;TBE?
  1071.     jr    stat
  1072.  
  1073. cimpu    equ    $    ;TTY Input Character
  1074.     call    csmpu    ;RDA?
  1075.     jrz    cimpu
  1076.     in    mpudata    ;Get data
  1077.     ani    7fh    ;Mask
  1078.     ret
  1079.  
  1080. compu8    equ    $    ;TTY Output Character (8 Sig Bits)
  1081.     mvi    a,0ffh    ;8th Bit Allowed
  1082.     jr    compu0
  1083. compu    equ    $    ;TTY Output Character
  1084.     mvi    a,07fh    ;No 8th Bit
  1085. compu0:
  1086.     sta    mpumask
  1087.     call    csmpu    ;Any character?
  1088.     jrnz    compu2    ;Process if so
  1089. compu1:
  1090.     call    cosmpu    ;TBE?
  1091.     jrz    compu1
  1092.     mov    a,c    ;Get data
  1093.     ani    0ffh    ;Mask
  1094. mpumask    equ    $-1    ;Address of Mask
  1095.     out    mpudata    ;Put data
  1096.     ret
  1097. compu2:
  1098.     call    cimpu    ;X-OFF?
  1099.     cpi    XOFF    ;Do nothing if not X-OFF
  1100.     jrnz    compu1
  1101.     call    cimpu    ;Wait for next char
  1102.     jr    compu1
  1103.  
  1104. *****************************************************************
  1105. *                                *
  1106. *  User-Defined (CRT and Modem) Input Status, Input Character,    *
  1107. *    and Output Character                    *
  1108. *                                *
  1109. *****************************************************************
  1110.  
  1111. csusr    equ    $    ;User (CRT and Modem) Input Status
  1112.     call    cscrt    ;Input from CRT?
  1113.     rnz        ;Char found
  1114.     call    csmod    ;Input from Modem?
  1115.     ret
  1116.  
  1117. cosusr    equ    cosmod    ;Output status same as modem since modem is slower
  1118.  
  1119. ciusr    equ    $    ;Modem/CRT Input Combination
  1120.     call    cscrt    ;Input from CRT?
  1121.     jnz    cicrt    ;Get char from CRT
  1122.     call    csmod    ;Input from Modem?
  1123.     jnz    cimod    ;Get char from Modem
  1124.     jr    ciusr    ;Continue
  1125.  
  1126. cousr    equ    $    ;Modem/CRT Output Combination
  1127.     call    comod    ;Output to Modem
  1128.     jmp    cocrt    ;Output to CRT
  1129.  
  1130. ciusr1    equ    $    ;Modem/CRT Input w/CRT Output Combination
  1131.     call    ciusr    ;Get char
  1132.     push    psw    ;Save char in A
  1133.     mov    c,a    ;Char in C
  1134.     call    cocrt    ;Output to CRT
  1135.     pop    psw    ;Restore char in A
  1136.     ret
  1137.  
  1138. cousr1    equ    $    ;Remote System/CRT Output Combination
  1139.     call    corem    ;Output to Remote System
  1140.     jmp    cocrt    ;Output to CRT
  1141.  
  1142. *****************************************************************
  1143. *                                *
  1144. * Record Output Routines                    *
  1145. *    CROUT - Console Recorder                *
  1146. *    LROUT - List Recorder                    *
  1147. *                                *
  1148. *****************************************************************
  1149.  
  1150. crout    equ    $
  1151.     lda    crecord    ;get flag
  1152.     ora    a    ;test flag for 0 (no recording)
  1153.     rz
  1154.     mov    a,c    ;check char
  1155.     ani    7fh
  1156.     cpi    ctrlz    ;don't allow ^Z
  1157.     rz
  1158.     jmp    corem    ;remote output if flag set
  1159.  
  1160. lrout    equ    $
  1161.     lda    lrecord    ;get flag
  1162.     ora    a    ;test flag for 0 (no recording)
  1163.     rz
  1164.     mov    a,c    ;check char
  1165.     ani    7fh
  1166.     cpi    ctrlz    ;don't allow ^Z
  1167.     rz
  1168.     jmp    corem    ;remote output if flag set
  1169.  
  1170. ;
  1171. ;  COPEN -- Open Console File for Output
  1172. ;  LOPEN -- Open Printer File for Output
  1173. ;
  1174. ;    Turn Appropriate Flag ON
  1175. ;
  1176. copen:
  1177.     mvi    a,0ffh    ;set flag
  1178.     jr    ccrset
  1179. lopen:
  1180.     mvi    a,0ffh    ;set flag
  1181.     jr    lcrset
  1182.  
  1183. ;
  1184. ;  Close Disk Files
  1185. ;    CCLOSE -- CON file (DSK1)
  1186. ;    LCLOSE -- LST file (DSK2)
  1187. ;
  1188. ;    Send ^Z to Terminate File Recording and Zero Appropriate Flag
  1189. ;
  1190. cclose:
  1191.     mvi    c,ctrlz    ;send ctrlz
  1192.     call    corem
  1193.     xra    a
  1194. ccrset:
  1195.     sta    crecord    ;set flag off
  1196.     ret
  1197. lclose:
  1198.     mvi    c,ctrlz    ;send ctrlz
  1199.     call    corem
  1200.     xra    a
  1201. lcrset:
  1202.     sta    lrecord    ;set flag off
  1203.     ret
  1204.  
  1205. ;
  1206. ; Recording Buffers
  1207. ;
  1208. crecord:
  1209.     ds    1    ;console device
  1210. lrecord:
  1211.     ds    1    ;list device
  1212.  
  1213. ;
  1214. ; Test for Size Error
  1215. ;
  1216.     if    ($ GT (IOP + IOPS*128))
  1217. sizerr    equ    novalue    ;IOP is too large for buffer
  1218.     endif
  1219.  
  1220.     end
  1221.