Path: chuka.playstation.co.uk!chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: Spellweaver Newsgroups: scea.yaroze.problems.pc,scea.yaroze.programming.codewarrior Subject: Yet Another CodeWarrior Problem Date: Sat, 20 Sep 1997 01:38:36 -0500 Organization: The Implementor Lines: 239 Message-ID: <34236F6C.16A9@ix.netcom.com> Reply-To: spelwevr@ix.netcom.com NNTP-Posting-Host: norn.tiphares.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mozilla 3.02 (WinNT; I) Xref: chuka.playstation.co.uk scea.yaroze.problems.pc:141 scea.yaroze.programming.codewarrior:197 OK, perhaps this is a foolish mistake on my part. If so, I apologise, and someone, please show me what is wrong. If not, though, it is just another instance of what makes CodeWarrior for Win95 the worst compiler that I have ever used. (Sorry guys, but it just has too many bugs in the code generator, let alone the obvious glaring terrors of the IDE. Perhaps the update will be a wonderful improvement, but for now, even if this particular bug is my fault, many others are not. I truly feel very unsatisfied with this compiler, and do not feel that it is, in its present form, worth at all what I paid for it.) DESCRIPTION OF THIS PROBLEM (Note: This is very similar to a problem that I emailed MetroWerks about a while back, but I never received any reply, so....) System: I am using the second release of the CodeWarrior for Yaroze for Windows 95. The system is a Pentium 100 with 16Mb of RAM. Create a standard Yaroze project, using these two .C files Build the project as-is and run it. Note the bluish object. Now end the program (reset the Yaroze) and go to the file main.c. Look at the beginning of main(), where there are two OBJECT declarations. Comment out the active declaration and un-comment the other declaration. Save, rebuild, and run. Lo and behold, the image is gone! At first I thought that this was perhaps some memory overrun, BUT I have had this happen with totally mundane variables such as ints (i.e., no structures or shadowy library calls were involved). If anyone can explain this, please let me know. I am rather tired, so who knows, it could just be me. Thank you for any assistance! /***** GR3D.H -- 3D graphics library [hacked, maimed version] © Copyright 1997 by J. Black *****/ #include #ifndef __GR3D_H__ #define __GR3D_H__ /***** Custom typs *****/ typedef GsDOBJ2 OBJECT; typedef unsigned long dword; typedef unsigned short word; typedef unsigned char byte; /***** Loop constructs *****/ #define loop for(;;) /***** Prototypes *****/ void Gr3dInit ( dword MaxPackets ); void Gr3dUnInit ( void ); void Gr3dBeginDraw ( void ); void Gr3dEndDraw ( void ); void Gr3dInitTmd ( dword *tmd, OBJECT *obj ); #endif /***** End of header *****/ /***** GR3D.C -- 3D graphics library [broken, hacked, maimed version] © Copyright 1997 by J. Black *****/ #include #include "gr3d.h" /***** Local macros *****/ #define OT_LENGTH 10 #define BIT(n) (1<<(n)) #define WORLDOT (WorldOT+ACT) /***** Local data *****/ static GsOT WorldOT [ 2 ] = { 0 }; static GsOT_TAG OTTags [ 2 ][ 1 << OT_LENGTH ] = { 0 }; static PACKET *GPUPkBuf [ 2 ] = { 0 }; static int ACT = 0; /***** Local code *****/ static void localInitVid ( dword paksize ) { SetVideoMode ( MODE_NTSC ); GsInitGraph ( 640, 480, 5, 1, 0 ); GsDefDispBuff ( 0, 0, 0, 0 ); GsInit3D (); GPUPkBuf [ 0 ] = (PACKET *)malloc ( paksize ); GPUPkBuf [ 1 ] = (PACKET *)malloc ( paksize ); WorldOT [ 0 ].length = OT_LENGTH; WorldOT [ 0 ].org = OTTags [ 0 ]; WorldOT [ 1 ].length = OT_LENGTH; WorldOT [ 1 ].org = OTTags [ 1 ]; GsSetAmbient ( 2048, 2048, 2048 ); // 50% intensity ambient lighting } /***** Public code *****/ // This is a weird kluge due to the CodeWarrior's // excessive problems if obj and mat aren't in the // same functional scope void FooBarBaz ( OBJECT *obj, MATRIX *mat ) { GsGetLs ( obj->coord2, mat ); GsSetLsMatrix ( mat ); GsSortObject4 ( obj, WORLDOT, 14 - OT_LENGTH, (dword *)getScratchAddr ( 0 ) ); } void Gr3dInit ( dword max_packets ) { localInitVid ( max_packets * 24 ); GsSetLightMode ( 0 ); GsSetAmbient ( 2048, 2048, 2048 ); // 50% lit GsSetProjection ( 500 ); } void Gr3dUnInit ( void ) { free ( GPUPkBuf [ 0 ] ); free ( GPUPkBuf [ 1 ] ); } void Gr3dBeginDraw ( void ) { ACT = GsGetActiveBuff (); GsSetWorkBase ( GPUPkBuf [ ACT ] ); GsClearOt ( 0, 0, WORLDOT ); } void Gr3dEndDraw ( void ) { VSync ( 0 ); ResetGraph ( 1 ); GsSwapDispBuff (); GsSortClear ( 0, 0, 0, WORLDOT ); // Background R, G, B (bytes) GsDrawOt ( WORLDOT ); } void Gr3dInitTmd ( dword *tmd, OBJECT *obj ) { GsMapModelingData ( tmd + 1 ); GsLinkObject4 ( (dword)( tmd + 3 ), obj, 0 ); obj->coord2 = NULL; // Coordinates based on world-space } /***** End of file *****/ /***** main.c *****/ #include "gr3d.h" static byte TMD [] = { 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xDC, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x20, 0xFF, 0x00, 0x00, 0x20, 0x00, 0x00, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x20, 0xFF, 0x00, 0x00, 0x20, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x03, 0x00, 0x20, 0x00, 0xFF, 0x00, 0x20, 0x02, 0x00, 0x07, 0x00, 0x06, 0x00, 0x04, 0x00, 0x04, 0x03, 0x00, 0x20, 0x00, 0xFF, 0x00, 0x20, 0x03, 0x00, 0x07, 0x00, 0x04, 0x00, 0x05, 0x00, 0x04, 0x03, 0x00, 0x20, 0x00, 0x00, 0xFF, 0x20, 0x04, 0x00, 0x03, 0x00, 0x07, 0x00, 0x05, 0x00, 0x04, 0x03, 0x00, 0x20, 0x00, 0x00, 0xFF, 0x20, 0x05, 0x00, 0x03, 0x00, 0x05, 0x00, 0x01, 0x00, 0x04, 0x03, 0x00, 0x20, 0xFF, 0xFF, 0x00, 0x20, 0x06, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x03, 0x00, 0x20, 0xFF, 0xFF, 0x00, 0x20, 0x07, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x20, 0x00, 0xFF, 0xFF, 0x20, 0x08, 0x00, 0x07, 0x00, 0x03, 0x00, 0x02, 0x00, 0x04, 0x03, 0x00, 0x20, 0x00, 0xFF, 0xFF, 0x20, 0x09, 0x00, 0x07, 0x00, 0x02, 0x00, 0x06, 0x00, 0x04, 0x03, 0x00, 0x20, 0xFF, 0x00, 0xFF, 0x20, 0x0A, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x03, 0x00, 0x20, 0xFF, 0x00, 0xFF, 0x20, 0x0B, 0x00, 0x04, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x64, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00 }; // This is here because originally this program used the // controller to change the view. static void SetTheView ( long fx, long fy, long fz, long tx, long ty, long tz, long r ) { GsRVIEW2 view; view.vpx = fx; view.vpy = fy; view.vpz = fz; view.vrx = tx; view.vry = ty; view.vrz = tz; view.rz = r; view.super = NULL; GsSetRefView2 ( &view ); } int main ( void ) { OBJECT obj; MATRIX mat; //OBJECT obj; GsF_LIGHT light; long xx [ 2 ] = { 0, 0 }; long yy [ 2 ] = { 0, 0 }; long zz [ 2 ] = { -3000, 0 }; Gr3dInit ( 1024 ); Gr3dInitTmd ( (dword *)TMD, &obj ); light.r = light.g = light.b = 255; light.vx = 0; light.vy = 4096; light.vz = 0; GsSetFlatLight ( 0, &light ); loop { Gr3dBeginDraw (); SetTheView ( xx [ 0 ], yy [ 0 ], zz [ 0 ], xx [ 1 ], yy [ 1 ], zz [ 1 ], 0 ); FooBarBaz ( &obj, &mat ); Gr3dEndDraw (); } Gr3dUnInit (); return 0; } /***** End of file *****/