;====================================================================== ; Interrupt handlers ;=================== ; ; Control program for Morrow Terminal ; Copyright 1984 ; Morrow Designs, Inc. ; San Leandro, Ca. ; ; Written by David Block and Jim Kearney (September 1983) ; ; ;---------------------------------------------------------------------- ; Irq occurs when the keyboard wants to send a char to the processor ;------------------------------------------------------------------- ; FTCHKEY PLA ; fix so RTI returns properly TAX INX TXA PHA PHP IRQVEC PHA TYA ; else PHA ; save registers TXA PHA JSR GETKEY ; get key from keyboard LDY LOCKMD ; see if keyboard locked BMI IRQRET ; if (keyboard locked) then return JSR KEYINS ; else, insert character key buffer IRQRET PLA TAX ; restore registers PLA TAY PLA ; and return RTI ;---------------------------------------------------------------------- ; Ok, we've got a character interrupt from the USART. ;---------------------------------------------------- ; NMIRET LDA S1DATA ; clear NMI, and throw away the character PLA RTI NMIVEC SEI ; disable interrupts PHA LDA NMIOK ; see if NMI is enabled CMP #$A5 ; must be A5 to handle interrupts BNE NMIRET TYA ; save other registers PHA TXA PHA LDA S1DATA ; GET A CHARACTER FROM USART AND #%01111111 ; ignore the eighth bit CMP #$0 ; don't put nulls in buffer BEQ NOINS JSR ININS ; put in incoming character buffer if room exists NOINS PLA TAX PLA TAY PLA RTI ;---------------------------------------------------------------------- ; get a character from the kbrd and returns with character in A reg ;------------------------------------------------------------------ ; GETKEY LDX #0 STX PARTIAL ; clear input assembly area LDX #3 JSR KDLY ; wait 30 micro seconds LDY #8 ; set to receive 8 data bits from kbrd NXTBIT LDA #1 ORA BDREG ; must not change other bits in baud register STA BAUD ; send request data to KBRD LDX #21 JSR KDLY ; wait 210 microseconds LDA BAUD AND #%10000000 ; get kbrd data bit ORA PARTIAL ; add in other bits STA PARTIAL ; save the bit(s) we have so far LDA BDREG STA BAUD ; clear request data DEY BEQ GOTCHAR ; if 0, then we have 8 bits, so go LDA PARTIAL ; else, set up partial for getting next bit added to it LSR A STA PARTIAL ; and restore partial LDX #10 JSR KDLY ; wait 100 micro secs JMP NXTBIT ; then, go get the next bit GOTCHAR LDX #10 JSR KDLY LDA PARTIAL ; get the character we rcv'd RTS ;---------------------------------------------------------------------- ; Keyboard Delay ;--------------- ; waits for a number of micro seconds, as specified in X REG ; the delay is in 10.3 micro second increments ; KDLY DEX NOP NOP NOP NOP BNE KD1 RTS KD1 NOP JMP KDLY ;---------------------------------------------------------------------- ; inins - puts the character in the A reg into the input buffer if there ; is any room left for it. ; ININS TAX ; save the character LDY #0 LDA (INEP),Y ; get next character CMP #$FF BNE INFULL ; if not FF, then the buffer is full TXA ; else, put the char into buffer STA (INEP),Y CLC ; adjust end of pointer LDA #1 ADC INEP STA INEP LDA #0 ADC INEP+1 CMP #4 BNE INDONE LDA #2 INDONE STA INEP+1 RTS INFULL LDA #$FF STA BUFFULL RTS ; keyins - puts the char in A reg into the keyboard input buffer KEYINS PHA ; save the character LDA KEYSP ; get pointer to start of keyboard buffer TAX CLC ; calculate next location ADC #1 AND #15 TAY CPY KEYEP ; see if at end ( BUFFER FULL ) BEQ KEYOVF ; yes, ignore key PLA ; get character back STY KEYSP ; update start of buffer STA KEYBUF,X ; Put char in keychar buffer RTS KEYOVF PLA ; restore stack RTS PAGE END