- fprintf (F, " .byte $%02X", (*D++ & 0xFF));
- for (I = 1; I < Chunk; ++I) {
- fprintf (F, ",%02X", (*D++ & 0xFF));
+ fputs (" .byte ", F);
+ for (I = 0; I < Chunk; ++I) {
+ 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;
+
+ }