home *** CD-ROM | disk | FTP | other *** search
- /* macfun.c - macintosh user interface functions for xlisp */
-
- #include <Quickdraw.h>
- #include <WindowMgr.h>
- #include <MemoryMgr.h>
- #include "xlisp.h"
-
- /* external variables */
- extern GrafPtr cwindow,gwindow;
-
- /* forward declarations */
- FORWARD LVAL do_0();
- FORWARD LVAL do_1();
- FORWARD LVAL do_2();
-
- /* xptsize - set the command window point size */
- LVAL xptsize()
- {
- LVAL val;
- val = xlgafixnum();
- xllastarg();
- TextSize((int)getfixnum(val));
- InvalRect(&cwindow->portRect);
- SetupScreen();
- return (NIL);
- }
-
- /* xhidepen - hide the pen */
- LVAL xhidepen()
- {
- return (do_0('H'));
- }
-
- /* xshowpen - show the pen */
- LVAL xshowpen()
- {
- return (do_0('S'));
- }
-
- /* xgetpen - get the pen position */
- LVAL xgetpen()
- {
- LVAL val;
- Point p;
- xllastarg();
- SetPort(gwindow);
- GetPen(&p);
- SetPort(cwindow);
- xlsave1(val);
- val = consa(NIL);
- rplaca(val,cvfixnum((FIXTYPE)p.h));
- rplacd(val,cvfixnum((FIXTYPE)p.v));
- xlpop();
- return (val);
- }
-
- /* xpenmode - set the pen mode */
- LVAL xpenmode()
- {
- return (do_1('M'));
- }
-
- /* xpensize - set the pen size */
- LVAL xpensize()
- {
- return (do_2('S'));
- }
-
- /* xpenpat - set the pen pattern */
- LVAL xpenpat()
- {
- LVAL plist;
- char pat[8],i;
- plist = xlgalist();
- xllastarg();
- for (i = 0; i < 8 && consp(plist); ++i, plist = cdr(plist))
- if (fixp(car(plist)))
- pat[i] = getfixnum(car(plist));
- SetPort(gwindow);
- PenPat(pat);
- SetPort(cwindow);
- return (NIL);
- }
-
- /* xpennormal - set the pen to normal */
- LVAL xpennormal()
- {
- xllastarg();
- SetPort(gwindow);
- PenNormal();
- SetPort(cwindow);
- return (NIL);
- }
-
- /* xmoveto - Move to a screen location */
- LVAL xmoveto()
- {
- return (do_2('m'));
- }
-
- /* xmove - Move in a specified direction */
- LVAL xmove()
- {
- return (do_2('M'));
- }
-
- /* xlineto - draw a Line to a screen location */
- LVAL xlineto()
- {
- return (do_2('l'));
- }
-
- /* xline - draw a Line in a specified direction */
- LVAL xline()
- {
- return (do_2('L'));
- }
-
- /* xshowgraphics - show the graphics window */
- LVAL xshowgraphics()
- {
- xllastarg();
- scrsplit(1);
- return (NIL);
- }
-
- /* xhidegraphics - hide the graphics window */
- LVAL xhidegraphics()
- {
- xllastarg();
- scrsplit(0);
- return (NIL);
- }
-
- /* xcleargraphics - clear the graphics window */
- LVAL xcleargraphics()
- {
- xllastarg();
- SetPort(gwindow);
- EraseRect(&gwindow->portRect);
- SetPort(cwindow);
- return (NIL);
- }
-
- /* do_0 - Handle commands that require no arguments */
- LOCAL LVAL do_0(fcn)
- int fcn;
- {
- xllastarg();
- SetPort(gwindow);
- switch (fcn) {
- case 'H': HidePen(); break;
- case 'S': ShowPen(); break;
- }
- SetPort(cwindow);
- return (NIL);
- }
-
- /* do_1 - Handle commands that require one integer argument */
- LOCAL LVAL do_1(fcn)
- int fcn;
- {
- int x;
- x = getnumber();
- xllastarg();
- SetPort(gwindow);
- switch (fcn) {
- case 'M': PenMode(x); break;
- }
- SetPort(cwindow);
- return (NIL);
- }
-
- /* do_2 - Handle commands that require two integer arguments */
- LOCAL LVAL do_2(fcn)
- int fcn;
- {
- int h,v;
- h = getnumber();
- v = getnumber();
- xllastarg();
- SetPort(gwindow);
- switch (fcn) {
- case 'l': LineTo(h,v); break;
- case 'L': Line(h,v); break;
- case 'm': MoveTo(h,v); break;
- case 'M': Move(h,v); break;
- case 'S': PenSize(h,v);break;
- }
- SetPort(cwindow);
- return (NIL);
- }
-
- /* getnumber - get an integer parameter */
- LOCAL int getnumber()
- {
- LVAL num;
- num = xlgafixnum();
- return ((int)getfixnum(num));
- }
-
- /* xtool - call the toolbox */
- LVAL xtool()
- {
- LVAL val;
- int trap;
-
- trap = getnumber();
- /*
-
- asm {
- move.l args(A6),D0
- beq L2
- L1: move.l D0,A0
- move.l 2(A0),A1
- move.w 4(A1),-(A7)
- move.l 6(A0),D0
- bne L1
- L2: lea L3,A0
- move.w trap(A6),(A0)
- L3: dc.w 0xA000
- clr.l val(A6)
- }
- */
-
- return (val);
- }
-
- /* xtool16 - call the toolbox with a 16 bit result */
- LVAL xtool16()
- {
- int trap,val;
-
- trap = getnumber();
- /*
-
- asm {
- clr.w -(A7)
- move.l args(A6),D0
- beq L2
- L1: move.l D0,A0
- move.l 2(A0),A1
- move.w 4(A1),-(A7)
- move.l 6(A0),D0
- bne L1
- L2: lea L3,A0
- move.w trap(A6),(A0)
- L3: dc.w 0xA000
- move.w (A7)+,val(A6)
- }
- */
-
- return (cvfixnum((FIXTYPE)val));
- }
-
- /* xtool32 - call the toolbox with a 32 bit result */
- LVAL xtool32()
- {
- int trap;
- long val;
-
- trap = getnumber();
- /*
-
- asm {
- clr.l -(A7)
- move.l args(A6),D0
- beq L2
- L1: move.l D0,A0
- move.l 2(A0),A1
- move.w 4(A1),-(A7)
- move.l 6(A0),D0
- bne L1
- L2: lea L3,A0
- move.w trap(A6),(A0)
- L3: dc.w 0xA000
- move.l (A7)+,val(A6)
- }
- */
-
- return (cvfixnum((FIXTYPE)val));
- }
-
- /* xnewhandle - allocate a new handle */
- LVAL xnewhandle()
- {
- LVAL num;
- long size;
- num = xlgafixnum(); size = getfixnum(num);
- xllastarg();
- return (cvfixnum((FIXTYPE)NewHandle(size)));
- }
-
- /* xnewptr - allocate memory */
- LVAL xnewptr()
- {
- LVAL num;
- long size;
- num = xlgafixnum(); size = getfixnum(num);
- xllastarg();
- return (cvfixnum((FIXTYPE)NewPtr(size)));
- }
-
- /* xhiword - return the high order 16 bits of an integer */
- LVAL xhiword()
- {
- unsigned int val;
- val = (unsigned int)(getnumber() >> 16);
- xllastarg();
- return (cvfixnum((FIXTYPE)val));
- }
-
- /* xloword - return the low order 16 bits of an integer */
- LVAL xloword()
- {
- unsigned int val;
- val = (unsigned int)getnumber();
- xllastarg();
- return (cvfixnum((FIXTYPE)val));
- }
-
- /* xrdnohang - get the next character in the look-ahead buffer */
- LVAL xrdnohang()
- {
- int ch;
- xllastarg();
- if ((ch = scrnextc()) == EOF)
- return (NIL);
- return (cvfixnum((FIXTYPE)ch));
- }
-
- /* ossymbols - enter important symbols */
- ossymbols()
- {
- LVAL sym;
-
- /* setup globals for the window handles */
- sym = xlenter("*COMMAND-WINDOW*");
- setvalue(sym,cvfixnum((FIXTYPE)cwindow));
- sym = xlenter("*GRAPHICS-WINDOW*");
- setvalue(sym,cvfixnum((FIXTYPE)gwindow));
- }
-