]>
git.defcon.no Git - avrfbosd/blob - fbosd.c
e4524aaf52bd339ea1f9cb2894cc2b93bbfa5407
2 #include <avr/interrupt.h>
3 #include <util/delay.h>
5 #include <avr/pgmspace.h>
7 #include "video_properties.h"
12 void (*line_handler
)( void );
14 const int vres_scale
= ( SCREEN_LINES
/ VRES
-1 );
15 const int hres_bytes
= HRES
/ 8;
17 volatile uint8_t* screen_buffer
;
20 volatile int buffer_position
;
22 void Delay_ms(int cnt
)
24 while(cnt
-->0) _delay_ms(1);
27 void set_busy ( uint8_t busy
)
34 // TODO: Disable SPI communication here...
39 PORTB
&= ~(uint8_t)(1 << PB1
);
41 // TODO: Enable SPI communication here...
45 void active_lines ( void )
51 // Set Busy signal. Line rendering is time-critical.
58 if ( buffer_position
< ((VRES
*hres_bytes
)) )
59 buffer_position
+= hres_bytes
;
66 void blank_lines ( void )
68 // Do nothing on the "lead-in" lines
69 if ( line
< FIRST_LINE
)
72 // Clear Frame Ready signal
73 PORTD
&= ~(uint8_t)(1 << PD5
);
76 line_handler
= active_lines
;
87 line_handler
= &blank_lines
;
88 EIMSK
&= ~(uint8_t)(1<<INT1
);
90 // Set Frame Ready signal
98 // VSync is getting close to done.
99 // Set line-handler to blank-handler to count-up the undesired lines,
100 // and enable HSync interrupts.
102 line_handler
= &blank_lines
;
111 // Note: PB0 is used as CLKO outputting 20MHz clock to ATtiny
113 // Set PB2 as Output for BUSY signal
116 // Set PD5 as Output for FR signal
117 // Set PD6 as Output for Status LED
118 // Using pin 7 on PD to clock out pixels \o/
119 DDRD
= (1<<PD5
)|(1<<PD6
)|(1<<PD7
);
121 // Clear PORTB and PORTD
125 // Allocate the framebuffer :D
126 screen_buffer
= (uint8_t*) malloc( hres_bytes
* VRES
* sizeof(uint8_t) );
127 // And make sure it's cleared
130 /* LM1881 pins are connected to:
131 INT0 / PCINT18 / PD2 <- VSYNC
132 INT1 / PCINT19 / PD3 <- CSYNC
133 PCINT20 / PD4 <- ODD/EVEN
135 EICRA
|= (1<<ISC01
)|(1<<ISC00
); // Select Rising-edge interrupt for VSync
136 EICRA
|= (1<<ISC11
)|(1<<ISC10
); // Select Rising-edge interrupt for HSync
137 EIMSK
|= (1<<INT0
); // Enable VSync-interrupts
139 // Enable interrupts globally.
143 // Do some static drawing :P
145 set_pixel(92, 82, 1);
148 set_pixel(28, 82, 1);
150 draw_line(0, 0, 128, 92, 1);
151 draw_line(128, 0, 0, 92, 1);
153 draw_rect( 0, 1, 127, 91, 1);
155 draw_rect( 34, 21, 60, 50, 1);
156 _draw_rect( 24, 11, 80, 70, 1, -1);
157 draw_rect( 34, 21, 60, 50, 1);
159 fill_circle( 64,46, 45, 1 );
160 fill_circle( 64,46, 40, 0 );
162 _draw_circle( 64,46, 35, 1, -1 );
163 draw_circle( 64,46, 30, 1 );
164 fill_rect( 38, 25, 52, 42, 1);
165 fill_rect( 41, 28, 46, 36, 0);
170 PORTD ^= (uint8_t)(1 << PD6);
172 for ( int j = 0; j < 92; j++ )
174 draw_line(0,0,128,j, 2);
175 draw_line(128,0,0,j, 2);
176 draw_line(0,92,128,92-j, 2);
177 draw_line(128,92,0,92-j, 2);
182 for ( int j = 0; j < 92; j++ )
184 draw_line(0,0,128,j, 2);
185 draw_line(128,0,0,j, 2);
186 draw_line(0,92,128,92-j, 2);
187 draw_line(128,92,0,92-j, 2);
196 for (int q
= 0; q
< font_height
; q
++ )
198 //for (int r = 0; r < font_width; r++ )
200 uint8_t t
= pgm_read_byte(&(font
[0][q
]));
201 screen_buffer
[q
*hres_bytes
+3+hres_bytes
] |= t
;
203 t
= pgm_read_byte(&(font
[1][q
]));
204 screen_buffer
[q
*hres_bytes
+5+hres_bytes
] |= t
;
206 t
= pgm_read_byte(&(font
[2][q
]));
207 screen_buffer
[q
*hres_bytes
+6+hres_bytes
] |= t
;