dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hds / lib / dolSupport.cpp
diff --git a/dol/src/dol/visitor/hds/lib/dolSupport.cpp b/dol/src/dol/visitor/hds/lib/dolSupport.cpp
new file mode 100644 (file)
index 0000000..1db732a
--- /dev/null
@@ -0,0 +1,149 @@
+#include "dolSupport.h"\r
+#include "ProcessWrapper.h"\r
+\r
+/**\r
+ *\r
+ */\r
+unsigned write(void *port, void *buf, unsigned len, DOLProcess *process)\r
+{\r
+    Fifo *fifo = static_cast<Fifo *>(port);\r
+    char *str = static_cast<char*>(buf);\r
+    #ifdef INCLUDE_PROFILER\r
+    (static_cast<ProcessWrapper *>(process->wptr))->addToProfile(\r
+            "w", port, len);\r
+    #endif\r
+    fifo->write((void*)str, len);\r
+    #ifdef INCLUDE_TRACE\r
+    strcpy((static_cast<ProcessWrapper *>(process->wptr))->channel_name,\r
+            fifo->getName());\r
+    #endif\r
+    return len;\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+unsigned read(void *port, void *buf, unsigned len, DOLProcess *process) {\r
+    Fifo *fifo = static_cast<Fifo *>(port);\r
+    char *str = static_cast<char*>(buf);\r
+    #ifdef INCLUDE_PROFILER\r
+    (static_cast<ProcessWrapper *>(process->wptr))->addToProfile(\r
+            "r", port, len);\r
+    #endif\r
+    fifo->read((void*)str, len);\r
+    #ifdef INCLUDE_TRACE\r
+    strcpy((static_cast<ProcessWrapper *>(process->wptr))->channel_name,\r
+            fifo->getName());\r
+    #endif\r
+    return len;\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+int wtest(void *port, unsigned len, DOLProcess *process) {\r
+    Fifo *fifo = static_cast<Fifo *>(port);\r
+    return (fifo->unused() >= len) ? 1 : 0;\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+int rtest(void *port, unsigned len, DOLProcess *process) {\r
+    Fifo *fifo = static_cast<Fifo *>(port);\r
+    return (fifo->used() >= len) ? 1 : 0;\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+unsigned reserve(void* fifo, void** destination, unsigned len, DOLProcess* p) {\r
+    return ((WindowedFifo*)fifo)->reserve(destination, len);\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void release(void* fifo, DOLProcess* p) {\r
+    ((WindowedFifo*)fifo)->release();\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+unsigned capture(void* fifo, void** destination, unsigned len, DOLProcess* p) {\r
+    return ((WindowedFifo*)fifo)->capture(destination, len);\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void consume(void* fifo, DOLProcess* p) {\r
+    ((WindowedFifo*)fifo)->consume();\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+void DOL_detach(DOLProcess* p) {\r
+    static_cast<ProcessWrapper *>(p->wptr)->detach();\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+void createPort(void** port,\r
+                void* base,\r
+                int number_of_indices,\r
+                int index0, int range0) {\r
+    *port = (void**)((void**)base)[index0];\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+void createPort(void** port,\r
+                void* base,\r
+                int number_of_indices,\r
+                int index0, int range0,\r
+                int index1, int range1) {\r
+    *port = (void**)((void**)base)[index0 * range1 + index1];\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+void createPort(void** port,\r
+                void* base,\r
+                int number_of_indices,\r
+                int index0, int range0,\r
+                int index1, int range1,\r
+                int index2, int range2) {\r
+    *port = (void**)((void**)base)[index0 * range1 * range2\r
+                       + index1 * range2 + index2];\r
+}\r
+\r
+\r
+/**\r
+ *\r
+ */\r
+void createPort(void** port,\r
+                void* base,\r
+                int number_of_indices,\r
+                int index0, int range0,\r
+                int index1, int range1,\r
+                int index2, int range2,\r
+                int index3, int range3) {\r
+    *port = (void**)((void**)base)[index0 * range1 * range2 * range3\r
+                       + index1 * range2 * range3\r
+                       + index2 * range3\r
+                       + index3];\r
+}\r