On Sunday, August 26, 2018 at 7:24:01 PM UTC-7, Thomas Harte wrote:
> On Sunday, 26 August 2018 20:43:08 UTC-4, John Brooks wrote:
> > Hi Thomas. Below is a grab-bag of mistakes I have seen in most //e emulators:
>
> Without even checking:
>
> > 1) GR mode with AN3 on and 80-column off should activate 4-color 140x48 mode
> >
> > 2) HGR mode with AN3 on and 80-column off should activate 4-color 140x192 mode
>
> Not implemented; currently an error. The annunciators might as well be /dev/null.
How are you differentiating HGR plus 80-col text in mixed mode vs DHGR with 80-col text in mixed mode without using AN3?
> I guess (2) puts you back to where you were with a 1977 Apple II, ignoring the delay bit (?); I can't immediately imagine how (1) would work, presumably it's the address calculation of GR mode coupled to no-delay-bit HGR serialisation?
Yes, AN3 suppresses bit 7 of each HGR byte and forces HGR pixel shift even in GR mode.
>
> > 3) 6502/65c02 P reg should have bit 5 set: PHP, PLA, AND #$20 == $20
>
> Implemented correctly.
>
> > 4) 6502/65c02 should have false reads during indexed reads & writes which affects LC bank switching and DiskII writes
>
> Implemented correctly. Though I took the 65C02's datasheet at its word that "Indexed addressing across page boundary" produces "Extra read of last instruction byte" rather than "Extra read of invalid address". RMWs will still perform read, read, write upon a correct address though, exactly as on a 6502.
>
> But in general, both processors should perform all memory accesses, one per cycle, exactly as the real ones do.
Does that include the undocumented instructions which access memory and alter registers?
>
> > 5) .DSK should make tracks of length 51024 bits == 1020484 cycles-per-second div 5 (300 RPM) div 4 cycles-per-disk_bit. Or if the emu supports adjustable drive RPM, the Apple drive spec is between 48473 bits (315 RPM) and 53,575.4 (285 RPM)
>
> There seems to be no canonical definition of a DSK; can you provide a reference for that?
No, but I may be able to provide some missing details. Based on ProDOS timing and behavior, I recommend:
370 bit Gap1: 37x $FF<00> self-sync bytes. Apple spec is 128x self-sync but most of that gets overwritten.
For each of 16x sectors:
1) 112 bit Address hdr (14x disk nibbles)
2) 70 bit Gap2: 7x $FF<00> self-sync bytes
3) 2792 bit Data
4) 200 bit Gap3: 20x $FF<00> self-sync bytes
= 3166 bits per sector
* 16 sectors
= 50656 bits
+ 368 bit Gap1 ( 2 bits of Gap1 overwritten, or use an 8-bit $FF plus 36x self-sync
= 51024 bits per track @ 300 RPM
Ideally sectors are equally spaced across the disk so that each sector has max freedom to contract/expand as it gets rewritten by drives with varying RPMs.
A 160 bit gap 3 is problematic because that 2862 Gap2+data formatted at 300RPM, when rewritten on a 315 RPM drive, will stretch to cover the equivalent of 3005 bits, overwriting 143 of the 160 bit Gap3, and likely causing the head to be out of sync and unable to read the next sector's address header.
A self-sync field needs to be at least 40 bits long to guarantee sync, hence Gap3 needs to be at least 190 bits long to remain functional after a 143 bit overwrite. I recommend a Gap3 of 200, or even 220 if you want max room per sector don't mind a minimal 40-50 bit Gap1.
Since emulators can now write .woz images and be brought back to physical machines with variable RPM drives, it's important to have the emulators create tracks that will not be corrupted if sectors are rewritten at speeds other than 300RPM, even though the emulators are locked to 300RPM.
>
> Mine is 16 sync words, then per sector: the header, 7 sync words, the sector body, then 16 sync words. So I make that 160 + 16*(112 + 70 + 2792 + 160) = 50304 bits.
>
> RPM is always exactly 300, so each bit on a DSK will last whatever length that makes. Obviously the bits on a WOZ will be whatever rate the disk image requires. And if you write data, that'll be written at the rate the disk controller writes at. So you might easily end up with multi-rate data across the track.
>
> > 6) If drive RPM variation is supported, the Apple drive spec allows up to 10% variation in nibble read speed due to a disk written at 285 RPM being read on a 315 RPM drive == disk nibbles arriving as fast as every 28.8 cycles, or as slow as 35.2 cycles. 3.6us to 4.4us per bit.
>
> No, it's fixed at 300 for now.
>
> > 7) ProDOS .DSK have VOL=$01 in sector headers, DOS 3.3 .DSK have VOL=$FE
>
> Implemented incorrectly. Always $FE.
>
> > 8) Sectors on .DSK should be skewed so each track is ~4 sectors delayed from the previous track. This is due to head step time + 36ms settle time delaying writing sector 0 by ~40ms relative to the previous track during formatting.
>
> I think this again cuts to how well defined DSK is, but this is unimplemented. It's an easy-enough fix.
>
> WOZs, of course, have no such issue.
>
> > 9) The DiskII head will step to 1/4 tracks when adjacent phases are on
>
> Implemented correctly, albeit fairly uselessly for DSKs. Correct for WOZs.
>
> > 10) DiskII head step takes time to move (~1ms per 1/4 track for half-height drives, full-height is ~1.5ms)
> >
> > 11) DiskII inner head stop is at track 36.5
>
> I very much doubt that this is working.
>
> > 12) Write/erase head width is ~0.8 track, so writing a track also writes to adjacent 1/4 tracks. When writing only on full-tracks, the 1/2 tracks typically contain the previous full track data for half their length, followed by the next full track contents for the other half length due to the disk being slightly off-center and wobbling during rotation.
>
> Not implemented. You can create a magical 140-track disk if you want.
I consider this a feature. At Datasoft in the 80s, we had disk copiers with 1/4 track heads which allowed better data density and copy protection than the stock Disk II could perform.
Personally, I'd like emulators to provide the option of 1/4 track head width or 3/4 track head width.
>
> > 13) Disk II can reads & write 81 nibbles (not just the 66 used by DOS3.3 & ProDOS)
>
> Implemented correctly. Write any old nibble you want. Just don't expect to be able to read it back correctly if it offends the automatic gain rule on adjoining zeroes.
The Disk][ can read all 81 nibbles (no more than 2 zero bits between one bits) 100% of the time, but it can read three zeroes in a row too, just not at 100%. Three or more zeroes can cause extra 'ghost' 1 bits to be injected by the read head due to over-amplification, which increases the bit-rate above 4cycles-per-bit and alters byte alignment. Though a good drive can also 'go silent' on a long run of zeroes and return nothing, dropping the bit rate below 4-cycles-per bit and also breaking byte alignment.
But in either case does the drive does not return random data every 4 usecs, though that emulation technique usually suffices for passing weak-bits copy protection checks.
>
> > 14) Disk II controller write state transition expects false-read of STA abs,X to access DiskII regs on 2 adjacent cycles: 6502 false read on 4th cycle sets controller to write mode, then 6502 write on 5th cycle writes byte to disk
>
> The 6502 performs every access exactly when it should. The original Disk II state machine is being used, unmodified, interpreted. No shortcuts. So whatever it normally requires should be required.
Good!
>
> On Sunday, 26 August 2018 21:10:34 UTC-4, John Brooks wrote:
> > I tested your emu with the latest ProDOS rev and found two problems:
> >
> > 1) Adjacent tracks are not skewed correctly, causing a sector 0 miss and extra disk rotation on every track step (visible in stuttering boot load indicator)
>
> Indeed, with DSKs there is no attempt at skew. Easy to fix.
>
> > 2) 40-column text font is correct at power-up but gets into a bad/corrupt state in Bitsy Bye making everything unreadable. If you select the 3rd program, BASIC, the font corrects.
> >
> > Here is a disk image so you can repro: ...
>
> That's curious. I guess I'm still doing something dumb.
>
> Anyway, I'll file all of the above that exist as issues on my GitHub project, which means they'll be fixed. None should be too troubling, and I absolutely want to get things right.
-JB
@JBrooksBSI