dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hds / lib / dolSupport.cpp
1 #include "dolSupport.h"\r
2 #include "ProcessWrapper.h"\r
3 \r
4 /**\r
5  *\r
6  */\r
7 unsigned write(void *port, void *buf, unsigned len, DOLProcess *process)\r
8 {\r
9     Fifo *fifo = static_cast<Fifo *>(port);\r
10     char *str = static_cast<char*>(buf);\r
11     #ifdef INCLUDE_PROFILER\r
12     (static_cast<ProcessWrapper *>(process->wptr))->addToProfile(\r
13             "w", port, len);\r
14     #endif\r
15     fifo->write((void*)str, len);\r
16     #ifdef INCLUDE_TRACE\r
17     strcpy((static_cast<ProcessWrapper *>(process->wptr))->channel_name,\r
18             fifo->getName());\r
19     #endif\r
20     return len;\r
21 }\r
22 \r
23 \r
24 /**\r
25  *\r
26  */\r
27 unsigned read(void *port, void *buf, unsigned len, DOLProcess *process) {\r
28     Fifo *fifo = static_cast<Fifo *>(port);\r
29     char *str = static_cast<char*>(buf);\r
30     #ifdef INCLUDE_PROFILER\r
31     (static_cast<ProcessWrapper *>(process->wptr))->addToProfile(\r
32             "r", port, len);\r
33     #endif\r
34     fifo->read((void*)str, len);\r
35     #ifdef INCLUDE_TRACE\r
36     strcpy((static_cast<ProcessWrapper *>(process->wptr))->channel_name,\r
37             fifo->getName());\r
38     #endif\r
39     return len;\r
40 }\r
41 \r
42 \r
43 /**\r
44  *\r
45  */\r
46 int wtest(void *port, unsigned len, DOLProcess *process) {\r
47     Fifo *fifo = static_cast<Fifo *>(port);\r
48     return (fifo->unused() >= len) ? 1 : 0;\r
49 }\r
50 \r
51 \r
52 /**\r
53  *\r
54  */\r
55 int rtest(void *port, unsigned len, DOLProcess *process) {\r
56     Fifo *fifo = static_cast<Fifo *>(port);\r
57     return (fifo->used() >= len) ? 1 : 0;\r
58 }\r
59 \r
60 \r
61 /**\r
62  *\r
63  */\r
64 unsigned reserve(void* fifo, void** destination, unsigned len, DOLProcess* p) {\r
65     return ((WindowedFifo*)fifo)->reserve(destination, len);\r
66 }\r
67 \r
68 /**\r
69  *\r
70  */\r
71 void release(void* fifo, DOLProcess* p) {\r
72     ((WindowedFifo*)fifo)->release();\r
73 }\r
74 \r
75 /**\r
76  *\r
77  */\r
78 unsigned capture(void* fifo, void** destination, unsigned len, DOLProcess* p) {\r
79     return ((WindowedFifo*)fifo)->capture(destination, len);\r
80 }\r
81 \r
82 /**\r
83  *\r
84  */\r
85 void consume(void* fifo, DOLProcess* p) {\r
86     ((WindowedFifo*)fifo)->consume();\r
87 }\r
88 \r
89 \r
90 /**\r
91  *\r
92  */\r
93 void DOL_detach(DOLProcess* p) {\r
94     static_cast<ProcessWrapper *>(p->wptr)->detach();\r
95 }\r
96 \r
97 \r
98 /**\r
99  *\r
100  */\r
101 void createPort(void** port,\r
102                 void* base,\r
103                 int number_of_indices,\r
104                 int index0, int range0) {\r
105     *port = (void**)((void**)base)[index0];\r
106 }\r
107 \r
108 \r
109 /**\r
110  *\r
111  */\r
112 void createPort(void** port,\r
113                 void* base,\r
114                 int number_of_indices,\r
115                 int index0, int range0,\r
116                 int index1, int range1) {\r
117     *port = (void**)((void**)base)[index0 * range1 + index1];\r
118 }\r
119 \r
120 \r
121 /**\r
122  *\r
123  */\r
124 void createPort(void** port,\r
125                 void* base,\r
126                 int number_of_indices,\r
127                 int index0, int range0,\r
128                 int index1, int range1,\r
129                 int index2, int range2) {\r
130     *port = (void**)((void**)base)[index0 * range1 * range2\r
131                        + index1 * range2 + index2];\r
132 }\r
133 \r
134 \r
135 /**\r
136  *\r
137  */\r
138 void createPort(void** port,\r
139                 void* base,\r
140                 int number_of_indices,\r
141                 int index0, int range0,\r
142                 int index1, int range1,\r
143                 int index2, int range2,\r
144                 int index3, int range3) {\r
145     *port = (void**)((void**)base)[index0 * range1 * range2 * range3\r
146                        + index1 * range2 * range3\r
147                        + index2 * range3\r
148                        + index3];\r
149 }\r