main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "u8x8.h"
  2. /*
  3. https://www.streamlinehq.com/icons/pixel?search=&icon=ico_94BhV342TAIclS4E
  4. Business_Product_Startup_1__Streamline_Pixel
  5. Made by Streamline
  6. 24x24 XBM
  7. */
  8. static unsigned char startup_xbm[] = {
  9. 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x24, 0x00, 0x00, 0x42, 0x00,
  10. 0x00, 0xff, 0x00, 0x00, 0x81, 0x00, 0x80, 0x18, 0x01, 0x80, 0x34, 0x01,
  11. 0x80, 0x3c, 0x01, 0xc0, 0x18, 0x03, 0xa0, 0x00, 0x05, 0x90, 0x40, 0x09,
  12. 0x90, 0x00, 0x09, 0xd0, 0x40, 0x0b, 0xb0, 0x00, 0x0d, 0x10, 0xff, 0x08,
  13. 0x00, 0x42, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x80, 0xa5, 0x01,
  14. 0x6c, 0x24, 0x36, 0x12, 0x42, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  15. u8x8_t u8x8;
  16. uint8_t *get_tile_from_xbm(uint8_t tx, uint8_t ty, uint8_t xbm_byte_width, const unsigned char *xbm)
  17. {
  18. static uint8_t d[8];
  19. uint8_t mask = 1;
  20. uint8_t i;
  21. const uint8_t *p = xbm;
  22. p += tx;
  23. p += xbm_byte_width*ty*8;
  24. for( i = 0; i < 8; i++ )
  25. d[i] = 0;
  26. for( i = 0; i < 8; i++ )
  27. {
  28. if ( *p & 1 ) d[0] |= mask;
  29. if ( *p & 2 ) d[1] |= mask;
  30. if ( *p & 4 ) d[2] |= mask;
  31. if ( *p & 8 ) d[3] |= mask;
  32. if ( *p & 16 ) d[4] |= mask;
  33. if ( *p & 32 ) d[5] |= mask;
  34. if ( *p & 64 ) d[6] |= mask;
  35. if ( *p & 128 ) d[7] |= mask;
  36. mask <<= 1;
  37. p += xbm_byte_width;
  38. }
  39. return d;
  40. }
  41. void u8x8_draw_xbm(uint8_t tx, uint8_t ty, uint8_t xbm_width, uint8_t xbm_height, const unsigned char *xbm)
  42. {
  43. uint8_t x, y;
  44. uint8_t *tile;
  45. for( y = 0; y < xbm_height/8; y++ )
  46. {
  47. for( x = 0; x < xbm_width/8; x++ )
  48. {
  49. tile = get_tile_from_xbm(x, y, xbm_width/8, xbm);
  50. u8x8_DrawTile(&u8x8, tx+x, ty+y, 1, tile);
  51. // u8x8.drawTile(tx+x, ty+y, 1, tile);
  52. }
  53. }
  54. }
  55. int main(void)
  56. {
  57. u8x8_Setup_SDL_128x64(&u8x8);
  58. u8x8_InitDisplay(&u8x8);
  59. u8x8_draw_xbm(1, 1, 24, 24, startup_xbm);
  60. while( u8g_sdl_get_key() < 0 )
  61. ;
  62. return 0;
  63. }