i can provide a simple Stars Scroller. made with GsSortLine. not used TIM.
Code: Select all
//--------------------------------------------------------------------------
// I N C L U D E S
//--------------------------------------------------------------------------
#include <sys/types.h>
#include <stdlib.h>
#include <libetc.h>
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <libsnd.h>
#include <libmath.h>
#include <libspu.h>
#include "hitmod.h"
#include "pad.h"
#include "colorsin.h" // gives the Font a nice GREEN Effect
//-------------------- ASM ADRESS DEFINITION --------------------------
//---------------------------------------------------------------------
//---------------------------------------------------------------------
#define ORDERING_TABLE_LENGTH (12)
#define MAX_NO_PACKETS (4000)
//---------------------------------------------------------------------
//-------------DEFINITION STARS IN BACKGROUND --------------------
//---------------------------------------------------------------------
#define STARSC 50 // COUNT OF STARS
#define SPEED 1 // Max Scroll SPEED
#define PLANE 4 // MAXIMUM LAYERS for STARS
//--------------------------------------------------------------------------
// G L O B A L S
//--------------------------------------------------------------------------
GsOT othWorld[2];
GsOT_TAG otWorld[2][1<<ORDERING_TABLE_LENGTH];
PACKET out_packet[2][(MAX_NO_PACKETS * 24)];
int currentBuffer; // Actual Buffer for Double Buffering
u_long PADstatus=0; // SAVE PADSTATUS
int v_countGFX=0, v_countCODE=0; // HSync COUNTER
u_char HZMode=MODE_NTSC; // Not needed in here. it's for our Patches
//---------------------------------------------------------------------
//---------- READ INFO FROM EXTERNAL OBJECTS -----------------
//---------------------------------------------------------------------
extern char intro[];
extern char logl[];
extern char logr[];
extern char lef[];
extern char rig[];
typedef struct
{
int x; // X-Coordinate STARS
int y; // Y-Coordinate STARS
int z; // PLANE-ID
} STAR;
STAR Stars[STARSC];
//---------------------------------------------------------------------
//---------- Font-Sprites & Textures for TYPER -------------
//---------------------------------------------------------------------
extern char font1[];
#define PAGEW (30)
#define PAGEH (8)
#define ZEICHEN (32)// <--- How much Letters in a line of used Font
#define ZEILEN (3)// <--- Wieviele Rows in used font
#define MAX_CHAR (PAGEH*PAGEW)
GsSPRITE fontspr[ZEICHEN * ZEILEN];
GsSPRITE page[MAX_CHAR];
//-----------------------------------------------------------------------------
//--------------------SPRITES & DEFENITION ---------------------------
//-----------------------------------------------------------------------------
GsSPRITE sprLetter;
GsSPRITE sprLogl;
GsSPRITE sprLogr;
GsSPRITE sprLef;
GsSPRITE sprRig;
GsLINE line; // horizontally line
GsGLINE line2;// again
GsGLINE line3;// again :)
GsGLINE line4;
GsGLINE line5;
GsGLINE line6;
GsGLINE line7;
GsGLINE Wobble[320]; //Wobble Lines
int iScrollOffset=0;
//--------------------------------------------------------------------------
// P R O T O T Y P E S
//--------------------------------------------------------------------------
void InitialiseGraphics(int,int,int); // Width, Height, MODE
void UpdateWorld();
void RenderWorld(char cClear);
void LoadTIMData (u_long *tMemAddress); // RAM -> VRam
void SetSpriteInfo(GsSPRITE *tSprite, u_long tMemAddress, long tX, long tY, int tCut);
void init_LogoSprites(void);
void init_Typer(void);
void do_Typer(void);
void init_Page(int);
void InitStars(void);
void MoveStars(void);
void init_Wobble(void);
void do_Wobble(void);
int logosinoff=0;
int savedlogosin=0;
int logosinoff2=0; //Wobble Sin
int savedlogosin2=0; //Wobble Sin
//-------------- ABC-Table & Scroller for Typer ------------------
#define FONT_W (8)
#define FONT_H (10)
int anzfontabc=0;
static int isinit=0;
char fontabc[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,.-+*#!\"%&/()=?;:ÖÄÜöäüß ";
//-----------------------
// Count of Pages
//-----------------------
#define PAGES 7 // <------------ How many Signs
//-------------------------------
// The Page starts here
//-------------------------------
char texte[PAGEH*PAGES][PAGEW]=
{
// 1 5 10 15 20 25 30 SIGNS max. SIGNS
// | | | | | | |
{" "},// 1
{" "},// 2
{" "},// 3
{" "},// 4
{" "},// 5
{" P A R A D O X "},// 6
{" "},// 7
{" "},// 8
{" "},// 1
{" "},// 2
{" "},// 3
{" "},// 4
{" "},// 5
{" A N D "},// 6
{" "},// 7
{" "},// 8
{" "},// 1
{" "},// 2
{" "},// 3
{" "},// 4
{" "},// 5
{" UNDERCOVER - AGENTS "},// 6
{" "},// 7
{" "},// 8
{" "},// 1
{" "},// 2
{" "},// 3
{" "},// 4
{" "},// 5
{" PRESENT YOU "},// 6
{" "},// 7
{" "},// 8
{" "},// 1
{" "},// 2
{" "},// 3
{" "},// 4
{" "},// 5
{" ALIEN RESURRECTION "},// 6
{"US by Fox Interactive (c) 2000"},// 7
{" "},// 8
{" P A R A D O X "},// 1
{" "},// 2
{" "},// 3
{" Say hello to new talented "},// 4
{" Members for codings each "},// 5
{" and every Time: "},// 6
{" Gandhi and Inc. "},// 7
{" the Dudeds by U.C.A. "},// 8
{" P A R A D O X "},// 1
{" "},// 2
{" "},// 3
{" "},// 4
{"Coding................... INC."},// 5
{"Sound.................... INC."},// 6
{"Graphix.................. INC."},// 7
{" "},// 8
};
//--------------------------------------------------------------------------
// Function: main() MAIN PROG
// Description: --
// Parameters: --
// Returns: int
// Notes: N/A
//--------------------------------------------------------------------------
int main()
{
u_long lTmp1;
//-------------------- INIT SLIDING LOGO -----------------------------------
int iLogoPos=0,iLogoSpd=1,iTmp1;
int iPdxPos=640,iPdxSpd=2;
int iPdxPos1=800,iPdxSpd1=2;
int i,j;
int temp,temp1;
int Move=0;
//-------------------------------------------------------------------------
PadInit(0); // Joypad Init
init_Typer();
InitialiseGraphics(320,240,MODE_NTSC); // GFX Init, inkl. Init current Buffer...
// FntLoad(960,256); // not needed here . it's code for our Patches
// FntOpen(0, 85, 320, 220, 0, 512); // not needed here . it's code for our Patches
// FntPrint(" X --> PAL O --> NTSC\n"); // not needed here . it's code for our Patches
RenderWorld(1);RenderWorld(1); // 2x da DoubleBuffering...
// Chose FREQUENZY // not needed here . it's code for our Patches
// while (1) // not needed here . it's code for our Patches
// { // not needed here . it's code for our Patches
// PADstatus=PadRead(4); // not needed here . it's code for our Patches
// if (PADstatus & Pad1crc) // not needed here . it's code for our Patches
// break; // HZMode Initvalue == MODE_NTSC // not needed here . it's code for our Patches
// if (PADstatus & Pad1x) // not needed here . it's code for our Patches
// {HZMode=MODE_PAL;break; // not needed here . it's code for our Patches
// } // not needed here . it's code for our Patches
//} // not needed here . it's code for our Patches
InitialiseGraphics(320,240,HZMode); // GFX Init, incl. Init current Buffer...
//--------------------------------------------------------------------------
//-------------------------LOAD MUSIC AND PLAY ------------------------
//--------------------------------------------------------------------------
MOD_Init();
MOD_Load((u_char *) intro); // intro is the name of the sound file
MOD_Start();
//--------------------------------------------------------------------------
//------------------ READ EXTERNAL INFO FROM GFX -----------------------
//--------------------------------------------------------------------------
LoadTIMData((u_long*)logl);
LoadTIMData((u_long*)logr);
LoadTIMData((u_long*)font1);
LoadTIMData((u_long*)lef);
LoadTIMData((u_long*)rig);
for (iTmp1=0;iTmp1<1456;iTmp1+=1)
{
do_Typer();
if (iTmp1==28) VSync(80); // WAIT any SECONDS
RenderWorld(1); // DRAW
}
// --------------------------- INIT LOGO -----------------------------------
SetSpriteInfo(&sprLogl,(u_long)logl,80,30,1);
SetSpriteInfo(&sprLogr,(u_long)logr,240,30,1);
SetSpriteInfo(&sprRig,(u_long)rig,235,121,3);//x,y
SetSpriteInfo(&sprLef,(u_long)lef,80,119,3);//x,y
//--------------------------------------------------------------------------
//--------------------- INIT LETTERS ----------------------------------
//--------------------------------------------------------------------------
sprLetter.w=sprLetter.h=16;// height of 1 Letter
sprLetter.mx=sprLetter.my=0;
sprLetter.v=sprLetter.u=0;
{
GsSortSprite(&sprLetter,&othWorld[currentBuffer],2);
RenderWorld(1);
}
//--------------------------------------------------------------------------
init_Wobble(); // Init Wobble as GsGLINE´s
InitStars();
// ------------------------------------
// -------- MAIN PROGRAMM --------
// ------------------------------------
while(1)
{
int iTmp1,iTmp2,iTmp3,iTmp4,iTmp5;
PADstatus=PadRead(4);
if ((PADstatus&Pad1Start)) break;
do_Typer();
do_Wobble();
//-----------------LOGO S L I D I N G S----------------
if (iLogoPos<-40) iLogoSpd=1;
if (iLogoPos>40) iLogoSpd=-1;
iLogoPos+=iLogoSpd;
if (iPdxPos<-100) iPdxSpd=2;
if (iPdxPos>260) iPdxSpd=-2;
iPdxPos+=iPdxSpd;
if (iPdxPos1<60) iPdxSpd1=2;
if (iPdxPos1>420) iPdxSpd1=-2;
iPdxPos1+=iPdxSpd1;
//--------------------------------------------------
//--------- GIVE SLIDINGS FREE --------
//--------------------------------------------------
sprLogl.x=iPdxPos;
sprLogr.x=iPdxPos1;
//---------- LAYER DEFENITION OF SPRITES -----------
GsSortSprite(&sprLogl,&othWorld[currentBuffer],1);
GsSortSprite(&sprLogr,&othWorld[currentBuffer],1);
GsSortSprite(&sprLef,&othWorld[currentBuffer],3);
GsSortSprite(&sprRig,&othWorld[currentBuffer],3);
//----------------------------------------------------
MoveStars();
//----------------DRAW 3 LINES ------------------
line2.r0=150;line2.g0=100;line2.b0=40;
line2.x1=10;line2.x0=160;
line2.y0=line2.y1=80;
line7.r0=150;line7.g0=100;line7.b0=40;
line7.x0=160;line7.x1=309;
line7.y0=line7.y1=80;
line5.r0=150;line5.g0=100;line5.b0=40;
line5.x1=10;line5.x0=160;
line5.y0=line5.y1=157;
line6.r0=150;line6.g0=100;line6.b0=40;
line6.x0=160;line6.x1=309;
line6.y0=line6.y1=157;
line3.r0=1;line3.g0=120;line3.b0=0;
line3.x0=line3.x1=320;
line3.y0=0;line3.y1=240;
line4.r0=1;line4.g0=120;line4.b0=0;
line4.x0=0;line4.x1=320;
line4.y0=line4.y1=120;
GsSortGLine(&line2,&othWorld[currentBuffer],1);
GsSortGLine(&line5,&othWorld[currentBuffer],1);
GsSortGLine(&line6,&othWorld[currentBuffer],1);
GsSortGLine(&line7,&othWorld[currentBuffer],1);
//-------------------------------------------------------------
RenderWorld(1);
}
// MOD_Stop();MOD_Free();VSync(3);
// PadStop();
// ResetGraph(0);
// StopCallback();
//-------------------------------------------------------------
//------------------PATCH FUNKTION- Spiel entpacken------------
//-------------------------------------------------------------
//EnterCriticalSection();
//depack1();
//start1();
//ExitCriticalSection();
//-------------------------------------------------------------
//************************* starts game ***********************
//-------------------------------------------------------------
//asm("nop");
//asm("j 0x8008656c"); // ExecAddress --> Load Game after PAD BREAK
//asm("nop");
// return 0;
}
void InitStars(void)
{
int l,zi;
srand(1);
for(l=0;l<STARSC;l++)
{
zi=rand()%320;
Stars[l].x=zi;
zi=rand()%160;
Stars[l].y=zi;
zi=rand()%PLANE;
Stars[l].z=zi+1;
}
}
void MoveStars(void)
{
int i;
for(i=0; i<STARSC; i++)
{
Stars[i].x+=SPEED*Stars[i].z;
if(Stars[i].x>320)
Stars[i].x=0;
line.x0 = line.x1 = Stars[i].x;
line.y0 = line.y1 = Stars[i].y;
line.r = 1;
line.g = line.b =Stars[i].z*50;
GsSortLine(&line,&othWorld[currentBuffer],2);
}
}
//------------------------------------------------------------------------------
// F U N C T I O N D E F I N I T I O N E N
//------------------------------------------------------------------------------
void InitialiseGraphics(int SCRWidth,int SCRHeight,int HZMode)
{
SetVideoMode(HZMode);
if ((HZMode == MODE_NTSC) && (SCRHeight==256)) SCRHeight=240;
GsInitGraph(SCRWidth, SCRHeight, GsNONINTER|GsOFSGPU, 0, 0);
GsDefDispBuff(0, 0, 0, SCRHeight);
if (SCRHeight == 256) GsDISPENV.screen.h=256;
othWorld[0].length = ORDERING_TABLE_LENGTH;
othWorld[1].length = ORDERING_TABLE_LENGTH;
othWorld[0].org = otWorld[0];
othWorld[1].org = otWorld[1];
GsClearOt(0,0,&othWorld[0]);
GsClearOt(0,0,&othWorld[1]);
currentBuffer=GsGetActiveBuff();
GsSetWorkBase((PACKET*)out_packet[currentBuffer]);
}
//------------------------------------------------------------------------------
void RenderWorld(char cClear)
{
v_countCODE=VSync(1);
DrawSync(0);
v_countGFX = VSync(1);
VSync(0);
GsSwapDispBuff();
// "check "ClearScreen"-Kommando in OT R, G, B
if (cClear==1) GsSortClear( 0, 0, 0,&othWorld[currentBuffer]); //background Color
if (cClear==155) GsSortClear( 0, 0, 0,&othWorld[currentBuffer]);
// start Draw (GPU is drawing OT in Background)
GsDrawOt(&othWorld[currentBuffer]);
FntFlush(-1);
// ------------------------------------ "NEW LIST
currentBuffer=GsGetActiveBuff();
GsSetWorkBase((PACKET*)out_packet[currentBuffer]);
GsClearOt(0, 0, &othWorld[currentBuffer]);
}
//------------------------------------------------------------------------------
void LoadTIMData(u_long *tMemAddress)
{
RECT tRect;
GsIMAGE tTim;
DrawSync(0);
tMemAddress++;
GsGetTimInfo(tMemAddress, &tTim); // SAVE TIM-Info in TIM
tRect.x = tTim.px;
tRect.y = tTim.py;
tRect.w = tTim.pw;
tRect.h = tTim.ph;
LoadImage(&tRect, tTim.pixel); // Load TIM-DATA into VideoRam
DrawSync(0);
if ((tTim.pmode >> 3) & 0x01)
{
tRect.x = tTim.cx;
tRect.y = tTim.cy;
tRect.w = tTim.cw;
tRect.h = tTim.ch;
LoadImage(&tRect, tTim.clut); // load CLUT into VideoRam
};
DrawSync(0); // wait until GPU is ready
}
//------------------------------------------------------------------------------
// Function: SetSpriteInfo(...)
//------------------------------------------------------------------------------
void SetSpriteInfo(GsSPRITE *tSprite, u_long tMemAddress, long tX, long tY, int tCut)
{
GsIMAGE tTim; // TIM image Information
tMemAddress += 4; // Pointer to DATA
GsGetTimInfo((u_long *) tMemAddress, &tTim); // get TIM Info in tTim
tSprite->x = tX; // CORDINATES
tSprite->y = tY; // CORDINATES
switch (tTim.pmode & 3) // X-Value depends of Depth Bit!
{
case 0: tSprite->w = tTim.pw << 2;
tSprite->u = (tTim.px & 0x3f) * 4;
break;
case 1: tSprite->w = tTim.pw << 1;
tSprite->u = (tTim.px & 0x3f) * 2;
break;
default: tSprite->w = tTim.pw;
tSprite->u = tTim.px & 0x3f;
};
tSprite->h = tTim.ph;
tSprite->v = tTim.py & 0xff;
tSprite->tpage = GetTPage((tTim.pmode & 3),0,tTim.px,tTim.py);
tSprite->attribute = (tTim.pmode & 3) << 24;
tSprite->cx = tTim.cx; // give CLUT by Sprite
tSprite->cy = tTim.cy;
tSprite->r = tSprite->g = tSprite->b = 128; // normally Intensity (of Colours)
tSprite->mx = tSprite->w/2; // Ref Point to Sprite Center
tSprite->my = tSprite->h/2;
tSprite->scalex = tSprite->scaley = ONE; // Skale to 1 (normal Size)
tSprite->rotate = 0; // Rotation to 0
if (tCut) // Cut Sprite if Tim
tSprite->w -= tCut; // have an ivailid Size
};
//-----------------------------------------------------------------
// INIT WOBBLE GsGLINE´s
//-----------------------------------------------------------------
void init_Wobble()
{
int i=0;
for(i=0;i<320;i++)
{
Wobble[i]=Wobble[0];
Wobble[i].x0=Wobble[i].x1=i;
Wobble[i].y0=60;
Wobble[i].y1=100;
Wobble[i].r0=Wobble[i].b0=Wobble[i].g0=0;
Wobble[i].r1=Wobble[i].b1=Wobble[i].g1=0;
}
}
void do_Wobble()
{
int j;
int i;
logosinoff2=savedlogosin2;
for(i=0;i<320;i++)
{
j=i+1;
Wobble[i].attribute=(2<<24)+(0<<29)+(1<<30);
Wobble[i].r0=Wobble[i].b0=0;
Wobble[i].g0=30;//colorsin;
Wobble[i].r1=Wobble[i].b1=Wobble[i].g1=0;
Wobble[i].y0=155+logosin[logosinoff2]/2+logosin4[i]/2;
Wobble[i].y1=190+logosin[logosinoff2]/2+logosin3[i]/2;
GsSortGLine(&Wobble[i],&othWorld[currentBuffer], 3);
logosinoff2++;
if(logosinoff2==520)logosinoff2=0;
}
savedlogosin2++;
if(savedlogosin2==520) savedlogosin2=0;
}
//===========================
// Typer Font INIT
//===========================
void init_Typer()
{
GsIMAGE fontimg;
int i=0,j=0,k=0;
unsigned char fontxy[ZEICHEN*ZEILEN*2];
anzfontabc=strlen(fontabc);
//--------------------------------------------
// X+Y Offset Calculating in between of Textur
//--------------------------------------------
for(i=0;i<ZEILEN;i++)
{
for(j=0;j<ZEICHEN;j++)
{
fontxy[k++]=(j*FONT_W); // X Offset
fontxy[k++]=(i*FONT_H); // Y Offset
}
}
//---------------------------------------
// Textur & all Sprites init
//----------------------------------------
SetSpriteInfo(&fontspr[0],(u_long)font1,0,0,1);
j=0;
fontspr[0].w=FONT_W;
fontspr[0].h=FONT_H;
fontspr[0].u=fontxy[j++];
fontspr[0].v=fontxy[j++];
for(i=1;i<anzfontabc;i++)
{
fontspr[i]=fontspr[0];
fontspr[i].u=fontxy[j++];
fontspr[i].v=fontxy[j++];
}
}
//================
// DO Typer
//================
void do_Typer()
{
static int act_x=0,act_y=0,act_p=0;
static int charcnt=0,delaycnt=10*10,
clrcount=55;
int i=0,subit=-2;
logosinoff=savedlogosin;
//charcnt=MAX_CHAR;
//-----------------------------
// ERASE PAGE ?
//-----------------------------
if(clrcount==55)
{
//---------------------------------------------------------------------
// if actual Page not set. do it now
//---------------------------------------------------------------------
if(isinit==0)
{
init_Page(act_p);
isinit++;
}
//-----------------------------------
// Do Pager, letter by letter
//-----------------------------------
for(i=0;i<charcnt;i++)
{
page[i].r=0; page[i].g=0-(colorsin[logosinoff]); page[i].b=0;
GsSortFastSprite(&page[i],&othWorld[currentBuffer],3);
logosinoff--;
if (logosinoff==10) logosinoff=520;
}
savedlogosin++;
if (savedlogosin==1040) savedlogosin=5;
//-------------------------------------------------------
// if one Sign is missed. do one more
//-------------------------------------------------------
if(charcnt<MAX_CHAR)
{
charcnt++;
}
//----------------------------------------------------
// ok, now all shown... now wait and erase
//----------------------------------------------------
else
{
if(--delaycnt==0)
{
delaycnt=10*10;
clrcount--;
}
}
}
//----------------------
// ok, get new page
//----------------------
else
{
if(++act_p==PAGES) act_p=0;
charcnt=0;
isinit=0;
clrcount=55;
}
}
//=================================
// fill here Sprite-Array for Typer
//=================================
void init_Page(int pagenum)
{
int h,i,j,k=0;
//--------------------------------------------------
// calculate Sprites
//--------------------------------------------------
for(h=0;h<PAGEH;h++)
{
for(i=0;i<PAGEW;i++)
{
for(j=0;j<anzfontabc;j++)
{
//-------------------------------------------------
// if "SPACE" ? don't show a letter or Sign
//-------------------------------------------------
if(texte[h+(PAGEH*pagenum)][i]==' ')
{
page[k++].w=0;
break;
}
//------------------------------------------------
// give Letter the correct Sprite
//------------------------------------------------
if(texte[h+(PAGEH*pagenum)][i]==fontabc[j])
{
page[k ]=fontspr[j];
page[k ].x=42+(i*FONT_W); // on which X Cord it should Print?
page[k++].y=65+(h*FONT_H); // on which Y Cord it should Print?
break;
}
}
}
}
}