Re: Commodore64 serial interface From: John Iannetta <76703.4244@CompuServe.COM> Reply to: John Iannetta Date: Sat, 19 Sep 1998 16:10:25 -0400 Organization: CompuServe, Inc. (1-800-689-0736) References: ZUBSoft said, "1) The different voltages (c64-rs232c) could be converted. 2) On the rs232c side of the hw, there could be an UART. 3) So, as I see it, the only one problem is to create the c64 side - to decode the signal into bytes and pass it to the UART (and also to create an mechanism, how to send to PC info about the select mode and about the EOI)". If you want to build a device that will accept a byte from the C-64 IEC (serial) port and load it into an 8250 (or equivalent), it is not a blue-sky project. You will need an 8-bit shift register; it will shift left since the IEC standard is bit 7 first 8as opposed to RS-232). You will need three lines; DATA (pin 2), CLK (pin 4), and -ATN (pin 3); they all use TTL voltage levels. -ATN is an input on your end; the other two lines are bidirectional. You should use circuitry similar to that used by the C-64 and the 1541. Each of those lines (DATA and CLK) should connect to the output of an open-collector inverter (or non-inverter), and also to the input of a gate. Use a pull-up resistor of about 1 kohm for each line. Since the O-C devices are electronic switches, I'll say "off" to mean a low input to an O-C inverter, and "on" to mean a high input. Normally, the -ATN line (driven by the C-64) should be high. Your device should have both the DATA and CLK switches off. If you see -ATN go low, you should turn the DATA switch on. That is your reponse to the C-64's announcement that it wants to send a control character. Your device should then wait for the C-64 to take CLK high. When you are ready to accept a byte, turn your DATA switch off. The C-64 should then send eight negative pulses along the CLK line; the trailing (rising) edge should clock your shift register. The DATA line should feed the data input pin of the shift register; high is a one and low is a zero. After you receive the byte (and latch it into your 8250), turn the DATA switch on. You are then ready for another byte. When you see -ATN go high, that is the end of receiving control bytes. Regular data bytes are sent with -ATN high. The control bytes must be examined; they contain instructions frrm the C-64. Remembering that the IEC standard allows device numbers (addresses) from 0 to 30, there may be 31 peripheral devices on the line simultaneously. Control bytes include LISTEN and TALK. The former instructs the device to receive data; the latter to send data. A LISTEN is the device number ORed with 32; a TALK is the device number ORed with 64. An UNLISTEN (63) tells all devices to stop receiving; an UNTALK (95) tells all devices to stop sending. An SA (Secondary Address), a number from 0 to 15, may immediately follow either a TALK or a LISTEN (sent with -ATN low). If the C-64 wants to send data to a new file, it sends a LISTEN followed by an SA ORed with 240. The device uses that SA to reference that file. Then, with -ATN high, the C-64 sends the filename string (followed by ",w" to indicate a write file). Then, with -ATN lows, an UNLISTEN is sent. When the C-64 wants to send data to that file, it sends a LISTEN, followed by the SA ORed with 96 (both with -ATN low). That tells the device to get ready to receive data, and to put those data into the the proper file. Since the LISTEN contains the device number, all other devices on the bus should go off-line (turn both DATA and CLK switches off). When the C-64 is finished sending data to the file, it closes the file by sending a LISTEN followed by the SA ORed with 224 (both with -ATN low). Then, with -ATN low, an UNLISTEN is sent. Presumably, your software would examine the control characters and instruct the device either to prepare to send data, to prepare to receive data, or to go off-line. To receive data, the same scheme is used as when receiving the control bytes, but with -ATN high. But if your device is TALKed, you must "turn the line around" in order to send data. This is the procedure. After receiving the SA, and seeing that -ATN has gone high, your DATA switch should be on and your CLK switch off. Wait for the CLK line to go high; then turn your CLK switch on and your data switch off. I've omitted some details such as timing specs, in the interests of brevity. But I'll describe the EOI procedure. As implemented by the C-64 and the 1541, EOI is used by the drive to indicate both end-of-file and end-of-record (for relative files). The C-64 uses EOI only for end-of-record. The EOI (last) byte is essentially a delayed byte. As previously stated, when you are ready to receive a byte (with your CLK switch off), you turn your DATA switch off. You would normally then get the eight negative pulses on the CLK line. Start a timer that times out in about 250 usec. If CLK does not go low by then, turn your DATA switch on for about 100 usec., and then off. You should then get the eight negative pulses on the CLK line representing the EOI byte. -- When backing up your hard drive, shift into reverse gear S M O O T H L Y. John