-
Notifications
You must be signed in to change notification settings - Fork 1
/
xmode.h
265 lines (193 loc) · 6.44 KB
/
xmode.h
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
/* Allegro port Copyright (C) 2014 Gavin Smith. */
/*-------------------------------------------------------*/
/* */
/* Combined definiton file for XMODEC.C & XMODEASM.ASM */
/* */
/* */
// Header file for xmode.
#ifndef __XMODE__
#define __XMODE__
#include <allegro.h>
// Definiton of graphics window.
#define XMIN 0
#define XMAX 319
#define YMIN 0
#define YMAX 219
#define MAXSPRITES 60
#define MAXOBJS 60
#define OBJ_ONECYCLE 0x01 // Destroy object after a cycle.
#define OBJ_HIGH 0x02 // High priority.
#define OBJ_LOW 0x00 // Low priority.
/* --- SPRITE DEFINITION
A sprite is defined as the following:
xs : Width of sprite in pixels.
ys : Heigth in pixels.
maxn: Number of pictures per sprite. (always > 0)
Located after this header is the sprite data itself.
Each pixel is ONE byte. (planar video mode)
First row of first picture, second row of first picture, ...
First row of second picture, ... and so on.
*/
#define SPR_ALIGN 0x07 // Align Field.
#define SPR_DOUBLE 0x08 // Double paint picture.
#define STAR_X 0
#define STAR_Y 2
#define STAR_COLOR 4
#define STAR_SPEED 6
#define STARSTRC_SIZE 8;
/* Function to access field in starstrc array. */
int starstrc_member (unsigned char *data, int i, int member);
void set_starstrc_member (unsigned char *data, int i, int member,
unsigned short int value);
struct sprstrc {
short xs; // x size of sprite.
short ys; // y size.
short maxn; // Number of pictures.
// Immediately here follows the SPRITEDATA.
//char data[];
char *data;
};
void load_sprstrc_from_file (struct sprstrc **s, void *database, char *file);
/* --- Low level sprite definition structure.
If a sprite has been pushed into the following structure it is ready
to be used by the low level sprite routines.
*/
struct lowspr {
int active; // Is sprite active ?
/* x size, possibly multiplied by 4, once for each VGA page. */
int xs;
int ys; // y size.
int nadd; // picture increment value.
int maxn; // number of pictures * 2
int xsalign; // x size, but a multiple of 4
int picsize; // Size of one image
int seqsize; // Size of all images in animation
int fullsize;
BITMAP **bmp; // Pointer to array of BITMAP *
BITMAP **bmp_silhouette; // Pointer to array of BITMAP *
char *data; // Sprite data: Ptr into SCREEN MEM
/* Each byte in mask corresponds to a pixel in the image. There are
* four bits used in each byte which correspond to the 4 pages of
* VGA memory. sizeof (mask) == fullsize. */
/* Is set for plane p if (data[x+p-a] != 0). 0 presumably is a 0 in the
* image bitmap representing a transparent pixel. */
char *mask; // Mask data: Ptr into MAIN MEM
};
/* --- STAR definition
Very simple indeed.
Just a coordinate pair, a color and a base speed. (per star)
A STARFIELD consists of an array of STARS.
*/
struct starstrc {
int x, y;
int color;
int speed;
};
void create_sprstrc (struct sprstrc **, unsigned char *);
static void retrace() {}
#define FLASH_COLOUR 230
void setpalette(PALETTE ptr);
void setcolor(int c, int r, int g, int b);
void setvanillapalette(int c);
void setstandardpalette(void);
void glowto(int r, int g, int b);
void glowin(int dir);
void glowout(void);
int cyclepalette(int c1, int c2, int pos);
void defstarfield(int n, unsigned char *star);
void gostarfield(void);
void stopstarfield(void);
void killstarfield(void);
int defsprite(void *sprite, unsigned flags);
void killsprite(int sprite);
void killallsprites(void);
int defobject(int sprite, int x, int y, int cycle);
void abandonobject(int obj);
void killobject(int obj);
void killallobjects(void);
void shutxmode(void);
void initxmode(void);
void setpage(int p);
void updatescreen(void);
unsigned long getspritesize(int sprite);
unsigned long getobjectsize(int object);
unsigned long getobjectpos(int object);
#define DISPLAY_SCALE 2
void setxmode(void);
void screenmode(int mode);
int moveobject(int obj, int x, int y);
int moveobjectdelta(int obj, int deltax, int deltay);
void flash(int obj);
int changesprite(short obj, short sprite);
int crashtest(int obj1, int obj2);
int outofwindow(int obj);
void putsprite(int sprite, int x, int y, int n);
void removesprite(int sprite, int x, int y);
void putspritedirect(struct sprstrc *spr, int xp, int yp, int n);
void clearscreen(void);
void clearregion(int y, int n);
void copypage(int src, int dst);
void showpage(int p);
void showline(int line);
void showpcx256(char *pic, int line);
int smooth_move (int difference, int subtick);
// window definition.
extern int windowx0, windowy0;
extern int windowx1, windowy1;
extern int objflashcolor;
extern int backgrndcolor;
#define FALSE 0
//#define TRUE 1
// VGA ports.
#define SC_INDEX 0x3c4 // Sequence Controller Index.
#define GC_INDEX 0x3ce
#define CRTC_INDEX 0x3d4 // CRT Controller Index.
#define MISC_OUTPUT 0x3c2 // Miscellaneous Output register.
#define MAP_MASK 0x2
#define BIT_MASK 0x8
#define INPUT_STATUS 0x3da
#define START_ADDR_HIGH 0xc
#define START_ADDR_LOW 0xd
// VGA 320x240 low level graphic constants.
#define BYTESPERLINE 80
#define PAGESIZE (BYTESPERLINE * (YMAX+1))
#define OFFSCREEN (2*PAGESIZE)
#define PALETTESIZE 768
// Object states.
#define O_FLASH 0x0001
struct objstrc {
int active;
int flags; // State of the object.
int x; // (x, y)
int y;
int xa; // (xa, ya) in active screen.
int ya;
int xb;
int yb;
int xs;
int ys;
int n;
int nadd;
int maxn;
int cycle; // 0-forward, 1-destroy
int destroy;
int sprite;
};
struct sfieldstrc {
int active; // Field active?
int go;
int n; // Number of STARS in field.
unsigned char *star; // Pointer to array of stars.
};
/* ----- Global data ----- */
extern struct lowspr _sprite[MAXSPRITES];
extern struct objstrc _obj[MAXOBJS];
extern struct sfieldstrc _sfield;
extern unsigned base;
extern unsigned page;
extern BITMAP *pages[2];
extern BITMAP *full_pages[2];
extern int objflashcolor; // Object flashes in white first.
extern int backgrndcolor; // Background is black.
extern PALETTE palette; // Palette currently in use.
#endif