2021-06-26 17:15:17 +00:00
|
|
|
#include <avr/io.h>
|
|
|
|
#include "macro.h"
|
2021-06-27 19:57:02 +00:00
|
|
|
#include "const.h"
|
2021-06-26 17:15:17 +00:00
|
|
|
|
|
|
|
.data
|
2021-06-26 20:34:22 +00:00
|
|
|
|
2021-06-27 19:57:02 +00:00
|
|
|
frame:
|
2021-06-28 19:38:39 +00:00
|
|
|
.word 0
|
2021-06-26 20:34:22 +00:00
|
|
|
|
2021-06-26 21:42:23 +00:00
|
|
|
line:
|
2021-06-28 19:38:39 +00:00
|
|
|
.word 0
|
2021-06-26 21:42:23 +00:00
|
|
|
|
2021-06-26 17:15:17 +00:00
|
|
|
.text
|
|
|
|
|
2021-06-27 19:57:02 +00:00
|
|
|
.global main
|
|
|
|
main:
|
|
|
|
ldi r16, 0x30 ; port B, pin 4 and 5 as output
|
2021-06-26 17:15:17 +00:00
|
|
|
sts DDRB, r16
|
|
|
|
|
2021-06-27 19:57:02 +00:00
|
|
|
; set interrupt vectors at address 0x0, not bootloader
|
|
|
|
; timing is important, see atmel datasheet
|
|
|
|
ldi r16, (1 << IVCE)
|
2021-06-26 17:15:17 +00:00
|
|
|
ldi r17, 0
|
|
|
|
out IO(MCUCR), r16
|
|
|
|
out IO(MCUCR), r17
|
|
|
|
|
2021-06-26 21:42:23 +00:00
|
|
|
ldi r16, 0xa ; external interrupt 0 and 1, falling edge
|
2021-06-26 17:15:17 +00:00
|
|
|
sts EICRA, r16
|
|
|
|
|
2021-06-26 21:42:23 +00:00
|
|
|
ldi r16, 0x3 ; external interrupt 0 and 1, mask enable
|
2021-06-26 17:15:17 +00:00
|
|
|
sts EIMSK, r16
|
|
|
|
|
2021-06-27 19:57:02 +00:00
|
|
|
sei ; global interrupt enable
|
2021-06-26 17:15:17 +00:00
|
|
|
|
|
|
|
1:
|
2021-06-27 19:57:02 +00:00
|
|
|
rjmp 1b
|
|
|
|
|
2021-06-26 21:42:23 +00:00
|
|
|
.global int_horizontal_sync
|
|
|
|
int_horizontal_sync:
|
2021-06-26 20:34:22 +00:00
|
|
|
push r31
|
|
|
|
in r31, IO(SREG) ; status register
|
|
|
|
push r31
|
2021-06-28 19:38:39 +00:00
|
|
|
push r30
|
|
|
|
|
|
|
|
; if (line >= VERTICAL_OFFSET), then enter
|
|
|
|
lds r30, line
|
|
|
|
lds r31, line + 1
|
|
|
|
adiw z, 1
|
|
|
|
sts line, r30
|
|
|
|
sts line + 1, r31
|
2021-06-27 19:57:02 +00:00
|
|
|
cpi r31, 0
|
2021-06-28 19:38:39 +00:00
|
|
|
brne enter
|
|
|
|
cpi r30, VERTICAL_OFFSET
|
|
|
|
brlo int_horizontal_sync_end
|
2021-06-27 19:57:02 +00:00
|
|
|
|
2021-06-27 20:37:11 +00:00
|
|
|
enter:
|
|
|
|
ldi r31, HORIZONTAL_OFFSET_CYCLE ; skip back porch
|
|
|
|
1:
|
|
|
|
dec r31
|
|
|
|
brne 1b
|
|
|
|
|
|
|
|
; do things
|
2021-06-27 19:57:02 +00:00
|
|
|
lds r31, frame
|
2021-06-27 20:37:11 +00:00
|
|
|
cpi r31, 0
|
2021-06-27 19:57:02 +00:00
|
|
|
breq 2f
|
|
|
|
1:
|
2021-06-26 20:34:22 +00:00
|
|
|
dec r31
|
2021-06-27 19:57:02 +00:00
|
|
|
brne 1b
|
2021-06-27 20:37:11 +00:00
|
|
|
2:
|
|
|
|
|
|
|
|
sbi IO(PORTB), 4
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
nop
|
|
|
|
cbi IO(PORTB), 4
|
2021-06-27 19:57:02 +00:00
|
|
|
|
2021-06-26 21:42:23 +00:00
|
|
|
int_horizontal_sync_end:
|
2021-06-28 19:38:39 +00:00
|
|
|
pop r30
|
2021-06-26 20:34:22 +00:00
|
|
|
pop r31
|
|
|
|
out IO(SREG), r31
|
|
|
|
pop r31
|
|
|
|
reti
|
2021-06-26 17:15:17 +00:00
|
|
|
|
2021-06-26 21:42:23 +00:00
|
|
|
.global int_vertical_sync
|
|
|
|
int_vertical_sync:
|
|
|
|
push r31
|
2021-06-27 19:57:02 +00:00
|
|
|
in r31, IO(SREG)
|
|
|
|
push r31
|
2021-06-28 19:38:39 +00:00
|
|
|
push r30
|
2021-06-27 19:57:02 +00:00
|
|
|
|
2021-06-28 19:38:39 +00:00
|
|
|
lds r31, frame + 1
|
|
|
|
lds r30, frame
|
|
|
|
adiw z, 1
|
|
|
|
sts frame + 1, r31
|
|
|
|
sts frame, r30
|
2021-06-27 19:57:02 +00:00
|
|
|
|
2021-06-28 19:38:39 +00:00
|
|
|
ldi r30, 1
|
|
|
|
ldi r31, 0
|
|
|
|
sts line, r30
|
|
|
|
sts line + 1, r31
|
2021-06-27 19:57:02 +00:00
|
|
|
|
|
|
|
int_vertical_sync_end:
|
2021-06-28 19:38:39 +00:00
|
|
|
pop r30
|
2021-06-27 19:57:02 +00:00
|
|
|
pop r31
|
|
|
|
out IO(SREG), r31
|
2021-06-26 21:42:23 +00:00
|
|
|
pop r31
|
|
|
|
reti
|
|
|
|
|
|
|
|
|