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 ]

Diff markup

Differences between /userland/banner.c (Article 7.5) and /userland/banner.c (Article 9.5)


001 /* Copyright (C) 2005 David Decotigny             001 /* Copyright (C) 2005 David Decotigny
002                                                   002 
003    This program is free software; you can redi    003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU Genera    004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundatio    005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any lat    006    of the License, or (at your option) any later version.
007                                                   007    
008    This program is distributed in the hope tha    008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the     009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR    010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details    011    GNU General Public License for more details.
012                                                   012    
013    You should have received a copy of the GNU     013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to t    014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 3    015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA.                                           016    USA. 
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  * @file banner.c                                 026  * @file banner.c
027  *                                                027  *
028  * Basic tests demonstrating how to create mul    028  * Basic tests demonstrating how to create multithreaded processes
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  * Structure of a character in the x86 video m    048  * Structure of a character in the x86 video memory mapping (text mode)
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  * Helper function that scrolls the given stri    065  * Helper function that scrolls the given string on the screen
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;
                                                   >> 124 
123   /* Map the x86 text-mode framebuffer in user    125   /* Map the x86 text-mode framebuffer in user space */
                                                   >> 126   fd = open("/dev/mem", O_RDWR);
124   video = mmap(0, 4096,                           127   video = mmap(0, 4096,
125                PROT_READ | PROT_WRITE,            128                PROT_READ | PROT_WRITE,
126                MAP_SHARED,                        129                MAP_SHARED,
127                "/dev/mem", 0xb8000);           !! 130                fd, 0xb8000);
                                                   >> 131   close(fd);
128                                                   132 
129   p1.top_line  = 3;                               133   p1.top_line  = 3;
130   p1.str       = str1;                            134   p1.str       = str1;
131   p1.nlines    = 6;                               135   p1.nlines    = 6;
132   p1.attr      = 14 | (7 << 4);                   136   p1.attr      = 14 | (7 << 4);
133   p1.pause_ms  = 10;                              137   p1.pause_ms  = 10;
134   p1.direction = 1;                               138   p1.direction = 1;
135   _sos_new_thread((sos_thread_func_t*)banner_t    139   _sos_new_thread((sos_thread_func_t*)banner_thread, (void*) & p1, 8192);
136                                                   140 
137   p2.top_line  = 10;                              141   p2.top_line  = 10;
138   p2.str       = str2;                            142   p2.str       = str2;
139   p2.nlines    = 6;                               143   p2.nlines    = 6;
140   p2.attr      = (4 << 4) | (7 << 4);             144   p2.attr      = (4 << 4) | (7 << 4);
141   p2.pause_ms  = 20;                              145   p2.pause_ms  = 20;
142   p2.direction = -1;                              146   p2.direction = -1;
143   _sos_new_thread((sos_thread_func_t*)banner_t    147   _sos_new_thread((sos_thread_func_t*)banner_thread, (void*) & p2, 8192);
144                                                << 
145   _sos_nanosleep(3, 0);                        << 
146                                                   148 
147   return 0;                                       149   return 0;
148 }                                                 150 }
                                                      

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