2000-09-24 15:55:57 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
|
/* attrtab.c */
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
|
/* Disassembler attribute table */
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2006-01-29 19:00:22 +00:00
|
|
|
|
/* (C) 2000-2006 Ullrich von Bassewitz */
|
2003-08-23 09:20:33 +00:00
|
|
|
|
/* R<>merstrasse 52 */
|
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
|
/* */
|
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
|
/* distribution. */
|
|
|
|
|
/* */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* da65 */
|
|
|
|
|
#include "error.h"
|
|
|
|
|
#include "attrtab.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
|
/* Data */
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Attribute table */
|
2006-01-29 19:00:22 +00:00
|
|
|
|
static unsigned short AttrTab[0x10000];
|
2000-09-24 15:55:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
|
/* Code */
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-29 19:00:22 +00:00
|
|
|
|
void AddrCheck (unsigned Addr)
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/* Check if the given address has a valid range */
|
|
|
|
|
{
|
|
|
|
|
if (Addr >= 0x10000) {
|
2013-05-09 11:56:54 +00:00
|
|
|
|
Error ("Address out of range: %08X", Addr);
|
2000-09-24 15:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 20:27:53 +00:00
|
|
|
|
int SegmentDefined (unsigned Start, unsigned End)
|
|
|
|
|
/* Return true if the atSegment bit is set somewhere in the given range */
|
|
|
|
|
{
|
|
|
|
|
while (Start <= End) {
|
|
|
|
|
if (AttrTab[Start++] & atSegment) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2007-09-02 19:49:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int HaveSegmentChange (unsigned Addr)
|
|
|
|
|
/* Return true if the segment change attribute is set for the given address */
|
|
|
|
|
{
|
|
|
|
|
/* Check the given address */
|
|
|
|
|
AddrCheck (Addr);
|
|
|
|
|
|
|
|
|
|
/* Return the attribute */
|
|
|
|
|
return (AttrTab[Addr] & atSegmentChange) != 0;
|
|
|
|
|
}
|
2007-08-31 20:27:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-04-29 14:00:28 +00:00
|
|
|
|
unsigned GetGranularity (attr_t Style)
|
|
|
|
|
/* Get the granularity for the given style */
|
|
|
|
|
{
|
|
|
|
|
switch (Style) {
|
2013-05-09 11:56:54 +00:00
|
|
|
|
case atDefault: return 1;
|
|
|
|
|
case atCode: return 1;
|
|
|
|
|
case atIllegal: return 1;
|
|
|
|
|
case atByteTab: return 1;
|
|
|
|
|
case atDByteTab: return 2;
|
|
|
|
|
case atWordTab: return 2;
|
|
|
|
|
case atDWordTab: return 4;
|
|
|
|
|
case atAddrTab: return 2;
|
|
|
|
|
case atRtsTab: return 2;
|
|
|
|
|
case atTextTab: return 1;
|
|
|
|
|
|
|
|
|
|
case atSkip:
|
|
|
|
|
default:
|
|
|
|
|
Internal ("GetGraularity called for style = %d", Style);
|
|
|
|
|
return 0;
|
2004-04-29 14:00:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-24 15:55:57 +00:00
|
|
|
|
void MarkRange (unsigned Start, unsigned End, attr_t Attr)
|
|
|
|
|
/* Mark a range with the given attribute */
|
|
|
|
|
{
|
|
|
|
|
/* Do it easy here... */
|
|
|
|
|
while (Start <= End) {
|
2013-05-09 11:56:54 +00:00
|
|
|
|
MarkAddr (Start++, Attr);
|
2000-09-24 15:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MarkAddr (unsigned Addr, attr_t Attr)
|
|
|
|
|
/* Mark an address with an attribute */
|
|
|
|
|
{
|
|
|
|
|
/* Check the given address */
|
|
|
|
|
AddrCheck (Addr);
|
|
|
|
|
|
|
|
|
|
/* We must not have more than one style bit */
|
|
|
|
|
if (Attr & atStyleMask) {
|
2013-05-09 11:56:54 +00:00
|
|
|
|
if (AttrTab[Addr] & atStyleMask) {
|
|
|
|
|
Error ("Duplicate style for address %04X", Addr);
|
|
|
|
|
}
|
2000-09-24 15:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set the style */
|
|
|
|
|
AttrTab[Addr] |= Attr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-09-02 19:49:12 +00:00
|
|
|
|
attr_t GetAttr (unsigned Addr)
|
|
|
|
|
/* Return the attribute for the given address */
|
|
|
|
|
{
|
|
|
|
|
/* Check the given address */
|
|
|
|
|
AddrCheck (Addr);
|
|
|
|
|
|
|
|
|
|
/* Return the attribute */
|
|
|
|
|
return AttrTab[Addr];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-29 19:00:22 +00:00
|
|
|
|
attr_t GetStyleAttr (unsigned Addr)
|
2000-09-24 15:55:57 +00:00
|
|
|
|
/* Return the style attribute for the given address */
|
|
|
|
|
{
|
|
|
|
|
/* Check the given address */
|
|
|
|
|
AddrCheck (Addr);
|
|
|
|
|
|
|
|
|
|
/* Return the attribute */
|
|
|
|
|
return (AttrTab[Addr] & atStyleMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-29 19:00:22 +00:00
|
|
|
|
attr_t GetLabelAttr (unsigned Addr)
|
2000-09-29 12:26:34 +00:00
|
|
|
|
/* Return the label attribute for the given address */
|
|
|
|
|
{
|
|
|
|
|
/* Check the given address */
|
|
|
|
|
AddrCheck (Addr);
|
|
|
|
|
|
|
|
|
|
/* Return the attribute */
|
|
|
|
|
return (AttrTab[Addr] & atLabelMask);
|
|
|
|
|
}
|