Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

scrottie (4167)


My email address is Spam me harder! *moan*

Journal of scrottie (4167)

Tuesday June 30, 2009
01:44 PM

Playing with Tektronix emulation for vector graphics!

[ #39195 ]

This is one of those, hmm, seems possible, wonder why no one has done it things.

The stock xterm that comes with X has emulation built in for the old Tektronix 4014 graphics terminal in addition to DEC220 emulation.

The Tektronix 4014 is a Vectrex like thing where lines are drawn directly onto the screen rather than being broken up into pixels and the entire surface of the display scanned. It also used a "storage tube" strategy where the beam detects what's already lit and re-energizes it, apparently mixing scanning with direct vector drawing. But that's beside the point of this. I've actually seen some of these beasts at UVA's Unix lab. The interesting bit is they draw vector graphics, xterm emulates them, and this works over bloody telnet. is the best resource I could find -- the original manual. Other example programs sucked. But even that manual was tricky.

print unpack "u", q{M&UL_,SAH&PP=?U]O7QUW7W=;'7];;UL=>U=_4QU_4V]3'7M7<U,=?TMO1QU_22V]/'7-'<T\=?T-O 0QUO0V]`};

... my new JAPH. Requires a real xterm (probably) without GNU screen in the way. That was the 3rd thing I wrote.

$|=1;print chr(27),"[?38h",chr(29);while(1){print chr(32+rand 32),chr(96+rand 32),chr(32+rand 32),chr(64+rand 32);}

... demo program, shortened for Twitter. That was the 2nd thing I wrote.

use strict;
use warnings;
use IO::Handle;
print chr(27), "[?38h"; sleep 1;  # TEK mode from vt-whatever mode; this is an xterm/DEC escape sequence, not a TEK one
print chr(27), chr(12); sleep 1;  # clear screen
print chr(13+16);  # 13 plus some offset relating to shift+ctrl to get into graphics mode
while(1) {
    print chr(32 + int rand 32), chr(96 + int rand 32), # the 5 high bits of Y+32, 5 low bits of Y + 96
          chr(32 + int rand 32), chr(64 + int rand 32); # the 5 high bits of X+32, 5 low bits of X+64
    sleep 1;

The first program in its final form, which is just a long version of the above.

The manual explained that to get into Tek graphics mode, push shift+control+M with the thing in loopback mode. I have no idea what ASCII code a Tektronix terminal sends when you do that so that was a little useless and originally I misread the table as just being a control-M. Through trial and error, I established it as being ord("^M")+16. Some control codes are escape (chr(27)) plus another character; others are just a control character. Tektronix terminals also have a character mode which itself has many options including up to 133 char display. I haven't played with any of that yet except that it operates as a dumb terminal with an addressable cursor (movable cursor) when its not in graphics mode, and text and graphics can be mixed.

The while loop needs explanation. To draw lines, four characters of certain ranges are sent. The X and Y high bits

Send the Y high byte (ASCII value of 32-63 encoding the top 5 bits), the Y low byte (96-127 encoding the low 5 bits), the X high byte (32-63, again), then the X low byte (64-95). I guess when it sees that X low byte, it actually draws the line. It's possible to skip sending the high bits and only send the low bits in which case the high bits just stay zero. The JAPH program does that.

There's no "okay, this is a line draw!" code or escape sequence between the line data; the line data just goes in place of ASCII and gets interpreted as points. That three different character ranges are used to specify four different points is a bit tricky. The X-high and Y-high ranges are one and the same and the value gets set twice. X-low and Y-low are different ranges though.

When sending coordinates like this, it always draws a line from the last coordinate unless you just switched to graphics mode with a chr(29). Of course you can switch into graphics mode while in graphics mode, so to reposition the beam and start drawing a new, unattached line, send chr(29) and then the four bytes encoding the coordinates. Also, the coordinates are relative the top right of the screen. Try to figure that one out. While the X and Y values can encode up to 1024 positions, the Y resolution is only 768 (hey, completely standard resolution!) so it's possible to draw off of the top of the screen (cuz, you know, the coordinates are backwards and upsidedown).

Output and input do not happen at the same time, but there's an additional mode where the cursor becomes a crosshair and mouse clicks are sent with the mouse location are sent and can be polled. The real 4014 didn't have a mouse but instead had two knobs, not unlike an Etch-o-sketch. The text mode is of course an input mode.

What's next? Hmm, do the sinus scroller I meant to do for YAPC for presentation software? XTank clone that runs over telnet? First person 3D GUI for the MUD with wireframe orcs and elves?


The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • gnuplot also has support for the tek mode. Just do

    $ gnuplot
    set term tek40xx

    Then use the "Switch to tek mode" menu item from the middle menu () and finally plot something:

    plot sin(x)

  • First thing I did was convert the program at [] into perl, outputting to stdout instead of the serial port. I imagine the reason why very little uses the Tektronix emulation mode is the requirement to clear the screen to erase anything.