2 // coded by Ketmar // Invisible Vector
13 #include "liburasm/liburasm.h"
16 static uint8_t memory
[65536];
19 static uint8_t getByte (uint16_t addr
) {
24 static const char *cmdName (const char *s
) {
26 const char *t
= strchr(s
, '\t');
28 memset(cmd
, 0, sizeof(cmd
));
30 while (strlen(cmd
) < 5+(urasm_allow_zxnext
? 3 : 0)) strcat(cmd
, " ");
35 static const char *cmdArgs (const char *s
) {
36 const char *t
= strchr(s
, '\t');
37 if (!t
) return s
+strlen(s
);
42 int main (int argc
, char *argv
[]) {
44 uint16_t pc
= 0x0100U
;//0xECC8UL;
46 int len
, idx
, len1
, f
;
47 for (int aidx
= 1; aidx
< argc
; ++aidx
) {
48 if (strcmp(argv
[aidx
], "--") == 0) {
49 for (int c
= aidx
+1; c
< argc
; ++c
) argv
[c
-1] = argv
[c
];
53 if (strcmp(argv
[aidx
], "--z80") == 0 || strcmp(argv
[aidx
], "--z80a") == 0) {
54 for (int c
= aidx
+1; c
< argc
; ++c
) argv
[c
-1] = argv
[c
];
56 urasm_allow_zxnext
= 0;
60 if (strcmp(argv
[aidx
], "--z80n") == 0 || strcmp(argv
[aidx
], "--z80next") == 0 ||
61 strcmp(argv
[aidx
], "--zxnext") == 0)
63 for (int c
= aidx
+1; c
< argc
; ++c
) argv
[c
-1] = argv
[c
];
65 urasm_allow_zxnext
= 1;
70 FILE *fl
= fopen(argc
>1?argv
[1]:"zout_0100.bin", "rb");
71 if (!fl
) { fprintf(stderr
, "ERROR: can't open input file!\n"); return 1; }
72 if (argc
> 2) pc
= (strtol(argv
[2], NULL
, 0))&0xffff;
73 maxlen
= fread(memory
+pc
, 1, 65536-pc
, fl
);
76 urasm_getbyte
= getByte
;
78 if (pc
>= 65535-16) break;
79 idx
= urasm_disasm_opfind(pc
);
81 len
= urasm_disasm_oplen(idx
);
82 len1
= urasm_disasm_opdisasm(dstr
, pc
);
83 printf("%04X: [", pc
);
84 for (f
= 0; f
< len1
; ++f
) { if (f
) putchar(' '); printf("%02X", memory
[pc
+f
]); }
85 for (; f
< 4; ++f
) { if (f
) putchar(' '); printf(" "); }
87 printf("] idx=%3d; len=%d; len1=%d; [%s%s]\n", idx
, len
, len1
, cmdName(dstr
), cmdArgs(dstr
));
89 printf("] len=%d; len1=%d; [%s%s]\n", len
, len1
, cmdName(dstr
), cmdArgs(dstr
));
91 if (len
!= len1
) abort();
92 if (len
<= 0) abort();
93 pc
+= len1
; maxlen
-= len1
;