]>
cvs.zerfleddert.de Git - 32620_extract/blob - extract.c
1 /* Extractor for Geraet 32620 ROM files
3 * Copyright (c) 2020 Michael Gernoth <michael@gernoth.net>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 #include <sys/types.h>
33 int main(int argc
, char **argv
)
36 uint32_t adrs
[(64/3)+1] = { 0 };
44 fprintf(stderr
, "Syntax: %s in.bin prefix\n", argv
[0]);
48 fd
= open(argv
[1], O_RDONLY
);
50 perror("Can't open ROM");
54 r
= read(fd
, header
, sizeof(header
));
55 if (r
!= sizeof(header
)) {
56 perror("Can't read header");
61 * From: https://blog.ardy.io/2020/8/geraet-32620/
63 * 00000000 01000000 01000011 10110111 01001010 01000011 11000011 01011000
64 * ^^^^^^^^ ^^^^^^^^ ^^^^^^^^| |
65 * LIIIIIII LIILIIII LIIIILII
66 * I I I | +-- Amplification (Default: 3)
67 * I I I +----- Chip/Module Select lines/EOF?
68 * I I +----------- Address (HI Byte)
69 * I +---------------- Chip Select lines A15, A14, A13
70 * +-------------------- Address (LO Byte)
72 for (i
= 0; i
< 62; i
+=3) {
73 uint8_t hi
, lo
, amp
, cs
;
77 hi
= header
[i
+1] & 0x1f;
80 if ((header
[i
+2] & 0xf8) != 0xf8)
81 cs2
= (header
[i
+2] & 0xf8) >> 3;
84 cs
= ((header
[i
+1] & 0xe0) >> 5) - 2;
86 cs
= (((header
[i
+1] & 0xe0) >> 5) | (1 << 3)) - 4;
89 amp
= header
[i
+2] & 0x3;
91 adr
= ((hi
<< 8) | lo
) + (cs
* 8192);
93 adr
+= sizeof(header
);
95 printf("%02d. hi: 0x%02x, lo: 0x%02x, cs: 0x%02x, cs2: 0x%02x -> adr: 0x%04x; amp: 0x%02x\n",
96 i
/3, hi
, lo
, cs
, ((header
[i
+2] & 0xf8) >> 3), adr
, amp
);
99 if ((header
[i
+2] & 0xf8) == 0xf8)
105 for (i
= 0; i
< count
; i
++) {
111 lseek(fd
, adrs
[i
], SEEK_SET
);
113 len
= adrs
[i
+1] - adrs
[i
];
118 printf("%02d. Length: %d\n", i
, len
);
119 memset(file
, 0, sizeof(file
));
120 snprintf(file
, sizeof(file
)-1, "%s-%02d.raw", argv
[2], i
);
122 fd_out
= open(file
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0644);
124 perror("Can't open out");
128 r
= read(fd
, buf
, len
);
130 perror("Can't read content");
134 r
= write(fd_out
, buf
, len
);
136 perror("Can't write content");