]> 4ch.mooo.com Git - 16.git/blob - 16/cawat/JAM_IO.C
wwww
[16.git] / 16 / cawat / JAM_IO.C
1 /* Catacomb Armageddon Source Code\r
2  * Copyright (C) 1993-2014 Flat Rock Software\r
3  *\r
4  * This program is free software; you can redistribute it and/or modify\r
5  * it under the terms of the GNU General Public License as published by\r
6  * the Free Software Foundation; either version 2 of the License, or\r
7  * (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License along\r
15  * with this program; if not, write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
17  */\r
18 \r
19 #include <stdio.h>\r
20 #include <stdlib.h>\r
21 #include <string.h>\r
22 #include <ctype.h>\r
23 #include <alloc.h>\r
24 #include <fcntl.h>\r
25 #include <dos.h>\r
26 #include <io.h>\r
27 \r
28 #include "def.h"\r
29 #include "gelib.h"\r
30 #include "jam_io.h"\r
31 \r
32 //----------------------------------------------------------------------------\r
33 //\r
34 //                                                      PTR/PTR COMPRESSION ROUTINES\r
35 //\r
36 //\r
37 //----------------------------------------------------------------------------\r
38 \r
39 \r
40 \r
41 //---------------------------------------------------------------------------\r
42 // WritePtr()  -- Outputs data to a particular ptr type\r
43 //\r
44 //      PtrType MUST be of type DEST_TYPE.\r
45 //\r
46 // NOTE : For PtrTypes DEST_MEM a ZERO (0) is always returned.\r
47 //\r
48 //---------------------------------------------------------------------------\r
49 char WritePtr(long outfile, unsigned char data, unsigned PtrType)\r
50 {\r
51         int returnval = 0;\r
52 \r
53         switch (PtrType & DEST_TYPES)\r
54         {\r
55                 case DEST_FILE:\r
56                         write(*(int far *)outfile,(char *)&data,1);\r
57                 break;\r
58 \r
59                 case DEST_FFILE:\r
60                         returnval = putc(data, *(FILE **)outfile);\r
61                 break;\r
62 \r
63                 case DEST_IMEM:\r
64                         printf("WritePtr - unsupported ptr type\n");\r
65                         exit(0);\r
66                 break;\r
67 \r
68                 case DEST_MEM:\r
69                         *((char far *)*(char far **)outfile)++ = data;\r
70                 break;\r
71         }\r
72 \r
73         return(returnval);\r
74 \r
75 }\r
76 \r
77 \r
78 //---------------------------------------------------------------------------\r
79 // ReadPtr()  -- Reads data from a particular ptr type\r
80 //\r
81 //      PtrType MUST be of type SRC_TYPE.\r
82 //\r
83 // RETURNS :\r
84 //              The char read in or EOF for SRC_FFILE type of reads.\r
85 //\r
86 //\r
87 //---------------------------------------------------------------------------\r
88 int ReadPtr(long infile, unsigned PtrType)\r
89 {\r
90         int returnval = 0;\r
91 \r
92         switch (PtrType & SRC_TYPES)\r
93         {\r
94                 case SRC_FILE:\r
95                         read(*(int far *)infile,(char *)&returnval,1);\r
96                 break;\r
97 \r
98                 case SRC_FFILE:\r
99                         returnval = getc(*(FILE far **)infile\r
100                         );\r
101                 break;\r
102 \r
103                 case SRC_BFILE:\r
104                         returnval = bio_readch((BufferedIO *)*(void far **)infile);\r
105                 break;\r
106 \r
107 //              case SRC_IMEM:\r
108 //                      printf("WritePtr - unsupported ptr type\n");\r
109 //                      exit(0);\r
110 //              break;\r
111 \r
112                 case SRC_MEM:\r
113                         returnval = (unsigned char)*((char far *)*(char far **)infile)++;\r
114                 break;\r
115         }\r
116 \r
117         return(returnval);\r
118 }\r
119 \r
120 \r
121 \r