Ruud's Commodore Site Home  Email

PC-Flop




What is it?

Remark in advance: this project is the ancestor of 1541LPT, No more floppies anymore!, so some text and ideas will look familiar.

PC-Flop is a project where I am going to use a PC as an harddisk for the C64, C128 and VIC-20 and other IEC-computers using a 1541 as an interface. As a small bonus you can use the CD-ROM, 1.44 MB-drive and network-drives of the PC as well!
Products: software, a cable and a modified 1541-board.


The story

Marko Makela, Frank Kontros, Andre Fachat and I exchange a lot of ideas and one day I suggested to build a small 6502-machine as an interface between the PC and the C64 to let GEOS think it is dealing with an real 1541 or other drive. Marko (or Andre ?) replied that I should use an old 1541-board instead, it would save me a lot of soldering.


Theory

To understand how the 1541 transfers data to/from the floppy disk, you can read this document . The 1541 uses a 6522 (UC2) to transfer data from/to the head of the drive and to steer the stepping motor. This 6522 is as far as a programmer can go. The idea is to remove the mechanical part and the connected electronics and to connect the I/O-lines of the 6522 with the printer port of a PC instead. The PC now must emulate the parts we removed: it must read the data send by the 6522 and store it, and it must send stored data to the 6522 as if it was coming from a real floppy.

This can only be done when the PC handles/emulates the "handshake" signals in the right way. I use the word "handshake" by lack of a better word.
The first thing a drive does when a command is given is to read the track where the head is above. The PC can detect this because PB2, motor on/off, becomes active (H). As you know, the original 1540 and 1541 have no "track 0"-detector. It detects the track where the head is above by reading the first header off a sector it "sees" because the header contains this information. If it doesn't read anything, then the "famous" head-bumping occurs because the floppy thinks the mis-reading could be caused by a wrong alignment of the head. My idea is anyway to let a drive think that, after powering up or "changing" the floppy, the head is above track 18.
If the drive wants to change the track, it does this by changing the outputs PB0 and PB1 like 00, 01, 10, 11, 00 etc. when increasing the tracknumber and changing the values in the opposite way when decreasing the tracknumber. The head is above a track when PB0 = 0. This means that the drive needs two steps to change the track. We will come back to this matter when discussing "Copy protections". The PC only has to detect the changes of both PB0 and PB1 and act on it as needed.

The PC must start reading and storing data the moment it detects CB2 is (L). If the byte has been stored it must signal this to the drive by negating the "Byte ready"-line towards CA1 and the SO-input of the processor. Normally the drive needs 26 to 32 usec to write the info away. The needed time depends on the track where it is on. After receiving the "Byte ready"-signal the processor outputs a new byte to port A of the 6522. I do not know how much time this will take but with the help of the following disassembly it can be calculated:
B_F5BF  LDA     (BUFPNT),Y              6
  
B_F5C1  BVC     B_F5C1                  3
  
        CLV                             2
        STA     PortA2                  4
        INY                             2
        BNE     B_F5BF                  3
                                      ----+
                                       20
The above is a part of the procedure to write a complete datablock to the floppy disk. The numbers behind the text is the number of cycles this instruction needs to be executed. As you can see the total is 20. We have to wait at least this amount of time plus some reserve. We also can see that it takes up to 11 cycles before the new data is outputted to the port.

When reading data the opposite happens:
B_F4D4  BVC     B_F4D4
  
        CLV     
        LDA     PortA2         STA     (BUFPNT),Y
        INY     
        BNE     B_F4D4
Again the 6502 needs at least 20 cycles to read a byte.
Notice that the 6502 immediately resets the overflowflag after detecting it has been set. This is possible because the SO-input is edge sensitive. For the same reason the PC can set the signal immediately after it had been negated.
Remark: From now on the handling of the "Byte ready"-signal is included when I mention reading or writing a byte from/to port A. As we have no handshake from the drive to signal that it is ready to write/read the next byte, we must respect the timing mentioned above.

We'll now discuss all actions the drive can perform on a disk:

Copy protections

At this moment I only can think of six types of copy protection that can be used on a disk: Copying an already existing floppy is a different matter. There are two solutions:

Realisation

The only thing we have to do is to place two extra sockets between the 6522 and its original socket. All pins are connected to each other by means of soldering with the exception of:
As you can see there are 8 bi-directional lines, 7 outputs and 3 inputs. PB5 and PB6 influence the density of data on the floppy and, IMHO, can be neglected for our purposes. This means we have 5 outputs to deal with. A bi-directional printer port of a PC has 8 bi-directional lines, 5 inputs and 4 outputs. As you can see this makes a nice match.
The second step is to connect a male 25 pins D-connector to the free pins of the upper socket. This connector is used to make the connection with the LPT-port of the PC and is wired like this:
                6522                                    LPT
        Name    Meaning pin                     name            pin
        ----    ------- ---                     ----------      ---
        PA0              2                      D0               2
         .                                       .
         .                                       .
        PA7              9                      D7               9
  
        CA1     BRDY    40                      Strobe           1  (O) 
        PB7     SYNC    17                      Auto feed       14  (O) 
        PB4     WPE     14                      Initialise      16  (O)   
        PB0     Stp1    10                      Select          13  (I) 
        PB1     Stp0    11                      Paper out       12  (I) 
        PB2     Mtr     12                      Acknowl.        10  (I) 
        CB2     Mode    19                      Busy            11  (I) 
        CA2     SOE     19                      Error           15  (I)   
        CB1             18                      Select out      17  (O)   
  
