Skip to content

Commit bbf4c0d

Browse files
committed
* Working vga driver
1 parent 52dacc6 commit bbf4c0d

File tree

6 files changed

+79
-68
lines changed

6 files changed

+79
-68
lines changed

Drivers/Keyboard.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void PrintHDD();
1515
void detect_cpu();
1616
void PrintMEM(const void* multiboot_structure);
1717
void PrintSATA();
18+
void PVGA();
1819

1920
PowerControl power;
2021

@@ -305,7 +306,7 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
305306
else if(key_buffer[5] == "2")
306307
printf("Help page 2:\nadd1 <num1> <num2> :To add 2 numbers.This command only supports 1 digit number\nsub1 <num1> <num2> :to subtract 2 numbers.This command only supports 1 digit number\ntxt : To enter the text mode. You cannot save files\nmul1 <num1> <num2> : To multiply 2 numbers.");
307308
else if (key_buffer[5] == "3")
308-
printf("Help page 3:\nspi : To print the data in serial port 0x3F8.\nspo : To write data to serial port 0x3F8.\nsysinfo [option] : To get info about system.");
309+
printf("Help page 3:\nspi : To print the data in serial port 0x3F8.\nspo : To write data to serial port 0x3F8.\nsysinfo [option] : To get info about system.\nvga : To use experimental vga graphics.");
309310
else
310311
printf("Help page 1:\necho <message> : to print the message in the console \nhelp : to show this message \nclear : to clear the screen \nsd <options> : controls the power of the computer ");
311312
}
@@ -447,6 +448,11 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
447448
printf("SectorOS Kernel "); printf(KERNEL_VERSION); printf(" "); printf(KERNEL_BUILD);
448449
}
449450
}
451+
else if (key_buffer[0] == "v" && key_buffer[1] == "g" && key_buffer[2] == "a")
452+
{
453+
COMNAME = "vga";
454+
PVGA();
455+
}
450456
else
451457
{
452458
printf("Unknown Command. Type help in console to get all the commands");

Drivers/VGADriver.cpp

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#include "VGADriver.h"
22

33
VideoGraphicsArray::VideoGraphicsArray() :
4-
MiscPort(0x3c2),
5-
CRTCIndexPort(0x3d4),
6-
CRTCDataPort(0x3d5),
7-
SequencerIndexPort(0x3c4),
8-
SequencerDataPort(0x3c5),
9-
GraphicsControllerIndexPort(0x3ce),
10-
GraphicsControllerDataPort(0x3cf),
11-
AttributeControllerIndexPort(0x3c0),
12-
AttributeControllerReadPort(0x3c1),
13-
AttributeControllerWritePort(0x3c0),
14-
AttributeControllerResetPort(0x3da)
4+
miscPort(0x3c2),
5+
crtcIndexPort(0x3d4),
6+
crtcDataPort(0x3d5),
7+
sequencerIndexPort(0x3c4),
8+
sequencerDataPort(0x3c5),
9+
graphicsControllerIndexPort(0x3ce),
10+
graphicsControllerDataPort(0x3cf),
11+
attributeControllerIndexPort(0x3c0),
12+
attributeControllerReadPort(0x3c1),
13+
attributeControllerWritePort(0x3c0),
14+
attributeControllerResetPort(0x3da)
1515
{
1616
}
1717

@@ -21,61 +21,61 @@ VideoGraphicsArray::~VideoGraphicsArray()
2121

2222

2323

24-
void VideoGraphicsArray::WriteToRegisters(uint8_t* registers)
24+
void VideoGraphicsArray::WriteRegisters(uint8_t* registers)
2525
{
2626
// misc
27-
MiscPort.WriteToPort(*(registers++));
27+
miscPort.WriteToPort(*(registers++));
2828

29-
// Sequencer
29+
// sequencer
3030
for(uint8_t i = 0; i < 5; i++)
3131
{
32-
SequencerIndexPort.WriteToPort(i);
33-
SequencerDataPort.WriteToPort(*(registers++));
32+
sequencerIndexPort.WriteToPort(i);
33+
sequencerDataPort.WriteToPort(*(registers++));
3434
}
3535

3636
// cathode ray tube controller
37-
CRTCIndexPort.WriteToPort(0x03);
38-
CRTCDataPort.WriteToPort(CRTCDataPort.ReadFromPort() | 0x80);
39-
CRTCIndexPort.WriteToPort(0x11);
40-
CRTCDataPort.WriteToPort(CRTCDataPort.ReadFromPort() & ~0x80);
37+
crtcIndexPort.WriteToPort(0x03);
38+
crtcDataPort.WriteToPort(crtcDataPort.ReadFromPort() | 0x80);
39+
crtcIndexPort.WriteToPort(0x11);
40+
crtcDataPort.WriteToPort(crtcDataPort.ReadFromPort() & ~0x80);
4141

4242
registers[0x03] = registers[0x03] | 0x80;
4343
registers[0x11] = registers[0x11] & ~0x80;
4444

4545
for(uint8_t i = 0; i < 25; i++)
4646
{
47-
CRTCIndexPort.WriteToPort(i);
48-
CRTCDataPort.WriteToPort(*(registers++));
47+
crtcIndexPort.WriteToPort(i);
48+
crtcDataPort.WriteToPort(*(registers++));
4949
}
5050

5151
// graphics controller
5252
for(uint8_t i = 0; i < 9; i++)
5353
{
54-
GraphicsControllerIndexPort.WriteToPort(i);
55-
GraphicsControllerDataPort.WriteToPort(*(registers++));
54+
graphicsControllerIndexPort.WriteToPort(i);
55+
graphicsControllerDataPort.WriteToPort(*(registers++));
5656
}
5757

58-
// Attribute controller
58+
// attribute controller
5959
for(uint8_t i = 0; i < 21; i++)
6060
{
61-
AttributeControllerResetPort.ReadFromPort();
62-
AttributeControllerIndexPort.WriteToPort(i);
63-
AttributeControllerWritePort.WriteToPort(*(registers++));
61+
attributeControllerResetPort.ReadFromPort();
62+
attributeControllerIndexPort.WriteToPort(i);
63+
attributeControllerWritePort.WriteToPort(*(registers++));
6464
}
6565

66-
AttributeControllerResetPort.ReadFromPort();
67-
AttributeControllerIndexPort.WriteToPort(0x20);
66+
attributeControllerResetPort.ReadFromPort();
67+
attributeControllerIndexPort.WriteToPort(0x20);
6868

6969
}
7070

71-
bool VideoGraphicsArray::isModeSupported(uint32_t width, uint32_t height, uint32_t colordepth)
71+
bool VideoGraphicsArray::SupportsMode(uint32_t width, uint32_t height, uint32_t colordepth)
7272
{
7373
return width == 320 && height == 200 && colordepth == 8;
7474
}
7575

7676
bool VideoGraphicsArray::SetMode(uint32_t width, uint32_t height, uint32_t colordepth)
7777
{
78-
if(!isModeSupported(width, height, colordepth))
78+
if(!SupportsMode(width, height, colordepth))
7979
return false;
8080

8181
unsigned char g_320x200x256[] =
@@ -98,14 +98,15 @@ bool VideoGraphicsArray::SetMode(uint32_t width, uint32_t height, uint32_t color
9898
0x41, 0x00, 0x0F, 0x00, 0x00
9999
};
100100

101-
WriteToRegisters(g_320x200x256);
101+
WriteRegisters(g_320x200x256);
102102
return true;
103103
}
104104

105-
uint8_t* VideoGraphicsArray::GetVGAFrameBuffer()
105+
106+
uint8_t* VideoGraphicsArray::GetFrameBufferSegment()
106107
{
107-
GraphicsControllerIndexPort.WriteToPort(0x06);
108-
uint8_t segmentNumber = GraphicsControllerDataPort.ReadFromPort() & (3<<2);
108+
graphicsControllerIndexPort.WriteToPort(0x06);
109+
uint8_t segmentNumber = graphicsControllerDataPort.ReadFromPort() & (3<<2);
109110
switch(segmentNumber)
110111
{
111112
default:
@@ -118,18 +119,18 @@ uint8_t* VideoGraphicsArray::GetVGAFrameBuffer()
118119

119120
void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t colorIndex)
120121
{
121-
uint8_t* pixelAddress = GetVGAFrameBuffer() + 320*y + x;
122+
uint8_t* pixelAddress = GetFrameBufferSegment() + 320*y + x;
122123
*pixelAddress = colorIndex;
123124
}
124125

125-
uint8_t VideoGraphicsArray::GetColorIndex(uint8_t Redr, uint8_t Green, uint8_t Blue)
126+
uint8_t VideoGraphicsArray::GetColorIndex(uint8_t r, uint8_t g, uint8_t b)
126127
{
127-
if(Redr == 0x00, Green == 0x00, Blue == 0xA8)
128+
if(r == 0x00, g == 0x00, b == 0xA8)
128129
return 0x01;
129130
return 0x00;
130131
}
131132

132-
void VideoGraphicsArray::PutPixelOnScreen(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b)
133+
void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b)
133134
{
134135
PutPixel(x,y, GetColorIndex(r,g,b));
135136
}

Drivers/VGADriver.h

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,30 @@
55
#include "IOPorts.h"
66
#include "Driver.h"
77

8-
//! This driver is deprecated because it will cause damage to the monitor, I guess
98
class VideoGraphicsArray
109
{
1110
protected:
12-
port8BIT MiscPort;
13-
port8BIT CRTCIndexPort;
14-
port8BIT CRTCDataPort;
15-
port8BIT SequencerIndexPort;
16-
port8BIT SequencerDataPort;
17-
port8BIT GraphicsControllerIndexPort;
18-
port8BIT GraphicsControllerDataPort;
19-
port8BIT AttributeControllerIndexPort;
20-
port8BIT AttributeControllerReadPort;
21-
port8BIT AttributeControllerWritePort;
22-
port8BIT AttributeControllerResetPort;
23-
24-
25-
protected:
26-
void WriteToRegisters(uint8_t* registers);
27-
uint8_t* GetVGAFrameBuffer();
28-
virtual void PutPixel(uint32_t X, uint32_t Y, uint8_t ColorIndex);
29-
virtual uint8_t GetColorIndex(uint8_t Red, uint8_t Green, uint8_t Blue);
30-
11+
port8BIT miscPort;
12+
port8BIT crtcIndexPort;
13+
port8BIT crtcDataPort;
14+
port8BIT sequencerIndexPort;
15+
port8BIT sequencerDataPort;
16+
port8BIT graphicsControllerIndexPort;
17+
port8BIT graphicsControllerDataPort;
18+
port8BIT attributeControllerIndexPort;
19+
port8BIT attributeControllerReadPort;
20+
port8BIT attributeControllerWritePort;
21+
port8BIT attributeControllerResetPort;
22+
void WriteRegisters(uint8_t* registers);
23+
uint8_t* GetFrameBufferSegment();
24+
virtual uint8_t GetColorIndex(uint8_t r, uint8_t g, uint8_t b);
3125
public:
3226
VideoGraphicsArray();
3327
~VideoGraphicsArray();
34-
35-
public:
36-
virtual bool SetMode(uint32_t ScreenWidth, uint32_t ScreenHeight, uint32_t ColorDepth);
37-
virtual bool isModeSupported(uint32_t ScreenWidth, uint32_t ScreenHeight, uint32_t ColorDepth);
38-
virtual void PutPixelOnScreen(uint32_t X, uint32_t Y, uint8_t Red, uint8_t Green, uint8_t Blue);
28+
virtual bool SupportsMode(uint32_t width, uint32_t height, uint32_t colordepth);
29+
virtual bool SetMode(uint32_t width, uint32_t height, uint32_t colordepth);
30+
virtual void PutPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b);
31+
virtual void PutPixel(uint32_t x, uint32_t y, uint8_t colorIndex);
3932
};
4033

4134

Includes/Public_VAR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
inline char* OS_NAME = "SectorOS";
55

66
inline char* KERNEL_NAME = "SectorOS";
7-
inline char* KERNEL_VERSION = "V1.4.4";
7+
inline char* KERNEL_VERSION = "V1.4.5";
88
inline char* KERNEL_BUILD = "Build: 2021-11-24";
99
inline char* KERNEL_ARCH = "x86";
1010

1111
inline char* SHELL_NAME = "SOSH";
12-
inline char* SHELL_VER = "V1.0.5";
12+
inline char* SHELL_VER = "V1.0.6";
1313

1414
#endif

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Drivers/Driver.o \
1414
CPU/PowerControl.o \
1515
Drivers/Keyboard.o \
1616
Drivers/HDD-ATA.o \
17+
Drivers/VGADriver.o \
1718
Drivers/Mouse.o \
1819
Drivers/RTC.o \
1920
Hardcom/SerialPort.o \

kernel/kernel.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "../Memory/MemoryManagement.h"
1414
#include "../Includes/Debug.h"
1515
#include "../Drivers/HDD-ATA.h"
16+
#include "../Drivers/VGADriver.h"
1617

1718
static uint8_t cursory;
1819
static uint8_t cursorx;
@@ -405,6 +406,15 @@ void printTime()
405406

406407
}
407408

409+
void PVGA()
410+
{
411+
VideoGraphicsArray vga;
412+
vga.SetMode(320,200,8);
413+
for(int32_t y = 0; y < 200; y++)
414+
for(int32_t x = 0; x < 320; x++)
415+
vga.PutPixel(x, y, 0x00, 0x00, 0xA8);
416+
}
417+
408418
void printfchar(char st)
409419
{
410420
static uint8_t x=0, y=0;

0 commit comments

Comments
 (0)