diff options
author | Benedikt Böhm <bb@xnull.de> | 2009-05-18 20:53:42 +0200 |
---|---|---|
committer | Benedikt Böhm <bb@xnull.de> | 2009-05-18 20:53:42 +0200 |
commit | 49f510d2d60129526832bfcd9c0f4049962bc80e (patch) | |
tree | 2828b773c75bdbc4014a3421c8046778a1a2b11b /src/emu/asm.c | |
parent | 144258f0196b69cbdd2f29bd501276942efc3182 (diff) | |
download | swppy-49f510d2d60129526832bfcd9c0f4049962bc80e.tar.gz swppy-49f510d2d60129526832bfcd9c0f4049962bc80e.tar.xz swppy-49f510d2d60129526832bfcd9c0f4049962bc80e.zip |
move stuff around and create initial source structure
Diffstat (limited to 'src/emu/asm.c')
-rw-r--r-- | src/emu/asm.c | 33 |
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; +} |