square: DOL squaring example (shown in live demo)
[jump.git] / square / src / Gen.c
diff --git a/square/src/Gen.c b/square/src/Gen.c
new file mode 100644 (file)
index 0000000..133e5aa
--- /dev/null
@@ -0,0 +1,28 @@
+#include <stdio.h>
+#include "Gen.h"
+
+void Gen_delay(void)
+{
+       for(volatile int a = 0; a < 50; a++)
+               for(volatile int b = 0; b < 2000000; b++)
+                       ;
+}
+
+void Gen_init(DOLProcess *p) {
+       ((Gen_State*)p->local)->index = 0;
+}
+
+int Gen_fire(DOLProcess *p) {
+       float i;
+
+       if (p->local->index < LENGTH) {
+Gen_delay();
+               p->local->index++;
+               i = p->local->index;
+               DOL_write(PORT_OUTPUT, &i, sizeof(float), p);
+       } else {
+               DOL_detach(p);
+       }
+
+       return 0;
+}