|
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: 5084 (0x13dc) Types: TextFile Notes: UNIX file Names: »dmesg.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦2d53db1df⟧ UNIX Filesystem └─ ⟦this⟧ »hr/src/desk/dmesg.c«
#include <signal.h> #include <stdio.h> #include <errno.h> #include "desk.h" MESSAGE dskM; readmsg() { struct job *p; top: if ( ioctl(myfd, CIOGETM, &dskM) != 0 ) { if ( errno != EDATTN ) croak("CIOGETM errno = %d", errno); return -1; } if ( dskM.msg_Sender == DRIVER ) switch ( dskM.msg_Cmd ) { case SM_MKEY: mouse.tog = dskM.msg_Data[1] & (MRIGHT+MLEFT+MMID); mouse.but = dskM.msg_Data[2] & (MRIGHT+MLEFT+MMID); case SM_MOUSE: mouse.pt.x = dskM.msg_Data[1] & MMASK; mouse.pt.y = dskM.msg_Data[2] & MMASK; break; case SM_KKEY: goto top; default: croak("Bad cmd from DRIVER = %d", dskM.msg_Cmd); } else if ( dskM.msg_Sender == SMGR ) switch ( dskM.msg_Cmd ) { case WM_MTRANS: dskM.msg_Cmd = SM_MKEY; mouse.tog = dskM.msg_Data[1] & (MRIGHT+MLEFT+MMID); mouse.but = dskM.msg_Data[2] & (MRIGHT+MLEFT+MMID); mouse.pt.x = dskM.msg_Data[1] & MMASK; mouse.pt.y = dskM.msg_Data[2] & MMASK; break; case WM_MMOVE: dskM.msg_Cmd = SM_MOUSE; mouse.pt.x = dskM.msg_Data[1] & MMASK; mouse.pt.y = dskM.msg_Data[2] & MMASK; break; case WM_REPLY: break; case WM_ACK: dskM.msg_Cmd = WM_REPLY; dskM.msg_Data[0] |= 0xff; break; case WM_NACK: dskM.msg_Cmd = WM_REPLY; dskM.msg_Data[0] &= 0xff00; break; default: croak("Bad cmd from SMGR = %d", dskM.msg_Cmd); } else croak("Bad sender to DMGR = %d", dskM.msg_Sender); return dskM.msg_Cmd; } sendmsg(m) register MESSAGE *m; { ioctl(myfd, CIOUHOLD); m->msg_Sender = SMGR; m->msg_Data[0] = dskWin << 8; while ( 1 ) { if(ioctl( myfd, CIOSENDM, m) == 0) return; if( errno != EDBUSY) croak("CIOSENDM errno=%d", errno); readmsg(); } } /* ** Wait for ALL mouse buttons to be up. */ upAwait() { while ( mouse.but ) { readmsg(); } } /* ** Up transition waits on a single button don't care about ** transitions on the other two buttons. ** While the condition is not met, execute *ftn on the mouse ** location. */ upLwait(ftn) int (*ftn)(); { if ( ~mouse.but & MLEFT ) croak("upLwait"); do { (*ftn)(mouse.pt.x, mouse.pt.y); } while ( readmsg() != SM_MKEY || ~mouse.tog & MLEFT ); (*ftn)(mouse.pt.x, mouse.pt.y); } upRwait(ftn) int (*ftn)(); { if ( ~mouse.but & MRIGHT ) croak("upRwait"); do { (*ftn)(mouse.pt.x, mouse.pt.y); } while ( readmsg() != SM_MKEY || ~mouse.tog & MRIGHT ); (*ftn)(mouse.pt.x, mouse.pt.y); } /* ** Wait for single down transition on MLEFT. Or a cancel down ** transition on MMID or MRIGHT. All events are from DRIVER. ** ** Exit: ~0, if MLEFT down ** 0, if MMID or MRIGHT down */ dnLwait() { if ( mouse.but & MLEFT ) upLwait( fnull ); while ( 1 ) { if ( readmsg() != SM_MKEY ) continue; if ( mouse.tog == MLEFT ) return ~0; if ( mouse.tog ) return 0; } } /* ** Wait for single down transition on MRIGHT from SMGR. Don't ** return until you've got it. */ dnRwait() { while ( 1 ) { if ( readmsg() != SM_MKEY ) continue; if ( mouse.but == MRIGHT ) { dskWin = dskM.msg_Data[0] >> 8; return; } } } /* ** Take the window to the front. */ setFront() { MESSAGE m; m.msg_Cmd = SM_FRONT; sendmsg(&m); } /* ** Push the window to the back. */ setBack() { MESSAGE m; m.msg_Cmd = SM_BACK; sendmsg(&m); } /* ** Set the window's size. ** Enter: rp, rectangle pointer ** Exit: 0, if bad ** ~0, if OK. Corner coords are updated to actual position. */ setSize(rp) register RECT *rp; { MESSAGE m; m.msg_Cmd = SM_SETSIZE; m.msg_Data[1] = rp->corner.x - rp->origin.x; m.msg_Data[2] = rp->corner.y - rp->origin.y; sendmsg(&m); while ( readmsg() != WM_REPLY ) ; if ( dskM.msg_Data[0] & 0xff ) { rp->corner.x = dskM.msg_Data[1]; rp->corner.y = dskM.msg_Data[2]; return ~0; } else return 0; } /* ** Set the window's origin. ** Exit: 0, if bad ** ~0, if OK */ setOrigin(x0, y0) int x0; int y0; { MESSAGE m; m.msg_Cmd = SM_SETPHY; m.msg_Data[1] = x0; m.msg_Data[2] = y0; sendmsg(&m); while ( readmsg() != WM_REPLY ) ; return ( dskM.msg_Data[1] ); } /* ** Get the window's physical rectangle. ** Exit: 0, if bad ** ~0, if OK */ RECT getRect() { RECT rect; struct xfer xfer; MESSAGE m; rect.origin.x = 0; rect.origin.y = 0; rect.corner.x = 0; rect.corner.y = 0; m.msg_Cmd = SM_GETPHY; sendmsg(&m); while ( readmsg() != WM_REPLY ) ; xfer.x_src = SMGR; xfer.x_count = sizeof(RECT); xfer.x_dstp = (char *) ▭ xfer.x_srcp = (char *) addptr(dskM.msg_Data[1], dskM.msg_Data[2], 0); if ( xfer.x_srcp ) ioctl(myfd, CIOGETD, &xfer); return rect; } /* ** Track mouse movements and all mouse button events. */ Track() { MESSAGE m; ioctl(myfd, CIOEVMGR); ioctl(myfd, CIOHOLD); } /* ** Don't track mouse movements and only track DMGR mouse button events. */ unTrack() { MESSAGE m; ioctl(myfd, CIOUHOLD); ioctl(myfd, CIOUEVMGR); } /* ** Tell window manager to update a window. */ fupdate() { MESSAGE m; m.msg_Cmd = SM_UPDATE; sendmsg(&m); } /* ** Tell window managers to update all windows. */ fupdall() { MESSAGE m; m.msg_Cmd = SM_UPDALL; sendmsg(&m); }