🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by mikem Tue, 16 Apr 1985 23:41
Sun device driver for S.
#88
Author: mikem
Date: Tue, 16 Apr 1985 23:41
505 lines
13659 bytes
Here is the S device driver for Sun workstations.  I'm sorry it took me
so long to post this, but there was a bug to fix before it could go out.
Please note, that I am not the author of this software and I won't
listen to complaints (or praise!) or problems with it. Please use it if
you can.

Mike Meyer

(----------------------------CUT----------------------------)
#!/bin/sh
echo 'Start of SUNDRIVER, part 01 of 01:'
echo 'x - DO.THIS'
sed 's/^X//' > DO.THIS << '/'
Xdefine(`SUNBW',`-100')
Xdefine(`SUNCOLOR',`-101')
/
echo 'x - README'
sed 's/^X//' > README << '/'
XAdd the contents of  DO.THIS  to $I/device.m  .  Otherwise it should work.
/
echo 'x - Smakefile'
sed 's/^X//' > Smakefile << '/'
Xall: sun dev.sun 
X
Xsun: interface.o sun.x
X	$(F77) $(LDFLAGS) $(STRIP) -o x/sun interface.o sun.x $(LIBR)
X	/bin/rm -f x/csun > /dev/null 2>&1
X	/bin/ln x/sun x/csun
X	@touch sun
X	@echo sun loaded
Xinterface.C: ; echo "INCLUDE(u/cinter)CINTER(sun)" >interface.C
X
Xdev.sun: sun.o
X	$(F77) $(LDFLAGS) $(STRIP) -o x/dev.sun $L/device.z sun.o $(GRZLIB) -lc
Xore -lsunwindow -lpixrect
X	@touch dev.sun
X	@echo sun driver loaded
/
echo 'x - sun.C'
sed 's/^X//' > sun.C << '/'
X#include <usercore.h>
X#include <sunwindow/window_hs.h>
XINCLUDE(device)
X
X#define am(i)		bgrp_[i-1]
X#define FOREVER		2147483647
X
Xfloat F77_SUB(bgrp)[200];
Xfloat aspect;
Xfloat char_width = 0.02, char_height = 0.02;
Xstruct vwsurf vws, *surface = &vws;
Xstruct rect r;
Xint ask = 1;
Xint color = 0;
Xint colorpos = SCR_WEST;
Xint nseg = 1;
Xint cg1dd();
Xint cgpixwindd();
X
XF77_SUB(pbegnz)(par, n)
Xfloat par[];
Xlong *n;
X{
X	int i;
X	char *av[4];
X	char *getenv(), *gfx, *me;
X	float zero = 0, one = 1;
X
X	if(*n >= 1)
X		ask = par[0];
X	if(*n >= 2)
X		color = par[1];
X	if(*n >= 3)
X		colorpos = par[2] < 0 ? colorpos : par[2];
X
X	/* find the surface on which to do the graphics */
X	i = 0;
X	av[i++] = "";
X	if(color) {
X		av[i++] = "-d";
X		av[i++] = "/dev/cgone0";
X	}
X	av[i++] = 0;
X	if(get_view_surface(&vws, av))
X		FATAL(Cannot initialize sun device driver);
X
X	/* don't blanket a tty subwindow */
X	gfx = getenv("WINDOW_GFX");
X	me = getenv("WINDOW_ME");
X	if(gfx && me && strcmp(gfx, me) == 0)
X		surface->flags = VWSURF_NEWFLG;
X
X	/* prepare for output */
X	if(initialize_core(BUFFERED, SYNCHRONOUS, TWOD))
X		FATAL(Cannot initialize SunCore)
X	if(initialize_view_surface(surface, FALSE))
X		FATAL(Cannot initialize view surface);
X	if(select_view_surface(surface))
X		FATAL(Cannot select view surface);
X	win_getsize(surface->windowfd, &r);
X	aspect = (float)r.r_height / (float)r.r_width;
X	set_ndc_space_2(1.0, aspect);
X	set_viewport_2(0.0, 1.0, 0.0, aspect);
X	set_window(0.0, 1.0, 0.0, 1.0);
X
X	/* prepare for input */
X	initialize_device(LOCATOR, 1);
X	set_echo_surface(LOCATOR, 1, surface);
X	set_echo(LOCATOR, 1, 1);	/* pointing finger cursor */
X	for(i = 1; i <= 3; i++) {
X		initialize_device(BUTTON, i);
X		set_echo_surface(BUTTON, i, surface);
X	}
X
X	/* fill the amodes array */
X	fill_am();
X
X	/* open segment and initialize character primitive static attributes */
X	create_retained_segment(nseg = 1);
X	set_charprecision(`CHARACTER');
X	set_charsize(char_width, char_height);
X	set_font(STICK);
X
X	/* establish the relative positions of the b&w and color monitors */
X	if(color && colorscreen(surface->windowfd))
X		WARNING(Cannot extend cursor domain to color screen);
X}
X
XF77_SUB(zlinsz)(x, y, n)
Xfloat x[], y[];
Xlong *n;
X{
X	if(*n <= 0)
X		return;
X	move_abs_2(x[0], y[0]);
X	polyline_abs_2(&x[1], &y[1], (int)*n - 1);
X}
X
XF77_SUB(zpntsz)(x, y, n)
Xfloat x[], y[];
Xlong *n;
X{
X	char buf[2];
X	int i, s;
X
X	if(*n <= 0)
X		return;
X	polymarker_abs_2(x, y, (int)*n);
X}
X
XF77_SUB(zpolyz)(x, y, n)
Xfloat x[], y[];
Xlong *n;
X{
X	if(*n <= 0)
X		return;
X	polygon_abs_2(x, y, (int)*n);
X	move_abs_2(x[0], y[0]);
X	polyline_abs_2(&x[1], &y[1], (int)*n - 1);
X	polyline_abs_2(&x[0], &y[0], 1);
X}
X
XF77_SUB(zsegsz)(x1, y1, x2, y2, n)
Xfloat x1[], y1[], x2[], y2[];
Xlong *n;
X{
X	int i;
X
X	for(i = 0; i < *n; i++) {
X		move_abs_2(*x1++, *y1++);
X		line_abs_2(*x2++, *y2++);
X	}
X}
X
XF77_SUB(ztextz)(x, y, string, nch, adj, lch)
Xchar *string;
Xfloat *x, *y, *adj;
Xlong *nch, lch;
X{
X	float dx, dy, nx, ny;
X	float vxmin, vxmax, vymin, vymax;
X	float wxmin, wxmax, wymin, wymax;
X	char *buf, *malloc();
X
X	buf = malloc(*nch + 1);
X	if(buf == (char *)0)
X		FATAL(Cannot allocate memory for ztextz)
X	strncpy(buf, string, *nch);
X	buf[*nch]='\0';
X
X	/*
X	 * To keep a constant aspect ratio for characters, we
X	 * first find the desired string position in NDC space,
X	 * then open a new segment with world coords which match
X	 * NDC space.  This string is plotted, and the remembered
X	 * previous viewport and window are restored in another
X	 * retained segment.
X	 */
X	map_world_to_ndc_2(*x, *y, &nx, &ny);
X	inquire_viewport_2(&vxmin, &vxmax, &vymin, &vymax);
X	inquire_window(&wxmin, &wxmax, &wymin, &wymax);
X	close_retained_segment(nseg);
X	set_charsize(am(18)*char_width*0.5, am(18)*char_height*0.5);
X	set_viewport_2(0.0, 1.0, 0.0, aspect);
X	set_window(0.0, 1.0, 0.0, aspect);
X	create_retained_segment(++nseg);
X	inquire_text_extent_2(buf, &dx, &dy);
X	move_abs_2(nx - *adj * dx, ny - *adj * dy);
X	text(buf);
X	close_retained_segment(nseg);
X	set_viewport_2(vxmin, vxmax, vymin, vymax);
X	set_window(wxmin, wxmax, wymin, wymax);
X	create_retained_segment(++nseg);
X	free(buf);
X}
X
XF77_SUB(zejecz)()
X{
X	if(ask) {
X		fprintf(stderr, "GO? ");
X		while(getchar() != '\n') ;	/* ignore reply */
X	}
X	delete_all_retained_segments();
X	create_retained_segment(nseg = 1);
X}
X
X
XF77_SUB(zflshz)() { }
X
XF77_SUB(zintrz)() { }
X
XF77_SUB(zwrapz)()
X{
X	delete_all_retained_segments();
X	deselect_view_surface(surface);
X	terminate_view_surface(surface);
X	terminate_device(LOCATOR, 1);
X	terminate_core();
X}
X
XF77_SUB(zrdpnz)(x, y, n, nmax)
Xfloat x[], y[];
Xlong *n, *nmax;
X{
X	int but, i;
X	float xin, yin;
X
X	for(i = 0; i < *nmax; i++) {
X		/* set_locator_2(1, xin, yin); */
X		but = 0;
X		while(but == 0)
X			await_any_button_get_locator_2(FOREVER, 1, &but, &xin, 
X&yin);
X		if(but != 1)
X			break;
X		map_ndc_to_world_2(xin, yin, x++, y++);
X		fprintf(stderr, "\07");
X	}
X	*n = i;
X}
X
XF77_SUB(amdiff)(x, n) /* look for important parameter changes */
Xfloat x[];
Xlong *n;
X{
X	static int styles[] = {SOLID, DOTTED, DASHED, DOTDASHED};
X	static int nstyles = (sizeof(styles) / sizeof(*styles));
X	int i, which, istyle;
X	float value, fracx, fracy;
X	double sin(), cos(), dvalue;
X	int do_window = 0;
X
X	for(i = 0; i < *n; i += 2) {
X		which = x[i];
X		value = x[i + 1];
X		am(which) = value;
X		switch(which) {
X
X		case 8:
X			istyle = (int)(value - 1) % nstyles;
X			set_linestyle(styles[istyle]);
X			break;
X
X		case 9:
X			set_linewidth(value - 1);
X			break;
X
X		case 10:
X			set_line_index((int)value);
X			set_fill_index((int)value);
X			set_text_index((int)value);
X			break;
X
X		case 14:
X			dvalue = value * DEG2RD;
X			set_charpath_2(cos(dvalue), sin(dvalue));
X			dvalue += PI/2;
X			set_charup_2(cos(dvalue), sin(dvalue));
X			break;
X
X		case 15:
X			set_marker_symbol((char)value);
X			break;
X
X		case 40: /* plot in figure */
X		case 41:
X		case 42:
X		case 43:
X		case 44: /* figure on device */
X		case 45:
X		case 46:
X		case 47:
X		case 61: /* user coords */
X		case 62:
X		case 63:
X		case 64:
X		case 65: /* flag for clipping */
X			do_window = 1;
X			break;
X		}
X	}
X
X	if(!do_window)
X		return;
X
X	/* close current segment to change viewport and window */
X	close_retained_segment(nseg);
X	if(do_window && am(65) > 0) {
X		set_viewport_2(am(44), am(45), aspect*am(46), aspect*am(47));
X		fracx = (am(62)-am(61)) / (am(41)-am(40));
X		fracy = (am(64)-am(63)) / (am(43)-am(42));
X		set_window(
X			am(61) - am(40)*fracx,
X			am(62) + (1 - am(41))*fracx,
X			am(63) - am(42)*fracy,
X			am(64) + (1 - am(43))*fracy);
X	}
X	if(do_window && am(65) <= 0) {
X		fracx = am(45) - am(44);
X		fracy = am(47) - am(46);
X		set_viewport_2(
X			am(44) + am(40)*fracx,
X			am(44) + am(41)*fracx,
X			(am(46) + am(42)*fracy)*aspect,
X			(am(46) + am(43)*fracy)*aspect);
X		set_window(am(61), am(62), am(63), am(64));
X	}
X	create_retained_segment(++nseg);
X}
X
X
X
Xcolorscreen(color_fd)
Xint color_fd;
X{
X	int color_num, bw_fd, bw_num, i;
X	int color_neighbors[SCR_POSITIONS], bw_neighbors[SCR_POSITIONS];
X
X	/*
X	(void) signal(SIGWINCH, winch_catcher);
X	strcpy(color.scr_fbname, "/dev/cgone0");
X	colorpr = pr_open("/dev/cgone0");
X	pr_getcolormap(colorpr, 0, 256, red, green, blue);
X	color.scr_foreground.red = red[255];
X	color.scr_foreground.green = green[255];
X	color.scr_foreground.blue = blue[255];
X	color.scr_background.red = red[0];
X	color.scr_background.green = green[0];
X	color.scr_background.blue = blue[0];
X	color_fd = win_screennew(&color);
X	*/
X	color_num = win_fdtonumber(color_fd);
X	bw_fd = open("/dev/win0", 0);
X	if(bw_fd < 0)
X		return(1);
X	bw_num = win_fdtonumber(bw_fd);
X	for(i = 0; i < SCR_POSITIONS; i++)
X		color_neighbors[i] = bw_neighbors[i] = -1;
X	bw_neighbors[colorpos] = color_num;
X	color_neighbors[(2+colorpos)%4] = bw_num;
X	win_setscreenpositions(color_fd, color_neighbors);
X	win_setscreenpositions(bw_fd, bw_neighbors);
X	close(bw_fd);
X	return(0);
X}
X
Xfill_am()
X{
X	double drw, drh, px, py, c1em, dev_width, dev_height;
X	int i;
X
X	for(i = 1; i <= 130; i++)
X		am(i) = 0;
X
X	/* device specific paramaters */
X	am(20) = char_width * r.r_width;	/* char width in rasters */
X	am(21) = char_height * r.r_height;	/* char height in rasters */
X	am(22) = 0;  am(23) = r.r_width - 1;	/* x limits in rasters */
X	am(24) = 0;  am(25) = r.r_height - 1;	/* y limits in rasters */
X	am(26) = 0;  am(27) = 0;		/* char addressing offset */
X	am(28) = am(29) = color ? 0.016 : 0.0125;/* raster size in inches */
X	am(30) = color ? SUNCOLOR : SUNBW;	/* device code number (< 0)) */
X	am(31) = 1;				/* allow char rotation */
X	am(1) = 1;				/* allow char size change */
X
X	/* fixed parameters, mainly from defltz.r */
X	am(8) = 1;	am(9) = 1;	am(10) = 1;	am(11) = 1;
X	am(15) = 42;	am(17) = 3;	am(18) = 1;	am(45) = 1;
X	am(47) = 1;	am(49) = 1;	am(54) = 1;	am(57) = 5;
X	am(58) = 5;	am(59) = 7;	am(60) = 126;	am(62) = 1;
X	am(64) = 1;	am(66) = 0.02;	am(79) = -1;	am(80) = 1;
X	am(81) = 1;	am(82) = 1;	am(83) = 1;	am(85) = 0.2;
X	am(89) = 1;	am(91) = 1;	am(93) = 1;	am(94) = 1;
X	am(97) = 109;	am(100) = 0.5;	am(101) = -1;	am(102) = 115;
X	am(103) = 32;	am(105) = 1;	am(106) = 5;	am(107) = 115;
X	am(108) = 32;	am(110) = 1;	am(111) = 5;	am(112) = 3;
X	am(113) = 1;	am(119) = 111;	am(122) = 109;	am(130) = 0.001;
X
X	/* dependencies, mainly from zzpltz.r, zscalz.r and zcsizz.r */
X	drw = am(23) - am(22);
X	drh = am(25) - am(24);
X	am(70) = am(28);
X	am(71) = am(29);
X	am(74) = am(20) * am(28);
X	am(75) = am(21) * am(29);
X	c1em = max(am(74), am(75));
X	am(50) = am(51) = am(52) = am(53) = 7 * c1em;
X	am(123) = am(98) = drw * am(28);
X	am(124) = am(99) = drh * am(29);
X	am(40) = 7 * c1em / am(98);
X	am(41) = 1 - am(40);
X	am(42) = 7 * c1em / am(99);
X	am(43) = 1 - am(42);
X	px = am(41) - am(40);
X	py = am(43) - am(42);
X	am(76) = am(55) = am(98) * px;
X	am(77) = am(56) = am(99) * py;
X	am(32) = am(22) + am(40) * drw;
X	am(33) = am(22) + am(41) * drw;
X	am(34) = am(24) + am(42) * drh;
X	am(35) = am(24) + am(43) * drh;
X	am(36) = am(32);
X	am(37) = px * drw;
X	am(38) = am(34);
X	am(39) = py * drh;
X	am(67) = am(74) / am(76);
X	am(68) = am(75) / am(77);
X	am(72) = c1em / am(76);
X	am(73) = c1em / am(77);
X	am(84) = c1em / min(am(98),am(99));
X}
X
XF77_SUB(wclosz)(){}
XF77_SUB(wcopyz)(){}
XF77_SUB(wdiffz)(){}
XF77_SUB(wejecz)(){}
XF77_SUB(winitz)(){}
XF77_SUB(wlinsz)(){}
XF77_SUB(wpntsz)(){}
XF77_SUB(wpolyz)(){}
XF77_SUB(wsegsz)(){}
XF77_SUB(wtextz)(){}
XF77_SUB(wupdtz)(){}
XF77_SUB(wwrapz)(){}
X/*F77_MAIN (){}*/
/
echo 'x - sun.i'
sed 's/^X//' > sun.i << '/'
XFUNCTION sun(
X	ask	/REAL,1,0./
X	color	/LGL,1,streq(TEXT(FNAME),TSTRING(csun))/
X	pos	/INT,1,-1/
X	)
X
XSTRUCTURE(parms/REAL,3/, cpos)
XSTATIC(POINTER getds)
X
Xparms[1] = ask
Xif(color)
X	parms[2] = 1
Xelse
X	parms[2] = 0
Xparms[3] = pos
X#if(!MISSING(pos)) {
X	#P(cpos) = getds(TSTRING(Color.Monitor),0)
X	#if(P(cpos) != NULL) {
X		#COERCE(cpos/INT/)
X		#parms[3] = mod(cpos[1],4)
X	#}
X#}
X
XDEVICE_DRIVER(sun)
X
XRETURN(parms)
XEND
/
echo 'Part 01 of SUNDRIVER complete.'
exit

-- 

Mike Meyer --  Phone +1 (608) 262-1157 (Leave messages at 262-2598)

ARPA:  mikem@Statistics  <==>	mikem@Wisc-Stat.ARPA
UUCP:  ...!{allegra,ihnp4,seismo,ucbvax,pyr_chi,heurikon}!uwvax!uwstat!mikem
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads