I'll spend some more thought on it, but first idea I had was that maybe the Kaypro ROM (since you are using it directly) does not realize that you had selected a different disk and so it was taking an optimization that it wasn't entitled to. I'm not sure what that might be, though. Does your code use the same 'dirbf' as the ROM BIOS (floppy)?
Was thinking along that line too, maybe the rom code takes a shortcut in calculating the DPH and since it normally only does only 2 drives and now finds a drive number of 3 in lastdrive, it gets the wrong disk parameters.
My (seperate) 'dirbuf' points to the end of my code, just beyond the sector buffer I have.
Another possibility is that 'all00' is not the right size (too small), and some memory corruption results.
While this is not going to cause any fatal problems, I do notice that your "alloc 0/1" bytes (DPB.ALV0) are reserving 4 blocks for the directory, but you are using (DPB.DRM) only 64 directory entries (which is very small for a harddisk). You reserved 4 blocks, and have specified 16K block size, so that is a total of 2048 directory entries reserved (possible, in the space reserved). The number in the DPB.DRM word defines how much work the BDOS does when scanning the directory, and the DPB.ALV0 bytes just reserve the space.
Have been fiddling with those numbers and since it is not a really big harddrive (only 10 MByte) I came up with these. Since CP/M seems to have no notion of 'heads' and to keep numbers in manageable quantities I made the following scheme:
316 cylinders
17 sectors (of 512 bytes) per track
4 heads
By incorporating the head number into the track number as bottom two bits (and since that was already a 16 bit number), head movement would be optimized for every 4 cpm tracks.
Same thing for the sector number, by shifting the sector number two bits up, I can use the bottom two bits as index for which of the 128 bytes cpm wants to read/write out of the 512 byte physical sectors.
That way the sector number is still within 8 bits and easier to code with. My bios read/write sector routines simply receive a track and a sector number. My blocking/deblocking routine is always reading/writing a whole 512 byte sector for every 128 byte cpm sector aka 'not cached' and so not optimal but since the speed is more than adequate I do not mind (yet).
Kaypro floppies reserve extra space for the system (CCP or BIOS, I forget which) and so have a similar anomaly - just much smaller discrepancy.
Yes I did find out that Kaypro floppies have the CCP/BDOS/BIOS sectors on track 0 and 1, and in a strange layout: on track 0 it uses cpm sectors 1 to 39 but then it advances to sector 16 on track 1 for the rest.
Sectors 0-15 on track 1 are for the directory. Oh, and sector 0 on track 0 is used to store some info on where to put the CCP/BDOS/BIOS in memory (so it is not a boot sector as such).
The strange layout got me puzzled as all the CP/M books just say: load in the first two tracks and you're done. So I wrote my 'getsys' program to copy the system to the first track(s) of the harddrive and just got rubbish (since the directory data got in the middle of the code..)
CP/M 2.2 generally does not perform well with huge directories, so you need to find a balance between the size of the drive (DPB.DSM) and what is practical for CP/M 2.2. Your drive size is 664 blocks (less 4 reserved), and you have a very large block size, so most files are going to fit in a single block. In order to be able to use all the drive space, you would need 660 directory entries. Of course, if a number of files will be larger than 16K then you could reduce that number.
Yes maybe I need to recalculate the DPB for the harddrive, for now it seems to work. Also CP/M does not really know how to 'format' the drive. I ended up just writing a bunch of $E5 on the directory sectors (in fact: on a large part of the disk) and started writing some files downloaded with the communication program (ST.COM) and so far it looks ok. STAT gave me about 9000k on the empty drive and now with some 35 files on it, it gives 8576k free space. Considering I wrote the blocking/deblocking code in one stretch and so far the CP/M programs I stored onto the drive seem to behave I am quite happy with that..
On the original Kaypro disks I have there is a beautiful basic (compiler) called S-Basic and it came with a pretty large demo program called XAMN.BAS, it displays the disk information it finds from the DPB(s). It compiled without a hitch on the harddisk btw.
For disk 2 (my harddisk) it comes up with this):
When selecting disk 0 or 1 it also comes up with sensible data: