1
/* BOGL - Ben's Own Graphics Library.
2
Written by Ben Pfaff <pfaffben@debian.org>.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of the
7
License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful, but
10
WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19
/* bogl-cfb.h: Common inline functions and data structures used by the
20
packed-pixel drivers. This should be considered an internal,
23
Written by David Huggins-Daines <dhd@debian.org> */
25
#include <sys/types.h>
30
unsigned int p0:4 __attribute__ ((packed));
31
unsigned int p1:4 __attribute__ ((packed));
32
} __attribute__ ((packed));
35
unsigned char bytes[3] __attribute__ ((packed));
36
} __attribute__ ((packed));
38
static inline unsigned int
39
get_var (volatile void* src, size_t off, size_t b)
45
/* FIXME: probably has endianness problems */
46
return ((u_int32_t*)(src))[off];
48
/* FIXME: probably also has endianness problems */
49
c = ((struct bits24*)(src))[off].bytes[2] << 16;
50
c += ((struct bits24*)(src))[off].bytes[1] << 8;
51
c += ((struct bits24*)(src))[off].bytes[0];
54
return ((unsigned short*)(src))[off];
56
return ((unsigned char*)(src))[off];
59
return ((struct bits4*)(src))[off/2].p1;
61
return ((struct bits4*)(src))[off/2].p0;
67
put_var (volatile void* dst, size_t off, unsigned int c, size_t b)
72
/* FIXME: probably has endianness problems */
73
((u_int32_t*)(dst))[off] = c;
76
/* FIXME: probably also has endianness problems */
77
((struct bits24*)(dst))[off].bytes[2] = (c >> 16);
78
((struct bits24*)(dst))[off].bytes[1] = (c >> 8);
79
((struct bits24*)(dst))[off].bytes[0] = c;
82
((unsigned short*)(dst))[off] = c;
85
((unsigned char*)(dst))[off] = c;
89
((struct bits4*)(dst))[off/2].p1 = c;
91
((struct bits4*)(dst))[off/2].p0 = c;
97
memset_24(void* d, unsigned int c, size_t len, size_t b)
99
unsigned char* dst = d;
103
/* We have to use a block of 3 regardless of the sizeof(int) */
104
unsigned int block[3];
105
const unsigned int bsiz = sizeof(unsigned int);
108
/* Yes we have to do it this way due to little-endian brain
110
put_var (block, 0, c, 24);
111
put_var (block, 1, c, 24);
112
put_var (block, 2, c, 24);
113
put_var (block, 3, c, 24);
115
if (sizeof(unsigned int) == 8)
117
put_var (block, 4, c, 24);
118
put_var (block, 5, c, 24);
119
put_var (block, 6, c, 24);
120
put_var (block, 7, c, 24);
123
/* Align to an int boundary */
124
while ((unsigned int)dst % sizeof(unsigned int))
126
put_var(dst, 0, c, 24);
135
((unsigned int*)(dst))[0] = block[0];
136
((unsigned int*)(dst))[1] = block[1];
137
((unsigned int*)(dst))[2] = block[2];
138
dst += sizeof(block);
144
/* Plot individual pixels */
147
put_var(dst, 0, c, 24);
154
memset_sub8(void* d, unsigned int c, ssize_t offset, size_t len, size_t b)
156
unsigned char* dst = d;
160
/* Align to one byte */
161
while (offset % (8 / b))
163
put_var (dst, offset, c, b);
167
dst += offset * b / 8;
170
for (i = 0; i*b < 8; i++)
171
put_var (&fill, i, c, b);
172
memset (dst, fill, len * b / 8);
177
for (i = 0; i < len; i++)
179
put_var (dst, i, c, b);
186
void* memset_var(void* d, unsigned int c, ssize_t offset,
187
size_t len, size_t b);