Skip to content
Snippets Groups Projects
Commit 69284517 authored by Thierno souleymane Bah's avatar Thierno souleymane Bah
Browse files

feat(hello world displayed)

parent 60f63f30
Branches
Tags 05-fork1
No related merge requests found
...@@ -7,7 +7,8 @@ void putc(char aChar); /* print a single char on screen */ ...@@ -7,7 +7,8 @@ void putc(char aChar); /* print a single char on screen */
void puts(char *aString); /* print a string on the screen */ void puts(char *aString); /* print a string on the screen */
void puthex(int aNumber); /* print an Hex number on screen */ void puthex(int aNumber); /* print an Hex number on screen */
void empty_irq(int_regs_t *r) { void empty_irq(int_regs_t *r)
{
} }
/* multiboot entry-point with datastructure as arg. */ /* multiboot entry-point with datastructure as arg. */
...@@ -33,39 +34,47 @@ void main(unsigned int * mboot_info) ...@@ -33,39 +34,47 @@ void main(unsigned int * mboot_info)
/* minimal setup done ! */ /* minimal setup done ! */
puts("Hello world\n\n");
for (;;)
for(;;) ; /* nothing more to do... really nothing ! */ ; /* nothing more to do... really nothing ! */
} }
/* base address for the video output assume to be set as character oriented by the multiboot */ /* base address for the video output assume to be set as character oriented by the multiboot */
unsigned char *video_memory = (unsigned char *)0xB8000; unsigned char *video_memory = (unsigned char *)0xB8000;
/* clear screen */ /* clear screen */
void clear_screen() { void clear_screen()
{
int i; int i;
for(i=0;i<80*25;i++) { /* for each one of the 80 char by 25 lines */ for (i = 0; i < 80 * 25; i++)
{ /* for each one of the 80 char by 25 lines */
video_memory[i * 2 + 1] = 0x0F; /* color is set to black background and white char */ video_memory[i * 2 + 1] = 0x0F; /* color is set to black background and white char */
video_memory[i * 2] = (unsigned char)' '; /* character shown is the space char */ video_memory[i * 2] = (unsigned char)' '; /* character shown is the space char */
} }
} }
/* print a string on the screen */ /* print a string on the screen */
void puts(char *aString) { void puts(char *aString)
{
char *current_char = aString; char *current_char = aString;
while(*current_char!=0) { while (*current_char != 0)
{
putc(*current_char++); putc(*current_char++);
} }
} }
/* print an number in hexa */ /* print an number in hexa */
char *hex_digit = "0123456789ABCDEF"; char *hex_digit = "0123456789ABCDEF";
void puthex(int aNumber) { void puthex(int aNumber)
{
int i; int i;
int started = 0; int started = 0;
for(i=28;i>=0;i-=4) { for (i = 28; i >= 0; i -= 4)
{
int k = (aNumber >> i) & 0xF; int k = (aNumber >> i) & 0xF;
if(k!=0 || started) { if (k != 0 || started)
{
putc(hex_digit[k]); putc(hex_digit[k]);
started = 1; started = 1;
} }
...@@ -76,7 +85,8 @@ void puthex(int aNumber) { ...@@ -76,7 +85,8 @@ void puthex(int aNumber) {
int cursor_x = 0; /* here is the cursor position on X [0..79] */ int cursor_x = 0; /* here is the cursor position on X [0..79] */
int cursor_y = 0; /* here is the cursor position on Y [0..24] */ int cursor_y = 0; /* here is the cursor position on Y [0..24] */
void setCursor() { void setCursor()
{
int cursor_offset = cursor_x + cursor_y * 80; int cursor_offset = cursor_x + cursor_y * 80;
_outb(0x3d4, 14); _outb(0x3d4, 14);
_outb(0x3d5, ((cursor_offset >> 8) & 0xFF)); _outb(0x3d5, ((cursor_offset >> 8) & 0xFF));
...@@ -84,20 +94,34 @@ void setCursor() { ...@@ -84,20 +94,34 @@ void setCursor() {
_outb(0x3d5, (cursor_offset & 0xFF)); _outb(0x3d5, (cursor_offset & 0xFF));
} }
void putc(char c) { void putc(char c)
if(cursor_x>79) { {
if (cursor_x > 79)
{
cursor_x = 0; cursor_x = 0;
cursor_y++; cursor_y++;
} }
if(cursor_y>24) { if (cursor_y > 24)
{
cursor_y = 0; cursor_y = 0;
clear_screen(); clear_screen();
} }
switch(c) { /* deal with a special char */ switch (c)
case '\r': cursor_x=0; break; /* carriage return */ { /* deal with a special char */
case '\n': cursor_x=0; cursor_y++; break; /* new ligne */ case '\r':
case 0x8 : if(cursor_x>0) cursor_x--; break;/* backspace */ cursor_x = 0;
case 0x9 : cursor_x=(cursor_x+8)&~7; break; /* tabulation */ break; /* carriage return */
case '\n':
cursor_x = 0;
cursor_y++;
break; /* new ligne */
case 0x8:
if (cursor_x > 0)
cursor_x--;
break; /* backspace */
case 0x9:
cursor_x = (cursor_x + 8) & ~7;
break; /* tabulation */
/* or print a simple character */ /* or print a simple character */
default: default:
video_memory[(cursor_x + 80 * cursor_y) * 2] = c; video_memory[(cursor_x + 80 * cursor_y) * 2] = c;
...@@ -106,5 +130,3 @@ void putc(char c) { ...@@ -106,5 +130,3 @@ void putc(char c) {
} }
setCursor(); setCursor();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment