SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2005 David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 
019 #include <crt.h>
020 #include <libc.h>
021 #include <string.h>
022 #include <stdarg.h>
023 #include <debug.h>
024 
025 /**
026  * @file banner.c
027  *
028  * Basic tests demonstrating how to create multithreaded processes
029  */
030 
031 static char *str1 =
032 "  _   _          _   _                 ___                           _     _                                 _       _     _ "
033 " | | | |   ___  | | | |   ___         |_ _|     __ _   _ __ ___     | |_  | |__    _ __    ___    __ _    __| |     / |   | |"
034 " | |_| |  / _ \\ | | | |  / _ \\         | |     / _` | | '_ ` _ \\    | __| | '_ \\  | '__|  / _ \\  / _` |  / _` |     | |   | |"
035 " |  _  | |  __/ | | | | | (_) |  _     | |    | (_| | | | | | | |   | |_  | | | | | |    |  __/ | (_| | | (_| |     | |   |_|"
036 " |_| |_|  \\___| |_| |_|  \\___/  ( )   |___|    \\__,_| |_| |_| |_|    \\__| |_| |_| |_|     \\___|  \\__,_|  \\__,_|     |_|   (_)"
037 "                                |/                                                                                           ";
038 
039 static char *str2 =
040 "  _   _          _   _                 ___                           _     _                                 _       ____      _ "
041 " | | | |   ___  | | | |   ___         |_ _|     __ _   _ __ ___     | |_  | |__    _ __    ___    __ _    __| |     |___ \\    | |"
042 " | |_| |  / _ \\ | | | |  / _ \\         | |     / _` | | '_ ` _ \\    | __| | '_ \\  | '__|  / _ \\  / _` |  / _` |       __) |   | |"
043 " |  _  | |  __/ | | | | | (_) |  _     | |    | (_| | | | | | | |   | |_  | | | | | |    |  __/ | (_| | | (_| |      / __/    |_|"
044 " |_| |_|  \\___| |_| |_|  \\___/  ( )   |___|    \\__,_| |_| |_| |_|    \\__| |_| |_| |_|     \\___|  \\__,_|  \\__,_|     |_____|   (_)"
045 "                                |/                                                                                               ";
046 
047 /**
048  * Structure of a character in the x86 video memory mapping (text mode)
049  */
050 static struct x86_videomem_char
051 {
052   unsigned char character;
053   unsigned char attribute;
054 } * video;
055 
056 
057 static void print(int line, int col, char c, unsigned char attr)
058 {
059    video[line*80 + col].character = c;
060    video[line*80 + col].attribute = attr;
061 }
062 
063 
064 /**
065  * Helper function that scrolls the given string on the screen
066  */
067 static void print_banner(int top_line, const char * str, int nlines,
068                          unsigned char attr, unsigned pause_ms,
069                          int direction)
070 {
071   int nbcols = strnlen(str, 16384) / nlines;
072   int base_char = 0;
073 
074   while (1)
075     {
076       int col;
077 
078       for (col = 0 ; col < 80 ; col ++)
079         {
080           int col_in_str = (col + base_char) % (nbcols + 20);
081           int line;
082 
083           for (line = 0 ; line < nlines ; line ++)
084             if (col_in_str < nbcols)
085               print(top_line + line, col, str[line*nbcols + col_in_str], attr);
086             else
087               print(top_line + line, col, ' ', attr);
088         }
089 
090       _sos_nanosleep(0, pause_ms * 1000000);
091 
092       if (direction > 0)
093         base_char ++;
094       else
095         base_char --;
096 
097       if (base_char < 0)
098         base_char = nbcols + 20 - 1;
099     }
100 }
101 
102 
103 struct thread_param
104 {
105   int top_line;
106   const char * str;
107   int nlines;
108   unsigned char attr;
109   unsigned int pause_ms;
110   int direction;
111 };
112 
113 
114 static void banner_thread(const struct thread_param *p)
115 {
116   print_banner(p->top_line, p->str, p->nlines, p->attr,
117                p->pause_ms, p->direction);
118 }
119 
120 static struct thread_param p1, p2;
121 int main()
122 {
123   int fd;
124 
125   /* Map the x86 text-mode framebuffer in user space */
126   fd = open("/dev/mem", O_RDWR);
127   video = mmap(0, 4096,
128                PROT_READ | PROT_WRITE,
129                MAP_SHARED,
130                fd, 0xb8000);
131   close(fd);
132 
133   p1.top_line  = 3;
134   p1.str       = str1;
135   p1.nlines    = 6;
136   p1.attr      = 14 | (7 << 4);
137   p1.pause_ms  = 10;
138   p1.direction = 1;
139   _sos_new_thread((sos_thread_func_t*)banner_thread, (void*) & p1, 8192);
140 
141   p2.top_line  = 10;
142   p2.str       = str2;
143   p2.nlines    = 6;
144   p2.attr      = (4 << 4) | (7 << 4);
145   p2.pause_ms  = 20;
146   p2.direction = -1;
147   _sos_new_thread((sos_thread_func_t*)banner_thread, (void*) & p2, 8192);
148 
149   return 0;
150 }

source navigation ] diff markup ] identifier search ] general search ]