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