thx now i am adding a menu screen but how can i make the the apps change from MenuInput (); to input_key(); 
Code: Select all
// *******************************************************************
// 
// This is a port of a classic old voxel terrain renderer. Andrea kindly
// released his code back in 2000 so here it is again but on PSP!!!
//
// The other person that needs thanking is Nem - your hello world, sound
// and pg lib made there way here, I hope thats ok? :-)
//
// The rest of it is written by Grover.. for anyone to use, and abuse.
// The windows rendering is incomplete and only a few sce functions have
// been emulated - its an ongoing thing, so it will get filled out in the
// next week or so...
//								Grover - May 2005.
//								dlannan@gagagames.com
//
// *******************************************************************
// Credits for Original Glvox writer -  Andrea "6502" Griffini, programmer
//                                             agriff@ix.netcom.com
//                                         http://vv.val.net/~agriffini
//
// *******************************************************************
#include "syscall.h"
#include "pg.h"
#include "_clib.h"
// *******************************************************************
// Not yet used.. yet..
#include "HeightMap.c"
#include "Sky.c"
//#include "Pause.c"
//#include "Water1.c"
// *******************************************************************
#ifdef WIN32
#include "win32_psp.h"
#endif
// *******************************************************************
#define PIXELSKIP		4
#define CLOCKS_PER_SEC	1000000
float FOV=3.141592654/4;   // half of the xy field of view
// *******************************************************************
#define BUFFER_WIDTH    ((512/PIXELSKIP)+1)
#define BUFFER_HEIGHT   271
// *******************************************************************
// These dont seem to hurt the ps2 compiler.. 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
// *******************************************************************
typedef unsigned char byte;
#define MAP_W		256
#define MAP_H		256
#define MAP_MASK	0xFFFF
// *******************************************************************
unsigned char app_running = 1;
//unsigned short *HMap = (unsigned short *)Water1Data;						// Height field
unsigned char HMap[MAP_W*MAP_H];						// Color map
unsigned char CMap[MAP_W*MAP_H];						// Color map
unsigned char LMap[MAP_W*MAP_H];
unsigned short *Video;
// unsigned char Video[BUFFER_WIDTH * BUFFER_HEIGHT];		// Off-screen buffer
static float gl_ss, gl_sa, gl_a, gl_s;
static int gl_x0, gl_y0;
// *******************************************************************
//
// Reduces a value to 0..255 (used in height field computation)
//
int Clamp(int x)
{
  return (x<0 ? 0 : (x>255 ? 255 : x));
}
// *******************************************************************
static void calc_light( int x1, int y1, int x2, int y2 )
{
  int i, j, k, c, z ;
  int max=0;
  float norm;
  float t;
  for(z = 0; z < 256 * 256; z++)
	  LMap[z] = 0;
//for( k = 2 ; k >= 1; k -- )
  for( c = 0 ; c < 2 ; c ++ )
  {
    for( i = y1 ; i <= y2 ; i ++ )
    {
      for( j = x1 ; j <= x2 ; j ++ )
      {
        int h00 = HMap[ ((i-1) * MAP_W + (j-1)) & MAP_MASK ];
        int h01 = HMap[ ((i-1) * MAP_W + (j+1)) & MAP_MASK ];
        int h10 = HMap[ ((i+1) * MAP_W + (j-1)) & MAP_MASK ];
        int h11 = HMap[ ((i+1) * MAP_W + (j+1)) & MAP_MASK ];
        int dx  = h11 - h00 ;
        int dy  = h10 - h01 ;
        int d   = dx * dx + dy * dy ;
        if( c == 0 )
        {
           if( max < d ) max = d;
        } else
        {
//           t = (float)sqrtu(d) * norm * 0.5f;
           t = (float)sqrtu(d) * norm;
//		   t -= 2.0f;
		   t *= 0.5f;
		   // Some evil replacements until I find a solution for the gcc c.lt.s problem
           if( (*(unsigned int *)&t) & 0x80000000 ) t = 0.0f;
//           if( t < 0.0f ) t = 0.0f;
           if( ((int )t) > 255) t = 255.0f;
//           if( t > 255.0f ) t = 255.0f;
           LMap[ (i * MAP_W + j) & MAP_MASK ] = ((int)t);
           LMap[ (i * MAP_W + j) & MAP_MASK ] ^= 0xFF;
        }
      }
	  norm = 512.0f / (float)sqrtu(max);
    }
  }
}
// *******************************************************************
//
// Heightfield and colormap computation
//
void MakeMap1(void)
{
  int x,y,p,i,j,k,k2,p2;
  //
  // Start from a plasma clouds fractal
  //
  for(y=0; y<256; y++)
   {
      for(x=0; x<256; x++)
      {
        HMap[x + y * 256] = HeightMapData1[x + y * 256];
      }
   }
  calc_light(0,0,255,255);// all terrain black if uncommented
  //
  // Color computation (derivative of the height field)
  //
  /*for ( i=0; i<256*256; i+=256 )
    for ( j=0; j<256; j++ )
    {
      k=128+(HMap[((i+256)&0xFF00)+((j+1)&255)]-HMap[i+j])*4;
      if ( k<0 ) k=0; if (k>255) k=255;
      CMap[i+j]=k;
    }
	
	calc_light(0,0,255,255);
  //
  // Smoothing
  //
    for ( i=0; i<256*256; i+=256 )
      for ( j=0; j<256; j++ )
      {
        HMap[i+j]=(HMap[((i+256)&0xFF00)+j]+HMap[i+((j+1)&0xFF)]+
                   HMap[((i-256)&0xFF00)+j]+HMap[i+((j-1)&0xFF)])>>2;
      }*/
}
// *******************************************************************
int lasty[BUFFER_WIDTH],         // Last pixel drawn on a given column
    lastc[BUFFER_WIDTH];         // Color of last pixel on a column
    lastx0[BUFFER_WIDTH];         // Color of last pixel on a column
    lasty0[BUFFER_WIDTH];         // Color of last pixel on a column
	lastl[BUFFER_WIDTH];
