/*---------------------------------------------------------------------- Set or reset what needs to be set when coming out of pico to run an alternate editor. Args: come_back -- If come_back is 0 we're going out of our environment to set up for an external editor. If come_back is 1 we're coming back into pine. ----------------------------------------------------------------------*/ int ttyfix(int come_back) { #if defined(DEBUG) && (!defined(DOS) || defined(_WINDOWS)) if(debugfile) fflush(debugfile); #endif if(come_back) { #ifdef OS2 enter_text_mode(NULL); #endif init_screen(); init_tty_driver(ps_global); init_keyboard(F_ON(F_USE_FK,ps_global)); #ifdef OS2 dont_interrupt(); #endif fix_windsize(ps_global); } else { EndInverse(); end_keyboard(F_ON(F_USE_FK,ps_global)); end_tty_driver(ps_global); end_screen(NULL, 0); #ifdef OS2 interrupt_ok(); #endif } return(0); }
/* reset terminal to original state */ void settty(char *s) { clr_screen(); end_screen(); if(s) printf("%s", s); (void) fflush(stdout); if(tcsetattr(0, TCSADRAIN, &inittyb) < 0) perror("Hack (settty)"); flags.echo = (inittyb.c_lflag & ECHO) ? ON : OFF; flags.cbreak = (inittyb.c_lflag & ICANON) ? OFF : ON; setioctls(); }
/*---------------------------------------------------------------------- Timeout when no user input for a long, long time. Treat it pretty much the same as if we got a HUP. Only difference is we sometimes turns the timeout off (when composing). ----------------------------------------------------------------------*/ void user_input_timeout_exit(int to_hours) { char msg[80]; dprint((1, "\n\n** Exiting: user input timeout (%d hours) **\n\n\n\n", to_hours)); snprintf(msg, sizeof(msg), _("\n\nAlpine timed out (No user input for %d %s)\n"), to_hours, to_hours > 1 ? "hours" : "hour"); msg[sizeof(msg)-1] = '\0'; fast_clean_up(); end_screen(msg, 0); end_titlebar(); end_keymenu(); end_keyboard(F_ON(F_USE_FK,ps_global)); end_tty_driver(ps_global); end_signals(0); #if defined(DEBUG) && (!defined(DOS) || defined(_WINDOWS)) if(debugfile) fclose(debugfile); #endif exit(0); }
int start_video(char *peer, char *port, vid_options_t *vopt) { width = GET_WIDTH(vopt->width); height = GET_HEIGHT(vopt->height); render_type = vopt->render_type; disp_bandwidth = vopt->disp_bandwidth; display_options_t dopt; memset(&dopt, 0, sizeof(display_options_t)); dopt.intensity_threshold = vopt->intensity_threshold; dopt.saturation = vopt->saturation; dopt.monochrome = vopt->monochrome; dopt.r = vopt->r; dopt.g = vopt->g; dopt.b = vopt->b; dopt.ascii_values = vopt->ascii_values; init_screen(&dopt); curs_set(0); pthread_mutex_init(&conslock, NULL); cons = calloc(1, sizeof(connection_t)); if (p2p_connect(peer, port, &(cons[0]))) { fprintf(stderr, "Unable to connect to server.\n"); } else { conslen++; } pthread_t thr; pthread_create(&thr, NULL, &dolisten, (void *)port); IplImage* color_img; IplImage* resize_img = cvCreateImage(cvSize(width, height), 8, 3); IplImage* edge = cvCreateImage(cvGetSize(resize_img), IPL_DEPTH_8U, 1); cv_cap = cvCaptureFromCAM(0); char line_buffer[sizeof(unsigned long) + width * depth]; struct timespec tim, actual_tim; tim.tv_sec = 0; tim.tv_nsec = (1000000000 - 1) / vopt->refresh_rate; int kernel = 7; while (1) { /* Get each frame */ color_img = cvQueryFrame(cv_cap); if(color_img && resize_img) { cvResize(color_img, resize_img, CV_INTER_AREA); if (vopt->edge_filter) { cvCvtColor(resize_img, edge, CV_BGR2GRAY); cvCanny(edge, edge, vopt->edge_lower * kernel * kernel, vopt->edge_upper * kernel * kernel, kernel); cvCvtColor(edge, resize_img, CV_GRAY2BGR); } unsigned long line_index; for (line_index = 0; line_index < (resize_img->imageSize / (width * depth)); line_index++) { memset(line_buffer, 0, sizeof(line_buffer)); unsigned long send_index = htonl(line_index); memcpy(line_buffer, &send_index, sizeof(unsigned long)); memcpy(&(line_buffer[sizeof(unsigned long)]), resize_img->imageData + (line_index * width * depth), width * depth); p2p_broadcast(&cons, &conslen, &conslock, line_buffer, + sizeof(line_buffer)); } nanosleep(&tim, &actual_tim); } } /* Housekeeping */ cvReleaseCapture(&cv_cap); end_screen(); return 0; }
void video_shutdown(int signal) { cvReleaseCapture( &cv_cap ); end_screen(); }
int main(int args, char *argv[]) { char *save_file; ines_file *nes_rom; /* Print NOW everything :D */ #ifdef _MSC_VER setvbuf(stdout,NULL,_IONBF,0); setvbuf(stderr,NULL,_IONBF,0); #else setbuf(stdout,NULL); setbuf(stderr,NULL); #endif /* i18n stuff */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); /* Parse command line options */ initialize_configuration(); switch ( parse_options(args, argv) ) { case -1: usage(stderr,argv); exit(EXIT_FAILURE); case 0: exit(EXIT_SUCCESS); default: break; } load_user_configuration(); /* Initialize static data */ initialize_palette(); initialize_instruction_set(); initialize_playback(); initialize_apu(); initialize_cpu(); initialize_ppu(); initialize_clock(); initialize_pads(); /* Read the ines file and get all the ROM/VROM */ config.rom_file = argv[optind]; nes_rom = check_ines_file(config.rom_file); map_rom_memory(nes_rom); save_file = load_sram(config.rom_file); /* Init the graphics engine */ init_screen(); init_gui(); /* Main execution loop */ main_loop(); /* After finishing the emulation, save the SRAM if necessary */ save_sram(save_file); free(save_file); /* Free all the used resources */ mapper->end_mapper(); end_screen(); end_gui(); end_ppu(); end_cpu(); end_apu(); end_playback(); free_ines_file(nes_rom); return 0; }
static int readlinedumb(char *buffer, int size) { char *ptr = buffer, ch, cnt = 0, maxcnt = 0; extern volatile sig_atomic_t leaveflag; ssize_t len; /* allow room for null terminator */ size -= 1; /* read loop */ while ((fflush(stdout), (len = read(STDIN_FILENO, ptr, 1)) > 0)) { if (len == 0 || leaveflag) { end_screen(); exit(0); } /* newline means we are done */ if ((ch = *ptr) == '\n') break; /* handle special editing characters */ if (ch == ch_kill) { /* return null string */ *buffer = '\0'; putr(); return (-1); } else if (ch == ch_erase) { /* erase previous character */ if (cnt <= 0) { /* none to erase! */ if (putchar('\7') == EOF) exit(1); } else { if (fputs("\b \b", stdout) == EOF) exit(1); ptr--; cnt--; } } /* check for character validity and buffer overflow */ else if (cnt == size || !isprint(ch)) { /* not legal */ if (putchar('\7') == EOF) exit(1); } else { /* echo it and store it in the buffer */ if (putchar(ch) == EOF) exit(1); ptr++; cnt++; if (cnt > maxcnt) maxcnt = cnt; } } /* all done -- null terminate the string */ *ptr = '\0'; /* return either inputted number or string length */ putr(); return (cnt == 0 ? -1 : cnt); }
main() { register char c; register int fd, lgt; char buf[512+1]; ini_mem(); if( ini_screen() < 0 ) exit( 0 ); dpo( увт ); if( (fd=open("/usr/minihelp/dtest",0)) > 0 ) { while( read(fd,buf,512) > 0 ) {buf[lgt]=0; dpc( buf );} close( fd ); } state = 0; radr=0177776; wadr=0177776; dpp( xr, yr-1 ); dpc( " READ" ); dpp( xr, yr ); dpo( '(' ); dpc( conv( radr, 6, 8, '0' ) ); dpc( ")=" ); dpc( conv( get(radr), 6, 8, '0' ) ); dpp( xw, yw-1 ); dpc( " WRITE" ); dpp( xw, yw ); dpo( '(' ); dpc( conv( wadr, 6, 8, '0' ) ); dpc( ")=" ); dpc( conv( wvalue, 6, 8, '0' ) ); dpp( x=xr+1, y=yr ); for(;;) { switch( state ) { case 0: c = getnumb( &radr, x-xr-1, 0177777, 0160000 ); break; case 1: c = getnumb( &wadr, x-xw-1, 0177777, 0160000 ); break; case 2: c = getnumb(&wvalue,x-xw-9, 0177777, 0000000 ); break; } rep: switch( c ) { case CTRL(D): end_screen(); exit(0); case 'r': case 'R': state=0; x=xr+1; dpp(x,y); break; case 'w': case 'W': state=1; x=xw+1; dpp(x,y); break; case 'v': case 'V': state=2; x=xw+9; dpp(x,y); break; case 'c': case 'C': if( state ) { wcycle = !wcycle; dpp(xw+8,yw-1); dpc( wcycle ? "(CYCLE)" : " " ); } else { rcycle = !rcycle; dpp(xr+8,yr-1); dpc( rcycle ? "(CYCLE)" : " " ); } dpp( x, y ); break; case CR: switch( state ) { case 0: rvalue = get( radr ); dpp( xr+9, yr ); dpc( conv(rvalue,6,8,'0') ); c='r'; goto rep; case 1: c='v'; goto rep; case 2: set( wadr, wvalue ); c='v'; goto rep; } } } }
void Game::play() { bool launched = false; // is the ball moving bool quit = false; while( !quit ) { // Event handling while( event.poll() ) { if( event.type() == SDL_QUIT ) quit = true; else if( event.type() == SDL_KEYDOWN ) { switch( event.key() ) { case SDLK_ESCAPE : quit = true; break; case SDLK_SPACE : case SDLK_RETURN : if( !launched ) { launched = true; ball.begin_moving(); } break; default : break; } } else if( event.type() == SDL_MOUSEBUTTONDOWN && !launched ) { launched = true; ball.begin_moving(); } player.handle_events( event ); } // Logic if( launched ) // only move the paddles if the game has started { ArtificialIntelligence::ai.move_paddle( computer , ball.pos ); computer.move(); ball.move(); if( ball.handle_collision( sdl::Rect( PADDLE_X_DISP , player.y , PADDLE_WIDTH , PADDLE_HEIGHT ) ) || ball.handle_collision( sdl::Rect( SCREEN_WIDTH - PADDLE_X_DISP - PADDLE_WIDTH , computer.y , PADDLE_WIDTH , PADDLE_HEIGHT ) ) ) { sound_man.play( blip_sound ); } } if( ball.pos.x < PADDLE_X_DISP ) { ai_score++; ball.reset_pos(); launched = false; sound_man.play( lose_sound ); } else if( ball.pos.x > SCREEN_WIDTH - PADDLE_WIDTH - PADDLE_X_DISP ) { player_score++; ball.reset_pos(); launched = false; sound_man.play( lose_sound ); } if( ai_score == MAX_SCORE || player_score == MAX_SCORE ) { end_screen(); return; } // Rendering screen.blit( ORIGIN , background ); player.show(); computer.show(); ball.show(); draw_scores(); screen.flip(); // Capping if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) SDL_Delay( 1000 / FRAMES_PER_SECOND - fps.get_ticks() ); } }
static void end_pgm(int sig) { end_screen (); exit(0); }
void * read_keys() { int ch = '\0'; printHeader(); while (1) { switch (ch) { case 'c': sort_type = 0; sort_accounts(); break; case 'r': sort_type = 1; sort_accounts(); break; case 'w': sort_type = 2; sort_accounts(); break; case 'u': sort_type = 3; sort_accounts(); break; case 'l': sort_type = 4; sort_accounts(); break; case 't': sort_type = 5; sort_accounts(); break; case '1': screen_view = 1; sort_accounts(); break; case KEY_F (10): end_screen (); //closesock(); exit(0); break; case CTRLC: end_screen (); //closesock(); exit(0); break; case 'q': end_screen (); //closesock(); exit(0); break; case 'h': case '?': screen_view = 5; break; case 'z': colorize(); break; } screen_regenerate(); ch = getch (); if (ch == ERR) { screen_regenerate(); continue; } } }