Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!uunet!sugar!peterc From: peterc@Sugar.NeoSoft.com (Peter Creath) Newsgroups: comp.sys.mac.programmer Subject: Re: MPW and Think Summary: inSANEity? Or just unexplicable crashes? Message-ID: <1991Jun30.185942.25260@Sugar.NeoSoft.com> Date: 30 Jun 91 18:59:42 GMT References: <1991Jun25.180736.28590@gn.ecn.purdue.edu> <1991Jun30.042022.19588@Sugar.NeoSoft.com> Organization: Sugar Land Unix -- Houston, TX Lines: 252 Well, I've got more problems. I'm not sure if it's math, or what, but here's the errors I've been getting: for GraphIt(): Bus Error at 0034956E (I hit "G" to continue, and then) Spurious Interrupt or Uninitialized Interrupt Vector at 00349572 (I hit "G" once again, and these errors repeat a few times. Then the program locks up) for GraphIt2(): "Unimplemented Instruction at 0001A208 Unimplemented Instruction at 0001A208 *** MacsBug caused the exception ***" and then it locks up... Now, I don't know what the hell is wrong with this program. I'm sure it's some small detail I'm overlooking. (It's probably a big detail, actually...) Anyway, here's the source code. If you can figure out what's wrong, PLEASE mail me. #define NIL 0L EventRecord gTheEvent; main() { ToolBoxInit(); WindowShow(); ExitToShell(); } ToolBoxInit() { InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent,0); InitWindows(); InitMenus(); TEInit(); InitDialogs(NIL); InitCursor(); } WindowShow() { WindowPtr theWindow; GrafPtr savedPort; int c=0; theWindow=NewWindow(NIL,&(screenBits.bounds),"\p",TRUE, plainDBox,-1L,FALSE,0L); GetPort(&savedPort); SetPort(theWindow); SetOrigin(-100,-100); BackPat(black); PenPat(white); HideCursor(); FillRect(&(theWindow->portRect),black); GraphIt(); /* GraphIt() or GraphIt2() */ SetPort(savedPort); while (!Button()); ShowCursor(); DisposeWindow(theWindow); } GraphIt(void) { short g[44],p[28][18]; short i,j,jc,x,y,z; float zz; for (i=1;i<=43;i++) { g[i]=159-(6*(i-27))*(i>27); } y=-8; for (i=127;i>=31;i-=6) { x=-13; for (j=128-i;j<=(284-i);j+=6) { jc=(j+5)/6; zz=(x*x+y*y); zz=10*sin(zz/20); z=zz; if ((z+i)<0) z=-i; if ((z+i)>g[jc]) { if (j==(128-i)) MoveTo(j,g[jc]); else LineTo(j,g[jc]); } else { g[jc]=z+i; if (j==(128-i)) MoveTo(j,(z+i)); else LineTo(j,(z+i)); } p[(x+14)][(y+9)]=g[jc]; x++; } y++; } for (x=1;x<=27;x++) { MoveTo((6*x-5),p[x][1]); for (y=2;y<=17;y++) { LineTo((6*(x+y)-11),p[x][y]); } } for (x=1;x<=27;x++) { MoveTo((6*x-5),p[x][1]); LineTo((6*x-5),159); } for (y=2;y<=17;y++) { MoveTo((6*y+151),p[27][y]); LineTo((6*y+151),165-y*6); } MoveTo(1,159); LineTo(157,159); LineTo(253,63); } /*================================================*/ GraphIt2() { /* CONSTANTS = A,B,C,D,E,F,G (81,58) should be 1st point FOR-NEXT VARIABLES = H,BB DEPENDENT ON H = AA,BB DEPENDENT ON H AND BB = CC, D1,DD PLOTTING VARIABLES = X,X1,Y,Y1 DEPENDENT ON BB AND H = X,X1 DEPENDENT ON DD AND H = Y,Y1 */ float n1,n2,p; float a=144,c,e=160,f,g=199; float bb,cc,d1,dd; float x,y,fTemp; float b=2.25,h; short x1,y1,aa; Fract frc,frc2; n1=20; /* -40 to 40 - vscale */ n2=90; /* -50 to 150 - vpos */ c=n1;f=n2; for (h=-a;h<=a;h+=b) { p=a*a-h*h; p=sqrt(p); p+=.5; aa=p; /* aa=int(.5+sqr(a^2-h^2)); */ for (bb=-aa;bb<=aa;bb++) { fTemp=sqrt(bb*bb+h*h)*0.0327; /* q=sqrt(bb*bb+h*h)*0.0327 */ d1=cos(b); d1+=cos(2*b); d1+=cos(5*b); /* cos(q)+cos(2*q)+cos(5*q) */ dd=d1*c; x=bb+(h/b)+e; y=dd-(h/b)+f; x=x*0.85;y=0.9*(g-y); x1=x; y1=y; if (y1>=0 && y1<191) { MoveTo(x1,y1); LineTo(x1,y1); PenPat(black); MoveTo(x1,(y1+1)); LineTo(x1,190); PenPat(white); } } } } And here's the AppleSoft BASIC program I took GraphIt2() from: 1000 REM ------------------------------ 1010 : 1020 REM *********************** 1030 REM * * 1040 REM * THREE-DIMENSIONAL PLOT 1050 REM * * 1060 REM *********************** 1070 : 1080 HOME 1090 PRINT : PRINT 1100 PRINT "TO EXPAND OR COMPRESS THE PLOT 1110 PRINT "VERTICALLY, ENTER A NUMBER 1120 INPUT "FROM -40 TO 40 (20 IS TYPICAL).";N1 1130 PRINT : PRINT 1140 PRINT " TO MOVE THE PLOT UP OR DOWN 1150 PRINT " ON THE SCREEN, ENTER A NUMBER 1160 INPUT " FROM -50 TO 150 (90 IS TYPICAL).";N2 1170 : 1180 REM ------------------------------ 1190 : 1200 REM CONSTANTS = A,B,C,D,E,F,G 1210 REM FOR-NEXT VARIABLES = H,BB 1220 REM DEPENDENT ON H = AA,BB 1230 REM DEPENDENT ON H AND BB = CC, D1,DD 1240 REM PLOTTING VARIABLES = X,X1,Y,Y1 1250 REM DEPENDENT ON BB AND H = X,X1 1260 REM DEPENDENT ON DD AND H = Y,Y1 1270 : 1280 A = 144 1290 B = 2.25 1300 C = N1 1310 D = .0327 1320 E = 160 1330 F = N2 1340 G = 199 1350 : 1360 REM ------------------------------ 1370 : 1380 HGR : POKE - 16302,0 1390 HCOLOR= 3 1400 : 1410 FOR H = - A TO A STEP B 1420 AA = INT (.5 + SQR (A ^ 2 - H ^ 2)) 1430 FOR BB = - AA TO AA 1440 CC = SQR (BB ^ 2 + H ^ 2) * D 1450 D1 = FN R(CC) 1460 DD = D1 * C 1470 GOSUB 1520 1480 NEXT BB 1490 NEXT H 1500 : 1510 STOP 1520 : 1530 REM ------------------------------ 1540 : 1550 X = BB + (H / B) + E 1560 Y = DD - (H / B) + F 1570 X1 = INT (.85 * X) 1580 Y1 = INT (.9 * (G - Y)) 1590 IF Y1 < 0 OR Y1 > 190 THEN RETURN 1600 HPLOT X1,Y1 1610 : 1620 REM ERASE BACKGROUND 1630 HCOLOR= 0: REM BLACK 1640 HPLOT X1,(Y1 + 1) TO X1,190 1650 HCOLOR= 3: REM WHITE AGAIN 1660 : 1670 RETURN PLEASE send all responses in E-mail. My news system doesn't allow threading... -- peterc@sugar.neosoft.com "Listen, there's a hell of a good peterc@sugar.hackercorp.com universe next door. Let's go!" (take your pick) -e e cummings p.s. I'm using Think C 4.0.4 including MacHeaders and ANSI-881 p.p.s On the BASIC source, I forgot: "10 DEF FN R(Q) = COS(Q) + COS (2 * Q) + COS (5 * Q)" --