DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦d3f72b070⟧ TextFile

    Length: 11597 (0x2d4d)
    Types: TextFile
    Notes: UNIX file
    Names: »smgr.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦2d53db1df⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »hr/src/smgr/smgr.c« 

TextFile

#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include "smgr.h"

extern MESSAGE msg;
extern  int nameofroutine();
extern LAYER *DM_frontmost, *DM_rearmost;;
extern WSTRUCT *wtbl[];
extern void (*wmgr_tab[])();
extern FONT_HEADER *aftable[];

char	MYDEVICE[] = "/dev/smgr";
char	DEF_FONT[] = "/usr/hr/fonts/sysfont";
int	DEF_MOUSE[] = { 0xfffc, 0xfff8, 0xfff0, 0xffe0, 
			0xffc0, 0xffc0, 0xffe0, 0xfff0,
			0xfff8, 0xfffc, 0xf3fe, 0xe1ff,
			0x80ff, 0x007f, 0x003e, 0x001c };


#define SM_MSG_BUF (50)
MESSAGE mbuf[SM_MSG_BUF];
int mbuf_head, mbuf_tail;
int myfd;


sigalrm()
{
	signal(SIGALRM, sigalrm);
	ioctl(myfd, CIOWAIT);
	errno = 0;
	return ~0;
}


main()
{
	int i;

#ifdef DEBUG
	peteprint("initial entry\n");
#endif

	signal(SIGSEGV, nameofroutine);
	myfd = open( MYDEVICE, 2);
	if ( myfd < 0 )
	{
		peteprint("open failed %s\n", MYDEVICE);
		exit(0);
	}

	ioctl(myfd, CIOEVMGR);
	signal(SIGALRM, sigalrm);

	
	for ( i = 0; i < SM_MSG_BUF; i++ )
	{
		mbuf[i].msg_Sender = 0;
		mbuf[i].msg_Cmd = 0;
		mbuf[i].msg_Data[0] = 0;
		mbuf[i].msg_Data[1] = 0;
		mbuf[i].msg_Data[2] =0;
	}
	mbuf_head = mbuf_tail = 0;

	for ( i = 0; i < FM_MAXFONT; i++) 
		aftable[i] = (FONT_HEADER *)FONT_NULL;

	i = FM_open(DEF_FONT);
	if ( i != 0 )
	{
		peteprint("System Font failed to open\n");
		exit(0);
	}

	SM_Reset();

	ioctl(myfd, CIOMOUSE, DEF_MOUSE);	
	ioctl(myfd, CIOMSEON, (char*)NULL);
	sm_main();
}

sm_main()
{
	MESSAGE m;
	
#ifdef DEBUG
	peteprint(" sm_main\n");
#endif
	
	loop 
	{
		if ( ioctl(myfd, CIOGETM, &m) < 0 )
		{
			if ( !errno )
				continue;

			if ( errno != EDATTN )
				die( "CIOGETM errno = %d\n", errno);

		        while ( mbuf_head != mbuf_tail )
			    if ( ioctl( myfd, CIOSENDM, &mbuf[mbuf_head]) < 0 )
				if ( errno != EDBUSY )
					die( "CIOSENDM errno = %d\n", errno);
				else
					break;
			    else
			    {
#ifdef MESSAGETRACE
peteprint("empty one message wid = %d\n", mbuf[mbuf_head].msg_Data[0]>>8);
#endif
				if (++mbuf_head == SM_MSG_BUF )
					mbuf_head = 0;
			    }
		}
		else
		     do_msg(&m);
	}

}



