# Displaying graphics when a disc directory is listed

There are two instructions to display a directory of a disc:

- CAT
- |DIR

The differences between these two commands are listed below.

## CAT

Example output using CAT command:

    cat

    Drive A: user  0

    CATALOG .ASM   4K   SCROLL  .BAK   2K
    HWSPRITE.ASM*  4K   SPLTSCRN.ASM   3K
    SCROLL  .ASM   2K

    163K free

    Ready

Notes:

- File names are sorted into increasing alphabetical order before display
- The file-size is displayed
- The file names are printed using firmware "TXT OUTPUT" (&BB5A) function which will execute control characters.
- A "*" character is displayed after the extension if the file is read-only. If the file is read-write then a " " (space) character is displayed.
- Hidden/system files are not displayed
- Free space remaining on disc is displayed

## |DIR

Example output using |DIR command:

    |dir

    Drive A: user  0

    HWSPRITE.ASM   CATALOG .ASM
    SPLTSCRN.ASM   SCROLL  .ASM

    163K free

    Ready

Notes:

- File names are listed in the order stored in the directory
- File size is not displayed.
- The file names are printed using firmware "TXT OUTPUT" (&BB5A) function which will execute control characters
- read-only/read-write state is not displayed
- Hidden/system files are not displayed
- Free space remaining on disc is displayed

## Displaying text and graphics using CAT and/or |DIR

The standard DATA and SYSTEM formats have 64 directory entries.

The following procedure is used to display a directory listing:

1. Display blank line
2. Display "Drive " followed by drive letter ("A" or "B")
3. Display ":" character
4. Display " user " followed by user number (the user number is displayed padded with spaces) e.g. " 0", " 15"
5. Display blank line
6. if CAT:
   - Perform directory operation and sort filenames into increasing alphabetical order
7. if |DIR:
   - Perform directory operation and do not sort
8. The following procedure is repeated for each filename:
   - Display the 8 characters of the name part of the filename
   - Display a "." character
   - Display the 3 characters of the extension part of the filename
   - If |DIR
     - display 3 spaces
   - if CAT
     - If file is read-only, display a "*" character, otherwise if file is read-write display a " " (space) character.
     - display 2 spaces
     - display file size in K, followed by "K" character

If you want the output to look identical with CAT and |DIR, follow these rules:

- List the directory entries in the order that they are "executed"
- Do not use the extra characters ("*" and file size) displayed by CAT, or the 3 spaces displayed by |DIR

Offset | Count | Description
--- | --- | ---
0 | 1 | User number (set to "0")
1 | 1 | Sort key (use the characters with ASCII codes 32-127 in ascending order)
2 | 1 | ACK control code (enable printing of characters)
3..8 | 6 | (useable)
9 | 6 | BS (to erase "." character)
10 | 1 | (useable)
11 | 1 | NAK
12..31 | 19 | not used (set to "0")