1 /* 2 * VGA 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 __VGA_DISPLAY_H__ 21 #define __VGA_DISPLAY_H__ 22 23 #include "display.h" 24 #include "pic32_c.h" 25 #include "vga.h" 26 27 28 29 /* Display configuration type. */ 30 31 typedef struct 32 { 33 /* Current display state handler. */ 34 35 void (*state_handler)(); 36 37 /* Common transfer properties. */ 38 39 int line_timer; 40 uint32_t output; 41 42 /* DMA transfer properties. */ 43 44 int line_channels, transfer_int_num; 45 uint32_t transfer_cell_size; 46 47 /* Horizontal and vertical sync peripherals. */ 48 49 int hsync_unit, vsync_unit; 50 51 /* Current scanline and pixel line. */ 52 53 uint32_t scanline, line; 54 uint8_t *linedata; 55 56 /* Separate display windows dividing the display vertically. */ 57 58 int window, windows, max_windows; 59 60 /* A collection of line numbers ending each window. */ 61 62 uint32_t *window_end; 63 64 /* The start, limit and size of the screen are copied to this structure, 65 allowing the display configuration to use different values such as those 66 for a different display frame. */ 67 68 /* Screen start address, frame limit. */ 69 70 uint8_t **screen_start, **screen_limit; 71 72 /* Screen size, used to wrap the current line pointer. */ 73 74 uint32_t *screen_size; 75 76 /* General display properties defined by the collection of windows. */ 77 78 uint32_t line_length, line_count; 79 80 /* Number of scanlines on the display. */ 81 82 uint32_t scanlines; 83 84 /* Number of scanlines per display line. */ 85 86 int line_multiplier; /* = scanlines / line_count */ 87 88 /* Display line positions. */ 89 90 uint32_t hfreq_limit, hsync_start, hsync_end; 91 92 /* Display region scanline positions. */ 93 94 uint32_t visible_start, vfp_start, vsync_start, vsync_end; 95 96 } vga_display_t; 97 98 99 100 /* Initialise a VGA display object with timing and pixel transfer details. 101 This macro depends on the VGA timing constants being defined, and they are 102 included above. 103 104 VGA_Display(<name>, int windows) 105 */ 106 107 #define VGA_Display(NAME, WINDOWS) \ 108 uint32_t __##NAME##_window_end[WINDOWS]; \ 109 uint8_t *__##NAME##_screen_start[WINDOWS]; \ 110 uint8_t *__##NAME##_screen_limit[WINDOWS]; \ 111 uint32_t __##NAME##_screen_size[WINDOWS]; \ 112 \ 113 vga_display_t NAME = { \ 114 .window_end = __##NAME##_window_end, \ 115 .screen_start = __##NAME##_screen_start, \ 116 .screen_limit = __##NAME##_screen_limit, \ 117 .screen_size = __##NAME##_screen_size, \ 118 .window = 0, \ 119 .windows = 0, \ 120 .max_windows = WINDOWS, \ 121 .transfer_cell_size = TRANSFER_CELL_SIZE, \ 122 .scanlines = SCANLINES, \ 123 .hfreq_limit = HFREQ_LIMIT, \ 124 .hsync_start = HSYNC_START, \ 125 .hsync_end = HSYNC_END, \ 126 .visible_start = VISIBLE_START, \ 127 .vfp_start = VFP_START, \ 128 .vsync_start = VSYNC_START, \ 129 .vsync_end = VSYNC_END}; 130 131 /* Initialisation functions. */ 132 133 void init_vga(display_config_t *display_config, int line_channels, 134 int line_timer, int transfer_int_num); 135 136 void init_vga_with_timers(display_config_t *display_config, int line_channels, 137 int line_timer, int transfer_timer); 138 139 void vga_configure_sync(int hsync_unit, int vsync_unit); 140 141 void vga_configure_transfer(uint32_t output); 142 143 void vga_configure_dma_transfer(uint32_t output); 144 145 /* Initialisation helpers. */ 146 147 void vga_configure_line_channel(int channel, int int_num, enum dma_chain chain, 148 uint32_t output); 149 150 void vga_configure_zero_channel(int channel, int int_num, int initiating, 151 uint32_t output); 152 153 void vga_update_properties(void); 154 155 /* Access-related operations. */ 156 157 void vga_add_window(display_config_t *display_config); 158 void vga_set_frame(display_config_t *display_config, int window); 159 void vga_wait_visible(void); 160 161 /* Interrupt handlers. */ 162 163 void vga_interrupt_handler(void); 164 void vga_hsync_interrupt_handler(void); 165 void vga_transfer_interrupt_handler(void); 166 167 /* Display state handlers. */ 168 169 void vbp_active(void); 170 void visible_active(void); 171 void vfp_active(void); 172 void vsync_active(void); 173 174 /* DMA transfer operations. */ 175 176 void start_visible(void); 177 void update_visible(void); 178 void stop_visible(void); 179 void update_transfers(int enable); 180 181 /* Vertical sync operations. */ 182 183 void vsync_high(void); 184 void vsync_low(void); 185 186 #endif /* __VGA_DISPLAY_H__ */