z80dasm.c, source codes,dokumenty

[ Pobierz całość w formacie PDF ]
/* Z80dasm.c - a Z80 opcode disassembler *//* Version 1.1 19-MAY-96 *//* Copyright © 1996 Sean Riddle *//* Freely distributable on any medium given all copyrights are retained *//* by the author and no charge greater than $7.00 is made for obtaining *//* this software *//* Please send all bug reports, update ideas and data files to: *//* seanriddle <at> airosurf <dot> com *//* latest version at: *//* the data files must be kept compatible across systems! *//* usage: Z80dasm <file> [<data file>] *//* output to stdout, so use redirection *//* The optional data file contains 6 types of lines: *//* o Remarks - these are lines beginning with a semi-colon (;) *//* they are completely ignored. *//* o 1 ORG line - gives the origin of the code; this is the starting *//* address to be used for the disassembly. *//* o COMMENT lines - used to add comments to the end of lines of the *//* disassembly. *//* o COMMENTLINE lines - provide full-line comments to be included before *//* a given address in the disassembly. *//* o DATA lines - mark sections as data. These sections will not be *//* disassembled, but dumped as hex data instead. *//* o ASCII lines - mark sections as text. These sections will not be *//* disassembled, but printed as text instead. *//* current limitations: *//* o number of LABEL, DATA/ASCII, COMMENT and COMMENTLINE lines determined *//* at compile-time - see MAXLABEL, MAXDATA, MAXCOMMENT and MAXCOMMLINE *//* o all DATA/ASCII lines in data file must be sorted in ascending *//* address order *//* o ditto for COMMENT and COMMENTLINE lines *//* o if a DATA/ASCII area is preceded by what Z80dasm thinks is code *//* that continues into the DATA/ASCII area, the data will not be marked *//* as such, and an error will be printed. If this is the case, mark the *//* line before the data as data also. *//* to do: *//* o sort comment, ascii, data lines *//* o look at JMP and JSR addresses- set to code unless overridden *//* in data file *//* o perhaps a 'scan' that creates a first-guess .dat file? *//* generate dummy labels, mark code, find ASCII, etc. *//* compiled on Amiga SAS/C 6.55 and Sun 10 Unix cc (and others) *//* built from 6809dasm 1.5 */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>/* a few of my datatypes (from Amiga) */#define TRUE (1==1)#define FALSE (!TRUE)typedef short BOOL; /* boolean quantity */typedef unsigned char UBYTE; /* unsigned 8-bit quantity *//* array sizes for labels, DATA/ASCII definitions and COMMENT/COMMENTLINE */#define MAXLABEL 999#define MAXDATA 999 /* both DATA and ASCII lines */#define MAXCOMMENT 999#define MAXCOMMLINE 999/* output listing spacing */#define TABOPNAME 22#define TABOPERAND 28#define TABCOMM 43#define OPNAMETAB (TABOPNAME-1)#define OPERANDTAB (TABOPERAND-1)#define COMMTAB (TABCOMM-1)typedef struct { /* opcode structure */UBYTE opcode; /* 8-bit opcode value */UBYTE numoperands;char name[15]; /* opcode name */UBYTE mode; /* addressing mode */UBYTE numcycles; /* number of cycles */} opcodeinfo;/* Z80 ADDRESSING MODES */#define IMP 0 /* implied */#define ABS 1 /* absolute (extended) */#define INDX 2 /* indexed x */#define INDY 3 /* indexed y */#define REL 4 /* relative */#define EXT 5 /* external */#define IMM 6 /* immediate */#define INDIR 7 /* indirect *//* page switches */#define CBOP 9 /* cb page */#define EDOP 10 /* ed page */#define DDOP 11 /* dd page */#define FDOP 12 /* fd page */#define DDCBOP 13 /* ddcb page */#define FDCBOP 14 /* fdcb page */#define BITS 0x10 /* bits */#define REG0 0x20 /* implicit 1 reg, bits 0-2 */#define REG3 0x40 /* implicit 1 reg, bits 3-5 */#define DBLREGS 0x80 /* implicit 2 regs */#define CC1 0xA0 /* condition codes 1 */#define CC2 0xC0 /* condition codes 2 *//* number of opcodes in each page */#define NUMOPS 84#define NUMCBOPS 20#define NUMDDOPS 28#define NUMEDOPS 37#define NUMFDOPS 28#define NUMDDCBOPS 10#define NUMFDCBOPS 10int numops[7]={NUMOPS,NUMCBOPS,NUMEDOPS,NUMDDOPS,NUMFDOPS,NUMDDCBOPS,NUMFDCBOPS};char modenames[8][14]={ /* not used */"implied","absolute","xindexed","yindexed","relative","external","immediate","indirect"};short useops[256]={ /* maps opcodes */0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0x4,0x5,0x6,0xf,0x10,0x1,0x12,0x3,0x4,0x5,0x6,0x17,0x18,0x19,0x1a,0xb,0x4,0x5,0x6,0x1f,0x20,0x1,0x22,0x3,0x4,0x5,0x6,0x27,0x20,0x29,0x2a,0xb,0x4,0x5,0x6,0x2f,0x20,0x1,0x32,0x3,0x34,0x35,0x36,0x37,0x20,0x39,0x3a,0xb,0x4,0x5,0x06,0x3f,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x70,0x70,0x70,0x70,0x70,0x70,0x76,0x70,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x86,0x80,0x88,0x88,0x88,0x88,0x88,0x88,0x8e,0x88,0x90,0x90,0x90,0x90,0x90,0x90,0x96,0x90,0x98,0x98,0x98,0x98,0x98,0x98,0x9e,0x98,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa6,0xa0,0xa8,0xa8,0xa8,0xa8,0xa8,0xa8,0xae,0xa8,0xb0,0xb0,0xb0,0xb0,0xb0,0xb0,0xb6,0xb0,0xb8,0xb8,0xb8,0xb8,0xb8,0xb8,0xbe,0xb8,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc0,0xc9,0xc2,0xcb,0xc4,0xcd,0xce,0xc7,0xc0,0xc1,0xc2,0xd3,0xc4,0xc5,0xd6,0xc7,0xc0,0xd9,0xc2,0xdb,0xc4,0xdd,0xde,0xc7,0xc0,0xc1,0xc2,0xe3,0xc4,0xc5,0xe6,0xc7,0xc0,0xe9,0xc2,0xeb,0xc4,0xed,0xee,0xc7,0xc0,0xc1,0xc2,0xf3,0xc4,0xc5,0xf6,0xc7,0xc0,0xf9,0xc2,0xfb,0xc4,0xfd,0xfe,0xc7,};opcodeinfo opcodes[NUMOPS]={0x00,0,"NOP",IMP,4,0x01,2,"LD",IMM|DBLREGS,10,0x02,0,"LD (BC),A",INDIR,7,0x03,0,"INC",IMP|DBLREGS,6,0x04,0,"INC",IMP|REG3,4,0x05,0,"DEC",IMP|REG3,4,0x06,1,"LD",IMM|REG3,7,0x07,0,"RLCA",IMP,4,0x08,0,"EX AF,AF'",IMP,4,0x09,0,"ADD HL,",IMP|DBLREGS,11,0x0a,0,"LD A,(BC)",INDIR,7,0x0b,0,"DEC",IMP|DBLREGS,6,0x0f,0,"RRCA",IMP,4,0x10,1,"DJNZ",REL,13,0x12,0,"LD (DE),A",INDIR,7,0x17,0,"RLA",IMP,4,0x18,1,"JR",REL,12,0x19,0,"ADD HL,",IMP|DBLREGS,11,0x1a,0,"LD A,(DE)",INDIR,7,0x1f,0,"RRA",IMP,4,0x20,1,"JR",REL|CC2,12, /* diff CC !!! */0x22,2,"LD",ABS,16,0x27,0,"DAA",IMP,4,0x29,0,"ADD HL,",IMP|DBLREGS,11,0x2a,2,"LD HL,",ABS,16,0x2f,0,"CPL",IMP,4,0x32,2,"LD",ABS,13,0x34,0,"INC (HL)",INDIR,11,0x35,0,"DEC (HL)",INDIR,11,0x36,1,"LD (HL),",IMM,10,0x37,0,"SCF",IMP,4,0x39,0,"ADD HL,",IMP|DBLREGS,11,0x3a,2,"LD A,",ABS,13,0x3f,0,"CCF",IMP,4,0x40,0,"LD",IMP|REG0|REG3,4,0x46,0,"LD",INDIR|REG3,7,0x70,0,"LD (HL),",INDIR|REG0,7,0x76,0,"HALT",IMP,4,0x80,0,"ADD A,",IMP|REG0,4,0x86,0,"ADD A,",INDIR,7,0x88,0,"ADC A,",IMP|REG0,4,0x8e,0,"ADC A,",INDIR,7,0x90,0,"SUB A,",IMP|REG0,4,0x96,0,"SUB A,",INDIR,7,0x98,0,"SBC A,",IMP|REG0,4,0x9e,0,"SBC A,",INDIR,7,0xa0,0,"AND A,",IMP|REG0,4,0xa6,0,"AND A,",INDIR,7,0xa8,0,"XOR A,",IMP|REG0,4,0xae,0,"XOR A,",INDIR,7,0xb0,0,"OR A,",IMP|REG0,4,0xb6,0,"OR A,(HL)",INDIR,7,0xb8,0,"CP A,",IMP|REG0,4,0xbe,0,"CP A,",INDIR,7,0xc0,0,"RET",INDIR|CC1,11,0xc1,0,"POP",INDIR|DBLREGS,10,0xc2,2,"JP",IMM|CC1,10,0xc3,2,"JP",IMM,10,0xc4,2,"CALL",IMM|CC1,17,0xc5,0,"PUSH",INDIR|DBLREGS,11,0xc6,1,"ADD A,",IMM,7,0xc7,0,"RST",INDIR|BITS,11,0xc9,0,"RET",INDIR,10,0xcb,0,"CB",CBOP,0,0xcd,2,"CALL",IMM,17,0xce,1,"ADC A,",IMM,7,0xd3,1,"OUT",EXT,11,0xd6,1,"SUB A,",IMM,7,0xd9,0,"EXX",IMP,4,0xdb,1,"IN A,",EXT,11,0xdd,0,"DD",DDOP,0,0xde,1,"SBC A,",IMM,7,0xe3,0,"EX (SP),HL",INDIR,19,0xe6,1,"AND A,",IMM,7,0xe9,0,"JP (HL)",IMP,4,0xeb,0,"EX DE,HL",IMP,4,0xed,0,"ED",EDOP,0,0xee,1,"XOR A,",IMM,7,0xf3,0,"DI",IMP,4,0xf6,1,"OR A,",IMM,7,0xf9,0,"LD SP,HL",IMP,6,0xfb,0,"EI",IMP,4,0xfd,0,"FD",FDOP,0,0xfe,1,"CP A,",IMM,7,};short cbuseops[256]={2,2,2,2,2,2,6,2,8,8,8,8,8,8,0xe,8,0x10,0x10,0x10,0x10,0x10,0x10,0x16,0x10,0x18,0x18,0x18,0x18,0x18,0x18,0x1e,0x18,0x20,0x20,0x20,0x20,0x20,0x20,0x26,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x2e,0x28,-1,-1,-1,-1,-1,-1,-1,-1,0x38,0x38,0x38,0x38,0x38,0x38,0x3e,0x38,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x40,0x80,0x80,0x80,0x80,0x80,0x80,0x86,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x86,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x86,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x86,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x86,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x... [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • telefongry.keep.pl






  • Formularz

    POst

    Post*

    **Add some explanations if needed