diff --git a/libr/parse/p/Makefile b/libr/parse/p/Makefile index 2f5ddce608..3bfc95bb67 100644 --- a/libr/parse/p/Makefile +++ b/libr/parse/p/Makefile @@ -9,7 +9,7 @@ CFLAGS+=-DCORELIB foo: all ALL_TARGETS= -ARCHS=att2intel.mk x86_pseudo.mk mreplace.mk arm_pseudo.mk +ARCHS=att2intel.mk x86_pseudo.mk mreplace.mk arm_pseudo.mk z80_pseudo.mk include $(ARCHS) all: ${ALL_TARGETS} diff --git a/libr/parse/p/parse_z80_pseudo.c b/libr/parse/p/parse_z80_pseudo.c new file mode 100644 index 0000000000..f04473eb27 --- /dev/null +++ b/libr/parse/p/parse_z80_pseudo.c @@ -0,0 +1,88 @@ +/* radare - LGPL - Copyright 2015 - julien (jvoisin) voisin */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +static int replace(int argc, const char *argv[], char *newstr) { + int i,j,k; + struct { + char *op; + char *str; + } ops[] = { + { "adc", "1 = 1 + 2"}, + { "add", "1 = 1 + 2"}, + { "and", "1 = 1 & 2"}, + { "cpl", "1 = ~1"}, + { "ex", "swap(1, 2)"}, + { "in", "1 = [2]"}, + { "jp", "goto [1]"}, + { "jp", "goto 1"}, + { "jr", "goto +1"}, + { "ld", "1 = 2"}, + { "ldd", "1 = 2--"}, + { "neg", "1 = -1"}, + { "nop", ""}, + { "or", "1 = 1 | 2"}, + { "pop", "pop 1"}, + { "push", "push 1"}, + { "rr", "1 = 1 << 2"}, + { "sbc", "1 = 1 - 2"}, + { "sla", "1 = 1 << 2"}, + { "sra", "1 = 1 >> 2"}, + { "srl", "1 = 1 >> 2"}, + { "sub", "1 = 1 - 2"}, + { "xor", "1 = 1 ^ 2"}, + { NULL } + }; + + for (i=0; ops[i].op != NULL; i++) { + if (!strcmp (ops[i].op, argv[0])) { + if (newstr != NULL) { + for (j=k=0;ops[i].str[j]!='\0';j++,k++) { + if (ops[i].str[j]>='1' && ops[i].str[j]<='9') { + const char *w = argv[ ops[i].str[j]-'0' ]; + if (w != NULL) { + strcpy (newstr+k, w); + k += strlen(w)-1; + } + } else newstr[k] = ops[i].str[j]; + } + newstr[k]='\0'; + } + return R_TRUE; + } + } + + /* TODO: this is slow */ + if (newstr != NULL) { + newstr[0] = '\0'; + for (i=0; i