Newsgroups: comp.sys.sinclair
Path: ulke.hiMolde.no!trane.uninett.no!sunic!lunic.luth.se!eru.mt.luth.se!bloom-beacon.mit.edu!gatech!swrinde!howland.reston.ans.net!news.sprintlink.net!pipex!uknet!comlab.ox.ac.uk!imc
From: imc@comlab.ox.ac.uk (Ian Collier)
Subject: Re: RS232 on the 128k
Message-ID: <5951.imc@uk.ac.ox.prg>
X-Local-Date: Thursday, 19th January 1995 at 2:06pm GMT
Originator: imc@msc2.comlab
Organization: Oxford University Computing Laboratory
References: <3eueni$7l@gabriel.keele.ac.uk> <3f0r87$if5@icebox.mfltd.co.uk>
Date: Thu, 19 Jan 1995 14:06:45 GMT
Lines: 103

In article <3f0r87$if5@icebox.mfltd.co.uk>, dnh@mfltd.co.uk (Des Herriott) wrote:
>u3g12@cc.keele.ac.uk (Muhhk) wrote:
>>Does anyone have a wiring diagram for the RS232 port on the 128k? Can it be
>>used for both input and output? Also, does anyone know the port address for
>>the MIDI port? And any other information that may be of use for the
>>RS232/MIDI/keypad.

Here is a summary of pages 318-319 of the +3 manual...

The pins of each BT socket are numbered as follows:

     +-------------+
    ++             |
    |  6 5 4 3 2 1 |
    ++ = = = = = = |
     +-------------+

The connections of the RS232 port are as follows:

  1  GND
  2  TXD
  3  RXD
  4  DTR
  5  CTS
  6  +12V

The connections of the MIDI port, which actually uses the same socket as the
RS232, are:

  1  RETURN
  2  not used
  3  not used
  4  not used
  5  DATA OUT
  6  not used

The AUX socket supports two input lines (pins 3 and 5) and two output lines
(pins 2 and 4).  The I/O lines are driven by 1488 and 1489 line driver chips
which are, in turn, connected to the I/O lines of the AY-3-8912.  Basically,
register 14 of the AY-3-8912 controls eight I/O lines; the bits are
designated as follows:

  0  AUX pin 2 (out)
  1  AUX pin 4 (out)
  2  RS232 pin 5 (CTS out)
  3  RS232 pin 3 (RXD out)
  4  AUX pin 3 (in)
  5  AUX pin 5 (in)
  6  RS232 pin 4 (DTR in)
  7  RS232 pin 5 (TXD in)

The AUX socket is wired as follows:

  1  GND
  2  output bit 0
  3  input bit 4
  4  output bit 1
  5  input bit 5
  6  +12V

(note that the +3 has an AUX socket where the 128K used to have a keypad
socket).

[End of summary.]

In order to control these three devices you need to do some bit twiddling
and some delay loop counting.  The +3 ROM supports RS232 output and input
and MIDI output.  I have implemented MIDI input (but I forget which pin I
allocated it to...  also it didn't seem to work without a 10K pull-down
resistor from one of the unused outputs (at -12V) to the input).

In order to twiddle bits, you need to output 14 (the register number) to
port FFFD and then either input from port FFFD (to read the inputs) or
output to port BFFD (to set the outputs).

>And while we're on the subject, does anyone know the addresses in
>128K ROM where the RS232 handling code lives?  And was a disassembly
>of the 128K ROMs ever published?

I have not known about any 128K ROM disassembly.  I have an annotated
(in sloppy handwriting!) disassembly of the +3 ROMS (ROM 0 (editor) and
ROM 1 (syntax) plus the differences in ROM 3 (48K)), but nothing on the
plain 128K.

I have found the RS232 input at address 1E78 in the +3's ROM 1, and the
output at address 205B in the +3's ROM 1. Both routines may affect the
values of AF, BC, DE and HL, and in addition the input routine may change
the values of A'F', B'C', D'E' and H'L'.  1E78 returns a character in A with
carry set, or returns carry reset if the input timed out.  205B outputs the
character contained in A.

Note that ROM addresses are liable to change.  I assume that the +2A ROMs
(or actually the "new" +3 ROMS, most of which have gone into +2A machines)
have slightly different addresses.

This information was collected from archived messages.  I have no
information about the MIDI output routine as I have forgotten to look
it up...

Ian Collier - Departmental Lecturer (and perpetual postgrad student) -
imc@comlab.ox.ac.uk - Oxford University Computing Laboratory, Wolfson
Building, Parks Road, Oxford OX1 3QD - WWW Home Page (including Spectrum
section): http://www.comlab.ox.ac.uk/oucl/users/ian.collier/index.html
