
 1000  *SAVE S.RECURCAT
 1010  *--------------------------------
 1020  MLI    .EQ $BF00
 1030  DEVNUM .EQ $BF30
 1040  BELL   .EQ $FBDD
 1050  CROUT  .EQ $FD8E
 1060  COUT   .EQ $FDED
 1070  PNTR   .EQ $EB AND EC
 1080  *--------------------------------
 1090  CAT
 1100         JSR MLI           GET CURRENT PREFIX
 1110         .DA #$C7,P.PREFIX
 1120         BCS .1            ...ERROR
 1130         JSR MLI           OPEN THE DIRECTORY
 1140         .DA #$C8,P.OPEN     AND READ FIRST BLOCK
 1150         BCS .1            ...ERROR
 1160         LDA DEVNUM        SET UP READ MLI BLOCK
 1170         STA R.DEVNUM
 1180         JSR MLI           CLOSE THE DIRECTORY
 1190         .DA #$CC,P.CLOSE
 1200         BCC .2            ...NO ERROR
 1210  .1     JSR BELL          INDICATE ERROR
 1220         RTS
 1230  .2     LDA #0       BUFFERS ON PAGE BOUNDARIES
 1240         STA NEST.LEVEL    START AT TOP LEVEL
 1250         LDY /BUFFER.ONE   POINT TO NEXT BLOCK
 1260         JSR SETUP.NEXT.BLOCK
 1270  *--------------------------------
 1280  LIST.DIRECTORY
 1290         INC NEST.LEVEL    DROP TO NEXT LEVEL
 1300  *---GET DIR DATA-----------------
 1310         LDY #38
 1320  .1     LDA (PNTR),Y           GET: BYTES.PER.ENTRY....35
 1330         STA BYTES.PER.ENTRY-35,Y    ENTRIES.PER.BLOCK..36
 1340         DEY                         FILE.COUNT......37,38
 1350         CPY #35
 1360         BCS .1
 1370  *---POINT TO FIRST FILE NAME-----
 1380         LDA #2            SKIP OVER DIR HEADER
 1390         STA CURRENT.ENTRY.NUMBER
 1400         ASL               A=4, CLEAR CARRY
 1410         ADC BYTES.PER.ENTRY
 1420         STA PNTR          POINT AT FIRST NAME
 1430         LDA #0            START FILE COUNT
 1440         STA CURRENT.FILE.COUNT
 1450         STA CURRENT.FILE.COUNT+1
 1460  *---STOP IF NO ACTIVE FILES------
 1470         LDA ACTIVE.FILE.COUNT
 1480         ORA ACTIVE.FILE.COUNT+1
 1490         BNE .2       ...AT LEAST ONE FILE
 1500         RTS          ...END OF DIRECTORY
 1510  *---PRINT FILE NAME--------------
 1520  .2     LDY #0            POINT TO TYPE/LENGTH
 1530         LDA (PNTR),Y
 1540         BEQ .8            0 = DELETED FILE
 1550         AND #$0F          ISOLATE NAME LENGTH
 1560         TAX               X = #CHARS IN NAME
 1570         LDY NEST.LEVEL    NUMBER OF LEADING BLANKS
 1580         LDA #" "
 1590  .3     JSR COUT          INDENT BY DIRECTORY LEVEL
 1600         DEY
 1610         BNE .3
 1620         LDA (PNTR),Y      GET TYPE/LENGTH
 1630         PHA               1L, 2L, 3L, OR DL
 1640         BPL .4            ...NOT DIR FILE
 1650         LDA #"/"          DIR FILE, PRINT A SLASH
 1660         JSR COUT
 1670  .4     INY               PRINT THE FILE'S NAME
 1680         LDA (PNTR),Y
 1690         ORA #$80
 1700         JSR COUT
 1710         DEX
 1720         BNE .4
 1730         JSR CROUT
 1740         PLA               GET TYPE/LENGTH AGAIN
 1750         BPL .7            ...NOT DIR FILE
 1760  *---PUSH DATA ON STACK-----------
 1770         LDA PNTR+1        SAVE POINTER IN CURRENT BLOCK
 1780         PHA
 1790         LDA PNTR
 1800         PHA          SAVE:  R.BLOCK
 1810         LDX #0              BYTES.PER.ENTRY
 1820  .5     LDA PUSH.VARS,X     ENTRIES.PER.BLOCK
 1830         PHA                 ACTIVE.FILE.COUNT
 1840         INX                 CURRENT.FILE.COUNT
 1850         CPX #PUSH.COUNT     CURRENT.ENTRY.NUMBER
 1860         BNE .5              NEXT.BLOCK
 1870  *---READ HEADER OF SUBDIR--------
 1880         LDY #$12          POINT AT KEYBLOCK POINTER
 1890         LDA (PNTR),Y      GET HIGH BYTE
 1900         TAX
 1910         DEY
 1920         LDA (PNTR),Y      GET LOW BYTE
 1930         JSR READ.NEXT.BLOCK
 1940  *---RECURSIVE CALL---------------
 1950         JSR LIST.DIRECTORY
 1960         DEC NEST.LEVEL    POP TO HIGHER LEVEL
 1970  *---POP DATA OFF STACK-----------
 1980         LDX #PUSH.COUNT   GET BLOCK OF VARS
 1990  .6     PLA
 2000         STA PUSH.VARS-1,X
 2010         DEX
 2020         BNE .6
 2030         PLA
 2040         STA PNTR          GET KEYBLOCK POINTER
 2050         PLA
 2060         STA PNTR+1
 2070         CMP /BUFFER.TWO   IS BLOCK IN BUFFER.TWO?
 2080         BCC .7            ...NO, DON'T NEED TO READ
 2090         JSR MLI           ...YES, MUST READ THE BLOCK
 2100         .DA #$80,P.READ
 2110  *---COUNT THE FILE---------------
 2120  .7     INC CURRENT.FILE.COUNT
 2130         BNE .8
 2140         INC CURRENT.FILE.COUNT+1
 2150  *---SEE IF THAT WAS LAST FILE----
 2160  .8     LDA CURRENT.FILE.COUNT
 2170         CMP ACTIVE.FILE.COUNT
 2180         LDA CURRENT.FILE.COUNT+1
 2190         SBC ACTIVE.FILE.COUNT+1
 2200         BCC .9            ...NOT LAST FILE
 2210         RTS               ...END OF DIRECTORY
 2220  *---ADVANCE PNTR TO NEXT ENTRY---
 2230  .9     CLC
 2240         LDA PNTR          GET RESULT IN Y,X
 2250         ADC BYTES.PER.ENTRY
 2260         TAX
 2270         LDA PNTR+1
 2280         ADC #0
 2290         TAY
 2300  *---ARE WE STILL INSIDE BLOCK?---
 2310         LDA CURRENT.ENTRY.NUMBER
 2320         INC CURRENT.ENTRY.NUMBER
 2330         CMP ENTRIES.PER.BLOCK
 2340         BCC .10           ...INSIDE SAME BLOCK
 2350  *---READ NEXT BLOCK--------------
 2360         LDA NEXT.BLOCK
 2370         LDX NEXT.BLOCK+1
 2380         JSR READ.NEXT.BLOCK
 2390         LDA #1            START WITH FIRST ENTRY
 2400         STA CURRENT.ENTRY.NUMBER    IN NEW BLOCK
 2410         LDX #4            SKIP OVER BLOCK NUMBERS
 2420         LDY /BUFFER.TWO
 2430  .10    STX PNTR          NEW PNTR VALUE
 2440         STY PNTR+1
 2450         JMP .2            ...TO LIST NEXT FILENAME
 2460  *--------------------------------
 2470  READ.NEXT.BLOCK
 2480         STA R.BLOCK       BLOCK # IN X,A
 2490         STX R.BLOCK+1
 2500         JSR MLI           READ THE BLOCK
 2510         .DA #$80,P.READ
 2520         LDA #BUFFER.TWO   WE USED BUFFER.TWO
 2530         LDY /BUFFER.TWO
 2540  SETUP.NEXT.BLOCK
 2550         STA PNTR          PNTR FROM Y,A
 2560         STY PNTR+1
 2570         LDY #2            GET NEXT BLOCK #
 2580         LDA (PNTR),Y
 2590         STA NEXT.BLOCK
 2600         INY
 2610         LDA (PNTR),Y
 2620         STA NEXT.BLOCK+1
 2630         RTS               RETURN
 2640  *--------------------------------
 2650  P.PREFIX   .DA #1
 2660             .DA BUFFER.TWO
 2670  *--------------------------------
 2680  P.OPEN     .DA #3
 2690             .DA BUFFER.TWO
 2700  OPENBUF    .DA BUFFER.ONE
 2710             .DA #0
 2720  *--------------------------------
 2730  P.CLOSE    .DA #1
 2740             .DA #0
 2750  *--------------------------------
 2760  P.READ     .DA #3
 2770  R.DEVNUM   .DA #$60
 2780             .DA BUFFER.TWO
 2790  PUSH.VARS .EQ *
 2800  R.BLOCK    .DA 0
 2810  *--------------------------------
 2820  BYTES.PER.ENTRY          .BS 1
 2830  ENTRIES.PER.BLOCK        .BS 1
 2840  ACTIVE.FILE.COUNT        .BS 2
 2850  CURRENT.FILE.COUNT       .BS 2
 2860  CURRENT.ENTRY.NUMBER     .BS 1
 2870  NEXT.BLOCK               .BS 2
 2880  PUSH.COUNT               .EQ *-PUSH.VARS
 2890  *--------------------------------
 2900  NEST.LEVEL               .BS 1
 2910  *--------------------------------
 2920  WASTED .EQ *+255/256*256-*
 2930         .BS WASTED
 2940  *--------------------------------
 2950  BUFFER.ONE  .BS 512
 2960  BUFFER.TWO  .BS 512
 2970  *--------------------------------

