1 /* 2 * Common display-related functions. 3 * 4 * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "display.h" 21 22 23 24 /* Return the line data position for the given pixel. */ 25 26 int get_position(display_config_t *cfg, int x) 27 { 28 int cell = x / cfg->cell_size, offset = x % cfg->cell_size; 29 int pos = (cell / 2) * cfg->cell_size + offset; 30 31 return cell % 2 ? pos + cfg->line_length / 2 : pos; 32 } 33 34 /* Provide a pattern to test the line data. */ 35 36 void test_linedata(display_config_t *cfg) 37 { 38 int x, y; 39 uint8_t *linedata = cfg->framebuffer; 40 41 for (y = 0; y < cfg->line_count; y++) 42 { 43 for (x = 0; x < cfg->line_length; x++) 44 { 45 /* Pixel: I0RRGGBB = Y0YYYYXX */ 46 47 linedata[get_position(cfg, x)] = (x % 2) ? 48 (((y / (cfg->line_count / 32)) & 0b1) << 7) | 49 (((y / (cfg->line_count / 16)) & 0b1111) << 2) | 50 ((x / (cfg->line_length / 4)) & 0b11) : 51 0x00; 52 } 53 54 linedata += cfg->line_length; 55 } 56 }