My I answer on this old thread? I even registered here in order to add what I have to say.
I stumbled about the WDTEST macro myself some days ago, and I tried to do my own investigations.
I wrote my findings an guesses on the cbm-hackers mailing list (cf.
http://www.softwolves.com/arkiv/cbm-hac ... 1585.html; unfortunately, many of the postings on this list were very OT), and I want to give the results here:
My first post was (
http://www.softwolves.com/arkiv/cbm-hac ... 31585.html):
Quote:
I am trying to understand the sources of the 1571 and 1581 drives.
In the original drive sources of the 1571 and 1581 (as found on
zimmers.net), there is a macro WDTEST:
Code:
WDTEST .macro
.ife <*!.$03
nop
.endif
.endm
I am not completely familiar with the syntax of the assembler used, but
if I understand it correctly, it issues a NOP if bit 0 and bit 1 of the
PC are both 0 - that is, the PC address is divisble by 4.
The (incomplete) listing at
http://www.zimmers.net/anonftp/pub/cbm/ ... serlib.zip seems to
confirm my assumption.
This macro is always used before the WD177x status is read (lda, bit) or
stored to the same address (WD177x command register). That is, it is
always similar to this:
Code:
WDTEST ; chk address
cmd7 lda wdstat
So, can anyone think of a reason WHY it is done this way? I cannot think
of a reason why this NOP would be needed in some cases, and why it
depends upon the address bits.
I have thought if there might be a problem if the PC is divisible by 4,
because of the sequence of the bus operation of the 6502? That is, could
it be that the WD177x accidiantially recognises a read of the DATA
register, and there would be data loss?
What do I mean?
The 6502 absolute addressing is as follows (looking into the MOS 6502
programming manual, appendix E.3):
Code:
Clock Adress Bus PC DAta bus comments
Cycle
1 PC PC + 1 OP CODE fetch op code
2 PC + 1 PC + 2 ADL fetch ADL
3 PC + 2 PC + 3 ADH fetch ADH
4 ADH,ADL PC + 3 Data fetch Data
5 PC + 3 PC + 4 OP CODE fetch new op code, execute old op cod
Now, if in cycle 4, there would be a glitch in that the ADH is already
correct, but the ADL is not yet there (but, instead, PC+3 would be
output), this might be a read (or write) to the data register of the
WD1772.
I know, this is a VERY wild guess, and I cannot think that this problem
would only occur in the 157x and 158x drives, but also with other
peripheral devices (like CIA, PIA, VIA, ...). Unfortunately, other than
that, I cannot think of any reason for these NOP.
---------------------------
Then, Francesco/Frank answered with another wild guess, saying that it might be related to using the "wrong" clock PHI1 instead of PHI2 (
http://www.softwolves.com/arkiv/cbm-hac ... 31586.html):
Quote:
wild guess:
The WD1770 in the Commodore 1571 (and I guess in the 1581 too, but
I've never seen one) has its chip select line
qualified with the wrong clock. Let me explain better: when a
peripheral device must be connected to the 6502's bus, it either has a
phi2 input
or we usually qualify the select to happen during phi2 high.
Sometimes, for example with static rams, it's usually enough to
qualify the write signal to phi2 high only.
Now, the 1571 was made when all the good engineers had already left
Commodore by a long time and to save one gate, they used phi1 LOW
OR'ed with the decoded
address range to obtain the WD1770 select.
Phi1 and phi2 aren't an inverted replica of each other. The low phase
of phi1 is LARGER than the high phase of phi2 and phi2's low phase is
larger than phi1 high phase,
that's to avoid any possible bus contention if devices use phi1 and
phi2 HIGH phases to access the same bus (like on the old dual cpu
drives for example).
Now, if one uses phi1 as "poor man's" inverted phi2, it turns out that
the chip select to the WD1770 might happen too early (phi2 not yet
high) and cause unpredictable
behaviour.
Since also the WD1770 need two address lines and they are supplied by
A0 and A1, it was probably wise to never have both A0 and A1 both low
just before a real access
to this device, since its chip select has the wrong timing and maybe
A0=A1=0 was the worst possible fake access to this device.
However, they should have corrected the hardware, not make this
software workaround.
VIA/PIA and all other native 6502 peripherals have a phi2 input, so
the address decode glue logic need not worry about qualifying the
selects against phi2 high phase.
I said it doesn't make sense, because the -CS of the WD177x is wired to PHI2 (cf.
http://www.softwolves.com/arkiv/cbm-hac ... 31591.html), and it was confirmed by Gerrit Heitsch (in
http://www.softwolves.com/arkiv/cbm-hac ... 31592.html).
Now, I believe I was wrong and I looked into the wrong floppy drive! I believe this is a problem of the 1571 only, not of the 1581! This might explain why the tests made above did not show any result!
I wrote the following (cf.
http://www.softwolves.com/arkiv/cbm-hac ... 31638.html):
Quote:
As the code is already there with the 1571, it might be a hardware
glitch that was to be prevented that does not exist on the 1581. Or it
might be something that happens very seldom.
I looked at the data sheets of the WD1770/WD1772, the 6502 and the
schematics of the 1581:
The -CS for the WD177x is generated as: -CS = -(PHI2 AND NOT -WDSEL)
(cf.
http://www.zimmers.net/anonftp/pub/cbm/ ... 581-16.gif)
with a 74LS00,
and
-WDSEL = is the output of a 74LS139 decoder with A13=A14=1 and A15=0),
connected directly to the 6502 output (cf.
http://www.zimmers.net/anonftp/pub/cbm/ ... 581-15.gif)
So, the -CS is gated directly with PHI2 through a 74LS00. The maximum
propagation delay of it is 15 ns.
For the WD177x, T_AH (address hold after -CS is going high) is minimum
10 ns.
For the 6502, the t_ADH (address hold after PHI2 falls) is minimum 30 ns.
Thus, when PHI2 falls, at most 15 ns later, -CS is de-asserted. Thus,
t_ADH of the 6502 guarantees that it will be stable for at least 15 ns,
which is enough for the T_AH of the WD177x.
I do not see any problems with this on the 1581.
For the 1570/1571, it is different (cf. marked schematics at
in the attachment):
The -CS of the WD177x is generated through a 74F32 (a 2-Input OR gate)
and pin 17 (-CS1) of the 20 pin gate array (marked in red), and PHI1 (!
- marked in green).
So, it seems that the "wild guess" of Frank is right! I did not find any
numbers in the 6502 data sheet of when PHI1 goes high after PHI2 goes
low, but it seems to be later than PHI2. It must be later, because
otherwise, PHI1 and PHI2 would be overlapping.
So, the time to react for the -CS of the WD177x is shortened. This might
explain why Commodore used a 74*F*32, which has a shorter propagation
delay (max of around 7 ns) than a 74LS32 or 74LS00, but it could be that
this is still not enough!
This would explain why the tests of the forum.6502.org thread did not
show any bad effect when the NOP was removed: On the 1581, it seems not
to be critical, but on the 1570/1571, it might be critical!
Now, I think you are more knowledgeable on the 6502 than I am. Does anyone know how long the delay of the PHI1 going high after PHI2 going low? The data sheet only says "0 ns min." for "Delay between PHI1 and PHI2", which does not help much.
Of course, even if it is a problem, it might not be a problem with all 1570/1571 drives.