/* --------------------------------------------------------------------- ** Project: Tetixx (a Tetris clone) ** File: tetixxscr.c ** Date: 07.02.1999 ** Autor: Robert Jurziga */ #include #include #include "tetixx.h" // --------------------------------------------------------------------- // E X T E R N A L S // --------------------------------------------------------------------- extern GsSPRITE BGLeft; extern GsSPRITE BGRight; extern GsSPRITE TXLeft; extern GsSPRITE TXRight; extern char tx_left[]; extern char tx_right[]; extern GsSPRITE Font16Chars[]; extern char *textpages[]; extern int font16xsize[]; extern char PressStart[]; // --------------------------------------------------------------------- // P R O T O T Y P E S // --------------------------------------------------------------------- void TetixxScreen(void); static void _Initialize(void); static void _InitTXSprites(void); static int _DoTextPages(void); static int _TXPage_Init(void); static int _TXPage_ComeUp(void); static int _TXPage_GoDown(void); static void _Create_PressStart(void); // --------------------------------------------------------------------- // V A R I A B L E S // --------------------------------------------------------------------- static GsSPRITE TextPageSprites[7*26]; static GsSPRITE PressStartSprite; static int _txpage_status; static int _txpage_used; static int _txpage_page; static int _txpage_ytop; static int _txpage_waveindex; static short _comewave[]={ 512-0,512-17,512-33,512-50,512-67,512-83,512-100,512-116, 512-133,512-149,512-165,512-180,512-196,512-211,512-226,512-241, 512-256,512-270,512-284,512-298,512-312,512-325,512-338,512-350, 512-362,512-374,512-385,512-396,512-406,512-416,512-426,512-435, 512-444,512-452,512-460,512-467,512-472,512-476,512-480,512-482}; static short _txpage_wave[]={ 0,6,13-6,19-13,25-19,31-25,37-31,43-37,49-43,55-49,60-55,66-60, 71-66,76-71,81-76,86-81, 91-86,95-91,99-95,103-99,106-103,110-106,113-110,116-113, 118-116,121-118,122-121,124-122,126-124,127-126,128-127}; static int _comewaveindex; static int _ActiBuf; static int _done; static int _phase; static int _fade; static int _count; static int _action; static short _bg_ready; static short _ps_count; static u_long _ps_switch; static int _start_pressed; static int _changepage; static short _nox; /* --------------------------------------------------------------------- // Function: TetixxScreen // Description: Background sprites fade form black to orginal brightness. // The logo comes down and the crediz and greets come out. */ void TetixxScreen() { unsigned char mask; short i; if (!credz_flag) { _Initialize(); TXLeft.x=512; TXRight.x=512+256; } _done=_phase=_fade=_count=_comewaveindex=0; _bg_ready=0; _txpage_status=0; _txpage_used=0; _txpage_page=0; _txpage_waveindex=0; _start_pressed=0; _changepage=0; _nox = 0; _action = 0; while(!_done) { _ActiBuf = GsGetActiveBuff(); PadBits=(~(*(pport0+2) | *(pport0+3) << 8 )); if (_bg_ready) { mask = *(pport0+1) >> 4; if (*pport0 == 0xff || mask != 0x4) InsertStandardController(&ThemeMod); } GsSetWorkBase((PACKET*)GPU_WorkArea[_ActiBuf]); GsClearOt(0, 0, &WorldOT[_ActiBuf]); switch (_phase) { case 0: { if (!credz_flag) { if (_fade < 0x68) { BGLeft.r = BGRight.r = _fade; BGLeft.g = BGRight.g = _fade; BGLeft.b = BGRight.b = _fade; _fade+=8; } TXLeft.x=_comewave[_comewaveindex]; TXRight.x=256+_comewave[_comewaveindex]; _comewaveindex++; if (_comewaveindex == 40) {_phase++; _bg_ready=1;} } else { _phase++; _bg_ready=1; } break; } case 1: { _action=_DoTextPages(); if (_action) _phase++; break; } case 2: { _done=1; break; } } GsSortFastSprite(&BGLeft,&WorldOT[_ActiBuf],15); // draw background GsSortFastSprite(&BGRight,&WorldOT[_ActiBuf],15); GsSortFastSprite(&TXRight,&WorldOT[_ActiBuf],14); GsSortFastSprite(&TXLeft,&WorldOT[_ActiBuf],14); // draw logo if (_bg_ready) { _ps_count++; if (_ps_count > 35) { _ps_count=0; _ps_switch^=(1<<31); } PressStartSprite.attribute=_ps_switch; GsSortFastSprite(&PressStartSprite,&WorldOT[_ActiBuf],13); // if (PadBits & PAD_Start) _start_pressed=1; if (!_nox) { if (PadBits & PAD_Cross) { SsUtKeyOn(ChooseSoundVabID, 0, SFX_HIHAT, 55, 0, 127, 127); _changepage=1; } if (PadBits & PAD_Start) { SsUtKeyOn(ChooseSoundVabID, 0, SFX_SELECT, 50, 0, 127, 127); _start_pressed=1; _changepage=1;} } // if (PadBits & PAD_Select) _start_pressed=dumpScreen(0, 0, 511, 255); } if (_txpage_used) // draw the texter { for (i=0; i< _txpage_used; i++) { GsSortFastSprite(&TextPageSprites[i],&WorldOT[_ActiBuf],13); } } PlayYXM(&ThemeMod); DrawSync(0); VSync(0); GsSwapDispBuff(); GsSortClear(0x0, 0x0, 0x0, &WorldOT[_ActiBuf]); GsDrawOt(&WorldOT[_ActiBuf]); } // go back to main programm } /* --------------------------------------------------------------------- // Function: _DoTextPages // Description: Here the text pages come up // OUT: 0 = stay here // 1 = increase _phase */ static int _DoTextPages() { int rts; int i = 0; int retval = 0; // if (! _start_pressed) // { if (! _changepage) { switch (_txpage_status) { case 0: { _txpage_used=_TXPage_Init(); _txpage_status++; _txpage_waveindex=0; break; } case 1: { rts=_TXPage_ComeUp(); if (rts) {_count=0; _txpage_status++; _nox=0;} break; } case 2: { if (_count == 242) _txpage_status++; _count++; break; } case 3: { rts=_TXPage_GoDown(); if (rts) { _txpage_status=0; _txpage_page++; if (_start_pressed) retval = 1; } break; } } } else { _txpage_status = 3; _changepage = 0; _nox = 1; } // } // else // { // retvar=_TXPage_GoDown(); // } return(retval); } // ------------------------------------------ static int _TXPage_GoDown() { GsSPRITE *spr; short i; spr=TextPageSprites; for (i=0; i<_txpage_used; i++) { spr=&TextPageSprites[i]; spr->y+=_txpage_wave[_txpage_waveindex]; GsSortFastSprite(spr,&WorldOT[_ActiBuf],13); } _txpage_waveindex++; if (_txpage_waveindex == 31) { _txpage_waveindex=0; return(1); } else return(0); } // ------------------------------------------ static int _TXPage_ComeUp() { GsSPRITE *spr; short i; spr=TextPageSprites; for (i=0; i<_txpage_used; i++) { spr=&TextPageSprites[i]; spr->y-=_txpage_wave[_txpage_waveindex]; GsSortFastSprite(spr,&WorldOT[_ActiBuf],13); } _txpage_waveindex++; if (_txpage_waveindex == 31) { _txpage_waveindex=0; return(1); } else return(0); } // ------------------------------------------ // Funtion: _TXPage_Init // Description: Calculate the Vertical center of the text page // Then calculate the horizontal centern of each line. // static int _TXPage_Init() { int lines; int ysize; int xposs[7]; int i=0; int xsize; int j=0; int _charsused=0; int k; char *tmppage,*tmppage2; GsSPRITE *srcspr,*destspr; // init text page pointers tmppage=textpages[_txpage_page]; if (*tmppage == '\xfd') {_txpage_page=0; tmppage=textpages[0];} // count lines to find out the center. tmppage2=tmppage; lines=0; while (*tmppage2 != '\xfe') { if (*tmppage2 == '\xff') lines++; tmppage2++; } ysize=(lines*17); _txpage_ytop=((128-ysize)>>1)+128; // now count chars in each line to calculate the // horizontal center of each line store the x points // in the xposs array tmppage2=tmppage; for (i=0; i>1; } // init now the sprites for each font char // how much sprites are required is specified in _charsused // if there is a space in the line there is no sprite inited // the font chars were inited in the Font16Chars. // To init a TextPage sprite the whole GsSPIRTE has to be copied. j=0; for (i=0; iattribute = srcspr->attribute; destspr->x=xsize; destspr->y=_txpage_ytop+128+(i*17); destspr->w=16; destspr->h=16; destspr->tpage = srcspr->tpage; destspr->u = srcspr->u; destspr->v = srcspr->v; destspr->cx = srcspr->cx; destspr->cy = srcspr->cy; destspr->r = 128; destspr->g = 128; destspr->b = 128; destspr->mx=0; destspr->my=0; destspr->scaley=ONE; destspr->scalex=ONE; destspr->rotate=0; j++; _charsused++; } xsize+=font16xsize[k]; tmppage++; } tmppage++; } return(_charsused); } /* --------------------------------------------------------------------- // Function: _Initalize // Description: Init the graphix for the Tetixx Screen display. // o Tetixx Logo (Sprites (left/right)) */ static void _Initialize() { _InitTXSprites(); _Create_PressStart(); } // - - - - - - - - - - - - - - - - - - // Function: _Create_PressStart // Description: Init a sprite which contains. // "PRESS >START<" // // static void _Create_PressStart() { GsIMAGE tim; RECT rect; u_long *ptr; ptr=(u_long *)PressStart; ptr++; GsGetTimInfo(ptr, &tim); rect.x = tim.px; rect.y = tim.py; rect.w = tim.pw; rect.h = tim.ph; LoadImage(&rect, tim.pixel); DrawSync(0); rect.x = tim.cx; rect.y = tim.cy; rect.w = tim.cw; rect.h = tim.ch; LoadImage(&rect, tim.clut); DrawSync(0); PressStartSprite.attribute=0; PressStartSprite.x=((512-196)>>1); PressStartSprite.y=(108+4); PressStartSprite.w=196; PressStartSprite.h=9; PressStartSprite.tpage=GetTPage(0, 0, tim.px, tim.py); PressStartSprite.u=0; PressStartSprite.v=108+64; PressStartSprite.cx=tim.cx; PressStartSprite.cy=tim.cy; PressStartSprite.r = 0x80; PressStartSprite.g = 0x80; PressStartSprite.b = 0x80; PressStartSprite.mx = 0; PressStartSprite.my = 0; PressStartSprite.scalex=ONE; PressStartSprite.scaley=ONE; PressStartSprite.rotate=0; } // - - - - - - - - - - - - - - - - - - // Function: _InitTXSprites // Description: Set the TXLogo sprites TXLeft and Right. // TXLeft: 512,256/768,2 256x108 // TXRight: 640,256/768,3 192x109 // static void _InitTXSprites() { static GsIMAGE tim; static RECT rect; static u_long *ptr; static u_short tpage; // Setup left tetixx sprite ptr=(u_long *)tx_left; ptr++; GsGetTimInfo(ptr, &tim); rect.x = tim.px; rect.y = tim.py; rect.w = tim.pw; rect.h = tim.ph; LoadImage(&rect, tim.pixel); DrawSync(0); rect.x = tim.cx; rect.y = tim.cy; rect.w = tim.cw; rect.h = tim.ch; LoadImage(&rect, tim.clut); DrawSync(0); tpage = GetTPage(1, 0, tim.px, tim.py); TXLeft.attribute=((1<<24)); TXLeft.x=0; TXLeft.y=0; TXLeft.w=256; TXLeft.h=108; TXLeft.tpage=tpage; TXLeft.u=0; TXLeft.v=0; TXLeft.cx=tim.cx; TXLeft.cy=tim.cy; TXLeft.r = 0x60; TXLeft.g = 0x60; TXLeft.b = 0x60; TXLeft.mx = 0; TXLeft.my = 0; TXLeft.scalex=ONE; TXLeft.scaley=ONE; TXLeft.rotate=0; // Setup right tetixx sprite ptr=(u_long *)tx_right; ptr++; GsGetTimInfo(ptr, &tim); rect.x = tim.px; rect.y = tim.py; rect.w = tim.pw; rect.h = tim.ph; LoadImage(&rect, tim.pixel); DrawSync(0); rect.x = tim.cx; rect.y = tim.cy; rect.w = tim.cw; rect.h = tim.ch; LoadImage(&rect, tim.clut); DrawSync(0); tpage = GetTPage(1, 0, tim.px, tim.py); TXRight.attribute=((1<<24)); TXRight.x=256; TXRight.y=0; TXRight.w=192; TXRight.h=108; TXRight.tpage=tpage; TXRight.u=0; TXRight.v=0; TXRight.cx=tim.cx; TXRight.cy=tim.cy; TXRight.r = 0x60; TXRight.g = 0x60; TXRight.b = 0x60; TXRight.mx = 0; TXRight.my = 0; TXRight.scalex=ONE; TXRight.scaley=ONE; TXRight.rotate=0; }