;Name:  Derek Marston and Pete Susi
;Date:   3/05/03
;Desc:  This program will send a byte serially on the TxD pin
;       and receive the same byte on the RxD pin that we connect
;       together

RAM             EQU     800h;
FLASH           EQU     8000h;
StatusReg       EQU     00C4h;
DataReg         EQU     00C7h;
ControlReg1     EQU     00C2h;
ControlReg2     EQU     00C3h;
SCIvector       EQU     0FFD6h;
PortA           EQU     0000h;
DirA            EQU     0002h;

;******************************************************

     org        FLASH

main:
     ldaa #0FFh;
     staa DirA;
     staa PortA;
     bsr        ConfigPort;
     ldaa       #0AAh;
     
     cli                        ; ENABLE the interrupts (Doofus)

loop:
     bsr        TransmitA;
     bra        loop;


;******************************************************
;Name:          ConfigPort
;Input:         None
;Output:        None
;Destroys:      A
;Description:   Configures port for:
;               Asyncronous serial data
;               8 bit data, no parity, 1 stop bit
;               enable transmitter and receiever

ConfigPort:
     ldaa       #00100000q      ; no loopback
     staa       ControlReg1;
     
; THESE OPERATE NORMALLY when bit 7 is 0!  otherwise in loopback mode

     ldaa       #00101100q      ; enable transmitter and receiver (and RIE)
     staa       ControlReg2

     rts;

;******************************************************
;Name:          TransmitA
;Input:         A = the byte to transmit
;Output:        None
;Destroys:      X
;Description:   Wait until the transmitter is ready (wait until the
;		TDRE bit in the Status Register is 1), then
;		write the contents of A to the Data register.
TransmitA:
      ldx       #StatusReg      ; get status flags
      ldab       StatusReg
      andb       #10000000q     ; Check for ready
      beq        TransmitA      ; Wait until ready

      staa      DataReg
      rts;
      
      
;******************************************************
;Name ReceiveInterrupt
;Input: none
;Output: none
;Destroys: A
;Desc: shows on PortA that a byte has been recieved

ReceiveInterrupt:
    ldaa #00h;
    staa PortA;
    bra  ReceiveInterrupt       ; loop and hold


;******************************************************
;Name:		InstallInterruptVector
;  NOT A ROUTINE
;
;InstallInterruptVector:

        org SCIvector           ; address for jump vec: FFD6h

SCIVec:  DW      ReceiveInterrupt

;******************************************************
