do reboot more flexibly
[unix-history] / usr / src / old / lib2648 / lib2648.3
CommitLineData
927955d2
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
3d10db30 5.\" @(#)lib2648.3 6.2 (Berkeley) %G%
927955d2 6.\"
66a99ca4 7.TH LIB2648 3X ""
927955d2
KM
8.UC 5
9.SH NAME
10lib2648 \- subroutines for the HP 2648 graphics terminal
11.SH SYNOPSIS
12.B #include <stdio.h>
13.sp
14.B "typedef char"
15.RB * bitmat ;
16.br
17FILE *trace;
18.sp
19cc file.c
20.B \-l2648
21.SH DESCRIPTION
22.I Lib2648
23is a general purpose library of subroutines useful
24for interactive graphics on the Hewlett-Packard 2648 graphics terminal.
25To use it you must call the routine
26.IR ttyinit ()
27at the beginning of execution,
28and
29.IR done ()
30at the end of execution.
31All terminal input and output must go through the routines
32.IR rawchar ,
33.IR readline ,
34.IR outchar ,
35and
36.IR outstr .
37.PP
38.I Lib2648
39does the necessary ^E/^F handshaking if
40.I "getenv(``TERM'')"
41returns ``hp2648'', as it will if set by
42.IR tset (1).
43Any other value, including for example ``2648'', will disable handshaking.
44.PP
45Bit matrix routines are provided to model the graphics memory of the 2648.
46These routines are generally useful, but are specifically useful for the
47.I update
48function which efficiently changes what is on the screen to what is
49supposed to be on the screen.
50The primative bit matrix routines are
51.IR newmat ,
52.IR mat ,
53and
54.IR setmat .
55.PP
56The file
57.IR trace ,
58if non-null, is expected to be a file descriptor as returned by
59.IR fopen .
60If so,
61.I lib2648
62will trace the progress of the output by writing onto
63this file.
64It is provided to make debugging output feasible for graphics programs without
65messing up the screen or the escape sequences being sent.
66Typical use of trace will include:
67.nf
68 \fBswitch\fP (argv[1][1]) {
69 \fBcase\fP 'T':
70 trace = fopen("trace", "w");
71 \fBbreak\fP;
72 ...
73 \fBif\fP (trace)
74 fprintf(trace, "x is %d, y is %s\en", x, y);
75 ...
76 dumpmat("before update", xmat);
77.fi
78.SH ROUTINES
79.TP
80.B agoto(x, y)
81Move the alphanumeric cursor to position (x, y),
82measured from the upper left corner of the screen.
83.TP
84.B aoff()
85Turn the alphanumeric display off.
86.TP
87.B aon()
88Turn the alphanumeric display on.
89.TP
90.B areaclear(rmin, cmin, rmax, cmax)
91Clear the area on the graphics screen bordered by the four arguments.
92In normal mode the area is set to all black, in inverse video mode
93it is set to all white.
94.TP
95.B beep()
96Ring the bell on the terminal.
97.TP
98.B bitcopy(dest, src, rows, cols) bitmat dest, src;
99Copy a
100.I rows
101by
102.I cols
103bit matrix from
104.I src
105to (user provided)
106.I dest.
107.TP
108.B cleara()
109Clear the alphanumeric display.
110.TP
111.B clearg()
112Clear the graphics display.
113Note that the 2648 will only clear the part of the screen
114that is visible if zoomed in.
115.TP
116.B curoff()
117Turn the graphics cursor off.
118.TP
119.B curon()
120Turn the graphics cursor on.
121.TP
122.B dispmsg(str, x, y, maxlen) char *str;
123Display the message
124.I str
125in graphics text at position
126.I (x, y).
127The maximum message length is given by
128.IR maxlen ,
3d10db30 129and is needed for dispmsg to know how big an area to clear
927955d2
KM
130before drawing the message.
131The lower left corner of the first character is at
132.I (x, y).
133.TP
134.B done()
135Should be called before the program exits.
136Restores the tty to normal, turns off graphics screen,
137turns on alphanumeric screen, flushes the standard output, etc.
138.TP
139.B draw(x, y)
140Draw a line from the pen location to
141.I (x, y).
142As with all graphics coordinates,
143.I (x, y)
144is measured from the bottom left corner of the screen.
145.I (x, y)
146coordinates represent the first quadrant of the usual Cartesian system.
147.TP
148.B drawbox(r, c, color, rows, cols)
149Draw a rectangular box on the graphics screen.
150The lower left corner is at location
151.I (r, c).
152The box is
153.I rows
154rows high and
155.I cols
156columns wide.
157The box is drawn if
158.I color
159is 1, erased if
160.I color
161is 0.
162.I (r, c)
163absolute coordinates represent row and column on the screen,
164with the origin at the lower left.
165They are equivalent to
166.I (x, y)
167except for being reversed in order.
168.TP
169.B "dumpmat(msg, m, rows, cols) char *msg; bitmat m;"
170If
171.I trace
172is non-null, write a readable ASCII representation
173of the matrix
174.I m
175on
176.I trace.
177.I Msg
178is a label to identify the output.
179.TP
180.B emptyrow(m, rows, cols, r) bitmat m;
181Returns 1 if row
182.I r
183of matrix
184.I m
185is all zero, else returns 0.
186This routine is provided because it can be implemented more
187efficiently with a knowledge of the internal representation
188than a series of calls to
189.I mat.
190.TP
191.B error(msg) char *msg;
192Default error handler.
193Calls
194.I message(msg)
195and returns.
196This is called by certain routines in
197.IR lib2648 .
198It is also suitable for calling by the user program.
199It is probably a good idea for a fancy graphics program
200to supply its own error procedure which uses
201.IR setjmp (3)
202to restart the program.
203.TP
204.B gdefault()
205Set the terminal to the default graphics modes.
206.TP
207.B goff()
208Turn the graphics display off.
209.TP
210.B gon()
211Turn the graphics display on.
212.TP
213.B koff()
214Turn the keypad off.
215.TP
216.B kon()
217Turn the keypad on.
218This means that most special keys on the terminal (such as the alphanumeric
219arrow keys) will transmit an escape sequence instead of doing their function
220locally.
221.TP
222.B line(x1, y1, x2, y2)
223Draw a line in the current mode from
224.I (x1, y1)
225to
226.I (x2, y2).
227This is equivalent to
228.I "move(x1, y1); draw(x2, y2);"
229except that a bug in the terminal involving repeated lines from the
230same point is compensated for.
231.TP
232.B lowleft()
233Move the alphanumeric cursor to the lower left (home down) position.
234.TP
235.B "mat(m, rows, cols, r, c) bitmat m;"
236Used to retrieve an element from a bit matrix.
237Returns 1 or 0 as the value of the
238.I [r, c]
239element of the
240.I rows
241by
242.I cols
243matrix
244.I m.
245Bit matrices are numbered
246.I (r, c)
247from the upper left corner of the matrix,
248beginning at (0, 0).
249.I R
250represents the row, and
251.I c
252represents the column.
253.TP
254.B message(str) char *str;
255Display the text message
256.I str
257at the bottom of the graphics screen.
258.TP
259.B "minmax(g, rows, cols, rmin, cmin, rmax, cmax) bitmat g;"
260.ti -.5i
261.B int *rmin, *cmin, *rmax, *cmax;
262.br
263Find the smallest rectangle that contains all the 1 (on) elements in
264the bit matrix g.
265The coordinates are returned in the variables
266pointed to by rmin, cmin, rmax, cmax.
267.TP
268.B move(x, y)
269Move the pen to location
270.I (x, y).
271Such motion is internal and will not cause output
272until a subsequent
273.I sync().
274.TP
275.B movecurs(x, y)
276Move the graphics cursor to location
277.I (x, y).
278.TP
279.B bitmat newmat(rows, cols)
280Create (with
281.IR malloc (3))
282a new bit matrix of size
283.I rows
284by
285.I cols.
286The value created (e.g. a pointer to the first location) is returned.
287A bit matrix can be freed directly with
288.IR free .
289.TP
290.B outchar(c) char c;
291Print the character
292.I c
293on the standard output.
294All output to the terminal should go through this routine or
295.IR outstr .
296.TP
297.B outstr(str) char *str;
298Print the string str on the standard output by repeated calls to
299.I outchar.
300.TP
301.B printg()
302Print the graphics display on the printer.
303The printer must be configured as device 6 (the default) on the HPIB.
304.TP
305.B char rawchar()
306Read one character from the terminal and return it.
307This routine or
308.I readline
309should be used to get all input,
310rather than
311.IR getchar (3).
312.TP
313.B rboff()
314Turn the rubber band line off.
315.TP
316.B rbon()
317Turn the rubber band line on.
318.TP
319.B char *rdchar(c) char c;
320Return a readable representation of the character
321.I c.
322If
323.I c
324is a printing character it returns itself, if a control
325character it is shown in the ^X notation, if negative
326an apostrophe is prepended. Space returns ^\`, rubout returns ^?.
327.IP
328.B NOTE:
329A pointer to a static place is returned.
330For this reason, it will not work to pass rdchar twice to the same
331.IR fprintf / sprintf
332call.
333You must instead save one of the values in your own buffer with strcpy.
334.TP
335.B readline(prompt, msg, maxlen) char *prompt, *msg;
336Display
337.I prompt
338on the bottom line of the graphics display
339and read one line of text from the user, terminated by a newline.
340The line is placed in the buffer
341.IR msg ,
342which has size
343.I maxlen
344characters.
345Backspace processing is supported.
346.TP
347.B setclear()
348Set the display to draw lines in erase mode.
349(This is reversed by inverse video mode.)
350.TP
351.B "setmat(m, rows, cols, r, c, val) bitmat m;"
352The basic operation to store a value in an element of a bit matrix.
353The
354.I [r, c]
355element of
356.I m
357is set to
358.I val,
359which should be either 0 or 1.
360.TP
361.B setset()
362Set the display to draw lines in normal (solid) mode.
363(This is reversed by inverse video mode.)
364.TP
365.B setxor()
366Set the display to draw lines in exclusive or mode.
367.TP
368.B sync()
369Force all accumulated output to be displayed on the screen.
370This should be followed by fflush(stdout).
371The cursor is not affected by this function.
372Note that it is normally never necessary to call
373.IR sync ,
374since
375.I rawchar
376and
377.I readline
378call
379.I sync()
380and
381.I fflush(stdout)
382automatically.
383.TP
384.B togvid()
385Toggle the state of video.
386If in normal mode, go into inverse video mode,
387and vice versa.
388The screen is reversed as well as the
389internal state of the library.
390.TP
391.B ttyinit()
392Set up the terminal for processing.
393This routine should be called at the beginning of execution.
394It places the terminal in CBREAK mode, turns off echo,
395sets the proper modes in the terminal,
396and initializes the library.
397.TP
398.B "update(mold, mnew, rows, cols, baser, basec) bitmat mold, mnew;"
399Make whatever changes are needed to make a window on the screen
400look like
401.IR mnew .
402.I Mold
403is what the window on the screen currently looks like.
404The window has size
405.I rows
406by
407.IR cols ,
408and the lower left corner on
409the screen of the window is
410.I [baser, basec].
411Note:
412.I update
413was not intended to be used for the entire screen.
414It would work but be very slow and take 64K bytes
415of memory just for mold and mnew.
416It was intended for 100 by 100 windows with objects in the center
417of them, and is quite fast for such windows.
418.TP
419.B vidinv()
420Set inverse video mode.
421.TP
422.B vidnorm()
423Set normal video mode.
424.TP
425.B zermat(m, rows, cols) bitmat m;
426Set the bit matrix
427.I m
428to all zeros.
429.TP
430.B zoomn(size)
431Set the hardware zoom to value
432.I size,
433which can range from 1 to 15.
434.TP
435.B zoomoff()
436Turn zoom off.
437This forces the screen to zoom level 1 without affecting the
438current internal zoom number.
439.TP
440.B zoomon()
441Turn zoom on.
442This restores the screen to the previously specified zoom size.
443.SH DIAGNOSTICS
444The routine
445.I error
446is called when an error is detected.
447The only error currently detected is overflow of the buffer
448provided to
449.IR readline .
450.PP
451Subscripts out of bounds to
452.I setmat
453return without setting anything.
454.SH FILES
455/usr/lib/lib2648.a
456.SH "SEE ALSO"
457fed(1)
458.SH AUTHOR
459Mark Horton
460.SH BUGS
461This library is not supported.
462It makes no attempt to use all of the features of the terminal,
463only those needed by fed.
464Contributions from users will be accepted for addition to the library.
465.PP
466The HP 2648 terminal is somewhat unreliable at speeds over 2400 baud,
467even with the ^E/^F handshaking.
468In an effort to improve reliability, handshaking is done every 32 characters.
469(The manual claims it is only necessary every 80 characters.)
470Nonetheless, I/O errors sometimes still occur.
471.PP
472There is no way to control the amount of debugging output generated
473on
474.I trace
475without modifying the source to the library.