.title SCI_LIB.ASM by YOURNAME HERE! ;*********************************************************** ;* SCI_LIB.ASM ;* SCI Equates and Library Routines ;* Date ;*********************************************************** ;.---------------------------------------------------------. ;| HARDWARE EQUATES | ;`---------------------------------------------------------' REGS = 0x1000 ;Internal Registers Base Address BAUD = REGS+0x2B ;Baud-Rate Control Register SCCR1 = REGS+0x2C ;SCI Control Register 1 SCCR2 = REGS+0x2D ;SCI Control Register 2 SCSR = REGS+0x2E ;SCI Status Register SCDR = REGS+0x2F ;SCI Data Register ;*********************************************************** ;* HEXTOASC - Converts hex byte in A to two ASCII bytes * ;* in accumulator D * ;*********************************************************** ; REQUIRES - HEX INPUT IN ACCUMULATOR A ; RETURNS - ASCII MSB IN A ; - ASCII LSB IN B ; REGS AFFECTED - None HEXTOASC: PSHX ;SAVE X REGISTER PSHA ;SAVE ACC A LDX #HEXTABLE ;POINT TO CONVERSION TABLE TAB ;COPY INPUT TO B LSRB LSRB LSRB LSRB ;HI NIBBLE IN B ABX LDAB ,X ;HI ASCII IN ACC B TBA ;HI ASCII IN ACC A LDX #HEXTABLE PULB ANDB #0x0F ABX LDAB ,X PULX ;RESTORE X & RETURN RTS HEXTABLE: .ASCII '0123456789ABCDEF' ;.---------------------------------------------------------. ;| RxByte - Receives a byte from the terminal via the SCI.| ;| Waits for the character, no echo. | ;`---------------------------------------------------------' ; REQUIRES - Nothing ; RETURNS - Char received in acc A. ; REGS AFFECTED - No other registers affected RxByte: ldaa SCSR ;Check RDRF flag = b5 anda #0x20 ;Discard all but b5 beq RxByte ;If RDRF==0, wait ldaa SCDR ;If RDRF==1, get the char rts ;.---------------------------------------------------------. ;| TxByte - Transmits a byte (char) via the SCI. | ;`---------------------------------------------------------' ; REQUIRES - Acc A contains the char to send ; RETURNS - Nothing ; REGS AFFECTED - None TxByte: tst SCSR ;Check TDRE = b7 bpl TxByte ;Wait if TDRE==0 staa SCDR ;Otherwise send the char rts ;.---------------------------------------------------------. ;| TxString - Transmits a null terminated string via the | ;| SCI. | ;`---------------------------------------------------------' ; REQUIRES - X contains the starting address of the string ; RETURNS - Nothing ; REGS AFF - None TxString: psha pshx TxString0: ldaa 0,X ;Read one character. beq TxString1 ; If NULL, done. bsr TxByte ; Else send it. inx ;Point to next char. bra TxString0 TxString1: pulx pula rts