Exemple #1
0
int check_start() {
    maple_device_t *cont;
    cont_state_t *state;

    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    if(cont) {
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state)
            return 0;

        if(state->buttons & CONT_START)
            return 1;

        if(state->buttons & CONT_DPAD_UP)
            my -= 1.0f;

        if(state->buttons & CONT_DPAD_DOWN)
            my += 1.0f;

        if(state->buttons & CONT_DPAD_LEFT)
            mx -= 1.0f;

        if(state->buttons & CONT_DPAD_RIGHT)
            mx += 1.0f;
    }

    return 0;
}
Exemple #2
0
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;

    dbgio_dev_select("fb");

    printf("Opus Decoder Library Example Program\n\n");

    opusplay_init();

    if(opusplay_play_file("/rd/test.opus", 0)) {
        printf("Cannot play /rd/test.opus!\n");
        printf("Did you remember to put an opus file in the\n"
               "romdisk before compiling?\n");
        thd_sleep(10 * 1000);

        opusplay_shutdown();
        snd_stream_shutdown();
        return 0;
    }

    printf("The Opus file should now be playing in a thread...\n\n");
    printf("Press START to exit and (Y) to restart playback.\n");

    while(1) {
        if((cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER))) {
            if((state = (cont_state_t *)maple_dev_status(cont))) {
                if(state->buttons & CONT_START)
                    break;

                if(state->buttons & CONT_Y) {
                    opusplay_stop();
                    opusplay_play_file("/rd/test.opus", 0);
                }
            }

            thd_sleep(100);
        }

    }

    printf("Cleaning up...\n");
    opusplay_stop();
    opusplay_shutdown();
    snd_stream_shutdown();
    return 0;
}
int check_start() {
    maple_device_t *cont;
    cont_state_t *state;

    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    if(cont) {
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state)
            return 0;

        return (state->buttons & CONT_START);
    }
    else
        return 0;
}
Exemple #4
0
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;

    printf("nehe05 beginning\n");

    /* Get basic stuff initialized */
    glKosInit();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    while(1) {
        cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

        /* Check key status */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state) {
            printf("Error reading controller\n");
            break;
        }

        if(state->buttons & CONT_START)
            break;

        /* Draw the "scene" */
        draw_gl();

        /* Finish the frame */
        glutSwapBuffers();
    }

    return 0;
}
Exemple #5
0
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;

    /* Get basic stuff initialized */
    printf("nehe02 beginning\n");
    /* Notice we do not init the PVR here, that is handled by OpenGL */
    glKosInit();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    while(1) {
        cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

        /* Check key status */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state) {
            printf("Error reading controller\n");
            break;
        }

        if(state->buttons & CONT_START)
            break;

        /* Draw the "scene" */
        draw_gl();

        /* Finish the frame - Notice there is no glKosBegin/FinshFrame */
        glutSwapBuffers();
    }

    return 0;
}
Exemple #6
0
void wait_start() {
    maple_device_t *cont;
    cont_state_t *state;

    while(1) {
        cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

        if(!cont) continue;

        /* Check for start on the controller */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state)
            continue;

        if(state->buttons & CONT_START) {
            printf("Pressed start\n");
            return;
        }

        thd_sleep(10);
    }
}
Exemple #7
0
/* Simple Input Callback with a return value */
int InputCallback() {
    maple_device_t *cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    if(cont) {
        cont_state_t *state = (cont_state_t *)maple_dev_status(cont);

        if(!state)
            return 0;

        if(state->buttons & CONT_DPAD_UP)
            return INP_RESIZE_UP;

        if(state->buttons & CONT_DPAD_DOWN)
            return INP_RESIZE_DOWN;

        if(state->buttons & CONT_X)
            return INP_USE_MIP_MAP;

        if(state->buttons & CONT_Y)
            return INP_NO_MIP_MAP;
    }

    return 0;
}
Exemple #8
0
void update()
{
	maple_device_t *cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
	if (cont)
	{
		cont_state_t *state = (cont_state_t *) maple_dev_status(cont);

		if (!state)
			return;

		if (state->buttons & CONT_DPAD_UP || state->buttons & CONT_DPAD2_UP)
		{
			//dbglog(DBG_DEBUG, "\nDPad UP Pressed\n");
			if (stateM == statePaused)
			{
				dbglog(DBG_DEBUG, "\n*** RESUME RENDERING PVR ***\n\n");
				stateM = stateMenu;
			}
			else if (stateM != statePaused)
			{
				dbglog(DBG_DEBUG, "\n*** PAUSE RENDERING PVR ***\n");
				stateM = statePaused;
			}

			usleep(400000);
		}

		if (state->buttons & CONT_DPAD_DOWN || state->buttons & CONT_DPAD2_DOWN)
		{

			dbglog(DBG_DEBUG, "~ Settings ~\n");
			settingDBRead("/hd/settings.conf");

			usleep(400000);
		}

		if (state->buttons & CONT_DPAD_LEFT || state->buttons & CONT_DPAD2_LEFT)
		{
			usleep(400000);
		}

		if (state->buttons & CONT_DPAD_RIGHT || state->buttons & CONT_DPAD2_RIGHT)
		{
		}

		if (state->buttons & CONT_Y)
		{
			//dbglog(DBG_DEBUG, "\nButton Y Pressed\n");
			if (writeRTF())
				dbglog(DBG_DEBUG, "** FS WRITE FAILED!\n");

			if (settingDBWrite("/hd/settings.conf", "CYRUS", "HelloWorld", 1))
				dbglog(DBG_DEBUG, "** Settings Save Failed!\n");

			usleep(400000);
		}

		if (state->buttons & CONT_A)
		{

			dbglog(DBG_DEBUG, "\nBooting romdisk binary...\n");
			if (executeSub("/rd/SUB.ECS"))
				dbglog(DBG_DEBUG, "** EXEC FAILED!\n");
			usleep(400000);

		}

		if (state->buttons & CONT_X)
		{
			//dbglog(DBG_DEBUG, "\nButton X Pressed\n");
			if (mountState)
			{
				mountCTL("/hd", 0);
				mountState = 0;
			}
			else if (!mountState)
			{
				mountCTL("/hd", 1);
				mountState = 1;
			}

			usleep(400000);
		}

		if (state->buttons & CONT_B)
		{
			//dbglog(DBG_DEBUG, "\nButton B Pressed\n");
			bCount += 1;

			if (bCount == 2)
			{
				bCount = 0;
				stateM = stateMenu;
				dbglog(DBG_DEBUG, "~ STATEMACHINE set to Menu\n");
			}
			else if (mountState)
			{
				stateM = statePrintDIR;
				dbglog(DBG_DEBUG, "~ STATEMACHINE set to PrintDIR\n");

			}
			usleep(400000);
		}

		if (state->buttons & CONT_START)
		{
			dbglog(DBG_DEBUG, "\nStart Pressed\n\n");
			shutDown("/hd");
		}
	}
}
int main(int argc, char **argv) {
    
    /* Controller Stuff */
    maple_device_t * dev;
    cont_state_t * state;
    
    int rquad = 0;
    int rtri = 0;
    
	/* Init PVR API */
	if (pvr_init(&params) < 0)
		return -1;
		
	printControls();	

    /* Sets the background color to black */
	pvr_set_bg_color(0.0f,0.0f,0.0f);
	
	plx_cxt_init();                 // Initialize the plx context system
	plx_cxt_texture(NULL);          // No texture will be used
    plx_cxt_culling(PLX_CULL_NONE); // No culling
	
	// GET SOME 3D GOING!!
	/* Init matrices */
	plx_mat3d_init();                    /* Clear internal to an identity matrix */
	plx_mat3d_mode(PLX_MAT_PROJECTION);  /** Projection (frustum, screenview) matrix */
	plx_mat3d_identity();                /** Load an identity matrix */
	plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);  // (float angle, float aspect, float znear, float zfar);
	plx_mat3d_mode(PLX_MAT_MODELVIEW);   /** Modelview (rotate, scale) matrix */
	
	while(1) {
        
        // Check for the user pressing START
		dev = maple_enum_dev(0, 0);
		if(dev == NULL) {
            printf("Error: Could not find controller in first port.\n");
            break;
        }
	    state = (cont_state_t *)maple_dev_status(dev);
	    if (state->buttons & CONT_START) {
		    break;           // exit the program
        }               
		
		pvr_wait_ready();
		pvr_scene_begin();
		pvr_list_begin(PVR_LIST_OP_POLY);
     	
		// Submit the context
		plx_cxt_send(PVR_LIST_OP_POLY);  // Submit the Header for PVR_LIST_OP_POLY
		
		// DRAW THE PYRAMID
	    plx_mat3d_identity();
	    plx_mat3d_translate(-1.5f, 0.0f, -6.0f);  // Move 1.5f units to the left and 6 units into the screen
	    plx_mat3d_rotate(rtri, 0.0f, 1.0f, 0.0f); // Rotate the pyramid angle 'rtri' on the Y axis
  	    
	    /* Clear internal to an identity matrix */
	    plx_mat_identity();
	
    	/* "Applying" all matrixs: multiply a matrix onto the "internal" one */
	    plx_mat3d_apply_all();
	    
	    // Front Face of Pyramid
	    plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));       // Red: Top Of Triangle (Front)
	    plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f));     // Green: Left Of Triangle (Front)
	    plx_vert_inpm3(PLX_VERT_EOS, 1, -1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));  // Blue: Right Of Triangle (Front)
	    
	    // Right Face of Pyramid
	    plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));       // Red: Top Of Triangle (Right)
	    plx_vert_inpm3(PLX_VERT, 1, -1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));      // Blue: Left Of Triangle (Right)
	    plx_vert_inpm3(PLX_VERT_EOS, 1, -1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Green: Right Of Triangle (Right)
	    
	    // Back Face of Pyramid
	    plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));       // Red: Top Of Triangle (Back)
	    plx_vert_inpm3(PLX_VERT, 1, -1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f));     // Green: Left Of Triangle (Back)
	    plx_vert_inpm3(PLX_VERT_EOS, -1, -1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));// Blue: Right Of Triangle (Back)
	    
	    // Left Face of Pyramid
	    plx_vert_inpm3(PLX_VERT, 0, 1, 0, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));       // Red: Top Of Triangle (Left)
	    plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));    // Blue: Left Of Triangle (Left)
	    plx_vert_inpm3(PLX_VERT_EOS, -1, -1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Green: Right Of Triangle (Left)
	    
        // DRAW THE BOX	
        plx_mat3d_identity();
	    plx_mat3d_translate(1.5f, 0.0f, -6.0f);    // Move 1.5f units to the right and 6 units into the screen
	    plx_mat3d_rotate(rquad, 1.0f, 0.0f, 0.0f); // Rotate the box angle 'rquad' on the X axis 
	    
	    /* Clear internal to an identity matrix */
	    plx_mat_identity();
	    
    	/* "Applying" all matrixs: multiply a matrix onto the "internal" one */
	    plx_mat3d_apply_all();
		
		// Top Face of Box (GREEN)
		plx_vert_inpm3(PLX_VERT, -1, 1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f));     // Bottom Left Of The Quad (Top)
		plx_vert_inpm3(PLX_VERT, -1, 1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f));    // Top Left Of The Quad (Top)
		plx_vert_inpm3(PLX_VERT, 1, 1, 1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f));      // Bottom Right Of The Quad (Top)
		plx_vert_inpm3(PLX_VERT_EOS, 1, 1, -1, plx_pack_color(1.0f, 0.0f, 1.0f, 0.0f)); // Top Right Of The Quad (Top)
	    
		// Bottom Face of Box (ORANGE)
		plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f));   // Bottom Left Of The Quad (Bottom)
		plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f));    // Top Left Of The Quad (Bottom)
		plx_vert_inpm3(PLX_VERT, 1, -1, -1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f));    // Bottom Right Of The Quad (Bottom)
		plx_vert_inpm3(PLX_VERT_EOS, 1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.5f, 0.0f)); // Top Right Of The Quad (Bottom)	    
		
		// Front Face of Box (RED)
		plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));    // Bottom Left Of The Quad (Front)
	    plx_vert_inpm3(PLX_VERT, -1, 1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));     // Top Left Of The Quad (Front)
	    plx_vert_inpm3(PLX_VERT, 1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));     // Bottom Right Of The Quad (Front)
	    plx_vert_inpm3(PLX_VERT_EOS, 1, 1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 0.0f));  // Top Right Of The Quad (Front)
		
		// Back Face of Box (YELLOW)
		plx_vert_inpm3(PLX_VERT, -1, 1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f));    // Bottom Left Of The Quad (Back)
	    plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f));   // Top Left Of The Quad (Back)
	    plx_vert_inpm3(PLX_VERT, 1, 1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f));     // Bottom Right Of The Quad (Back)
		plx_vert_inpm3(PLX_VERT_EOS, 1, -1, -1, plx_pack_color(1.0f, 1.0f, 1.0f, 0.0f));// Top Right Of The Quad (Back)
		
		// Left Face of Box (BLUE)
		plx_vert_inpm3(PLX_VERT, -1, -1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));   // Bottom Left Of The Quad (Left)
	    plx_vert_inpm3(PLX_VERT, -1, 1, -1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));    // Top Left Of The Quad (Left)
	    plx_vert_inpm3(PLX_VERT, -1, -1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f));    // Bottom Right Of The Quad (Left)
	    plx_vert_inpm3(PLX_VERT_EOS, -1, 1, 1, plx_pack_color(1.0f, 0.0f, 0.0f, 1.0f)); // Top Right Of The Quad (Left)
	    
		// Right Face of Box (VIOLET)
		plx_vert_inpm3(PLX_VERT, 1, -1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f));     // Bottom Left Of The Quad (Right)
	    plx_vert_inpm3(PLX_VERT, 1, 1, 1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f));      // Top Left Of The Quad (Right)
	    plx_vert_inpm3(PLX_VERT, 1, -1, -1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f));    // Bottom Right Of The Quad (Right)
	    plx_vert_inpm3(PLX_VERT_EOS, 1, 1, -1, plx_pack_color(1.0f, 1.0f, 0.0f, 1.0f)); // Top Right Of The Quad (Right)

		pvr_scene_finish();
		
		rquad -= 2.0f;  // Increases the box's rotation angle
		rtri += 2.0f;   // Increases the pyramid's rotation angle
    }

	return 0;
}
Exemple #10
0
static int rip_sec(int tn,int first,int count,int type,char *dst_file, int disc_type){

double percent,percent_last=0.0;
maple_device_t *cont;
cont_state_t *state;
file_t hnd;
int secbyte = (type == 4 ? 2048 : 2352) , i , count_old=count, bad=0, cdstat, readi;
uint8 *buffer = (uint8 *)memalign(32, SEC_BUF_SIZE * secbyte);
	
	GUI_WidgetMarkChanged(self.app->body);
//	ds_printf("Track %d		First %d	Count %d	Type %d\n",tn,first,count,type);
/*	if (secbyte == 2048) cdrom_set_sector_size (secbyte);
	else _cdrom_reinit (1);
*/
	cdrom_set_sector_size (secbyte);
	
	if ((hnd = fs_open(dst_file,O_WRONLY | O_TRUNC | O_CREAT)) == FILEHND_INVALID) {
		ds_printf("Error open file %s\n" ,dst_file); 
		cdrom_spin_down(); free(buffer); 
		return CMD_ERROR;
		}
	
	LockVideo();
	
	while(count) {
	
		int nsects = count > SEC_BUF_SIZE ? SEC_BUF_SIZE : count;
		count -= nsects;
		
		
		while((cdstat=cdrom_read_sectors(buffer, first, nsects)) != ERR_OK ) {
			if (atoi(GUI_TextEntryGetText(self.num_read)) == 0) break;
			readi++ ;
			if (readi > 5) break ;
			thd_sleep(200);
		}
			readi = 0;
		if (cdstat != ERR_OK) {
			if (!GUI_WidgetGetState(self.bad)) {
				UnlockVideo();
				GUI_ProgressBarSetPosition(self.read_error, 1.0);
				for(;;) {
					cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
					
					if(!cont) continue;
					state = (cont_state_t *)maple_dev_status(cont);
					
					if(!state) continue;
					if(state->buttons & CONT_A) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						ds_printf("DS_ERROR: Can't read sector %ld\n", first); 
						free(buffer); 
						fs_close(hnd); 
						return CMD_ERROR;
					} else if(state->buttons & CONT_B) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					} else if(state->buttons & CONT_Y) {
						GUI_ProgressBarSetPosition(self.read_error, 0.0); 
						GUI_WidgetSetState(self.bad, 1);
						GUI_WidgetMarkChanged(self.app->body); 
						break;
					}
				}
			}
			// Ошибка, попробуем по одному
			uint8 *pbuffer = buffer;
			LockVideo();
			for(i = 0; i < nsects; i++) {
				
				while((cdstat=cdrom_read_sectors(pbuffer, first, 1)) != ERR_OK ) {
				readi++ ;
				if (readi > atoi(GUI_TextEntryGetText(self.num_read))) break ;
				if (readi == 1 || readi == 6 || readi == 11 || readi == 16 || readi == 21 || readi == 26 || readi == 31 || readi == 36 || readi == 41 || readi == 46) cdrom_reinit();
				thd_sleep(200);
				}
				readi = 0;
				
				if (cdstat != ERR_OK) {
					// Ошибка, заполним нулями и игнорируем
					UnlockVideo();
					cdrom_reinit();
					memset(pbuffer, 0, secbyte);
					bad++;
					ds_printf("DS_ERROR: Can't read sector %ld\n", first);
					LockVideo();
				}
			
				pbuffer += secbyte;
				first++;
			}
		
		} else {
			// Все ок, идем дальше
			first += nsects;
		}
	
		if(fs_write(hnd, buffer, nsects * secbyte) < 0) {
			// Ошибка записи, печально, прерываем процесс
			UnlockVideo();
			free(buffer);
			fs_close(hnd);
			return CMD_ERROR;
		}
		UnlockVideo();
		percent = 1-(float)(count) / count_old;
		if ((percent = ((int)(percent*100 + 0.5))/100.0) > percent_last) {
		percent_last = percent;
		GUI_ProgressBarSetPosition(self.pbar, percent);
		LockVideo();
		}
	}
