Mercurial > hg > Game > Cerium
annotate old/simple_pack/fb.cpp @ 656:66810c71442b draft
branch merge
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 27 Nov 2009 18:27:32 +0900 |
parents | 3bc98f6d31ff |
children |
rev | line source |
---|---|
91 | 1 /* |
2 * fbtst.c | |
3 * 2006.7.19 Kensuke Ooyu | |
4 */ | |
5 #include <unistd.h> | |
6 #include <stdio.h> | |
7 #include <fcntl.h> | |
8 #include <linux/fb.h> | |
9 #include <linux/fs.h> | |
10 #include <sys/mman.h> | |
11 #include <sys/ioctl.h> | |
12 #include <stdlib.h> | |
78 | 13 #include <iostream> |
14 using namespace std; | |
15 | |
91 | 16 #define DEVICE_NAME "/dev/fb0" |
17 #define DIV_BYTE 8 | |
18 | |
19 #define X_PIXEL_MAX 320 | |
20 #define Y_LINE_MAX 240 | |
21 | |
22 #define BORDER1 80 | |
23 #define BORDER2 160 | |
24 | |
25 #define COLOR_RED 0xf800 | |
26 #define COLOR_GREEN 0x07e0 | |
27 #define COLOR_BLUE 0x001f | |
28 #define COLOR_WHITE 0xffff | |
29 #define COLOR_BLACK 0x0000 | |
30 #define COLOR_YELLOW 0xffe0 | |
31 | |
32 /* function prototype */ | |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
33 void send_current_error_msg(const char *ptr); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
34 void send_current_information(const char *ptr); |
91 | 35 |
36 int get_fbdev_addr(void) | |
37 { | |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
38 int fd_framebuffer ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
39 struct fb_var_screeninfo vinfo; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
40 struct fb_fix_screeninfo finfo; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
41 long int screensize ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
42 long int location; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
43 char *fbptr ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
44 char tmp[DIV_BYTE*10]; |
91 | 45 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
46 int x , y ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
47 int xres,yres,vbpp,line_len; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
48 unsigned short tcolor ; |
78 | 49 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
50 /* 読み書き用にファイルを開く */ |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
51 fd_framebuffer = open( DEVICE_NAME , O_RDWR); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
52 if ( !fd_framebuffer ) { |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
53 send_current_error_msg("Framebuffer device open error !"); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
54 exit(1); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
55 } |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
56 send_current_information("The framebuffer device was opened !"); |
91 | 57 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
58 /* 固定スクリーン情報取得 */ |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
59 if ( ioctl( fd_framebuffer , FBIOGET_FSCREENINFO , &finfo ) ) { |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
60 send_current_error_msg("Fixed information not gotton !"); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
61 exit(2); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
62 } |
78 | 63 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
64 /* 変動スクリーン情報取得 */ |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
65 if ( ioctl( fd_framebuffer , FBIOGET_VSCREENINFO , &vinfo ) ) { |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
66 send_current_error_msg("Variable information not gotton !"); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
67 exit(3); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
68 } |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
69 xres = vinfo.xres ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
70 yres = vinfo.yres ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
71 vbpp = vinfo.bits_per_pixel ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
72 line_len = finfo.line_length ; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
73 sprintf( tmp , "%d(pixel)x%d(line), %dbpp(bits per pixel)",xres,yres,vbpp); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
74 send_current_information( tmp ); |
91 | 75 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
76 /* バイト単位でのスクリーンのサイズを計算 */ |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
77 screensize = xres * yres * vbpp / DIV_BYTE ; |
91 | 78 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
79 /* デバイスをメモリにマップする */ |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
80 fbptr = (char *)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd_framebuffer,0); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
81 if ( (int)fbptr == -1 ) { |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
82 send_current_error_msg("Don't get framebuffer device to memory !"); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
83 exit(4); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
84 } |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
85 send_current_information("The framebuffer device was mapped !"); |
91 | 86 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
87 printf("fb: %x \n",fbptr); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
88 return (int)fbptr; |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
89 //munmap(fbptr,screensize); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
90 //close(fd_framebuffer); |
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
91 //return 0; |
78 | 92 } |
93 | |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
94 void send_current_error_msg(const char *ptr) |
91 | 95 { |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
96 fprintf( stderr , "%s\n" , ptr ); |
91 | 97 } |
78 | 98 |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
99 void send_current_information(const char *ptr) |
91 | 100 { |
180
e3b7776b1420
いろいろ fix 。詳しくは TaskManager/Changelog、test_render/Changelog を
gongo@localhost.localdomain
parents:
91
diff
changeset
|
101 fprintf( stdout , "%s\n" , ptr ); |
78 | 102 } |