Updated vga code to newer coding conventions.
This commit is contained in:
parent
b2814db927
commit
d75a7145ef
|
@ -26,27 +26,12 @@
|
||||||
#ifndef LIBMAXSI_SORTIX_VGA_H
|
#ifndef LIBMAXSI_SORTIX_VGA_H
|
||||||
#define LIBMAXSI_SORTIX_VGA_H
|
#define LIBMAXSI_SORTIX_VGA_H
|
||||||
|
|
||||||
|
#include <sortix/vga.h>
|
||||||
|
|
||||||
namespace System
|
namespace System
|
||||||
{
|
{
|
||||||
namespace VGA
|
namespace VGA
|
||||||
{
|
{
|
||||||
// TODO: Move these to a better place
|
|
||||||
#define COLOR8_BLACK 0
|
|
||||||
#define COLOR8_BLUE 1
|
|
||||||
#define COLOR8_GREEN 2
|
|
||||||
#define COLOR8_CYAN 3
|
|
||||||
#define COLOR8_RED 4
|
|
||||||
#define COLOR8_MAGENTA 5
|
|
||||||
#define COLOR8_BROWN 6
|
|
||||||
#define COLOR8_LIGHT_GREY 7
|
|
||||||
#define COLOR8_DARK_GREY 8
|
|
||||||
#define COLOR8_LIGHT_BLUE 9
|
|
||||||
#define COLOR8_LIGHT_GREEN 10
|
|
||||||
#define COLOR8_LIGHT_CYAN 11
|
|
||||||
#define COLOR8_LIGHT_RED 12
|
|
||||||
#define COLOR8_LIGHT_MAGENTA 13
|
|
||||||
#define COLOR8_LIGHT_BROWN 14
|
|
||||||
#define COLOR8_WHITE 15
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||||
|
|
||||||
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
Sortix is free software: you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
sortix/vga.h
|
||||||
|
Standard symbolic constants and types for Sortix.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef INC_SORTIX_VGA_H
|
||||||
|
#define INC_SORTIX_VGA_H
|
||||||
|
|
||||||
|
#include <features.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
#define COLOR8_BLACK 0
|
||||||
|
#define COLOR8_BLUE 1
|
||||||
|
#define COLOR8_GREEN 2
|
||||||
|
#define COLOR8_CYAN 3
|
||||||
|
#define COLOR8_RED 4
|
||||||
|
#define COLOR8_MAGENTA 5
|
||||||
|
#define COLOR8_BROWN 6
|
||||||
|
#define COLOR8_LIGHT_GREY 7
|
||||||
|
#define COLOR8_DARK_GREY 8
|
||||||
|
#define COLOR8_LIGHT_BLUE 9
|
||||||
|
#define COLOR8_LIGHT_GREEN 10
|
||||||
|
#define COLOR8_LIGHT_CYAN 11
|
||||||
|
#define COLOR8_LIGHT_RED 12
|
||||||
|
#define COLOR8_LIGHT_MAGENTA 13
|
||||||
|
#define COLOR8_LIGHT_BROWN 14
|
||||||
|
#define COLOR8_WHITE 15
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
139
sortix/vga.cpp
139
sortix/vga.cpp
|
@ -35,38 +35,37 @@
|
||||||
|
|
||||||
using namespace Maxsi;
|
using namespace Maxsi;
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
{
|
namespace VGA {
|
||||||
namespace VGA
|
|
||||||
{
|
|
||||||
byte* const VGA = (byte* const) 0xB8000;
|
|
||||||
const unsigned WIDTH = 80;
|
|
||||||
const unsigned HEIGHT = 25;
|
|
||||||
const size_t VGA_SIZE = sizeof(uint16_t) * WIDTH * HEIGHT;
|
|
||||||
size_t vgafontsize;
|
|
||||||
uint8_t* vgafont;
|
|
||||||
|
|
||||||
static void WriteIndex(uint16_t port, uint8_t index, uint8_t value)
|
uint8_t* const VGA = (byte* const) 0xB8000;
|
||||||
{
|
const unsigned WIDTH = 80;
|
||||||
|
const unsigned HEIGHT = 25;
|
||||||
|
const size_t VGA_SIZE = sizeof(uint16_t) * WIDTH * HEIGHT;
|
||||||
|
size_t vgafontsize;
|
||||||
|
uint8_t* vgafont;
|
||||||
|
|
||||||
|
static void WriteIndex(uint16_t port, uint8_t index, uint8_t value)
|
||||||
|
{
|
||||||
CPU::OutPortB(port, index);
|
CPU::OutPortB(port, index);
|
||||||
CPU::OutPortB(port+1, value);
|
CPU::OutPortB(port+1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t ReadIndex(uint16_t port, uint8_t index)
|
static uint8_t ReadIndex(uint16_t port, uint8_t index)
|
||||||
{
|
{
|
||||||
CPU::OutPortB(port, index);
|
CPU::OutPortB(port, index);
|
||||||
return CPU::InPortB(port+1);
|
return CPU::InPortB(port+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t ReplaceIndex(uint16_t port, uint8_t index, uint8_t value)
|
static uint8_t ReplaceIndex(uint16_t port, uint8_t index, uint8_t value)
|
||||||
{
|
{
|
||||||
uint8_t ret = ReadIndex(port, index);
|
uint8_t ret = ReadIndex(port, index);
|
||||||
WriteIndex(port, index, value);
|
WriteIndex(port, index, value);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FetchVGAFont(uint8_t* font)
|
static void FetchVGAFont(uint8_t* font)
|
||||||
{
|
{
|
||||||
// TODO: I just got these magic constants off the net.
|
// TODO: I just got these magic constants off the net.
|
||||||
// Select plane 2 for reading.
|
// Select plane 2 for reading.
|
||||||
uint8_t old_03ce_04 = ReplaceIndex(0x03CE, 0x04, 0x02);
|
uint8_t old_03ce_04 = ReplaceIndex(0x03CE, 0x04, 0x02);
|
||||||
|
@ -93,11 +92,11 @@ namespace Sortix
|
||||||
WriteIndex(0x03CE, 0x05, old_03ce_05);
|
WriteIndex(0x03CE, 0x05, old_03ce_05);
|
||||||
WriteIndex(0x03CE, 0x06, old_03ce_06);
|
WriteIndex(0x03CE, 0x06, old_03ce_06);
|
||||||
WriteIndex(0x03CE, 0x04, old_03ce_04);
|
WriteIndex(0x03CE, 0x04, old_03ce_04);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TEST_VGAFONT
|
#if TEST_VGAFONT
|
||||||
static void PrintFontChar(const uint8_t* font, unsigned char c)
|
static void PrintFontChar(const uint8_t* font, unsigned char c)
|
||||||
{
|
{
|
||||||
const uint8_t* glyph = font + VGA_FONT_CHARSIZE * (size_t) c;
|
const uint8_t* glyph = font + VGA_FONT_CHARSIZE * (size_t) c;
|
||||||
for ( size_t y = 0; y < VGA_FONT_HEIGHT; y++ )
|
for ( size_t y = 0; y < VGA_FONT_HEIGHT; y++ )
|
||||||
{
|
{
|
||||||
|
@ -112,16 +111,16 @@ namespace Sortix
|
||||||
}
|
}
|
||||||
Log::Print("\n");
|
Log::Print("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint8_t* GetFont()
|
const uint8_t* GetFont()
|
||||||
{
|
{
|
||||||
return vgafont;
|
return vgafont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
vgafontsize = VGA_FONT_NUMCHARS * VGA_FONT_CHARSIZE;
|
vgafontsize = VGA_FONT_NUMCHARS * VGA_FONT_CHARSIZE;
|
||||||
if ( !(vgafont = new uint8_t[vgafontsize]) )
|
if ( !(vgafont = new uint8_t[vgafontsize]) )
|
||||||
Panic("Unable to allocate vga font buffer");
|
Panic("Unable to allocate vga font buffer");
|
||||||
|
@ -130,11 +129,11 @@ namespace Sortix
|
||||||
PrintFontChar(vgafont, 'A');
|
PrintFontChar(vgafont, 'A');
|
||||||
PrintFontChar(vgafont, 'S');
|
PrintFontChar(vgafont, 'S');
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes the position of the hardware cursor.
|
// Changes the position of the hardware cursor.
|
||||||
void SetCursor(nat x, nat y)
|
void SetCursor(unsigned x, unsigned y)
|
||||||
{
|
{
|
||||||
nat value = x + y * WIDTH;
|
nat value = x + y * WIDTH;
|
||||||
|
|
||||||
// This sends a command to indicies 14 and 15 in the
|
// This sends a command to indicies 14 and 15 in the
|
||||||
|
@ -145,16 +144,17 @@ namespace Sortix
|
||||||
CPU::OutPortB(0x3D5, (value >> 8) & 0xFF);
|
CPU::OutPortB(0x3D5, (value >> 8) & 0xFF);
|
||||||
CPU::OutPortB(0x3D4, 15);
|
CPU::OutPortB(0x3D4, 15);
|
||||||
CPU::OutPortB(0x3D5, (value >> 0) & 0xFF);
|
CPU::OutPortB(0x3D5, (value >> 0) & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DevVGA::DevVGA()
|
} // namespace VGA
|
||||||
{
|
|
||||||
|
DevVGA::DevVGA()
|
||||||
|
{
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevVGA::~DevVGA()
|
DevVGA::~DevVGA()
|
||||||
{
|
{
|
||||||
#ifdef PLATFORM_SERIAL
|
#ifdef PLATFORM_SERIAL
|
||||||
// TODO: HACK: This is a hack that is unrelated to this file.
|
// TODO: HACK: This is a hack that is unrelated to this file.
|
||||||
// This is a hack to make the cursor a proper color after the vga buffer
|
// This is a hack to make the cursor a proper color after the vga buffer
|
||||||
|
@ -163,18 +163,18 @@ namespace Sortix
|
||||||
// them, but this will do for now.
|
// them, but this will do for now.
|
||||||
Log::PrintF("\e[m");
|
Log::PrintF("\e[m");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t DevVGA::Read(byte* dest, size_t count)
|
ssize_t DevVGA::Read(byte* dest, size_t count)
|
||||||
{
|
{
|
||||||
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
|
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
|
||||||
Maxsi::Memory::Copy(dest, VGA::VGA + offset, count);
|
Maxsi::Memory::Copy(dest, VGA::VGA + offset, count);
|
||||||
offset += count;
|
offset += count;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t DevVGA::Write(const byte* src, size_t count)
|
ssize_t DevVGA::Write(const byte* src, size_t count)
|
||||||
{
|
{
|
||||||
if ( offset == VGA::VGA_SIZE && count ) { Error::Set(ENOSPC); return -1; }
|
if ( offset == VGA::VGA_SIZE && count ) { Error::Set(ENOSPC); return -1; }
|
||||||
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
|
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
|
||||||
Maxsi::Memory::Copy(VGA::VGA + offset, src, count);
|
Maxsi::Memory::Copy(VGA::VGA + offset, src, count);
|
||||||
|
@ -184,44 +184,45 @@ namespace Sortix
|
||||||
SerialTerminal::OnVGAModified();
|
SerialTerminal::OnVGAModified();
|
||||||
#endif
|
#endif
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevVGA::IsReadable()
|
bool DevVGA::IsReadable()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevVGA::IsWritable()
|
bool DevVGA::IsWritable()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DevVGA::BlockSize()
|
size_t DevVGA::BlockSize()
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintmax_t DevVGA::Size()
|
uintmax_t DevVGA::Size()
|
||||||
{
|
{
|
||||||
return VGA::VGA_SIZE;
|
return VGA::VGA_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uintmax_t DevVGA::Position()
|
uintmax_t DevVGA::Position()
|
||||||
{
|
{
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevVGA::Seek(uintmax_t position)
|
bool DevVGA::Seek(uintmax_t position)
|
||||||
{
|
{
|
||||||
if ( VGA::VGA_SIZE < position ) { Error::Set(EINVAL); return false; }
|
if ( VGA::VGA_SIZE < position ) { Error::Set(EINVAL); return false; }
|
||||||
offset = position;
|
offset = position;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevVGA::Resize(uintmax_t size)
|
bool DevVGA::Resize(uintmax_t size)
|
||||||
{
|
{
|
||||||
if ( size == VGA::VGA_SIZE ) { return false; }
|
if ( size == VGA::VGA_SIZE ) { return false; }
|
||||||
Error::Set(ENOSPC);
|
Error::Set(ENOSPC);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
64
sortix/vga.h
64
sortix/vga.h
|
@ -28,51 +28,36 @@
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
|
|
||||||
|
const size_t VGA_FONT_WIDTH = 8UL;
|
||||||
|
const size_t VGA_FONT_HEIGHT = 16UL;
|
||||||
|
const size_t VGA_FONT_NUMCHARS = 256UL;
|
||||||
|
const size_t VGA_FONT_CHARSIZE = VGA_FONT_WIDTH * VGA_FONT_HEIGHT / 8UL;
|
||||||
|
|
||||||
|
namespace VGA {
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void SetCursor(unsigned x, unsigned y);
|
||||||
|
const uint8_t* GetFont();
|
||||||
|
|
||||||
|
} // namespace VGA
|
||||||
|
|
||||||
|
// TODO: This class shouldn't be exposed publicly; it is used in a hack in the
|
||||||
|
// /dev filesystem. However, vga.cpp should register /dev/vga instead.
|
||||||
|
class DevVGA : public DevBuffer
|
||||||
{
|
{
|
||||||
const size_t VGA_FONT_WIDTH = 8UL;
|
public:
|
||||||
const size_t VGA_FONT_HEIGHT = 16UL;
|
|
||||||
const size_t VGA_FONT_NUMCHARS = 256UL;
|
|
||||||
const size_t VGA_FONT_CHARSIZE = VGA_FONT_WIDTH * VGA_FONT_HEIGHT / 8UL;
|
|
||||||
|
|
||||||
namespace VGA
|
|
||||||
{
|
|
||||||
// TODO: Move these to a better place
|
|
||||||
#define COLOR8_BLACK 0
|
|
||||||
#define COLOR8_BLUE 1
|
|
||||||
#define COLOR8_GREEN 2
|
|
||||||
#define COLOR8_CYAN 3
|
|
||||||
#define COLOR8_RED 4
|
|
||||||
#define COLOR8_MAGENTA 5
|
|
||||||
#define COLOR8_BROWN 6
|
|
||||||
#define COLOR8_LIGHT_GREY 7
|
|
||||||
#define COLOR8_DARK_GREY 8
|
|
||||||
#define COLOR8_LIGHT_BLUE 9
|
|
||||||
#define COLOR8_LIGHT_GREEN 10
|
|
||||||
#define COLOR8_LIGHT_CYAN 11
|
|
||||||
#define COLOR8_LIGHT_RED 12
|
|
||||||
#define COLOR8_LIGHT_MAGENTA 13
|
|
||||||
#define COLOR8_LIGHT_BROWN 14
|
|
||||||
#define COLOR8_WHITE 15
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
void SetCursor(nat x, nat y);
|
|
||||||
const uint8_t* GetFont();
|
|
||||||
}
|
|
||||||
|
|
||||||
class DevVGA : public DevBuffer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef DevBuffer BaseClass;
|
typedef DevBuffer BaseClass;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DevVGA();
|
DevVGA();
|
||||||
virtual ~DevVGA();
|
virtual ~DevVGA();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t offset;
|
size_t offset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ssize_t Read(byte* dest, size_t count);
|
virtual ssize_t Read(byte* dest, size_t count);
|
||||||
virtual ssize_t Write(const byte* src, size_t count);
|
virtual ssize_t Write(const byte* src, size_t count);
|
||||||
virtual bool IsReadable();
|
virtual bool IsReadable();
|
||||||
|
@ -83,8 +68,9 @@ namespace Sortix
|
||||||
virtual bool Seek(uintmax_t position);
|
virtual bool Seek(uintmax_t position);
|
||||||
virtual bool Resize(uintmax_t size);
|
virtual bool Resize(uintmax_t size);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <sortix/kernel/platform.h>
|
#include <sortix/kernel/platform.h>
|
||||||
#include <sortix/kernel/log.h>
|
#include <sortix/kernel/log.h>
|
||||||
|
#include <sortix/vga.h>
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
#include "vgaterminal.h"
|
#include "vgaterminal.h"
|
||||||
|
|
Loading…
Reference in New Issue