1515#define C_YELLOW 0xE
1616#define C_WHITE 0xF
1717
18+ #define INT_MAX 0xFFFFFFFF
19+
20+ #define WINDOW_HEIGHT 0x18
21+ #define WINDOW_WIDTH 0x4F
22+ #define CLOCKS_PER_MS 56230 // 5% of Host CPU
23+
24+ #define SLEEP_FACTOR_NUM 3 // Possiblity of improvement.
25+ #define SLEEP_FACTOR_DENO 2
26+ #define SLEEP_BURST_MS INT_MAX/CLOCKS_PER_MS/SLEEP_FACTOR_NUM*SLEEP_FACTOR_DENO
27+
1828#define make_color (fg , bg ) ((unsigned char)((fg) + ((bg)<<4)))
1929
20- extern void _low_print (char str [], unsigned short int n ,
30+ extern void _low_print (char str [], unsigned short n ,
2131 unsigned char x ,unsigned char y ,
2232 unsigned char color );
2333
34+ extern void _low_put_chars (char c ,unsigned short count , unsigned char color );
35+ extern void _low_move_xy (unsigned char x , unsigned char y , unsigned char page );
36+ extern void _low_clear_screen (unsigned char color ,
37+ unsigned char x1 ,unsigned char y1 ,
38+ unsigned char x2 , unsigned char y2 );
39+ extern void _low_sleep (unsigned int half_instructions_count );
40+
41+ void run ();
42+
2443char message_welcome [] = "C says 'Hello World'" ;
2544
26- void entry_stage2 () {
27- _low_print (message_welcome ,sizeof (message_welcome )- 1 ,6 ,11 , make_color (C_GREEN , C_BLACK ));
45+ unsigned char CURRENT_X = 0 ;
46+ unsigned char CURRENT_Y = 0 ;
47+
48+ void move_xy (unsigned char x , unsigned char y ) {
49+ CURRENT_X = x ;
50+ CURRENT_Y = y ;
51+ _low_move_xy (x ,y ,0 );
52+ }
53+
54+ void move_xy_diff (unsigned char dx , unsigned char dy ) {
55+ CURRENT_X += dx ;
56+ CURRENT_Y += dy ;
57+ _low_move_xy (CURRENT_X ,CURRENT_Y ,0 );
58+ }
59+
60+ void put_char (char c , unsigned char color ) {
61+ _low_put_chars (c ,1 , color );
62+ move_xy_diff (1 , 0 );
63+ }
64+
65+ void put_chars (char c ,unsigned short count , unsigned char color ) {
66+ _low_put_chars (c ,count , color );
67+ move_xy_diff (count , 0 );
68+ }
69+
70+ void put_string (char * str , unsigned char color ) {
71+ while ((* str )!= '\0' ) {
72+ put_char (* str , color );
73+ str ++ ;
74+ }
75+ }
76+
77+ void sleep (unsigned int ms ) {
78+ while (ms > 0 ) {
79+ unsigned int fms = ms > SLEEP_BURST_MS ?SLEEP_BURST_MS :ms ;
80+ unsigned int cycles = CLOCKS_PER_MS * fms /SLEEP_FACTOR_DENO * SLEEP_FACTOR_NUM ;
81+ _low_sleep (cycles );
82+ ms -= fms ;
83+ }
84+ }
85+
86+ void entry_stage () {
87+ move_xy (6 , 11 );
88+ put_string (message_welcome , make_color (C_GREEN , C_BLACK ));
89+ sleep (1000 );
90+ run ();
91+ while (1 );
92+ }
93+
94+ char application_list [5 ][10 ] = {"Sample 1" , "Sample 2" , "Sample 3" , "Sample 4" , "Sample 5" };
95+ void print_applications (unsigned char x , unsigned char y , char * list , unsigned char count , unsigned char max_strlen ) {
96+ for (int i = 0 ;i < count ;i ++ ) {
97+ move_xy (x ,y + i );
98+ put_string ("X " ,make_color (C_BLUE , C_LIGHT_GRAY ));
99+ put_string (list ,make_color (C_BLACK , C_LIGHT_GRAY ));
100+ list += max_strlen ;
101+ }
102+ }
103+
104+ void run () {
105+ _low_clear_screen (make_color (C_WHITE , C_DARK_GRAY ), 0 , 0 , WINDOW_WIDTH , WINDOW_HEIGHT );
106+ _low_clear_screen (make_color (C_WHITE , C_LIGHT_GRAY ), 1 , 1 , WINDOW_WIDTH - 1 , WINDOW_HEIGHT - 1 );
107+ move_xy (1 ,0 );
108+ put_string ("Fuzzy OS" , make_color (C_WHITE , C_DARK_GRAY ));
109+ move_xy (3 ,3 );
110+ put_string ("Applications:" , make_color (C_BLACK , C_LIGHT_GRAY ));
111+ print_applications (3 ,4 , (char * )application_list , 5 , 10 );
28112}
0 commit comments