//
// Draw a "section" of the landscape; x0,y0 and x1,y1 and the xy coordinates
// on the height field, hy is the viewpoint height, s is the scaling factor
// for the distance. x0,y0,x1,y1 are 16.16 fixed point numbers and the
// scaling factor is a 16.8 fixed point value.
//
void Line(int x0,int y0,int x1,int y1,int hy,int s,int depth)
{
	int	state = 0;
  int i,sx,sy;
  int hys=hy*s;
  // Compute xy speed
  sx=(x1-x0)/BUFFER_WIDTH; sy=(y1-y0)/BUFFER_WIDTH;
  for ( i=0; i<BUFFER_WIDTH-PIXELSIZE; i++ )
  {
    int l,c,y,h,u0,v0,u1,v1,a,b,h0,h1,h2,h3;
    //
    // Compute the xy coordinates; a and b will be the position inside the
    // single map cell (0..255).
    //
    u0=(x0>>16)&0xFF;    a=(x0>>8)&255;
    v0=((y0>>8)&0xFF00); b=(y0>>8)&255;
    u1=(u0+1)&0xFF;
    v1=(v0+256)&0xFF00;
    //
    // Fetch the height at the four corners of the square the point is in
    //
    h0=HMap[u0+v0]; h2=HMap[u0+v1];
    h1=HMap[u1+v0]; h3=HMap[u1+v1];
    h0=(h0<<8)+a*(h1-h0);
    h2=(h2<<8)+a*(h3-h2);
    h= (h0<<8)+b*(h2-h0);
    //
    // Fetch the color at the four corners of the square the point is in
    //
    h0=LMap[u0+v0]; h2=LMap[u0+v1];
    h1=LMap[u1+v0]; h3=LMap[u1+v1];
    h0=(h0<<8)+a*(h1-h0);
    h2=(h2<<8)+a*(h3-h2);
    l=((h0<<8)+b*(h2-h0));
    //
    // Compute screen height using the scaling factor
    //
	y=(h/256.0f)*(s/256.0f);
	y-=hys;
	y>>=11;
	y+=BUFFER_HEIGHT/2;
    //
    // Draw the column
    //
    if ( y<(a=lasty[i]) && y > 0 )
    {
		int ubl= l;
		int lastubl= lastl[i];
		int lastlastubl = lastl[i-1];
		int ubstep;
		int sc,cc;
		int endy = BUFFER_HEIGHT;
		if(lasty[i]<BUFFER_HEIGHT)
			endy = lasty[i];
		ubstep = (((lastubl - ubl)) / (endy-y)) ;
		for(a = y; (a<lasty[i]) && (a < BUFFER_HEIGHT); a++)
		{
			unsigned short *Vptr = &Video[i*PIXELSKIP + a * 512];
			unsigned short Val = ((ubl & 0x7fffffff) >> 16);// & 0x001f | 0x0e0 | 0x7c00;
			Val = ((Val >> 3) & 0x1f) | (((Val >> 3) & 0x1f) << 10) | (((Val >> 3) & 0x1f) << 5);
			cc = PIXELSKIP;
			while(cc--)
				*Vptr++ = Val;
            
			ubl +=ubstep;
		}
		lasty[i]=y;
    }
	lastx0[i]=x0;
	lasty0[i]=y0;
    lastc[i]=c;
	lastl[i]=l;
    //
    // Advance to next xy position
    //
    x0+=sx; y0+=sy;
  }
}
// *******************************************************************
//
// Draw the view from the point x0,y0 (16.16) looking at angle a
//
void View(int x0,int y0,float aa)
{
  int d,p;
  int a,b,h,u0,v0,u1,v1,h0,h1,h2,h3;
  int p1, p2, p3, p4;
  for ( d=0; d<BUFFER_WIDTH; d++ )
  {
    lasty[d]=BUFFER_HEIGHT;
    lastc[d]=-1;
    lastx0[d]=0;
    lasty0[d]=0;
  }
  u0=(x0>>16)&0xFF;    a=(x0>>8)&255;
  v0=((y0>>8)&0xFF00); b=(y0>>8)&255;
  u1=(u0+1)&0xFF;
  v1=(v0+256)&0xFF00;
  h0=HMap[u0+v0]; h2=HMap[u0+v1];
  h1=HMap[u1+v0]; h3=HMap[u1+v1];
  h0=(h0<<8)+a*(h1-h0);
  h2=(h2<<8)+a*(h3-h2);
  h=((h0<<8)+b*(h2-h0))>>16;
  p=0;
  for ( d=0; d<500; d+=1+(d>>6))
  {
    p1 = (int)((float)x0+(float)d*65535.0f*fcos(aa-FOV)) ;//<< 16;
	p2 = (int)((float)y0+(float)d*65535.0f*fsin(aa-FOV)) ;//<< 16;
	p3 = (int)((float)x0+(float)d*65535.0f*fcos(aa+FOV)) ;//<< 16;
	p4 = (int)((float)y0+(float)d*65535.0f*fsin(aa+FOV)) ;//<< 16;
    Line(p1,p2,p3,p4,
         h-30,BUFFER_HEIGHT*128/(d+1),d );
  }
}
// *******************************************************************
void IngameMenuInput( void )//aqui van lo q hace cada booton en el menu ingame
	{
	static unsigned long pad,pad1,lastpad;
	pad1=pgiGetpad();
		
	if ((pad1&CTRL_START)!=0) {
		//;//	sesupone q corra makemap1
	}
	lastpad=pad;
}
// *******************************************************************
void InGameMenu( void )
	{
	pgcPuts("Pause");
	pgScreenFrame(1,0);
	//pgBitBlt(0, 0, 1694, 272, 1, Pause, 1);// Rather than a screen clear, render half of the screen as a background
	IngameMenuInput();
	pgScreenFrame(1,0);
	}
