annotate 3rdparty/packages/sierra/convutils/picpatch.c @ 2202:981b4e7e8014

Fixed makefile to copy dsks
author boisy
date Sat, 14 Mar 2009 20:11:55 +0000
parents b2820d3f1e38
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2076
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
1 /***********************************************************************************
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
2 * Program Name : picpatch *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
3 * Description : Removes the Plot command (0xFA) from all the pictures to make *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
4 * them compatible with the coco AGI interpreter. *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
5 * Author : Guillaume Major *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
6 * Date : July 19, 2006 *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
7 * License : Freeware. Do whatever you want with it! *
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
8 ***********************************************************************************/
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
9
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
10 #include <stdio.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
11 #include <ctype.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
12 #include <string.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
13 #include <stdlib.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
14 #include <io.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
15 #include <direct.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
16 #include <windows.h>
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
17
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
18 /* VOL directory entry structure */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
19 struct DIRECTORY_ENTRY {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
20 unsigned char byte1;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
21 unsigned char byte2;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
22 unsigned char byte3;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
23 };
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
24
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
25 /* Global variables */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
26 char sGamePath[MAX_PATH];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
27
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
28 /* Function prototypes */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
29 void PatchPicture(unsigned int iVolFile, unsigned int iPicNum, unsigned int iPicPos);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
30 void ShowUsage();
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
31
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
32 /* Main */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
33 int main(int argc, char **argv) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
34
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
35 FILE *picDir;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
36 char sPicDir[MAX_PATH];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
37 unsigned int iPicNum, iVolFile, iPicPos;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
38 struct DIRECTORY_ENTRY dir;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
39
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
40 printf("\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
41 printf("picpatch AGI picture resources patcher\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
42 printf("Version 1.0 (July 2006)\n\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
43
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
44 if (argc < 2) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
45 ShowUsage();
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
46 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
47 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
48 strncpy(sGamePath, argv[1], MAX_PATH);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
49 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
50
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
51 /* Get the full path of picDir */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
52 sprintf(sPicDir, "%s\\picDir", sGamePath);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
53
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
54 /* Open picDir file */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
55 if ((picDir = fopen(sPicDir, "rb")) == NULL) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
56 perror("Error opening picDir file");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
57 exit(1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
58 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
59
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
60 /* Initialize the picture counter */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
61 iPicNum = 0;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
62
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
63 /* Loop through the picDir file to remove plot commands */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
64 while (!ferror(picDir) && !feof(picDir) && fread(&dir, sizeof(dir), 1, picDir)) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
65 /* Verify if the picture resource exists */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
66 if (dir.byte1 != 0xFF) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
67 iVolFile = (dir.byte1 >> 4);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
68 iPicPos = ((dir.byte1 & 0x0F) << 16) + (dir.byte2 << 8) + dir.byte3;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
69 PatchPicture(iVolFile, iPicNum, iPicPos);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
70 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
71 iPicNum++;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
72 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
73
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
74 printf("Done!\n\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
75
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
76 /* Exit normally */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
77 exit(0);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
78 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
79
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
80 /* Patch the picture number specified in the VOL file */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
81 void PatchPicture(unsigned int iVolFile, unsigned int iPicNum, unsigned int iPicPos) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
82
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
83 FILE *volFile;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
84 char sVolFile[MAX_PATH];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
85 unsigned short iPicSize = 0;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
86 unsigned char acBuffer[16184];
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
87 unsigned char cChar;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
88 BOOL bSkip = FALSE;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
89
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
90 printf("Patching picture.%03i\n", iPicNum);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
91
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
92 /* Get the VOL file name */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
93 sprintf(sVolFile, "%s\\vol.%i", sGamePath, iVolFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
94
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
95 /* Open the VOL file for writing */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
96 if ((volFile = fopen(sVolFile, "r+b")) == NULL) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
97 perror("Error opening VOL file");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
98 exit(1);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
99 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
100
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
101 /* Skip the resource header */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
102 fseek(volFile, iPicPos + 5, SEEK_SET);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
103
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
104 while (!ferror(volFile) && !feof(volFile) && fread(&cChar, sizeof(unsigned char), 1, volFile) && cChar != 0xFF) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
105 if ((cChar & 0xF0) == 0xF0) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
106 bSkip = FALSE;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
107 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
108 if (bSkip == FALSE) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
109 if (cChar != 0xFA) {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
110 acBuffer[iPicSize] = cChar;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
111 iPicSize++;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
112 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
113 else {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
114 bSkip = TRUE;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
115 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
116 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
117 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
118
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
119 /* Add 0xFF to the buffer */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
120 acBuffer[iPicSize] = 0xFF;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
121 iPicSize++;
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
122
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
123 /* Modify the size of the picture in the header */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
124 fseek(volFile, 0, SEEK_SET);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
125 fwrite(&iPicSize, sizeof(unsigned short), 1, volFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
126
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
127 /* Write the buffer in the VOL file */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
128 fwrite(acBuffer, sizeof(char), iPicSize, volFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
129
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
130 /* Close the VOL file */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
131 fclose(volFile);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
132
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
133 }
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
134
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
135 /* Shows usage */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
136 void ShowUsage() {
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
137
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
138 printf("Usage: picpatch game-path\n");
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
139
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
140 /* Exit normally */
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
141 exit(0);
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
142
b2820d3f1e38 Utils written by G. Major for VOL conversion to CoCo interpreter
boisy
parents:
diff changeset
143 }