News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_JonB

Interpreting uPD765 FDC result bytes

Started by JonB, 11:25, 05 April 15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JonB

According to 765 FDC - CPCWiki there are a set of status bytes returned by the FDC but I don't understand the values I'm getting following a read operation.


This is being done on a Philips P2000C which is a CP/M machine that uses the same FDC as the good old CPC. The drive is accessed via a diagnostic tool in the BIOS and it appears to be showing the status bytes after each operation.


When reading a track (track zero, side zero, drive zero) from a  floppy I am getting:[/size]40 01 00 00 00 01 01According to the service manual these are the uPD765 floppy controller's RESULT bytes (it should show OK if the operation was successful), but I don't know how to interpret them.


I looked at the datasheet for the controller and it mentions the main register and four others, but only gives the meaning of the four registers. I am not sure if one of these is the "RESULT" byte, or if it is the status register.When attempting to write to the floppy, I also get 40 01 00 00 00 01 01.

When attempting to write to a write protected floppy, I get 44 02 00 00 00 01 01.I do not know how to interpret these results, can anyone help?


Another question: Generally if the disk is corrupt or unformatted would this sort of low level access work or not? I mean, the format is at OS level, but I am making direct calls to the BIOS to write / read a track. would this be expected to work on a corrupted disk?


Thanks
jonB

TFM

Don't confuse FDC registers and bytes delivered during result phase.


getting &40 as first result byte is ok


Get some serious FDC765 docs!  :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

JonB

I've tried to read the data sheet but it is not clear on how you interpret the result bytes - hence the question...


Can you tell me what they mean, or point me to a doc that does?


Cheers
JonB


PS, 40, nice one - that is a step in the right direction.


arnoldemu

Hi Jon,

Each command *can* return different  status bytes.

For example, a sense drive status returns st3. In this case the status register is specific to the drive you did the sense drive status command on.

For sense drive status each bit has a meaning. 1 means true, 0 means false.
so bit 6 - write protect - is set if the disc in the drive is write protected. Here write protected means the write protect tab on the physical disc itself; which is ultimately read by a sensor and reported by the drive.

it will be 0, if the disc in the drive is set to read/write.

Looking at a read data command.

The first three bytes are ST0, ST1 and ST2. The next 4 bytes are C,H,R,N at the point the command was completed.

The NEC likes to be driven in the following ways:
1. DMA controlled. DMA controller does all the work and all the appropiate acknowledgement and indicating to the FDC when it's finished reading and to terminate the command.
2. Interrupt driven. IRQs are asserted on the host CPU, these are used to read data from the sector and to know when the command has completed.

It also likes the TC/Terminal Count input to be asserted, this tells it we have finished reading sectors.

The interrupt code, represented by bits 7,6 therefore will report success or not - but it's not as simple as both bits being 0.

On the CPC, polling method is used. Neither interrupts or DMA are used and TC is not connected. This means FDC will often give an "abnormal termination" because it didn't receive TC input. But, it's actually ok in this case, the complete sector has been read/written and the appropiate results are valid.

Bit 5 of ST0 is only valid when a seek command has been sent to FDC. It is best read using sense interrupt status and will tell you when the head has finished moving to the requested track - be aware if you're moving more than 77 tracks you will see bit 4 set and you will need to repeat the seek a second time. It's in the docs.

Bit 3 indicates that when the command was executed by the FDC the read state of the drive changed. It went from not-ready to ready (e.g. a disc is now in the drive and the motor has spun up) or ready->not ready (disc motor was turned off, or disc removed from drive).

bit 2,1,0 are like a status. They are more important with sense interrupt status. The fdc checks 4 drives and if the ready state changes, it will tell you which changed through these bits. Otherwise they are generally the bits you set for the side and drive in the command.


ST1 - Bit 5 - Data Error - this means there was an error reading the sector, the data checksum for the ID part (which holds the C,H,R,N values for a sector) and/or the checksum for the data part were bad.

Think of data on the disc like this:

<id field containing C,H,R,N matched with values in command> <gap> <data field> <gap> <id field for next sector> <gap> <data field for next sector>

ST1 - Bit 4 - Overrun - This will be set if you don't read the data or write the data from the sector fast enough. The FDC expects data at a fixed rate and if you're too slow it will indicate to you and fail the command.

ST1 - Bit 3 - No data - Set if the FDC can't find any valid ID fields or the c,h,r,n you sent in your command doesn't match any of the C,H,R,N stored in the id fields on the disc.

