|
17 | 17 |
|
18 | 18 | static uint16_t s_palette[256] __attribute((section(".fastdata"))); |
19 | 19 |
|
| 20 | +static uint16_t nearest_x_lut[96] __attribute((section(".fastdata"))); |
| 21 | +static uint8_t nearest_y_lut[64] __attribute((section(".fastdata"))); |
| 22 | + |
20 | 23 | void I_InitGraphics (void) { |
21 | | - // Only initialize once. |
22 | | - static int initialized = 0; |
23 | | - if (initialized!=0) |
24 | | - return; |
25 | | - initialized = 1; |
26 | | - screens[0] = (unsigned char*)malloc (SCREENWIDTH * SCREENHEIGHT); |
| 24 | + // Only initialize once. |
| 25 | + static int initialized = 0; |
| 26 | + if (initialized!=0) |
| 27 | + return; |
| 28 | + initialized = 1; |
| 29 | + |
| 30 | + screens[0] = (unsigned char*)malloc (SCREENWIDTH * SCREENHEIGHT); |
27 | 31 | if (screens[0] == NULL) |
28 | 32 | I_Error ("Couldn't allocate screen memory"); |
29 | | - oled_init(); |
| 33 | + |
| 34 | + float scaleX = (float)SCREENWIDTH / OLED_WIDTH; |
| 35 | + float scaleY = (float)SCREENHEIGHT / OLED_HEIGHT; |
| 36 | + |
| 37 | + for (uint8_t y = 0; y < OLED_HEIGHT; ++y) { |
| 38 | + uint8_t iy = (uint8_t)(y * scaleY); |
| 39 | + nearest_y_lut[y] = iy; |
| 40 | + } |
| 41 | + |
| 42 | + for(uint16_t x = 0; x < OLED_WIDTH; ++x){ |
| 43 | + uint16_t ix = (uint16_t)(x * scaleX); |
| 44 | + nearest_x_lut[x] = ix; |
| 45 | + } |
| 46 | + |
| 47 | + oled_init(); |
30 | 48 | } |
31 | 49 |
|
32 | 50 | void I_ShutdownGraphics (void) { |
@@ -66,19 +84,24 @@ static inline void oled_data_uint16_raw(uint16_t RGB) { |
66 | 84 | void I_FinishUpdate (void) { |
67 | 85 | #ifdef CSR_OLED_SPI_BASE |
68 | 86 | const unsigned char* src = (const unsigned char*)screens[0]; |
69 | | - // Resolution / 4, a centered 80x50 window |
70 | | - oled_write_window(8,7,87,56); |
| 87 | + |
| 88 | + oled_write_window(0,0,95,63); |
| 89 | + |
71 | 90 | const unsigned char* line_ptr = src; |
72 | 91 |
|
73 | 92 | oled_ctl_out_write(OLED_SPI_DAT); |
74 | 93 | oled_spi_cs_write(OLED_SPI_CS_LOW); |
75 | | - for(int y=0; y<200; y+=4) { |
76 | | - for(int x=0; x<320; x+=4) { |
77 | | - uint16_t pixelvalue = s_palette[line_ptr[x]]; |
| 94 | + |
| 95 | + for(int y=0; y<OLED_HEIGHT; y++) { |
| 96 | + for(int x=0; x<OLED_WIDTH; x++) { |
| 97 | + |
| 98 | + uint16_t pixelvalue = s_palette[line_ptr[(int)nearest_x_lut[x]]]; |
78 | 99 | oled_data_uint16_raw(pixelvalue); |
| 100 | + |
79 | 101 | } |
80 | | - line_ptr += 4*320; |
| 102 | + line_ptr = src + nearest_y_lut[y]*SCREENWIDTH; |
81 | 103 | } |
| 104 | + |
82 | 105 | oled_spi_cs_write(OLED_SPI_CS_HIGH); |
83 | 106 | #endif |
84 | 107 |
|
|
0 commit comments