Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
dasm.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <z80ex/z80ex_dasm.h>
4 
6 int data_len=0;
7 
8 void usage(char *name)
9 {
10  printf("simple z80 code disassembler\nusage: %s binary_file [base_adress]\n",name);
11 }
12 
14 {
15  int base_addr = *((int *)user_data);
16  return(data[addr-base_addr]);
17 }
18 
19 int main(int argc,char *argv[])
20 {
21  FILE *fp;
22  int base_addr=0,addr=0;
23  int t,t2;
24  char buf[80];
25 
26  if(argc < 2 || argc > 3)
27  {
28  usage(argv[0]);
29  return(0);
30  }
31 
32  fp=fopen(argv[1],"rb");
33  if(fp==NULL) goto fail;
34 
35  fseek(fp,0,SEEK_END);
36  data_len=ftell(fp);
37  fseek(fp,0,SEEK_SET);
38 
39  if(NULL==(data=(Z80EX_BYTE *)malloc(data_len))) goto fail;
40  if(fread(data,1,data_len,fp)!=data_len) goto fail;
41  fclose(fp);
42 
43  if(argc == 3) base_addr=atoi(argv[2]);
44 
45  addr=base_addr;
46  while((addr-base_addr) < data_len)
47  {
48  printf("%04X: ",addr);
49  addr+=z80ex_dasm(buf,80,0,&t,&t2,readbyte_cb,addr,&base_addr);
50  printf("%-15s t=%d",buf,t);
51  if(t2) printf("/%d",t2);
52  printf("\n");
53  }
54 
55  free(data);
56  return(0);
57 
58 fail:
59  fprintf(stderr,"ERROR\n");
60  if(data!=NULL) free(data);
61  return(1);
62 
63 }
main
int main(int argc, char *argv[])
Definition: dasm.c:19
addr
int addr
Definition: dma65.c:81
Z80EX_WORD
unsigned short Z80EX_WORD
Definition: z80ex.h:51
z80ex_dasm.h
data_len
int data_len
Definition: dasm.c:6
data
Z80EX_BYTE * data
Definition: dasm.c:5
Z80EX_BYTE
unsigned char Z80EX_BYTE
Definition: z80ex.h:49
usage
void usage(char *name)
Definition: dasm.c:8
readbyte_cb
Z80EX_BYTE readbyte_cb(Z80EX_WORD addr, void *user_data)
Definition: dasm.c:13
z80ex_dasm
int z80ex_dasm(char *output, int output_size, unsigned flags, int *t_states, int *t_states2, z80ex_dasm_readbyte_cb readbyte_cb, Z80EX_WORD addr)
Definition: z80ex_dasm.c:42
name
const char * name
Definition: joystick.c:46
buf
Uint8 buf[512]
Definition: fat32.c:155