#include "libgccvb.h"
#include "lhfont.h"

#include "vbtestchar.h"
#include "vbtestmap.h"

#include "titlescreenfg2char.h"
#include "titlescreenfg2map.h"
#include "titlescreenbgchar.h"
#include "titlescreenbgmap.h"

#include "logo3d2char.h"
#include "logo3d2map.h"

#include "titlescreen4char.h"
#include "titlescreen4map.h"
#include "fighterschar.h"
#include "fightersmap.h"
#include "magnifyingglass2char.h"
#include "magnifyingglass2map.h"
#include "wallpaper3map.h"
#include "wallpaper3char.h"
#include "cpufightermap.h"
#include "cpufighterchar.h"
#include "charactersmap.h"
#include "characterschar.h"
#include "exterminatemap.h"
#include "exterminatechar.h"
#include "giant5map.h"
#include "giant5mapflipped.h"
#include "giant5char.h"
#include "youchar.h"
#include "youmap.h"
#include "cpuchar.h"
#include "cpumap.h"
//#include "icoof.h"
//#include "icow3.h"
//#include "icmommy.h"
#include "ictitle3.h"
#include "cpu2char.h"
#include "cpu2map.h"
#include "you2char.h"
#include "you2map.h"
#include "creditsmap.h"
#include "creditschar.h"

#include "giantcrawl1map.h"
#include "giantcrawl1char.h"
#include "giantcrawl2map.h"
#include "giantcrawl2char.h"
#include "giantcrawl3map.h"
#include "giantcrawl3char.h"
#include "giantcrawl4map.h"
#include "giantcrawl4char.h"
#include "giantcrawl5map.h"
#include "giantcrawl5char.h"
#include "giantcrawl6map.h"
#include "giantcrawl6char.h"
#include "giantcrawl7map.h"
#include "giantcrawl7char.h"

#include "giantcrawl1map2.h"
#include "giantcrawl2map2.h"
#include "giantcrawl3map2.h"
#include "giantcrawl4map2.h"
#include "giantcrawl5map2.h"
#include "giantcrawl6map2.h"
#include "giantcrawl7map2.h"

#include "wallpaper6map.h"
#include "wallpaper6char.h"

#include "rumblebeebgmap.h"
#include "rumblebeebgchar.h"
#include "rumblebeefgmap.h"
#include "rumblebeefgchar.h"

#include "nothingtempchar.h"
#include "nothingtempmap.h"

#include "blankbgchar.h"
#include "blankbgmap.h"


int animframe=0, animframe2=1, fighterpos1x=0, fighterpos1y=0, fighterpos2x=0, fighterpos2y=0, fighterpos3x=0, fighterpos3y=208;
int cursorx=80, cursory=43, fighterx=60, fightery=122;
int fighter=1, opponent=1, scrolltimer=0, paused=0, currNoteLength=600, l=0, m=0, n=0, o=0;
int opponentx=160, opponenty=64, e=0;
int opponentxplus=0, opponentyminus=0, opponentyplus=0, sound=0, opponentxminus=0, sfxmake=0;
int StartGame=4, MusicOver=0, GoingToMain=0, fight=0;
int CreditsCheat=0, ButtonCredits=0, CreditsScrollingY=12, CreditsScrollingTimer=0, Credits=0;
int scrolltimer2=0, fighterx2=0, logoy=182, logotimer=0;
int flipping=0, w1=22, w2=20, count=1, turning=0, left=0, bgscroll=20;
int ActionSong=0, ActionTick=0, currActNote=0, StopActionNote=2;
int bgbgscrolltimer=0, bgbgscroll=40;


u32 SongTick;
u8 currNote;	

u16 freq;
u8 vol;
u8 chan=0;

//scrolling variables for the old version ("Insect Combat") in case I decide to go back to it.
//int scroll=-192, scrolly=0;
//int scroll2=112, scroll2y=-16;

//int scroll3=-192, scroll3y=224;
//int scroll4=112, scroll4y=208;

int scroll=-192, scrolly=0;
int scroll2=112, scroll2y=-16;
int scroll3=-192, scroll3y=224;
int scroll4=112, scroll4y=208;
int currSong=1;
int TitleScreenSong=0, currlowernote=0;
int jump=0, fall=0, jumptimer=11, falltimer=0, moverand=0, oppdir=0, movetimer=0, movestop=0, movetimer2=0, moverand2=3;

#define SSTOP            *(u8*)0x01000580 //Sound Stop: 0x01 = Stop (all other bits ignored)





//waveform RAM contents
u8 wave1[]={
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F
};






//~1.6 usec delay, count needs to be volatile or the optimizer basically removes this function
void delay1p6us(volatile int count)
{
	asm("
	1:
	add	-1,%0 /*decrement count*/
	cmp	0,%0 /*compare num with 0 to tell when done*/
	bgt	1b /*loop if count remaining is greater than 0*/
	"
	: /* No Output */
	: "r" (count) /* Input */
	/* :  no regs used */
	);
}





void HFlip(char bgmap, char startX, char startY, char width, char height) {
  char y;
  
  \
  for (y=0; y<height; y++, startY++) {
    HWORD* leftCell = &BGMM[bgmap*(0x1000) + (startY * 64) + startX];
    HWORD* rightCell = leftCell + width - 1;

    while (leftCell <= rightCell) {
      HWORD tmpCell = *rightCell;
      *rightCell = *leftCell ^ 0x2000;
      *leftCell = tmpCell ^ 0x2000;
      leftCell++;
      rightCell--;
	  
    }
  }
}





void PlayNote(u8 chan, u16 freq, u8 vol) {   

	SND_REGS[0].SxINT = 0x00;
	SND_REGS[chan].SxINT = 0x80;	
	//SND_REGS[2].SxINT = 0x80;	
	//SND_REGS[3].SxINT = 0x80;	
	
	//Set up the frequency the channel will play 
    SND_REGS[chan].SxFQH = freq >> 8; 
    SND_REGS[chan].SxFQL = freq & 0xFF; 

    //Set the volume for the channel (0-15, same for left/right) 
    SND_REGS[chan].SxLRV = 0x66;

    //Envelope for the channel (makes the tone fade out) 
    SND_REGS[chan].SxEV0 = 0xF7; 
    SND_REGS[chan].SxEV1 = 0x01; 
	}

