Date: Mon, 5 May 2025 15:22:25 -0500 (CDT) Subject: Re: Getting back on TRK00 On Sat, 3 May 2025, John D. Baker wrote: > I should extract all the duplicated stuff into appropriate macro > libraries and refactor the code... But instead, I dug out the printouts of the boot ROM source code and its associated assembler listing (.PRN) and have been typing away transforming the disassembly I started back in 1996 back into the source code on disk (I never had the actual source--only the printouts). I've attempted to make a faithful recreaton, including spelling/typographical errors, spacing, code style (lots of lowercase interspersed with all uppercase, etc.) In so doing, I discovered that the ROM in my board differs from the source listing by 2 bytes--the receiver mode byte for each of the first two serial ports. The listing shows "3,0E1H" which enables the receiver and sets it for 8 data bits as well as "auto-enable" which means DCD* must be asserted for the receiver to work and CTS* must be asserted for the transmitter to work. My machine's ROM has "3,0C1H", which omits the "auto-enable" bit, which I gather means the transmitter and receiver are active all the time. (I'm using an old Toshiba TLCS Z-80 databook and it has the usual translation challenges). So, I've made two versions. One that matches the printout and the other that matches my actual ROM image. A third copy I'm editing to use the macro definition libraries as well as appropriate local definitions instead of "magic numbers". I also intend to fix spelling/typographical/style issues and reformat block comments and long strings to be "email friendly" (72 columns or less). Perhaps then I'll compare it to the "4000ROM.ASM" file I have which seems to have been for later revision boards and included support for a couple of different SASI controllers that could be connected with an adapter interface (I even designed one myself some time back--if I can find my schematic I might try putting it in KiCAD...) But really, I hope to see how they managed to squeeze SASI support into an already packed 2K ROM. Then I could see about putting (G)IDE support in its place. ----- Date: Fri, 9 May 2025 03:51:37 -0500 (CDT) Subject: Re: Getting back on TRK00 On Mon, 5 May 2025, John D. Baker wrote: > But really, I hope to see how they managed to squeeze SASI support into > an already packed 2K ROM. Then I could see about putting (G)IDE support > in its place. The main thing they did was reduce the size of a number of character strings. A couple of functions that previously output a fixed sequence of characters one-by-one were changed to simply set up pointer to a string with that sequence and call (or fall through to) the string display routine. The convention that any carriage-return (0Dh) encountered in a string will always be accompanied by a line feed (0Ah) previously enforced CR,LF. For purposes of display it doesn't matter which comes first, so changing it to display LF before CR made the code simpler and shorter. The routine reading the serial port now does explicit "toupper()". I need to see if the longer input routine is offset by savings in other places. Another thing is one-time initialization code. The Davidge board maps ROM as read-only and RAM as write-only on power-up/RESET. So the first thing the ROM does is copy itself over itself so it is in RAM then switches off the ROM. For whatever reason, they chose to use 0080h as the buffer for reading the boot sector from a floppy disk. Since this is inside the area occupied by the (ex-)ROM code, the part from 80h-FFh will be overwritten with sector data. They didn't go far enough with putting single-use items in the floppy sector buffer; the entirety of the initializtion code and initial message, less a relative branch fits in the buffer with room to spare. That leaves a significant portion of the space from 00h-80h available for code and data. So, I've been grafting changes from the 4000ROM.ASM file to my heavily edited version of the "D3115" ROM image. I managed to get enough space to add in my code to load the hard disk boot sector. It was basically my chain-loading floppy-disk boot sector, but cut down even more, since it only ever has to read Sector 1 on Cylinder 0 of whatever "disk" (head) it is trying next (I abuse the ROM's retry mechanism to cycle heads and reset to 0 if an error is returned from the IDE disk). Concerned about getting stuck if the drive doesn't respond, I augmented my "WaitRdy" and "WaitDrq" routines to indicate an error if the respective bits in the status register don't indicate the desired result after 65536 tests. In the process, I learned that coding the countdown in each function was actually shorter than making it a subroutine. For testing, I substitute code of the same length that replaces jumps or calls to potentially hazardous stuff--namely the floppy-disk routines. Puzzling that the initial message display never happens. I jump over the code that initializes the I/O ports since the BIOS is already running, but any code that uses the right addresses should still be able to operate the SIOs directly. But the messages never appear. But my "ideload:" routine does sucessfully read the boot sector from the hard disk. ----- Date: Fri, 9 May 2025 21:32:03 -0500 (CDT) Subject: Re: Getting back on TRK00 On Fri, 9 May 2025, John D. Baker wrote: > The routine reading the serial port now does explicit "toupper()". I > need to see if the longer input routine is offset by savings in other > places. Doing "toupper()" (ANI 5Fh) on lowercase letters adds 13 bytes to "CHRIN:" but saves 8 bytes in "ASCHEX" and another 2 bytes in the test for a command character. So, net 3 bytes longer code. I finally got a chance to read in more detail some things added and changed. In particular, the Monitor entry point pushes its own start address on the stack and the various command functions were changed from spaghetti-code jumps/branches to RET back to the start of the monitor, or if their last operation was to use one of the other utility routines to jump/branch to it and when the utility routine returned, it started at the top of the monitor again. So it abuses the stack horribly as error exits simply jump to the error routine which jumps back to the call to display the error message which then re-enters the monitor proper, pushing its start address again. It makes me cringe, but being bootstrap ROM code, it can probably get away with this as it shouldn't be running long enough for the stack to grow all the way from the top of RAM to overwrite the bootROM code. In so doing they save a byte (JR) or two (JMP) here and there, so I suppose it adds up. Looking at it further, I think a single 1-byte instruction will keep stack operations balanced. The ERROR routine simply needs to pop the top of the stack before jumping back to before the beginning. Also, they duplicated an error exit which when eliminated will save another 3 bytes. Their ASCHEXB, ASCHEXW routines seemed fairly straighforward, but in the 4000ROM, I guess they realized they only ever use the ASCHEXB routine internally, so made it an extension of the ASCHEXW routine, but changed the input parameters to ASCHEXW by requiring HL to point to the byte _before_ the string to convert. It would only cost symbol table space to keep it "clean". ----- Date: Sun, 18 May 2025 12:56:38 -0500 (CDT) Subject: Re: Getting back on TRK00 So, having a boot ROM that can load a boot sector from an IDE drive is still not much use if the hard disk support still needs a program on floppy disk to activate it since its still entirely independent of the stock BIOS until its HBOOT routine is executed. So lately I've returned to analyzing and commenting the disassembly of the stock FD-4000 v1.3 BIOS so I can eventually integrate my IDE support. There are still a few functions and data areas to demystify, but I figured out enough to patch my GIDE extension to use the stock BIOS's message-display routine (hi-bit last character as terminator) and how to chain the extension's HBOOT routine to the floppy BIOS's stock BOOT routine. It's almost as good as a fully-integrated system. At some point I want to make that more automagic. In particular, reduce the image size by putting the extension BIOS and a small loader routine right at the end of the BIOS image and chaining to the loader which moves the code into place then jumps to HBOOT. Now that I think about it, I can't get it _too_ close to the end unless it can fit entirely in the host buffer space, or can't be placed closer than some of flag locations initialized by the final stage of the (W)BOOT routines. If my src/dest overlap, I'll have to see about moving code from the end rather than the beginning. ----- Date: Tue, 20 May 2025 08:42:12 -0500 (CDT) Subject: Re: Getting back on TRK00 I learned enough to be able to use the stock CBIOS' message-printing routines and where to patch my loader address so the stock CBIOS will run it instead of RETurning to the CCP. The loader routine and all of what used to be the BIOS extension's BOOT: routine fit easily in the space between the end of the stock CBIOS code and the data area initialized by it. The loader tests whether the destination address overlaps the code/data block to move and, if so, uses "LDDR" to move the code from back to front. As such, the BIOS extension's BOOT entry point is simply the same as WBOOT and there is no more code related to cold boot operations in the BIOS extension itself. It's as close to integration as I've come so far. I don't even need the turnkey command patch anymore, but I've left the code in and improved it so it's easy to skip if not needed. If I can burn a boot ROM, it should boot and run entirely from the hard disk. ----- Date: Tue, 20 May 2025 19:37:11 -0500 (CDT) Subject: CP/M development tools In other news: microsoft M80 is weird--at least the copy I have. It chokes on the 'SET' pseudo-op, claiming undefined symbol for anything I try to use it with. More recently, it has trouble with the MOD (modulus) operator in some contexts. Usually it works as expected, but sometimes it does something undesirable. In a few places, I want to pad the address to the next 8 or 16-byte boundary so things line up "right" when looking at them with DDT(Z) or some other file hex-dump utility, or to make it easy to find things if one must resort to patching the binary. My typical idiom is: defs 16 - $ mod 16 or defs 8 - $ mod 8 This works without issue in ASM or MAC ('ds' instead of 'defs'), but in M80, it _sometimes_ works, but mostly doesn't--it pads up to the desired boundary but then adds an additional 8 or 16 bytes besides. To get around this, I've taken to using: defs 16 - $ and (16-1) or defs 8 - $ and (8-1) So far, this has been Doing the Right Thing(tm). ----- Date: Wed, 21 May 2025 09:44:34 -0500 (CDT) Subject: Re: Getting back on TRK00 On Tue, 20 May 2025, John D. Baker wrote: > If I can burn a boot ROM, it should boot and run entirely from the > hard disk. I went back and looked at my modified "D3115" ROM source, the original, and the 4000ROM source just to be sure I didn't overlook something. My first concern was to make sure the CTC interrupt vectors fell on an 8- byte boundary, which they did. The original D3115 ROM source seemed to have arbitrarily put the CTC vectors beginning at 0048H (actually, it puts scratch space for a FDC "READ ID" command and a couple of extra result bytes at 0040H, EQUates "CTC0V" with the current location ($), computes the vectors for CTC channels 1, 2, and 3 then issues an ORG CTC3V DW CTCISR The 4000ROM code explicitly puts the CTC interrupt vectors at 0058H with a comment of "; must remain at this location" and defines a dummy ISR for channels 0-2. I went back and looked at my disassembly of the boot sector for a 64K CP/M system and saw what was going on. The ROM code itself doesn't use DMAC interrupts, only FDC interrupts via CTC3 (CTC0 ch 3), but the boot sector DOES use DMAC interrupts and sets up the DMAC interrupt vector at 0058H. In the stock D3115 ROM, this just trashes the ROM's DMA init string, but at that point it doesn't matter. The 4000ROM code, which supports booting from SASI, makes a point to put the CTC intvecs where the floppy boot sector won't damage anything (CTC0 ch 0-2 are programmed not to interupt, so the CTC00 vector can be used by the DMAC). So, I adjusted my modified D3115 ROM code to match the 4000ROM layout for the CTC vectors and rearranged some data items to fill the space between the end of the vectors and 0080h (where 1-time init code and messages live until overwritten by the floppy boot sector). There's 49 bytes of space left in that part of the ROM, and another 144+ in the part above the floppy boot sector buffer. I'd like to be able to use the DMAC for IDE data transfer. I could probably do it in the ROM code since I only have to transfer one sector. The FDC (and "high-speed parallel port"--for the SASI host adapter) can signal the DMAC in "byte-at-a-time" mode using its RDY signal (DRQ from FDC, [DATA & RQ] from SASI). The GIDE doesn't have such a connection, so I'd have to use the DMAC burst mode. In the boot rom and boot sector, I have some control over the DMAC operations, but in the BIOS itself, the DMAC interrupt vector(s) are under control of the CBIOS. I might be able to patch the ISR address and dispatch to the CBIOS DMACISR or the extension's DMACISR as necessary. I need to go back and look at the DMACISR to see just what it does. If all it does it operate the DMAC itself, it's probably harmless to use as-is and I just have to whip up my own DMAC init string. ----- Date: Wed, 21 May 2025 13:05:06 -0500 (CDT) Subject: Re: Getting back on TRK00 A friend commented: > I did not know the CTC interrupt vectors had to be on an 8 byte boundary. There are 4 channels in the CTC, so each channel can have an independent ISR. In the vector byte it supplies during the IACK cycle, bits 7-3 are the previously-programmed vector base address, bits 2,1 are set according to which channel (0-3) interrupted and bit 0 is always 0. Since CTC channel 3 has no ZC/TO pin, it is commonly used to allow arbitary LSI--the FDC or the SASI host adapter in this case--to participate in Z80 mode-2 vectored interrupts. The other channels are typically used as clock dividers/baud-rate generators for the SIO devices. The DMAC's interrupt vector can be anything and need not be aligned unless using the "status affects vector" feature where it will alter 2 bits (I forget which ones offhand) to provide a different vector address for each of 4 conditions. ----- Date: Thu, 22 May 2025 20:40:23 -0500 (CDT) Subject: Re: Getting back on TRK00 On Wed, 21 May 2025, John D. Baker wrote: > I'd like to be able to use the DMAC for IDE data transfer. I've revisited the ROM's operation of the FDC and DMAC and the stock boot sector's operation as well. In the ROM, only the FDC interrupts and its ISR just reads its own status port and stores it in a location that gets polled by the read routine. The DMAC is operated w/o interrupts and just transfers the requested length of data. After starting the DMAC, the ROM code sets up the FDC, conditions the status location, starts the FDC and sits in a tight loop polling the status location to determine when the FDC is finished. Since the DMAC only transfers data when it's RDY* input is asserted, it doesn't request the bus until the FDC signals it. The boot sector does something similar, but operates the DMAC with interrupts. Similarly (yet differently) to the ROM, the boot sector sets up the DMAC, sets up and starts the FDC and halts (instead of polling). When the FDC interrupts, the boot sector code resumes, checks status and if good, sets up the next sector to read in the FDC, starts it and halts again. Repeat until the block length programmed into the DMAC has been transferred. The DMAC ISR doesn't RETI--it reset the DMAC, stops the FDC and jumps to the BIOS BOOT entry point. I could probably use something similar to what the ROM and boot sector do with the FDC and DMAC, but using burst mode with the DMAC's internal RDY* signal. Basically, that makes it appear RDY* is always asserted, so as soon as the DMAC is started, it will transfer data in back-to-back read-write cycles until the byte count is exhausted. Once the DMAC acquires the bus in burst mode, it will not relinquish it until it is finished, so polling for status wouldn't work. So far, halting seems the most reasonable thing to do while waiting for a DMAC interrupt. Like the floppy boot sector, I could arrange to read multiple sectors from the IDE disk, although I wouldn't be able to handle SECID_NF errors after the fact--I'd have to know up front how many sectors I can read before bumping to the next track. Actually, I don't know what an IDE disk will do when you request more than 1 sector to read and the count overflows a track. I presume it continue with sector 1 on the next head of the same cylinder and only when the last sector on the last head of a cylinder is read will it go to the next cylinder. Since I manage each head as a separate "drive", I can only read sectors 2-n on track (cylinder) 0 and sectors 1-x on track (cylinder) 1. Sounds like time to hack up my utilities to experiment with multiple- sector transfers. As for the FD-4000 v1.3 BIOS, the DMAC ISR simply issues a reset command to the DMAC and the FDC ISR simply re-enables interrupts and does an RETI. I've figured out the BIOS' scheme for all the different floppy formats it supports and have been replacing fixed addresses with labels in my reconstructed source. Starting to wrap my head around some of the ancillary things involved, but need to ruminate on them a bit more. Figuring out the layout/ordering of the disk deblocking variables is being ironically difficult considering that it was my analysis of the FD-4000 BIOS 30 years ago that aided the development of my original GIDE extension. There was some clever ordering to the SEK/HST/UNA- DSK/TRK/SEC variables that made it easy to do block transfers for setup and a clever "STRNCMP" function rather than discrete loads/stores or comparisons. It isn't quite as clear today. ----- Date: Sat, 24 May 2025 05:49:35 -0500 (CDT) Subject: Re: Getting back on TRK00 So, I started playing around with my chain-loading boot sector to see if I could use the DMAC to load the HD boot sector. The Z80 DMAC documentation didn't say explicitly that the "forced RDY" couldn't be used with "byte mode" although it only referred to burst and continuous mode when discussing the forced RDY command. There's also no real description of what happens if the setup string programs contradictory options. From what I could see, the DMAC simply doesn't start. Switching the DMAC to burst mode with forced RDY seemed to work. Although in this arrangement the DMAC will only reliquish the bus at the end of the transfer, I used a polling loop that tests for the DRQ bit in the IDE status register to be 0 (previously waited for it to be 1 before starting the DMA). It seems to work. Then, out of paranoia, I augmented my polling loops with retry counters and error checks and it stopped working. I thought I'd screwed up the DMA string due to trying to make debug/non-debug code the same size in the same locations. Then, actually re-reading what I'd copy-pasta'd, I found a missed edit that sent a polling loop back to the wrong label (the loop i'd copied the code from). After fixing that, it worked again. I couldn't use DMA interrupts while debugging, so I'll have to live test that, but I basically copied what the stock boot sector does (except for handling the FDC). But I now see how to use the DMAC to load the HD boot sector from my custom ROM (if I ever get around to burning it). Probably experiment with multiple-sector IDE transfers next as that will be key to using DMA in the HD boot sector itself.