/* --------------------------------------------------------------------- ** Project: Background fading. ** File: main.c ** Purpose: The background is composed of 2x160x256 pixels tims. ** Is will be comosed as one 320x256 pixel background ** Exit with START button ** Date: 04.02.1999 ** Author: Robert Jurziga */ #include extern char moss8l[]; extern char moss8r[]; // --------------------------------------------------------------------- // D E F I N E S // --------------------------------------------------------------------- #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 256 #define DEF_SCREEN_X 4 #define DEF_SCREEN_Y 18 // normaly this would be the contens of a pad.h file. #define PADLup (1<<12) #define PADLdown (1<<14) #define PADLleft (1<<15) #define PADLright (1<<13) #define PADRup (1<< 4) #define PADRdown (1<< 6) #define PADRleft (1<< 7) #define PADRright (1<< 5) #define PADi (1<< 9) #define PADj (1<<10) #define PADk (1<< 8) #define PADl (1<< 3) #define PADm (1<< 1) #define PADn (1<< 2) #define PADo (1<< 0) #define PADh (1<<11) #define PADL1 PADn #define PADL2 PADo #define PADR1 PADl #define PADR2 PADm #define PADstart PADh #define PADselect PADk // --------------------------------------------------------------------- // F U N C T I O N S // --------------------------------------------------------------------- void InitView(); void RestoreView(); void UpdateScreen(); int CheckControllers(int pport); void InitBGSprite(); void DrawBackground(); void InitSprite( GsSPRITE *sprite, u_long attribute, short x, short y, u_short w, u_short h, u_short tpage, u_char u, u_char v, short cx, short cy, u_char r, u_char g, u_char b, short mx, short my, short scalex, short scaley, long rotate ); GsIMAGE *ReadTIM( u_long *addr ); // --------------------------------------------------------------------- // G L O B A L S // --------------------------------------------------------------------- #define OT_LENGTH 1 #define PACKETMAX 1000 GsOT wot[2]; GsOT_TAG otab[2][1<px,left->py); InitSprite( &leftscr,(1<<24),0,0,160,256,tpage,0,0,left->cx,left->cy, 0x80,0x80,0x80,0,0,ONE,ONE,0 ); // right side right = ReadTIM((u_long*)moss8r); tpage = GetTPage(1,0,right->px,right->py); InitSprite( &rightscr,(1<<24),160,0,160,256,tpage,0,0,right->cx,right->cy, 0x80,0x80,0x80,0,0,ONE,ONE,0 ); }// end InitBackground //-------------------------------------------------------------------------- // Function: InitSprite() // Description: Setup sprite structure // Parameters: Lots! Look at the Library Reference Manual // Returns: none // Notes: N/A //-------------------------------------------------------------------------- void InitSprite( GsSPRITE *sprite, u_long attribute, short x, short y, u_short w, u_short h, u_short tpage, u_char u, u_char v, short cx, short cy, u_char r, u_char g, u_char b, short mx, short my, short scalex, short scaley, long rotate ) { sprite->attribute = attribute; sprite->x = x; sprite->y = y; sprite->w = w; sprite->h = h; sprite->tpage = tpage; sprite->u = u; sprite->v = v; sprite->cx = cx; sprite->cy = cy;; sprite->r = r; sprite->g = g; sprite->b = b; sprite->mx = mx; sprite->my = my; sprite->scalex = scalex; sprite->scaley = scaley; sprite->rotate = rotate; }// end InitSprite //-------------------------------------------------------------------------- // Function: ReadTIM() // Description: Read a TIM and CLUT(if 4 bit or 8 bit) and transfer to VRAM // Parameters: u_long *addr: address of TIM // Returns: GsIMAGE: address of tim variable // Notes: N/A //-------------------------------------------------------------------------- GsIMAGE *ReadTIM( u_long *addr ) { static GsIMAGE tim; RECT rect; // skip id and initialize image structure addr ++; GsGetTimInfo(addr, &tim); // transfer pixel data to VRAM rect.x = tim.px; rect.y = tim.py; rect.w = tim.pw; rect.h = tim.ph; LoadImage(&rect, tim.pixel); DrawSync(0); // check if CLUT exists and transfer it to VRAM if( (tim.pmode >> 3) & 0x01 ) { rect.x = tim.cx; rect.y = tim.cy; rect.w = tim.cw; rect.h = tim.ch; LoadImage(&rect, tim.clut); } DrawSync(0); printf(" IMAGE - x:(%d), y:(%d), w:(%d), h:(%d) \n", tim.px, tim.py,tim.pw,tim.ph ); printf(" CLUT - x:(%d), y:(%d), w:(%d), h:(%d) \n", tim.cx, tim.cy,tim.cw,tim.ch ); printf(" image mode:%d \n", tim.pmode); printf(" tim addr: %p \n",&tim); return(&tim); }// end ReadTIM /* --------------------------------------------------------------------- // Function: CheckControllers // Purpose: This function checks out the port status. // If START is pressed the function returns a <>0 value. // Else it is 0. The direction buttons in or decreased // the variables ScrXOff and ScrYOff and sets it via // "GsDISPENV" */ int CheckControllers(int padport) { PadBits=(~(*(pport0+3) | *(pport0+2) << 8 | *(pport1+3) << 16 | *(pport1+2) << 24)); if (PadBits & PADstart) // return 1 here to signal exit!!! return(1); if (PadBits & PADLup) { FadeFlag++; if (FadeFlag==0) FadeFlag=0xff; goto setspr; } if (PadBits & PADLdown) { FadeFlag--; if (FadeFlag==0xff) FadeFlag=0x00; goto setspr; } setspr: leftscr.r=FadeFlag; leftscr.g=FadeFlag; leftscr.b=FadeFlag; rightscr.r=FadeFlag; rightscr.g=FadeFlag; rightscr.b=FadeFlag; } /* --------------------------------------------------------------------- // Function: UpdateScreen // Purpose: This function does the Double buffering and read the // pad data. */ void UpdateScreen() { ActiveBuff=GsGetActiveBuff(); GsSetWorkBase((PACKET*)gpu_WorkArea[ActiveBuff]); GsClearOt(0, 0, &wot[ActiveBuff]); DrawBackground(); DrawSync(0); VSync(0); GsSwapDispBuff(); GsSortClear(0x0,0x0,0x80,&wot[ActiveBuff]); GsDrawOt(&wot[ActiveBuff]); } /* --------------------------------------------------------------------- // Function: InitView // Purpose: Set up screen to display and save the previouse // screen datas. */ void InitView() { int count=0; OldView = GetVideoMode(); // Set up graphics SetVideoMode(MODE_PAL); ResetGraph(0); GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, GsOFSGPU, 0, 0); GsDefDispBuff(0, 0, 0, SCREEN_HEIGHT); // Set display output GsDISPENV.screen.x=ScrXOff; GsDISPENV.screen.y=ScrYOff; GsDISPENV.screen.w=ScrWidth; GsDISPENV.screen.h=ScrHeight; // Set bg clear color and flag GsDRAWENV.r0 = 0x00; GsDRAWENV.g0 = 0x00; GsDRAWENV.b0 = 0x80; GsDRAWENV.isbg = 0; // set up ordering table for( count=0; count < 2; count++ ) { wot[count].length = 1; wot[count].org = otab[count]; } // init ordering table GsClearOt(0, 0, &wot[0]); GsClearOt(0, 0, &wot[1]); } /* --------------------------------------------------------------------- // Function: RestoreView // Purpose: Restore the view. */ void RestoreView() { SetVideoMode(OldView); ResetGraph(3); }