Diff markup
001 001
002 002
003 003
004 004
005 005
006 006
007 007
008 008
009 009
010 010
011 011
012 012
013 013
014 014
015 015
016 016
017 017
018 018
019 #include <crt.h> 019 #include <crt.h>
020 #include <libc.h> 020 #include <libc.h>
021 #include <string.h> 021 #include <string.h>
022 #include <stdarg.h> 022 #include <stdarg.h>
023 #include <debug.h> 023 #include <debug.h>
024 024
025 025
026 026
027 027
028 028
029 029
030 030
031 static char *str1 = 031 static char *str1 =
032 " _ _ _ _ ___ 032 " _ _ _ _ ___ _ _ _ _ _ "
033 " | | | | ___ | | | | ___ |_ _| 033 " | | | | ___ | | | | ___ |_ _| __ _ _ __ ___ | |_ | |__ _ __ ___ __ _ __| | / | | |"
034 " | |_| | / _ \\ | | | | / _ \\ | | 034 " | |_| | / _ \\ | | | | / _ \\ | | / _` | | '_ ` _ \\ | __| | '_ \\ | '__| / _ \\ / _` | / _` | | | | |"
035 " | _ | | __/ | | | | | (_) | _ | | 035 " | _ | | __/ | | | | | (_) | _ | | | (_| | | | | | | | | |_ | | | | | | | __/ | (_| | | (_| | | | |_|"
036 " |_| |_| \\___| |_| |_| \\___/ ( ) |___| 036 " |_| |_| \\___| |_| |_| \\___/ ( ) |___| \\__,_| |_| |_| |_| \\__| |_| |_| |_| \\___| \\__,_| \\__,_| |_| (_)"
037 " |/ 037 " |/ ";
038 038
039 static char *str2 = 039 static char *str2 =
040 " _ _ _ _ ___ 040 " _ _ _ _ ___ _ _ _ ____ _ "
041 " | | | | ___ | | | | ___ |_ _| 041 " | | | | ___ | | | | ___ |_ _| __ _ _ __ ___ | |_ | |__ _ __ ___ __ _ __| | |___ \\ | |"
042 " | |_| | / _ \\ | | | | / _ \\ | | 042 " | |_| | / _ \\ | | | | / _ \\ | | / _` | | '_ ` _ \\ | __| | '_ \\ | '__| / _ \\ / _` | / _` | __) | | |"
043 " | _ | | __/ | | | | | (_) | _ | | 043 " | _ | | __/ | | | | | (_) | _ | | | (_| | | | | | | | | |_ | | | | | | | __/ | (_| | | (_| | / __/ |_|"
044 " |_| |_| \\___| |_| |_| \\___/ ( ) |___| 044 " |_| |_| \\___| |_| |_| \\___/ ( ) |___| \\__,_| |_| |_| |_| \\__| |_| |_| |_| \\___| \\__,_| \\__,_| |_____| (_)"
045 " |/ 045 " |/ ";
046 046
047 047
048 048
049 049
050 static struct x86_videomem_char 050 static struct x86_videomem_char
051 { 051 {
052 unsigned char character; 052 unsigned char character;
053 unsigned char attribute; 053 unsigned char attribute;
054 } * video; 054 } * video;
055 055
056 056
057 static void print(int line, int col, char c, u 057 static void print(int line, int col, char c, unsigned char attr)
058 { 058 {
059 video[line*80 + col].character = c; 059 video[line*80 + col].character = c;
060 video[line*80 + col].attribute = attr; 060 video[line*80 + col].attribute = attr;
061 } 061 }
062 062
063 063
064 064
065 065
066 066
067 static void print_banner(int top_line, const c 067 static void print_banner(int top_line, const char * str, int nlines,
068 unsigned char attr, u 068 unsigned char attr, unsigned pause_ms,
069 int direction) 069 int direction)
070 { 070 {
071 int nbcols = strnlen(str, 16384) / nlines; 071 int nbcols = strnlen(str, 16384) / nlines;
072 int base_char = 0; 072 int base_char = 0;
073 073
074 while (1) 074 while (1)
075 { 075 {
076 int col; 076 int col;
077 077
078 for (col = 0 ; col < 80 ; col ++) 078 for (col = 0 ; col < 80 ; col ++)
079 { 079 {
080 int col_in_str = (col + base_char) % 080 int col_in_str = (col + base_char) % (nbcols + 20);
081 int line; 081 int line;
082 082
083 for (line = 0 ; line < nlines ; line 083 for (line = 0 ; line < nlines ; line ++)
084 if (col_in_str < nbcols) 084 if (col_in_str < nbcols)
085 print(top_line + line, col, str[ 085 print(top_line + line, col, str[line*nbcols + col_in_str], attr);
086 else 086 else
087 print(top_line + line, col, ' ', 087 print(top_line + line, col, ' ', attr);
088 } 088 }
089 089
090 _sos_nanosleep(0, pause_ms * 1000000); 090 _sos_nanosleep(0, pause_ms * 1000000);
091 091
092 if (direction > 0) 092 if (direction > 0)
093 base_char ++; 093 base_char ++;
094 else 094 else
095 base_char --; 095 base_char --;
096 096
097 if (base_char < 0) 097 if (base_char < 0)
098 base_char = nbcols + 20 - 1; 098 base_char = nbcols + 20 - 1;
099 } 099 }
100 } 100 }
101 101
102 102
103 struct thread_param 103 struct thread_param
104 { 104 {
105 int top_line; 105 int top_line;
106 const char * str; 106 const char * str;
107 int nlines; 107 int nlines;
108 unsigned char attr; 108 unsigned char attr;
109 unsigned int pause_ms; 109 unsigned int pause_ms;
110 int direction; 110 int direction;
111 }; 111 };
112 112
113 113
114 static void banner_thread(const struct thread_ 114 static void banner_thread(const struct thread_param *p)
115 { 115 {
116 print_banner(p->top_line, p->str, p->nlines, 116 print_banner(p->top_line, p->str, p->nlines, p->attr,
117 p->pause_ms, p->direction); 117 p->pause_ms, p->direction);
118 } 118 }
119 119
120 static struct thread_param p1, p2; 120 static struct thread_param p1, p2;
121 int main() !! 121 int main(void)
122 { 122 {
123 int fd; 123 int fd;
124 124
125 125
126 fd = open("/dev/mem", O_RDWR); 126 fd = open("/dev/mem", O_RDWR);
127 video = mmap(0, 4096, 127 video = mmap(0, 4096,
128 PROT_READ | PROT_WRITE, 128 PROT_READ | PROT_WRITE,
129 MAP_SHARED, 129 MAP_SHARED,
130 fd, 0xb8000); 130 fd, 0xb8000);
131 close(fd); 131 close(fd);
132 132
133 p1.top_line = 3; 133 p1.top_line = 3;
134 p1.str = str1; 134 p1.str = str1;
135 p1.nlines = 6; 135 p1.nlines = 6;
136 p1.attr = 14 | (7 << 4); 136 p1.attr = 14 | (7 << 4);
137 p1.pause_ms = 10; 137 p1.pause_ms = 10;
138 p1.direction = 1; 138 p1.direction = 1;
139 _sos_new_thread((sos_thread_func_t*)banner_t 139 _sos_new_thread((sos_thread_func_t*)banner_thread, (void*) & p1, 8192);
140 140
141 p2.top_line = 10; 141 p2.top_line = 10;
142 p2.str = str2; 142 p2.str = str2;
143 p2.nlines = 6; 143 p2.nlines = 6;
144 p2.attr = (4 << 4) | (7 << 4); 144 p2.attr = (4 << 4) | (7 << 4);
145 p2.pause_ms = 20; 145 p2.pause_ms = 20;
146 p2.direction = -1; 146 p2.direction = -1;
147 _sos_new_thread((sos_thread_func_t*)banner_t 147 _sos_new_thread((sos_thread_func_t*)banner_thread, (void*) & p2, 8192);
148 148
149 return 0; 149 return 0;
150 } 150 }