-
Notifications
You must be signed in to change notification settings - Fork 173
/
gelib.c
238 lines (206 loc) · 5.54 KB
/
gelib.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* Keen Dreams Source Code
* Copyright (C) 2014 Javier M. Chavez
*
* 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 "KD_DEF.H"
#define BIO_BUFFER_LEN (512)
////////////////////////////////////////////////////////////////////////////
//
// FreeShape()
//
void FreeShape(struct Shape *shape)
{
if (shape->Data)
MM_FreePtr(&shape->Data);
}
////////////////////////////////////////////////////////////////////////////
//
// UnpackEGAShapeToScreen()
//
int UnpackEGAShapeToScreen(struct Shape *SHP,int startx,int starty)
{
int currenty;
signed char n, Rep, far *Src, far *Dst[8], loop, Plane;
unsigned int BPR, Height;
int NotWordAligned;
NotWordAligned = SHP->BPR & 1;
startx>>=3;
Src = MK_FP(SHP->Data,0);
currenty = starty;
Plane = 0;
Height = SHP->bmHdr.h;
while (Height--)
{
Dst[0] = (MK_FP(0xA000,displayofs));
Dst[0] += ylookup[currenty];
Dst[0] += startx;
for (loop=1; loop<SHP->bmHdr.d; loop++)
Dst[loop] = Dst[0];
for (Plane=0; Plane<SHP->bmHdr.d; Plane++)
{
outport(0x3c4,((1<<Plane)<<8)|2);
BPR = ((SHP->BPR+1) >> 1) << 1; // IGNORE WORD ALIGN
while (BPR)
{
if (SHP->bmHdr.comp)
n = *Src++;
else
n = BPR-1;
if (n < 0)
{
if (n != -128)
{
n = (-n)+1;
BPR -= n;
Rep = *Src++;
if ((!BPR) && (NotWordAligned)) // IGNORE WORD ALIGN
n--;
while (n--)
*Dst[Plane]++ = Rep;
}
else
BPR--;
}
else
{
n++;
BPR -= n;
if ((!BPR) && (NotWordAligned)) // IGNORE WORD ALIGN
n--;
while (n--)
*Dst[Plane]++ = *Src++;
if ((!BPR) && (NotWordAligned)) // IGNORE WORD ALIGN
Src++;
}
}
}
currenty++;
}
return(0);
}
////////////////////////////////////////////////////////////////////////////
//
// Verify()
//
long Verify(char *filename)
{
int handle;
long size;
if ((handle=open(filename,O_BINARY))==-1)
return (0);
size=filelength(handle);
close(handle);
return(size);
}
//--------------------------------------------------------------------------
// InitBufferedIO()
//--------------------------------------------------------------------------
memptr InitBufferedIO(int handle, BufferedIO *bio)
{
bio->handle = handle;
bio->offset = BIO_BUFFER_LEN;
bio->status = 0;
MM_GetPtr(&bio->buffer,BIO_BUFFER_LEN);
return(bio->buffer);
}
//--------------------------------------------------------------------------
// FreeBufferedIO()
//--------------------------------------------------------------------------
void FreeBufferedIO(BufferedIO *bio)
{
if (bio->buffer)
MM_FreePtr(&bio->buffer);
}
//--------------------------------------------------------------------------
// bio_readch()
//--------------------------------------------------------------------------
byte bio_readch(BufferedIO *bio)
{
byte far *buffer;
if (bio->offset == BIO_BUFFER_LEN)
{
bio->offset = 0;
bio_fillbuffer(bio);
}
buffer = MK_FP(bio->buffer,bio->offset++);
return(*buffer);
}
//--------------------------------------------------------------------------
// bio_fillbuffer()
//
// BUGS (Not really bugs... More like RULES!)
//
// 1) This code assumes BIO_BUFFER_LEN is no smaller than
// NEAR_BUFFER_LEN!!
//
// 2) BufferedIO.status should be altered by this code to report
// read errors, end of file, etc... If you know how big the file
// is you're reading, determining EOF should be no problem.
//
//--------------------------------------------------------------------------
void bio_fillbuffer(BufferedIO *bio)
{
#define NEAR_BUFFER_LEN (64)
byte near_buffer[NEAR_BUFFER_LEN];
short bio_length,bytes_read,bytes_requested;
bytes_read = 0;
bio_length = BIO_BUFFER_LEN;
while (bio_length)
{
if (bio_length > NEAR_BUFFER_LEN-1)
bytes_requested = NEAR_BUFFER_LEN;
else
bytes_requested = bio_length;
read(bio->handle,near_buffer,bytes_requested);
_fmemcpy(MK_FP(bio->buffer,bytes_read),near_buffer,bytes_requested);
bio_length -= bytes_requested;
bytes_read += bytes_requested;
}
}
///////////////////////////////////////////////////////////////////////////
//
// SwapLong()
//
void SwapLong(long far *Var)
{
asm les bx,Var
asm mov ax,[es:bx]
asm xchg ah,al
asm xchg ax,[es:bx+2]
asm xchg ah,al
asm mov [es:bx],ax
}
///////////////////////////////////////////////////////////////////////////
//
// SwapWord()
//
void SwapWord(unsigned int far *Var)
{
asm les bx,Var
asm mov ax,[es:bx]
asm xchg ah,al
asm mov [es:bx],ax
}
////////////////////////////////////////////////////////////////////////////
//
// MoveGfxDst()
//
void MoveGfxDst(short x, short y)
{
unsigned address;
address = (y*linewidth)+(x/8);
bufferofs = displayofs = address;
}