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/opc.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 '')
-rw-r--r-- | src/emu/opc.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/emu/opc.c b/src/emu/opc.c new file mode 100644 index 0000000..870a272 --- /dev/null +++ b/src/emu/opc.c @@ -0,0 +1,63 @@ +#include <stdlib.h> +#include <string.h> + +#include "opc.h" + +typedef struct opc_mapping { + const char *name; + uint32_t opcode; +} opc_mapping_t; + +opc_mapping_t opc_map[] = { + { "ADD", OPC_ADD }, + { "SUB", OPC_SUB }, + { "MUL", OPC_MUL }, + { "DIV", OPC_DIV }, + { "MOD", OPC_MOD }, + { "SHL", OPC_SHL }, + { "SHR", OPC_SHR }, + { "AND", OPC_AND }, + { "OR", OPC_OR }, + { "XOR", OPC_XOR }, + { "NOR", OPC_NOR }, + { "MOV", OPC_MOV }, + { "LB", OPC_LB }, + { "LH", OPC_LH }, + { "LW", OPC_LW }, + { "SB", OPC_SB }, + { "SH", OPC_SH }, + { "SW", OPC_SW }, + { "CMP", OPC_CMP }, + { "BEQ", OPC_BEQ }, + { "BNE", OPC_BNE }, + { "BLT", OPC_BLT }, + { "BGE", OPC_BGE }, + { "BLE", OPC_BLE }, + { "BGT", OPC_BGT }, + { "J", OPC_J }, + { "JAL", OPC_JAL }, + { "SYS", OPC_SYS }, + { NULL, 0 } +}; + +uint32_t mnemonic2opc(const char *mnemonic) +{ + for (uint8_t i = 0; opc_map[i].name; i++) { + if (strcmp(opc_map[i].name, mnemonic) == 0) + return opc_map[i].opcode << 26; + } + + return ~0; +} + +const char *opc2mnemonic(uint32_t IR) +{ + uint32_t opcode = IR >> 26; + + for (uint8_t i = 0; opc_map[i].name; i++) { + if (opc_map[i].opcode == opcode) + return opc_map[i].name; + } + + return NULL; +} |