rendered paste body#include "k_defines.h"
inline void outportb(unsigned int port,unsigned char value);
unsigned int panic(char *message);
void k_clear_screen();
unsigned int k_printf(char *message, unsigned int line);
void update_cursor(int row, int col);
k_main() // like main
{
k_clear_screen();
k_printf("Welcome to Simplified OS.", 0);
update_cursor(1, 0);
k_printf("Right now the kernel is loaded at 1MB physical,/nbut mapped at FF800000 hex.", 3);
update_cursor(5, 0);
};
void k_clear_screen() // clear the entire text screen
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
while(i<(80*2*25))
{
vidmem[i]=' ';
i++;
vidmem[i]=WHITE_TXT;
i++;
};
};
unsigned int k_printf(char *message, unsigned int line)
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
i=(line*80*2);
while(*message!=0) // 24h
{
if(*message==0x2F)
{
*message++;
if(*message==0x6e)
{
line++;
i=(line*80*2);
*message++;
if(*message==0)
{
return(1);
};
};
};
vidmem[i]=*message;
*message++;
i++;
vidmem[i]=0x7;
i++;
};
return(1);
};
/* ============== */
inline void outportb(unsigned int port,unsigned char value) // Output a byte to a port
{
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
};
/* ============== */
/* by DF */
void update_cursor(int row, int col)
{
USHORT position=(row*80) + col;
// cursor LOW port to vga INDEX register
outportb(0x3D4, 0x0F);
outportb(0x3D5, (UCHAR)(position&0xFF));
// cursor HIGH port to vga INDEX register
outportb(0x3D4, 0x0E);
outportb(0x3D5, (UCHAR)((position>>8)&0xFF));
};
unsigned int panic(char *message) // just a modified version of k_printf
{
char *vidmem = (char *) 0xb8000;
unsigned int i=0;
unsigned int line=0;
i=(line*80*2);
while(*message!=0) // 24h
{
if(*message==0x2F)
{
*message++;
if(*message==0x6e)
{
line++;
i=(line*80*2);
*message++;
if(*message==0)
{
return(1);
};
};
};
vidmem[i]=*message;
*message++;
i++;
vidmem[i]=0x9; // use blue text
i++;
};
return(1);
};