;FILE   DS2223.ASM
;-----------------------------
;MAIN PROGRAM
;-----------------------------

        $INCLUDE "C:\SXA51\J31HEAD.ASM"
        ORG     8000H

MAIN:   LCALL   WRITEC       ; WRITE COMMAND WORD
        MOV     R3,#80       ; WRITE ONE = 80 BIT [10 BYTE]
MAIN1:  LCALL   WONE
        DJNZ    R3,MAIN1
        MOV     R3,#88       ; WRITE ZERO = 88 BIT [11 BYTE]
MAIN11: LCALL   WZERO
        DJNZ    R3,MAIN11
        MOV     R3,#88       ; WRITE ONE = 88 BIT [11 BYTE]
MAIN12: LCALL   WONE
        DJNZ    R3,MAIN12

        LCALL   READC        ; READ COMMAND WORD
        MOV     DPTR,#9000H  ; START RAM
        MOV     R3,#32       ; 32 BYTE LOOP
MAIN2:  MOV     R4,#8        ; 8 BIT LOOP
        MOV     R5,#0
MAIN3:  LCALL   READ
        MOV     A,R5
        RRC     A
        MOV     R5,A
        DJNZ    R4,MAIN3
        MOV     A,R5
        MOVX    @DPTR,A
        INC     DPTR
        DJNZ    R3,MAIN2
        LJMP    ENDVEC       ; END-PROGRAM VECTOR

;-----------------------------
;WRITE COMMAND WORD SUB.
;-----------------------------

WRITEC: LCALL   WONE         ; FIRST BIT OF THE COMMAND WORD = 1
        LCALL   WZERO        ; PHYSICAL ADDRESS BIT 0 = 0
        LCALL   WZERO        ; PHYSICAL ADDRESS BIT 1 = 0
        LCALL   WONE         ; WRITE
        LCALL   WONE
        LCALL   WONE
        LCALL   WONE
        LCALL   WONE
        RET

;-----------------------------
;READ OPERATION SUB.
;-----------------------------

READC:  LCALL   WONE         ; FIRST BIT OF THE COMMAND WORD = 1
        LCALL   WZERO        ; PHYSICAL ADDRESS BIT 0 = 0
        LCALL   WZERO        ; PHYSICAL ADDRESS BIT 1 = 0
        LCALL   WZERO        ; READ
        LCALL   WZERO
        LCALL   WZERO
        LCALL   WZERO
        LCALL   WZERO
        RET

;-----------------------------
;WRITE ONE TIME SLOT SUB.
;-----------------------------

WONE:   NOP                  ; Tsyc = 2 uS
        CLR     P1.0
        MOV     R2,#4        ; Tlow1 = 10 uS
        DJNZ    R2,$
        SETB    P1.0
        MOV     R2,#30       ; MAKE Tslot = 80 uS
        DJNZ    R2,$
        NOP
        RET

;-----------------------------
;WRITE ZERO TIME SLOT SUB.
;-----------------------------

WZERO:  NOP                  ; Tsyc = 2 uS
        CLR     P1.0
        MOV     R2,#36       ; Tlow0 = Tslot = 80 uS
        DJNZ    R2,$
        SETB    P1.0
        RET

;-----------------------------
;READ DATA TIME SLOT SUB.
;-----------------------------

READ:   NOP                  ; Tsyc = 2 uS
        CLR     P1.0
        MOV     R2,#3        ; Tsu = 8 uS
        DJNZ    R2,$
        SETB    P1.0
        MOV     R2,#5        ; Tdvr = 14 uS
        DJNZ    R2,$
        NOP
        MOV     C,P1.0       ; GET DATA FROM EconoRAM TO CY
        MOV     R2,#28       ; MAKE Tslot = 80 uS
        DJNZ    R2,$
        NOP
        SETB    P1.0
        RET

        END
