Added dword tables, char comments etc.
git-svn-id: svn://svn.cc65.org/cc65/trunk@340 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
161
src/da65/data.c
161
src/da65/data.c
@@ -35,7 +35,7 @@
|
||||
|
||||
/* da65 */
|
||||
#include "attrtab.h"
|
||||
#include "code.h"
|
||||
#include "code.h"
|
||||
#include "error.h"
|
||||
#include "global.h"
|
||||
#include "output.h"
|
||||
@@ -49,108 +49,110 @@
|
||||
|
||||
|
||||
|
||||
void ByteTable (unsigned RemainingBytes)
|
||||
static unsigned GetSpan (attr_t Style)
|
||||
/* Get the number of bytes for a given style */
|
||||
{
|
||||
/* 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
|
||||
* attribute.
|
||||
*/
|
||||
unsigned Count = 1;
|
||||
while (Count < RemainingBytes) {
|
||||
if (HaveLabel(PC+Count) || GetStyle (PC+Count) != Style) {
|
||||
break;
|
||||
}
|
||||
++Count;
|
||||
}
|
||||
|
||||
/* Return the number of bytes */
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned DoTable (attr_t Style, unsigned MemberSize, void (*TableFunc) (unsigned))
|
||||
/* Output a table of bytes */
|
||||
{
|
||||
/* Count how many bytes may be output. This number is limited by the
|
||||
* number of remaining bytes, a label, or the end of the ByteTable
|
||||
* attribute.
|
||||
*/
|
||||
unsigned Count = 1;
|
||||
while (Count < RemainingBytes) {
|
||||
if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atByteTab) {
|
||||
break;
|
||||
}
|
||||
++Count;
|
||||
}
|
||||
RemainingBytes -= Count;
|
||||
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);
|
||||
|
||||
/* Output as many data bytes lines as needed */
|
||||
while (Count > 0) {
|
||||
BytesLeft = Count;
|
||||
while (BytesLeft > 0) {
|
||||
|
||||
/* Calculate the number of bytes for the next line */
|
||||
unsigned Chunk = (Count > BytesPerLine)? BytesPerLine : Count;
|
||||
unsigned Chunk = (BytesLeft > BytesPerLine)? BytesPerLine : BytesLeft;
|
||||
|
||||
/* Output a line with these bytes */
|
||||
DataByteLine (Chunk);
|
||||
TableFunc (Chunk);
|
||||
|
||||
/* Next line */
|
||||
Count -= Chunk;
|
||||
PC += Chunk;
|
||||
BytesLeft -= Chunk;
|
||||
PC += Chunk;
|
||||
}
|
||||
|
||||
/* If the next line is not a byte table line, add a separator */
|
||||
if (RemainingBytes > 0 && GetStyle (PC) != atByteTab) {
|
||||
/* If the next line is not the same style, add a separator */
|
||||
if (CodeLeft() && GetStyle (PC) != Style) {
|
||||
SeparatorLine ();
|
||||
}
|
||||
|
||||
/* Return the number of bytes output */
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WordTable (unsigned RemainingBytes)
|
||||
unsigned ByteTable (void)
|
||||
/* Output a table of bytes */
|
||||
{
|
||||
/* Call the low level function */
|
||||
return DoTable (atByteTab, 1, DataByteLine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned WordTable (void)
|
||||
/* Output a table of words */
|
||||
{
|
||||
/* Count how many bytes may be output. This number is limited by the
|
||||
* number of remaining bytes, a label, or the end of the WordTable
|
||||
* attribute.
|
||||
*/
|
||||
unsigned Count = 1;
|
||||
while (Count < RemainingBytes) {
|
||||
if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atWordTab) {
|
||||
break;
|
||||
}
|
||||
++Count;
|
||||
}
|
||||
RemainingBytes -= Count;
|
||||
|
||||
/* Make the given number even */
|
||||
Count &= ~1U;
|
||||
|
||||
/* Output as many data word lines as needed */
|
||||
while (Count > 0) {
|
||||
|
||||
/* Calculate the number of bytes for the next line */
|
||||
unsigned Chunk = (Count > BytesPerLine)? BytesPerLine : Count;
|
||||
|
||||
/* Output a line with these bytes */
|
||||
DataWordLine (Chunk);
|
||||
|
||||
/* Next line */
|
||||
PC += Chunk;
|
||||
Count -= Chunk;
|
||||
}
|
||||
|
||||
/* If the next line is not a byte table line, add a separator */
|
||||
if (RemainingBytes > 0 && GetStyle (PC) != atWordTab) {
|
||||
SeparatorLine ();
|
||||
}
|
||||
/* Call the low level function */
|
||||
return DoTable (atWordTab, 2, DataWordLine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AddrTable (unsigned RemainingBytes)
|
||||
unsigned DWordTable (void)
|
||||
/* Output a table of double words */
|
||||
{
|
||||
/* Call the low level function */
|
||||
return DoTable (atDWordTab, 4, DataDWordLine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned AddrTable (void)
|
||||
/* Output a table of addresses */
|
||||
{
|
||||
/* Count how many bytes may be output. This number is limited by the
|
||||
* number of remaining bytes, a label, or the end of the WordTable
|
||||
* attribute.
|
||||
*/
|
||||
unsigned Count = 1;
|
||||
while (Count < RemainingBytes) {
|
||||
if (HaveLabel(PC+Count) || GetStyle (PC+Count) != atAddrTab) {
|
||||
break;
|
||||
}
|
||||
++Count;
|
||||
}
|
||||
RemainingBytes -= Count;
|
||||
unsigned BytesLeft;
|
||||
|
||||
/* Count how many bytes may be output. */
|
||||
unsigned Count = GetSpan (atAddrTab);
|
||||
|
||||
/* Make the given number even */
|
||||
Count &= ~1U;
|
||||
|
||||
/* Output as many data bytes lines as needed. For addresses, each line
|
||||
* will hold just one address.
|
||||
*/
|
||||
while (Count > 0) {
|
||||
*/
|
||||
BytesLeft = Count;
|
||||
while (BytesLeft > 0) {
|
||||
|
||||
/* Get the address */
|
||||
unsigned Addr = GetCodeWord (PC);
|
||||
@@ -158,13 +160,13 @@ void AddrTable (unsigned RemainingBytes)
|
||||
/* In pass 1, define a label, in pass 2 output the line */
|
||||
if (Pass == 1) {
|
||||
if (!HaveLabel (Addr)) {
|
||||
AddLabel (Addr, MakeLabelName (Addr));
|
||||
AddLabel (Addr, MakeLabelName (Addr));
|
||||
}
|
||||
} else {
|
||||
const char* Label = GetLabel (Addr);
|
||||
if (Label == 0) {
|
||||
/* OOPS! Should not happen */
|
||||
Internal ("OOPS - Label for address %04X disappeard!", Addr);
|
||||
/* OOPS! Should not happen */
|
||||
Internal ("OOPS - Label for address %04X disappeard!", Addr);
|
||||
}
|
||||
Indent (MIndent);
|
||||
Output (".word");
|
||||
@@ -175,14 +177,17 @@ void AddrTable (unsigned RemainingBytes)
|
||||
}
|
||||
|
||||
/* Next line */
|
||||
PC += 2;
|
||||
Count -= 2;
|
||||
PC += 2;
|
||||
BytesLeft -= 2;
|
||||
}
|
||||
|
||||
/* If the next line is not a byte table line, add a separator */
|
||||
if (RemainingBytes > 0 && GetStyle (PC) != atAddrTab) {
|
||||
if (CodeLeft() && GetStyle (PC) != atAddrTab) {
|
||||
SeparatorLine ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the number of bytes output */
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user