Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define WHITE_TXT 0x07 // white on black text
- void k_clear_screen(); //the function to clear the screen
- int k_printf(char *message, int line); //printf function
- char test[58] = "This line is from a character datatype Defined in Globals!";
- char inb(short); //read input from an address given by the short
- void outb(short, char); //output to the address given by the short
- int temp; //a temporary variable to hold the scancode
- char current[1000]; //our current stuff typed in
- int inparse=0; //a generic variable to move through current and place the latest keypress
- int x; //generic variable for looping
- int y; //generic variable for looping
- char output[1000]; //our output (Stuff put out by echo, etc)
- char lowercase[128] = "001234567890-=0 qwertyuiop[]00asdfghjkl;'~0|zxcvbnm,./0*0 0000000000000789-456+1230."; //our lookup table. We get our character based on the scancode given by the keyboard
- void kmain() //main
- {
- k_clear_screen(); //Clear the Screen
- k_printf("Welcome to '???' Operating System, v0.0.1", 0); //print a welcome message
- k_printf(test, 1); //print out a line from a globally defined char
- k_printf("Test Line\nThe previous endline used the slash-n character", 2); //testing printf functionality of \n
- k_printf("Beginning the actual Kernel......", 4); //tell the user we are starting the kernel
- /* and.... BEGIN!*/
- while(1==1) //endless loop
- {
- k_printf(current, 6); //print out what has been typed so far
- temp=(int)inb(0x60); //read in what is on the keyboard
- k_printchar(temp, 5, 0); //print out what is on the keyboard at line 5, row 0
- if(inparse<1000) //prevent an overflow
- {
- if(lowercase[temp] != 0) //if the input is SOMETHING besides the non-printing characters
- {
- current[inparse]=lowercase[temp]; //the location given by inparse is set to the character sent by keyboard
- inparse++; //increment inparse, so next time, we are loading to the next character
- }
- outb(0x60, 0xad); //disable //disable the keyboard, so it clears out what we just did
- }
- if(temp==0x1c) //if our scancode we just got is 'return'
- {
- if(current[0]==lowercase[18] && current[1]==lowercase[46] && current[2]==lowercase[35] && current[3]==lowercase[24]) //if it is e c h o
- {
- for(x=0; x<inparse; x++) //loop through all the characters we have put into current so far
- {
- output[x]=current[x+5]; //set output equal to current. (We skip 5 characters in current so we do not echo out the word echo)
- }
- k_printf(output, 10); //print out our output of echo
- }
- if(current[0]==lowercase[46] && current[1]==lowercase[38] && current[2]==lowercase[31]) //if it is c l s
- {
- k_clear_screen(); //clear the screen
- }
- if(current[0]==lowercase[35] && current[1]==lowercase[18] && current[2]==lowercase[38] && current[3]==lowercase[25]) // if it is h e l p
- {
- k_clear_screen();
- k_printf("HELP:\n echo (Prints 'message' to screen): echo [message]\n cls(Clears Screen): cls", 0); //print out the help
- }
- for(x=0; x<inparse+1; x++) //clear current to all 0's. We go over 1 just to make sure
- {
- current[x]=0;
- }
- inparse=0; //reset inparse for the next command
- }
- }
- }
- void k_clear_screen() // clear the entire text screen
- {
- char *vidmem = (char *) 0xb8000; //the first location of video memory
- int i=0; //looping variable
- while(i < (80*25*2)) //we loop through all video memory
- {
- vidmem[i]=' '; //clear it
- i++;
- vidmem[i]=WHITE_TXT;
- i++;
- };
- };
- int k_printf(char *message, int line) // the message and then the line #
- {
- char *vidmem = (char *) 0xb8000; //first video memory location
- int i=0;
- i=(line*80*2); //we start at the location given by 'line'
- while(*message!=0) //if it's not the end of the char
- {
- if(*message=='\n') // check for a new line
- {
- line++; //go to the next line if we have a newline
- i=(line*80*2);
- *message++;
- } else {
- vidmem[i]=*message; //set location in videomemory to what we have in the char
- *message++;
- i++;
- vidmem[i]=WHITE_TXT;
- i++;
- };
- };
- return(1);
- };
- void k_printchar(char message, int line, int location)
- {
- char *vidmem = (char *) 0xb8000; //first vid memory locatoin
- int i = line*80*2; //get our line and such
- i += location; //move over in rows to location
- vidmem[i]=lowercase[(int)message]; //set videomemory given by the inputs to whatever message gives us
- };
- char inb (short port)
- {
- char value;
- asm volatile ("inb %w1, %0" : "=a" (value) : "Nd" (port));
- return value;
- }
- void outb (short port, char value)
- {
- asm volatile ("outb %b0, %w1" : : "a" (value), "Nd" (port));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement