⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.c

📁 AVR反汇编,对ATMEGA8有效
💻 C
字号:
/*  Program: revava - Atmel Dis-Assembler  File: Flash.C, Copyright (C) 2001 Daniel J. Winker  This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as published by the Free Software Foundation; either version 2  of the License, or (at your option) any later version.  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 General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/#include <string.h>#include "Error.h"#include "Flash.h"#define FALSE 0#define TRUE  (!FALSE)TFlash::TFlash(){	// Clear the Arrays because I don't remember what the rules of	// C++ are on this.	memset( (void *)code_space,        0, sizeof( code_space ));	memset( (void *)code_byte_written, 0, sizeof( code_byte_written ));}void TFlash::FlipEndian( void ){	int           i;	unsigned char temp;	for( i = 0; i < FLASH_SIZE; i += 2 ){		temp = code_space[ i ];		code_space[ i     ] = code_space[ i + 1 ] ;		code_space[ i + 1 ] = temp;	}}void TFlash::flashset(	unsigned short       addr,	unsigned char        nbytes,	const unsigned char* data){	int*           pi;	unsigned char* pc;	pi = code_byte_written + addr;	pc = code_space + addr;	// Check boundries	if(( addr + nbytes ) > FLASH_SIZE ){		char msg[ 80 ];	// FIXME - Magic Number		sprintf(			msg,			"Address: %04X, Offset: %02X exceeds FLASH_SIZE: %04X", 			addr, nbytes - 1, FLASH_SIZE);		throw TGenericError( msg ); 	}		while( nbytes-- ){		// Increment counter for this byte, then increment the pointer		// to the byte counter.		++( *( pi++ ) );		*pc++ = *data++;	}}unsigned short TFlash::get_flash_word(	unsigned short addr,	int*           high_byte_written,	int*           low_byte_written ){	// Check boundry	if(( addr + 1 ) >= FLASH_SIZE ){		char msg[ 80 ];	// FIXME - Magic Number		sprintf(			msg,			"get_flash_word: Word Address: %04X, exceeds FLASH_SIZE: %04X", 			addr, FLASH_SIZE);		throw TGenericError( msg ); 	}	*high_byte_written = code_byte_written[ addr ];	*low_byte_written  = code_byte_written[ addr + 1 ];	return( ( code_space[ addr ] << 8 ) | code_space[ addr + 1 ] );}void TFlash::Dump( void ){	char code_line[ 60 ];	// FIXME - Magic Number	char ascii_line[ 20 ];	// FIXME - Magic Number	char* pcode_line;	char* pascii_line;	unsigned char c1;	unsigned char c2;	int have_data;	int i;	int j;	for( i = 0; i < FLASH_SIZE; i += 0x10 ){		pcode_line  = code_line;		pascii_line = ascii_line;		have_data   = FALSE;		for( j = 0; j < 0x8; j += 2 ){			c1 = code_space[ i + j ];			c2 = code_space[ i + j + 1 ];			sprintf( pcode_line, "%02X%02X ", c1, c2 );			sprintf(				pascii_line,				"%c%c",				c1 >= (unsigned char)' ' && c1 <= (unsigned char)'~' ? c1 : '.',				c2 >= (unsigned char)' ' && c2 <= (unsigned char)'~' ? c2 : '.' );			// Cover them up if they weren't really there.			if( code_byte_written[ i + j ] ){				have_data = TRUE;			} else {				*( pcode_line  + 0 ) = '-';				*( pcode_line  + 1 ) = '-';				*( pascii_line + 0 ) = ' ';			}			if( code_byte_written[ i + j + 1 ] ){				have_data = TRUE;			} else {				*( pcode_line  + 2 ) = '-';				*( pcode_line  + 3 ) = '-';				*( pascii_line + 1 ) = ' ';			}			pcode_line  += 5;			pascii_line += 2;		}		*pascii_line++ = ' ';		while( j < 0x10 ){			c1 = code_space[ i + j ];			c2 = code_space[ i + j + 1 ];			sprintf( pcode_line, " %02X%02X", c1, c2 );			sprintf(				pascii_line,				"%c%c",				c1 >= (unsigned char)' ' && c1 <= (unsigned char)'~' ? c1 : '.',				c2 >= (unsigned char)' ' && c2 <= (unsigned char)'~' ? c2 : '.' );			// Cover them up if they weren't really there.			if( code_byte_written[ i + j ] ){				have_data = TRUE;			} else {				*( pcode_line  + 1 ) = '-';				*( pcode_line  + 2 ) = '-';				*( pascii_line + 0 ) = ' ';			}			if( code_byte_written[ i + j + 1 ] ){				have_data = TRUE;			} else {				*( pcode_line  + 3 ) = '-';				*( pcode_line  + 4 ) = '-';				*( pascii_line + 1 ) = ' ';			}			pcode_line  += 5;			pascii_line += 2;			j += 2;		}		if( have_data ){			printf( "%04X: %s  %s\n", i, code_line, ascii_line );		}	}}void TFlash::DebugDump( void ){	char code_line[ 60 ];	// FIXME - Magic Number	char flag_line[ 20 ];	// FIXME - Magic Number	char ascii_line[ 20 ];	// FIXME - Magic Number	char* pcode_line;	char* pflag_line;	char* pascii_line;	unsigned char c1;	unsigned char c2;	int i;	int j;	for( i = 0; i < FLASH_SIZE; i += 0x10 ){		pcode_line  = code_line;		pflag_line  = flag_line;		pascii_line = ascii_line;		for( j = 0; j < 0x8; j += 2 ){			c1 = code_space[ i + j ];			c2 = code_space[ i + j + 1 ];			sprintf( pcode_line, "%02X%02X ", c1, c2 );			pcode_line += 5;			sprintf(				pflag_line,				"%1.1d%1.1d",				code_byte_written[ i + j ],				code_byte_written[ i + j + 1 ] );			pflag_line += 2;			sprintf(				pascii_line,				"%c%c",				c1 >= (unsigned char)' ' && c1 <= (unsigned char)'~' ? c1 : '.',				c2 >= (unsigned char)' ' && c2 <= (unsigned char)'~' ? c2 : '.' );			pascii_line += 2;		}		*pflag_line++  = ' ';		*pascii_line++ = ' ';		while( j < 0x10 ){			c1 = code_space[ i + j ];			c2 = code_space[ i + j + 1 ];			sprintf( pcode_line, " %02X%02X", c1, c2 );			pcode_line += 5;			sprintf(				pflag_line,				"%1.1d%1.1d",				code_byte_written[ i + j ],				code_byte_written[ i + j + 1 ] );			pflag_line += 2;			sprintf(				pascii_line,				"%c%c",				c1 >= (unsigned char)' ' && c1 <= (unsigned char)'~' ? c1 : '.',				c2 >= (unsigned char)' ' && c2 <= (unsigned char)'~' ? c2 : '.' );			pascii_line += 2;			j += 2;		}		printf( "%04X: %s  %s  %s\n", i, code_line, flag_line, ascii_line );	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -