⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kernel.c

📁 my kernel developed in djgpp
💻 C
字号:
//ANNA kernel by Glushko A.N
#include "k_defines.h"
//#include "keydefs.h"
#include "keys.h"
#include "string.h"
//#include <dirent.h>


void read(char [],unsigned int);
//It speaks for itself
void clear_screen() // clear the entire text screen
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;
	while(i<(80*2*25))
	{
		vidmem[i]=' ';
		i++;
		vidmem[i]=WHITE_TXT;
		i++;
	};
};

void clear_line(unsigned int line)
{
	char *vidmem=0xb8000;
	unsigned int i=0;
	i=(line*80*2);
	while (i<(line+1)*80*2)
	{
		vidmem[i]=' ';
		i++;
		i++;
	};
};


/*inline unsigned char inportb(unsigned short port)
{
	unsigned char ret_val;

	asm volatile("inb %w1,%b0"
		: "=a"(ret_val)
		: "d"(port));
	return ret_val;
};

void enable_ints()
{
	asm("sti");
};
void disable_ints()
{
	asm("cli");
};*/

//prints the data on the screen

unsigned int print(char mes[200], unsigned int line) // the message and then the line #
{
	char *message=mes;
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;

	i=(line*80*2);

	while(*message!=0)
	{
		if(*message=='\n') // check for a new line
		{
			line++;
			i=(line*80*2);
			*message++;
		} else {
			vidmem[i]=*message;
			*message++;
			i++;
			vidmem[i]=WHITE_TXT;
			i++;
		};
	};

	return(1);
};

unsigned int print_p(char mes[200], unsigned int line,unsigned int pos) // the message and then the line #
{
	char *message=mes;
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;
	pos=pos*2;

	i=(line*80*2+pos);

	while(*message!=0)
	{
		if(*message=='\n') // check for a new line
		{
			line++;
			i=(line*80*2+pos);
			*message++;
		} else {
			vidmem[i]=*message;
			*message++;
			i++;
			vidmem[i]=WHITE_TXT;
			i++;
		};
	};

	return(1);
};
//char temp[]="";
//reading the strings from the keyboard
/*void read_(unsigned int line){	int i=0,j=0;	i=(line*80*2);	j=(line*80);	KEY KeyGot=0x00;	char *vidmem = (char *) 0xb8000;	while (KeyGot!=ENTER)	{				KeyGot = getch();
		if(KeyGot==BACKSPACE){
			update_cursor_c(j--);
            i--;
			i--;
			//j--;
		}
		else{
		//temp[0]=KeyGot;
	    vidmem[i]=KeyGot;		i++;        vidmem[i]=WHITE_TXT;		//print((char)KeyGot,3);	    i++;		j++;		//k++;		update_cursor_c(j);		}	}}*/


inline void outportb_(unsigned int port,unsigned char value)  // Output a byte to a port
{
    asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
};

inline void outportw(unsigned int port,unsigned int value)  // Output a word to a port
{
    asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
};

//used to update cursor in the <<row>> and <<col>>)
void update_cursor(int row, int col)
{
	unsigned short position=(row*80) + col;
	// cursor LOW port to vga INDEX register
	outportb_(0x3D4, 0x0F);
	outportb_(0x3D5, (UCHAR)(position&0xFF));
	// cursor HIGH port to vga INDEX register
	outportb_(0x3D4, 0x0E);
	outportb_(0x3D5, (UCHAR)((position>>8)&0xFF));                                                  
};
//used to update cursor just in the <<col>
void update_cursor_c(int col)
{
	unsigned short position=col;
	// cursor LOW port to vga INDEX register
	outportb_(0x3D4, 0x0F);
	outportb_(0x3D5, (UCHAR)(position&0xFF));
	// cursor HIGH port to vga INDEX register
	outportb_(0x3D4, 0x0E);
	outportb_(0x3D5, (UCHAR)((position>>8)&0xFF));                                                   
};

void menu(char a[],char t_[],char p[],char q[],char dir[])
{
 
  clear_screen();
  print(a,0);
  update_cursor(4,0);
  for(;;){
	  KEY k=getch();
	if(k=='1')
		reboot();
	else if(k=='2')
		rdtest(t_);
	else if(k=='3'){
		update_cursor(4,0);
		print(p,5);
        read(dir,6);
		
		//q=strcat(q,dir);
		//opendir(dir);
	}
	else if(k==ESC)
	     main();
  }
};

void rdtest(char t[])
{
   read(t,5);
   //read_(5);
   update_cursor(5,0);
   print(t,6);
};

void help(char t[])
{
 print(t,5);
};

char message[] = "==================================================================================\n                     ANNA operating system welcomes you                      \n================================================================================";
char loadms[]="loading ANNA kernel...";
char a[]="Select a command or press [ESC] to close menu:\n 1.reboot\n 2.read test\n 3.set directory\n";
char b[]="ANNA operating system developed by Glushko A.N (c) 2009";
char c[]="Press [M] to choose a command or [H] for help\n>";
char help_[]="M - command menu: choose command to execute\n ";
char curdir[30]="";
char d[]="current directory: ";
char e[]="Type directory name:";
unsigned char temp[]="                                                 ";


void main(void) 
{

	clear_screen();
	print(loadms, 0);
	clear_screen();
	//print(message);
    //update_cursor(1, 0);
	print(message, 0);
	//update_cursor(3, 0);
	//read_(3);
    print(b, 3);
	//update_cursor(3, 0);
	 print(c, 4);
	update_cursor(5, 1);
    print(d,23);
	print_p(curdir,23, 19);
	for(;;){
	KEY k=getch();
	if(k=='m'){
		menu(a,temp,e,d,curdir);  	
	}
	else if(k=='h')
		help(help_);
	/*else if(k=='z'){
         temp[0]=k;
		 print(temp,5);
		 read(temp,6);
		 print(temp,7);
	     }*/
    }
	
	//update_cursor(5, 0);
	//read_(5);
	//k_printf(message, 1);
	//print_s(message, 2);
	//update_cursor(5, 0);
	for (;;) ; // Hang:  There is nowhere to return to
}

//reading the strings from the keyboard
void read(char p[],unsigned int line)
{
  int i=0,j=0,k=0;	i=(line*80*2);	j=(line*80);	KEY KeyGot=0x00;	char *vidmem = (char *) 0xb8000;	vidmem[line*80*2]='>';	j++;i++;    vidmem[i]=WHITE_TXT;	i++;	update_cursor_c(j);	while (KeyGot!=ENTER)	{				KeyGot = getch();
		if(KeyGot==BACKSPACE){
			if(j==(line*80))
			{/*update_cursor(line*80,1);*/}
			else{
			update_cursor_c(j--);
			vidmem[i]=NULL;
			p[k]=NULL;
            i--;
			//vidmem[i]='';
			i--;
			k--;
			//j--;
			}
		}
		else{
		p[k]=KeyGot;
	    vidmem[i]=KeyGot;		i++;        vidmem[i]=WHITE_TXT;		//print((char)KeyGot,3);	    i++;		j++;		k++;		update_cursor_c(j);		}	}
};

⌨️ 快捷键说明

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