?? s3c44b0x.c
字號:
//
// $Id: s3c44b0x.c,2003,wen jian (wen_jian_1973@163.com) $
//
// s3c44b0x.c: Low Level Graphics Engine for ARM s3c44b0x
//
// This is customized graphics engine for an embedded system
// which based on samsung s3c44b0x.
//
// NOTE: you should use the new native GAL engine for the s3c44b0x systems.
//
/*
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library 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
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the Free
** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
** MA 02111-1307, USA
*/
// Modify records:
//
// Who When Where For What Status
//-----------------------------------------------------------------------------
//
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <cyg/hal/plf_io.h>
#include <cyg/infra/cyg_type.h> // base types
#include "common.h"
#include "gal.h"
#include "s3c44b0x.h"
static S3C44B0X *s3c44b0x;
static char FrameBuffer[MAX_X*MAX_Y/8*PIXELBPP] __attribute__ ((aligned(4)));
//#define FrameBuffer 0xc500000
#define MONOMODE 0
#define GRAY4MODE 1
#define GRAY16MODE 2
#define COLORMODE 3
#define _MODESEL GRAY16MODE
#define _BSWP 1
#define _CLKVAL 4
#define _LINEVAL (MAX_Y-1)
#define _HOZVAL ((MAX_X/4)-1)
#define _LCDBANK ((cyg_uint32)FrameBuffer>>22)
#define _LCDBASEU ((0x3fffff&(cyg_uint32)FrameBuffer)>>1)
#define _LCDBASEL (_LCDBASEU+((MAX_X*MAX_Y/8*(1<<_MODESEL))>>1))
#define _PAGEWIDTH ((MAX_X*(1<<_MODESEL))/16)
static void initlcd()
{
memset(FrameBuffer,0,sizeof(FrameBuffer));
*(cyg_uint32*)study_LCDCON1=(0)|(1<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(_CLKVAL<<12)|0x1e;
// disable,4B_SNGL_SCAN,WDLY=16clk,WLH=16clk,inv signal
*(cyg_uint32*)study_LCDCON2=(_LINEVAL)|(_HOZVAL<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
*(cyg_uint32*)study_LCDSADDR1= (_MODESEL<<27) | ( _LCDBANK<<21 ) | _LCDBASEU;
// monochrome, LCDBANK, LCDBASEU
*(cyg_uint32*)study_LCDSADDR2= _LCDBASEL | (0<<21) | (_BSWP<<29);
*(cyg_uint32*)study_LCDSADDR3= _PAGEWIDTH;
*(cyg_uint32*)study_DITHMODE= 0x12210;
//*(cyg_uint32*)study_REDLUT
//*(cyg_uint32*)study_GREENLUT
//*(cyg_uint32*)study_BLUELUT
*(cyg_uint32*)study_LCDCON1=(1)|(1<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(_CLKVAL<<12)|0x1e;
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
*(cyg_uint32*)study_PDATC|=0x8000; // b15=1 DISPON
}
static int getclippingrect (int sx1,int sy1,int sx2,int sy2,int *dx1,int *dy1,int *dx2,int *dy2)
{
*dx1 = ((*dx1) > sx1) ? (*dx1) : sx1;
*dy1 = ((*dy1) > sy1) ? (*dy1) : sy1;
*dx2 = ((*dx2) < sx2) ? (*dx2) : sx2;
*dy2 = ((*dy2) < sy2) ? (*dy2) : sy2;
if ( *dx1 >= *dx2 || *dy1 >= *dy2 )
{
return FALSE;
}
return TRUE;
}
// GC properties
static int bytes_per_pixel (GAL_GC gc)
{
return gc.s3c44b0x->bpp;
}
static int bits_per_pixel (GAL_GC gc)
{
return gc.s3c44b0x->depth;
}
static int width (GAL_GC gc)
{
return gc.s3c44b0x->width;
}
static int height (GAL_GC gc)
{
return gc.s3c44b0x->height;
}
static int colors (GAL_GC gc)
{
int depth = bits_per_pixel (gc);
return 1 << depth;
}
// Allocation and release of graphics context
static int allocategc (GAL_GC gc, int width, int height, int depth,
GAL_GC* newgc)
{
newgc->s3c44b0x = (S3C44B0X *)malloc(sizeof(S3C44B0X));
if ( newgc->s3c44b0x == NULL )
return -1;
newgc->s3c44b0x->bpp = gc.s3c44b0x->bpp;
newgc->s3c44b0x->bkcolor = gc.s3c44b0x->bkcolor;
newgc->s3c44b0x->fgcolor = gc.s3c44b0x->fgcolor;
newgc->s3c44b0x->x1 = gc.s3c44b0x->x1;
newgc->s3c44b0x->y1 = gc.s3c44b0x->y1;
newgc->s3c44b0x->x1 = gc.s3c44b0x->x1;
newgc->s3c44b0x->y2 = gc.s3c44b0x->y2;
newgc->s3c44b0x->shift = gc.s3c44b0x->shift;
newgc->s3c44b0x->stride = gc.s3c44b0x->stride;
newgc->s3c44b0x->fb_buf = gc.s3c44b0x->fb_buf;
newgc->s3c44b0x->width = width;
newgc->s3c44b0x->height = height;
newgc->s3c44b0x->depth = depth;
return 0;
}
// without any code
static void freegc (GAL_GC gc)
{
free(gc.s3c44b0x);
}
// Clipping of graphics context
// without any code
static void enableclipping (GAL_GC gc)
{
gc.s3c44b0x->x1 = 0;
gc.s3c44b0x->y1 = 0;
gc.s3c44b0x->x2 = gc.s3c44b0x->width-1;
gc.s3c44b0x->y2 = gc.s3c44b0x->height-1;
}
static void disableclipping (GAL_GC gc)
{
enableclipping(gc);
}
static int setclipping (GAL_GC gc, int x1, int y1, int x2, int y2)
{
// ggiSetGCClipping (gc.visual, x1, y1, x2 + 1, y2 + 1);
gc.s3c44b0x->x1 = x1;
gc.s3c44b0x->y1 = y1;
gc.s3c44b0x->x2 = x2;
gc.s3c44b0x->y2 = y2;
return 0;
}
static int getclipping (GAL_GC gc, int* x1, int* y1, int* x2, int* y2)
{
*x1 = gc.s3c44b0x->x1;
*y1 = gc.s3c44b0x->y1;
*x2 = gc.s3c44b0x->x2;
*y2 = gc.s3c44b0x->y2;
return 0;
}
// Background and foreground colors
/*static int getbgcolor (GAL_GC gc, gal_pixel* color)
{
*color = gc.s3c44b0x->bkcolor;
return 0;
}
static int setbgcolor (GAL_GC gc, gal_pixel color)
{
gc.s3c44b0x->bkcolor = color;
return 0;
}
static int getfgcolor (GAL_GC gc, gal_pixel* color)
{
*color = gc.s3c44b0x->fgcolor;
return 0;
}
static int setfgcolor (GAL_GC gc, gal_pixel color)
{
gc.s3c44b0x->fgcolor = color;
return 0;
}
*/
static gal_pixel mapcolor(GAL_GC gc, gal_color *color)
{
gal_pixel ret;
#ifdef GRAY16
return ret = (color->r*82 + color->g*124 + color->b*50) >> gc.s3c44b0x->shift;
#else
return ret = (color->r&0xe0) + ((color->g&0xe0)>>3) + ((color->b&0xc0)>>6);
#endif
}
static int unmappixel (GAL_GC gc, gal_pixel pixel, gal_color* color)
{
#ifdef GRAY16
color->r = color->g = color->b = (pixel << gc.s3c44b0x->shift) >> 8;
#else
color->r = pixel & 0xe0;
color->g =(pixel & 0x1c)<<3;
color->b =(pixel & 0x03)<<6;
#endif
return 0;
}
// Palette operations
static int getpalette (GAL_GC gc, int s, int len, gal_color* cmap)
{
int i;
for (i = 0; i < len; i++) {
#ifdef GRAY16
cmap[i].r = (((s + i)%16 + 1) << 4) - 1;
cmap[i].g = (((s + i)%16 + 1) << 4) - 1;
cmap[i].b = (((s + i)%16 + 1) << 4) - 1;
#else
cmap[i].r = ((s+i) & 0xe0);
cmap[i].g = ((s+i) & 0x1c)<<3;
cmap[i].b = ((s+i) & 0x03)<<6;
#endif
}
return 0;
}
static int setpalette (GAL_GC gc, int s, int len, gal_color* cmap)
{
return 0;
}
static int setcolorfulpalette (GAL_GC gc)
{
return 0;
}
// Box operations
static size_t boxsize (GAL_GC gc, int w, int h)
{
return w * h * bytes_per_pixel (gc);
}
static int fillbox (GAL_GC gc, int x, int y, int w, int h,
gal_pixel pixel)
{
int i,j,x1,y1,x2,y2,ret,ww,hh;
unsigned char *dest;
int shift;
shift = gc.s3c44b0x->depth;
getclipping(gc,&x1,&y1,&x2,&y2);
ww = w;
hh = h;
ww += x;
hh += y;
ret = getclippingrect(x1,y1,x2,y2,&x,&y,&ww,&hh);
if ( ret == -1 )
return -1;
ww -= x;
hh -= y;
for (i = 0; i < hh; i++)
{
#ifdef GRAY16
for (j =0; j < ww ; j++)
{
dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*(x+j)/MAX_X;
if ( (x+j) % (8/shift) == 1 )
{
*dest &= 0xff << shift;
pixel &= 0xff >> (8-shift);
*dest |= pixel;
}
else if ( (x+j) % (8/shift) == 0 )
{
*dest &= 0xff >> (8-shift);
pixel &= 0xff >> (8-shift);
*dest |= pixel << shift;
}
}
#else
j=j; // for waning
dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*x/MAX_X;
memset(dest,pixel,ww);
#endif
}
return 0;
}
static int putbox (GAL_GC gc, int x, int y, int w, int h, void* buf)
{
int i,j,k,x1,x2,y1,y2,ret,xx,yy,ww,hh;
unsigned char *dest;
int shift;
k = 0;
shift = gc.s3c44b0x->depth;
getclipping(gc,&x1,&y1,&x2,&y2);
ww = w;
hh = h;
xx = x;
yy = y;
ww += x;
hh += y;
ret = getclippingrect(x1,y1,x2,y2,&xx,&yy,&ww,&hh);
if ( ret == -1 )
return -1;
ww -= xx;
hh -= yy;
for ( i = 0; i < h; i++ )
{
#ifdef GRAY16
if ((y+i >= yy) && (y+i <= yy+hh))
{
for ( j = 0; j < w; j++ )
{
if ( (x+j>=xx)&&(x+j<=xx+ww))
{
dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*(x+j)/MAX_X;
if ( (x+j) % (8/shift) == 1 )
{
*dest &= 0xff << shift;
((unsigned char *)buf)[k] &= 0xff >> (8-shift);
*dest |= ((unsigned char *)buf)[k];
}
else if ( (x+j) % (8/shift) == 0 )
{
*dest &= 0xff >> (8-shift);
((unsigned char *)buf)[k] &= 0xff >> (8-shift);
*dest |= ((unsigned char *)buf)[k] << shift;
}
}
k++;
}
}
else
k += w;
#else
j=j; // for waning
if ( i < hh )
{
dest = gc.s3c44b0x->fb_buf + (gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*x/MAX_X;
memcpy(dest,&((unsigned char *)buf)[k],ww);
}
k+=w;
#endif
}
return 0;
}
static int getbox (GAL_GC gc, int x, int y, int w, int h, void* buf)
{
int i,j,k,x1,y1,x2,y2;
unsigned char *dest;
int shift;
k = 0;
shift = gc.s3c44b0x->depth;
getclipping(gc,&x1,&y1,&x2,&y2);
for ( i = 0; i < h; i++ )
{
#ifdef GRAY16
if ( y+i <= y2 && y+i >= y1 )
{
for ( j = 0; j < w; j++ )
{
if ( x+j <= x2 && x+j >= x1)
{
dest = gc.s3c44b0x->fb_buf+(gc.s3c44b0x->stride)*(y+i) + (gc.s3c44b0x->stride)*(x+j)/MAX_X;
if ( (x+j) % (8/shift) == 1 )
((unsigned char *)buf)[k] = (0xff >> (8-shift)) & (*dest);
else if ( (x+j) % (8/shift) == 0 )
((unsigned char *)buf)[k] = *dest >> (8-shift);
}
k++;
}
}
else
k += w;
#else
j=j; // for waning
if ( y+i <= y2 && y+i >= y1 )
{
dest = gc.s3c44b0x->fb_buf+(gc.s3c44b0x->stride)*(y+i)+(gc.s3c44b0x->stride)*x/MAX_X;
memcpy(&((unsigned char *)buf)[k],dest,min(x2-x,w));
}
k+=w;
#endif
}
return 0;
}
static int putboxmask (GAL_GC gc, int x, int y, int w, int h, void* buf)
{
return 0;
}
/****************************************************************************/
/* scalebox comes from SVGALib, Copyright 1993 Harm Hanemaayer */
typedef unsigned char uchar;
/* We use the 32-bit to 64-bit multiply and 64-bit to 32-bit divide of the */
/* 386 (which gcc doesn't know well enough) to efficiently perform integer */
/* scaling without having to worry about overflows. */
static inline int muldiv64 (int m1, int m2, int d)
{
long long int mul = (long long int) m1 * m2;
return (int) (mul / d);
}
/* This is a DDA-based algorithm. */
/* Iteration over target bitmap. */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -