2000-09-25 07:06:46 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* data.c */
|
|
|
|
/* */
|
|
|
|
/* Data output routines */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* (C) 2000 Ullrich von Bassewitz */
|
|
|
|
/* Wacholderweg 14 */
|
|
|
|
/* D-70597 Stuttgart */
|
|
|
|
/* EMail: uz@musoftware.de */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* 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 "attrtab.h"
|
2000-09-26 07:08:38 +00:00
|
|
|
#include "code.h"
|
2000-09-25 07:06:46 +00:00
|
|
|
#include "error.h"
|
|
|
|
#include "global.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "data.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 07:08:38 +00:00
|
|
|
static unsigned GetSpan (attr_t Style)
|
|
|
|
/* Get the number of bytes for a given style */
|
2000-09-25 07:06:46 +00:00
|
|
|
{
|
2000-09-26 07:08:38 +00:00
|
|
|
/* Get the number of bytes still available */
|
|
|
|
unsigned RemainingBytes = GetRemainingBytes ();
|
|
|
|
|
|
|
|
/* Count how many bytes are available. This number is limited by the
|
|
|
|
* number of remaining bytes, a label, or the end of the given Style
|
2000-09-25 07:06:46 +00:00
|
|
|
* attribute.
|
|
|
|
*/
|
|
|
|
unsigned Count = 1;
|
|
|
|
while (Count < RemainingBytes) {
|
2000-09-26 07:08:38 +00:00
|
|
|
if (HaveLabel(PC+Count) || GetStyle (PC+Count) != Style) {
|
2000-09-25 07:06:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++Count;
|
|
|
|
}
|
2000-09-26 07:08:38 +00:00
|
|
|
|
|
|
|
/* Return the number of bytes */
|
|
|
|
return Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned DoTable (attr_t Style, unsigned MemberSize, void (*TableFunc) (unsigned))
|
|
|
|
/* Output a table of bytes */
|
|
|
|
{
|
|
|
|
unsigned BytesLeft;
|
|
|
|
|
|
|
|
/* Count how many bytes may be output. */
|
|
|
|
unsigned Count = GetSpan (Style);
|
|
|
|
|
|
|
|
/* Make Count an even number of multiples of MemberSize */
|
|
|
|
Count &= ~(MemberSize-1);
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
/* Output as many data bytes lines as needed */
|
2000-09-26 07:08:38 +00:00
|
|
|
BytesLeft = Count;
|
|
|
|
while (BytesLeft > 0) {
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
/* Calculate the number of bytes for the next line */
|
2000-09-26 07:08:38 +00:00
|
|
|
unsigned Chunk = (BytesLeft > BytesPerLine)? BytesPerLine : BytesLeft;
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
/* Output a line with these bytes */
|
2000-09-26 07:08:38 +00:00
|
|
|
TableFunc (Chunk);
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
/* Next line */
|
2000-09-26 07:08:38 +00:00
|
|
|
BytesLeft -= Chunk;
|
|
|
|
PC += Chunk;
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
|
2000-09-26 07:08:38 +00:00
|
|
|
/* If the next line is not the same style, add a separator */
|
|
|
|
if (CodeLeft() && GetStyle (PC) != Style) {
|
2000-09-25 07:06:46 +00:00
|
|
|
SeparatorLine ();
|
|
|
|
}
|
2000-09-26 07:08:38 +00:00
|
|
|
|
|
|
|
/* Return the number of bytes output */
|
|
|
|
return Count;
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 07:08:38 +00:00
|
|
|
unsigned ByteTable (void)
|
|
|
|
/* Output a table of bytes */
|
2000-09-25 07:06:46 +00:00
|
|
|
{
|
2000-09-26 07:08:38 +00:00
|
|
|
/* Call the low level function */
|
|
|
|
return DoTable (atByteTab, 1, DataByteLine);
|
|
|
|
}
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 07:08:38 +00:00
|
|
|
unsigned WordTable (void)
|
|
|
|
/* Output a table of words */
|
|
|
|
{
|
|
|
|
/* Call the low level function */
|
|
|
|
return DoTable (atWordTab, 2, DataWordLine);
|
|
|
|
}
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 07:08:38 +00:00
|
|
|
unsigned DWordTable (void)
|
|
|
|
/* Output a table of double words */
|
|
|
|
{
|
|
|
|
/* Call the low level function */
|
|
|
|
return DoTable (atDWordTab, 4, DataDWordLine);
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 07:08:38 +00:00
|
|
|
unsigned AddrTable (void)
|
2000-09-25 07:06:46 +00:00
|
|
|
/* Output a table of addresses */
|
|
|
|
{
|
2000-09-26 07:08:38 +00:00
|
|
|
unsigned BytesLeft;
|
|
|
|
|
|
|
|
/* Count how many bytes may be output. */
|
|
|
|
unsigned Count = GetSpan (atAddrTab);
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
/* Make the given number even */
|
|
|
|
Count &= ~1U;
|
|
|
|
|
|
|
|
/* Output as many data bytes lines as needed. For addresses, each line
|
|
|
|
* will hold just one address.
|
2000-09-26 07:08:38 +00:00
|
|
|
*/
|
|
|
|
BytesLeft = Count;
|
|
|
|
while (BytesLeft > 0) {
|
2000-09-25 07:06:46 +00:00
|
|
|
|
|
|
|
/* Get the address */
|
|
|
|
unsigned Addr = GetCodeWord (PC);
|
|
|
|
|
|
|
|
/* In pass 1, define a label, in pass 2 output the line */
|
|
|
|
if (Pass == 1) {
|
|
|
|
if (!HaveLabel (Addr)) {
|
2000-09-26 07:08:38 +00:00
|
|
|
AddLabel (Addr, MakeLabelName (Addr));
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const char* Label = GetLabel (Addr);
|
|
|
|
if (Label == 0) {
|
2000-09-26 07:08:38 +00:00
|
|
|
/* OOPS! Should not happen */
|
|
|
|
Internal ("OOPS - Label for address %04X disappeard!", Addr);
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
Indent (MIndent);
|
|
|
|
Output (".word");
|
|
|
|
Indent (AIndent);
|
|
|
|
Output ("%s", Label);
|
|
|
|
LineComment (PC, 2);
|
|
|
|
LineFeed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next line */
|
2000-09-26 07:08:38 +00:00
|
|
|
PC += 2;
|
|
|
|
BytesLeft -= 2;
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the next line is not a byte table line, add a separator */
|
2000-09-26 07:08:38 +00:00
|
|
|
if (CodeLeft() && GetStyle (PC) != atAddrTab) {
|
2000-09-25 07:06:46 +00:00
|
|
|
SeparatorLine ();
|
2000-09-26 07:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of bytes output */
|
|
|
|
return Count;
|
2000-09-25 07:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|