Comp.Sys.Mac.Game.Programming.Book


Chapter 8: Direct Video vs Offscreen Graphics

This chapter will cover using copybits and how the get the most out of copybits and when and how to correctly write directly to the screen. Apple has said that if you follow some simple guidelines you should be able to write directly to the screen with a minimum of compatiblity issues. The tech note Of Time and Space and _CopyBits talks in great detail about how to speed up copybits. A must read before you try and write your own blitter.

In the mean time here are a few blitting routines to let you see how its done.

Another trick for doing fast animation is to uses video pages. On the Mac only a few video cards that support multiple pages. Juri Munkki posted this to the comp.sys.mac.programmer.misc group on this very topic:

From: jmunkki@beta.hut.fi (Juri Munkki)
Newsgroups: comp.sys.mac.programmer.misc
Subject: Re: Double Buffering?
Date: 24 Mar 1995 11:35:46 GMT
Organization: Helsinki University of Technology
Lines: 77
Distribution: world
Message-ID: <3kuaqi$ltm@nukkekoti.cs.hut.fi>
References: <mrz5149-1903952232250001@p22-ld41w1.isc.rit.edu> <3kkn14$t70@monet.ivi.com>
NNTP-Posting-Host: beta.hut.fi

In article <3kkn14$t70@monet.ivi.com>jons@ivi.com (Jon Steinmetz) writes:
>only other way would be if you could talk to the video driver directly
>and it supported the ability to change the buffer pointer.  I am
>starting to think this is not possible.

Not possible? Here's the code that does it on cards that support multiple
buffers: (I wrote this ages ago, when I still had a Mac II)

#include <video.h>

GDHandle        Device;
CntrlParam      VideoParam;
VDPageInfo      ModeRecord;
short       NumPages=1;  /* At least one page, I assume       */

void    GetMainInfo()
{
        Device=GetMainDevice();
        VideoParam.ioCompletion = 0;
        VideoParam.ioCRefNum = (*Device)->gdRefNum;
}

short   ReadCurrentMode()
{
        short               theErr;
        VDPageInfo               ThisModeRecord;
        
        *(void **)(&VideoParam.csParam) = &ThisModeRecord;

        VideoParam.csCode = cscGetMode;  
        theErr = PBStatus(&VideoParam,0);
        if(theErr) return theErr;

        ModeRecord = ThisModeRecord;
        
        VideoParam.csCode = cscGetPageCnt;
        theErr = PBStatus(&VideoParam,0);
        NumPages = ThisModeRecord.csPage;

        return theErr;
}

short       SetCurrentPage(n)
short       n;
{
        short               theErr;
        VDPageInfo               NewModeRecord;
        
        NewModeRecord = ModeRecord;
        NewModeRecord.csPage = n;
        
        *(void **)(&VideoParam.csParam) = &NewModeRecord;
        VideoParam.csCode = cscSetMode;
        theErr = PBControl(&VideoParam,0);
        
        return theErr;
}

void    main()
{
        short    i;
        long     j;
                 
        GetMainInfo();
        ReadCurrentMode();
        
        
        for(i=0;i <NumPages;i++)
        {        SetCurrentPage(i);
                 Delay(60,&j);
        }
        SetCurrentPage(ModeRecord.csPage);
}

-- 
Juri Munkki jmunkki@hut.fi      There ain't no such thing as a shareware lunch.
http://www.hut.fi/~jmunkki             Windsurfing: Faster than the wind.

And here is some more info for the new macs:
From: english@primenet.com (Lawson English)
Newsgroups: comp.sys.mac.programmer.misc,rec/games.programmer
Subject: Page-flipping on Mac!!! (Was Re: Double Buffering?)
Date: 25 Mar 1995 21:14:23 GMT
Organization: Primenet
Lines: 37
Message-ID: <3l213f$f3b@news.primenet.com>
References: <mrz5149-1903952232250001@p22-ld41w1.isc.rit.edu> <3kuaf8$lco@nukkekoti.cs.hut.fi> <D5z16L.s6@world.std.com>
NNTP-Posting-Host: usr2.primenet.com
X-Newsreader: TIN [version 1.2 PL2]

Ivan M CaveroBelaunde (ivanski@world.std.com) wrote:
[snipt]
: Hm. I was just looking at the March Developer CD, and in the Developer Notes
: folder is something entitled "Display Device Driver Guide," detailing
: some new driver calls dealing with, among other things, multiple video
: pages and baseAddresses. Anyone feel like trying either this or Juri's code
: on a Q630 to see if it actually does have the rumored page-flipping
: support, and whether it's possible to access it this way if it's there?



+++++++++++++++++++++++++++
the VDSwitchInfoRec record and the values passed in its fields are 
described in detail on page 1-11:

->      csMode    depth mode to switch to
->      csData    the number used by your video device to identify the 
                   functional sResource describing the new display mode 
->      csPage    number of the video page to switch to  
<->     csBaseAddr pointer to the base address for the video page 
                   specified in the csPage field
++++++++++++++++++++++++


Golly, this almost exciting...


Now, if only Apple would remember that not all games writers read every 
single piece of documentation coming from Apple, this might go 
somewhere... :-/

--
-------------------------------------------------------------------------------
Lawson English                            __  __     ____  ___       ___ ____
english@primenet.com                     /__)/__) / / / / /_  /\  / /_    /
                                        /   / \  / / / / /__ /  \/ /___  /
-------------------------------------------------------------------------------