*-----------------------------------------------------------
* Test code for 6850
*
* 6850 Test. Now with interrupts
* Echo whatever is received on RxD back out on TxD
*
* WRM 2022-07-22
*
*-----------------------------------------------------------
*

ACIA1CR   EQU      $FF2001             ; Write
ACIA1SR   EQU      $FF2001             ; Read
ACIA1TR   EQU      $FF2003             ; Write
ACIA1DR   EQU      $FF2003             ; Read

AV1VECT    EQU      $000064

*
* Here's a good description of how interrupts work
* https://clarkson.me.uk/academic/Lecture_notes/aldm8.htm
* ISR routine examples
* http://engr.case.edu/merat_francis/eeap282f97/lectures/26_Interrupts%20&%20Exceptions.pdf
*
         ORG $1000

         MOVE.L    #ISR,AV1VECT        ; Set Autovector for INT 1

         MOVE.B    #$03,ACIA1CR        ; Reset ACIA
         MOVE.B    #$D1,ACIA1CR        ; %1 10 100 01 RxInt enabled
                                       ; TxInt Disabled & RTS high, 8N2, /16
ERROR    MOVE.B    ACIA1SR,D0          ; Get status
         AND.B     #$7C,D0             ; %01111100 mask IRQ, TDRE, RDRF
         BNE       ERROR
         STOP      #$2000              ; Interrupt Mask = 0, wait for interrupt
         NOP
ISR      MOVE.L    D0,-(SP) ; Push
         BTST.B    #0,ACIA1SR          ; RDRF? Set Z if not
         BEQ       ISREND              ; no data
         MOVE.B    ACIA1DR,D0          ; Get the character in RDR
ISR2     BTST.B    #1,ACIA1SR          ; TDRE? Set Z if not
         BEQ       ISR2                ; Loop if Z set
         MOVE.B    D0,ACIA1TR          ; Put the character into TDR
ISREND   MOVE.L    (SP)+,D0 ; Pull
         RTE















