Changeset a2cd194 in mainline for fb/fb.c


Ignore:
Timestamp:
2006-05-22T11:14:25Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8bc924e
Parents:
6862338
Message:

Added some cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fb/fb.c

    r6862338 ra2cd194  
    11/*
    22 * Copyright (C) 2006 Jakub Vana
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  *
    9  * - Redistributions of source code must retain the above copyright
    10  *   notice, this list of conditions and the following disclaimer.
    11  * - Redistributions in binary form must reproduce the above copyright
    12  *   notice, this list of conditions and the following disclaimer in the
    13  *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
    15  *   derived from this software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    27  */
    28 
    29 #include <stdio.h>
    30 #include <ddi.h>
    31 #include <task.h>
    32 #include <stdlib.h>
    33 #include <ddi.h>
    34 #include <sysinfo.h>
    35 #include <align.h>
    36 #include <as.h>
    37 #include <ipc/fb.h>
    38 
    39 
    40 #include <ipc/ipc.h>
    41 #include <ipc/services.h>
    42 #include <unistd.h>
    43 #include <stdlib.h>
    44 #include <ipc/ns.h>
    45 
    46 #include <kernel/errno.h>
    47 #include <async.h>
    48 
    49 #include "fb.h"
    50 
    51 #define EFB (-1)
    52 
    53 #define DEFAULT_BGCOLOR         0x000080
    54 #define DEFAULT_FGCOLOR         0xffff00
    55 #define DEFAULT_LOGOCOLOR       0x0000ff
    56 
    57 #define MAIN_BGCOLOR            0x404000
    58 #define MAIN_FGCOLOR            0x000000
    59 #define MAIN_LOGOCOLOR  0x404000
    60 
    61 #define SPACING (2)
    62 
    63 #define H_NO_VFBS 3
    64 #define V_NO_VFBS 3
    65 
    66 
    67 static void fb_putchar(int item,char ch);
    68 int create_window(int item,unsigned int x, unsigned int y,unsigned int x_size, unsigned int y_size,
    69         unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);
    70 void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan,
    71         unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);
    72 
    73 
    74 unsigned int mod_col(unsigned int col,int mod);
    75 
    76 
    77 
    78 static int init_fb(void)
    79 {
    80         __address fb_ph_addr;
    81         unsigned int fb_width;
    82         unsigned int fb_height;
    83         unsigned int fb_bpp;
    84         unsigned int fb_scanline;
    85         __address fb_addr;
    86         int a=0;
    87         int i,j,k;
    88         int w;
    89         char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB ";
    90 
    91         fb_ph_addr=sysinfo_value("fb.address.physical");
    92         fb_width=sysinfo_value("fb.width");
    93         fb_height=sysinfo_value("fb.height");
    94         fb_bpp=sysinfo_value("fb.bpp");
    95         fb_scanline=sysinfo_value("fb.scanline");
    96 
    97         fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
    98 
    99 
    100        
    101         map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr,
    102                     (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,1);
    103        
    104         fb_init(0,fb_addr, fb_width, fb_height, fb_bpp, fb_scanline,
    105                 MAIN_BGCOLOR,MAIN_FGCOLOR,MAIN_LOGOCOLOR);
    106 
    107         fb_putchar(0,'\n');
    108         fb_putchar(0,' ');
    109 
    110         for(i=0;i<H_NO_VFBS;i++)
    111                 for(j=0;j<V_NO_VFBS;j++) {
    112                         w = create_window(0,(fb_width/H_NO_VFBS)*i+SPACING,
    113                                           (fb_height/V_NO_VFBS)*j+SPACING,(fb_width/H_NO_VFBS)-2*SPACING ,
    114                                           (fb_height/V_NO_VFBS)-2*SPACING,mod_col(DEFAULT_BGCOLOR,/*i+j*H_NO_VFBS*/0),
    115                                           mod_col(DEFAULT_FGCOLOR,/*i+j*H_NO_VFBS*/0),
    116                                           mod_col(DEFAULT_LOGOCOLOR,/*i+j*H_NO_VFBS)*/0));
    117                        
    118                         if( w== EFB)
    119                                 return -1;
    120                        
    121                         for(k=0;text[k];k++)
    122                                 fb_putchar(w,text[k]);
    123                         fb_putchar(w,w+'0');
    124                         fb_putchar(w,'\n');
    125                 }
    126         return 0;
    127 }
    128 
    129 int vfb_no = 1;
    130 void client_connection(ipc_callid_t iid, ipc_call_t *icall)
    131 {
    132         ipc_callid_t callid;
    133         ipc_call_t call;
    134         int vfb = vfb_no++;
    135 
    136         if (vfb > 9) {
    137                 ipc_answer_fast(iid, ELIMIT, 0,0);
    138                 return;
    139         }
    140         ipc_answer_fast(iid, 0, 0, 0);
    141 
    142         while (1) {
    143                 callid = async_get_call(&call);
    144                 switch (IPC_GET_METHOD(call)) {
    145                 case IPC_M_PHONE_HUNGUP:
    146                         ipc_answer_fast(callid,0,0,0);
    147                         return; /* Exit thread */
    148 
    149                 case FB_PUTCHAR:
    150                         ipc_answer_fast(callid,0,0,0);
    151                         fb_putchar(vfb,IPC_GET_ARG2(call));
    152                         break;
    153                 default:
    154                         ipc_answer_fast(callid,ENOENT,0,0);
    155                 }
    156         }
    157 }
    158 
    159 int main(int argc, char *argv[])
    160 {
    161         ipc_call_t call;
    162         ipc_callid_t callid;
    163         char connected = 0;
    164         int res;
    165         int c;
    166         ipcarg_t phonead;
    167        
    168         ipcarg_t retval, arg1, arg2;
    169 
    170         if(!sysinfo_value("fb")) return -1;
    171 
    172 
    173         if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0)
    174                 return -1;
    175        
    176         init_fb();
    177 
    178         async_manager();
    179         /* Never reached */
    180         return 0;
    181 }
    182 /*
    1833 * Copyright (C) 2006 Ondrej Palkovsky
    1844 * All rights reserved.
     
    20828 */
    20929
     30#include <stdio.h>
     31#include <ddi.h>
     32#include <task.h>
     33#include <stdlib.h>
     34#include <ddi.h>
     35#include <sysinfo.h>
     36#include <align.h>
     37#include <as.h>
     38#include <ipc/fb.h>
     39
     40
     41#include <ipc/ipc.h>
     42#include <ipc/services.h>
     43#include <unistd.h>
     44#include <stdlib.h>
     45#include <ipc/ns.h>
     46
     47#include <kernel/errno.h>
     48#include <async.h>
     49
     50
    21051#include "font-8x16.h"
    21152#include <string.h>
    21253
    21354#include "helenos.xbm"
    214 
    215 
    216 
    217 
     55#include "fb.h"
     56
     57#define EFB (-1)
     58
     59#define DEFAULT_BGCOLOR         0x000080
     60#define DEFAULT_FGCOLOR         0xffff00
     61#define DEFAULT_LOGOCOLOR       0x0000ff
     62
     63#define MAIN_BGCOLOR            0x404000
     64#define MAIN_FGCOLOR            0x000000
     65#define MAIN_LOGOCOLOR  0x404000
     66
     67#define SPACING (2)
     68
     69#define H_NO_VFBS 3
     70#define V_NO_VFBS 3
     71
     72
     73static void fb_putchar(int item,char ch);
     74int create_window(int item,unsigned int x, unsigned int y,unsigned int x_size, unsigned int y_size,
     75        unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);
     76void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan,
     77        unsigned int BGCOLOR,unsigned int FGCOLOR,unsigned int LOGOCOLOR);
     78
     79
     80unsigned int mod_col(unsigned int col,int mod);
     81
     82
     83
     84static int init_fb(void)
     85{
     86        __address fb_ph_addr;
     87        unsigned int fb_width;
     88        unsigned int fb_height;
     89        unsigned int fb_bpp;
     90        unsigned int fb_scanline;
     91        __address fb_addr;
     92        int a=0;
     93        int i,j,k;
     94        int w;
     95        char text[]="HelenOS Framebuffer driver\non Virtual Framebuffer\nVFB ";
     96
     97        fb_ph_addr=sysinfo_value("fb.address.physical");
     98        fb_width=sysinfo_value("fb.width");
     99        fb_height=sysinfo_value("fb.height");
     100        fb_bpp=sysinfo_value("fb.bpp");
     101        fb_scanline=sysinfo_value("fb.scanline");
     102
     103        fb_addr=ALIGN_UP(((__address)set_maxheapsize(USER_ADDRESS_SPACE_SIZE_ARCH>>1)),PAGE_SIZE);
     104
     105
     106       
     107        map_physmem(task_get_id(),(void *)((__address)fb_ph_addr),(void *)fb_addr,
     108                    (fb_scanline*fb_height+PAGE_SIZE-1)>>PAGE_WIDTH,1);
     109       
     110        fb_init(0,fb_addr, fb_width, fb_height, fb_bpp, fb_scanline,
     111                MAIN_BGCOLOR,MAIN_FGCOLOR,MAIN_LOGOCOLOR);
     112
     113        fb_putchar(0,'\n');
     114        fb_putchar(0,' ');
     115
     116        for(i=0;i<H_NO_VFBS;i++)
     117                for(j=0;j<V_NO_VFBS;j++) {
     118                        w = create_window(0,(fb_width/H_NO_VFBS)*i+SPACING,
     119                                          (fb_height/V_NO_VFBS)*j+SPACING,(fb_width/H_NO_VFBS)-2*SPACING ,
     120                                          (fb_height/V_NO_VFBS)-2*SPACING,mod_col(DEFAULT_BGCOLOR,/*i+j*H_NO_VFBS*/0),
     121                                          mod_col(DEFAULT_FGCOLOR,/*i+j*H_NO_VFBS*/0),
     122                                          mod_col(DEFAULT_LOGOCOLOR,/*i+j*H_NO_VFBS)*/0));
     123                       
     124                        if( w== EFB)
     125                                return -1;
     126                       
     127                        for(k=0;text[k];k++)
     128                                fb_putchar(w,text[k]);
     129                        fb_putchar(w,w+'0');
     130                        fb_putchar(w,'\n');
     131                }
     132        return 0;
     133}
     134
     135int vfb_no = 1;
     136void client_connection(ipc_callid_t iid, ipc_call_t *icall)
     137{
     138        ipc_callid_t callid;
     139        ipc_call_t call;
     140        int vfb = vfb_no++;
     141
     142        if (vfb > 9) {
     143                ipc_answer_fast(iid, ELIMIT, 0,0);
     144                return;
     145        }
     146        ipc_answer_fast(iid, 0, 0, 0);
     147
     148        while (1) {
     149                callid = async_get_call(&call);
     150                switch (IPC_GET_METHOD(call)) {
     151                case IPC_M_PHONE_HUNGUP:
     152                        ipc_answer_fast(callid,0,0,0);
     153                        return; /* Exit thread */
     154
     155                case FB_PUTCHAR:
     156                        ipc_answer_fast(callid,0,0,0);
     157                        fb_putchar(vfb,IPC_GET_ARG2(call));
     158                        break;
     159                default:
     160                        ipc_answer_fast(callid,ENOENT,0,0);
     161                }
     162        }
     163}
     164
     165int main(int argc, char *argv[])
     166{
     167        ipc_call_t call;
     168        ipc_callid_t callid;
     169        char connected = 0;
     170        int res;
     171        int c;
     172        ipcarg_t phonead;
     173       
     174        ipcarg_t retval, arg1, arg2;
     175
     176        if(!sysinfo_value("fb")) return -1;
     177
     178
     179        if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, &phonead)) != 0)
     180                return -1;
     181       
     182        init_fb();
     183
     184        async_manager();
     185        /* Never reached */
     186        return 0;
     187}
    218188
    219189
Note: See TracChangeset for help on using the changeset viewer.