110 lines
1.9 KiB
ArmAsm
110 lines
1.9 KiB
ArmAsm
#include <avr/io.h>
|
|
#include "macro.h"
|
|
#include "const.h"
|
|
|
|
.text
|
|
|
|
.global main
|
|
main:
|
|
ldi r16, 0x30 ; port B, pin 4 and 5 as output
|
|
sts DDRB, r16
|
|
cbi IO(DDRD), 2 ; port D, pin 2 and 3 as input
|
|
cbi IO(DDRD), 3
|
|
|
|
; init variables
|
|
ldi r16, 0
|
|
sts frame, r16
|
|
sts frame + 1, r16
|
|
sts line + 1, r16
|
|
ldi r16, 1
|
|
sts line, r16
|
|
|
|
cli ; global interrupt disable
|
|
|
|
call setup_c
|
|
|
|
wait_next_line:
|
|
in r16, IO(PIND)
|
|
andi r16, 0x08
|
|
brne wait_next_line
|
|
/*
|
|
; if (line >= VERTICAL_OFFSET), then enter
|
|
lds r30, line ; +2, 2
|
|
lds r31, line + 1 ; +2, 4
|
|
adiw z, 1 ; +2, 6
|
|
sts line, r30 ; +2, 8
|
|
sts line + 1, r31 ; +2, 10
|
|
cpi r31, 0 ; +1, 11
|
|
brne enter ; +2, 13
|
|
cpi r30, VERTICAL_OFFSET ; TODO timing bad at 256 lines
|
|
brsh enter
|
|
jmp horizontal_line_end
|
|
*/
|
|
|
|
enter:
|
|
; here, +13 cycles have passed since horizontal sync
|
|
; so, there are still (192 - 13) = 179 cycles before first useful data
|
|
ldi r31, 64 ; approx
|
|
1:
|
|
dec r31 ; 1
|
|
brne 1b ; 2
|
|
|
|
; here we are at the beginning of the visible line
|
|
ldi r31, 16
|
|
1:
|
|
dec r31
|
|
brne 1b
|
|
|
|
sbi IO(PORTB), 5
|
|
|
|
sbi IO(PORTB), 4
|
|
nop
|
|
nop
|
|
nop
|
|
nop
|
|
cbi IO(PORTB), 4
|
|
|
|
# ; draw things
|
|
# ldi r30, lo8(line_buffer)
|
|
# ldi r31, hi8(line_buffer)
|
|
|
|
#.rept LINE_BUFFER_SIZE
|
|
# ld r29, z+
|
|
# out IO(PORTB), r29
|
|
# nop
|
|
#.endr
|
|
|
|
cbi IO(PORTB), 5
|
|
|
|
horizontal_line_end:
|
|
jmp wait_next_line
|
|
|
|
|
|
/*
|
|
.global int_vertical_sync
|
|
int_vertical_sync:
|
|
push r31
|
|
in r31, IO(SREG)
|
|
push r31
|
|
push r30
|
|
|
|
lds r31, frame + 1
|
|
lds r30, frame
|
|
adiw z, 1
|
|
sts frame + 1, r31
|
|
sts frame, r30
|
|
|
|
ldi r30, 1
|
|
ldi r31, 0
|
|
sts line, r30
|
|
sts line + 1, r31
|
|
|
|
int_vertical_sync_end:
|
|
pop r30
|
|
pop r31
|
|
out IO(SREG), r31
|
|
pop r31
|
|
reti
|
|
|
|
*/
|