videochargen/main.S

129 lines
1.6 KiB
ArmAsm
Raw Normal View History

#include <avr/io.h>
#include "macro.h"
.data
status:
.byte 0x0
offset:
.byte 78
line:
.word 0
.text
.global main_s
main_s:
ldi r16, 0x30
sts DDRB, r16
ldi r16, (1 << IVCE) ; set vector at address 0x0
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
again:
sbi IO(PORTB), 5
ldi r16, 0x1
sts status, r16
wait1:
ldi r16, 0xff
ldi r17, 0xff
ldi r18, 0xff
1:
dec r16
brne 1b
dec r17
brne 1b
dec r18
brne 1b
cbi IO(PORTB), 5
ldi r16, 0x0
sts status, r16
wait2:
ldi r16, 0xff
ldi r17, 0xff
ldi r18, 0xff
1:
dec r16
brne 1b
dec r17
brne 1b
dec r18
brne 1b
jmp again
.global int_horizontal_sync
int_horizontal_sync:
push r31
in r31, IO(SREG) ; status register
push r31
lds r31, line
cpi r31, 255
brsh int_horizontal_sync_end
inc r31
sts line, r31
lds r31, status
cpi r31, 0
brne int_horizontal_sync_end
lds r31, offset
dec r31
cpi r31, 1
brne 1f
ldi r31, 140
1:
sts offset, r31
loop:
dec r31
brne loop
sbi IO(PORTB), 4
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
cbi IO(PORTB), 4
int_horizontal_sync_end:
pop r31
out IO(SREG), r31
pop r31
reti
.global int_vertical_sync
int_vertical_sync:
push r31
ldi r31, 0
sts line, r31
ldi r31, 140
sts offset, r31
pop r31
reti