static int kbd_readline(char *buf, int len) { int ch = 0; maple_device_t *dev; int pos = 0; if(!buf || !len) return 0; /* Clear the buffer. */ memset(buf, 0, len); while(ch != '\n' && pos < len - 1) { /* Not really sensible, but just in case someone unplugs and replugs their keyboard, we'll probably work right... */ if((dev = maple_enum_type(0, MAPLE_FUNC_KEYBOARD))) { ch = kbd_queue_pop(dev, 1); /* Make sure we got an ASCII character. */ if((ch & 0xFFFFFF00)) continue; /* Put the character into the buffer and print it out on the terminal. */ buf[pos++] = (char)ch; printf("%c", (char)ch); fflush(stdout); } } return 1; }
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; }
void updateVMUFlash(char *line1, char *line2, int force) { maple_device_t *mvmu = NULL; updateVMU(line1, line2, force); mvmu = maple_enum_type(0, MAPLE_FUNC_LCD); if(mvmu != 0) { vmu_invert_bitmap(bitmap); vmu_draw_lcd(mvmu, bitmap); vmu_invert_bitmap(bitmap); vmu_draw_lcd(mvmu, bitmap); } }
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; }
void updateVMU(char *line1, char *line2, int force) { maple_device_t *mvmu = NULL; if(!force && ovmode == vmode && ovcable == vcable) return; ovmode = vmode; ovcable = vcable; mvmu = maple_enum_type(0, MAPLE_FUNC_LCD); if (mvmu != 0) { vmu_clear_bitmap(bitmap); vmu_draw_str(bitmap, (unsigned char*)line1, 0, 0); vmu_draw_str(bitmap, (unsigned char*)line2, 0, 10); switch(vmode) { case VIDEO_240P: vmu_draw_str(bitmap, (unsigned char*)" 240p", 0, 20); break; case VIDEO_480I_A240: vmu_draw_str(bitmap, (unsigned char*)"240p->480i", 0, 20); break; case VIDEO_480I: vmu_draw_str(bitmap, (unsigned char*)" 480i/FS", 0, 20); break; case VIDEO_288P: vmu_draw_str(bitmap, (unsigned char*)" 288p", 0, 20); break; case VIDEO_576I_A264: vmu_draw_str(bitmap, (unsigned char*)"288p->576i", 0, 20); break; case VIDEO_576I: vmu_draw_str(bitmap, (unsigned char*)" 576i/FS", 0, 20); break; case VIDEO_480P: vmu_draw_str(bitmap, (unsigned char*)" 480p/FS", 0, 20); break; case VIDEO_480P_SL: vmu_draw_str(bitmap, (unsigned char*)" 480p/SL", 0, 20); break; } vmu_draw_lcd(mvmu, bitmap); } }
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; }
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; }
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); } }
/* 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; }
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 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 *) ¶m, 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); }
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; }
/* 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) { 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; }
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; }
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; }
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; }