Exemplo n.º 1
0
/**
 * keyboard_read() will invoke this routine after having recognized a key press.
 * 
 * @param tty  The key press is for whom.
 * @param key  The integer key with metadata.
 *****************************************************************************/
PUBLIC void in_process(TTY* tty, u32 key)
{
	if (!(key & FLAG_EXT)) {
		put_key(tty, key);
	}
	else {
		int raw_code = key & MASK_RAW;
		switch(raw_code) {
		case ENTER:
			put_key(tty, '\n');
			break;
		case BACKSPACE:
			put_key(tty, '\b');
			break;
		case UP:
			if ((key & FLAG_SHIFT_L) ||
			    (key & FLAG_SHIFT_R)) {	/* Shift + Up */
				scroll_screen(tty->console, SCR_DN);
			}
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) ||
			    (key & FLAG_SHIFT_R)) {	/* Shift + Down */
				scroll_screen(tty->console, SCR_UP);
			}
			break;
		case RIGHT:
			if ((key & FLAG_SHIFT_L) ||
			    (key & FLAG_SHIFT_R)) {	/* Shift + Right */
				select_console(current_console+1);
			}
			break;
		case LEFT:
			if ((key & FLAG_SHIFT_L) ||
			    (key & FLAG_SHIFT_R)) {	/* Shift + Left */
				select_console(current_console-1);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
		case F12:
			if ((key & FLAG_ALT_L) ||
			    (key & FLAG_ALT_R)) {	/* Alt + F1~F12 */
				select_console(raw_code - F1);
			}
			break;
		default:
			break;
		}
	}
}
Exemplo n.º 2
0
Arquivo: tty.c Projeto: kcao/kenos
/*======================================================================*
                           in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, t_32 key)
{
	if (!(key & FLAG_EXT)) {
		put_key(p_tty, key);
	}
	else {
		int raw_code = key & MASK_RAW;
		switch(raw_code) {
		case ENTER:
			put_key(p_tty, '\n');
			break;
		case BACKSPACE:
			put_key(p_tty, '\b');
			break;
		case UP:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) 
			{	/* Shift + Up */
				scroll_screen(p_tty->p_console,
						SCROLL_SCREEN_UP);
			}
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) 
			{	/* Shift + Down */
				scroll_screen(p_tty->p_console,
						SCROLL_SCREEN_DOWN);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
			if ((key & FLAG_ALT_L) || (key & FLAG_ALT_R)) 
			{	/* Alt + F1~F11 */
				select_console(raw_code - F1);
			}
			break;
		case F12:
			if ((key & FLAG_ALT_L) || (key & FLAG_ALT_R)) 
			{	
				if (schedule != sched0) {
					schedule = sched0;
				}
				else {
					schedule = (xmodfunc)XModPhyAddr;
				}
			}
			break;
		default:
			break;
		}
	}
}
Exemplo n.º 3
0
/*======================================================================*
				in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, u32 key)
{
        if (!(key & FLAG_EXT)) {
		put_key(p_tty, key);
        }
        else {
                int raw_code = key & MASK_RAW;
                switch(raw_code) {
                case ENTER:
			put_key(p_tty, '\n');
			break;
                case BACKSPACE:
			put_key(p_tty, '\b');
			break;
                case UP:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_DN);
                        }
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_UP);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
		case F12:
			/* Alt + F1~F12 */
			if ((key & FLAG_CTRL_L) || (key & FLAG_CTRL_R)) {
				select_console(raw_code - F1);
			}
			else {
				if (raw_code == F12) {
					disable_int();
					dump_proc(proc_table + 4);
					for(;;);
				}
			}
			break;
                default:
                        break;
                }
        }
}
Exemplo n.º 4
0
/*======================================================================*
                           in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, t_32 key)
{
	if (!(key & FLAG_EXT)) {
		put_key(p_tty, key);
		out_char(p_tty->p_console, key);
	}
	else {
		int raw_code = key & MASK_RAW;
		switch(raw_code) {
		case ENTER:

			put_key(p_tty, '\n');
			handle_command(p_tty);
			break;
		case BACKSPACE:
			if(p_tty->inbuf_count>0){
				out_char(p_tty->p_console, '\b');
			}
			put_key(p_tty, '\b');
			
			break;
		case UP:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {	/* Shift + Up */
				scroll_screen(p_tty->p_console, SCROLL_SCREEN_UP);
			}
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {	/* Shift + Down */
				scroll_screen(p_tty->p_console, SCROLL_SCREEN_DOWN);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
		case F12:
			if (1) {	/* Alt + F1~F12 */
				select_console(raw_code - F1);
			}
			break;
		default:
			break;
		}
	}
}
Exemplo n.º 5
0
/*======================================================================*
                           in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, t_32 key)
{
	if (!(key & FLAG_EXT)) {
		if (p_tty->startScanf==0) return ;
		put_key(p_tty, key);
		putToTemp(p_tty,key);
	}
	else {
		int raw_code = key & MASK_RAW;
		switch(raw_code) {
		case ENTER:
			put_key(p_tty, '\n');
			putToStr(p_tty);
			break;
		case BACKSPACE:
			if (p_tty->tmpLen)
			{
				put_key(p_tty, '\b');
				p_tty->tmpLen--;
			}
			break;
		case UP:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {	/* Shift + Up */
				scroll_screen(p_tty->p_console, SCROLL_SCREEN_UP);
			}
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {	/* Shift + Down */
				scroll_screen(p_tty->p_console, SCROLL_SCREEN_DOWN);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
		case F12:
			if ((key & FLAG_ALT_L) || (key & FLAG_ALT_R)) {	/* Alt + F1~F12 */
				select_console(raw_code - F1);
			}
			break;
		default:
			break;
		}
	}
}
Exemplo n.º 6
0
/*======================================================================*
                in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, u32 key)
{
        char output[2] = {'\0', '\0'};

        if (p_tty->disable_output) {
            sys_char = key;
            return;
        }

        if (!(key & FLAG_EXT)) {
            if (p_tty->inbuf_count < TTY_IN_BYTES) {
                *(p_tty->p_inbuf_head) = key;
                p_tty->p_inbuf_head++;
                if (p_tty->p_inbuf_head == p_tty->in_buf + TTY_IN_BYTES) {
                    p_tty->p_inbuf_head = p_tty->in_buf;
                }
                p_tty->inbuf_count++;
            }
        } else {
            int raw_code = key & MASK_RAW;
            switch(raw_code) {
                case UP:
                    if ((key & SHIFT_L) || (key & SHIFT_R)) {
                        scroll_screen(p_tty->p_console, SCR_UP);
                    }
                    break;
                case DOWN:
                    if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
                        scroll_screen(p_tty->p_console, SCR_DN);
                    }
                    break;
                case F1:
                case F2:
                case F3:
                    if ((key & FLAG_ALT_L) || (key & FLAG_ALT_R)) {
                        select_console(raw_code - F1);
                    }
                    break;
                case ENTER:
                    out_string(p_tty->p_console, "\n> ", Blue);
                    out_string(p_tty->p_console, "$ ", Light_Green);
                    break;
                case BACKSPACE:
                    out_char(p_tty->p_console, '\b', White);
                    break;
                default:
                    break;
            }
        }
}
Exemplo n.º 7
0
/*======================================================================*
				in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, u32 key)
{
        char output[2] = {'\0', '\0'};

        if (!(key & FLAG_EXT)) {
		put_key(p_tty, key);
        }
        else {
                int raw_code = key & MASK_RAW;
                switch(raw_code) {
                case ENTER:
			put_key(p_tty, '\n');
			break;
                case BACKSPACE:
			put_key(p_tty, '\b');
			break;
                case UP:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_DN);
                        }
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_UP);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
		case F12:
			/* Alt + F1~F12 */
			if ((key & FLAG_ALT_L) || (key & FLAG_ALT_R)) {
				select_console(raw_code - F1);
			}
			break;
                default:
                        break;
                }
        }
}
Exemplo n.º 8
0
void print_char(char ch)
{
    u16_t block = (white_on_black << 8) + ch;

    switch (ch)
    {
    case '\r':
        g_screen_cursor = (u16_t*)(((u32_t)(void*)g_screen_cursor - screen_init_cursor - 1) / (2 * screen_width) * 2 * screen_width + screen_init_cursor);
        break;
    case '\n':
        g_screen_cursor += screen_width;
        break;
    case 0:
        break;
    default:
        *g_screen_cursor = block;
        g_screen_cursor++;
        break;
    }

    if (g_screen_cursor >= (u16_t*)screen_end_cursor)
    {
        //clear_screen();
        scroll_screen();
    }

    update_cursor();
}
Exemplo n.º 9
0
void update()
{
  int x, y, z;

  current_view = (current_view == left_view) ? right_view : left_view;

  // draw complete background
  rectfill(current_view, 0, 0, 639, 479, BACKGROUND_COLOR);

  draw_sprite(current_view, new_game, NEW_GAME_BUTTON_X1, BUTTON_YOFF);
  draw_sprite(current_view,	undo,	  UNDO_BUTTON_X1, BUTTON_YOFF);
  draw_sprite(current_view,	help,	  HELP_BUTTON_X1, BUTTON_YOFF);
  draw_sprite(current_view,	quit,	  QUIT_BUTTON_X1, BUTTON_YOFF);

  if(editing)
  {
    textprintf(current_view, font, 200,  2, SELECTED,
	       "Editing: '%s' (%s)", layout_title, get_filename(editing));
    textprintf(current_view, font, 200, 12, SELECTED,
	       "%3i pieces left", n_pieces_left);
  }

  for(z = 0; z <  3; z++)
  for(y = 0; y <  9; y++)
  for(x = 0; x < 16; x++)
    if(board[x][y][z].value < EMPTY || editing)
      drawPiece(current_view, &board[x][y][z]);

  scroll_screen((current_view == left_view) ? 0 : SCREEN_WIDTH, 0);
  show_mouse(current_view);
}
Exemplo n.º 10
0
 void print(char ch) {
     switch (ch) {
     case '\n':
         ++_row;
         _column = 0;
         break;
     case '\t':
         _column += core::Log::TAB_NR_SPACES
             - (_column % core::Log::TAB_NR_SPACES);
         break;
     default:
         size_t position = 2 * ((_row * _gfx->columns) + _column);
         _gfx->start[position] = ch;
         _gfx->start[position + 1] = _color_code;
         ++_column;
         break;
     }
     
     if (_column >= _gfx->columns) {
         _column = 0;
         ++_row;
     }
     
     if (_row >= _gfx->rows) {
         --_row;
         scroll_screen();
     }
 }
Exemplo n.º 11
0
/**
 * Write a string on screen
 *
 * \param str String
 */
void kprint(char *str)
{
    unsigned int i = 0;
    char c;

    while((c = str[i]) != '\0') {
        switch(c) {
        case '\n':
            if(py <= VIDEO_ROWS) {
                py++;
                if(py >= VIDEO_ROWS) {
                    scroll_screen();
                    py = VIDEO_ROWS-1;
                }
            }
            px = 0;
            break;

        case '\r':
            if(px > 0) px--;
            break;

        case '\b':
            if(px > 0) px--;
            writechar(' ', c_attr);
            px--;
            break;

        default:
            writechar(str[i], c_attr);
        }
        i++;
    }
    return;
}
Exemplo n.º 12
0
/*======================================================================*
			   out_char
 *======================================================================*/
PUBLIC void out_char(CONSOLE* p_con, char ch)
{
	u8* p_vmem = (u8*)(V_MEM_BASE + p_con->cursor * 2);

	switch(ch) {
	case '\n':
		if (p_con->cursor < p_con->original_addr +
		    p_con->v_mem_limit - SCREEN_WIDTH) {
			p_con->cursor = p_con->original_addr + SCREEN_WIDTH * 
				((p_con->cursor - p_con->original_addr) /
				 SCREEN_WIDTH + 1);
		}
		break;
	case '\b':
		if (p_con->cursor > p_con->original_addr) {
			p_con->cursor--;
			*(p_vmem-2) = ' ';
			*(p_vmem-1) = DEFAULT_CHAR_COLOR;
		}
		break;
	case '\t':
		if (p_con->cursor <
		    p_con->original_addr + p_con->v_mem_limit - 1){
			int i=0;
			for (i=0;i<4;i++){
				*p_vmem++=' ';
				*p_vmem++=DEFAULT_CHAR_COLOR;
				p_con->cursor++;
			}

		}
		break;
	default:
		if (p_con->cursor <
		    p_con->original_addr + p_con->v_mem_limit - 1) {
			*p_vmem++ = ch;
			if (f1){
				*p_vmem++ = RED;
			}else if(f2){
				*p_vmem++ = BLUE;
			}else if(f3){
				*p_vmem++ = GREEN;
			}else if(f4){
				*p_vmem++ = CYAN;
			}else if(f5){
				*p_vmem++ = BROWN;
			}
			
			p_con->cursor++;
		}
		break;
	}

	while (p_con->cursor >= p_con->current_start_addr + SCREEN_SIZE) {
		scroll_screen(p_con, SCR_DN);
	}

	flush(p_con);
}
Exemplo n.º 13
0
Arquivo: tty.c Projeto: zzt93/Exercise
void in_process(struct Tty *p_tty, uint32_t key)
{

        if (!(key & FLAG_EXT)) {
                put_key(p_tty, key);
                
        } else {
                int raw_code = key & MASK_RAW;
                switch(raw_code) {
                case ENTER:
                        put_key(p_tty, 0x0a);
                        break;
                case BACKSPACE:
                        put_key(p_tty, '\b');
                        break;
                case UP:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R))
                                scroll_screen(p_tty->p_console, SCR_DN);
                        break;
                case DOWN:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R))
                                scroll_screen(p_tty->p_console, SCR_UP);
                        break;
                case F1:
                case F2:
                case F3:
                case F4:
                case F5:
                case F6:
                case F7:
                case F8:
                case F9:
                case F10:
                case F11:
                case F12:
                        /* Alt + F1~F12 */
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
                                select_console(raw_code - F1);
                        }
                        break;
                default:
                        break;
                }
        }

}
Exemplo n.º 14
0
/**
 * Print a char in a certain console.
 * 
 * @param con  The console to which the char is printed.
 * @param ch   The char to print.
 *****************************************************************************/
