···11+PSI file format (2013-06-09)
22+========================================================================
33+44+File structure
55+------------------------------------------------------------------------
66+77+<file header chunk>
88+<chunk 0>
99+<chunk 1>
1010+...
1111+<chunk n>
1212+<end chunk>
1313+1414+All integers are in big-endian format.
1515+1616+1717+Chunk format
1818+------------------------------------------------------------------------
1919+2020+offset size description
2121+2222+0 4 Chunk ID
2323+4 4 Chunk size (n)
2424+0 n Chunk data
2525+n 4 Chunk CRC
2626+2727+ - The size does not include the chunk ID, chunk size or chunk CRC
2828+ fields.
2929+3030+ - The chunk CRC covers the chunk ID, chunk size and chunk data.
3131+3232+3333+CHUNK "PSI ": File header chunk
3434+------------------------------------------------------------------------
3535+3636+offset size description
3737+3838+0 4 Chunk ID ('PSI ' = 0x50534920)
3939+4 4 Chunk size (4)
4040+0 2 Format version (0)
4141+2 2 Default sector format
4242+ 00 00 unknown
4343+ 01 00 IBM FM
4444+ 02 00 IBM MFM DD
4545+ 02 01 IBM MFM HD
4646+ 02 02 IBM MFM ED
4747+ 03 00 MAC GCR
4848+4 4 Chunk CRC
4949+5050+5151+CHUNK "END ": End chunk
5252+------------------------------------------------------------------------
5353+5454+offset size description
5555+5656+0 4 Chunk ID ('END ')
5757+4 4 Chunk size (0)
5858+0 4 Chunk CRC (0x3d64af78)
5959+6060+6161+CHUNK "TEXT": Comments
6262+------------------------------------------------------------------------
6363+6464+offset size description
6565+6666+0 4 Chunk ID ('TEXT')
6767+4 4 Chunk size
6868+0 n Comment
6969+n 4 Chunk CRC
7070+7171+ - Comments should be UTF-8, with lines separated by LF (0x0a).
7272+7373+7474+CHUNK "SECT": Sector header
7575+------------------------------------------------------------------------
7676+7777+offset size description
7878+7979+0 4 Chunk ID ('SECT')
8080+4 4 Chunk size (8)
8181+8282+0 2 cylinder
8383+2 1 head
8484+3 1 sector
8585+4 2 size in bytes
8686+6 1 flags
8787+ 1 Compressed
8888+ 2 Alternate sector
8989+ 4 Data CRC error
9090+7 1 Compressed sector data
9191+9292+8 4 Chunk CRC
9393+9494+ - The alternate sector flag indicates that this is the same
9595+ physical sector as the one immediately preceding it.
9696+9797+ - The sector header chunk starts a new sector. All non sector
9898+ header chunks that follow refer to the same sector.
9999+100100+ - If the sector is marked as compressed, the sector data is
101101+ filled with the byte in <compressed sector data> and no
102102+ data chunk follows.
103103+104104+105105+CHUNK "DATA": Sector data
106106+------------------------------------------------------------------------
107107+108108+offset size description
109109+110110+0 4 Chunk ID ('DATA')
111111+4 4 Chunk size (n)
112112+0 n Sector data
113113+n 4 Chunk CRC
114114+115115+116116+CHUNK "IBMM": IBM MFM sector header
117117+------------------------------------------------------------------------
118118+119119+offset size description
120120+121121+0 4 Chunk ID ('IBMM')
122122+4 4 Chunk size (6)
123123+0 1 Cylinder
124124+1 1 Head
125125+2 1 Sector
126126+3 1 Size
127127+4 1 Flags
128128+ 1 CRC error in ID field
129129+ 2 CRC error in data field
130130+ 4 Deleted data adress mark
131131+ 8 Missing data adress mark
132132+5 1 Encoding subtype
133133+ 0 Double density (250 KBit/s)
134134+ 1 High density (500 KBit/s)
135135+ 2 Extra density (1000 KBit/s)
136136+6 4 Chunk CRC
137137+138138+139139+CHUNK "MACG": Macintosh GCR sector header
140140+------------------------------------------------------------------------
141141+142142+offset size description
143143+144144+0 4 Chunk ID ('MACG')
145145+4 4 Chunk size (12)
146146+0 2 Cylinder
147147+2 1 Head
148148+3 1 Sector
149149+4 1 Sector format
150150+5 1 Flags
151151+ 1 Checksum error in ID field
152152+ 2 Checksum error in data field
153153+ 4 Missing data mark
154154+6 12 Tag data
155155+18 4 Chunk CRC
156156+157157+158158+CHUNK "OFFS": Sector position
159159+------------------------------------------------------------------------
160160+161161+offset size description
162162+163163+0 4 Chunk ID ('OFFS')
164164+4 4 Chunk size (4)
165165+0 4 Sector position in data bits from the start of the track
166166+4 4 Chunk CRC
167167+168168+169169+CHUNK "TIME": Clock rate adjustment
170170+------------------------------------------------------------------------
171171+172172+offset size description
173173+174174+0 4 Chunk ID ('TIME')
175175+4 4 Chunk size (4)
176176+0 4 Sector read time in data bits
177177+4 4 Chunk CRC
178178+179179+ - The time it takes to read the data field of this sector is
180180+ <sector read time> / <number of bits in data field>.
181181+ For example, for a 512 byte sector a sector read time of 4096
182182+ would be normal. Larger values would indicate that it takes
183183+ longer to read the sector.
184184+185185+186186+CRC
187187+------------------------------------------------------------------------
188188+189189+ - The algorithm used is big-endian CRC-32 with generator
190190+ polynomial 0x1edc6f41. The CRC value is initialized to 0.
191191+192192+ unsigned long psi_crc (const unsigned char *buf, unsigned cnt)
193193+ {
194194+ unsigned i, j;
195195+ unsigned long crc;
196196+197197+ crc = 0;
198198+199199+ for (i = 0; i < cnt; i++) {
200200+ crc ^= (unsigned long) (buf[i] & 0xff) << 24;
201201+202202+ for (j = 0; j < 8; j++) {
203203+ if (crc & 0x80000000) {
204204+ crc = (crc << 1) ^ 0x1edc6f41;
205205+ }
206206+ else {
207207+ crc = crc << 1;
208208+ }
209209+ }
210210+ }
211211+212212+ return (crc & 0xffffffff);
213213+ }
···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/drivers/psi/psi-img-psi.h *
77+ * Created: 2013-05-29 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2013 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#ifndef PSI_IMG_PSI_H
2424+#define PSI_IMG_PSI_H 1
2525+2626+2727+#include <drivers/psi/psi.h>
2828+2929+3030+psi_img_t *psi_load_psi (FILE *fp);
3131+3232+int psi_save_psi (FILE *fp, const psi_img_t *img);
3333+3434+int psi_probe_psi_fp (FILE *fp);
3535+int psi_probe_psi (const char *fname);
3636+3737+3838+#endif