| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,19 @@ |
| 1 |
+AlignAfterOpenBracket: DontAlign |
|
| 2 |
+AlignEscapedNewlines: DontAlign |
|
| 3 |
+AllowShortBlocksOnASingleLine: Empty |
|
| 4 |
+AllowShortCaseLabelsOnASingleLine: true |
|
| 5 |
+AllowShortIfStatementsOnASingleLine: false |
|
| 6 |
+AllowShortLoopsOnASingleLine: false |
|
| 7 |
+AlwaysBreakAfterDefinitionReturnType: TopLevel |
|
| 8 |
+BinPackArguments: false |
|
| 9 |
+BinPackParameters: false |
|
| 10 |
+BreakBeforeBraces: WebKit |
|
| 11 |
+IndentCaseLabels: false |
|
| 12 |
+TabWidth: 4 |
|
| 13 |
+IndentWidth: 4 |
|
| 14 |
+ContinuationIndentWidth: 4 |
|
| 15 |
+UseTab: ForContinuationAndIndentation |
|
| 16 |
+ColumnLimit: 0 |
|
| 17 |
+ReflowComments: false |
|
| 18 |
+SortIncludes: false |
|
| 19 |
+SpaceBeforeParens: false |
|
| 0 | 20 |
\ No newline at end of file |
| ... | ... |
@@ -7,3 +7,52 @@ A stack-based VM, written in ANSI C. |
| 7 | 7 |
``` |
| 8 | 8 |
cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn |
| 9 | 9 |
``` |
| 10 |
+ |
|
| 11 |
+## OP Codes |
|
| 12 |
+ |
|
| 13 |
+``` |
|
| 14 |
+VALUE OPCODE EXPLANATION |
|
| 15 |
+0x00000000 NOP do nothing |
|
| 16 |
+0x00000001 ADD pop a, pop b, push a + b |
|
| 17 |
+0x00000002 SUB pop a, pop b, push a - b |
|
| 18 |
+0x00000003 AND pop a, pop b, push a & b |
|
| 19 |
+0x00000004 OR pop a, pop b, push a | b |
|
| 20 |
+0x00000005 XOR pop a, pop b, push a ^ b |
|
| 21 |
+0x00000006 NOT pop a, push !a |
|
| 22 |
+0x00000007 IN read one byte from stdin, push as word on stack |
|
| 23 |
+0x00000008 OUT pop one word and write to stream as one byte |
|
| 24 |
+0x00000009 LOAD pop a, push word read from address a |
|
| 25 |
+0x0000000A STOR pop a, pop b, write b to address a |
|
| 26 |
+0x0000000B JMP pop a, goto a |
|
| 27 |
+0x0000000C JZ pop a, pop b, if a == 0 goto b |
|
| 28 |
+0x0000000D PUSH push next word |
|
| 29 |
+0x0000000E DUP duplicate word on stack |
|
| 30 |
+0x0000000F SWAP swap top two words on stack |
|
| 31 |
+0x00000010 ROL3 rotate top three words on stack once left, (a b c) -> (b c a) |
|
| 32 |
+0x00000011 OUTNUM pop one word and write to stream as number |
|
| 33 |
+0x00000012 JNZ pop a, pop b, if a != 0 goto b |
|
| 34 |
+0x00000013 DROP remove top of stack |
|
| 35 |
+0x00000014 PUSHIP push a in IP stack |
|
| 36 |
+0x00000015 POPIP pop IP stack to current IP, effectively performing a jump |
|
| 37 |
+0x00000016 DROPIP pop IP, but do not jump |
|
| 38 |
+0x00000017 COMPL pop a, push the complement of a |
|
| 39 |
+``` |
|
| 40 |
+ |
|
| 41 |
+## Design |
|
| 42 |
+ |
|
| 43 |
+### CPU |
|
| 44 |
+ |
|
| 45 |
+- Build stack with pointer |
|
| 46 |
+- Print stack |
|
| 47 |
+- Build memory |
|
| 48 |
+ |
|
| 49 |
+### PPU |
|
| 50 |
+ |
|
| 51 |
+### Assembler |
|
| 52 |
+ |
|
| 53 |
+ |
|
| 54 |
+### Emulator |
|
| 55 |
+ |
|
| 56 |
+- SDL Layer |
|
| 57 |
+ |
|
| 58 |
+### Assembly |
| ... | ... |
@@ -1,6 +1,6 @@ |
| 1 | 1 |
#include <stdio.h> |
| 2 | 2 |
|
| 3 |
-/* |
|
| 3 |
+/* |
|
| 4 | 4 |
Copyright (c) 2021 Devine Lu Linvega |
| 5 | 5 |
|
| 6 | 6 |
Permission to use, copy, modify, and distribute this software for any |
| ... | ... |
@@ -11,9 +11,28 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | 11 |
WITH REGARD TO THIS SOFTWARE. |
| 12 | 12 |
*/ |
| 13 | 13 |
|
| 14 |
+typedef unsigned char Uint8; |
|
| 15 |
+#define STACK_DEPTH 256 |
|
| 16 |
+ |
|
| 17 |
+Uint8 data[STACK_DEPTH]; |
|
| 18 |
+Uint8 address[STACK_DEPTH]; |
|
| 19 |
+ |
|
| 20 |
+void |
|
| 21 |
+stackprint(Uint8 *stack) |
|
| 22 |
+{
|
|
| 23 |
+ int i; |
|
| 24 |
+ for(i = 0; i < STACK_DEPTH; ++i) {
|
|
| 25 |
+ if(i % 16 == 0) |
|
| 26 |
+ printf("\n");
|
|
| 27 |
+ printf("%02x ", stack[i]);
|
|
| 28 |
+ } |
|
| 29 |
+ printf("\n");
|
|
| 30 |
+} |
|
| 31 |
+ |
|
| 14 | 32 |
int |
| 15 | 33 |
main(int argc, char *argv[]) |
| 16 | 34 |
{
|
| 17 | 35 |
printf("hello\n");
|
| 36 |
+ stackprint(data); |
|
| 18 | 37 |
return 0; |
| 19 | 38 |
} |