3BC,378,278 = Printerdata
3BD,379,279 = Printerstatus
bit 0 = not used
bit 1 = not used
bit 2 = not used
bit 3 = error (15)
bit 4 = select (13)
bit 5 = paper end (12)
bit 6 = acknowledge (10)
bit 7 = busy (11)
  
3BE,37A,27A = Printercontrol
bit 0 = strobe (1)
bit 1 = autofeed (14)
bit 2 = Initialise (16)
bit 3 = select out (17)
bit 4 = enable IRQ7
bit 5 = dataport direction
bit 6 = not used
bit 7 = not used
  
Control after reset:  $CC
Between the 74LS174 (= Printercontrol-port) and the Strobe-pin (1) at the connector you'll find a 74LS05 open-collector inverter. This is the same for Autofeed (14) and "Select out" (17). For Initialise you'll find two 05-inverters. Combining this info with the fact that the byte $EC is written to the controlport results in the fact that the inputs CA1, PB4 and PB7 all read a 1. CB1 will read a 0.


The software

Unless we expand, the rest is only a matter of software on the PC.

Under
Giving the appropriate commands to the PC, can 'change' the floppy. In this case a change of the Kernal or a major change of the hardware of the 1541 is not needed. But my idea is to use a stand-alone PC at the end so the next step is to add some commands to the Kernal.


Testing everything

At this moment everything is purely theoretically. To make sure that my theory is according the reality, I have to see first how a live drive uses the above mentioned signals. For this I need three extra inputs ie. a second printer port.
                6522                                            LPT
        Name    Meaning        pin                     name            pin 
        ----    -------        ---                     ----------      ---
        CA1     BRDY            40                     Acknowl.         10  (I)
        PB7     SYNC            17                     Busy             11  (I) 
        PB4     WPE             14                     Paper out        12  (I) 
What now has to be done is writing some software that scans the bus continuously.

In case we want to expand the Kernal with extra commands, we need to expand the onboard (EP)ROM and RAM. This is described below in separate parts.


We need more ROM

If we want to use a stand-alone PC, we must be able to command it in one or another way. This means we must use the 6522 in a way that is not provided by the standard Kernal of the 1541.
This could be archived by executing a small program in one of the buffers. The disadvantage of this procedure is we first have to load this program from disk. This does mean that this program has to be available on every "floppy" on the PC otherwise we are not able to change "floppies" anymore.
The more logical step is to change the Kernal. IMHO the only thing we need to change is the command-interpreter. And I'm very sure this can be done with maintaining 100% compatibility.
Adding more commands means we need more ROM. There are 256 bytes free in the range $C000/$C0FF but I don't think that this will be enough. My idea is to replace both onboard ROMs with one 32 KB EPROM like the 27256. This gives us an extra 16 KB of EPROM to be filled with our own programs.


We need more RAM

At this moment I don't know if I need more RAM. But expanding the 1541 with 2KB of extra RAM is simple and the 1541 will still be 100% compatible.
The only thing we have to do is to add one AND-gate and a 6116, 2016 or equivalent 2K*8 RAM. The last one can be piggybacked on the original one: all pins are soldered with the exception of pin 18, the ChipSelect-input. For the AND-gate we need a 74LS08 that can be piggybacked upon another TTL-IC with pin 14 and 7. The output of the AND-gate is connected to the previously mentioned CS-input. The inputs of the AND gate are connected to pin 13 and 12 of the onboard 74LS138. In this way the new RAM is mapped from $0800 to $0FFF.


Emulating more drives

Another idea is to have the possibility to assign more then one devicenumber to the 1541. But every device needs its own 2KB RAM starting at address $0000. So we must save the contents of this RAM every time another device needs this range. T archive this we could add more RAM to the board but this would mean a major rebuild and that is a little bit out of the scope of this project. Another idea is to save the contents of the RAM on the PC. This will cost some performance but will need fewer modifications of the 1541-board. To perform the needed save- and restore-operations, we will need some extra RAM but that is already covered by the part above.
One remark: A multi-device drive cannot be two devices at the same time. So I foresee troubles with copy-programs that transfer data directly from one drive to the other.


Software

The SW can be split up in two parts: To be able to alter the original kernal, you first must have the source code of it. As I haven't found one complete with comments etc. yet, I'm working on one myself. When this is done, I can start studying where and how to alter it.
The software for the PC is less trouble as I can use the core of CBM-HD for this purpose. Theoretically I only have to change the I/O- and command-interpreter-part (I hope).


Schematics

Not even started yet.





Having questions or comment? You want more Info?
You can email me here.