Code:
#include "kernel.h"
int strlen(string str);
void dec2bin(dword decimal, int prefix);
void drawdesktop(byte ch, char fore, char back);
void drawwindow(string title, int xpos, int ypos, int width, int height, char fore, char back);
void kernel(void) // kernel entry point
{
drawdesktop(177, COLOR_WHITE, COLOR_BLUE);
drawwindow(" Simple OS Example - by Napalm ", 4, 4, 72, 16, COLOR_LTWHITE, COLOR_BLUE);
putsnocr("Welcome to this example! ");
/* I put another putsnocr line here but it didnt show up only "Welcome to this example" showed */
hidecursor();
dword value = 0xDEADBEEF;
while(1){
// display value in decimal
gotoxy(6, 9);
dword decimal = value;
char base[10];
int i = 0;
while(decimal > 0){
base[i++] = '0' + (decimal % 10);
decimal /= 10;
}
while(i-- > 0) putch(base[i]);
// display value in hex
gotoxy(6, 10);
putsnocr("0x");
for(int i = 28; i > -1; i -= 4){
byte nibble = ((value >> i) & 0x0F);
if(nibble < 10) putch('0' + nibble);
else putch('A' + (nibble - 10));
}
// display value in binary
gotoxy(6, 11);
dec2bin(value, 32);
value++;
}
}
int strlen(string str) // simple string length
{
string end = str;
while(*end++);
return (end - str);
}
void drawdesktop(byte ch, char fore, char back)
{
// clear screen with foreground and background
// and also with desired character
settextcolor(fore, back);
cls(ch);
}
// decimal to binary
void dec2bin(dword decimal, int prefix)
{
dword j = 0;
for(int i = prefix; i >= 0; --i, j = ((decimal & (1 << i)) >> i))
if(prefix || j) prefix = putch('0' + j);
}
void drawwindow(string title, int xpos, int ypos, int width, int height, char fore, char back)
{
int xextent = (xpos + width - 1), yextent = (ypos + height - 1);
// draw window
for(int y = ypos; y <= yextent; y++){
settextcolor(fore, back);
gotoxy(xpos, y);
if(y == ypos){ // draw top caption bar
settextcolor(COLOR_LTYELLOW, COLOR_RED);
for(int x = xpos; x <= xextent; x++){
if(x == xpos) putch(213);
else if(x == xextent) putch(254);
else putch(205);
}
gotoxy(xpos + ((width - strlen(title)) / 2), y);
putsnocr(title);
}else if(y < yextent){ // draw middle lines
for(int x = xpos; x <= xextent; x++){
if(x == xpos || x == xextent) putch(179);
else putch(' ');
}
}else{ // draw bottom edge
for(int x = xpos; x <= xextent; x++){
if(x == xpos) putch(192);
else if(x == xextent) putch(217);
else putch(196);
}
}
}
// draw vertical shadow
for(int y = ypos; y <= yextent; y++){
gotoxy(xextent + 1, y + 1);
settextcolor(COLOR_WHITE, COLOR_BLACK);
putch(177);
}
// draw horizontal shadow
for(int x = xpos; x <= xextent; x++){
gotoxy(x + 1, yextent + 1);
settextcolor(COLOR_WHITE, COLOR_BLACK);
putch(177);
}
// position cursor inside window
gotoxy(xpos + 2, ypos + 2);
settextcolor(fore, back);
}
Can anyone please explain whats wrong?