do_msg(m)
MESSAGE *m;
{
	register int wid;
	msg = *m;

#ifdef DEBUG
peteprint("\nINCOMING MESSAGE : %d, %d, %d, %d, %d\n", msgSender, msgCmd, 
	msgData0, msgData1, msgData2);
peteprint("\tlast three in hex : %x, %x, %x\n", msgData0, msgData1, msgData2);
#endif

	/* map the window id, a minor device number, down into the range */
	/* zero (0) - MAX_WINDOW                                         */
	/* This process is reversed on the way out by sendmsg            */
	/* ONLY IF msgWid >= WINDOW                                      */
	if ( msgWid >= WINDOW )
		msgWid -= WINDOW;
#ifdef TRACE
	else
	  if ( (msgSender != 0) && (msgSender != DESKTOP) )
		peteprint("funky wid (%d) from %d\n", msgWid, msgSender);
#endif

	wid = msgWid;

	if ( msgCmd == 100 )
		exit(0);

	/* There are only three valid sources of messages.  A window */
	/* manager, the desktop process, and the kbd_mouse hardware  */
	if ( not isvsender(msgSender)  )
	{
#ifdef TRACE
		peteprint("not valid sender %d\n", msgSender);
#endif
		return;
	}

	/* make sure it's a valid command number                     */
	if ( not isvcmd(msgCmd)  )
	{
#ifdef TRACE
		peteprint("invalid cmd : %d\n", msgCmd);
#endif
		return;
	}

	/* the mouse is only allowed to do two things, both of which */
	/* require an active window                                  */
	if ( iskbdmouse(msgSender) )
	{
		if ( msgCmd == SM_KKEY )
			SM_Keyboard();
		else if ( msgCmd == SM_MKEY )
			SM_Mmkey();
		else if ( msgCmd == SM_MOUSE )
			SM_Mouse();
		/* in any event... */
		return;
	}

	switch (msgCmd ) 
	{
		case SM_OPENFONT:
				SM_OpenFont();
				return;
		case SM_CLOSEFONT:
				SM_CloseFont();
				return;
		case SM_GETFONTPARAM:
				SM_GetFontParam();
				return;

		case SM_CREATE:
				SM_Create();
				return;
		
		case SM_CLOSE:
			/* The only difference here is that you don't */
			/* save off the window when you exit          */
			if ( not legalwindow(wid) )
			{
#ifdef TRACE
				peteprint("close illegal window\n");
#endif
				return;
			}
	
			if ( wtbl[wid]!=(WSTRUCT *)NULL ) 
				gk = *wtbl[wid];
			else 
			{
#ifdef TRACE
				peteprint("close null window\n");
#endif
				return;
			}
	
			/* and now, make sure that if this is a
			 * window manager request
			 * that this window manager owns this window
			*/
			if ( iswmgr(msgSender) )
				if ( msgSender != gkWmgr )
				{
#ifdef TRACE
					peteprint("wrong wmgr\n");
#endif
					return;
				}
	
			(*wmgr_tab[msgCmd])();
			return;
		case SM_WRESET:
	
		case SM_GETXCLIP:
		case SM_GETYCLIP:
		case SM_SETXCLIP:
		case SM_SETYCLIP:
		case SM_CLRCLIP:
	
		case SM_GETPHY:
		case SM_SETLOG:
		case SM_GETLOG:
	
		case SM_SETEVMSK:
		case SM_GETEVMSK:
		case SM_RSTEVMSK:
	
		case SM_SETMPAT:
		case SM_GETMPAT:
		case SM_GETMOUSE:
	
		case SM_CHAR:
		case SM_STRING:
		case SM_CHARW:
		case SM_STRW:
		case SM_SCROLL:
		case SM_DEFCURS:
		case SM_DRAWCURS:
	
		case SM_SETGRAPH:
		case SM_GETGRAPH:
		case SM_RSTGRAPH:
		
		case SM_GETPOINT:
		case SM_RSTPOINT:
		case SM_POINT:
		case SM_TOPOINT:
		case SM_MOVE:
		case SM_TOMOVE:
		case SM_LINE:
		case SM_TOLINE:
		case SM_POLY:
		case SM_TOPOLY:
		case SM_RECT:
		case SM_RRECT:
		case SM_OVAL:
		case SM_WEDGE:
		case SM_ARC:
		case SM_AMAP:
			if ( not legalwindow(wid) )
			{
#ifdef TRACE
				peteprint("not legal window general\n");
#endif
				return;
			}
	
			if ( wtbl[wid]!=(WSTRUCT *)NULL ) 
				gk = *wtbl[wid];
			else 
			{
#ifdef TRACE
				peteprint("non-existant window general\n");
#endif
				return;
			}
	
			/* and now, make sure that if this is a
			 * window manager request
			 * that this window manager owns this window
			*/
			if ( iswmgr(msgSender) )
				if ( msgSender != gkWmgr )
				{
#ifdef TRACE
				peteprint("not owner general \n");
#endif
					return;
				}

	
			(*wmgr_tab[msgCmd])();
			*wtbl[wid] = gk;
			return;

	
		case SM_FRONT:
		case SM_BACK:
		case SM_SETPHY:
		case SM_SETSIZE:
		case SM_UPDATE:

			if ( not isdesktop(msgSender) )
			{
#ifdef TRACE
				peteprint("not desktop\n");
#endif
				return;
			}
				
			if ( not legalwindow(wid) )
			{
#ifdef TRACE
				peteprint("not legal wid, dtop\n");
#endif
				msgCmd = WM_NACK;
				msgReceiver = DESKTOP;
				sendmsg( &msg );
				return;
			}
			if ( wtbl[wid]!=(WSTRUCT *)NULL ) 
				gk = *wtbl[wid];
			else 
			{
#ifdef TRACE
				peteprint("null window, dtop\n");
#endif
				msgCmd = WM_NACK;
				msgReceiver = DESKTOP;
				sendmsg( &msg );
				return;
			}
	
			(*wmgr_tab[msgCmd])();
			*wtbl[wid] = gk;
			return;

		case SM_TRACK:
		case SM_UNTRACK:
		case SM_UPDALL:
		case SM_WHOTOPAT:
		case SM_WHOFRONT:
			if ( not isdesktop(msgSender) )
			{
#ifdef TRACE
				peteprint("not dtop, final\n");
#endif
				return;
			}
			(*wmgr_tab[msgCmd])();
			return;
			break;
	
		default:
			peteprint("Bad cmd in switch %d\n", msgCmd);
			break;
	}
}





