1 #include <fxcg/display.h>
3 #include <fxcg/keyboard.h>
4 #include <fxcg/system.h>
7 #include <fxcg/serial.h>
15 #include "graphicsProvider.hpp"
17 const short empty
[18] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
18 int PrintMiniFix( int x
, int y
, const char*Msg
, const int flags
, const short color
, const short bcolor
)
27 drawLine(x
, y
+24+7, x
+11, y
+24+7, color
);
28 drawLine(x
, y
+24+8, x
+11, y
+24+8, color
);
32 } else if( Msg
[i
] == 31) {
33 // small dot for multiply
35 PrintMini(&tx
, &ty
, (unsigned char*)"\xe6\xaa", 0, 0xFFFFFFFF, 0, 0, color
, bcolor
, 1, 0);
39 } else p
= GetMiniGlyphPtr( Msg
[ i
], &width
);
40 dx
= ( 12 - width
) / 2;
43 PrintMiniGlyph( x
, y
, (void*)empty
, flags
, dx
, 0, 0, 0, 0, color
, bcolor
, 0 );
47 PrintMiniGlyph( x
+ dx
, y
, p
, flags
, width
, 0, 0, 0, 0, color
, bcolor
, 0 );
48 if ( width
+ dx
< 12 )
50 PrintMiniGlyph( x
+ width
+ dx
, y
, (void*)empty
, flags
, 12 - width
- dx
, 0, 0, 0, 0, color
, bcolor
, 0 );
58 //draws a point of color color at (x0, y0)
59 void plot(int x0
, int y0
,unsigned short color
) {
60 unsigned short* VRAM
= (unsigned short*)0xA8000000;
61 VRAM
+= (y0
*LCD_WIDTH_PX
+ x0
);
65 void drawRectangle(int x
, int y
, int width
, int height
, unsigned short color
){
66 unsigned short*VRAM
= (unsigned short*)0xA8000000;
76 //Uses the Bresenham line algorithm
77 void drawLine(int x1
, int y1
, int x2
, int y2
, int color
) {
81 // if x1 == x2 or y1 == y2, then it does not matter what we set here
82 int delta_x
= (x2
> x1
?(ix
= 1, x2
- x1
):(ix
= -1, x1
- x2
)) << 1;
83 int delta_y
= (y2
> y1
?(iy
= 1, y2
- y1
):(iy
= -1, y1
- y2
)) << 1;
86 if (delta_x
>= delta_y
) {
87 int error
= delta_y
- (delta_x
>> 1); // error may go below zero
90 if (error
|| (ix
> 0)) {
100 int error
= delta_x
- (delta_y
>> 1); // error may go below zero
103 if (error
|| (iy
> 0)) {
114 //ReplaceColor By Kerm:
115 /*void VRAMReplaceColorInRect(int x, int y, int width, int height, color_t color_old, color_t color_new) {
116 //color_t* VRAM = GetVRAMAddress();
117 color_t* VRAM = (color_t*)0xA8000000;
118 VRAM += (y*LCD_WIDTH_PX)+x;
119 for(int j=0; j<height; VRAM += (LCD_WIDTH_PX-width), j++) {
120 for(int i=0; i<width; VRAM++, i++) {
121 if (*VRAM == color_old) *VRAM = color_new;
125 /*void CopySprite(const void* datar, int x, int y, int width, int height) {
126 color_t*data = (color_t*) datar;
127 color_t* VRAM = (color_t*)0xA8000000;
128 VRAM += LCD_WIDTH_PX*y + x;
129 for(int j=y; j<y+height; j++) {
130 for(int i=x; i<x+width; i++) {
131 *(VRAM++) = *(data++);
133 VRAM += LCD_WIDTH_PX-width;
136 void CopySpriteMasked(unsigned short* data
, int x
, int y
, int width
, int height
, unsigned short maskcolor
) {
137 unsigned short* VRAM
= (unsigned short*)0xA8000000;
138 VRAM
+= (LCD_WIDTH_PX
*y
+ x
);
142 if(*data
!=maskcolor
) {
143 *(VRAM
++) = *(data
++);
149 VRAM
+= (LCD_WIDTH_PX
-width
);
152 /*void CopySpriteNbit(const unsigned char* data, int x, int y, int width, int height, const color_t* palette, unsigned int bitwidth) {
153 color_t* VRAM = (color_t*)0xA8000000;
154 VRAM += (LCD_WIDTH_PX*y + x);
156 unsigned char buf = 0;
157 for(int j=y; j<y+height; j++) {
159 for(int i=x; i<x+width; i++) {
161 buf = data[offset++];
164 color_t thisthis = ((color_t)buf>>(8-bitwidth));
165 *VRAM = palette[(color_t)thisthis];
170 VRAM += (LCD_WIDTH_PX-width);
173 //the following does not update the screen automatically; it will draw the tny.im logo starting at screen coordinates x,y
174 //the tny.im logo is great enough not to require any sprites! yay!
177 static const unsigned char logoB
[]={
193 static const unsigned char logoO
[]={
203 void drawtnyimLogo(int x
, int y
) {
206 drawRectangle(x
+logoB
[i
], y
+logoB
[i
+1], logoB
[i
+2], logoB
[i
+3], COLOR_BLACK
);
208 drawRectangle(x
+logoO
[i
], y
+logoO
[i
+1], logoO
[i
+2], logoO
[i
+3], TNYIM_ORANGE
);
211 /*int textColorToFullColor(int textcolor) {
213 case TEXT_COLOR_BLACK: return COLOR_BLACK;
214 case TEXT_COLOR_BLUE: return COLOR_BLUE;
215 case TEXT_COLOR_GREEN: return COLOR_GREEN;
216 case TEXT_COLOR_CYAN: return COLOR_CYAN;
217 case TEXT_COLOR_RED: return COLOR_RED;
218 case TEXT_COLOR_PURPLE: return COLOR_PURPLE;
219 case TEXT_COLOR_YELLOW: return COLOR_YELLOW;
220 case TEXT_COLOR_WHITE: return COLOR_LIGHTGRAY;
221 default: return COLOR_BLACK;
225 void progressMessage(char* message, int cur, int total) {
226 char buffer[30] = "";
227 char buffer2[5] = "";
229 strcat(buffer, message);
230 strcat(buffer, " (");
231 itoa(cur, (unsigned char*)buffer2);
232 strcat(buffer, buffer2);
234 itoa(total, (unsigned char*)buffer2);
235 strcat(buffer, buffer2);
237 PrintXY(1,8,(char*)" ", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
238 PrintXY(1,8,(char*)buffer, TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
242 void printCentered(unsigned char* text
, int y
, int FGC
, int BGC
) {
243 int len
= strlen((char*)text
);
244 int x
= LCD_WIDTH_PX
/2-(len
*18)/2;
247 PrintCXY(x
, y
, &text
[cur
], 0x40, -1, FGC
, BGC
, 1, 0 );