|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - download
Length: 5605 (0x15e5) Types: TextFile Notes: UNIX file Names: »main.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦2d53db1df⟧ UNIX Filesystem └─ ⟦this⟧ »hr/src/desk/main.c«
#include <signal.h> #include <stdio.h> #include "desk.h" int myfd; POINT dskMpt; /* previous mouse position */ int dskWin; /* "active" window device no. */ int dskFntA; /* desktop font ascent */ int dskFntH; /* desktop font height(leading) */ struct dproc *dskTop, /* topmost layer process */ *dskBot, /* bottommost layer process */ dproc[WINDOW+DNW] = /* process/layer table */ { { 0, {0,0,0,0}, 0, 0 }, /* driver process */ { 0, {0,0,0,0}, 0, 0 }, /* smgr process */ { 0, {0,0,0,0}, 0, 0 }, /* dmgr process */ { 0, {0,0,0,0}, 0, 0 }, /* wmgr process */ { 0, {0,0,0,0}, 0, 0 }, /* wmgr process */ { 0, {0,0,0,0}, 0, 0 }, /* wmgr process */ { -1, {0,0,0,0}, 0, 0 }, /* 1st shell window */ { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, /* clock window */ { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, /* 1st graph window */ { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 }, { -1, {0,0,0,0}, 0, 0 } }; char SH[] = "/bin/sh"; char CLKSH[] = "/usr/hr/bin/clocksh"; char GSH[] = "/usr/hr/bin/gsh"; char SNAME[] = "-sh"; char CNAME[] = "clocksh"; char GNAME[] = "gsh"; char *shell[DNW][2] = { SH, SNAME, SH, SNAME, SH, SNAME, SH, SNAME, SH, SNAME, SH, SNAME, SH, SNAME, SH, SNAME, CLKSH, CNAME, NULL, NULL, GSH, GNAME, GSH, GNAME, GSH, GNAME, GSH, GNAME, }; struct mouse mouse; char *menu0[5] = { "New Shell", "New Graphics", "Clock", "", "Exit", "Redisplay All" }; char *menu1[] = { "Move", "Stretch", "Expose", "Hide", "Redisplay", "Quit" }; int (*fmenu[2][6])() = { {fshell, fgshell, fclock, fnull, fexit, fupdall }, {fmove, fstretch, ffront, fback, fupdate, fquit } }; char *mexit[4] = { "ARE YOU SURE?", NULL, "Click the LEFT button to confirm.", "Click the MIDDLE or RIGHT buttons to cancel." }; char *mstretch[] = { "CHANGE WINDOW SIZE.", NULL, "Move MOUSE to right or lower window border.", "Press LEFT button. Then move MOUSE and release button.", "OR, click the MIDDLE or RIGHT buttons now to cancel." }; int alstretch; int alexit; fexit() { AL_Open(alexit); if ( dnLwait() ) { AL_Close(); abort(); } else { upAwait(); AL_Close(); } } int almove; fmove() { RECT rect; RECT *r; extern int ghost(); ioctl(myfd, CIOMOUSE, MOV_MOUSE); if ( dnLwait() ) { if ( in_window(mouse.pt) || in_window(mouse.pt.x+MOUSEWIDTH-1, mouse.pt.y+MOUSEHEIGHT-1) || in_window(mouse.pt.x, mouse.pt.y+MOUSEHEIGHT-1) || in_window(mouse.pt.x+MOUSEWIDTH-1, mouse.pt.y) ) { rect = *(r = &dproc[dskWin].prect); dskMpt = mouse.pt; D_Frame(r, 1); upLwait( ghost ); D_Frame(r, 1); ioctl(myfd, CIOMSEOFF); if ( !setOrigin(r->origin) ) *r = rect; ioctl(myfd, CIOMSEON); } } else upAwait(); ioctl(myfd, CIOMOUSE, DSK_MOUSE); } ffront() { register struct dproc *p; if ( (p = &dproc[dskWin]) == dskTop ) return; dp_remove(p); dp_insert(p); setFront(); } fback() { register struct dproc *p; if ( (p = &dproc[dskWin]) == dskBot ) return; dp_remove(p); dp_append(p); setBack(); } fnull(){} abort() { int i; unTrack(); ioctl(myfd, CIOMSEOFF); close(myfd); fflush(stdout); fflush(stderr); for ( i=SWBASE; i<DESTMAX ; i++ ) if ( dproc[i].pid >= 0 ) killit(dproc[i].pid); exit(0); } main() { int mn; extern int MU_Start(); extern int MU_Point(); signal(SIGSEGV, abort); signal(SIGINT, abort); myfd = open("/dev/dmgr", 2); ioctl(myfd, CIOMOUSE, DSK_MOUSE); ioctl(myfd, CIOMSEON); FM_init(); MU_New(DSKMENU, 6, menu0); MU_New(WINMENU, 6, menu1); alexit = AL_New(4, mexit); alstretch = AL_New(5, mstretch); top: dnRwait(); Track(); MU_Start( (dskWin >= WINDOW ? WINMENU : DSKMENU), mouse.pt); upRwait( MU_Point ); mn = MU_End(); if ( mn != -1 ) { (* fmenu[mn>>8][mn&0xff])(); } unTrack(); goto top; } strlen(s) register char *s; { register int i; i=0; while ( *s++ != '\0' ) i++; return i; } killit(pid) int pid; { int pid2; kill(pid, SIGKILL); while ( (pid2=wait(NULL)) >= 0 && pid2 != pid ) ; } croak( fmt ) char *fmt; { fprintf(stderr, "dmgr: %r\n", &fmt); abort(); } nomem() { croak("no mem"); } /* ** Is the point inside the visible part of dskWin? */ in_window(pt) POINT pt; { register struct dproc *p; for ( p = dskTop; p != &dproc[dskWin] ; p = p->pnext ) { if ( R_point_in( p->prect, pt ) ) return 0; } return R_point_in( p->prect, pt); } ghost() { RECT rect; register RECT *r; r = &dproc[dskWin].prect; D_Frame( r, 1); if ( mouse.pt.x < dskMpt.x ) { rect.origin.x = r->origin.x - dskMpt.x + mouse.pt.x; if ( rect.origin.x < XMIN ) rect.origin.x = XMIN; rect.corner.x = rect.origin.x + (r->corner.x - r->origin.x); } else { rect.corner.x = r->corner.x - dskMpt.x + mouse.pt.x; if ( rect.corner.x > XMAX ) rect.corner.x = XMAX; rect.origin.x = rect.corner.x - (r->corner.x - r->origin.x); } if ( mouse.pt.y < dskMpt.y ) { rect.origin.y = r->origin.y - dskMpt.y + mouse.pt.y; if ( rect.origin.y < YMIN ) rect.origin.y = YMIN; rect.corner.y = rect.origin.y + (r->corner.y - r->origin.y); } else { rect.corner.y = r->corner.y - dskMpt.y + mouse.pt.y; if ( rect.corner.y > YMAX ) rect.corner.y = YMAX; rect.origin.y = rect.corner.y - (r->corner.y - r->origin.y); } dskMpt = mouse.pt; *r = rect; D_Frame(r, 1); }