
        NAM     NUMREG
        
*       Version 1.0     (H-19-terminal version)
*       hjoel 1987-12-18


FLEX    EQU     $CD03


ESC     EQU     $1B
SPACE   EQU     $20
ASCII   EQU     $30
NUMLEN  EQU     11
MEMLEN  EQU     110
EONUM   EQU     $0F
EXHIB   EQU     $80
KEEP    EQU     $C0

        ORG     $0100
        
USTACK  RMB     $20
USP     EQU     *
MEMS    RMB     110

PROMPT  FCC     $0A,$0D,ESC,/p * Hello Services, Inc. * /
        FCC     ESC,/q  /,STRSTP
EXHTXT  FCC     /Memory #/,STRSTP
STOTXT  FCC     /Saving in memory #/,STRSTP
COLON   FCC     /: /,STRSTP





        NAM WRITCHAR
        
***     Writes one character to terminal.
*
*       Version 1.0
*       hjoel 1987-12-04
*
*       Entry:  ASCII-code of character-to-be-
*                 typed in AccA.
*       AccB changed during operation.
*       All other registers unchanged.
***

ACIACR  EQU     $E004           Control-reg-addr of ACIA.
ACIADR  EQU     $E005           Data-reg-addr of ACIA.

        ORG     $BE10
WRITCH  LDB     ACIACR          ACIA ready to receive?
        RORB
        RORB
        BCC     WRITCH
        STA     ACIADR          Char. from AccA to ACIA.
        RTS
        
      

        NAM     WRITESTR
        
***     Writes a string of characters to terminal.
*
*       Version 1.0
*       hjoel 1987-12-10
*
*       Entry:  IX contains beginaddress of consecutive
*         memory-cells containing ASCII-codes of
*         characters to be written.
*       IX and AccA changed during operation.
*       All other registers unchanged.
***

PUTCHR  EQU     $CD18           S. char. system putout-
*                                 subroutine-addr.
STRSTP  EQU     $04             String-end mark.

        ORG     $BE30
GO      JSR     PUTCHR          Writes one char.
WRISTR  LDA     ,X+             ASCII of char into AccA.
        CMPA    #STRSTP         String-end?
        BNE     GO    
        RTS
        

        NAM WRITSTR2
        
*       Version 1.0
*       hjoel 1987-12-21
*
*       Entry:  IX contains adress of first value
*                 to be written.
*               AccB contains value of stopsign.
*       IX and AccA changed during operation.
*       All other registers unchanged.
***

        ORG     $BE50
EOSTR2  RMB     1

GETON   ADDA    #ASCII
        JSR     WRITCH
WRSTR2  STB     EOSTR2
        LDA     ,X+
        CMPA    EOSTR2          Stopsign?        
        BNE     GETON           If not, get one more.
        RTS
        
    
  

        
***     [Sub]routine that senses which key is
*       activated.
*       (This routine was developed for use on
*       Terminal Module 8415.
*       LSNibble = bit 0..3 of PIAA is connected 
*       to keypad columns.
*       MSNibble = bit 4..7 of PIAA is connected 
*       to keypad rows.)
*
*       Version 1.0
*       hjoel 1987-12-18
*
*       Exit:   Coded value of pressed
*               key i AccA.
*       Other registers unchanged.
***

GOORA   EQU     %00000100       Change CRA-flags -> ORA.
DDRORA  EQU     $E020           Adress of PIA DDRA & ORA.
CRA     EQU     $E021           Adress of PIA CRA.
MASKHI  EQU     %11110000       Mask of hi nibble.
MASKLO  EQU     %00001111       DDR-comb. + mask lo nib.

        ORG     $A000
MSNIB   RMB     1

******* Sets bit 0..3 of PIA as outport, & bit 4..7
*       as inport. Writes zeroes to all columns of
*       keypad. Reads rows (=MSN) of keypad. 
*       Stores value of MostSignificantNibble.

WCHKEY  PSHS    B               Save what's in AccB.
        CLRA
        STA     CRA             Choose DataDirect.Reg.
        LDB     #MASKLO            
        STB     DDRORA          Bit0..3 out, bit4..7 in.
        LDA     #GOORA
        STA     CRA             Choose Output Reg.
        CLRA    
        STA     DDRORA          Transmit to bit0..3.
        LDA     DDRORA          Receive from bit4..7.
        ANDA    #MASKHI         Mask MSN - just to make sure.
        STA     MSNIB           Save.
        
******* Sets bit 0..3 of PIAA as inport, & bit 4..7
*       as outport. Writes zeroes to all rows of 
*       keypad. Reads columns (=LSN) of keypad.
*       Combines MSN & LSN to give coded key-value.

        CLRA    
        STA     CRA             Choose DDRA.
        COMB
        STB     DDRORA          Bit0..3 in, bit4..7 out.
        LDA     #GOORA
        STA     CRA             Choose ORA.
        CLRA
        STA     DDRORA          Write to 4..7.
        LDA     DDRORA          Read from 0..3.
        ANDA    #MASKLO         Mask LSNibble.
        ADDA    MSNIB           Combine MSN & LSN.
        PULS    B               Restore AccB.
        RTS
        
      

***     [Sub]routine that makes a bounce-free
*       check that no keys are activated
*       by scanning keypad or keyboard #MANY
*       times in succession.
*
*       Version 1.0
*       hjoel 1987-12-21
*
*       Exit:   $FF in AccA.
***
                

ALLUP   EQU     $FF             Keypad-value when
*                               all keys are up.

        ORG     $A040
NOKEY   LDB     #MANY
SPINN   JSR     WCHKEY
        CMPA    #ALLUP
        BNE     NOKEY 
        DECB
        BNE     SPINN
        RTS        
    
  


***     [Sub]routine that does its best to
*       circumvent contact-bouncing problems
*       on keypad or keyboard thus:
*       Gets key-value, which is compared #MANY
*       times with successive key-scans.        
*       Utilizes subroutine WCHKEY.
*
*       Version 1.0
*       hjoel 1987-12-18
*
*       Exit:   Bounce-liberated coded key-value
*                 in AccA.
***


MANY    EQU     $A0             No. of key-scan loops.

        ORG     $A050
CHECK   RMB     1               S