From: triantos@acsu.buffalo.edu (Nick B Triantos)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Game Techniques (was: NON-QUICKDRAW GAMES)
Date: 10 Sep 92 14:27:51 GMT
	<1992Sep8.191342.15509@adobe.com>
Organization: The University at Buffalo
Originator: triantos@autarch.acsu.buffalo.edu

Hi, peoples.

I've been basing some test programs on the code that Joe Holt has provided over
the past few days (btw, thanks, Joe!).  Anyhow, I'm having a problem as
follows:  I want to draw blocks of color on my monitor, each of size 40x30, for
a total of 256, in a 16x16 grid.  Each one will be an increment in color from
the previous.  I find the base screen address using Joe's method, and then the
code at the bottom to try to do what I want.

My two problems are:
1.  After my first time cycling through my i for-loop, x_offset is being set
    to 1, even though x is still 1.
2.  More importantly, from the THINK debugger,
      offset + base_address (an extern Ptr) + i * 1024
    moves me to the correct scan line, but I get an error compiling with
    longPtr assigned to this equation because of a type conflict.  But if I
    type cast base_address to (long *) (as done in the code, see PROBLEM LINE
    below), it changes the value of longPtr from being incremented 0x0400 to
    being incremented by 0x1000.  Needless to say, my program therefore
    doesn't work.  I though I was only moderately rusty with my C.  What am
    I doing wrong?

Many thanks,
-Nick

code follows ...

void DirectDrawTest()
{
    register int            x,y ;
    register long int       x_offset = 0,
                            y_offset = 0 ;
    register long int       i ;
    register long int       color = 0 ;
    register long int       *longPtr ;
    register long int       offset ;
    char                    old_MMUMode ;
    
    /* Switch to 32-bit addressing, for 32-bit video cards */
    if ( (myErr == noErr) && (This_mac.hasColorQD) )
    {
        old_MMUMode = true32b ;
        SwapMMUMode( &old_MMUMode ) ;
    }

    /* No need to have the cursor erase my masterpiece... */
    HideCursor() ;

    /* Place 16 40x30 squares in each of 16 rows, inc.'ing colors as we go */
    for ( y = 0 ; y < 16 ; y++ ) /* 16 vert. boxes */
    {
        for ( x = 0 ; x < 16 ; x++ ) /* 16 horiz. boxes */
        {
            x_offset = 40 * x ; /* 40 horiz. pixels / color box */
            offset = x_offset + y_offset ;
            for ( i = 0 ; i < 30 ; i++ ) /* 30 lines of 40 pix. ea per box */
            {
PROBLEM LINE:   longPtr = offset + (long *)base_address + i * 1024 ;
                                                   /* 1024=bytes/scan line */
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
                *longPtr++ = color ;
            }
            color += 0x01010101 ;
        }
        y_offset += 30 * 1024 ; /* move down 30 pix. after each row of boxes */
    }

    /* Go back to old video mode */
    if ( This_mac.hasColorQD )
        SwapMMUMode( &old_MMUMode ) ;
        
    while (!Button()) ;    /* pause until the mouse button is hit. */
    
    ShowCursor() ;
    
    if (Button()) while ( Button() ) ;    /* Wait for button release */
}
--
Nick Triantos    internet: triantos@acsu.buffalo.edu
                 AOL:      Triantos
"Scientists tell us that the fastest animal on earth, with a top speed of
120 ft/sec, is a cow that has been dropped out of a helicopter." - Dave Barry