;---------------------------------------
;Directory to mem reader (c) Brush/Esm
;---------------------------------------
;This progy reads directory to ram and
;make a bit of order in it (you surely
;know how messed is directory file with-
;out any filtering).
;---------------------------------------
;-maximum number of files on disc is $90
;so buffer size (the 'buf' label) is
;$1200.
;-you can ofcourse use all wildcards
; (*,?) and patterns (prog*,d?pa), just
; put them into the dir name just after
; ':'! ('name' label).
;---------------------------------------
;Directory foramat looks like this:
;1.header line:
;   '"the name of disc" id123@@@@@@12'
;          ^              ^    ^    ^
;        disc name      discid     
;                                  
;                         not used  
;                        blocks free
;2.file line:
;
;   '12 "the file name   " prg c@@@@@'
;    ^         ^            ^  ^  ^
;file len.  filename    extens.  
;                                  
;                    lenght of name 
;                                   
;                               unused
;3.The end of directory is marked with
;  double $ff on the file len. position.
;---------------------------------------

dst      = $fb
buf      = $2000


         *= $1000

         lda #<buf
         sta dst
         lda #>buf
         sta dst+1
         lda #$12
         ldx #<name
         ldy #>name
         jsr $ffbd
         ldy #$60
         lda #$08
         ldx #$08
         jsr $ffba
         jsr $ffc0
         ldx #$08
         jsr $ffc6
         ldx #$07
         jsr $ffcf
         dex
         bne *-4
         ldx #$18
omi2     jsr $ffcf
         jsr wstaw
         dex
         bne omi2
         lda dst
         clc
         adc #$08
         sta dst
         lda dst+1
         adc #$00
         sta dst+1
dir2     jsr $ffcf
         jsr wstaw
         ldx $90
         bne close
         ldx #$1f
omi5     jsr $ffcf
         jsr wstaw
         dex
         bne omi5
         jsr porzadek
         bcs close
         jmp dir2
close    lda #$08
         jsr $ffc3
         jsr $ffcc
         rts

;---------------------------------------

porzadek ldx #$19
         lda #$20
omi40    sta bufer,x
         dex
         bne omi40
         ldx #$1f
         lda #$00
omi31    sta bufer,x
         dex
         cpx #$19
         bne omi31
         lda dst
         sec
         sbc #$20
         sta dst
         lda dst+1
         sbc #$00
         sta dst+1
         ldy #$05
         lda (dst),y
         cmp #$42
         bne normal
         ldy #$03
         lda (dst),y
         sta buf+$1e
         iny
         lda (dst),y
         sta buf+$1f
         ldy #$1f
         lda #$00
omi30    sta (dst),y
         dey
         bpl omi30
         ldy #$00
         lda #$ff
         sta (dst),y
         iny
         sta (dst),y
         sec
         rts

normal   ldx #$00
         ldy #$03
         lda (dst),y
         sta bufer,x
         iny
         inx
         lda (dst),y
         sta bufer,x
         inx
         iny
         lda #$20
         sta bufer,x
         inx
         lda #$22
         sta bufer,x
         inx
omi6     lda (dst),y
         cmp #$22
         beq omi43
         iny
         jmp omi6
omi43    lda #$00
         sta licz
omi13    inc licz
         iny
         lda (dst),y
         cmp #$22
         beq omi7
         sta bufer,x
         inx
         jmp omi13
omi7     sta bufer,x
         ldx #$15
         lda #$20
         sta bufer,x
omi10    iny
         lda (dst),y
         cmp #$20
         bne omi9
         jmp omi10
omi9     ldx #$16
         sta bufer,x
         iny
         inx
         lda (dst),y
         sta bufer,x
         iny
         inx
         lda (dst),y
         sta bufer,x
         lda licz
         inx
         inx
         sta bufer,x
         dec bufer,x
         ldy #$1f
omi14    lda bufer,y
         sta (dst),y
         dey
         bpl omi14
         lda dst
         clc
         adc #$20
         sta dst
         lda dst+1
         adc #$00
         sta dst+1
         clc
         rts

;---------------------------------------

wstaw    ldy #$00
         sta (dst),y
         sta tymcz
         inc dst
         bne omi1
         inc dst+1
omi1     lda tymcz
         rts

;---------------------------------------

name     .text "$:*              "
tymcz    .byte 0
licz     .byte 0

;---------------------------------------
bufer    .text "                "
         .text "        "
         .byte 0,0,0,0,0,0,0,0

;---------------------------------------

