Advertisement
Guest User

Untitled

a guest
May 6th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. #define WHITE_TXT 0x07 // white on black text
  2.  
  3. void k_clear_screen(); //the function to clear the screen
  4. int k_printf(char *message, int line); //printf function
  5. char test[58] = "This line is from a character datatype Defined in Globals!";
  6. char inb(short); //read input from an address given by the short
  7. void outb(short, char); //output to the address given by the short
  8. int temp; //a temporary variable to hold the scancode
  9. char current[1000]; //our current stuff typed in
  10. int inparse=0; //a generic variable to move through current and place the latest keypress
  11. int x; //generic variable for looping
  12. int y; //generic variable for looping
  13. char output[1000]; //our output (Stuff put out by echo, etc)
  14. 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
  15. void kmain() //main
  16. {
  17. k_clear_screen(); //Clear the Screen
  18.  
  19. k_printf("Welcome to '???' Operating System, v0.0.1", 0); //print a welcome message
  20. k_printf(test, 1); //print out a line from a globally defined char
  21. k_printf("Test Line\nThe previous endline used the slash-n character", 2); //testing printf functionality of \n
  22. k_printf("Beginning the actual Kernel......", 4); //tell the user we are starting the kernel
  23. /* and.... BEGIN!*/
  24. while(1==1) //endless loop
  25. {
  26. k_printf(current, 6); //print out what has been typed so far
  27. temp=(int)inb(0x60); //read in what is on the keyboard
  28. k_printchar(temp, 5, 0); //print out what is on the keyboard at line 5, row 0
  29. if(inparse<1000) //prevent an overflow
  30. {
  31. if(lowercase[temp] != 0) //if the input is SOMETHING besides the non-printing characters
  32. {
  33. current[inparse]=lowercase[temp]; //the location given by inparse is set to the character sent by keyboard
  34. inparse++; //increment inparse, so next time, we are loading to the next character
  35. }
  36. outb(0x60, 0xad); //disable //disable the keyboard, so it clears out what we just did
  37. }
  38. if(temp==0x1c) //if our scancode we just got is 'return'
  39. {
  40. if(current[0]==lowercase[18] && current[1]==lowercase[46] && current[2]==lowercase[35] && current[3]==lowercase[24]) //if it is e c h o
  41. {
  42. for(x=0; x<inparse; x++) //loop through all the characters we have put into current so far
  43. {
  44. 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)
  45. }
  46. k_printf(output, 10); //print out our output of echo
  47. }
  48. if(current[0]==lowercase[46] && current[1]==lowercase[38] && current[2]==lowercase[31]) //if it is c l s
  49. {
  50. k_clear_screen(); //clear the screen
  51. }
  52. if(current[0]==lowercase[35] && current[1]==lowercase[18] && current[2]==lowercase[38] && current[3]==lowercase[25]) // if it is h e l p
  53. {
  54. k_clear_screen();
  55. k_printf("HELP:\n echo (Prints 'message' to screen): echo [message]\n cls(Clears Screen): cls", 0); //print out the help
  56. }
  57. for(x=0; x<inparse+1; x++) //clear current to all 0's. We go over 1 just to make sure
  58. {
  59. current[x]=0;
  60. }
  61. inparse=0; //reset inparse for the next command
  62. }
  63. }
  64. }
  65.  
  66. void k_clear_screen() // clear the entire text screen
  67. {
  68. char *vidmem = (char *) 0xb8000; //the first location of video memory
  69. int i=0; //looping variable
  70. while(i < (80*25*2)) //we loop through all video memory
  71. {
  72. vidmem[i]=' '; //clear it
  73. i++;
  74. vidmem[i]=WHITE_TXT;
  75. i++;
  76. };
  77. };
  78.  
  79. int k_printf(char *message, int line) // the message and then the line #
  80. {
  81. char *vidmem = (char *) 0xb8000; //first video memory location
  82. int i=0;
  83.  
  84. i=(line*80*2); //we start at the location given by 'line'
  85.  
  86. while(*message!=0) //if it's not the end of the char
  87. {
  88. if(*message=='\n') // check for a new line
  89. {
  90. line++; //go to the next line if we have a newline
  91. i=(line*80*2);
  92. *message++;
  93. } else {
  94. vidmem[i]=*message; //set location in videomemory to what we have in the char
  95. *message++;
  96. i++;
  97. vidmem[i]=WHITE_TXT;
  98. i++;
  99. };
  100. };
  101.  
  102. return(1);
  103. };
  104.  
  105. void k_printchar(char message, int line, int location)
  106. {
  107. char *vidmem = (char *) 0xb8000; //first vid memory locatoin
  108. int i = line*80*2; //get our line and such
  109. i += location; //move over in rows to location
  110. vidmem[i]=lowercase[(int)message]; //set videomemory given by the inputs to whatever message gives us
  111. };
  112. char inb (short port)
  113. {
  114. char value;
  115. asm volatile ("inb %w1, %0" : "=a" (value) : "Nd" (port));
  116. return value;
  117. }
  118. void outb (short port, char value)
  119. {
  120. asm volatile ("outb %b0, %w1" : : "a" (value), "Nd" (port));
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement