Mercurial > hg > index.fcgi > lj > lj046-2players
comparison src/fontdraw_engine.c @ 2:80a2761bd3a4
change DS keys (add alt. rotate)
author | paulo@localhost |
---|---|
date | Mon, 23 Mar 2009 01:19:12 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:54544824d04e |
---|---|
1 /* | |
2 Variable width font drawing library for DS (and GBA) | |
3 | |
4 Copyright 2007-2008 Damian Yerrick <pinoandchester@pineight.com> | |
5 | |
6 This work is provided 'as-is', without any express or implied | |
7 warranty. In no event will the authors be held liable for any | |
8 damages arising from the use of this work. | |
9 | |
10 Permission is granted to anyone to use this work for any purpose, | |
11 including commercial applications, and to alter it and redistribute | |
12 it freely, subject to the following restrictions: | |
13 | |
14 1. The origin of this work must not be misrepresented; you must | |
15 not claim that you wrote the original work. If you use | |
16 this work in a product, an acknowledgment in the product | |
17 documentation would be appreciated but is not required. | |
18 2. Altered source versions must be plainly marked as such, and must | |
19 not be misrepresented as being the original work. | |
20 3. This notice may not be removed or altered from any source | |
21 distribution. | |
22 | |
23 "Source" is the preferred form of a work for making changes to it. | |
24 | |
25 */ | |
26 /* | |
27 | |
28 Set FONTDRAW_SPLIT_COMPILE when compiling the time-sensitve parts | |
29 into a separate file to be placed in "fast" memory. | |
30 | |
31 */ | |
32 | |
33 | |
34 #ifdef FONTDRAW_SPLIT_COMPILE | |
35 typedef unsigned int u32; | |
36 extern const unsigned char vwfont_bin[]; | |
37 | |
38 typedef struct GlyphRec { | |
39 unsigned short dataOffset; | |
40 unsigned char glyphWidth; | |
41 unsigned char reserved; | |
42 } GlyphRec; | |
43 #endif | |
44 | |
45 unsigned int fontdraw_putchar(u32 *dst, unsigned int colStride, int wid, int x, int glyph) { | |
46 glyph &= 0xFF; | |
47 if (glyph < vwfont_bin[1]) { | |
48 return 0; | |
49 } | |
50 glyph -= vwfont_bin[1]; | |
51 if (vwfont_bin[2] != 0 && glyph >= vwfont_bin[2]) { | |
52 return 0; | |
53 } | |
54 const GlyphRec *glyphRec = | |
55 ((const GlyphRec *)(vwfont_bin + vwfont_bin[0])) + glyph; | |
56 const unsigned char *data = vwfont_bin + glyphRec->dataOffset; | |
57 unsigned int dataShift = 2; | |
58 unsigned int dataBits = *data++; | |
59 unsigned int pixelCode = dataBits & 0x03; | |
60 | |
61 // Convert x to tile column address and bit address within tile | |
62 dst += colStride * (x >> 3); | |
63 x = (x & 0x07) << 2; | |
64 | |
65 if (dataShift >= 8) { | |
66 dataShift = 2; | |
67 dataBits = *data++; | |
68 } | |
69 | |
70 for (unsigned int height = vwfont_bin[3]; | |
71 height > 0; | |
72 --height, ++dst) { | |
73 int eol = 0; | |
74 int xLine = x; | |
75 int widLeft = wid; | |
76 u32 *dstLine = dst; | |
77 u32 dstBits = *dstLine; | |
78 while (!eol) { | |
79 | |
80 // Process a pixel instruction | |
81 if (pixelCode == 0) { | |
82 eol = 1; | |
83 } else if (widLeft > 0) { | |
84 | |
85 // Change pixel and move to next pixel | |
86 if (pixelCode > 1) { | |
87 //dstBits &= ~(0x0F << xLine); | |
88 dstBits |= (pixelCode - 1) << xLine; | |
89 } | |
90 xLine += 4; | |
91 --widLeft; | |
92 } | |
93 | |
94 // If finished with this tile, write back changed bits | |
95 if (xLine >= 32) { | |
96 xLine = 0; | |
97 *dstLine = dstBits; | |
98 dstLine += colStride; | |
99 dstBits = *dstLine; | |
100 } | |
101 | |
102 // Decode next pixel instruction | |
103 if (dataShift >= 8) { | |
104 dataShift = 0; | |
105 dataBits = *data++; | |
106 } | |
107 | |
108 // Decode a byte into pixel instructions | |
109 pixelCode = (dataBits >> dataShift) & 0x03; | |
110 dataShift += 2; | |
111 } | |
112 | |
113 // Write back changed bits | |
114 if (xLine > 0) { | |
115 *dstLine = dstBits; | |
116 } | |
117 } | |
118 return glyphRec->glyphWidth; | |
119 } | |
120 | |
121 void vwfRectfillColumn(u32 *dst, unsigned int colStride, | |
122 unsigned int l, unsigned int t, | |
123 unsigned int r, unsigned int b, | |
124 unsigned int c) | |
125 { | |
126 u32 mask = 0xffffffffU << (4 * l); | |
127 mask &= 0xffffffffU >> (4 * (8 - r)); | |
128 c &= mask; | |
129 mask = ~mask; | |
130 | |
131 for (; t < b; t++) { | |
132 dst[t] = (dst[t] & mask) | c; | |
133 } | |
134 } | |
135 |