void wavplay(const u8 *wav_data, int channels, int len, int delaytime)
{
  int i;
  //if (channels == 1) //mono
  //{
    for (i=0; i<len; i++)
    {
      if (!(i&1)) //first half of packed data
        SND_REGS[0].SxLRV=(wav_data[i>>1]&0xF0)|(wav_data[i>>1]>>4);
		
      else //second half of packed data
        SND_REGS[0].SxLRV=((wav_data[i>>1]&0x0F)<<4)|(wav_data[i>>1]&0x0F);
      delay1p6us(delaytime);
    }
 // }
 // else //stereo
 // {
 //   for (i=0; i<len; i++)
  //  {
   //   SND_REGS[0].SxLRV=wav_data[i];
    //  delay1p6us(delaytime);
   // }
  }
  
  

void ChangeCharsegOfBGMap(BYTE bgmap, BYTE chseg) { 
  HWORD j; 
   
  for (j=0; j<4096; j++) { 
    HWORD* currCell = &BGMM[bgmap*(0x1000) + j]; 
    *currCell &= 0xF9FF;
    *currCell |= (chseg << 9);
  } 
}

 
  
  
void init_speech()
{
  int j;
  
  SSTOP = 1; //stop all sounds
  
  for (j=0; j<32; j++) //copy waveform data
    WAVEDATA1[j<<2]=wave1[j];
  
  //turn off channels
  SND_REGS[0].SxINT = 0x00;
  //SND_REGS[1].SxINT = 0x00;
  //SND_REGS[2].SxINT = 0x00;
  //SND_REGS[3].SxINT = 0x00;
  //SND_REGS[4].SxINT = 0x00;
  //SND_REGS[5].SxINT = 0x00;
  
  SSTOP = 0; //allow sounds

  //use Waveform RAM0
  SND_REGS[0].SxRAM = 0x00;
  //SND_REGS[1].SxRAM = 0x00;
  //SND_REGS[2].SxRAM = 0x00;
  //SND_REGS[3].SxRAM = 0x00;
  //SND_REGS[4].SxRAM = 0x00;
  
  //mute all
  SND_REGS[0].SxLRV = 0x00;
  //SND_REGS[1].SxLRV = 0x00;
  //SND_REGS[2].SxLRV = 0x00;
  //SND_REGS[3].SxLRV = 0x00;
  //SND_REGS[4].SxLRV = 0x00;
  //SND_REGS[5].SxLRV = 0x00;
  
  //set initial envelope to max
  SND_REGS[0].SxEV0 = 0xF0;
  //SND_REGS[1].SxEV0 = 0xF0;
  //SND_REGS[2].SxEV0 = 0xF0;
  //SND_REGS[3].SxEV0 = 0xF0;
  //SND_REGS[4].SxEV0 = 0xF0;
  //SND_REGS[5].SxEV0 = 0xF0;
  
  //disable envelope
  SND_REGS[0].SxEV1 = 0x00;
  //SND_REGS[1].SxEV1 = 0x00;
  //SND_REGS[2].SxEV1 = 0x00;
  //SND_REGS[3].SxEV1 = 0x00;
  //SND_REGS[4].SxEV1 = 0x00;
  
  //set low freq (doesn't matter since waveform is DC)
  SND_REGS[0].SxFQL = 0x00;
  //SND_REGS[1].SxFQL = 0x00;
  //SND_REGS[2].SxFQL = 0x00;
  //SND_REGS[3].SxFQL = 0x00;
  //SND_REGS[4].SxFQL = 0x00;
  SND_REGS[0].SxFQH = 0x00;
  //SND_REGS[1].SxFQH = 0x00;
  //SND_REGS[2].SxFQH = 0x00;
  //SND_REGS[3].SxFQH = 0x00;
  //SND_REGS[4].SxFQH = 0x00;
  
  SND_REGS[0].SxINT = 0x80; //enable channel 0
}

//plays wav data passed in with parameters

//divide this number by sample rate for delay
//feel free free to tweak to get sound just right
//or just hardcode the delay once you get it
#define SR_DIV 3330000




	u16 song13[] = {F_2, AS2, F_2, DS2};
	
	const u16 song[] = {F_3, C_4, F_3, B_3, B_3, C_4, 
		C_4, F_3, AS3, F_4, AS3, E_4, E_4, F_4, F_4, 
		AS3, F_3, C_4, F_3, B_3, B_3, AS3, GS3, G_3}; 


	const u16 fightsong[]={C_3, D_3, DS3, F_3, G_3, F_3, DS3, D_3,
		C_3, D_3, DS3, F_3, G_3, F_3, DS3, D_3,
		C_3, D_3, DS3, F_3, G_3, F_3, G_3, A_3, AS3, A_3, G_3, F_3, G_3,
		A_3, AS3, A_3, G_3, A_3, AS3, C_4, AS3, A_3, G_3, A_3,
		AS3, C_4, D_4, C_4, AS3, G_3, FS3, G_3, FS3, G_3, FS3, F_3, DS3, D_3,
		C_3, D_3, C_3, AS2, C_3};
			
	
	u16 song7[] = {G_3, G_3, G_3}; 
	u16 song8[] = {B_3, B_3, B_3}; 
	u16 song9[] = {A_3, A_3, A_3};
	u16 song10[] = {C_4, C_4, C_4};
	u16 song11[] = {G_4, G_4, FS4};
	u16 song12[] = {E_4, E_4, FS4};




