summaryrefslogtreecommitdiffstats
path: root/src/emu/asm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/asm.c')
-rw-r--r--src/emu/asm.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/emu/asm.c b/src/emu/asm.c
new file mode 100644
index 0000000..caca72a
--- /dev/null
+++ b/src/emu/asm.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdint.h>
+
+#include "cpu.h"
+#include "log.h"
+#include "opc.h"
+
+uint32_t compile(const char *line)
+{
+ char mnem[4];
+ int32_t a = 0, b = 0, c = 0;
+
+ /* arithmetic & logic */
+ if (sscanf(line, "%3s r%2d, r%2d, r%2d", mnem, &a, &b, &c) == 4)
+ return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | ((c & 0x1F) << 11);
+
+ /* load/store & branch */
+ if (sscanf(line, "%3s r%2d, r%2d, %d", mnem, &a, &b, &c) == 4)
+ return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | (c & 0xFFFF);
+
+ if (sscanf(line, "%3s r%2d, %d", mnem, &b, &c) == 3)
+ return mnemonic2opc(mnem) | ((b & 0x1F) << 16) | (c & 0xFFFF);
+
+ /* jump */
+ if (sscanf(line, "%3s r%2d", mnem, &a) == 2)
+ return mnemonic2opc(mnem) | ((a & 0x1F) << 21);
+
+ /* misc */
+ if (sscanf(line, "%3s", mnem) == 1)
+ return mnemonic2opc(mnem);
+
+ return 0xFFFFFFFF;
+}