コード例 #1
0
ファイル: vt.c プロジェクト: Rappalot/FUZIX
static int escout(unsigned char c)
{
	if (c == 'A') {
		if (cursory)
			cursory--;
		return 0;
	}
	if (c == 'B') {
		if (cursory < VT_BOTTOM)
			cursory++;
		return 0;
	}
	if (c == 'C') {
		if (cursorx < VT_RIGHT)
			cursorx++;
		return 0;
	}
	if (c == 'D') {
		if (cursorx)
			cursorx--;
		return 0;
	}
	if (c == 'E') {
		clear_lines(0, VT_HEIGHT);
		return 0;
	}
	if (c == 'H') {
		cursorx = 0;
		cursory = 0;
		return 0;
	}
	if (c == 'I') {
		if (cursory)
			cursory--;
		else {
			scroll_down();
			clear_lines(0, 1);
		}
		return 0;
	}
	if (c == 'J') {
		clear_across(cursory, cursorx, VT_RIGHT - cursorx);
		clear_lines(cursory + 1, VT_BOTTOM - cursory);
		return 0;
	}
	if (c == 'K') {
		clear_across(cursory, cursorx, VT_RIGHT - cursorx);
		return 0;
	}
	if (c == 'Y')
		return 2;
	if (c == 'a')
		return 4;
	return 0;
}
コード例 #2
0
int gravity_tick()
{
    int i;
    render_tetromino('.');

    tetromino_t* tet = &game_state.current_T;
    ++tet->y;

    if(collision())
    {
        --tet->y;

        render_tetromino('#');

        game_state.current_T = game_state.next_T;
        game_state.next_T = prototypes[next_tetromino()];

        int x, y, hit_top = 0;
        for (y = 0; y < 2; ++y)
            for (x = 0; x < BOARD_W; ++x)
                if (game_state.board[y][x] == '#')
                    hit_top == 1;

        if(hit_top || collision())
        {
            printf("Game Over! Final Score: %d\n", game_state.score);
            return 1;
        }

        clear_lines();
    }

    render_tetromino('*');
    return 0;
}
コード例 #3
0
ファイル: win3d.cpp プロジェクト: 2php/eblearn
 void win3d::clear() {
   clear_spheres();
   clear_cylinders();
   clear_texts();
   clear_lines();
   win::clear();
 }
コード例 #4
0
ファイル: immix.hpp プロジェクト: angelim/rubinius
 Block()
   : address_(0)
   , status_(cFree)
   , holes_(1)
   , lines_used_(1)
   , objects_(0)
   , object_bytes_(0)
 {
   clear_lines();
 }
コード例 #5
0
void title_transition (Context* context, int state) {
	if (context->title->profile_name != NULL) {
		free(context->title->profile_name);
		context->title->profile_name = NULL;
	}
	
	if (context->title->profile_line != NULL) {
		del_line(context->glyphs, context->title->profile_line);
		context->title->profile_line = NULL;
	}
	
	if (context->title->user_bufs != NULL) {
		int i = 0;
		for (; i < MAX_PROFILES; i++) {
			if (context->title->user_bufs[i] == NULL) {
				continue;
			}
			
			context->video[1] = vertex_buffer_delete(
				context->video[1]
				, context->title->user_bufs[i]
			);
		}
		
		free(context->title->user_bufs);
		context->title->user_bufs = NULL;
	}
	
	context->title->state = state;
	clear_lines(
		context->glyphs
		, context->title->lines
		, TITLE_MAX_LINES
	);
	
	switch (state) {
		case TITLE_STATE_MAIN:
			context->title->lines = init_title(context);
			break;
		
		case TITLE_STATE_LOAD_PROFILE:
			context->title->lines = init_load_profile(context);
			break;
		
		case TITLE_STATE_NEW_PROFILE:
			context->title->lines = init_new_profile(context);
			break;
		
		case TYRIAN_GAME_LEVEL:
			context->engine = engine_init_level(context);
			break;
	}
	
}
コード例 #6
0
ファイル: vt.c プロジェクト: Rappalot/FUZIX
static void cursor_fix(void)
{
	if (cursorx < 0) {
		cursorx = VT_RIGHT;
		cursory--;
	}
	if (cursory < 0)
		cursory = 0;
	if (cursorx > VT_RIGHT) {
		cursorx = 0;
		cursory++;
	}
	if (cursory > VT_BOTTOM) {
		scroll_up();
		clear_lines(VT_BOTTOM, 1);
		cursory--;
	}
}
コード例 #7
0
ファイル: hough.c プロジェクト: hichem5/raspberry-gpu-stereo
inline void init_hough(hough_t *hs)
{
	int i;

	hs->img_w = IMG_W;
	hs->img_h = IMG_H;
	hs->h = (int)(IMG_W*1.4142);
	hs->w = 180;
	hs->max = 0;

	for(i=0; i< (hs->w * hs->h); i++){ 	/* Clear the accumulator of previous usage */
		hs->accu[i] = 0;
	}

	if(hs->l){				/* Clear the lines too */
		clear_lines(hs->l);
	}
	init_lines(hs->l);			/* Allocate memory for the new lines */
}
コード例 #8
0
ファイル: menus.c プロジェクト: aspacsa/vlp
void summons_list_scr(Summon_t *summons[], size_t count, size_t *selection) {
  Summon_t *summon;

  clear_lines( 20, 40 );
  mvprintw( 20, 5, "List:" );
  for ( size_t i = 0; i < count; ++i ) {
    summon = *summons++;
    mvprintw( 21 + i, 10, "%u. %s", i == 10 ? 0 : i + 1, summon->name );
  }
  *selection = 0;
  int ch;

  do {
    ch = getch();

    switch (ch) {
      case '1':  *selection = 1;
                 break;
      case '2':  *selection = 2;
                 break;
      case '3':  *selection = 3;
                 break;
      case '4':  *selection = 4;
                 break;
      case '5':  *selection = 5;
                 break;
      case '6':  *selection = 6;
                 break;
      case '7':  *selection = 7;
                 break;
      case '8':  *selection = 8;
                 break;
      case '9':  *selection = 9;
                 break;
      case '0':  *selection = 10;        
                 break;
    } 
  } while ( ch != ESC && ( *selection == 0 || *selection > count ) );
  clear_line( 20, 5);
  for ( size_t i = 0; i < count; ++i )
    clear_line( 21 + i, 10 );
  return;
}
コード例 #9
0
ファイル: text.cpp プロジェクト: iPodLinux-Community/iScummVM
/**
 * Write the status line.
 */
void TextMan::write_status() {
	char x[64];

	if (debug_.statusline) {
		print_status("%3d(%03d) %3d,%3d(%3d,%3d)               ",
				getvar(0), getvar(1), game.view_table[0].x_pos,
				game.view_table[0].y_pos, WIN_TO_PIC_X(mouse.x),
				WIN_TO_PIC_Y(mouse.y));
		return;
	}

	if (!game.status_line) {
		int l = game.line_status;
		clear_lines(l, l, 0);
		flush_lines(l, l);
		return;
	}

	sprintf(x, " Score:%i of %-3i", game.vars[V_score], game.vars[V_max_score]);
	print_status("%-17s             Sound:%s ", x, getflag(F_sound_on) ? "on " : "off");
}
コード例 #10
0
ファイル: text.cpp プロジェクト: iPodLinux-Community/iScummVM
/**
 * Print user input prompt.
 */
void TextMan::write_prompt() {
	int l, fg, bg, pos;

	if (!game.input_enabled || game.input_mode != INPUT_NORMAL)
		return;

	l = game.line_user_input;
	fg = game.color_fg;
	bg = game.color_bg;
	pos = game.cursor_pos;

	debugC(4, kDebugLevelText, "erase line %d", l);
	clear_lines(l, l, game.color_bg);

	debugC(4, kDebugLevelText, "prompt = '%s'", agi_sprintf(game.strings[0]));
	print_text(game.strings[0], 0, 0, l, 1, fg, bg);
	print_text((char *)game.input_buffer, 0, 1, l, pos + 1, fg, bg);
	print_character(pos + 1, l, game.cursor_char, fg, bg);

	flush_lines(l, l);
	do_update();
}
コード例 #11
0
ファイル: rtl8139.c プロジェクト: thentenaar/dc-load-ip
void bb_loop() 
{
    unsigned int intr;
    int i;
    char value[256];

    intr = 0;

    while(!escape_loop) {

	/* Check interrupt status */
	if (nic16[RT_INTRSTATUS/2] != intr) {
	    intr = nic16[RT_INTRSTATUS/2];
	    nic16[RT_INTRSTATUS/2] = intr;
	}

	/* Did we receive some data? */
	if (intr & RT_INT_RX_OK) {
	    i = bb_rx();
	}

	/* link change */
	if (intr & RT_INT_RXFIFO_UNDERRUN) {

	    if (booted && !running) {
		clear_lines(96, 24, 0);
		draw_string(0, 96, "link change...", 0xffff);
	    }

	    nic16[RT_MII_BMCR/2] = 0x9200;

	    /* wait for valid link */
	    while (!(nic16[RT_MII_BMSR/2] & 0x20));

	    /* wait for the additional link change interrupt that is coming */
	    while (!(nic16[RT_INTRSTATUS/2] & RT_INT_RXFIFO_UNDERRUN));
	    nic16[RT_INTRSTATUS/2] = RT_INT_RXFIFO_UNDERRUN;

	    if (booted && !running) {
		clear_lines(96, 24, 0);
		draw_string(0, 96, "idle...", 0xffff);
	    }

	}
	    
	/* Rx FIFO overflow */
	if (intr & RT_INT_RXFIFO_OVERFLOW) {
	    /* must clear Rx Buffer Overflow too for some reason */
	    nic16[RT_INTRSTATUS/2] = RT_INT_RXBUF_OVERFLOW;
	}

	/* Rx Buffer overflow */
	if (intr & RT_INT_RXBUF_OVERFLOW) {
            rtl.cur_rx = nic16[RT_RXBUFHEAD];
            nic16[RT_RXBUFTAIL]=  rtl.cur_rx - 16;
	    
            rtl.cur_rx = 0;
            nic8[RT_CHIPCMD] = RT_CMD_TX_ENABLE;
	    
            nic32[RT_RXCONFIG/4] = 0x00000e0a;
	    
            while ( !(nic8[RT_CHIPCMD] & RT_CMD_RX_ENABLE))
                nic8[RT_CHIPCMD] = RT_CMD_TX_ENABLE | RT_CMD_RX_ENABLE;
            
            nic32[RT_RXCONFIG/4] = 0x00000e0a;

	    nic16[RT_INTRSTATUS/2] = 0xffff;
	}
    }
    escape_loop = 0;
}
コード例 #12
0
ファイル: menus.c プロジェクト: aspacsa/vlp
void summons_dataentry_scr(const char *curr_path, const char *case_num) {
  const size_t n_fields = 6;
  const size_t starty = 6;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  Summon_t record;
  int width[] = {  MAX_SUMM_NAME, MAX_SUMM_STATUS, MAX_SUMM_REASON,  
                   MAX_SUMM_CITY, MAX_SUMM_DATE
                };
 
  for ( size_t i = 0; i < n_fields - 1; ++i )
    field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0);
  field[n_fields - 1] = NULL;
  
  set_field_back( field[0], A_UNDERLINE );
  field_opts_off( field[0], O_AUTOSKIP  );
  set_field_back( field[1], A_UNDERLINE );
  field_opts_on(  field[1], O_BLANK     );
  field_opts_off( field[1], O_AUTOSKIP  );
  set_field_back( field[2], A_UNDERLINE );
  field_opts_off( field[2], O_AUTOSKIP  );
  field_opts_on(  field[2], O_BLANK     );
  set_field_back( field[3], A_UNDERLINE );
  field_opts_off( field[3], O_AUTOSKIP  );
  field_opts_on(  field[3], O_BLANK     );
  set_field_back( field[4], A_UNDERLINE );
  field_opts_off( field[4], O_AUTOSKIP  );

  my_form = new_form(field);
  post_form(my_form);
  refresh();
 
  mvprintw( 0, 0,   curr_path );
  mvprintw( 4, 10,  "Case Number:   %s", case_num );
  mvprintw( 6, 10,  "Person:        " );
  mvprintw( 8, 10,  "Status:        " );
  mvprintw( 10, 10, "Reason:        " );
  mvprintw( 12, 10, "City:          " );
  mvprintw( 14, 10, "Date Summoned: " );
  mvprintw( 16, 10, "(F1) = Options | (F2) = Update | (F3) = Delete | (F5) = List | (ESC) = Main Menu" );
  set_visible_fields( field, 1, 5 );
  move( 6, 25 );
  set_current_field( my_form, field[0] );
 
  record.id = 0;
  int ch;
  do {
    ch = getch();
   
    switch ( ch ) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case KEY_BACKSPACE:
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        if ( current_field( my_form ) == field[0] )
          form_driver( my_form, REQ_END_LINE );
        break;
      case KEY_F(1):
        clear_lines( 20, 40 );
        {
          FIELD * curr_fld = current_field( my_form );
          size_t error = 0;
          size_t in_target_fld = 0;
          char fld_name[7];     

          if ( curr_fld == field[1] ) {
            error = query_select_all_codes_from_summon_status();
            in_target_fld = 1;
            strncpy( fld_name, "Status", 7 );
          } else if ( curr_fld == field[2] ) {
            error = query_select_all_codes_from_summon_reasons();
            in_target_fld = 1;
            strncpy( fld_name, "Reason", 7 );
          } else if ( curr_fld == field[3] ) {
            if ( query_select_all_codes_from_city_rates() ) {
              clear_line(20, 10);
              mvprintw( 20, 10, db_get_error_msg() );
              move( 12, 25 );
              set_current_field( my_form, curr_fld );
            } else {
              const SCode_t const * scode_ptr;
              size_t count = 0;
              size_t column = 10;

              mvprintw( 20, 5, "Cities:" );
              while ( ( scode_ptr = get_scode_from_result() ) != NULL ) {
                mvprintw( 21 + count++, column, "[%s] %s", scode_ptr->code, scode_ptr->name );
                if ( count == 30 ) {
                  column += 20;
                  count = 0;
                }
              }
              free_scode_result();
            }
          }
          if ( !error && in_target_fld ) {
            const Code_t const * code_ptr;
            size_t count = 0;

            mvprintw( 20, 5, "%s Options:", fld_name );
            while ( ( code_ptr = get_code_from_result() ) != NULL )          
              mvprintw( 21 + count++, 10, "[%d] %s", code_ptr->code, code_ptr->desc );
            free_code_result();
          }
          int row, col;
          get_cursor_pos( curr_fld, &row, &col );
          move( row, col );
          set_current_field( my_form, curr_fld );
        }
        break;
      case KEY_F(2):
        clear_lines( 20, 40 );

        char person_name[MAX_SUMM_NAME];
        strncpy( person_name, field_buffer(field[0], 0), MAX_SUMM_NAME );
         
        if ( is_empty_str( person_name, MAX_SUMM_NAME ) ) {
          mvprintw( 20, 10, "[!] Summon must at least have the person's name." ); 
          move( 6, 25 );
          set_current_field( my_form, field[0] );
          break;
        }
        strncpy( record.case_num, case_num, MAX_CANUM );
        strncpy( record.name, field_buffer(field[0], 0), MAX_SUMM_NAME );
        record.status = atoi( compress_str( field_buffer(field[1], 0) ) );
        record.reason = atoi( compress_str( field_buffer(field[2], 0) ) );
        strncpy( record.city_code, compress_str( field_buffer(field[3], 0) ), MAX_SUMM_CITY );
        strncpy( record.summon_date, compress_str( field_buffer(field[4], 0) ), MAX_SUMM_DATE );
        if ( query_update_summon( &record ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
          move( 6, 25 );
          set_current_field( my_form, field[0] );
        } else {
          clear_fields( field, 0, 4 );
          mvprintw( 20, 10, "[!] Summon has been updated." );
          move( 6, 25 );
          set_current_field( my_form, field[0] );
          record.id = 0;
        }
        break;
      case KEY_F(3):
        clear_lines( 20, 40 );
        if ( record.id > 0 ) {
          mvprintw( 20, 10, "[?] Delete summon '%u' ? [Y/n]", record.id );
          int ch = toupper( getch() );
          if ( ch == 'Y' ) {
            if ( query_delete_summon( record.id ) ) {
              mvprintw( 20, 10, db_get_error_msg() );
            } else {
              clear_fields( field, 0, 4 );    
              mvprintw( 20, 10, "[!] Summon '%u' has been deleted.", record.id );
              move( 6, 25 );
              set_current_field( my_form, field[0] );
              record.id = 0;
            }
          }
        }
        break;
      case KEY_F(5):
        clear_lines( 20, 40 );
        if ( query_select_all_from_summons_for( case_num ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
        } else {
          Summon_t *summ_ptr;
          Summon_t *summons[MAX_SUMM_SET];
          size_t count = 0;

          while ( ( summ_ptr = get_summon_from_result() ) != NULL ) {           
            summons[count] = summ_ptr;
            count++;
          }
          if ( count ) {
            size_t selection;
            char code_buff[4];

            summons_list_scr( summons, count, &selection );
            if ( selection > 0 ) {
              summ_ptr = summons[selection - 1];
              record.id = summ_ptr->id;
              set_field_buffer( field[0], 0, summ_ptr->name );
              snprintf( code_buff, 4, "%d", summ_ptr->status );
              set_field_buffer( field[1], 0, code_buff );
              snprintf( code_buff, 4, "%d", summ_ptr->reason );
              set_field_buffer( field[2], 0, code_buff );
              set_field_buffer( field[3], 0, summ_ptr->city_code );
               set_field_buffer( field[4], 0, summ_ptr->summon_date );
            }
            free_summon_result();
          } else {
            mvprintw( 20, 10, "[!] Case %s has no summons.", case_num );
          }
        }
        set_current_field( my_form, field[0] );
        move( 6, 25 );
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );
          if ( ch == '\'' )
            break;

          if ( curr_fld == field[1] || curr_fld == field[2] ) {
            if ( !isdigit( ch ) )
              break;
          } else if ( curr_fld == field[3] ) {
            if ( !isalpha( ch ) )
              break;
            else
              ch = toupper( ch );
          }
          form_driver( my_form, ch );
          break;
        } 
    }
  } while ( ch != ESC );

  unpost_form( my_form );
  free_form( my_form );
  for ( size_t i = 0; i < n_fields - 1; ++i )
    free_field( field[i] );
  return;
}
コード例 #13
0
ファイル: menus.c プロジェクト: aspacsa/vlp
void cases_menu(const char *curr_path) {
  const char *screen_title = "Cases";
  const size_t n_fields = 7;
  const size_t starty = 4;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  int width[] = { MAX_CANUM, MAX_CINUM, 
                  MAX_PHYADD, MAX_POSADD, 
                  MAX_STATUS, MAX_DELDATE 
                };
  
  initscr();
  curs_set(1);
  cbreak();
  clear();
  noecho();
  keypad(stdscr, TRUE);

  for (size_t i = 0; i < n_fields - 1; ++i) {
    field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0);
  }
  field[n_fields - 1] = NULL;

  set_field_back(field[0], A_UNDERLINE);
  field_opts_off(field[0], O_AUTOSKIP);
  field_opts_on(field[0], O_BLANK);
  set_field_back(field[1], A_UNDERLINE);
  field_opts_off(field[1], O_AUTOSKIP);
  set_field_back(field[2], A_UNDERLINE);
  field_opts_off(field[2], O_AUTOSKIP);
  set_field_back(field[3], A_UNDERLINE);
  field_opts_off(field[3], O_AUTOSKIP);
  set_field_back(field[4], A_UNDERLINE);
  field_opts_off(field[4], O_AUTOSKIP);
  set_field_back(field[5], A_UNDERLINE);
  field_opts_off(field[5], O_AUTOSKIP);

  my_form = new_form(field);
  post_form(my_form);
  refresh();

  mvprintw(0, 0, menu_path(curr_path, screen_title));
  mvprintw(4, 10,   "Case Num:      ");
  mvprintw(6, 10,   "Civil Num:     ");
  mvprintw(8, 10,   "Physical Add:  ");
  mvprintw(10, 10,  "Postal Add:    ");
  mvprintw(12, 10,  "Status:        ");
  mvprintw(14, 10,  "Delivery Date: ");
  mvprintw(16, 10,  "(F1) = Options | (F2) = Update | (F3) = Delete | (F4) = Exit");
  move(4, 25);
  refresh();

  int ch;
  do {
    ch = getch();
    switch(ch) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        form_driver( my_form, REQ_END_LINE );
        if (field_status(field[0])) {
          size_t count = 0;
          char case_num[MAX_CANUM];

          clear_line( 20, 10 );
          strcpy( case_num, compress_str(field_buffer(field[0], 0) ) );
          if ( query_select_count_from_case_for(case_num, &count) ) {
            mvprintw( 20, 10, db_get_error_msg() );
            move( 4, 25 );
          } else {
            if ( count ) {
              //call routine to fill in fields
              Case_t record;
              if ( query_select_all_from_case_for(case_num, &record) ) {
                mvprintw( 20, 10, db_get_error_msg() );
                move( 4, 25 );
              } else {
                char status_buff[4];

                set_field_buffer( field[1], 0, record.civil );
                set_field_buffer( field[2], 0, record.physical_add );
                set_field_buffer( field[3], 0, record.postal_add );
                snprintf( status_buff, 4, "%d", record.status );
                set_field_buffer( field[4], 0, status_buff );
                set_field_buffer( field[5], 0, record.delivery_date );
              }
            } else {            
              clear_fields( field, 1, 5 );    
              mvprintw( 20, 10, "[!] Case %s does not exist.", case_num );
              move( 6, 25 );
              set_current_field( my_form, field[0] );
            }
          }
          set_field_status( field[0], 0 );
        }
        break;
      case KEY_BACKSPACE:
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      case ESC:
        {
          FIELD * curr_field = current_field( my_form );
          int row, col;
          get_cursor_pos( curr_field, &row, &col );
          clear_lines( 20, 40 );
          move( row, col );
          set_current_field( my_form, curr_field );
        }
        break;
      case KEY_F(1):
        if ( current_field( my_form ) == field[4] ) {
          clear_lines( 20, 30 );
          if ( query_select_all_codes_from_case_status() ) {
            mvprintw( 20, 10, db_get_error_msg() );
          } else {
            const Code_t const * code_ptr;
            size_t count = 0;

            mvprintw( 20, 5, "Status Options:" );
            while ( ( code_ptr = get_code_from_result() ) != NULL ) {           
              mvprintw( 21 + count, 10, "[%d] %s", code_ptr->code, code_ptr->desc );
              count++;
            }
            free_code_result();
            move( 12, 25 );
            set_current_field( my_form, field[4] );
          }  
        } 
        break;
      case KEY_F(2):
      {
        size_t count = 0;
        char case_num[MAX_CANUM];
        
        clear_lines( 20, 30 );
        strncpy( case_num, compress_str(field_buffer(field[0], 0) ), MAX_CANUM );
        if ( query_select_count_from_case_for( case_num, &count ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
        } else {
          Case_t record;
          strncpy( record.number, compress_str(field_buffer(field[0], 0)), MAX_CANUM );
          strncpy( record.civil, compress_str(field_buffer(field[1], 0)), MAX_CINUM );
          strncpy( record.physical_add, field_buffer(field[2], 0), MAX_PHYADD );
          strncpy( record.postal_add, field_buffer(field[3], 0), MAX_POSADD );
          record.status = atoi( compress_str(field_buffer(field[4], 0)) );
          strncpy( record.delivery_date, compress_str(field_buffer(field[5], 0)), MAX_DELDATE );
          if ( count ) {
            // update existing record
            if ( query_update_case( &record ) == 0 ) {
              mvprintw( 20, 10, "[!] Case has been updated." );
            } else {
              mvprintw( 20, 10, db_get_error_msg() );
            }
          } else {
            // create new record
            if ( query_create_new_case( &record ) == 0 ) {
              mvprintw (20, 10, "[!] Case has been created successfully." );
            } else {
              mvprintw( 20, 10, db_get_error_msg() );
            }
          }
        }
        move(4, 25);
        set_current_field( my_form, field[0] );
       }
       break;
      case KEY_F(3):
        {
          size_t count = 0;
          char case_num[MAX_CANUM];

          clear_lines(20, 30);
          strncpy(case_num, compress_str(field_buffer(field[0], 0) ), MAX_CANUM);
          if ( strlen(case_num) ) {
            if ( query_select_count_from_case_for(case_num, &count) ) {
              mvprintw( 20, 10, db_get_error_msg() );
            } else {
              if (count) {
                mvprintw(20, 10, "[?] Delete case '%s' ? [Y/n]", case_num);
                int ch = toupper(getch());
                if (ch == 'Y') {
                  if ( query_delete_case(case_num) ) {
                    mvprintw( 20, 10, db_get_error_msg() );
                  } else {
                    clear_fields(field, 0, 5);    
                    mvprintw(20, 10, "[!] Case '%s' has been deleted.");
                  }
                }
              } else {
                mvprintw(20, 10, "[!] Case '%s' does not exist.", case_num);
              }
            }
          } else {
            mvprintw(20, 10, "[!] Must enter a valid Case Number to be deleted.");
          }
        }
        move(4, 25);
        set_current_field(my_form, field[0]);
        break;
      case DEL:
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( ch == '\'' )
            break;
          if ( curr_fld == field[4] ) {
            if ( !isdigit( ch ) )
              break;
          }
        }
        form_driver(my_form, ch);
        break;
    } 
  } while( ch != KEY_F(4) ); 

  unpost_form(my_form);
  free_form(my_form);
  for (size_t i = 0; i < n_fields -1; ++i) {
    free_field(field[i]);
  }
  endwin();
  return;
}
コード例 #14
0
ファイル: caliq.c プロジェクト: denever/linrad-rev
void cal_iqbalance(void)
{
char s[80];
int seg,color;
int ia,ib;
int i,j,k,m,n,mm,errskip;
float z[2*MAX_ADCHAN];
float t1,t2,t3;
caliq_clear_flag=TRUE;
clear_fft1_filtercorr();
bal_updflag=-1;
bal_segments=32;
bal_screen=screen_width;
make_power_of_two(&bal_screen);
if(bal_screen > screen_width)bal_screen>>=1;
mm=twice_rxchan;
restart:;
thread_status_flag[THREAD_CAL_IQBALANCE]=THRFLAG_ACTIVE;
if(bal_segments > BAL_MAX_SEG)bal_segments = BAL_MAX_SEG;
if(bal_segments > fft1_size/4)bal_segments = fft1_size/4;
if(bal_segments < 8)bal_segments = 8;
cal_initscreen();
lir_text(0,1,"Connect signal generator to antenna input(s).");
sprintf(s,"The frequency range is split in %d segments.",bal_segments);
lir_text(0,2,s);
lir_text(0,3,"Tune and wait for each segment to become green.");
settextcolor(14);
lir_text(5,4,"+/- => Change no of segments");
lir_text(7,5,  "S => Save current RAM contents to disk");
lir_text(7,6,  "C => Clear RAM");
lir_text(7,7,  "U => Compute new calibration and store in RAM");
settextcolor(7);
if(caliq_clear_flag)
  {
  for(i=0; i<=bal_segments; i++)bal_flag[i]=0;
  }
lir_refresh_screen();
while(thread_command_flag[THREAD_CAL_IQBALANCE] == THRFLAG_ACTIVE)
  {
  clear_lines(8,9);
  errskip=0;
  for(j=0; j<ui.rx_ad_channels; j++)
    {
    t1=(100*ad_maxamp[j])/0x8000;
    if(t1>90)
      {
      settextcolor(12);
      lir_text(10,8,"O V E R L O A D");
      errskip=1;
      }
    if(t1<5)
      {
      settextcolor(12);
      lir_text(10,8,"Signal too weak");
      errskip=1; 
      }
    sprintf(s,"A/D(%d) %.2f%%",j,t1);
    lir_text(20*j,9,s);
    settextcolor(7);
    }
  workload_reset_flag++;
  while(fft1_pb==fft1_px &&
                thread_command_flag[THREAD_CAL_IQBALANCE] == THRFLAG_ACTIVE)
    {     
    lir_sem_wait(SEM_FFT1);
    }
// Skip old data in case the cpu is a bit slow.
  while( ((fft1_pb-fft1_px+fft1_mask+1)&fft1_mask) > 2*fft1_block &&
                thread_command_flag[THREAD_CAL_IQBALANCE] == THRFLAG_ACTIVE)
    {
    lir_sem_wait(SEM_FFT1);
    fft1_nx=(fft1_nx+1)&fft1n_mask;
    fft1_px=fft1_nx*fft1_block;
    }
// Convert complex amplitudes to power and phase, store in cal_buf.
// Get the point of maximum. 
  t2=0;
  k=0;
  for(i=0; i<fft1_size; i++)
    {
    t1=0;
    for(j=0; j<mm; j+=2)
      {
      cal_buf[mm*i+j]=pow(fft1_float[fft1_px+mm*i+j  ],2.0)+
                       pow(fft1_float[fft1_px+mm*i+j+1],2.0);
      t1+=cal_buf[mm*i+j];
      cal_buf[mm*i+j+1]=atan2(fft1_float[fft1_px+mm*i+j+1],
                               fft1_float[fft1_px+mm*i+j  ]);
      }
    if(t2<t1)
      {
      t2=t1;
      k=i;
      }
    }
  fft1_nx=(fft1_nx+1)&fft1n_mask;
  fft1_px=(fft1_px+fft1_block)&fft1_mask;
  if(errskip==1) goto skipdat; 
  if(k<2)k=2;
  if(k>fft1_size-3)k=fft1_size-3;
// Since we use a sin power 4 window a peak will be a few points wide.
// collect the average amplitude ratio and average phase sum 
// Use power as weight factor in averaging.
  clear_lines(10,10);
  for(j=0; j<mm; j+=2)
    {
    z[2*j]=z[2*j+1]=z[2*j+2]=z[2*j+3]=0;
    for(i=k-2; i<=k+2; i++)
      {
      m=fft1_size-i;
      t1=cal_buf[mm*m+j+1]+cal_buf[mm*i+j+1];
      if(t1<-PI_L)t1+=2*PI_L;
      if(t1>PI_L)t1-=2*PI_L;
      t3=cal_buf[mm*i+j];
      t2=sqrt(cal_buf[mm*m+j]/cal_buf[mm*i+j]);
      z[2*j]+=t3;
      z[2*j+1]+=t3*t2;
      z[2*j+2]+=t3*t1;
      z[2*j+3]+=t3*i;
      }
    z[2*j+1]/=z[2*j];
    z[2*j+2]/=z[2*j];
    z[2*j+3]/=z[2*j];
    ia=z[2*j+3]+0.5;
    ib=ia+4;
    ia=ia-4;
    if(ia<0)ia=0;
    if(ib>fft1_size)ib=fft1_size;
    if(cal_buf[mm*ia+j]+cal_buf[mm*ib+j]>0.02*cal_buf[mm*k+j])
      {
      lir_text(0,10,"Signal too unstable");
      goto skipdat;
      }
    }
  clear_lines(10,10);
  seg=(bal_segments*z[3])/fft1_size+0.5;
  if(seg > bal_segments)seg=bal_segments;
  for(j=2; j<mm; j+=2)
    {
    k=(bal_segments*z[2*j+3])/fft1_size+0.5;
    if(seg != k )
      {
      lir_text(0,10,"Channels differ");
      goto skipdat;
      }
    }    
  if(bal_flag[seg]==BAL_AVGNUM)
    {
    sprintf(s,"Segment %d ok",seg);
    lir_text(0,10,s);
    goto skipdat_a;
    }
  k=(bal_flag[seg]*bal_segments+seg)*ui.rx_rf_channels;  
  for(j=0; j<ui.rx_rf_channels; j++)
    {
    bal_pos[k+j]=z[4*j+3]+0.5;
    bal_phsum[k+j]=z[4*j+2];
    bal_amprat[k+j]=z[4*j+1];
    }
  bal_flag[seg]++;
  skipdat_a:;
  for(j=0; j<ui.rx_rf_channels; j++)
    {
    sprintf(s,"Ch(%d) A=%f ph=%f",j,z[4*j+1],z[4*j+2]);
    lir_text(30*j,11,s);
    }
skipdat:;
  m=fft1_size/bal_screen;
  for(j=0; j<mm; j+=2)
    {
    for(i=0; i<bal_screen; i++)
      {
      lir_setpixel(i, cal_graph[bal_screen*j+i], 0);  
      k=i*m;
      if(k>fft1_size-m)k=fft1_size-m;
      t2=0;
      for(n=0;n<m;n++)t2+=cal_buf[mm*(k+n-m/2)+j];
      t2/=m;
      t2=0.03*log10(t2)-0.05;   
      if(t2 <-0.28)t2=-0.28;
      if(t2 > 0.28)t2= 0.28;
      if(j>0)t2-=.2;
      cal_graph[bal_screen*j+i]=screen_height*(0.5-t2);
      seg=(float)(bal_segments*k)/fft1_size+0.5;    
      color=13;
      if(bal_flag[seg]==0) color=15;
      if(bal_flag[seg]==BAL_AVGNUM)color=10;
      lir_setpixel(i, cal_graph[bal_screen*j+i], color);  
      }
    }
  lir_refresh_screen();
  }
if(thread_command_flag[THREAD_CAL_IQBALANCE]==THRFLAG_IDLE)
  {
  thread_status_flag[THREAD_CAL_IQBALANCE]=THRFLAG_IDLE;
  while(thread_command_flag[THREAD_CAL_IQBALANCE]==THRFLAG_IDLE)
    {
    lir_sem_wait(SEM_FFT1);
    fft1_nx=(fft1_nx+1)&fft1n_mask;
    fft1_px=fft1_nx*fft1_block;
    }
  if(thread_command_flag[THREAD_CAL_IQBALANCE]==THRFLAG_ACTIVE)goto restart;
  }  
thread_status_flag[THREAD_CAL_IQBALANCE]=THRFLAG_RETURNED;
while(thread_command_flag[THREAD_CAL_IQBALANCE] != THRFLAG_NOT_ACTIVE)
  {
  lir_sleep(1000);
  }
}
コード例 #15
0
	void renderer::call_and_clear_lines() {
		call_lines();
		clear_lines();
	}
