The Pedigree Project  0.1
kernel/machine/mach_pc/Vga.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef MACHINE_X86_VGA_H
21 #define MACHINE_X86_VGA_H
22 
23 #include "pedigree/kernel/machine/Vga.h"
24 #include "pedigree/kernel/processor/IoPort.h"
25 #include "pedigree/kernel/processor/MemoryMappedIo.h"
26 #include "pedigree/kernel/processor/types.h"
27 
28 #define VGA_BASE 0x3C0
29 #define VGA_AC_INDEX 0x0
30 #define VGA_AC_WRITE 0x0
31 #define VGA_AC_READ 0x1
32 #define VGA_MISC_WRITE 0x2
33 #define VGA_SEQ_INDEX 0x4
34 #define VGA_SEQ_DATA 0x5
35 #define VGA_DAC_READ_INDEX 0x7
36 #define VGA_DAC_WRITE_INDEX 0x8
37 #define VGA_DAC_DATA 0x9
38 #define VGA_MISC_READ 0xC
39 #define VGA_GC_INDEX 0xE
40 #define VGA_GC_DATA 0xF
41 #define VGA_REG_ATTR_MODE_CTL 0x10
42 /* COLOR emulation MONO emulation */
43 #define VGA_CRTC_INDEX 0x14 /* 0x3B4 */
44 #define VGA_CRTC_DATA 0x15 /* 0x3B5 */
45 #define VGA_INSTAT_READ 0x1A
46 
47 #define VGA_PAS 0x20 /* Palette Address Source */
48 
49 #define VGA_NUM_SEQ_REGS 5
50 #define VGA_NUM_CRTC_REGS 25
51 #define VGA_NUM_GC_REGS 9
52 #define VGA_NUM_AC_REGS 21
53 #define VGA_NUM_REGS \
54  (1 + VGA_NUM_SEQ_REGS + VGA_NUM_CRTC_REGS + VGA_NUM_GC_REGS + \
55  VGA_NUM_AC_REGS)
56 
60 class X86Vga : public Vga
61 {
62  public:
63  X86Vga(uint32_t nRegisterBase, uint32_t nFramebufferBase);
64  virtual ~X86Vga();
65 
69  virtual void setControl(VgaControl which);
70 
74  virtual void clearControl(VgaControl which);
75 
76  virtual bool setMode(int mode);
77 
82  virtual bool setLargestTextMode();
83 
88  virtual bool
89  isMode(size_t nCols, size_t nRows, bool bIsText, size_t nBpp = 0);
90 
95  virtual bool isLargestTextMode();
96 
100  virtual size_t getNumCols()
101  {
102  return m_nWidth;
103  }
104 
108  virtual size_t getNumRows()
109  {
110  return m_nHeight;
111  }
112 
116  virtual void rememberMode();
117 
121  virtual void restoreMode();
122 
133  virtual void pokeBuffer(uint8_t *pBuffer, size_t nBufLen);
134 
144  virtual void peekBuffer(uint8_t *pBuffer, size_t nBufLen);
145 
151  virtual void moveCursor(size_t nX, size_t nY);
152 
153  bool initialise();
154 
155  operator uint16_t *() const
156  {
157  if (m_Framebuffer == true)
158  return reinterpret_cast<uint16_t *>(m_Framebuffer.virtualAddress());
159  else
160  return reinterpret_cast<uint16_t *>(m_pFramebuffer);
161  }
162 
163  private:
164  X86Vga(const X86Vga &);
165  X86Vga &operator=(const X86Vga &);
166 
167  uint8_t getControls();
168  void setControls(uint8_t newControls);
169 
174 
175  MemoryMappedIo m_Framebuffer;
176 
180  uint8_t *m_pFramebuffer;
181 
185  size_t m_nWidth;
186 
190  size_t m_nHeight;
191 
199 
203  int m_nMode;
204 
208  uint8_t m_nControls;
209 };
210 
211 #endif
virtual void restoreMode()
virtual void peekBuffer(uint8_t *pBuffer, size_t nBufLen)
virtual void moveCursor(size_t nX, size_t nY)
virtual size_t getNumCols()
virtual void pokeBuffer(uint8_t *pBuffer, size_t nBufLen)
Memory mapped I/O range.
virtual void clearControl(VgaControl which)
uint8_t * m_pFramebuffer
I/O port range.
Definition: IoPort.h:34
virtual bool isMode(size_t nCols, size_t nRows, bool bIsText, size_t nBpp=0)
virtual bool isLargestTextMode()
virtual void setControl(VgaControl which)
virtual bool setMode(int mode)
void * virtualAddress() const
Definition: MemoryRegion.cc:39
virtual bool setLargestTextMode()
virtual void rememberMode()
virtual size_t getNumRows()