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 line channels used for pixel data transfers. */ 67 68 int line_channels; 69 70 /* Number of consecutive pixels provided by a framebuffer region. */ 71 72 uint32_t cell_size; 73 74 } display_config_t; 75 76 77 78 /* Initialise a display. This macro depends on certain VGA constants being 79 defined, and they are included above. 80 81 Display(<name>, int width, int height, int frames) 82 */ 83 84 #define Display(NAME, WIDTH, HEIGHT, FRAMES) \ 85 uint8_t __##NAME##_framebuffer[(WIDTH) * (HEIGHT + 1) * (FRAMES)]; \ 86 uint8_t *__##NAME##_screen_starts[FRAMES]; \ 87 \ 88 display_config_t NAME = { \ 89 .framebuffer=__##NAME##_framebuffer, \ 90 .screen_starts=__##NAME##_screen_starts, \ 91 \ 92 .line_length=WIDTH, \ 93 .line_count=HEIGHT, \ 94 .screen_size=(WIDTH) * (HEIGHT), \ 95 .total_lines=(HEIGHT + 1) * (FRAMES), \ 96 .frame=0, \ 97 .frames=FRAMES, \ 98 .max_frames=FRAMES, \ 99 \ 100 .line_channels = LINE_CHANNELS, \ 101 .cell_size = CELL_SIZE}; 102 103 /* Configuration functions. */ 104 105 void init_display(display_config_t *cfg); 106 107 void init_display_properties(display_config_t *cfg); 108 109 void init_frames(display_config_t *cfg); 110 111 void display_select_frame(display_config_t *cfg, int frame); 112 113 void display_select_next_frame(display_config_t *cfg); 114 115 void display_set_frames(display_config_t *cfg, int frames); 116 117 uint8_t *display_get_frame_start(display_config_t *cfg, int frame); 118 119 uint32_t display_get_start_offset(display_config_t *cfg); 120 121 /* Access functions. */ 122 123 int display_get_position(display_config_t *cfg, int x); 124 125 void display_copy(display_config_t *cfg, uint8_t *store, 126 int width, int height, 127 int x, int y, int key, int to_display); 128 129 void display_copy_section(display_config_t *cfg, uint8_t *store, 130 int width, int height, 131 int xstart, int ystart, int xsize, int ysize, 132 int x, int y, int key, int to_display); 133 134 void display_scroll(display_config_t *cfg, int x, int y); 135 136 void display_test_linedata(display_config_t *cfg); 137 138 /* Address-related functions. */ 139 140 uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr); 141 142 #endif /* __DISPLAY_H__ */