       ASB,HEX   ;KY36C - 6/25/76 - 1500 HRS. 
; 
;  COMMON EQUATES - CM34 - 6/10/76 - 1315 HRS.
; 
FSTRAM EQU  110400Q   ;FAST RAM LOWER LIMIT 
;***************************************
; KBDCSW - KEYBOARD DATA COMM SWITCHES *
;***************************************
FULDUP EQU  200Q      ;HALF/FULL DUPLEX 
;************************************** 
; KBJMPR - KEYBOARD INTERFACE JUMPERS * 
;************************************** 
; 
;  JUMPERS SENSED AS 0' WHEN INSERTED 
; 
;  ALL JUMPERS ARE NORMALLY INSERTED
; 
CONDIS EQU 001Q     ;CONTROL CODE DISABLE 
;                     (0=DISABLED)
SPLDIS EQU 002Q     ;SPOW LATCH DISABLE 
;                     (0=DISABLED)
LINWRP EQU 004Q     ;COLUMN 80 AUTO CR,LF 
;                     (0=ENABLED) 
PAGSTR EQU 010Q     ;PAGE MODE STRAP
;                     (0=LINE-FIELD MODE) 
LFPOS  EQU 20Q      ;LINE FEED POSITION 
;                     (0 = POSITION LINE FEED 
;                         AT START OF NEXT I/O
;                         READ
;                      1 = PUT LINE FEED AT END 
;                         OF RECORD)
FSTSND EQU 40Q      ;9600 BAUD DATACOM SHIFT
;                     (0=9600 BAUD FOR ESC,E) 
HNDSHK EQU 100Q     ;BLOCK TRANSFER HANDSHAKE 
;                     (0 = FOLLOW DC2SND SETTING
;                      1 = SEND DC2 BEFORE DATA)
DC2SND EQU 200Q 
;                     (0 = SEND DC2 ON ENTER
;                          AND FUNCTION KEY IN
;                          BLOCK MODE 
;                      1 = INHIBIT ALL DC2
;                          HANDSHAKE) 
 
;****************************************** 
; KBJMP2 - SECOND SET OF KEYBOARD JUMPERS * 
;****************************************** 
AUTTRM EQU  1Q        ;AUTO TERMINATE ON "ENTER"
CLRTRM EQU  2Q        ;CLEAR TERMINATOR ON TRANSMI
NOTEST EQU  4Q        ;INHIBIT TERMINAL SELF-TEST 
EDTWRP EQU  10Q       ;INVERT SENSE OF EDIT WRAP
PRNTAL EQU  20Q       ;SEND ALL CODES TO PRINTER
DCJMP0 EQU  200Q      ;DATA COMM JUMPER 
;*****************************************
; KBJMP3 - THIRD SET OF KEYBOARD JUMPERS *
;*****************************************
DCJMP1 EQU  1Q        ;DATA COMM JUMPERS
DCJMP2 EQU  2Q              ;.
DCJMP3 EQU  4Q              ;.
DCJMP4 EQU  10Q             ;.
NODCST EQU  20Q       ;INHIBIT DATA COMM SELF-TEST
;                       (0 = DISABLED)
SETCH  EQU  40Q       ;TURN ON "CH" CONTROL LINE
;                       (0 = OFF, 1 = ON) 
CHEKCC EQU  100Q      ;MONITOR CC CONTROL LINE
;                       (1 = ENABLED) 
FRCPTY EQU  200Q      ;FORCE PARITY ON/NO IN CHECK
;                       (1 = ENABLED) 
;************************ 
; CMFLGS - COMMON FLAGS * 
;************************ 
BLKTRG EQU  1Q        ;BLOCK TRANSFER TRIGGER 
INSWRP EQU  2Q        ;INSERT WITH WRAP AROUND
FRCRST EQU  4Q        ;FORCE FULL TERMINAL RESET
DEFSKY EQU  10Q       ;DEFINE SOFT KEY MODE ENABLE
REMSET EQU  20Q       ;REMOTE MODE ENABLED
RCVMDE EQU  40Q       ;TERMINAL IN RECEIVE MODE 
;***********************
; ERRFLG - ERROR FLAGS *
;***********************
DCMERR EQU  1Q        ;DATACOM (1 = ERROR)
TESTOK EQU  2Q        ;SELF-TEST (0 = ERROR)
LDRCHK EQU  4Q        ;LOADER CHECKSUM (0 = ERROR)
;************************** 
; INTFLG - INTERRUPT FLAG * 
;************************** 
TMRINT EQU  3         ;TIMER INTERRUPT
 
;***********************************
; PRCCTL - PROCESSOR CONTROL FLAGS *
;***********************************
TMIACK EQU  0Q        ;ACKNOWLEDGE TIMER INTERRUPT
;                       (BIT 1 OFF) 
TMRON  EQU  1Q        ;SET TIMER ON 
TMIEN  EQU  2Q        ;RE-ENABLE TIMER INTERRUPT
DCIOFF EQU  20Q       ;DISABLE DATA COMM INTERRUPT
TMIOFF EQU  40Q       ;DISABLE TIMER INTERRUPTS 
POLL   EQU  100Q      ;POLL CTU INTERRUPTS
;V*V*V*V*  SET TO ZERO FOR ROM VERSION  *V*V*V*V* 
SETROM EQU  200Q      ;DISABLE (1)/ENABLE (0) ROM 
;*********************************
; MDFLG1 - TERMINAL MODE FLAGS 1 *
;*********************************
DSPFNC EQU  1Q        ;DISPLAY FUNCTIONS ENABLED
INSCHR EQU  2Q        ;INSERT CHARACTER ENABLED 
MEMLOK EQU  4Q        ;MEMORY LOCK ENABLED
FORMAT EQU  10Q       ;FORMAT MODE ENABLED
EDIT   EQU  20Q       ;EDIT MODE ENABLED
SELECT EQU  40Q       ;SELECT MODE ENABLED
RECORD EQU  100Q      ;RECORD MODE ENABLED
FORGN  EQU  200Q      ;FOREIGN MODE ENABLED 
;*********************************
; MDFLG2 - TERMINAL MODE FLAGS 2 *
;*********************************
CAPSLK EQU  1Q        ;CAPS LOCK ENABLED
BLKMDE EQU  2Q        ;BLOCK MODE ENABLED 
AUTOLF EQU  4Q        ;AUTO LF ENABLED
REMOTE EQU  10Q       ;REMOTE ENABLED 
WBSR   EQU  40Q       ;WRITE-BACKSPACE-READ MODE
;********************************************** 
; RADIX - BASE OF INPUT PARAMETER FOR ESC SEQ * 
;********************************************** 
DECRDX EQU  10        ;DECIMAL NUMBERS
OCTRDX EQU  8         ;OCTAL NUMBERS
 
;*******************
; COMMON VARIABLES *
;*******************
INTVEC EQU  FSTRAM+145Q  ;CENTRAL INTERRUPT VECTOR
SCNVEC EQU  INTVEC+3  ;FOREIGN TERMINAL DISPLY SCA
; 
COMMON EQU  177777Q   ;UPPER LIMIT OF COMMON AREA 
CMBASE EQU  COMMON/256  ;MSB OF COMMON ADDRESSES
CMSTOR EQU  CMBASE*256  ;MSB ADJUSTMENT FACTOR
; 
DISPST EQU  COMMON-1  ;DISPLAY REFRESH START PTR
TRMTYP EQU  DISPST-1  ;TERMINAL TYPE NUMBER 
KBDCSW EQU  TRMTYP-1  ;KEYBOARD DATACOM SWITCHES
KBJMPR EQU  KBDCSW-1  ;KEYBOARD STRAPS
KBJMP2 EQU  KBJMPR-1    ;SET 2
KBJMP3 EQU  KBJMP2-1    ;SET 3
CMFLGS EQU  KBJMP3-1  ;COMMON FLAGS 
ERRFLG EQU  CMFLGS-1  ;ERROR FLAGS
INTFLG EQU  ERRFLG-1  ;INTERRUPT FLAG 
PRCCTL EQU  INTFLG-1  ;PROCESSOR CONTROL FLAGS
MDFLG1 EQU  PRCCTL-1  ;TERMINAL MODE FLAGS 1
MDFLG2 EQU  MDFLG1-1    ;AND 2
MSGPT1 EQU  MDFLG2-2  ;MESSAGE POINTERS 
MSGPT2 EQU  MSGPT1-2       ;. 
MSGPT3 EQU  MSGPT2-2       ;. 
MSGPT4 EQU  MSGPT3-2       ;. 
MSGPT5 EQU  MSGPT4-2       ;. 
MSGPT6 EQU  MSGPT5-2       ;. 
MSGPT7 EQU  MSGPT6-2       ;. 
MSGPT8 EQU  MSGPT7-2       ;. 
CTIVEC EQU  MSGPT8-2  ;CTU INTERRUPT VECTOR 
CTIJMP EQU  CTIVEC-1  ;JUMP CODE FOR VECTOR 
IODATA EQU  CTIJMP-2  ;ESQ SEQ PARM ACCUMULATOR 
IOCSGN EQU  IODATA-1  ;SIGN FOR PARAMETER 
IOPSGN EQU  IOCSGN-1  ;PARAMETER SIGN 
PARM1  EQU  IOPSGN-1  ;ESCAPE SEQUENCE PARAMETERS 
PARM2  EQU  PARM1-1        ;. 
PARM3  EQU  PARM2-1        ;. 
PARM4  EQU  PARM3-1        ;. 
PARM5  EQU  PARM4-1        ;. 
PARM6  EQU  PARM5-2        ;. 
RADIX  EQU  PARM6-1   ;RADIX OF PARAMETERS
RNGTA  EQU  RADIX-2   ;CHAR FUNCTION TABLE ADDRESS
ESCFLG EQU  RNGTA-1   ;ESCAPE SEQUENCE FLAG 
;                       = 0, NOT IN ESCAPE SEQ
;                       # 0, ESC SEQ IN PROGRESS
RSTTMR EQU  ESCFLG-1  ;SOFT RESET TIMER 
; * * * * * * * * * * * * * * * * * * * * * * * * 
;  END OF COMMON EQUATES                        * 
;^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^* 
 
;*************************************************
; 
;        DATACOM CONSTANTS
; 
;*************************************************
ZDCBAS EQU  50000Q    ;DATACOM START ADDRESS
TRIGGR EQU  ZDCBAS+2  ;BLOCK TRANSFER TRIGGER 
RECSEP EQU  TRIGGR+1  ;RECORD SEPARATOR CHARACTER 
BLKTRM EQU  RECSEP+1  ;BLOCK TERMINATOR CHARACTER 
DCJMSK EQU  BLKTRM+1  ;DATA COMM JUMPER MASK
DCJMS2 EQU  DCJMSK+1  ;DATA COMM JUMPER MASK #2 
;*************************************************
; 
;        DATACOM ENTRY VECTOR POINTERS
; 
;*************************************************
ZINIDC EQU  ZDCBAS+10Q   ;INITIALIZE DATACOM
ZIN2DC EQU  ZINIDC+3  ;INITIALIZATION CONTINUATOR 
ZDCMON EQU  ZIN2DC+3  ;MONITORING ROUTINE 
ZDCCTL EQU  ZDCMON+3  ;MISC CONTROL FUNCTIONS 
ZDCTST EQU  ZDCCTL+3  ;SELF-TEST
ZGETDC EQU  ZDCTST+3  ;GET DC CHARACTER 
ZPUTDC EQU  ZGETDC+3  ;PUT DC CHARACTER 
ZGTBIN EQU  ZPUTDC+3  ;GET BINARY DC CHARACTER
ZSTBIN EQU  ZGTBIN+3  ;START BINARY OUTPUT
ZNDBIN EQU  ZSTBIN+3  ;END BINARY OUTPUT
ZDCINT EQU  ZNDBIN+3  ;DATACOM INTERRUPTS 
;*************************************************
; 
;        DATACOM CONTROL CALL CODES 
; 
;*************************************************
CLRTRG EQU  0         ;CLEAR BLOCK TRANSFER TRIGGE
SETTRG EQU  1         ;SET BLOCK TRANSFER TRIGGER 
RSETDC EQU  2         ;RESET DATACOM
SETREM EQU  3         ;SET REMOTE MODE
SETLCL EQU  4         ;SET LOCAL MODE 
PUTBRK EQU  5         ;OUTPUT BREAK SIGNAL
DISCNT EQU  6         ;MODEM DISCONNECT 
ENDBLK EQU  7         ;TERMINATE OUTPUT MESSAGE 
SETMON EQU  8         ;ENTER MONITOR MODE 
SETNRM EQU  9         ;ENTER NORMAL MODE
FSTBIN EQU  10        ;ENTER FAST BINARY OUT MODE 
SNDATN EQU  11        ;SEND ATTENTION CODE
SNDFCT EQU  12        ;SEND FUNCTION DATA 
PROMPT EQU  13        ;SEND PROMPT CODE 
 
