tty.c

来自「raywill写的操作系统内核」· C语言 代码 · 共 73 行

C
73
字号
#include <maray/tty.h>


#define TAB_SIZE 8
#define thisline(vp) ((vp -VIDMEM)%80)
#define thisrow(vp)	((vp -VIDMEM)/80)

unsigned short* const VIDMEM = ((unsigned short*) 0xB8000);

static void clear( void );

unsigned short * vp;

void init_tty(void)
{
	vp=VIDMEM;
	clear();
}

void clrscr(void)
{
	clear();
}

void getxy(int *x,int  *y)
{
	*x=thisline(vp);
	*y=thisrow(vp);
}
void gotoxy(int x,int y)
{
	if(y<0||y>24||x<0||x>79)
		return;
	vp=VIDMEM+y*80+x;
}

static void clear( void )
{
    int i;
    for (i = 0; i < 80 * 25 ; i++)
        *vp++ = 0;
		vp = VIDMEM;
}



void print( const char* str )
{
    if( vp>=VIDMEM+80*25 )
    	{
    		clear();
    		vp=VIDMEM	;
    	}
    while (*str != '\0')
    {
        if(*str=='\n')
       	 	{
        		vp=vp + 80 - (vp -VIDMEM) % 80;
        		str++;
        		continue;
        	}
        if(*str=='\t')
        	{
        		vp=vp+TAB_SIZE-thisline(vp)%TAB_SIZE;
        		str++;
        		continue;	
        	}
        *vp++ = (0x0600 | ((unsigned short) *str++));
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?