1.1 --- a/vga.S Sat May 06 17:53:56 2017 +0200
1.2 +++ b/vga.S Sun May 07 19:27:37 2017 +0200
1.3 @@ -21,6 +21,10 @@
1.4 #include "pic32.h"
1.5
1.6 #define HFREQ_LIMIT 627 /* 20MHz cycles */
1.7 +#define VSYNC_START 1 /* horizontal lines, front porch end */
1.8 +#define VISIBLE_START 4 /* horizontal lines */
1.9 +#define VBP_START 516 /* horizontal lines, back porch start */
1.10 +#define VBP_END 531 /* horizontal lines, back porch end */
1.11
1.12 /* Disable JTAG functionality on pins. */
1.13
1.14 @@ -105,7 +109,9 @@
1.15 nop
1.16
1.17 li $a1, 20000000 /* counter = 20000000 */
1.18 - li $a2, 31872
1.19 + li $a2, 6374 /* test timer scaling */
1.20 + li $s0, 0 /* line counter */
1.21 + la $s1, vfp_active /* current event */
1.22 loop:
1.23 addiu $a1, $a1, -1 /* counter -= 1 */
1.24 bnez $a1, loop /* until counter == 0 */
1.25 @@ -113,8 +119,8 @@
1.26
1.27 li $a1, 20000000 /* counter = 20000000 */
1.28
1.29 - la $v0, PORTB
1.30 - la $v1, (1 << 10) /* PORTB<10> = RB10 */
1.31 + la $v0, PORTA
1.32 + la $v1, (1 << 2) /* PORTA<2> = RA2 */
1.33 sw $v1, INV($v0)
1.34
1.35 _next:
1.36 @@ -124,7 +130,7 @@
1.37
1.38
1.39 init_pins:
1.40 - /* DEVCFG<2> needs setting to 0 before the program is run. */
1.41 + /* DEVCFG0<2> needs setting to 0 before the program is run. */
1.42
1.43 la $v0, CFGCON
1.44 li $v1, (1 << 3) /* CFGCON<3> = JTAGEN = 0 */
1.45 @@ -210,17 +216,21 @@
1.46 beqz $v1, irq_exit
1.47 nop
1.48
1.49 + /* Test timer scaling. */
1.50 +
1.51 addiu $a2, $a2, -1
1.52 bnez $a2, irq_clear
1.53 nop
1.54 + li $a2, 6374
1.55
1.56 - li $a2, 31872
1.57 + /* Increment the line counter. */
1.58
1.59 - /* Invert an LED. */
1.60 + addiu $s0, $s0, 1
1.61
1.62 - la $v0, PORTB
1.63 - la $v1, (1 << 11) /* PORTB<11> = RB11 */
1.64 - sw $v1, INV($v0)
1.65 + /* Jump to the event handler. */
1.66 +
1.67 + jalr $s1
1.68 + nop
1.69
1.70 irq_clear:
1.71
1.72 @@ -275,3 +285,121 @@
1.73
1.74 jr $ra
1.75 nop
1.76 +
1.77 +
1.78 +
1.79 +/* Event routines. */
1.80 +
1.81 +/* Start of, and within, the vertical front porch. */
1.82 +
1.83 +vfp_start:
1.84 + /* Clear vsync. */
1.85 +
1.86 + la $v0, PORTB
1.87 + la $v1, (1 << 10) /* PORTB<10> = RB10 */
1.88 + sw $v1, CLR($v0)
1.89 +
1.90 + /* Enter the active region. */
1.91 +
1.92 + la $s1, vfp_active
1.93 +
1.94 +vfp_active:
1.95 + /* Test for vsync. */
1.96 +
1.97 + subu $v0, $s0, VSYNC_START
1.98 + bnez $v0, _vfp_active_ret
1.99 + nop
1.100 +
1.101 + /* Start the vsync region. */
1.102 +
1.103 + la $s1, vsync_start
1.104 +
1.105 +_vfp_active_ret:
1.106 + jr $ra
1.107 + nop
1.108 +
1.109 +
1.110 +
1.111 +/* Start of, and within, vsync. */
1.112 +
1.113 +vsync_start:
1.114 + /* Set vsync. */
1.115 +
1.116 + la $v0, PORTB
1.117 + la $v1, (1 << 10) /* PORTB<10> = RB10 */
1.118 + sw $v1, SET($v0)
1.119 +
1.120 + /* Enter the active region. */
1.121 +
1.122 + la $s1, vsync_active
1.123 +
1.124 +vsync_active:
1.125 + /* Test for visible region. */
1.126 +
1.127 + subu $v0, $s0, VISIBLE_START
1.128 + bnez $v0, _vsync_active_ret
1.129 + nop
1.130 +
1.131 + /* Start the visible region. */
1.132 +
1.133 + la $s1, visible_start
1.134 +
1.135 +_vsync_active_ret:
1.136 + jr $ra
1.137 + nop
1.138 +
1.139 +
1.140 +
1.141 +/* Start of, and within, the visible period. */
1.142 +
1.143 +visible_start:
1.144 + /* Clear vsync. */
1.145 +
1.146 + la $v0, PORTB
1.147 + la $v1, (1 << 10) /* PORTB<10> = RB10 */
1.148 + sw $v1, CLR($v0)
1.149 +
1.150 + /* Enter the active region. */
1.151 +
1.152 + la $s1, visible_active
1.153 +
1.154 +visible_active:
1.155 + /* NOTE: Perform line activities. */
1.156 +
1.157 + la $v0, PORTB
1.158 + la $v1, (1 << 11) /* PORTB<11> = RB11 */
1.159 + sw $v1, INV($v0)
1.160 +
1.161 + /* Test for back porch. */
1.162 +
1.163 + subu $v0, $s0, VBP_START
1.164 + bnez $v0, _visible_active_ret
1.165 + nop
1.166 +
1.167 + /* Start the back porch. */
1.168 +
1.169 + la $s1, vbp_active
1.170 +
1.171 +_visible_active_ret:
1.172 + jr $ra
1.173 + nop
1.174 +
1.175 +
1.176 +
1.177 +/* Within the vertical back porch. */
1.178 +
1.179 +vbp_active:
1.180 + /* Test for front porch. */
1.181 +
1.182 + subu $v0, $s0, VBP_END
1.183 + bnez $v0, _vbp_active_ret
1.184 + nop
1.185 +
1.186 + /* Start the front porch. */
1.187 +
1.188 + li $s0, 0
1.189 + la $s1, vfp_start
1.190 +
1.191 +_vbp_active_ret:
1.192 + jr $ra
1.193 + nop