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); } }
int main() { int key; Bdisp_AllClr_VRAM(); while (1) { Bdisp_PutDisp_DD(); GetKey(&key); } return 1; }
int main() { int key; Bdisp_AllClr_VRAM(); while (1) { printf("Blah\n"); Bdisp_PutDisp_DD(); GetKey(&key); } return 1; }
Exec_info play_game() { static int delay_t, sound_t; char pc_s[10]; uint16_t next_instruction; int id_opcode; int debug = 0, key_menu = 0; Exec_info exec_info = {0,0,0}; exec_info.tick_start = time_getTicks(); while(!keydown(47)) { if(debug) { memset(pc_s, '*', 10); itoa(machine.pc, pc_s + 3); PrintXY(2, 8, pc_s, 0, 0); Bdisp_PutDisp_DD(); OS_InnerWait_ms(800); } if(keydown(78)) debug ^= 1; if(keydown(48)) { while(key_menu != KEY_CTRL_MENU) { GetKey(&key_menu); } } next_instruction = (machine.memory[machine.pc])<<8 | machine.memory[machine.pc+1]; id_opcode = get_opcode(next_instruction); (*do_opcode[id_opcode])(next_instruction); exec_info.cycles_count++; if(machine.delay > 0 && time_getTicks() - delay_t > TIMER_TICKS_PERIOD) { machine.delay --; delay_t = time_getTicks(); } if(machine.sound > 0 && time_getTicks() - sound_t > TIMER_TICKS_PERIOD) { machine.sound --; sound_t = time_getTicks(); } if(id_opcode == 28) delay_t == time_getTicks(); else if(id_opcode == 29) sound_t == time_getTicks(); if(machine.draw_state) { display(); machine.draw_state = 0; } } exec_info.tick_end = time_getTicks(); return exec_info; }
void main(void){ Bdisp_EnableColor(0);//Use 3-bit mode. Bdisp_AllClr_VRAM(); Bdisp_PutDisp_DD(); for(;;){ HourGlass(); if(keyPressed(KEY_PRGM_MENU)){ int key; GetKey(&key); } } }
void viewTOTPcode(totp* tkn) { unsigned short key = 0; int keyCol, keyRow; Bdisp_AllClr_VRAM(); drawScreenTitle(tkn->name); int shown_since_beginning = 0; while(key != KEY_PRGM_EXIT && key != KEY_PRGM_LEFT) { int ThirtySecCode = computeTOTP(tkn); char buffer[10]; itoa_zeropad(tkn->totpcode, buffer, 6); long long int ms_spent_ll = currentUTCUEBT() - (long long int)ThirtySecCode * 30LL * 1000LL; int ms_spent = (int)(ms_spent_ll); drawCircularCountdownIndicator(LCD_WIDTH_PX/2, 104, 44, COLOR_BLACK, COLOR_WHITE, (ms_spent*43)/30000, getCurrentSecond() < 30 ? 0 : 1); // fade in/out animation for text int val = 0; if(ms_spent >= 29000) { val += (-29000 + ms_spent)/4; } else if (ms_spent <= 1020) { val += (1020 - ms_spent)/4; } int color = drawRGB24toRGB565(val, val, val); printCentered(buffer, 164, color, COLOR_WHITE); if(ms_spent < 2500) shown_since_beginning = 1; else if(ms_spent < 15000 && shown_since_beginning) DefineStatusMessage((char*)totpHelpMessages[(ms_spent-2500)/2500], 1, 0, 0); else DefineStatusMessage((char*)"", 1, 0, 0); DisplayStatusArea(); Bdisp_PutDisp_DD(); key = PRGM_GetKey(); if(key == KEY_PRGM_MENU) GetKeyWait_OS(&keyCol, &keyRow, 2, 0, 0, &key); //this is here to handle the Menu key if(key == KEY_PRGM_OPTN) { DefineStatusMessage((char*)"", 1, 0, 0); GetKeyWait_OS(&keyCol, &keyRow, 2, 0, 0, &key); // clear keybuffer RTCunadjustedWizard(0, 1); setTimezone(); return; // so we don't have to redraw etc. // Also, this way the Shift+Menu instruction shown in the adjustment wizard becomes vali // immediately, which is great if the user wants to repeat the adjustment. } } DefineStatusMessage((char*)"", 1, 0, 0); // clear keybuffer: GetKeyWait_OS(&keyCol, &keyRow, 2, 0, 0, &key); }
void game() { /* MAIN LOOP, DO NOT BREAK */ while (1) { /* GETKEY */ keyupdate(); // handle [menu] if (PRGM_GetKey()==48) { GetKey(&key); } // direction keys if (keydownlast(KEY_PRGM_LEFT) && cursor_pos[0]>33) { cursor_pos[0] -= cursor_speed; } else if (keydownlast(KEY_PRGM_RIGHT) && cursor_pos[0]<LCD_WIDTH_PX-33) { cursor_pos[0] += cursor_speed; } if (keydownlast(KEY_PRGM_UP) && cursor_pos[1]>0) { cursor_pos[1] -= cursor_speed; } else if (keydownlast(KEY_PRGM_DOWN) && cursor_pos[1]<(LCD_HEIGHT_PX-dash_height-cart_height-man_height-10)) { cursor_pos[1] += cursor_speed; } // control keys // shift if (keydownlast(KEY_PRGM_SHIFT) && man_is_hanging) { // drop man man_is_hanging = false; man_pos[0] = copter_pos[0]; man_pos[1] = copter_pos[1]+9; } /* OPERATIONS */ // move copter if (cursor_pos[0] > copter_pos[0]) { copter_pos[0]+=copter_speed; } else if (cursor_pos[0] < copter_pos[0]) { copter_pos[0]-=copter_speed; } if (cursor_pos[1] > copter_pos[1]) { copter_pos[1]+=copter_speed; } else if (cursor_pos[1] < copter_pos[1]) { copter_pos[1]-=copter_speed; } // if man is falling, drop him if (!man_is_hanging) { man_pos[1] += man_speed; } // if man is below cart level, check if he is in the cart if (!man_is_hanging && man_pos[1]>(LCD_HEIGHT_PX-dash_height-cart_height-5)) { if (!man_is_dead && man_pos[0]>cart_pos && man_pos[0]<cart_pos+35) { next_try(); } else { die_animation(man_pos[0], man_pos[1]); } } // move cart cart_counter = (cart_counter+1) % LCD_WIDTH_PX; cart_pos = cart_counter-70; // update frame cart_frame = (cart_frame+1) % 2; /* GRAPHICS */ // clear screen Bdisp_AllClr_VRAM(); // display functions draw_copter(copter_pos[0], copter_pos[1], man_is_hanging); draw_cart(cart_pos, LCD_HEIGHT_PX-dash_height-cart_height, cart_frame); // if man is falling, draw him if (!man_is_hanging /* && !man_is_dead */) { draw_man(man_pos[0], man_pos[1]); } // draw dash draw_dash(); // draw cursor on top of everything draw_cursor(cursor_pos[0], cursor_pos[1]); // copy VRAM to screen Bdisp_PutDisp_DD(); } }
void draw() { Bdisp_PutDisp_DD(); }
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); }