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