sendmsg(m)
register MESSAGE *m;
{
	MESSAGE mm;

	/* map the window id back up to a minor device number unless it */
	/* was a negative number, in which case leave it alone          */

	mm = *m;

	if ( (mm.msg_Data[0] >> 8) >= 0 )
		mm.msg_Data[0] += WINDOW << 8;
#ifdef TRACE
	else
		if ( mm.msg_Receiver != DESKTOP )
			peteprint("sending funky wid %d to %d \n",
				 mm.msg_Data[0], mm.msg_Receiver);
#endif

	if ( mbuf_head == mbuf_tail )
		if ( ioctl( myfd, CIOSENDM, &mm) < 0 )
		{
			if ( errno != EDBUSY )
				die( "CIOSEND errno = %d\n", errno);
		}
		else
			return;

	if (mbuf_tail == (mbuf_head-1) )
	{
		peteprint(" internal buffer overflow\n");
		return;
	}
	if ( (mbuf_tail == (SM_MSG_BUF-1)) && (mbuf_head == 0) )
	{
		peteprint(" internal buffer overflow\n");
		return;
	}

		
		mbuf[mbuf_tail] = mm;
#ifdef MESSAGETRACE
	peteprint("add message wid = %d\n", mbuf[mbuf_tail].msg_Data[0]>>8);
#endif
		if ( ++mbuf_tail == SM_MSG_BUF )
			mbuf_tail = 0; 

			
}
		

getdata(src, n, srcp, dstp)
register uint src, n;
register char *srcp, *dstp;
{
	register XFER x;

	x.x_src = src;
	x.x_count = n;
	x.x_srcp = srcp;
	x.x_dstp = dstp;
	if ( ioctl(myfd, CIOGETD, &x) < 0 )
		die(" CIOGETD errno = %d\n", errno);
}



nameofroutine()
{
	fflush(stdout);
	fflush(stderr);
	peteprint("How dare you attempt to violate a segment which doesn't\n");
	peteprint("belong to you.  You animal !!!\n");
	exit(0);
}

peteprint( fmt )
char	*fmt;
{
	FILE *fopen(), *pp;
	pp = fopen("/dev/console", "w");
	if ( pp == NULL )
		printf("peteprint blew up \n");
	fprintf(pp, "SMGR: %r", &fmt);
	fclose(pp);
}


die( fmt )
char *fmt;
{
	FILE *fopen(), *fp;
	
	fp = fopen("/dev/console", "w");
	fprintf(fp, "%r\n", &fmt);
	exit(1);
}


#ifdef TRACE
int DB_dump()
{
	register int i;
	LAYER *lp;
	FILE *fopen(), *fp;

	fp = fopen("/dev/console", "w");


	fprintf(fp, "\n\nfr = 0x%lx, re = 0x%lx\n", 
		DM_frontmost, DM_rearmost);

	for (i=0; i<MAX_WINDOWS; i++ )
		if ( wtbl[i] != (WSTRUCT *)NULL)
			DB_pw(i);
	fprintf(fp, "Unallocated Windows : ");
	for (i=0; i<MAX_WINDOWS; i++)
		if ( wtbl[i] == (WSTRUCT *)NULL)
			fprintf(fp, " %d ", i);
	fprintf(fp,"\n");
	fprintf(fp, "list from front to rear : ");
	for ( lp = DM_frontmost; lp; lp = lp->back )
		fprintf(fp, " %d ", wtbl[lp2id(lp)]->wn_Wid);
	fprintf(fp,"\n");
	fprintf(fp," list from rear to front : ");
	for ( lp = DM_rearmost; lp; lp = lp->front )
		fprintf(fp, " %d ", wtbl[lp2id(lp)]->wn_Wid);
	
	fprintf(fp, "\n\n\n");
	fclose(fp);
	return;
}

