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 | #ifndef __DISPLAY_H__ |
paul@41 | 21 | #define __DISPLAY_H__ |
paul@41 | 22 | |
paul@41 | 23 | #include <stdint.h> |
paul@41 | 24 | |
paul@49 | 25 | |
paul@49 | 26 | |
paul@49 | 27 | /* Display configuration type. */ |
paul@49 | 28 | |
paul@49 | 29 | typedef struct |
paul@49 | 30 | { |
paul@93 | 31 | /* Framebuffer address, potentially referencing many frames. */ |
paul@49 | 32 | |
paul@49 | 33 | uint8_t *framebuffer; |
paul@93 | 34 | |
paul@93 | 35 | /* The total number of lines in the framebuffer including spare lines to |
paul@93 | 36 | support horizontal scrolling. */ |
paul@93 | 37 | |
paul@93 | 38 | uint32_t total_lines; |
paul@93 | 39 | |
paul@93 | 40 | /* The screen dimensions and size (derived from the dimensions). */ |
paul@93 | 41 | |
paul@49 | 42 | uint32_t line_length, line_count; /* width, height */ |
paul@93 | 43 | uint32_t screen_size; /* = width * height */ |
paul@93 | 44 | |
paul@93 | 45 | /* The current frame, number of frames, and the maximum number supported. */ |
paul@93 | 46 | |
paul@93 | 47 | int frame, frames, max_frames; |
paul@49 | 48 | |
paul@93 | 49 | /* The fixed start address of the current frame. */ |
paul@93 | 50 | |
paul@93 | 51 | uint8_t *frame_start; /* = framebuffer + (frame_size * frame) */ |
paul@93 | 52 | |
paul@93 | 53 | /* The floating screen start/top pointer. */ |
paul@93 | 54 | |
paul@93 | 55 | uint8_t *screen_start; /* >= frame_start; < screen_limit */ |
paul@49 | 56 | |
paul@93 | 57 | /* The fixed end address of the current frame. */ |
paul@93 | 58 | |
paul@93 | 59 | uint8_t *screen_limit; /* = frame_start + screen_size */ |
paul@93 | 60 | |
paul@93 | 61 | /* Number of scanlines on the display. */ |
paul@93 | 62 | |
paul@93 | 63 | uint32_t scanlines; |
paul@49 | 64 | |
paul@49 | 65 | /* Number of scanlines per display line. */ |
paul@49 | 66 | |
paul@93 | 67 | int line_multiplier; /* = scanlines / line_count */ |
paul@49 | 68 | |
paul@106 | 69 | /* Number of line channels used for pixel data transfers. */ |
paul@106 | 70 | |
paul@106 | 71 | int line_channels; |
paul@106 | 72 | |
paul@49 | 73 | /* Number of consecutive pixels provided by a framebuffer region. */ |
paul@49 | 74 | |
paul@56 | 75 | uint32_t cell_size; |
paul@56 | 76 | |
paul@56 | 77 | /* DMA transfer sizes. */ |
paul@56 | 78 | |
paul@56 | 79 | uint32_t transfer_cell_size; |
paul@49 | 80 | |
paul@53 | 81 | /* Display line positions. */ |
paul@53 | 82 | |
paul@53 | 83 | uint32_t hfreq_limit, hsync_start, hsync_end; |
paul@53 | 84 | |
paul@50 | 85 | /* Display region scanline positions. */ |
paul@50 | 86 | |
paul@50 | 87 | uint32_t visible_start, vfp_start, vsync_start, vsync_end; |
paul@50 | 88 | |
paul@49 | 89 | } display_config_t; |
paul@49 | 90 | |
paul@49 | 91 | |
paul@49 | 92 | |
paul@93 | 93 | /* Configuration functions. */ |
paul@93 | 94 | |
paul@93 | 95 | void init_display(display_config_t *cfg, uint8_t *framebuffer, |
paul@93 | 96 | uint32_t line_length, uint32_t line_count, int frames); |
paul@93 | 97 | |
paul@93 | 98 | void init_display_properties(display_config_t *cfg, uint32_t offset); |
paul@93 | 99 | |
paul@93 | 100 | void select_frame(display_config_t *cfg, int frame, uint32_t offset); |
paul@93 | 101 | |
paul@93 | 102 | void set_frames(display_config_t *cfg, int frames); |
paul@93 | 103 | |
paul@93 | 104 | uint32_t get_start_offset(display_config_t *cfg); |
paul@93 | 105 | |
paul@49 | 106 | /* Access functions. */ |
paul@49 | 107 | |
paul@49 | 108 | int get_position(display_config_t *cfg, int x); |
paul@74 | 109 | |
paul@49 | 110 | void test_linedata(display_config_t *cfg); |
paul@74 | 111 | |
paul@101 | 112 | void copy_display(display_config_t *cfg, uint8_t *store, |
paul@101 | 113 | int width, int height, int ystep, |
paul@74 | 114 | int x, int y, int key, int to_display); |
paul@41 | 115 | |
paul@83 | 116 | void copy_display_section(display_config_t *cfg, uint8_t *store, |
paul@83 | 117 | int width, int height, |
paul@101 | 118 | int xstart, int ystart, int xsize, int ysize, int ystep, |
paul@83 | 119 | int x, int y, int key, int to_display); |
paul@83 | 120 | |
paul@83 | 121 | void scroll_display(display_config_t *cfg, int x, int y); |
paul@83 | 122 | |
paul@100 | 123 | /* Address-related functions. */ |
paul@100 | 124 | |
paul@100 | 125 | uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper); |
paul@100 | 126 | |
paul@100 | 127 | uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr); |
paul@100 | 128 | |
paul@41 | 129 | #endif /* __DISPLAY_H__ */ |