Skip to content

Commit 0ebb087

Browse files
committed
* Implemented vga textmode
* Implemented scrolling * Updated Makefile * Incremented kernel version * Added new welcome message
1 parent e0529c9 commit 0ebb087

File tree

7 files changed

+183
-10
lines changed

7 files changed

+183
-10
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ISOFILE=$(PROJECT).iso
3232
OBJECTS= $(SRCDIR)/boot/boot.o \
3333
$(SRCDIR)/drivers/io/ports.o \
3434
$(SRCDIR)/common/system.o \
35+
$(SRCDIR)/drivers/video/vga_text.o \
3536
$(SRCDIR)/drivers/io/serial.o \
3637
$(SRCDIR)/kernel/kernel.o
3738

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A new rewrite of SectorOS_RE2.
44

5-
The kernel is currently v0.23.03.1ALPR
5+
The kernel is currently v0.23.03.2ALPR
66

77
## Build
88

docs/changelog.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@
1212
* Implemented serial IO
1313
* Fixed some typos
1414
* Updated Makefile
15-
* Deleted object files
15+
* Deleted object files
16+
17+
26-03-2023: 09:44 PM IST v0.23.03.2ALPR
18+
* Implemented vga textmode
19+
* Implemented scrolling
20+
* Updated Makefile
21+
* Incremented kernel version
22+
* Added new welcome message

src/drivers/video/vga_text.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#include "vga_text.h"
2+
3+
vga_text_t textmode;
4+
5+
static uint16_t* text_fb = (uint16_t*)VGA_TEXT_FB;
6+
7+
void init_text()
8+
{
9+
textmode.height = 25;
10+
textmode.width = 80;
11+
12+
textmode.x = 0;
13+
textmode.y = 0;
14+
15+
textmode.fg = 0x0F;
16+
textmode.bg = 0x00;
17+
}
18+
19+
void move_cursor()
20+
{
21+
uint16_t pos = textmode.y * textmode.width + textmode.x;
22+
outb(0x3D4, 0x0F);
23+
outb(0x3D5, (uint8_t) (pos & 0xFF));
24+
outb(0x3D4, 0x0E);
25+
outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF));
26+
}
27+
28+
void scroll()
29+
{
30+
uint8_t attr = (textmode.bg << 4) | (textmode.fg & 0x0F);
31+
uint8_t space = 0x20 | (attr << 8);
32+
33+
if(textmode.y >= textmode.height)
34+
{
35+
int i;
36+
for(i = 0*80; i < 24*80; i++)
37+
{
38+
text_fb[i] = text_fb[i+80];
39+
}
40+
41+
for ( i = 24*80; i < 25*80; i++)
42+
{
43+
text_fb[i] = space;
44+
}
45+
46+
textmode.y = 24;
47+
}
48+
}
49+
50+
void text_putc(char c)
51+
{
52+
uint8_t attr = (textmode.bg << 4) | (textmode.fg & 0x0F);
53+
uint16_t* location;
54+
55+
if(c == '\b' & textmode.x)
56+
{
57+
textmode.x--;
58+
}
59+
else if(c == '\t')
60+
{
61+
textmode.x = (textmode.x + 8) & ~(8 - 1);
62+
}
63+
else if(c == '\r')
64+
{
65+
textmode.x = 0;
66+
}
67+
else if(c == '\n')
68+
{
69+
textmode.x = 0;
70+
textmode.y++;
71+
}
72+
else if (c >= ' ')
73+
{
74+
location = text_fb + (textmode.y * textmode.width + textmode.x);
75+
*location = c | (attr << 8);
76+
textmode.x++;
77+
}
78+
79+
if (textmode.x >= 80)
80+
{
81+
textmode.x = 0;
82+
textmode.y++;
83+
}
84+
85+
scroll();
86+
move_cursor();
87+
}
88+
89+
void text_clear()
90+
{
91+
uint8_t attr = (textmode.bg << 4) | (textmode.fg & 0x0F);
92+
uint8_t space = 0x20 | (attr << 8);
93+
for(int i = 0*80; i < 25*80; i++)
94+
{
95+
text_fb[i] = space;
96+
}
97+
}
98+
99+
void text_chcolor(uint8_t fg, uint8_t bg)
100+
{
101+
textmode.bg = bg;
102+
textmode.fg = fg;
103+
}
104+
105+
void text_puts(char* str)
106+
{
107+
while(*str)
108+
{
109+
text_putc(*str);
110+
str++;
111+
}
112+
}

