|
|
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 - metrics - download
Length: 4167 (0x1047)
Types: TextFile
Notes: UNIX file
Names: »cmgr.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦2d53db1df⟧ UNIX Filesystem
└─⟦this⟧ »hr/src/clock/cmgr.c«
#include <signal.h>
#include <stdio.h>
#include <math.h>
#include <jlib.h>
#define CWOPEN 0x0001 /* its open */
#define CWUPD 0x0002 /* it needs updating */
#define CWLOCK 0x0004 /* busy drawing already */
#define CWINSET 20 /* amount to inset clipping region */
#define CWINDOW (WINDOW+8) /* devno of 1st window */
#define PUMP 127 /* window command for "tick" */
int myfd;
uint CXMAX,
CYMAX,
CXCEN,
CYCEN,
CXRAD,
CYRAD,
CFLAG;
char *MYDEVICE = "/dev/wmgr2";
struct jqueue sendq,
s_replyq;
struct job j_start();
RECT cwrect = /* new clock window rect */
{
32, 640, 160, 768
};
main()
{
extern int sigalrm();
myfd = open( MYDEVICE, 2);
if ( myfd < 0 )
croak("can't open %s", MYDEVICE);
jmain();
}
readmesg()
{
extern int cwalarm(), cwopen(), cwclose(), cwsize(), cwupd();
struct job *p;
MESSAGE m;
if ( ioctl(myfd, CIOGETM, &m) != 0 )
{
if ( !errno )
return;
if ( errno != EDATTN )
croak("CIOGETM errno = %d", errno);
while ( p = sendq.jq_head )
{
if ( ioctl(myfd, CIOSENDM, &p->j_m) != 0 )
{
if ( errno != EDBUSY )
croak("CIOSENDM errno = %d", errno);
break;
}
jalert( &sendq );
}
return;
}
if (m.msg_Sender == SMGR)
switch (m.msg_Cmd) {
case WM_CHARACTER:
case WM_MTRANS:
case WM_MMOVE:
break;
case WM_UPDATE:
if ( CFLAG & CWOPEN )
CFLAG |= CWUPD;
break;
case WM_SIZECHANGE:
jstart( cwsize );
break;
case WM_REPLY:
case WM_ACK:
s_replyq.jq_head->j_m = m;
jalert( &s_replyq );
break;
default:
croak( "bad command from smgr %d", m.msg_Cmd);
}
else if ( CWINDOW == m.msg_Sender )
switch (m.msg_Cmd) {
case WM_OPEN:
jstart( cwopen );
break;
case WM_GETC:
ioctl(myfd, CIODATA, m.msg_Sender, 0);
break;
case WM_TIOGETP:
case WM_TIOGETC:
m.msg_Data[0] = 0;
m.msg_Data[1] = 0;
m.msg_Data[2] = 0;
ioctl(myfd, CIOTCHRS, &m);
break;
case WM_PUTD:
case WM_TIOSETN:
case WM_TIOSETP:
case WM_TIOSETC:
case WM_TIOFLSH:
break;
case WM_CLOSE:
jstart( cwclose );
break;
case PUMP:
if ( ~CFLAG & CWLOCK )
{
CFLAG |= CWLOCK;
jstart( cwalarm );
}
break;
default:
fprintf(stderr, "clock: %d, cmd=%d, errno=%d\n",
m.msg_Sender, m.msg_Cmd, errno);
croak( "\007bad command from window");
}
else
{
fprintf(stderr, "clock: command %d\015\n", m.msg_Cmd);
fprintf(stderr, "clock: src %d, errno=%d\015\n", m.msg_Sender, errno);
croak( "\007bad src");
}
}
cwopen()
{
int i;
int y;
int count;
WIN_CREATE w;
extern RECT R_inset();
w.wc_type = 0;
w.wc_dims = cwrect;
w.wc_ascii = NULL;
i = S_Create(CWINDOW, &w);
if ( i < 0 )
{
printf("clock: Bad Wid %d", i);
ioctl(myfd, CIOACK, CWINDOW, -1);
return;
}
ioctl(myfd, CIOACK, CWINDOW, 0);
CFLAG = CWOPEN+CWLOCK;
CXMAX = cwrect.corner.x - cwrect.origin.x;
CYMAX = cwrect.corner.y - cwrect.origin.y;
CXCEN = CXMAX/2;
CYCEN = CYMAX/2;
CXRAD = CXCEN - CWINSET;
CYRAD = CYCEN - CWINSET;
setpoints();
drawface();
CFLAG &= ~CWLOCK;
}
cwclose()
{
CFLAG = 0;
S_Close(CWINDOW);
ioctl(myfd, CIOACK, CWINDOW, 0 );
}
cwsize()
{
register int cxmax, cymax;
RECT rect;
extern RECT S_GetPhy();
extern RECT R_inset();
if ( CFLAG & CWOPEN )
{
rect = S_GetPhy(CWINDOW);
cxmax = rect.corner.x - rect.origin.x;
cymax = rect.corner.y - rect.origin.y;
if ( cxmax < 80 )
cxmax = 80;
if ( cymax < 80 )
cymax = 80;
if ( cymax != CYMAX || cxmax != CXMAX )
{
CFLAG |= CWUPD;
CXMAX = cxmax;
CYMAX = cymax;
CXCEN = cxmax/2;
CYCEN = cymax/2;
CXRAD = CXCEN - CWINSET;
CYRAD = CYCEN - CWINSET;
setpoints();
}
}
}
cwline(x, y, xf, yf)
int x,
y,
xf,
yf;
{
G_Move(CWINDOW, x, y);
G_Line(CWINDOW, xf, yf);
}
cwtoline(x, y)
int x,
y;
{
G_Line(CWINDOW, x, y);
}
cwmove(x, y)
int x,
y;
{
G_Move(CWINDOW, x, y);
}
cwalarm()
{
if ( CFLAG & CWUPD )
{
CFLAG &= ~CWUPD;
drawface();
}
drawhands();
CFLAG &= ~CWLOCK;
}
warn(s)
char *s;
{
fprintf(stderr, "\007clock: %r\n", &s);
}
croak(s)
char *s;
{
fprintf(stderr, "clock: %r\n", &s);
exit(0);
}
nomem()
{
fprintf(stderr, "clock: no mem\n");
exit(0);
}