2 #include "oswald_strings.h"
3 #include "oswald_fonts.h"
4 #include "oswald_hal.h"
6 #include "oswald_graphics.h"
8 // dummies for MW replacement stuff
10 void SetFont(etFontType Type)
14 u8t WriteLcdString(const uint8_t x, const uint8_t y, const char *str)
19 void WriteLcdNumber(const uint8_t x, const uint8_t y, const int16_t number)
23 u8t WriteLcdCharacter(const uint8_t x, const uint8_t y, const uint8_t Character)
29 void oswald_draw_bitmap_offset(const unsigned int xstart, const unsigned int ystart, const unsigned int xoff, const unsigned int yoff, const unsigned int width, const unsigned int height, const void *bmp)
37 // we only draw set pixel, unset pixel remain as they are
38 for (y=yoff; y<height; y++) {
39 for (x=xoff; x<width; x++) {
40 cb = (uint8_t *)(bmp + (y * ((width / 8) + ((width % 8) ? 1 : 0))) + (x / 8));
41 if (*cb & (1 << (x % 8)))
42 hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
48 /*inline*/ void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
53 // we only draw set pixel, unset pixel remain as they are
54 for (y=0; y<height; y++) {
55 for (x=0; x<width; x++) {
56 cb = (uint8_t *)(bmp + (y * ((width / 8) + ((width % 8) ? 1 : 0))) + (x / 8));
57 if (*cb & (1 << (x % 8)))
58 hal_lcd_set_pixel((xstart + x), (ystart + y), TRUE);
63 void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
65 // seems we are triggering a MSPGCC compiler bug here...
66 // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
67 volatile unsigned int num;
69 num = (unsigned int) bmp;
71 oswald_draw_bitmap_offset(xstart, ystart, 0, 0, width, height, bmp);
75 void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend)
77 int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
82 incx = (dx >= 0) ? 1 : -1;
83 incy = (dy >= 0) ? 1 : -1;
103 hal_lcd_set_pixel(x, y, TRUE);
105 for (t = 0; t < el; ++t) {
115 hal_lcd_set_pixel(x, y, TRUE);
117 // hal_lcd_update_display();
120 void oswald_draw_line_ww(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend, const uint8_t thickness)
122 int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
127 incx = (dx >= 0) ? 1 : -1;
128 incy = (dy >= 0) ? 1 : -1;
154 hal_lcd_set_pixel(x, y, TRUE);
155 for (i=1; i<thickness; i++) {
156 hal_lcd_set_pixel(x-i, y, TRUE);
157 hal_lcd_set_pixel(x+i, y, TRUE);
158 hal_lcd_set_pixel(x, y-i, TRUE);
159 hal_lcd_set_pixel(x, y+i, TRUE);
162 for (t = 0; t < el; ++t) {
172 hal_lcd_set_pixel(x, y, TRUE);
173 for (i=1; i<thickness; i++) {
174 hal_lcd_set_pixel(x-i, y, TRUE);
175 hal_lcd_set_pixel(x+i, y, TRUE);
176 hal_lcd_set_pixel(x, y-i, TRUE);
177 hal_lcd_set_pixel(x, y+i, TRUE);
180 // hal_lcd_update_display();
183 uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_font_face face, const uint8_t Character)
186 u8t CharacterHeight = GetCharacterHeight();
187 u8t CharacterWidth = GetCharacterWidth(Character);
188 u16t bitmap[MAX_FONT_ROWS];
191 GetCharacterBitmap(Character, bitmap);
193 // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
194 for (ly=0; ly<CharacterHeight; ly++) {
195 for (lx=0; lx<CharacterWidth; lx++) {
196 if (bitmap[ly] & (1<<lx)) {
197 hal_lcd_set_pixel(lx+x, ly+y, TRUE);
200 hal_lcd_set_pixel(lx+x, ly+y, FALSE);
207 return CharacterWidth + GetFontSpacing();
209 uint8_t *cdata = oswald_fonts[face].data;
212 if (Character == 32) // space / blank
213 return oswald_fonts[face].width / 2;
215 csize = ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * oswald_fonts[face].height;
216 //csize += (oswald_fonts[face].height / 8) + ((oswald_fonts[face].height % 8) ? 1 : 0);
218 // g_printerr("fp = 0x%08lx cdata = 0x%08lx\n", font_7x12, cdata);
220 cdata = (cdata + (csize * (int)Character));
222 //g_printerr("%02x\n", oswald_fonts[face].data[0][0]);
223 //g_printerr("char %02x face %d %dx%d csize %d\n", Character, face, oswald_fonts[face].width, oswald_fonts[face].height, csize);
224 //g_printerr("char %02x %02x %02x\n", (uint8_t)cdata[0], (uint8_t)cdata[1], (uint8_t)cdata[2]);
226 // oswald_draw_bitmap(x, y, oswald_fonts[face].height, oswald_fonts[face].height, cdata);
227 //oswald_draw_bitmap(x, y, ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8, oswald_fonts[face].height, cdata);
228 oswald_draw_bitmap_offset(x, y, (oswald_fonts[face].width % 8) > 0 ? (8-(oswald_fonts[face].width % 8)) : 0, 0, ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8, oswald_fonts[face].height, cdata);
230 return oswald_fonts[face].width;
234 void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, char *str)
238 strl = oswald_strlen(str);
243 for (i=0; i<strl; i++) {
244 lx += oswald_write_character(lx, y, face, str[i]);
249 void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const int16_t number)
254 itoa(number, str, 10);
255 strl = oswald_strlen(str);
260 for (i=0; i<strl; i++) {
261 lx += oswald_write_character(lx, y, face, str[i]);