        UNL
STATUS  EQU R22
DEVICE  EQU R31
COMAND  EQU R30
BUFLEN  EQU R26
DATLEN  EQU R24
BUFADR  EQU R21
ATTRIB  EQU R19
TEMP1H  EQU R13
TEMP1L  EQU R14
TEMP2H  EQU R15
TEMP2L  EQU R16
TEMP3H  EQU R17
TEMP3L  EQU R18
DOS     EQU >D013
SELDOS  EQU >C801
SELCOS  EQU >C804
SELRAM  EQU >C80A
CLS     EQU >C87F
WRTSCN  EQU >C83D
KEYIN   EQU >C846
PRNTST  EQU >C852
KEYSCN  EQU >C855
CURSOR  EQU >C858
AFMESS  EQU >C894
BINASC  EQU >C897
AFPNUM  EQU >C8A3
BUFIN   EQU >D070 
CURDRV  EQU >EF5E
PARAM   EQU >EFC0
DRVTST  EQU ?00000001
DRIVEA  EQU >64
DRIVEB  EQU >65
READS   EQU >12
RAMVDP  EQU >00
RAM     EQU >01
HIMEM   EQU >7FFF
NBFIC   EQU >C0F8

        LDA  @CURDRV
        BTJO %DRVTST,A,DRVA
        MOV  %DRIVEB,A
        JMP  DEBUT
DRVA    MOV  %DRIVEA,A
DEBUT   STA  @DRIVE
        CALL @ARG
        CMP  %>00,STATUS
        JNE  BADEND
        CALL @LOAD
        CMP  %>00,STATUS
        JEQ  EXEC
BADEND  CALL @AFMESS
        RETS
EXEC
        CALL @INIT
        CALL @SHORT
        CALL @DISPL
        RETS

LOAD    MOVD %HIMEM,BUFADR
        MOV  %>01,B
        CLR  A
NEXTS   CLRC
        RLC  B
        RLC  A
        XCHB A
        MOVD BUFADR,TEMP3L
        STA  *TEMP3L
        DECD TEMP3L
        XCHB A
        STA  *TEMP3L
        DECD TEMP3L
        MOV  %>02,A
        STA  *TEMP3L
        LDA  @DRIVE
        MOV  A,DEVICE
        MOV  %RAM,ATTRIB
        MOV  %READS,COMAND
        MOVD %>0200,BUFLEN
        MOVD %>0003,DATLEN
        CALL @DOS
        MOVD BUFADR,TEMP3L
        SUB  %>F8,TEMP3L
        SBB  %>01,TEMP3H
        MOVD TEMP3L,BUFADR
        SUB  %>06,TEMP3L
        SBB  %>00,TEMP3H
        LDA  *TEMP3L
        MOV  A,B
        DECD TEMP3L
        LDA  *TEMP3L
        XCHB A
        CMP  %>80,A
        JNE  NEXTS
        ADD  %>07,TEMP3L
        ADC  %>00,TEMP3H
        CLR  A
        STA  *TEMP3L
        DECD TEMP3L
        STA  *TEMP3L
        RETS

ARG
        CLR  B
        LDA  @PARAM(B)
        CMP  %>2B,A
        JNE  LECA
        MOV  %1,A
        STA  @TRI
        INC  B
        LDA  @PARAM(B)
LECA    CMP  %>41,A        
        JNE  LECB
        ADD  %>23,A
        STA  @LEC
        INC  B
        JMP  LEC2PT
LECB    CMP  %>42,A
        JNE  LECSTA
        ADD  %>23,A
        STA  @LEC
        INC  B
LEC2PT  LDA  @PARAM(B)
        CMP  %>3A,A
        JNE  ERROR
        INC  B
        LDA  @PARAM(B)
LECSTA  CMP  %>2A,A
        JEQ  LECPT
        CLR  A
        STA  @FILT3
        JMP  VIDE
LECPT   INC  B
        LDA  @PARAM(B)
        CMP  %>2E,A
        JNE  ERROR
        INC  B
        LDA  @PARAM(B)
        CMP  %0,A
        JEQ  FIN4
        CMP  %>2A,A
        JNE  EXT
        CLR  A
        STA  @FILT3
        INC  B
        LDA  @PARAM(B)
        JMP VIDE
EXT     STA  @FILT3
        INC  B
        LDA  @PARAM(B)
        CMP  %0,A
        JEQ  FIN5
        STA  @FILT2
        INC  B
        LDA  @PARAM(B)
        CMP  %0,A
        JEQ  FIN4
        STA  @FILT1
        INC  B
        LDA  @PARAM(B)

VIDE    CMP  %0,A
        JEQ  FIN4

ERROR   MOV  %>0A,STATUS
        RETS

FIN5    CLR  A
        STA  @FILT3
 
        
FIN4    LDA  @LEC
        CMP  %0,A
        JEQ  FIN4C
        CMPA @DRIVE
        JNE  FIN4B
        MOV  %>21,STATUS
        CALL @AFMESS
        CALL @KEYIN
        CLR  STATUS
FIN4B   LDA  @LEC
        STA  @DRIVE
FIN4C   RETS

INIT    MOVD %HIMEM,TEMP3L
        CALL @SEARCH
        MOV  TEMP2L,A
        STA  *TEMP3L
        DECD TEMP3L
        MOV  TEMP2H,A
        STA  *TEMP3L
AGAIN1  MOVD TEMP2L,TEMP3L
        CMP  %>00,TEMP2L
        JNE  AGAIN2
        CMP  %>00,TEMP2H
        JEQ   FIN0