コード例 #16
0
void MainWindow::choose_file_button_clicked()
{   try {
        QString fileName = QFileDialog::getOpenFileName(this,QString::fromUtf8("Choose File"),QDir::currentPath(),"Text(*.txt)");
        if (fileName.length() != 0) {
            // ДАЛЕЕ ОЧИСТКА ЗНАЧЕНИЙ!!!
            clear_data();
            clear_lines();

            ui->fileName->setText(fileName);
            QFile my_file(fileName);
            my_file.open(QIODevice::ReadOnly);
            if (my_file.isOpen())
                while (!my_file.atEnd()) {
                    QString exmpl = changeOnDoTA(my_file.readLine());
                    double obj = exmpl.toDouble();
                    started_data.push_back(obj);
                }

            try {

                set_average_data();

               // qDebug() << max_x << " " << min_x;
                set_square_deviation();
                set_Sx();
    //            for (int i = 0; i < started_data.size(); i++)
    //                qDebug() << started_data[i];
                set_r(); //  КИДАЕТ ВНУТРЕННИЙ ЭКСЕПШЕН!
                set_h();

                fill_intervals();
                set_f();
                set_middle_value();
                set_middle_value2();
                set_average_of_intervals();
                set_si();
                set_n_i();
                set_xi_sq();

                choose_quantile();

//                qDebug() << "BEgin";
//                for (int i = 0;i < started_data.size();i++)
//                    qDebug() << started_data[i];
//                qDebug() << "END";

                set_lines();
                for (int i = 0; i < intervals.size();i++) {
                    for (int j = 0; j < intervals[i].size();j++)
                        qDebug() << intervals[i][j];
                    qDebug() << "end_line";
                }

              //  check_result();

                is_chButton_clicked_flag = true;
                my_file.close();
            } catch(std::exception &e){
                clear_data();
                clear_lines();
                is_chButton_clicked_flag = false;
                QMessageBox::critical(this,"Not Valid!!!",e.what());
            }
        }
        else {
            throw (std::invalid_argument("Choose txt File!"));
        }
    } catch(std::exception& e) {
        clear_data();
        clear_lines();
        is_chButton_clicked_flag = false;
       // QMessageBox::critical(this, "Error!",e.what());
    }

}
コード例 #17
0
ファイル: vt.c プロジェクト: Rappalot/FUZIX
void vtinit(void)
{
	vtmode = 0;
	clear_lines(0, VT_HEIGHT);
	cursor_on(0, 0);
}
コード例 #18
0
ファイル: sdr14.c プロジェクト: denever/linrad-rev
int init_sdr14(void)
{
char ss[80];
char sn[80];
char s[80];
int i, line;
float t1;
FILE *sdr14_file;
int *sdr_pi;
char *looking;
looking="Looking for an SDR on the USB port.";
// Set device_no to appropriate values if some dedicated hardware
// is selected by the user.
//  ------------------------------------------------------------
// See if there is an SDR-14 or an SDR-IQ on the system.
settextcolor(12);
lir_text(10,10,looking);
SNDLOG"\n%s",looking);
lir_text(10,11,"Reset CPU, USB and SDR hardware if system hangs here.");
lir_refresh_screen();
open_sdr14();
settextcolor(7);
clear_lines(10,11);
lir_refresh_screen();
line=0;
if(sdr != -1)
  {
  SNDLOG"open_sdr14 sucessful.\n");
  lir_text(5,5,"An SDR is detected on the USB port.");
  lir_text(5,6,"Do you want to use it for RX input (Y/N)?");
