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