📄 dis6502.c
字号:
/*** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)****** This program is free software; you can redistribute it and/or** modify it under the terms of version 2 of the GNU Library General ** Public License as published by the Free Software Foundation.**** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** Library General Public License for more details. To obtain a ** copy of the GNU Library General Public License, write to the Free ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.**** Any permitted reproduction of these routines, in whole or in part,** must bear this legend.****** dis6502.c**** 6502 disassembler based on code from John Saeger** $Id: dis6502.c,v 1.2 2003/12/05 15:55:01 f1rmb Exp $*/#include "types.h"#include "log.h"#include "nes6502.h"#include "dis6502.h"#ifdef NES6502_DEBUG/* addressing modes */enum { _imp, _acc, _rel, _imm, _abs, _abs_x, _abs_y, _zero, _zero_x, _zero_y, _ind, _ind_x, _ind_y };/* keep a filthy local copy of PC to** reduce the amount of parameter passing*/static uint32 pc_reg;static uint8 dis_op8(void){ return (nes6502_getbyte(pc_reg + 1));}static uint16 dis_op16(void){ return (nes6502_getbyte(pc_reg + 1) + (nes6502_getbyte(pc_reg + 2) << 8));}static void dis_show_ind(void){ log_printf("(%04X) ", dis_op16());}static void dis_show_ind_x(void){ log_printf("(%02X,x) ", dis_op8());}static void dis_show_ind_y(void){ log_printf("(%02X),y ", dis_op8());}static void dis_show_zero_x(void){ log_printf(" %02X,x ", dis_op8());}static void dis_show_zero_y(void){ log_printf(" %02X,y ", dis_op8());}static void dis_show_abs_y(void){ log_printf(" %04X,y ", dis_op16());}static void dis_show_abs_x(void){ log_printf(" %04X,x ", dis_op16());}static void dis_show_zero(void){ log_printf(" %02X ", dis_op8());}static void dis_show_abs(void){ log_printf(" %04X ", dis_op16());}static void dis_show_immediate(void){ log_printf("#%02X ", dis_op8());}static void dis_show_acc(void){ log_printf(" a ");}static void dis_show_relative(void){ int target; target = (int8) dis_op8(); target += (pc_reg + 2); log_printf(" %04X ", target);}static void dis_show_code(int optype){ log_printf("%02X ", nes6502_getbyte(pc_reg)); switch (optype) { case _imp: case _acc: log_printf(" "); break; case _rel: case _imm: case _zero: case _zero_x: log_printf("%02X ", nes6502_getbyte(pc_reg + 1)); break; case _abs: case _abs_x: case _abs_y: case _ind: case _ind_x: case _ind_y: log_printf("%02X %02X ", nes6502_getbyte(pc_reg + 1), nes6502_getbyte(pc_reg + 2)); break; }}static void dis_show_op(char *opstr, int optype){ dis_show_code(optype); log_printf("%s ", opstr); switch(optype) { case _imp: log_printf(" "); break; case _acc: dis_show_acc(); break; case _rel: dis_show_relative(); break; case _imm: dis_show_immediate(); break; case _abs: dis_show_abs(); break; case _abs_x: dis_show_abs_x(); break; case _abs_y: dis_show_abs_y(); break; case _zero: dis_show_zero(); break; case _zero_x: dis_show_zero_x(); break; case _ind: dis_show_ind(); break; case _ind_x: dis_show_ind_x(); break; case _ind_y: dis_show_ind_y(); break; }}void nes6502_disasm(uint32 PC, uint8 P, uint8 A, uint8 X, uint8 Y, uint8 S){ pc_reg = PC; log_printf("%04X: ", pc_reg); switch(nes6502_getbyte(pc_reg)) { case 0x00: dis_show_op("brk",_imp); break; case 0x01: dis_show_op("ora",_ind_x); break; case 0x02: dis_show_op("jam",_imp); break; case 0x03: dis_show_op("slo",_ind_x); break; case 0x04: dis_show_op("nop",_zero); break; case 0x05: dis_show_op("ora",_zero); break; case 0x06: dis_show_op("asl",_zero); break; case 0x07: dis_show_op("slo",_zero); break; case 0x08: dis_show_op("php",_imp); break; case 0x09: dis_show_op("ora",_imm); break; case 0x0a: dis_show_op("asl",_acc); break; case 0x0b: dis_show_op("anc",_imm); break; case 0x0c: dis_show_op("nop",_abs); break; case 0x0d: dis_show_op("ora",_abs); break; case 0x0e: dis_show_op("asl",_abs); break; case 0x0f: dis_show_op("slo",_abs); break; case 0x10: dis_show_op("bpl",_rel); break; case 0x11: dis_show_op("ora",_ind_y); break; case 0x12: dis_show_op("jam",_imp); break; case 0x13: dis_show_op("slo",_ind_y); break; case 0x14: dis_show_op("nop",_zero_x); break; case 0x15: dis_show_op("ora",_zero_x); break; case 0x16: dis_show_op("asl",_zero_x); break; case 0x17: dis_show_op("slo",_zero_x); break; case 0x18: dis_show_op("clc",_imp); break; case 0x19: dis_show_op("ora",_abs_y); break; case 0x1a: dis_show_op("nop",_imp); break; case 0x1b: dis_show_op("slo",_abs_y); break; case 0x1c: dis_show_op("nop",_abs_x); break; case 0x1d: dis_show_op("ora",_abs_x); break; case 0x1e: dis_show_op("asl",_abs_x); break; case 0x1f: dis_show_op("slo",_abs_x); break; case 0x20: dis_show_op("jsr",_abs); break; case 0x21: dis_show_op("and",_ind_x); break; case 0x22: dis_show_op("jam",_imp); break; case 0x23: dis_show_op("rla",_ind_x); break; case 0x24: dis_show_op("bit",_zero); break; case 0x25: dis_show_op("and",_zero); break; case 0x26: dis_show_op("rol",_zero); break; case 0x27: dis_show_op("rla",_zero); break; case 0x28: dis_show_op("plp",_imp); break; case 0x29: dis_show_op("and",_imm); break; case 0x2a: dis_show_op("rol",_acc); break; case 0x2b: dis_show_op("anc",_imm); break; case 0x2c: dis_show_op("bit",_abs); break; case 0x2d: dis_show_op("and",_abs); break; case 0x2e: dis_show_op("rol",_abs); break; case 0x2f: dis_show_op("rla",_abs); break; case 0x30: dis_show_op("bmi",_rel); break; case 0x31: dis_show_op("and",_ind_y); break; case 0x32: dis_show_op("jam",_imp); break; case 0x33: dis_show_op("rla",_ind_y); break;/* case 0x34: dis_show_op("nop",_zero); break;*/ case 0x34: dis_show_op("nop",_imp); break; case 0x35: dis_show_op("and",_zero_x); break; case 0x36: dis_show_op("rol",_zero_x); break; case 0x37: dis_show_op("rla",_zero_x); break; case 0x38: dis_show_op("sec",_imp); break; case 0x39: dis_show_op("and",_abs_y); break; case 0x3a: dis_show_op("nop",_imp); break; case 0x3b: dis_show_op("rla",_abs_y); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -