paul@41 | 1 | /* |
paul@41 | 2 | * Common display-related functions. |
paul@41 | 3 | * |
paul@41 | 4 | * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@41 | 5 | * |
paul@41 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@41 | 7 | * it under the terms of the GNU General Public License as published by |
paul@41 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@41 | 9 | * (at your option) any later version. |
paul@41 | 10 | * |
paul@41 | 11 | * This program is distributed in the hope that it will be useful, |
paul@41 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@41 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@41 | 14 | * GNU General Public License for more details. |
paul@41 | 15 | * |
paul@41 | 16 | * You should have received a copy of the GNU General Public License |
paul@41 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@41 | 18 | */ |
paul@41 | 19 | |
paul@41 | 20 | #ifndef __DISPLAY_H__ |
paul@41 | 21 | #define __DISPLAY_H__ |
paul@41 | 22 | |
paul@41 | 23 | #include <stdint.h> |
paul@125 | 24 | #include "vga.h" |
paul@41 | 25 | |
paul@49 | 26 | |
paul@49 | 27 | |
paul@49 | 28 | /* Display configuration type. */ |
paul@49 | 29 | |
paul@49 | 30 | typedef struct |
paul@49 | 31 | { |
paul@93 | 32 | /* Framebuffer address, potentially referencing many frames. */ |
paul@49 | 33 | |
paul@49 | 34 | uint8_t *framebuffer; |
paul@93 | 35 | |
paul@93 | 36 | /* The total number of lines in the framebuffer including spare lines to |
paul@93 | 37 | support horizontal scrolling. */ |
paul@93 | 38 | |
paul@93 | 39 | uint32_t total_lines; |
paul@93 | 40 | |
paul@93 | 41 | /* The screen dimensions and size (derived from the dimensions). */ |
paul@93 | 42 | |
paul@49 | 43 | uint32_t line_length, line_count; /* width, height */ |
paul@93 | 44 | uint32_t screen_size; /* = width * height */ |
paul@93 | 45 | |
paul@93 | 46 | /* The current frame, number of frames, and the maximum number supported. */ |
paul@93 | 47 | |
paul@93 | 48 | int frame, frames, max_frames; |
paul@49 | 49 | |
paul@93 | 50 | /* The fixed start address of the current frame. */ |
paul@93 | 51 | |
paul@93 | 52 | uint8_t *frame_start; /* = framebuffer + (frame_size * frame) */ |
paul@93 | 53 | |
paul@93 | 54 | /* The floating screen start/top pointer. */ |
paul@93 | 55 | |
paul@93 | 56 | uint8_t *screen_start; /* >= frame_start; < screen_limit */ |
paul@49 | 57 | |
paul@115 | 58 | /* A pointer to a collection of screen start pointers, one per frame. */ |
paul@115 | 59 | |
paul@115 | 60 | uint8_t **screen_starts; |
paul@115 | 61 | |
paul@93 | 62 | /* The fixed end address of the current frame. */ |
paul@93 | 63 | |
paul@93 | 64 | uint8_t *screen_limit; /* = frame_start + screen_size */ |
paul@93 | 65 | |
paul@106 | 66 | /* Number of line channels used for pixel data transfers. */ |
paul@106 | 67 | |
paul@106 | 68 | int line_channels; |
paul@106 | 69 | |
paul@49 | 70 | /* Number of consecutive pixels provided by a framebuffer region. */ |
paul@49 | 71 | |
paul@56 | 72 | uint32_t cell_size; |
paul@56 | 73 | |
paul@49 | 74 | } display_config_t; |
paul@49 | 75 | |
paul@49 | 76 | |
paul@49 | 77 | |
paul@125 | 78 | /* Initialise a display. This macro depends on certain VGA constants being |
paul@125 | 79 | defined, and they are included above. |
paul@125 | 80 | |
paul@125 | 81 | Display(<name>, int width, int height, int frames) |
paul@125 | 82 | */ |
paul@123 | 83 | |
paul@123 | 84 | #define Display(NAME, WIDTH, HEIGHT, FRAMES) \ |
paul@123 | 85 | uint8_t __##NAME##_framebuffer[(WIDTH) * (HEIGHT + 1) * (FRAMES)]; \ |
paul@123 | 86 | uint8_t *__##NAME##_screen_starts[FRAMES]; \ |
paul@125 | 87 | \ |
paul@123 | 88 | display_config_t NAME = { \ |
paul@123 | 89 | .framebuffer=__##NAME##_framebuffer, \ |
paul@123 | 90 | .screen_starts=__##NAME##_screen_starts, \ |
paul@123 | 91 | \ |
paul@123 | 92 | .line_length=WIDTH, \ |
paul@123 | 93 | .line_count=HEIGHT, \ |
paul@123 | 94 | .screen_size=(WIDTH) * (HEIGHT), \ |
paul@123 | 95 | .total_lines=(HEIGHT + 1) * (FRAMES), \ |
paul@123 | 96 | .frame=0, \ |
paul@123 | 97 | .frames=FRAMES, \ |
paul@123 | 98 | .max_frames=FRAMES, \ |
paul@123 | 99 | \ |
paul@123 | 100 | .line_channels = LINE_CHANNELS, \ |
paul@125 | 101 | .cell_size = CELL_SIZE}; |
paul@123 | 102 | |
paul@93 | 103 | /* Configuration functions. */ |
paul@93 | 104 | |
paul@123 | 105 | void init_display(display_config_t *cfg); |
paul@93 | 106 | |
paul@115 | 107 | void init_display_properties(display_config_t *cfg); |
paul@93 | 108 | |
paul@115 | 109 | void init_frames(display_config_t *cfg); |
paul@115 | 110 | |
paul@115 | 111 | void display_select_frame(display_config_t *cfg, int frame); |
paul@93 | 112 | |
paul@116 | 113 | void display_select_next_frame(display_config_t *cfg); |
paul@116 | 114 | |
paul@111 | 115 | void display_set_frames(display_config_t *cfg, int frames); |
paul@93 | 116 | |
paul@115 | 117 | uint8_t *display_get_frame_start(display_config_t *cfg, int frame); |
paul@115 | 118 | |
paul@111 | 119 | uint32_t display_get_start_offset(display_config_t *cfg); |
paul@93 | 120 | |
paul@49 | 121 | /* Access functions. */ |
paul@49 | 122 | |
paul@111 | 123 | int display_get_position(display_config_t *cfg, int x); |
paul@74 | 124 | |
paul@111 | 125 | void display_copy(display_config_t *cfg, uint8_t *store, |
paul@140 | 126 | int width, int height, |
paul@74 | 127 | int x, int y, int key, int to_display); |
paul@41 | 128 | |
paul@111 | 129 | void display_copy_section(display_config_t *cfg, uint8_t *store, |
paul@83 | 130 | int width, int height, |
paul@140 | 131 | int xstart, int ystart, int xsize, int ysize, |
paul@83 | 132 | int x, int y, int key, int to_display); |
paul@83 | 133 | |
paul@111 | 134 | void display_scroll(display_config_t *cfg, int x, int y); |
paul@111 | 135 | |
paul@111 | 136 | void display_test_linedata(display_config_t *cfg); |
paul@83 | 137 | |
paul@100 | 138 | /* Address-related functions. */ |
paul@100 | 139 | |
paul@111 | 140 | uint8_t *display_wrap_pointer(display_config_t *cfg, uint8_t *ptr); |
paul@100 | 141 | |
paul@41 | 142 | #endif /* __DISPLAY_H__ */ |