/* * refresh game area */ static void refresh(void) { struct console * con = get_console_stdout(); s32_t w, h; s32_t x, y, xp, yp; if(!con) return; for(y=0; y < GAME_AREA_HEIGHT; y++) { if(map.dirty[y] == FALSE) continue; for(x=0; x < GAME_AREA_WIDTH; x++) { console_getwh(con, &w, &h); xp = (w - GAME_AREA_WIDTH) / 2; yp = (h - GAME_AREA_HEIGHT) / 2; console_gotoxy(con, xp + x, yp + y); if(map.screen[x][y] != TCOLOR_BLACK) console_setcolor(con, TCOLOR_BLACK, map.screen[x][y]); else console_setcolor(con, TCOLOR_WHITE, TCOLOR_BLACK); console_putcode(con, UNICODE_SPACE); } map.dirty[y] = FALSE; } }
static int console(int argc, char ** argv) { if(argc != 2) return 0; if(strcmp(argv[1], "on") == 0) { console_onoff(get_console_stdin(), TRUE); console_onoff(get_console_stdout(), TRUE); console_onoff(get_console_stderr(), TRUE); } else if(strcmp(argv[1], "off") == 0) { console_onoff(get_console_stdin(), FALSE); console_onoff(get_console_stdout(), FALSE); console_onoff(get_console_stderr(), FALSE); } return 0; }
/* * running the shell mode */ void run_shell_mode(void) { char * p; char cwd[256]; char prompt[256]; /* * clear the screen */ console_cls(get_console_stdout()); do { getcwd(cwd, sizeof(cwd)); sprintf(prompt, "%s: %s$ ", getenv("prompt"), cwd); p = readline(prompt); exec_cmdline(p); free(p); } while(xboot_get_mode() == MODE_SHELL); }
static int version(int argc, char ** argv) { xboot_banner(get_console_stdout()); return 0; }
static int tetris(int argc, char ** argv) { struct console * con = get_console_stdout(); u32_t x, y, shape; u32_t newx, newy, newshape; bool_t fell = FALSE; bool_t try_again = FALSE; u32_t code; if(!con) return -1; console_setcursor(con, FALSE); console_cls(con); srand(jiffies + rand()); do { screen_init(); y = 3; x = GAME_AREA_WIDTH / 2; shape = rand() % ARRAY_SIZE(shapes); shape_draw(x, y, shape); refresh(); while(1) { newx = x; newy = y; newshape = shape; if(console_stdin_getcode_with_timeout(&code, 250)) { switch(code) { case 0x10: /* up */ newshape = shapes[shape].plus90; fell = FALSE; break; case 0xe: /* down */ if(y < GAME_AREA_HEIGHT - 1) newy = y + 1; fell = TRUE; break; case 0x2: /* left */ if(x > 0) newx = x - 1; fell = FALSE; break; case 0x6: /* right */ if(x < GAME_AREA_WIDTH - 1) newx = x + 1; fell = FALSE; break; default: newy++; fell = TRUE; break; } } else { newy++; fell = TRUE; } if((newx == x) && (newy == y) && (newshape == shape)) continue; shape_erase(x, y, shape); if(shape_hit(newx, newy, newshape) == FALSE) { x = newx; y = newy; shape = newshape; } else if(fell == TRUE) { shape_draw(x, y, shape); y = 3; x = GAME_AREA_WIDTH / 2; shape = rand() % ARRAY_SIZE(shapes); collapse(); if(shape_hit(x, y, shape)) { try_again = FALSE; break; } } shape_draw(x, y, shape); refresh(); } }while(try_again); console_setcursor(con, TRUE); console_setcolor(con, TCOLOR_WHITE, TCOLOR_BLACK); console_cls(con); return 0; }