void AppendToFile(tDevice dev, tDumpMode mode) { FILE *pFile; u8 *block_buffer; int bytes= INFO_BLOCK_PACK*getDumpBlockSize(mode); int num_blocks= WII_MAX_BUFFER/INFO_BLOCK_PACK; int block; pFile = fopen(getDeviceFile(dev, mode), "a"); if (pFile==NULL) { printf("\nERROR: fopen(\"%s\") failed. No FAT filesystem on the %s ?\n", getDeviceFile(dev, mode), getDeviceName(dev)); pressAnyButton(); exit(0); } else { printf(" -> To %s: ", getDeviceName(dev)); for(block=0 ; block<num_blocks; block++) { block_buffer= buffer + block*bytes; if(fwrite(block_buffer, 1, bytes, pFile)!=bytes) { printf("\nError writting on %s. Is it Full?\n", getDeviceName(dev)); pressAnyButton(); exit(0); } else printf("* "); } fclose(pFile); } }
void DumpFlash(tDevice dev, tDumpMode mode) { int totalBlocks= WII_FLASH_SIZE/FLASH_BLOCKSIZE; // Number of pages in NAND int totalSteps= totalBlocks/WII_MAX_BUFFER; FILE *pFile; int blocks_read=0; int steps= 0; // To test //totalSteps= 2; buffer = (u8*) memalign(0x40, WII_MAX_BUFFER*getDumpBlockSize(mode)); if(buffer==NULL) { printf("ERROR: Unable to allocate enough memory for buffer. Unable to continue. Exiting...\n"); pressAnyButton(); exit(0); } initialise_fat(dev); pFile = fopen(getDeviceFile(dev, mode), "wb+"); if (pFile==NULL) { printf("ERROR: fopen(\"%s\") failed. No FAT filesystem on the %s?\n", getDeviceFile(dev, mode), getDeviceName(dev)); pressAnyButton(); exit(0); } else { fclose(pFile); CleanScreen(); for(steps=0; steps<totalSteps; steps++) { // Block set to read in this step starts on... blocks_read= steps*WII_MAX_BUFFER; if((steps % WII_SCREEN_LINES)==0) {CleanScreen(); printf("\nDumping NAND. Pass %d of %d.", (steps/WII_SCREEN_LINES)+1, WII_SCREEN_STEPS);} ReadFlash(blocks_read, mode); AppendToFile(dev, mode); } } printf("\n\nEnd of Flash Dump."); pressAnyButton(); if(buffer!=NULL) free(buffer); }
void initialise_fat(tDevice dev) { if (!fatInit(CACHE_PAGES, false)) { printf("Unable to initialise FAT subsystem. Are there any connected devices?\n"); pressAnyButton(); exit(0); } else { if (1) //!fatEnableReadAhead(getDeviceNum(dev), 64, 128)) printf("Could not enable FAT read-ahead caching on %s, speed will suffer...\n", getDeviceName(dev)); } }
void ReadFlash(int blocks_read, tDumpMode mode) { s32 res; s32 flash_fd = -1; u8 *block_buffer; int block; int flash_block_size= getDumpBlockSize(mode); printf("\nReading 0x%05X : ", blocks_read); flash_fd = IOS_Open(WII_FLASH_DEVICE, 1 /* 2 = write, 1 = read */); for(block=0 ; block<WII_MAX_BUFFER; block++) { // Do not panic: gives something to user if((block%INFO_BLOCK_PACK)==0) printf("."); block_buffer= buffer + block*flash_block_size; // must seek before every block read -- offset is block number, not byte number IOS_Seek(flash_fd, blocks_read+block, SEEK_SET); res = IOS_Read(flash_fd, block_buffer, flash_block_size); // -12 is "bad block" and should be ignored (fill with zeroes) if(res!=flash_block_size) { if(res==-12) memset(block_buffer, 0, flash_block_size); else { printf("\nERROR reading flash at %d (error:%d)\n", blocks_read+block, res); pressAnyButton(); exit(0); } } } IOS_Close(flash_fd); }
int main() { // Initial setup signal(SIGINT, shutDown); openPath(); instructions(); srand(time(NULL)); game_state currGame; memset(&currGame, 0, sizeof(game_state)); // Sets up piezobuzzer for sound using designated PWM pin pwm = fopen("/sys/devices/bone_capemgr.9/slots", "w"); fseek(pwm, 0, SEEK_END); fprintf(pwm, "am33xx_pwm"); fprintf(pwm, "bone_pwm_P9_14"); fflush(pwm); // Sets the pointers to the appropriate duty and period files dirDuty = fopen("/sys/devices/ocp.3/pwm_test_P9_14.15/duty", "w"); dirT = fopen("/sys/devices/ocp.3/pwm_test_P9_14.15/period", "w"); // Main game loop while (!currGame.quit) { char *playScreen = " Press button to start! "; write(fd_lcd, playScreen, SCREEN_SIZE * 3); pressAnyButton(); // usleep necessary here to prevent signal overlap once game begins usleep(500000); // Initializes the playing screen char symbolScreen[SCREEN_SIZE + 1]; int i; for (i = 0; i < SCREEN_SIZE; i++) { symbolScreen[i] = ' '; } symbolScreen[SCREEN_SIZE] = '\0'; session_state currSession; memset(&currSession, 0, sizeof(session_state)); currSession.misses = -1; // Current game session loop while (currSession.misses < WRONG_GUESSES) { // When software counter resets, update to the next screen frame if (currSession.counter == 0) { // Respond to player's input if (currSession.correctInput && symbolScreen[0] != ' ') { currSession.currScore++; } else if (!currSession.correctInput) { currSession.misses++; } currSession.inputted = 0; currSession.correctInput = 0; if (nextScreenFrame(&currSession, symbolScreen) == -1) { shutDown(); return EXIT_FAILURE; } } // Delay inbetween input update usleep(DELAY_TIME); // Reads the current status of the button inputs read(fd_but, currGame.inputs, NUM_BUTTONS * sizeof(int)); currSession.pressed = 5; for (i = 0; i < NUM_BUTTONS; i++) { if (currGame.inputs[i] == 1) { currSession.pressed = i; } } // Play sound on buzzer which corresponds to the input // This is done less often to improve smoothness of gameplay if (currSession.counter % 15 == 0) { if (currSession.pressed == 0) { buzzer(noteA); } else if (currSession.pressed == 1) { buzzer(noteB); } else if (currSession.pressed == 2) { buzzer(noteC); } else if (currSession.pressed == 3) { buzzer(noteD); } else if (currSession.pressed == 4) { buzzer(noteE); } else { buzzer(0); } } updateSession(&currSession, symbolScreen[0]); } printGameOver(currSession.currScore, &(currGame.highScore)); pressAnyButton(); usleep(500000); // Prompts user to choose to play again currGame.quit = wantToQuit(); usleep(500000); } shutDown(); return EXIT_SUCCESS; }