CATRUN V2.0
Implemented by norecess464 2023-2026.
-=-=-=-=-

CATRUN is a simple tool for the Amstrad CPC machines to fasten the process of disc's content discovery / launch a program.

When inserting a new disc into the machine, I bet than 95% of the regular Amstrad CPC users will first type the CAT command to discover its content, then type RUN"FILENAME to launch a targeted program.

With CATRUN, the user can press CTRL+TAB (or SHIFT+TAB for 464 owners) at machine startup (or any other time, of course) to show the list of files stored on the disc, then use the arrow keys to select the targeted file to execute, then press RETURN/ENTER/COPY/SPACE key to auto-type the RUN command. Few key presses are saved in the process, while enhancing (a little bit !) the launching experience.

While selecting a file, it's also possible to:

* use H key to print the program help (the first |CATRUN after the machine starts reminds it: "Press H for HELP!")
* use ESC key to just get back to BASIC (cf. discard the RUN command)
* use TAB key (or Control+Tab, Shift+Tab on a 464) to redo a catalogue discovery (cf. when the user is willing to change disc and rebrowse its content)
* use R key to rename the selected file
* use D key to delete the selected file (UniDOS: a folder too, with everything in it, even when it is not empty)
* use A or B key to switch current drive to A: or B:
* use L key, when the AmStudio ROM is there (its |TE found; else L does nothing and the help doesn't show it), to load the selected files into AmStudio (none selected: the file under the cursor; the folders are skipped). CATRUN calls |TE,"FILE1","FILE2",... itself (on a 464 too) and AmStudio sorts them: a text file is opened in a document, a binary file is loaded into the memory at an address AmStudio asks (its length shown in decimal and in hexadecimal; RETURN: its own address, ESC: not loaded), another file (a BASIC program...) is refused ("Not a text file"); then the edit mode on the first text file
* use U key to change the user number (0-15) with |USER, then the catalogue of that user is shown (AMSDOS only, not under UniDOS)
* use S key for multiselection (Control+A selects all the files shown: a catalogue holds 146 entries at most, 92 of them on the screen). You can combine that with the delete, copy, move and AmStudio (L) operations.

Starting V1.2, if UniDOS gets detected:
* the folders are listed first, then the files (each in the order the DOS gives)
* use CLR key to navigate to root folder
* use DEL key to navigate to parent folder
* use RETURN/ENTER/COPY to navigate into a sub-folder
* use N key to create a new folder
* use P key to change the device of the current drive: CATRUN lists the devices UniDOS knows that have a medium (SD:, UMS:, DFA:, TAPE:..., with their descriptions, as |DRIVE shows them), you press its number (ESC: cancel) and CATRUN calls |DRIVE,"A","SD:" (or "B"); the catalogue of the device is shown
* use C key to copy a file or a folder (with everything in it, its sub-folders too) to the other logical drive, and M key to move it there (copied, then the original deleted, only when everything was copied); both can be combined with S key (multiselection). A copy stops at the first file not copied ("Not all done")

And that's all :)

* supports both MODE 1 and MODE 2. If the current video mode is MODE 0, then a regular CAT will be applied and the user will get back to BASIC
* to be available system-wide from the BASIC prompt, this program is distributed as a ROM to be installed on a ROMBoard (X-MEM, FlashGordon, etc.)
* the ROM reserves a single byte of RAM below HIMEM (it remembers that "Press H for HELP!" was shown). The Control+Tab (Shift+Tab on 464) shortcut uses its own keyboard expansion token (141), so Control+Enter still types RUN" as usual.
* if another ROM already filled the keyboard expansion buffer (UTOPIA defines 10 keys, for example), CATRUN moves all the expansions to a bigger buffer at the top of the RAM (about 230 bytes below HIMEM) instead of losing its shortcut. ROMs are initialised from the highest slot number down: with UTOPIA, put CATRUN in a lower slot number than UTOPIA, otherwise UTOPIA finds the buffer full and loses its last key (|ERA,"*.BAK").
* if the shortcut still can't be installed, the startup message only shows |CATRUN.
* the catalogue is read into a 2K buffer taken at the top of BASIC's free memory (just like BASIC's own CAT does): the BASIC program, its variables and its strings are never touched. With less than about 2.3K of free memory (or when the free memory lies below &4000), CATRUN says "Not enough free memory" and gets back to BASIC. Copying/deleting selected files needs 4K more.
* if the catalogue on disc appears to be a CATART, then a regular CAT will be applied and the user will get back to BASIC
* if the catalogue appears to be impossible to browse for whatever reasons, then a regular CAT will be applied and the user will get back to BASIC. This happens for example with the (great!) Duke's M4 expansion not behaving internally like the regular CAT from Amstrad -- for programmers: the 2K buffer not being populated by CAS CATALOG.
* generally speaking, this program refers only to the firmware routines. It provides full compatibility between 464, 664 and 6128 Amstrad CPC machines (tested)
* the commands (delete, rename, copy, folders, drives) call the DOS/ROM commands (|ERA, |REN, |COPY...) directly instead of typing them at the BASIC prompt, so they work the same with the 464's BASIC 1.0. Only RUN" is typed.
* a test is done to ensure that the call of |CATRUN is made from the BASIC prompt: typed in Protext's command mode, CATRUN does nothing (it touches no memory there; Protext has its own CAT)
* UniDOS-specific: the current drive and its path get displayed on top of all printed catalogues ("A: PI:GAMES/")
* UniDOS-specific: a folder (shown [DIR]) is a read-only entry of 0K; without UniDOS such an entry is a normal file
* the catalogue lists the entries fitting on one screen: up to 48 in MODE 1 (MODE 2 is used from 43 entries) and 96 in MODE 2. Bigger folders show the first 92 entries and "(+ N more entries not shown)"
* sizes are shown in K up to 999K, then in M (rounded)
* the build date is displayed in the Help
* Doesn't assume AmsDOS is at ROM7
* internally relies on a "fast print routine" (faster than the standard Amstrad one).
* when displaying a catalog, CATRUN will try to pre-select an executable file, based on filename (thanks Eto/Prodatron!):
 * if it finds a file "disc."/"disk."/"disc.bas"/"disk.bas"/"disc.bin"/"disk.bin"
 * and if not, if it finds the first "*. "
 * and if not, if it finds the first "*.bas"
 * and if not, if it finds the first "*.bin"
 Very useful, most of the time it's accurate. A folder is never pre-selected ("menu." and "menu.bas" are tried after "disk.bin").

