From 14fd0412d492f6ee1b1249f8650a7a481172db8a Mon Sep 17 00:00:00 2001 From: giomba Date: Sun, 27 Jun 2021 21:57:02 +0200 Subject: [PATCH] something strange is happening --- const.h | 4 ++ main.S | 113 +++++++++++++++++++++++++++++--------------------------- main.c | 6 --- 3 files changed, 62 insertions(+), 61 deletions(-) create mode 100644 const.h diff --git a/const.h b/const.h new file mode 100644 index 0000000..179fd25 --- /dev/null +++ b/const.h @@ -0,0 +1,4 @@ +#pragma once + +#define VERTICAL_OFFSET 30 + diff --git a/main.S b/main.S index ee11340..96a0f8c 100644 --- a/main.S +++ b/main.S @@ -1,25 +1,27 @@ #include #include "macro.h" +#include "const.h" .data +vertical_offset: +.byte 0 -status: -.byte 0x0 - -offset: -.byte 78 +frame: +.byte 0 line: -.word 0 +.byte 0 .text -.global main_s -main_s: - ldi r16, 0x30 +.global main +main: + ldi r16, 0x30 ; port B, pin 4 and 5 as output sts DDRB, r16 - ldi r16, (1 << IVCE) ; set vector at address 0x0 + ; 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 @@ -30,44 +32,25 @@ main_s: 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 + sei ; global interrupt enable 1: - dec r16 - brne 1b - dec r17 - brne 1b + sbi IO(PORTB), 5 + ldi r18, 0 +2: dec r18 - brne 1b + brne 2b 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 + ldi r18, 0 +3: dec r18 - brne 1b + brne 3b - jmp again + rjmp 1b + + jmp . .global int_horizontal_sync int_horizontal_sync: @@ -75,26 +58,34 @@ int_horizontal_sync: in r31, IO(SREG) ; status register push r31 +#if 0 + lds r31, vertical_offset + cpi r31, 0 + breq enter1 + dec r31 + sts vertical_offset, r31 + jmp int_horizontal_sync_end + +enter1: lds r31, line - cpi r31, 255 - brsh int_horizontal_sync_end + cpi r31, 0 + breq int_horizontal_sync_end inc r31 sts line, r31 - lds r31, status - cpi r31, 0 - brne int_horizontal_sync_end - - lds r31, offset + lds r31, frame + lsr r31 + lsr r31 + breq 2f +1: dec r31 - cpi r31, 1 - brne 1f + brne 1b +#endif + ldi r31, 140 1: - sts offset, r31 -loop: dec r31 - brne loop + brne 1b sbi IO(PORTB), 4 nop @@ -118,10 +109,22 @@ int_horizontal_sync_end: .global int_vertical_sync int_vertical_sync: push r31 - ldi r31, 0 + in r31, IO(SREG) + push r31 + + lds r31, frame + inc r31 + sts frame, r31 + + ldi r31, 1 sts line, r31 - ldi r31, 140 - sts offset, r31 + + ldi r31, VERTICAL_OFFSET + sts vertical_offset, r31 + +int_vertical_sync_end: + pop r31 + out IO(SREG), r31 pop r31 reti diff --git a/main.c b/main.c index f509ba1..168862f 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,6 @@ #include #include -void main_s(void); - - ISR(INT0_vect, ISR_NAKED) { asm("jmp int_vertical_sync"); } @@ -11,6 +8,3 @@ ISR(INT1_vect, ISR_NAKED) { asm("jmp int_horizontal_sync"); } -int main() { - main_s(); -}