Date: Wed, 23 Apr 2025 10:47:14 -0500 (CDT) Subject: Getting back on TRK00 Since recuperating from shoulder surgery means I can't do a lot of physical activity, for the last month or so I've been watching a LOT of stuff on the YouTube on our network-enabled TV. I ended up watching a number of retro-computing channels and it made me nostalgic. So, I managed to dig out the Davidge DSB-4000 that a friend gave me back in the mid-1990s and scratched out enough horizontal surface to set it up. The next several days were spent turning the house upside down trying to find the boot disks. The DSB-4000 is the machine for which I developed a BIOS extension to let CP/M use the RehDesign GIDE interface which sandwiches between the Z80 and its socket on the main board. It still needs to boot from floppy. When I found the disks, I was dismayed to discover that the 3.5-inch disks wouldn't boot and I had a "720K" 3.5-inch disk as drive A:. I had a 5.25-inch 80-track DD drive as B:. Swapping the drive-select settings to put the 5.25-inch disk at A:, the 5.25-inch media booted! Furthermore, the 3.5-inch disks still had intact data on them--just the system tracks had "faded". I was able to re-write them with the Davidge FDGEN utility and they now boot. I'm still sorting my way through the disks as some have different requirements and features. It's been 30 years since I messed with that stuff and I'm having to re- familiarize myself with nearly everything. ----- Date: Fri, 25 Apr 2025 22:17:19 -0500 (CDT) Subject: Re: Getting back on TRK00 So, I've been getting my retro-computing fix working towards getting the Davidge to boot from the hard disk. (Damnit! When using WordStar, I have 'vi' fingers; now using 'vi', I have WordStar fingers...) As a first step, I reworked my "IDEGEN" utility to correct a major oversight--I'd only ever written CCP+BDOS to the hard disk system tracks in the past. Now I have it writing the full system image (less boot sector). To test it, I'm trying to cram my IDE disk reading code into 128 bytes so the ROM will load it from floppy and it will load the system from the hard disk. You'd think that using a modern *NIX system and a graphical terminal would have no problem keeping up with a 9600 baud console, but you'd be wrong. Or rather it's not speed, it's the peculiarities of XTerm/URxvt/etc.'s "ANSI" emulation versus how a genuine Heath/Zenith H/Z-19 terminal in ANSI mode behaves. Paging/scrolling in WordStar is fraught with clutter from where the screen isn't updated. I might just have to dig out a proper terminal to save my sanity. Having to look up syntax for M80 and L80 and so forth. The M80 I have seems to have a problem with the "SET" pseudo-op. It complains about undefined symbols for anything that uses it. I worked around it with an extra symbol using "EQU" and a conditional expression. ----- Date: Sun, 27 Apr 2025 21:14:16 -0500 (CDT) Subject: Re: Getting back on TRK00 On Fri, 25 Apr 2025, John D. Baker wrote: > To test it, I'm trying to cram my IDE disk reading code into 128 bytes > so the ROM will load it from floppy and it will load the system from > the hard disk. Success! It's a mess of spaghetti code and there's no room for error handling, but it loads CP/M from the hard disk and jumps to the CBIOS (cold) boot entry. Then I realized that with some wily conditionals, the same source could assemble boot sectors for the hard disk itself, and a "chain loader" floppy boot sector (that loads/runs the hard disk boot sector). Also, conditionals for testing under a debugger. Once I had a notional boot sector for the hard disk, I needed to update my "IDEGEN" program to include writing the boot sector. While futzing around in the code, I thought I would try to make it a bit more robust and user-patchable, but not before breaking it so it wrote garbage to the disk. It took a while to get all that "state" back in my head, but I eventually got it working again. The Conner CP-342 disk I'm using operates as 5 heads, 17 sec/trk, and I forget how many cylinders, but the result is that I manage each head as a separate disk for 5 full 8MB volumes. Once I was able to restore a working system to the "disk" (head) I was using for testing, I verified the hard disk boot sector worked. Then I verified the floppy-disk chain loader; then both of them together. It worked just like I envisioned, so I changed "test" to "false" and reassembled them, patched them into copies of the system image file and IDEGEN'd the hard disk and FDGEN'd the floppy. Now, on power-up/reset the rom boots the floppy which boots the hard disk which boots CP/M. I still need the floppy disk to load the bios extension to operate the hard disk, so the next step is to extract the BIOS code from the loader program, patch it into the system image file, patch the IDEGEN program with the new length to write, and patch the boot sectors with the new number of sectors to read. As a next step, the loader code will verify the extension's presence and jump to the BIOS extension's cold boot routine. If the code isn't found, it'll check for space and load it as before. Once I can guarantee presence of the extension code in any boot scenario, the "loader" reduces to just jumping to the extension's cold boot routine. I don't have actual CBIOS source for this machine. The only such source file is just the skeleton CBIOS supplied by Digital Research. I started disassembling the BIOS I actually have way back when, but it still needs much commenting and study. Likewise, I have source for _a_ boot ROM, but not _the_ boot ROM the machine actually executes. I'd also started a disassembly of it as well (again, way back when), although I have a print-out of the actual ROM source on ancient fan-fold paper. ----- Date: Tue, 29 Apr 2025 16:20:06 -0500 (CDT) Subject: Re: Getting back on TRK00 On Sun, 27 Apr 2025, John D. Baker wrote: > I still need the floppy disk to load the bios extension to operate the > hard disk, so the next step is to extract the BIOS code from the loader > program, patch it into the system image file, patch the IDEGEN program > with the new length to write, and patch the boot sectors with the new > number of sectors to read. Well, that didn't go as planned at all... I got the image file patched with the GIDE code (or so I thought) and got the IDEGEN utility set up to write the longer image (again, or so I thought). So I detoured into some utilities I wrote in C to dump a range of cylinders/head/sectors to verify the disk contents. It appeared that nothing was being written beyond the end of the first track. That led down a path of modifying my C utility to do more error checking and provide information, which led to having to remember how to use the Aztec C development tools (and how I structured the IDE support libraries 30 years ago). I did find a blatant error in the IDEGEN program where I was writing the same value to BOTH the Cylinder-Low AND the Cylinder-High registers. Fortunately, there were no active files in that part of the disk, and for the most part a competing error saved me from corrupting the disk... To make the IDE utility programs as generic as possible, I don't bother trying to know the disk layout in advance. So, I read or write until I get a "Sector ID Not Found" error and take the appropriate action. This strategy works fine for reading, but it seems at least for the Conner CP-342 if you try to write to an out-of-range cyl/hd/sec, nothing is written, even if subsequent writes are to valid addresses. So, I fell back on the strategy I used for the "geometry seeker" utility and emprically determined the number of sectors/track using the "ID not found" error result and saved the count for later comparison so I'd know when to switch cylinders. I was already doing this to count the number of heads so I could offer the user a choice of "disk" (head) to read or write, so it was mainly a matter of duplicating the code except for which "coordinate" I was probing. With IDEGEN suitably modified, I was able to write the larger OS image past the first track. (It just so happened that the standard CCP+BDOS+BIOS fits _exactly_ in the first track--16 sectors plus boot sector.) There are still some rough edges to deal with, however. The OS image file was another puzzle--I am failing at math or something. Based on where my self-loading BIOS extension loads versus where all the parts reside in memory after a MOVCPM, the address where I loaded the standalone version of the BIOS extension should have put it in the right place, but it was 512 bytes too high. I eventually got that sorted out (I think) and the boot sector now loads the larger system image from the hard disk (ID Not Found doesn't have an adverse affect on subsequent reads). Then I wrote a simple bootstrap program in DDT that jumps to the BIOS extension's cold boot routine. With it set as the stock system's "turn-key" command in the CCP, the ROM boots the floppy which boot the hard disk which boots CP/M which activates the hard disk extension and which then stuffs a new command into the CCP to run NZCOM. There are rough edges to smooth out and I'd like to automate some of the steps--especially patching the boot sectors for which "disk" (head) of the hard disk to read and the number of sectors to read. ----- Date: Thu, 1 May 2025 09:12:38 -0500 (CDT) Subject: Re: Getting back on TRK00 On Tue, 29 Apr 2025, John D. Baker wrote: > There are rough edges to smooth out and I'd like to automate some > of the steps--especially patching the boot sectors for which "disk" > (head) of the hard disk to read and the number of sectors to read. And they got a LOT rougher before they got smoother. I almost had a catastrophe because I failed to mount a scratch monkey. At some point in my IDEGEN (re)development cycle, I got logic or arithmetic wrong and instead of reading/writing all sectors of the reserved/system tracks, it instead wrote the system image spread out on Sector 01 of every track for the given head! It almost took my source code with it! Almost. It took some experimentation to remember which of the utilities I had was a sector editor. I got even luckier that some of my IDE utilities in C weren't damaged, so I was able to use them to repair the damage to the directory blocks. The main source and .BAK files were small enough to load into DDT and patch out garbled areas so that it could be handled in an editor or with PIP. The main source and the .BAK file were both damaged, but not in the same places, so I was able to extract 2 of 3 "patches" from the .BAK file with PIP and re-inserted them with WordStar (in non-document mode, of course). The last patch came from the .PRN file created by the assembler. I had to patch it to make it readable, but it was too large to be loaded into memory with DDT. Eventually, I re-discovered PATCH.COM and was able to find non-ASCII bytes in the file and patch them out so I could extract the third patch I needed to recreate my source code. Once I had the IDEGEN source reconstituted, I started adding debugging measures--mainly conditionally-assembled dummy code that simply prints the cylinder/head/sector numbers and buffer addresses where it is expected to operate. The weird bit is that as long as both Read and Write operations were both dummies, it printed exactly what I expected. When I put the Read operation back to being the real thing, it bombed. As long as I skipped reading the system tracks (which would hang the system, the dummy write function would show the same behavior that trashed my disk before. The sector number stayed fixed at 1 while the track and the buffer address increased without bound (wrapping as you would expect). Fortunately, being dummy code, it just printed what it would have done. When my read routine was dummy code, I couldn't empirically determine the number of heads or number of sectors/track, so I just initialized those variables to the known values for my hard disk and continued. And while writing the above sentence, I finally figured out what was going wrong... The code was behaving as if there were only 1 sector/track, so when it came time to increment the sector, it thought it'd run off the end of the track and incremented the track. (But then the "bumptrk" code should have aborted the operation when the track number exceeded that of the reserved tracks--more debugging to do...) The crux of the issue is that I got sloppy and forgot that when the read routine returns, "A" is set to 1 as that's the last value loaded to be written to the Sector Count register of the IDE drive. I mistakenly saved it as "hstspt" thinking it was still the last sector number I'd saved in memory. Loading the last "hstsec" value and saving that at "hstspt" fixed that. (There was also some question about 8-bit versus 16-bit load/store and arithmetic. When I worked at VMETRO, I bitched about Lars' sloppy programming doing 8-bit stores and then 16-bit loads w/masking to read it back. You can theoretically get away with that on a little-endian machine, but when I was porting the code to run in a big-endian system (PowerPC), that bit me hard. So I had to sift through the code and make sure the data access sizes agreed for both stores and loads.) Likewise with my code. Even though there's only a single 8-bit register for the sector number (and sector count) in an IDE drive, CP/M uses 16-bit values for these data so I do as well. I made sure to initialize them appropriately, but was "cheating" by only reading/writing the LSB in the SPT-counting code (and then ignoring the result as mentioned above). Changing to 16-bit load/store (which read/wrote the _actual_ result) fixed things. Now to figure out why "bumptrk" isn't detecting access beyond the number of reserved tracks... So, using WordStar as a programming editor is frustratingly slow and its screen managment plays havoc with urxvt. I have long had VEDIT (v1.33) and used to use it when programming, but I'd forgotten how I had it configured. I was pretty sure I made it mimic WordStar as much as possible, but I needed to remember its command-mode functions. I finally got the ladder and fetched the manual down from the box where I'd put all that stuff away. I got just enough re-familiarized so I could load/save/search and it has been such a relief to use--so much faster. ----- Date: Fri, 2 May 2025 19:38:32 -0500 (CDT) Subject: Re: Getting back on TRK00 On Thu, 1 May 2025, John D. Baker wrote: > Now to figure out why "bumptrk" isn't detecting access beyond the > number of reserved tracks... A large part of that was forgetting what was a symbol definition versus a label and what they represented. Instead of loading HL _with_ the number of reserved tracks, I loaded HL _from_ the number of reserved tracks; which, being 2, meant that the program had a number of system tracks equal to IOBYTE*256 + WBOOTE SHR 8--more than the number of cylinders on the disk. The other part was me overspecifying the problem. I was trying to keep actual sector counts when all I really needed to do was read or write the system tracks in their entirety (like the sample cold-start loader in the Digital Research documentation does). So I ripped it out. (It didn't help that I wasn't computing the remaining sectors until _after_ I'd already read the first one.) Once satisfied that it was doing the right thing, I set "test" to "false" and gave it a go. It seems to do the write(!) thing. So I turned my attention back to the boot sectors and discovered why my math wasn't math-ing. Actually, my math was correct, but I forgot about a crucial issue with IDE drives. If you give it an invalid sector address, the cycle still completes with data available, but the data is that of the most recently-read valid sector. I suppose one can check for the error before reading data, or one can not advance their local buffer address so the next read from a valid sector replaces the erroneous data. I opted for the latter strategy. It's even messier spaghetti code than before and does a lot of DE<->HL jiggery-pokery, but it doesn't use the stack and fits in 128 bytes with room to spare. Testing the new IDEGEN and bootsector showed that they worked, but when I turned off test mode for the bootsector, reassembled, and patched it into an image, the boot failed with floppy disk BIOS printing its sign- on message and then garbage. It seems that the OS image files I was using got corrupted in my previous blunder and that's what was written to the hard disk's system tracks. Fortunately, I have several good copies around, so I was able to start re-patching those to generate the bootloader image for the floppy and the full CBIOS+GIDE extension image for the hard disk. Once regenerated, it works a treat! Next up, regenerate the hard disk boot sector and the chain-loader boot sector. ----- Date: Sat, 3 May 2025 08:02:37 -0500 (CDT) Subject: Re: Getting back on TRK00 On Fri, 2 May 2025, John D. Baker wrote: > Next up, regenerate the hard disk boot sector and the chain-loader > boot sector. Since the boot code is actually identical aside from load address (and number of sectors to load), for the hard-disk boot sector, I padded it so the same 128-byte sector of actual code was in the same location relative to the OS image as the standard boot sector, my full-load sector and my chain-load sector. So, there are 3 sets of relative jumps with 126 bytes of padding at the start. Should it ever be possible to generate a fully-relocatable system, MOVCPM will be able to relocate the BIOS jump addresses. The only remaining puzzle is why my math isn't mathing. Computing the number of sectors to load comes up one short, so I've been patching that in manually when I load an OS image file (or after IDEGEN with PATCH). Of course, I have to patch the head/drive selection byte as well, so it's not a big deal, but it would be nice to have that properly pre-computed. The image in memory (less boot sector) begins at 0980h and ends at 2900h (for the stock BIOS) or at 32B0 with my GIDE extension patched in. For 512-byte host sectors this gives: For the stock BIOS 2900h - 980h = 1F80h 1F80h / 200h = 0Fh ;15 512-byte sectors 1F80h % 200h = 180h ;with this much left over for 10h or 16 sectors to load, which is correct. With my GIDE BIOS extension patched in: 32B0h - 980h = 2930h 2930h / 200h = 14h ; 14h or 20 full sectors 2930h % 200h = 130h ; with this much left over for a total of 15h or 21 host sectors, except that's 1 short. And I think I figured it out. On SECID_NF, I'm skipping the buffer advance, but I'm still decrementing the sector count. I need to rearrange so it resets the sector number and bumps the track number and just goes back for another read without decrementing the count.. ----- Date: Sat, 3 May 2025 08:26:07 -0500 (CDT) Subject: Re: Getting back on TRK00 On Sat, 3 May 2025, John D. Baker wrote: > for a total of 15h or 21 host sectors, except that's 1 short. > > And I think I figured it out. On SECID_NF, I'm skipping the buffer > advance, but I'm still decrementing the sector count. I need to rearrange > so it resets the sector number and bumps the track number and just goes > back for another read without decrementing the count.. OK, that was an easy enough fix. Saves an extra byte and 17 clock cycles. Actually, it saves even more than that since instead of falling through a "jp z,ldadr", I branch directly to the code that restores the next transfer address which then branches to read another sector. And, best of all, it works and my math is mathing again. Naturally, relative branches wherever possible. If you don't care about bit tests being destructive, "and n" saves a clock cycle on a memory access versus an opcode fetch (for "bit n,r"). If the bit of interest is 7 or 0, rla/rra to push the bit into the Carry flag is only the one opcode fetch. I should extract all the duplicated stuff into appropriate macro libraries and refactor the code...