	ORG   #0100
BDOS:	EQU   #05
	JP    START

; The following text is printed with the TYPE command.

	DEFB  13,"ADIR - ANSI Dir",13,10
	DEFB  "Version 1.3",13,10
	DEFB  "Copyright (c) 1994 By C.P.U. and 1997 By : NYYRIKKI"
	DEFB  13,10,10,26

; DOS1? Too bad, that won't work.

START:	LD    C,#6F
        CALL  BDOS
        LD    A,B
        CP    2
        JP    C,DOS1

; Check to see whether ANSI is on or off.

	LD    A,(#FCAF)
	CP    7
	JR    Z,PARCOM
	CP    255
	LD    A,23
	LD    (HEIGHT+1),A
	JR    Z,PARCOM
	JP    ANSI

; Parse the command line.

PARCOM: LD    A,(#80)
        LD    DE,COMLIN
        OR    A
        JP    Z,NEXT02
        LD    B,0
        LD    C,A
        INC   C
        LD    DE,COMLIN
	LD    HL,#81
        LDIR

; Find any options.

        LD    HL,COMLIN
        LD    C,A
        LD    IX,OPTION
        LD    IY,ATTR
PLP:    INC   C
        DEC   C
        JR    Z,PARSE
        LD    A,"/"
        CPIR
        JR    NZ,PARSE
        LD    A,(HL)
	OR    %00100000
CHK_H:  CP    "h"
        JR    NZ,CHK_W
        SET   1,(IY)
        JR    KILOPT
CHK_W:  CP    "w"
        JR    NZ,CHK_P
        SET   0,(IX)
        RES   4,(IY)
        JR    KILOPT
CHK_P:  CP    "p"
        JR    NZ,CHK_D
        SET   1,(IX)
        JR    KILOPT
CHK_D:  CP    "d"
        JR    NZ,CHK_2
        SET   4,(IY)
        JR    KILOPT
CHK_2:  CP    "2"
	JR    NZ,CHK_S
        SET   2,(IX)
        JR    KILOPT
CHK_S:	CP    "s"
	JR    NZ,CHK_KM
	LD    (SPAR),A
	JR    KILOPT
CHK_KM: CP    "?"
        JP    Z,EXPL
ERR136: LD    A,136
        JP    ERROR
KILOPT: DEC   HL
        LD    (HL)," "
        INC   HL
        LD    (HL)," "
        JR    PLP

; Create the correct pathname (add *.* when necessary).

PARSE:  LD    HL,COMLIN-1
SNEXT:  INC   HL
        LD    A,(HL)
        CP    " "
        JR    Z,SNEXT
        CP    9
        JR    Z,SNEXT
        CP    0
        JR    NZ,PP
        LD    BC,4
        LD    DE,COMLIN
        LD    HL,T_STER+1
        LDIR
        LD    DE,COMLIN
        JR    NEXT02
PP:     LD    DE,COMLIN
        CALL  COMP
        JR    Z,NEXT02
NEXT01: LDI
        LD    A,(HL)
        OR    A
        JR    NZ,NEXT01
        LDI
        LD    DE,COMLIN
NEXT02: LD    BC,#5B
        CALL  BDOS
        LD    A,C
        LD    (DRIVE),A
        PUSH  DE
        EX    DE,HL
        LD    (HL),0
        BIT   5,B
        JR    NZ,AMBI
        CALL  COMP
        JR    Z,AMBI
        LD    DE,COMLIN
        LD    IX,FIB
	LD    BC,#1240
        CALL  BDOS
        JR    Z,NEXT03
        CP    215
        JP    Z,NEXT04
        JP    ERROR
NEXT03: LD    A,(FIB+14)
        BIT   4,A
        JR    Z,AMBI
        POP   DE
        LD    HL,T_STER
        LD    BC,5
        LDIR
        PUSH  DE
AMBI:   POP   DE
NEXT04: CALL  HEAD1

; Check /S parameter

	LD    A,(SPAR)
	AND   A
	JP    NZ,SOPTION
	LD    DE,COMLIN
	CALL  MIDLE
	JP    THEEND

; Find first file and print it.

MIDLE
        LD    A,(ATTR)
        LD    B,A
	LD    C,#40
        LD    IX,FIB
        CALL  BDOS
        JR    Z,NEXT05
        CP    215
        JP    Z,NEXT10
        JP    ERROR
NEXT05: CALL  HEAD2
NEXT06: LD    DE,FIB+1
        LD    HL,FILBUF
	LD    C,#5C
        CALL  BDOS
        LD    HL,FILBUF+10
        LD    DE,FILBUF+11
        LD    BC,3
        LDDR
        LD    HL,FILBUF+8
        LD    (HL)," "
        INC   HL
        LD    IX,OPTION
        BIT   0,(IX)
        JR    Z,NEXT41
        LD    A,(HL)
        CP    " "
        JR    Z,NEXT41
        DEC   HL
        LD    (HL),"."
        INC   HL
NEXT41: CALL  FNDEXT
        CALL  PRTSTR
        CALL  LOWER
        LD    HL,FILBUF
        LD    B,12
	LD    C,#02
NEXT07: LD    E,(HL)
        CALL  PRTCHR
        INC   HL
        DJNZ  NEXT07
        LD    HL,(NUMBER)
        INC   HL
        LD    (NUMBER),HL
	LD    HL,(TNUMB)
	INC   HL
	LD    (TNUMB),HL
	CALL  COLUMN
        PUSH  AF
        LD    HL,(FIB+21)
        LD    DE,(FIB+23)
        CALL  OPTEL
        POP   AF
        JR    C,NEXT22
        LD    HL,T_HR
        LD    A,(FIB+14)
        BIT   1,A
        JR    Z,NO_HID
        LD    (HL),"h"
        INC   HL
NO_HID: LD    A,(FIB+14)
        BIT   0,A
        JR    Z,NO_RO
        LD    (HL),"r"
NO_RO:  LD    HL,T_HR+1
        LD    A,(HL)
        CP    " "
        JR    NZ,NEXT08
        DEC   HL
        LD    A,(HL)
        LD    (HL)," "
        INC   HL
        LD    (HL),A
NEXT08: LD    DE,T_HR
        PUSH  DE
        CALL  PRTSTR
        POP   HL
        LD    (HL)," "
        INC   HL
        LD    (HL)," "
        LD    A,(FIB+14)
        BIT   4,A
        JR    Z,NO_DIR
        LD    DE,T_DIR
        CALL  PRTSTR
        JR    NO_LEN
NO_DIR: LD    HL,(FIB+21)
        LD    DE,(FIB+23)
	CALL  DECI
        LD    DE,T_FREE+2
        CALL  PRTSTR
NO_LEN: LD    HL,(FIB+17)
	LD    DE,EMPTY
	LD    A,H
	OR    L
	JR    Z,ZERODAT
	CALL  DATE
        CALL  PRTSTR
	LD    HL,(FIB+15)
	LD    DE,EMPTY2
	LD    A,H
	OR    L
	JR    Z,ZERODAT

	CALL  TIME
ZERODAT CALL  PRTSTR
        CALL  TWOCOL

; Find next file and print it.

NEXT22: LD    C,#41
        LD    IX,FIB
        CALL  BDOS
        JP    Z,NEXT06
        CP    215
        JR    NZ,ERROR
NEXT09: CALL  PRTLEN
	RET

THEEND
	CALL  PRTEMP
        JR    STOP


; Error handling routines.

NEXT10: CALL  HEAD2
        JR    NEXT09
ERROR2: CP    215
        JR    Z,STOP
ERROR:  PUSH  AF
        LD    DE,T_OFF
        CALL  PRTSTR
        POP   AF
        LD    B,A
STOP2:	LD    C,#62
        JP    BDOS
STOP:   LD    A,0
        JR    ERROR

; Check to see whether the extension exists in our list.

FNDEXT: LD    DE,LIST
NEXT11: PUSH  DE
        PUSH  HL
        LD    A,(DE)
        CP    255
        JR    Z,FNDEND
        LD    B,3
NEXT40: CP    (HL)
        JR    NZ,NIET
        INC   HL
        INC   DE
	LD    A,(DE)
	CP    "?"
	JR    NZ,NEXT42
	LD    A,(HL)
NEXT42: DJNZ  NEXT40
        POP   HL
        POP   BC
        RET
NIET:   POP   HL
        POP   DE
	LD    BC,15
        EX    DE,HL
        ADD   HL,BC
        EX    DE,HL
        JR    NEXT11
FNDEND: POP   HL
        POP   DE
        LD    DE,T_OFF
        RET

; Put DE,HL (32-bit) decimal in T_FREE

DECI:   PUSH  DE
        LD    DE,T_FREE
        LD    B,10
        LD    A," "
DC1:    LD    (DE),A
        INC   DE
        DJNZ  DC1
        POP   DE
DC2:    XOR   A
        LD    C,A
        LD    B,32
DC3:    RL    L
        RL    H
        RL    E
        RL    D
        RL    C
        LD    A,C
        SUB   10
        CCF
        JR    NC,DC4
        LD    C,A
DC4:    DJNZ  DC3
        RL    L
        RL    H
        RL    E
        RL    D
        LD    A,C
        ADD   A,"0"
        PUSH  HL
        PUSH  DE
        LD    HL,T_FREE+8
        LD    DE,T_FREE+9
        LD    BC,9
        LDDR
        LD    (T_FREE),A
        POP   DE
        POP   HL
        LD    A,H
        OR    L
        JR    NZ,DC2
        LD    A,D
        OR    E
        JR    NZ,DC2
DC5:    LD    A,(T_FREE+9)
        CP    " "
        RET   NZ
        LD    DE,T_FREE+9
        LD    HL,T_FREE+8
        LD    BC,9
        LDDR
        LD    A," "
        LD    (T_FREE),A
        JR    DC5
        RET

; Put A ( < 100) decimal in (HL).

DECI2:  PUSH  HL
        PUSH  DE
        EX    DE,HL
        LD    D,"0"
TEL:	SUB   10
        JR    C,PRT
        INC   D
        JR    TEL
PRT:    LD    (HL),D
        INC   HL
        ADD   A,10
        ADD   A,"0"
        LD    (HL),A
        POP   DE
        POP   HL
        RET

; Print date using format specified with SET DATE.

DATE:	LD    A,H	
	AND   %11111110
        SRL   A
        ADD   A,80
        CP    100
        JR    C,NO_CEN
	SUB   100
NO_CEN: LD    DE,T_DATE
        CALL  DECI2
        LD    A,L
	AND   %11100000
        SRL   A
        SRL   A
        SRL   A
        SRL   A
        SRL   A
        BIT   0,H
        JR    Z,NO_DEC
        SET   3,A
NO_DEC: LD    DE,T_DATE+3
        CALL  DECI2
        LD    A,L
	AND   %00011111
        LD    DE,T_DATE+6
        CALL  DECI2
	LD    BC,#086B
        LD    DE,ENVBUF
        LD    HL,ENVDAT
        CALL  BDOS
        LD    A,(ENVBUF)
        OR    A
        JR    NZ,DO_DAT
        LD    BC,8
        LD    DE,ENVBUF
        LD    HL,T_ENV
        LDIR
DO_DAT: LD    HL,ENVBUF
        CALL  INVUL
        LD    HL,ENVBUF+3
        CALL  INVUL
        LD    HL,ENVBUF+6
        CALL  INVUL
        LD    A,"-"
        LD    (ENVBUF+2),A
        LD    (ENVBUF+5),A
        LD    DE,ENVBUF
        RET

; Print time using format specified with SET TIME.

TIME:   LD    A,H
	AND   %11111000
        SRL   A
        SRL   A
        SRL   A
        PUSH  AF
        LD    DE,T_TIME
        CALL  DECI2
        LD    A,H
	AND   %00000111
        LD    B,A
        LD    A,L
	AND   %11100000
        SRL   B
        RRA
        SRL   B
        RRA
        SRL   B
        RRA
        SRL   A
        SRL   A
        LD    DE,T_TIME+3
        CALL  DECI2
	LD    BC,#086B
        LD    DE,ENVBUF
        LD    HL,ENVTIM
        CALL  BDOS
        LD    HL,ENVBUF
        LD    A,(HL)
        CP    "2"
        JR    NZ,NO_24
        INC   HL
        LD    A,(HL)
        CP    "4"
        JR    NZ,NO_24
TIMEND: LD    DE,T_TIME
        POP   AF
        LD    A,(DE)
        CP    "0"
        RET   NZ
        LD    A," "
        LD    (DE),A
        RET
NO_24:  POP   AF
        PUSH  AF
        CP    12
        JR    NC,PM
        LD    A,"a"
        LD    (T_TIME+5),A
        JR    AM
PM:     LD    A,"p"
        LD    (T_TIME+5),A
AM:     POP   AF
	PUSH  AF
	CP    13
        JR    C,TIMEND
	SUB   12
        LD    DE,T_TIME
        CALL  DECI2
        JR    TIMEND

; Fill in the correct date

INVUL:  LD    A,(HL)
	OR    %00100000
CHKYEA: CP    "y"
        JR    NZ,CHKMON
        LD    DE,(T_DATE)
        LD    (HL),E
        INC   HL
        LD    (HL),D
        RET
CHKMON: CP    "m"
        JR    NZ,CHKDAY
        LD    DE,(T_DATE+3)
        LD    (HL),E
        INC   HL
        LD    (HL),D
        RET
CHKDAY: CP    "d"
        JR    NZ,CHKNOT
        LD    DE,(T_DATE+6)
        LD    (HL),E
        INC   HL
        LD    (HL),D
        RET
CHKNOT: LD    A,"?"
        LD    (HL),A
        INC   HL
        LD    (HL),A
        RET

; Print header 1 (Volume Name).

HEAD1:	
	LD    DE,COMLIN
	LD    BC,#0840
        LD    IX,FIB
        CALL  BDOS
        LD    DE,FIB+1
        JR    Z,NO_ERR
        CP    215
        JP    NZ,ERROR
        LD    DE,T_NVOL
NO_ERR: PUSH  DE
        LD    A,(FIB+25)
        ADD   A,"@"
        LD    (T_VOLU+21),A
        LD    DE,T_VOLU
        CALL  PRTSTR
        POP   HL
        PUSH  HL
        XOR   A
        LD    DE,FIB+1
        SBC   HL,DE
        JR    NZ,NO_IS
        LD    DE,T_IS
        CALL  PRTSTR
NO_IS:  LD    DE,T_ON
        CALL  PRTSTR
        POP   HL
NEXT12: LD    A,(HL)
        OR    A
        JR    Z,NEXT13
        LD    E,A
        CALL  PRTCHR
        INC   HL
        JR    NEXT12
NEXT13: CALL  CRLF
        CALL  PAUZE
        RET

; Print header 2 (Path String).

HEAD2:  LD    DE,T_ADIR
        CALL  PRTSTR
        LD    DE,T_ON
        CALL  PRTSTR
        LD    A,(DRIVE)
        ADD   A,"@"
        LD    (PTHBUF),A
        LD    DE,PTHBUF+3
        PUSH  DE
	LD    C,#5E
        CALL  BDOS
        POP   DE
        CALL  COMP
        JR    Z,NEXT14
        DEC   HL
NEXT14: LD    (HL),0
        LD    HL,PTHBUF
NEXT15: LD    A,(HL)
        OR    A
        JR    Z,NEXT16
        LD    E,A
        CALL  PRTCHR
        INC   HL
        JR    NEXT15
NEXT16: CALL  CRLF
	CALL  PAUZE
	CALL  CRLF
	CALL  PAUZE
        RET

; Compare HL with DE (standard routine RST #20).

COMP:   LD    A,H
        SUB   D
        RET   NZ
        LD    A,L
        SUB   E
        RET

; Add DE,HL (32 bit) to TOTAL1,TOTAL2 (32 bit).

OPTEL:  PUSH  HL
        PUSH  DE
        EX    DE,HL
        LD    HL,(TOTAL1)
        ADD   HL,DE
        LD    (TOTAL1),HL
        POP   DE
        LD    HL,(TOTAL2)
        ADC   HL,DE
        LD    (TOTAL2),HL
        POP   HL
        RET

; Print total length + number of files.

PRTLEN: LD    HL,OPTION
        BIT   7,(HL)
        JR    NZ,DO_CR
        LD    A,(KOLOM)
        OR    A
        JR    Z,NO_CR
DO_CR:	CALL  CRLF
	CALL  PAUZE
NO_CR:  LD    DE,T_ON
        CALL  PRTSTR
        LD    HL,(TOTAL1)
        LD    A,H
	AND   %11111100
        JR    NZ,PRTKB
        LD    HL,(TOTAL2)
        LD    A,H
        OR    L
        JR    NZ,PRTKB
        LD    HL,(TOTAL1)
        LD    DE,(TOTAL2)
        CALL  DECI
        CALL  TRIM
        CALL  PRTSTR
        LD    A,(TOTAL2)
        OR    A
        JR    NZ,PRTBTS
        LD    A,(TOTAL2+1)
        OR    A
        JR    NZ,PRTBTS
        LD    A,(TOTAL1+1)
        OR    A
        JR    NZ,PRTBTS
        LD    A,(TOTAL1)
        DEC   A
        JR    NZ,PRTBTS
        LD    DE,T_BYTE
        JR    PRTBYT
PRTBTS: LD    DE,T_BTS
PRTBYT: CALL  PRTSTR
        JR    PRTNUM
PRTKB:  LD    B,10
        LD    HL,(TOTAL1)
        LD    DE,(TOTAL2)
NEXT17: SRL   D
        RR    E
        RR    H
        RR    L
        DJNZ  NEXT17
        CALL  DECI

	LD    DE,T_ON
        CALL  PRTSTR
	CALL  TRIM
        LD    HL,T_FREE+10
        LD    (HL),"$"
        CALL  PRTSTR
        LD    DE,T_K
        CALL  PRTSTR
PRTNUM: LD    HL,(NUMBER)
        PUSH  HL
        LD    DE,0
        CALL  DECI
        LD    DE,T_ON
        CALL  PRTSTR
        CALL  TRIM
        LD    HL,T_FREE+10
        LD    (HL)," "
        CALL  PRTSTR
        POP   HL
        DEC   L
        LD    A,H
        OR    L
        LD    DE,T_FILS
        JR    NZ,PRTFIL
        LD    DE,T_FIL
PRTFIL: CALL  PRTSTR
        RET

; Remove leading spaces from T_FREE.

TRIM:   LD    DE,T_FREE
NEXT18: LD    A,(DE)
        CP    " "
        JR    NZ,NEXT19
        INC   DE
        JR    NEXT18
NEXT19: DEC   DE
        RET

; Print free diskspace.

PRTEMP: LD    HL,0
        LD    (TOTAL1),HL
        LD    (TOTAL2),HL
	LD    C,#1B
        LD    A,(DRIVE)
        LD    E,A
        CALL  BDOS
        LD    B,A
        EX    DE,HL
NEXT20: LD    HL,(TOTAL1)
        ADD   HL,DE
        LD    (TOTAL1),HL
        JR    NC,NEXT21
        LD    HL,(TOTAL2)
        INC   HL
        LD    (TOTAL2),HL
NEXT21: DJNZ  NEXT20
        LD    HL,(TOTAL1)
        LD    DE,(TOTAL2)
        SRL   D
        RR    E
        RR    H
        RR    L
        CALL  DECI
        LD    DE,T_TABS
        CALL  PRTSTR
        LD    DE,T_ON
        CALL  PRTSTR
        LD    HL,T_FREE+10
        LD    (HL),"$"
        CALL  TRIM
        CALL  PRTSTR
        LD    DE,T_KFRE
        CALL  PRTSTR
        RET

; Pause at bottom of screen.

PAUZE:  LD    HL,OPTION
        BIT   1,(HL)
        RET   Z
        LD    A,(REGEL)
        INC   A
        LD    (REGEL),A
HEIGHT	CP    25
        RET   NZ
        LD    DE,T_PAUZ
        CALL  PRTSTR
        LD    C,7
        CALL  BDOS
        LD    DE,T_DLLN
        CALL  PRTSTR
        XOR   A
        LD    (REGEL),A
        RET

; Print two columns.

TWOCOL: LD    HL,OPTION
        BIT   2,(HL)
        JR    Z,ONECOL
        BIT   7,(HL)
        JR    Z,NXTCOL
        RES   7,(HL)
ONECOL: CALL  CRLF
        CALL  PAUZE
        RET
NXTCOL: SET   7,(HL)
        LD    DE,T_HR
        CALL  PRTSTR
        RET

; Print multiple columns (/W option)

COLUMN: LD    HL,OPTION
        XOR   A
        BIT   0,(HL)
        RET   Z
        LD    A,(KOLOM)
        INC   A
        LD    (KOLOM),A
        CP    5
        JR    Z,COLNXT
        LD    DE,T_SPC
        CALL  PRTSTR
        XOR   A
        CCF
        RET
COLNXT: CALL  CRLF
        CALL  PAUZE
        XOR   A
        LD    (KOLOM),A
        CCF
        RET

; Convert filename to lower case.

LOWER:  LD    HL,OPTION
        BIT   0,(HL)
        RET   Z
        LD    A,(FIB+14)
        BIT   4,A
        RET   Z
        LD    B,12
        LD    HL,FILBUF
NEXT24: LD    A,(HL)
        CALL  MKCAST
        LD    (HL),A
        INC   HL
        DJNZ  NEXT24
        RET

; Convert to lower case.

MKCAST: CP    "A"
        RET   C
        CP    "Z"
        RET   NC
	OR    %00100000
        RET

; Print CR/LF.

CRLF:   LD    DE,T_END

; Print string.

PRTSTR: LD    C,#09
        CALL  BDOS
        RET

; Print character.

PRTCHR: LD    C,#02
        PUSH  HL
        PUSH  BC
        CALL  BDOS
        POP   BC
        POP   HL
        RET

; Print text for DOS1.

DOS1:   LD    DE,T_DOS1
PRINT:  CALL  PRTSTR
        LD    B,0
        JP    STOP2

; Print text for no ANSI.

ANSI:   LD    DE,T_ANSI
        JR    PRINT

; Print manual.

EXPL:   LD    DE,T_EXPL
        JR    PRINT

; /S parameter handling.

SOPTION 
	LD    DE,COMLIN
	PUSH  DE
	LD    BC,#5B
	CALL  BDOS
	LD    DE,STNAME
	LD    BC,13
	LDIR
	POP   DE

	LD    BC,#40
	LD    IX,FIB
	CALL  BDOS
	LD    A,(DRIVE)
	ADD   A,"@"
	LD    (TXT),A
	LD    DE,TXT+3
	PUSH  DE
	LD    C,#5E
	CALL  BDOS
	LD    (PRED),HL
	POP   DE
	CALL  COMP
	JR    Z,NODEC
	DEC   HL
NODEC	LD    (HL),0

LOOP
	CALL  FIX
	LD    B,16
	LD    C,#40
	LD    IX,(SIX)
	LD    DE,TXT
	PUSH  DE
	CALL  BDOS
	POP   DE
	PUSH  AF
	CALL  NZ,MIDLE
	POP   AF
	JP    NZ,THEEND

	PUSH  IX

	LD    HL,STNAME
	LD    DE,(SDE)
	LD    BC,12
	LDIR

	LD    DE,TXT

	LD    IX,FIB
	LD    A,(ATTR)
	LD    B,A
	LD    C,#40
	CALL  BDOS
	JR    NZ,NOMID

	LD    HL,0
	LD    (NUMBER),HL
	LD    (TOTAL1),HL
	LD    (TOTAL2),HL

	LD    DE,TXT
	CALL  MIDLE
	LD    HL,(TTOT1)
	LD    DE,(TTOT2)
	CALL  OPTEL
	LD    HL,(TOTAL1)
	LD    (TTOT1),HL
	LD    HL,(TOTAL2)
	LD    (TTOT2),HL

	CALL  CRLF
	CALL  PAUZE
	LD    HL,OPTION
	RES   7,(HL)
	CALL  COLNXT

NOMID
	POP   IX
	JR    FIRSTT

LOOP2
	LD    C,#41
	CALL  BDOS
	JR    NZ,PREV
FIRSTT	LD    A,(IX+14)
	CP    16
	JR    NZ,LOOP2
	LD    A,(IX+1)
	CP    "."
	JR    Z,LOOP2

	LD    HL,(SIX)
	INC   HL
	LD    DE,(SDE)
	LD    BC,12
	LDIR
	EX    DE,HL
	LD    (HL),0
	LD    HL,(SIX)
	LD    DE,64
	ADD   HL,DE
	LD    (SIX),HL
	JP    LOOP

PREV	
	LD    HL,(PRED)
	DEC   HL
	LD    (HL),0

	CALL  FIX

	LD    HL,(SIX)
	LD    DE,-64
	ADD   HL,DE
	LD    (SIX),HL
	LD    IX,(SIX)
	LD    A,(AIX)
	CP    L
	JP    NZ,LOOP2
	LD    A,(AIX+1)
	CP    H
	JP    NZ,LOOP2

	LD    HL,(TTOT1)
	LD    (TOTAL1),HL
	LD    HL,(TTOT2)
	LD    (TOTAL2),HL
	LD    HL,(TNUMB)
	LD    (NUMBER),HL
	LD    DE,PTOT
	CALL  PRTSTR
	CALL  PRTLEN
	JP    THEEND

FIX	LD    BC,#5B
	LD    DE,TXT
	CALL  BDOS
	LD    (PRED),HL
	EX    DE,HL
	DEC   HL
	LD    A,"\"
	CP    (HL)
	JR    Z,NOINC
	INC   HL
NOINC	LD    (HL),"\"
	INC   HL
	LD    (SDE),HL
	LD    (HL),"*"
	INC   HL
	LD    (HL),"."
	INC   HL
	LD    (HL),"*"
	INC   HL
	LD    (HL),0
	RET

; Storage area for various variables.

ATTR:	DEFB  #10
OPTION: DEFB  0
DRIVE:	DEFB  0
TOTAL1: DEFW  0
TOTAL2: DEFW  0
NUMBER: DEFW  0
REGEL:	DEFB  0
KOLOM:	DEFB  0

SPAR	DEFB  0

; Storage area for various texts.

T_END:	DEFB  27,"[0m",13,10,"$"
T_STER: DEFB  "\*.*",0
T_DIR:	DEFB  "  ",27,"[0;36m<dir>",27,"[0m  $"
T_FREE: DEFB  "           $"
T_DATE: DEFB  "  -  -  $";|
T_TIME: DEFB  "  :   $"
T_HR:	DEFB  "  $"
T_VOLU: DEFB  27,"[0m Volume in drive A: $"
T_IS:	DEFB  "is $"
T_ADIR: DEFB  27,"[0m A-Directory of $"
T_NVOL: DEFB  "has no name",0
T_ENV:	DEFB  "mm-dd-yy",0
T_BYTE: DEFB  27,"[0mbyte in$"
T_BTS:	DEFB  27,"[0mbytes in$"
T_K:	DEFB  27,"[0mK in$"
T_FIL:	DEFB  27,"[0mfile$"
T_FILS: DEFB  27,"[0mfiles$"
T_KFRE: DEFB  27,"[0mK free$"
T_PAUZ: DEFB  27,"[0;1;5;33mPress any key to continue... $"
T_DLLN: DEFB  13,27,"[K",13,"$"
T_TABS: DEFB  13,27,"[23C$"
T_SPC:	DEFB  27,"[0m    $"
T_DOS1: DEFB  13,10,"Sorry, DOS2.xx required.",13,10,7,"$"
T_ANSI: DEFB  13,10,"Sorry, ANSI screen required.",13,10,7,"$"
EMPTY	DEFB  27,"[0m         "
EMPTY2	DEFB  27,"[0m      $"
PTOT	DEFB  27,"[A Total :",10,13,"$"

; Various storage areas

ENVDAT: DEFB  "DATE",0
ENVTIM: DEFB  "TIME",0

FILBUF: DEFB  "            "
ENVBUF: DEFB  "         $"

PTHBUF: DEFB  "A:\"
	DEFS  64

FIB:	DEFS  64

COMLIN: DEFB  "*.*",0
	DEFS  124


; List with ANSI codes.

T_OFF:	DEFB  27,"[0m","$"

T_ON:	DEFB  27,"[0;1;33m","$"

LIST:
	DEFB  "PMA",27,"[0;1;35m","$",0,0
	DEFB  "LZH",27,"[0;1;35m","$",0,0
	DEFB  "ARJ",27,"[0;1;35m","$",0,0
	DEFB  "ZIP",27,"[0;1;35m","$",0,0

	DEFB  "TXT",27,"[0;1;33m","$",0,0
	DEFB  "HLP",27,"[0;1;33m","$",0,0
	DEFB  "DOC",27,"[0;1;33m","$",0,0
	DEFB  "ME ",27,"[0;1;33m","$",0,0
	DEFB  "MIJ",27,"[0;1;33m","$",0,0

	DEFB  "BAT",27,"[0;31m","$",0,0,0,0

	DEFB  "MBM",27,"[0;41m","$",0,0,0,0
	DEFB  "BGM",27,"[0;41m","$",0,0,0,0
	DEFB  "MUS",27,"[0;41m","$",0,0,0,0
	DEFB  "MOD",27,"[0;41m","$",0,0,0,0

	DEFB  "MBK",27,"[0;45m","$",0,0,0,0

	DEFB  "GEN",27,"[0;44;37m","$",0
	DEFB  "ASM",27,"[0;44;37m","$",0
	DEFB  "MAC",27,"[0;44;37m","$",0
	DEFB  "PAS",27,"[0;44;37m","$",0
	DEFB  "C  ",27,"[0;44;37m","$",0


	DEFB  "PIC",27,"[0;1;36m","$",0,0
	DEFB  "SC?",27,"[0;1;36m","$",0,0
	DEFB  "SR?",27,"[0;1;36m","$",0,0
	DEFB  "GE5",27,"[0;1;36m","$",0,0

	DEFB  "COM",27,"[0;1;31m","$",0,0
	DEFB  "BIN",27,"[0;1;32m","$",0,0

	DEFB  "BAS",27,"[0;32m","$",0,0,0,0
	DEFB  "LDR",27,"[0;32m","$",0,0,0,0

	DEFB  "BAK",27,"[0;30;43m","$",0
	DEFB  255

; Text for manual.

T_EXPL: DEFB  13,10
	DEFB  27,"[0;1;33mADIR",27,"[0m Version ",27,"[0;1;33m1.3",13,10
	DEFB  27,"[0mCopyright (c) ",27,"[0;1;33m1994",27,"[0m by C.P.U."
	DEFB  " and ",27,"[0;1;33m1997",27,"[0m By : NYYRIKKI"
	DEFB  13,10,10
	DEFB  27,"[0;1;33mADIR",27,"[0m is ",27,"[0;1;33mP",27,"[0mublic "
	DEFB  27,"[0;1;33mD",27,"[0momain!",13,10,10
	DEFB  "Usage:",13,10
	DEFB  27,"[0;1;33m  ADIR [filespec] [/H] [/W] [/D] [/P] [/S] [/2] [/?]"
	DEFB  27,"[0m",13,10,10
	DEFB  "Purpose:",13,10
	DEFB  "  Displays the names of files on disk in different colors"
	DEFB  13,10,10
	DEFB  "Options:",13,10
	DEFB  27,"[0;1;33m  /H",27,"[0m   Shows hidden files as well",13,10
	DEFB  27,"[0;1;33m  /W",27,"[0m   Shows wide list",13,10
	DEFB  27,"[0;1;33m  /D",27,"[0m   Shows directories in wide list",13,10
	DEFB  27,"[0;1;33m  /P",27,"[0m   Pauzes at bottom of screen",13,10
	DEFB  27,"[0;1;33m  /S",27,"[0m   Shows also files inside directories",13,10
	DEFB  27,"[0;1;33m  /2",27,"[0m   Displays files in two columns",13,10
	DEFB  27,"[0;1;33m  /?",27,"[0m   Shows this help screen",13,10
	DEFB  10
	DEFB  "  See ",27,"[0;1;33mHELP ADIR",27,"[0m for more information!"
	DEFB  13,10,10,"$"

; Variables for /S parameter

PRED	DEFW  0

AIX	DEFW  FIB2-64

SIX	DEFW  FIB2
SDE	DEFW  0

TNUMB	DEFW  0
TTOT1	DEFW  0
TTOT2	DEFW  0

TXT	DEFB  "A:\"
	DEFS  128
STNAME	DEFS  13

FIB2




                  