PUBLIC void out_char(CONSOLE* con, char ch)
{
	disable_int();

	u8* pch = (u8*)(V_MEM_BASE + con->cursor * 2);

	assert(con->cursor - con->orig < con->con_size);

	/*
	 * calculate the coordinate of cursor in current console (not in
	 * current screen)
	 */
	int cursor_x = (con->cursor - con->orig) % SCR_WIDTH;
	int cursor_y = (con->cursor - con->orig) / SCR_WIDTH;

	switch(ch) {
	case '\n':
		con->cursor = con->orig + SCR_WIDTH * (cursor_y + 1);
		break;
	case '\b':
		if (con->cursor > con->orig) {
			con->cursor--;
			*(pch - 2) = ' ';
			*(pch - 1) = DEFAULT_CHAR_COLOR;
		}
		break;
	default:
		*pch++ = ch;
		*pch++ = DEFAULT_CHAR_COLOR;
		con->cursor++;
		break;
	}

	if (con->cursor - con->orig >= con->con_size) {
		cursor_x = (con->cursor - con->orig) % SCR_WIDTH;
		cursor_y = (con->cursor - con->orig) / SCR_WIDTH;
		int cp_orig = con->orig + (cursor_y + 1) * SCR_WIDTH - SCR_SIZE;
		w_copy(con->orig, cp_orig, SCR_SIZE - SCR_WIDTH);
		con->crtc_start = con->orig;
		con->cursor = con->orig + (SCR_SIZE - SCR_WIDTH) + cursor_x;
		clear_screen(con->cursor, SCR_WIDTH);
		if (!con->is_full)
			con->is_full = 1;
	}

	assert(con->cursor - con->orig < con->con_size);

	while (con->cursor >= con->crtc_start + SCR_SIZE ||
	       con->cursor < con->crtc_start) {
		scroll_screen(con, SCR_UP);

		clear_screen(con->cursor, SCR_WIDTH);
	}

	flush(con);

	enable_int();
}
Exemplo n.º 15
0
/*======================================================================*
				in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, u32 key)
{
        char output[2] = {'\0', '\0'};

        if (!(key & FLAG_EXT)) {
		put_key(p_tty, key);
        }
        else {
                int raw_code = key & MASK_RAW;
                switch(raw_code) {
                case ENTER:
			put_key(p_tty, '\n');
			break;
                case BACKSPACE:
			put_key(p_tty, '\b');
			break;
				case TAB:
					put_key(p_tty,' ');					
					put_key(p_tty,' ');
					put_key(p_tty,' ');
					put_key(p_tty,' ');
					break;
                case UP:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_DN);
                        } else {
							changeColor();
						}
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_UP);
			} else {
					changeColor();
			}
			break;
		
                default:
                        break;
                }
        }
}
Exemplo n.º 16
0
/* show_video_bitmap:
 *  Page flipping function: swaps to display the specified video memory 
 *  bitmap object (this must be the same size as the physical screen).
 */
int show_video_bitmap(BITMAP *bitmap)
{
   if ((!is_video_bitmap(bitmap)) || 
       (bitmap->w != SCREEN_W) || (bitmap->h != SCREEN_H) ||
       (_dispsw_status))
      return -1;

   if (gfx_driver->show_video_bitmap)
      return gfx_driver->show_video_bitmap(bitmap);

   return scroll_screen(bitmap->x_ofs, bitmap->y_ofs);
}
Exemplo n.º 17
0
Arquivo: console.c Projeto: Zach41/OS
PUBLIC void out_char(CONSOLE *p_con, char ch) {
    u8* p_vmem = (u8*)(V_MEM_BASE + p_con -> cursor * 2);

    switch(ch) {
    case '\n':
	/* 回车键 */
	if (p_con -> cursor < p_con -> original_addr + p_con -> v_mem_limit - SCREEN_WIDTH) {
	    int line = (p_con -> cursor - p_con -> original_addr) / SCREEN_WIDTH + 1;
	    p_con -> cursor = p_con -> original_addr + SCREEN_WIDTH * line;
	}
	break;

    case '\b':
	/* Backspace */
	if (p_con -> cursor > p_con -> original_addr) {
	    p_con -> cursor--;
	    *(p_vmem-2) = ' ' ;
	    *(p_vmem-1) = DEFAULT_COLOR;
		
	}
	break;
    default:
	if (p_con -> cursor < p_con -> original_addr + p_con -> v_mem_limit - 1) {
	    *p_vmem++ = ch;
	    *p_vmem++ = DEFAULT_COLOR;
	    p_con -> cursor++;
	}
    }

    while (p_con -> cursor >= p_con -> current_start_addr + SCREEN_SIZE) {
	scroll_screen(p_con, SCR_DN);
    }

    while (p_con -> cursor < p_con -> current_start_addr) {
	/* 向上卷 */
	scroll_screen(p_con, SCR_UP);
    }

    flush(p_con);
}
Exemplo n.º 18
0
/*======================================================================*
               out_char
 *======================================================================*/
