示例#1
0
void VblankHandler()
{
	static int heartbeat = 0;

	uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0, batt=0, aux=0;

	// Read the X/Y buttons and the /PENIRQ line
	but = REG_KEYXY;
	if (!(but & 0x40)) {
		// Read the touch screen
		touchPosition tempPos = touchReadXY();

		x = tempPos.x;
		y = tempPos.y;
		xpx = tempPos.px;
		ypx = tempPos.py;

	}

	// Update the IPC struct

	IPC->buttons   = but;
	IPC->touchX    = x;
	IPC->touchY    = y;
	IPC->touchXpx  = xpx;
	IPC->touchYpx  = ypx;
	IPC->touchZ1   = z1;
	IPC->touchZ2   = z2;
	IPC->battery   = batt;
	IPC->aux       = aux;

}
示例#2
0
void update_doorminigame()
{
  if (pressed & KEY_TOUCH)
    {
      touch_down = touchReadXY();
          
      if (touch_down.px > 64 && touch_down.py > 88 &&
          touch_down.px < door_pos + 64+16 && touch_down.py < door_pos + 88 + 32)
        {
          dragging = true;
          old_pos = door_pos;
        }
    }

  if ((held & KEY_TOUCH) && dragging == true)
    {
      //int scrollpos = abs(std::max(std::min(0, (touch_down.px - cur.px)), -128));
  
      door_pos = std::min(std::max(0, old_pos + (touch.px - touch_down.px)), 128);
    }
  else
    {
      dragging = false;
    }

  SUB_BG2_CX = -door_pos << 8;
  if (door_pos < 4)
    SUB_BG2_CY = door_pos << 8;
  else
    SUB_BG2_CY = 4 << 8;
}
示例#3
0
文件: input.c 项目: swolchok/dspython
void inputGetAndSend(void){

	static bool penDown = false;
	static int sleepCounter = 0;

	touchPosition tempPos = {0};
	FifoMessage msg = {0};

	u16 keys= REG_KEYXY;

	msg.SystemInput.keys = keys;

	if(keys & KEY_TOUCH)
	{
		penDown = false;	
	}
	else
	{
		msg.SystemInput.keys |= KEY_TOUCH;

		if(penDown)
		{
			touchReadXY(&tempPos);	
			
			if(tempPos.rawx && tempPos.rawy)
			{
				msg.SystemInput.keys &= ~KEY_TOUCH;
				msg.SystemInput.touch = tempPos;
			}
			else
			{
				penDown = false;
			}
		}
		else
		{
			penDown = true;
		}
	}	

	if(keys & KEY_LID) 
		sleepCounter++;
	else
		sleepCounter = 0;

	//sleep if lid has been closed for 20 frames
	if(sleepCounter >= 20) 
	{
		systemSleep();
		sleepCounter = 0;
	}

	msg.type = SYS_INPUT_MESSAGE; //set message type

	fifoSendDatamsg(FIFO_SYSTEM, sizeof(msg), (u8*)&msg);
}
示例#4
0
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
	static int lastbut = -1;
	
	uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;

	but = REG_KEYXY;

	if (!( (but ^ lastbut) & (1<<6))) {
 
		tempPos = touchReadXY();

		if ( tempPos.x == 0 || tempPos.y == 0 ) {
			but |= (1 <<6);
			lastbut = but;
		} else {
			x = tempPos.x;
			y = tempPos.y;
			xpx = tempPos.px;
			ypx = tempPos.py;
			z1 = tempPos.z1;
			z2 = tempPos.z2;
		}
		
	} else {
		lastbut = but;
		but |= (1 <<6);
	}

	if ( vcount == 80 ) {
		first = tempPos;
	} else {
		if (	abs( xpx - first.px) > 10 || abs( ypx - first.py) > 10 ||
				(but & ( 1<<6)) ) {

			but |= (1 <<6);
			lastbut = but;

		} else { 	
			IPC->mailBusy = 1;
			IPC->touchX			= x;
			IPC->touchY			= y;
			IPC->touchXpx		= xpx;
			IPC->touchYpx		= ypx;
			IPC->touchZ1		= z1;
			IPC->touchZ2		= z2;
			IPC->mailBusy = 0;
		}
	}
	IPC->buttons		= but;
	vcount ^= (80 ^ 130);
	SetYtrigger(vcount);

}
示例#5
0
void scan_touch_screen()
{
  raw_touch_coords = touchReadXY();

  old_touch_coords = touch_coords;
  was_touching = touching;

  if ((raw_touch_coords.rawx == 0) || (raw_touch_coords.rawy == 0)) {
    touching = 0;
  } else {
    touch_coords.x = raw_touch_coords.px;
    touch_coords.y = raw_touch_coords.py;

    touching = 1;
  }
}
示例#6
0
void
NDS_PumpEvents(_THIS)
{
    scanKeys();
    /* TODO: defer click-age */
    if (keysDown() & KEY_TOUCH) {
        SDL_SendMouseButton(0, SDL_PRESSED, 0);
    } else if (keysUp() & KEY_TOUCH) {
        SDL_SendMouseButton(0, SDL_RELEASED, 0);
    }
    if (keysHeld() & KEY_TOUCH) {
        touchPosition t = touchReadXY();
        SDL_SendMouseMotion(0, 0, t.px, t.py, 1);       /* last arg is pressure,
                                                           hardcoded 1 for now */
    }
}
示例#7
0
//---------------------------------------------------------------------------------
void VblankHandler(void) 
{
    static int lastbut = -1;
    
    uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
    uint16 batt=0, aux=0;

    but = REG_KEYXY;

    if (!( (but ^ lastbut) & (1<<6))) {
 
        tempPos = touchReadXY();

        if ( tempPos.x == 0 || tempPos.y == 0 ) {
            but |= (1 <<6);
            lastbut = but;
        } else {
            x = tempPos.x;
            y = tempPos.y;
            xpx = tempPos.px;
            ypx = tempPos.py;
            z1 = tempPos.z1;
            z2 = tempPos.z2;
        }
        
    } else {
        lastbut = but;
        but |= (1 <<6);
    }

    batt = touchRead(TSC_MEASURE_BATTERY);
    aux  = touchRead(TSC_MEASURE_AUX);

    IPC->touchX         = x;
    IPC->touchY         = y;
    IPC->touchXpx       = xpx;
    IPC->touchYpx       = ypx;
    IPC->touchZ1        = z1;
    IPC->touchZ2        = z2;
    IPC->buttons        = but;
    IPC->battery        = batt;
    IPC->aux            = aux;

#ifdef WIFI
	Wifi_Update(); // update wireless in vblank
#endif
}
示例#8
0
//---------------------------------------------------------------------------------
void VcountHandler() {
//---------------------------------------------------------------------------------
    static int lastbut = -1;

    uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;

    but = REG_KEYXY;

    if (!( (but ^ lastbut) & (1<<6))) {

        tempPos = touchReadXY();

        if ( tempPos.x == 0 || tempPos.y == 0 ) {
            but |= (1 <<6);
            lastbut = but;
        } else {
            x = tempPos.x;
            y = tempPos.y;
            xpx = tempPos.px;
            ypx = tempPos.py;
            z1 = tempPos.z1;
            z2 = tempPos.z2;
        }

    } else {
        lastbut = but;
        but |= (1 <<6);
    }

    IPC->touchX			= x;
    IPC->touchY			= y;
    IPC->touchXpx		= xpx;
    IPC->touchYpx		= ypx;
    IPC->touchZ1		= z1;
    IPC->touchZ2		= z2;
    IPC->buttons		= but;

}
示例#9
0
文件: adrift.cpp 项目: nornagon/torch
void handler() {
	process_keys();
	update_projectiles();
	update_animations();
	step_monsters();

	game.player.light->update_flicker();
	process_sight();
	draw_lights(game.fov_light, &game.map.block, game.map.lights);
	{
		lightsource *k = game.map.lights.head();
		for (; k; k = k->next()) {
			k->update_flicker();
			draw_light(game.fov_light, &game.map.block, k);
		}
	}

	u32 keys = keysHeld();
	u32 down = keysDown();
	touchPosition touch = touchReadXY();
	if (down & KEY_TOUCH && keys & KEY_R && touch.px != 0 && touch.py != 0) {
		luxel *l = torch.buf.luxat(torch.buf.scroll.x + touch.px/8, torch.buf.scroll.y + touch.py/8);
		iprintf("c:%d,%d,%d v:%d, low:%d\n", l->lr, l->lg, l->lb, l->lval, torch.get_low_luminance());
	}

	refresh(&game.map.block);

	if (game.player.hp <= 0) {
		playerdeath();
		game.player.clear();
		new_game();
	}

	if (game.cooldown <= 0) game.player.regenerate();

	statusbar();
}
示例#10
0
int main()
{	
    struct touchPosition pos;
	float rotateX = 0.0;
	float rotateY = 0.0;

	powerON(POWER_ALL);
    consoleDemoInit();

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);

	//irqs are nice
	irqInit();
	irqEnable(IRQ_VBLANK);
    
	// initialize gl
	glInit();
    
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);

	//this should work the same as the normal gl call
	glViewPort(0,0,255,191);
    
	//any floating point gl call is being converted to fixed prior to being implemented
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(35, 256.0 / 192.0, 0.1, 100);
	
	gluLookAt(	0.0, 0.0, 1.0,		//camera possition 
				0.0, 0.0, 0.0,		//look at
				0.0, 1.0, 0.0);		//up

	while(1)		
	{
        float px, py;
        
    	pos = touchReadXY();
        px = pos.px;
        py = pos.py;

        px = (px * 5) / 256;
        py = (py * 3) / 192;

        px -= 2.5;
        py -= 1.5;

		glPushMatrix();

		//move it away from the camera
		glTranslate3f32(0, 0, floattof32(-1));

		glRotateX(rotateX);
		glRotateY(rotateY);

		glMatrixMode(GL_MODELVIEW);

		//not a real gl function and will likely change
		glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
        
		scanKeys();
		
		u16 keys = keysHeld();
		
		if((keys & KEY_UP)) rotateX += 3;
		if((keys & KEY_DOWN)) rotateX -= 3;
		if((keys & KEY_LEFT)) rotateY += 3;
		if((keys & KEY_RIGHT)) rotateY -= 3;
        
		//draw the obj
		glBegin(GL_TRIANGLE);
			
			glColor3b(255,0,0);
			glVertex3v16(inttov16(-1),inttov16(-1),0);

			glColor3b(0,255,0);
			glVertex3v16(inttov16(1), inttov16(-1), 0);

			glColor3b(0,0,255);
			glVertex3v16(inttov16(0), inttov16(1), 0);
			
		glEnd();

        glLoadIdentity();
        glTranslatef(px,-py,-3.0);
        glBegin(GL_TRIANGLE);
            glVertex3f( 0.0, 1.0, 0.0);
            glVertex3f(-1.0,-1.0, 0.0);
            glVertex3f( 1.0,-1.0, 0.0);
        glEnd();

		glPopMatrix(1);

		glFlush(0);
		swiWaitForVBlank();
	}

	return 0;
}//end main 
示例#11
0
文件: main.cpp 项目: jkroll20/libflux
int main(void)
{
    touchPosition touch;

    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);	//sub bg 0 will be used to print text
    vramSetBankC(VRAM_C_SUB_BG);

    SUB_BG0_CR = BG_MAP_BASE(31);

    BG_PALETTE_SUB[255] = RGB15(31,31,31);	//by default font will be rendered with color 255

    //consoleInit() is a lot more fluxible but this gets you up and running quick
    consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
    
