146 lines
1.9 KiB
ArmAsm
146 lines
1.9 KiB
ArmAsm
#include <avr/io.h>
|
|
#include "macro.h"
|
|
#include "const.h"
|
|
|
|
.data
|
|
vertical_offset:
|
|
.byte 0
|
|
|
|
frame:
|
|
.byte 0
|
|
|
|
line:
|
|
.byte 0
|
|
|
|
.text
|
|
|
|
.global main
|
|
main:
|
|
ldi r16, 0x30 ; port B, pin 4 and 5 as output
|
|
sts DDRB, r16
|
|
|
|
; set interrupt vectors at address 0x0, not bootloader
|
|
; timing is important, see atmel datasheet
|
|
ldi r16, (1 << IVCE)
|
|
ldi r17, 0
|
|
out IO(MCUCR), r16
|
|
out IO(MCUCR), r17
|
|
|
|
ldi r16, 0xa ; external interrupt 0 and 1, falling edge
|
|
sts EICRA, r16
|
|
|
|
ldi r16, 0x3 ; external interrupt 0 and 1, mask enable
|
|
sts EIMSK, r16
|
|
|
|
sei ; global interrupt enable
|
|
|
|
1:
|
|
sbi IO(PORTB), 5
|
|
ldi r18, 0
|
|
2:
|
|
dec r18
|
|
brne 2b
|
|
|
|
cbi IO(PORTB), 5
|
|
|
|
ldi r18, 0
|
|
3:
|
|
dec r18
|
|
brne 3b
|
|
|
|
rjmp 1b
|
|
|
|
jmp .
|
|
|
|
.global int_horizontal_sync
|
|
int_horizontal_sync:
|
|
push r31
|
|
in r31, IO(SREG) ; status register
|
|
push r31
|
|
|
|
lds r31, vertical_offset
|
|
cpi r31, 0
|
|
breq enter
|
|
dec r31
|
|
sts vertical_offset, r31
|
|
jmp int_horizontal_sync_end
|
|
|
|
enter:
|
|
lds r31, line
|
|
cpi r31, 0
|
|
breq int_horizontal_sync_end
|
|
inc r31
|
|
sts line, r31
|
|
|
|
ldi r31, HORIZONTAL_OFFSET_CYCLE ; skip back porch
|
|
1:
|
|
dec r31
|
|
brne 1b
|
|
|
|
; do things
|
|
lds r31, frame
|
|
cpi r31, 0
|
|
breq 2f
|
|
1:
|
|
dec r31
|
|
brne 1b
|
|
2:
|
|
|
|
sbi IO(PORTB), 4
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
cbi IO(PORTB), 4
|
|
|
|
#if 0
|
|
ldi r31, 140
|
|
1:
|
|
dec r31
|
|
brne 1b
|
|
|
|
sbi IO(PORTB), 4
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
cbi IO(PORTB), 4
|
|
#endif
|
|
|
|
int_horizontal_sync_end:
|
|
pop r31
|
|
out IO(SREG), r31
|
|
pop r31
|
|
reti
|
|
|
|
.global int_vertical_sync
|
|
int_vertical_sync:
|
|
push r31
|
|
in r31, IO(SREG)
|
|
push r31
|
|
|
|
lds r31, frame
|
|
inc r31
|
|
sts frame, r31
|
|
|
|
ldi r31, 1
|
|
sts line, r31
|
|
|
|
ldi r31, VERTICAL_OFFSET
|
|
sts vertical_offset, r31
|
|
|
|
int_vertical_sync_end:
|
|
pop r31
|
|
out IO(SREG), r31
|
|
pop r31
|
|
reti
|
|
|
|
|