]> git.defcon.no Git - avrfbosd/blob - fbosd.c
Oops, got a bit trigger-happy with the cleanup, ripped out an opening bracket
[avrfbosd] / fbosd.c
1 #include <avr/io.h>
2 #include <avr/interrupt.h>
3 #include <util/delay.h>
4 #include <stdlib.h>
5
6 #include "video_properties.h"
7 #include "render.h"
8 #include "draw.h"
9
10 void (*line_handler)( void );
11
12 const int vres_scale = ( SCREEN_LINES / VRES -1 );
13 const int hres_bytes = HRES / 8;
14
15 volatile uint8_t* screen_buffer;
16
17 volatile int line;
18 volatile int buffer_position;
19
20 void Delay_ms(int cnt)
21 {
22 while(cnt-->0) _delay_ms(1);
23 }
24
25 void active_lines ( void )
26 {
27 static uint8_t rept;
28
29 _delay_us(4);
30
31 asm_render_line();
32
33 if( !rept )
34 {
35 if ( buffer_position < ((VRES*hres_bytes)) )
36 buffer_position += hres_bytes;
37 rept = vres_scale;
38 }
39 else
40 rept--;
41
42 }
43
44 void blank_lines ( void )
45 {
46 if ( line < FIRST_LINE )
47 {
48 PORTB ^= 0x001;
49 return;
50 }
51 line_handler = active_lines;
52 }
53
54 ISR (INT1_vect)
55 {
56 line_handler();
57 line++;
58 if( line > LAST_LINE)
59 {
60 line = 0;
61 buffer_position = 0;
62 line_handler = &blank_lines;
63 EIMSK &= ~(uint8_t)(1<<INT1);
64 }
65 }
66
67 ISR (INT0_vect)
68 {
69 // VSync is getting close to done.
70 // Set line-handler to blank-handler to count-up the undesired lines,
71 // and enable HSync interrupts.
72
73 line_handler = &blank_lines;
74
75 EIMSK |= (1<<INT1);
76
77 }
78
79 //Main Function
80 int main(void)
81 {
82
83 // Using some pins on PORTB for debug-indicator-LEDs
84 DDRB = (1<< PB0)|(1 << PB1)|(1 << PB2);
85 PORTB = 0x0;
86
87 // Using pin 7 on PD to clock out pixels \o/
88 DDRD = (1<<PD7);
89 PORTD = 0x0;
90
91 /* LM1881 pins are connected to:
92 INT0 / PCINT18 / PD2 <- VSYNC
93 INT1 / PCINT19 / PD3 <- CSYNC
94 PCINT20 / PD4 <- ODD/EVEN
95 */
96 EICRA |= (1<<ISC01)|(1<<ISC00); // Select Rising-edge interrupt for VSync
97 EICRA |= (1<<ISC11)|(1<<ISC10); // Select Rising-edge interrupt for HSync
98 EIMSK |= (1<<INT0); // Enable VSync-interrupts
99
100 // And enable interrupts globally.
101 sei();
102
103 // Allocate the framebuffer :D
104 screen_buffer = (uint8_t*) malloc( hres_bytes * VRES * sizeof(uint8_t) );
105 // And make sure it's cleared
106 fill(c_BLACK);
107
108 // Do some static drawing :P
109 set_pixel(28, 8, 1);
110 set_pixel(92, 82, 1);
111
112 set_pixel(92, 8, 1);
113 set_pixel(28, 82, 1);
114
115
116 draw_line(0, 0, 128, 92, 1);
117 draw_line(128, 0, 0, 92, 1);
118
119 draw_rect( 0, 1, 127, 91, 1);
120
121 draw_rect( 34, 21, 60, 50, 1);
122 _draw_rect( 24, 11, 80, 70, 1, -1);
123 draw_rect( 34, 21, 60, 50, 1);
124
125
126 _draw_circle( 64,46, 35, 1, -1 );
127 draw_circle( 64,46, 30, 1 );
128 fill_circle( 64,46, 25, 1 );
129 fill_circle( 64,46, 20, 0 );
130 fill_rect( 44, 31, 40, 30, 1);
131 fill_rect( 54, 41, 20, 10, 0);
132
133 for (;;)
134 {
135 PORTB ^= 0x002;
136
137 for ( int j = 8; j < 89; j++ )
138 {
139 draw_line(8,88-j,120,j, 2);
140 draw_line(120,j,8,88-j, 2);
141 Delay_ms(5);
142 draw_line(8,88-j,120,j, 2);
143 Delay_ms(5);
144 }
145 Delay_ms(150);
146 }
147 }
148
149
150