/////////////
    powerON(POWER_ALL);

    // set mode 0, enable BG0 and set it to 3D
    videoSetMode(MODE_0_3D);
    vramSetBankA(VRAM_A_TEXTURE);

    // irqs are nice
    irqInit();
    irqEnable(IRQ_VBLANK);
    
    // initialize gl
    glInit();
    
    // setup the rear plane
    glClearColor(2, 4, 3, 16);
    glClearDepth(GL_MAX_DEPTH);
    
    // this should work the same as the normal gl call
    glViewPort(0,0, 255,191);
    
    glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);
    
    glMatrixMode(GL_PROJECTION);
    
    glLoadIdentity();
    //~ glOrtho(0, 1, 192.0/256.0, 0, -10, 10);
    glOrthof32(0, 1<<12, (192<<12)/256, 0, -10<<12, 10<<12);
    
    REG_POWERCNT^= POWER_SWAP_LCDS;
/////////////


    flux_init();
    create_frame_groups();
    create_button_groups();
    create_titleframe();
    
    dmaCopy(fluxcolors, syscol_table, sizeof(fluxcolors));
    
    dword rc1= create_rect(NOPARENT, 20,20, 128,96, 0x808080);
    dword rc= create_rect(NOPARENT, 10,10, 128,96, 0x404040|TRANSL_3);
    dword frm= clone_frame("titleframe", rc);
    clone_frame("titleframe", rc1);
    //~ clone_group("button", rc, 10,30, 30,14, ALIGN_LEFT|ALIGN_TOP);

    create_rect(rc, 10,10, 10,10, 0xFFFFFF|TRANSL_1);
    create_rect(rc, 20,10, 10,10, 0xFFFFFF|TRANSL_2);
    create_rect(rc, 30,10, 10,10, 0xFFFFFF|TRANSL_3);
    create_rect(rc, 10,15, 30,10, 0xFFFFFF|TRANSL_1);
    
    create_text(rc, 10,30, 40,40, "Text! Space!\nNewline!", 0xFFFFFF, FONT_DEFAULT);
    
    bool redraw_all= true;
    bool touch_wasdown= false;
    int lasttouch_x, lasttouch_y;
    while(1)
    {
	scanKeys();
    	u32 keysheld= keysHeld();
	u32 keysdown= keysDown();
	touch= touchReadXY();
	
	if(keysdown&KEY_A)
	{
	    redraw_all^= 1;
	    iprintf("redraw each frame: %s\n", redraw_all? "on": "off");
	}
	
	if(keysdown&KEY_B)
	{
	    do_texalpha^= 1;
	    iprintf("texture alpha: %s\n", do_texalpha? "on": "off");
	}
	
	if(touch.x || touch.y)
	{
	    flux_mouse_event(touch.px, touch.py, 1);
	    lasttouch_x= touch.px, lasttouch_y= touch.py;
	    touch_wasdown= true;
	}
	else
	{
	    if(touch_wasdown) flux_mouse_event(lasttouch_x, lasttouch_y, 0);
	    touch_wasdown= false;
	}
	    

	flux_tick();
	if(redraw_all)
	{
	    redraw_rect(&viewport);
	    update_rect(&viewport);
	}
	
	swiWaitForVBlank();
    }

    return 0;
}
示例#12
0
文件: main7.c 项目: sypherce/dslua
void VcountHandler()
{
	static int lastbut = -1;
	uint8 ct[sizeof(IPC->time.rtc)];
	
	uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;

	but = REG_KEYXY;

	if(!((but ^ lastbut) & (1<<6)))
	{
		tempPos = touchReadXY();
		if(tempPos.x == 0 || tempPos.y == 0)
		{
			but |= (1 <<6);
			lastbut = but;
		}
		else
		{
			x = tempPos.x;
			y = tempPos.y;
			xpx = tempPos.px;
			ypx = tempPos.py;
			z1 = tempPos.z1;
			z2 = tempPos.z2;
		}
	}
	else
	{
		lastbut = but;
		but |= (1 <<6);
	}

	if(vcount == 80)
	{
		first = tempPos;
	}
	else
	{
		if(abs(xpx - first.px) > 10 || abs(ypx - first.py) > 10 || (but & (1<<6)))
		{
			but |= (1 <<6);
			lastbut = but;
		}
		else
		{ 	
			IPC->mailBusy = 1;
			IPC->touchX			= x;
			IPC->touchY			= y;
			IPC->touchXpx		= xpx;
			IPC->touchYpx		= ypx;
			IPC->touchZ1		= z1;
			IPC->touchZ2		= z2;
			IPC->mailBusy = 0;
		}
	}
    // Read the time
    rtcGetTime((uint8 *)ct);
    BCDToInteger((uint8 *)&(ct[1]), 7); 
	u8 i;
	u8 *temp;
	temp = (u8*)&IPC->time.rtc;
	for(i=0; i<sizeof(ct); i++)
	{
		temp[i] = ct[i];
	} 

	IPC->buttons		= but;
	vcount ^= (80 ^ 130);
	SetYtrigger(vcount);
}
示例#13
0
void gamescreen()
{
  // set the mode for 2 text layers and two extended background layers
  videoSetMode(MODE_5_2D |
               //DISPLAY_BG1_ACTIVE |
               DISPLAY_BG3_ACTIVE |
               DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT
               );

  // set the first bank as background memory and the third as sub background memory
  // B and D are not used (if you want a bitmap greater than 256x256 you will need more
  // memory so another vram bank must be used and mapped consecutivly
  vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_SPRITE, //VRAM_B_MAIN_BG_0x6020000,
                   VRAM_C_SUB_BG, VRAM_D_MAIN_BG_0x6020000);
  
  // set up our bitmap background
  BG3_CR     = BG_BMP8_512x256 | BG_WRAP_ON| BG_BMP_BASE(0);
  //BG2_CR     = BG_BMP8_256x256 | BG_BMP_BASE(8);
  
  BG1_CR = BG_32x32 | BG_TILE_BASE(0) | BG_MAP_BASE(8) | BG_256_COLOR;


  // these are rotation backgrounds so you must set the rotation attributes:
  // these are fixed point numbers with the low 8 bits the fractional part
  // this basicaly gives it a 1:1 translation in x and y so you get a nice flat bitmap
  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1 << 8;

  BG2_XDX = 1 << 8;
  BG2_XDY = 0;
  BG2_YDX = 0;
  BG2_YDY = 1 << 8;


  //our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
  BG3_CX = 0;
  BG3_CY = 0;

  BG2_CX = 0;
  BG2_CY = 0;

  for(int i = 0; i < 512*256; i++)
    BG_GFX[i] = ((u16*)topscreen_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    BG_PALETTE[i] = ((u16*)topscreen_pal_bin)[i];
  //for(int i = 0; i < 256; ++i)
  //BG_PALETTE[i] = ((u16*)numbers_pal_bin)[i];

        
  x = 0;
  y = 0;
  px = 128-32;
  py = 103;
  oldx = x;
  oldy = y;
  drag = false;
  touch_down = touchReadXY();

  initSprites();
  
  for(int i=0;i<256*256;i++)
    {
      SPRITE_GFX[i] = i % 256 | ((i % 256) << 8);
    }

  //for(int i = 0; i < 8*8*256/2; ++i)
  //    ((u16*)BG_TILE_RAM(0))[i] = ((u16*)numbers_img_bin)[i];

  //for(int i = 0; i < 32*32; ++i)
  //((u16*)BG_MAP_RAM(8))[i] = i%256;

  /*    for(int y=0;y<64; ++y)
        for(int x=0;x<32; ++x)
        {
        SPRITE_GFX[y*64+x] = ((u16*)sprite_img_bin)[y*32+x];
        }*/

  const u8* frames[16];
  frames[0]  = walk_frame00_img_bin;
  frames[1]  = walk_frame01_img_bin;
  frames[2]  = walk_frame02_img_bin;
  frames[3]  = walk_frame03_img_bin;
  frames[4]  = walk_frame04_img_bin;
  frames[5]  = walk_frame05_img_bin;
  frames[6]  = walk_frame06_img_bin;
  frames[7]  = walk_frame07_img_bin;
  frames[8]  = walk_frame08_img_bin;
  frames[9]  = walk_frame09_img_bin;
  frames[10] = walk_frame10_img_bin;
  frames[11] = walk_frame11_img_bin;
  frames[12] = walk_frame12_img_bin;
  frames[13] = walk_frame13_img_bin;
  frames[14] = walk_frame14_img_bin;
  frames[15] = walk_frame15_img_bin;

  const u8* pal_frames[16];
  pal_frames[0]  = walk_frame00_pal_bin;
  pal_frames[1]  = walk_frame01_pal_bin;
  pal_frames[2]  = walk_frame02_pal_bin;
  pal_frames[3]  = walk_frame03_pal_bin;
  pal_frames[4]  = walk_frame04_pal_bin;
  pal_frames[5]  = walk_frame05_pal_bin;
  pal_frames[6]  = walk_frame06_pal_bin;
  pal_frames[7]  = walk_frame07_pal_bin;
  pal_frames[8]  = walk_frame08_pal_bin;
  pal_frames[9]  = walk_frame09_pal_bin;
  pal_frames[10] = walk_frame10_pal_bin;
  pal_frames[11] = walk_frame11_pal_bin;
  pal_frames[12] = walk_frame12_pal_bin;
  pal_frames[13] = walk_frame13_pal_bin;
  pal_frames[14] = walk_frame14_pal_bin;
  pal_frames[15] = walk_frame15_pal_bin;

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)sprite_img_bin)[i];

  for(int i=0;i<32*32/2; ++i)
    SPRITE_GFX[i+64*32] = ((u16*)use_icon_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i+ (64*32) + (32*16)] = ((u16*)smalldoor_img_bin)[i];

  for(int i=0;i<64*32; ++i)
    SPRITE_GFX[i] = ((u16*)walk_frame00_img_bin)[i];

  for(int i = 0; i < 256; ++i)
    SPRITE_PALETTE[i] = ((u16*)walk_frame00_pal_bin)[i];


  sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_BMP | px;
  sprites[0].attribute[1] = ATTR1_SIZE_64 | py  | ATTR1_FLIP_Y;
  sprites[0].attribute[2] = ATTR2_ALPHA(3);

  sprites[1].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | (192-32-8) | ATTR0_DISABLED;
  sprites[1].attribute[1] = ATTR1_SIZE_32 | (256-32-8);
  sprites[1].attribute[2] = 64*2;//64*64;//64*32;

  sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_COLOR_256 | 90-6;
  sprites[2].attribute[1] = ATTR1_SIZE_64 | 200+16+2;
  sprites[2].attribute[2] = 64*2+32;

  int frame_index = 0;
  int sx = 0;
  //int sy = 0;
  bool left = true;;

  if (subscreen_mode == PDA)
    init_pda();
  else
    init_doorminigame();

  while(1) 
    {
      swiWaitForVBlank();

      frame_index += 1;
      frame_index = frame_index % 80;

      //SPRITE_GFX[i] = ((u16*)numbers_img_bin)[i];


      // read the button states
      scanKeys();
      touch = touchReadXY();

      pressed = keysDown();	// buttons pressed this loop
      held = keysHeld();		// buttons currently held
      
      if (subscreen_mode != DIALOG)
        {
          sprites[0].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(103,512);
          sprites[0].attribute[1] = ATTR1_SIZE_64 | mod(128-32,512) | (left ? 0: ATTR1_FLIP_X);
          sprites[0].attribute[2] = ATTR2_ALPHA(3);

          sprites[2].attribute[0] = ATTR0_SQUARE | ATTR0_TYPE_BLENDED | ATTR0_COLOR_256 | mod(90-6, 512);
          sprites[2].attribute[1] = ATTR1_SIZE_64 | mod((200+16+2 - px + 128-32 + door_pos/4),512);
          sprites[2].attribute[2] = ATTR2_ALPHA(1) | 64*2+32;
        }
      else
        {
          sprites[0].attribute[0] |=  ATTR0_DISABLED;
          sprites[1].attribute[0] |=  ATTR0_DISABLED;
          sprites[2].attribute[0] |=  ATTR0_DISABLED;
        }

      if ((held & KEY_L) && (held & KEY_R))
        swiSoftReset();

      if ((pressed & KEY_LEFT) || (pressed & KEY_RIGHT))
        {
          frame_index = 0;
        }

      if (held & KEY_LEFT)
        {
          left = true;
          px -= 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] & ~ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else if (held & KEY_RIGHT)
        {
          left = false;
          px += 1;
          sprites[0].attribute[1] = sprites[0].attribute[1] | ATTR1_FLIP_X;

          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[frame_index/5])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[frame_index/5])[i];
        }
      else
        {
          for(int i=0;i<64*32; ++i)
            SPRITE_GFX[i] = ((u16*)frames[0])[i];
      
          for(int i = 0; i < 256; ++i)
            SPRITE_PALETTE[i] = ((u16*)pal_frames[0])[i];
        }

      if (held & KEY_DOWN)
        py += 1;
      else if (held & KEY_UP)
        py -= 1;


      if ((px + 128) > 328-16 && 
          (px + 128) < (328+35+16))
        {
          sprites[1].attribute[0] &=  ~ATTR0_DISABLED;
          //if (pressed & KEY_X)
          //            {
          if (subscreen_mode == PDA)
            {
              init_doorminigame();
              subscreen_mode = DOOR_MINIGAME;
            }
          else if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
          //}
        }
      else if ((px + 128) > 133-16 &&
               (px + 128) < 133-16+32)
        {
          init_dialog();
          subscreen_mode = DIALOG;
        }
      else
        {
          sprites[1].attribute[0] |= ATTR0_DISABLED;
          if (subscreen_mode == DOOR_MINIGAME)
            {
              init_pda();
              subscreen_mode = PDA;
            }
        }


      sx = px;
      //sx += 1;
      
      if ((held & KEY_TOUCH)  && drag)
        {
          x = oldx + (touch_down.px - touch.px);
          y = oldy + (touch_down.py - touch.py);
        }

      if (!(held & KEY_TOUCH))
        drag = false;
      
      if (subscreen_mode != DIALOG)
        {
          BG3_CX  = x*500 + sx<<8 ;
          BG3_CY  = y*500 + (32<<8);
        }
      //2_CX  = -x;
      //2_CY  = -y;
      
      update_subscreen();

      updateOAM();
    }
}
void
update_touchscreen (void)
{
  static int graffiti = 0;
  struct MW_UID_MESSAGE m;
  int x, y, k, kh, btns = 0;
  touchPosition pos;
  char c;

  /* update keypad & touchscreen */
  scanKeys ();
  pos = touchReadXY ();
  x = pos.px;
  y = pos.py;
  k = keysDown ();
  kh = keysHeld ();

  /* check for character recognition */
  if ((kh & KEY_L) || (kh & KEY_R)) {
    graffiti = 1;
    c = PA_CheckLetter ((kh & KEY_TOUCH ? 1 : 0), x, y);
    if (c) {
      /* signal the console driver */
      console_push (c);
      if (kbd_queue_id != 0) {
        /* send the read character */
        m.type = MV_UID_KBD;
        m.m.kbd.code = c;
        m.m.kbd.modifiers = 0;
        m.m.kbd.mode = MV_KEY_MODE_ASCII;
        rtems_message_queue_send (kbd_queue_id, (void *) &m,
                                  sizeof (struct MW_UID_MESSAGE));
      }
    }
  } else {
    if (graffiti == 1) {
      x = old_x;
      y = old_y;
    }
    graffiti = 0;
  }

  if (mou_queue_id == 0)
    return;

  if (hand == 1) {
    if (k & KEY_LEFT) {
      btns = MV_BUTTON_LEFT;
    }
    if (k & KEY_RIGHT) {
      btns = MV_BUTTON_RIGHT;
    }
  } else {
    if (k & KEY_A) {
      btns = MV_BUTTON_LEFT;
    }
    if (k & KEY_B) {
      btns = MV_BUTTON_RIGHT;
    }
  }

  if (!((kh & KEY_L) || (kh & KEY_R)) && (kh & KEY_TOUCH)
      && (x != old_x || y != old_y || btns)) {
    /* send the read position */
    m.type = MV_UID_ABS_POS;
    old_btns = m.m.pos.btns = btns;
    old_x = m.m.pos.x = x;
    old_y = m.m.pos.y = y;
    m.m.pos.z = 0;
    rtems_message_queue_send (mou_queue_id, (void *) &m,
                              sizeof (struct MW_UID_MESSAGE));
  }
}
示例#15
0
文件: adrift.cpp 项目: nornagon/torch
void process_keys() {
	if (game.cooldown <= 0) {
		scanKeys();
		u32 keys = keysHeld();
		u32 down = keysDown();
		touchPosition touch = touchReadXY();

		if (down & KEY_START) {
			new_game();
			return;
		}

		if (down & KEY_SELECT) {
			test_map();

			torch.buf.scroll.x = game.player.x - 16;
			torch.buf.scroll.y = game.player.y - 12;
			torch.buf.bounded(torch.buf.scroll.x, torch.buf.scroll.y);
			torch.dirty_screen();
			torch.reset_luminance();

			return;
		}

		if (down & KEY_X) {
			inventory(); return;
		}
		if (down & KEY_L) {
			overview(); return;
		}

		if (down & KEY_TOUCH && touch.px != 0 && touch.py != 0) {
			if (!(keys & KEY_R) && game.player.projectile) {
				game.player.chuck(torch.buf.scroll.x + touch.px/8,
													torch.buf.scroll.y + touch.py/8);
			}
			return;
		}

		if (down & KEY_R) {
			printf("Saving... ");
			fflush(stdout);
			game.save("blah.adrift");
			printf("done\n");
			printf("Loading... ");
			fflush(stdout);
			game.load("blah.adrift");
			printf("done\n");
		}

		if (keys & KEY_Y) {
			if (get_items()) return;
		}

		DIRECTION dir = 0;
		if (keys & KEY_RIGHT)
			dir |= D_EAST;
		else if (keys & KEY_LEFT)
			dir |= D_WEST;
		if (keys & KEY_DOWN)
			dir |= D_SOUTH;
		else if (keys & KEY_UP)
			dir |= D_NORTH;

		if (dir) {
			game.player.moveDir(dir, keys & KEY_B);
			return;
		}

		if (down & KEY_A) {
			seek_and_destroy();
			if (!game.player.target) {
				// no monsters in range
				for (int x = game.player.x-1; x <= game.player.x+1; x++) {
					for (int y = game.player.y-1; y <= game.player.y+1; y++) {
						Object *o = game.map.at(x,y)->objects.head();
						if (!o) continue;
						if (o->type == VENDING_MACHINE) {
							if (game.player.x == x+D_DX[o->orientation] && game.player.y == y+D_DY[o->orientation]) {
								iprintf("You kick the vending machine. ");
								if (o->quantity > 0 && rand4() < 5) {
									if (rand4() & 1) {
										iprintf("Clunk! A can rolls out.\n");
										addObject(game.player.x, game.player.y, CAN_OF_STEWED_BEEF);
									} else {
										iprintf("Clunk! A bottle rolls out.\n");
										addObject(game.player.x, game.player.y, BOTTLE_OF_WATER);
									}
									o->quantity--;
								} else {
									iprintf("Nothing happens.\n");
								}
								game.cooldown += 5;
							}
						}
					}
				}
			} else return;
		}
		if (keys & KEY_A) {
			seek_and_destroy(); return;
		}

	} else if (game.cooldown > 0)
		game.cooldown--;
}