// *******************************************************************
void input_key( void )
{
	static unsigned long pad,pad1,lastpad;
	pad1=pgiGetpad();
		
	if ((pad1&CTRL_START)!=0) {//MENU
		gl_ss = 0;
		gl_sa = 0;
		InGameMenu;// pause screen
	}
	if ((pad1&CTRL_SELECT)!=0) {//jump now stop
		gl_ss = 0;
	}
	if ((pad1&CTRL_LEFT )!=0) {//left changed the CTRL_CIRCLE to CTRL_LEFT 
		gl_sa += 0.005f;
	}
	if ((pad1&CTRL_RIGHT)!=0) {//right changed the CTRL_SQUARE to CTRL_RIGHT
		gl_sa -= 0.005f;
	}
	if ((pad1&CTRL_TRIANGLE)!=0) {
	    gl_ss = gl_s;//up modified original should have +=
		
	}
	if ((pad1&CTRL_CROSS)!=0) {
		gl_ss -= gl_s;//problem if you remove -  dosnt stop
	}
	lastpad=pad;
}
// *******************************************************************
void Run( void )
	{
	
	pgScreenFrame(1,0);
	MakeMap1(); 
	pgBitBlt(0, 0, 1694, 150, 1, SkyData, 1);// Rather than a screen clear, render half of the screen as a background
		
	}
// *******************************************************************
void MenuInput( void )
	{
	static unsigned long pad,pad1,lastpad;
	pad1=pgiGetpad();
	
	if ((pad1&CTRL_CROSS)!=0) {
		
		pgcPuts("Running");
		Run();//	sesupone q corra makemap1
		
	}
	lastpad=pad;
	
}
// *******************************************************************
	
void glvox_main( void )
{
		View(gl_x0,gl_y0,gl_a);
		//
		// Update position/angle
		//
		gl_x0+=gl_ss*fcos(gl_a);
		gl_y0+=gl_ss*fsin(gl_a);
		gl_a+=gl_sa;
		gl_sa*=0.975f;
}
// *******************************************************************
int xmain( void )
{
   static char flipper = 1;
   
    //
    // Main loop
    //
    //   a     = angle
    //   x0,y0 = current position
    //   s     = speed constant
    //   ss    = current forward/backward speed
    //   sa    = angular speed
    //
    gl_a=0;
   gl_x0=0x0;
   gl_y0=0x0;
    gl_s=4096;
    gl_ss=100.0f;
    gl_sa=0;
    //
    // Compute the height map
	
   // Uncomment this to have a perlin noise generated heightmap
	
   // Copy in a heightmap into the HMap array
   
   
   
   
   while(app_running)
   {
      Video = pgGetVramAddr(0,0);
      pgScreenFrame(2,flipper);
      pgcCls();
		pgcPuts("Menu");
		MenuInput();//this are menu screen controls i have problems here how can i change the input from MenuInput (); to input_key();
		flipper = 1-flipper;
      glvox_main();
      
	  
      pgScreenFlipV();
   }
   pgScreenFrame(1,0);
   pgcCls();
   return 0;
} 
// *******************************************************************