Some extra-testing has been achieved by Poulette73 (thanks!) on multiple hardware configurations (cf. when Amsdos gets patched with custom file systems):

* M4 Board + USB storage is well supported
* RSF3 + USB storage is well supported
* CubeMDOS, UniDOS, ParaDOS and X-Ddos work fine too

--
Final words.
This program is useful to me. With some luck it will also be useful to you ! :)

>>norecess464.condense 2023!

Thanks to TotO, Offset, Poulette73, roudoudou & everyone else keeping the Amstrad scene alive! =)

--
CHANGELOG
V2.0 (not released yet; the differences with V1.3, the version published on norecess464.com)
The changes are big enough for a new major version: file and folder tools, and many fixes.

New
- UniDOS: C copies a folder with everything in it (its files and sub-folders), not only a file
- UniDOS: new M key: moves the selected files and folders to the other logical drive (copied, then the originals deleted, only when everything was copied)
- UniDOS: D deletes a folder even when it is not empty
- UniDOS: C and M are refused when the other drive shows the same folder, or a folder inside the one copied; a copy stops at the first file not copied ("Not all done")
- UniDOS: P key (new meaning): changes the device of the current drive (SD:, UMS:, DFA:, TAPE:...), picked among the devices UniDOS lists with a medium (|DRIVE)
- UniDOS: the folders are listed first, then the files; the first row shows the drive and its path ("A: PI:GAMES/", was "PI:GAMES/")
- the multiselection (S, Control+A) works with copy, move, delete and L, not only with delete
- new L key: loads the selected files into AmStudio when its ROM is there (|TE called with them)
- new U key (AMSDOS): changes the user number (0-15)
- SPACE runs the file too; Control+Tab / Shift+Tab refresh the catalogue inside CATRUN
- the help (H) lists the commands of the current setup and fits on one screen; it clears the cursor's bar, and its "Press a key" row is erased afterwards. The first |CATRUN after the machine starts says "Press H for HELP!"
- the catalogue is printed about 3 times faster (60 files: about 21 frames instead of 70)
- a big folder lists only the entries fitting on the screen (92 in MODE 2), then "(+ N more entries not shown)"; sizes from 100K are right, and shown in M from 1000K
- the name typed for R (rename) and N (new folder) only takes the characters every DOS accepts, in upper case, as 8.3
- a separation line (the whole row) above "Refreshing catalog...", which comes right after the catalogue or the command's question (no empty row)
- the commands (|ERA, |REN, |COPY, |LOAD, |SAVE, |A, |B, |DRIVE...) are called by CATRUN itself instead of being typed at the BASIC prompt (only RUN" is still typed)

Removed
- the P key (open with Protext): |P,"L FILE" never loaded the file (the Protext ROM ignores the name); P now chooses the UniDOS device
- E as a delete key: D only
- "catrun" typed in Protext's command mode does nothing now (V1.3 placed its catalogue buffer with BASIC's pointers, which are Protext's data there)

Fixed
- CPC 464 (BASIC 1.0): delete, rename and the UniDOS commands failed with "Type mismatch" (BASIC 1.0 refuses literal strings as RSX parameters)
- |CATRUN destroyed up to 2K (4K with multiselection) of BASIC strings: the catalogue buffer now lives in BASIC's free memory, like the CAT command's
- a disc with a blank filename (Batman Forever) made CATRUN overwrite memory above HIMEM
- with UniDOS standalone (no AMSDOS), |CATRUN froze on a blank screen
- RETURN on a file did not run it when more statements followed |CATRUN (|CATRUN:CLS) or from a program; from a program it now stops with Break, then runs the file
- Control+Enter types RUN" again (the shortcut has its own expansion token, 141); a keyboard expansion buffer already full (UTOPIA) no longer loses the shortcut
- the RUN" autotype no longer writes in the DOS' workspace, and its event is gone before BASIC runs the line
- the first |CATRUN wrote a byte in another ROM's data (or BASIC's); the ROM reserves a single byte of RAM
- the text output (TXT OUTPUT) silenced while reading the catalogue is put back exactly as it was
- the SPACE key did not run the file (while "/" did); the up arrow did nothing on entries 128 and beyond; Control+A with 16 entries or more wrote over the firmware's restarts at &0018
- the pre-selection never picks a folder; an AMSDOS file with CP/M's archive attribute, or a read-only file of 0K without UniDOS, is no longer taken for a folder
- a big folder no longer scrolls entries out of the screen (which highlighted the wrong lines)
- the ROM's name can no longer be typed as a command (|CATRUNV13 ran the ROM's init again)
- the ROM file is exactly 16384 bytes (CATRUN20.ROM; V1.3 and V1.4 were one byte short, which some ROM boards and emulators refuse)
- the build (make.sh) works on macOS and Linux, without /tmp

