aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md25
-rw-r--r--ppu/ppu.c57
2 files changed, 77 insertions, 5 deletions
diff --git a/README.md b/README.md
index e2bfa42..7deb686 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,31 @@
-# pu2!
+# pu2 + ppu!
smaller, better, faster, compact-er! let's gooooo
-## how does this workkk
+## pu2
+
+### how does this workkk
to be humble, pretty clever stuff. (i forgor)
-## WHAT IS PU2
+### WHAT IS PU2
- CPU Emulator
- Assembler
- Test Suite
-## instruction set
-pu2 has less instructions than pu (aka pu1),
+### instruction set
+pu2 has less instructions than pu (aka pu1), [moon's note: wow it seems like i forgor to complete this sentence...]
+
+## ppu
+
+### what the hell
+yeah i know! it's a parallel cpu. so much cool stuff you can do with openmp. just make sure to compile with `-fopenmp`
+
+### WHAT IS THIS
+- CPU
+- Assembler
+- A full day of pain and suffering (now that i think about it, a day isn't really that much time)
+
+### instruction set
+RTFM (in ppu/ppu.c ofc)
# ~~moonvm~~
~~i have no idea what to name this. gimme names if you got any.~~
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