示例#1
0
//function to print a character to the screen
void print_char(char character, int row, int col, char attribute){

  //pointer to start of video memory
  unsigned char* vidmem = (unsigned char*) VID_ADDR;
  
  //default color scheme
  if (!attribute){
    attribute = WHIT_BLK;
  }

  //memory offset
  int offset; 
  // if row and col < 0, offset is cursor

  if (col >= 0 && row >= 0){
    offset = get_screen_offset(col, row);
  }
  else {
    offset = get_cursor();
  }
  int backspace = 0;
  if (character == '\b'){
    //backspace
    offset -= 2;
    character = ' ';
    backspace = 1;
  }
  
  if (character == '\n'){
    //new line
    int rows = offset / (2 * MAX_COLS);
    offset = get_screen_offset(79, rows);
  }

  else{
    unsigned char* locale = vidmem + offset;
    unsigned char* attr_locale = vidmem + offset + 1;
    *locale = character;
    *attr_locale = attribute;
  }

  if (backspace == 0){
    offset += 2;
  }
  offset = handle_scrolling(offset);
  set_cursor(offset);
}
示例#2
0
文件: screen.c 项目: daomtquan/MisaOS
/*
 Print a char on the screen at col, row, or at cursor position
*/
void print_char(char nChar, int nCol, int nRow, char nAttribute)
{
	unsigned char * pVidMem = (unsigned char*) VIDEO_ADDRESS;

	if (!nAttribute)
	{
		nAttribute = WHITE_ON_BLACK;
	}

	int offset = 0;
	
//	if (nCol >= 0 && nRow >= 0)
//	{
//		offset = get_screen_offset(nCol, nRow);
//	}	
//	else
//	{
		offset = get_cursor();
//	}


	
	if (nChar == '\n')
	{
		int rows = offset / (2*MAX_COLS);
		offset = get_screen_offset(79, rows);
		offset += 2;
	}
	else
	{
		pVidMem[offset] = nChar;
		pVidMem[offset + 1] = nAttribute;
		offset += 2;		
	}
	
	offset = handle_scrolling(offset);
	
	set_cursor(offset);
}
示例#3
0
/* Print a char on the screen at col , row , or at cursor position */
void print_char(const char character, int col, int row, char attribute_byte)
{
  /* Create a byte ( char ) pointer to the start of video memory */
  unsigned char volatile *vidmem = VIDEO_ADDRESS;
  /* If attribute byte is zero , assume the default style . */
  if (!attribute_byte) {
    attribute_byte = WHITE_ON_BLACK;
  }
  /* Get the video memory offset for the screen location */
  int offset;
  /* If col and row are non - negative , use them for offset . */
  if (col >= 0 && row >= 0) {
    offset = get_screen_offset(col, row);
    /* Otherwise , use the current cursor position . */
  } else {
    offset = get_cursor();
  }
  // If we see a newline character , set offset to the end of
  // current row , so it will be advanced to the first col
  // of the next row.
  if (character == '\n') {
    int rows = offset / (2 * MAX_COLS);
    offset = get_screen_offset(79, rows);
    // Otherwise , write the character and its attribute byte to
    // video memory at our calculated offset .
  } else {
    vidmem[offset] = character;
    vidmem[offset + 1] = attribute_byte;
  }
  // Update the offset to the next character cell , which is
  // two bytes ahead of the current cell .
  offset += 2;
  // Make scrolling adjustment , for when we reach the bottom
  // of the screen .
  offset = handle_scrolling(offset);
  // Update the cursor position on the screen device .
  set_cursor(offset);
}