]>
git.defcon.no Git - avrfbosd/blob - fbosd.c
c30ee9b5aa3606601ef10f6c07168f890560ca64
2 #include <avr/interrupt.h>
3 #include <util/delay.h>
6 #include "video_properties.h"
10 void (*line_handler
)( void );
12 const int vres_scale
= ( SCREEN_LINES
/ VRES
-1 );
13 const int hres_bytes
= HRES
/ 8;
15 volatile uint8_t* screen_buffer
;
18 volatile int buffer_position
;
20 void Delay_ms(int cnt
)
22 while(cnt
-->0) _delay_ms(1);
25 void set_busy ( uint8_t busy
)
32 // TODO: Disable SPI communication here...
37 PORTB
&= ~(uint8_t)(1 << PB1
);
39 // TODO: Enable SPI communication here...
43 void active_lines ( void )
49 // Set Busy signal. Line rendering is time-critical.
56 if ( buffer_position
< ((VRES
*hres_bytes
)) )
57 buffer_position
+= hres_bytes
;
64 void blank_lines ( void )
66 // Do nothing on the "lead-in" lines
67 if ( line
< FIRST_LINE
)
70 // Clear Frame Ready signal
71 PORTD
&= ~(uint8_t)(1 << PD5
);
74 line_handler
= active_lines
;
85 line_handler
= &blank_lines
;
86 EIMSK
&= ~(uint8_t)(1<<INT1
);
88 // Set Frame Ready signal
96 // VSync is getting close to done.
97 // Set line-handler to blank-handler to count-up the undesired lines,
98 // and enable HSync interrupts.
100 line_handler
= &blank_lines
;
109 // Note: PB0 is used as CLKO outputting 20MHz clock to ATtiny
111 // Set PB2 as Output for BUSY signal
114 // Set PD5 as Output for FR signal
115 // Set PD6 as Output for Status LED
116 // Using pin 7 on PD to clock out pixels \o/
117 DDRD
= (1<<PD5
)|(1<<PD6
)|(1<<PD7
);
119 // Clear PORTB and PORTD
123 // Allocate the framebuffer :D
124 screen_buffer
= (uint8_t*) malloc( hres_bytes
* VRES
* sizeof(uint8_t) );
125 // And make sure it's cleared
128 /* LM1881 pins are connected to:
129 INT0 / PCINT18 / PD2 <- VSYNC
130 INT1 / PCINT19 / PD3 <- CSYNC
131 PCINT20 / PD4 <- ODD/EVEN
133 EICRA
|= (1<<ISC01
)|(1<<ISC00
); // Select Rising-edge interrupt for VSync
134 EICRA
|= (1<<ISC11
)|(1<<ISC10
); // Select Rising-edge interrupt for HSync
135 EIMSK
|= (1<<INT0
); // Enable VSync-interrupts
137 // Enable interrupts globally.
140 // Do some static drawing :P
142 set_pixel(92, 82, 1);
145 set_pixel(28, 82, 1);
147 draw_line(0, 0, 128, 92, 1);
148 draw_line(128, 0, 0, 92, 1);
150 draw_rect( 0, 1, 127, 91, 1);
152 draw_rect( 34, 21, 60, 50, 1);
153 _draw_rect( 24, 11, 80, 70, 1, -1);
154 draw_rect( 34, 21, 60, 50, 1);
156 fill_circle( 64,46, 45, 1 );
157 fill_circle( 64,46, 40, 0 );
159 _draw_circle( 64,46, 35, 1, -1 );
160 draw_circle( 64,46, 30, 1 );
161 fill_rect( 38, 25, 52, 42, 1);
162 fill_rect( 41, 28, 46, 36, 0);
167 PORTD
^= (uint8_t)(1 << PD6
);
169 for ( int j
= 0; j
< 92; j
++ )
171 draw_line(0,0,128,j
, 2);
172 draw_line(128,0,0,j
, 2);
173 draw_line(0,92,128,92-j
, 2);
174 draw_line(128,92,0,92-j
, 2);
179 for ( int j
= 0; j
< 92; j
++ )
181 draw_line(0,0,128,j
, 2);
182 draw_line(128,0,0,j
, 2);
183 draw_line(0,92,128,92-j
, 2);
184 draw_line(128,92,0,92-j
, 2);