📄 fblin4hp.c
字号:
/*
* Copyright (c) 1999 Greg Haerr <greg@censoft.com>
*
* 4bpp Packed Linear Video Driver for Microwindows
* This driver is written for the Vr41xx Palm PC machines
* Hopefully, we can get the 4bpp mode running 320x240x16
*
* In this driver, psd->linelen is line byte length, not line pixel length
*/
/*#define NDEBUG*/
#include <assert.h>
#include <string.h>
#include "device.h"
#include "fb.h"
//static unsigned char notmask[2] = { 0x0f, 0xf0}; // non-linear
static unsigned char notmask[2] = { 0xf0, 0x0f }; // linear
static unsigned char revnotmask[2] = { 0xf0, 0x0f};
/* Calc linelen and mmap size, return 0 on fail*/
static int
linear4_init(PSD psd)
{
if (!psd->size)
psd->size = psd->yres * psd->linelen;
/* linelen in bytes for bpp 1, 2, 4, 8 so no change*/
return 1;
}
#if 1 // kykim
/* Read pixel at x, y*/
static MWPIXELVAL
linear4_readpixel(PSD psd, MWCOORD x, MWCOORD y)
{
ADDR8 addr = psd->addr;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y >= 0 && y < psd->yres);
return (addr[(x>>1) + y * psd->linelen] >> (((x&1))<<2) ) & 0x0f;
}
/* Draw a vertical line from x,y1 to x,y2 including final point*/
static void
linear4_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
{
ADDR8 addr = psd->addr;
int linelen = psd->linelen;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y1 >= 0 && y1 < psd->yres);
assert (y2 >= 0 && y2 < psd->yres);
assert (y2 >= y1);
assert (c < psd->ncolors);
DRAWON;
addr += (x>>1) + y1 * linelen;
while(y1++ <= y2) {
*addr = (*addr & notmask[x&1]) | (c << (((x&1))<<2));
addr += linelen;
}
DRAWOFF;
}
#endif // kykim
/* ########################################################################## */
#if 0 // For 8 bit memory access
/* Set pixel at x, y, to pixelval c*/
static void
linear4_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
{
ADDR8 addr = psd->addr;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y >= 0 && y < psd->yres);
assert (c < psd->ncolors);
DRAWON;
addr += (x>>1) + y * psd->linelen;
// if(gr_mode == MWMODE_XOR)
// *addr ^= c << ((1-(x&1))<<2);
// else
*addr = (*addr & notmask[x&1]) | (c << (((x&1))<<2) );
DRAWOFF;
}
/* Read pixel at x, y*/
static MWPIXELVAL
linear4_readpixel(PSD psd, MWCOORD x, MWCOORD y)
{
ADDR8 addr = psd->addr;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y >= 0 && y < psd->yres);
return (addr[(x>>1) + y * psd->linelen] >> (((x&1))<<2) ) & 0x0f;
}
/* Draw horizontal line from x1,y to x2,y including final point*/
static void
linear4_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
{
ADDR8 addr = psd->addr;
assert (addr != 0);
assert (x1 >= 0 && x1 < psd->xres);
assert (x2 >= 0 && x2 < psd->xres);
assert (x2 >= x1);
assert (y >= 0 && y < psd->yres);
assert (c < psd->ncolors);
DRAWON;
addr += (x1>>1) + y * psd->linelen;
/* if(gr_mode == MWMODE_XOR) {
while(x1 <= x2) {
*addr ^= c << ((1-(x1&1))<<2);
if((++x1 & 1) == 0)
++addr;
}
} else {
*/
while(x1 <= x2) {
*addr = (*addr & notmask[x1&1]) | (c << (((x1&1))<<2));
if((++x1 & 1) == 0)
++addr;
}
// }
DRAWOFF;
}
/* Draw a vertical line from x,y1 to x,y2 including final point*/
static void
linear4_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
{
ADDR8 addr = psd->addr;
int linelen = psd->linelen;
assert (addr != 0);
assert (x >= 0 && x < psd->xres);
assert (y1 >= 0 && y1 < psd->yres);
assert (y2 >= 0 && y2 < psd->yres);
assert (y2 >= y1);
assert (c < psd->ncolors);
DRAWON;
addr += (x>>1) + y1 * linelen;
while(y1++ <= y2) {
*addr = (*addr & notmask[x&1]) | (c << (((x&1))<<2));
addr += linelen;
}
DRAWOFF;
}
/* srccopy bitblt, opcode is currently ignored*/
static void
linear4_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
{
ADDR8 dst;
ADDR8 src;
int i;
int dlinelen = dstpsd->linelen;
int slinelen = srcpsd->linelen;
assert (dstpsd->addr != 0);
assert (dstx >= 0 && dstx < dstpsd->xres);
assert (dsty >= 0 && dsty < dstpsd->yres);
assert (w > 0);
assert (h > 0);
assert (srcpsd->addr != 0);
assert (srcx >= 0 && srcx < srcpsd->xres);
assert (srcy >= 0 && srcy < srcpsd->yres);
assert (dstx+w <= dstpsd->xres);
assert (dsty+h <= dstpsd->yres);
assert (srcx+w <= srcpsd->xres);
assert (srcy+h <= srcpsd->yres);
DRAWON;
dst = dstpsd->addr + (dstx>>1) + dsty * dlinelen;
src = srcpsd->addr + (srcx>>1) + srcy * slinelen;
while(--h >= 0) {
ADDR8 d = dst;
ADDR8 s = src;
MWCOORD dx = dstx;
MWCOORD sx = srcx;
for(i=0; i<w; ++i) {
*d = (*d & notmask[dx&1]) |
((*s >> (((sx&1))<<2) & 0x0f) << (((dx&1))<<2));
if((++dx & 1) == 0)
++d;
if((++sx & 1) == 0)
++s;
}
dst += dlinelen;
src += slinelen;
}
DRAWOFF;
}
#endif // For 8 bit memory access
/* ########################################################################## */
// All these functions are working using the same philosophie:
// There are 8 pixels in an int (pixel0= bit 0 to 3, ....)
// As this is a 32 bits micro, all access should be made
// on 32 bits and should try to work on as many pixels as necceseray
// in order to minimize memory access.
typedef unsigned int T8p; // set of 8 pixels
typedef unsigned int * P8p; // pointer on a set of 8 pixels
// this set of mask allows to select the n first pixels of an int
static const T8p Masks[]=
{0x00000000, 0x0000000f, 0x000000ff, 0x00000fff,
0x0000ffff, 0x000fffff, 0x00ffffff, 0x0fffffff};
// this set of mask allow to select the n first pixels of an int.
// but a selection of 0 pixels selects in fact the 8 pixels.
static const T8p Masks2[]=
{0xffffffff, 0x0000000f, 0x000000ff, 0x00000fff,
0x0000ffff, 0x000fffff, 0x00ffffff, 0x0fffffff};
// this function create a set of 8 pixels of the same color.
static inline T8p EColor(T8p c)
{
c|= c<<4; c|= c<<8; c|= c<<16;
return(c);
}
// this function compute the addres of the group of pixels containing
// pixel x, y when the graphic is pointed by m and the size of a line is
// LineSize bytes
static inline P8p PPointer(P8p m, int LineSize, int x, int y)
{
return( (P8p) (((int)m+((x>>1)+y*LineSize))&~3) );
}
// this function is a memset, but faster, and for ints....
void intset(int *d, int value, int nbInts);
#define swap(t, a, b) { t temp= a; a= b; b= temp; }
static
void linear41_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
{
P8p p= PPointer(psd->addr, psd->linelen, x, y); // get pixel address
DRAWON;
x= (x&0x7)<<2; // get pixel position in the word (pixel number * 4)
*p= ((*p)&~(0xf<<x))|(c<<x); // graphic = graphic - current pixel at pos + new picel at pos
DRAWOFF;
}
/*
// timing used to check if the video memory is cachable.
// to use: uncomment, and uncomment the call to ltime in drawhorzline.
// if the result is around 170us, it's not chached.
// if it's around 10us, it's cached.
#include <sys/time.h>
#include <stdio.h>
long gt()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return(tv.tv_sec*1000000+tv.tv_usec);
}
static void ltime(int *p)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -