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@115 | 57 | /* A pointer to a collection of screen start pointers, one per frame. */ |
paul@115 | 58 | |
paul@115 | 59 | uint8_t **screen_starts; |
paul@115 | 60 | |
paul@93 | 61 | /* The fixed end address of the current frame. */ |
paul@93 | 62 | |
paul@93 | 63 | uint8_t *screen_limit; /* = frame_start + screen_size */ |
paul@93 | 64 | |
paul@93 | 65 | /* Number of scanlines on the display. */ |
paul@93 | 66 | |
paul@93 | 67 | uint32_t scanlines; |
paul@49 | 68 | |
paul@49 | 69 | /* Number of scanlines per display line. */ |
paul@49 | 70 | |
paul@93 | 71 | int line_multiplier; /* = scanlines / line_count */ |
paul@49 | 72 | |
paul@106 | 73 | /* Number of line channels used for pixel data transfers. */ |
paul@106 | 74 | |
paul@106 | 75 | int line_channels; |
paul@106 | 76 | |
paul@49 | 77 | /* Number of consecutive pixels provided by a framebuffer region. */ |
paul@49 | 78 | |
paul@56 | 79 | uint32_t cell_size; |
paul@56 | 80 | |
paul@56 | 81 | /* DMA transfer sizes. */ |
paul@56 | 82 | |
paul@56 | 83 | uint32_t transfer_cell_size; |
paul@49 | 84 | |
paul@53 | 85 | /* Display line positions. */ |
paul@53 | 86 | |
paul@53 | 87 | uint32_t hfreq_limit, hsync_start, hsync_end; |
paul@53 | 88 | |
paul@50 | 89 | /* Display region scanline positions. */ |
paul@50 | 90 | |
paul@50 | 91 | uint32_t visible_start, vfp_start, vsync_start, vsync_end; |
paul@50 | 92 | |
paul@49 | 93 | } display_config_t; |
paul@49 | 94 | |
paul@49 | 95 | |
paul@49 | 96 | |
paul@123 | 97 | /* Initialise a display. */ |
paul@123 | 98 | |
paul@123 | 99 | #define Display(NAME, WIDTH, HEIGHT, FRAMES) \ |
paul@123 | 100 | uint8_t __##NAME##_framebuffer[(WIDTH) * (HEIGHT + 1) * (FRAMES)]; \ |
paul@123 | 101 | uint8_t *__##NAME##_screen_starts[FRAMES]; \ |
paul@123 | 102 | display_config_t NAME = { \ |
paul@123 | 103 | .framebuffer=__##NAME##_framebuffer, \ |
paul@123 | 104 | .screen_starts=__##NAME##_screen_starts, \ |
paul@123 | 105 | \ |
paul@123 | 106 | .line_length=WIDTH, \ |
paul@123 | 107 | .line_count=HEIGHT, \ |
paul@123 | 108 | .screen_size=(WIDTH) * (HEIGHT), \ |
paul@123 | 109 | .total_lines=(HEIGHT + 1) * (FRAMES), \ |
paul@123 | 110 | .frame=0, \ |
paul@123 | 111 | .frames=FRAMES, \ |
paul@123 | 112 | .max_frames=FRAMES, \ |
paul@123 | 113 | \ |
paul@123 | 114 | .scanlines = SCANLINES, \ |
paul@123 | 115 | .line_channels = LINE_CHANNELS, \ |
paul@123 | 116 | .cell_size = CELL_SIZE, \ |
paul@123 | 117 | .transfer_cell_size = TRANSFER_CELL_SIZE, \ |
paul@123 | 118 | \ |
paul@123 | 119 | .hfreq_limit = HFREQ_LIMIT, \ |
paul@123 | 120 | .hsync_start = HSYNC_START, \ |
paul@123 | 121 | .hsync_end = HSYNC_END, \ |
paul@123 | 122 | .visible_start = VISIBLE_START, \ |
paul@123 | 123 | .vfp_start = VFP_START, \ |
paul@123 | 124 | .vsync_start = VSYNC_START, \ |
paul@123 | 125 | .vsync_end = VSYNC_END}; |
paul@123 | 126 | |
paul@93 | 127 | /* Configuration functions. */ |
paul@93 | 128 | |
paul@123 | 129 | void init_display(display_config_t *cfg); |
paul@93 | 130 | |
paul@115 | 131 | void init_display_properties(display_config_t *cfg); |
paul@93 | 132 | |
paul@115 | 133 | void init_frames(display_config_t *cfg); |
paul@115 | 134 | |
paul@115 | 135 | void display_select_frame(display_config_t *cfg, int frame); |
paul@93 | 136 | |
paul@116 | 137 | void display_select_next_frame(display_config_t *cfg); |
paul@116 | 138 | |
paul@111 | 139 | void display_set_frames(display_config_t *cfg, int frames); |
paul@93 | 140 | |
paul@115 | 141 | uint8_t *display_get_frame_start(display_config_t *cfg, int frame); |
paul@115 | 142 | |
paul@111 | 143 | uint32_t display_get_start_offset(display_config_t *cfg); |
paul@93 | 144 | |
paul@49 | 145 | /* Access functions. */ |
paul@49 | 146 | |
paul@111 | 147 | int display_get_position(display_config_t *cfg, int x); |
paul@74 | 148 | |
paul@111 | 149 | void display_copy(display_config_t *cfg, uint8_t *store, |
paul@101 | 150 | int width, int height, int ystep, |
paul@74 | 151 | int x, int y, int key, int to_display); |
paul@41 | 152 | |
paul@111 | 153 | void display_copy_section(display_config_t *cfg, uint8_t *store, |
paul@83 | 154 | int width, int height, |
paul@101 | 155 | int xstart, int ystart, int xsize, int ysize, int ystep, |
paul@83 | 156 | int x, int y, int key, int to_display); |
paul@83 | 157 | |
paul@111 | 158 | void display_scroll(display_config_t *cfg, int x, int y); |
paul@111 | 159 | |
paul@111 | 160 | void display_test_linedata(display_config_t *cfg); |
paul@83 | 161 | |
paul@100 | 162 | /* Address-related functions. */ |
paul@100 | 163 | |
paul@111 | 164 | uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr); |
paul@100 | 165 | |
paul@41 | 166 | #endif /* __DISPLAY_H__ */ |