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 /* The fixed end address of the current frame. */ 58 59 uint8_t *screen_limit; /* = frame_start + screen_size */ 60 61 /* Number of scanlines on the display. */ 62 63 uint32_t scanlines; 64 65 /* Number of scanlines per display line. */ 66 67 int line_multiplier; /* = scanlines / line_count */ 68 69 /* Number of line channels used for pixel data transfers. */ 70 71 int line_channels; 72 73 /* Number of consecutive pixels provided by a framebuffer region. */ 74 75 uint32_t cell_size; 76 77 /* DMA transfer sizes. */ 78 79 uint32_t transfer_cell_size; 80 81 /* Display line positions. */ 82 83 uint32_t hfreq_limit, hsync_start, hsync_end; 84 85 /* Display region scanline positions. */ 86 87 uint32_t visible_start, vfp_start, vsync_start, vsync_end; 88 89 } display_config_t; 90 91 92 93 /* Configuration functions. */ 94 95 void init_display(display_config_t *cfg, uint8_t *framebuffer, 96 uint32_t line_length, uint32_t line_count, int frames); 97 98 void init_display_properties(display_config_t *cfg, uint32_t offset); 99 100 void select_frame(display_config_t *cfg, int frame, uint32_t offset); 101 102 void set_frames(display_config_t *cfg, int frames); 103 104 uint32_t get_start_offset(display_config_t *cfg); 105 106 /* Access functions. */ 107 108 int get_position(display_config_t *cfg, int x); 109 110 void test_linedata(display_config_t *cfg); 111 112 void copy_display(display_config_t *cfg, uint8_t *store, 113 int width, int height, int ystep, 114 int x, int y, int key, int to_display); 115 116 void copy_display_section(display_config_t *cfg, uint8_t *store, 117 int width, int height, 118 int xstart, int ystart, int xsize, int ysize, int ystep, 119 int x, int y, int key, int to_display); 120 121 void scroll_display(display_config_t *cfg, int x, int y); 122 123 /* Address-related functions. */ 124 125 uint8_t *wrap_pointer(uint8_t *ptr, uint8_t *lower, uint8_t *upper); 126 127 uint8_t *wrap_screen_pointer(display_config_t *cfg, uint8_t *ptr); 128 129 #endif /* __DISPLAY_H__ */