;
; This demo uses an 8088 in the min mode to control two 8251a (Programmable
; Communication Interface). 
; The 8251a is operated in the full duplex mode; so both the receiver
; and the transmitter are enabled at the same time. The program initializes
; the 8251a's and then write a character to Left. Left will start 
; transmitting the character to Right serially. While Left is still
; transmitting the CPU write a character to Right to be transmitted to Left.
; The CPU will be idle while the 8251a's are transmitting the characters.
; When the character is received, the receiver will assert the RXRDY line 
; which will interrupt the CPU. The CPU will then read the character from 
; the 8251a and store it in memory.
;
; The demo uses a reference element for the 8088mn and a single reference
; for the two instances of the 8251's. The 8088mn is modelled as a dynamic
; device and the 8251a as a static device.
;
;
;
;
; Memory address allocation
;
;  A12   A11   
; ----------------------
;   0     0    Memory
;   0     1    I/O
;   1     0    I/O
;   1     1    Memory
;
;
;
; The 8251A I/O addresses is as follows:
;
;  A12  A11 ... A2  A1  A0
; --------------------------------------------------------
;   0    1      1   0   0    804H    Left Data Channel
;   0    1      1   0   1    805H    Left Control Channel
;
;   0    1      0   1   0    802H    Right Data Channel
;   0    1      0   1   1    803H    Right Control Channel
;
;
;
; The listing of the demo program is as follows:


        aseg    0ffffh
        org     0
        jmps    start


        aseg    0

        org     80h             
        db      50h,04,00,00    ;interrupt vector address for nmi


        org     400h
start:  
        mov     ax,#0ffefh      ;initialize stack pointer
        mov     sp,ax
        mov     bx,#500h        ;initialize memory address pointer

        movb    805h,#0cdh      ;Mode Instruction to Left
        movb    805h,#27h       ;Command Intruction to Left

        movb    803h,#0cdh      ;Mode Instruction to Right
        movb    803h,#27h       ;Command Intruction to Right


        movb    cl,#00          ;cl=0 --> Left = transmitter
        sti                     ;set interrupt

        movb    804h,#0aah      ;send char to be xmitted to Left
        movb    802h,#055h      ;send char to be xmitted to Right

stop:   
        jmp     stop            ;wait for interrupt


        org     450h            ;beginning of service routine
intr:   
        cmpb    cl,#00          ;is cl = 0 ?
        jz      readr           ;if yes then read Right
readl:
        movb    al,804h         ;read char from Left's register
        movb    [bx],al         ;store it in memory
        inc     bx              ;increment memory address pointer
        decb    cl              ;set cl = 0 --> Left = transmitter
        iret
readr:
        movb    al,802h         ;read char from Right's register
        movb    [bx],al         ;store it in memory
        inc     bx              ;increment memory address pointer
        incb    cl              ;set cl = 1 --> Right = transmitter
        iret

        end