int main()

	{

	
    vbTextOut(0, 31, 1,"                ");
    vbTextOut(0, 1, 1,"                ");	
	
    vbTextOut(0, 31, 2,"                ");
    vbTextOut(0, 1, 2,"                ");	
	
	vbTextOut(3, 1, 26,"                              ");

	copymem ((void*)CharSeg3, (void*)LHFONT, 8192);
	
	currNote=-1, SongTick=660, currNoteLength=660, left=0;
	
	vbSetWorld(31, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);		
	vbSetWorld(27, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(28, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(29, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);		
	vbSetWorld(30, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(22, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(26, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(25, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);		
	vbSetWorld(24, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(23, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(21, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 0, 0);		
	vbSetWorld(29, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(30, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 0, 0);	
	
	// while (vbReadPad()==0) { 
	// randomPointer++; 
	// } 
	// randomPointer %= 4; 

	vbDisplayOn();
	vbDisplayShow();

    if (StartGame>2) vbTextOut(0, 20, 11,"IMPORTANT:");
    if (StartGame>2) vbTextOut(0, 14, 12,"SCREW THE INSTRUCTION");
    if (StartGame>2) vbTextOut(0, 13, 13,"AND PRECAUTION BOOKLETS");
    if (StartGame>2) vbTextOut(0, 15, 14,"JUST PLAY THE GAME.");

	while(StartGame>3){
	

	if((vbReadPad()&K_STA) && (StartGame==4)) StartGame=5;
	if((!(vbReadPad()&K_STA)) && (StartGame==5)) StartGame=3;
	
	}
	
	
	copymem((void*)CharSeg1, (void*)VBTESTCHAR, 256*16);
	copymem((void*)BGMap(1), (void*)VBTESTMAP, 512*16);
	
	while(StartGame>2){


    if (StartGame>2) vbSetWorld(31, WRLD_LON|1, 0, 0, 0, 0, 0, 0, 384, 224);
    if (StartGame>2) vbSetWorld(30, WRLD_RON|1, 0, 0, 0, 0, 0, 224, 384, 224);

	if((vbReadPad()&K_STA) && (StartGame==3)) StartGame=4;
	if((!(vbReadPad()&K_STA)) && (StartGame==4)) StartGame=2;
	
	}
	
	
	
	while(StartGame>2){
	
	if((vbReadPad()&K_A) && (CreditsCheat==0) && (ButtonCredits==0)) ButtonCredits=1;
	if((!(vbReadPad()&K_A) && (CreditsCheat==0) && (ButtonCredits==1))) ButtonCredits=0, CreditsCheat=1;
	
	if((vbReadPad()&K_B) && (CreditsCheat==1) && (ButtonCredits==0)) ButtonCredits=1;
	if((!(vbReadPad()&K_B) && (CreditsCheat==1) && (ButtonCredits==1))) ButtonCredits=0, CreditsCheat=2;
	
	if((vbReadPad()&K_B) && (CreditsCheat==2) && (ButtonCredits==0)) ButtonCredits=1;
	if((!(vbReadPad()&K_B) && (CreditsCheat==2) && (ButtonCredits==1))) ButtonCredits=0, CreditsCheat=3;

	if((vbReadPad()&K_A) && (CreditsCheat==3) && (ButtonCredits==0)) ButtonCredits=1;
	if((!(vbReadPad()&K_A) && (CreditsCheat==3) && (ButtonCredits==1))) ButtonCredits=0, CreditsCheat=4;	
	
	if((vbReadPad()&K_STA) && (StartGame==3)) StartGame=4;
	if((!(vbReadPad()&K_STA)) && (StartGame==4)) StartGame=2;

	}
	
	if (CreditsCheat>3) currNote=-1;
	
	while(CreditsCheat>3){
	
	SongTick++;
	copymem((void*)WAVEDATA1, (void*)VIOLIN, 128); 
	
	if (SongTick>currNoteLength) 
	{
	currNote++;
	if (currNote>2) currSong++, currNote=0;
	if (currSong>4) currSong=1;
	if (currNote==0) currNoteLength=15;
	if (currNote==1) currNoteLength=15;
	if (currNote==2) currNoteLength=30;
	SongTick=1;
	
	if (currSong<3) PlayNote(1, song7[currNote], 8); 
	if (currSong>2) PlayNote(1, song9[currNote], 8);
	
	if (currSong<3) PlayNote(2, song8[currNote], 8); 
	if (currSong>2) PlayNote(2, song10[currNote], 8);	
	
	PlayNote(3, song11[currNote], 8); 		
	}
	
	copymem((void*)CharSeg1, (void*)CREDITSCHAR, 256*16);
	copymem((void*)BGMap(1), (void*)CREDITSMAP, 256*16);	
	
    CreditsScrollingY=CreditsScrollingY-1;
	if (CreditsScrollingY==-224) Credits=Credits+1, CreditsScrollingY=12;

	vbSetWorld(31, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(29, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 384, 224);
	vbSetWorld(30, WRLD_ON|3, 0, -2, CreditsScrollingY, 0, 0, 0, 384, 224);	

	
	if (Credits==0) vbTextOut(3, 1, 26,"PROGRAMMED BY CHRIS READ");
	if (Credits==1) vbTextOut(3, 1, 26,"SPRITE ART BY MORINTARI "); 
	if (Credits==2) vbTextOut(3, 1, 26,"MUSIC COMPOSED BY DAVE BRUBECK AND CHRIS READ");
	if (Credits==3) vbTextOut(3, 1, 26,"GAME DESIGN BY CHRIS READ AND MORINTARI      ");
	if (Credits==4) vbTextOut(3, 1, 26,"SPECIAL THANKS TO PVB FORUMS                 ");
	if (Credits==5) CreditsCheat=0, currSong=1, currNote=0, copymem((void*)WAVEDATA1, (void*)SAWTOOTH, 128); 	
	}
	
	{
	copymem((void*)WAVEDATA1, (void*)SAWTOOTH, 128); 	
	fight=0;
	
	copymem((void*)CharSeg0, (void*)TITLESCREENFG2CHAR, 512*16);
	copymem((void*)BGMap(0), (void*)TITLESCREENFG2MAP, 512*16);		
	
	copymem((void*)CharSeg1, (void*)LOGO3D2CHAR, 512*16);
	copymem((void*)BGMap(1), (void*)LOGO3D2MAP, 512*16);	
	
	//copymem((void*)CharSeg1, (void*)TITLESCREENBGCHAR, 256*16);
	//copymem((void*)BGMap(1), (void*)TITLESCREENBGMAP, 256*16);	
	


	vbSetWorld(27, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(28, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(29, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);		
	vbSetWorld(30, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(22, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(26, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(25, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);		
	vbSetWorld(24, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(23, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(21, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 0, 0);		
	vbSetWorld(29, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(30, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 0, 0);	
	vbSetWorld(20, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 0, 0);	
	fighterx=60, fightery=62;
	StartGame=0;
	
	while(StartGame<2){
	
    //SND_REGS[2].SxINT = 0x00;
    //SND_REGS[3].SxINT = 0x00;

   // SND_REGS[0].SxLRV = 0x66;
 
 
	if (SongTick>currNoteLength) {

	if (currNote>23) currNote=0;

	PlayNote(2, song[currNote], 8);
	currNote++;
	if (currNote & 1)
	currNoteLength = 400;
	else
	currNoteLength = 601;
	
	if (currNote==0) currNoteLength=440;
	
	if (currNote<9) PlayNote(1, song13[0], 8);
	if ((currNote>8) && (currNote<17)) PlayNote(1, song13[1], 8);
	if (currNote>16) PlayNote(1, song13[2], 8);

	SongTick=0;
	}
	
	vbSetWorld(29, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);
	vbSetWorld(30, WRLD_RON|1, 20, 2, logoy, 0, 0, 0, 384, 224);	
	vbSetWorld(31, WRLD_LON|1, 12, 2, logoy, 0, 0, 0, 384, 224);

	if (logoy>100) logotimer++;
	if (logotimer>19) logotimer=0, logoy--;
	if (logoy==100) SongTick++;

	if((vbReadPad()&K_STA) && (StartGame==0)) StartGame=1;
	if((!(vbReadPad()&K_STA)) && (StartGame==1)) currNote--, SongTick=SongTick/6, currNoteLength=currNoteLength/6, StartGame=2;	


	
	}

	VIP_REGS[GPLT2]=0x08;
	VIP_REGS[GPLT1]=0x24;

	copymem((void*)CharSeg2, (void*)WALLPAPER6CHAR, 512*16);
	copymem((void*)BGMap(2), (void*)WALLPAPER6MAP, 512*16);

	copymem((void*)CharSeg0, (void*)FIGHTERSCHAR, 512*16);
	copymem((void*)BGMap(0), (void*)FIGHTERSMAP, 512*16);

  	copymem((void*)CharSeg1, (void*)MAGNIFYINGGLASS2CHAR, 256*16);
	copymem((void*)BGMap(1), (void*)MAGNIFYINGGLASS2MAP, 256*16);		
	
	StartGame=0;

	while(StartGame<2){
	
    //SND_REGS[2].SxINT = 0x00;
    //SND_REGS[3].SxINT = 0x00;
	
	scrolltimer=scrolltimer+1;

	vbSetWorld(27, WRLD_ON, -2, 0, -2, 0, 0, 0, 384, 224);
	vbSetWorld(26, WRLD_ON|1, cursorx, 0, cursory, 0, 0, 0, 384, 224);
	vbSetWorld(28, WRLD_ON|2, scroll3, -3, scroll3y, 0, 0, 0, 384, 224);
	vbSetWorld(29, WRLD_ON|2, scroll4, -3, scroll4y, 0, 0, 0, 384, 224);		
	vbSetWorld(30, WRLD_ON|2, scroll2, -3, scroll2y, 0, 0, 0, 384, 224);
	vbSetWorld(31, WRLD_ON|2, scroll, -3, scrolly, 0, 0, 0, 384, 224);	

	vbTextOut(0, 15, 2," SELECT FIGHTER ");

	SongTick++;	

	if (fighter<5) cursory=1; else cursory=66;
	if (fighter==-1) fighter=8;
	if ((fighter<1) && (fighter>-1)) fighter=8; 
	if (fighter==-2) fighter=5;
	if (fighter==9) fighter=1;
	if (fighter==10) fighter=2;
	if (fighter==11) fighter=3;
	if (fighter==1) cursorx=41, vbTextOut(0, 15, 25,"      GI ANT    ");	
	if (fighter==2) cursorx=125, vbTextOut(0, 15, 25,"    BEHE MOTH   ");
	if (fighter==3) cursorx=200, vbTextOut(0, 15, 25,"    RUMBLEBEE   ");
	if (fighter==4) cursorx=267, vbTextOut(0, 15, 25,"     SUPERFLY   ");
	
    if (fighter==5) cursorx=41,  vbTextOut(0, 15, 25,"   MELEE-DYBUG  ");
	if (fighter==6) cursorx=125, vbTextOut(0, 15, 25,"    KILLIPEDE   ");
	if (fighter==7) cursorx=200, vbTextOut(0, 15, 25,"     SUPERFLY   ");
	if (fighter==8) cursorx=267, vbTextOut(0, 15, 25,"PANZER DRAGONFLY");
	//old x positions, 89, 137, 185, 233
	//old y pos - 1, 47
  
	if(vbReadPad()&K_LR)  l=l+1;
    if (l>30) fighter=fighter+1, l=0;
	
	if(vbReadPad()&K_LL)  m=m+1;
    if (m>30) fighter=fighter-1, m=0;	
	
	if(vbReadPad()&K_LU)  n=n+1;
    if (n>30) fighter=fighter-4, n=0;
	
	if(vbReadPad()&K_LD)  o=o+1;
    if (o>30) fighter=fighter+4, o=0;		

	if (scrolltimer>20) scroll=scroll+1, scroll2=scroll2+1, scroll3=scroll3+1, scroll4=scroll4+1;
	if (scrolltimer>20) scrolly=scrolly-1, scroll2y=scroll2y-1, scroll3y=scroll3y-1, scroll4y=scroll4y-1, scrolltimer=0;
	if (scroll>-41) scroll=-192, scrolly=0, scroll2=112, scroll2y=-16, scroll3=-192, scroll3y=224, scroll4=112, scroll4y=208;		
	
	if((vbReadPad()&K_STA) && (StartGame==0)) StartGame=1;
	if((!(vbReadPad()&K_STA)) && (StartGame==1)) StartGame=2;
	
	if (SongTick>currNoteLength) {
	currNote++;
	if (currNote>23) currNote=0;

	if (currNote & 1)
	currNoteLength = 167;
	else
	currNoteLength = 100;
	
	if (currNote==0) currNoteLength=167;
	
	PlayNote(2, song[currNote], 8);

	if (currNote<8) PlayNote(1, song13[0], 8);
	if ((currNote>7) && (currNote<16)) PlayNote(1, song13[1], 8);
	if (currNote>15) PlayNote(1, song13[2], 8);

	SongTick=0;
	}
	
	}
	//copymem ((void*)CharSeg3, (void*)LHFONT, 8192);	
	
	vbTextOut(0, 15, 2," SELECT OPPONENT");	
	
	//copymem((void*)CharSeg0, (void*)CPU2CHAR, 512*16);
	//copymem((void*)BGMap(0), (void*)CPU2MAP, 512*16);	
	
	copymem((void*)CharSeg2, (void*)WALLPAPER6CHAR, 256*16);
	copymem((void*)BGMap(2), (void*)WALLPAPER6MAP, 256*16);
	
  	copymem((void*)CharSeg1, (void*)MAGNIFYINGGLASS2CHAR, 256*16);
	copymem((void*)BGMap(1), (void*)MAGNIFYINGGLASS2MAP, 256*16);	

{
	vbSetWorld(27, WRLD_ON, -2, 0, -2, 0, 0, 0, 384, 224);
	vbSetWorld(28, WRLD_ON|2, scroll3, -3, scroll3y, 0, 0, 0, 384, 224);
	vbSetWorld(29, WRLD_ON|2, scroll4, -3, scroll4y, 0, 0, 0, 384, 224);		
	vbSetWorld(30, WRLD_ON|2, scroll2, -3, scroll2y, 0, 0, 0, 384, 224);
	vbSetWorld(31, WRLD_ON|2, scroll, -3, scrolly, 0, 0, 0, 384, 224);	

	StartGame=0;
	}

	while(StartGame<2)
	{
	if(vbReadPad()&K_STA) StartGame=1;
	if((!(vbReadPad()&K_STA)) && (StartGame==1)) StartGame=2;
	
	vbSetWorld(27, WRLD_ON, -2, 0, -2, 0, 0, 0, 384, 224);
	vbSetWorld(26, WRLD_ON|1, cursorx, 0, cursory, 0, 0, 0, 384, 224);
	vbSetWorld(28, WRLD_ON|2, scroll3, -3, scroll3y, 0, 0, 0, 384, 224);
	vbSetWorld(29, WRLD_ON|2, scroll4, -3, scroll4y, 0, 0, 0, 384, 224);		
	vbSetWorld(30, WRLD_ON|2, scroll2, -3, scroll2y, 0, 0, 0, 384, 224);
	vbSetWorld(31, WRLD_ON|2, scroll, -3, scrolly, 0, 0, 0, 384, 224);	
	
	scrolltimer=scrolltimer+1;

	SongTick++;
 
	if(vbReadPad()&K_LR)  l=l+1;
    if (l>30) opponent=opponent+1, l=0;
	
	if(vbReadPad()&K_LL)  m=m+1;
    if (m>30) opponent=opponent-1, m=0;	
	
	if(vbReadPad()&K_LU)  n=n+1;
    if (n>30) opponent=opponent-4, n=0;
	
	if(vbReadPad()&K_LD)  o=o+1;
    if (o>30) opponent=opponent+4, o=0;	



	if (opponent<5) cursory=1; else cursory=66;
	if (opponent==-1) opponent=8;
	if ((opponent<1) && (opponent>-1)) opponent=8; 
	if (opponent==-2) opponent=5;
	if (opponent==9) opponent=1;
	if (opponent==10) opponent=2;
	if (opponent==11) opponent=3;
	
    //if (opponent==fighter) opponent=opponent+1;	
	
	if (opponent==1) cursorx=41, vbTextOut(0, 15, 25,"      GI ANT    ");	
	if (opponent==2) cursorx=125, vbTextOut(0, 15, 25,"    BEHE MOTH   ");
	if (opponent==3) cursorx=200, vbTextOut(0, 15, 25,"    RUMBLEBEE   ");
	if (opponent==4) cursorx=267, vbTextOut(0, 15, 25,"     SUPERFLY   ");
	
    if (opponent==5) cursorx=41,  vbTextOut(0, 15, 25,"   MELEE-DYBUG  ");
	if (opponent==6) cursorx=125, vbTextOut(0, 15, 25,"    KILLIPEDE   ");
	if (opponent==7) cursorx=200, vbTextOut(0, 15, 25,"     SUPERFLY   ");
	if (opponent==8) cursorx=267, vbTextOut(0, 15, 25,"PANZER DRAGONFLY");
	
	if (scrolltimer>20) scroll=scroll+1, scroll2=scroll2+1, scroll3=scroll3+1, scroll4=scroll4+1;
	if (scrolltimer>20) scrolly=scrolly-1, scroll2y=scroll2y-1, scroll3y=scroll3y-1, scroll4y=scroll4y-1, scrolltimer=0;
	if (scroll>-41) scroll=-192, scrolly=0, scroll2=112, scroll2y=-16, scroll3=-192, scroll3y=224, scroll4=112, scroll4y=208;		
	
	if (SongTick>currNoteLength) {

	if (currNote>23) currNote=0;
	currNote++;
	if (currNote & 1)
	currNoteLength = 167;
	else
	currNoteLength = 100;
	
	if (currNote==0) currNoteLength=167;
	
	PlayNote(2, song[currNote], 8);

	if (currNote<8) PlayNote(1, song13[0], 8);
	if ((currNote>7) && (currNote<16)) PlayNote(1, song13[1], 8);
	if (currNote>15) PlayNote(1, song13[2], 8);

	SongTick=0;
	}
	}
	
	{

	vbSetWorld(27, WRLD_ON, -2, 0, -2, 0, 0, 0, 384, 224);
	vbSetWorld(28, WRLD_ON|2, scroll3, -3, scroll3y, 0, 0, 0, 384, 224);
	vbSetWorld(29, WRLD_ON|2, scroll4, -3, scroll4y, 0, 0, 0, 384, 224);		
	vbSetWorld(30, WRLD_ON|2, scroll2, -3, scroll2y, 0, 0, 0, 384, 224);
	vbSetWorld(31, WRLD_ON|2, scroll, -3, scrolly, 0, 0, 0, 384, 224);	
	
	if (scrolltimer>20) scroll=scroll+1, scroll2=scroll2+1, scroll3=scroll3+1, scroll4=scroll4+1;
	if (scrolltimer>20) scrolly=scrolly-1, scroll2y=scroll2y-1, scroll3y=scroll3y-1, scroll4y=scroll4y-1, scrolltimer=0;
	if (scroll>-41) scroll=-192, scrolly=0, scroll2=112, scroll2y=-16, scroll3=-192, scroll3y=224, scroll4=112, scroll4y=208;
	
	TitleScreenSong++;
	
	if (TitleScreenSong>4) TitleScreenSong=0, scrolltimer=scrolltimer+1, SongTick++;
	SongTick++;	
	
	if (SongTick>currNoteLength) {

	if (currNote>23) currNote=0;
	currNote++;
	if (currNote & 1)
	currNoteLength = 167;
	else
	currNoteLength = 100;
	
	if (currNote==0) currNoteLength=167;
	
	PlayNote(2, song[currNote], 8);

	if (currNote<8) PlayNote(1, song13[0], 8);
	if ((currNote>7) && (currNote<16)) PlayNote(1, song13[1], 8);
	if (currNote>15) PlayNote(1, song13[2], 8);

	SongTick=0;
	}
	}

	vbFXFadeOut(1);
		

		VIP_REGS[GPLT0]=0x38;
		VIP_REGS[GPLT1]=0x84; //ant1
		VIP_REGS[GPLT2]=0xE4; // foreground	
		VIP_REGS[GPLT3]=0xE8; // background
		
	vbSetWorld(26, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0); // make cursor go off
	vbSetWorld(27, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(31, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(30, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(29, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(28, WRLD_ON|2, 0, 0, 0, 0, 0, 0, 0, 0);
	vbSetWorld(25, WRLD_ON, 0, 0, 0, 0, 0, 0, 0, 0);		
	
	//init_speech(); //initialize sound regs for speech

	copymem((void*)CharSeg3, (void*)RUMBLEBEEBGCHAR, 512*16);
	copymem((void*)BGMap(3), (void*)RUMBLEBEEBGMAP, 512*16);


	if (fighter==1) vbTextOut(3, 1, 0,"GI ANT               ");
	if (fighter==2) vbTextOut(3, 1, 0,"BEHE MOTH            ");
	if (fighter==3) vbTextOut(3, 1, 0,"RUMBLEBEE            ");
	if (fighter==4) vbTextOut(3, 1, 0,"SLAYING MANTIS       ");
	if (fighter==5) vbTextOut(3, 1, 0,"MELEE-DYBUG          ");
	if (fighter==6) vbTextOut(3, 1, 0,"KILLIPEDE            ");
	if (fighter==7) vbTextOut(3, 1, 0,"SUPERFLY             ");	
	if (fighter==8) vbTextOut(3, 1, 0,"PANZER DRAGONFLY     ");
	
	if (opponent==1) vbTextOut(3, 26, 0,"               GI ANT  ");
	if (opponent==2) vbTextOut(3, 26, 0,"            BEHE MOTH  ");
	if (opponent==3) vbTextOut(3, 26, 0,"            RUMBLEBEE  ");
	if (opponent==4) vbTextOut(3, 26, 0,"       SLAYING MANTIS  ");
	if (opponent==5) vbTextOut(3, 26, 0,"          MELEE-DYBUG  ");
	if (opponent==6) vbTextOut(3, 26, 0,"            KILLIPEDE  ");
	if (opponent==7) vbTextOut(3, 26, 0,"             SUPERFLY  ");
	if (opponent==8) vbTextOut(3, 26, 0,"     PANZER DRAGONFLY  ");
	
	vbTextOut(3, 0, 1," QQQQQQQQQQQQQQQQ");
	vbTextOut(3, 31, 1,"QQQQQQQQQQQQQQQQ");	
	
	//vbSetWorld(20, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);	

	

	
	//copymem((void*)CharSeg0, (void*)BLANKBGCHAR, 512*16);
	//copymem((void*)BGMap(0), (void*)BLANKBGMAP, 512*16);	

	
	copymem((void*)CharSeg0, (void*)RUMBLEBEEFGCHAR, 512*16);
	copymem((void*)BGMap(0), (void*)RUMBLEBEEFGMAP, 512*16);
	
	copymem((void*)CharSeg2, (void*)GIANTCRAWL1CHAR, 512*16);
	copymem((void*)BGMap(2), (void*)GIANTCRAWL1MAP, 512*16);			
	
	copymem((void*)CharSeg1, (void*)GIANTCRAWL1CHAR, 512*16);
	copymem((void*)BGMap(1), (void*)GIANTCRAWL1MAP, 512*16);

	
		
	//ChangeCharsetOfBGMap(1, 1);
	
	//DID YOU REMEMBER TO PRESS THE OK BUTTON WHEN MAKING A GPLT>0??????
	
	//FIGHTER=BGMap2
	//OPPONENT=BGMap1
	
	//levels
	//31 - background left eye scrolling
	//30 - background right eye scrolling
	//29 - 
	//28 - foreground scrolling
	//27 - foreground scrolling continuted
	//26 - opponent part 1
	//25 - opponent part 2
	//24 - opponent part 3
	//23 - fighter part 1
	//22 - fighter part 2
	//21 - fighter part 3
	
	
	currNote=59, SongTick=21, bgscroll=20, opponentx=160, opponenty=64; 
	vbSetWorld(20, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 384, 12);
	vbSetWorld(31, WRLD_LON|3, bgbgscroll, -3, -16, 0, 0, 0, 384, 200);
	vbSetWorld(30, WRLD_RON|3, bgbgscroll+8, -3, -16, 0, 0, 0, 384, 200);	
	
	
	//vbSetWorld(28, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);
	vbSetWorld(28, WRLD_ON, bgscroll-20, 2, 0, 0, 0, 0, 384, 224);
	vbSetWorld(27, WRLD_ON, bgscroll+364, 2, 0, 0, 0, 224, 384, 224);	
	
	vbSetWorld(w1, WRLD_ON|2, fighterx, 1, fightery, 0, 0, 0, 160, 148);	// front
	vbSetWorld(w2, WRLD_ON|2, fighterx, -1, fightery, 160, 0, 0, 160, 148);	// back
	vbSetWorld(23, WRLD_ON|2, fighterx, 0, fightery, 320, 0, 0, 160, 148);	     // body
	
	vbSetWorld(26, WRLD_ON|1, opponentx, 1, opponenty, 0, 0, 0, 160, 148);	// front
	vbSetWorld(25, WRLD_ON|1, opponentx, -1, opponenty, 160, 0, 0, 160, 148);	// back
	vbSetWorld(24, WRLD_ON|1, opponentx, 0, opponenty, 320, 0, 0, 160, 148);	     // body
	//ChangeCharsegOfBGMap(1, 1);

	//fighter=ant then CharSeg(2)
	//opponent=ant then CharSeg(1) - isn't implemented yet.
	
	//fighter=ant then GPLT1






	
	vbFXFadeIn(1);
	
	logoy=182;
	currNoteLength=2;
	turning=0;
	fight=1;
	paused=0;
	

	while(1){

	if ((vbReadPad()&K_SEL) && (paused==1)) SSTOP=1, main();
	if (paused>0) animframe2=1, vbTextOut(3, 22, 0,"PAUSED");	
	if ((paused>0) && (left>0)) HFlip(2, 0, 0, 60, 52); 	
	
	if ((vbReadPad()&K_STA) && (paused==1)) paused=2;
	if ((!(vbReadPad()&K_STA)) && (paused==2) && (left>0)) HFlip(2, 0, 0, 60, 52); 
	if ((!(vbReadPad()&K_STA)) && (paused==2)) paused=0;

	if (paused<1){
	e=e+1;	

	//if(!(vbReadPad()&K_LL) && (left==1)) left=0;


	//VIP_REGS[XPCTRL] = VIP_REGS[XPSTTS] | XPEN; // sets the XPEN bit to make sure Etch-A-Sketch board shows up
	//while (!(VIP_REGS[XPSTTS] & XPBSY1)); // makes sure to freeze screen on framebuffer 0
	//VIP_REGS[XPCTRL] = VIP_REGS[XPSTTS] & ~XPEN; // turn off screen refreshing so once a dot is drawn it stays there until refreshed again (start pressed)
		
	opponentyminus=opponenty-10;
	opponentyplus=opponenty+25;
	opponentxminus=opponentx-40;
	opponentxplus=opponentx+40;
	
 

	if ((vbReadPad()&K_LR) && (fighterx<221)) left=0, animframe2++, fighterx=fighterx+2;	
	if ((fighterx>220) && (vbReadPad()&K_LR) && (bgscroll>-364)) opponentx=opponentx-2, animframe2++, bgbgscrolltimer++, left=0, bgscroll=bgscroll-2, fighterx=221;


	if ((vbReadPad()&K_LL) && (fighterx>29)) left=1, animframe2++, fighterx=fighterx-2;	
	if ((fighterx<30) && (vbReadPad()&K_LL) && (bgscroll<20)) opponentx=opponentx+2, bgbgscrolltimer++, animframe2++, left=1, bgscroll=bgscroll+2, fighterx=29;

	if ((vbReadPad()&K_LR) && (bgbgscrolltimer>1)) bgbgscrolltimer=0, bgbgscroll--;
	if ((vbReadPad()&K_LL) && (bgbgscrolltimer>1)) bgbgscrolltimer=0, bgbgscroll++;
	



	if((vbReadPad()&K_LD) && (fightery<124)) fightery=fightery+1; 
	
	if((vbReadPad()&K_LU) && (fightery>46)) fightery=fightery-1;

	if((vbReadPad()&K_A) && (jumptimer==11)) jump=1;
	if((!(vbReadPad()&K_A)) && (jump==1)) jump=2, falltimer=jumptimer, fall=1;	

	if ((jumptimer>0) && (jump==1)) jumptimer=jumptimer-1, fightery=fightery-6;
	if ((jumptimer==0) && (fall==0)) falltimer=jumptimer, jump=0, fall=1;
	
	if (fall==1) falltimer=falltimer+1, fightery=fightery+6;
	if ((fall==1) && (falltimer>10)) fall=0, falltimer=11, jumptimer=11;
	if ((fall==1) && (fightery>124)) fall=0, falltimer=11, jumptimer=11;
	
	
	if (fightery>124) fall=0, jumptimer=11;	
	

	

	
	//octoy, xbeginning, ?, ybeginning, totalx, totaly
	
	if (vbReadPad()&K_STA) paused=-1;
	if ((!(vbReadPad()&K_STA)) && (paused==-1)) paused=1;

	//cloudtimer++;
	//if (cloudtimer>6) cloudtimer=0, cloudx++, cloudx2++, cloudx3++;
	//if (cloudx3>0) cloudx3=-192;
	//if (cloudx>192) cloudx=0;
	//if (cloudx2>384) cloudx2=192;

	if (paused<1) vbTextOut(3, 22, 0,"      "); 
	
	



	
	if (left>0) HFlip(2, 0, 0, 60, 52); 
	if (left>0) w1=21, w2=23;	
	if (left==0) w1=23, w2=21;	
	
	copymem((void*)WAVEDATA2, (void*)PIANO, 128);

	SongTick++;	
	
	if (SongTick>currNoteLength) {


	currNote++;
	if (currNote>58) currNote=0;
	
	currNoteLength=1;
	if (currNote==28) currNoteLength=5;
	if (currNote==58) currNoteLength=7;
	


	PlayNote(1, fightsong[currNote], 8);

	SongTick=0;
	}
	}

			VIP_REGS[XPCTRL] = VIP_REGS[XPSTTS] | XPEN; // sets the XPEN bit to refresh the screen
			while (!(VIP_REGS[XPSTTS] & XPBSY1)); // makes sure to freeze screen on framebuffer 0
			VIP_REGS[XPCTRL] = VIP_REGS[XPSTTS] & ~XPEN; // turn screen refreshing off again
	

	

	
	vbSetWorld(w1, WRLD_ON|2, fighterx, 1, fightery, 0, 0, 0, 160, 148);	// front
	vbSetWorld(w2, WRLD_ON|2, fighterx, -1, fightery, 160, 0, 0, 160, 148);	// back
	vbSetWorld(22, WRLD_ON|2, fighterx, 0, fightery, 320, 0, 0, 160, 148);	     // body	
	
	

	vbSetWorld(26, WRLD_ON|1, opponentx, 1, opponenty, 0, 0, 0, 160, 148);	// front
	vbSetWorld(25, WRLD_ON|1, opponentx, -1, opponenty, 160, 0, 0, 160, 148);	// back
	vbSetWorld(24, WRLD_ON|1, opponentx, 0, opponenty, 320, 0, 0, 160, 148);	     // body	
	
	
	// ant :
	// fighterpos1 = front legs
	// fighterpos2 = back legs
	// fighterpos3 = body
	
	
	vbSetWorld(20, WRLD_ON|3, 0, 0, 0, 0, 0, 0, 384, 12);
	vbSetWorld(31, WRLD_LON|3, bgbgscroll, -3, -16, 0, 0, 0, 384, 200);
	vbSetWorld(30, WRLD_RON|3, bgbgscroll+8, -3, -16, 0, 0, 0, 384, 200);	


	//vbSetWorld(28, WRLD_ON, 0, 0, 0, 0, 0, 0, 384, 224);
	vbSetWorld(29, WRLD_ON, bgscroll-20, 2, 0, 0, 0, 0, 384, 224);
	vbSetWorld(28, WRLD_ON, bgscroll+364, 2, 0, 0, 0, 224, 384, 224);	
	vbSetWorld(27, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 0, 0); 



	if((!(vbReadPad()&K_LL)) && (!(vbReadPad()&K_LR))) animframe2=1;
	if (animframe2==8) animframe2=1;


	

	if (fighter==1)
	{

	if (animframe2==1) copymem((void*)CharSeg2, (void*)GIANTCRAWL1CHAR, 512*16);
	if (animframe2==1) copymem((void*)BGMap(2), (void*)GIANTCRAWL1MAP, 512*16);		
	
	if (animframe2==2) copymem((void*)CharSeg2, (void*)GIANTCRAWL2CHAR, 512*16);
	if (animframe2==2) copymem((void*)BGMap(2), (void*)GIANTCRAWL2MAP, 512*16);	
	
	if (animframe2==3) copymem((void*)CharSeg2, (void*)GIANTCRAWL3CHAR, 512*16);
	if (animframe2==3) copymem((void*)BGMap(2), (void*)GIANTCRAWL3MAP, 512*16);	
		
	if (animframe2==4) copymem((void*)CharSeg2, (void*)GIANTCRAWL4CHAR, 256*16);
	if (animframe2==4) copymem((void*)BGMap(2), (void*)GIANTCRAWL4MAP, 256*16);		
	
	if (animframe2==5) copymem((void*)CharSeg2, (void*)GIANTCRAWL5CHAR, 512*16);
	if (animframe2==5) copymem((void*)BGMap(2), (void*)GIANTCRAWL5MAP, 512*16);	
	
	if (animframe2==6) copymem((void*)CharSeg2, (void*)GIANTCRAWL6CHAR, 512*16);
	if (animframe2==6) copymem((void*)BGMap(2), (void*)GIANTCRAWL6MAP, 512*16);	
		
	if (animframe2==7) copymem((void*)CharSeg2, (void*)GIANTCRAWL7CHAR, 256*16);
	if (animframe2==7) copymem((void*)BGMap(2), (void*)GIANTCRAWL7MAP, 256*16);			
	

 	//octoy, xbeginning, ?, ybeginning, totalx, totaly
	}
 

	if (opponent==1)
	{

	if (animframe==1) copymem((void*)CharSeg2, (void*)GIANTCRAWL1CHAR, 512*16);
	if (animframe==1) copymem((void*)BGMap(2), (void*)GIANTCRAWL1MAP, 512*16);		
	
	if (animframe==2) copymem((void*)CharSeg2, (void*)GIANTCRAWL2CHAR, 512*16);
	if (animframe==2) copymem((void*)BGMap(2), (void*)GIANTCRAWL2MAP, 512*16);	
	
	if (animframe==3) copymem((void*)CharSeg2, (void*)GIANTCRAWL3CHAR, 512*16);
	if (animframe==3) copymem((void*)BGMap(2), (void*)GIANTCRAWL3MAP, 512*16);	
		
	if (animframe==4) copymem((void*)CharSeg2, (void*)GIANTCRAWL4CHAR, 256*16);
	if (animframe==4) copymem((void*)BGMap(2), (void*)GIANTCRAWL4MAP, 256*16);		
	
	if (animframe==5) copymem((void*)CharSeg2, (void*)GIANTCRAWL5CHAR, 512*16);
	if (animframe==5) copymem((void*)BGMap(2), (void*)GIANTCRAWL5MAP, 512*16);	
	
	if (animframe==6) copymem((void*)CharSeg2, (void*)GIANTCRAWL6CHAR, 512*16);
	if (animframe==6) copymem((void*)BGMap(2), (void*)GIANTCRAWL6MAP, 512*16);	
		
	if (animframe==7) copymem((void*)CharSeg2, (void*)GIANTCRAWL7CHAR, 256*16);
	if (animframe==7) copymem((void*)BGMap(2), (void*)GIANTCRAWL7MAP, 256*16);			
	
	ChangeCharsegOfBGMap(1, 1);

 	//octoy, xbeginning, ?, ybeginning, totalx, totaly
	}

	}
	}
	}