Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!think!ames!ucbcad!ucbvax!decvax!decwrl!labrea!rocky!rokicki From: rokicki@rocky.STANFORD.EDU (Tomas Rokicki) Newsgroups: comp.sys.amiga Subject: BlitLab 1.2 (part 4/4) Message-ID: <377@rocky.STANFORD.EDU> Date: Mon, 22-Jun-87 20:28:22 EDT Article-I.D.: rocky.377 Posted: Mon Jun 22 20:28:22 1987 Date-Received: Wed, 24-Jun-87 06:42:01 EDT Organization: Stanford University Computer Science Department Lines: 586 ---start--- gvals[id] = parse(s) ; RemoveGadget(mywindow, gadgets[id]) ; strcpy(((struct StringInfo *)(gadgets[id]->SpecialInfo))->Buffer, s) ; AddGadget(mywindow, gadgets[id], -1) ; RefreshGadgets(gadgets[id], mywindow, NULL) ; } /* * This routine flips the state of a toggle gadget. */ flipgadg(id) int id ; { struct IntuiText *temp ; struct Gadget *gp = gadgets[id] ; RemoveGadget(mywindow, gp) ; temp = gp->GadgetText ; gp->GadgetText = (struct IntuiText *)gp->UserData ; gp->UserData = (APTR)temp ; gp->NextGadget = NULL ; AddGadget(mywindow, gp, -1) ; RefreshGadgets(gp, mywindow, NULL) ; gvals[id] = 1 - gvals[id] ; } /* * This routine sets up a line. */ setupline() { int x, y ; int i ; int X, Y ; int q = 0 ; parseall() ; stuff(GDGADAT, "$8000") ; stuff(GDGBDAT, "$ffff") ; x = gvals[GDGSX] ; y = gvals[GDGSY] ; sprintf(errorbuf, "%d", x & 15) ; stuff(GDGASH, errorbuf) ; i = ((x >> 3) & ~1) + y * 12 ; sprintf(errorbuf, "M+%d", i) ; stuff(GDGCPT, errorbuf) ; stuff(GDGDPT, errorbuf) ; stuff(GDGCMOD, "12") ; stuff(GDGDMOD, "12") ; stuff(GDGH, "2") ; x = (gvals[GDGEX] - gvals[GDGSX]) ; y = (gvals[GDGEY] - gvals[GDGSY]) ; if (x < 0) X = - x ; else X = x ; if (y < 0) Y = - y ; else Y = y ; if (x > 0) { if (y > 0) { q = (X > Y ? 1 : 0) ; } else { q = (X > Y ? 3 : 4) ; } } else { if (y > 0) { q = (X > Y ? 5 : 2) ; } else { q = (X > Y ? 7 : 6) ; } } if (Y > X) { i = X ; X = Y ; Y = i ; } sprintf(errorbuf, "%d", X+1) ; stuff(GDGV, errorbuf) ; sprintf(errorbuf, "%d", 4 * Y - 2 * X) ; stuff(GDGAPT, errorbuf) ; if (2 * Y - X < 0) { if (!gvals[GDGSIGN]) flipgadg(GDGSIGN) ; } else { if (gvals[GDGSIGN]) flipgadg(GDGSIGN) ; } sprintf(errorbuf, "%d", 4 * (Y - X)) ; stuff(GDGAMOD, errorbuf) ; sprintf(errorbuf, "%d", 4 * Y) ; stuff(GDGBMOD, errorbuf) ; stuff(GDGAFWM, "%1111111111111111") ; stuff(GDGALWM, "%1111111111111111") ; if (! gvals[GDGLINE]) flipgadg(GDGLINE) ; if ((q & 1) != gvals[GDGEFE]) flipgadg(GDGEFE) ; if (((q >> 1) & 1) != gvals[GDGIFE]) flipgadg(GDGIFE) ; if (((q >> 2) & 1) != gvals[GDGFCI]) flipgadg(GDGFCI) ; if (! gvals[GDGUSEA]) flipgadg(GDGUSEA) ; if (gvals[GDGUSEB]) flipgadg(GDGUSEB) ; if (! gvals[GDGUSEC]) flipgadg(GDGUSEC) ; if (! gvals[GDGUSED]) flipgadg(GDGUSED) ; if (gvals[GDGOVF]) flipgadg(GDGOVF) ; } 20488!Funky!Stuff! echo x - mem.c cat > mem.c << '20488!Funky!Stuff!' /* * Memory allocation and deallocation for BlitLab. */ #include "structures.h" struct memnode { struct memnode * next ; long size ; } ; static struct memnode *head ; /* * Replacement for AllocMem. If not enough memory, we exit. */ void *allocmem(size, type) long size ; long type ; { struct memnode *p ; extern void *AllocMem() ; p = (struct memnode *)AllocMem(size + sizeof(struct memnode), type) ; if (p==NULL) error("! out of memory") ; p->size = size + sizeof(struct memnode) ; p->next = head ; head = p ; return(p + 1) ; } /* * Frees all allocated memory. */ freemem() { struct memnode *p ; while (head != NULL) { p = head->next ; FreeMem(head, head->size) ; head = p ; } } 20488!Funky!Stuff! echo x - parse.c cat > parse.c << '20488!Funky!Stuff!' /* * Parse.c of BlitLab software package. This routine handles * parsing the strings into integers, in any of the possible * formats. */ #include "structures.h" /* * Externals we use. */ extern short *realbits ; extern char *bufarr[] ; extern long gvals[] ; extern struct blitregs blitregs ; extern char errorbuf[] ; /* * This is the main parse routine. First, a static to indicate if * we saw a parse error or not. */ static int parseerr ; /* * We allow the following formats: * * (M+)?-?[$%]?[0-9a-f]+ * (~?[ABC])(+(~?[ABC]))* */ long parse(s) register char *s ; { int negative = 1 ; int c ; int radix = 10 ; long toadd = 0 ; long val ; static varr[] = { 0xf0, 0xcc, 0xaa } ; parseerr = 0 ; while (*s == ' ') s++ ; if (*s=='~' || *s=='A' || *s=='B' || *s=='C' || *s=='a' || *s=='b' || *s=='c') { val = 0 ; while (1) { toadd = 255 ; while (1) { if (*s == '~') { negative = 255 ; s++ ; } else negative = 0 ; c = *s++ ; if (c == 0 || c == '+') { if (toadd == 255) parseerr = 1 ; break ; } if (c >= 'a' && c <= 'z') c -= 'a' - 'A' ; if (c < 'A' || c > 'C') { parseerr = 1 ; break ; } toadd &= negative ^ varr[c-'A'] ; } val |= toadd ; if (c != '+') { if (c != 0) parseerr = 1 ; break ; } } return(val) ; } else { if (*s == 'm' || *s == 'M') { if (s[1]=='+') { s += 2 ; toadd = (long)realbits ; } else if (s[1]==0) return((long)realbits) ; else { parseerr = 1 ; return(0) ; } } if (*s == '-') { negative = -1 ; s++ ; } if (*s == '$') { radix = 16 ; s++ ; } else if (*s == '%') { radix = 2 ; s++ ; } val = 0 ; if (*s == 0) { parseerr = 1 ; return(val) ; } while (1) { c = *s ++ ; if (c == 0) break ; if (c >= 'a' && c <= 'z') c -= 'a' - 'A' ; if (c >= 'A' && c <= 'F') c -= 'A' - 10 ; else c -= '0' ; if (c < 0 || c >= radix) { parseerr = 1 ; break ; } val = val * radix + c ; } return(toadd + negative * val) ; } } /* * This routine parses all of the string gadgets. If it is successful, * it returns 1, otherwise it returns 0. */ int parseall() { int i ; for (i=0; i>= 4 ; tmp[2] = hex[val & 15] ; val >>= 4 ; tmp[1] = hex[val & 15] ; val >>= 4 ; tmp[0] = hex[val & 15] ; drawtext(x, y, tmp) ; } /* * This routine calculates and writes out *all* of the blitter * register values. */ updateregs() { int i ; blitregs.con0 = ((gvals[GDGASH] & 15) << 12) + (gvals[GDGUSEA] << 11) + (gvals[GDGUSEB] << 10) + (gvals[GDGUSEC] << 9) + (gvals[GDGUSED] << 8) + (gvals[GDGFUNC] & 255) ; blitregs.con1 = ((gvals[GDGBSH] & 15) << 12) + (gvals[GDGSIGN] << 6) + (gvals[GDGOVF] << 5) + (gvals[GDGEFE] << 4) + (gvals[GDGIFE] << 3) + (gvals[GDGFCI] << 2) + (gvals[GDGDESC] << 1) + gvals[GDGLINE] ; blitregs.size = ((gvals[GDGV] & 1023) << 6) + (gvals[GDGH] & 63) ; blitregs.afwm = (gvals[GDGAFWM] & 65535) ; blitregs.alwm = (gvals[GDGALWM] & 65535) ; for (i=0; i<4; i++) { blitregs.pth[i] = ((gvals[GDGAPT+i] >> 16) & 65535) ; blitregs.ptl[i] = (gvals[GDGAPT+i] & 65535) ; blitregs.mod[i] = (gvals[GDGAMOD+i] & 65535) ; } for (i=0; i<3; i++) blitregs.dat[i] = (gvals[GDGADAT+i] & 65535) ; /* * Now we write out the values. */ writefour(HRVC2, VRVL1, blitregs.con0) ; writefour(HRVC2, VRVL2, blitregs.con1) ; writefour(HRVC2, VRVL3, blitregs.size) ; writefour(HRVC2, VRVL4, blitregs.afwm) ; writefour(HRVC2, VRVL5, blitregs.alwm) ; for (i=0; i<4; i++) { writefour(HRVC4, VRVL2 + 9 * i, blitregs.pth[i]) ; writefour(HRVC5, VRVL2 + 9 * i, blitregs.ptl[i]) ; writefour(HRVC6, VRVL2 + 9 * i, blitregs.mod[i]) ; } for (i=0; i<3; i++) writefour(HRVC6B, VRVL2 + 9 * i, blitregs.dat[i]) ; } 20488!Funky!Stuff! echo x - render.c cat > render.c << '20488!Funky!Stuff!' /* * This file handles the graphics primitives for BlitLab. */ #include "structures.h" /* * External variables we use. */ extern struct RastPort *myrp ; /* * color sets the current foreground color to the appropriate value. */ color(c) int c ; { SetAPen(myrp, (long)c) ; SetDrMd(myrp, (long)JAM1) ; } /* * This routine draws a horizontal or vertical line. */ line(x1, y1, x2, y2) int x1, y1, x2, y2 ; { int t ; if (x1 > x2) { t = x1 ; x1 = x2 ; x2 = t ; } if (y1 > y2) { t = y1 ; y1 = y2 ; y2 = t ; } if (x1 != x2 && y1 != y2) error("! can only draw h/v lines currently") ; RectFill(myrp, (long)x1, (long)y1, (long)x2, (long)y2) ; } /* * This routine draws a box. */ box(x1, y1, xsize, ysize) int x1, y1, xsize, ysize ; { xsize = x1 + xsize - 1 ; ysize = y1 + ysize - 1 ; line(x1, y1, xsize, y1) ; line(xsize, y1, xsize, ysize) ; line(xsize, ysize, x1, ysize) ; line(x1, ysize, x1, y1) ; } /* * This routine draws a filled box. */ fbox(x1, y1, xsize, ysize) int x1, y1, xsize, ysize ; { RectFill(myrp, (long)x1, (long)y1, (long)(x1 + xsize - 1), (long)(y1 + ysize - 1)) ; } /* * This routine draws a text string at a particular location. It is * somewhat crude; we build an IntuiText structure, and tell it to * draw it. */ static struct IntuiText dmy = { WHITE, BLUE, JAM2, 0, 0, NULL, NULL, NULL } ; drawtext(x, y, s) int x, y ; char *s ; { dmy.IText = (UBYTE *)s ; PrintIText(myrp, &dmy, (long)(x), (long)(y)) ; } 20488!Funky!Stuff! echo x - structures.h cat > structures.h << '20488!Funky!Stuff!' /* * The structures and include files used in BlitLab. */ #define BANNER "BlitLab 1.2, Copyright (C) 1987, Radical Eye Software" #include "exec/exec.h" #include "intuition/intuition.h" #include "functions.h" #include "graphics/display.h" #include "graphics/gfx.h" #include "graphics/gfxmacros.h" #include "graphics/gfxbase.h" #include "stdio.h" /* * This is the blitter register structure we use. */ struct blitregs { short con0, con1, size, afwm, alwm ; short pth[4] ; short ptl[4] ; short mod[4] ; short dat[4] ; } ; /* * Here we number the gadgets. */ #define GDGPNTREG (0) #define GDGCLRSET (1) #define GDGGO (2) #define GDGSX (3) #define GDGSY (4) #define GDGEX (5) #define GDGEY (6) #define GDGLINE (7) #define GDGH (8) #define GDGV (9) #define GDGDESC (10) #define GDGFCI (11) #define GDGIFE (12) #define GDGEFE (13) #define GDGSETUP (14) #define GDGFUNC (15) #define GDGUSEA (16) #define GDGUSEB (17) #define GDGUSEC (18) #define GDGUSED (19) #define GDGAPT (20) #define GDGBPT (21) #define GDGCPT (22) #define GDGDPT (23) #define GDGAMOD (24) #define GDGBMOD (25) #define GDGCMOD (26) #define GDGDMOD (27) #define GDGADAT (28) #define GDGBDAT (29) #define GDGCDAT (30) #define GDGASH (31) #define GDGBSH (32) #define GDGAFWM (33) #define GDGALWM (34) #define GDGCALC (35) #define GDGSIGN (36) #define GDGOVF (37) #define MAXGADG (38) /* * These defines set the size of the screen and various subareas of * the screen, including most gadget locations. */ #define HWINSTART (0) #define VWINSTART (5) #define HWINSIZE (640) #define VWINSIZE (195) #define HBITSTART (4) #define VBITSTART (11) #define HBITSIZE (96 * 6) #define VBITSIZE (32 * 3 + 1) #define HLMGSTART (HBITSIZE + HBITSTART + 2) #define HLMGSIZE (HWINSIZE - HLMGSTART - 4) #define VLMGSIZE (12) #define VLMGINT (4) #define VLMG1 (VBITSTART + VLMGINT) #define VLMG2 (VLMG1 + VLMGSIZE + VLMGINT) #define VLMG3 (VLMG2 + VLMGSIZE + VLMGINT) #define VLMG4 (VLMG3 + VLMGSIZE + VLMGINT) #define VLMG5 (VLMG4 + VLMGSIZE + VLMGINT) #define VGOSTART (VLMG5 + VLMGSIZE + VLMGINT) #define HGOSTART (HLMGSTART + 2) #define HGOSIZE (HLMGSIZE - 4) #define VGOSIZE (VRVSTART - VGOSTART - VLMGINT) #define VSTRSIZE (11) #define HSTRSIZE(a) (8 * (a) + 4) #define HMGSIZE (63) #define VMGSIZE (11) #define HMGINT (1) #define VMGINT (0) #define HMG1START (HBITSTART) #define HMG2START (HMG1START + HMGSIZE + HMGINT) #define HMG3START (HMG2START + HMGSIZE + HMGINT) #define HMG4START (HMG3START + HMGSIZE + HMGINT) #define HMG5START (HMG4START + HMGSIZE + HMGINT) #define HMG6START (HMG5START + HMGSIZE + HMGINT) #define HMG7START (HMG6START + HMGSIZE + HMGINT) #define HMG8START (HMG7START + HMGSIZE + HMGINT) #define HMG9START (HMG8START + HMGSIZE + HMGINT) #define VMG1START (VBITSTART + VBITSIZE) #define VMG2START (VMG1START + VMGSIZE + VMGINT) #define VRVSTART (VMG2START + VMGSIZE) #define VRVL1 (VRVSTART + 2) #define VRVL2 (VRVL1 + 9) #define VRVL3 (VRVL2 + 9) #define VRVL4 (VRVL3 + 9) #define VRVL5 (VRVL4 + 9) #define VRVL6 (VRVL5 + 9) #define VRVLL2 (VRVL1 + 10) #define VRVLL3 (VRVLL2 + 11) #define VRVLL4 (VRVLL3 + 11) #define VRVLL5 (VRVLL4 + 11) #define VRVLL6 (VRVLL5 + 11) #define VRG1 (VRVL1 + 8) #define VRVSIZE (VWINSIZE - VRVSTART) #define HRVSIZE (HWINSIZE - HBITSTART - 3) #define HRVSTART (HBITSTART) #define HRVC1 (HRVSTART + 6) #define HRVC2 (HRVC1 + 5 * 8) #define HRVC3 (HRVC2 + 5 * 8) #define HRVC4 (HRVC3 + 2 * 8) #define HRVC5 (HRVC4 + 5 * 8) #define HRVC6 (HRVC5 + 5 * 8) #define HRVC6B (HRVC6 + 5 * 8) #define HMVSTART (HRVC6B + 35) #define HRVC7 (HRVC6B + 5 * 8) #define HRVC8 (HRVC7 + 2 * 8) #define HRVC9 (HRVC8 + 3 * 8 + 4) #define HRVC10 (HRVC9 + 9 * 8) #define HRVC11 (HRVC10 + 7 * 8) #define HRVC12 (HRVC11 + 19 * 8) #define VTEXTOFF (2) #define HTEXTOFF (2) /* * Colors. */ #define BLUE (0) #define WHITE (1) #define BLACK (2) #define ORANGE (3) 20488!Funky!Stuff! ---end---