@@ -25,12 +25,39 @@ static OSIF_WindowFrameBufferInfo createWindow (const char* const title)
2525 return fbi ;
2626}
2727
28+ static void triangle_sum (int * now , int start , int end , int * incby )
29+ {
30+ int l_now = * now ;
31+
32+ l_now += * incby ;
33+
34+ if (l_now >= end ) {
35+ l_now = end ;
36+ } else if (l_now <= start ) {
37+ l_now = start ;
38+ }
39+
40+ if (l_now == end || l_now == start ) {
41+ * incby *= -1 ;
42+ }
43+
44+ * now = l_now ;
45+ }
46+
47+ static void repaint_on_yield (OSIF_ProcessEvent const * const e )
48+ {
49+ (void )e ;
50+ cm_window_flush_graphics ();
51+ }
52+
2853void proc_main ()
2954{
3055 cm_window_flush_graphics ();
56+ cm_thread_create (& thread0 , false);
3157 cm_thread_create (& thread1 , false);
3258 cm_thread_create (& thread2 , false);
33- cm_thread_create (& thread0 , false);
59+
60+ cm_process_register_event_handler (OSIF_PROCESS_EVENT_PROCCESS_YIELD_REQ , repaint_on_yield );
3461
3562 while (1 ) {
3663 cm_process_handle_events ();
@@ -39,68 +66,54 @@ void proc_main()
3966
4067void thread0 ()
4168{
42- UINT color = 0x5F9FFF ;
43- INT x = 0 ;
44- INT width = 20 ;
45- OSIF_WindowFrameBufferInfo fbi = createWindow ("gui0 - Window 3" );
46- graphics_rect (& fbi , 0 , 0 , fbi .width_px , fbi .height_px , 0x0 );
69+ OSIF_WindowFrameBufferInfo fbi = createWindow ("gui0 - Window 1" );
70+ int value = 1 ;
71+ int incby = 1 ;
4772 while (1 ) {
48- if ((UINT )(x + width ) >= fbi .width_px ) {
49- x = 0 ;
50- graphics_rect (& fbi , 0 , 0 , fbi .width_px , fbi .height_px , 0x0 );
51- }
52- graphics_rect (& fbi , (UINT )x , 0 , (UINT )width , fbi .height_px , color );
53- x += width + 3 ;
73+ triangle_sum (& value , 1 , 10 , & incby );
5474
55- cm_window_flush_graphics ();
56- cm_delay (500 );
75+ for (unsigned int x = 0 ; x < fbi .width_px ; x ++ ) {
76+ for (unsigned int y = 0 ; y < fbi .height_px ; y ++ ) {
77+ UINT color = ((x ) * (UINT )value & 255 ) << 0 ;
78+ graphics_putpixel (& fbi , x , y , color );
79+ }
80+ }
81+ cm_delay (50 );
5782 }
5883}
5984
6085void thread1 ()
6186{
62- OSIF_WindowFrameBufferInfo fbi = createWindow ("gui0 - Window 1 " );
63- int modby = 1 ;
87+ OSIF_WindowFrameBufferInfo fbi = createWindow ("gui0 - Window 2 " );
88+ int value = 10 ;
6489 int incby = 1 ;
6590 while (1 ) {
66- if (modby == 10 ) {
67- incby = -1 ;
68- } else if (modby == 1 ) {
69- incby = 1 ;
70- }
71- modby += incby ;
91+ triangle_sum (& value , 10 , 20 , & incby );
7292
7393 for (unsigned int x = 0 ; x < fbi .width_px ; x ++ ) {
7494 for (unsigned int y = 0 ; y < fbi .height_px ; y ++ ) {
75- UINT color = (20 * (UINT )modby & 255 ) << 16 ;
95+ UINT color = (( y ) * (UINT )value & 255 ) << 16 ;
7696 graphics_putpixel (& fbi , x , y , color );
7797 }
7898 }
79- cm_window_flush_graphics ();
80- cm_delay (100 );
99+ cm_delay (50 );
81100 }
82101}
83102
84103void thread2 ()
85104{
86- OSIF_WindowFrameBufferInfo fbi = createWindow ("gui0 - Window 2 " );
87- int modby = 1 ;
105+ OSIF_WindowFrameBufferInfo fbi = createWindow ("gui0 - Window 3 " );
106+ int value = 1 ;
88107 int incby = 1 ;
89108 while (1 ) {
90- if (modby == 10 ) {
91- incby = -1 ;
92- } else if (modby == 1 ) {
93- incby = 1 ;
94- }
95- modby += incby ;
109+ triangle_sum (& value , 1 , 10 , & incby );
96110
97111 for (unsigned int x = 0 ; x < fbi .width_px ; x ++ ) {
98112 for (unsigned int y = 0 ; y < fbi .height_px ; y ++ ) {
99- UINT color = ((x + y ) * (UINT )modby & 255 ) << 8 ;
113+ UINT color = ((x + y ) * (UINT )value & 255 ) << 8 ;
100114 graphics_putpixel (& fbi , x , y , color );
101115 }
102116 }
103- cm_window_flush_graphics ();
104117 cm_delay (80 );
105118 }
106119}
0 commit comments