Rev 3675 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3675 | Rev 4377 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | */ |
34 | */ |
35 | /** @file |
35 | /** @file |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <async.h> |
38 | #include <async.h> |
39 | #include <ipc/fb.h> |
- | |
40 | #include <ipc/ipc.h> |
- | |
41 | #include <libc.h> |
39 | #include <libc.h> |
42 | #include <errno.h> |
- | |
43 | #include <string.h> |
- | |
44 | #include <libc.h> |
- | |
45 | #include <stdio.h> |
- | |
46 | #include <ipc/fb.h> |
- | |
47 | #include <sysinfo.h> |
40 | #include <sysinfo.h> |
48 | #include <as.h> |
41 | #include <as.h> |
49 | #include <align.h> |
- | |
50 | #include <ddi.h> |
42 | #include <ddi.h> |
51 | 43 | ||
52 | #include "serial_console.h" |
44 | #include "serial_console.h" |
53 | #include "msim.h" |
45 | #include "msim.h" |
54 | 46 | ||
55 | #define WIDTH 80 |
47 | #define WIDTH 80 |
56 | #define HEIGHT 25 |
48 | #define HEIGHT 24 |
57 | - | ||
58 | #define MAX_CONTROL 20 |
- | |
59 | - | ||
60 | /* Allow only 1 connection */ |
- | |
61 | static int client_connected = 0; |
- | |
62 | 49 | ||
63 | static char *virt_addr; |
50 | static char *virt_addr; |
64 | 51 | ||
65 | static void msim_putc(const char c) |
52 | static void msim_putc(const char c) |
66 | { |
53 | { |
67 | *virt_addr = c; |
54 | *virt_addr = c; |
68 | } |
55 | } |
69 | 56 | ||
70 | static void msim_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
- | |
71 | { |
- | |
72 | int retval; |
- | |
73 | ipc_callid_t callid; |
- | |
74 | ipc_call_t call; |
- | |
75 | char c; |
- | |
76 | int lastcol = 0; |
- | |
77 | int lastrow = 0; |
- | |
78 | int newcol; |
- | |
79 | int newrow; |
- | |
80 | int fgcolor; |
- | |
81 | int bgcolor; |
- | |
82 | int i; |
- | |
83 | - | ||
84 | if (client_connected) { |
- | |
85 | ipc_answer_0(iid, ELIMIT); |
- | |
86 | return; |
- | |
87 | } |
- | |
88 | - | ||
89 | client_connected = 1; |
- | |
90 | ipc_answer_0(iid, EOK); |
- | |
91 | - | ||
92 | /* Clear the terminal, set scrolling region |
- | |
93 | to 0 - 25 lines */ |
- | |
94 | serial_clrscr(); |
- | |
95 | serial_goto(0, 0); |
- | |
96 | serial_puts("\033[0;25r"); |
- | |
97 | - | ||
98 | while (true) { |
- | |
99 | callid = async_get_call(&call); |
- | |
100 | switch (IPC_GET_METHOD(call)) { |
- | |
101 | case IPC_M_PHONE_HUNGUP: |
- | |
102 | client_connected = 0; |
- | |
103 | ipc_answer_0(callid, EOK); |
- | |
104 | return; |
- | |
105 | case FB_PUTCHAR: |
- | |
106 | c = IPC_GET_ARG1(call); |
- | |
107 | newrow = IPC_GET_ARG2(call); |
- | |
108 | newcol = IPC_GET_ARG3(call); |
- | |
109 | if ((lastcol != newcol) || (lastrow != newrow)) |
- | |
110 | serial_goto(newrow, newcol); |
- | |
111 | lastcol = newcol + 1; |
- | |
112 | lastrow = newrow; |
- | |
113 | msim_putc(c); |
- | |
114 | retval = 0; |
- | |
115 | break; |
- | |
116 | case FB_CURSOR_GOTO: |
- | |
117 | newrow = IPC_GET_ARG1(call); |
- | |
118 | newcol = IPC_GET_ARG2(call); |
- | |
119 | serial_goto(newrow, newcol); |
- | |
120 | lastrow = newrow; |
- | |
121 | lastcol = newcol; |
- | |
122 | retval = 0; |
- | |
123 | break; |
- | |
124 | case FB_GET_CSIZE: |
- | |
125 | ipc_answer_2(callid, EOK, HEIGHT, WIDTH); |
- | |
126 | continue; |
- | |
127 | case FB_CLEAR: |
- | |
128 | serial_clrscr(); |
- | |
129 | retval = 0; |
- | |
130 | break; |
- | |
131 | case FB_SET_STYLE: |
- | |
132 | fgcolor = IPC_GET_ARG1(call); |
- | |
133 | bgcolor = IPC_GET_ARG2(call); |
- | |
134 | if (fgcolor < bgcolor) |
- | |
135 | serial_set_style(0); |
- | |
136 | else |
- | |
137 | serial_set_style(7); |
- | |
138 | retval = 0; |
- | |
139 | break; |
- | |
140 | case FB_SCROLL: |
- | |
141 | i = IPC_GET_ARG1(call); |
- | |
142 | if ((i > HEIGHT) || (i < -HEIGHT)) { |
- | |
143 | retval = EINVAL; |
- | |
144 | break; |
- | |
145 | } |
- | |
146 | serial_scroll(i); |
- | |
147 | serial_goto(lastrow, lastcol); |
- | |
148 | retval = 0; |
- | |
149 | break; |
- | |
150 | case FB_CURSOR_VISIBILITY: |
- | |
151 | if(IPC_GET_ARG1(call)) |
- | |
152 | serial_cursor_enable(); |
- | |
153 | else |
- | |
154 | serial_cursor_disable(); |
- | |
155 | retval = 0; |
- | |
156 | break; |
- | |
157 | default: |
- | |
158 | retval = ENOENT; |
- | |
159 | } |
- | |
160 | ipc_answer_0(callid, retval); |
- | |
161 | } |
- | |
162 | } |
- | |
163 | - | ||
164 | int msim_init(void) |
57 | int msim_init(void) |
165 | { |
58 | { |
166 | void *phys_addr = (void *) sysinfo_value("fb.address.physical"); |
59 | void *phys_addr = (void *) sysinfo_value("fb.address.physical"); |
167 | virt_addr = (char *) as_get_mappable_page(1); |
60 | virt_addr = (char *) as_get_mappable_page(1); |
168 | 61 | ||
169 | physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE); |
62 | if (physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE) != 0) |
- | 63 | return -1; |
|
170 | 64 | ||
171 | serial_console_init(msim_putc, WIDTH, HEIGHT); |
65 | serial_console_init(msim_putc, WIDTH, HEIGHT); |
172 | 66 | ||
173 | async_set_client_connection(msim_client_connection); |
67 | async_set_client_connection(serial_client_connection); |
174 | return 0; |
68 | return 0; |
175 | } |
69 | } |
176 | 70 | ||
177 | /** |
71 | /** |
178 | * @} |
72 | * @} |