Permalink
Browse files

Files for part 12, https://www.youtube.com/watch?v=N68cYNWZgy8

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent f6a0fc8 commit 16476d7d44cf5aba7837d53721bbcc4052462ac6
Showing with 204 additions and 0 deletions.
  1. +49 −0 include/drivers/vga.h
  2. +1 −0 makefile
  3. +144 −0 src/drivers/vga.cpp
  4. +10 −0 src/kernel.cpp
View
@@ -0,0 +1,49 @@
#ifndef __MYOS__DRIVERS__VGA_H
#define __MYOS__DRIVERS__VGA_H
#include <common/types.h>
#include <hardwarecommunication/port.h>
#include <drivers/driver.h>
namespace myos
{
namespace drivers
{
class VideoGraphicsArray
{
protected:
hardwarecommunication::Port8Bit miscPort;
hardwarecommunication::Port8Bit crtcIndexPort;
hardwarecommunication::Port8Bit crtcDataPort;
hardwarecommunication::Port8Bit sequencerIndexPort;
hardwarecommunication::Port8Bit sequencerDataPort;
hardwarecommunication::Port8Bit graphicsControllerIndexPort;
hardwarecommunication::Port8Bit graphicsControllerDataPort;
hardwarecommunication::Port8Bit attributeControllerIndexPort;
hardwarecommunication::Port8Bit attributeControllerReadPort;
hardwarecommunication::Port8Bit attributeControllerWritePort;
hardwarecommunication::Port8Bit attributeControllerResetPort;
void WriteRegisters(common::uint8_t* registers);
common::uint8_t* GetFrameBufferSegment();
virtual common::uint8_t GetColorIndex(common::uint8_t r, common::uint8_t g, common::uint8_t b);
public:
VideoGraphicsArray();
~VideoGraphicsArray();
virtual bool SupportsMode(common::uint32_t width, common::uint32_t height, common::uint32_t colordepth);
virtual bool SetMode(common::uint32_t width, common::uint32_t height, common::uint32_t colordepth);
virtual void PutPixel(common::uint32_t x, common::uint32_t y, common::uint8_t r, common::uint8_t g, common::uint8_t b);
virtual void PutPixel(common::uint32_t x, common::uint32_t y, common::uint8_t colorIndex);
};
}
}
#endif
View
@@ -15,6 +15,7 @@ objects = obj/loader.o \
obj/hardwarecommunication/pci.o \
obj/drivers/keyboard.o \
obj/drivers/mouse.o \
obj/drivers/vga.o \
obj/kernel.o
View
@@ -0,0 +1,144 @@
#include <drivers/vga.h>
using namespace myos::common;
using namespace myos::drivers;
VideoGraphicsArray::VideoGraphicsArray() :
miscPort(0x3c2),
crtcIndexPort(0x3d4),
crtcDataPort(0x3d5),
sequencerIndexPort(0x3c4),
sequencerDataPort(0x3c5),
graphicsControllerIndexPort(0x3ce),
graphicsControllerDataPort(0x3cf),
attributeControllerIndexPort(0x3c0),
attributeControllerReadPort(0x3c1),
attributeControllerWritePort(0x3c0),
attributeControllerResetPort(0x3da)
{
}
VideoGraphicsArray::~VideoGraphicsArray()
{
}
void VideoGraphicsArray::WriteRegisters(uint8_t* registers)
{
// misc
miscPort.Write(*(registers++));
// sequencer
for(uint8_t i = 0; i < 5; i++)
{
sequencerIndexPort.Write(i);
sequencerDataPort.Write(*(registers++));
}
// cathode ray tube controller
crtcIndexPort.Write(0x03);
crtcDataPort.Write(crtcDataPort.Read() | 0x80);
crtcIndexPort.Write(0x11);
crtcDataPort.Write(crtcDataPort.Read() & ~0x80);
registers[0x03] = registers[0x03] | 0x80;
registers[0x11] = registers[0x11] & ~0x80;
for(uint8_t i = 0; i < 25; i++)
{
crtcIndexPort.Write(i);
crtcDataPort.Write(*(registers++));
}
// graphics controller
for(uint8_t i = 0; i < 9; i++)
{
graphicsControllerIndexPort.Write(i);
graphicsControllerDataPort.Write(*(registers++));
}
// attribute controller
for(uint8_t i = 0; i < 21; i++)
{
attributeControllerResetPort.Read();
attributeControllerIndexPort.Write(i);
attributeControllerWritePort.Write(*(registers++));
}
attributeControllerResetPort.Read();
attributeControllerIndexPort.Write(0x20);
}
bool VideoGraphicsArray::SupportsMode(uint32_t width, uint32_t height, uint32_t colordepth)
{
return width == 320 && height == 200 && colordepth == 8;
}
bool VideoGraphicsArray::SetMode(uint32_t width, uint32_t height, uint32_t colordepth)
{
if(!SupportsMode(width, height, colordepth))
return false;
unsigned char g_320x200x256[] =
{
/* MISC */
0x63,
/* SEQ */
0x03, 0x01, 0x0F, 0x00, 0x0E,
/* CRTC */
0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F,
0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3,
0xFF,
/* GC */
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F,
0xFF,
/* AC */
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00
};
WriteRegisters(g_320x200x256);
return true;
}
uint8_t* VideoGraphicsArray::GetFrameBufferSegment()
{
graphicsControllerIndexPort.Write(0x06);
uint8_t segmentNumber = graphicsControllerDataPort.Read() & (3<<2);
switch(segmentNumber)
{
default:
case 0<<2: return (uint8_t*)0x00000;
case 1<<2: return (uint8_t*)0xA0000;
case 2<<2: return (uint8_t*)0xB0000;
case 3<<2: return (uint8_t*)0xB8000;
}
}
void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t colorIndex)
{
uint8_t* pixelAddress = GetFrameBufferSegment() + 320*y + x;
*pixelAddress = colorIndex;
}
uint8_t VideoGraphicsArray::GetColorIndex(uint8_t r, uint8_t g, uint8_t b)
{
if(r == 0x00, g == 0x00, b == 0xA8)
return 0x01;
return 0x00;
}
void VideoGraphicsArray::PutPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b)
{
PutPixel(x,y, GetColorIndex(r,g,b));
}
View
@@ -6,6 +6,7 @@
#include <drivers/driver.h>
#include <drivers/keyboard.h>
#include <drivers/mouse.h>
#include <drivers/vga.h>
using namespace myos;
using namespace myos::common;
@@ -151,11 +152,20 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
PeripheralComponentInterconnectController PCIController;
PCIController.SelectDrivers(&drvManager, &interrupts);
VideoGraphicsArray vga;
printf("Initializing Hardware, Stage 2\n");
drvManager.ActivateAll();
printf("Initializing Hardware, Stage 3\n");
interrupts.Activate();
vga.SetMode(320,200,8);
for(int32_t y = 0; y < 200; y++)
for(int32_t x = 0; x < 320; x++)
vga.PutPixel(x, y, 0x00, 0x00, 0xA8);
while(1);
}

0 comments on commit 16476d7

Please sign in to comment.