int DB_map()
{
	register int i;
	FILE *fopen(), *fp;

	fp = fopen("/dev/console", "w");

	fprintf(fp, "\nAllocated windows : ");
	for (i=0; i<=MAX_WINDOWS; i++ )
		if ( wtbl[i] != (WSTRUCT *)NULL)
			fprintf(fp, " %d ", i);
	fprintf(fp, "\n\n\n");
	fclose(fp);
	return;
}




DB_pw(id)
int id;
{
	WSTRUCT *wp, w;
	RECT r;
	int i;
	FILE *fopen(), *fp;

	fp = fopen("/dev/console", "w");

	fprintf(fp, "\n");
	fprintf(fp, "Window %d\n", id);
	wp = wtbl[id];
	if ( wp == (WSTRUCT *)NULL)
	{
		fprintf(fp, "Window undefined\n");
		return;
	}

	w = *wp;
	

	r = w.wn_Layer->rect;
	fprintf(fp, "Wid = %d  Type = %d  Flags = %d, Ev = %d, Wmgr = %d\n",
		w.wn_Wid, w.wn_Type,w.wn_Flags,w.wn_Evmask,w.wn_Wmgr);
	fprintf(fp, "Layer data: (%d,%d) (%d,%d) w = %d, b = 0x%lx\n ",
		 r.origin.x, r.origin.y, r.corner.x, r.corner.y,
		 w.wn_Layer->width, w.wn_Layer->base);

	r = w.wn_Crect;
fprintf(fp, "Clipping rect: (%d,%d) (%d,%d) Psize = (%d,%d),Lorig = (%d,%d)\n",
	 r.origin.x, r.origin.y, r.corner.x, r.corner.y,
	w.wn_Psize.x, w.wn_Psize.y, w.wn_Lorigin.x, w.wn_Lorigin.y);
	
	fprintf(fp, "Font: %d, Pen : H = %d  W = %d,  P = %d\n", 
	     w.wn_G.wn_Font.fi_Id, w.wn_G.wn_Pen.pn_Height,
	     w.wn_G.wn_Pen.pn_Width, w.wn_G.wn_Pen.pn_Pat);

	fprintf(fp, "Dp = (%d, %d) FPat = %d,  BPat = %d,  Logop = %d\n",
	 w.wn_Dp.x, w.wn_Dp.y,  w.wn_G.wn_Fpat,
		w.wn_G.wn_Bpat, w.wn_G.wn_Logop);
	

	fprintf(fp, "Visible list printing :\n");
	for( i = 0; i < MAX_LRBUF; i++ )
	  if ( w.wn_Layer->reg[i].flag )
	    DB_bmpr( w.wn_Layer->reg[i] );
	fprintf(fp, "\n");
	fclose(fp);
}



DB_bmpr(i)
SM_REGION i;
{
	FILE *fopen(), *fp;
	fp = fopen("/dev/console", "w");	

	fprintf(fp, "\t(%d, %d), (%d, %d), w = %d, b = 0x%lx ",
		i.bm.rect.origin.x, i.bm.rect.origin.y,
		i.bm.rect.corner.x, i.bm.rect.corner.y,
		i.bm.width, i.bm.base);
	if ( i.flag == L_VISIBLE )
		fprintf(fp, "VISIBLE\n");
	else if ( i.flag == L_OBSCURED )
		fprintf(fp, "OBSCURED by %d\n", lp2id(i.cov_by));
	else 
		fprintf(fp, "ERROR\n");
	fclose(fp);
	return;
}




DB_prect(r)
RECT r;
{
	FILE *fopen(), *fp;
	fp = fopen("/dev/console", "w");

fprintf(fp, "\t(%d, %d), (%d, %d)\n", r.origin.x,r.origin.y,r.corner.x,r.corner.y);
	fclose(fp);
}
#endif