New attribute "base".
git-svn-id: svn://svn.cc65.org/cc65/trunk@5590 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
|
#include "check.h"
|
||||||
#include "cmdline.h"
|
#include "cmdline.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
|
|||||||
FILE* F;
|
FILE* F;
|
||||||
const char* D;
|
const char* D;
|
||||||
unsigned Size;
|
unsigned Size;
|
||||||
|
unsigned Base = 16;
|
||||||
unsigned BytesPerLine = 16;
|
unsigned BytesPerLine = 16;
|
||||||
char C;
|
char C;
|
||||||
|
|
||||||
@@ -74,6 +76,13 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
|
|||||||
Error ("Invalid value for attribute `bytesperline'");
|
Error ("Invalid value for attribute `bytesperline'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for a base attribute */
|
||||||
|
V = GetAttrVal (A, "base");
|
||||||
|
if ((V && sscanf (V, "%u%c", &Base, &C) != 1) ||
|
||||||
|
(Base != 2 && Base != 10 && Base != 16)) {
|
||||||
|
Error ("Invalid value for attribute `base'");
|
||||||
|
}
|
||||||
|
|
||||||
/* Open the output file */
|
/* Open the output file */
|
||||||
F = fopen (Name, "w");
|
F = fopen (Name, "w");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
@@ -101,9 +110,30 @@ void WriteAsmFile (const StrBuf* Data, const Collection* A)
|
|||||||
if (Chunk > BytesPerLine) {
|
if (Chunk > BytesPerLine) {
|
||||||
Chunk = BytesPerLine;
|
Chunk = BytesPerLine;
|
||||||
}
|
}
|
||||||
fprintf (F, " .byte $%02X", (*D++ & 0xFF));
|
fputs (" .byte ", F);
|
||||||
for (I = 1; I < Chunk; ++I) {
|
for (I = 0; I < Chunk; ++I) {
|
||||||
fprintf (F, ",%02X", (*D++ & 0xFF));
|
unsigned char V = *D++;
|
||||||
|
if (I > 0) {
|
||||||
|
fputc (',', F);
|
||||||
|
}
|
||||||
|
switch (Base) {
|
||||||
|
case 2:
|
||||||
|
fprintf (F, "%%%u%u%u%u%u%u%u%u",
|
||||||
|
(V >> 7) & 0x01, (V >> 6) & 0x01,
|
||||||
|
(V >> 5) & 0x01, (V >> 4) & 0x01,
|
||||||
|
(V >> 3) & 0x01, (V >> 2) & 0x01,
|
||||||
|
(V >> 1) & 0x01, (V >> 0) & 0x01);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 10:
|
||||||
|
fprintf (F, "%u", V);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
fprintf (F, "$%02X", V);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fputc ('\n', F);
|
fputc ('\n', F);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user