;************************** 
; MAIN CODE ENTRY VECTORS * 
;************************** 
MNCDBS EQU  100Q
ZDSPMS EQU  MNCDBS    ;DISPLAY MESSAGE
ZRSTDS EQU  ZDSPMS+3  ;RESTORE NORMAL DISPLAY 
ZDCNUM EQU  ZRSTDS+3  ;ACCUMULATE DIGIT FOR ESC SE
ZDCPLS EQU  ZDCNUM+3  ;ADD IN PLUS SIGN 
ZDCMNS EQU  ZDCPLS+3  ;ADD IN MINUS SIGN
ZESCND EQU  ZDCMNS+3  ;TERMINATE ESCAPE SEQUENCE
;**************************************** 
; KBFLGS - KEYBOARD ROUTINE LOCAL FLAGS * 
;**************************************** 
KBLOCK EQU  1Q        ;KEYBOARD DISABLED
PERMBM EQU  2Q        ;PERMANENT BLOCK MODE 
RPTKY  EQU  10Q       ;REPEAT LAST KEY HIT
;************************************** 
; KBLEDS - LOCAL KEYBOARD LED EQUATES * 
;************************************** 
DSFLED EQU  1Q      ;DISPLAY FUNCTIONS
ICHLED EQU  2Q      ;INSERT CHARACTER 
MLKLED EQU  4Q        ;MEMORY LOCK
XMTLED EQU  10Q       ;TRANSMIT LED 
EDTLED EQU  20Q       ;EDIT MODE
SELLED EQU 40Q      ;SELECT MODE
RECLED EQU  100Q      ;RECORD MODE
BELLED EQU  200Q      ;BELL 
 