PUBLIC void out_char(CONSOLE* p_con, char ch, int color)
{
    int row, column;

    u8* p_vmem = (u8*)(V_MEM_BASE + p_con->cursor * 2);

    switch(ch) {
        case '\n':
            if (p_con->cursor < p_con->original_addr + 
                p_con->v_mem_limit - SCREEN_WIDTH) {
                p_con->cursor = p_con->original_addr + SCREEN_WIDTH * 
                        ((p_con->cursor - p_con->original_addr) / SCREEN_WIDTH + 1);
            }
            break;
        case '\b':
            row = (p_con->cursor - p_con->original_addr) / SCREEN_WIDTH;
            column = p_con->cursor - row * SCREEN_WIDTH;
            if (column > 4) {
                p_con->cursor--;
                *(p_vmem - 2) = ' ';
                *(p_vmem - 1) = White;
            }
            break;
        case '\t':
            out_string(p_con, "    ", color);
            break;
        default:
            if (p_con->cursor < p_con->original_addr + p_con->v_mem_limit - 1) {
                *p_vmem++ = ch;
                *p_vmem++ = color;
                p_con->cursor++;
            }
            break;
    }

    while (p_con->cursor >= p_con->current_start_addr + SCREEN_SIZE) {
        scroll_screen(p_con, SCR_DN);
    }
    if (p_con == console_table + nr_current_console){
        flush(p_con);
    }
}
Exemplo n.º 19
0
/* Be carefull:
 * You can not use printf or other function thant invoke out_char before the tty is inittied,
 * for the cursor_location is an invalid location, which whill result in Page Fault!
 * */
void out_char(CONSOLE * p_con,char ch)
{
	disp_pos=0;
	t_8	*vmem_p=(t_8 *)(V_MEM_BASE + p_con->cursor_location*2);
	switch(ch){
		case '\n':
			if(p_con->cursor_location + SCREEN_WIDETH < p_con->begin_adr+p_con->vmem_limit ){
				int line=(p_con->cursor_location - p_con->begin_adr)/SCREEN_WIDETH+1;
				p_con->cursor_location=line*SCREEN_WIDETH + p_con->begin_adr;
			}
			break;
		case '\b':
			if(p_con->cursor_location > p_con->begin_adr){
				p_con->cursor_location--;
				*(vmem_p-2)=' ';
				*(vmem_p-1)=COLOR;
			}
			break;
		default:
			if(p_con->cursor_location < p_con->begin_adr+p_con->vmem_limit){
				*vmem_p = ch;
				vmem_p++;
				*vmem_p = COLOR;
				vmem_p++;
				p_con->cursor_location++;
			}
			else{
				p_con->cursor_location=p_con->begin_adr;
				vmem_p=(t_8 *)(V_MEM_BASE + p_con->cursor_location*2);
				*vmem_p = ch;
				vmem_p++;
				*vmem_p = COLOR;
				vmem_p++;
				
			}
	}
	while(p_con->cursor_location >= p_con->current_start_addr + SCREEN_SIZE){
		scroll_screen(p_con,SCROLL_DOWN);
	}
	set_cursor(p_con->cursor_location);//display position

}
Exemplo n.º 20
0
/* request_scroll:
 *  Attempts to initiate a triple buffered hardware scroll, which will
 *  take place during the next retrace. Returns 0 on success.
 */
int request_scroll(int x, int y)
{
   int ret = 0;
   int h;

   /* can driver handle triple buffering? */
   if ((!gfx_driver->request_scroll) || (_dispsw_status)) {
      scroll_screen(x, y);
      return -1;
   }

   /* clip x */
   if (x < 0) {
      x = 0;
      ret = -1;
   }
   else if (x > (VIRTUAL_W - SCREEN_W)) {
      x = VIRTUAL_W - SCREEN_W;
      ret = -1;
   }

   /* clip y */
   if (y < 0) {
      y = 0;
      ret = -1;
   }
   else {
      h = (_screen_split_position > 0) ? _screen_split_position : SCREEN_H;
      if (y > (VIRTUAL_H - h)) {
	 y = VIRTUAL_H - h;
	 ret = -1;
      }
   }

   /* scroll! */
   if (gfx_driver->request_scroll(x, y) != 0)
      ret = -1;

   return ret;
}
Exemplo n.º 21
0
// 2 bytes are written: <color> then <character>
void display_character(uint8_t c) {
	uint16_t attr = color << 8; // first byte is color
	uint16_t *loc = video_memory + (80*cursor_y + cursor_x);

	// backspace
	if (c == 0x08 && !(cursor_x==0 && cursor_y==8)) {
		if (cursor_x == 0) {
			cursor_x = 79;
			cursor_y --;
		}
		else
			cursor_x--;
		*(loc-1) = ' ' | attr;
	}
	// tab
	else if (c == 0x09) cursor_x = 8 * ((cursor_x+8)/8);
	// carriage return
	else if (c == '\r') cursor_x = 0;
	// new line
	else if (c == '\n') {
		cursor_x = 0;
		cursor_y++;
	}	
	// other characters
	else if(c >= 32) {
		*loc = c | attr;
		cursor_x++;
	}

	// edge conditions
	if (cursor_x >= 80) { // goto next line
		cursor_x = 0;
		cursor_y++;
	}
	if (cursor_y >= 25) { // scroll screen up
		scroll_screen();
	}

	set_cursor(cursor_x,cursor_y);
}
Exemplo n.º 22
0
static void vga_putc(int c)
{
    bool new_row = false;

    switch ( c ) {
        case '\n':
            cursor_y++;
            cursor_x = 0;
            new_row = true;
            break;
        case '\r':
            cursor_x = 0;
            break;
        case '\t':
            cursor_x += 4;
            break;
        default:
            __putc(cursor_x, cursor_y, c);
            cursor_x++;
            break;
    }

    if ( cursor_x >= MAX_COLS ) {
        cursor_x %= MAX_COLS;
        cursor_y++;
        new_row = true;
    }

    if ( new_row ) {
        num_lines++;
        if ( cursor_y >= MAX_LINES ) {
            scroll_screen();
            cursor_y--;
        }

        /* (optionally) pause after every screenful */
        if ( (num_lines % (MAX_LINES - 1)) == 0 && g_vga_delay > 0 )
            delay(g_vga_delay * 1000);
    }
}
Exemplo n.º 23
0
/**
 * Write a character on screen
 *
 * \param ch Character
 * \param attr Character attribute (color)
 */
