aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2017-01-17 15:46:24 +0000
committerIan C <ianc@noddybox.co.uk>2017-01-17 15:46:24 +0000
commit2ac64e7b95dd26df77d0e386fadd00c2e2151ca1 (patch)
treeea79d5e0c65aae6263075b5b3d31e27684745aea /src
parent7bfdf10881b8dbff2690aeff58d84ef38567f1b3 (diff)
Added 3-byte word output to cpcout and added small tool for investigating CPC
CDT files.
Diffstat (limited to 'src')
-rw-r--r--src/cpcout.c12
-rw-r--r--src/example/dump.c129
2 files changed, 141 insertions, 0 deletions
diff --git a/src/cpcout.c b/src/cpcout.c
index b962340..53496ea 100644
--- a/src/cpcout.c
+++ b/src/cpcout.c
@@ -70,6 +70,18 @@ static void WriteWord(FILE *fp, int w)
}
+static void Write3(FILE *fp, unsigned long l)
+{
+ int f;
+
+ for(f = 0; f < 3; f++)
+ {
+ WriteByte(fp, l & 0xff);
+ l >>= 8u;
+ }
+}
+
+
static void WriteLong(FILE *fp, unsigned long l)
{
int f;
diff --git a/src/example/dump.c b/src/example/dump.c
new file mode 100644
index 0000000..93713de
--- /dev/null
+++ b/src/example/dump.c
@@ -0,0 +1,129 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+typedef struct
+{
+ int len;
+ unsigned char *addr;
+} Block;
+
+static int Word(FILE *fp)
+{
+ int i0;
+ int i1;
+
+ i0 = getc(stdin);
+ i1 = getc(stdin);
+
+ return i0 | i1 << 8;
+}
+
+static int Triplet(FILE *fp)
+{
+ int i0;
+ int i1;
+ int i2;
+
+ i0 = getc(stdin);
+ i1 = getc(stdin);
+ i2 = getc(stdin);
+
+ return i0 | i1 << 8 | i2 << 16;
+}
+
+static Block *DumpBlock(FILE *fp)
+{
+ Block *block;
+
+ Word(fp); /* PILOT */
+ Word(fp); /* SYNC1 */
+ Word(fp); /* SYNC2 */
+ Word(fp); /* ZERO */
+ Word(fp); /* ONE */
+ Word(fp); /* PILOT LEN */
+ getc(fp); /* USED BITS */
+ Word(fp); /* PAUSE */
+
+ block = malloc(sizeof *block);
+
+ block->len = Triplet(fp); /* LEN */
+ block->addr = malloc(block->len);
+ fread(block->addr, 1, block->len, fp);
+
+ return block;
+}
+
+static void CompareEnds(Block **block, int count)
+{
+ int f;
+ int n;
+ int min;
+ int done;
+
+ min = 0xffffff;
+
+ for(f=0; f < count; f++)
+ {
+ if (block[f]->len < min)
+ {
+ min = block[f]->len;
+ }
+ }
+
+ done = 0;
+
+ for(f = 0; f < min && !done; f++)
+ {
+ for(n = 0; n < count - 1 && !done; n++)
+ {
+ if (block[n]->addr[block[n]->len - 1 - f] !=
+ block[n+1]->addr[block[n+1]->len - 1 - f])
+ {
+ done = 1;
+ }
+ }
+ }
+
+ if (done)
+ {
+ printf("Last %d bytes match\n", --f);
+
+ for(n = 0; n < f; n++)
+ {
+ if (n > 0)
+ {
+ printf(" ");
+ }
+
+ printf("%x", (unsigned)block[0]->addr[block[0]->len - 1 - n]);
+ }
+
+ printf("\n");
+ }
+}
+
+int main(int argc, char *argv)
+{
+ int ch;
+ int count;
+ int f;
+ Block *block[256] = {0};
+
+ ch = getc(stdin);
+
+ while(ch != EOF)
+ {
+ if (ch == 0x11)
+ {
+ block[count++] = DumpBlock(stdin);
+ }
+
+ ch = getc(stdin);
+ }
+
+ printf("Got %d blocks\n", count);
+
+ CompareEnds(block, count);
+}