Exemplo n.º 1
0
static inline unsigned int DROPPING(unsigned char* x) {
	unsigned char loop = 0, y = 2, STATUS = RUNNING;
	signed char sign = 1;
	BOOL PEG = FALSE;
	
	unsigned char peg_X_array[16] =
		{1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1};
	signed char peg_Y_array[16] =
		{-1, -1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 2, 1, 2};
	unsigned int money[9] =
		{100, 500, 1000, 0, 5000, 0, 1000, 500, 100};
		
	do
	{
		if (PEG == TRUE) {
			*x+= sign*peg_X_array[ loop ];
			y+= peg_Y_array[ loop ];
			loop++;
			if (loop == 16) PEG = FALSE;
		} else {
			y++;
			if (pxltst(*x, y) && y < 84) {
				PEG  = TRUE;
				loop = 0;
				sign = 1-2*random(2);
				
				if (_keytest (RR_F1)) sign = -1;  // hmm, what could this do?
				else if (_keytest (RR_F5)) sign = 1;
				
				if (*x == 3) sign = 1;  // Makes sure the ball won't go off the board
				else if (*x == 115) sign = -1;
			}
		}
		
		DRAWALL(*x, y);
		
		//for(wait = 0; wait < 130000; wait++ );  // Slow Downnnnnn
		DELAY(4);
		if (_keytest (RR_ESC)) STATUS = EXIT;
		
	}  while (y < 93 && STATUS == RUNNING);
	
	if (STATUS != RUNNING)
		return EXIT;
	
	*x = (*x - 3) / 14;
	
	return money[*x];
}
Exemplo n.º 2
0
/**
* Throws an error, prints out the error message, and aborts.
*
* @param format - format string in printf format
*
* @return nothing
* @todo Allow errors to be caught in try/catch block?
*/
void x3d_error(const char* format, ...) {
  char buf[512];
  va_list list;

  va_start(list, format);
  vsprintf(buf, format, list);

  
//#ifdef __TIGCC__
  GrayOff();
  PortRestore();
  clrscr();

//#endif
  printf("Error: %s\nPress Esc to quit\n\n", buf);

  //x3d_print_stacktrace();

#ifdef __TIGCC__
  while(!_keytest(RR_ESC));
#endif
  
  //while(1);

  longjmp(exit_jmp, 1);
  
}
Exemplo n.º 3
0
void _main(void)
{
	OldInt1 = GetIntVec (AUTO_INT_1);
	OldInt2 = GetIntVec (AUTO_INT_2);
	SetIntVec (AUTO_INT_1, DUMMY_HANDLER);
  SetIntVec (AUTO_INT_2, myint2);
  	
	pSnd_EnableSound ();
	pSnd_InstallSound ();
	
	pSnd_PlayMode (MONO);
	pSnd_SetTempo (90);
		
	pSnd_PlaySound_voice1 (channel);
	
	pSnd_SetState (ALLVOICES);
	
	while ((_keytest (RR_ESC)!=TRUE) && (pSnd_VoiceState()));
		
	pSnd_UninstallSound ();
	pSnd_DisableSound ();
	
	SetIntVec (AUTO_INT_1, OldInt1);
	SetIntVec (AUTO_INT_2, OldInt2);
}
Exemplo n.º 4
0
unsigned char wait_for_keypress(void) {
	unsigned long wait2 = 0;
	
	while( !_keytest (RR_2ND) ) {
		if (wait2++ > 2000) {
			wait2 = 0;
			if ( _keytest (RR_MINUS) )
				OSContrastDn ();//  turn contrast down
			else if ( _keytest (RR_PLUS) )
				OSContrastUp ();//  turns contrast up
		} else if ( _keytest (RR_ESC) )
			return 1;
	}
	while( _keytest (RR_2ND) );
	
	return 0;
}
Exemplo n.º 5
0
/**
* Reads the physical keys on the keypad and updates the keystate.
*
* @param    - state to update
*
* @return nothing
* @note Make sure to call this before calling x3d_keystate_down!
*/
void x3d_keystate_update(X3D_KeyState* state) {
  int16 i;

  state->state = 0;

  for(i = 15; i >= 0; --i) {
    state->state = (state->state << 1) | _keytest(state->keys[i].row, state->keys[i].col);
  }
}
Exemplo n.º 6
0
static inline int MENU(void) {
	int STATUS = RUNNING, choice = 0;
	FastCopyScreen(Actived, virtual_light);
	memset(virtual_dark, 0, LCD_SIZE);
	GraySpriteX8_OR(48, 16, 67, menul, menud, 8, virtual_light, virtual_dark);
	char buf[2] = { 0, 0 };
	
	do  // Loops until you choose new game, exit, or press Home
	{
		do
		{
			DRAW_MENU(choice);
			
			/*if (_keytest (RR_UP) && choice > 0) {
				choice--;
			}
			if (_keytest (RR_DOWN) && choice < 3) {
				choice++;
			}*/
			if (_keytest (RR_DOWN)) {
				if (buf[0] == FALSE) {
					buf[0] = TRUE;
					if (++choice > 3) choice = 0;
				}
			} else buf[0] = FALSE;
			if (_keytest (RR_UP)) {
				if (buf[1] == FALSE) {
					buf[1] = TRUE;
					if (--choice < 0) choice = 3;
				}
			} else buf[1] = FALSE;
			
			if (_keytest (RR_2ND) || _keytest (RR_ENTER)) {
				STATUS = DROP;
				while(_keytest (RR_2ND) || _keytest (RR_ENTER));
			}
			if (_keytest (RR_ESC)) STATUS = EXIT;
		} while (STATUS == RUNNING);
		
		if (STATUS == DROP && choice != 3) {
			STATUS = RUNNING;
			
			switch(choice) {
				case 1:
					if (DISPLAY_SCORES() == QUIT)
						return QUIT;
					break;
				case 2:
					info();
					break;
			}
		}
		
		if (STATUS == EXIT || choice == 3) return -1;
		
	} while(choice);
	
	return STATUS;
}
Exemplo n.º 7
0
uint16 get_num() {
  char buf[20];
  uint16 pos = 0;
  
  uint16 keys[10][2] = {
    {RR_0},
    {RR_1},
    {RR_2},
    {RR_3},
    {RR_4},
    {RR_5},
    {RR_6},
    {RR_7},
    {RR_8},
    {RR_9},
  };
  
  uint16 i;
  
  do {
    for(i = 0; i < 10; ++i) {
      if(_keytest(keys[i][0], keys[i][1])) {
        while((_keytest(keys[i][0], keys[i][1]))) ;
        
        buf[pos] = i + '0';
        printf("%c", buf[pos]);
        buf[++pos] = '\0';
      }
    }
    
    if(_keytest(RR_ENTER)) {
      return atoi(buf);
    }
    
  } while(1);
  
}
Exemplo n.º 8
0
static inline void RenderMaps(void *big_vscreen,void *dest)
{
  short x=0,y=0,old_x=0,old_y=0,update=1;
  unsigned short i=0;

  do
  {
    // Affichage
    if(update)
    {
      RefreshGrayBuffer16B(20,&map[y>>4][x>>4],big_vscreen,sprts);
      update=0;
    }
#ifndef USE_TI89
    DrawGrayBufferWithShifts_RPLC(big_vscreen,x&15,y&15,dest,dh+((i>>3)&15),dv+((i>>3)&15));
#else
    DrawGrayBufferWithShifts89_RPLC(big_vscreen,x&15,y&15,dest,dh+((i>>3)&15),dv+((i>>3)&15));
#endif

    FastCopyScreen_R(dest,GrayGetPlane(LIGHT_PLANE));
    FastCopyScreen_R(dest+LCD_SIZE,GrayGetPlane(DARK_PLANE));
/*
    memcpy(GrayGetPlane(LIGHT_PLANE),dest,LCD_SIZE);
    memcpy(GrayGetPlane(DARK_PLANE),dest+LCD_SIZE,LCD_SIZE);
*/

    // Déplacement
    BEGIN_KEYTEST
    if(_keytest_optimized(RR_UP) && y>0)
      y--;
    if(_keytest_optimized(RR_DOWN) && y<12*16-HEIGHT-2)
      y++;
    if(_keytest_optimized(RR_LEFT) && x>0)
      x--;
    if(_keytest_optimized(RR_RIGHT) && x<19*16+11-WIDTH)
      x++;
    END_KEYTEST

    i++;

    update=(((x&16)^(old_x&16)) || ((y&16)^(old_y&16)));

    old_x=x;old_y=y;

  }while(!_keytest(RR_ESC));
}
Exemplo n.º 9
0
void _main(void) {

   INT_HANDLER int1 = GetIntVec(AUTO_INT_1);
   INT_HANDLER int5 = GetIntVec(AUTO_INT_5);
   SetIntVec(AUTO_INT_1, DUMMY_HANDLER);
   SetIntVec(AUTO_INT_5, DUMMY_HANDLER);
   GrayOn();  ////  everything above is just magic, you need it but
//don't need to understand it.
   clrscr();

   Sprite8(0,0,8,square,GetPlane(0),SPRT_XOR);
   Sprite8(8,0,8,square,GetPlane(1),SPRT_XOR);
   Sprite8(16,0,8,square,GetPlane(0),SPRT_XOR);
   Sprite8(16,0,8,square,GetPlane(1),SPRT_XOR);

   while(!_keytest(RR_ENTER));

   GrayOff();
   SetIntVec(AUTO_INT_1, int1);
   SetIntVec(AUTO_INT_5, int5);

}
Exemplo n.º 10
0
/*	Returns the option chosen by the user	 */
short Menu(const char *title, const char Options[], short Max_Length, short pos, short Fading) {
	short width = 0, No_Options = 0, Main_Pos = 0;
	short a, Changing = FALSE;
	
	while(_KeyCheck(ESCKEY));
	do 
	{
		if (DrawStrWidth(Options + (Max_Length * No_Options), F_6x8) > width)
			width = DrawStrWidth(Options + (Max_Length * No_Options), F_6x8);
	} while(*(Options + (Max_Length * (++No_Options))) != 0);
	
	do {
		
		memset(Hiddenl, 0xFF, LCD_SIZE + LCD_SIZE);
		GraySpriteX8_AND(g->Zerox + 8, 0, 16, ExciteBike_Title[1], ExciteBike_Title[0], 18, 
			Hiddenl, Hiddend);
		
		Display_Author();
		FS_DrawGrayString(0, 22, title, A_SHADOWED | A_XOR | A_CENTERED, F_6x8);
		for(a = (No_Options > 5 ? 6 : No_Options); a--;)
			FS_DrawGrayString(g->Zerox + 22, 34 + 10 * a, Options + (Max_Length * (Main_Pos + a)), 
			A_XOR, F_6x8);
		
		register short Offset = 2 + (g->Zerox >> 3) + 30 * (10 * pos + 0 + 36);
		*((char*)Hiddend + Offset +  0) &= 0x1F;
		*((char*)Hiddend + Offset + 30) &= 0x1F;
		*((char*)Hiddenl + Offset + 30) &= 0xBF;
		*((char*)Hiddend + Offset + 60) &= 0x1F;
		
		// Highlight the selected Option
		GrayInvertRect2B(g->Zerox + 21, 33 + 10 * pos, g->Zerox + 23 + width, 41 + 10 * pos, Hiddenl, Hiddend);
		
		if (!strcmp(title, "- Choose Mode -")) {
			a = Zeroy + 75;
			if (pos == 0) {
				FS_DrawGrayString(0, a, EFG("(The fastest time at the end of the race wins)", 
					"(Le plus rapide à la course gagne)", "(die beste Zeit am Ende des Rennens gewinnt)"), A_CENTERED | A_XOR, F_4x6);
				FS_DrawGrayString(0, a + 7, EFG("Hint: Perform flips to lower your time", 
					"Astuce: pirouettes pour meil. tps", "Tipp: Loopings für eine bessere Zeit"), 
					A_CENTERED | A_XOR, F_4x6);
			}
			if (pos == 1) {
				FS_DrawGrayString(0, a, EFG("(The first person to cross the finish line wins)", 
					"(Celui qui arrive en premier gagne)", "(derjenige, der als Erster ankommt, gewinnt)"), 
					A_CENTERED | A_XOR, F_4x6);
			}
		}
		
		if (Fading) {  // Make a new menu screen fade in
			Dissolve();
			Fading = FALSE;
		} else {
			Toggle_Screens();
		}
		
		// Algorithm allows for any size menues to be scrolled easily
		if (_keytest(RR_UP)) {
		 	if (Changing == FALSE) {
				Changing = TRUE;
				if (--pos < 0) {
					if (--Main_Pos < 0) {
						pos = (No_Options > 5 ? 5 : No_Options - 1);
						Main_Pos = (No_Options > 5) * (No_Options - 6);
					} else pos = 0;
				}
			}
		} else if (_keytest(RR_DOWN)) {
			if (Changing == FALSE) {
				Changing = TRUE;
				if (++pos >= (No_Options > 5 ? 6 : No_Options)) {
					if (++Main_Pos >= (No_Options > 5) * (No_Options - 5))
						pos = Main_Pos = 0;
					else pos = 5;
				}
			}
		} else Changing = FALSE;
		
		if (_KeyCheck(ESCKEY) || _KeyCheck(TEACHERKEY)) {
			Exit_Linkplay();
			while(_KeyCheck(ESCKEY));
			
			return QUIT;
		}
	} while (!_KeyCheck(CONFIRMKEY) && !(_keytest(RR_ENTER) || (CALCULATOR && _keytest(RR_ENTER1)) || 
	(CALCULATOR && _keytest(RR_ENTER2))));
	
	while(_rowread(0));
	return Main_Pos + pos;  // Return the option chosen by the user
}
Exemplo n.º 11
0
uint16 input_polygon2d(Vex2D* v) {
  uint16 total_v = 0;
  uint16 cursor_x = LCD_WIDTH / 2, cursor_y = LCD_HEIGHT / 2;
  
  uint16 old_x = cursor_x, old_y = cursor_y;
  uint16 old_value = GetPix(old_x, old_y);
  
  _Bool start = 1;
  
  do {
    if(cursor_x != old_x || cursor_y != old_y || start) {
      DrawPix(old_x, old_y, old_value ? A_NORMAL : A_REVERSE);
      old_value = GetPix(cursor_x, cursor_y);
      old_x = cursor_x;
      old_y = cursor_y;
      DrawPix(cursor_x, cursor_y, A_NORMAL);
      start = 0;
      
      idle();
      
      if(_keytest(RR_DIAMOND)) {
        idle();
        idle();
        idle();
        idle();
      }
    }
    
    
    if(_keytest(RR_W)) {
      if(cursor_y > 0)
        --cursor_y;
    }
    else if(_keytest(RR_S)) {
      if(cursor_y + 1  < LCD_HEIGHT)
        ++cursor_y;
    }
    else if(_keytest(RR_A)) {
      if(cursor_x > 0)
        --cursor_x;
    }
    if(_keytest(RR_D)) {
      if(cursor_x + 1 < LCD_WIDTH)
        ++cursor_x;
    }
    else if(_keytest(RR_ENTER)) {
      v[total_v++] = (Vex2D) { cursor_x, cursor_y };
      
      if(total_v > 1)
        draw_line(v[total_v - 2], v[total_v - 1]  );
      
      while(_keytest(RR_ENTER)) ;
    }
    
    else if(_keytest(RR_ESC)) {
      while(_keytest(RR_ESC)) ;
      
      draw_line(v[0], v[total_v - 1]);
      return total_v;
    }
    
  } while(1);
  
  
  
}
Exemplo n.º 12
0
// Main function for showing products and determining how many plinkos you get
static inline int PRODUCTS(void) {
	unsigned char STATUS = RUNNING, FLAG;
	unsigned char plinkos = 1;  // You automatically start out with 1 plinko
	char turn = 1;  // Start out on First turn
	unsigned char n1, n2, real;
	unsigned char x = 0;
	char PRESSED, name[30], option, sign1, sign2;
	typedef unsigned short BOOL;
	BOOL ANSWER;
	
	//const char question[42] = "Which digit is in the actual retail price?";
	
	unsigned char *LIGHT, *DARK;
	
	while(STATUS == RUNNING && turn < 5) {
		
		PRESSED = 0;
		GET_PRODUCT(&n1, &n2, name);  // Send the address of n1, n2, and name.  The reason why name doesn't have a 
		// star is because it is an array and an array automatically give a pointer to it's the first item.
		
		if (random(2)) {  // Discards one of the actual retail price digits and replaces it with a "fake" number
			real = n1;  // Remember the real number to show after a guess
			ANSWER = 1;
			do 
			{
				n1 = random(10);
			} while (real == n1 || n1 == n2);  // Make sure n1 and n2 are not equal and the fake random number is not
			// equal to the real number
		} else {
			real = n2;
			ANSWER = 0;
			do 
			{
				n2 = random(10);
			} while (real == n2 || n1 == n2);
		}
		
		option = random(3);
		
		FLAG = FALSE;
		while(STATUS == RUNNING) {
			
			if (FLAG == FALSE) {
				if (_keytest (RR_LEFT))  x = 0;
				if (_keytest (RR_RIGHT))  x = 1;
			}
			
			LIGHT = Hiddenl;
			DARK = Hiddend;
			
			UPDATE_SCREEN(option, LIGHT, DARK);
			
			sign1 = 1 - 2 * random(2);
			sign2 = 1 - 2 * random(2);
			
			GRAPHIC(56 + (!x)*(sign1 * random(3)), 40 + (!x)*(sign2 * random(3)), n1, TRUE);
			GRAPHIC(82 + (x)*(sign1 * random(3)), 40 + (x)*(sign2 * random(3)), n2, TRUE);
			
			SHOW_PLINKOS(turn, plinkos, Hiddenl, Hiddend);
			
			DrawString (0, name);
			
			if (FLAG != FALSE) {
				GRAPHIC(56 + 26 * (ANSWER == 0), FLAG, real, TRUE);
				if ((FLAG -= 3) <= 40)
					break;
			}
			
			GrayDBufToggleSync(); // switches two sets of planes
			if (FLAG == FALSE) {
				DELAY(5);
				
				if (_keytest (RR_2ND)) PRESSED = 1;
				else if (PRESSED == 1) FLAG = 85;
			}
			
			if (_keytest (RR_ESC))
				return QUIT;
		}
		
		//GRAPHIC(x2, 40, real, TRUE);
		DRAW_BOX(60, 65, 14, 32);
		
		if (ANSWER == x) {  // You guessed right
			plinkos++;
			GraySprite32_OR(64, 69, 14, WINl, WINd, Hiddenl, 
			Hiddend);  // Show WIN
		} else
			GraySprite32_OR(64, 69, 14, wrongl, wrongd, Hiddenl,
			Hiddend);  // Show Wrong
		
		GrayDBufToggleSync(); // switches two sets of planes
		Waitkey();
		
		turn++;
	}
	
	return plinkos;
}
Exemplo n.º 13
0
static inline char main_game(unsigned char plinkos) {
	unsigned char STATUS = RUNNING, x, y = 0, oldx = 59;
	unsigned int Amount, Total = 0;
	char buffer[15];
	
	FontSetSys(F_4x6);
	
	while( plinkos-- ) {
		
		ClearGrayScreen2B(virtual_dark, virtual_light);
		GraySpriteX8_OR(0, 0, 100, plinkol, plinkod, 20, virtual_light, virtual_dark);
		PRINT_TOTAL(Total);
		SHOW_PLINKOS(5, plinkos - 1, virtual_light, virtual_dark);
		new_chip(oldx, plinkos);
		x = oldx;
		y = 2;
		DRAWALL(x, y);
		
		
		while (STATUS == RUNNING) {
			
			if (_keytest (RR_LEFT) && x > 3)  MOVE_LEFT( &x );
			
			if (_keytest (RR_RIGHT) && x < 115)  MOVE_RIGHT( &x );
			
			if (_keytest (RR_ESC))  STATUS = EXIT;
			
			if (_keytest (RR_2ND) || _keytest (RR_DOWN))  STATUS = DROP;
		}
		
		if (STATUS == EXIT)  return -1;
		
		oldx = x;
		Amount = DROPPING( &x );  // After this, x will be from 0 to 8
		if (Amount == EXIT) return -1;
		
		Total += Amount;
		
		
		
		//GRAPHIC(30, 20, /* HEIGHT */14, /* WIDTH */32, (char*) Zerol, (char*) Zerod, SMALL);
		/*for(y = 1; y < 6; y++) {
			period = 15000*(1+random( y ));
			memset (Actived, 255, LCD_SIZE); // clear virtual gray planes
			memset (Activel, 255, LCD_SIZE);
			for(wait = 1; wait < period; wait++);
			
			period = 15000*(1+random( y ));
			DRAWALL(14 * x + 3, 93);
			for(wait = 1; wait < period; wait++);
		}*/
		
		SHUFFLE( x );
		
		DRAWALL(14 * x + 3, 93);
		DRAWALL(14 * x + 3, 93);
		GRAPHIC(45, 36, x, FALSE);//, gfx_light[x], gfx_dark[x], x); 
		GrayDBufToggleSync(); // switches two sets of planes
		Waitkey()
		
		STATUS = RUNNING;
	}
	
	sprintf(buffer, "Score %d", Total);
	x = (LCD_WIDTH - DrawStrWidth(buffer, F_6x8)) / 2 - 16;
	DrawGrayStrExt2B(x, 2, (char*)buffer, A_NORMAL|A_SHADOWED, F_6x8, 
	Activel, Actived);
	
	wait_for_keypress();
	
	if (CHECK_FOR_HIGH(Total) == QUIT)  // Checks whether or not the user got a high score, writes a new 
	// high score if they did get one, and calls a function to display the new high scores
		return QUIT;
	
	return STATUS;
}