void GoL_editRules(settings* sets) { unsigned char cursor_y = 0; unsigned char cursor_x = 0; while(!KeyDown(31)){ if(KeyDown(28) && cursor_y){//up if(cursor_y == 1) cursor_x = 0; cursor_y--; } if(KeyDown(37) && cursor_y < 2) {//down if(cursor_x == 0) cursor_x = 0; cursor_y++; } if(KeyDown(38) && cursor_x) {//left cursor_x--; } if(KeyDown(27) && cursor_x < (cursor_y == 0 ? sets->col_num -1 : 8)) {//right cursor_x++; } if(KeyDown(78)) { switch(cursor_y) { case 0: break; case 1: sets->gol_neighbour_num_survive[cursor_x] ^= 1; break; case 2: sets->gol_neighbour_num_born[cursor_x] ^= 1; break; } } GoL_showRules(sets); if(cursor_y == 0) { Rectangle(18 + 20*cursor_x, 18, 32 + 20*cursor_x, 32, 1, COLOR_RED); }else{ unsigned char check[] = " \xE6\xA5"; //Check box unsigned char box = cursor_y == 1 ?sets->gol_neighbour_num_survive[cursor_x] : sets->gol_neighbour_num_born[cursor_x]; check[3] = box? 0xA9 : 0xA5; PrintXY( cursor_x+4, 3*cursor_y, check, TEXT_MODE_NORMAL, TEXT_COLOR_RED ); Print_OS(check, TEXT_MODE_NORMAL, TEXT_COLOR_RED); } Bdisp_PutDisp_DD(); int time = RTC_GetTicks(); while(RTC_GetTicks() - time < 16); } }
void SDL_StartTicks(void) { /* unsigned char m8 = '0' + (*R64CNT & 0b111); unsigned char s1 = '0' + (*RSECCNT & 0b1111); unsigned char s2 = '0' + ((*RSECCNT >> 4) & 0b111); unsigned char m1 = '0' + (*RMINCNT & 0b1111); unsigned char m2 = '0' + ((*RMINCNT >> 4) & 0b111); unsigned char h1 = '0' + (*RHRCNT & 0b1111); unsigned char h2 = '0' + ((*RHRCNT >> 4) & 0b11); start = m8*8+s1*1000+s2*10000+m1*60000+m2*600000+h1*3600000+h2*36000000*/ start=RTC_GetTicks(); }
Uint32 SDL_GetTicks (void) { /*Uint32 diff; unsigned char m8 = '0' + (*R64CNT & 0b111); unsigned char s1 = '0' + (*RSECCNT & 0b1111); unsigned char s2 = '0' + ((*RSECCNT >> 4) & 0b111); unsigned char m1 = '0' + (*RMINCNT & 0b1111); unsigned char m2 = '0' + ((*RMINCNT >> 4) & 0b111); unsigned char h1 = '0' + (*RHRCNT & 0b1111); unsigned char h2 = '0' + ((*RHRCNT >> 4) & 0b11); diff = (m8*8+s1*1000+s2*10000+m1*6000+m2*60000+h1*3600000+h2*36000000) - start*/ return (RTC_GetTicks()-start)*125/16; }
int open(const char * name,int flags,...){ if(strcmp(name,"/dev/urandom")==0){ sys_srand(RTC_GetTicks()); return urandom_FD; }else if(strcmp(name,"/dev/fb0")==0){ LCDstatefd=(unsigned char *)0xA8000000; return frameBuf_FD; }else{ //Display message on screen informing user that file does not exists int sysmode = 0; if (flags==O_RDONLY) { sysmode = SYSFILE_MODE_READ; /*} else if (flags==O_WRONLY) { sysmode = SYSFILE_MODE_WRITE; } else if (flags==O_RDWR) { sysmode = SYSFILE_MODE_READWRITE;*/ } else { fprintf(stderr,"Flag combination %d not yet supported\n",flags); return -1; } // Convert string to system native size_t plen = strlen(name); // We have several potential exits, so alloca simplifies ensuring this // gets freed (an early revision of the following logic had memory leaks). unsigned short *chars16 = alloca(2 * (plen + 1)); if (chars16 == NULL) { errno = ENOMEM; return -1; } // Get a handle from the system Bfile_StrToName_ncpy(chars16, name, plen); int syshandle = Bfile_OpenFile_OS(chars16, sysmode, 0); if(syshandle>0) return fromNativeFD(syshandle); else return -1; } }
unsigned sleep(unsigned seconds){ //TODO put cpu in lower power mode int a=RTC_GetTicks()+(seconds*128);// returns 1/128 seconds while(a>RTC_GetTicks()); return 0; }
void blockForTicks(int ticks) { //stop program execution for n ticks (1 tick = 1/128 s) int ot = RTC_GetTicks(); while (RTC_GetTicks()-ot <= ticks) {} }
// // I_GetTime // returns time in 1/70th second tics int I_GetTime (void) { //Returns the RTC-basecount in units of 1/128 s. //1/70 ~ 2/128 +-troleybus return (RTC_GetTicks()/2); }
void passwordGenerator() { Menu menu; menu.type = MENUTYPE_FKEYS; menu.title = (char*)"Password Generator"; menu.height = 7; MenuItem items[6]; int length = 10; int seed = RTC_GetTicks() * (GetMainBatteryVoltage(1) % 100); char lstr[10]; items[1].text = (char*)"Include symbols"; items[1].type = MENUITEM_CHECKBOX; items[2].text = (char*)"Include numbers"; items[2].type = MENUITEM_CHECKBOX; items[2].value = MENUITEM_VALUE_CHECKED; items[3].text = (char*)"Include uppercase"; items[3].type = MENUITEM_CHECKBOX; items[3].value = MENUITEM_VALUE_CHECKED; items[4].text = (char*)"Include confusable"; items[4].type = MENUITEM_CHECKBOX; items[4].value = MENUITEM_VALUE_CHECKED; items[5].text = (char*)"Memorable vowel mix"; items[5].type = MENUITEM_CHECKBOX; menu.numitems = 6; menu.items = items; while(1) { drawFkeyLabels(0x03B3, 0, 0, 0, 0, 0x0184); // FILE, EXE (white) itoa(length, (unsigned char*)lstr); char t[20]; strcpy(t, "Length: "); strcat(t, lstr); items[0].text = t; switch(doMenu(&menu)) { case MENU_RETURN_EXIT: return; case MENU_RETURN_SELECTION: if(menu.selection > 1) items[menu.selection-1].value = !items[menu.selection-1].value; else { Selector sel; sel.min = 6; sel.value = length; sel.max = 30; sel.cycle = 1; sel.title = (char*)"Password Generator"; sel.subtitle = (char*)"Length"; if(doSelector(&sel) == SELECTOR_RETURN_SELECTION) { length = sel.value; } } break; case KEY_CTRL_F1: { Selector sel; sel.min = 1; sel.value = 10; sel.max = 1000; sel.cycle = 1; sel.title = (char*)"Generate to file"; sel.subtitle = (char*)"Number of passwords"; if(doSelector(&sel) != SELECTOR_RETURN_SELECTION) break; SetBackGround(10); drawScreenTitle("Generate to file", "Filename:"); char newname[MAX_NAME_SIZE]; newname[0] = 0; textInput input; input.forcetext=1; input.symbols = 0; input.charlimit=MAX_NAME_SIZE; input.buffer = (char*)newname; int inscreen = 1; while(inscreen) { input.key=0; int res = doTextInput(&input); if (res==INPUT_RETURN_EXIT) break; // user aborted else if (res==INPUT_RETURN_CONFIRM) { inscreen = 0; } } if(inscreen) break; char newfilename[MAX_FILENAME_SIZE]; strcpy(newfilename, SMEM_PREFIX); strcat(newfilename, newname); strcat(newfilename, ".txt"); unsigned short pFile[0x10A]; Bfile_StrToName_ncpy(pFile, newfilename, 0x10A); unsigned int size = 1; int ntry = 0; while(ntry < 2) { ntry++; int BCEres = Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size); if(BCEres >= 0) { int hFile = Bfile_OpenFile_OS(pFile, READWRITE, 0); // Get handle if(hFile >= 0) { char password[35]; char line[37]; for(int i = 0; i < sel.value; i++) { generateRandomString(password, length, items[1].value, items[2].value, items[3].value, items[4].value, items[5].value, &seed); sprintf(line, "%s\r\n", password); Bfile_WriteFile_OS(hFile, line, length+2); } Bfile_CloseFile_OS(hFile); } else AUX_DisplayErrorMessage(0x2B); break; } else if(ntry < 2) { // File creation probably failed due to the presence of a file with the same name if(overwriteFilePrompt(newfilename)) Bfile_DeleteEntry(pFile); else break; } else AUX_DisplayErrorMessage(0x2B); } break; } case KEY_CTRL_F6: int inscreen = 1; while(inscreen) { Bdisp_AllClr_VRAM(); drawScreenTitle("Password Generator", "Generated passwords:"); textArea text; text.type = TEXTAREATYPE_INSTANT_RETURN; text.scrollbar = 0; text.y = 48+3; text.lineHeight = 20; textElement e[5]; char passwords[5][35]; for(int i = 0; i < 5; i++) { generateRandomString(passwords[i], length, items[1].value, items[2].value, items[3].value, items[4].value, items[5].value, &seed); e[i].text = passwords[i]; if(i) e[i].newLine = 1; } text.elements = e; text.numelements = 5; doTextArea(&text); drawFkeyLabels(0x036F, 0, 0, 0, 0, 0x02B9); // <, REPEAT (white) while(1) { int key; mGetKey(&key); if(key == KEY_CTRL_F6) break; if(key == KEY_CTRL_F1 || key == KEY_CTRL_EXIT) { inscreen = 0; break; } } } break; } } }
int AddIn_main(int isAppli, unsigned short OptionNum) { SaveData dataToSave; int i; Game_Data data; // variables for fps calculation unsigned int fps = 0, frame = 0, tempsOrigine = RTC_GetTicks(); // char string to display the fps unsigned char fps_text[8] = {0}; // rand initialisation srand(RTC_GetTicks()); // Key init data.shift_latch_value = 0; data.alpha_latch_value = 0; data.entry_highscores = NULL; data.entry_highscores = malloc(sizeof(float) * 6); if(data.entry_highscores == NULL) switch_to_state(OUT_OF_MEMORY, &data); data.entry_difficulties = NULL; data.entry_difficulties = malloc(sizeof(char*) * 6); if(data.entry_difficulties == NULL) switch_to_state(OUT_OF_MEMORY, &data); load_difficulty_names(data.entry_difficulties); loadDataFromSave(&data); switch_to_state(TITLE, &data); { char machin[] = "0"; machin[0] = GetMPU() + '0'; locate(1,1); Print(machin); GetKey(&i); } while(KeyUp(K_EXIT)){ // main loop // fps if(RTC_GetTicks() - tempsOrigine >= 32 )// if 1/4 seconds elapsed { fps = frame*4; frame = 0; tempsOrigine = RTC_GetTicks(); } frame++; update(&data); draw(&data); // printing debug information // updating the screen ML_display_vram(); ML_clear_vram(); Sleep(1/0.06); } for(i = 0; i < 6; ++i) dataToSave.highscores[i] = data.entry_highscores[i]; Bfile_CreateFile(filename, filesize); data.fileHandle = Bfile_OpenFile(filename, _OPENMODE_WRITE); if(data.fileHandle >= 0) { Bfile_WriteFile(data.fileHandle, &dataToSave, filesize); Bfile_CloseFile(data.fileHandle); } free(data.entry_highscores); return 1; }
void engine(settings sets) { unsigned char done = 0; unsigned char* topTable; unsigned char* backTable; unsigned char* tableA = (unsigned char*)(malloc(sizeof(unsigned char) * sets.width * sets.height)); unsigned char* tableB = (unsigned char*)(malloc(sizeof(unsigned char) * sets.width * sets.height)); srandom(RTC_GetTicks()); unsigned int numCells = sets.width*sets.height; for(unsigned int i =0; i<numCells; i++) { tableB[i] = random()%2; tableA[i] = tableB[i]; } topTable = tableA; backTable = tableB; int decal = 0; int menu_vy = 0; while(!done) { if(KeyDown(68)) {//OPTN if(decal == 0) menu_vy = 2; else if(decal == 10) menu_vy = -2; } decal+= menu_vy; if(decal == 0 || decal == 10) menu_vy = 0; if(decal == 10) UI(&sets, topTable, backTable); if(KeyDown(47)) done = 1; //switching tables unsigned char* temp; temp = backTable; backTable = topTable; topTable = temp; //operating switch(sets.sim_type) { case GOL: GoL_reaction(topTable, backTable, sets); break; case WW: WW_reaction(topTable, backTable, sets); break; } //drawing Bdisp_AllClr_VRAM(); Bdisp_EnableColor(1); draw_grid(topTable, sets); drawMenu(decal); Bdisp_PutDisp_DD(); } free(tableA); free(tableB); }