qsdr:;
  await_processed_keyboard();
  if(kill_all_flag) goto sdr14_errexit;
  if(lir_inkey == 'Y')
    {
    sdr_target_name(sn);
    sprintf(s,"Target name: %s",sn);
    SNDLOG"%s\n",s);
    lir_text(5,10,s);
    if( strcmp(sdr14_name_string,sn) == 0)
      {
      ui.rx_addev_no=SDR14_DEVICE_CODE;
      }
    if( strcmp(sdriq_name_string,sn) == 0)
      {
      ui.rx_addev_no=SDRIQ_DEVICE_CODE;
      }
    if(ui.rx_addev_no == -1)  
      {
      lir_text(5,12,"Unknown hardware, can not use.");
      lir_text(5,13,press_any_key);
      await_keyboard();
      if(kill_all_flag) goto sdr14_errexit;
      clear_screen();
      }
    else
      {
      ui.rx_input_mode=IQ_DATA+DIGITAL_IQ;
      ui.rx_rf_channels=1;
      ui.rx_ad_channels=2;
      ui.rx_admode=0;
      sdr_target_serial_number(ss);
      sprintf(s,"Serial no: %s",ss);
      lir_text(5,11,s);
      sdr_target_interface_version(ss);
      i=(short int)ss[0];
      sprintf(s,"Interface version: %d.%02d",i/100,i%100);
      lir_text(5,12,s);
      sdr_target_boot_version(ss);
      i=(short int)ss[0];
      sprintf(s,"PIC boot version: %d.%02d",i/100,i%100);
      lir_text(5,13,s);
      sdr_target_firmware_version(ss);
      i=(short int)ss[0];
      sprintf(s,"PIC firmware version: %d.%02d",i/100,i%100);
      lir_text(5,14,s);
      lir_text(10,16,"PRESS ANY KEY");
restart_sdr14par:;
      await_processed_keyboard();
      if(kill_all_flag) goto sdr14_errexit;
      clear_screen();
      sprintf(s,"%s selected for input",sn);
      lir_text(10,line,s);
      line++;
      if(ui.newcomer_mode == 0)
        {
        lir_text(5,line,"Set CIC2 decimation (2 - 16)");
        sdr14.m_cic2=lir_get_integer(35, line, 2, 2,16);
        if(kill_all_flag)goto sdr14_errexit;
        t1=SDR14_SAMPLING_CLOCK/sdr14.m_cic2;
        sprintf(s,"clk=%.2f MHz",t1);
        lir_text(39,line,s);
        line++;
        lir_text(5,line,"Set CIC5 decimation (2 - 32)");
        sdr14.m_cic5=lir_get_integer(35, line, 2, 2,32);
        if(kill_all_flag)goto sdr14_errexit;
        t1/=sdr14.m_cic5;
        sprintf(s,"clk=%.4f MHz",t1);
        lir_text(39,line,s);
        line++;
        lir_text(5,line,"Set RCF decimation (2 - 32)");
        sdr14.m_rcf=lir_get_integer(35, line, 2, 2,32);
        if(kill_all_flag)goto sdr14_errexit;
        t1/=sdr14.m_rcf;
        ui.rx_ad_speed=t1*1000000;
        if(ui.rx_ad_speed > MAX_SDR14_SPEED)
          {
          line++;
          settextcolor(12);
          lir_text(5,line,
                "ERROR The sampling speed is far too high for USB 1.0");
          line++;
          lir_text(5,line,press_any_key);
          settextcolor(7);
          goto restart_sdr14par;
          }
        }
      else
        {
        sdr14.m_cic2=10;
        t1=SDR14_SAMPLING_CLOCK/sdr14.m_cic2;
        sdr14.m_cic5=10;
        t1/=sdr14.m_cic5;
        line++;
        for(i=4; i<8; i++)
          {
          sprintf(s,"RCF= %d  Speed %f kHz",i,1000*t1/i);
          lir_text(0,line,s);
          line++; 
          }
        line++;  
        lir_text(5,line,"Set RCF decimation (4 - 7)");
        sdr14.m_rcf=lir_get_integer(35, line, 2, 4,7);
        if(kill_all_flag)goto sdr14_errexit;
        t1/=sdr14.m_rcf;
        ui.rx_ad_speed=t1*1000000;
        }
      sprintf(s,"clk=%.2f kHz",t1*1000);
      lir_text(39,line,s);
      line++;
      lir_text(5,line,"Set RCF output shift (0 - 7)");
      sdr14.ol_rcf=lir_get_integer(35, line, 2, 0,7);
      if(kill_all_flag)goto sdr14_errexit;
      line++;
      if(ui.newcomer_mode == 0)
        {
        lir_text(5,line,"Set sampling clock shift (Hz)");
        sdr14.clock_adjust=lir_get_integer(35, line, 6,-10000,10000);
        if(kill_all_flag)goto sdr14_errexit;
        line++;
        }
      else
        {
        sdr14.clock_adjust=0;
        }
      adjusted_sdr_clock=SDR14_SAMPLING_CLOCK+0.000001*sdr14.clock_adjust,
      ui.rx_ad_speed=1000000.*adjusted_sdr_clock/(M_CIC2*M_CIC5*M_RCF);
      if(ui.rx_addev_no == SDR14_DEVICE_CODE)
        {
        lir_text(5,line,"Select direct input (0 - 1)");
        sdr14.input=lir_get_integer(35, line, 2, 0, 1);
        if(kill_all_flag)return 0;
        }
      else
        {
        if(ui.newcomer_mode == 0)
          {
          lir_text(5,line,"Attenuation below which to use 10dB (10 - 25)");
          sdr14.input=lir_get_integer(52, line, 2, 10, 25);
          if(kill_all_flag)return 0;
          }
        else
          {
          sdr14.input=20;  
          }
        }
      sdr14_file=fopen("par_sdr14","w");
      if(sdr14_file == NULL)
        {
        lirerr(381264);
sdr14_errexit:;
        close_sdr14();
        clear_screen(); 
        return 0;
        }
      sdr14.check=SDR14PAR_VERNR;
      sdr_pi=(void*)(&sdr14);
      for(i=0; i<MAX_SDR14_PARM; i++)
        {
        fprintf(sdr14_file,"%s [%d]\n",sdr14_parm_text[i],sdr_pi[i]);
        }
      parfile_end(sdr14_file);
      }
    }
