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