void ocos_draw(NSLNSLnet *net,va_list args) { int nn; BOOL refresh=va_arg(args,BOOL); nio_ds *np=nsl_drv(nio_ds); w_clear(np->scr_d); w_clear(np->scr_l); w_clear(np->scr_s); for(nn=0;nn<np->numbar;++nn) w_printf(np->scr_s,"\n--- \n+++ \n*** "); if(refresh) {w_refresh(np->scr_d,TRUE); w_refresh(np->scr_l,TRUE); w_refresh(np->scr_s,TRUE);} }
int main(int argc, char** argv) { char tecla_pulsada; int c; int i = 0; struct itimerval req_ts; struct termios t; //Setup del terminal tcgetattr(STDIN_FILENO, &t); t.c_lflag &= ~ICANON; //No espera a enter para meter la informacion t.c_lflag &= ~ECHO; //No imprime el caracter en pantalla tcsetattr(STDIN_FILENO, TCSANOW, &t); /* No funcionan... printf("\033f");//Esconder el cursor printf("\033w");//Desactivar wrapping mode */ w_clear(); //Setup de timer req_ts.it_interval.tv_sec = 0; req_ts.it_interval.tv_usec = 0; req_ts.it_value.tv_sec = REFRESH_MS / 1000; req_ts.it_value.tv_usec = (REFRESH_MS % 1000) * 1000L; signal(SIGALRM, contador_timeout); setitimer(ITIMER_REAL, &req_ts, 0); //Setup de ctetris estado_init(&estado); leds_init(&leds); juego_init(&juego); resultados_init(&resultados); //Setup de las posiciones dentro del terminal windows_init(); //Inicio de ctetris output(TEXTO_BIENVENIDA); output(TEXTO_NIVELES_POSIBLES); while (c = getchar()) { tecla_pulsada = (char) c; if (estado.jugando == FALSE) { menu(&estado, &leds, &juego, &resultados, tecla_pulsada); } else { //Remapeamos las teclas para que sea comodo de usar en el PC switch (tecla_pulsada) { case KEY_LEFT: juego_tecla_pulsada(&leds, &juego, &resultados, &estado, TECLA_IZQUIERDA); break; case KEY_DOWN: juego_tecla_pulsada(&leds, &juego, &resultados, &estado, TECLA_ABAJO); break; case KEY_RIGHT: juego_tecla_pulsada(&leds, &juego, &resultados, &estado, TECLA_DERECHA); break; case KEY_UP: juego_tecla_pulsada(&leds, &juego, &resultados, &estado, TECLA_ROTAR); break; case 'e': //Para tener una salida "limpia" en el Netbeans... signal(SIGALRM, no_interrrupcion); w_clear(); return EXIT_SUCCESS; break; } } } return EXIT_SUCCESS; }
static void phantom_debug_window_loop() { static char buf[DEBBS+1]; int step = 0; int show = 's'; t_current_set_name("Debug Win"); // Which thread will receive typein for this window phantom_debug_window->owner = get_current_tid(); int wx = 600; #if CONF_NEW_CTTY if( t_new_ctty( get_current_tid() ) ) panic("console t_new_ctty"); #else // Need separate ctty t_set_ctty( get_current_tid(), wtty_init( WTTY_SMALL_BUF ) ); #endif // TODO HACK! Need ioctl to check num of bytes? wtty_t *tty; t_get_ctty( get_current_tid(), &tty ); while(1) { if(tty && !wtty_is_empty(tty)) { char c = wtty_getc( tty ); switch(c) { case '?': case'h': printf( "Commands:\n" "---------\n" "w\t- show windows list\n" "t\t- show threads list\n" "s\t- show stats\n" "p\t- show profiler\n" "d\t- dump threads to JSON\n" ); break; case 'p': // profiler case 't': //w_set_title( phantom_debug_window, "Threads" ); //show = c; //break; case 'w': //w_set_title( phantom_debug_window, "Windows" ); //show = c; //break; case 's': //w_set_title( phantom_debug_window, "Stats" ); show = c; break; case 'd': { json_output jo = { 0 }; json_start( &jo ); json_dump_threads( &jo ); json_stop( &jo ); } break; } } { static char old_show = 0; if( old_show != show ) { old_show = show; switch(show) { case 't': w_set_title( phantom_debug_window, "Threads" ); break; case 'w': w_set_title( phantom_debug_window, "Windows" ); break; case 's': w_set_title( phantom_debug_window, "Stats" ); break; case 'p': w_set_title( phantom_debug_window, "Profiler" ); break; } } } //hal_sleep_msec(1000); hal_sleep_msec(100); #if 1 #if 1 w_clear( phantom_debug_window ); ttyd = DEBWIN_YS-20; ttxd = 0; #endif //put_progress(); void *bp = buf; int len = DEBBS; int rc; time_t sec = uptime(); int min = sec/60; sec %= 60; int hr = min/60; min %= 60; int days = hr/24; hr %= 24; struct tm mt = *current_time; rc = snprintf(bp, len, " View: \x1b[32mt\x1b[37mhreads \x1b[32ms\x1b[37mtats \x1b[32mw\x1b[37mindows \x1b[32mp\x1b[37mrofile \x1b[32m?\x1b[37m - help\n \x1b[32mStep %d, uptime %dd, %02d:%02d:%02d\x1b[37m, %d events\n Time %04d/%02d/%02d %02d:%02d:%02d GMT, CPU 0 %2d%% idle\n", step++, days, hr, min, (int)sec, ev_get_n_events_in_q(), mt.tm_year + 1900, mt.tm_mon, mt.tm_mday, mt.tm_hour, mt.tm_min, mt.tm_sec, 100-percpu_cpu_load[0] ); bp += rc; len -= rc; switch(show) { case 't': default: phantom_dump_threads_buf(bp,len); break; case 'w': phantom_dump_windows_buf(bp,len); break; case 's': phantom_dump_stats_buf(bp,len); break; case 'p': phantom_dump_profiler_buf(bp,len); break; } phantom_debug_window_puts(buf); if(wx == 600) wx = 620; else wx = 600; //w_move( phantom_debug_window, wx, 50 ); #endif put_progress(); w_update( phantom_debug_window ); } }