home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / mac / programm / 15276 < prev    next >
Encoding:
Internet Message Format  |  1992-09-10  |  3.9 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!rutgers!ub!acsu.buffalo.edu!triantos
  2. From: triantos@acsu.buffalo.edu (Nick B Triantos)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: Game Techniques (was: NON-QUICKDRAW GAMES)
  5. Message-ID: <BuD6qK.7HM@acsu.buffalo.edu>
  6. Date: 10 Sep 92 14:27:51 GMT
  7. References: <1992Sep8.004821.11323@adobe.com> <Bu8oyn.LD6@acsu.buffalo.edu>
  8.     <1992Sep8.191342.15509@adobe.com>
  9. Sender: nntp@acsu.buffalo.edu
  10. Organization: The University at Buffalo
  11. Lines: 90
  12. Originator: triantos@autarch.acsu.buffalo.edu
  13. Nntp-Posting-Host: autarch.acsu.buffalo.edu
  14.  
  15. Hi, peoples.
  16.  
  17. I've been basing some test programs on the code that Joe Holt has provided over
  18. the past few days (btw, thanks, Joe!).  Anyhow, I'm having a problem as
  19. follows:  I want to draw blocks of color on my monitor, each of size 40x30, for
  20. a total of 256, in a 16x16 grid.  Each one will be an increment in color from
  21. the previous.  I find the base screen address using Joe's method, and then the
  22. code at the bottom to try to do what I want.
  23.  
  24. My two problems are:
  25. 1.  After my first time cycling through my i for-loop, x_offset is being set
  26.     to 1, even though x is still 1.
  27. 2.  More importantly, from the THINK debugger,
  28.       offset + base_address (an extern Ptr) + i * 1024
  29.     moves me to the correct scan line, but I get an error compiling with
  30.     longPtr assigned to this equation because of a type conflict.  But if I
  31.     type cast base_address to (long *) (as done in the code, see PROBLEM LINE
  32.     below), it changes the value of longPtr from being incremented 0x0400 to
  33.     being incremented by 0x1000.  Needless to say, my program therefore
  34.     doesn't work.  I though I was only moderately rusty with my C.  What am
  35.     I doing wrong?
  36.  
  37. Many thanks,
  38. -Nick
  39.  
  40. code follows ...
  41.  
  42. void DirectDrawTest()
  43. {
  44.     register int            x,y ;
  45.     register long int       x_offset = 0,
  46.                             y_offset = 0 ;
  47.     register long int       i ;
  48.     register long int       color = 0 ;
  49.     register long int       *longPtr ;
  50.     register long int       offset ;
  51.     char                    old_MMUMode ;
  52.     
  53.     /* Switch to 32-bit addressing, for 32-bit video cards */
  54.     if ( (myErr == noErr) && (This_mac.hasColorQD) )
  55.     {
  56.         old_MMUMode = true32b ;
  57.         SwapMMUMode( &old_MMUMode ) ;
  58.     }
  59.  
  60.     /* No need to have the cursor erase my masterpiece... */
  61.     HideCursor() ;
  62.  
  63.     /* Place 16 40x30 squares in each of 16 rows, inc.'ing colors as we go */
  64.     for ( y = 0 ; y < 16 ; y++ ) /* 16 vert. boxes */
  65.     {
  66.         for ( x = 0 ; x < 16 ; x++ ) /* 16 horiz. boxes */
  67.         {
  68.             x_offset = 40 * x ; /* 40 horiz. pixels / color box */
  69.             offset = x_offset + y_offset ;
  70.             for ( i = 0 ; i < 30 ; i++ ) /* 30 lines of 40 pix. ea per box */
  71.             {
  72. PROBLEM LINE:   longPtr = offset + (long *)base_address + i * 1024 ;
  73.                                                    /* 1024=bytes/scan line */
  74.                 *longPtr++ = color ;
  75.                 *longPtr++ = color ;
  76.                 *longPtr++ = color ;
  77.                 *longPtr++ = color ;
  78.                 *longPtr++ = color ;
  79.                 *longPtr++ = color ;
  80.                 *longPtr++ = color ;
  81.                 *longPtr++ = color ;
  82.                 *longPtr++ = color ;
  83.                 *longPtr++ = color ;
  84.             }
  85.             color += 0x01010101 ;
  86.         }
  87.         y_offset += 30 * 1024 ; /* move down 30 pix. after each row of boxes */
  88.     }
  89.  
  90.     /* Go back to old video mode */
  91.     if ( This_mac.hasColorQD )
  92.         SwapMMUMode( &old_MMUMode ) ;
  93.         
  94.     while (!Button()) ;    /* pause until the mouse button is hit. */
  95.     
  96.     ShowCursor() ;
  97.     
  98.     if (Button()) while ( Button() ) ;    /* Wait for button release */
  99. }
  100. --
  101. Nick Triantos    internet: triantos@acsu.buffalo.edu
  102.                  AOL:      Triantos
  103. "Scientists tell us that the fastest animal on earth, with a top speed of
  104. 120 ft/sec, is a cow that has been dropped out of a helicopter." - Dave Barry
  105.