aboutsummaryrefslogtreecommitdiff
path: root/ppu
diff options
context:
space:
mode:
Diffstat (limited to 'ppu')
-rw-r--r--ppu/ppu.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/ppu/ppu.c b/ppu/ppu.c
new file mode 100644
index 0000000..9b4fc5a
--- /dev/null
+++ b/ppu/ppu.c
@@ -0,0 +1,57 @@
+#define inline
+
+#include <ctype.h>
+#include <omp.h>
+#include <stdio.h>
+#include <string.h>
+
+#pragma clang diagnostic ignored "-Wreturn-type"
+
+typedef char* string;
+
+// opcodes!
+// 0: halt
+// 1: nop
+// 2: mov
+// 3: movi
+// 4: add
+// 5: addi
+// 6: sub
+// 7: subi
+// 8: moveq -> moves m[B] to m[A] if m[Q] == 0
+// program counter is m[0]
+// Q is set to the previous A in memory
+
+// error handling for unknown ops
+#define W 0
+
+// clang-format off
+#define J while
+#define S 1<<20
+#define H !K--
+m[S]={0},c,N,Q,E;
+ppu(){E=1;_Pragma("omp parallel")J(E){_Pragma("omp single")N=m[m[0]],c=m[0],m[0]+=++N*4;int i;_Pragma("omp for")for(i=0;i<N;i++){int t=c+i*4,Y=m[t++],K=m[t++],A=m[t++],B=m[t++];H?E=0:H?:H?m[A]=m[B]:H?m[A]=B:H?m[A]+=m[B]:H?m[A]+=m[B]:H?m[A]-=m[B]?H:m[Q]?:(m[A]=m[B]):W;Q=A;}}}
+
+#define X J(isspace(*I))I++
+char*t="halt\0\0nop\0\0mov\0\2movi\0\2add\0\2addi\0\2sub\0\2subi\0\2moveq\0\2\1";*D,Z;
+char*pas(char*I){J(*I){X;if(*I==64)Z=strtol(++I,&I,10);X;char*O=t,F=0;J(*O!=1){int G=strlen(O),L=O[G+1],V=L,B=strncmp(I,O,G);F++,O+=G+2;if(B||!isspace(I[G]))continue;I+=G;*D++=Z,Z=0;*D++=F-1;J(V--){X;*D++=strtol(I,&I,10);}J(2-L++)*D++=0;goto N;}return I;N:;}return 0;}
+// clang-format on
+
+main() {
+ D = &m[ 1 ];
+ pas("@4 movi 10 2");
+
+ // int C;
+ // for (C = 0; C < 16; C++) printf("%i ", m[ C + 1 ]);
+ // fflush(stdout);
+
+ int x[] = { 1,
+ 3, 3, 5, 1,
+ 0, 3, 5, 2,
+ 0, 3, 5, 3,
+ 0, 3, 5, 4,
+ 0, 0, 0, 0 };
+ memcpy(m, x, sizeof(x));
+ ppu();
+ printf("result: %i\n", m[ 5 ]);
+} \ No newline at end of file