Mtgxyz

Untitled

Dec 1st, 2013
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.03 KB | None | 0 0
  1. //    MTGos - Ein einfaches Hobby-OS in C geschrieben
  2. //    Copyright (C) 2013 Morten Delenk
  3. //
  4. //    This program is free software: you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation, either version 3 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. #define SPALTEN 80
  17. #define REIHEN 24 // 25, Bei Null Beginnend
  18. unsigned short * const pScreen = (unsigned short *) 0xB8000; // Einen Pointer den wir als Array Missbrauchen
  19. // Juhuu! :-D (Geht wirklich :D)
  20. unsigned gPos = 0; // Ist eigentlich egal welchen Datentyp der Compiler nimmt;
  21. // Hauptsache es ist vorzeichenlos
  22. unsigned short gAttr 0x1F00 // Bluescreenalarm^^ Darüber wird noch abgestimmt
  23. // Aber Weiß auf Blau sieht super aus :-D
  24. // Ich könnte mir aber auch 0xF000 denken. (Schwarz auf Weiß) :D
  25. unsigned getX()
  26. {
  27.   return (gPos % SPALTEN);
  28. }
  29. unsigned getY()
  30. {
  31.   return ((gPos-getX()) / SPALTEN);
  32. }
  33. void gotoxy(unsigned x, unsigned y)
  34. {
  35.   gPos = x+(y*REIHEN); // Cusorposition := Reihe + (Zeile*REIHEN)
  36. }
  37. void scroll() { // Mit dieser Funktion Scrollen wir ne Reihe nach oben :D
  38.   unsigned quellePos = SPALTEN;
  39.   unsigned zielPos = 0;
  40.   for(zielPos=0; quellePos<SPALTEN*REIHEN+SPALTEN; quellePos++) {
  41.     pScreen[zielPos++] = pScreen[quellePos]; // MISSBRAUCHT!!!
  42.   }
  43.   for zielPos=SPALTEN*REIHEN; zielPos<=SPALTEN*REIHEN+SPALTEN; zielPos++) {
  44.     pScreen[zielPos] = gAttr; // Und Bit Blau Machen!
  45.   }
  46.   gPos-=SPALTEN;
  47. }
  48. void scrollMultiLine(unsigned lines) { // Gibt bessere Methoden, da eine VGA-Karte
  49.   //Lahm ist dauert das ein Wenig^^
  50.   unsigned c=0;
  51.   for(c=0; c<lines; c++) {
  52.     scroll();
  53.   }
  54. }
  55. void MonitorInit() // Färbe den Kompletten Bildschirm ein. Nützlich, wenn man clrscr() nicht verwenden will!
  56. {
  57.   unsigned i;
  58.   for(i=0; i<SPALTEN*REIHEN+SPALTEN; i++) {
  59.     gPos[i]&= 0x00FF;
  60.     gPos[i]|= gAttr;
  61.   }
  62. }
  63. void setColor(unsigned char foreground, unsigned char background, int recolor) {
  64.   gAttr=((background << 4) | foreground) << 8;
  65.   if(recolor) {
  66.     MonitorInit();
  67.   }
  68. }
  69. void clrscr()
  70. {
  71.   scrollMultiLine(REIHEN+1);
  72.   unsigned short tmp=gAttr;
  73.   gAttr=0x1F00;
  74.   MonitorInit();
  75.   gAttr=tmp;
  76.   gPos=0;
  77. }
  78. void putchar(char ch) {
  79.   switch(ch) {
  80.     case '\n':
  81.       if(getY()==REIHEN) {
  82.     scroll();
  83.       }
  84.       gotoxy(0,getY()+1);
  85.       break;
  86.     case '\r':
  87.       gotoxy(0,getY());
  88.       break;
  89.     default:
  90.       if(gPos==SPALTEN*REIHEN+SPALTEN) {
  91.     scroll();
  92.       }
  93.       pScreen[gPos++] = (unsigned short) ch | gAttr;
  94.       break;
  95.   }
  96. }
  97. void puts(const char *s) {
  98.   while(*s)
  99.     putchar(*(s++));
  100. }
Advertisement
Add Comment
Please, Sign In to add comment