1
// vi:ts=4:shiftwidth=4:expandtab
2
/***************************************************************************
3
vgadev.cpp - description
5
begin : Wed Sept 05 2001
6
copyright : (C) 2001 by rick, huyong
7
email : rick@chinaren.com
10
***************************************************************************/
12
/***************************************************************************
14
* This program is free software; you can redistribute it and/or modify *
15
* it under the terms of the GNU General Public License as published by *
16
* the Free Software Foundation; either version 2 of the License, or *
17
* (at your option) any later version. *
19
***************************************************************************/
32
#include <sys/ioctl.h>
42
#define GRAPH_BASE 0xA0000
43
#define GRAPH_ADDR 0x3ce
44
#define GRAPH_DATA 0x3cf
46
char *VGADev::mpBuf = NULL;
47
int VGADev::mBufLen = 0;
48
unsigned long VGADev::mNextLine = 0; // offset to one line below
51
bool VGADev::TryOpen() {
53
fprintf(stderr, "\n(VGADev::TryOpen) LRMI_init() failed.\n");
58
if (!SetVideoMode(0x12)) {
60
fprintf(stderr, "\n(VGADev::TryOpen) LRMI_init() failed, can not set video mode 0x12\n");
64
if ((mFd = open("/dev/mem", O_RDWR)) < 0) {
66
fprintf(stderr, "\n(VGADev::TryOpen) can not open /dev/mem in read/write mode\n");
72
mBufLen = mXres * mYres / 8;
73
mpBuf = static_cast<char *>(mmap((__ptr_t)0, mBufLen, PROT_READ | PROT_WRITE, MAP_SHARED,
75
if (mpBuf == MAP_FAILED) {
77
fprintf(stderr, "\n(VGADev::TryOpen) mmap() call failed\n");
81
mpGraphDev = new VGADev;
86
mNextLine = mXres >> 3;
93
munmap(mpBuf, mBufLen);
100
void VGADev::EnableIOPerm()
102
ioperm(GRAPH_ADDR, 1, 1);
103
ioperm(GRAPH_DATA, 1, 1);
108
void VGADev::DisableIOPerm()
110
ioperm(GRAPH_ADDR, 1, 0);
111
ioperm(GRAPH_DATA, 1, 0);
116
inline bool VGADev::SetVideoMode(int mode)
119
memset(&r, 0, sizeof(r));
121
return LRMI_int(0x10, &r);
124
inline void VGADev::SetDefaultMode() {
130
inline void VGADev::SetBitMask(char mask) {
132
outb(mask, GRAPH_DATA);
135
inline void VGADev::SetOper(int op) {
137
outb(op, GRAPH_DATA);
140
inline void VGADev::SetWriteMode(int mode) {
142
outb(mode, GRAPH_DATA);
145
inline void VGADev::SetColor(int color) {
147
outb(color, GRAPH_DATA);
150
void VGADev::PutPixel(int x,int y,int color) {
151
static int prevColor = -1;
152
if (prevColor != color) {
157
__u8* dest = (__u8*)mpBuf + mNextLine * y + (x>>3);
159
*dest = 0x80 >> (x & 7);
162
void VGADev::FillRect(int x1,int y1,int x2,int y2,int color) {
163
assert( x1 >= 0 && x1 < mXres && y1 >=0 && y1 < mYres);
164
assert( x2 >= 0 && x2 < mXres && y2 >=0 && y2 < mYres);
165
assert(x1 <= x2 && y1 <= y2);
168
//debug<<"FillRect ("<<x1<<","<<y1<<")-("<<x2<<","<<y2<<")"<<endl;
172
__u8* destorig = (__u8*)mpBuf + mNextLine * y1 + (x1>>3);
173
__u8* dest = destorig;
175
int width = x2 - x1 + 1;
176
int left, right, midbytes;
179
if (left == 8) left = 0;
185
right = (x1 + width) & 7;
186
midbytes = (width - left - right) / 8;
189
if (left + right > width || midbytes < 0) {
190
debug<<"FillRect x1="<<x1<<" width="<<width<<" left="<<left;
191
debug<<" midbytes="<<midbytes<<" right="<<right<<endl;
197
__u8 leftmask = 0xff >> (8 - left);
198
if (left > width) leftmask &= 0xff << (left - width);
199
for (height = y2 - y1 + 1; height--; dest += mNextLine) {
200
fb_readb(dest); // fill latches
207
for (height = y2 - y1 + 1; height--; dest += mNextLine) {
208
memset(dest, 0xff, midbytes);
210
destorig += midbytes;
214
__u8 rightmask = 0xff << (8 - right);
215
for (height = y2 - y1 + 1; height--; dest += mNextLine) {
216
fb_readb(dest); // fill latches
222
void VGADev::RevRect(int x1,int y1,int x2,int y2) {
223
assert( x1 >= 0 && x1 < Width() && y1 >=0 && y1 < Height());
224
assert( x2 >= 0 && x2 < Width() && y2 >=0 && y2 < Height());
225
assert(x1 <= x2 && y1 <= y2);
227
__u8* dest = (__u8*)mpBuf + mNextLine * y1 + (x1>>3);
235
int width = x2 - x1 + 1;
236
int left, right, midbytes;
239
if (left == 8) left = 0;
245
right = (x1 + width) & 7;
246
midbytes = (width - left - right) / 8;
249
__u8 leftmask = 0xff >> (8 - left);
250
if (left > width) leftmask &= 0xff << (left - width);
251
__u8 rightmask = 0xff << (8 - right);
253
for(int height = y2 - y1 + 1; height--; dest += mNextLine) {
257
fb_writeb(leftmask, dest8++);
260
for(cnt = midbytes; cnt--; ) {
262
fb_writeb(0xff, dest8++);
267
fb_writeb(rightmask, dest8);
273
void VGADev::DrawChar(int x,int y,int fg,int bg,struct CharBitMap* pFont) {
274
__u8* destorig = (__u8*)mpBuf + mNextLine * y + (x >> 3);
278
int LeftShift = x & 7;
279
int FillBytes = (LeftShift + pFont->w + 7) >> 3;
280
// maxium 24 pixel width font
281
if (FillBytes > 3) FillBytes = 3;
290
UniLine.l = (0xffffffff >> LeftShift)
291
& (0xffffffff << (32 - LeftShift - pFont->w));
295
for (rows = mBlockHeight; rows-- ; dest += mNextLine) {
297
cdat8 = (__u8*)&UniLine.ch[3];
298
for (cnt = FillBytes; cnt--;) {
300
fb_writeb(*cdat8--, dest8++);
306
char *pFontLine = pFont->pBuf;
307
if (LeftShift == 0) {
308
for (rows = mBlockHeight; rows-- ; dest += mNextLine) {
311
memcpy(&UniLine, pFontLine, pFont->wBytes);
312
cdat8 = (__u8*)&UniLine;
313
for (cnt = FillBytes; cnt--;) {
315
fb_writeb(*cdat8++, dest8++);
317
pFontLine += pFont->wBytes;
322
for (rows = mBlockHeight; rows-- ; dest += mNextLine) {
327
cdat8 = (__u8*)pFontLine;
328
for (cnt = 0; cnt < pFont->wBytes; cnt++) {
329
UniLine.ch[3 - cnt] = *cdat8++;
331
UniLine.l >>= LeftShift;
332
cdat8 = (__u8*)&UniLine.ch[3];
333
for (cnt = FillBytes; cnt--;) {
335
fb_writeb(*cdat8--, dest8++);
337
pFontLine += pFont->wBytes;
341
void VGADev::SwitchToGraph() {
346
void VGADev::SwitchToText() {