diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..67c9a1b --- /dev/null +++ b/.clang-format @@ -0,0 +1,19 @@ +AlignAfterOpenBracket: DontAlign +AlignEscapedNewlines: DontAlign +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: TopLevel +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: WebKit +IndentCaseLabels: false +TabWidth: 4 +IndentWidth: 4 +ContinuationIndentWidth: 4 +UseTab: ForContinuationAndIndentation +ColumnLimit: 0 +ReflowComments: false +SortIncludes: false +SpaceBeforeParens: false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..28b1921 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS* +*jpg~ +*png~ +*gif~ +*bmp~ +uxn \ No newline at end of file diff --git a/README.md b/README.md index ddcc048..5eb2276 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,52 @@ A stack-based VM, written in ANSI C. ``` cc uxn.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -o uxn ``` + +## OP Codes + +``` +VALUE OPCODE EXPLANATION +0x00000000 NOP do nothing +0x00000001 ADD pop a, pop b, push a + b +0x00000002 SUB pop a, pop b, push a - b +0x00000003 AND pop a, pop b, push a & b +0x00000004 OR pop a, pop b, push a | b +0x00000005 XOR pop a, pop b, push a ^ b +0x00000006 NOT pop a, push !a +0x00000007 IN read one byte from stdin, push as word on stack +0x00000008 OUT pop one word and write to stream as one byte +0x00000009 LOAD pop a, push word read from address a +0x0000000A STOR pop a, pop b, write b to address a +0x0000000B JMP pop a, goto a +0x0000000C JZ pop a, pop b, if a == 0 goto b +0x0000000D PUSH push next word +0x0000000E DUP duplicate word on stack +0x0000000F SWAP swap top two words on stack +0x00000010 ROL3 rotate top three words on stack once left, (a b c) -> (b c a) +0x00000011 OUTNUM pop one word and write to stream as number +0x00000012 JNZ pop a, pop b, if a != 0 goto b +0x00000013 DROP remove top of stack +0x00000014 PUSHIP push a in IP stack +0x00000015 POPIP pop IP stack to current IP, effectively performing a jump +0x00000016 DROPIP pop IP, but do not jump +0x00000017 COMPL pop a, push the complement of a +``` + +## Design + +### CPU + +- Build stack with pointer +- Print stack +- Build memory + +### PPU + +### Assembler + + +### Emulator + +- SDL Layer + +### Assembly diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 diff --git a/uxn.c b/uxn.c index 16ca6d5..dd11941 100644 --- a/uxn.c +++ b/uxn.c @@ -1,6 +1,6 @@ #include -/* +/* Copyright (c) 2021 Devine Lu Linvega 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 WITH REGARD TO THIS SOFTWARE. */ +typedef unsigned char Uint8; +#define STACK_DEPTH 256 + +Uint8 data[STACK_DEPTH]; +Uint8 address[STACK_DEPTH]; + +void +stackprint(Uint8 *stack) +{ + int i; + for(i = 0; i < STACK_DEPTH; ++i) { + if(i % 16 == 0) + printf("\n"); + printf("%02x ", stack[i]); + } + printf("\n"); +} + int main(int argc, char *argv[]) { printf("hello\n"); + stackprint(data); return 0; }