コード例 #19
0
ファイル: keyboard.c プロジェクト: UIKit0/sarien
void handle_keys (int key)
{
	UINT8 *p=NULL;
	int c = 0;
	static UINT8 formated_entry[256];
	int l = game.line_user_input;
	int fg = game.color_fg, bg = game.color_bg;

	setvar (V_word_not_found, 0);

	_D ("handling key: %02x", key);

	switch (key) {
	case KEY_ENTER:
		_D (("KEY_ENTER"));
		game.keypress = 0;

		/* Remove all leading spaces */
		for (p = game.input_buffer; *p && *p == 0x20; p++);

		/* Copy to internal buffer */
		for (; *p; p++) {
			/* Squash spaces */
			if (*p == 0x20 && *(p + 1) == 0x20) {
				p++;
				continue;
			}
			formated_entry[c++] = tolower (*p);
		}
		formated_entry[c++] = 0;

		/* Handle string only if it's not empty */
		if (formated_entry[0]) {
			strcpy (game.echo_buffer, game.input_buffer);
			strcpy (last_sentence, formated_entry);
			dictionary_words (last_sentence);
		}

		/* Clear to start a new line*/
		game.has_prompt = 0;
		game.input_buffer[game.cursor_pos = 0] = 0;
		_D (_D_WARN "clear lines");
	   	clear_lines (l, l + 1, bg);
		flush_lines (l, l + 1);

		break;
	case KEY_ESCAPE:
		_D (("KEY_ESCAPE"));
		new_input_mode (INPUT_MENU);
		break;
	case KEY_BACKSPACE:
		/* Ignore backspace at start of line */
		if (game.cursor_pos == 0) break;

		/* erase cursor */
		print_character (game.cursor_pos + 1, l, ' ', fg, bg);
		game.input_buffer[--game.cursor_pos] = 0;
		/* Print cursor */
		print_character (game.cursor_pos + 1, l, game.cursor_char, fg, bg );
		break;
	default:
		/* Ignore invalid keystrokes */
		if (key < 0x20 || key > 0x7f)
			break;

		/* Maximum input size reached */
		if (game.cursor_pos >= getvar (V_max_input_chars))
			break;

		game.input_buffer[game.cursor_pos++] = key;
		game.input_buffer[game.cursor_pos] = 0;

		/* echo */
		print_character (game.cursor_pos, l,
			game.input_buffer[game.cursor_pos - 1], fg, bg);

		/* Print cursor */
		print_character (game.cursor_pos + 1, l, game.cursor_char, fg, bg);
		break;
	}
}