-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.c
More file actions
269 lines (243 loc) · 7.21 KB
/
Copy pathgraph.c
File metadata and controls
269 lines (243 loc) · 7.21 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
** Copyright 1998-2008, Pete J. Jensen
** Copyright 1998-2008, Robin McNeil
** All Rights Reserved.
**
** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Hairylogic, Inc.
** the contents of this file may not be disclosed to third parties, copied or
** duplicated in any form, in whole or in part, without the prior written
** permission of Hairylogic, Inc.
**
** RESTRICTED RIGHTS LEGEND:
** Use, duplication or disclosure by the Government is subject to restrictions
** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
** rights reserved under the Copyright Laws of the United States.
**
** ______
** /_____/\
** /_____\\ \ FILE: graph.c
** /_____\ \\ / AUTHOR: Pete Jensen
** /_____/ \/ / / DATE: Feb 6th, 2002
** /_____/ / \//\ VERSION: 3.0.5
** \_____\//\ / /
** \_____/ / /\ /
** \_____/ \\ \ HTTP://WWW.HAIRYLOGIC.COM
** \_____\ \\
** \_____\/
**
** This module handles all low level video operations, such as initializing a
** graphics mode, ending a graphics mode, puting pixels etc.
**
** CONTENTS:
** initializeGraphicsMode();
** endGraphicsMode();
** putPixel();
** getPixel();
** loadPaletteData();
** setPaletteData();
**/
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <dir.h>
#include <alloc.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <io.h>
#include <limits.h>
/* Graphics Header File*/
#include "graph.h"
#include "error.h"
#include "globals.h"
/**
* Function: initializeGraphicsMode
* Purpose : To initialize the graphics mode into mode 13H; it has the
* properties of 320x200 screensize & 8 bits per pixel.
* Inputs : Void
* Returns : Void
* Modifies: The current graphics mode.
* Sample Call : initializeGraphicsMode();
*/
void initializeGraphicsMode()
{
asm MOV AL, 13H;
asm MOV AH, 00H;
asm INT VIDEO_BIOS;
}
/*
* Function: endGraphicsMode
* Purpose : To take us out of the 13H graphics mode and back into dos text
* mode. This should be run anytime the program hits an error.
* and displays an error message.
* Inputs : Void
* Returns : Void.
* Modifies: The Current Graphics Mode.
* Sample Call : endGraphicsMode();
*/
void endGraphicsMode()
{
asm MOV AL, 3H;
asm MOV AH, 00H;
asm INT VIDEO_BIOS;
}
/*
* Function: putPixel
* Purpose : To put a pixel @ x,y with given colorByte.
* Inputs : word X: The X location of the pixel.
word Y: The Y location of the pixel.
* Returns : Void
* Modifies: Adds one pixel to the graphics screen.
* Sample Call : putPixel(10, 10, 14);
*/
void putPixel(word X, word Y, byte color)
{
asm mov DI, VIDEO_RAM;
asm mov ES, DI;
asm mov AX, Y;
asm mov BX, Y;
asm shl AX, 8;
asm shl BX, 6;
asm add AX, BX;
asm add AX, X;
asm mov DI, AX;
asm mov AL, color;
asm mov ES:[DI], AL;
}
/*
* Function: getPixel
* Purpose : To get a pixel @ x,y with & return colorByte.
* Inputs : word X: The X location of the pixel.
word Y: The Y location of the pixel.
* Returns : The byteColor @ x,y.
* Sample Call : byteColor = getPixel(10, 10);
*/
byte getPixel(word X, word Y)
{
byte getColor;
asm MOV AH,0DH
asm MOV CX,X
asm MOV DX,Y
asm INT VIDEO_BIOS
asm MOV getColor, AL
return getColor;
}
/*
* Function: loadPaletteData
* Purpose : To load palette Data
* Inputs : The filename where the palette data is stored.
* Returns : Void
* Sample Call : loadPaletteData("palette//pal.pal");
*/
void loadPaletteData(char *palFileName)
{
unsigned char palette_data[256][3];
FILE *fp;
unsigned int w, h;
char errorBuffer[70];
if ((fp = fopen(palFileName, "rb")) != NULL)
{
for (h = 0; h < 256; h++)
for (w = 0; w < 3; w++)
if (fscanf(fp,"%d", &palette_data[h][w]) != 1)
errorHandler("Unable to read palette data!");
else continue;
setVGApalette(&palette_data[0][0]);
if (fclose(fp) == NULL)
errorHandler("Unable to close palette file!");
}
else
{
sprintf(errorBuffer, "Could not open palette file: %s", palFileName);
errorHandler(errorBuffer);
}
}
/*
* Function: setVGApalette
* Purpose : To set the Vga palette; pass this function palette data.
* Inputs : Arrary of unsigned chars.
* Returns : Void
* Sample Call : setVGApalette(paletteData);
*/
void setVGApalette(unsigned char *buffer)
{
union REGS reg;
struct SREGS inreg;
reg.x.ax = 0x1012;
segread(&inreg);
inreg.es = inreg.ds;
reg.x.bx = 0;
reg.x.cx = 256;
reg.x.dx = (int)&buffer[0];
int86x(0x10,®,®,&inreg);
}
void displayHFGFile(char *fileName, unsigned char x,
unsigned char y, signed char transparentByte)
{
/* File Pointer */
FILE *fp;
/* Width; Height & Color Information */
unsigned short int width;
unsigned short int height;
unsigned int w, h;
unsigned int colorByte;
/* The error buffer to store compound strings. */
char errorBuffer[80];
/* Try to open the HFG file. */
if ((fp = fopen(fileName, "rb")) != NULL)
{
/* Try to read a valid image size; if not goto error handler */
if ( (fscanf(fp, "%d", &width) + fscanf(fp, "%d", &height)) != 2)
errorHandler("Unable to Read HFG File Width & Height.");
/* Iterate through the image data. */
for (h = 0; h < height; h++)
for (w = 0; w < width; w++)
if ( fscanf(fp, "%d", &colorByte) != 1)
/* We did not read valid value. */
errorHandler("Invalid HFG File format.");
else
if (colorByte != transparentByte)
/* Move to proper location, put colorByte @ x+w, y+h */
putPixel((x + w), (y + h), colorByte);
/* Make 100% sure we close the file, I ran into a bug here because In
* displaying several pictures one after another I would be unable to
* open another file. */
if (fclose(fp) == EOF)
errorHandler("Unable to close an open HFG file!");
}
else
{
/* Display */
sprintf(errorBuffer, "Unable to open a file named: %s", fileName);
errorHandler(errorBuffer);
}
}
void displaySplash(char *fileName, signed char transparentColor)
{
FILE *fp;
unsigned short int garbage;
unsigned int w, h;
const SPLASH_WIDTH = 320;
const SPLASH_HEIGHT = 200;
unsigned int colorByte;
if ((fp = fopen(fileName,"rb")) != NULL)
{
fscanf(fp,"%d", &garbage);
fscanf(fp,"%d", &garbage);
for (h = 0; h < SPLASH_HEIGHT; h++)
for (w = 0; w < SPLASH_WIDTH; w++)
{
fscanf(fp, "%d", &colorByte);
if(colorByte != transparentColor)
putPixel(w ,h ,colorByte);
}
fclose(fp);
}
else
errorHandler("Could not open splash file.");
}