OSDN Git Service

attempted font system added
[proj16/16.git] / 16 / v2 / source / verge / UTIL / CHRCONV / CHRCONV.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <stdio.h>\r
18 #include <malloc.h>\r
19 \r
20 char c[100];\r
21 FILE *f;\r
22 char *jalblkasd;\r
23 char byte, *t;\r
24 short word;\r
25 int quad;\r
26 \r
27 int bufsize=0;\r
28 unsigned char *csrc, *cb;\r
29 \r
30 void EmitC (unsigned char c)\r
31 {\r
32   *csrc++=c;\r
33   bufsize++;\r
34 }\r
35 \r
36 void Compress(unsigned char *p, int len)\r
37 {\r
38   int i;\r
39   unsigned char byt,samect;\r
40   unsigned char repcode;\r
41 \r
42   csrc=cb;\r
43   i=0; bufsize=0;\r
44   do\r
45   {   byt=p[i++];\r
46       samect=1;\r
47       while (samect<254 && i<len && byt==p[i])\r
48       {\r
49          samect++;\r
50          i++;\r
51       }\r
52       if (samect==2 && byt != 0xFF) { EmitC(byt); }\r
53       if (samect==3 && byt != 0xFF) { EmitC(byt); EmitC(byt); }\r
54       if (samect>3 || byt == 0xFF)\r
55       {\r
56          repcode=0xFF;\r
57          EmitC(repcode);\r
58          repcode=(char) samect;\r
59          EmitC(repcode);\r
60       }\r
61       EmitC(byt);\r
62   } while (i<len);\r
63 }\r
64 \r
65 int main(int argc, char *argv[])\r
66 {\r
67   int i;\r
68 \r
69   printf("CHRCONV v.1.00 Copyright (C)1998 BJ Eirich \n");\r
70   if (argc==1)\r
71   {\r
72     printf("CHR filename: "); fflush(stdout);\r
73     scanf("%s",c);\r
74     f=fopen(c, "rb");\r
75   }\r
76   if (argc==2)\r
77   {\r
78     memcpy(c, argv[1], strlen(argv[1]));\r
79     printf("Converting %s.\n",c);\r
80     f=fopen(c, "rb");\r
81   }\r
82   if (!f)\r
83   {\r
84     printf("Invalid filename.\n");\r
85     exit(-1);\r
86   }\r
87   jalblkasd=(char *) malloc(15360);\r
88   fread(jalblkasd, 1, 15360, f);\r
89   fclose(f);\r
90 \r
91   f=fopen(c,"wb");\r
92   byte=2; fwrite(&byte, 1, 1, f);\r
93   word=16; fwrite(&word, 1, 2, f);\r
94   word=32; fwrite(&word, 1, 2, f);\r
95   word=0;  fwrite(&word, 1, 2, f);\r
96   word=16; fwrite(&word, 1, 2, f);\r
97   word=16; fwrite(&word, 1, 2, f);\r
98   word=16; fwrite(&word, 1, 2, f);\r
99   word=30; fwrite(&word, 1, 2, f);\r
100 \r
101   cb=(char *) malloc(512*30);\r
102   Compress(jalblkasd, 512*30);\r
103   free(jalblkasd);\r
104   fwrite(&bufsize, 1, 4, f);\r
105   fwrite(cb, 1, bufsize, f);\r
106   free(cb);\r
107 \r
108   quad=15; fwrite(&quad, 1, 4, f);\r
109   quad=10; fwrite(&quad, 1, 4, f);\r
110   quad=5; fwrite(&quad, 1, 4, f);\r
111   quad=0; fwrite(&quad, 1, 4, f);\r
112 \r
113   t="F16W10F17W10F16W10F15W10F18W10F19W10F18W10F15W10";\r
114   i=(strlen(t)+1); fwrite(&i, 1, 4, f); fwrite(t, 1, i, f);\r
115   t="F11W10F12W10F11W10F10W10F13W10F14W10F13W10F10W10";\r
116   i=(strlen(t)+1); fwrite(&i, 1, 4, f); fwrite(t, 1, i, f);\r
117   t="F6W10F7W10F6W10F5W10F8W10F9W10F8W10F5W10";\r
118   i=(strlen(t)+1); fwrite(&i, 1, 4, f); fwrite(t, 1, i, f);\r
119   t="F1W10F2W10F1W10F0W10F3W10F4W10F3W10F0W10";\r
120   i=(strlen(t)+1); fwrite(&i, 1, 4, f); fwrite(t, 1, i, f);\r
121 \r
122   fclose(f);\r
123 \r
124   return 0;\r
125 }\r