src/include/system.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ extern uint32_t k_end;
1010
void panic(char* message, char* file);
1111
void kernel_panic(char* message);
1212

13-
#define khalt asm("cli") asm("hlt")
13+
#define khalt asm("cli"); \
14+
asm("hlt")
1415

1516
#define KERNEL_START 0x100000
1617
#define KERNEL_END k_end
@@ -23,7 +24,7 @@ void kernel_panic(char* message);
2324
* RELN: index of current release in the current month
2425
* STATUS: [PR]:Prerelease, [AL]:alpha, [NR]:Normal release
2526
*/
26-
#define KERNEL_VERSION "0.23.03.1ALPR"
27+
#define KERNEL_VERSION "0.23.03.2ALPR"
2728

2829
void reboot();
2930

src/include/vga_text.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef __VGA_TEXT__
2+
#define __VGA_TEXT__
3+
4+
#include "system.h"
5+
#include "ports.h"
6+
7+
#define VGA_TEXT_FB 0xB8000
8+
9+
10+
#define VGA_BLACK 0
11+
#define VGA_BLUE 1
12+
#define VGA_GREEN 2
13+
#define VGA_CYAN 3
14+
#define VGA_RED 4
15+
#define VGA_MAGENTA 5
16+
#define VGA_BROWN 6
17+
#define VGA_LIGHT_GREY 7
18+
#define VGA_DARK_GREY 8
19+
#define VGA_LIGHT_BLUE 9
20+
#define VGA_LIGHT_GREEN 10
21+
#define VGA_LIGHT_CYAN 11
22+
#define VGA_LIGHT_RED 12
23+
#define VGA_LIGHT_MAGENTA 13
24+
#define VGA_LIGHT_BROWN 14
25+
#define VGA_WHITE 15
26+
27+
typedef struct vga_text
28+
{
29+
uint32_t x;
30+
uint32_t y;
31+
32+
uint32_t height;
33+
uint32_t width;
34+
35+
uint8_t fg;
36+
uint8_t bg;
37+
}vga_text_t;
38+
39+
void init_text();
40+
41+
void text_putc(char c);
42+
void text_puts(char* str);
43+
44+
void text_chcolor(uint8_t fg, uint8_t bg);
45+
void text_clear();
46+
47+
#endif /*__VGA_TEXT__*/

src/kernel/kernel.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
#include "system.h"
22
#include "multiboot.h"
33
#include "serial.h"
4+
#include "vga_text.h"
45

56
void kernelmain(const multiboot_info_t* info, uint32_t multiboot_magic)
67
{
7-
init_serial(COM1, 0);
8+
init_serial(COM1, 1);
9+
init_text();
10+
text_chcolor(VGA_LIGHT_GREEN, VGA_BLACK);
11+
text_clear();
812
if(multiboot_magic != 0x2BADB002)
913
{
1014
serial_puts("multiboot bootloader magic is invalid\n");
1115
return;
1216
}
13-
serial_puts("multiboot bootloader magic is valid...\n");
14-
serial_puts("Kernel version is:");
15-
serial_puts(KERNEL_VERSION);
16-
serial_putc('\n');
17-
reboot();
17+
text_puts("Hello World!\n");
18+
text_puts("multiboot bootloader magic is valid...\n");
19+
text_puts("Kernel version is: ");
20+
text_puts(KERNEL_VERSION);
21+
text_putc('\n');
22+
khalt;
1823
}

0 commit comments

Comments
 (0)