-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdisasm.c
More file actions
47 lines (35 loc) · 894 Bytes
/
disasm.c
File metadata and controls
47 lines (35 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* Quick and dity 6502 disassembler. */
#include <stdio.h>
#include <stdlib.h>
#include "M6502.h"
byte mem[0x10000];
int main (int argc, char **argv)
{
FILE *in;
long pc;
long limit;
size_t size;
byte *base;
if (argc!=3) {
printf("Usage: dis6502 ORG INFILE\n(ORG is in hex)\n");
return 0;
}
in=fopen(argv[2],"rb");
if (!in) {
fprintf(stderr,"Could not open \"%s\"\n",argv[2]);
return 1;
}
pc=strtol(argv[1],NULL,16);
fprintf(stderr,"Disassembly starting at $%04X\n",(unsigned int)pc);
size=fread(mem,1,0x10000,in);
limit=pc+size;
base=mem-pc;
fclose(in);
fprintf(stderr,"Disassembling $%04X bytes (%i kilobytes)\n",size,size>>10);
while (pc<limit) {
char txt[256]="";
pc+=DAsm(txt,base+pc,pc);
printf("%04X %s\n",(unsigned)pc,txt);
}
return 0;
}