diff --git a/fb2/test_arm b/fb2/test_arm new file mode 100755 index 0000000..03aea1c Binary files /dev/null and b/fb2/test_arm differ diff --git a/fb5/Makefile b/fb5/Makefile index 36f1232..aaf421d 100644 --- a/fb5/Makefile +++ b/fb5/Makefile @@ -1,4 +1,4 @@ all: - gcc page.h fbtool.h fbtool.c test.c -o test + arm-linux-gnueabihf-gcc page.h fbtool.h fbtool.c test.c -o test_fb5 clean: rm test diff --git a/fb5/test_fb5 b/fb5/test_fb5 new file mode 100755 index 0000000..ec2c8b4 Binary files /dev/null and b/fb5/test_fb5 differ diff --git a/fb6/Makefile b/fb6/Makefile index 1f041fd..99aff4a 100644 --- a/fb6/Makefile +++ b/fb6/Makefile @@ -1,4 +1,4 @@ all: - gcc page.h fbtool.h fbtool.c test.c -o test -lm + arm-linux-gnueabihf-gcc page.h fbtool.h fbtool.c test.c -o test_fb6 -lm clean: rm test diff --git a/fb6/test b/fb6/test deleted file mode 100755 index 3090945..0000000 Binary files a/fb6/test and /dev/null differ diff --git a/fb6/test.c b/fb6/test.c index c2dcc8f..57ea8c2 100644 --- a/fb6/test.c +++ b/fb6/test.c @@ -12,7 +12,7 @@ int main() return -1; } - /** + //打印frame buffer 所占内存的开始地址  pmem_start(&fbdev); //打印FB_TYPE @@ -35,7 +35,7 @@ int main() getchar(); //清屏 - clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */ + clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); POINT p; @@ -43,7 +43,7 @@ int main() p.y = 100; //画点 draw_x_y_dot(&fbdev,100,100,0x0,0xff,0x0); - /* + RGBT c; c.r = 0xff; c.g = 0xff; @@ -82,7 +82,7 @@ int main() p42.x = 120; p42.y = 160; POINT p43; - p43.x = 160; + p43.x = 16; p43.y = 160; //画矩形 draw_rec(&fbdev,p40,p42,p41,p43,0x0,0xff,0x0); @@ -100,7 +100,7 @@ int main() p53.x = 160; p53.y = 220; //填充矩形 - fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0);*/ + fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0); //draw_circle(&fbdev,500,400,100,RED); diff --git a/fb6/test_fb6 b/fb6/test_fb6 new file mode 100755 index 0000000..969839b Binary files /dev/null and b/fb6/test_fb6 differ diff --git a/fb7/Makefile b/fb7/Makefile index 1886068..a68a0ae 100644 --- a/fb7/Makefile +++ b/fb7/Makefile @@ -1,15 +1,15 @@ objects = fbtool.o point.o line.o rectangle.o circle.o test : test.c $(objects) - gcc test.c $(objects) -o test -lm + arm-linux-gnueabihf-gcc test.c $(objects) -o test_fb7 -lm fbtool.o : page.h color.h fbtool.h fbtool.c - gcc -c page.h color.h fbtool.h fbtool.c + arm-linux-gnueabihf-gcc -c page.h color.h fbtool.h fbtool.c point.o : fbtool.h point.h point.c - gcc -c fbtool.h point.h point.c + arm-linux-gnueabihf-gcc -c fbtool.h point.h point.c line.o : fbtool.h point.h line.h line.c - gcc -c fbtool.h point.h line.h line.c + arm-linux-gnueabihf-gcc -c fbtool.h point.h line.h line.c rectangle.o : fbtool.h point.h line.h rectangle.h rectangle.c - gcc -c fbtool.h point.h line.h rectangle.h rectangle.c + arm-linux-gnueabihf-gcc -c fbtool.h point.h line.h rectangle.h rectangle.c circle.o : fbtool.h point.h circle.h circle.c - gcc -c fbtool.h point.h circle.h circle.c -lm + arm-linux-gnueabihf-gcc -c fbtool.h point.h circle.h circle.c -lm clean: - rm *.o *.gch test + \rm *.o *.gch test test_fb7 diff --git a/fb7/test.c b/fb7/test.c index 022e8df..fbd2b6a 100644 --- a/fb7/test.c +++ b/fb7/test.c @@ -15,7 +15,7 @@ int main() return -1; } - /** + //打印frame buffer 所占内存的开始地址  pmem_start(&fbdev); //打印FB_TYPE-c kbd.c @@ -38,14 +38,14 @@ int main() getchar(); //清屏 - clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,-1,fbdev.fb_fix.smem_len); */ + clear_con((void *)(fbdev.fb_mem + fbdev.fb_mem_offset),-1,fbdev.fb_fix.smem_len); POINT p; p.x = 100; p.y = 100; - /* + //画点 draw_x_y_dot(&fbdev,100,100,0x0,0xff,0x0); @@ -105,8 +105,8 @@ int main() p53.x = 160; p53.y = 220; //填充 - fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0);*/ - + fill_rec(&fbdev,p50,p52,p51,p53,0x0,0xff,0x0); +/* int x = 500; while(1){ draw_circle(&fbdev,x,400,100,RED); @@ -117,10 +117,10 @@ int main() if(x == 1200) break; - clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,1,fbdev.fb_fix.smem_len); + clear_con((void *)(fbdev.fb_mem + fbdev.fb_mem_offset),1,fbdev.fb_fix.smem_len); } - +*/ fb_close(&fbdev); return 0; diff --git a/fb7/test_fb7 b/fb7/test_fb7 new file mode 100755 index 0000000..32a0223 Binary files /dev/null and b/fb7/test_fb7 differ diff --git a/svgalib/Makefile b/svgalib/Makefile new file mode 100644 index 0000000..406426e --- /dev/null +++ b/svgalib/Makefile @@ -0,0 +1,25 @@ +srcdir = $(shell sh -c pwd) +prefix = /export/imx6/rootfs/rootfs-mx6g2c-new-nand/usr/local/test + +CC = arm-linux-gnueabihf-gcc + +objects = fbtool.o point.o line.o rectangle.o circle.o +frist:clean test +test : test.c $(objects) + $(CC) test.c $(objects) -o test_fb7 -lm +fbtool.o : page.h color.h fbtool.h fbtool.c + $(CC) -c page.h color.h fbtool.h fbtool.c +point.o : fbtool.h point.h point.c + $(CC) -c fbtool.h point.h point.c +line.o : fbtool.h point.h line.h line.c + $(CC) -c fbtool.h point.h line.h line.c +rectangle.o : fbtool.h point.h line.h rectangle.h rectangle.c + $(CC) -c fbtool.h point.h line.h rectangle.h rectangle.c +circle.o : fbtool.h point.h circle.h circle.c + $(CC) -c fbtool.h point.h circle.h circle.c -lm +.PHONY:clean install all +clean: + @rm -fv *.o *.gch test_fb7 +install: clean test + @cp -vf $(srcdir)/test_fb7 $(prefix) + @chmod 777 $(prefix)/test_fb7 \ No newline at end of file diff --git a/svgalib/README.md b/svgalib/README.md new file mode 100644 index 0000000..0c4b48a --- /dev/null +++ b/svgalib/README.md @@ -0,0 +1,84 @@ +**(一):写在前面** + +这一次没有进行功能上的改进,主要是为了后来修改方便,而将画点,画线,画长方形,画圆等的提取出来,对Makefile进行了修改,方便于后期的维护.同时,为了后面实现我的思路,我进行了一个测试,就是实现一个运动的圆的效果.圆是可以运动了,但是效果不是特别好.后面再了解一下图形化界面是怎么实现的.我再试一下别的思路. + + +**(二):功能介绍** + +*1:Makefile文件的修改* + +``` +objects = fbtool.o point.o line.o rectangle.o circle.o +test : test.c $(objects) + gcc test.c $(objects) -o test -lm +fbtool.o : page.h color.h fbtool.h fbtool.c + gcc -c page.h color.h fbtool.h fbtool.c +point.o : fbtool.h point.h point.c + gcc -c fbtool.h point.h point.c +line.o : fbtool.h point.h line.h line.c + gcc -c fbtool.h point.h line.h line.c +rectangle.o : fbtool.h point.h line.h rectangle.h rectangle.c + gcc -c fbtool.h point.h line.h rectangle.h rectangle.c +circle.o : fbtool.h point.h circle.h circle.c + gcc -c fbtool.h point.h circle.h circle.c -lm +clean: + rm *.o *.gch test +``` + +*2:测试实现圆的运动* + +``` +int x = 500; +while(1){ + draw_circle(&fbdev,x,400,100,RED); + usleep(100); + + x++; + + if(x == 1200) + break; + + clear_con(fbdev.fb_mem + fbdev.fb_mem_offset,1,fbdev.fb_fix.smem_len); + +} +``` + +这次测试暂时是这样实现的,不过界面的刷新和图形的运动是在同时发生的,也就是说是同一个频率的.这样是不行的.就会出现闪频的问题.后面我将修改这个,初步思路是将界面刷新放到一个单独的线程当中,或者是根据时钟来刷新,这个后面再说吧. + +**(三):后期规划** + +后面的话主要的想法就是先实现图形的刷新,让图形能够移动或者是使图形能够一直存在.完成这个之后,就是纯图形库的编写工作了. + + +**(四):写在后面** + +众里寻他千百度,蓦然回首,那人却在灯火阑珊处. + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svgalib/circle.c b/svgalib/circle.c new file mode 100644 index 0000000..53dc0f0 --- /dev/null +++ b/svgalib/circle.c @@ -0,0 +1,17 @@ +#include "circle.h" + +//画圆 +void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color) +{ + double i; + + int tmp; + + for(i = x - radius; i < x + radius;i+=0.01){ + tmp = sqrt(radius * radius - (i - x) * (i - x)); + + draw_x_y_color_dot_with_string(pFbdev,i,(tmp + y),color); + draw_x_y_color_dot_with_string(pFbdev,i,(-tmp + y),color); + } +} + diff --git a/svgalib/circle.h b/svgalib/circle.h new file mode 100644 index 0000000..febfdea --- /dev/null +++ b/svgalib/circle.h @@ -0,0 +1,24 @@ +/* + * 画圆或者是填充圆的实现 + * @作者 陈洪波 + */ + +#ifndef _CIRCLE_H_ +#define _CIRCLE_H_ + +#include "fbtool.h" +#include "point.h" +#include + +/* + * 画一个圆 + * @param pFbdev 参考结构体 fbdev + * @param x 圆的圆心所在的点的x值 + * @param y 圆的圆心所在的点的y值 + * @param radius 圆的半径的长度 + * @color 代表颜色的字符串 + * @return void + */ +void draw_circle(PFBDEV pFbdev,int x,int y,int radius,const char *color); + +#endif //_CIRCLE_H_ diff --git a/svgalib/color.h b/svgalib/color.h new file mode 100644 index 0000000..4ce0c86 --- /dev/null +++ b/svgalib/color.h @@ -0,0 +1,61 @@ +#ifndef _COLOR_H_ +#define _COLOR_H_ + + +#include +/** + * 代表颜色的结构体 + * @property r 颜色对应的R值 + * @property g 颜色对应的G值 + * @property b 颜色对应的B值 + * @property t 颜色对应的T值 + */ +typedef struct rgbt{ + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t t; +}RGBT; + +//定义一些常用的颜色属性 + +#define COLOR16(r, g, b) (((r)&0x1F) << 11 | ((g)&0x1F) << 6 | ((b)&0x3F)) + +#define BLACK COLOR16(0, 0, 0) // 0 BLACK (masked write) +#define BLUE COLOR16(0, 0, 15) // 1 BLUE +#define GREEN COLOR16(0, 15, 0) // 2 GREEN +#define CYAN COLOR16(0, 15, 15) // 3 CYAN +#define RED COLOR16(15, 0, 0) // 4 RED +#define MAGENTA COLOR16(15, 0, 15) // 5 MAGENTA +#define BROWN COLOR16(15, 15, 0) // 6 BROWN +#define LT_GRAY COLOR16(24, 24, 24) // 7 LT_GRAY wallpaper +#define DT_GRAY COLOR16(12, 12, 12) // 8 DT_GRAY +#define LT_BLUE COLOR16(0, 0, 31) // 9 LT_BLUE set_text +#define LT_GREEN COLOR16(0, 31, 0) // 10 LT_GREEN +#define LT_CYAN COLOR16(0, 31, 31) // 11 LT_CYAN +#define LT_RED COLOR16(31, 0, 0) // 12 LT_RED +#define LT_MAGENTA COLOR16(31, 0, 31) // 13 LT_MAGENTA +#define YELLOW COLOR16(31, 31, 0) +// 14 YELLOW err_message/act_text/err_win/icon/(clk_sec_hd) +#define WHITE COLOR16(31, 31, 31) // 15 WHITE +//#define COLOR16(1, 1, 1) // 16 BLACK (cheat putboxmask +// routine) +//#define COLOR16(4, 12, 12) // 17 frame +//#define COLOR16(12, 22, 26) // 18 sel_window / pointer / +//(clk_bg) +//#define COLOR16(21, 24, 22) // 19 key/page/dummy/graphic/gray_text +//#define COLOR16(9, 10, 10) // 20 key_fg / graphic_sh / pointer_sh +//#define COLOR16(0, 8, 0) // 21 curve1_color / breakdown 4th +// color +//#define COLOR16(18, 8, 12) // 22 curve2_color / breakdown +//5th +// color +//#define COLOR16(31, 5, 27) // 23 curve3_color +//#define COLOR16(22, 6, 6) // 24 err_win_icon/breakdown 1st color +//#define COLOR16(31, 22, 22) // 25 rev_set_text_bg / hp_window +//#define COLOR16(31, 13, 17) // 26 curve4_color / (well_text) / +//(well_logo) +//#define COLOR16(7, 14, 20) // 27 win_sh +//#define COLOR16(31, 15, 3) // 28 Amber (Yellow + Orange) + +#endif //_COLOR_H_ diff --git a/svgalib/fbtool.c b/svgalib/fbtool.c new file mode 100644 index 0000000..f857f30 --- /dev/null +++ b/svgalib/fbtool.c @@ -0,0 +1,206 @@ +#include "fbtool.h" +#include +#include +#include +#include +#include +#include +#include +#include + +FBDEV currFbdev; + +//打开并且初始化该frame buffer +int fb_open(char * sFbdev) +{ + memset(&currFbdev, 0, sizeof(FBDEV)); + strcpy(currFbdev.dev, sFbdev); + + //打开frame buffer + currFbdev.fb = open(currFbdev.dev, O_RDWR); + + if (currFbdev.fb < 0) { + printf("打开错误 %s.请检查内核配置\n", currFbdev.dev); + return 0; + } + + // 初始化fb_var + if(-1 == ioctl(currFbdev.fb,FBIOGET_VSCREENINFO,&(currFbdev.fb_var))) + { + printf("ioctl FBIOGET_VSCREENINFO\n"); + return 0; + } + + // 初始化fb_fix + if(-1 == ioctl(currFbdev.fb,FBIOGET_FSCREENINFO,&(currFbdev.fb_fix))) + { + printf("ioctl FBIOGET_FSCREENINFO\n"); + return 0; + } + + //将物理地址映射到虚拟地址 + currFbdev.fb_mem_offset = (unsigned long)currFbdev.fb_fix.smem_start & (~PAGE_MASK); + + currFbdev.fb_mem = (unsigned long int)mmap(NULL,currFbdev.fb_fix.smem_len + currFbdev.fb_mem_offset,PROT_READ|PROT_WRITE,MAP_SHARED,currFbdev.fb,0); + + if(-1L == (long)currFbdev.fb_mem){ + printf("mmap error with mem:%lu,mem_offset:%lu\n",currFbdev.fb_mem_offset,currFbdev.fb_mem); + return 0; + } + + return 1; +} + +//关闭frame buffer +int fb_close(PFBDEV pFbdev) +{ + int r = close(currFbdev.fb); + currFbdev.fb = -1; + + return r; +} + +//打印frame buffer 所占内存的开始地址  +void pmem_start(PFBDEV pFbdev) +{ + printf("frame buffer所占内存的开始地址为:%lu\n",currFbdev.fb_fix.smem_start); +} + +//打印FB_TYPE +void p_type(PFBDEV pFbdev) +{ + printf("frame buffer 的类型为:%d\n",currFbdev.fb_fix.type); +} + +//打印可见清晰度 +void p_visible_res(PFBDEV pFbdev) +{ + printf("frame buffer的可见清晰度为:\n\tx = %d\n\ty = %d\n",currFbdev.fb_var.xres,currFbdev.fb_var.yres); +} + +//打印虚拟分辨率 +void p_virt_res(PFBDEV pFbdev) +{ + printf("frame buffer的虚拟清晰度为:\n\tx = %d\n\ty = %d\n",currFbdev.fb_var.xres_virtual,currFbdev.fb_var.yres_virtual); +} + +//打印虚拟到可见的偏移量 +void p_offset(PFBDEV pFbdev) +{ + printf("frame buffer的虚拟分辨率到可见分辨率的偏移量为:\n\tx = %d\n\ty = %d\n",currFbdev.fb_var.xoffset,currFbdev.fb_var.yoffset); +} + +//打印每个像素的位数 +void p_bpp(PFBDEV pFbdev) +{ + printf("frame buffer的BPP为:%d\n",currFbdev.fb_var.bits_per_pixel); +} + +//打印R,G,B和透明度 +void p_rgbt(PFBDEV pFbdev) +{ + //R位域 + printf("R位域:\n"); + struct fb_bitfield bf = currFbdev.fb_var.red; + printf("\t开始:%d\n",bf.offset); + printf("\t长度:%d\n",bf.length); + printf("\tMSB:%d\n",bf.msb_right); + + //G位域 + printf("G位域:\n"); + bf = currFbdev.fb_var.green; + printf("\t开始:%d\n",bf.offset); + printf("\t长度:%d\n",bf.length); + printf("\tMSB:%d\n",bf.msb_right); + + // B位域 + printf("B位域:\n"); + bf = currFbdev.fb_var.blue; + printf("\t开始:%d\n",bf.offset); + printf("\t长度:%d\n",bf.length); + printf("\tMSB:%d\n",bf.msb_right); + + // 透明度位域 + printf("透明度位域:\n"); + bf = currFbdev.fb_var.transp; + printf("\t开始:%d\n",bf.offset); + printf("\t长度:%d\n",bf.length); + printf("\tMSB:%d\n",bf.msb_right); +} + +//打印在内存中的高度和宽度 +void p_hw(PFBDEV pFbdev) +{ + printf("frame buffer在内存中所占的高度和宽度分别是:\n\t宽度 = %d\n\t高度 = %d\n",currFbdev.fb_var.height,currFbdev.fb_var.width); +} + +//清空控制台  +void clear_con(void *addr,int n,size_t len) +{ + memset(addr,n,len); +} + +//映射到内存 +void inline fb_memcpy(void *addr,void *color,size_t len) +{ + memcpy(addr,color,len); +} + +RGBT getRGBT(const char *temp){ + RGBT rgbt; + + char *c_tmp; + c_tmp = (char *)malloc(4 * sizeof(int)); + + c_tmp[0] = '0'; + c_tmp[1] = 'x'; + int r,g,b,t; + + //RGBT值的计算 + c_tmp[2] = temp[0]; + c_tmp[3] = temp[1]; + + r = strtol(c_tmp,NULL,16); + + c_tmp[2] = temp[2]; + c_tmp[3] = temp[3]; + + g = strtol(c_tmp,NULL,16); + + c_tmp[2] = temp[4]; + c_tmp[3] = temp[5]; + + b = strtol(c_tmp,NULL,16); + + c_tmp[2] = temp[6]; + c_tmp[3] = temp[7]; + + t = strtol(c_tmp,NULL,16); + + rgbt.r = r; + rgbt.g = g; + rgbt.b = b; + rgbt.t = t; + + return rgbt; +} + + + + + + + + + + + + + + + + + + + + diff --git a/svgalib/fbtool.h b/svgalib/fbtool.h new file mode 100644 index 0000000..381dbfe --- /dev/null +++ b/svgalib/fbtool.h @@ -0,0 +1,154 @@ +#ifndef __FBTOOL_H_ +#define __FBTOOL_H_ + +#include +#include "page.h" +#include "color.h" + +/** + * 该结构体主要是定义了一组保存frame buffer的属性 + * @property fb frame buffer打开后的唯一标识符 + * @property fb_fix frame buffer的固定属性就保存在这个结构体中 + * @property fb_var frame buffer的可变属性保存在这个结构体中 + * @property fb_mem_offset frame buffer所占内存的偏移量 + * @property fb_mem frame buffer的映射到进程内存空间的起始地址 + */ +typedef struct fbdev{ + int fb; + struct fb_fix_screeninfo fb_fix; + struct fb_var_screeninfo fb_var; + /* 新增 */ + unsigned long fb_mem_offset; + unsigned long fb_mem; + + char dev[20]; +} FBDEV, *PFBDEV; + +extern FBDEV currFbdev; + +/** + * 该结构体用于定位点的位置,包括横坐标,纵坐标,深坐标 + * @property x 横坐标 + * @property y 纵坐标 + * @property z 深坐标(这个用于3D) + */ +typedef struct point{ + int x; + int y; + int z; +}POINT,*PPOINT; + +/* + * 该函数用于打开frame buffer + * @param sFbdev 设备名,如"/dev/fb0" + * @return 0 - 打开失败 + * 1 - 打开成功 + */ +int fb_open(char *sFbdev); + +/* + * 该函数用于关闭frame buffer设备 + * @param pFbdev 参照结构体 fbdev + * @return 0 - 关闭成功 + * >0 - 关闭失败 + */ +int fb_close(PFBDEV pFbdev); + +/* + * 该函数用于打印frame buffer 所占内存的开始地址  + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void pmem_start(PFBDEV pFbdev); + +/* + * 该函数用于打印FB_TYPE + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_type(PFBDEV pFbdev); + +/* + * 该函数用于打印可见清晰度 + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_visible_res(PFBDEV pFbdev); + +/* + * 该函数用于打印虚拟分辨率 + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_virt_res(PFBDEV pFbdev); + +/* + * 该函数用于打印虚拟到可见的偏移量 + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_offset(PFBDEV pFbdev); + +/* + * 该函数用于打印每个像素的位数 + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_bpp(PFBDEV pFbdev); + +/* + * 该函数用于打印R,G,B和透明度 + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_rgbt(PFBDEV pFbdev); + +/* + * 该函数用于打印在内存中的高度和宽度 + * @param pFbdev 参照结构体 fbdev + * @return void + */ +void p_hw(PFBDEV pFbdev); + +/* + * 将addr开始的len个字符用n替换 + * @param addr 开始的地址 + * @param n 替换后的字符 + * @param len 要替换的字符的个数 + * @return void + */ +void clear_con(void *addr,int n,size_t len); + +/* + * 该函数将逻辑地址空间的数据映射到内存当中 + * @param addr 内存空间的地址 + * @param color 颜色值 + * @param len 需要映射的长度 + * @return void + */ +void inline fb_memcpy(void *addr,void *color,size_t len); + + + +/* + * 根据字符串获得相应的RGBT + * @param color 颜色对应的字符串 + * @return 返回代表颜色的结构体 RGBT + */ +RGBT getRGBT(const char *color); + + + +#endif + + + + + + + + + + + + diff --git a/svgalib/glline.c b/svgalib/glline.c new file mode 100644 index 0000000..93cf5e6 --- /dev/null +++ b/svgalib/glline.c @@ -0,0 +1,633 @@ +/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */ +/* line.c Line drawing */ +#define DO_NOT_USE_VGALIB + +#include + +#ifndef DO_NOT_USE_VGALIB +#include +#endif + +#include "inlstring.h" /* include inline string operations */ + +#include "vgagl.h" +#include "def.h" +#include "driver.h" + + +#ifdef __alpha__ + +static inline int muldiv64(int m1, int m2, int d) +{ + return (long) m1 *(long) m2 / (long) d; +} + +#else + +#ifdef NO_ASSEMBLY + +static inline int muldiv64(int m1, int m2, int d) +{ + return (float) m1 * (float) m2 / ((float) d); +} + +#else + +/* 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) +{ +/* int32 * int32 -> int64 / int32 -> int32 */ + int result; + int dummy; + __asm__( + "imull %%edx\n\t" + "idivl %4\n\t" + : "=a"(result), "=d"(dummy) /* out */ + : "0"(m1), "1"(m2), "g"(d) /* in */ + /***rjr***: "ax", "dx" ***/ /* mod */ + ); + return result; +} + +#endif /* !NO_ASSEMBLY */ +#endif /* !__alpha__ */ + +#ifdef __alpha__ + +static inline int gl_regioncode(int x, int y) +{ + int result = 0; + if (x < __clipx1) + result |= 1; + else if (x > __clipx2) + result |= 2; + if (y < __clipy1) + result |= 4; + else if (y > __clipy2) + result |= 8; + return result; +} + +#else +#ifdef NO_ASSEMBLY + +static inline int gl_regioncode (int x, int y) +{ + int result = 0; + if (x < __clipx1) + result |= 1; + else if (x > __clipx2) + result |= 2; + if (y < __clipy1) + result |= 4; + else if (y > __clipy2) + result |= 8; + return result; +} + +#else + +#define INC_IF_NEG(y, result) \ +{ \ + __asm__("btl $31,%1\n\t" \ + "adcl $0,%0" \ + : "=r" ((int) result) \ + : "rm" ((int) (y)), "0" ((int) result) \ + ); \ +} + +static inline int gl_regioncode (int x, int y) +{ + int dx1, dx2, dy1, dy2; + int result; + result = 0; + dy2 = __clipy2 - y; + INC_IF_NEG (dy2, result); + result <<= 1; + dy1 = y - __clipy1; + INC_IF_NEG (dy1, result); + result <<= 1; + dx2 = __clipx2 - x; + INC_IF_NEG (dx2, result); + result <<= 1; + dx1 = x - __clipx1; + INC_IF_NEG (dx1, result); + return result; +} + +#endif /* ! NO_ASSEMBLY */ +#endif /* !__alpha__ */ + + +#define line_start_paged(s) \ + fp = y * bytesperrow + x * s; \ + vga_setpage (fpp = (fp >> 16)); \ + fp &= 0xFFFF; + +#define line_start_linear(s) \ + vp = VBUF + y * bytesperrow + x * s; + + +#define line_loop_paged_a(m,i,u,v) \ + { \ + int d = ay - (ax >> 1); \ + if ((x = abs (dx))) \ + do { \ + i; \ + if (d m 0) { \ + fp v; \ + d -= ax; \ + } \ + fp u; \ + d += ay; \ + if (fp & 0xFFFF0000) { /* has it cross a page boundary ? */ \ + fpp += fp >> 16; \ + vga_setpage (fpp); \ + } \ + fp &= 0x0000FFFF; \ + } while (--x); \ + } + +#define line_loop_linear_a(m,i,u,v) \ + { \ + int d = ay - (ax >> 1); \ + if ((x = abs (dx))) \ + do { \ + i; \ + if (d m 0) { \ + vp v; \ + d -= ax; \ + } \ + vp u; \ + d += ay; \ + } while (--x); \ + } + + +#define line_loop_paged_b(m,i,u,v) \ + { \ + int d = ax - (ay >> 1); \ + if ((y = abs (dy))) \ + do { \ + i; \ + if (d m 0) { \ + fp u; \ + d -= ay; \ + } \ + fp v; \ + d += ax; \ + if (fp & 0xFFFF0000) { \ + fpp += fp >> 16; \ + vga_setpage (fpp); \ + } \ + fp &= 0x0000FFFF; \ + } while (--y); \ + } + + +#define line_loop_linear_b(m,i,u,v) \ + { \ + int d = ax - (ay >> 1); \ + if ((y = abs (dy))) \ + do { \ + i; \ + if (d m 0) { \ + vp u; \ + d -= ay; \ + } \ + vp v; \ + d += ax; \ + } while (--y); \ + } + + + +/* Partly based on the work which was partly based on vgalib by Tommy Frandsen */ +/* This is a lot faster now that setpixel is inlined */ + +void gl_line (int x1, int y1, int x2, int y2, int c) +{ + int dx, dy, ax, ay, sx, sy, x, y; + int bytesperrow; + unsigned char *vp = NULL; + + if (__clip) + /* Cohen & Sutherland algorithm */ + for (;;) { + int r1 = gl_regioncode (x1, y1); + int r2 = gl_regioncode (x2, y2); + if (!(r1 | r2)) + break; /* completely inside */ + if (r1 & r2) + return; /* completely outside */ + if (r1 == 0) { + swap (x1, x2); /* make sure first */ + swap (y1, y2); /* point is outside */ + r1 = r2; + } + if (r1 & 1) { /* left */ + y1 += muldiv64 (__clipx1 - x1, y2 - y1, x2 - x1); + x1 = __clipx1; + } else if (r1 & 2) { /* right */ + y1 += muldiv64 (__clipx2 - x1, y2 - y1, x2 - x1); + x1 = __clipx2; + } else if (r1 & 4) { /* top */ + x1 += muldiv64 (__clipy1 - y1, x2 - x1, y2 - y1); + y1 = __clipy1; + } else if (r1 & 8) { /* bottom */ + x1 += muldiv64 (__clipy2 - y1, x2 - x1, y2 - y1); + y1 = __clipy2; + } + } + dx = x2 - x1; + dy = y2 - y1; + ax = abs (dx) << 1; + ay = abs (dy) << 1; + sx = (dx >= 0) ? 1 : -1; + sy = (dy >= 0) ? 1 : -1; + x = x1; + y = y1; + +#ifdef __alpha__ + if (ax > ay) { + int d = ay - (ax >> 1); + while (x != x2) { + setpixel (x, y, c); + + if (d > 0 || (d == 0 && sx == 1)) { + y += sy; + d -= ax; + } + x += sx; + d += ay; + } + } else { + int d = ax - (ay >> 1); + while (y != y2) { + setpixel (x, y, c); + + if (d > 0 || (d == 0 && sy == 1)) { + x += sx; + d -= ay; + } + y += sy; + d += ax; + } + } + + setpixel (x, y, c); + +#else + +#define insert_pixel_1 *((unsigned char *) vp) = c; +#define insert_pixel_2 *((unsigned short *) vp) = c; + +#define insert_pixel_3 *((unsigned char *) vp) = c; \ + *((unsigned char *) (vp + 1)) = (c>>8); \ + *((unsigned char *) (vp + 2)) = (c>>16); + +#define insert_pixel_4 *((unsigned long *) vp) = c; + + bytesperrow = BYTEWIDTH; + + if (MODETYPE == CONTEXT_VIRTUAL || MODETYPE == CONTEXT_LINEAR) { + switch BYTESPERPIXEL { + case 1: + line_start_linear(1); + if (ax > ay) { + if(sx > 0) { + line_loop_linear_a(>=,insert_pixel_1,++,+=bytesperrow*sy); + } else { + line_loop_linear_a(>,insert_pixel_1,--,+=bytesperrow*sy); + } + } else { + if(sy > 0) { + line_loop_linear_b(>=,insert_pixel_1,+=sx,+=bytesperrow); + } else { + line_loop_linear_b(>,insert_pixel_1,+=sx,-=bytesperrow); + } + } + insert_pixel_1; + break; + case 2: + line_start_linear(2); + if (ax > ay) { + if(sx > 0) { + line_loop_linear_a(>=,insert_pixel_2,+=2,+=bytesperrow*sy); + } else { + line_loop_linear_a(>,insert_pixel_2,-=2,+=bytesperrow*sy); + } + } else { + sx <<= 1; + if(sy > 0) { + line_loop_linear_b(>=,insert_pixel_2,+=sx,+=bytesperrow); + } else { + line_loop_linear_b(>,insert_pixel_2,+=sx,-=bytesperrow); + } + } + insert_pixel_2; + break; + case 3: + line_start_linear(3); + if (ax > ay) { + if(sx > 0) { + line_loop_linear_a(>=,insert_pixel_3,+=3,+=bytesperrow*sy); + } else { + line_loop_linear_a(>,insert_pixel_3,-=3,+=bytesperrow*sy); + } + } else { + sx *= 3; + if(sy > 0) { + line_loop_linear_b(>=,insert_pixel_3,+=sx,+=bytesperrow); + } else { + line_loop_linear_b(>,insert_pixel_3,+=sx,-=bytesperrow); + } + } + insert_pixel_3; + break; + case 4: + line_start_linear(4); + if (ax > ay) { + if(sx > 0) { + line_loop_linear_a(>=,insert_pixel_4,+=4,+=bytesperrow*sy); + } else { + line_loop_linear_a(>,insert_pixel_4,-=4,+=bytesperrow*sy); + } + } else { + sx <<= 2; + if(sy > 0) { + line_loop_linear_b(>=,insert_pixel_4,+=sx,+=bytesperrow); + } else { + line_loop_linear_b(>,insert_pixel_4,+=sx,-=bytesperrow); + } + } + insert_pixel_4; + break; + } + } + + + + +#ifndef DO_NOT_USE_VGALIB + +#undef insert_pixel_1 +#undef insert_pixel_2 +#undef insert_pixel_3 +#undef insert_pixel_4 + +#define insert_pixel_1 *((unsigned char *) (vp + fp)) = c; +#define insert_pixel_2 *((unsigned short *) (vp + fp)) = c; + +#define insert_pixel_3 *((unsigned char *) (vp + fp)) = c; \ + *((unsigned char *) (vp + fp + 1)) = (c>>8); \ + *((unsigned char *) (vp + fp + 2)) = (c>>16); + +#define insert_pixel_4 *((unsigned long *) (vp + fp)) = c; + + + if (MODETYPE == CONTEXT_PAGED) { + vp = VBUF; + switch BYTESPERPIXEL { + int fpp; + int fp; + case 1: + line_start_paged(1); + if (ax > ay) { + if(sx > 0) { + line_loop_paged_a(>=,insert_pixel_1,++,+=bytesperrow*sy); + } else { + line_loop_paged_a(>,insert_pixel_1,--,+=bytesperrow*sy); + } + } else { + if(sy > 0) { + line_loop_paged_b(>=,insert_pixel_1,+=sx,+=bytesperrow); + } else { + line_loop_paged_b(>,insert_pixel_1,+=sx,-=bytesperrow); + } + } + insert_pixel_1; + break; + case 2: + line_start_paged(2); + if (ax > ay) { + if(sx > 0) { + line_loop_paged_a(>=,insert_pixel_2,+=2,+=bytesperrow*sy); + } else { + line_loop_paged_a(>,insert_pixel_2,-=2,+=bytesperrow*sy); + } + } else { + sx <<= 1; + if(sy > 0) { + line_loop_paged_b(>=,insert_pixel_2,+=sx,+=bytesperrow); + } else { + line_loop_paged_b(>,insert_pixel_2,+=sx,-=bytesperrow); + } + } + insert_pixel_2; + break; + case 3: + line_start_paged(3); + if (ax > ay) { + if(sx > 0) { + line_loop_paged_a(>=,insert_pixel_3,+=3,+=bytesperrow*sy); + } else { + line_loop_paged_a(>,insert_pixel_3,-=3,+=bytesperrow*sy); + } + } else { + sx *= 3; + if(sy > 0) { + line_loop_paged_b(>=,insert_pixel_3,+=sx,+=bytesperrow); + } else { + line_loop_paged_b(>,insert_pixel_3,+=sx,-=bytesperrow); + } + } + insert_pixel_3; + break; + case 4: + line_start_paged(4); + if (ax > ay) { + if(sx > 0) { + line_loop_paged_a(>=,insert_pixel_4,+=4,+=bytesperrow*sy); + } else { + line_loop_paged_a(>,insert_pixel_4,-=4,+=bytesperrow*sy); + } + } else { + sx <<= 2; + if(sy > 0) { + line_loop_paged_b(>=,insert_pixel_4,+=sx,+=bytesperrow); + } else { + line_loop_paged_b(>,insert_pixel_4,+=sx,-=bytesperrow); + } + } + insert_pixel_4; + break; + } + } + +#endif + + if (!vp) { + + if (ax > ay) { + int d = ay - (ax >> 1); + while (x != x2) { + setpixel (x, y, c); + + if (d > 0 || (d == 0 && sx == 1)) { + y += sy; + d -= ax; + } + x += sx; + d += ay; + } + } else { + int d = ax - (ay >> 1); + while (y != y2) { + setpixel (x, y, c); + + if (d > 0 || (d == 0 && sy == 1)) { + x += sx; + d -= ay; + } + y += sy; + d += ax; + } + } + setpixel (x, y, c); + } +#endif +} + + +static void gl_setcirclepixels(int x, int y, int sx, int sy, int c) +{ + if (__clip) { + int z = max(x, y); + if (sx - z < __clipx1 || sx + z > __clipx2 + || sy - z < __clipy1 || sy + z > __clipy2) { + /* use setpixel clipping */ + gl_setpixel(sx + x, sy + y, c); + gl_setpixel(sx - x, sy + y, c); + gl_setpixel(sx + x, sy - y, c); + gl_setpixel(sx - x, sy - y, c); + gl_setpixel(sx + y, sy + x, c); + gl_setpixel(sx - y, sy + x, c); + gl_setpixel(sx + y, sy - x, c); + gl_setpixel(sx - y, sy - x, c); + return; + } + } + setpixel(sx + x, sy + y, c); + setpixel(sx - x, sy + y, c); + setpixel(sx + x, sy - y, c); + setpixel(sx - x, sy - y, c); + setpixel(sx + y, sy + x, c); + setpixel(sx - y, sy + x, c); + setpixel(sx + y, sy - x, c); + setpixel(sx - y, sy - x, c); +} + +void gl_circle(int sx, int sy, int r, int c) +{ + int x, y, d; + if (r < 1) { + gl_setpixel(sx, sy, c); + return; + } + if (__clip) + if (sx + r < __clipx1 || sx - r > __clipx2 + || sy + r < __clipy1 || sy - r > __clipy2) + return; + x = 0; + y = r; + d = 1 - r; + gl_setcirclepixels(x, y, sx, sy, c); + while (x < y) { + if (d < 0) + d += x * 2 + 3; + else { + d += x * 2 - y * 2 + 5; + y--; + } + x++; + gl_setcirclepixels(x, y, sx, sy, c); + } +} + +void gl_fillcircle(int sx, int sy, int r, int c) +{ + int x = 0, + y = r, + d = 1 - r; + + if (r < 1) { + gl_setpixel(sx, sy, c); + return; + } + if (__clip) + if (sx + r < __clipx1 || sx - r > __clipx2 + || sy + r < __clipy1 || sy - r > __clipy2) + return; + gl_hline(sx - x, sy + y, sx + x, c); + gl_hline(sx - x, sy - y, sx + x, c); + gl_hline(sx - y, sy + x, sx + y, c); + gl_hline(sx - y, sy - x, sx + y, c); + while (x < y) + { + if (d < 0) + { + d += x * 2 + 3; + } else { + d += x * 2 - y * 2 + 5; + y--; + } + x++; + gl_hline(sx - x, sy + y, sx + x, c); + gl_hline(sx - x, sy - y, sx + x, c); + gl_hline(sx - y, sy + x, sx + y, c); + gl_hline(sx - y, sy - x, sx + y, c); + } +} + +void gl_bcircle(int sx, int sy, int r, int c, int fill) +{ + int x = 0, + y = r, + d = 2 * (1 - r); + + if (r < 1) { + gl_setpixel(sx, sy, c); + return; + } + if (__clip) + if (sx + r < __clipx1 || sx - r > __clipx2 + || sy + r < __clipy1 || sy - r > __clipy2) + return; + while (y >= 0) + { + if (fill == 0) + { + gl_setpixel(sx + x, sy + y, c); + gl_setpixel(sx + x, sy - y, c); + gl_setpixel(sx - x, sy + y, c); + gl_setpixel(sx - x, sy - y, c); + } else { + gl_hline(sx - x, sy + y, sx + x, c); + gl_hline(sx - x, sy - y, sx + x, c); + } + if ((d + y) > 0) + { + y--; + d -= (2 * y * WIDTH / HEIGHT) - 1; + } + if (x > d) + { + x++; + d += (2 * x) + 1; + } + } +} diff --git a/svgalib/grlib.c b/svgalib/grlib.c new file mode 100644 index 0000000..be1fbe5 --- /dev/null +++ b/svgalib/grlib.c @@ -0,0 +1,667 @@ +/* Framebuffer Graphics Libary for Linux, Copyright 1993 Harm Hanemaayer */ +/* grlib.c Main module */ + + +#include +//#include + +#include "vgagl.h" + + +#define outside(x, y) (x < __clipx1 || x > __clipx2) +/* Global variables */ + +#ifdef DLL_CONTEXT_SHADOW + +/* The current context variable is shadowed in a read-only variable for */ +/* external use. */ + +GraphicsContext __currentcontext; /* Internal current context. */ +GraphicsContext currentcontext; /* Copy for external use. */ + +#else + +GraphicsContext currentcontext; + +#endif + +void (*__svgalib_nonaccel_fillbox)(int, int, int, int, int); +static int screenoffset = 0; /* Used by copy(box)toscreen. */ + + + + +/* Initialization and graphics contexts */ + +#define SCREENSIZE(gc) ((gc).bytewidth * (gc).height) + +static int colorbits(int c) +{ + switch (c) { + default: + case 256: + return 8; + case 32768: + return 15; + case 65536: + return 16; + case 256 * 65536: + return 24; + } +} + +int gl_setcontextvga(int m) +{ + return 0; +} + +int gl_setcontextvgavirtual(int m) +{ +} + +GraphicsContext * + gl_allocatecontext() +{ + return malloc(sizeof(GraphicsContext)); +} + +void gl_setcontext(GraphicsContext * gc) +{ + __currentcontext = *gc; +#ifdef DLL_CONTEXT_SHADOW + currentcontext = *gc; +#endif +} + +void gl_getcontext(GraphicsContext * gc) +{ + *gc = __currentcontext; +} + +void gl_freecontext(GraphicsContext * gc) +{ + if (gc->modetype == CONTEXT_VIRTUAL) + free(gc->vbuf); +} + +void gl_setcontextwidth(int w) +{ + __currentcontext.width = w; + currentcontext.width = w; + __currentcontext.bytewidth = w * BYTESPERPIXEL; + currentcontext.bytewidth = __currentcontext.bytewidth; + +} + +void gl_setcontextheight(int h) +{ + __currentcontext.height = currentcontext.height = h; +} + + +/* Clipping */ + +void gl_setclippingwindow(int x1, int y1, int x2, int y2) +{ + __clip = 1; + __clipx1 = x1; + __clipy1 = y1; + __clipx2 = x2; + __clipy2 = y2; +} + +void gl_enableclipping() +{ + __clip = 1; + __clipx1 = 0; + __clipy1 = 0; + __clipx2 = WIDTH - 1; + __clipy2 = HEIGHT - 1; +} + +void gl_disableclipping() +{ + __clip = 0; +} + + +/* Primitive functions */ + +void gl_setpixel(int x, int y, int c) +{ + if (__clip && outside(x, y)) + return; + setpixel(x, y, c); +} + +int gl_getpixel(int x, int y) +{ + if (__clip && outside(x, y)) + return -1; + return getpixel(x, y); +} + +void gl_hline(int x1, int y, int x2, int c) +{ + if (__clip) { + if (y_outside(y)) + return; + clipxleft(x1); + clipxright(x2); + } + if (x1 > x2) + return; + hline(x1, y, x2, c); +} + +#define ADJUSTBITMAPBOX() \ + nw = w; nh = h; nx = x; ny = y; \ + if (nx + nw < __clipx1 || nx > __clipx2) \ + return; \ + if (ny + nh < __clipy1 || ny > __clipy2) \ + return; \ + if (nx < __clipx1) { /* left adjust */ \ + nw += nx - __clipx1; \ + nx = __clipx1; \ + } \ + if (ny < __clipy1) { /* top adjust */ \ + nh += ny - __clipy1; \ + ny = __clipy1; \ + } \ + if (nx + nw > __clipx2) /* right adjust */ \ + nw = __clipx2 - nx + 1; \ + if (ny + nh > __clipy2) /* bottom adjust */ \ + nh = __clipy2 - ny + 1; \ + +void gl_fillbox(int x, int y, int w, int h, int c) +{ + if (__clip) { + if (x + w < __clipx1 || x > __clipx2) + return; + if (y + h < __clipy1 || y > __clipy2) + return; + if (x < __clipx1) { + w -= __clipx1 - x; + x = __clipx1; + } + if (y < __clipy1) { + h -= __clipy1 - y; + y = __clipy1; + } + if (x + w > __clipx2 + 1) + w = __clipx2 - x + 1; + if (y + h > __clipy2 + 1) + h = __clipy2 - y + 1; + } + if (w <= 0 || h <= 0) + return; + fillbox(x, y, w, h, c); +} + +void gl_putboxpart(int x, int y, int w, int h, int ow, int oh, void *b, + int ox, int oy) +{ + putboxpart(x, y, w, h, ow, oh, b, ox, oy); +} + +void gl_putbox(int x, int y, int w, int h, void *b) +{ + uchar *bp = b; + if (w <= 0 || h <= 0) + return; + if (__clip) { + int nx, ny, nw, nh; + ADJUSTBITMAPBOX(); + if (nw <= 0 || nh <= 0) + return; + if (nw != w || nh != h) { + putboxpart(nx, ny, nw, nh, w, h, bp, nx - x, ny - y); + return; + } + } + putbox(x, y, w, h, bp, w); +} + +static void emulate_putboxmask(int x, int y, int w, int h, void *b) +{ + void *box; + GraphicsContext gc; + box = alloca(w * h * BYTESPERPIXEL); + gl_getbox(x, y, w, h, box); /* does clipping */ + + gl_getcontext(&gc); /* save context */ + + /* create context that is only the box */ + gl_setcontextvirtual(w, h, BYTESPERPIXEL, BITSPERPIXEL, box); + gl_putboxmask(0, 0, w, h, b); + + gl_setcontext(&gc); /* restore context */ + gl_putbox(x, y, w, h, box); +} + +void gl_putboxmask(int x, int y, int w, int h, void *b) +{ + if (w <= 0 || h <= 0) + return; + if (__clip) { + if (x + w < __clipx1 || x > __clipx2) + return; + if (y + h < __clipy1 || y > __clipy2) + return; + if (x < __clipx1 || y < __clipy1 + || x + w > __clipx2 + 1 || y + h > __clipy2 + 1) { + /* clipping is not directly implemented */ + emulate_putboxmask(x, y, w, h, b); + return; + } + } + if (MODETYPE == CONTEXT_PAGED) + /* paged primitive is not implemented */ + emulate_putboxmask(x, y, w, h, b); + else + putboxmask(x, y, w, h, b); +} + +void gl_getbox(int x, int y, int w, int h, void *b) +{ + if (__clip) { + int nx, ny, nw, nh; + ADJUSTBITMAPBOX(); + if (nw <= 0 || nh <= 0) + return; + if (nw != w || nh != h) { + getboxpart(nx, ny, nw, nh, w, h, b, nx - x, ny - y); + return; + } + } + getbox(x, y, w, h, b, w); +} + +void gl_copybox(int x1, int y1, int w, int h, int x2, int y2) +{ +/* Doesn't handle clipping. */ + if (MODETYPE == CONTEXT_PAGED) { + /* Paged primitive is not implemented. */ + void *box; + box = alloca(w * h * BYTESPERPIXEL); + getbox(x1, y1, w, h, box, w); + putbox(x2, y2, w, h, box, w); + return; + } + copybox(x1, y1, w, h, x2, y2); +} + + +/* Miscellaneous functions */ + +void gl_clearscreen(int c) +{ + gl_fillbox(0, 0, WIDTH, HEIGHT, c); +} + +int gl_rgbcolor(int r, int g, int b) +{ + unsigned v; + switch (BITSPERPIXEL) { + case 8: + /* assumes RGB palette at index 0-255 */ + /* bits 0-2 = blue (3 bits) */ + /* 3-5 = green (3 bits) */ + /* 6-7 = red (2 bits) */ + return (r & 0xc0) + ((g & 0xe0) >> 2) + (b >> 5); + case 24: + case 32: + v = (r << 16) + (g << 8) + b; + if (MODEFLAGS & MODEFLAG_32BPP_SHIFT8) + return v << 8; + return v; + case 15: + return ((r & 0xf8) << 7) + ((g & 0xf8) << 2) + (b >> 3); + case 16: + return ((r & 0xf8) << 8) + ((g & 0xfc) << 3) + (b >> 3); + case 4: + /* Now this is real fun. Map to standard EGA palette. */ + v = 0; + if (b >= 64) + v += 1; + if (g >= 64) + v += 2; + if (r >= 64) + v += 4; + if (b >= 192 || g >= 192 || r >= 192) + v += 8; + return v; + } + return -1; +} + +void gl_setpixelrgb(int x, int y, int r, int g, int b) +{ +/* Color components range from 0 to 255 */ + if (__clip && outside(x, y)) + return; + setpixel(x, y, gl_rgbcolor(r, g, b)); +} + +void gl_getpixelrgb(int x, int y, int *r, int *g, int *b) +{ + unsigned c; + if (__clip && outside(x, y)) { + *r = *g = *b = -1; + return; + } + c = getpixel(x, y); + switch (BITSPERPIXEL) { + case 8: + *b = (c & (1 + 2 + 4)) << 5; /* bits 0-2 */ + *g = (c & (8 + 16 + 32)) << 2; /* bits 3-5 */ + *r = (c & (64 + 128)); /* bits 6-7 */ + break; + case 32: + if (MODEFLAGS & MODEFLAG_32BPP_SHIFT8) { + *b = (c & 0xff00) >> 8; + *g = (c & 0xff0000) >> 16; + *r = c >> 24; + break; + } + case 24: + *b = c & 0xff; + *g = (c & 0xff00) >> 8; + *r = c >> 16; + break; + case 15: + *b = (c & (1 + 2 + 4 + 8 + 16)) << 3; + *g = (c & (32 + 64 + 128 + 256 + 512)) >> 2; + *r = (c & (1024 + 2048 + 4096 + 8192 + 16384)) >> 7; + break; + case 16: + *b = (c & (1 + 2 + 4 + 8 + 16)) << 3; + *g = (c & (32 + 64 + 128 + 256 + 512 + 1024)) >> 3; + *r = (c & (2048 + 4096 + 8192 + 16384 + 32768)) >> 8; + break; + case 4: + *b = (c & 1) * ((c & 8) ? 255 : 128); + *g = (c & 2) * ((c & 8) ? 255 : 128); + *r = (c & 4) * ((c & 8) ? 255 : 128); + break; + } +} + +void gl_setdisplaystart(int x, int y) +{ + vga_setdisplaystart(y * BYTEWIDTH + x * BYTESPERPIXEL); +} + + +/* Screen copying */ + +void gl_setscreenoffset(int o) +{ + screenoffset = o; +} + +int gl_enablepageflipping(GraphicsContext * gc) +{ + if (gc->modeflags & MODEFLAG_PAGEFLIPPING_CAPABLE) { + gc->modeflags |= MODEFLAG_PAGEFLIPPING_ENABLED; + } + if (gc->modeflags & MODEFLAG_TRIPLEBUFFERING_CAPABLE) { + gc->modeflags &= ~(MODEFLAG_PAGEFLIPPING_ENABLED); + gc->modeflags |= MODEFLAG_TRIPLEBUFFERING_ENABLED; + } + gc->flippage = 0; + if (gc->modeflags & MODEFLAG_TRIPLEBUFFERING_ENABLED) + return 3; + if (gc->modeflags & MODEFLAG_PAGEFLIPPING_ENABLED) + return 2; + return 0; +} +#if 0 //有__svgalib_memcpy32shift8,不支持 +void gl_copyscreen(GraphicsContext * gc) +{ + int size; + void *svp, *dvp; + + if (gc->modeflags & MODEFLAG_PAGEFLIPPING_ENABLED) + gc->flippage ^= 1; + if (gc->modeflags & MODEFLAG_TRIPLEBUFFERING_ENABLED) + gc->flippage = (gc->flippage + 1) % 3; + if (gc->modeflags & (MODEFLAG_PAGEFLIPPING_ENABLED | + MODEFLAG_TRIPLEBUFFERING_ENABLED)) { + /* Calculate screen offset in bytes. */ + screenoffset = gc->bytewidth * HEIGHT * gc->flippage; + if (gc->modeflags & MODEFLAG_FLIPPAGE_BANKALIGNED) + screenoffset = ((screenoffset + 0xffff) & ~0xffff); + } + if (gc->modetype == CONTEXT_MODEX) { + vga_copytoplanar256(VBUF, BYTEWIDTH, screenoffset / 4, + gc->bytewidth / 4, WIDTH, HEIGHT); + goto end; + } + if (gc->modetype == CONTEXT_PLANAR16) { + if (WIDTH == 1024 && HEIGHT >= 512 && + ((screenoffset / 8) & 0xffff) == 0) { + /* Kludge to allow 1024x768x16 with page flipping. */ + int page; + page = (screenoffset / 8) >> 16; + vga_setpage(page); + vga_copytoplanar16(VBUF, BYTEWIDTH, 0, + gc->bytewidth / 8, WIDTH, 512); + vga_setpage(page + 1); + vga_copytoplanar16(VBUF + WIDTH * 512, BYTEWIDTH, + 0, gc->bytewidth / 8, WIDTH, HEIGHT - 512); + return; + } + if (WIDTH * HEIGHT >= 512 * 1024) + /* We don't handle banking. */ + return; + + vga_copytoplanar16(VBUF, BYTEWIDTH, screenoffset / 8, + gc->bytewidth / 8, WIDTH, HEIGHT); + goto end; + } + if (BYTESPERPIXEL == 4 && gc->bytesperpixel == 3) { + /* Special case. */ + int soffset, doffset; + if (BYTEWIDTH / 4 != gc->bytewidth / 3) { + /* Even more special case for physical truecolor */ + /* modes that have extra scanline padding. */ + /* This has the effect of slowing down */ + /* '3d' in some truecolor modes on ATI mach32. */ + gl_copyboxtocontext(0, 0, WIDTH, HEIGHT, gc, 0, 0); + goto end; + } + soffset = 0; + doffset = screenoffset; + size = WIDTH * HEIGHT; + while (soffset / 4 < size) { + int schunk, dchunk; + int count; + schunk = __svgalib_driver_setread(&__currentcontext, soffset, &svp); + dchunk = __svgalib_driver_setwrite(gc, doffset, &dvp); + if (dchunk == 1) { + /* One byte left in segment. */ + int pix; + pix = *(unsigned *) svp; /* 32-bit pixel */ + *(unsigned char *) dvp = pix; + dchunk = __svgalib_driver_setwrite(gc, doffset + 1, &dvp); + *(unsigned short *) dvp = pix >> 8; + count = 1; /* 1 pixel handled. */ + } else if (dchunk == 2) { + /* Two bytes left. */ + int pix; + pix = *(unsigned *) svp; /* 32-bit pixel */ + *(unsigned short *) dvp = pix; + dchunk = __svgalib_driver_setwrite(gc, doffset + 2, &dvp); + *(unsigned char *) dvp = pix >> 16; + count = 1; /* 1 pixel handled. */ + } else { + count = min(min(schunk / 4, dchunk / 3), + size - (soffset / 4)); + __svgalib_memcpy4to3(dvp, svp, count); + } + soffset += count * 4; + doffset += count * 3; + } + goto end; + } + if (BYTESPERPIXEL == 4 && gc->bytesperpixel == 4 && + (gc->modeflags & MODEFLAG_32BPP_SHIFT8)) { + int soffset = 0; + int doffset = screenoffset; + size = SCREENSIZE(__currentcontext); + while (soffset < size) { + int schunk, dchunk; + int count; + schunk = __svgalib_driver_setread(&__currentcontext, soffset, &svp); + dchunk = __svgalib_driver_setwrite(gc, doffset, &dvp); + count = min(min(schunk, dchunk), (size - soffset)); + __svgalib_memcpy32shift8(dvp, svp, count / 4); + soffset += count; + doffset += count; + } + } else { + int soffset = 0; + int doffset = screenoffset; + size = SCREENSIZE(__currentcontext); + while (soffset < size) { + int schunk, dchunk; + int count; + schunk = __svgalib_driver_setread(&__currentcontext, soffset, &svp); + dchunk = __svgalib_driver_setwrite(gc, doffset, &dvp); + count = min(min(schunk, dchunk), (size - soffset)); + __memcpy(dvp, svp, count); + soffset += count; + doffset += count; + } + } + + end: + if (gc->modeflags & (MODEFLAG_PAGEFLIPPING_ENABLED | + MODEFLAG_TRIPLEBUFFERING_ENABLED)) { + GraphicsContext save; + /* setdisplaystart will use BYTEWIDTH of the virtual screen, */ + /* which is what we want since vga_setdisplaystart is */ + /* defined in terms of pixel offset (except for hicolor */ + /* modes, which are defined in terms of bytes). */ + gl_getcontext(&save); + gl_setcontext(gc); + if (gc->modeflags & MODEFLAG_FLIPPAGE_BANKALIGNED) + vga_setdisplaystart(screenoffset); + else + gl_setdisplaystart(0, gc->height * gc->flippage); + gl_setcontext(&save); + /* For page flipping, it might be appropriate to add a */ + /* waitverticalretrace here. */ + } + screenoffset = 0; +} +#endif //0 +#if 0 //有 __svgalib_memcpy4to3,不支持 +void gl_copyboxtocontext(int x1, int y1, int w, int h, GraphicsContext * gc, + int x2, int y2) +{ +/* This is now reasonably efficient if clipping is not enabled. */ + void *buf; + GraphicsContext save; + gl_getcontext(&save); + if ((MODETYPE == CONTEXT_LINEAR || MODETYPE == CONTEXT_VIRTUAL) && + (BYTESPERPIXEL == gc->bytesperpixel) && + !__clip && !gc->clip) { +#ifdef DLL_CONTEXT_SHADOW + __currentcontext = *gc; +#else + gl_setcontext(gc); +#endif +/* + * Note: Using save.bytewidth / BYTESPERPIXEL is probably not an optimal hack here. + * it would be better to transfer save.bytewidth to putbox as it is what is really + * used there. However, putbox is used all over interpreting the last entry as a + * pixel count, so we keep it this way to avoid problems if some other place not + * updated by accident. + */ + putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, save.vbuf + + y1 * save.bytewidth + x1 * BYTESPERPIXEL, + save.bytewidth / BYTESPERPIXEL); + goto end; + } + buf = alloca(w * h * BYTESPERPIXEL); + gl_getbox(x1, y1, w, h, buf); +#ifdef DLL_CONTEXT_SHADOW + __currentcontext = *gc; +#else + gl_setcontext(gc); +#endif + + if (save.bytesperpixel == 4 && gc->bytesperpixel == 3) { + /* Special case conversion from 32-bit virtual screen to */ + /* 24-bit truecolor framebuffer. */ + if (gc->modetype == CONTEXT_PAGED || gc->clip) { + /* For paged modes or clipping, use another buffer. */ + void *buf2; + buf2 = alloca(w * h * 3); + __svgalib_memcpy4to3(buf2, buf, w * h); + gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, + buf2); + } else + /* No clipping, linear. */ + __svgalib_driver24_putbox32(x2, y2, w, h, buf, w); + } else /* Contexts assumed to have same pixel size. */ + gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, buf); + + end: +#ifdef DLL_CONTEXT_SHADOW + __currentcontext = save; +#else + gl_setcontext(&save); +#endif +} + +void gl_copyboxfromcontext(GraphicsContext * gc, int x1, int y1, int w, int h, + int x2, int y2) +{ + void *buf; + GraphicsContext save; + if ((gc->modetype == CONTEXT_LINEAR || gc->modetype == CONTEXT_VIRTUAL) && + (BYTESPERPIXEL == gc->bytesperpixel) && + !__clip && !gc->clip) { +/* + * see above on gc->bytewidth / BYTESPERPIXEL. + */ + putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, gc->vbuf + + y1 * gc->bytewidth + x1 * BYTESPERPIXEL, + gc->bytewidth / BYTESPERPIXEL); + return; + } + gl_getcontext(&save); +#ifdef DLL_CONTEXT_SHADOW + __currentcontext = *gc; +#else + gl_setcontext(gc); +#endif + buf = alloca(w * h * BYTESPERPIXEL); + gl_getbox(x1, y1, w, h, buf); +#ifdef DLL_CONTEXT_SHADOW + __currentcontext = save; +#else + gl_setcontext(&save); +#endif + + if (gc->bytesperpixel == 4 && save.bytesperpixel == 3) { + /* Special case conversion from 32-bit virtual screen to */ + /* 24-bit truecolor framebuffer. */ + if (save.modetype == CONTEXT_PAGED || save.clip) { + /* For paged modes or clipping, use another buffer. */ + void *buf2; + buf2 = alloca(w * h * 3); + __svgalib_memcpy4to3(buf2, buf, w * h); + gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, + buf2); + } else + /* No clipping, linear. */ + __svgalib_driver24_putbox32(x2, y2, w, h, buf, w); + } else /* Contexts assumed to have same pixel size. */ + gl_putbox(x2, y2 + screenoffset / BYTEWIDTH, w, h, buf); +} + +#endif //0 \ No newline at end of file diff --git a/svgalib/line.c b/svgalib/line.c new file mode 100644 index 0000000..59894a9 --- /dev/null +++ b/svgalib/line.c @@ -0,0 +1,53 @@ +#include "line.h" + +//画横线 +void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b) +{ + int m; + POINT tp; + + int length = maxX.x - minX.x; + tp.x = minX.x; + tp.y = minX.y; + for(m = 0;m < length;m++){ + tp.x++; + draw_dot(pFbdev,tp,r,g,b); + } +} + +void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t){ + int m; + + int length = maxX.x - minX.x; + for(m = 0;m < length;m++){ + POINT tp; + tp.x = minX.x + m; + tp.y = minX.y; + + draw_dot_with_trans(pFbdev,tp,r,g,b,t); + } +} + +//画竖线 +void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b) +{ + int m; + + int length = maxY.y - minY.y; + for(m = 0;m < length;m++){ + POINT tp; + tp.x = minY.x; + tp.y = minY.y + m; + + draw_dot(pFbdev,tp,r,g,b); + } +} + +//划横线 +void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color) +{ + RGBT rgbt = getRGBT(color); + + draw_h_line_with_trans(pFbdev,minX,maxX,rgbt.r,rgbt.g,rgbt.b,rgbt.t); +} + diff --git a/svgalib/line.h b/svgalib/line.h new file mode 100644 index 0000000..008a57b --- /dev/null +++ b/svgalib/line.h @@ -0,0 +1,60 @@ +/* + * 画线的实现 + * @作者 陈洪波 + */ + +#ifndef _LINE_H_ +#define _LINE_H_ + +#include "fbtool.h" +#include "point.h" + +/* + * 指定x值较小的点和x值较大的点,并指定颜色的rgb值画一条横线 + * @param pFbdev 参考结构体 fbdev + * @param minX x较小的点 + * @param maxX x较大的点 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @return void + */ +void draw_h_line(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b); + +/* + * 指定x值较小的点和x值较大的点,并指定颜色的rgb值和透明度画一条横线 + * @param pFbdev 参考结构体 fbdev + * @param minX x较小的点 + * @param maxX x较大的点 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @param t 颜色对应的透明度 + * @return void + * + */ +void draw_h_line_with_trans(PFBDEV pFbdev,POINT minX,POINT maxX,uint8_t r,uint8_t g,uint8_t b,uint8_t t); + +/* + * 使用字符串作为颜色的表示来画一条横线 + * @param pFbdev 参考结构体 fbdev + * @param minX x较小的点 + * @param maxX x较大的点 + * @param color 颜色所对应的字符串 + * @return void + */ +void draw_h_line_with_string(PFBDEV pFbdev,POINT minX,POINT maxX,const char *color); + +/* + * 指明y最小的一个点和一个y较大的点,并指明RGB值画一条竖线 + * @param pFbdev 参考结构体 fbdev + * @param minY y较小的点 + * @param maxY y较大的点 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + */ +void draw_v_line(PFBDEV pFbdev,POINT minY,POINT maxY,uint8_t r,uint8_t g,uint8_t b); + + +#endif //_LINE_H_ diff --git a/svgalib/page.h b/svgalib/page.h new file mode 100644 index 0000000..0a61ebe --- /dev/null +++ b/svgalib/page.h @@ -0,0 +1,112 @@ +#ifndef _I386_PAGE_H +#define _I386_PAGE_H +/* PAGE_SHIFT determines the page size */ +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#define PAGE_MASK (~(PAGE_SIZE-1)) +#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) +#define LARGE_PAGE_SIZE (1UL << PMD_SHIFT) +#ifdef __KERNEL__ +#ifndef __ASSEMBLY__ +#include +#ifdef CONFIG_X86_USE_3DNOW +#include +#define clear_page(page) mmx_clear_page((void *)(page)) +#define copy_page(to,from) mmx_copy_page(to,from) +#else +/* +* On older X86 processors it's not a win to use MMX here it seems. +* Maybe the K6-III ? +*/ +#define clear_page(page) memset((void *)(page), 0, PAGE_SIZE) +#define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE) +#endif +#define clear_user_page(page, vaddr, pg) clear_page(page) +#define copy_user_page(to, from, vaddr, pg) copy_page(to, from) +/* +* These are used to make use of C type-checking.. +*/ +#ifdef CONFIG_X86_PAE +typedef struct { unsigned long pte_low, pte_high; } pte_t; +typedef struct { unsigned long long pmd; } pmd_t; +typedef struct { unsigned long long pgd; } pgd_t; +#define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32)) +#define HPAGE_SHIFT 21 +#else +typedef struct { unsigned long pte_low; } pte_t; +typedef struct { unsigned long pmd; } pmd_t; +typedef struct { unsigned long pgd; } pgd_t; +#define boot_pte_t pte_t /* or would you rather have a typedef */ +#define pte_val(x) ((x).pte_low) +#define HPAGE_SHIFT 22 +#endif +#define PTE_MASK PAGE_MASK +#ifdef CONFIG_HUGETLB_PAGE +#define HPAGE_SIZE ((1UL) << HPAGE_SHIFT) +#define HPAGE_MASK (~(HPAGE_SIZE - 1)) +#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) +#endif +typedef struct { unsigned long pgprot; } pgprot_t; +#define pmd_val(x) ((x).pmd) +#define pgd_val(x) ((x).pgd) +#define pgprot_val(x) ((x).pgprot) +#define __pte(x) ((pte_t) { (x) } ) +#define __pmd(x) ((pmd_t) { (x) } ) +#define __pgd(x) ((pgd_t) { (x) } ) +#define __pgprot(x) ((pgprot_t) { (x) } ) +#endif /* !__ASSEMBLY__ */ +/* to align the pointer to the (next) page boundary */ +#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) +/* +* This handles the memory map.. We could make this a config +* option, but too many people screw it up, and too few need +* it. +* +* A __PAGE_OFFSET of 0xC0000000 means that the kernel has +* a virtual address space of one gigabyte, which limits the +* amount of physical memory you can use to about 950MB. +* +* If you want more physical memory than this then see the CONFIG_HIGHMEM4G +* and CONFIG_HIGHMEM64G options in the kernel configuration. +*/ +/* +* This much address space is reserved for vmalloc() and iomap() +* as well as fixmap mappings. +*/ +#define __VMALLOC_RESERVE (128 << 20) +#ifndef __ASSEMBLY__ +/* Pure 2^n version of get_order */ +static __inline__ int get_order(unsigned long size) +{ +int order; +size = (size-1) >> (PAGE_SHIFT-1); +order = -1; +do { + size >>= 1; + order++; +} while (size); +return order; +} +#endif /* __ASSEMBLY__ */ +#ifdef __ASSEMBLY__ +#define __PAGE_OFFSET (0xC0000000) +#else +#define __PAGE_OFFSET (0xC0000000UL) +#endif +#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) +#define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) +#define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) +#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) +#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) +#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) +#ifndef CONFIG_DISCONTIGMEM +#define pfn_to_page(pfn) (mem_map + (pfn)) +#define page_to_pfn(page) ((unsigned long)((page) - mem_map)) +#define pfn_valid(pfn) ((pfn) < max_mapnr) +#endif /* !CONFIG_DISCONTIGMEM */ +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) +#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | / + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) +#endif /* __KERNEL__ */ +#endif /* _I386_PAGE_H */ diff --git a/svgalib/page.h.bak2 b/svgalib/page.h.bak2 new file mode 100755 index 0000000..37d1fe2 --- /dev/null +++ b/svgalib/page.h.bak2 @@ -0,0 +1,103 @@ +#ifndef __ASM_GENERIC_PAGE_H +#define __ASM_GENERIC_PAGE_H +/* + * Generic page.h implementation, for NOMMU architectures. + * This provides the dummy definitions for the memory management. + */ + +#ifdef CONFIG_MMU +#error need to prove a real asm/page.h +#endif + + +/* PAGE_SHIFT determines the page size */ + +#define PAGE_SHIFT 12 +#ifdef __ASSEMBLY__ +#define PAGE_SIZE (1 << PAGE_SHIFT) +#else +#define PAGE_SIZE (1UL << PAGE_SHIFT) +#endif +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#include + +#ifndef __ASSEMBLY__ + +#define get_user_page(vaddr) __get_free_page(GFP_KERNEL) +#define free_user_page(page, addr) free_page(addr) + +#define clear_page(page) memset((page), 0, PAGE_SIZE) +#define copy_page(to,from) memcpy((to), (from), PAGE_SIZE) + +#define clear_user_page(page, vaddr, pg) clear_page(page) +#define copy_user_page(to, from, vaddr, pg) copy_page(to, from) + +/* + * These are used to make use of C type-checking.. + */ +typedef struct { + unsigned long pte; +} pte_t; +typedef struct { + unsigned long pmd[16]; +} pmd_t; +typedef struct { + unsigned long pgd; +} pgd_t; +typedef struct { + unsigned long pgprot; +} pgprot_t; +typedef struct page *pgtable_t; + +#define pte_val(x) ((x).pte) +#define pmd_val(x) ((&x)->pmd[0]) +#define pgd_val(x) ((x).pgd) +#define pgprot_val(x) ((x).pgprot) + +#define __pte(x) ((pte_t) { (x) } ) +#define __pmd(x) ((pmd_t) { (x) } ) +#define __pgd(x) ((pgd_t) { (x) } ) +#define __pgprot(x) ((pgprot_t) { (x) } ) + +extern unsigned long memory_start; +extern unsigned long memory_end; + +#endif /* !__ASSEMBLY__ */ + +#ifdef CONFIG_KERNEL_RAM_BASE_ADDRESS +#define PAGE_OFFSET (CONFIG_KERNEL_RAM_BASE_ADDRESS) +#else +#define PAGE_OFFSET (0) +#endif + +#ifndef ARCH_PFN_OFFSET +#define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) +#endif + +#ifndef __ASSEMBLY__ + +#define __va(x) ((void *)((unsigned long) (x))) +#define __pa(x) ((unsigned long) (x)) + +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) +#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) + +#define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr)) +#define page_to_virt(page) pfn_to_virt(page_to_pfn(page)) + +#ifndef page_to_phys +#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT) +#endif + +#define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr) + +#define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ + ((void *)(kaddr) < (void *)memory_end)) + +#endif /* __ASSEMBLY__ */ + +#include +#include + +#endif /* __ASM_GENERIC_PAGE_H */ diff --git a/svgalib/point.c b/svgalib/point.c new file mode 100644 index 0000000..41cd3cf --- /dev/null +++ b/svgalib/point.c @@ -0,0 +1,95 @@ +#include "point.h" + +//画点 +void draw_dot(PFBDEV pFbdev, POINT p, uint8_t r, uint8_t g, uint8_t b) { + uint32_t offset; + uint8_t color[2]; + color[0] = COLOR16(r, g, b) & 0x00FF; + color[1] = COLOR16(r, g, b) >> 8; + // color[2] = r; + // color[3] = 0x0; //透明度 + + offset = p.y * pFbdev->fb_fix.line_length + 2 * p.x; + //将操作映射到内存中 + fb_memcpy((void *)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset, color, 2); +} + +void draw_dot_c(PFBDEV pFbdev, POINT p, uint16_t c) { + uint32_t offset; + uint8_t color[2]; + // color[0] = COLOR16(r, g, b) & 0x00FF; + // color[1] = COLOR16(r, g, b) >>8; + // color[2] = r; + // color[3] = 0x0; //透明度 + + offset = p.y * pFbdev->fb_fix.line_length + 2 * p.x; + //将操作映射到内存中 + // fb_memcpy((void *)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset, + // color, 2); + // + long location = + (p.x + pFbdev->fb_var.xoffset) * (pFbdev->fb_var.bits_per_pixel / 8) + + (p.y + pFbdev->fb_var.yoffset) * pFbdev->fb_fix.line_length; + *((uint16_t *)(pFbdev->fb_mem + location)) = c; +} + +//画点 +void draw_dot_with_trans(PFBDEV pFbdev, POINT p, uint8_t r, uint8_t g, + uint8_t b, uint8_t t) { + uint32_t offset; + uint8_t color[4]; + color[0] = b; + color[1] = g; + color[2] = r; + color[3] = t; //透明度 + + offset = p.y * pFbdev->fb_fix.line_length + 4 * p.x; + //将操作映射到内存中 + fb_memcpy((void *)pFbdev->fb_mem + pFbdev->fb_mem_offset + offset, color, 4); +} + +//画点 +void draw_x_y_dot(PFBDEV pFbdev, int x, int y, uint8_t r, uint8_t g, + uint8_t b) { + POINT p; + p.x = x; + p.y = y; + + // draw_dot(pFbdev, p, r, g, b); +} + +//画点 +void draw_x_y_dot_with_trans(PFBDEV pFbdev, int x, int y, uint8_t r, uint8_t g, + uint8_t b, uint8_t t) { + POINT p; + p.x = x; + p.y = y; + + draw_dot_with_trans(pFbdev, p, r, g, b, t); +} + +//画点 +void draw_x_y_color_dot(PFBDEV pFbdev, int x, int y, RGBT c) { + draw_x_y_dot(pFbdev, x, y, c.r, c.g, c.b); +} + +//画点 +void draw_x_y_color_dot_with_trans(PFBDEV pFbdev, int x, int y, RGBT c) { + draw_x_y_dot_with_trans(pFbdev, x, y, c.r, c.g, c.b, c.t); +} + +//画点 color8位,分别代表RGBT +void draw_x_y_color_dot_with_string(PFBDEV pFbdev, int x, int y, + const char *temp) { + RGBT rgbt = getRGBT(temp); + + draw_x_y_dot_with_trans(pFbdev, x, y, rgbt.r, rgbt.g, rgbt.b, rgbt.t); +} + +// 画点 color16位 +void gl_setpixel(int x, int y, int c) +{ + long location = (x + pFbdev->fb_var.xoffset) * 2 + + (y + pFbdev->fb_var.yoffset) * pFbdev->fb_fix.line_length; + *((int16_t *)(pFbdev->fb_mem + location)) = c; +} \ No newline at end of file diff --git a/svgalib/point.h b/svgalib/point.h new file mode 100644 index 0000000..7b81b65 --- /dev/null +++ b/svgalib/point.h @@ -0,0 +1,96 @@ +/** + * 画点实现 + * @作者 陈洪波 + */ + +#ifndef _POINT_H_ +#define _POINT_H_ + +#include "fbtool.h" + +/* + * 该函数用于在命令行中画点 + * @param pFbdev 参考结构体 fbdev + * @param p 点的坐标 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @return void + */ +void draw_dot(PFBDEV pFbdev,POINT p,uint8_t r,uint8_t g,uint8_t b); +void draw_dot_c(PFBDEV pFbdev, POINT p, uint16_t c); +/* + * 该函数用于实现画点,不过在这个函数中需要设定透明度参数 + * @param pFbdev 参考结构体 fbdev + * @param p 点的坐标 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @param t 颜色对应的透明度值 + * @return void + */ +void draw_dot_with_trans(PFBDEV pFbdev, POINT p, uint8_t r, uint8_t g, + uint8_t b, uint8_t t); + +/* + * 该函数用于指定点的横坐标,纵坐标的值来画点 + * @param pFbdev 参考结构体 fbdev + * @param x 点的坐标对应的横坐标的值 + * @param y 点的坐标对应的纵坐标的值 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + */ +void draw_x_y_dot(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b); + +/* + * 该函数用于指定点的横坐标,纵坐标的值,并且必须指明透明度来画点 + * @param pFbdev 参考结构体 fbdev + * @param x 点的坐标对应的横坐标的值 + * @param y 点的坐标对应的纵坐标的值 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @param t 颜色对应的透明度值 + */ +void draw_x_y_dot_with_trans(PFBDEV pFbdev,int x,int y,uint8_t r,uint8_t g,uint8_t b,uint8_t t); + +/* + * 该函数指定点的横纵坐标,然后使用结构体rgbt来代替颜色来画点 + * @param pFbdev 参考结构体 fbdev + * @param x 点的坐标对应的横坐标的值 + * @param y 点的坐标对应的纵坐标的值 + * @param c 用来代表颜色的结构体 + * @return void + * + */ +void draw_x_y_color_dot(PFBDEV pFbdev,int x,int y,RGBT c); + +/* + * 该函数指定点的横纵坐标,然后使用结构体rgbt来代替颜色来画点,不过在这里指明透明度是有效果 + * @param pFbdev 参考结构体 fbdev + * @param x 点的坐标对应的横坐标的值 + * @param y 点的坐标对应的纵坐标的值 + * @param c 用来代表颜色的结构体 + * @return void + * + */ +void draw_x_y_color_dot_with_trans(PFBDEV pFbdev,int x,int y,RGBT c); + +/* + * 该函数指定点的横纵坐标,然后使用八位的字符串来指明颜色来画点 + * 注意:这里的字符串里面都是16进制的数值,例如,"ffff0000" + * + * @param pFbdev 参考结构体 fbdev + * @param x 点的坐标对应的横坐标的值 + * @param y 点的坐标对应的纵坐标的值 + * @param c 用来代表颜色的结构体 + * @param color 用来指明颜色的字符串 + * @return void + * + */ +void draw_x_y_color_dot_with_string(PFBDEV pFbdev,int x,int y,const char *color); + +#endif //_POINT_H_ + + diff --git a/svgalib/rectangle.c b/svgalib/rectangle.c new file mode 100644 index 0000000..1ca77da --- /dev/null +++ b/svgalib/rectangle.c @@ -0,0 +1,30 @@ +#include "rectangle.h" + +//画一个矩形框 +void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) +{ + draw_h_line(pFbdev,lu,ru,r,g,b); + draw_h_line(pFbdev,ld,rd,r,g,b); + draw_v_line(pFbdev,lu,ld,r,g,b); + draw_v_line(pFbdev,ru,rd,r,g,b); +} + +//填充一个矩形框 +void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b) +{ + int xlen = ru.x - lu.x; + int ylen = ld.y - lu.y; + + int m,n; + + for(m = 0;m < ylen;m++){ + for(n = 0;n < xlen;n++){ + POINT p; + p.x = lu.x + n; + p.y = lu.y + m; + + draw_dot(pFbdev,p,r,g,b); + } + } +} + diff --git a/svgalib/rectangle.h b/svgalib/rectangle.h new file mode 100644 index 0000000..f1c4e11 --- /dev/null +++ b/svgalib/rectangle.h @@ -0,0 +1,44 @@ +/* + * 实现画矩形或者是填充矩形 + * @作者 陈洪波 + */ + +#ifndef _RECTANGLE_H_ +#define _RECTANGLE_H_ + +#include "fbtool.h" +#include "point.h" +#include "line.h" + +/* + * 画一个矩形框 + * @param pFbdev 参考结构体 fbdev + * @param lu 矩形框左上角的点 + * @param ld 矩形框左下角的点 + * @param ru 矩形框右上角的点 + * @param rd 矩形框右下角的点 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @return void + */ +void draw_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); + +/* + * 填充一个矩形框 + * @param pFbdev 参考结构体 fbdev + * @param lu 矩形框左上角的点 + * @param ld 矩形框左下角的点 + * @param ru 矩形框右上角的点 + * @param rd 矩形框右下角的点 + * @param r 颜色对应的R值 + * @param g 颜色对应的G值 + * @param b 颜色对应的B值 + * @return void + */ +void fill_rec(PFBDEV pFbdev,POINT lu,POINT ld,POINT ru,POINT rd,uint8_t r,uint8_t g,uint8_t b); + + + +#endif //_RECTANGLE_H_ + diff --git a/svgalib/test.c b/svgalib/test.c new file mode 100644 index 0000000..6db1f0f --- /dev/null +++ b/svgalib/test.c @@ -0,0 +1,150 @@ +#include "circle.h" +#include "line.h" +#include "point.h" +#include "rectangle.h" + +int main() { + FBDEV fbdev; + + memset(&fbdev, 0, sizeof(FBDEV)); + strcpy(fbdev.dev, "/dev/fb0"); + + if (0 == fb_open(&fbdev)) { + printf("Open fail!!\n"); + return -1; + } + + //打印frame buffer 所占内存的开始地址  + pmem_start(&fbdev); + //打印FB_TYPE-c kbd.c + p_type(&fbdev); + //打印可见清晰度 + p_visible_res(&fbdev); + //打印虚拟分辨率 + p_virt_res(&fbdev); + //打印虚拟到可见的偏移量 + p_offset(&fbdev); + //打印每个像素的位数 + p_bpp(&fbdev); + //打印R,G,B和透明度 + p_rgbt(&fbdev); + //打印在内存中的高度和宽度 + p_hw(&fbdev); + //打印fb的RGB和透明度的位域 + p_rgbt(&fbdev); + + getchar(); + + //清屏 + clear_con((void *)(fbdev.fb_mem + fbdev.fb_mem_offset), -1, + fbdev.fb_fix.smem_len); + + POINT p; + p.x = 100; + p.y = 100; + + //画点 + // draw_x_y_dot(&fbdev,100,100,0x0,0xff,0x0); + draw_dot(&fbdev, p, 31, 31, 0); + + p.x = 50; + p.y = 50; + draw_dot_c(&fbdev, p, LT_RED); + p.x++; + draw_dot_c(&fbdev, p, LT_RED); + p.x++; + draw_dot_c(&fbdev, p, LT_RED); + + p.x = 100; + p.y = 50; + draw_dot_c(&fbdev, p, LT_GREEN); + p.x++; + draw_dot_c(&fbdev, p, LT_GREEN); + p.x++; + draw_dot_c(&fbdev, p, LT_GREEN); + + p.x = 150; + p.y = 50; + draw_dot_c(&fbdev, p, LT_BLUE); + p.x++; + draw_dot_c(&fbdev, p, LT_BLUE); + p.x++; + draw_dot_c(&fbdev, p, LT_BLUE); + + RGBT c; + c.r = 0xff; + c.g = 0xff; + c.b = 0xff; + c.t = 0x00; + // draw_x_y_color_dot_with_trans(&fbdev,100,100,RED); + // draw_x_y_color_dot_with_string(&fbdev,100,300,YELLOW); + + //划横线 + //画横线 + POINT p21; + p21.x = 120; + p21.y = 100; + POINT p2; + p2.x = 160; + p2.y = 160; + // draw_h_line(&fbdev,p21,p2,0x0,0xff,0x0); +// draw_h_line_with_string(&fbdev, p21, p2, RED); + + //画竖线 + POINT p31; + p31.x = 100; + p31.y = 120; + POINT p3; + p3.x = 100; + p3.y = 160; + draw_v_line(&fbdev, p31, p3, 0x0, 0xff, 0x0); + + POINT p40; + p40.x = 120; + p40.y = 120; + POINT p41; + p41.x = 160; + p41.y = 120; + POINT p42; + p42.x = 120; + p42.y = 160; + POINT p43; + p43.x = 160; + p43.y = 160; + //画矩形 + draw_rec(&fbdev, p40, p42, p41, p43, 0x0, 0xff, 0x0); + + POINT p50; + p50.x = 100; + p50.y = 180; + POINT p51; + p51.x = 160; + p51.y = 180; + POINT p52; + p52.x = 100; + p52.y = 220; + POINT p53; + p53.x = 160; + p53.y = 220; + //填充 + fill_rec(&fbdev, p50, p52, p51, p53, 0x0, 0xff, 0x0); + /* + int x = 500; + while(1){ + draw_circle(&fbdev,x,400,100,RED); + usleep(100); + + x++; + + if(x == 1200) + break; + + clear_con((void *)(fbdev.fb_mem + + fbdev.fb_mem_offset),1,fbdev.fb_fix.smem_len); + + } + */ + fb_close(&fbdev); + + return 0; +} diff --git a/svgalib/test_fb7 b/svgalib/test_fb7 new file mode 100755 index 0000000..d42437e Binary files /dev/null and b/svgalib/test_fb7 differ diff --git a/svgalib/vga.c b/svgalib/vga.c new file mode 100644 index 0000000..c992649 --- /dev/null +++ b/svgalib/vga.c @@ -0,0 +1,7 @@ +#include "vga.h" + +int vga_init(void) +{ + + +} \ No newline at end of file diff --git a/svgalib/vga.h b/svgalib/vga.h new file mode 100644 index 0000000..67c2502 --- /dev/null +++ b/svgalib/vga.h @@ -0,0 +1,551 @@ +/* VGAlib version 1.2 - (c) 1993 Tommy Frandsen */ +/* */ +/* This library is free software; you can redistribute it and/or */ +/* modify it without any restrictions. This library is distributed */ +/* in the hope that it will be useful, but without any warranty. */ + +/* Extended for svgalib by Harm Hanemaayer and Hartmut Schirmer */ + +#ifndef VGA_H +#define VGA_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define TEXT 0 /* Compatible with VGAlib v1.2 */ +#define G320x200x16 1 +#define G640x200x16 2 +#define G640x350x16 3 +#define G640x480x16 4 +#define G320x200x256 5 +#define G320x240x256 6 +#define G320x400x256 7 +#define G360x480x256 8 +#define G640x480x2 9 + +#define G640x480x256 10 +#define G800x600x256 11 +#define G1024x768x256 12 + +#define G1280x1024x256 13 /* Additional modes. */ + +#define G320x200x32K 14 +#define G320x200x64K 15 +#define G320x200x16M 16 +#define G640x480x32K 17 +#define G640x480x64K 18 +#define G640x480x16M 19 +#define G800x600x32K 20 +#define G800x600x64K 21 +#define G800x600x16M 22 +#define G1024x768x32K 23 +#define G1024x768x64K 24 +#define G1024x768x16M 25 +#define G1280x1024x32K 26 +#define G1280x1024x64K 27 +#define G1280x1024x16M 28 + +#define G800x600x16 29 +#define G1024x768x16 30 +#define G1280x1024x16 31 + +#define G720x348x2 32 /* Hercules emulation mode */ + +#define G320x200x16M32 33 /* 32-bit per pixel modes. */ +#define G640x480x16M32 34 +#define G800x600x16M32 35 +#define G1024x768x16M32 36 +#define G1280x1024x16M32 37 + +/* additional resolutions */ +#define G1152x864x16 38 +#define G1152x864x256 39 +#define G1152x864x32K 40 +#define G1152x864x64K 41 +#define G1152x864x16M 42 +#define G1152x864x16M32 43 + +#define G1600x1200x16 44 +#define G1600x1200x256 45 +#define G1600x1200x32K 46 +#define G1600x1200x64K 47 +#define G1600x1200x16M 48 +#define G1600x1200x16M32 49 + +#define G320x240x256V 50 +#define G320x240x32K 51 +#define G320x240x64K 52 +#define G320x240x16M 53 +#define G320x240x16M32 54 + +#define G400x300x256 55 +#define G400x300x32K 56 +#define G400x300x64K 57 +#define G400x300x16M 58 +#define G400x300x16M32 59 + +#define G512x384x256 60 +#define G512x384x32K 61 +#define G512x384x64K 62 +#define G512x384x16M 63 +#define G512x384x16M32 64 + +#define G960x720x256 65 +#define G960x720x32K 66 +#define G960x720x64K 67 +#define G960x720x16M 68 +#define G960x720x16M32 69 + +#define G1920x1440x256 70 +#define G1920x1440x32K 71 +#define G1920x1440x64K 72 +#define G1920x1440x16M 73 +#define G1920x1440x16M32 74 + +/* The following modes have been introduced by SciTech Display Doctor */ + +#define G320x400x256V 75 +#define G320x400x32K 76 +#define G320x400x64K 77 +#define G320x400x16M 78 +#define G320x400x16M32 79 + +#define G640x400x256 80 +#define G640x400x32K 81 +#define G640x400x64K 82 +#define G640x400x16M 83 +#define G640x400x16M32 84 + +#define G320x480x256 85 +#define G320x480x32K 86 +#define G320x480x64K 87 +#define G320x480x16M 88 +#define G320x480x16M32 89 + +#define G720x540x256 90 +#define G720x540x32K 91 +#define G720x540x64K 92 +#define G720x540x16M 93 +#define G720x540x16M32 94 + +#define G848x480x256 95 +#define G848x480x32K 96 +#define G848x480x64K 97 +#define G848x480x16M 98 +#define G848x480x16M32 99 + +#define G1072x600x256 100 +#define G1072x600x32K 101 +#define G1072x600x64K 102 +#define G1072x600x16M 103 +#define G1072x600x16M32 104 + +#define G1280x720x256 105 +#define G1280x720x32K 106 +#define G1280x720x64K 107 +#define G1280x720x16M 108 +#define G1280x720x16M32 109 + +#define G1360x768x256 110 +#define G1360x768x32K 111 +#define G1360x768x64K 112 +#define G1360x768x16M 113 +#define G1360x768x16M32 114 + +#define G1800x1012x256 115 +#define G1800x1012x32K 116 +#define G1800x1012x64K 117 +#define G1800x1012x16M 118 +#define G1800x1012x16M32 119 + +#define G1920x1080x256 120 +#define G1920x1080x32K 121 +#define G1920x1080x64K 122 +#define G1920x1080x16M 123 +#define G1920x1080x16M32 124 + +#define G2048x1152x256 125 +#define G2048x1152x32K 126 +#define G2048x1152x64K 127 +#define G2048x1152x16M 128 +#define G2048x1152x16M32 129 + +#define G2048x1536x256 130 +#define G2048x1536x32K 131 +#define G2048x1536x64K 132 +#define G2048x1536x16M 133 +#define G2048x1536x16M32 134 + +#define G512x480x256 135 +#define G512x480x32K 136 +#define G512x480x64K 137 +#define G512x480x16M 138 +#define G512x480x16M32 139 + +#define G400x600x256 140 +#define G400x600x32K 141 +#define G400x600x64K 142 +#define G400x600x16M 143 +#define G400x600x16M32 144 + +#define __GLASTMODE G400x600x16M32 +#define GLASTMODE vga_lastmodenumber() + + extern int vga_version; + + extern int vga_setmode(int mode); + extern int vga_hasmode(int mode); + extern int vga_setflipchar(int c); + + extern int vga_clear(void); + extern int vga_flip(void); + + extern int vga_getxdim(void); + extern int vga_getydim(void); + extern int vga_getcolors(void); + + extern int vga_setpalette(int index, int red, int green, int blue); + extern int vga_getpalette(int index, int *red, int *green, int *blue); + extern int vga_setpalvec(int start, int num, int *pal); + extern int vga_getpalvec(int start, int num, int *pal); + + extern int vga_screenoff(void); + extern int vga_screenon(void); + + extern int vga_setcolor(int color); + extern int vga_drawpixel(int x, int y); + extern int vga_drawline(int x1, int y1, int x2, int y2); + extern int vga_drawscanline(int line, unsigned char *colors); + extern int vga_drawscansegment(unsigned char *colors, int x, int y, int length); + extern int vga_getpixel(int x, int y); /* Added. */ + extern int vga_getscansegment(unsigned char *colors, int x, int y, int length); + + extern int vga_getch(void); + + extern int vga_dumpregs(void); + + +/* Extensions to VGAlib v1.2: */ + +/* blit flags */ +#define HAVE_BITBLIT 1 +#define HAVE_FILLBLIT 2 +#define HAVE_IMAGEBLIT 4 +#define HAVE_HLINELISTBLIT 8 +#define HAVE_BLITWAIT 16 + +/* other flags */ +#define HAVE_RWPAGE 1 /* vga_setreadpage() / vga_setwritepage() available */ +#define IS_INTERLACED 2 /* mode is interlaced */ +#define IS_MODEX 4 /* ModeX style 256 colors */ +#define IS_DYNAMICMODE 8 /* Dynamic defined mode */ +#define CAPABLE_LINEAR 16 /* Can go to linear addressing mode. */ +#define IS_LINEAR 32 /* Linear addressing enabled. */ +#define EXT_INFO_AVAILABLE 64 /* Returned modeinfo contains valid extended fields */ +#define RGB_MISORDERED 128 /* Mach32 32bpp uses 0BGR instead of BGR0. */ + /* As of this version 1.25 also used to signal if real RGB + (red first in memory) is used instead of BGR (Mach32 DAC 4) */ +#define HAVE_EXT_SET 256 /* vga_ext_set() available */ + +#define IS_IN_STANDARD_VGA_DRIVER(mode) ( \ + ((mode) < G640x480x256) || ((mode) == G720x348x2) ) + + typedef struct { + int width; + int height; + int bytesperpixel; + int colors; + int linewidth; /* scanline width in bytes */ + int maxlogicalwidth; /* maximum logical scanline width */ + int startaddressrange; /* changeable bits set */ + int maxpixels; /* video memory / bytesperpixel */ + int haveblit; /* mask of blit functions available */ + int flags; /* other flags */ + + /* Extended fields: */ + + int chiptype; /* Chiptype detected */ + int memory; /* videomemory in KB */ + int linewidth_unit; /* Use only a multiple of this as parameter for set_logicalwidth and + set_displaystart */ + char *linear_aperture; /* points to mmap secondary mem aperture of card (NULL if unavailable) */ + int aperture_size; /* size of aperture in KB if size>=videomemory. 0 if unavail */ + void (*set_aperture_page) (int page); + /* if aperture_size= has bits set for mouse/keyboard events detected. + * mouse and raw keyboard events are already handled and their bits removed + * from *in when vga_waitevent returns. + * VGA_KEYEVENT relates to vga_getch NOT vga_getkey. + * return values < 0 signal errors. In this case check errno. + */ + +/* Background running */ +extern void vga_runinbackground(int stat, ...); +#define VGA_GOTOBACK -1 +#define VGA_COMEFROMBACK -2 +extern int vga_runinbackground_version(void); + +#ifdef __cplusplus +} + +#endif +#endif /* VGA_H */ diff --git a/svgalib/vgagl.h b/svgalib/vgagl.h new file mode 100644 index 0000000..e1a17e7 --- /dev/null +++ b/svgalib/vgagl.h @@ -0,0 +1,188 @@ +/* Graphics Library headerfile */ + +#ifndef VGAGL_H +#define VGAGL_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/* Graphics context */ + +#define CONTEXT_VIRTUAL 0x0 +#define CONTEXT_PAGED 0x1 +#define CONTEXT_LINEAR 0x2 +#define CONTEXT_MODEX 0x3 +#define CONTEXT_PLANAR16 0x4 + +#define MODEFLAG_PAGEFLIPPING_CAPABLE 0x01 +#define MODEFLAG_TRIPLEBUFFERING_CAPABLE 0x02 +#define MODEFLAG_PAGEFLIPPING_ENABLED 0x04 +#define MODEFLAG_TRIPLEBUFFERING_ENABLED 0x08 +#define MODEFLAG_FLIPPAGE_BANKALIGNED 0x10 +/* + * The next two can never occur together, thus we use the same flag + * (as svgalib does). + */ +#define MODEFLAG_32BPP_SHIFT8 0x20 +#define MODEFLAG_24BPP_REVERSED 0x20 + + typedef struct { + void (*driver_setpixel_func) (int, int, int); + int (*driver_getpixel_func) (int, int); + void (*driver_hline_func) (int, int, int, int); + void (*driver_fillbox_func) (int, int, int, int, int); + void (*driver_putbox_func) (int, int, int, int, void *, int); + void (*driver_getbox_func) (int, int, int, int, void *, int); + void (*driver_putboxmask_func) (int, int, int, int, void *); + void (*driver_putboxpart_func) (int, int, int, int, int, int, void *, + int, int); + void (*driver_getboxpart_func) (int, int, int, int, int, int, void *, + int, int); + void (*driver_copybox_func) (int, int, int, int, int, int); + } framebufferfunctions; + + typedef struct { + unsigned char modetype; /* virtual, paged, linear, mode X */ + unsigned char modeflags; /* or planar16 */ + unsigned char dummy; + unsigned char flippage; + int width; /* width in pixels */ + int height; /* height in pixels */ + int bytesperpixel; /* bytes per pixel (1, 2, 3, or 4) */ + int colors; /* number of colors */ + int bitsperpixel; /* bits per pixel (8, 15, 16 or 24) */ + int bytewidth; /* length of a scanline in bytes */ + unsigned char *vbuf; /* address of framebuffer */ + int clip; /* clipping enabled? */ + int clipx1; /* top-left coordinate of clip window */ + int clipy1; + int clipx2; /* bottom-right coordinate of clip window */ + int clipy2; + framebufferfunctions ff; + } GraphicsContext; + + extern GraphicsContext currentcontext; + +#define BYTESPERPIXEL (currentcontext.bytesperpixel) +#define BYTEWIDTH (currentcontext.bytewidth) +#define WIDTH (currentcontext.width) +#define HEIGHT (currentcontext.height) +#define VBUF (currentcontext.vbuf) +#define MODETYPE (currentcontext.modetype) +#define MODEFLAGS (currentcontext.modeflags) +#define BITSPERPIXEL (currentcontext.bitsperpixel) +#define COLORS (currentcontext.colors) + +#define __clip (currentcontext.clip) +#define __clipx1 (currentcontext.clipx1) +#define __clipy1 (currentcontext.clipy1) +#define __clipx2 (currentcontext.clipx2) +#define __clipy2 (currentcontext.clipy2) + + +/* Configuration */ + + int gl_setcontextvga(int m); + int gl_setcontextvgavirtual(int m); + void gl_setcontextvirtual(int w, int h, int bpp, int bitspp, void *vbuf); + void gl_setcontextwidth(int w); + void gl_setcontextheight(int h); + GraphicsContext *gl_allocatecontext(void); + void gl_setcontext(GraphicsContext * gc); + void gl_getcontext(GraphicsContext * gc); + void gl_freecontext(GraphicsContext * gc); + +/* Line drawing */ + + void gl_setpixel(int x, int y, int c); + void gl_setpixelrgb(int x, int y, int r, int g, int b); + int gl_getpixel(int x, int y); + void gl_getpixelrgb(int x, int y, int *r, int *g, int *b); + int gl_rgbcolor(int r, int g, int b); + void gl_hline(int x1, int y, int x2, int c); + void gl_line(int x1, int y1, int x2, int y2, int c); + void gl_circle(int x, int y, int r, int c); + void gl_fillcircle(int sx, int sy, int r, int c); + void gl_bcircle(int sx, int sy, int r, int c, int fill); + +/* Box (bitmap) functions */ + + void gl_fillbox(int x, int y, int w, int h, int c); + void gl_getbox(int x, int y, int w, int h, void *dp); + void gl_putbox(int x, int y, int w, int h, void *dp); + void gl_putboxpart(int x, int y, int w, int h, int bw, int bh, void *b, + int xo, int yo); + void gl_putboxmask(int x, int y, int w, int h, void *dp); + void gl_copybox(int x1, int y1, int w, int h, int x2, int y2); + void gl_copyboxtocontext(int x1, int y1, int w, int h, GraphicsContext * gc, + int x2, int y2); + void gl_copyboxfromcontext(GraphicsContext * gc, int x1, int y1, int w, int h, + int x2, int y2); +/* The following functions only work in 256-color modes: */ + void gl_compileboxmask(int w, int h, void *sdp, void *ddp); + int gl_compiledboxmasksize(int w, int h, void *sdp); + void gl_putboxmaskcompiled(int x, int y, int w, int h, void *dp); + +/* Miscellaneous */ + + void gl_clearscreen(int c); + void gl_scalebox(int w1, int h1, void *sb, int w2, int h2, void *db); + void gl_setdisplaystart(int x, int y); + void gl_enableclipping(void); + void gl_setclippingwindow(int x1, int y1, int x2, int y2); + void gl_disableclipping(void); + +/* Screen buffering */ + + void gl_copyscreen(GraphicsContext * gc); + void gl_setscreenoffset(int o); + int gl_enablepageflipping(GraphicsContext * gc); + +/* Text */ + +/* Writemode flags. */ +#define WRITEMODE_OVERWRITE 0 +#define WRITEMODE_MASKED 1 +#define FONT_EXPANDED 0 +#define FONT_COMPRESSED 2 + + void gl_expandfont(int fw, int fh, int c, void *sfdp, void *dfdp); + void gl_setfont(int fw, int fh, void *fdp); + void gl_colorfont(int fw, int fh, int c, void *fdp); + void gl_setwritemode(int wm); + void gl_write(int x, int y, char *s); + void gl_writen(int x, int y, int n, char *s); + void gl_setfontcolors(int bg, int fg); + +/* gl_printf is only available in ELF libraries!! */ + int gl_printf(int x, int y, const char *fmt,...); + + extern unsigned char *gl_font8x8; /* compressed 8x8 font */ + +/* 256-color Palette */ + + typedef struct { + struct { + unsigned char red; /* 6-bit values */ + unsigned char green; + unsigned char blue; + } color[256]; + } Palette; + + void gl_setpalettecolor(int c, int r, int b, int g); + void gl_getpalettecolor(int c, int *r, int *b, int *g); + void gl_setpalettecolors(int s, int n, void *dp); + void gl_getpalettecolors(int s, int n, void *dp); + void gl_setpalette(void *p); + void gl_getpalette(void *p); + void gl_setrgbpalette(void); + + +#ifdef __cplusplus +} + +#endif +#endif diff --git a/svgalib/vgakeyboard.h b/svgalib/vgakeyboard.h new file mode 100644 index 0000000..914ca88 --- /dev/null +++ b/svgalib/vgakeyboard.h @@ -0,0 +1,198 @@ +/* Keyboard interface for svgalib. */ +/* Can be used independently. */ + +#ifndef VGAKEYBOARD_H +#define VGAKEYBOARD_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define SCANCODE_ESCAPE 1 + +#define SCANCODE_1 2 +#define SCANCODE_2 3 +#define SCANCODE_3 4 +#define SCANCODE_4 5 +#define SCANCODE_5 6 +#define SCANCODE_6 7 +#define SCANCODE_7 8 +#define SCANCODE_8 9 +#define SCANCODE_9 10 +#define SCANCODE_0 11 + +#define SCANCODE_MINUS 12 +#define SCANCODE_EQUAL 13 + +#define SCANCODE_BACKSPACE 14 +#define SCANCODE_TAB 15 + +#define SCANCODE_Q 16 +#define SCANCODE_W 17 +#define SCANCODE_E 18 +#define SCANCODE_R 19 +#define SCANCODE_T 20 +#define SCANCODE_Y 21 +#define SCANCODE_U 22 +#define SCANCODE_I 23 +#define SCANCODE_O 24 +#define SCANCODE_P 25 +#define SCANCODE_BRACKET_LEFT 26 +#define SCANCODE_BRACKET_RIGHT 27 + +#define SCANCODE_ENTER 28 + +#define SCANCODE_LEFTCONTROL 29 + +#define SCANCODE_A 30 +#define SCANCODE_S 31 +#define SCANCODE_D 32 +#define SCANCODE_F 33 +#define SCANCODE_G 34 +#define SCANCODE_H 35 +#define SCANCODE_J 36 +#define SCANCODE_K 37 +#define SCANCODE_L 38 +#define SCANCODE_SEMICOLON 39 +#define SCANCODE_APOSTROPHE 40 +#define SCANCODE_GRAVE 41 + +#define SCANCODE_LEFTSHIFT 42 +#define SCANCODE_BACKSLASH 43 + +#define SCANCODE_Z 44 +#define SCANCODE_X 45 +#define SCANCODE_C 46 +#define SCANCODE_V 47 +#define SCANCODE_B 48 +#define SCANCODE_N 49 +#define SCANCODE_M 50 +#define SCANCODE_COMMA 51 +#define SCANCODE_PERIOD 52 +#define SCANCODE_SLASH 53 + +#define SCANCODE_RIGHTSHIFT 54 +#define SCANCODE_KEYPADMULTIPLY 55 + +#define SCANCODE_LEFTALT 56 +#define SCANCODE_SPACE 57 +#define SCANCODE_CAPSLOCK 58 + +#define SCANCODE_F1 59 +#define SCANCODE_F2 60 +#define SCANCODE_F3 61 +#define SCANCODE_F4 62 +#define SCANCODE_F5 63 +#define SCANCODE_F6 64 +#define SCANCODE_F7 65 +#define SCANCODE_F8 66 +#define SCANCODE_F9 67 +#define SCANCODE_F10 68 + +#define SCANCODE_NUMLOCK 69 +#define SCANCODE_SCROLLLOCK 70 + +#define SCANCODE_KEYPAD7 71 +#define SCANCODE_CURSORUPLEFT 71 +#define SCANCODE_KEYPAD8 72 +#define SCANCODE_CURSORUP 72 +#define SCANCODE_KEYPAD9 73 +#define SCANCODE_CURSORUPRIGHT 73 +#define SCANCODE_KEYPADMINUS 74 +#define SCANCODE_KEYPAD4 75 +#define SCANCODE_CURSORLEFT 75 +#define SCANCODE_KEYPAD5 76 +#define SCANCODE_KEYPAD6 77 +#define SCANCODE_CURSORRIGHT 77 +#define SCANCODE_KEYPADPLUS 78 +#define SCANCODE_KEYPAD1 79 +#define SCANCODE_CURSORDOWNLEFT 79 +#define SCANCODE_KEYPAD2 80 +#define SCANCODE_CURSORDOWN 80 +#define SCANCODE_KEYPAD3 81 +#define SCANCODE_CURSORDOWNRIGHT 81 +#define SCANCODE_KEYPAD0 82 +#define SCANCODE_KEYPADPERIOD 83 + +#define SCANCODE_LESS 86 + +#define SCANCODE_F11 87 +#define SCANCODE_F12 88 + +#define SCANCODE_KEYPADENTER 96 +#define SCANCODE_RIGHTCONTROL 97 +#define SCANCODE_CONTROL 97 +#define SCANCODE_KEYPADDIVIDE 98 +#define SCANCODE_PRINTSCREEN 99 +#define SCANCODE_RIGHTALT 100 +#define SCANCODE_BREAK 101 /* Beware: is 119 */ +#define SCANCODE_BREAK_ALTERNATIVE 119 /* on some keyboards! */ + +#define SCANCODE_HOME 102 +#define SCANCODE_CURSORBLOCKUP 103 /* Cursor key block */ +#define SCANCODE_PAGEUP 104 +#define SCANCODE_CURSORBLOCKLEFT 105 /* Cursor key block */ +#define SCANCODE_CURSORBLOCKRIGHT 106 /* Cursor key block */ +#define SCANCODE_END 107 +#define SCANCODE_CURSORBLOCKDOWN 108 /* Cursor key block */ +#define SCANCODE_PAGEDOWN 109 +#define SCANCODE_INSERT 110 +#define SCANCODE_REMOVE 111 + +#define SCANCODE_RIGHTWIN 126 +#define SCANCODE_LEFTWIN 125 + +#define KEY_EVENTRELEASE 0 +#define KEY_EVENTPRESS 1 + +#define MAX_KEYNAME_LEN 20 + +/* Initialize keyboard handler (brings keyboard into RAW mode). Returns */ +/* 0 if succesful, -1 otherwise. */ + int keyboard_init(void); +/* Similar, but returns console fd if succesful. */ + int keyboard_init_return_fd(void); +/* Set event handler invoked by keyboard_update(). */ + typedef void (*__keyboard_handler) (int scancode, int press); + void keyboard_seteventhandler(__keyboard_handler handler); +/* Return keyboard to normal state. */ + void keyboard_close(void); +/* Read raw keyboard device and handle events. Returns 0 if no event. */ + int keyboard_update(void); +/* Similar to keyboard_update, but wait for an event to happen. */ +/* [This doesn't seem to work very well -- use select on fd] */ + void keyboard_waitforupdate(void); + +/* keyboard_init sets default event handler that keeps track of complete */ +/* keyboard state: */ + +/* Result of keypressed. */ +#define KEY_NOTPRESSED 0 +#define KEY_PRESSED 1 + +/* Modes for translatekeys. */ +#define TRANSLATE_CURSORKEYS 1 /* Map cursor block to keypad cursor. */ +#define TRANSLATE_DIAGONAL 2 /* Map keypad diagonal to keypad cursor. */ +#define TRANSLATE_KEYPADENTER 4 /* Map keypad enter to main enter key. */ +#define DONT_CATCH_CTRLC 8 /* Disable Crtl-C check. */ + +/* Revert to default handler. */ + void keyboard_setdefaulteventhandler(void); +/* Return pointer to buffer holding state of each key (scancode). */ +/* Value 1 corresponds to key that is pressed, 0 means not pressed. */ + char *keyboard_getstate(void); +/* Force keyboard state to nothing pressed (all zeroes). */ + void keyboard_clearstate(void); +/* Let default handler translate cursor key block events to numeric keypad */ +/* cursor key events and other translations. */ + void keyboard_translatekeys(int mask); + +/* Return nonzero if key is depressed. */ + int keyboard_keypressed(int scancode); + +#ifdef __cplusplus +} + +#endif +#endif