//---------------------------------------------------------------------------------------------------------------- // FILE: init.c // AUTHOR: Shaun Gibson // FILE-GROUP: Fading tutorial //---------------------------------------------------------------------------------------------------------------- #include #include "main.h" //includes all of the defines, global variables and procedure definitions void Init(void) { short count; FntLoad(960, 256); fnt_id = FntOpen(0, 10, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 80); //setup for the fonts SetVideoMode (MODE_PAL); ResetGraph(0); //initialise the graphics GsInitGraph( SCREEN_WIDTH, SCREEN_HEIGHT, GsOFSGPU|GsNONINTER, 0, 0 ); GsDefDispBuff( 0, 0, 0, SCREEN_HEIGHT ); //setup the display buffer GsDISPENV.screen.x=6; //move the screen for TV viewing GsDISPENV.screen.y=20; for( count = 0; count < 2; count++ ) { WorldOT[count].length = OT_LENGTH; WorldOT[count].org = OT_TAGS[count]; //Initialise the ordering table } GsClearOt( 0, 0, &WorldOT[0] ); GsClearOt( 0, 0, &WorldOT[1] ); //clear the ordering table fading = 0; //initialise the value of fading } void InitBoxes(void) //sets up the background objects { short a; for (a = 0; a < NUM_BOXES; a++) { box[a].attribute = (1<<30); box[a].r = (u_char)(rand() % 256); box[a].g = (u_char)(rand() % 256); box[a].b = (u_char)(rand() % 256); box[a].x = (short)(rand() % 280); //give the background objects random box[a].y = (short)(rand() % 216); //positions, sizes and colours box[a].w = (u_short)(rand() % 100); box[a].h = (u_short)(rand() % 100); //rand() must be typecast each time } } void InitSpotLight(void) { short a; GsIMAGE *tim = ReadTIM((u_long *)SPOT_ADDR); //get the image tim from the tim file stored at //address SPOT_ADDR u_short tpage = GetTPage(1, 0, tim->px, tim->py); //get the texture page of the tim InitSprite(&spotsprite, (1<<24) | (1<<29) | (1<<30), 0, 0, 64, 64, tpage, 0, 0, tim->cx, tim->cy, 0xa0, 0xa0, 0xa0, 0, 0, ONE, ONE, 0); //initialise the sprite //(1<<29) is used (+1 back -1 front) so that the higher the sprite's rgb values, the darker the area on the screen //if you look at the bmp or tim for the spotlight, the middle is black, so no dulling occurs, while the outside //is white, so maximum dulling occurs (blacks out area) for (a = 0; a < 4; a++) { spotblock[a].r = spotblock[a].g = spotblock[a].b = 0; //set the blocking boxes for the spotlight //to black } } void InitFadeBox(void) { fadebox.x = 0; fadebox.y = 0; fadebox.w = SCREEN_WIDTH; fadebox.h = SCREEN_HEIGHT; //setup the position and size (full screen) of the box for fading fadebox.r = fadebox.g = fadebox.b = 0; //and initialise it to black } GsIMAGE *ReadTIM( u_long *addr ) { static GsIMAGE tim; RECT rect; // skip id and initialize image structure addr ++; GsGetTimInfo(addr, &tim); DrawSync(0); // 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); return(&tim); } 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; //this procedure just stops me having to write all this for each sprite sprite->rotate = rotate; }