FreeNOS
VGA.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FreeNOS/User.h>
19#include <Types.h>
20#include <MemoryBlock.h>
21#include "VGA.h"
22
23VGA::VGA(const u32 inode,
24 const Size w,
25 const Size h)
26 : Device(inode, FileSystem::BlockDeviceFile)
27 , width(w)
28 , height(h)
29{
30 m_identifier << "vga0";
31}
32
34{
35 Memory::Range range;
36
37 // Request VGA memory
38 range.size = PAGESIZE;
39 range.access = Memory::User |
42 range.virt = ZERO;
43 range.phys = VGA_PADDR;
44 VMCtl(SELF, MapContiguous, &range);
45
46 // Point to the VGA mapping
47 vga = (u16 *) range.virt;
48
49 // Clear screen
50 for (uint i = 0; i < width * height; i++)
51 {
52 vga[i] = VGA_CHAR(' ', LIGHTGREY, BLACK);
53 }
54
55 // Disable hardware cursor
56 m_io.outb(VGA_IOADDR, 0x0a);
57 m_io.outb(VGA_IODATA, 1 << 5);
58
59 // Successfull
61}
62
64 Size & size,
65 const Size offset)
66{
67 if (offset + size > width * height * sizeof(u16))
68 {
70 }
71
72 buffer.write(vga + (offset / sizeof(u16)), size);
74}
75
77 Size & size,
78 const Size offset)
79{
80 if (offset + size > width * height * sizeof(u16))
81 {
83 }
84
85 MemoryBlock::copy(vga + (offset / sizeof(u16)), buffer.getBuffer(), size);
87}
Abstract device class interface.
Definition Device.h:36
String m_identifier
Unique identifier for this Device.
Definition Device.h:79
Abstract Input/Output buffer.
Definition IOBuffer.h:38
u8 * getBuffer()
Get raw buffer.
Definition IOBuffer.cpp:125
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition IOBuffer.cpp:180
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read video memory.
Definition VGA.cpp:63
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Write video memory.
Definition VGA.cpp:76
u16 * vga
VGA video memory address.
Definition VGA.h:151
virtual FileSystem::Result initialize()
Initialize the VGA device.
Definition VGA.cpp:33
VGA(const u32 inode, const Size width=80, const Size height=25)
Class constructor function.
Definition VGA.cpp:23
Size height
Number of characters vertically.
Definition VGA.h:157
Arch::IO m_io
Port I/O object.
Definition VGA.h:160
Size width
Number of characters horizontally.
Definition VGA.h:154
#define SELF
Definition ProcessID.h:35
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition VMCtl.h:61
@ MapContiguous
Definition VMCtl.h:37
#define PAGESIZE
ARM uses 4K pages.
Definition ARMConstant.h:97
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int uint
Unsigned integer number.
Definition Types.h:44
unsigned short u16
Unsigned 16-bit number.
Definition Types.h:56
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43
#define VGA_IODATA
VGA I/O data port.
Definition VGA.h:40
#define VGA_PADDR
VGA physical video memory address.
Definition VGA.h:34
#define VGA_IOADDR
VGA I/O address port.
Definition VGA.h:37
#define VGA_CHAR(ch, front, back)
Encodes a character for VGA output.
Definition VGA.h:58
@ LIGHTGREY
Definition VGA.h:73
@ BLACK
Definition VGA.h:66
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
@ InvalidArgument
Definition FileSystem.h:55
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
@ Writable
Definition Memory.h:42
Memory range.
Definition Memory.h:56
Size size
Size in number of bytes.
Definition Memory.h:59
Address phys
Physical address.
Definition Memory.h:58
Address virt
Virtual address.
Definition Memory.h:57
Access access
Page access flags.
Definition Memory.h:60