]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_vlpal.c
a6af26188012e9fd2121dc3ec4d92dc4afe8e22e
[16.git] / src / lib / 16_vlpal.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 \r
23 #include "src/lib/16_vlpal.h"\r
24 \r
25 //color checker~\r
26 //i want to make another vesion that checks the palette when the palette is being appened~\r
27 void modexchkcolor(imgtestpal_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/, global_game_variables_t *gv)\r
28 {\r
29                 byte *pal=&(gv->video.palette);\r
30                 word zz=0;\r
31                 //pal = modexNewPal();\r
32 //              modexPalSave(pal);\r
33                 CHKCOLDBGOUT1\r
34                 //check palette for dups\r
35                 for(; (*z)<PAL_SIZE; (*z)+=3)\r
36                 {\r
37                         CHKCOLDBGOUT2\r
38                         //if((*z)%3==0)\r
39                         //{\r
40 //----                    if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])\r
41                                 if((*z)==(*i))\r
42                                 {\r
43                                         CHKCOLDBGOUT3\r
44 //0000                            (*z)-=3;\r
45                                         break;\r
46                                 }\r
47                                 else for(zz=0; zz<(*q); zz+=3)\r
48                                 {\r
49                                         CHKCOLDBGOUT4\r
50                                         if(zz%3==0)\r
51                                         {\r
52                                                 if(pal[((*z)+(*q))]==pal[((*z)+(*q))+3] && pal[((*z)+(*q))+1]==pal[((*z)+(*q))+4] && pal[((*z)+(*q))+2]==pal[((*z)+(*q))+5])    //break if duplicate colors found in palette because it have reached the end of the current data of the palette\r
53                                                 {\r
54 //                                                        (*z)-=3;\r
55 //                                                        (*i)-=3;\r
56                                                         CHKCOLDBGOUT5\r
57                                                         break;\r
58                                                 }\r
59                                                 else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])\r
60                                                 {\r
61                                                         CHKCOLDBGOUT6\r
62 //++++                                            (*i)--;\r
63 //                                                        (*z)--;\r
64                                                         //expand dong here\r
65 /*\r
66 planned features that i plan to implement~\r
67 image that has values on the pallete list!\r
68 wwww\r
69 no... wait.... no wwww\r
70 */\r
71                                                         //for(zzii=0; zzii<3; zzii++)\r
72                                                         //{\r
73                                                                 CHKCOLDBGOUT7\r
74                                                                 a[(((*z)+(*q)))]=zz;\r
75                                                         //}\r
76                                                         (*aa)=(((*z)+(*q)));\r
77                                                         CHKCOLDBGOUT8\r
78                                                 }\r
79                                                 /*else\r
80                                                 {\r
81                                                         printf("================\n");\r
82                                                         printf("zq: %d  [%02d][%02d][%02d]\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);\r
83                                                         printf("zz: %d  [%02d][%02d][%02d]\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);\r
84                                                         printf("z : %d  [%02d][%02d][%02d]\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);\r
85                                                         printf("================\n");\r
86                                                 }*/\r
87                                                 CHKCOLDBGOUT9\r
88                                         }\r
89                                 }\r
90                 }\r
91                 CHKCOLDBGOUT10\r
92                 //free(pal);\r
93 }\r
94 \r
95 //what is *i, w, q, qq, z, aq, aa, pp, qp, and aqoffset...\r
96 //pp is related to i\r
97 \r
98 void\r
99 VL_palette(imgtestpal_t *bmp, byte *p, word *i, word qp, word aqoffset, word *apal, global_game_variables_t *gv)\r
100 {\r
101         //byte *p = bmp->palette;\r
102         word w=0;\r
103         word q=0;\r
104         word qq=0;\r
105         word a[PAL_SIZE];       //palette array of change values!\r
106         word z=0, aq=0, aa=0, pp=0;\r
107 \r
108         //modexWaitBorder();\r
109         vga_wait_for_vsync();\r
110         if((*i)==0)\r
111         {\r
112                 memset(a, -1, sizeof(a));\r
113                 outp(PAL_WRITE_REG, 0);  /* start at the beginning of palette */\r
114         }\r
115         else if(qp==0)\r
116         {\r
117                 q=(*i);\r
118         }\r
119         else\r
120         {\r
121                 q=(*i);\r
122                 qq=(*i)/3;\r
123 #ifdef BEVERBOSEPALCHECK\r
124                 printf("q: %02d\n", (q));//\r
125                 printf("qq: %02d\n", (qq));//\r
126                 printf("          (*i)-q=%02d\n", (*i)-q);//\r
127 #endif\r
128                 outp(PAL_WRITE_REG, qq);  /* start at the beginning of palette */\r
129         }\r
130         if((*i)<PAL_SIZE && w==0)\r
131         {\r
132                 for(; (*i)<PAL_SIZE; (*i)++)\r
133                 {\r
134                         //if(i%3==0 && (p[i+5]==p[i+4] && p[i+4]==p[i+3] && p[i+3]==p[i+2] && p[i+2]==p[i+1] && p[i+1]==p[i] && p[i+5]==p[i]))\r
135 //____            if((qp>0)&&((*i)-q)%3==0 && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) outp(PAL_DATA_REG, p[(*i)-q]); else\r
136                         if(((((*i)-q)%3==0)) && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5]))\r
137                         {\r
138                                 w++;\r
139                                 break;\r
140                         }\r
141                         else if(qp>0 && (*i)>=(qp) && (*i)<((qp)+3))\r
142                         {\r
143 #ifdef BEVERBOSEPALCHECK\r
144                                 printf("qp=%d\n", qp);//\r
145                                 printf("                  (*i)=%d a[%d]=%d\n", (*i), qp, a[qp]);//\r
146                                 printf("                %d's color=%d\n", (*i), (a[qp])-(bmp->offset*3)+qp);//\r
147 #endif\r
148                                 outp(PAL_DATA_REG, p[((a[qp])-(bmp->offset*3)+qp)]);// fix this shit!\r
149                                 if((*i)+1==(qp)+3){ w++; /*(*i)++;*/ break; }\r
150                         }\r
151                         else\r
152                         {\r
153                                 if(bmp->offset==0 && (*i)<3 && q==0) outp(PAL_DATA_REG, 0);\r
154                                 else\r
155                                 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);\r
156                                 else\r
157                                 { outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3)+qp)]);\r
158 #ifdef BEVERBOSEPALCHECK\r
159                                 printf("p[]=%d  qp=%d   p[]-qp=%d\n", ((*i)-(bmp->offset*3)), qp, ((*i)-(bmp->offset*3))+qp);\r
160 #endif\r
161                                 }\r
162                         }\r
163                 }\r
164 #ifdef BEVERBOSEPALCHECK\r
165                 if(qp>0) printf("qp=%d\n", qp);//\r
166                 if(qp>0) printf("                                                (*i)=%d\n", (*i)/3);//\r
167                 printf("                                                  (*i)=%d\n", (*i)/3);\r
168 #endif\r
169         }\r
170 \r
171 #ifdef BEVERBOSEPALCHECK\r
172         printf("\nqqqqqqqq\n\n");\r
173 #endif\r
174 \r
175         //palette checker~\r
176         if(q>0 && qp==0)\r
177         {\r
178                 long lq;\r
179                 long bufSize = (bmp->width * bmp->height);\r
180                 pp = q;\r
181 #ifdef BEVERBOSEPALCHECK\r
182                 printf("1(*i)=%02d\n", (*i)/3);//\r
183                 printf("1z=%02d\n", z/3);//\r
184 #endif\r
185                 modexchkcolor(bmp, &q, &a, &aa, &z, i, gv);\r
186 #ifdef BEVERBOSEPALCHECK\r
187                 printf("2(*i)=%02d\n", (*i)/3);\r
188                 printf("2z=%02d\n", z/3);\r
189 #endif\r
190                 aq=0;\r
191 aqpee:\r
192                 while(aq<=aa)\r
193                 {\r
194 #ifdef BEVERBOSEPALCHECK\r
195 //                      printf("a[%02d]=(%d)\n", aq, a[aq]);//0000\r
196 #endif\r
197                         if(a[aq]==-1) aq++;\r
198                         else { aqoffset++; break; }\r
199                 }\r
200 //update the image data here!\r
201         for(lq=0; lq<bufSize; lq++)\r
202         {\r
203                                 /*\r
204                                                                         note to self\r
205                                                                         use a[qp] instead of bmp->offset for this spot!\r
206                                                                         NO! wwww\r
207                                 */\r
208 \r
209                                 /*\r
210                                 Facking bloody point the values of the changed palette to correct values.... major confusion! wwww\r
211                                 */\r
212 \r
213                 //(offset/bmp->offset)*bmp->offset\r
214 \r
215 #ifdef BEVERBOSEPALCHECK\r
216                 //printf("%02d ",bmp->data[lq]+bmp->offset);//\r
217                 //if(lq > 0 && lq%bmp->width==0) printf("\n");//\r
218                 //printf("%02d_", bmp->data[lq]+bmp->offset);//\r
219 #endif\r
220                 /*if(bmp->data[lq]+bmp->offset==aq)\r
221                 {\r
222 #ifdef BEVERBOSEPALCHECK\r
223                         printf("%02d", bmp->data[lq]);//\r
224                         printf("\n%02d\n", bmp->offset);//\r
225                         printf("aq=%02d ", aq);\r
226                         printf("a[aq]=%02d        ", a[aq]);\r
227                         printf("a[aq]+aqpp=%02d ", a[aq]+aqpp);\r
228                         printf("a[aq]-aqpp=%02d\n", a[aq]-aqpp);\r
229 #endif\r
230                         //bmp->data[lq]=((bmp->data[lq]+bmp->offset)-a[aq]);\r
231 //++++            bmp->data[lq]=a[aq]-aqpp;\r
232 #ifdef BEVERBOSEPALCHECK\r
233                           printf("_%d ", bmp->data[lq]);//\r
234                         if(lq > 0 && lq%bmp->width==0) printf("\n");//\r
235 #endif\r
236                 }\r
237                 else if(bmp->data[lq]+bmp->offset < ((*i)/3)-aqpp)\r
238                 {\r
239                         if(bmp->data[lq]+bmp->offset >= aq)\r
240                         {\r
241                                 bmp->data[lq]=(bmp->data[lq]+bmp->offset)-aqpp;//-((z-(*i))/3);\r
242 #ifdef BEVERBOSEPALCHECK\r
243                                 printf("_%d ", bmp->data[lq]+bmp->offset)-aqpp-((z-(*i))/3);//\r
244 #endif\r
245                         }\r
246                         else bmp->data[lq]+=(bmp->offset-aqpp);\r
247                 }*/\r
248 #ifdef BEVERBOSEPALCHECK\r
249                 //printf("%02d`", bmp->data[lq]);//\r
250                 //if(lq > 0 && lq%bmp->width==0) printf("\n");//\r
251 #endif\r
252         }\r
253 \r
254 #ifdef BEVERBOSEPALCHECK\r
255 printf("                  aq=%02d\n", aq);//\r
256 printf("                  aa=%02d\n", aa);//\r
257 #endif\r
258         //update the palette~\r
259         VL_palette(bmp, p, &pp, aq, aqoffset, &a, gv);\r
260         (*i)=pp;\r
261 \r
262         if(aq<aa){ pp=q; aq++; goto aqpee; }\r
263         }\r
264 }\r