void writechar(char ch, unsigned char attr)
{
    unsigned int pos;

    pos = ((VIDEO_COLS * py) + px) * 2;

    /* Update cursor position */
    if(px >= VIDEO_COLS) {
        px = 0;
        py++;

        if(py >= VIDEO_ROWS) {
            scroll_screen();
            py = VIDEO_ROWS-1;
        }
    } else {
        px++;
    }

    videomem[pos]   = ch;
    videomem[pos+1] = attr;
}
Exemplo n.º 24
0
/*======================================================================*
			   out_char
 *======================================================================*/
PUBLIC void out_char(CONSOLE* p_con, char ch , char color)
{
	u8* p_vmem = (u8*)(V_MEM_BASE + p_con->cursor * 2);

	switch(ch) {
	case '\n':
		if (p_con->cursor < p_con->original_addr +
		    p_con->v_mem_limit - SCREEN_WIDTH) {
			p_con->cursor = p_con->original_addr + SCREEN_WIDTH * 
				((p_con->cursor - p_con->original_addr) /
				 SCREEN_WIDTH + 1);
		}
		break;
	case '\b':
		if (p_con->cursor > p_con->original_addr) {
			p_con->cursor--;
			*(p_vmem-2) = ' ';
			*(p_vmem-1) = DEFAULT_CHAR_COLOR;
		}
		break;
	default:
		if (p_con->cursor <
		    p_con->original_addr + p_con->v_mem_limit - 1) {
			*p_vmem++ = ch;
			*p_vmem++ = color;
			p_con->cursor++;
		}
		break;
	}

	while (p_con->cursor >= p_con->current_start_addr + SCREEN_SIZE) {
		scroll_screen(p_con, SCR_DN);
	}

	flush(p_con);
}
Exemplo n.º 25
0
int main(void)
{
   BITMAP *scroller;
   RGB black = { 0, 0, 0, 0 };
   int x = 0;
   int next_x;
   int h = 100;

   if (allegro_init() != 0)
      return 1;
   install_keyboard();

   if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 640, 240) != 0) {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set a 320x240 mode with 640x240 "
		      "virtual dimensions\n");
      return 1;
   }

   /* the scrolling area is twice the width of the screen (640x240) */
   scroller = create_sub_bitmap(screen, 0, 0, SCREEN_W*2, SCREEN_H);

   set_palette(desktop_palette);
   set_color(0, &black);

   rectfill(scroller, 0, 0, SCREEN_W, 100, 6);
   rectfill(scroller, 0, 100, SCREEN_W, SCREEN_H, 2);

   do {
      /* advance the scroller, wrapping every 320 pixels */
      next_x = x + 1;
      if (next_x >= 320)
	 next_x = 0;

      /* draw another column of the landscape */
      acquire_bitmap(scroller);
      vline(scroller, next_x+SCREEN_W-1, 0, h, 6);
      vline(scroller, next_x+SCREEN_W-1, h+1, SCREEN_H, 2);
      release_bitmap(scroller);

      /* scroll the screen */
      scroll_screen(next_x, 0);

      /* duplicate the landscape column so we can wrap the scroller */
      if (next_x > 0) {
	 acquire_bitmap(scroller);
	 vline(scroller, x, 0, h, 6);
	 vline(scroller, x, h+1, SCREEN_H, 2);
	 release_bitmap(scroller);
      }

      /* randomly alter the landscape position */
      if (AL_RAND()&1) {
	 if (h > 5)
	    h--;
      }
      else {
	 if (h < 195)
	    h++;
      }

      x = next_x;

      rest(0);
   } while (!keypressed());

   destroy_bitmap(scroller);

   clear_keybuf();

   return 0;
}
Exemplo n.º 26
0
int main(int argc, char *argv[])
{
  {
    int i;

    if((argc - 1) % 2)
      goto help;

    for(i = 1; i < argc - 1; i += 2)
      if(!editing && (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--edit")))
	editing = argv[i+1];
      else if(!layout_title[0] && (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--title")))
      {
	bzero(layout_title, 55);
	strncpy(layout_title, argv[i+1], 54);
      }
      else
      {
help:
	printf("usage: mahjong [--edit <layout> [--title <layout title>]]\n");
	return 0;
      }
  }

  srand(time(NULL));
  allegro_init();

  {
    int x, y, z;
    for(x = 16; x--;)
    for(y =  9; y--;)
    for(z =  3; z--;)
      pieceInit(board[x][y][z], x, y, z);
  }

  set_color_depth(SCREEN_DEPTH);

  if(set_gfx_mode(GFX_AUTODETECT_WINDOWED,
      SCREEN_WIDTH,   SCREEN_HEIGHT,
      SCREEN_WIDTH*2, SCREEN_HEIGHT) < 0)
  {
    fprintf(stderr, "fatal: %s\n", allegro_error);
    exit(1);
  }

#ifdef ALLEGRO_WINDOWS
  set_display_switch_callback(SWITCH_IN, update);
#endif

  left_view =
    create_sub_bitmap(screen, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  right_view =
    create_sub_bitmap(screen, SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

  // init colors
    BACKGROUND_COLOR = makecol32(0x2F, 0x5F, 0x2F); // soft green
      SELECTED_COLOR = makecol32(0x00, 0xDF, 0x00); // green
  OLD_SELECTED_COLOR = makecol32(0x00, 0xBF, 0xBF); // cyan

  // load data
  {
    DATAFILE *data = load_datafile("#");
    new_game   = data[NEW_GAME_BMP].dat;
    undo       = data[UNDO_BMP].dat;
    help       = data[HELP_BMP].dat;
    quit       = data[QUIT_BMP].dat;
    tile       = data[TILE_BMP].dat;
    number[ 0] = data[BLACK1_BMP].dat;
    number[ 2] = data[BLACK2_BMP].dat;
    number[ 4] = data[BLACK3_BMP].dat;
    number[ 6] = data[BLACK4_BMP].dat;
    number[ 8] = data[BLACK5_BMP].dat;
    number[10] = data[BLACK6_BMP].dat;
    number[12] = data[BLACK7_BMP].dat;
    number[14] = data[BLACK8_BMP].dat;
    number[16] = data[BLACK9_BMP].dat;
    number[ 1] = data[RED1_BMP].dat;
    number[ 3] = data[RED2_BMP].dat;
    number[ 5] = data[RED3_BMP].dat;
    number[ 7] = data[RED4_BMP].dat;
    number[ 9] = data[RED5_BMP].dat;
    number[11] = data[RED6_BMP].dat;
    number[13] = data[RED7_BMP].dat;
    number[15] = data[RED8_BMP].dat;
    number[17] = data[RED9_BMP].dat;
    suit[0]    = data[SPADE_BMP].dat;
    suit[1]    = data[CLUB_BMP].dat;
    suit[2]    = data[DIAMOND_BMP].dat;
    suit[3]    = data[HEART_BMP].dat;
    layouts[0] = data[BLOCK_LYT].dat;
    layouts[1] = data[FLAT_LYT].dat;
    layouts[2] = data[FROGGER_LYT].dat;
    layouts[3] = data[PRECIOUS_LYT].dat;
    layouts[4] = data[PTRAD_LYT].dat;
    layouts[5] = data[PYRAMID_LYT].dat;
    layouts[6] = data[STEPS_LYT].dat;
    layouts[7] = data[THETA_LYT].dat;
  }

  scroll_screen(SCREEN_WIDTH, 0);
  current_view = right_view;

  install_timer();
  install_mouse();
  install_keyboard();
  show_mouse(current_view);

  text_mode(BACKGROUND_COLOR);

  if(!editing)
  {
    defaultLayout();

    if(alert("Our Own Version of Mahjong Solitaire, v0.1.4", NULL,
	     "Copyright (c) 2001 Eric Mulvaney, Michelle Bondy",
	     "Play", "Edit", 0, 0) == 2
	&& file_select_ex("Please select layout file to edit:", path, "lyt",
	    PATH_LENGTH-1, OLD_FILESEL_WIDTH, OLD_FILESEL_HEIGHT))
    {
      int x, y, z;

      editing = path;

      for(x = 16; x--;)
      for(y =  9; y--;)
      for(z =  3; z--;)
	board[x][y][z].value = EMPTY;
    }
  }

  mouse_callback = editing ? mouse_handler_for_editing : mouse_handler;

  if(editing)
  {
    Layout data;
    FILE *file = fopen(editing, "r");

    if(file)
    {
      if(fread(&data, sizeof(Layout), 1, file))
      {
	int x, y, z;

	if(!layout_title[0])
	  memcpy(layout_title, data.title, 55);

	for(x = 16; x--;)
	for(y =  9; y--;)
	for(z = (data.board[x][y] > 3) ? 3 : data.board[x][y]; z--;)
	{
	  board[x][y][z].value = BLANK;
	  if(!--n_pieces_left)
	    goto skip;
	}
      }
skip:
      fclose(file);
    }

    update();
  }

  click_ready = 0;
  while(1) // game loop
  {
    if(click_ready)
    {
      int x = click_x - (BOARD_XOFF - 2 * EDGE_WIDTH );
      int y = click_y - (BOARD_YOFF - 2 * EDGE_HEIGHT);
      int z;

      for(z = 3; x > 0 && y > 0 && z--; x -= EDGE_WIDTH, y -= EDGE_HEIGHT)
      {
	int i = x / FACE_WIDTH;
	int j = y / FACE_HEIGHT;

	if(i >= 16 || j >= 9)
	  continue;

	if(editing)
	{
	  if(click_ready == 1 && board[i][j][z].value == EMPTY)
	  {
	    if((z == 0 || board[i][j][z-1].value != EMPTY) && n_pieces_left)
	    {
	      n_pieces_left--;
	      board[i][j][z].value = BLANK;
	      updatePiece(&board[i][j][z]);
	      goto event_handled;
	    }
	  }
	  else if(click_ready == 2 && board[i][j][z].value != EMPTY)
	  {
	    if(z == 2 || board[i][j][z+1].value == EMPTY)
	    {
	      board[i][j][z].value = EMPTY;
	      n_pieces_left++;
	      updatePiece(&board[i][j][z]);
	      goto event_handled;
	    }
	  }
	}
	else if(selectPiece(&board[i][j][z]))
	{
	  if(!n_pairs_remaining)
	  {
	    if(current_view != left_view)
	      update();

	    if(alert("Congratulations!	You won!",
		     "Play another?",
		     NULL, "Yes", "No", 0, 0) == 1)
	      newGame();
	    else
	      return 0;
	  }

	  goto event_handled;
	}
      }

      if(click_y < BUTTON_YOFF + BUTTON_HEIGHT && click_y > BUTTON_YOFF)
      {
	if(editing)
	{
	  if(click_x > NEW_GAME_BUTTON_X1 && click_x < NEW_GAME_BUTTON_X2)
	  {
	    if(n_pieces_left == 144)
	      goto event_handled;

	    if(current_view != left_view)
	      update();

	    if(alert("Are you sure you want to clear the current Layout?",
		     NULL, NULL, "Yes", "No", 0, 0) == 1)
	    {
	      int x, y, z;
	      for(x = 16; x--;)
	      for(y =  9; y--;)
	      for(z =  3; z--;)
		board[x][y][z].value = EMPTY;
	      n_pieces_left = 144;
	      update();
	    }
	  }
	  else if(click_x > QUIT_BUTTON_X1 && click_x < QUIT_BUTTON_X2)
	  {
	    int ync;

	    if(current_view != left_view)
	      update();

	    if(n_pieces_left)
	      ync = alert3("WARNING: Layout is incomplete.",
			   NULL,
			   "Do you wish to save before exiting?",
			   "Yes", "No", "Cancel", 0, 0, 0);
	    else
	      ync = alert3("Do you wish to save before exiting?",
		    NULL, NULL, "Yes", "No", "Cancel", 0, 0, 0);

	    if(ync == 2)
	      return 0;
	    else if(ync == 1)
	    {
	      Layout data;
	      FILE *file;

	      memcpy(data.title, layout_title, 55);

	      data.complete = (n_pieces_left) ? 0 : 1;

	      if((file = fopen(editing, "w")))
	      {
		for(x = 16; x--;)
		for(y =  9; y--;)
		{
		  if	 (board[x][y][2].value == BLANK) data.board[x][y] = 3;
		  else if(board[x][y][1].value == BLANK) data.board[x][y] = 2;
		  else if(board[x][y][0].value == BLANK) data.board[x][y] = 1;
		  else					 data.board[x][y] = 0;
		}

		if(fwrite(&data, sizeof(Layout), 1, file))
		{
		  fclose(file);
		  return 0;
		}
		else
		  fclose(file);
	      }

	      if(alert("WARNING: Save failed!",
		       NULL,
		       "Do you still wish to exit?",
		       "Yes", "No", 0, 0) == 1)
		return 0;
	    }
	  }
	}
	else if(click_x > NEW_GAME_BUTTON_X1 && click_x < NEW_GAME_BUTTON_X2)
	  newGame();
	else if(click_x > UNDO_BUTTON_X1 && click_x < UNDO_BUTTON_X2)
	  undoMove();
	else if(click_x > HELP_BUTTON_X1 && click_x < HELP_BUTTON_X2)
	  giveHelp(1);
	else if(click_x > QUIT_BUTTON_X1 && click_x < QUIT_BUTTON_X2)
	{
	  if(current_view != left_view)
	    update();

	  if(alert("Are you sure you want to quit?",
	      NULL, NULL, "Yes", "No", 0, 0) == 1)
	    return 0;
	}
      }

event_handled:

      click_ready = 0;
    }
    else
      rest(100);
  }

  return 0;
}
Exemplo n.º 27
0
void scroll_text(char* s){
	uint16_t i;
	for (i=0;s[i]!=0;i++) {
		scroll_screen(s[i]);
	}
}
Exemplo n.º 28
0
/**
 * Yes, it is an ugly function.
 *
 * @param tty  Which TTY is reading the keyboard input.
 *****************************************************************************/
PUBLIC void keyboard_read(TTY* tty)
{
	if (!is_current_console((CONSOLE *)tty->tty_dev)) return;

	u8	scan_code;

	/**
	 * 1 : make
	 * 0 : break
	 */
	int	make;

	/**
	 * We use a integer to record a key press.
	 * For instance, if the key HOME is pressed, key will be evaluated to
	 * `HOME' defined in keyboard.h.
	 */
	u32	key = 0;


	/**
	 * This var points to a row in keymap[]. I don't use two-dimension
	 * array because I don't like it.
	 */
	u32*	keyrow;

	while (kb_in.count > 0) {
		code_with_E0 = 0;
		scan_code = get_byte_from_kb_buf();

		/* parse the scan code below */
		if (scan_code == 0xE1) {
			int i;
			u8 pausebreak_scan_code[] = {0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5};
			int is_pausebreak = 1;
			for (i = 1; i < 6; i++) {
				if (get_byte_from_kb_buf() != pausebreak_scan_code[i]) {
					is_pausebreak = 0;
					break;
				}
			}
			if (is_pausebreak) {
				key = PAUSEBREAK;
			}
		}
		else if (scan_code == 0xE0) {
			code_with_E0 = 1;
			scan_code = get_byte_from_kb_buf();

			/* PrintScreen is pressed */
			if (scan_code == 0x2A) {
				code_with_E0 = 0;
				if ((scan_code = get_byte_from_kb_buf()) == 0xE0) {
					code_with_E0 = 1;
					if ((scan_code = get_byte_from_kb_buf()) == 0x37) {
						key = PRINTSCREEN;
						make = 1;
					}
				}
			}
			/* PrintScreen is released */
			else if (scan_code == 0xB7) {
				code_with_E0 = 0;
				if ((scan_code = get_byte_from_kb_buf()) == 0xE0) {
					code_with_E0 = 1;
					if ((scan_code = get_byte_from_kb_buf()) == 0xAA) {
						key = PRINTSCREEN;
						make = 0;
					}
				}
			}
		}

		if ((key != PAUSEBREAK) && (key != PRINTSCREEN)) {
			int caps;

			/* make or break */
			make = (scan_code & FLAG_BREAK ? 0 : 1);
			
			keyrow = &keymap[(scan_code & 0177) * MAP_COLS];

			column = 0;

			caps = shift_l || shift_r;
			if (caps_lock &&
			    keyrow[0] >= 'a' && keyrow[0] <= 'z')
				caps = !caps;

			if (caps)
				column = 1;

			if (code_with_E0)
				column = 2;

			if (ctrl_l || ctrl_r) column = 3;

			key = keyrow[column];

			switch(key) {
			case SHIFT_L:
				shift_l	= make;
				break;
			case SHIFT_R:
				shift_r	= make;
				break;
			case CTRL_L:
				ctrl_l	= make;
				break;
			case CTRL_R:
				ctrl_r	= make;
				break;
			case ALT_L:
				alt_l	= make;
				break;
			case ALT_R:
				alt_l	= make;
				break;
			case CAPS_LOCK:
				if (make) {
					caps_lock   = !caps_lock;
					set_leds();
				}
				break;
			case NUM_LOCK:
				if (make) {
					num_lock    = !num_lock;
					set_leds();
				}
				break;
			case SCROLL_LOCK:
				if (make) {
					scroll_lock = !scroll_lock;
					set_leds();
				}
				break;
			default:
				break;
			}
		}

		if(make){ /* Break Code is ignored */
			int pad = 0;

			/* deal with the numpad first */
			if ((key >= PAD_SLASH) && (key <= PAD_9)) {
				pad = 1;
				switch(key) {	/* '/', '*', '-', '+',
						 * and 'Enter' in num pad
						 */
				case PAD_SLASH:
					key = '/';
					break;
				case PAD_STAR:
					key = '*';
					break;
				case PAD_MINUS:
					key = '-';
					break;
				case PAD_PLUS:
					key = '+';
					break;
				case PAD_ENTER:
					key = ENTER;
					break;
				default:
					/* the value of these keys
					 * depends on the Numlock
					 */
					if (num_lock) {	/* '0' ~ '9' and '.' in num pad */
						if (key >= PAD_0 && key <= PAD_9)
							key = key - PAD_0 + '0';
						else if (key == PAD_DOT)
							key = '.';
					}
					else{
						switch(key) {
						case PAD_HOME:
							key = HOME;
							break;
						case PAD_END:
							key = END;
							break;
						case PAD_PAGEUP:
							key = PAGEUP;
							break;
						case PAD_PAGEDOWN:
							key = PAGEDOWN;
							break;
						case PAD_INS:
							key = INSERT;
							break;
						case PAD_UP:
							key = UP;
							break;
						case PAD_DOWN:
							key = DOWN;
							break;
						case PAD_LEFT:
							key = LEFT;
							break;
						case PAD_RIGHT:
							key = RIGHT;
							break;
						case PAD_DOT:
							key = DELETE;
							break;
						default:
							break;
						}
					}
					break;
				}
			}
			key |= shift_l	? FLAG_SHIFT_L	: 0;
			key |= shift_r	? FLAG_SHIFT_R	: 0;
			key |= ctrl_l	? FLAG_CTRL_L	: 0;
			key |= ctrl_r	? FLAG_CTRL_R	: 0;
			key |= alt_l	? FLAG_ALT_L	: 0;
			key |= alt_r	? FLAG_ALT_R	: 0;
			key |= pad	? FLAG_PAD	: 0;

			int raw_code = key & MASK_RAW;
			switch(raw_code) {
			case UP:
				if ((key & FLAG_SHIFT_L) ||
				    (key & FLAG_SHIFT_R)) {	/* Shift + Up */
					scroll_screen((CONSOLE *)tty->tty_dev, SCR_DN);
				}
				break;
			case DOWN:
				if ((key & FLAG_SHIFT_L) ||
			 	   (key & FLAG_SHIFT_R)) {	/* Shift + Down */
					scroll_screen((CONSOLE *)tty->tty_dev, SCR_UP);
				}
				break;
			case F1:
			case F2:
			case F3:
			case F4:
			case F5:
			case F6:
			case F7:
			case F8:
			case F9:
			case F10:
			case F11:
			case F12:
				if ((key & FLAG_ALT_L) ||
				    (key & FLAG_ALT_R)) {	/* Alt + F1~F12 */
					select_console(raw_code - F1);
				}
				break;
			default:
				break;
			}
			in_process(tty, key);
		}
	}
}
Exemplo n.º 29
0
/*======================================================================*
			   out_char
 *======================================================================*/
PUBLIC void out_char(CONSOLE* p_con, char ch)
{
        
        /*if(clear){
               p_con->cursor=p_con->original_addr;
               clear=0;
        }*/

         u8* p_vmem = (u8*)(V_MEM_BASE + p_con->cursor * 2);
       // last_cursor[0]=p_con->original_addr;
        int i=0;
        for(i;i<count;i++){
             if(last_cursor[i][0]==p_con->original_addr)
                     break;
        }
        if(i==count){
             int j=0;
             for(;j<100;j++){
                    last_cursor[i][j]=0;
             }
             size[i]=0;
             last_cursor[i][0]=p_con->original_addr;
             count++;
        }

/*
	unsigned int	current_start_addr;	 当前显示到了什么位置	  
	unsigned int	original_addr;		 当前控制台对应显存位置 
	unsigned int	v_mem_limit;		 当前控制台占的显存大小 
	unsigned int	cursor;			 当前光标位置 
*/
        //last_cursor[i][++size[i]]=p_con->cursor;

        // disp_str(shit+'0');
       // last_cursor[i][shit]=i;

        int j=0;
	switch(ch) {
	case '\n':
		if (p_con->cursor < p_con->original_addr +
		    p_con->v_mem_limit - SCREEN_WIDTH) {
                       last_cursor[i][++size[i]]=p_con->cursor;
			p_con->cursor = p_con->original_addr + SCREEN_WIDTH * 
				((p_con->cursor - p_con->original_addr) /
				 SCREEN_WIDTH + 1);
		}
		break;
	case '\b':
		if (p_con->cursor > p_con->original_addr) {
                        if(isTab(p_con)){
                            p_con->cursor=p_con->cursor-4;
                            *(p_vmem-2) = ' ';
			    *(p_vmem-1) = DEFAULT_CHAR_COLOR;
                            tabSize--;
                        }
                        else{ 
                          if((p_con->cursor-p_con->original_addr)%SCREEN_WIDTH==0){
                              if(size[i]>=1&&size[i]<=99){
                                     p_con->cursor=last_cursor[i][size[i]--];
                               }else
                                  p_con->cursor=last_cursor[i][0];
                              
                           }else
			       p_con->cursor--;
                        
			*(p_vmem-2) = ' ';
			*(p_vmem-1) = DEFAULT_CHAR_COLOR;
                        }
		}
		break;
        case '\t':
                   p_con->cursor+=4;
                   lastTab[tabSize]=p_con->cursor;
                   tabSize++;
               break;
	default:
		if (p_con->cursor <
		    p_con->original_addr + p_con->v_mem_limit - 1) {
			*p_vmem++ = ch;
                        //*p_vmem++ = DEFAULT_CHAR_COLOR;
                        if(color==2){
			   *p_vmem++ = F2_COLOR; 
                         }else if(color==3){
			   *p_vmem++ = F3_COLOR; //blue
                         }else if(color==4){
			   *p_vmem++ = F4_COLOR;                            
                         }else if(color==5){//green
			   *p_vmem++ = F5_COLOR;                          
                         }else
			   *p_vmem++=DEFAULT_CHAR_COLOR;   
                        //last_cursor= p_con->cursor;                     
                        p_con->cursor++;
		}
		break;
	}

       /* if(tab){
              lastTab[tabSize]=p_con->cursor;
              tabSize++;
              tab=0;
        }*/

	while (p_con->cursor >= p_con->current_start_addr + SCREEN_SIZE) {
		scroll_screen(p_con, SCR_DN);
	}

	flush(p_con);
}
Exemplo n.º 30
0
/**
 * Prints a character to the screen, is used
 * by kprintf and kputs
 *
 * @param c Character to print
 **/
void kputch(unsigned char c)
{
    unsigned short *where;
    unsigned att = get_attribute() << 8;


    if(c == 0x08)
    {
		/// ! SELBER SCHREIBEN !
        if(get_cursor_x() != 0) set_cursor_x(get_cursor_x() - 1);
    }

	//
    else if(c == 0x09)
    {
        int newx;

		/// ! SELBER SCHREIBEN !
        newx = (get_cursor_x() + 8) & ~(8 - 1);

        set_cursor_x(newx);
    }

	// Carriage return? Set the cursor to the beginning of the current line
    else if(c == '\r')
    {
		/// ! SELBER SCHREIBEN !
        set_cursor_x(0);
    }

	// Linefeed? Set the cursor to the next line
    else if(c == '\n')
    {
		/// ! SELBER SCHREIBEN !
        set_cursor_x(0);
        set_cursor_y(get_cursor_y() + 1);
    }

    else if(c >= ' ')
    {
		/// ! SELBER SCHREIBEN !
        //FIXME: get_textmemptr() doesn't work here (whyever...)
        where = (unsigned short*)0xB8000 + (get_cursor_y() * 80 + get_cursor_x());
        *where = c | att;
        set_cursor_x(get_cursor_x() + 1);
    }

	/// ! SELBER SCHREIBEN !

    // More than 80 lines? Scroll the screen
    if(get_cursor_x() >= 80)
    {
        set_cursor_x(0);
        set_cursor_y(get_cursor_y() + 1);
    }

	/// ! SELBER SCHREIBEN !

    // Scroll the screen and move the cursor
    scroll_screen();
    move_cursor();
}