paul@50 | 1 | /* |
paul@50 | 2 | * Generate a VGA signal using a PIC32 microcontroller. |
paul@50 | 3 | * |
paul@50 | 4 | * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> |
paul@50 | 5 | * |
paul@50 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@50 | 7 | * it under the terms of the GNU General Public License as published by |
paul@50 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@50 | 9 | * (at your option) any later version. |
paul@50 | 10 | * |
paul@50 | 11 | * This program is distributed in the hope that it will be useful, |
paul@50 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@50 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@50 | 14 | * GNU General Public License for more details. |
paul@50 | 15 | * |
paul@50 | 16 | * You should have received a copy of the GNU General Public License |
paul@50 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@50 | 18 | */ |
paul@50 | 19 | |
paul@50 | 20 | #include "pic32_c.h" |
paul@53 | 21 | #include "init.h" |
paul@50 | 22 | #include "vga_display.h" |
paul@50 | 23 | |
paul@50 | 24 | |
paul@50 | 25 | |
paul@50 | 26 | /* Display state. */ |
paul@50 | 27 | |
paul@50 | 28 | vga_display_t vga_display; |
paul@50 | 29 | |
paul@56 | 30 | /* Pixel data. */ |
paul@56 | 31 | |
paul@56 | 32 | static const int ZERO_LENGTH = 1; |
paul@56 | 33 | static const uint8_t zerodata[1] = {0}; |
paul@56 | 34 | |
paul@50 | 35 | |
paul@50 | 36 | |
paul@50 | 37 | /* Initialise the state machine. */ |
paul@50 | 38 | |
paul@56 | 39 | void init_vga(display_config_t *display_config, int line_channels, |
paul@59 | 40 | int line_timer, int transfer_int_num) |
paul@50 | 41 | { |
paul@50 | 42 | /* Display parameters. */ |
paul@50 | 43 | |
paul@50 | 44 | vga_display.display_config = display_config; |
paul@56 | 45 | vga_display.line_channels = line_channels; |
paul@50 | 46 | |
paul@50 | 47 | /* Initial state. */ |
paul@50 | 48 | |
paul@50 | 49 | vga_display.state_handler = vbp_active; |
paul@50 | 50 | vga_display.line = 0; |
paul@59 | 51 | |
paul@59 | 52 | /* Configure a general display timer to start line data transfer and for the |
paul@59 | 53 | horizontal sync. */ |
paul@59 | 54 | |
paul@59 | 55 | vga_display.line_timer = line_timer; |
paul@59 | 56 | |
paul@59 | 57 | /* Configure a separate transfer interrupt condition, if indicated. |
paul@59 | 58 | Otherwise, transfers are initiated by the line timer. */ |
paul@59 | 59 | |
paul@59 | 60 | vga_display.transfer_int_num = transfer_int_num; |
paul@92 | 61 | |
paul@92 | 62 | /* Update the addresses used for the display. */ |
paul@92 | 63 | |
paul@92 | 64 | vga_set_frame(display_config); |
paul@59 | 65 | } |
paul@59 | 66 | |
paul@59 | 67 | /* Initialise a separate transfer timer if different from the general display |
paul@59 | 68 | timer. */ |
paul@59 | 69 | |
paul@59 | 70 | void init_vga_with_timers(display_config_t *display_config, int line_channels, |
paul@59 | 71 | int line_timer, int transfer_timer) |
paul@59 | 72 | { |
paul@59 | 73 | /* Initialise the basic properties of the display. */ |
paul@59 | 74 | |
paul@59 | 75 | init_vga(display_config, line_channels, line_timer, |
paul@59 | 76 | transfer_timer ? timer_interrupt_number(transfer_timer) : -1); |
paul@59 | 77 | |
paul@59 | 78 | /* Configure a line timer for horizontal sync and line data transfers. */ |
paul@59 | 79 | |
paul@59 | 80 | /* The timers have no prescaling (0). */ |
paul@59 | 81 | |
paul@59 | 82 | timer_init(line_timer, 0, display_config->hfreq_limit); |
paul@88 | 83 | |
paul@88 | 84 | /* Enable interrupt requests when the CPU needs to perform the transfer, as |
paul@88 | 85 | opposed to the DMA channels doing so. */ |
paul@88 | 86 | |
paul@88 | 87 | if (!line_channels) |
paul@88 | 88 | timer_init_interrupt(line_timer, 7, 3); |
paul@88 | 89 | |
paul@59 | 90 | timer_on(line_timer); |
paul@59 | 91 | |
paul@59 | 92 | /* Configure a separate transfer timer, if indicated. */ |
paul@59 | 93 | |
paul@88 | 94 | if (!line_channels || !transfer_timer || (transfer_timer == line_timer)) |
paul@59 | 95 | return; |
paul@59 | 96 | |
paul@59 | 97 | /* The timer wraps around immediately. */ |
paul@59 | 98 | |
paul@59 | 99 | timer_init(transfer_timer, 0, 1); |
paul@59 | 100 | timer_on(transfer_timer); |
paul@50 | 101 | } |
paul@50 | 102 | |
paul@56 | 103 | |
paul@56 | 104 | |
paul@88 | 105 | /* Configure the transfer of pixel data. */ |
paul@88 | 106 | |
paul@88 | 107 | void vga_configure_transfer(uint32_t output) |
paul@88 | 108 | { |
paul@88 | 109 | vga_display.output = output; |
paul@88 | 110 | |
paul@88 | 111 | if (vga_display.line_channels) |
paul@88 | 112 | vga_configure_dma_transfer(output); |
paul@88 | 113 | } |
paul@88 | 114 | |
paul@56 | 115 | /* Configure DMA channels for the transfer of pixel data. */ |
paul@56 | 116 | |
paul@88 | 117 | void vga_configure_dma_transfer(uint32_t output) |
paul@56 | 118 | { |
paul@56 | 119 | int dual_channel = vga_display.line_channels == 2; |
paul@56 | 120 | int channel = 0; |
paul@56 | 121 | |
paul@59 | 122 | /* Determine whether an initiating channel is used. */ |
paul@59 | 123 | |
paul@59 | 124 | int initiating_channel = vga_display.transfer_int_num >= 0; |
paul@59 | 125 | |
paul@59 | 126 | /* Determine the different interrupt conditions, with pixel data employing |
paul@59 | 127 | any specified transfer condition or the line condition otherwise. */ |
paul@59 | 128 | |
paul@59 | 129 | int line_int_num = timer_interrupt_number(vga_display.line_timer); |
paul@59 | 130 | int transfer_int_num = initiating_channel ? |
paul@59 | 131 | vga_display.transfer_int_num : line_int_num; |
paul@59 | 132 | |
paul@56 | 133 | /* Where dual line channels are involved, put the first before any |
paul@56 | 134 | initiating channel, chaining it to such a channel. */ |
paul@56 | 135 | |
paul@56 | 136 | if (dual_channel) |
paul@56 | 137 | { |
paul@56 | 138 | vga_configure_line_channel(channel++, transfer_int_num, |
paul@56 | 139 | initiating_channel ? dma_chain_next : dma_chain_none, |
paul@56 | 140 | output); |
paul@56 | 141 | } |
paul@56 | 142 | |
paul@59 | 143 | /* Introduce a special initiating channel if a separate transfer interrupt |
paul@59 | 144 | has been indicated. */ |
paul@56 | 145 | |
paul@56 | 146 | if (initiating_channel) |
paul@56 | 147 | { |
paul@59 | 148 | vga_configure_zero_channel(channel++, line_int_num, 1, output); |
paul@56 | 149 | } |
paul@56 | 150 | |
paul@56 | 151 | /* A line channel is always configured, chaining it to any initiating |
paul@56 | 152 | channel. */ |
paul@56 | 153 | |
paul@56 | 154 | vga_configure_line_channel(channel++, transfer_int_num, |
paul@56 | 155 | initiating_channel ? dma_chain_previous : dma_chain_none, |
paul@56 | 156 | output); |
paul@56 | 157 | |
paul@56 | 158 | /* A zero channel is always configured, chaining it to the preceding line |
paul@56 | 159 | channel, with the same transfer interrupt initiating the transfer. */ |
paul@56 | 160 | |
paul@56 | 161 | vga_configure_zero_channel(channel, transfer_int_num, 0, output); |
paul@56 | 162 | } |
paul@56 | 163 | |
paul@56 | 164 | void vga_configure_line_channel(int channel, int int_num, enum dma_chain chain, |
paul@56 | 165 | uint32_t output) |
paul@56 | 166 | { |
paul@56 | 167 | dma_init(channel, 2); |
paul@56 | 168 | |
paul@56 | 169 | /* If initiating, configure to always be enabled. */ |
paul@56 | 170 | |
paul@56 | 171 | if (chain == dma_chain_none) |
paul@56 | 172 | dma_set_auto_enable(channel, 1); |
paul@56 | 173 | |
paul@56 | 174 | /* Chain to either the previous or next channel where a special initiating |
paul@56 | 175 | channel is used. */ |
paul@56 | 176 | |
paul@56 | 177 | else |
paul@56 | 178 | dma_set_chaining(channel, chain); |
paul@56 | 179 | |
paul@56 | 180 | /* Initiate DMA on the transfer interrupt, transferring line data to the |
paul@56 | 181 | first byte of the output word. */ |
paul@56 | 182 | |
paul@56 | 183 | dma_set_interrupt(channel, int_num, 1); |
paul@56 | 184 | |
paul@56 | 185 | dma_set_destination(channel, HW_PHYSICAL(output), 1); |
paul@56 | 186 | dma_set_cell(channel, vga_display.display_config->transfer_cell_size); |
paul@56 | 187 | } |
paul@56 | 188 | |
paul@56 | 189 | void vga_configure_zero_channel(int channel, int int_num, int initiating, |
paul@56 | 190 | uint32_t output) |
paul@56 | 191 | { |
paul@56 | 192 | dma_init(channel, 3); |
paul@56 | 193 | |
paul@56 | 194 | /* If initiating, configure to always be enabled. */ |
paul@56 | 195 | |
paul@56 | 196 | if (initiating) |
paul@56 | 197 | dma_set_auto_enable(channel, 1); |
paul@56 | 198 | |
paul@56 | 199 | /* Otherwise, chain to the preceding channel and register prior transfer |
paul@56 | 200 | events before the channel is activated. */ |
paul@56 | 201 | |
paul@56 | 202 | else |
paul@56 | 203 | { |
paul@56 | 204 | dma_set_chaining(channel, dma_chain_previous); |
paul@56 | 205 | dma_set_receive_events(channel, 1); |
paul@56 | 206 | } |
paul@56 | 207 | |
paul@56 | 208 | /* Transfer upon the indicated interrupt condition. */ |
paul@56 | 209 | |
paul@56 | 210 | dma_set_interrupt(channel, int_num, 1); |
paul@56 | 211 | dma_set_transfer(channel, PHYSICAL((uint32_t) zerodata), |
paul@56 | 212 | ZERO_LENGTH, |
paul@56 | 213 | HW_PHYSICAL(output), 1, |
paul@56 | 214 | ZERO_LENGTH); |
paul@56 | 215 | } |
paul@56 | 216 | |
paul@59 | 217 | /* Configure output compare units for horizontal and vertical sync. */ |
paul@53 | 218 | |
paul@59 | 219 | void vga_configure_sync(int hsync_unit, int vsync_unit) |
paul@53 | 220 | { |
paul@54 | 221 | /* Record the peripherals in use. */ |
paul@54 | 222 | |
paul@54 | 223 | vga_display.hsync_unit = hsync_unit; |
paul@54 | 224 | vga_display.vsync_unit = vsync_unit; |
paul@54 | 225 | |
paul@53 | 226 | /* Horizontal sync. */ |
paul@65 | 227 | |
paul@53 | 228 | /* Configure output compare in dual compare (continuous output) mode using |
paul@53 | 229 | the timer as time base. The interrupt condition drives the first DMA |
paul@53 | 230 | channel and is handled to drive the display state machine. */ |
paul@53 | 231 | |
paul@59 | 232 | oc_init(hsync_unit, 0b101, vga_display.line_timer); |
paul@53 | 233 | oc_set_pulse(hsync_unit, vga_display.display_config->hsync_end); |
paul@53 | 234 | oc_set_pulse_end(hsync_unit, vga_display.display_config->hsync_start); |
paul@53 | 235 | oc_init_interrupt(hsync_unit, 7, 3); |
paul@53 | 236 | oc_on(hsync_unit); |
paul@53 | 237 | |
paul@53 | 238 | /* Vertical sync. */ |
paul@53 | 239 | |
paul@53 | 240 | /* Configure output compare in single compare (output driven low) mode using |
paul@53 | 241 | the timer as time base. The unit is enabled later. It is only really used |
paul@53 | 242 | to achieve precisely-timed level transitions in hardware. */ |
paul@65 | 243 | |
paul@59 | 244 | oc_init(vsync_unit, 0b010, vga_display.line_timer); |
paul@53 | 245 | oc_set_pulse(vsync_unit, 0); |
paul@53 | 246 | } |
paul@53 | 247 | |
paul@50 | 248 | |
paul@50 | 249 | |
paul@92 | 250 | /* Update the display addresses from the general display configuration. */ |
paul@92 | 251 | |
paul@92 | 252 | void vga_set_frame(display_config_t *display_config) |
paul@92 | 253 | { |
paul@97 | 254 | vga_wait_visible(); |
paul@97 | 255 | |
paul@92 | 256 | vga_display.screen_start = display_config->screen_start; |
paul@92 | 257 | vga_display.screen_limit = display_config->screen_limit; |
paul@92 | 258 | vga_display.screen_size = display_config->screen_size; |
paul@92 | 259 | } |
paul@92 | 260 | |
paul@96 | 261 | /* Wait for the visible region to be completed. */ |
paul@96 | 262 | |
paul@96 | 263 | void vga_wait_visible(void) |
paul@96 | 264 | { |
paul@96 | 265 | while (((volatile void (*)()) vga_display.state_handler) == visible_active) |
paul@96 | 266 | __asm__ __volatile__("wait"); |
paul@96 | 267 | } |
paul@96 | 268 | |
paul@96 | 269 | |
paul@96 | 270 | |
paul@88 | 271 | /* Display state machine interrupt handler. */ |
paul@50 | 272 | |
paul@50 | 273 | void vga_interrupt_handler(void) |
paul@50 | 274 | { |
paul@88 | 275 | uint32_t ifs; |
paul@88 | 276 | |
paul@88 | 277 | if (!vga_display.line_channels) |
paul@88 | 278 | { |
paul@88 | 279 | /* Check for a timer interrupt condition. */ |
paul@88 | 280 | |
paul@88 | 281 | ifs = REG(TIMERIFS) & TIMER_INT_FLAGS(vga_display.line_timer, TxIF); |
paul@88 | 282 | |
paul@88 | 283 | if (ifs) |
paul@88 | 284 | { |
paul@88 | 285 | vga_transfer_interrupt_handler(); |
paul@88 | 286 | CLR_REG(TIMERIFS, ifs); |
paul@88 | 287 | } |
paul@88 | 288 | } |
paul@88 | 289 | |
paul@88 | 290 | /* Check for a OC1 interrupt condition. */ |
paul@88 | 291 | |
paul@88 | 292 | ifs = REG(OCIFS) & OC_INT_FLAGS(1, OCxIF); |
paul@88 | 293 | |
paul@88 | 294 | if (ifs) |
paul@88 | 295 | { |
paul@88 | 296 | vga_hsync_interrupt_handler(); |
paul@88 | 297 | CLR_REG(OCIFS, ifs); |
paul@88 | 298 | } |
paul@88 | 299 | |
paul@88 | 300 | } |
paul@88 | 301 | |
paul@88 | 302 | /* Display state machine interrupt handler. */ |
paul@88 | 303 | |
paul@88 | 304 | void vga_hsync_interrupt_handler(void) |
paul@88 | 305 | { |
paul@50 | 306 | vga_display.line += 1; |
paul@50 | 307 | vga_display.state_handler(); |
paul@50 | 308 | } |
paul@50 | 309 | |
paul@88 | 310 | /* Visible region pixel output handler, used when the CPU is responsible for |
paul@88 | 311 | producing pixel output rather than the DMA channels. */ |
paul@88 | 312 | |
paul@88 | 313 | void vga_transfer_interrupt_handler(void) |
paul@88 | 314 | { |
paul@88 | 315 | display_config_t *cfg = vga_display.display_config; |
paul@88 | 316 | uint8_t *current, *end, *output; |
paul@88 | 317 | |
paul@88 | 318 | if (vga_display.state_handler != visible_active) |
paul@88 | 319 | return; |
paul@88 | 320 | |
paul@88 | 321 | /* Generate the pixel signal. */ |
paul@88 | 322 | |
paul@88 | 323 | output = (uint8_t *) vga_display.output; |
paul@88 | 324 | end = vga_display.linedata + cfg->line_length; |
paul@88 | 325 | |
paul@88 | 326 | /* This is potentially not as efficient as loading words and shifting bytes |
paul@88 | 327 | but it appears difficult to implement that approach without experiencing |
paul@88 | 328 | data load exceptions. */ |
paul@88 | 329 | |
paul@88 | 330 | for (current = vga_display.linedata; current < end; current++) |
paul@88 | 331 | REG(output) = *current; |
paul@88 | 332 | |
paul@88 | 333 | /* Reset the signal level. */ |
paul@88 | 334 | |
paul@88 | 335 | REG(output) = 0; |
paul@88 | 336 | } |
paul@88 | 337 | |
paul@50 | 338 | |
paul@50 | 339 | |
paul@50 | 340 | /* Vertical back porch region. */ |
paul@50 | 341 | |
paul@50 | 342 | void vbp_active(void) |
paul@50 | 343 | { |
paul@50 | 344 | if (vga_display.line < vga_display.display_config->visible_start) |
paul@50 | 345 | return; |
paul@50 | 346 | |
paul@50 | 347 | /* Enter the visible region. */ |
paul@50 | 348 | |
paul@50 | 349 | vga_display.state_handler = visible_active; |
paul@50 | 350 | |
paul@50 | 351 | /* Set the line address. */ |
paul@50 | 352 | |
paul@92 | 353 | vga_display.linedata = vga_display.screen_start; |
paul@88 | 354 | |
paul@88 | 355 | if (vga_display.line_channels) |
paul@88 | 356 | start_visible(); |
paul@50 | 357 | } |
paul@50 | 358 | |
paul@50 | 359 | /* Visible region. */ |
paul@50 | 360 | |
paul@50 | 361 | void visible_active(void) |
paul@50 | 362 | { |
paul@81 | 363 | display_config_t *cfg = vga_display.display_config; |
paul@81 | 364 | |
paul@81 | 365 | if (vga_display.line < cfg->vfp_start) |
paul@50 | 366 | { |
paul@50 | 367 | /* Update the line address and handle wraparound. */ |
paul@50 | 368 | |
paul@81 | 369 | if (!(vga_display.line % cfg->line_multiplier)) |
paul@50 | 370 | { |
paul@81 | 371 | vga_display.linedata += cfg->line_length; |
paul@50 | 372 | |
paul@92 | 373 | if (vga_display.linedata >= vga_display.screen_limit) |
paul@92 | 374 | vga_display.linedata -= vga_display.screen_size; |
paul@50 | 375 | } |
paul@50 | 376 | |
paul@88 | 377 | if (vga_display.line_channels) |
paul@88 | 378 | update_visible(); |
paul@50 | 379 | return; |
paul@50 | 380 | } |
paul@50 | 381 | |
paul@50 | 382 | /* End the visible region. */ |
paul@50 | 383 | |
paul@50 | 384 | vga_display.state_handler = vfp_active; |
paul@50 | 385 | |
paul@50 | 386 | /* Disable the channel for the next line. */ |
paul@50 | 387 | |
paul@88 | 388 | if (vga_display.line_channels) |
paul@88 | 389 | stop_visible(); |
paul@50 | 390 | } |
paul@50 | 391 | |
paul@50 | 392 | /* Vertical front porch region. */ |
paul@50 | 393 | |
paul@50 | 394 | void vfp_active(void) |
paul@50 | 395 | { |
paul@50 | 396 | if (vga_display.line < vga_display.display_config->vsync_start) |
paul@50 | 397 | return; |
paul@50 | 398 | |
paul@50 | 399 | /* Enter the vertical sync region. */ |
paul@50 | 400 | |
paul@50 | 401 | vga_display.state_handler = vsync_active; |
paul@50 | 402 | |
paul@50 | 403 | /* Bring vsync low when the next line starts. */ |
paul@50 | 404 | |
paul@54 | 405 | vsync_low(); |
paul@50 | 406 | } |
paul@50 | 407 | |
paul@50 | 408 | /* Vertical sync region. */ |
paul@50 | 409 | |
paul@50 | 410 | void vsync_active(void) |
paul@50 | 411 | { |
paul@50 | 412 | if (vga_display.line < vga_display.display_config->vsync_end) |
paul@50 | 413 | return; |
paul@50 | 414 | |
paul@50 | 415 | /* Start again at the top of the display. */ |
paul@50 | 416 | |
paul@50 | 417 | vga_display.line = 0; |
paul@50 | 418 | vga_display.state_handler = vbp_active; |
paul@50 | 419 | |
paul@50 | 420 | /* Bring vsync high when the next line starts. */ |
paul@50 | 421 | |
paul@54 | 422 | vsync_high(); |
paul@50 | 423 | } |
paul@54 | 424 | |
paul@54 | 425 | |
paul@54 | 426 | |
paul@56 | 427 | /* Enable the channels for the next line. */ |
paul@56 | 428 | |
paul@56 | 429 | void start_visible(void) |
paul@56 | 430 | { |
paul@56 | 431 | update_visible(); |
paul@56 | 432 | update_transfers(1); |
paul@56 | 433 | } |
paul@56 | 434 | |
paul@56 | 435 | /* Update the channels for the next line. */ |
paul@56 | 436 | |
paul@56 | 437 | void update_visible(void) |
paul@56 | 438 | { |
paul@56 | 439 | uint32_t transfer_start = (uint32_t) vga_display.linedata; |
paul@56 | 440 | uint32_t transfer_length = vga_display.display_config->line_length / |
paul@56 | 441 | vga_display.line_channels; |
paul@56 | 442 | |
paul@56 | 443 | /* Determine whether an initiating channel is used. */ |
paul@56 | 444 | |
paul@59 | 445 | int initiating_channel = vga_display.transfer_int_num >= 0; |
paul@56 | 446 | int channel = 0; |
paul@56 | 447 | |
paul@56 | 448 | /* Update the source of a secondary line channel. */ |
paul@56 | 449 | |
paul@56 | 450 | if (vga_display.line_channels == 2) |
paul@56 | 451 | { |
paul@56 | 452 | dma_set_source(channel, PHYSICAL(transfer_start), transfer_length); |
paul@56 | 453 | transfer_start += transfer_length; |
paul@56 | 454 | channel++; |
paul@56 | 455 | } |
paul@56 | 456 | |
paul@56 | 457 | /* Skip any initiating channel. */ |
paul@56 | 458 | |
paul@56 | 459 | if (initiating_channel) |
paul@56 | 460 | channel++; |
paul@56 | 461 | |
paul@56 | 462 | /* Update the source of a line channel, with potentially updated start |
paul@56 | 463 | address. */ |
paul@56 | 464 | |
paul@56 | 465 | dma_set_source(channel, PHYSICAL(transfer_start), transfer_length); |
paul@56 | 466 | } |
paul@56 | 467 | |
paul@56 | 468 | /* Disable the channels for the next line. */ |
paul@56 | 469 | |
paul@56 | 470 | void stop_visible(void) |
paul@56 | 471 | { |
paul@56 | 472 | update_transfers(0); |
paul@56 | 473 | } |
paul@56 | 474 | |
paul@56 | 475 | /* Enable or disable transfers. */ |
paul@56 | 476 | |
paul@56 | 477 | void update_transfers(int enable) |
paul@56 | 478 | { |
paul@59 | 479 | void (*fn)() = enable ? dma_on : dma_off; |
paul@59 | 480 | |
paul@59 | 481 | /* Determine whether an initiating channel is used. */ |
paul@59 | 482 | |
paul@59 | 483 | int initiating_channel = vga_display.transfer_int_num >= 0; |
paul@56 | 484 | int channel = 0; |
paul@56 | 485 | |
paul@56 | 486 | /* Update line channels if no initiating channel is used. */ |
paul@56 | 487 | |
paul@56 | 488 | if (vga_display.line_channels == 2) |
paul@56 | 489 | { |
paul@56 | 490 | if (!initiating_channel) |
paul@56 | 491 | fn(channel); |
paul@56 | 492 | channel++; |
paul@56 | 493 | } |
paul@56 | 494 | |
paul@56 | 495 | /* Update any initiating channel. */ |
paul@56 | 496 | |
paul@56 | 497 | if (initiating_channel) |
paul@56 | 498 | { |
paul@56 | 499 | fn(channel); |
paul@56 | 500 | channel++; |
paul@56 | 501 | } |
paul@56 | 502 | |
paul@56 | 503 | /* Update line channels if no initiating channel is used. */ |
paul@56 | 504 | |
paul@56 | 505 | if (!initiating_channel) |
paul@56 | 506 | fn(channel); |
paul@56 | 507 | } |
paul@56 | 508 | |
paul@56 | 509 | |
paul@56 | 510 | |
paul@54 | 511 | /* Bring vsync low (single compare, output driven low) when the next line |
paul@54 | 512 | starts. */ |
paul@54 | 513 | |
paul@54 | 514 | void vsync_low(void) |
paul@54 | 515 | { |
paul@59 | 516 | oc_init(vga_display.vsync_unit, 0b010, vga_display.line_timer); |
paul@54 | 517 | oc_on(vga_display.vsync_unit); |
paul@54 | 518 | } |
paul@54 | 519 | |
paul@54 | 520 | /* Bring vsync high (single compare, output driven high) when the next line |
paul@54 | 521 | starts. */ |
paul@54 | 522 | |
paul@54 | 523 | void vsync_high(void) |
paul@54 | 524 | { |
paul@59 | 525 | oc_init(vga_display.vsync_unit, 0b001, vga_display.line_timer); |
paul@54 | 526 | oc_on(vga_display.vsync_unit); |
paul@54 | 527 | } |