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 /* Configuration functions. */ 98 99 void init_display(display_config_t *cfg, uint8_t *framebuffer, 100 uint32_t line_length, uint32_t line_count, 101 int frames, uint8_t **screen_starts); 102 103 void init_display_properties(display_config_t *cfg); 104 105 void init_frames(display_config_t *cfg); 106 107 void display_select_frame(display_config_t *cfg, int frame); 108 109 void display_set_frames(display_config_t *cfg, int frames); 110 111 uint8_t *display_get_frame_start(display_config_t *cfg, int frame); 112 113 uint32_t display_get_start_offset(display_config_t *cfg); 114 115 /* Access functions. */ 116 117 int display_get_position(display_config_t *cfg, int x); 118 119 void display_copy(display_config_t *cfg, uint8_t *store, 120 int width, int height, int ystep, 121 int x, int y, int key, int to_display); 122 123 void display_copy_section(display_config_t *cfg, uint8_t *store, 124 int width, int height, 125 int xstart, int ystart, int xsize, int ysize, int ystep, 126 int x, int y, int key, int to_display); 127 128 void display_scroll(display_config_t *cfg, int x, int y); 129 130 void display_test_linedata(display_config_t *cfg); 131 132 /* Address-related functions. */ 133 134 uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr); 135 136 #endif /* __DISPLAY_H__ */