1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
23 //#include "src/lib/16_vlpal.h"
26 //i want to make another vesion that checks the palette when the palette is being appened~
27 void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z)
33 //printf("q: %02d\n", (*q));
35 //check palette for dups
36 for((*z)=0; (*z)<PAL_SIZE; (*z)+=3)
38 // printf("\n z: %d\n", (*z));
39 // printf(" q: %d\n", (*q));
40 // printf(" z+q: %d\n\n", ((*z)+(*q)));
43 if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])
45 // printf("\n%d [%02d][%02d][%02d]\n", (*z), pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
46 // printf("%d [%02d][%02d][%02d]\n\n", (*z)+3, pal[(*z)+3], pal[(*z)+4], pal[(*z)+5]);
49 else for(zz=0; zz<(*q); zz+=3)
52 //printf("zz: %02d\n", zz/3);
55 if(pal[((*z)+(*q))]==pal[((*z)+(*q))+3] && pal[((*z)+(*q))+1]==pal[((*z)+(*q))+4] && pal[((*z)+(*q))+2]==pal[((*z)+(*q))+5])
57 // printf("\nzq1:%d[%02d][%02d][%02d]\n", (zz+q), pal[(zz+q)], pal[(zz+q)+1], pal[(zz+q)+2]);
58 // printf("zq2:%d[%02d][%02d][%02d]\n\n", (zz+q)+3, pal[(zz+q)+3], pal[(zz+q)+4], pal[(zz+q)+5]);
61 else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])
63 // printf("\n\nwwwwwwwwwwwwwwww\n");
64 // printf(" zq: %d [%02d][%02d][%02d] value that is needing to be changed~\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);
65 // printf(" zz: %d [%02d][%02d][%02d] value that the previous value is going to change to~\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);
66 // //printf(" zv: %d [%02d][%02d][%02d] wwww\n", (zz-z+q)/3, pal[(zz-z+q)], pal[(zz-z+q)+1], pal[(zz-z+q)+2]);
67 // printf(" z : %d [%02d][%02d][%02d] offset value~\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
68 a[((*z)+(*q))/3]=zz/3;
70 // printf("\n aa: %d\n\n", (*aa));
71 // printf(" a[%02d]=(%02d) offset array i think the palette should be updated again~\n", ((*z)+(*q))/3, a[((*z)+(*q))/3]);
72 // printf("wwwwwwwwwwwwwwww\n\n");
76 printf("================\n");
77 printf("zq: %d [%02d][%02d][%02d]\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);
78 printf("zz: %d [%02d][%02d][%02d]\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);
79 printf("z : %d [%02d][%02d][%02d]\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
80 printf("================\n");
82 //printf("[%d]", (zz+q));
85 //printf("\nz: %d\n", z);
86 //printf("q: %d\n", q);
87 //printf("zz: %d\n", zz);
94 modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqpp)
96 byte *p = bmp->palette;
101 static word a[256] = { 0 };
103 word pp=0,spee=0,ppee=0;
106 // if(qp>0) printf("(*i)=%02d\n", (*i));
108 if((*i)==0) outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
117 // printf("q: %02d\n", (q));
118 // printf("qq: %02d\n", (qq));
119 //printf(" (*i)-q=%02d\n", (*i)-q);
120 // printf("================\n");
121 outp(PAL_WRITE_REG, qq); /* start at the beginning of palette */
123 if((*i)<PAL_SIZE/2 && w==0)
125 for(; (*i)<PAL_SIZE/2; (*i)++)
127 //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]))
128 //____ 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
129 if(((((*i)-q)%3==0) || ((qp>0)&&((*i)-(bmp->offset*3))%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]))
135 outp(PAL_WRITE_REG, qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
136 for(ii=aqpp; ii>0; ii--)
138 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]);
139 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+1)-(bmp->offset*3))]);
140 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+2)-(bmp->offset*3))]);
141 // printf("position = %d\n", qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
142 /*if(qp>0){ //printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]); }
143 printf("[%d]", p[((((*i)+((aqpp-ii)*3)))-(bmp->offset*3))]);
144 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3))]);
145 printf("[%d] | ", p[((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3))]);
146 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+3)-(bmp->offset*3))]);
147 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+4)-(bmp->offset*3))]);
148 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+5)-(bmp->offset*3))]);
149 printf(" %d [%d]\n",((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))/3, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]); }*/
150 //printf("%d\n", ((*i)+((ii)*3))/3);
151 //printf("ii=%d\n", ii);
152 //printf("aqpp=%d\n", aqpp);
153 //printf(" %d\n", ((*i)+((aqpp-ii)*3))/3);
155 //printf(" %d\n",((((*i)+((aqpp-ii)*3)))-(bmp->offset*3)));
156 //printf(" %d\n",((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3)));
157 //printf(" %d\n",((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3)));
158 //printf("(*i)=%d\n", (*i));
160 //printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]);
166 if(bmp->offset==0 && (*i)<3 && q==0) outp(PAL_DATA_REG, 0);
168 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);
169 else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]);
173 modexWaitBorder(); /* waits one retrace -- less flicker */
174 if((*i)>=PAL_SIZE/2 && w==0)
176 for(; (*i)<PAL_SIZE; (*i)++)
178 //____ 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
179 if(((((*i)-q)%3==0) || ((qp>0)&&((*i)-(bmp->offset*3))%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]))
185 outp(PAL_WRITE_REG, qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
186 for(ii=aqpp; ii>0; ii--)
188 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]);
189 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+1)-(bmp->offset*3))]);
190 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+2)-(bmp->offset*3))]);
191 // printf("position = %d\n", qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
192 /*if(qp>0){ //printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]); }
193 printf("[%d]", p[((((*i)+((aqpp-ii)*3)))-(bmp->offset*3))]);
194 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3))]);
195 printf("[%d] | ", p[((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3))]);
196 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+3)-(bmp->offset*3))]);
197 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+4)-(bmp->offset*3))]);
198 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+5)-(bmp->offset*3))]);
199 printf(" %d [%d]\n",((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))/3, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]); }*/
200 //printf("%d\n", ((*i)+((ii)*3))/3);
201 //printf("ii=%d\n", ii);
202 //printf("aqpp=%d\n", aqpp);
203 //printf(" %d\n", ((*i)+((aqpp-ii)*3))/3);
205 //printf(" %d\n",((((*i)+((aqpp-ii)*3)))-(bmp->offset*3)));
206 //printf(" %d\n",((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3)));
207 //printf(" %d\n",((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3)));
208 //printf("(*i)=%d\n", (*i));
210 //printf("[%d]", p[((*i)-q)]); printf("[%d]", p[((*i)-q)+1]); printf("[%d]", p[((*i)-q)+2]); printf("[%d]", p[((*i)-q)+3]); printf("[%d]", p[((*i)-q)+4]); printf("[%d]", p[((*i)-q)+5]); printf(" %d [%d]\n", (*i), p[((*i)-q)]);
216 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);
217 else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]);
226 long bufSize = (bmp->width * bmp->height);
227 chkcolor(bmp, &q, &a, &aa, &z);
229 /*printf("z=%d\n", z/3);
230 printf("q+z=%d\n", (q+z)/3);
231 printf("z-ppee=%d\n", (z-ppee)/3);
232 printf("q=%d\n", q/3);
233 printf("aa=%d\n", aa);*/
235 aq=0; pp = q; ppee=q;
239 //printf("a[%02d]=(%d)", aq, a[aq]);
241 else{ aqpp++; break; }
244 /* printf("aq=%02d\n", aq);
245 printf("z=%02d\n", z/3);
246 printf("(z/3)-aqpp=%02d\n", (z/3)-aqpp);
247 printf("aqpp=%02d\n", aqpp);*/
249 for(lq=0; lq<bufSize; lq++)
251 if(bmp->data[lq]+bmp->offset==aq)
253 //printf("\n%02d\n", bmp->data[lq]);
254 //printf("\n%02d\n", bmp->offset);
255 //printf("\naq= %02d\n", aq);
256 //printf("a[aq]= %02d\n", a[aq]);
257 //bmp->data[lq]=((bmp->data[lq]+bmp->offset)-a[aq]);
259 //printf("_%d \n", bmp->data[lq]);
261 else if(bmp->data[lq]+bmp->offset < (z/3)-aqpp)
263 if(bmp->data[lq]+bmp->offset >= aq) bmp->data[lq]=(bmp->data[lq]+bmp->offset)-aqpp;
264 else bmp->data[lq]+=(bmp->offset);
267 //printf("%02d ", bmp->data[lq]);
268 //if(lq > 0 && lq%bmp->width==0) printf("\n");
273 if(((pp/3)==aq || spee>0))
275 /*printf("spee=%d\n", spee);
276 printf(" pp=%02d ", pp/3);
277 printf("old bmp: [%d]", bmp->palette[(pp-ppee)]);
278 printf("[%d]", bmp->palette[(pp-ppee)+1]);
279 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/
280 //if(spee==0) printf("\npp=%02d\n\n", pp/3);
281 bmp->palette[(pp-ppee)]= bmp->palette[(pp-ppee)+3];
282 bmp->palette[(pp-ppee)+1]= bmp->palette[(pp-ppee)+4];
283 bmp->palette[(pp-ppee)+2]= bmp->palette[(pp-ppee)+5];
286 /*printf(" pp=%02d ", pp/3);
287 printf(" bmp: [%d]", bmp->palette[(pp-ppee)]);
288 printf("[%d]", bmp->palette[(pp-ppee)+1]);
289 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/
293 //update the palette~
294 //printf(" aqpp= %d\n", aqpp);
295 modexPalUpdate(bmp, &ppee, 1, aqpp);
297 //printf(" aqpp= %d\n", aqpp);
298 //printf(" ppee= %d\n", ppee);
301 printf("aqpp= %02d\n", aqpp/3);
302 printf("aq= %02d\n", aq);
303 printf("aa= %02d\n", aa);
304 printf(" ppee= %02d\n", ppee);*/
306 if(aq<aa){ /*printf("~~~~\n"); */ppee=q; aq++; goto aqpee; }
307 /*printf("ppee=%d\n", ppee);
308 printf("pp=%d\n", pp);
310 printf("(*i)=%d\n", (*i));*/
316 modexPalUpdate2(byte *p)
320 outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
321 for(i=0; i<PAL_SIZE/2; i++)
323 outp(PAL_DATA_REG, p[i]);
325 modexWaitBorder(); /* waits one retrace -- less flicker */
326 for(; i<PAL_SIZE; i++)
328 outp(PAL_DATA_REG, p[(i)]);