UnlockVideo();
free(buffer);
fs_close(hnd);
ds_printf("%d Bad sectors on track\n", bad);
return CMD_OK;
}
int main(int argc, char **argv) {
    
    /* Controller Stuff */
    maple_device_t * dev;
    cont_state_t * state;
    
    int x, y;
    float xrot = 0;	/* X Rotation */
    float yrot = 0;	/* Y Rotation */
    float zrot = 0;	/* Z Rotation */
    float points[45][45][3];    // The Array For The Points On The Grid Of Our "Wave"
    int wiggle_count = 0;		// Counter Used To Control How Fast Flag Waves
    float hold;					// Temporarily Holds A Floating Point Value
    
    uint32 color = plx_pack_color(1.0f, 1.0f, 1.0f, 1.0f);  // Pure white color.  Used for images to keep original color
    plx_texture_t *a_texture;  // Storage for 1 texture
    
    float float_x, float_y, float_xb, float_yb;       // loop counters.
    
	/* Init PVR API */
	if (pvr_init(&params) < 0)
		return -1;

    printControls();

    /* Sets the background color to blue */
	pvr_set_bg_color(0.0f, 0.0f, 1.0f);
	
	/* Load the texture */
	a_texture = plx_txr_load("/rd/tim.png", 0, PVR_TXRLOAD_16BPP);
	
	plx_cxt_init();                  // Initialize the plx context system
	plx_cxt_texture(a_texture);      // Texture 'a_texture' will be used with the context system 
    plx_cxt_culling(PLX_CULL_NONE);  // No culling
	
	// GET SOME 3D GOING!!
	plx_mat3d_init();                    /* Clear internal to an identity matrix */
	plx_mat3d_mode(PLX_MAT_PROJECTION);  /** Projection (frustum, screenview) matrix */
	plx_mat3d_identity();                /** Load an identity matrix */
	plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);  // (float angle, float aspect, float znear, float zfar);
	plx_mat3d_mode(PLX_MAT_MODELVIEW);   /** Modelview (rotate, scale) matrix */
	
	for(float_x = 0.0f; float_x < 9.0f; float_x +=  0.2f )	{
	    for(float_y = 0.0f; float_y < 9.0f; float_y += 0.2f)		{
	        points[ (int) (float_x*5) ][ (int) (float_y*5) ][0] = float_x - 4.4f;
	        points[ (int) (float_x*5) ][ (int) (float_y*5) ][1] = float_y - 4.4f;
	        points[ (int) (float_x*5) ][ (int) (float_y*5) ][2] = (float) (fsin( ( (float_x*5*8)/360 ) * 3.14159 * 2));
	    }
    }
	
	while(1) {
        
        // Check for the user pressing START
		dev = maple_enum_dev(0, 0);
		if(dev == NULL) {
            printf("Error: Could not find controller in first port.\n");
            break;
        }
	    state = (cont_state_t *)maple_dev_status(dev);
	    if (state->buttons & CONT_START) {
		    break;           // exit the program
        }          
		
		pvr_wait_ready();
		pvr_scene_begin();
		pvr_list_begin(PVR_LIST_OP_POLY);
     	
		// Submit the context
		plx_cxt_send(PVR_LIST_OP_POLY);     // Submit the Header for PVR_LIST_OP_POLY 
		
        // DRAW THE BOX	
        plx_mat3d_identity();
	    plx_mat3d_translate(0.0f, 0.0f, -12.0f);  // Move 12 units into the screen
	    plx_mat3d_rotate(xrot, 1.0f, 0.0f, 0.0f); // Rotate the Wavy texture angle 'xrot' on the X axis  
	    plx_mat3d_rotate(yrot, 0.0f, 1.0f, 0.0f); // Rotate the Wavy texture angle 'yrot' on the Y axis  
	    plx_mat3d_rotate(zrot, 0.0f, 0.0f, 1.0f); // Rotate the Wavy texture angle 'zrot' on the Z axis  
	    
	    /* Clear internal to an identity matrix */
	    plx_mat_identity();
	    
    	/* "Applying" all matrixs: multiply a matrix onto the "internal" one */
        plx_mat3d_apply_all();
	    
        // Draw each section of the image
    	for (x = 0; x < 44; x++) {
	        for (y = 0; y < 44; y++) {
	            float_x  = (float) (x)/44;
	            float_y  = (float) (y)/44;
	            float_xb = (float) (x+1)/44;
	            float_yb = (float) (y+1)/44;
             
                plx_vert_ifpm3(PLX_VERT, points[x][y+1][0], points[x][y+1][1], points[x][y+1][2], color, float_x, float_yb);         
                plx_vert_ifpm3(PLX_VERT, points[x][y][0], points[x][y][1], points[x][y][2], color, float_x, float_y);                
                plx_vert_ifpm3(PLX_VERT, points[x+1][y+1][0], points[x+1][y+1][1], points[x+1][y+1][2], color, float_xb, float_yb);  
                plx_vert_ifpm3(PLX_VERT_EOS, points[x+1][y][0], points[x+1][y][1], points[x+1][y][2], color, float_xb, float_y);     
	        }
        }

		pvr_scene_finish();
        
        
        if (wiggle_count == 2) {            // Used To Slow Down The Wave (Every 2nd Frame Only)
	        for( y = 0; y < 45; y++ )		// Loop Through The Y Plane
		    {
			    hold = points[0][y][2];		// Store Current Value One Left Side Of Wave
			    for( x = 0; x < 44; x++)	// Loop Through The X Plane
			    {
				    // Current Wave Value Equals Value To The Right
				    points[x][y][2] = points[x+1][y][2];
			    }
			    points[44][y][2] = hold;	// Last Value Becomes The Far Left Stored Value
		    }
		    wiggle_count = 0;				// Set Counter Back To Zero
    	}
	    wiggle_count++;						// Increase The Counter

        xrot += 0.3f;  // Increase the Wavy Texture's angle(x-axis) rotation
        yrot += 0.2f;  // Increase the Wavy Texture's angle(y-axis) rotation
        zrot += 0.4f;  // Increase the Wavy Texture's angle(z-axis) rotation
    }
    // Clean up!!!
    plx_txr_destroy(a_texture);
    
	return 0;
}
Exemple #12
0
/* Handle controller input */
void check_controller() {
    static int up_moved = 0, down_moved = 0, a_pressed = 0, y_pressed = 0;
    maple_device_t *cont;
    cont_state_t *state;

    if((!(sndoggvorbis_isplaying())) && (lst_playing != -1)) {
        lst_playing++;

        if(lst_playing == lst_size) {
            printf("DEBUG: Reached end of playlist...\r\n");
            lst_playing = -1;
            lst_size = 0;
        }
        else {
            printf("DEBUG: Next song in playlist...\r\n");
            start(lst_entries[lst_playing].fn);
        }
    }

    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    if(!cont) {
        return;
    }

    state = (cont_state_t *)maple_dev_status(cont);

    if(!state) {
        return;
    }

    if(state->buttons & CONT_DPAD_UP) {
        if((framecnt - up_moved) > 10) {
            if(selected > 0) {
                selected--;

                if(selected < top) {
                    top = selected;
                }
            }

            up_moved = framecnt;
        }
    }

    if(state->buttons & CONT_DPAD_DOWN) {
        if((framecnt - down_moved) > 10) {
            if(selected < (num_entries - 1)) {
                selected++;

//              if (selected >= (top+14)) {
                if(selected >= (top + 10)) {
                    top++;
                }
            }

            down_moved = framecnt;
        }
    }

    if(state->ltrig > 0) {
        if((framecnt - up_moved) > 10) {
//          selected -= 14;
            selected -= 10;

            if(selected < 0) selected = 0;

            if(selected < top) top = selected;

            up_moved = framecnt;
        }
    }

    if(state->rtrig > 0) {
        if((framecnt - down_moved) > 10) {
//          selected += 14;
            selected += 10;

            if(selected > (num_entries - 1))
                selected = num_entries - 1;

//          if (selected >= (top+14))
            if(selected >= (top + 10))
                top = selected;

            down_moved = framecnt;
        }
    }

    if((state->buttons & CONT_B) && sndoggvorbis_isplaying()) {
        stop();
    }

    if(state->buttons & CONT_Y) {
        if((framecnt - y_pressed) > 10) {
            strcat(workstring, curdir);
            strcat(workstring, "/");
            strcat(workstring, entries[selected].fn);
            strcpy(lst_entries[lst_size].fn, workstring);

            printf("DEBUG: Entry %d : %s\r\n", lst_size, lst_entries[lst_size].fn);

            workstring[0] = 0;

            lst_size++;

        }

        y_pressed = framecnt;
    }

    if((state->buttons & CONT_A) && !load_queued) {
        if((framecnt - a_pressed) > 10) {
            if(!strcmp(entries[selected].fn, "Error!")) {
                num_entries = 0;
            }
            else if(lst_size > 0) {
                printf("DEBUG: Playing playlist...\r\n");
                lst_playing = 0;
                stop();
                start(lst_entries[lst_playing].fn);
                // sndoggvorbis_wait_play();
            }
            else if(entries[selected].size >= 0) {
                stop();
                strcpy(playdir, curdir);
                strcat(loadme, curdir);
                strcat(loadme, "/");
                strcat(loadme, entries[selected].fn);
                start(loadme);
                loadme[0] = 0;
                iplaying = selected;
            }
            else {
                if(!strcmp(entries[selected].fn, "<..>")) {
                    int i;

                    for(i = strlen(curdir); i > 0; i--) {
                        if(curdir[i] == '/') {
                            curdir[i] = 0;
                            break;
                        }
                        else {
                            curdir[i] = 0;
                        }
                    }
                }
                else {
                    if(strcmp(curdir, "/"))
                        strcat(curdir, "/");

                    strcat(curdir, entries[selected].fn);
                }

                mutex_lock(mut);
                selected = top = num_entries = 0;
                mutex_unlock(mut);
                printf("current directory is now '%s'\n", curdir);
            }
        }

        a_pressed = framecnt;
    }
}
int main(int argc, char **argv) {
    
    /* Controller Stuff */
    maple_device_t * dev;
    cont_state_t * state;
    int xp = 0;    // False (True or False: Pressed X button last) Toggles Filtering
    int yp = 0;    // False (True or False: Pressed Y button last) Toggles Transparency
    int blend = 0; // blending on/off
    
    float x_m, y_m, z_m, u_m, v_m;
    float xtrans, ztrans, ytrans;
    float sceneroty;
    int numtriangles;
    
    int filter = 0;   // texture filtering method to use (NONE or BILINEAR)
    uint32 color = plx_pack_color(0.5f, 1.0f, 1.0f, 1.0f);

	/* Init PVR API */
	if (pvr_init(&params) < 0)
		return -1;
		
	printControls();	
    
    /* Sets the background color to black */
	pvr_set_bg_color(0.0f, 0.0f, 0.0f);

	/* load our world from romdisk */
    SetupWorld();
	
	/* Load the textures */
	textures[0] = plx_txr_load("/rd/mud.png", 0, PVR_TXRLOAD_16BPP | PVR_TXRLOAD_INVERT_Y);  
	textures[1] = plx_txr_load("/rd/mud.png", 0, PVR_TXRLOAD_16BPP | PVR_TXRLOAD_INVERT_Y);  

	plx_cxt_init();                 // Initialize the plx context system
    plx_cxt_culling(PLX_CULL_NONE); // No culling
	
	// GET SOME 3D GOING!!
	plx_mat3d_init();                    /* Clear internal to an identity matrix */
	plx_mat3d_mode(PLX_MAT_PROJECTION);  /** Projection (frustum, screenview) matrix */
	plx_mat3d_identity();                /** Load an identity matrix */
	plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);  // (float angle, float aspect, float znear, float zfar);
	plx_mat3d_mode(PLX_MAT_MODELVIEW);   /** Modelview (rotate, scale) matrix */
	
	/* Set the filters for each texture */
	plx_txr_setfilter(textures[0], PLX_FILTER_NONE);
	plx_txr_setfilter(textures[1], PLX_FILTER_BILINEAR);
	
	while(1) {
             
        /* Check key status */
		dev = maple_enum_dev(0, 0);
	    if(dev == NULL) {
            printf("Error: Could not find controller in first port.\n");
            break;
        }
        state = (cont_state_t *)maple_dev_status(dev);
	    if (state->buttons & CONT_START) {
            break;           // exit the program
        }   
        if (state->buttons & CONT_X && !xp) {
            xp = 1;           
            filter += 1;     // Toggle Filter 
            if (filter > 1)
                filter = 0;
        } 
        if (!(state->buttons & CONT_X)) {
            xp = 0;
        }
        if (state->buttons & CONT_Y && !yp) {
            yp = 1;
            blend = !blend;  // Toggle Blending
        } 
        if (!(state->buttons & CONT_Y)) {
            yp = 0;
        }
        if (state->buttons & CONT_A) {
            lookupdown -= 1.0f;  // look up
        } 
        if (state->buttons & CONT_B) {
            lookupdown += 1.0f;  // look down
        } 
        if (state->buttons & CONT_DPAD_UP) {
            xpos -= fsin(yrot*piover180) * 0.05f;  // moves you forward(bobbing head)
            zpos -= fcos(yrot*piover180) * 0.05f;	
            if (walkbiasangle >= 359.0f) {
                walkbiasangle = 0.0f;	
            } else {
                walkbiasangle += 10.0f;
            }
            walkbias = fsin(walkbiasangle * piover180)/20.0f;
        } 
        if (state->buttons & CONT_DPAD_DOWN) {
            xpos += fsin(yrot*piover180) * 0.05f;  // moves you backward(bobbing head)
            zpos += fcos(yrot*piover180) * 0.05f;	
            if (walkbiasangle <= 1.0f) {
                walkbiasangle = 359.0f;	
            } else {
                walkbiasangle -= 10.0f;
            }
            walkbias = fsin(walkbiasangle * piover180)/20.0f;
        }   
        if (state->buttons & CONT_DPAD_LEFT) {
            yrot += 1.5f;    // Turn Left
        } 
        if (state->buttons & CONT_DPAD_RIGHT) {
            yrot -= 1.5f;	  // Turn Right   
        }         
                 
		pvr_wait_ready();
		pvr_scene_begin();
		
	    if(blend) {
		    pvr_list_begin(PVR_LIST_TR_POLY);
		    plx_cxt_send(PVR_LIST_TR_POLY);     // Submit the Header for PVR_LIST_TR_POLY
        } else {
            pvr_list_begin(PVR_LIST_OP_POLY);
		    plx_cxt_send(PVR_LIST_OP_POLY);     // Submit the Header for PVR_LIST_OP_POLY 
        }
		
		/* Select texture according to filter */
		plx_cxt_texture(textures[filter]);
		
	    xtrans = -xpos;   // Used For Player Translation On The X Axis    
        ztrans = -zpos;   // Used For Player Translation On The Z Axis
        ytrans = -walkbias - 0.25f;  // Used For Bouncing Motion Up And Down
        sceneroty = 360.0f - yrot;   // 360 Degree Angle For Player Direction
        
        plx_mat3d_identity();                                           
        plx_mat3d_rotate(lookupdown, 1.0f, 0.0f, 0.0f); // Rotate Up And Down To Look Up And Down             
        plx_mat3d_rotate(sceneroty, 0.0f, 1.0f, 0.0f);  // Rotate Depending On Direction Player Is Facing 
        plx_mat3d_translate(xtrans, ytrans, ztrans);    // Translate The Scene Based On Player Position          
	    
        /* Clear internal to an identity matrix */
        plx_mat_identity();
	    
	    /* "Applying" all matrixs: multiply a matrix onto the "internal" one */
        plx_mat3d_apply_all();
		    
		numtriangles = sector1.numtriangles;    
	
        for (loop = 0; loop < numtriangles; loop++) {        // loop through all the triangles
 
	        // Vertex 1
	        x_m = sector1.triangle[loop].vertex[0].x;
	        y_m = sector1.triangle[loop].vertex[0].y;
	        z_m = sector1.triangle[loop].vertex[0].z;
	        u_m = sector1.triangle[loop].vertex[0].u;
	        v_m = sector1.triangle[loop].vertex[0].v;
	        plx_vert_ifpm3(PLX_VERT, x_m, y_m, z_m, color, u_m, v_m);
	        
	        // Vertex 2
	        x_m = sector1.triangle[loop].vertex[1].x;
	        y_m = sector1.triangle[loop].vertex[1].y;
	        z_m = sector1.triangle[loop].vertex[1].z;
	        u_m = sector1.triangle[loop].vertex[1].u;
	        v_m = sector1.triangle[loop].vertex[1].v;
	        plx_vert_ifpm3(PLX_VERT, x_m, y_m, z_m, color, u_m, v_m);
	        
	         // Vertex 3
	        x_m = sector1.triangle[loop].vertex[2].x;
	        y_m = sector1.triangle[loop].vertex[2].y;
	        z_m = sector1.triangle[loop].vertex[2].z;
	        u_m = sector1.triangle[loop].vertex[2].u;
	        v_m = sector1.triangle[loop].vertex[2].v;
	        plx_vert_ifpm3(PLX_VERT_EOS, x_m, y_m, z_m, color, u_m, v_m);
	        
        }
        pvr_scene_finish();      
    }
    // Clean up!!!
    free(sector1.triangle);
    plx_txr_destroy(textures[0]);
    plx_txr_destroy(textures[1]);
    
	return 0;
}
Exemple #14
0
int builtin_dreameye_cmd(int argc, char *argv[]) {
    
    if(argc < 2) {
		ds_printf("Usage: %s options args...\n"
					"Options: \n"
					" -g, --grab    -Grab images from dreameye and save to file\n"
					" -e, --erase   -Erase images from dreameye\n"
					" -c, --count   -Get images count\n"
					" -p, --param   -Get param\n\n"
					"Arguments: \n"
					" -f, --file    -File for save image\n"
					" -d, --dir     -Directory for save all images\n"
					" -n, --num     -Image number for grab or erase (doesn't set it for all)\n\n"
					"Example: %s -g -n 2 -f /sd/photo.jpg\n"
					"         %s -g -d /sd", argv[0], argv[0], argv[0]);
		return CMD_NO_ARG; 
    } 

	/* Arguments */
	int grab = 0, count = 0, erase = 0, param = 0;
	char *file = NULL, *dir = NULL;
	int num = -1;
	
	/* Buffers */
	char fn[MAX_FN_LEN];
	uint8 *buf;
	int size, err, i;
	
	/* Device state */
	maple_device_t *dreameye;
	dreameye_state_t *state;

	struct cfg_option options[] = {
		{"grab",  'g', NULL, CFG_BOOL, (void *) &grab,  0},
		{"count", 'c', NULL, CFG_BOOL, (void *) &count, 0},
		{"erase", 'e', NULL, CFG_BOOL, (void *) &erase, 0},
		{"param", 'p', NULL, CFG_BOOL, (void *) &param, 0},
		{"file",  'f', NULL, CFG_STR,  (void *) &file,  0},
		{"num",   'n', NULL, CFG_INT,  (void *) &num,   0},
		{"dir",   'd', NULL, CFG_STR,  (void *) &dir,   0},
		CFG_END_OF_LIST
	};
  
  	CMD_DEFAULT_ARGS_PARSER(options);
	
	dreameye = maple_enum_type(0, MAPLE_FUNC_CAMERA);

	if(!dreameye) {
		ds_printf("DS_ERROR: Couldn't find any attached devices, bailing out.\n");
		return CMD_ERROR;
	}

	state = (dreameye_state_t *)maple_dev_status(dreameye);
	
	if(param) {
		
		uint16 val;

		while(++num < 0x20) {
			dreameye_get_param(dreameye, DREAMEYE_COND_REG_JANGGU, num & 0xff, &val);
			ds_printf("0x%02x = 0x%02x\n", num & 0xff, val & 0xff);
		}

		return CMD_OK;
	}

	/* Get count option */
	if(count) {

		ds_printf("DS_PROCESS: Attempting to grab the number of saved images...\n");
		dreameye_get_image_count(dreameye, 1);

		if(state->image_count_valid && state->image_count > 0) {
			ds_printf("DS_INFO: Count of images: %d\n", state->image_count);
		} else {
			ds_printf("DS_INFO: No images avaible.\n");
		}
	}

	/* Grap data option */
	if(grab) {

		ds_printf("DS_PROCESS: Attempting to grab the %s...\n", (num > -1 ? "image" : "all images"));
		
		if(num < 0) {

			dreameye_get_image_count(dreameye, 1);

			if(!state->image_count_valid || !state->image_count) {
				ds_printf("DS_ERROR: No images avaible.\n");
				return CMD_ERROR;
			}

			for(i = 2; i < state->image_count + 2; i++) {

				err = dreameye_get_image(dreameye, i, &buf, &size);

				if(err != MAPLE_EOK) {
					ds_printf("DS_ERROR: No image data at index: %d\n", i);
					break;
				}

				sprintf(fn, "%s/photo_%d.jpg", dir, i);
				ds_printf("DS_OK: Image received successfully. Writing %d bytes to %s\n", size, fn);

				if(save_image(fn, buf, size) < 0) {
					ds_printf("DS_ERROR: Couldn't save image to %s\n", fn);
				}

				free(buf);
			}

		} else {

			if(num < 2) {
				err = dreameye_get_video_frame(dreameye, num, &buf, &size);
			} else {
				err = dreameye_get_image(dreameye, num, &buf, &size);
			}

			if(err != MAPLE_EOK) {
				ds_printf("DS_ERROR: No image data at index: %d\n", num);
				return CMD_ERROR;
			}

			ds_printf("DS_OK: Image received successfully. Writing %d bytes to %s\n", size, file);

			if(save_image(file, buf, size) < 0) {
				ds_printf("DS_ERROR: Couldn't save image to %s\n", file);
				free(buf);
				return CMD_ERROR;
			}

			free(buf);
		}

		ds_printf("DS_OK: Complete.\n");
		return CMD_OK;
	}

	/* Erase option */
	if(erase) {
		
		if(num < 2 || num > 33) {
			ds_printf("DS_ERROR: Wrong image index: %d\n", num);
			return CMD_ERROR;
		}

		ds_printf("DS_PROCESS: Erasing %s...\n", (num > 1 ? "image" : "all images"));

		err = dreameye_erase_image(dreameye, (num > 1 ? num : 0xFF), 1);

		if(err != MAPLE_EOK) {
			
			if(num > -1) {
				ds_printf("DS_ERROR: Couldn't erase image at index: %d\n", num);
			} else {
				ds_printf("DS_ERROR: Couldn't erase all images\n");
			}
			
			return CMD_ERROR;
		}

		ds_printf("DS_OK: Complete.\n");
		return CMD_OK;
	}

	return (!count ? CMD_NO_ARG : CMD_OK);
}
Exemple #15
0
int PERDCHandleEvents(void)	{
    maple_device_t *dev;

    dev = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
    if(dev != NULL) {
        cont_state_t *state = (cont_state_t *) maple_dev_status(dev);

        if(state != NULL)   {
            if(state->buttons & CONT_DPAD_UP)
                *pad1->padbits &= 0xEF;
            else
                *pad1->padbits |= 0x10;

            if(state->buttons & CONT_DPAD_DOWN)
                *pad1->padbits &= 0xDF;
            else
                *pad1->padbits |= 0x20;

            if(state->buttons & CONT_DPAD_RIGHT)
                *pad1->padbits &= 0x7F;
            else
                *pad1->padbits |= 0x80;

            if(state->buttons & CONT_DPAD_LEFT)
                *pad1->padbits &= 0xBF;
            else
                *pad1->padbits |= 0x40;

            if(state->buttons & CONT_START)
                *pad1->padbits &= 0xF7;
            else
                *pad1->padbits |= 0x08;

            if(state->buttons & CONT_A)
                *pad1->padbits &= 0xFB;
            else
                *pad1->padbits |= 0x04;

            if(state->buttons & CONT_B)
                *pad1->padbits &= 0xFE;
            else
                *pad1->padbits |= 0x01;

            if(state->buttons & CONT_X)
                *(pad1->padbits + 1) &= 0xBF;
            else
                *(pad1->padbits + 1) |= 0x40;

            if(state->buttons & CONT_Y)
                *(pad1->padbits + 1) &= 0xDF;
            else
                *(pad1->padbits + 1) |= 0x20;

            if(state->rtrig > 20)
                *(pad1->padbits + 1) &= 0x7F;
            else
                *(pad1->padbits + 1) |= 0x80;

            if(state->ltrig > 20)
                *(pad1->padbits + 1) &= 0xF7;
            else
                *(pad1->padbits + 1) |= 0x08;

            if(state->joyx > 20)
                *pad1->padbits &= 0xFD;
            else
                *pad1->padbits |= 0x02;

            if(state->joyy > 20)
                *(pad1->padbits + 1) &= 0xEF;
            else
                *(pad1->padbits + 1) |= 0x10;

        }
    }

    YabauseExec();

	return 0;
}
Exemple #16
0
int main(int argc, char **argv) {
    maple_device_t *cont;
    cont_state_t *state;
    float   r = 0.0f;
    float   dr = 2.0f;
    float   z = -14.0f;
    GLuint  texture;
    int trans = 0;

    /* Initialize KOS */
    dbglog_set_level(DBG_WARNING);
    pvr_init_defaults();

    printf("gltest beginning\n");

    /* Get basic stuff initialized */
    glKosInit();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, vid_mode->width / (GLfloat)vid_mode->height, 0.1f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);

    /* Expect CW vertex order */
    glFrontFace(GL_CW);

    /* Enable Transparancy */
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    /* Load a texture and make it look nice */
    loadtxr("/rd/glass.pvr", &texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_FILTER, GL_FILTER_BILINEAR);
    glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATEALPHA);


    printf("texture is %08x\n", texture);

    Cube *cubes[4] = {
        new Cube(-5.0f, 0.0f, 0.0f),
        new Cube(5.0f, 0.0f, 0.0f),
        new Cube(0.0f, 5.0f, 0.0f),
        new Cube(0.0f, -5.0f, 0.0f)
    };
    cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);

    while(1) {
        /* Check key status */
        state = (cont_state_t *)maple_dev_status(cont);

        if(!state) {
            printf("Error reading controller\n");
            break;
        }

        if(state->buttons & CONT_START)
            break;

        if(state->buttons & CONT_DPAD_UP)
            z -= 0.1f;

        if(state->buttons & CONT_DPAD_DOWN)
            z += 0.1f;

        if(state->buttons & CONT_DPAD_LEFT) {
            /* If manual rotation is requested, then stop
               the automated rotation */
            dr = 0.0f;

            for(int i = 0; i < 4; i++)
                cubes[i]->rotate(- 2.0f);

            r -= 2.0f;
        }

        if(state->buttons & CONT_DPAD_RIGHT) {
            dr = 0.0f;

            for(int i = 0; i < 4; i++)
                cubes[i]->rotate(+ 2.0f);

            r += 2.0f;
        }

        if(state->buttons & CONT_A) {
            /* This weird logic is to avoid bouncing back
               and forth before the user lets go of the
               button. */
            if(!(trans & 0x1000)) {
                if(trans == 0)
                    trans = 0x1001;
                else
                    trans = 0x1000;
            }
        }
        else {
            trans &= ~0x1000;
        }

        for(int i = 0; i < 4; i++)
            cubes[i]->rotate(dr);

        r += dr;

        /* Draw four objects */
        glLoadIdentity();
        glTranslatef(0.0f, 0.0f, z);
        glRotatef(r, 0.0f, 1.0f, 0.5f);

        cubes[0]->draw();
        cubes[1]->draw();

        /* Potentially do two as translucent */
        if(trans & 1) {
            glEnable(GL_BLEND);
            glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
            glDisable(GL_CULL_FACE);
        }

        cubes[2]->draw();
        cubes[3]->draw();

        if(trans & 1) {
            glEnable(GL_CULL_FACE);
			glDisable(GL_BLEND);
        }

        /* Finish the frame */
        glutSwapBuffers();            
    }

    for(int i = 0; i < 4; i++)
        delete cubes[i];

	glDeleteTextures(1, &texture);

    return 0;
}
Exemple #17
0
int main(int argc, char **argv) {

    /* Controller Stuff */
    maple_device_t * dev;
    cont_state_t * state;

    Model *pModel = NULL;	// Holds The Model Data
    float  yrot = 0.0f;		// Y Rotation

    /* vector_t defined in C:\cygwin\usr\local\dc\kos\kos\addons\include\kos\vector.h */
    /* Holds 3 floats */
    vector_t eye = {75.0f, 75.0f, 75.0f};
    vector_t center = {0.0f, 0.0f, 0.0f};
    vector_t up = {0.0f, 1.0f, 0.0f};

    /* Init PVR API */
    if (pvr_init(&params) < 0)
        return -1;

    printControls();

    /* Sets the background color to black */
    pvr_set_bg_color(0.0f, 0.0f, 0.0f);

    /* Load the model */
    pModel = new MilkshapeModel();
    if ( pModel->loadModelData( "/rd/model.ms3d" ) == false )		// Loads The Model And Checks For Errors
    {
        printf("Couldn't load the model data /rd/model.ms3d \n");
        return 0;													// If Model Didn't Load Quit
    }

    // GET SOME 3D GOING!!
    plx_mat3d_init();                    /* Clear internal to an identity matrix */
    plx_mat3d_mode(PLX_MAT_PROJECTION);  /** Projection (frustum, screenview) matrix */
    plx_mat3d_identity();                /** Load an identity matrix */
    plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 1000.0f);  // (float angle, float aspect, float znear, float zfar);
    plx_mat3d_mode(PLX_MAT_MODELVIEW);   /** Modelview (rotate, scale) matrix */

    pModel->reloadTextures();	// Loads Model Textures

    while(1) {

        /* Check key status */
        dev = maple_enum_dev(0, 0);
        if(dev == NULL) {
            printf("Error: Could not find controller in first port.\n");
            break;
        }
        state = (cont_state_t *)maple_dev_status(dev);
        if (state->buttons & CONT_START) {
            break;           // exit the program
        }

        pvr_wait_ready();
        pvr_scene_begin();
        pvr_list_begin(PVR_LIST_OP_POLY);

        plx_mat3d_identity();
        plx_mat3d_lookat(&eye,&center,&up);  /* Do a camera "look at" */
        plx_mat3d_rotate(yrot, 0.0f, 1.0f, 0.0f);  /* Rotate the model by 'yrot' degrees on the Y-Axis */

        /* Clear internal to an identity matrix */
        plx_mat_identity();

        /* "Apply" all matrices */
        plx_mat3d_apply_all();

        /* Draw the Model */
        pModel->draw();

        pvr_scene_finish();

        yrot += 1.0f;	// Increase the 'yrot' angle
    }
    // Clean Up!!!
    pModel->destroyModel();

    return 0;
}
Exemple #18
0
int main(int argc, char *argv[]) {
    maple_device_t *dreameye;
    dreameye_state_t *state;
    uint8 *buf;
    int size, err;
    FILE *fp;
    int img_count, i;
    char fn[64];
    kos_blockdev_t sd_dev;
    uint8 partition_type;

    /* We're not using these, obviously... */
    (void)argc;
    (void)argv;

    /* Comment this out if you'd rather that debug output went to dcload. Of
       course, you'll need to be using dcload-ip, but you should have already
       known that. ;-) */
    dbgio_dev_select("fb");

    printf("KallistiOS Dreameye Image Dump program\n");
    printf("Attempting to find a connected Dreameye device...\n");

    dreameye = maple_enum_type(0, MAPLE_FUNC_CAMERA);

    if(!dreameye) {
        printf("Couldn't find any attached devices, bailing out.\n");
        exit(EXIT_FAILURE);
    }

    state = (dreameye_state_t *)maple_dev_status(dreameye);

    printf("Attempting to grab the number of saved images...\n");
    dreameye_get_image_count(dreameye, 1);

    printf("Image Count is %s -- (%d)\n",
           state->image_count_valid ? "valid" : "invalid", state->image_count);
    img_count = state->image_count;

    /* Initialize the low-level SD card stuff. */
    if(sd_init()) {
        printf("Could not initialize the SD card. Please make sure that you "
               "have an SD card adapter plugged in and an SD card inserted.\n");
        exit(EXIT_FAILURE);
    }

    /* Grab the block device for the first partition on the SD card. Note that
       you must have the SD card formatted with an MBR partitioning scheme. */
    if(sd_blockdev_for_partition(0, &sd_dev, &partition_type)) {
        printf("Could not find the first partition on the SD card!\n");
        exit(EXIT_FAILURE);
    }

    /* Check to see if the MBR says that we have a Linux partition. */
    if(partition_type != 0x83) {
        printf("MBR indicates a non-ext2 filesystem. Will try to mount "
               "anyway\n");
    }

    /* Initialize fs_ext2 and attempt to mount the device. */
    if(fs_ext2_init()) {
        printf("Could not initialize fs_ext2!\n");
        exit(EXIT_FAILURE);
    }

    if(fs_ext2_mount("/sd", &sd_dev, FS_EXT2_MOUNT_READWRITE)) {
        printf("Could not mount SD card as ext2fs. Please make sure the card "
               "has been properly formatted.\n");
        exit(EXIT_FAILURE);
    }

    /* Try to make a "dreameye" directory on the root of the card and move to
       the new directory. */
    if(mkdir("/sd/dreameye", 0777)) {
        printf("Cannot create a dreameye directory: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    if(chdir("/sd/dreameye")) {
        printf("Cannot set current working directory: %s\n", strerror(errno));
        exit(EXIT_FAILURE);
    }

    for(i = 0; i < img_count; ++i) {
        printf("Reading image %d...\n", i + 1);
        err = dreameye_get_image(dreameye, i + 2, &buf, &size);

        if(err != MAPLE_EOK) {
            printf("Error was: %d\n", err);
            free(buf);
            continue;
        }

        printf("Image received successfully, size %d bytes\n", size);
        sprintf(fn, "image%02d.jpg", i + 1);

        if(!(fp = fopen(fn, "wb"))) {
            printf("Cannot open /sd/dreameye/%s: %s\n", fn, strerror(errno));
            free(buf);
            continue;
        }

        if(fwrite(buf, 1, size, fp) != (size_t)size) {
            printf("Cannot write image to file: %s\n", strerror(errno));
            free(buf);
            fclose(fp);
            continue;
        }

        fclose(fp);
        free(buf);
    }

    /* Clean up the filesystem and everything else */
    fs_ext2_unmount("/sd");
    fs_ext2_shutdown();
    sd_shutdown();

    printf("Complete!\n");
    return 0;
}
Exemple #19
0
int ffplay(const char *filename, const char *force_format) {

	char errbuf[256];
	int r = 0;
	
	int frameFinished;
	AVPacket packet;
	int audio_buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
	int16_t *audio_buf = (int16_t *) malloc((AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2);
	
	if(!audio_buf) {
		ds_printf("DS_ERROR: No free memory\n");
		return -1;
	}
	
	memset(audio_buf, 0, (AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2);
	
	AVFormatContext *pFormatCtx = NULL;
	AVFrame *pFrame = NULL;
	AVCodecContext *pVideoCodecCtx = NULL, *pAudioCodecCtx = NULL;
	AVInputFormat *file_iformat = NULL;
	
	video_txr_t movie_txr;
	int videoStream = -1, audioStream = -1;
	
	maple_device_t *cont = NULL;
	cont_state_t *state = NULL;
	int pause = 0, done = 0;
	
	char fn[MAX_FN_LEN];
	sprintf(fn, "ds:%s", filename);

	memset(&movie_txr, 0, sizeof(movie_txr));
	
	if(!codecs_inited) {
		avcodec_register_all();
		avcodec_register(&mp1_decoder);
		avcodec_register(&mp2_decoder);
		avcodec_register(&mp3_decoder);
		avcodec_register(&vorbis_decoder);
		//avcodec_register(&mpeg4_decoder);
		codecs_inited = 1;
	}
	
	if(force_format)
      file_iformat = av_find_input_format(force_format);
    else
      file_iformat = NULL;


	// Open video file
	ds_printf("DS_PROCESS_FFMPEG: Opening file: %s\n", filename);
	if((r = av_open_input_file((AVFormatContext**)(&pFormatCtx), fn, file_iformat, /*FFM_PACKET_SIZE*/0, NULL)) != 0) {
		av_strerror(r, errbuf, 256);
		ds_printf("DS_ERROR_FFMPEG: %s\n", errbuf);
		free(audio_buf);
		return -1; // Couldn't open file
	}
	
	// Retrieve stream information
	ds_printf("DS_PROCESS_FFMPEG: Retrieve stream information...\n");
	if((r = av_find_stream_info(pFormatCtx)) < 0) {
		av_strerror(r, errbuf, 256);
		ds_printf("DS_ERROR_FFMPEG: %s\n", errbuf);
		av_close_input_file(pFormatCtx);
		free(audio_buf);
		return -1; // Couldn't find stream information
	}

	// Dump information about file onto standard error
	dump_format(pFormatCtx, 0, filename, 0);
	//thd_sleep(5000);
	
	pVideoCodecCtx = findDecoder(pFormatCtx, AVMEDIA_TYPE_VIDEO, &videoStream);
	pAudioCodecCtx = findDecoder(pFormatCtx, AVMEDIA_TYPE_AUDIO, &audioStream);
	
	//LockInput();
	
	if(pVideoCodecCtx) {
		
		//LockVideo();
		ShutdownVideoThread();
		SDL_DS_FreeScreenTexture(0);
		int format = 0;
		
		switch(pVideoCodecCtx->pix_fmt) {
			case PIX_FMT_YUV420P:
			case PIX_FMT_YUVJ420P:
			
				format = PVR_TXRFMT_YUV422;
#ifdef USE_HW_YUV				
				yuv_conv_init();
#endif
				break;
				
			case PIX_FMT_UYVY422:
			case PIX_FMT_YUVJ422P:
			
				format = PVR_TXRFMT_YUV422;
				break;
				
			default:
				format = PVR_TXRFMT_RGB565;
				break;
		}
		
		MakeVideoTexture(&movie_txr, pVideoCodecCtx->width, pVideoCodecCtx->height, format | PVR_TXRFMT_NONTWIDDLED, PVR_FILTER_BILINEAR);
		
#ifdef USE_HW_YUV				
		yuv_conv_setup(movie_txr.addr, PVR_YUV_MODE_MULTI, PVR_YUV_FORMAT_YUV420, movie_txr.width, movie_txr.height);
		pvr_dma_init();
#endif

	} else {
		ds_printf("DS_ERROR: Didn't find a video stream.\n");
	}
	
	
	if(pAudioCodecCtx) {
		
#ifdef USE_DIRECT_AUDIO
		audioinit(pAudioCodecCtx);
#else

		sprintf(fn, "%s/firmware/aica/ds_stream.drv", getenv("PATH"));
		
		if(snd_init_fw(fn) < 0) {
			goto exit_free;
		}
	
		if(aica_audio_open(pAudioCodecCtx->sample_rate, pAudioCodecCtx->channels, 8192) < 0) {
			goto exit_free;
		}
		//snd_cpu_clock(0x19);
		//snd_init_decoder(8192);
#endif
		
	} else {
		ds_printf("DS_ERROR: Didn't find a audio stream.\n");
	}
	
	//ds_printf("FORMAT: %d\n", pVideoCodecCtx->pix_fmt);

	// Allocate video frame
	pFrame = avcodec_alloc_frame();

	if(pFrame == NULL) {
		ds_printf("DS_ERROR: Can't alloc memory\n");
		goto exit_free;
	}
	
	int pressed = 0, framecnt = 0;
	uint32 fa = 0;
	
	fa = GET_EXPORT_ADDR("ffplay_format_handler");
	
	if(fa > 0 && fa != 0xffffffff) {
		EXPT_GUARD_BEGIN;
			void (*ff_format_func)(AVFormatContext *, AVCodecContext *, AVCodecContext *) = 
				(void (*)(AVFormatContext *, AVCodecContext *, AVCodecContext *))fa;
			ff_format_func(pFormatCtx, pVideoCodecCtx, pAudioCodecCtx);
		EXPT_GUARD_CATCH;
		EXPT_GUARD_END;
	}
	
	fa = GET_EXPORT_ADDR("ffplay_frame_handler");
	void (*ff_frame_func)(AVFrame *) = NULL;
	
	if(fa > 0 && fa != 0xffffffff) {
		EXPT_GUARD_BEGIN;
			ff_frame_func = (void (*)(AVFrame *))fa;
			// Test call
			ff_frame_func(NULL);
		EXPT_GUARD_CATCH;
			ff_frame_func = NULL;
		EXPT_GUARD_END;
	}
	
	fa = GET_EXPORT_ADDR("ffplay_render_handler");
	
	if(fa > 0 && fa != 0xffffffff) {
		EXPT_GUARD_BEGIN;
			movie_txr.render_cb = (void (*)(void *))fa;
			// Test call
			movie_txr.render_cb(NULL);
		EXPT_GUARD_CATCH;
			movie_txr.render_cb = NULL;
		EXPT_GUARD_END;
	}
	
	while(av_read_frame(pFormatCtx, &packet) >= 0 && !done) {
		
		do {
			if(ff_frame_func) 
				ff_frame_func(pFrame);
					
			cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
			framecnt++;

			if(cont) {
				state = (cont_state_t *)maple_dev_status(cont);
				
				if (!state) {
					break;
				}
				if (state->buttons & CONT_START || state->buttons & CONT_B) {
					av_free_packet(&packet);
					done = 1;
				}
				if (state->buttons & CONT_A) {
					if((framecnt - pressed) > 10) {
						pause = pause ? 0 : 1;
						if(pause) {
#ifdef USE_DIRECT_AUDIO
							audio_end();
#else
							stop_audio();
#endif
						} else {
#ifndef USE_DIRECT_AUDIO
							start_audio();
#endif
						}
					}
					pressed = framecnt;
				}
				
				if(state->buttons & CONT_DPAD_LEFT) {
					//av_seek_frame(pFormatCtx, -1, timestamp * ( AV_TIME_BASE / 1000 ), AVSEEK_FLAG_BACKWARD);
				}
				
				if(state->buttons & CONT_DPAD_RIGHT) {
					//av_seek_frame(pFormatCtx, -1, timestamp * ( AV_TIME_BASE / 1000 ), AVSEEK_FLAG_BACKWARD);
				}
			}
			
			if(pause) thd_sleep(100);
			
		} while(pause);
		
		//printf("Packet: size: %d data: %02x%02x%02x pst: %d\n", packet.size, packet.data[0], packet.data[1], packet.data[2], pFrame->pts);
		
		// Is this a packet from the video stream?
		if(packet.stream_index == videoStream) {
			//printf("video\n");
			// Decode video frame
			if((r = avcodec_decode_video2(pVideoCodecCtx, pFrame, &frameFinished, &packet)) < 0) {
				//av_strerror(r, errbuf, 256);
				//printf("DS_ERROR_FFMPEG: %s\n", errbuf);
			} else {
				
				// Did we get a video frame?
				if(frameFinished && !pVideoCodecCtx->hurry_up) {
					RenderVideo(&movie_txr, pFrame, pVideoCodecCtx);
				}
			}

		} else if(packet.stream_index == audioStream) {
			//printf("audio\n");
			//snd_decode((uint8*)audio_buf, audio_buf_size, AICA_CODEC_MP3);
			
			audio_buf_size = AVCODEC_MAX_AUDIO_FRAME_SIZE;
			if((r = avcodec_decode_audio3(pAudioCodecCtx, audio_buf, &audio_buf_size, &packet)) < 0) {
				//av_strerror(r, errbuf, 256);
				//printf("DS_ERROR_FFMPEG: %s\n", errbuf);
				//continue;
			} else {
				
				if(audio_buf_size > 0 && !pAudioCodecCtx->hurry_up) {

#ifdef USE_DIRECT_AUDIO
					audio_write(pAudioCodecCtx, audio_buf, audio_buf_size);
#else
					aica_audio_write((char*)audio_buf, audio_buf_size);
#endif
				}
			}
		}

		// Free the packet that was allocated by av_read_frame
		av_free_packet(&packet);
	}
	
	goto exit_free;
	
exit_free:

	if(pFrame)
		av_free(pFrame);
	
	if(pFormatCtx)
		av_close_input_file(pFormatCtx);
	
	if(audioStream > -1) {
		if(pAudioCodecCtx)
			avcodec_close(pAudioCodecCtx);
#ifdef USE_DIRECT_AUDIO
		audio_end();
#else
		aica_audio_close();
		sprintf(fn, "%s/firmware/aica/kos_stream.drv", getenv("PATH"));
		snd_init_fw(fn);
#endif
	}
	
	if(audio_buf) {
		free(audio_buf);
	}
	
	if(videoStream > -1) {
		if(pVideoCodecCtx)
			avcodec_close(pVideoCodecCtx);
		FreeVideoTexture(&movie_txr);
		SDL_DS_AllocScreenTexture(GetScreen());
		InitVideoThread();
		//UnlockVideo();
	}
	
	//UnlockInput();
	ProcessVideoEventsUpdate(NULL);
	return 0;
}