Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
9837 turbocat 1
/* dZ80 Disassembler Header */
2
 
3
#ifndef _MIDISSZ80_
4
#define _MIDISSZ80_
5
 
6
#ifdef __cplusplus
7
extern "C" {
8
#endif
9
 
10
#ifndef _DZ80_EXCLUDE_SCRIPT
11
#include "lua.h"
12
#else
13
#define	LUA_VERSION		"(scripting not included)"
14
#endif
15
 
16
#define	DZ80_WWW		"http://www.inkland.org"
17
#define	DZ80_EMAIL		"dz80@inkland.org"
18
 
19
#define Z80MEMSIZE				65536
20
 
21
#define	D_CUSTOMSTRING_MAXLEN	6
22
 
23
#define DISFLAG_OPCODEDUMP		0x01
24
#define DISFLAG_ADDRDUMP		0x02
25
#define DISFLAG_UPPER			0x04
26
#define DISFLAG_SINGLE	 		0x08	/* Disassemble a single instruction */
27
#define DISFLAG_VERBOSE 		0x10
28
#define DISFLAG_QUIET			0x20
29
#define DISFLAG_LABELLED		0x40
30
#define DISFLAG_REFINPORT		0x80
31
#define DISFLAG_REFOUTPORT		0x100
32
#define DISFLAG_REFADDR 		0x200
33
#define DISFLAG_REFINDIRECT 	0x400
34
#define DISFLAG_REFLIMITRANGE	0x800
35
#define DISFLAG_USELABELADDRS	0x1000
36
#define DISFLAG_RELCOMMENT		0x2000	/* Relative jump comments */
37
#define DISFLAG_LINECOMMANDS	0x4000	/* Process line commands (auto blank lines) */
38
#define DISFLAG_CALLBACK	0x8000  /* Access memory through a callback */
39
 
40
/* Reference listing stuff */
41
#define DISFLAG_ANYREF			(DISFLAG_REFINPORT | DISFLAG_REFOUTPORT | DISFLAG_REFADDR | DISFLAG_REFINDIRECT)
42
 
43
/* parametersModified flags (used by the GUI when importing a config file) */
44
#define	DPM_STARTADDR			0x0001
45
#define	DPM_ENDADDR				0x0002
46
#define	DPM_HDRSIZE				0x0004
47
#define	DPM_FILESTARTADDR		0x0008
48
#define	DPM_CPUTYPE				0x0010
49
#define	DPM_RADIX				0x0020
50
#define	DPM_NUMPREFIX			0x0040
51
#define	DPM_NUMSUFFIX			0x0080
52
#define	DPM_OPMAP				0x0100
53
 
54
/* Configuration file name */
55
#define	CONFIGFILENAME			"dz80.ini"
56
 
57
enum dz80Cpus
58
	{
59
	DCPU_Z80GB,
60
	DCPU_Z80,
61
	DCPU_Z180,
62
 
63
	DCPU_TOTAL
64
	};
65
 
66
 
67
enum dz80Passes
68
	{
69
	DPASS_INIT,
70
	DPASS_WRITE,
71
	DPASS_ANALYSE,
72
 
73
	DPASS_TOTAL
74
	};
75
 
76
 
77
 
78
enum dz80Errors
79
	{
80
	DERR_NONE,
81
	DERR_OUTOFMEM,
82
	DERR_COULDNTCREATEFILE,
83
	DERR_COULDNTWRITETOFILE,
84
	DERR_BADOPCODELENGTH,
85
	DERR_INVALIDPARAMS,
86
	DERR_SCRIPTERROR,
87
	DERR_WRONGARGUMENTTYPE,
88
	DERR_COULDNTOPENFILE,
89
	DERR_SCRIPTING_NA,
90
 
91
	DERR_TOTAL
92
	};
93
 
94
 
95
enum DRADIX
96
{
97
	DRADIX_HEX,
98
	DRADIX_DECIMAL,
99
	DRADIX_OCTAL,
100
 
101
	DRADIX_TOTAL,
102
 
103
	DRADIX_DEFAULT = DRADIX_HEX
104
};
105
 
106
 
107
enum DISREF_TYPES
108
{
109
	DISREF_INPORT,
110
	DISREF_OUTPORT,
111
	DISREF_ADDR,
112
	DISREF_INDIRECT,
113
 
114
	DISREF_TOTAL
115
};
116
 
117
 
118
typedef struct DISREFADDR
119
{
120
	WORD				RefAddress;
121
	struct DISREFADDR	*pNext;
122
} DISREFADDR;
123
 
124
typedef struct DISREF
125
{
126
	WORD		RefType;				/* Reference type */
127
	WORD		Addr;					/* Memory or port address */
128
	WORD		Hits;					/* Number of times referenced */
129
	DISREFADDR	*pRefAddrHead;			/* Pointer to the list of referenced addresses */
130
	DISREFADDR	*pRefAddrTail;			/* Pointer to the last referenced address */
131
 
132
	struct DISREF *pPrev;
133
	struct DISREF *pNext;
134
} DISREF;
135
 
136
 
137
typedef struct DISZ80
138
{
139
	BYTE		*mem0Start; 				/* Pointer to Z80's zero address */
140
	BYTE		(*memCB)(void *ctx, WORD addr);		/* Indirect access through callback (DISFLAG_CALLBACK) */
141
	WORD		start;						/* Starting disassembler address */
142
	WORD		end;						/* Ending disassembler address */
143
	DWORD		flags; 						/* See DISFLAG_ defines */
144
	DWORD		flagsModified;				/* Which bits have been modified via config files */
145
	DWORD		parametersModified;			/* Which other parameters have been modified via config file */
146
	int 		numInstructions;			/* How many instructions were disassembled */
147
	int 		createdRefOK;				/* Set to TRUE if created .ref file OK */
148
	char		srcFileName[_MAX_PATH];		/* Used only to display the source filename in the report header */
149
	char		outFileName[_MAX_PATH];		/* Destination assembler file */
150
	char		opMapFileName[_MAX_PATH];	/* Opcode map file name */
151
	char		refFileName[_MAX_PATH];		/* Reference file name */
152
	char		scriptFileName[_MAX_PATH];	/* Lua script file name */
153
 
154
/* CPU type */
155
	BYTE		cpuType;					/* See the DCPU_ enums */
156
 
157
/* New flexible number formats */
158
	BYTE		layoutRadix;							/* Do ya want hex with that? */
159
	char		layoutComment[D_CUSTOMSTRING_MAXLEN];	/* The string used as a comment marker */
160
	char		layoutNumberPrefix[D_CUSTOMSTRING_MAXLEN];
161
	char		layoutNumberSuffix[D_CUSTOMSTRING_MAXLEN];
162
	char		layoutDefineByte[D_CUSTOMSTRING_MAXLEN];/* Default of "db" */
163
 
164
/* Pointer to the function callbacks */
165
	void		(*fnProgressCallback)(struct DISZ80 *d);
166
	void		(*fnErrorMessage)(char *msg);
167
	void		(*fnOutputMessage)(char *msg);
168
 
169
/* dZ80 private workspace stuff - hands off ;) */
170
	char		hexDisBuf[32];				/* Holds the hex. code bytes (easy one!) */
171
	char		disBuf[128];				/* Holds the disassembly */
172
	char		commentBuf[128];
173
	WORD		lastDisPC, lastRefAddr, disStart, disEnd;
174
	int 		op, realop, lineCmd;
175
	BYTE		*Z80MemBase;
176
	BYTE		(*Z80MemCB)(void *ctx, WORD addr);
177
	signed char	IXIYDisp;				/* The IXIY displacement (-128 to 127) */
178
	int 		Z80Flags;
179
	int 		currentPass, totalPasses;
180
	int 		numRecursions;
181
	BYTE		*fnMap, *opMap;
182
	DISREF		*pRefHead[DISREF_TOTAL];
183
	DWORD		numRefs[DISREF_TOTAL];
184
	DWORD		bytesToProcess, bytesProcessed;
185
	FILE		*outStream, *refStream;
186
	int 		labelledOutput, dissingToConsole, haveTabbed;
187
	int 		progressCounter;
188
	WORD		PC, lastPC;
189
	BYTE		*pTrapMap;				/* Pointer to the trap map */
190
	BYTE		firstByte;
191
	int 		haveWrapped;
192
	int			disBufIndex;			/* Index into the disassembly buffer */
193
	DWORD		fileHeaderSize;			/* The size of the file's header (to skip) */
194
	WORD		fileStartAddr;			/* The Z80 address of the start of the file */
195
 
196
#ifndef _DZ80_EXCLUDE_SCRIPT
197
	lua_State	*ls;					/* Pointer to the Lua state in which the scripts are run */
198
#endif
199
 
200
} DISZ80;
201
 
202
 
203
int		dZ80_LoadConfiguration(DISZ80 *d, char *pConfigFile);
204
void	dZ80_SetDefaultOptions(DISZ80 *d);
205
int 	dZ80_Disassemble(DISZ80 *d);
206
void	dZ80_SetRadix(DISZ80 *d, int radix);
207
int 	dZ80_SingleDisassembly(DISZ80 *d);
208
void	dZ80_InheritRadix(DISZ80 *dst, DISZ80 *src);
209
char	*dZ80_GetVersionString(void);
210
void	dZ80_StringToLower(char *s);
211
void	dZ80_StringToUpper(char *s);
212
void	dZ80_SafeStringCopy(char *dst, char *src, int dstSize);
213
const char *dZ80_GetErrorText(int errNum);
214
int 	dZ80_LoadZ80File(DISZ80 *d, DWORD *BytesLoaded);
215
void	dZ80_Error(DISZ80 *d, char *msg);
216
void	dZ80_ShowMsg(DISZ80 *d, char *msg);
217
int		dZ80_AllocateOpMap(DISZ80 *d);
218
 
219
extern char *dZ80CpuTypeNames[DCPU_TOTAL];
220
 
221
#ifdef __cplusplus
222
}
223
#endif
224
 
225
#endif		/* _MIDISSZ80_ */