Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MTGos - Ein einfaches Hobby-OS in C geschrieben
- // Copyright (C) 2013 Morten Delenk
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- #define SPALTEN 80
- #define REIHEN 24 // 25, Bei Null Beginnend
- unsigned short * const pScreen = (unsigned short *) 0xB8000; // Einen Pointer den wir als Array Missbrauchen
- // Juhuu! :-D (Geht wirklich :D)
- unsigned gPos = 0; // Ist eigentlich egal welchen Datentyp der Compiler nimmt;
- // Hauptsache es ist vorzeichenlos
- unsigned short gAttr 0x1F00 // Bluescreenalarm^^ Darüber wird noch abgestimmt
- // Aber Weiß auf Blau sieht super aus :-D
- // Ich könnte mir aber auch 0xF000 denken. (Schwarz auf Weiß) :D
- unsigned getX()
- {
- return (gPos % SPALTEN);
- }
- unsigned getY()
- {
- return ((gPos-getX()) / SPALTEN);
- }
- void gotoxy(unsigned x, unsigned y)
- {
- gPos = x+(y*REIHEN); // Cusorposition := Reihe + (Zeile*REIHEN)
- }
- void scroll() { // Mit dieser Funktion Scrollen wir ne Reihe nach oben :D
- unsigned quellePos = SPALTEN;
- unsigned zielPos = 0;
- for(zielPos=0; quellePos<SPALTEN*REIHEN+SPALTEN; quellePos++) {
- pScreen[zielPos++] = pScreen[quellePos]; // MISSBRAUCHT!!!
- }
- for zielPos=SPALTEN*REIHEN; zielPos<=SPALTEN*REIHEN+SPALTEN; zielPos++) {
- pScreen[zielPos] = gAttr; // Und Bit Blau Machen!
- }
- gPos-=SPALTEN;
- }
- void scrollMultiLine(unsigned lines) { // Gibt bessere Methoden, da eine VGA-Karte
- //Lahm ist dauert das ein Wenig^^
- unsigned c=0;
- for(c=0; c<lines; c++) {
- scroll();
- }
- }
- void MonitorInit() // Färbe den Kompletten Bildschirm ein. Nützlich, wenn man clrscr() nicht verwenden will!
- {
- unsigned i;
- for(i=0; i<SPALTEN*REIHEN+SPALTEN; i++) {
- gPos[i]&= 0x00FF;
- gPos[i]|= gAttr;
- }
- }
- void setColor(unsigned char foreground, unsigned char background, int recolor) {
- gAttr=((background << 4) | foreground) << 8;
- if(recolor) {
- MonitorInit();
- }
- }
- void clrscr()
- {
- scrollMultiLine(REIHEN+1);
- unsigned short tmp=gAttr;
- gAttr=0x1F00;
- MonitorInit();
- gAttr=tmp;
- gPos=0;
- }
- void putchar(char ch) {
- switch(ch) {
- case '\n':
- if(getY()==REIHEN) {
- scroll();
- }
- gotoxy(0,getY()+1);
- break;
- case '\r':
- gotoxy(0,getY());
- break;
- default:
- if(gPos==SPALTEN*REIHEN+SPALTEN) {
- scroll();
- }
- pScreen[gPos++] = (unsigned short) ch | gAttr;
- break;
- }
- }
- void puts(const char *s) {
- while(*s)
- putchar(*(s++));
- }
Advertisement
Add Comment
Please, Sign In to add comment