2011-08-08 09:18:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
|
|
|
|
vga.h
|
|
|
|
A Video Graphics Array driver.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "platform.h"
|
2011-11-25 07:38:31 -05:00
|
|
|
#include <libmaxsi/error.h>
|
2011-08-08 09:18:39 -04:00
|
|
|
#include <libmaxsi/memory.h>
|
|
|
|
#include "vga.h"
|
|
|
|
#include "memorymanagement.h"
|
|
|
|
#include "scheduler.h"
|
2011-10-26 18:05:20 -04:00
|
|
|
#include "syscall.h"
|
2011-09-21 14:52:29 -04:00
|
|
|
#include "process.h"
|
2011-11-20 09:58:42 -05:00
|
|
|
#include "serialterminal.h"
|
2011-08-08 09:18:39 -04:00
|
|
|
|
|
|
|
using namespace Maxsi;
|
|
|
|
|
|
|
|
namespace Sortix
|
|
|
|
{
|
|
|
|
namespace VGA
|
|
|
|
{
|
2011-11-25 07:38:31 -05:00
|
|
|
byte* const VGA = (byte* const) 0xB8000;
|
|
|
|
const unsigned WIDTH = 80;
|
|
|
|
const unsigned HEIGHT = 25;
|
|
|
|
const size_t VGA_SIZE = sizeof(uint16_t) * WIDTH * HEIGHT;
|
2011-08-08 09:18:39 -04:00
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-08-22 05:11:50 -04:00
|
|
|
// Changes the position of the hardware cursor.
|
|
|
|
void SetCursor(nat x, nat y)
|
|
|
|
{
|
2011-11-25 07:38:31 -05:00
|
|
|
nat value = x + y * WIDTH;
|
2011-08-22 05:11:50 -04:00
|
|
|
|
|
|
|
// This sends a command to indicies 14 and 15 in the
|
|
|
|
// CRT Control Register of the VGA controller. These
|
|
|
|
// are the high and low bytes of the index that show
|
|
|
|
// where the hardware cursor is to be 'blinking'.
|
|
|
|
CPU::OutPortB(0x3D4, 14);
|
|
|
|
CPU::OutPortB(0x3D5, (value >> 8) & 0xFF);
|
|
|
|
CPU::OutPortB(0x3D4, 15);
|
|
|
|
CPU::OutPortB(0x3D5, (value >> 0) & 0xFF);
|
2011-11-25 07:38:31 -05:00
|
|
|
}
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
DevVGA::DevVGA()
|
|
|
|
{
|
|
|
|
offset = 0;
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
DevVGA::~DevVGA()
|
|
|
|
{
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
ssize_t DevVGA::Read(byte* dest, size_t count)
|
|
|
|
{
|
|
|
|
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
|
|
|
|
Maxsi::Memory::Copy(dest, VGA::VGA + offset, count);
|
|
|
|
offset += count;
|
|
|
|
return count;
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
ssize_t DevVGA::Write(const byte* src, size_t count)
|
|
|
|
{
|
|
|
|
if ( offset == VGA::VGA_SIZE && count ) { Error::Set(ENOSPC); return -1; }
|
|
|
|
if ( VGA::VGA_SIZE - offset < count ) { count = VGA::VGA_SIZE - offset; }
|
|
|
|
Maxsi::Memory::Copy(VGA::VGA + offset, src, count);
|
|
|
|
offset = (offset + count) % VGA::VGA_SIZE;
|
|
|
|
return count;
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
bool DevVGA::IsReadable()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
bool DevVGA::IsWritable()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-26 18:05:20 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
size_t DevVGA::BlockSize()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
uintmax_t DevVGA::Size()
|
|
|
|
{
|
|
|
|
return VGA::VGA_SIZE;
|
2011-08-08 09:18:39 -04:00
|
|
|
}
|
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
uintmax_t DevVGA::Position()
|
2011-08-08 09:18:39 -04:00
|
|
|
{
|
2011-11-25 07:38:31 -05:00
|
|
|
return offset;
|
2011-08-08 09:18:39 -04:00
|
|
|
}
|
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
bool DevVGA::Seek(uintmax_t position)
|
2011-08-08 09:18:39 -04:00
|
|
|
{
|
2011-11-25 07:38:31 -05:00
|
|
|
if ( VGA::VGA_SIZE < position ) { Error::Set(EINVAL); return false; }
|
|
|
|
offset = position;
|
|
|
|
return true;
|
2011-08-08 09:18:39 -04:00
|
|
|
}
|
|
|
|
|
2011-11-25 07:38:31 -05:00
|
|
|
bool DevVGA::Resize(uintmax_t size)
|
2011-11-16 02:37:29 -05:00
|
|
|
{
|
2011-11-25 07:38:31 -05:00
|
|
|
if ( size == VGA::VGA_SIZE ) { return false; }
|
|
|
|
Error::Set(ENOSPC);
|
|
|
|
return false;
|
2011-11-16 02:37:29 -05:00
|
|
|
}
|
2011-08-08 09:18:39 -04:00
|
|
|
}
|