Rev 1501 | Rev 1534 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1501 | Rev 1530 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <align.h> |
29 | #include <align.h> |
30 | #include <async.h> |
30 | #include <async.h> |
31 | #include <ipc/ipc.h> |
31 | #include <ipc/ipc.h> |
32 | #include <errno.h> |
32 | #include <errno.h> |
33 | #include <stdio.h> |
33 | #include <stdio.h> |
34 | #include <ddi.h> |
34 | #include <ddi.h> |
35 | #include <sysinfo.h> |
35 | #include <sysinfo.h> |
36 | #include <as.h> |
36 | #include <as.h> |
37 | #include <ipc/fb.h> |
37 | #include <ipc/fb.h> |
38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
39 | #include <ipc/ns.h> |
39 | #include <ipc/ns.h> |
40 | #include <ipc/services.h> |
40 | #include <ipc/services.h> |
41 | 41 | ||
42 | #include "ega.h" |
42 | #include "ega.h" |
43 | 43 | ||
44 | /* Allow only 1 connection */ |
44 | /* Allow only 1 connection */ |
45 | static int client_connected = 0; |
45 | static int client_connected = 0; |
46 | 46 | ||
47 | static unsigned int scr_width; |
47 | static unsigned int scr_width; |
48 | static unsigned int scr_height; |
48 | static unsigned int scr_height; |
49 | static char *scr_addr; |
49 | static char *scr_addr; |
50 | 50 | ||
51 | static void clrscr(void) |
51 | static void clrscr(void) |
52 | { |
52 | { |
53 | int i; |
53 | int i; |
54 | 54 | ||
55 | for (i=0; i < scr_width*scr_height; i++) |
55 | for (i=0; i < scr_width*scr_height; i++) |
56 | scr_addr[i*2] = ' '; |
56 | scr_addr[i*2] = ' '; |
57 | } |
57 | } |
58 | 58 | ||
59 | static void printchar(char c, unsigned int row, unsigned int col) |
59 | static void printchar(char c, unsigned int row, unsigned int col) |
60 | { |
60 | { |
61 | scr_addr[(row*scr_width + col)*2] = c; |
61 | scr_addr[(row*scr_width + col)*2] = c; |
62 | } |
62 | } |
63 | 63 | ||
64 | static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
64 | static void ega_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
65 | { |
65 | { |
66 | int retval; |
66 | int retval; |
67 | ipc_callid_t callid; |
67 | ipc_callid_t callid; |
68 | ipc_call_t call; |
68 | ipc_call_t call; |
69 | char c; |
69 | char c; |
70 | unsigned int row, col; |
70 | unsigned int row, col; |
71 | 71 | ||
72 | if (client_connected) { |
72 | if (client_connected) { |
73 | ipc_answer_fast(iid, ELIMIT, 0,0); |
73 | ipc_answer_fast(iid, ELIMIT, 0,0); |
74 | return; |
74 | return; |
75 | } |
75 | } |
76 | client_connected = 1; |
76 | client_connected = 1; |
77 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
77 | ipc_answer_fast(iid, 0, 0, 0); /* Accept connection */ |
78 | 78 | ||
79 | while (1) { |
79 | while (1) { |
80 | callid = async_get_call(&call); |
80 | callid = async_get_call(&call); |
81 | switch (IPC_GET_METHOD(call)) { |
81 | switch (IPC_GET_METHOD(call)) { |
82 | case IPC_M_PHONE_HUNGUP: |
82 | case IPC_M_PHONE_HUNGUP: |
83 | client_connected = 0; |
83 | client_connected = 0; |
84 | ipc_answer_fast(callid,0,0,0); |
84 | ipc_answer_fast(callid,0,0,0); |
85 | return; /* Exit thread */ |
85 | return; /* Exit thread */ |
86 | case FB_GET_CSIZE: |
86 | case FB_GET_CSIZE: |
87 | ipc_answer_fast(callid, 0, scr_width, scr_height); |
87 | ipc_answer_fast(callid, 0, scr_height, scr_width); |
88 | continue; |
88 | continue; |
89 | case FB_CLEAR: |
89 | case FB_CLEAR: |
90 | clrscr(); |
90 | clrscr(); |
91 | retval = 0; |
91 | retval = 0; |
92 | break; |
92 | break; |
93 | case FB_PUTCHAR: |
93 | case FB_PUTCHAR: |
94 | c = IPC_GET_ARG1(call); |
94 | c = IPC_GET_ARG1(call); |
95 | row = IPC_GET_ARG2(call); |
95 | row = IPC_GET_ARG2(call); |
96 | col = IPC_GET_ARG3(call); |
96 | col = IPC_GET_ARG3(call); |
97 | if (row >= scr_width || col >= scr_height) { |
97 | if (row >= scr_width || col >= scr_height) { |
98 | retval = EINVAL; |
98 | retval = EINVAL; |
99 | break; |
99 | break; |
100 | } |
100 | } |
101 | printchar(c,row,col); |
101 | printchar(c,row,col); |
102 | retval = 0; |
102 | retval = 0; |
103 | break; |
103 | break; |
104 | default: |
104 | default: |
105 | retval = ENOENT; |
105 | retval = ENOENT; |
106 | } |
106 | } |
107 | ipc_answer_fast(callid,retval,0,0); |
107 | ipc_answer_fast(callid,retval,0,0); |
108 | } |
108 | } |
109 | } |
109 | } |
110 | 110 | ||
111 | int ega_init(void) |
111 | int ega_init(void) |
112 | { |
112 | { |
113 | void *ega_ph_addr; |
113 | void *ega_ph_addr; |
114 | size_t sz; |
114 | size_t sz; |
115 | 115 | ||
116 | 116 | ||
117 | ega_ph_addr=(void *)sysinfo_value("fb.address.physical"); |
117 | ega_ph_addr=(void *)sysinfo_value("fb.address.physical"); |
118 | scr_width=sysinfo_value("fb.width"); |
118 | scr_width=sysinfo_value("fb.width"); |
119 | scr_height=sysinfo_value("fb.height"); |
119 | scr_height=sysinfo_value("fb.height"); |
120 | 120 | ||
121 | sz = scr_width*scr_height*2; |
121 | sz = scr_width*scr_height*2; |
122 | scr_addr = as_get_mappable_page(sz); |
122 | scr_addr = as_get_mappable_page(sz); |
123 | 123 | ||
124 | map_physmem(ega_ph_addr, scr_addr, ALIGN_UP(sz,PAGE_SIZE)>>PAGE_WIDTH, |
124 | map_physmem(ega_ph_addr, scr_addr, ALIGN_UP(sz,PAGE_SIZE)>>PAGE_WIDTH, |
125 | AS_AREA_READ | AS_AREA_WRITE); |
125 | AS_AREA_READ | AS_AREA_WRITE); |
126 | 126 | ||
127 | async_set_client_connection(ega_client_connection); |
127 | async_set_client_connection(ega_client_connection); |
128 | 128 | ||
129 | clrscr(); |
129 | clrscr(); |
130 | 130 | ||
131 | return 0; |
131 | return 0; |
132 | } |
132 | } |
133 | 133 |