Date: Sun, 25 May 2025 15:47:38 -0500 (CDT) Subject: Re: Getting back on TRK00 I thought I could hack a way to use DMA interrupts while debugging by plugging in the known IVL byte the BIOS uses since it just resets the DMA and RETI. I was able to trace operation up to the HALT instruction, then nothing. My guess is that as soon as I enabled the DMAC, it acquired the bus, transferred the data, interrupted and the ISR ran all before my HALT instruction was ever fetched. So, it's sitting halted with nothing to wake it up. So, unlikely to be able to use DMAC interrupts with the IDE disk. As long as I do my little polling loop, it seems to work. Re-reading some of the IDE interfacing articles that got me involved with this project in the first place, I realized I should always check the BSY bit of the status register before anything else, then check the ERR bit and, if set, handle that before anything else. Even if you told the drive to read a non-existent sector and the drive still sets DRQ, check the ERR bit before anything else. You are under no obligation to read any data available if an error is indicated. Non-destructive bit tests FTW. I made this change to the HD boot sector I wrote and it eliminates having to save the current xfer address since the data from the bogus read is never actually transferred. When experimenting with my chain-loader boot sector for the floppy, I realized there was only one byte of variable data needed, so I made sure to locate it as the very last byte of the sector. The idea is to tell the hard disk boot sector which "disk" (head) it was loaded from so it will load the system from the same one. My nascent boot ROM does the same (although it will need to be updated to the new scheme). The floppy and HD full-loader boot sectors need 3 additional bytes of variables, so they now come before the "disk"/head variable. I was thinking about multi-sector reads (Sector Count register >1), but I'm not sure I can use them since the disk pauses between each sector to do the BSY/DRQ dance rather than just transfer n*512 bytes directly. I think that might be what the {READ,WRITE}_MULTI commands do, but I don't have much documentation on those. So then I started playing around with loading the system from the hard disk using the DMAC. A key feature is the "Continue DMA" command. After initial setup, the address counters remain at whatever the next tranfer address is so one only needs issue the "Continue" command, load a new byte count and any other options (like forced RDY) and start the DMA. This overflowed 128 bytes, but it's for the hard disk boot sector, so that's OK. It seems to work great in testing, but something's not right when I try to use it for real. I get the FD-4000's sign-on, then the GIDE extension's sign-on, but then it looks like the monitor prompt displayed on the terminal. Something is reading characters and responding, but I don't know what it is. ----- Date: Mon, 26 May 2025 08:02:11 -0500 (CDT) Subject: Re: Getting back on TRK00 On Sun, 25 May 2025, John D. Baker wrote: > So then I started playing around with loading the system from the hard > disk using the DMAC. A key feature is the "Continue DMA" command. > [...] > It seems to work great in testing, but something's not right > when I try to use it for real. I get the FD-4000's sign-on, then the > GIDE extension's sign-on, but then it looks like the monitor prompt > displayed on the terminal. Something is reading characters and responding, > but I don't know what it is. So that brings up another possibilty. After loading the system instead of jumping to BOOT:, deliberately jump to the Monitor since it's still in memory and unmolested at this point. I went back to my binary image of the D3115 ROM to find the entry point (I should check that my re-creation of the D3115 source matches--my custom ROM, if I ever get around to burning it, will have a different entry point). ----- Date: Mon, 26 May 2025 08:19:25 -0500 (CDT) Subject: Re: Getting back on TRK00 A friend asked: > I would be interested to know how much time your "little polling loop" > takes up. > I know that you write good software, but I have seen some really crappy > ones come out of Micro$oft. Considering what I've seen in testing, nearly 0. Once I start the DMAC, it grabs the bus and everything happens before the next instruction fetch. Back when I had retry counters on it, they never decremented unless something went wrong with the DMA operation. ;Before writing to IDE registers: iWtRdy: in a,(iRgStat) ;get status rlc ;BSY bit to Cy jr c,iWtRdy ;brif still busy ;After writing the command byte to the IDE Cmd register: iWtDrq: in a,(iRgStat) ;get status bit 7,a jr nz,iWtDrq ;brif still busy bit 0,a jr z,chkDrq ;brif no error if chain jr cold ;start over if error else jr chknf ;see if it's one we handle endif chkDrq: and 8 jr z,iWtDrq ;brif no data yet ;After starting the DMAC: iWtDma: in a,(iRgStat) bit 7,a jr nz,iWtDma bit 0,a jr z,chkDone ;brif no error jr cold ;else start over chkDone: and 8 jr nz,iWtDma ;brif data unread ----- Date: Wed, 28 May 2025 10:58:26 -0500 (CDT) Subject: Re: Getting back on TRK00 So, email has resumed working. (At least the POP3S part has. This will be a test of whether the SMTP part is working.) On Mon, 26 May 2025, John D. Baker wrote: > So that brings up another possibilty. After loading the system instead > of jumping to BOOT:, deliberately jump to the Monitor since it's still > in memory and unmolested at this point. I went back to my binary image > of the D3115 ROM to find the entry point. So, I did just that. Nothing looked amiss, but G produced the same result. So combining my Block I/O boot sector and my DMA boot sector into one test program and using the STRNCMP function I learned from the FD-4000 BIOS, I discovered that the DMA boot sector is dropping a byte. It's at a weird place, too You'd expect it maybe at a sector boundary, but it's 136 bytes into a sector. Also, it's the second sector of track (cylinder) 1, when I'd expect trouble between the track0->track1 switch. The handling of the IDE disk is identical in each case. Wait for not BSY, set up the cyl/hd/sec, sector count and send the command. Then wait for not BSY, check for error (if error, handle it and start over) wait for data. The data read operation is the only thing that differs. For Block I/O, just a pair of INIR instructions reads 512 bytes. For DMA, an OUTI instruction sends the ENABLE DMA command to the DMAC. After the DMA, the IDE status register is again polled to make sure the data have all been read. Then the sector number is incremented, the count is decremented--in the case of DMA, the CONTINUE command is sent--and the read operation is repeated until the sector count reaches 0. There are some refinements I can make now that I've been able to read a Z80 peripherals manual that doesn't have translation challenges. (instead it has OCR challenges). ----- Date: Wed, 28 May 2025 22:12:53 -0500 (CDT) Subject: Re: Getting back on TRK00 A friend asked: > OCR challenges? Really? Hmm. Maybe not. Maybe just typographical errors reading from a poor original. At one place in the DMAC section of the Z80-Family peripherals user manual, what should have been "DMA" is printed as "DIVA". In a diagram showing the hierarchy of WR4, bits 2,1 of the IVL byte can change with the "Status Affects Vector" option, but all bit combinations are shown as "0 0". This is in the copy I just downloaded directly from Zilog.com. I did learn that to use the "Continue DMA" command one does not have to load a new byte count. There's a difference between the transfer length one programs and the actual byte counter. The byte counter starts at 0 and counts up until it reaches the value programmed via the init string. The Continue DMA command clears the counter back to 0, which is exactly what is needed. The Forced RDY is disabled on various conditions including end-of-block and when the DMAC releases the bus, so of course one must include it in the command stream to use the Continue DMA function. ----- Date: Fri, 30 May 2025 11:02:47 -0500 (CDT) Subject: Re: Getting back on TRK00 On Wed, 28 May 2025, John D. Baker wrote: > So combining my Block I/O boot sector and my DMA boot sector into one > test program and using the STRNCMP function I learned from the FD-4000 > BIOS, I discovered that the DMA boot sector is dropping a byte. It's > at a weird place, too You'd expect it maybe at a sector boundary, but > it's 136 bytes into a sector. Also, it's the second sector of track > (cylinder) 1, when I'd expect trouble between the track0->track1 switch. Even weirder is that less than a sector later, it's back in sync and the rest of the data compare exactly. > There are some refinements I can make now that I've been able to read > a Z80 peripherals manual that doesn't have translation challenges. I misunderstood the difference between the user-accessible registers versus the internal registers the DMAC uses during operation. That the "Continue DMA" command clears the Byte Count Register to 0 doesn't mean one must load a new byte count. The Byte Count Register always starts at 0 and increments and is compared to the tranfer length that was programmed. So, that's 3 bytes I don't need to send (WR0 base register word + 2 bytes of length). Nothing I did made things better--in fact everything I've tried so far seemed only to make the data loss occur earlier in the stream. So, I've been looking back at IDE interface documentation to see if there's something there that might help. So far, the only thing I've played with is using the Read Verify Sectors command (40h, 41h w/o retries) for doing head/sector/cylinder counting instead of a standard Read Sectors (20h, 21h w/o retries) since the Read Verify Sectors command guarantees no data transfer. So, I've gone through another round of debugging, first loading A _from_ 0040h instead of loading A _with_ 40h, then twisting my READY, DRQ, STATUS and ERROR routines around to make them more robust but breaking them first and trying to figure out why it's off in the weeds. Realizing that if one is interested in an error condition one must read the ERROR register to clear it even if you don't care what the exact error is. I think I have the IDEGEN program back in working order--still running in test mode for now (reads are real but writes are simulated). ----- Date: Fri, 30 May 2025 18:50:18 -0500 (CDT) Subject: Re: Getting back on TRK00 On Fri, 30 May 2025, John D. Baker wrote: > of loading A _with_ 40h, then twisting my READY, DRQ, STATUS and ERROR > routines around to make them more robust but breaking them first and > trying to figure out why it's off in the weeds. Realizing that if one One thing I realized is that the strategy for the ROM code is not really appropriate for the IDEGEN utility. In the ROM code, any error condition is grounds to abort the entire attempt, so my status routines check everything, looking for an error condition. In the IDEGEN utility, when we're counting heads or sec/trk, an error is expected, but only one particular error (SECID_NF)--any other is outside the scope of what we can handle. I at first had put in my Swiss-Army-Status-Routines, but then realized I needed to differentiate between different types of failure. I've made some progress there, but I'm still pondering how to approach the issues. First and foremost, Wait for Not BSY (iWtRdy) is key to everything. Until the BSY bit the in status register is reset, the most recent command written to the Command Register is not finished, no other register contents can be considered valid, and the Task File registers must not be written to. The examples I cribbed my original implementation from simply looped until the bit was reset. Paranoid about entering an endless loop, I wrapped a counter routine around polling the BSY bit but I'm still pondering what it means for the routine to return a result meaning the drive is still busy and what the caller should do when it gets that result. Even more troublesome is when the caller is a fairly low-level routine (the one that sets up the Task File registers for the next operation). Maybe that's the answer--only call iWtRdy from a routine that will actually be sending a command byte. Then, the low-level setup routine doesn't have to and the upper-level routine handles the case of the drive still being busy. That's likely the answer to the other status routines (iWtDrq, iChkErr, iErrTyp) as well. Don't check the BSY bit yourself, if the upper level routine determines it needs your services, it will have done that before calling you. Also, an issue of unifying the results of status routines that return a error/no-error result. In the past, I simply used whatever mechanism was most convenient--rotate a bit to the Carry flag or AND with a mask of the bit of interest, so you had to know how error/no-error was indicated depending on which status routine you used. With the introduction of the counters around polling BSY (and DRQ), I've since implemented a Bourne-shell-like mechanism where the routine returns A=0,Z=1 for no error and A=FF,Z=0 for error. (Now that I think about it, I believe routines like CP/M CONST do the opposite--actually, I need to look at the CBIOS source reconstruction to see how they do their status routines. It would be good to have consistent style.) It helps to talk (write) these things out. ----- Date: Tue, 10 Jun 2025 22:09:50 -0500 (CDT) Subject: Re: Getting back on TRK00 I've been assembling my sources with microsoft M80 using Zilog mnemonics (".Z80" pseudo-op). It appears that while one may freely mix intel-style and Zilog-style pseudo-ops in either 8080 or Z80 mode, Z80 mode _requires_ using the Zilog-style "DEFL" rather than intel-style "SET". Having discovered that, I've been updating my boot-sector sources accordingly. A subtle rearrangement of data areas in my boot sector code saves an instruction and makes the boot sector more easily patchable for the number of sectors to load as well as from which "disk" (head) of the hard disk the system should be loaded. The disk/head is always the last byte as it is present in all forms of my boot sector and the number of sectors is just before it in the non-chain-loading boot sectors. This way, the IDEGEN utility can patch the number of sectors according to the number of records read from a system image file. I've decided that using the DMAC with the GIDE is not reliable enough. Perhaps in a more sophisticated implementation where the various other interface signals (INTRQ, DMARQ/DMAACK, etc) can be incorporated, the DMAC could be used, but that's not the GIDE. It only sees the world through the pins on the Z80 CPU. I've been making a few improvements to my (G)IDE ID program. I think the Conner CP-342 must predate even ATA-1 as its ID record has nothing after the model string. So far, I can parse the Configuration Word among other basic data. Re-learning the behavior of unions in C along the way. I also re-wrote my (G)IDE Geometry Seeker that empirically determines the number of heads, sectors/track, and cylinders a disk has. It uses the Read Verify Sectors command so there's never any data transfer. It prints more progress information (a '.' for every head, every sector, and every 32 cylinders scanned). When I say re-wrote, I basically typed it all in again as I don't have the source code for it on any of the disks I have. (It might be on one of the 8-inch floppies, but I don't have 8-inch drives attached right now and don't have space for them anyway.) The source only exist(ed) on an archive copy of my old web pages back when I had access to a public-facing web server. While I can play tricks with 'cu's "~<" and 'pip con:=foo' to send text from the DSB-4/6 to the UNIX host, going the other way was just too fast for the Davidge to keep up, so I hand- transcribed it all. I've since written a 'pace' utility that simply reads from STDIN and writes to STDOUT sleeping 1ms (really 10ms due to NetBSD tick frequency) between characters and an additional 1(0)ms after a newline. I haven't had a chance to try it yet, though. ----- Date: Wed, 11 Jun 2025 07:58:57 -0500 (CDT) Subject: Re: Getting back on TRK00 I stepped away for a while to think after having some disturbing run-ins with the 'SAVE' utility (writes 'n' pages starting at 0100H to the named disk file). Sometimes it would pre-pend an extra record (128 bytes) and lately, it caused a broken directory entry to be written to disk. In the stock CCP and standalone replacements like ZCPR, 'SAVE' is a resident (built-in) command. Under the NZ-COM arrangement, 'SAVE' is an external utility that relocates itself and runs at the top of the TPA so that it won't(!) clobber the image it's supposed to save. I may just have to dump NZ-COM for stock CP/M (and ZCPR w/resident SAVE) before SAVEing any memory images (patching w/DDTZ or extracting system images from the reserved tracks). Finally reading "The SCSI Bus and the IDE interface" that I bought decades ago. I put union{}foo; around elements of the ATA ID record that changed meaning between ATA-1 and ATA-2 (ATA-3 was still just a proposal at the time the book was written). Then, I had to access a union member in my ID reading/parsing utility. ----- Date: Thu, 12 Jun 2025 09:40:09 -0500 (CDT) Subject: Re: Getting back on TRK00 On Tue, 10 Jun 2025, John D. Baker wrote: > I've since written a 'pace' utility that simply reads from STDIN and > writes to STDOUT sleeping 1ms (really 10ms due to NetBSD tick frequency) > between characters and an additional 1(0)ms after a newline. I haven't > had a chance to try it yet, though. So, I tried it and it's useless because the terminal has an output buffer that only gets written when a newline appears, so I may be delaying between each character I send, but the buffer is written at full speed, so I still lose characters. At least putting the tty into "raw" mode disables "imaxbel" which inserts Ctrl-G into the data stream if I still manage to overflow the buffer. So I had to re-learn how I patched 'ZMP', a smart terminal program that supports Z-Modem transfers. Looking at it with DDTZ, I saw that I had hacked it to reserve a 256-byte fifo at the top of TPA (and created an extra level of BDOS entry indirection so ZMP wouldn't wipe it out with its own memory-sizing routine. It also does interrupt-driven receive and RTS/CTS handshaking. (I also patched the command-escape character from ESC (0x1b) to FS (0x1c) so it would operate the same way as QTERM. Still use ESC to abort a protocol transfer, however.) The first hurdle was a null-modem cable that implemented RTS/CTS. I use a lot of 4-wire phone cord for simple serial connections with DE-9 and DB-25 RJ-11 adapters and I have a lot of 6P6C RJ-11 ends. So I went to my pile of de-commissioned ethernet patch cords (those rated less than Cat5e) and found one of suitable length to make a 6-wire phone patch cord (what Cizzcoee would call a "rollover cable"). The DE-9/DB-25 RJ11 adapters all loop DTR back onto DCD and DSR, and are otherwise wired identically, so a plain patch cord of 4 wires forms a null modem and 6 wires adds RTS/CTS handshaking. After a number of false starts (and subsequent reset cycles), I got it working enough to log in to the *NIX system on its other serial port. I could have sworn I got better performance out of it when using a high-speed modem, but even with handshaking it drops characters above 9600baud and protocol transfers have to do lots of retries at 19200 and above. It may be that the tty on the *NIX system isn't really doing RTS/CTS even though I told it to. Zmodem receive works OK, but sending fails. Ymodem send works fine. Using the 'lrzsz' package from NetBSD pkgsrc which provides [XYZ]-modem protocols. I dug around in my stash and found my Big Box O'EPROMs. There are loads of 27x64/128/256/512, but precious few 2716 or 2732. I could wire up the larger EPROMs to run in the 24-pin socket, but I don't know if there's room around the socket on the board for the overhang at the front. I also poked briefly at the Davidge FDGEN utility for writing the OS image to the floppy disks. One of the first things it does is read the Warm Boot address from 0001,2 and assumes that it points to the floppy-disk BIOS. It proceeds to copy some disk timeout values from known offsets from the beginning of BIOS, so with my IDE bios having swapped the jump table to let me hook into the disk-related routines, the floppy-oriented utilities won't work. Since the first page of the BIOS is also where the interrupt vectors live, I could hack it to get the correct high byte from the Z80 I register (ld a,i [or ldai in the "Z80.LIB" macro definitions from DRI]). Hmm. Now that I think about it, since I swapped the jump tables, I should preserve the FBIOS's entry point since it will go to the HBIOS first anyway... This may have been a long-standing (30 years) bug...