NOLIST
        ORG 40000
;
DEBUT   LD HL,39000
        LD B,255
BCL1    LD (HL),#80
        INC HL
        DJNZ BCL1
;
        CALL #BB09
        CP 13
        RET Z
        AND #DF
        CP "S"
        CALL Z,MOTON
        CP "A"
        CALL Z,MOTOFF
        CALL TEST
        JR DEBUT
;
TEST    LD HL,39000
        CALL RAZINTE
        LD HL,39000
REC     LD A,(HL)
        CP #80
        RET Z
        CP #FF
        JR Z,CR1
        PUSH AF
        CALL PRTHEX1
        POP AF
        CALL PRTBIN
        INC HL
        JR REC
CR1     CALL CR
        JR REC
;        
RAZINTE CALL LITSTAT
        CP #80
        RET Z
        LD A,(ETOCLUS)
        LD B,A
        LD DE,ET0
BCL2    LD A,(DE)
        LD (HL),A
        INC HL
        INC DE
        DJNZ BCL2
        LD (HL),#FF
        INC HL
        JR RAZINTE
;
;----------------------------
;- LIRE CAUSE INTERRUPTIONS -
;----------------------------
LITSTAT LD A,#08
        CALL ENVOFDC
        JP RESULT
;
;-----------------------------------------------------------------------------
;- PHASE INSTRUCTION DU FDC . Attendre que le FDC soit pret et envoyer octet -
;-----------------------------------------------------------------------------
;--- Attendre que le FDC soit pret ---
;
ENVOFDC PUSH BC
        LD BC,#FB7E
        PUSH AF
        PUSH AF
        DI
WAITFDC IN A,(C)
        ADD A,A
        JR NC,WAITFDC
        ADD A,A
        JR NC,VEUTOCT
        EI
        POP AF
        POP AF
        POP BC
        RET
;
;--- Transmettre un octet instruction au FDC ---
;
VEUTOCT POP AF
        INC C
        OUT (C),A
        DEC C
        LD A,5
DIGERE  DEC A
        NOP
        JR NZ,DIGERE
        EI
        POP AF
        POP BC
        RET
;------------------------------------------------------
;- EXTRAIRE ET RANGER LES OCTETS DE LA PHASE RESULTAT -
;------------------------------------------------------
RESULT  PUSH BC
        LD BC,#FB7E
        PUSH HL
        PUSH DE
        LD D,0
        LD HL,ET0
        PUSH HL
        DI
JEBOSSE IN A,(C)
        CP #C0
        JR C,JEBOSSE
        INC C
        IN A,(C)
        LD (HL),A
        INC HL
        INC D
        DEC C
        LD A,5
TEMPRES DEC A
        JR NZ,TEMPRES
        IN A,(C)
        AND #10
        JR NZ,JEBOSSE
        POP HL
        LD A,(HL)
        AND #C0
        DEC HL
        LD (HL),D
        POP DE
        POP HL
        POP BC
        EI
        LD A,(ET0)
        RET NZ
        SCF
        RET
;
PRTBIN  PUSH BC    ;8B
        PUSH AF
        LD C,A
        LD B,8
BCLBIN  LD A,#30
        RLC C
        JR NC,BINZERO
        INC A
BINZERO CALL #BB5A
        DJNZ BCLBIN
        POP AF
        POP BC
        JP SPACE
;
PRTHEX2 CALL SPACE
        LD A,"&"
        CALL #BB5A
        LD A,H
        CALL PRTHEX1 ;16B
        LD A,8
        CALL #BB5A
        LD A,L
;
PRTHEX1 PUSH AF
        CALL SPACE
        LD A,"&"
        CALL #BB5A
        POP AF
        PUSH AF ;8B
        PUSH AF
        RRCA
        RRCA
        RRCA
        RRCA
        CALL AFFHEX
        POP AF
        CALL AFFHEX
        POP AF
        JP SPACE
;
AFFHEX  AND #F
        ADD A,#30
        CP #3A
        JR C,OKHEX
        ADD A,7
OKHEX   JP #BB5A
;
PRT     LD A,(HL)
        CP #FF
        RET Z
        CALL #BB5A
        INC HL
        JR PRT
;
;- Affichage -
;
CR      LD A,10
        CALL #BB5A
        LD A,13
        CALL #BB5A
        INC HL
        RET      
;
SPACE   LD A,32
        JP #BB5A
;
;- Resultat -
;
ETOCLUS DEFB 0
ET0     DEFB 0
ET1     DEFB 0
ET2     DEFB 0
ETPIST  DEFB 0
ETHEAD  DEFB 0
ETNUMSEC DEFB 0
ETLENSEC DEFB 0
;
TEMPAMS PUSH AF
        LD A,12
        CALL TEMPMIL
        POP AF
        DEC A
        JR NZ,TEMPAMS
        LD A,15
        CALL TEMPMIL
        RET
;
TEMPMIL PUSH AF
        LD A,#F6
BCLTEMP DEC A
        JR NZ,BCLTEMP
        POP AF
        DEC A
        JR NZ,TEMPMIL
        RET
;--------------------
;- COMMANDE  MOTEUR -
;--------------------
MOTON   PUSH HL
        LD HL,TMOTON
        CALL PRT
        POP HL
        LD A,(FLAGMOT)
        CP 1
        RET Z
        LD A,1
        CALL MOTCOM
        LD A,(TEMPMOT) ;Mini 55
        JP TEMPAMS
MOTCOM  LD (FLAGMOT),A
        LD BC,#FA7E
        OUT (C),A
        RET
MOTOFF  PUSH HL
        LD HL,TMOTOFF
        CALL PRT
        POP HL
        XOR A
        JR MOTCOM
FLAGMOT DEFB 0
TEMPMOT DEFB 55
TMOTON  DEFB 10,13," MOTEUR ON",10,13,#FF
TMOTOFF DEFB 10,13," MOTEUR OFF",10,13,#FF
LIST 
DEFB 0ISEE PAR LE PROGRAMME PRCALL PRT
        POP HL
        LD A,(FLAGMOT)
        CP 1
        RET Z
        LD A,1
        CALL MOTCOM
        LD A,(TEMPMOT) ;Mini 55
        JP TEMPAMS
MOTCOM  LD (FLAGMOT),A
        LD BC,#FA7E
        OUT (C),A
        RET
MOTOFF  PUSH HL
        LD HL,TMOTOFF
        CALL PRT
        POP HL
        XOR A
        JR MOTCOM
FLAGMOT DEFB 0
TEMPMOT DEFB 5