                         Catalogue



[ This program was only a small part of the article, which

  was part of Your Computer's "Microdrive File" series.

  Below I've only copied the part that was relevant to

  the program itself. I've appended a note at the end,

  which should be read before running this program. ]



[This program] is an example of what can be done using the

routines in the new ROM. It gives you a greatly improved

catalogue of all files on a Microdrive cartridge - see

figure 1 for an example. This catalogue contains details of

every file on the tape, including "secret" files saved with

a CHR$ 0 as the first character of their filename. [Y]ou

can load it with

        LOAD *"m";1;"Cat" LINE 10

To try out the routine, put a test cartridge into drive 1.

If you have made a mistake in the machine code [I hope

not!] there is a risk that the routine might go haywire

and corrupt your files, so use a cartridge for your first

test where this won't matter too much! Run the routine with

the command RANDOMIZE 1*USR 64000, and the catalogue should

appear.

  If CHR$ 0 has been used in the name of a secret file, it

is printed as a copyright symbol and secret files always

appear at the beginning of the listing. If any other non-

printable characters have been used in the name - for

example, CHR$ 1 - they appear as a question mark. It will

take longer to produce this catalogue than the normal one,

because a lot more information has to be read in from the

tape.

  If there is more than one screenfull, the routine will

stop and give the "Scroll?" query. If you press any key

except N or space, the catalogue will continue.

  To catalogue files on a different drive, use a different

number after RANDOMIZE - for example RANDOMIZE 2*USR 64000

looks at drive 2. If you miss out the drive number, or use

an invalid number, you will get an appropriate error

message.

  The routine is not relocatable, and it also uses 600

bytes from address 64523 as a data area.

___________________________________________________________



  Figure 1. Example of catalogue.



 Tape 5



 hush-hush

 secret    LINE 10

 catcode    CODE 64000,523

 chararray  DATA Z$

 database   LINE 1

 info       PRINT

 numbarray  DATA N

 testprog



 86

___________________________________________________________



[ Catalogue is supplied on an .mdr file, which also

  contains a number of small files of various kinds, so

  you have something to try it on. The loader for the

  routine is called "Cat"; the machine code itself is

  "catcode".

    When I first ran this program, it reset the machine.

  Luckily I'd just come across a similar problem, so it

  was relatively easy to diagnose and solve the problem:

  this code, though it does use some hook codes, also

  calls absolute addresses in the Interface 1 ROM.

  Unfortunately, it calls addresses which changed between

  issues of the IF1, and it assumes a different issue

  than the one supplied by my emulator.

    Again, it was lucky I'd just handled a similar case,

  because I had a program ready to patch the code to work

  with newer ROMs. In fact, the code present on the .mdr

  is the patched code; the original code, should you have

  a version 1 ROM, has been preserved as "catcdorig".



  However, all is still not well. There is still a bug in

  the code: it will print a catalogue, but it will miss

  some files. Why, I do not know. It may be a real bug

  in the original code; it may be a genuine difference

  between IF1 ROMs which cannot be handled by simply

  calling the ROM routines at different addresses; or it

  may very well be an oversight in my attempt to patch

  the issue 1 addresses.

    There is certainly a suspicious call in the code:

  near the end (address 64511, for those willing to poke

  around) there is a call to an address which is _inside_

  a LD LD BC,(SECTOR) command, but just happens to point

  to the byte of SECTOR's address which is C9, i.e. RET.

  This is obviously not what was intended, but because it

  doesn't crash, it lets Catalogue _mostly_ work. There

  are at least two obvious ways to patch this and several

  non-obvious ones. I've tried them all, and none seem to

  do the trick. Maybe someone else can spot what I've

  overlooked.

                                   Richard Bos, May 2012. ]