36 static unsigned char *
obuf;
38 #define write_one_byte(x, y) obuf[obuflen++] = x
39 #define wrtb(x) obuf[obuflen++] = x
44 "call",
"cpdr",
"cpir",
"djnz",
"halt",
"indr",
"inir",
"lddr",
"ldir",
45 "otdr",
"otir",
"outd",
"outi",
"push",
"reti",
"retn",
"rlca",
"rrca",
46 "defb",
"defw",
"defs",
"defm",
47 "adc",
"add",
"and",
"bit",
"ccf",
"cpd",
"cpi",
"cpl",
"daa",
"dec",
"equ",
48 "exx",
"inc",
"ind",
"ini",
"ldd",
"ldi",
"neg",
"nop",
"out",
"pop",
49 "res",
"ret",
"rla",
"rlc",
"rld",
"rra",
"rrc",
"rrd",
"rst",
"sbc",
50 "scf",
"set",
"sla",
"sll",
"sli",
"sra",
"srl",
"sub",
"xor",
"org",
51 "cp",
"di",
"ei",
"ex",
"im",
"in",
"jp",
"jr",
"ld",
"or",
"rl",
"rr",
52 "db",
"dw",
"ds",
"dm",
53 "include",
"incbin",
"if",
"else",
"endif",
"end",
"macro",
"endm",
103 fprintf (stderr,
"internal assembler error, sp == %i\n",
sp);
104 vfprintf (stderr, fmt, l);
108 vfprintf (stderr, fmt, l);
117 static const char *
delspc(
const char *ptr) {
118 while (*ptr &&
isspace ((
const unsigned char) *ptr))
130 RZ_LOG_ERROR(
"assembler: z80: `,' expected. Remainder of line: %s\n", *
p);
159 RZ_LOG_ERROR(
"assembler: z80: unexpected end of line\n");
169 const char *
input = *ptr;
178 }
else if (*
check ==
'*') {
183 }
else if (*
check ==
'+') {
222 const char *
c, *
d, *
pos, *dummy;
224 struct label *previous;
225 for (
d = *
p; *
d && *
d !=
';';
d++) {
228 for (
c = *
p; !strchr (
" \r\n\t", *
c) &&
c <
d;
c++) {
231 pos = strchr (*
p,
':');
236 RZ_LOG_ERROR(
"assembler: z80: `:' found without a label");
247 RZ_LOG_ERROR(
"assembler: z80: duplicate definition of label %s\n", *
p);
258 int backup_addr =
addr;
260 int backup_comma =
comma;
261 int backup_file =
file;
280 comma = backup_comma;
286 static int rd_word(
const char **
p,
char delimiter) {
298 static int rd_byte(
const char **
p,
char delimiter) {
314 const char *
list[] = {
315 "( sp )",
"de",
"af",
NULL
323 const char *
list[] = {
324 "b",
"c",
"d",
"e",
"h",
"l",
"f",
"a",
NULL
331 const char *
list[] = {
332 "b",
"c",
"d",
"e",
"h",
"l",
"0",
"a",
NULL
341 const char *
list[] = {
342 "( c )",
"(*)",
"a , (*)",
NULL
353 const char *
list[] = {
354 "( c )",
"( bc )",
NULL
362 const char *
list[] = {
392 const char *
list[] = {
393 "ixh",
"ixl",
"iyh",
"iyl",
"bc",
"de",
"hl",
"sp",
"ix",
394 "iy",
"b",
"c",
"d",
"e",
"h",
"l",
"( hl )",
"a",
"i",
395 "r",
"( bc )",
"( de )",
"( ix +)",
"(iy +)",
"(*)",
NULL
404 return ldH + (
i == 2);
408 return ldH + (
i == 4);
429 const char *
list[] = {
430 "nz",
"z",
"nc",
"c",
"po",
"pe",
"p",
"m",
"( ix )",
"( iy )",
446 const char *
list[] = {
447 "nz",
"z",
"nc",
"c",
NULL
454 const char *
list[] = {
463 const char *
list[] = {
464 "bc",
"de",
"hl",
"af",
"ix",
"iy",
NULL
480 const char *
list[] = {
481 "ixl",
"ixh",
"iyl",
"iyh",
"b",
"c",
"d",
"e",
"h",
"l",
482 "( hl )",
"a",
"( ix +)",
"( iy +)",
"hl",
"ix",
"iy",
"*",
NULL
512 const char *
list[] = {
513 "bc",
"de",
"hl",
"sp",
NULL
520 const char *listx[] = {
521 "bc",
"de",
"ix",
"sp",
NULL
523 const char *listy[] = {
524 "bc",
"de",
"iy",
"sp",
NULL
526 const char *
list[] = {
527 "bc",
"de",
"hl",
"sp",
NULL
543 const char *
list[] = {
544 "ixl",
"ixh",
"iyl",
"iyh",
"b",
"c",
"d",
"e",
"h",
"l",
"( hl )",
545 "a",
"( ix +)",
"( iy +)",
"*",
NULL
569 const char *
list[] = {
570 "b",
"c",
"d",
"e",
"h",
"l",
"( hl )",
"a",
"( ix +)",
"( iy +)",
NULL
593 const char *
list[] = {
594 "nz",
"z",
"nc",
"c",
"po",
"pe",
"p",
"m",
NULL
602 const char *
list[] = {
603 "iy",
"ix",
"sp",
"hl",
"de",
"bc",
"",
"b",
"c",
"d",
"e",
"h",
604 "l",
"( hl )",
"a",
"( ix +)",
"( iy +)",
NULL
610 if (i < 16 && i > 2) {
623 const char *
list[] = {
632 const char *
list[] = {
633 "hl",
"ix",
"iy",
NULL
645 const char *
list[] = {
653 const char *
list[] = {
654 "0",
"",
"1",
"2",
NULL
662 const char *
list[] = {
663 "b",
"c",
"d",
"e",
"h",
"l",
"",
"a",
"*",
NULL
678 const char *
list[] = {
679 "bc",
"de",
"",
"sp",
"hl",
"a",
"ix",
"iy",
NULL
696 const char *
list[] = {
697 "( sp )",
"( iy +)",
"( de )",
"( bc )",
"( ix +)",
"b",
"c",
"d",
"e",
"h",
698 "l",
"( hl )",
"a",
"i",
"r",
"(*)",
"*",
NULL
702 if (
i == 2 ||
i == 5) {
721 const char *
list[] = {
722 "b",
"c",
"d",
"e",
"h",
"l",
"( hl )",
"a",
"( ix +)",
"( iy +)",
"ixh",
723 "ixl",
"iyh",
"iyl",
"*",
NULL
734 x = 0xdd + 0x20 * (
i > 12);
736 RZ_LOG_ERROR(
"assembler: z80: illegal use of index registers\n");
744 RZ_LOG_ERROR(
"assembler: z80: illegal use of index registers\n");
757 const char *
list[] = {
768 const char *
list[] = {
769 "hl",
"ix",
"iy",
"(*)",
"*",
NULL
799 for (bufptr =
z80buffer; (bufptr = strchr (bufptr,
'\n'));) {
802 for (bufptr =
z80buffer; (bufptr = strchr (bufptr,
'\r'));) {
841 wrtb (0x4A + 0x10 *
r);
844 if (!(
r =
rd_r (&ptr))) {
859 wrtb (0x09 + 0x10 *
r);
864 RZ_LOG_ERROR(
"assembler: z80: parse error before: %s\n", ptr);
867 if (!(
r =
rd_r (&ptr))) {
878 if (!(
r =
rd_r (&ptr))) {
893 wrtb (0x40 + (
r - 1));
908 if (!(
r =
rd_r (&ptr))) {
946 wrtb (0x0B + 0x10 *
r);
997 if (!(
r =
rd_in (&ptr))) {
1006 wrtb (0x40 + 8 * (
A - 1));
1017 wrtb (0x40 + 8 *
r);
1025 wrtb (0x04 - 8 *
r);
1029 wrtb (0x03 + 0x10 *
r);
1055 wrtb (0xC2 + 8 *
r);
1066 wrtb (0x18 + 8 *
r);
1069 if (!(
r =
rd_ld (&ptr))) {
1093 wrtb (0x43 + 0x10 * --
r);
1105 wrtb (0x57 + 8 * (
r ==
A_R ? 1 : 0));
1116 wrtb (0x0A - 0x10 *
r);
1132 wrtb (0x08 * (
r - 7) + 0x6);
1135 wrtb (0x40 + 0x08 * (
r -7) + (
s - 1));
1143 wrtb (0x4B + 0x10 * (
r ==
ldDE ? 1 : 0));
1146 wrtb (0x01 + (
r ==
ldDE ? 1 : 0) * 0x10);
1150 wrtb (0x21 + (
r ==
_NN ? 1 : 0) * 9);
1158 wrtb (0x47 + 0x08 * (
r ==
ldR ? 1 : 0));
1199 if (!(
r =
rd_r (&ptr))) {
1223 wrtb (0x41 + 8 *
r);
1244 wrtb (0xC1 + 0x10 *
r);
1251 wrtb (0xC5 + 0x10 *
r);
1258 if (!(
r =
rd_r_(&ptr))) {
1266 if (!(
r =
rd_cc (&ptr))) {
1271 wrtb (0xC0 + 8 *
r);
1282 if (!(
r =
rd_r_(&ptr))) {
1293 if (!(
r =
rd_r_(&ptr))) {
1308 if (!(
r =
rd_r_(&ptr))) {
1319 if (!(
r =
rd_r_(&ptr))) {
1346 wrtb (0x42 + 0x10 *
r);
1349 if (!(
r =
rd_r (&ptr))) {
1363 if (!(
r =
rd_r_(&ptr))) {
1371 if (!(
r =
rd_r_(&ptr))) {
1379 if (!(
r =
rd_r_(&ptr))) {
1387 if (!(
r =
rd_r_(&ptr))) {
1395 if (!(
r =
rd_r_(&ptr))) {
1403 if (!(
r =
rd_r (&ptr))) {
1408 RZ_LOG_ERROR(
"assembler: z80: parse error before: %s\n", ptr);
1411 if (!(
r =
rd_r (&ptr))) {
1419 if (!(
r =
rd_r (&ptr))) {
1431 have_quote = (*ptr ==
'"' || *ptr ==
'\'');
1436 while (*ptr != quote) {
1439 RZ_LOG_ERROR(
"assembler: z80: end of line in quoted string\n");
1454 RZ_LOG_ERROR(
"assembler: z80: junk in byte definition: %s\n", ptr);
1462 RZ_LOG_ERROR(
"assembler: z80: No data for word definition\n");
1472 RZ_LOG_ERROR(
"assembler: z80: Missing expression in defw\n");
1480 RZ_LOG_ERROR(
"assembler: z80: ds should have its first argument >=0"
1481 " (not -0x%x)\n", -
r);
1492 for (
i = 0;
i <
r;
i++) {
1511 RZ_LOG_ERROR(
"assembler: z80: endm outside macro definition\n");
1533 unsigned char buf[4];
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
static int rd_expr(const char **p, char delimiter, int *valid, int level, int print_errors)
static int rd_label(const char **p, int *exists, struct label **previous, int level, int print_errors)
static int rd_character(const char **p, int *valid, int print_errors)
unsigned char outbuf[SIZE]
static void list(RzEgg *egg)
static static fork const void static count static fd const char const char static newpath char char argv
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
int main(int argc, char **argv)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
void error(const char *msg)
static int readcommand(const char **p)
static void readlabel(const char **p, int store)
static int assemble(const char *str, unsigned char *_obuf)
static int compute_ref(struct reference *ref, int allow_invalid)
static int rd_r_rr(const char **p)
static const char * delspc(const char *ptr)
static void printerr(int error, const char *fmt,...)
static int rd_a_hl(const char **p)
static int rd_jr(const char **p)
static void rd_comma(const char **p)
static int rd_rrxx(const char **p)
#define write_one_byte(x, y)
static int has_argument(const char **p)
static int rd_byte(const char **p, char delimiter)
static int rd_ld(const char **p)
static int rd_r_add(const char **p)
static int rd_cc(const char **p)
static char mem_delimiter
static int rd_stack(const char **p)
static unsigned char * obuf
static int rd_in(const char **p)
static int rd_out(const char **p)
static int rd_nn_nn(const char **p)
static int rd_rr_(const char **p)
static int indx(const char **ptr, const char **list, int error, const char **expr)
static int rd_r_(const char **p)
static int rd_ex1(const char **p)
static int rd_sp(const char **p)
static int rd_0_2(const char **p)
static const char * mnemonics[]
static int rd_jp(const char **p)
static int rd_r(const char **p)
static void skipword(const char **pos, char delimiter)
static const char * bitsetres
RZ_API_I int z80asm(unsigned char *outbuf, const char *s)
static int rd_hlx(const char **p)
static int rd_a(const char **p)
static int rd_af_(const char **p)
static int rd_word(const char **p, char delimiter)
static int rd_ld_nn(const char **p)
static int rd_ld_hl(const char **p)
static int rd_nnc(const char **p)
static int rd_ldbcdehla(const char **p)
static const char * readword
static int rd_0_7(const char **p)
static int rd_hl(const char **p)
static const char * indexjmp
static int rd_lda(const char **p)
static const char * readbyte
static int rd_c(const char **p)
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)