videochargen/main.c

82 lines
1.7 KiB
C

/**
* @file main.c
* @author giomba@glgprograms.it
* @brief OSDY main.
*
* @copyright Copyright RetrOfficina GLG Programs (c) 2022
*
* Video image generator superimposition for analog PAL signals,
* with Atmega328, for your retro OSD titles.
*
*/
#include "const.h"
#include <avr/interrupt.h>
#include <avr/io.h>
#include <string.h>
volatile uint16_t frame = 0;
volatile uint16_t line = 0xfe;
volatile uint8_t image = 0xff;
// horizontal and vertical position of bouncing logo
volatile uint8_t vpos = 0;
volatile uint8_t hpos = 0;
volatile int8_t vinc = +1;
volatile int8_t hinc = +1;
void int_vertical_sync_s(void);
ISR(INT0_vect) {
frame += 1;
vpos += vinc;
hpos += hinc;
if (vpos == 0)
vinc = +1;
if (vpos == 256 - 64)
vinc = -1;
if (hpos == HORIZONTAL_OFFSET)
hinc = +1;
if (hpos == 255 - 40)
hinc = -1;
int_vertical_sync_s();
}
void int_horizontal_sync_s(void);
ISR(INT1_vect) {
line += 1;
// if (line >= 256)
if (line >= vpos + 64)
return;
if (line >= vpos)
int_horizontal_sync_s();
}
ISR(TIMER0_COMPA_vect, ISR_NAKED) {
// back porch timer interrupt
asm("jmp int_timer_0");
}
// external assembly main loop
void main_asm(void);
int main() {
// port B, pin 4 and 5 as output, others as input
DDRB |= 0x30;
// set interrupt vectors at address 0x0, not bootloader
// timing is important, see atmel datasheet
_SFR_IO8(MCUCR) = (1 << IVCE);
_SFR_IO8(MCUCR) = 0;
EICRA = 0x0a; // external interrupt 0 and 1, falling edge
EIMSK = 0x03; // external interrupt 0 and 1, mask enable
TCCR0A = 0x02; // don't connect output pins to timer, CTC[1:0] mode
TCCR0B = 0x01; // CTC[2] mode, no prescaler
main_asm();
}