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 /* Provided by the application. */ 23 24 #include "vga.h" 25 26 27 28 /* Return the line data position for the given pixel. */ 29 30 int get_position(int x) 31 { 32 int cell = x / CELL_SIZE, offset = x % CELL_SIZE; 33 int pos = (cell / 2) * CELL_SIZE + offset; 34 35 return cell % 2 ? pos + LINE_LENGTH / 2 : pos; 36 } 37 38 /* Provide a pattern to test the line data. */ 39 40 void test_linedata(uint8_t *framebuffer) 41 { 42 int x, y; 43 uint8_t *linedata = framebuffer; 44 45 for (y = 0; y < LINE_COUNT; y++) 46 { 47 for (x = 0; x < LINE_LENGTH; x++) 48 { 49 /* Pixel: I0RRGGBB = Y0YYYYXX */ 50 51 linedata[get_position(x)] = (x % 2) ? 52 (((y / (LINE_COUNT / 32)) & 0b1) << 7) | 53 (((y / (LINE_COUNT / 16)) & 0b1111) << 2) | 54 ((x / (LINE_LENGTH / 4)) & 0b11) : 55 0x00; 56 } 57 58 linedata += LINE_LENGTH; 59 } 60 }