ST1 - Bit 2 - Not writeable - set if you do a write sector and the disc is write protected.

ST1 - Bit 0 - Missing address mark - this means FDC failed to find any valid ID fields on the disc, it tried for 2 rotations but nothing.

ST1 - Bit 7 - I can't remember the conditions for this, I think if you set the read command to read multiple sectors and it fails to find 1 it will fail with this error. Can't remember.

ST2 - Bit 6 - If you used READ DATA command, but the sector had a "deleted data" mark. This will be set. OR you used READ DELETED DATA command, but the sector had a "data" mark. The "deleted data" is just a byte, it doesn't mean the data has been deleted.

ST2 - Bit 5- When reading the data for a sector the fdc found an error. checksum didn't match data.

ST2 - bit 4 - FDC found a sector with matching R value, but the C value didn't match the one you passed in the command.

ST1 - bit 1 - similar to bit 4, but where C was ff. I think C in the command. Can't remember exact details.

ST2 - bit 0 - FDC found a matching ID field, but didn't find a data field. Remember id field and data field are stored seperarely.

I hope that helps?




My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

JonB

#5
Right... Using 22DISK with a specific set of drive parameters allows me to read the P2000C disks and they all appear to have CPM on them.
I'm using the "read track" test in the BIOS and getting the result bytes 40 01 00 00 00 01 01.

On revisiting the u765FDC datasheet it looks like they are interpreted as follows:

40 is Status Register 0. A binary value of 01000000 - D7 clear, D6 set; which means "Abnormal Termination of Command (AT)".
01 is Status Register 1. A binary value of 00000001 - D0 set; which means "Missing address Mark (MA)".

These agree with what you wrote, arnoldemu (very nice description, by the way - might be good to add it to the wiki page on the FDC). I get this result set consistently on any disk which, in the PC, I can actually read the directory from, and I can even see what the (text) files contain. So I guess the question is: Why am I getting a missing address mark every time I try to read a disk on the P2000C? Could I have a faulty connection or FDC?

I think the drives themselves are OK, as I am using one on the PC to read the disks.


kevin.c

JonB, what kind of this P2000C disks you have - single or double sided?
Let's say...:
If your "read track" command has  D7 bit set to "1", which means Multi Track Mode operation
(manual: Multi Track Mode - after finishing Read/Write operation on side 0, FDC will automatically start searching for sector 1 on side 1)
and your disk is one sided, so after successfull read of side 0 track, FDC switches to side 1 and trying to find Address Mark on next track. Of course this AM does not exists on SD Disk, and command terminates with "1" in D0 of Status Register 1 - Missing Address Mark.


arnoldemu

I would say don't use read track.

If you can use multiple "read id"s first. You will see a pattern and where it repeats you can find the number of sectors on the track and their ids and sizes. Take the last 4 bytes of the status to get each of the CHRN.

On CPC they look a bit like this for track 0:

0 0 C1 2
0 0 C2 2
0 0 C3 2
0 0 C4 2
0 0 C5 2
0 0 C6 2
0 0 C7 2
0 0 C8 2
0 0 C9 2

Then use read sector on just one of those specifying the C,H,R,N values in your read data command. e.g.

0 0 0 C1 2 C1 2A FF

On CPC the read data report looks a bit like this (from memory).

40 80 00 00 00 C1 02

Read track is a bit more tough to use because it's working from the start of the track and it's doing a special comparison with the id values.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

Quote from: kevin.c on 08:29, 07 April 15
JonB, what kind of this P2000C disks you have - single or double sided?
Let's say...:
If your "read track" command has  D7 bit set to "1", which means Multi Track Mode operation
(manual: Multi Track Mode - after finishing Read/Write operation on side 0, FDC will automatically start searching for sector 1 on side 1)
and your disk is one sided, so after successfull read of side 0 track, FDC switches to side 1 and trying to find Address Mark on next track. Of course this AM does not exists on SD Disk, and command terminates with "1" in D0 of Status Register 1 - Missing Address Mark.
I would follow Kevin's advice here.

Use a single read data command, not multi track and turn on MFM mode. I assume the discs are double density recording - could be wrong though. Set side and drive to be 0 and 0.

Input the CHRN as I mentioned before and you should get nicer looking values AND if it works, you should have either overrun or a buffer of data :)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

kevin.c

In my previous post I wrote: "(...) AM does not exists on SD Disk" . Of course I meant Single Side disk, not a Single Density one... Sorry for my mistake.

