/************************************************ * * * SCROLLING BACKGROUND DEMONSTRATION * * ==================================== * * * * Written by Steven Lewis * * * * Downloaded From: * * http://www.netyaroze-europe.com/~slewis/ * * * * e-mail: * * stevenlewis@birminghamhome.freeserve.co.uk * * * * This program loads in two 160*256 TIM files * * and turns them into a scrolling background * * which loops until select is pressed * ************************************************/ // --------------- // HEADER FILES // --------------- #include #include // -------------- // DEFINITIONS // -------------- #define SCREEN_WIDTH (320) // Sets the width of the screen #define SCREEN_HEIGHT (256) // Sets the height of the screen #define TIM_ADDRESS1 (0x80094000) // States where the first TIM is located in memory #define TIM_ADDRESS2 (0x800a4000) // States where the second TIM file is located #define NO_OF_BACKGROUND_IMAGES (2) // Sets the number of images on screen at one time // --------------------------- // ORDERING TABLE VARIABLES // --------------------------- #define OT_LENGTH (1) // Sets the length of the Ordering Table GsOT WorldOT[2]; // Sets two OT headers GsOT_TAG OTTags[2][1<>3) & 0x01) { rect.x = tim_info.cx; // x position of CLUT rect.y = tim_info.cy; // y position of CLUT rect.w = tim_info.cw; // width of the CLUT rect.h = tim_info.ch; // height of the CLUT LoadImage(&rect,tim_info.clut); // Loads all of the above into the frame buffer } // switch statement which sets image data depending on the type of image switch(tim_info.pmode) { // If the image is 4-bit case 0x08: sprite->attribute = 0x00000000; // Sets the image attribute sprite->w = tim_info.pw*4; // Sets the width of the image sprite->tpage = GetTPage(0,0,tim_info.px,tim_info.py); // Texture page info break; // breaks from the loop // If the image is 8-bit case 0x09: sprite->attribute = 0x01000000; // Sets the image attribute sprite->w = tim_info.pw*2; // Sets the width of the image sprite->tpage = GetTPage(1,0,tim_info.px,tim_info.py); // Texture page info break; // breaks from the loop // If the image is 16-bit default: sprite->attribute = 0x02000000; // Sets the image attribute sprite->w = tim_info.pw; // Sets the width of the image sprite->tpage = GetTPage(2,0,tim_info.px,tim_info.py); // Texture page info break; // breaks from the loop } if(checkNo==1) // Sets the correct x position on screen for each image sprite->x = 0; // Image 1 x screen position else sprite->x = 160; // Image 2 x screen position sprite->y = 0; // y screen position sprite->h = tim_info.ph; // height of the image sprite->u = 0; // Texture page offset - x axis sprite->v = 0; // Texture page offset - y axis sprite->cx = tim_info.cx; // Clut x axis position sprite->cy = tim_info.cy; // Clut y axis position sprite->r = 128; // Provides red screen tint - 128=normal sprite->g = 128; // Provides green screen tint - 128=normal sprite->b = 128; // Provides blue screen tint - 128=mormal sprite->mx = 0; // Sets the center position of each image - x axis sprite->my = 0; // Sets the center position of each image - y axis sprite->scalex = ONE; // Sets the scale ratio to 1:1 - x axis sprite->scaley = ONE; // Sets the scale ratio to 1:1 - y axis sprite->rotate = 0; // Sets image rotation to off DrawSync(0); // Waits for all of the above to finish before continuing printf("BACKGROUND %d LOADED\n",i); /* Prints text to the PC screen saying which image has been loaded */ i++; /* Increments the i variable so the above text displays the appropriate number on the next pass through */ } // ----------------------- // PAD READING FUNCTION // ----------------------- static u_long ReadPads(long) // Reads what is being entered on the pads { return(~(*(pad1Buffer+3)|*(pad1Buffer+2)<<8|*(pad2Buffer+3)<<16|*(pad2Buffer+2)<<24)); } // ----------------------------- // FUNCTION TO SET UP THE PADS // ----------------------------- static long InitPads() // Sets up the pads ready to use { padCheck = ReadPads(1); // calls the above function of a button is pressed if(padCheck & PADselect) return(99); // returns the value 99 to break out of the main loop }