V1.4 (not published on norecess464.com)
- can open file with Orgams with O key (gone in V2.0)

V1.3 (20th of Dec 2023)
- fixed bugs with selection when doing an action on files
- direct calls to |ERA and |COPY RSXs for multiselection (cf. removed the limit of 9 files max. to be auto-typed in BASIC prompt)

V1.2 (5th of Dec 2023)
- 464 fix + added Shift+TAB/COPY key usage (better ergonomy for CPC 464 users)
- user can now go to Drive A or B (key A or B)
- added multiselection for file delete operations (key S to toggle select on a file, Control+A to select all).
- P key on a text file to open Protext editor
- if UniDOS gets detected:
  * current path gets displayed on top of all printed catalogues
  * user can navigate through the directory hierarchy (go to root (CLR key), go to parent directory (DEL key), go to subfolder (right arrow key))
  * user can create a new directory (key N)
  * simple file copy to the other logical drive (key C)
- minor improvements (better internal memory management, build date shown in Help, don't assume AmsDOS ROM being at ROM 7, etc).

V1.1 (17th of Sept 2023) -> First feedbacks received, adjusting few things.
- implemented pre-selection of an executable file in the catalog, based on filename (thanks Eto/Prodatron!):
 * if it finds a file "disc."/"disk."/"disc.bas"/"disk.bas"/"disc.bin"/"disk.bin"
 * and if not, if it finds the first "*. "
 * and if not, if it finds the first "*.bas"
 * and if not, if it finds the first "*.bin"
 Very useful, most of the time it's accurate. 
 Of course, user must still press RETURN key to trigger the launch of the program (cf. RUN it).
- if we are about to display more than 42 files in MODE 1, the video-mode will be automatically switched to MODE 2 (to allow more files displayed on screen)
- 2 new (unrelated) helpers, while I was at it:
 * it's now possible to press E or D keys ("E"rase or "D"elete) to delete the selected file. A confirmation gets presented to the user before proceeding.
 * it's now possible to press R key ("R"ename) to rename the selected file. ESC to cancel while entering the new filename.

V1.0 (15th Sept 2023) -> Initial release 