-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics.cpp
More file actions
94 lines (75 loc) · 2.13 KB
/
graphics.cpp
File metadata and controls
94 lines (75 loc) · 2.13 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
#include "graphics.h"
void DrawTile(FILE* rom, long address, int xx, int yy, int pal, unsigned char sprite[80][64])
{
unsigned char ch;
int i;
int y;
char sprLine[8][8];
fseek(rom, address, SEEK_SET);
for (y = 0; y < 8; y++)
{
ch = fgetc(rom);
for (i = 0; i < 8; i++)
sprLine[y][7 - i] = (ch & (1 << i)) >> i;
ch = fgetc(rom);
for (i = 0; i < 8; i++)
sprLine[y][7 - i] += ((ch & (1 << i)) >> i) << 1;
}
for (y = 0; y < 8; y++)
{
ch = fgetc(rom);
for (i = 0; i < 8; i++)
sprLine[y][7 - i] += ((ch & (1 << i)) >> i) << 2;
ch = fgetc(rom);
for (i = 0; i < 8; i++)
sprLine[y][7 - i] += ((ch & (1 << i)) >> i) << 3;
}
for (y = 0; y < 8; y++)
{
for (i = 0; i < 8; i++)
{
if (sprLine[y][i] == 0)
sprite[yy + y][xx + i] = 0;
else
sprite[yy + y][xx + i] = (16 * pal) + sprLine[y][i];
}
}
}
void GetSprite(FILE* rom, int spriteNum, unsigned char sprite[80][64], int* width, int* height)
{
// width and height and palette will have to be predetermined and then
// selected in this function. Calling functions do not require this info.
// Same goes for address of each sprite. This function just takes a
// sprite "number", which is determined by where it appears in the rom.
static OSprite osprite[1144]; // DJGPP doesn't like 1144 for some reason
static int firstTime = 1;
unsigned int address = 0;
int offset = 0;
int pal = 0;
if (firstTime == 1)
{
#include "osprites.h"
firstTime = 0;
}
address = osprite[spriteNum].address;
*width = osprite[spriteNum].width;
*height = osprite[spriteNum].height;
pal = osprite[spriteNum].palette;
for (int y = 0; y < 80; y++)
{
for (int x = 0; x < 64; x++)
{
sprite[y][x] = 0;
}
}
{
for (int a = 0; a < *height; a++)
{
for (int i = 0; i < *width; i++)
{
DrawTile(rom, address + offset, i * 8, a * 8, pal, sprite);
offset += 32;
}
}
}
}