AGAIN2
        SUB  %>10,TEMP3L
        SBB  %>00,TEMP3H
        CALL @SEARCH
        MOV  TEMP2L,A
        STA  *TEMP3L
        DECD TEMP3L
        MOV  TEMP2H,A
        STA  *TEMP3L 
        JMP   AGAIN1
FIN0    RETS        

SEARCH  MOVD TEMP3L,TEMP2L
AGAIN3  LDA  *TEMP2L
        DECD TEMP2L
        CMP  %>00,A
        JNE  LIREZ
        LDA  *TEMP2L
        CMP  %>00,A
        JNE  LIREZ
        MOVD %>0000,TEMP2L
        RETS
LIREZ   DECD TEMP2L
        LDA  *TEMP2L
        JNZ  TSTFLT
        SUB  %>10,TEMP2L
        SBB  %>00,TEMP2H
        JMP  AGAIN3
TSTFLT  SUB  %>0D,TEMP2L
        SBB  %>00,TEMP2H
        MOV  %3,B
        LDA  @FILT(B)
        JNZ  REPT1
        ADD  %>0D,TEMP2L
        ADC  %>00,TEMP2H
        RETS
REPT1   CMPA @FILT(B)
        JZ   CAROK
        SUB  B,TEMP2L
        SBB  %>00,TEMP2H
        JMP AGAIN3
CAROK   DECD TEMP2L
        LDA  *TEMP2L
        DJNZ B,REPT1
        MOV  %>10,A
        SUB  B,A
        ADD  A,TEMP2L
        ADC  %0,TEMP2H
       RETS

SHORT
        RETS

DISPL   CLR  A
        STA  @RECH
        STA  @RECL
        CLR  R3
        STA  @NBL
        MOVD %HIMEM,TEMP3L
        MOVD TEMP3L,TEMP2L
AGAIN5
        CMP  %27,R3
        JNE  SUITE
        RETS
SUITE   CLR R3
        LDA  *TEMP2L
        XCHB A
        DECD TEMP2L
        LDA  *TEMP2L
        MOVD B,TEMP2L
        CMP  %>00,TEMP2L
        JNE  AGAIN4
        CMP  %>00,TEMP2H
        JEQ  FIN2
AGAIN4  LDA  @RECL
        XCHB A
        LDA  @RECH
        INC  B
        ADC  %0,A
        STA  @RECH
        XCHB A
        STA  @RECL
        MOVD %LIGNE,TEMP3L
        MOVD TEMP2L,TEMP1L
        CALL @CPD2C
        MOV  TEMP2L,A
        STA  @STMP2L
        MOV  TEMP2H,A
        STA  @STMP2H
        MOVD %LIGNE,TEMP3L
        CALL @ALERT
        LDA  @STMP2L
        MOV  A,TEMP2L
        LDA  @STMP2H
        MOV  A,TEMP2H
        SUB  %>10,TEMP2L
        SBB  %>00,TEMP2H
        MOVD TEMP2L,TEMP3L
        JMP  AGAIN5
FIN2    LDA  @RECL
        XCHB A
        LDA  @RECH
        CALL @BINASC
        CALL @AFPNUM
        CALL @LF
        MOV  %6,B
AGAIN9  LDA  @NBFIC(B)
        CALL @WRTSCN
        DJNZ B,AGAIN9
        MOVD %MESS2,TEMP3L
        CALL @PRNTST 
        LDA  @DRIVE
        SUB  %35,A
        CALL @WRTSCN
        MOV  %58,A
        CALL @WRTSCN
EXIT    RETS

ALERT
        MOV  TEMP3L,A
        STA  @STMP3L
        MOV  TEMP3H,A
        STA  @STMP3H
        CALL @LF
        LDA  @NBL
        INC  A
        STA  @NBL
        CMP  %23,A
        JNE  FIN3
        CLR  A
        STA  @NBL
        MOVD %MESS1,TEMP3L
        CALL @PRNTST
        CALL @KEYIN
        MOV  %>0D,A
        CALL @WRTSCN
FIN3
        LDA  @STMP3L
        MOV  A,TEMP3L
        LDA  @STMP3H
        MOV  A,TEMP3H
        CALL @PRNTST
        RETS 

CPD2C   MOV  %16,B
AGAIN6  LDA  *TEMP1L
        CMP  %>20,A
        JEQ  SPACE
        STA  *TEMP3L
        INC  TEMP3L
        ADC  %00,TEMP3H
SPACE   DECD TEMP1L
        CMP  %4,B
        JNE  AGAIN8
        MOV  %>2E,A
        STA  *TEMP3L
        INC  TEMP3L
        ADC  %>00,TEMP3H
AGAIN8  DJNZ B,AGAIN6
        MOV  %>00,A
        STA  *TEMP3L
        RETS

LF      MOV  %>0A,A
        CALL @WRTSCN
        MOV  %>0D,A
        CALL @WRTSCN
        RETS

STMP2H  BYTE 0
STMP2L  BYTE 0
STMP3H  BYTE 0
STMP3L  BYTE 0
RECH    BYTE 0
RECL    BYTE 0
DRIVE   BYTE 0
LEC     BYTE 0
NBL     BYTE 0
TRI     BYTE 0
FILT    BYTE 0
FILT1   BYTE >20
FILT2   BYTE >20
FILT3   BYTE >20
LIGNE   BSS 18
MESS1   TEXT 'Appuyer sur une touche pour continuer...',0
MESS2   TEXT ' fichiers sur le disque ',0
        END