;************************ 
; MISCELLANEOUS EQUATES * 
;************************ 
RPTDLY EQU  6         ;REPEAT DELAY (50 MSEC) 
SRTDLY EQU  51        ;SHORT START DELAY (500 MSEC
LNGDLY EQU  91        ;LONG START DELAY (900 MSEC)
; 
BLKDLY EQU  30        ;LED BLINK DELAY (30X10 MSEC
BLKSET EQU  377Q      ;BLINK SET FLAG 
; 
NUMCOL EQU  13        ;# OF KEYBOARD COLUMNS - 1
REMBIT EQU  3         ;REMOTE FLAG BIT NUMBER 
;************************** 
; ASCII CHARACTER EQUATES * 
;************************** 
BKSPCE EQU  10Q       ;ASCII BACKSPACE CONTROL COD
TAB    EQU  11Q       ;ASCII TAB CONTROL CODE 
CTLMSK EQU  37Q       ;MASK FOR CONTROL CODES 
CPSADJ EQU  40Q       ;CAPS LOCK ADJUSTMENT FACTOR
PLUS   EQU  53Q       ;(+) - PLUS SIGN
SLANT  EQU  57Q       ;(/) - SLANT
ZERO   EQU  60Q       ;ASCII ZERO 
ABLNK  EQU  40Q       ;ASCII BLANK
UPRLIM EQU  100Q      ;UPPER CASE LOWER LIMIT 
A      EQU  101Q      ;UPPER CASE A 
Z      EQU  132Q      ;UPPER CASE Z 
LWRLIM EQU  140Q      ;LOWER CASE CHAR LOWER LIMIT
DEL    EQU  177Q      ;DELETE CHARACTER ( = RUBOUT
; 
B15    EQU  100000Q   ;BIT 15 CONSTANT
 
; 
;  FUNCTION ESCAPE CODES
; 
CLRTAB EQU  262Q      ;2 - CLEAR TAB
CLRTBS EQU  263Q      ;3 - CLEAR ALL TABS 
SETLMG EQU  264Q      ;4 - SET LEFT MARGIN
SETRMG EQU  265Q      ;5 - SET RIGHT MARGIN 
ENHNCF EQU  377Q      ;DISPLAY ENHANCEMENT FUNCTIO
CURRHT EQU  303Q      ;C - CURSOR RIGHT 
CURLFT EQU  304Q      ;D - CURSOR LEFT
HOMEDN EQU  306Q      ;F - HOME DOWN
CLSCRN EQU  312Q      ;J - CLEAR SCREEN 
CLRLNE EQU  313Q      ;K - CLEAR LINE 
IWRPON EQU  316Q      ;N - INSERT CHAR W/WRAP ON
DCHWRP EQU  317Q      ;O - DELETE CHAR W/WRAPAROUN
DELCHR EQU  320Q      ;P - DELETE CHARACTER 
ICHRON EQU  321Q      ;Q - INSERT CHARACTER ON
ICHROF EQU  322Q      ;R - INSERT CHARACTER OFF 
NEXTPG EQU  325Q      ;U - NEXT PAGE
FMTONF EQU  327Q      ;W - FORMAT MODE ON 
FMTOFF EQU  330Q      ;X - FORMAT MODE OFF
DSPFON EQU  331Q      ;Y - DISPLAY FUNCTIONS ON 
ENDPRF EQU  333Q      ;[ - END PROTECTED FIELD
STPRF  EQU  335Q      ;] - START PROTECTED FIELD
;                 LOWER CASE
HOMEUP EQU  350Q      ;H - HOME UP TO UNPROTECT 
BACKTB EQU  351Q      ;I - BACK TAB 
SETSFK EQU  352Q      ;J - SET SOFT KEY DEFINE ON 
MLKON  EQU  354Q      ;L - MEMORY LOCK ON 
F1FUNC EQU  360Q      ;P - F1 FUNCTION CODE 
MNMDON EQU  371Q      ;Y - MONITOR MODE ON
TEST   EQU  372Q      ;Z - SELF-TEST
STXMOF EQU  373Q      ;[ - START TRANSMIT ONLY
; 
;  EXTERNAL FUNCTION CODES
; 
ENTRCD EQU  230Q      ;ENTER KEY
DFNCOF EQU  232Q      ;DISPLAY FUNCTIONS OFF
RDKYCD EQU  234Q      ;READ KEY 
CONDTN EQU  237Q      ;CONDITION TAPE 
CTRDKY EQU  240Q      ;CONTROL READ KEY 
EXFNLM EQU  241Q      ;EXTERNAL FUNCTION UPPER LIM
 
; 
;  KEYBOARD SLOW RAM EQUATES
; 
KBSRAM EQU  177440Q   ;UPPER LIMIT OF SLOW RAM ARE
KBSBSE EQU  (KBSRAM-1)/256;MSB OF SLOW RAM AREA 
KBSSTR EQU  KBSBSE*256  ;MSB ADJUSTMENT FACTOR
KBBUF2 EQU  KBSRAM-14  ;ACTIVE KEYS STATE TABLE 
KBFLGS EQU  KBBUF2-1  ;KEYBOARD FLAGS 
KBJ1MS EQU  KBFLGS-1  ;JUMPER ALTER INHIBIT MASK -
;                       SET TO 1 IF NOT TO BE 
;                       ALTERED BY ESCAPE SEQUENCE
KBCHAR EQU  KBJ1MS-1  ;REPEATING KEY CHARACTER
BLKFLG EQU  KBCHAR-1  ;LED BLINK FLAG 
KBKNSV EQU  BLKFLG-1  ;REPEATING KEY NUMBER 
KBLEDS EQU  KBKNSV-1  ;STATE OF KEYBOARD LED'S
LEDSAV EQU  KBLEDS-1  ;SAVE AREA FOR LED VALUES 
; 
;  KEYBOARD FAST ACCESS RAM EQUATES 
; 
KBFRAM EQU  FSTRAM+400Q  ;UPPER LIMIT OF FAST RAM 
KBFBSE EQU  (KBFRAM-1)/256;MSB OF FAST RAM AREA 
KBFSTR EQU  KBFBSE*256  ;MSB ADJUSTMENT FACTOR
; 
KBBUF  EQU  KBFRAM-14  ;COLUMN STATE TABLE BUFFER 
KBBUFL EQU  KBBUF-KBFSTR  ;LSB OF STATE TABLE ADDR
KBBFPT EQU  KBBUF-2   ;KEYBOARD STATE TABLE POINTE
KEYCOL EQU  KBBFPT-2  ;KEYBOARD COLUMN ADDRESS
BLKTMR EQU  KEYCOL-1  ;BLINK DELAY TIMER
KBTIMR EQU  BLKTMR-1  ;KEY REPEAT TIMER 
KEYBLN EQU  40        ;KEY BUFFER LENGTH
KEYBUF EQU  KBTIMR-KEYBLN  ;KEY BUFFER
;                       EACH TWO BYTE ENTRY IN THE
;                       KEY BUFFER REPRESENTS ONE 
;                       OR MORE KEY TRANSITIONS.
;                       THE MSB IS THE KEYBOARD 
;                       COLUMN NUMBER AND THE LSB,
;                       THE BITS CHANGED. 
KEYBFL EQU  KEYBUF-KBFSTR  ;LSB OF KEY BUFFER ADDR
KBPTPT EQU  KEYBUF-2  ;KEY BUFFER PUT POINTER 
KBGTPT EQU  KBPTPT-2  ;KEY BUFFER GET POINTER 
 
; 
;  EQUATES TO SPECIFIC COLUMNS IN STATE TABLE 
; 
KBCTSH EQU  KBBUF2    ;CONTROL AND SHIFT KEYS 
CTLKEY EQU  1Q          ;CONTROL KEY BIT
LSHFKY EQU  10Q         ;LEFT SHIFT KEY 
RSHFKY EQU  20Q         ;RIGHT SHIFT KEY
; 
TSTROW EQU  KBBUF2+5  ;TEST KEY ROW 
TSTCOL EQU  1Q          ;TEST KEY BIT 
; 
IOKYRW EQU  KBBUF2+9  ;I/O CONTROL KEY ROW
IOKYCL EQU  1Q          ;I/O CONTROL (GOLD) KEY 
ENTCOL EQU  2Q          ;ENTER KEY
; 
BRKYRN EQU  13        ;BREAK KEY ROW NUMBER 
BRKCOL EQU  1Q          ;BREAK KEY
; 
;  EQUATES TO SPECIFIC KEY NUMBERS
; 
RMKYNM EQU  10Q       ;REMOTE 
CLKYNM EQU  20Q       ;CAPS LOCK
ALKYNM EQU  40Q       ;AUTO LINE FEED 
BMKYNM EQU  100Q      ;BLOCK MODE 
 
;*********************
; I/O MODULE EQUATES *
;*********************
IOBASE EQU 200Q     ;I/O ADDRESS MSB'S
IOKB   EQU  (3Q+IOBASE)*256;MODULE 11 BASE ADDRESS
IOKBSW EQU  IOKB+16Q  ;KEYBOARD JUMPERS IN
IOKBDC EQU  IOKB+17Q  ;DATACOM SWITCHES IN
IOKBS2 EQU  IOKB+200Q  ;KEYBOARD JUMPERS 2 IN 
IOKBS3 EQU  IOKB+240Q  ;KEYBOARD JUMPERS 3 IN 
; 
IOKBLD EQU  IOKB+0Q   ;SET KEYBOARD LED'S 
IOKBCO EQU  IOKB+200Q  ;RESET KEY CONTROL 
RSTON  EQU  2Q           ;ENABLE RESET KEY
RSTOFF EQU  4Q           ;DISABLE RESET KEY 
IOKBCL EQU  IOKB+40Q  ;OUTPUT LAST COLUMN STATE 
 
; 
;***************************
;  START OF KEYBOARD CODE  *
;***************************
       ORG  44000Q    ;START OF KEYBOARD CODE 
KBBASE EQU  $           ;REGION (2K)
       DB   120Q      ;SET ROM PRESENT INDICATORS 
       DB   KBBASE/256
; 
;  KEYBOARD ENTRY VECTOR
; 
       JMP  INITKB    ;KEYBOARD INITIALIZATION
       JMP  GTKEY     ;GET KEYBOARD KEY 
       JMP  KBCTL     ;PERFORM KEYBOARD CONTROL 
       JMP  KBMON     ;MONITOR KEYBOARD 
       JMP  SETMD1    ;SET MODE 1 FLAGS 
       JMP  CLRMD1    ;CLEAR MODE 1 FLAGS 
       JMP  BELL      ;SOUND THE KEYBOARD BELL
       JMP  SETXMT    ;SET TRANSMIT LED 
       JMP  CLRXMT    ;CLEAR TRANSMIT LED 
       JMP  STJMPR    ;SET JUMPER ESC SEQ ROUTINE 
       JMP  STLKYS    ;SET LATCHING KEYS ESC SEQ
       JMP  ALPCHK    ;CHECK FOR ALPHA KEY ENTRY
       JMP  NUMCHK    ;CHECK FOR NUMERIC KEY ENTRY
; 
;  KEYBOARD CONSTANTS 
; 
FRSALT:DB   20Q       ;INITIAL ALT CHAR SET = SET 
ALTOUT:DB   0Q        ;INITIAL ALT CHAR SET OUT = 
 
; 
;  LOWER CASE ASCII TRANSLATION TABLE 
; 
LWRASC EQU  $ 
       DB   000Q,033Q,011Q,000Q  ;COLUMN 0
       DB   000Q,061Q,064Q,010Q 
       DB   206Q,061Q,161Q,172Q  ;COLUMN 1
       DB   015Q,062Q,065Q,134Q 
       DB   203Q,062Q,167Q,170Q  ;COLUMN 2
       DB   135Q,063Q,066Q,364Q 
       DB   200Q,063Q,145Q,143Q  ;COLUMN 3
       DB   072Q,304Q,323Q,365Q 
       DB   204Q,064Q,162Q,166Q  ;COLUMN 4
       DB   073Q,350Q,301Q,366Q 
       DB   372Q,065Q,164Q,142Q  ;COLUMN 5
       DB   154Q,303Q,325Q,367Q 
       DB   305Q,066Q,171Q,040Q  ;COLUMN 6
       DB   153Q,326Q,312Q,202Q 
       DB   201Q,067Q,165Q,156Q  ;COLUMN 7
       DB   152Q,302Q,261Q,320Q 
       DB   205Q,070Q,151Q,155Q  ;COLUMN 8
       DB   150Q,324Q,262Q,315Q 
       DB   233Q,230Q,157Q,054Q  ;COLUMN 9
       DB   147Q,056Q,071Q,314Q 
       DB   234Q,071Q,160Q,056Q  ;COLUMN 10 
       DB   146Q,060Q,070Q,363Q 
       DB   235Q,060Q,100Q,057Q  ;COLUMN 11 
       DB   144Q,000Q,067Q,362Q 
       DB   236Q,055Q,133Q,000Q  ;COLUMN 12 
       DB   163Q,000Q,000Q,361Q 
       DB   231Q,136Q,137Q,000Q  ;COLUMN 13 
       DB   141Q,000Q,000Q,360Q 
 
; 
;  UPPER CASE ASCII TABLE 
; 
UPRASC EQU  $ 
       DB   000Q,033Q,011Q,000Q  ;COLUMN 0
       DB   000Q,061Q,064Q,010Q 
       DB   206Q,041Q,121Q,132Q  ;COLUMN 1
       DB   015Q,062Q,065Q,174Q 
       DB   203Q,042Q,127Q,130Q  ;COLUMN 2
       DB   175Q,063Q,066Q,364Q 
       DB   200Q,043Q,105Q,103Q  ;COLUMN 3
       DB   052Q,304Q,323Q,365Q 
       DB   204Q,044Q,122Q,126Q  ;COLUMN 4
       DB   053Q,350Q,301Q,366Q 
       DB   372Q,045Q,124Q,102Q  ;COLUMN 5
       DB   114Q,303Q,325Q,367Q 
       DB   305Q,046Q,131Q,040Q  ;COLUMN 6
       DB   113Q,326Q,312Q,202Q 
       DB   201Q,047Q,125Q,116Q  ;COLUMN 7
       DB   112Q,302Q,261Q,320Q 
       DB   205Q,050Q,111Q,115Q  ;COLUMN 8
       DB   110Q,324Q,262Q,315Q 
       DB   233Q,230Q,117Q,074Q  ;COLUMN 9
       DB   107Q,056Q,071Q,314Q 
       DB   234Q,051Q,120Q,076Q  ;COLUMN 10 
       DB   106Q,060Q,070Q,363Q 
       DB   235Q,060Q,140Q,077Q  ;COLUMN 11 
       DB   104Q,000Q,067Q,362Q 
       DB   236Q,075Q,173Q,000Q  ;COLUMN 12 
       DB   123Q,000Q,000Q,361Q 
       DB   231Q,176Q,177Q,000Q  ;COLUMN 13 
       DB   101Q,000Q,000Q,360Q 
 
;*****************************************
; ALTERNATE FUNCTION KEY FUNCTIONS TABLE *
;*****************************************
; 
;  NORMAL FUNCTION CODES FOLLOWED BY ALTERNATES 
; 
NRMFCT EQU  $ 
       DB   RDKYCD    ;READ KEY 
       DB   CTRDKY      ;CONTROL READ KEY 
       DB   CLRTAB    ;CLEAR TAB
       DB   CLRTBS      ;CLEAR ALL TABS 
       DB   CURLFT    ;CURSOR LEFT
       DB   SETLMG      ;SET LEFT MARGIN
       DB   CURRHT    ;CURSOR RIGHT 
       DB   SETRMG      ;SET RIGHT MARGIN 
       DB   CLSCRN    ;CLEAR SCREEN 
       DB   CLRLNE      ;CLEAR LINE 
       DB   DELCHR    ;DELETE CHARACTER 
       DB   CHECK1      ;ADDITIONAL CHECK 1 
       DB   NEXTPG    ;NEXT PAGE
       DB   CHECK2      ;ADDITIONAL CHECK 2 
       DB   HOMEUP    ;HOME UP
       DB   HOMEDN      ;HOME DOWN
       DB   TEST      ;SELF-TEST
       DB   CONDTN      ;CONDITION TAPE 
       DB   F1FUNC    ;F1 KEY 
       DB   ENHNCF      ;START DISPLAY ENHANCEMENT
       DB   F1FUNC+1  ;F2 KEY 
       DB   ENDPRF      ;END PROTECTED FIELD
       DB   F1FUNC+2  ;F3 KEY 
       DB   STPRF       ;START PROTECTED FIELD
       DB   F1FUNC+3  ;F4 KEY 
       DB   FMTONF      ;FORMAT MODE ON 
       DB   F1FUNC+4  ;F5 KEY 
       DB   FMTOFF      ;FORMAT MODE OFF
       DB   F1FUNC+5  ;F6 KEY 
       DB   STXMOF      ;START TRANSMIT-ONLY FIELD
; 
NUMALT EQU  ($-NRMFCT)/2;# OF ALTERNATE FUNCTIONS 
CHECK1 EQU  1         ;EXTRA CHECK 1 FLAG 
CHECK2 EQU  2         ;EXTRA CHECK 2 FLAG 
 
; 
;  INTERNAL FUNCTIONS VECTOR TABLE
; 
FNCTAB EQU  $ 
       DW   CKMLOK    ;200 - MEMORY LOCK
       DW   CKDSFN    ;201 - DISPLAY FUNCTIONS
       DW   CKICHR    ;202 - INSERT CHARACTER 
       DW   STCPLK    ;203 - CAPS LOCK
       DW   STAULF    ;204 - AUTO LF
       DW   STBLKM    ;205 - BLOCK MODE 
       DW   STRMMD    ;206 - SET REMOTE MODE
; 
FNBASE EQU  200Q      ;FUNCTION LOWER LIMIT 
FNCLIM EQU  207Q      ;FUNCTION CODE UPPER LIMIT
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  INITKB - INITIALIZE KEYBOARD 
; 
;      ENTRY:  DON'T CARE 
; 
;      EXIT :  A DESTROYED
;              NC = NO ERRORS 
;              C = ERROR DETECTED 
;                B,C = POINTER TO ERROR MESSAGE 
; 
INITKB EQU  $ 
       LDA  IOKBSW    ;GET KEYBOARD STRAP SETTINGS
       STA  KBJMPR      ;AND STORE THEM 
       LDA  IOKBS2
       STA  KBJMP2
       LDA  IOKBS3
       STA  KBJMP3
       LDA  IOKBDC    ;GET AND STORE THE DATA 
       STA  KBDCSW      ;COMM SWITCHES
; 
INITK0 EQU  $ 
       LXI  H,KBBUF+NUMCOL
       SHLD KBBFPT    ;INITIALIZE STATE TABLE 
       LXI  H,IOKB+NUMCOL  ;POINTERS
       SHLD KEYCOL
       LXI  H,KEYBUF+KEYBLN-1 
       SHLD KBGTPT    ;INITIALIZE TRANSITION
       SHLD KBPTPT      ;BUFFER POINTERS
; 
       XRA  A         ;CLEAR THE LEDS ON THE
INITK1 EQU  $           ;KEYBOARD 
       STA  IOKBLD
       RET            ;RETURN C = FALSE 
 
;***********************************
; GTKEY - GET A KEYBOARD CHARACTER *
;***********************************
; 
;  ENTRY:  DON'T CARE 
; 
;  EXIT :  Z - KEYBOARD INPUT PRESENT 
;            A = KEYBOARD CHARACTER CODE
;          NZ - NO KEYBOARD INPUT 
;            A = 0, NO KEY HIT (OR NULL CHAR) 
;            A # 0, KEYBOARD LOCKED (A IS 
;              KEYBOARD CHARACTER CODE) 
;          B,C,D,E DESTROYED
; 
;  KEY VALUES IN THE RANGE 260-376 (OCTAL)
;  REPRESENT TWO CHARACTER ESCAPE SEQUENCES 
;  GENERATED FROM FUNCTION KEYS.  THE SECOND
;  CHARACTER IS OBTAINED BY MASKING OUT THE 
;  HIGH ORDER BIT.
; 
;  KEY VALUES IN THE RANGE 230-241 (OCTAL)
;  REPRESENT INTERNAL FUNCTION KEYS AS
;  FOLLOWS: 
; 
;       230 - ENTER KEY PRESSED 
;       231 - BREAK KEY PRESSED 
;       232 - DISPLAY FUNCTIONS OFF 
;       233 - I/O CONTROL KEY PRESSED 
;       234 - READ KEY PRESSED
;       235 - RECORD KEY PRESSED
;       236 - SELECT KEY PRESSED
;       237 - CONDITION TAPE FUNCTION 
; 
GTKEY  EQU  $ 
       PUSH H         ;SAVE H AND L 
       CALL STRTS1    ;ENABLE RESET KEY 
       LDA  KBFLGS    ;GET KEYBOARD FLAGS 
       ANI  RPTKY     ;REPEAT LAST KEY HIT? 
       JNZ  GTK040    ;YES - RE-ISSUE THE KEY 
       LHLD KBGTPT    ;NO - FETCH BUFFER GET PTR
GTK005 EQU  $ 
       LDA  KBPTPT    ;GET LSB OF PUT POINTER 
       CMP  L         ;BUFFER EMPTY?
       JNZ  GTK100    ;NO - PROCESS KEYBOARD INPUT
       CALL KBMON1    ;YES - LOOK FOR STATE CHANGE
GTK010 EQU  $ 
       LHLD KBGTPT    ;GET KEY BUFFER POINTERS
       LDA  KBPTPT
       CMP  L         ;BUFFER EMPTY?
       JNZ  GTK100    ;NO - PROCESS KEYBOARD INPUT
GTK020 EQU  $ 
       LDA  IOKBDC    ;YES - UPDATE SETTINGS OF 
       STA  KBDCSW      ;KEYBOARD DATACOM SWITCHES
 
;************************** 
; CHECK FOR REPEATING KEY * 
;************************** 
       LXI  H,KBTIMR  ;GET THE REPEAT DELAY TIMER 
       MOV  A,M 
       DCR  A         ;TIME TO REPEAT?
       JNZ  GTK060    ;NO - EXIT NO KEY HIT 
       MVI  M,RPTDLY  ;YES - RESET COUNTER
GTK030 EQU  $ 
       LDA  KBCHAR    ;RECALL THE KEYBOARD CHAR 
       JMP  GTKYX1    ;RETURN KEY HIT 
;********************** 
; REPEAT LAST KEY HIT * 
;********************** 
GTK040 EQU  $ 
       LXI  H,KBFLGS  ;CLEAR REPEAT FLAG
       CMA            ;CONVERT BIT TO CLEAR MASK
       ANA  M         ;CLEAR REPEAT KEY FLAG
       MOV  M,A       ;UPDATE FLAGS 
       JMP  GTK030    ;RE-ISSUE THE KEY CODE
;************************ 
; NO KEY CHANGES - EXIT * 
;************************ 
GTK060 EQU  $ 
       ORI  377Q      ;SET NC, NZ 
       POP  H         ;RESTORE H,L
       RET
 
; 
;  KEYBOARD STATE CHANGE IN BUFFER
; 
GTK100 EQU  $ 
       MVI  D,0       ;SET D FOR MSB = 0
       MOV  E,M       ;GET KEYBOARD COLUMN NUMBER 
       DCX  H           ;(D = 0)
       MOV  C,M       ;GET NEW STATE VALUE
       PUSH H         ;SAVE BUFFER ADDRESS
       LXI  H,KBBUF2  ;COMPUTE LOCATION OF
       DAD  D           ;STATE TABLE BYTE 
       MOV  A,M 
       XRA  C         ;ANY MORE CHANGES?
       JNZ  GTK130    ;YES - GO PROCESS CHANGES 
       POP  H         ;NO - ADVANCE TO NEXT 
       MVI  A,KEYBFL    ;BUFFER ENTRY 
       CMP  L         ;REACHED START OF BUFFER? 
       JNZ  GTK120    ;NO - MOVE TO NEXT BYTE 
       MVI  L,KEYBFL+KEYBLN  ;YES - RESET POINTER 
GTK120 EQU  $ 
       DCX  H         ;MOVE TO NEXT BYTE
       SHLD KBGTPT    ;UPDATE GET POINTER 
       JMP  GTK005    ;CHECK FOR MORE CHANGES 
;********************************************** 
; KEYBOARD CHANGE FOUND - DETERMINE NEW STATE * 
;********************************************** 
GTK130 EQU  $ 
       INX  SP        ;POP OFF TOP OF STACK 
       INX  SP
       MOV  C,A       ;EXTRACT RIGHTMOST CHANGED
       XRA  A           ;BIT
       SUB  C 
       ANA  C 
       MOV  B,A       ;SAVE CHANGED BIT IN B-REG
       XRA  M         ;COMPUTE NEW STATE AND
       MOV  M,A         ;UPDATE STATE TABLE 
       ANA  B         ;WAS KEY RELEASED?
       JNZ  GTK200    ;NO - EXTRACT KEY CODE
       CALL GTKYNM    ;YES - COMPUTE KEY NUMBER 
       CMP  M         ;WAS THE KEY REPEATING? 
       JNZ  GTK150    ;NO - CHECK FOR LATCH RELEAS
       MOV  A,D       ;CLEAR THE REPEAT TIMER 
       STA  KBTIMR
       JMP  GTK010    ;TRY FOR ANOTHER KEY
 
; 
;  NON-REPEATING KEY RELEASED - CHECK FOR 
;    LATCHING KEY RELEASE 
; 
GTK150 EQU  $ 
       CPI  BMKYNM    ;BLOCK MODE KEY?
       JZ   GTK160    ;YES - RESET BLOCK MODE 
       JP   GTK010    ;NOT LATCHING KEY - TRY AGAI
       CPI  ALKYNM    ;AUTO LF KEY? 
       JZ   GTK170    ;YES - RESET AUTO LF FLAG 
       CPI  CLKYNM    ;CAPS LOCK KEY
       JZ   GTK180    ;YES - RESET CAPS LOCK FLAG 
       SUI  RMKYNM    ;REMOTE KEY?
       JNZ  GTK010    ;NO - TRY FOR ANOTHER KEY 
       STA  KBTIMR    ;YES - CLEAR REPEAT TIMER 
       MVI  A,REMOTE    ;AND CLEAR REMOTE FLAG
       JMP  GTK190
; 
;  BLOCK MODE KEY RELEASED - RESET BLOCK MODE FLAG
; 
GTK160 EQU  $ 
       LDA  KBFLGS    ;GET KEYBOARD FLAGS 
       ANI  PERMBM    ;SET FOR PERMANENT BLOCK MDE
       JNZ  GTK010    ;YES - TRY FOR ANOTHER KEY
       MVI  A,BLKMDE  ;NO - CLEAR BLOCK MODE FLAG 
       JMP  GTK190
; 
;  AUTO LF KEY RELEASED - RESET AUTO LF FLAG
; 
GTK170 EQU  $ 
       MVI  A,AUTOLF  ;SET FLAG BIT TO BE CLEARED 
       JMP  GTK190    ;CLEAR THE FLAG AND RETURN
; 
;  CAPS LOCK KEY RELEASE - RESET CAPS LOCK FLAG 
; 
GTK180 EQU  $ 
       MVI  A,CAPSLK  ;SET FLAG BIT TO BE CLEARED 
; 
GTK190 EQU  $ 
       CMA            ;CONVERT TO CLEAR MASK
       LXI  H,MDFLG2  ;CLEAR FLAG FROM TERMINAL 
       ANA  M           ;MODE FLAGS 2 
       MOV  M,A       ;UPDATE FLAGS 
       JMP  GTK010    ;TRY FOR ANOTHER KEY
 
; 
;  NEW KEY IS PRESSED DOWN - COMPUTE KEY CODE 
; 
GTK200 EQU  $ 
       LXI  H,KBTIMR  ;CLEAR THE REPEAT TIMER 
       MOV  M,D 
       CALL GTKYNM    ;COMPUTE KEY NUMBER 
       MOV  M,A       ;UPDATE CURRENT REPEATING KE
       LDA  KBCTSH    ;GET CONTROL/SHIFT KEY COLUM
       ANI  LSHFKY+RSHFKY  ;SHIFT KEY DOWN
       LXI  H,LWRASC    ;(SET FOR LOWER CASE TABLE
       JZ   GTK210    ;YES - GET THE KEY CODE 
       LXI  H,UPRASC  ;NO - USE UPPER CASE TABLE
; 
;  EXTRACT KEY CODE FROM TABLE
; 
GTK210 EQU  $           ;(D = 0, E = KEY NUMBER)
       DAD  D         ;INDEX TABLE BY KEY NUMBER
       MOV  B,M       ;FETCH THE TABLE VALUE
       MOV  A,B 
       ORA  A         ;ANY KEY CODE?
       JZ   GTK010    ;NO - TRY FOR ANOTHER KEY 
       JM   GTK300    ;PROCESS FUNCTION CODE IF S=
       LDA  KBCTSH      ;(GET CONTROL/SHIFT COLUMN
       ANI  CTLKEY    ;CONTROL KEY PRESSED? 
       JZ   GTK220    ;NO - CHECK CAPS LOCK 
       MOV  A,B       ;YES - MOVE CHARACTER TO A
       CPI  BKSPCE    ;IS IT THE BACKSPACE KEY? 
       JZ   GTK215    ;YES - CHANGE TO BACK TAB 
       CPI  TAB       ;IS IT THE TAB KEY? 
       JZ   GTK215    ;YES - CHANGE TO BACK TAB 
       CPI  UPRLIM    ;IS CHARACTER ALPHABETIC? 
       JM   GTK230    ;NO - RETURN UNALTERED CHAR 
       ANI  CTLMSK    ;YES - MASK FOR CONTROL CODE
       JMP  GTK230    ;RETURN KEY HIT 
; 
;  CONTROL-BACKSPACE/TAB - CHANGE TO BACK TAB 
; 
GTK215 EQU  $ 
       MVI  A,BACKTB  ;RETURN BACK TAB CODE 
       JMP  GTK230
 
; 
;  CONTROL KEY UP - CHECK FOR CAPS LOCK 
; 
GTK220 EQU  $ 
       LDA  MDFLG2    ;GET TERMINAL MODE FLAGS 2
       ANI  CAPSLK    ;CAPS LOCK SET? 
       MOV  A,B         ;(PUT KEY CODE IN A-REG)
       JZ   GTK230    ;NO - RETURN KEY HIT
       CPI  LWRLIM    ;IS KEY LOWER CASE? 
       JM   GTK230    ;NO - RETURN KEY HIT
       CPI  DEL       ;IS KEY = DELETE (RUBOUT)?
       JZ   GTK230    ;YES - RETURN KEY HIT 
       SUI  CPSADJ    ;NO - ADJUST TO UPPER CASE
; 
;  RETURN WITH LONG REPEAT DELAY
; 
GTK230 EQU  $ 
       LXI  H,KBTIMR  ;SET KEYBAORD REPEAT TIMER
       MVI  M,LNGDLY    ;FOR LONG START DELAY 
; 
;  GTKYX1 - RETURN KEY HIT
; 
GTKYX1 EQU  $ 
       STA  KBCHAR    ;SAVE THE CHARACTER FOR RPT 
       MOV  L,A       ;SAVE CHARACTER IN L-REGISTE
       LDA  KBFLGS    ;GET KEYBOARD FLAGS 
       ANI  KBLOCK    ;KEYBOARD LOCKED? 
       MOV  A,L         ;(RECALL KEYBOARD CHAR) 
       JNZ  GTK240    ;YES - RETURN NO KEY HIT
       POP  H         ;NO - RESTORE H,L 
       RET            ;RETURN Z TRUE
; 
;  RETURN NO KEY HIT FOR LOCKED KEYBOARD
; 
GTK240 EQU  $ 
       LXI  H,KBTIMR  ;CLEAR THE REPEAT TIMER 
       MOV  M,D 
       POP  H         ;RECALL H,L 
       RET            ;RETURN Z FALSE 
 
;*********************************************
; FUNCTION KEY - CHECK FOR CONTROL EXCHANGES *
;*********************************************
GTK300 EQU  $ 
       CPI  FNCLIM    ;INTERNAL FUNCTION CODE?
       JM   GTK400    ;YES - PROCESS INTERNAL CODE
       LDA  KBCTSH    ;NO - GET CONTROL/SHIFT COLM
       ANI  CTLKEY    ;CONTROL KEY DOWN?
       JNZ  GTK310    ;YES - CHECK FOR ALTERNATES 
       LDA  KBJMP2    ;NO - GET KEYBOARD JUMPERS 2
       ANI  EDTWRP    ;EDIT WRAP AROUND REVERSED? 
       MOV  A,B         ;(RECALL FUNCTION CODE) 
       JZ   GTK350    ;NO - RETURN NORMAL CODE
       CPI  DELCHR    ;IS IT DELETE CHARACTER?
       JNZ  GTK350    ;NO - RETURN NORMAL CODE
       MVI  A,DCHWRP  ;YES - USE DELETE WRAPAROUND
       JMP  GTK350    ;SET THE FUNCTION CODE
 
;*****************************************
; CONTROL KEY DOWN - CHECK FOR ALTERNATE *
;  FUNCTIONS                             *
;*****************************************
GTK310 EQU  $ 
       MOV  A,B       ;RECALL THE FUCNTION CODE 
       LXI  H,NRMFCT  ;SET INITIAL TABLE ADDRESSES
       MVI  C,NUMALT  ;SET NUMBER OF ALTERNATES 
; 
GTK320 EQU  $ 
       CMP  M         ;FUNCTION FOUND?
       INX  H           ;(ADVANCE TO ALT CODE)
       JZ   GTK330    ;YES - GET ITS ALTERNATE
       INX  H         ;NO - STEP TO NEXT ENTRY
       DCR  C         ;TABLE EXHAUSTED? 
       JNZ  GTK320    ;NO - TRY NEXT VALUE
       JMP  GTK350    ;YES - USE NORMAL FUNCTION
;************************************************ 
; FUNCTION WITH ALTERNATE FOUND - USE ALTERNATE * 
;************************************************ 
GTK330 EQU  $ 
       MOV  A,M       ;GET THE ALTERNATE FUNCTION 
       CPI  CHECK1    ;FURTHER CHECKING REQUIRED? 
       JZ   GTK380    ;YES - GO DO IT 
       CPI  CHECK2
       JZ   GTK370    ;YES - GO DO IT 
;                     NO - SET FUNCTION CODE
;******************** 
; SET FUNCTION CODE * 
;******************** 
GTK350 EQU  $ 
       CALL SETRPT    ;SET THE REPEAT RATE
       JMP  GTKYX1    ;RETURN KEY HIT 
 
; 
;  TOGGLE SOFT KEY/NORMAL DISPLAY 
; 
GTK370 EQU  $ 
       LDA  CMFLGS    ;GET COMMON FLAGS 
       ANI  DEFSKY    ;SOFT KEY DEFINE ACTIVE?
       MVI  A,SETSFK    ;(SET CODE FOR SOFT KEYS) 
       JZ   GTK350    ;NO - RETURN NORMAL CODE
       INR  A         ;YES - RETURN CODE TO RESTOR
       JMP  GTK350      ;NORMAL DISPLAY 
; 
;  DELETE CHARACTER AND CONTROL KEY DOWN
; 
GTK380 EQU  $ 
       LDA  KBJMP2    ;GET KEYBOARD JUMPERS 2 
       ANI  EDTWRP    ;EDIT WRAP AROUND REVERSED? 
       MOV  A,B         ;(RECALL NORMAL CODE) 
       JNZ  GTK350    ;YES - RETURN NORMAL CODE 
       MVI  A,DCHWRP  ;NO - RETURN WRAP AROUND COD
       JMP  GTK350
 
;*****************************
; PROCESS INTERNAL FUNCTIONS *
;*****************************
GTK400 EQU  $ 
       SUI  FNBASE    ;COMPUTE FUNCTION INDEX 
       ADD  A 
       MOV  E,A       ;PUT INTO E (D = 0) 
       LXI  H,FNCTAB  ;GET POINTER TO FUNCTION
       DAD  D           ;ROUTINE
       MOV  A,M 
       INX  H 
       MOV  H,M 
       MOV  L,A 
       PCHL           ;PERFORM FUNCTION 
; 
;  MEMORY LOCK
; 
CKMLOK EQU  $ 
       LDA  MDFLG1    ;GET TERMINAL MODE FLAGS
       ANI  MEMLOK    ;MEMORY LOCK ON?
       MVI  A,MLKON     ;(SET TURN ON ESCAPE CODE)
       JZ   GTKYX1    ;NO - RETURN TURN ON CODE 
       INR  A         ;YES - RETURN TURN OFF CODE 
       JMP  GTKYX1
; 
;  DISPLAY FUNCTIONS
; 
CKDSFN EQU  $ 
       LDA  MDFLG1    ;GET TERMINAL MODE FLAGS 1
       ANI  DSPFNC    ;DISPLAY FUNCTIONS ON?
       JNZ  GTK410    ;YES - TURN OFF DISPLAY FUNC
       LDA  KBCTSH    ;NO - GET CONTROL/SHIFT COLM
       ANI  CTLKEY    ;CONTROL KEY DOWN?
       MVI  A,DSPFON    ;(SET CODE FOR DSP FNCT ON
       JZ   GTKYX1    ;NO - TURN DISPLAY FUNCTIONS
       MVI  A,MNMDON  ;YES - SET TO TURN ON MONITO
       JMP  GTKYX1      ;MODE 
; 
GTK410 EQU  $ 
       MVI  A,DFNCOF  ;RETURN DISPLAY FUNCTIONS 
       JMP  GTKYX1      ;OFF CODE 
 
; 
;  INSERT CHARACTER 
; 
CKICHR EQU  $ 
       LDA  MDFLG1    ;GET TERMINAL MODE FLAGS
       ANI  INSCHR    ;INSERT CHARACTER ON? 
       MVI  A,ICHROF    ;(SET OFF ESCAPE CODE)
       JNZ  GTKYX1    ;YES - RETURN OFF CODE
       LDA  KBJMP2    ;NO - GET KEYBOARD JUMPERS 2
       ANI  EDTWRP    ;REVERSE SENSE OF EDIT WRAP?
       JZ   CKC010    ;NO - USE NORMAL SENSE
       MVI  A,377Q    ;YES - INVERT SENSE OF CTL
CKC010 EQU  $ 
       LXI  H,KBCTSH  ;GET CONTROL/SHIFT COLUMN 
       XRA  M         ;SET FOR PROPER SENSE 
       ANI  CTLKEY    ;USE ALTERNATE CODE?
       MVI  A,ICHRON    ;(SET TURN ON ESCAPE CODE)
       JZ   GTKYX1    ;NO - RETURN NORMAL ON CODE 
       MVI  A,IWRPON  ;YES - RETURN WRAP AROUND ON
       JMP  GTKYX1
; 
;  SET CAPS LOCK
; 
STCPLK EQU  $ 
       MVI  A,CAPSLK  ;SET FLAG BIT TO BE SET 
       JMP  GTK450    ;SET THE FLAG AND EXIT
; 
;  SET AUTO LINE FEED 
; 
STAULF EQU  $ 
       MVI  A,AUTOLF  ;SET FLAG BIT TO BE SET 
       JMP  GTK450    ;SET THE FLAG AND EXIT
; 
;  SET BLOCK MODE 
; 
STBLKM EQU  $ 
       MVI  A,BLKMDE  ;SET FLAG BIT TO BE SET 
       JMP  GTK450    ;SET FLAG AND EXIT
; 
;  SET REMOTE MODE
; 
STRMMD EQU  $ 
       MVI  A,REMOTE  ;SET FLAG BIT TO BE SET 
; 
GTK450 EQU  $ 
       LXI  H,MDFLG2
       ORA  M         ;SET THE FLAG 
       MOV  M,A       ;UPDATE THE FLAGS 
       XRA  A         ;CLEAR KEY NUMBER SAVE WORD 
       STA  KBKNSV
       JMP  GTK010    ;TRY FOR ANOTHER KEY
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  KBMON - MONITOR KEYBOARD 
; 
;      ENTRY:  DON'T CARE 
; 
;      EXIT :  ALL REGISTERS DESTROYED
; 
KBMON  EQU  $ 
       LXI  H,KBTIMR  ;DECREMENT THE REPEAT 
       MOV  A,M         ;KEY TIMER
       DCR  A         ;TIMER ACTIVE?
       JM   KBM010    ;NO - DON'T UPDATE TIMER
       JZ   KBM010    ;TIME OUT - DON'T UPDATE
       MOV  M,A       ;YES - UPDATE TIMER 
KBM010 EQU  $ 
       INX  H         ;DECREMENT BLINK TIMER
       DCR  M         ;TIME TO BLINK LEDS?
       LDA  KBLEDS      ;(GET CURRENT LED STATE)
       JP   KBM020    ;NO - SET LED'S ONLY
       MOV  B,A       ;SAVE CURRENT STATE IN B-REG
       MVI  M,BLKDLY  ;YES - RESET TIMER
       LDA  BLKFLG    ;GET LED BLINK FLAG 
       XRA  B         ;SET NEW LED VALUES 
       STA  KBLEDS    ;STORE NEW VALUES 
KBM020 EQU  $ 
       EI             ;RE-ENABLE INTERRUPTS 
       STA  IOKBLD    ;SET KEYBOARD LED'S 
 
; 
;  CHECK FOR NEW KEY HIT
; 
KBMON1 EQU  $ 
       DI             ;DISABLE INTERRUPTS 
       LHLD KEYCOL    ;GET CURRENT KEY COLUMNN
       XCHG             ;IN D,E 
       LHLD KBBFPT    ;GET STATE TABLE POINTER
       MOV  A,M       ;GET PREVIOUS STATE 
       MOV  B,A       ;SAVE IT IN B-REGISTER
       STA  IOKBCL    ;SET HYSTERESIS FOR DETECTOR
       LDAX D         ;GET NEW STATE
       XRA  B         ;ANY CHANGES? 
       JNZ  KBM100    ;YES - PROCESS NEW STATE
       DCX  H         ;NO - DECREMENT TO NEXT COL 
       DCR  E         ;ALL COLUMNS DONE?
       JP   KBM030    ;NO - CHECK NEXT COLUMN 
       MVI  E,NUMCOL  ;YES - RESET COLUMN POINTERS
       MVI  L,KBBUFL+NUMCOL 
KBM030 EQU  $ 
       MOV  A,M       ;GET PREVIOUS STATE 
       MOV  B,A 
       STA  IOKBCL    ;SET HYSTERESIS 
       LDAX D         ;GET NEW STATE
       XRA  B         ;ANY CHANGES? 
       JNZ  KBM100    ;YES - PROCESS NEW STATE
       DCX  H         ;NO - DECREMENT TO NEXT COL 
       DCR  E         ;ALL COLUMNS DONE?
       JP   KBM040    ;NO - EXIT
       MVI  E,NUMCOL  ;YES - RESET COLUMN POINTERS
       MVI  L,KBBUFL+NUMCOL 
KBM040 EQU  $ 
       SHLD KBBFPT    ;SAVE COLUMN POINTERS 
       XCHG 
       SHLD KEYCOL
       EI             ;RE-ENABLE INTERRUPTS 
       RET            ;RETURN 
 
; 
;  KEYBOARD STATE CHANGE - ADD CHANGE TO BUFFER 
; 
KBM100 EQU  $ 
       SHLD KBBFPT    ;SAVE COLUMN POINTERS 
       XCHG 
       SHLD KEYCOL
       MOV  C,L       ;PUT COLUMN NUMBER IN C 
       LHLD KBPTPT    ;GET PUT POINTER
       MOV  M,C       ;STORE COLUMN NUMBER
       DCX  H         ;DECREMENT TO NEXT POSITION 
       XRA  B         ;RESTORE NEW STATE
       MOV  M,A       ;STORE NEW STATE IN BUFFER
       MOV  B,A       ;SAVE CHANGED BITS IN B-REG 
       MVI  A,KEYBFL
       CMP  L         ;REACHED END OF BUFFER? 
       JNZ  KBM110    ;NO - CHECK FOR BUFFER FULL 
       MVI  L,KEYBFL+KEYBLN  ;YES - RESET POINTER 
KBM110 EQU  $ 
       DCX  H         ;DECREMENT TO NEXT POSITION 
       LDA  KBGTPT
       CMP  L         ;BUFFER FULL? 
       JZ   KBM120    ;YES - DON'T UPDATE POINTERS
       SHLD KBPTPT    ;NO - UPDATE POINTERS 
       XCHG 
       MOV  M,B       ;UPDATE STATE TABLE 
KBM120 EQU  $ 
       EI             ;RE-ENABLE INTERRUPTS 
       RET            ;RETURN 
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  GTKYNM - GET KEY NUMBER
; 
;      ENTRY:  B = KEY BIT IN COLUMN
;              E = COLUMN NUMBER
; 
;      EXIT :  A = E = KEY NUMBER 
;              L = KBKNSV-KBSTOR
; 
GTKYNM EQU  $ 
       MOV  A,E       ;MULTIPLY COLUMN NUMBER 
       RLC              ;BY 8 
       RLC
       RLC
       MOV  E,A       ;PUT PRODUCT INTO E 
       DCR  E         ;ADJUST TO INITIAL VALUE
       MOV  A,B       ;PUT KEY BIT IN A 
; 
;  ADD IN BIT NUMBER
; 
GTN010 EQU  $ 
       INR  E         ;INCREMENT COUNT
       RRC            ;BIT FOUND? 
       JNC  GTN010    ;NO - CONTINUE COUNTING 
       MOV  A,E       ;YES - PUT RESULT IN A
       LXI  H,KBKNSV  ;SET H,L TO REPEATING KEY # 
       RET            ;RETURN 
 
;********************************************** 
; SETRPT - SET REPEAT TIMER FOR FUNCTION KEYS * 
;********************************************** 
;  ENTRY:  A = KEYBOARD CHARACTER 
; 
;  EXIT :  KBTIMR = DELAY FOR REPEAT
;          B,H,L DESTROYED
; 
SETRPT EQU  $ 
       LXI  H,KBTIMR  ;SET H,L TO REPEAT TIMER
       MVI  B,LNGDLY  ;SET B FOR LONG DELAY TIME
       CPI  ENTRCD    ;ENTER KEY? 
       JZ   STR020    ;YES - SET FOR LONG DELAY 
       CPI  EXFNLM    ;EXTERNAL FUNCTION? 
       RM             ;YES - SET NO REPEAT
       MOV  M,B       ;SET FOR LONG START DELAY 
       CPI  301Q      ;CURSOR CONTROL?
       RM             ;NO - RETURN LONG DELAY 
       CPI  305Q
       JM   STR010    ;YES - SET SHORT DELAY
       CPI  323Q      ;ROLL UP OR ROLL DOWN?
       RM             ;NO - RETURN LONG DELAY 
       CPI  325Q
       RP             ;NO - RETURN LONG DELAY 
STR010 EQU  $         ;YES - SET FOR SHORT REPEAT 
       MVI  B,SRTDLY    ;START DELAY
STR020 EQU  $ 
       MOV  M,B       ;SET REPEAT TIMER 
       RET            ;RETURN 
 
;******************************************** 
; KBCTL - PERFORM KEYBOARD CONTROL FUNCTION * 
;******************************************** 
; 
;  ENTRY:  A = CONTROL CODE 
; 
;  EXIT :  DETERMINED BY INDIVIDUAL CONTROL 
;            ROUTINES 
;          GENERALLY D-L REGISTERS ARE SAVED
;            AND A-C DESTROYED
; 
KBCTL  EQU  $ 
       CPI  KBCTLM+1  ;CONTROL CODE WITHIN RANGE? 
       RNC            ;NO - EXIT IMMEDIATELY
       PUSH H         ;YES - SAVE THE WORKING 
       PUSH D           ;REGISTERS
       ADD  A         ;DOUBLE THE PARAMETER VALUE 
       MOV  E,A       ;COMPUTE CONTROL VECTOR 
       MVI  D,0         ;LOCATION 
       LXI  H,KBCTAB-2
       DAD  D 
       MOV  E,M       ;FETCH THE CONTROL VECTOR 
       INX  H 
       MOV  H,M 
       MOV  L,E 
       POP  D         ;RECALL D AND E 
       PCHL           ;GO TO CONTROL ROUTINE
; 
;   CONTROL VECTORS 
; 
KBCTAB EQU  $ 
       DW   LOKKBD    ;1 - LOCK KEYBOARD
       DW   UNLKBD    ;2 - UNLOCK KEYBOARD
       DW   RPTKEY    ;3 - REPEAT LAST KEY HIT
       DW   STBLMD    ;4 - SET PERMANENT BLOCK MOD
       DW   STRTST    ;5 - SELF-TEST START
       DW   ENDTST    ;6 - SELF-TEST END
       DW   RSETKB    ;7 - RESET KEYBOARD 
       DW   CKIOKY    ;8 - CHECK FOR I/O KEY
       DW   STPRPT    ;9 - STOP KEY REPEAT
       DW   CKBRKY    ;10 - CHECK FOR BREAK KEY 
;******************************** 
; UNSUPPORTED CONTROL FUNCTIONS * 
;******************************** 
;      DFAD SWCHAR    11 - SWITCH CHARACTER SET 
;      DFAD SETFRN    12 - UPDATE FOREIGN MODE
;      DFAD STCHST    13 - SET FOREIGN MODE OUTPUT
;      DFAD FRNMD1    14 - SET FOREIGN MODE 1 
;      DFAD FRNMD2    15 - SET FOREIGN MODE 2 
; 
ZSTRTS EQU  5         ;SELF-TEST START CONTROL
KBCTLM EQU  10        ;KEYBOARD CONTROL LIMIT 
 
; 
;  LOKKBD - LOCK THE KEYBOARD 
; 
LOKKBD EQU  $ 
       XRA  A         ;CLEAR THE REPEAT TIMER 
       STA  KBTIMR
       LDA  KBFLGS
       ANI  377Q-RPTKY  ;CLEAR REPEAT KEY FLAG
       ORI  KBLOCK        ;AND SET LOCKED FLAG
       STA  KBFLGS
; 
KBCTX1 EQU  $ 
       POP  H         ;RESTORE H AND L
       RET            ;RETURN 
; 
;  UNLKBD - UNLOCK KEYBOARD 
; 
UNLKBD EQU  $ 
       MVI  A,377Q-KBLOCK  ;CLEAR KEYBOARD
       LXI  H,KBFLGS  ;CLEAR KEYBOARD FLAG
       ANA  M 
       MOV  M,A 
       POP  H         ;RESTORE H AND L
       RET            ;RETURN 
; 
;  STBLMD - SET PERMANENT BLOCK MODE
; 
STBLMD EQU  $ 
       LXI  H,KBFLGS  ;SET PERMANENT BLOCK MODE 
       MOV  A,M         ;FLAG 
       ORI  PERMBM
       MOV  M,A 
       LXI  H,MDFLG2  ;SET BLOCK MODE FLAG
       MOV  A,M 
       ORI  BLKMDE
       MOV  M,A 
       MVI  A,HNDSHK+DC2SND 
       STA  KBJ1MS    ;SET JUMPER INHIBIT MASK
       MVI  L,KBJMPR-CMSTOR 
       ORA  M         ;SET JUMPERS TO INHIBIT 
       MOV  M,A         ;ALL TOP LEVEL HANDSHAKE
       POP  H         ;RESTORE H AND L
       RET            ;RETURN 
 
; 
;  RPTKEY - REPEAT LAST KEY HIT 
; 
RPTKEY EQU  $ 
       MVI  A,RPTKY   ;SET REPEAT KEY FLAG
       LXI  H,KBFLGS  ;SET KEYBOARD FLAG
       ORA  M 
       MOV  M,A 
       POP  H         ;RESTORE H AND L
       RET            ;RETURN 
;***************************
; STRTST - SELF-TEST START *
;***************************
STRTST EQU  $ 
       LXI  H,KBLEDS  ;GET CURRENT LED'S STATE
       MOV  A,M 
       CPI  377Q-BELLED  ;ALL LIGHTS ON ALREADY?
       JZ   KBCTX1     ;YES - DON'T CHANGE LED'S
       STA  LEDSAV     ;NO - SAVE CURRENT LED STAT
       MVI  A,377Q-BELLED 
       MOV  M,A       ;FORCE ALL LED'S ON 
       STA  IOKBLD
       MVI  L,CMFLGS-CMSTOR 
       MOV  A,M       ;TURN FORCE FULL RESET
       ORI  FRCRST      ;FLAG 
       MOV  M,A 
       POP  H         ;RESTORE H AND L
STRTS1 EQU  $         ;ENABLE RESET KEY 
       MVI  A,RSTON 
       STA  IOKBCO
       RET            ;RETURN 
 
;*************************
; ENDTST - END SELF-TEST *
;*************************
ENDTS0 EQU  $         ;CHECK FOR SOFT RESET IN
       LXI  H,KBLEDS    ;PROGRESS 
       MOV  A,M       ;GET CURRENT LED SETTINGS 
       CPI  377Q-BELLED  ;SOFT RESET IN PROGRESS? 
       RNZ            ;NO - RETURN
       PUSH H         ;YES - RESET LED'S
ENDTST EQU  $ 
       LXI  H,CMFLGS
       MOV  A,M       ;TURN OFF FORCE FULL RESET
       ANI  377Q-FRCRST  ;FLAG
       MOV  M,A 
       LDA  LEDSAV    ;RESTORE LED STATE
       STA  KBLEDS    ;************************** 
;                     * "KBMON" WILL RESTORE   *
;                     * KEYBOARD LED'S WHEN    *
;                     * TIMER INTERRUTS OCCURS *
;                     **************************
       POP  H         ;RESTORE H AND L
       RET            ;RETURN 
 
;*****************************************
; RSETKB - RESET KEYBOARD FOR SOFT RESET *
;*****************************************
RSETKB EQU  $ 
       CALL INITK0    ;INITIALIZE BUFFER POINTERS 
       LXI  H,KBBUF   ;TRANSFER VALUES FROM "REAL 
       LXI  D,KBBUF2    ;TIME" STATE TABLE TO 
       MVI  C,NUMCOL+1  ;CURRENTLY ACTIVE TABLE 
; 
RSK010 EQU  $ 
       MOV  A,M 
       STAX D 
       INX  H 
       INX  D 
       DCR  C         ;ALL ENTRIES DONE?
       JNZ  RSK010    ;NO - CONTINUE TRANSFER 
; 
;  CLEAR KEYBOARD FLAGS 
; 
       LXI  H,KBFLGS  ;YES - UNLOCK THE KEYBOARD
       MOV  A,M 
       ANI  377Q-KBLOCK-RPTKY 
       MOV  M,A 
       MVI  L,KBLEDS-KBSSTR 
       MOV  A,M       ;TURN OFF RECORD, SELECT AND
       ANI  377Q-RECLED-SELLED-DSFLED 
       MOV  M,A         ;FUNCTIONS LED'S
       MVI  L,BLKFLG-KBSSTR 
       MOV  A,M       ;STOP RECORD, SELECT AND
       ANI  377Q-RECLED-SELLED-DSFLED 
       MOV  M,A         ;FUNCTIONS BLINKING 
       LXI  H,MDFLG1
       MOV  A,M       ;TURN OFF RECORD, SELECT AND
       ANI  377Q-RECORD-SELECT-DSPFNC  ;DISPLAY 
       MOV  M,A         ;FUNCTIONS MODE FLAGS 
       XRA  A 
       STA  INTFLG    ;CLEAR INTERRUPT FLAG 
       STA  KBTIMR    ;STOP KEY REPEAT
       LXI  H,CMFLGS  ;CLEAR THE REMOTE SET FLAG
       MOV  A,M         ;TO FORCE DATA COMM RESET 
       ANI  377Q-REMSET 
       MOV  M,A 
       CALL BELL      ;SOUND THE BELL 
       JMP  STRTST    ;TURN ON ALL LED'S AND EXIT 
 
;*********************************************
; CKIOKY - CHECK FOR I/O CONTROL (GREEN) KEY *
;*********************************************
; 
;  EXIT :  Z - I/O CONTROL KEY NOT PRESSED
;          NZ - I/O CONTROL KEY PRESSED 
;          A-E DESTROYED
; 
CKIOKY EQU  $ 
       LDA  KBCHAR    ;GET CURRENT KEYBOARD CHAR
       MOV  H,A       ;SAVE CHARACTER IN H-REGISTE
;                       (CHARACTER RESTORED IN H
;                        ON RETURN FROM "CKBRK1") 
       CALL CKBRK1    ;CLEAR KEYBOARD BUFFER
       LDA  IOKYRW    ;NO - GET I/O CNTRL KEY ROW 
       ANI  IOKYCL    ;I/O CONTROL KEY DOWN?
       JZ   KBCTX1    ;NO - EXIT
       MVI  A,LNGDLY  ;YES - RESTORE REPEAT TIMER 
       STA  KBTIMR
       MOV  A,H       ;RESTORE ORIGINAL KEYBOARD
       LXI  H,KBCHAR    ;CHARACTER
       MOV  M,A 
       CPI  TEST      ;CURRENT KEY = TEST?
       LDA  IOKYRW      ;(SET FOR ALTERNATE SELF- 
       LXI  D,ENTCOL*256+ENTRCD  ;TEST CHECK) 
       JZ   CKI010    ;YES - CHECK FOR ENTER KEY
       LDA  TSTROW    ;NO - CHECK FOR TEST KEY
       LXI  D,TSTCOL*256+TEST 
; 
;  CHECK FOR ALTERNATING SELF-TEST
; 
CKI010 EQU  $ 
       CMA            ;INVERT KEYBOARD ROW SETTING
       ANA  D         ;OTHER SELF-TEST KEY DOWN?
       JNZ  KBCTX1    ;NO - EXIT
       MOV  M,E       ;YES - SET ALTERNATE TEST KE
       ORA  E         ;SET Z FALSE
       POP  H         ;RESTORE H AND L
       RET            ;RETURN Z FALSE 
;***************************
; STPRPT - STOP KEY REPEAT *
;***************************
STPRPT EQU  $ 
       XRA  A         ;ZERO REPEAT TIMER
       STA  KBTIMR
       POP  H         ;RESTORE H AND L
       RET            ;RETURN 
 
;***************************
; CHECK FOR BREAK KEY DOWN *
;***************************
; 
;  EXIT :  Z - BREAK KEY NOT DOWN 
;          NZ - BREAK KEY DOWN
; 
CKBRKY EQU  $ 
       POP  H         ;POP OFF H AND L
       XRA  A         ;CHECK HARDWARE LATCHES 
       STA  IOKBCL      ;FOR BREAK KEY DOWN 
       LDA  IOKB+BRKYRN 
       ANI  BRKCOL    ;BREAK KEY DOWN?
       RZ             ;NO - RETURN FAIL 
CKBRK1 EQU  $         ;YES - CLEAR KEYBOARD BUFFER
CKB010 EQU  $ 
       CALL GTKEY     ;ANY KEY HIT? 
       INR  A           ;(ADJUST FOR LOCKED KEYBD)
       JNZ  CKB010    ;YES - CONTINUE UNTIL NONE
NZEXIT EQU  $         ;NON-ZERO EXIT
       INR  A         ;NO - FORCE Z-FALSE 
       RET            ;RETURN NZ
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  SETMD1 - SET MODE 1 FLAGS
; 
;      ENTRY:  A = FLAG BIT TO BE SET 
;              B = 377B, BLINK ASSOCIATED LED 
;                = 0, DON'T BLINK LED 
; 
;      EXIT :  A,C DESTROYED
;              ASSOCIATED LED, IF ANY, IS SET ON
; 
SETMD1 EQU  $ 
       PUSH H         ;SAVE H,L 
       MOV  C,A       ;SAVE BIT TO BE SET 
       LXI  H,MDFLG1
       ORA  M         ;SET THE FLAG 
       MOV  M,A       ;STORE UPDATED FLAGS
       CALL FNDLED    ;LOCATE ASSOCIATED LED
       MOV  C,A       ;SAVE LED BIT 
       DI             ;DISABLE INTERRUPTS 
       ORA  M         ;ADD BIT TO LED CONTROL WORD
       MOV  M,A       ;STORE NEW CONTROL WORD 
       EI             ;RE-ENABLE INTERRUPTS 
       MOV  A,C       ;RECALL LED BIT 
       LXI  H,BLKFLG  ;SET H,L TO BLINK FLAG
       INR  B         ;SET LED BLINKING?
       JZ   ST1010    ;YES - SET BLINK BIT
       CMA            ;NO - SET A TO CLEAR MASK 
       ANA  M         ;CLEAR BLINK FLAG 
       JMP  ST1020    ;GO UPDATE BLINK FLAG 
; 
ST1010 EQU  $ 
       ORA  M         ;SET BLINK BIT
ST1020 EQU  $ 
       MOV  M,A 
       DI             ;DISABLE INTERRUPTS 
       CALL ENDTS0    ;CHECK SOFT RESET IN PROGRES
       ORA  M         ;TURN ALL BLINKING LED'S ON 
       MOV  M,A 
       EI             ;RE-ENABLE INTERRUPTS 
       POP  H         ;RESTORE H,L
       RET            ;RETURN 
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  CLRMD1 - CLEAR MODE 1 FLAG 
; 
;      ENTRY:  A = FLAG BIT TO BE CLEARED 
; 
;      EXIT :  A,C DESTROYED
;              ASSOCIATED LED, IF ANY, IS SET OFF 
; 
;      INTERRUPT SYSTEM IS DISABLED AND ENABLED 
;        AGAIN
; 
CLRMD1 EQU  $ 
       PUSH H         ;SAVE H,L 
       MOV  C,A       ;SAVE BIT TO BE CLEARED 
       LXI  H,MDFLG1
       CMA            ;COMPLEMENT TO GET CLEAR MAS
       ANA  M         ;CLEAR THE BIT
       MOV  M,A 
       CALL FNDLED    ;LOCATE ASSOCIATED LED
       CMA            ;COMPLEMENT TO GET CLEAR MAS
       MOV  C,A       ;SAVE CLEAR PATTERN 
       LXI  H,BLKFLG  ;CLEAR BLINK FLAG IN CASE 
       ANA  M           ;LED WAS BLINKING 
       MOV  M,A 
       DI             ;DISABLE INTERRUPTS 
       CALL ENDTS0    ;CHECK SOFT RESET IN PROGRES
       ANA  C         ;CLEAR LED BIT
       MOV  M,A 
       EI             ;ENABLE INTERRUPTS
       POP  H         ;RESTORE H,L
       RET            ;RETURN 
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  FNDLED - FIND LED BIT ASSOCIATED WITH
;    MODE 1 FLAGS 
; 
;      ENTRY:  C = MODE 1 FLAG BIT TO BE USED 
; 
;      EXIT :  A = ASSOCIATED LED BIT 
; 
;              H,L = KBLEDS 
; 
FNDLED EQU  $ 
       MOV  A,C       ;PUT BIT INTO A 
       LXI  H,LEDTAB-1  ;SET INITIAL TABLE ADDRESS
; 
FLD010 EQU  $ 
       INX  H         ;ADVANCE TO NEXT TABLE ENTRY
       RRC            ;BIT FOUND? 
       JNC  FLD010    ;NO - GO TO NEXT ENTRY
       MOV  A,M       ;YES - GET TABLE ENTRY
       LXI  H,KBLEDS  ;SET H,L TO LED CONTROL WORD
       RET            ;RETURN 
; 
;  LED ASSOCIATION TABLE
; 
LEDTAB EQU  $         ;BIT  FUNCTION
       DB   DSFLED     ;0 - DISPLAY FUNCTIONS 
       DB   ICHLED     ;1 - INSERT CHARACTER
       DB   MLKLED     ;2 - MEMORY LOCK 
       DB   0          ;3 - FORMAT MODE 
       DB   EDTLED     ;4 - EDIT MODE 
       DB   SELLED     ;5 - SELECT MODE 
       DB   RECLED     ;6 - RECORD MODE 
       DB   0          ;7 - UNUSED
 
; 
; * * * * * * * * * * * * * * * * * * * * * * * * 
; 
;  BELL - SOUND THE KEYBOARD BELL 
; 
;      ENTRY:  DON'T CARE 
; 
;      EXIT :  A DESTROYED
;              Z FALSE
; 
BELL   EQU  $ 
       LDA  KBLEDS    ;GET CURRENT LED SETTINGS 
       ORI  BELLED    ;ADD CONTROL TO SOUND BELL
       STA  IOKBLD    ;SOUND THE BELL 
       RET            ;RETURN 
;******************************** 
; SETXMT - TURN ON TRANSMIT LED * 
;******************************** 
; 
;  EXIT :  Z = TRUE 
; 
SETXMT EQU  $ 
       MVI  A,XMTLED  ;SET TRANSMIT LED BIT 
       LXI  H,KBLEDS  ;SET H,L TO LED STATE WORD
       ORA  M         ;ADD TRANSMIT LED BIT 
       MOV  M,A       ;UPDATE LED STATE 
       CMP  A         ;SET Z TRUE 
       RET            ;RETURN 
;*********************************
; CLRXMT - TURN OFF TRANSMIT LED *
;*********************************
CLRXMT EQU  $ 
       LXI  H,KBLEDS
       MOV  A,M       ;GET CURRENT LED SETTINGS 
       CPI  377Q-BELLED  ;SET FOR TEST MODE?
       RZ             ;YES - RETURN 
       ANI  377Q-XMTLED  ;NO - CLEAR TRANSMIT 
       MOV  M,A         ;LED
       RET            ;RETURN 
 
;***********************************************
; STJMPR - SET KEYBOARD JUMPER ESCAPE SEQUENCE *
;***********************************************
STJMPR EQU  $ 
       LHLD KBJMP2    ;INITIALIZE PARAMETER VALUES
       SHLD PARM2 
       LDA  KBJMP3
       STA  PARM3 
       LXI  H,STJTAB  ;SET ESC SEQ RANGE TABLE ADD
;********************************************** 
; SET RANGE TABLE AND CLEAR INPUT ACCUMULATOR * 
;********************************************** 
STJMP1 EQU  $ 
       MVI  A,DECRDX  ;SET INPUT RADIX AS DECIMAL 
       STA  RADIX 
       SHLD RNGTA     ;SET NEW RANGE TABLE VALUE
STJMP2 EQU  $ 
       LXI  H,0       ;CLEAR INPUT ACCUMULATOR
       SHLD IODATA
STJMP3 EQU  $         ;CONTINUE ESCAPE SEQUENCE 
       MVI  A,2       ;SET ESC SEQ FLAG TO INDICAT
       STA  ESCFLG      ;ESC SEQ IN PROGRESS
       RET            ;RETURN TO WAIT LOOP
 
;*************************************
; PARAMETER RECEIVED - SET ITS VALUE *
;*************************************
; 
;  ENTRY:  B = 1
;          C = INPUT CHARACTER
;          H = BASEH
; 
STJ100 EQU  $         ;ENTRY FOR INPUTS P-Z 
       DCR  B         ;SET ADJUSTMENT FACTOR
STJ110 EQU  $         ;ENTRY FOR INPUTS J-N 
       DCR  B         ;SET ADJUSTMENT FACTOR
STJ120 EQU  $         ;ENTRY FOR INPUTS A-H 
       MOV  A,C       ;PUT INPUT CHAR IN A-REG
       ANI  377Q-40Q  ;FORCE TO UPPER CASE VALUE
       SUI  A+1       ;SET TO RANGE 0-23
       ADD  B         ;ADD IN ADJUSTMENT FOR
;                       MISSING LETTERS (I, O)
       CALL STPARM    ;SET THE PARAMETER
       MOV  A,C       ;RECALL INPUT CHARACTER 
       ANI  40Q       ;IS IT UPPER CASE?
       JNZ  STJMP2    ;NO - CLEAR INPUT ACCUMULATO
;                       AND CONTINUE ESCAPE SEQ 
; 
       LXI  D,PARM1   ;NO - SET KEYBOARD STRAPS 
       LXI  H,KBJMPR    ;(D,E=SOURCE; H,L=DEST) 
       LDA  KBJ1MS    ;GET INHIBIT MASK 
       CALL STBITS    ;SET JUMPER 1 VALUES
; 
       LDA  DCJMS2    ;GET JUMPER 2 INHIBIT MASK
       CALL STBITS    ;SET JUMPER 2 VALUES
; 
       LDA  DCJMSK    ;GET JUMPER 3 INHIBIT MASK
       JMP  STBITS    ;SET JUMPER 3 VALUES AND EXI
 
;*****************************************
; SET JUMPER ESCAPE SEQUENCE RANGE TABLE *
;*****************************************
STJTAB EQU  $-3 
       DB   101Q,110Q  ;UPPER CASE <A> - <H>
       DW   STJ120+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   112Q,116Q  ;UPPER CASE <J> - <N>
       DW   STJ110+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   120Q,132Q  ;UPPER CASE <P> - <Z>
       DW   STJ100+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   141Q,150Q  ;LOWER CASE <A> - <H>
       DW   STJ120+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   152Q,156Q  ;LOWER CASE <J> - <N>
       DW   STJ110+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   160Q,172Q  ;LOWER CASE <P> - <Z>
       DW   STJ100+B15  ;SET APPROPRIATE PARAMETER
;*************************************************
; STKTAB - SET LATCHING KEYS ESC SEQ RANGE TABLE *
;*************************************************
STKTAB EQU  $-3 
       DB   40Q,40Q   ;SPACE
       DW   STJMP3+B15  ;IGNORE 
; 
       DB   60Q,61Q   ;NUMBERS <0> AND <1>
       DW   ZDCNUM+B15  ;ACCUMULATE INPUT VALUE 
; 
       DB   101Q,103Q  ;UPPER CASE <A> - <C>
       DW   STK020+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   122Q,122Q  ;UPPER CASE <R>
       DW   STK010+B15  ;SET REMOTE FLAG
; 
       DB   141Q,143Q  ;LOWER CASE <A> - <C>
       DW   STK020+B15  ;SET APPROPRIATE PARAMETER
; 
       DB   162Q,162Q  ;LOWER CASE <R>
       DW   STK010+B15  ;SET REMOTE FLAG
; 
       DB   0Q,177Q   ;ALL OTHER CODES
       DW   ZESCND+B15  ;ABORT ESCAPE SEQUENCE
 
;*********************************************
; STLKYS - SET LATCHING KEYS ESCAPE SEQUENCE *
;*********************************************
STLKYS EQU  $ 
       LDA  MDFLG2    ;INITIALIZE PARAMETER VALUE 
       STA  PARM1 
       LXI  H,STKTAB  ;PUT RANGE TABLE ADDR IN H,L
       JMP  STJMP1    ;EXIT TO WAIT LOOP
;**************************************** 
; REMOTE FLAG PARAMETER - SET BIT VALUE * 
;**************************************** 
STK010 EQU  $ 
       MVI  A,REMBIT  ;PUT BIT NUMBER IN A-REGISTE
       JMP  STK050    ;SET THE BIT VALUE
;************************************************ 
; INPUT PARAMETER RECEIVED - SET PARAMETER MASK * 
;************************************************ 
STK020 EQU  $ 
       LXI  H,PARM1   ;SET H,L TO PARAMETER ADDRES
       MVI  A,A+2     ;COMPUTE BIT INDEX: 
       SUB  C           ;<A>=2, <B>=1, <C>=0
; 
STK050 EQU  $ 
       CALL STPAR1    ;SET PARAMETER MASK 
       MOV  A,C       ;RECALL INPUT CHARACTER 
       ANI  40Q       ;UPPER CASE CHARACTER?
       JNZ  STJMP2    ;NO - CLEAR ACCUMULATOR AND 
;                       CONTINUE ESCAPE SEQUENCE
       LXI  D,PARM1   ;YES - SET LATCHING KEYS
       LXI  H,MDFLG2    ;(D,E=SOURCE; H,L=DEST) 
       LDAX D         ;GET INPUT PARAMETER
       LDA  KBFLGS    ;EXTRACT INHIBIT MASK 
       ANI  PERMBM      ;(PERMANENT BLOCK MODE) 
;                     FALL INTO EVALUATION ROUTINE
;                       AND EXIT
 
;*********************************************
; STBITS - SET FLAG BITS FROM PARAMETER MASK *
;*********************************************
; 
;  ENTRY:  A = CHANGE INHIBIT MASK
;            BIT SET TO 1 TO INHIBIT CHANGES
;          D,E = INPUT PARAMETER
;          H,L = WORD TO BE SET 
; 
;  EXIT :  A,B DESTROYED
;          (H,L) UPDATED
; 
STBITS EQU  $ 
       CMA            ;INVERT INHIBIT MASK
       MOV  B,A       ;SAVE INHIBIT MASK
       LDAX D         ;GET PARAMETER VALUE
       XRA  M         ;EXTRACT CHANGES TO SETTINGS
       ANA  B         ;MASK OUT INHIBITED CHANGES 
       XRA  M         ;ALTER APPROPRIATE BITS 
       MOV  M,A       ;UPDATE CURRENT SETTINGS
       DCX  D         ;INCREMENT TO NEXT VALUES 
       DCX  H 
       RET            ;RETURN 
 
;****************************** 
; STPARM - SET PARAMETER MASK * 
;****************************** 
; 
;  ENTRY:  A = BIT/WORD INDEX 
;          H = BASEH
;          IODATA = PARAMETER VALUE 
; 
;  EXIT :  PARAMETER WORD MASK SET
;          A,B,L DESTROYED
; 
STPARM EQU  $ 
       MOV  B,A       ;SAVE INDEX IN B-REGISTER 
       ANI  370Q      ;MASK OUT 3 LEASE SIGNIFICAN
       RRC              ;BITS AND DIVIDE BY 8 TO
       RRC              ;DETERMINE WORD INDEX (0-2
       RRC
       CMA            ;SET TO NEGATIVE INDEX
       INR  A 
       ADI  PARM1-CMSTOR  ;COMPUTE JUMPER WORD ADD
       MOV  L,A       ;PUT LSB INTO L (H = BASEH) 
;*******************************
; DETERMINE BIT TO BE MODIFIED *
;*******************************
       MOV  A,B       ;RECALL CHARACTER INDEX 
STPAR1 EQU  $ 
       ANI  7Q        ;EXTRACT BIT NUMBER 
       MOV  B,A 
       MVI  A,200Q    ;SET INITIAL BIT LOCATION 
; 
STP010 EQU  $ 
       RLC            ;ROTATE ONE BIT LEFT
       DCR  B         ;BIT POSITION FOUND?
       JP   STP010    ;NO - CONTINUE ROTATING 
       MOV  B,A       ;YES - SAVE BIT MASK IN B 
;************************************************ 
; DETERMINE WHETHER BIT IS TO BE SET OR CLEARED * 
;************************************************ 
       XCHG           ;SAVE WORD ADDRESS IN D,E 
       LHLD IODATA    ;GET PARAMETER VALUE
       MOV  A,L 
       ORA  H         ;BIT TO BE SET? 
       XCHG             ;(RESTORE H,L)
       MOV  A,B         ;(RECALL BIT TO MODIFY) 
       JZ   STP020    ;NO - SET PARM BIT TO CLEAR 
       ORA  M         ;YES - ADD BIT TO PARAMETER 
       MOV  M,A       ;SET PARAMETER
       RET            ;RETURN 
 
;*************************
; CLEAR BIT IN PARAMETER *
;*************************
STP020 EQU  $ 
       CMA            ;SET TO CLEAR MASK
       ANA  M         ;CLEAR BIT FROM PARAMETER 
       MOV  M,A       ;SET PARAMETER
       RET            ;RETURN 
 
;****************************************** 
; ALPCHK - CHECK FOR ALPHA TYPE CHARACTER * 
;****************************************** 
ALPCHK EQU  $ 
       CPI  ABLNK     ;IS CHARACTER A BLANK?
       RZ             ;YES - RETURN OK (Z TRUE) 
       ANI  377Q-40Q  ;NO - FORCE TO UPPER CASE 
       CPI  A         ;IS IT ABOVE LETTER A?
       RM             ;NO - RETURN FAIL (Z FALSE) 
       CPI  Z         ;IS IT Z OR ABOVE 
       RP             ;YES - RETURN (Z TRUE IF =) 
       CMP  A         ;NO - SET Z TRUE
       RET            ;RETURN GOOD (Z TRUE) 
;******************************************** 
; NUMCHK - CHECK FOR NUMERIC TYPE CHARACTER * 
;******************************************** 
NUMCHK EQU  $ 
       CPI  ABLNK     ;IS CHARACTER A BLANK?
       RZ             ;YES - RETURN OK (Z TRUE) 
       CPI  PLUS      ;BELOW PLUS?
       RC             ;YES - RETURN FAIL
       CPI  SLANT     ;SLANT CHARACTER? 
       JZ   NZEXIT    ;YES - RETURN FAIL
       CPI  ZERO+9    ;NINE OR BELOW? 
       RP             ;NO - RETURN (Z TRUE IF =)
       CMP  A         ;YES - SET Z TRUE 
       RET            ;RETURN 
       END
