RFC 401

Conversion of NGP-0 Coordinates to Device Specific Coordinates

πŸ“… published October 1972, from ietf

Conversion of NGP-0 Coordinates to Device Specific Coordinates ✨

okay bestie, this one is from Jim Hansen at the Center for Advanced Computation, University of Illinois πŸŽ€ It's NIC #11923, dated October 23, 1972, and it's Category D.6. It Updates RFC #387 and Obsoletes None 🧚 It's part of the Network Working Group crew, so get ready to level up πŸ’œ


Okay so RFC #387 already talked about turning NGP-0 coordinates into floating point PDP-10 coordinates πŸ’– But ngl, floating point is usually a bad look here, because real devices need integer addressing πŸ™ˆ So this RFC shows how to turn NGP coordinates into integer coordinates from zero to M, where M is the maximum address of the device screen on a machine using 2's complement arithmetic ✨ It wouldn't be hard to tweak this for machines using one's complement or sign-magnitude arithmetic either 🫢

First, the NGP coordinate format πŸ¦‹

Here's the vibe:

                   +--+-----------+
                   |  |   n       |
                   +--+-----------+
                    s ^  FRACTION
                    i
                    g
                    n

The sign lives in the most significant bit, and the rest is numerical info. The initial NGP implementation uses N=15 πŸ”₯ Negative numbers are stored in 2's complement πŸ’…

The big conversion formula πŸ‘‘

To get to device coordinates, you do this:

                    D = S * f + S

Where D =>integer device coordinate
      S =>scaling factor (typically M/2)
      f =>NGP fractional coordinate

Let's rewrite it as:

                            n     n
                    D = S*(2 *f)/2 +S

Now we split up S into two terms:

                            I
                    S= Q * 2

where Q is an odd integer and I is an integer 🌈

Plug that in and you get:

When:                        I   n     n
                    D = Q * 2 *(2 *f)/2  +S

                             I-n   n
                      = Q * 2   *(2 *f)  +S
             n

The (2 *f) factor is in 2's complement because you just extend the sign bit of f into the upper part of the computer word 🧚 If Q = 1 (which is what a lot of devices use), you can skip it. If Q >< 1, the consolation prize is that an integer multiply is usually faster than a floating point multiply on most machines πŸ“ On a PDP-10, this multiply can often happen with no memory access, since Q is usually small 😭

Now we're left with the 2^(I-n) factor:

                          I-n

This can be done with an arithmetic shift left by (I-n), or an arithmetic shift right by (n-I), whichever fits πŸ’œ Then S gets added with an integer add. Iconic. ✨

The step-by-step procedure πŸŽ€

So the full procedure for turning NGP coordinates into integer device coordinates goes:

  1. move coordinate to a register and extend sign
  2. integer multiply by Q (if necessary)
  3. arithmetic shift left by (I-n)
  4. integer add S
This procedure is generally way faster than the float route πŸ’€

Here's that float route, for comparison:

  1. move coordinate to register and extend sign
  2. float fractional coordinate
  3. floating point multiply
  4. floating point add
  5. conversion to fixed point

Literally the integer way is the main character here πŸ‘‘πŸ«Ά


       [ This RFC was put into machine readable form for entry ]
       [ into the online RFC archives by BBN Corp. under the   ]
       [ direction of Alex McKenzie.                      1/97 ]
πŸ“¦ where this page comes from