]> 4ch.mooo.com Git - 16.git/blob - 16/sauce/tile.c
f33a9369052a04520e522b225af28bcae3d29c46
[16.git] / 16 / sauce / tile.c
1 #include "tile.h"
2 #include <mem.h>
3 #include <malloc.h>
4
5
6 extern unsigned char far* dbuffer;
7
8 //copy 16x16 tile to dest, loop unrolled 4 times
9 void putile(unsigned char far* dest, unsigned char far* source);
10 #pragma aux putile=     \
11     "mov bx, 0"   \
12     "marker:"     \
13     "mov cx, 4"   \
14     "rep movsb"   \
15     "add di, 304" \
16     "mov cx, 4"   \
17     "rep movsb"   \
18     "add di, 304" \
19     "mov cx, 4"   \
20     "rep movsb"   \
21     "add di, 304" \
22     "mov cx, 4"   \
23     "rep movsb"   \
24     "add di, 304" \
25     "add bx, 1"   \
26     "cmp bx, 4"   \
27     "jnz marker"    \ 
28     modify [cx bx]  \
29     parm [es di] [ds si];
30
31 int tilecreate(tile *ntile, int frames)  {
32     int i; //loop counter
33     int error = 0;
34
35     ntile->numimages = frames;
36     ntile->state = 0;
37   
38     for(i=0; i<frames; i++)  {
39         ntile->images[i] = (unsigned char far*)_fmalloc(256);
40         if(!ntile->images[i])
41             error = 1;
42     }
43     
44     return error;
45 }//end tilecreate
46
47 void tileclose(tile *dtile)  {
48     int i; // loop counter
49     
50     for(i=0; i<dtile->numimages; i++)
51         _ffree(dtile->images[i]);
52 }//end sprclose
53
54 void tileload (tile * in)  {
55     unsigned char far* dest;
56     unsigned char far* source;
57     int x_loc = 0, y_loc = 0;  //frame coordinates in dbuffer
58     int i,j;  //loop counters
59     
60     for(i=0; i < in->numimages; i++)  {
61         x_loc = i * (17);
62         if (x_loc > (304))  {
63             x_loc = 0;
64             y_loc += (17);
65         }//endif
66         source = dbuffer + ((y_loc * 320) + x_loc);
67         dest = in->images[i];
68         for(j=0; j < 16; j++) {
69             _fmemcpy(dest,source,16);
70             source += 320;
71             dest += 16;
72         }//end for
73     }//end outer for
74    
75 }//end tileload
76     
77 writetile(tile *out, unsigned char far* dest)  {
78     unsigned char far* source;
79     
80     dest += ((out->y_loc << 8) + (out->y_loc << 6) + out->x_loc);
81     source = out->images[out->curimage];
82      
83     putile(dest,source);
84         return 0;
85     
86 }//end writetile
87
88 int writetile_xclip(tile *out, unsigned char far* dest)  {
89     int dx;     //clipped starting x location
90     int dwidth; //clipped width of sprite
91     int i;
92
93     unsigned char far * source = out->images[out->curimage];
94     
95
96     if(out->x_loc < 0)  {
97         if(out->x_loc > -16)  {
98             dx = 0;
99         //    preclip = - out->x_loc;
100             source -= out->x_loc;
101             dwidth = 16 + out->x_loc;
102         }
103         else
104             return 0;  //tile not visible
105     }
106     else if(out->x_loc > 303)  {
107         if(out->x_loc < 320)  {
108         //    preclip = 0;
109             dx = out->x_loc;
110             dwidth = 320 - dx;
111         }
112         else
113             return 0;  //tile not visible
114     }
115     else  {
116     //    preclip = 0;
117         dwidth = 16;
118         dx = out->x_loc;
119     }
120
121
122     dest= dest + (out->y_loc << 8) + (out->y_loc << 6) + dx;  //find first pixel in dest
123
124     for(i = 0; i < 16; i++)  {
125         _fmemcpy(dest,source,dwidth);
126         source += 16;
127         dest += 320;
128     }
129
130     //  x_clip = dx;
131     //  x_dim_clip = dwidth;
132
133     return 1;
134 }//writetile_xclip
135
136 /*  not sure if this is working
137 ***********************************************************
138 sprite::writetile_prexclip(unsigned char far* dest)  {
139     int dwidth = x_dim_clip;
140     unsigned char far * source = images[curimage];
141     int i;
142
143     dest= dest + (y_loc << 8) + (y_loc << 6) + x_clip;  //find first pixel in dest
144     source += preclip;  //set source at first visible pixel
145
146     for(i = 0; i < 16; i++)  {
147         _fmemcpy(dest,source,dwidth);
148         source += 16;
149         dest += 320;
150     }
151 }      
152 ***************************************************************/