TFM

Well, if you really read the sector id's on a Data Disc it look like this


C1, C6, C2, C7, C3, C8, C4, C9, C5.


Because the tracks get formatted with an interleave of 1.



TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

JonB

I only have access to read a track in the P2000C's monitor. The command is documented in the attached image below. The disks are DS DD 80 track and as you can see, I can select a track from a specific side of the disk, but nothing else, no sector addressing, for example.


The only way to test other functions of the FDC would be to write some machine code then enter it into the monitor one byte at a time (using a separate "set memory" command for each byte, rather painful!


Now the FDC uses a PLL to detect address marks, and it has a reference frequency of 500KhZ. But I measure mine at 303kHz and the adjuster has no effect on it. I'm wondering if there is a component in the PLL circuit that's failed, but I know zero about them. The PCB certainly has quite a few discrete components around the trimmer, including some electrolytics. Maybe if I recap it..?

JonB

PLL for reference. TP2 is at 303Khz.

arnoldemu

Can you post a circuit diagram of the fdc from the p2000c?

it should be possible to determine what parts of the nec765 document apply.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

JonB

Pin 8 of the 74LS293 top right is @ 150Khz, should be 250. Pin 10 is @ 500Khz, correct.

So should I conclude the '293 is bad?

Bryce

#15
No. The 293 is receiving the 250khz, not producing it, so it's probably ok. What part creates the 250khz?

Sorry, correction. The 250khz should be coming out of the 293, why do they show the arrow in the wrong direction?? Anyway, yes, this could mean that the 293 is faulty.

Bryce.

JonB

I have one lying around somewhere. :D


Here is the controller circuit diagram.




Bryce

#17
Ok, I went to the bother of actually checking the datasheet (which I should have done in the first place)  :D What frequency do you measure on pin 11 of the 293? What are you using to measure the frequency?

It looks like the 293 is probably ok, the input clock is probably wrong though.

Bryce.

kevin.c

This circuit is clock recovery from Read Data, and correct output frequency on pin8 depends on
1.presence of correct data read from diskette
2. correct revolution rate of floppy
I'm sure that on standby - I mean floppy is stopped - the output clock frequency will be  random, and that is the case.

Bryce

Ah, you're right, I didn't look at the whole circuit (extremely difficult on a phone), just the 293. I thought this was just a clock generator for writing.

Bryce.

kevin.c

Write data circiut is very simple, it just require divided cristal clock. This PLL is to compensate read data clock jitter.
Frequency measurement will be valid on stable data read out. In other case PLL is out of synch.

Bryce

I'll take a proper look at the schematics when I'm home and at my computer. Scrolling around a 4in screen is a pain.

Bryce.

JonB

#22
Hi Bryce


I have a frequency counting multimeter here, it's accurate enough.


Turns out I don't have a 293 lying around, drat and double drat!


The measurements are:-


pin 4 - 302.5khz
Pin 8 - 151.2khz
Pin 9 - 250khz
Pin 10 - 500khz
Pin 11 - 1200khz


Is this consistent with a fully functional '293?


Pin 4 is supposed to read 500khz as it is connected to the test point.


It also says you should ground pin 3 (CLR) of the chip labelled 7415 (74LS221) before taking measurements (and making adjustments), but this doesn't alter the readings. Would this be to force it into a stable state?





kevin.c

JonB why we came to PLLs and counters, instead of secret FDC bits   ;D ;D ? Anyway I find it interesting...

JonB

(Serious hat on.. I realise you're joking) ...Because the FDC is using the PLL to detect the address mark on the disk, or rather, to interpret the read data bit. Err, I think. Either way, on this machine the designated test point for the PLL is showing the wrong frequency, and the PLL is all tied up with the read pulse. We have deciphered the error which is "missing address mark" and so I am looking into how the mark is read. I know the disks are OK because I can read them on a PC with 22DISK (a nice bit of software for transferring files to/from a gazillion different co/m formatted disks, including the ones used by the P2000C).


So the missing address mark isn't caused by the disks, or the drives (already independently tested with the P2000C disks and 22DISK). Therefore there is something wrong with the circuit that controls the read. The FDC is starting up fine. I can see this because the seek occurs, as does spinning up the drive and stopping it as well as head load and unload; it all looks normal. All that is left (that I can think of, anyway) is the actual read signal.


Hence, we are now debugging the PLL... Your advice is very much appreciated! :)



Powered by SMFPacks Menu Editor Mod