15 extern unsigned char *tilemap;
16 extern int tiles[16*256];
17 volatile int lastindex = 0;
18 volatile int background = 0;
19 volatile int lockindex = 0;
21 void inittiles(
int val)
25 memset(tilemap, 0, 40*30);
26 memset(tiles, val, 16*4);
30 inline int getindex(uint8_t *ptr)
35 if (index > lockindex)
43 memcpy(&tiles[index << 4], &tiles[index1 << 4], 64);
49 void drawobject(
int col,
int row,
unsigned int *ptr,
int width,
int height)
54 int lastrow, row15, shift;
55 int numtilerow, numtilecol;
56 int index1, index2, index3;
57 unsigned int val1, val2, val3;
58 uchar map[3][3] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
60 numtilecol = (width + (col&15) + 15) >> 4;
61 numtilerow = (height + (row&15) + 15) >> 4;
64 for (i = 0, tilerow = (row >> 4); i < numtilerow; i++, tilerow++)
66 if (tilerow < 0 || tilerow >= 30)
continue;
67 for (j = 0, tilecol = (col >> 4); j < numtilecol; j++, tilecol++)
69 if (tilecol < 0 || tilecol >= 40)
continue;
70 map[i][j] = getindex(&tilemap[tilecol + tilerow * 40]);
75 for (i = 0; i < 3; i++)
77 for (j = 0; j < 3; j++) printf(
"%4d", map[i][j]);
82 lastrow = row + height;
83 if (lastrow > nrow) lastrow = nrow;
86 shift = (col & 15) << 1;
87 index1 = map[0][0] << 4;
88 index2 = map[0][1] << 4;
89 index3 = map[0][2] << 4;
92 for (i = 0; row < lastrow; row++)
103 val3 = val2 >> (30 - shift);
104 val2 = (val1 >> (30 - shift)) | (val2 << shift);
111 mask = (val1 | (val1 >> 1)) & 0x55555555;
112 mask = ~(mask | (mask << 1));
113 tiles[index1 + row15] = (tiles[index1 + row15] & mask) | val1;
117 mask = (val2 | (val2 >> 1)) & 0x55555555;
118 mask = ~(mask | (mask << 1));
119 tiles[index2 + row15] = (tiles[index2 + row15] & mask) | val2;
123 mask = (val3 | (val3 >> 1)) & 0x55555555;
124 mask = ~(mask | (mask << 1));
125 tiles[index3 + row15] = (tiles[index3 + row15] & mask) | val3;
132 index1 = map[i][0] << 4;
133 index2 = map[i][1] << 4;
134 index3 = map[i][2] << 4;
139 inline void drawdotfast(
int col,
int row,
int color)
141 int tilenum, index, shift;
143 tilenum = (col >> 4) + (row >> 4) * (ncol >> 4);
144 if (!(index = getindex(&tilemap[tilenum])))
return;
147 shift = (col & 15) << 1;
148 tiles[index] = (tiles[index] & ~(3 << shift)) | (color << shift);
151 inline void drawdot(
int col,
int row,
int color)
153 int tilenum, index, shift;
155 if (col < 0 || col >= ncol || row < 0 || row >= nrow)
return;
157 if (color < 0 || color >= COLOR_MAX)
return;
161 tilenum = (col >> 4) + (row >> 4) * (ncol >> 4);
162 if (!(index = getindex(&tilemap[tilenum])))
return;
165 shift = (col & 15) << 1;
166 tiles[index] = (tiles[index] & ~(3 << shift)) | (color << shift);
169 void drawhorzline(
int col0,
int col1,
int row,
int color)
173 if (row < 0 || row >= nrow)
return;
182 if (col1 < 0)
return;
183 if (col0 >= ncol)
return;
184 if (col1 >= ncol) col1 = ncol - 1;
185 if (col0 < 0) col0 = 0;
187 for (;col0 <= col1; col0++)
189 drawdotfast(col0, row, color);
193 void drawvertline(
int col,
int row0,
int row1,
int color)
197 if (col < 0 || col >= ncol)
return;
206 if (row1 < 0)
return;
207 if (row0 >= nrow)
return;
208 if (row1 >= nrow) row1 = nrow - 1;
209 if (row0 < 0) row0 = 0;
211 for (;row0 <= row1; row0++)
213 drawdotfast(col, row0, color);
217 void drawline(
int col0,
int row0,
int col1,
int row1,
int color)
219 int col, row, incr, acc;
220 int temp, cdiff, rdiff, cdiffa, rdiffa;
222 cdiffa = cdiff = col1 - col0;
223 rdiffa = rdiff = row1 - row0;
225 if (cdiff == 0 && rdiff == 0)
227 drawdot(col0, row0, color);
232 drawvertline(col0, row0, row1, color);
237 drawhorzline(col0, col1, row1, color);
241 if (cdiffa < 0) cdiffa = -cdiffa;
242 if (rdiffa < 0) rdiffa = -rdiffa;
244 if (((cdiffa > rdiffa) && (cdiff < 0)) || ((rdiffa >= cdiffa) && (rdiff < 0)))
259 incr = (rdiff << 16) / cdiff;
260 for (col = col0; col <= col1; col++)
262 row = row0 + (acc >> 16);
264 drawdot(col, row, color);
269 incr = (cdiff << 16) / rdiff;
270 for (row = row0; row <= row1; row++)
272 col = col0 + (acc >> 16);
274 drawdot(col, row, color);