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)
34 //check palette for dups
35 for((*z)=0; (*z)<PAL_SIZE; (*z)+=3)
41 if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])
47 else for(zz=0; zz<(*q); zz+=3)
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])
59 else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])
63 a[((*z)+(*q))/3]=zz/3;
69 printf("================\n");
70 printf("zq: %d [%02d][%02d][%02d]\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);
71 printf("zz: %d [%02d][%02d][%02d]\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);
72 printf("z : %d [%02d][%02d][%02d]\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);
73 printf("================\n");
85 VL_modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqpp)
87 byte *p = bmp->palette;
92 static word a[256] = { 0 };
94 word pp=0,spee=0,ppee=0;
97 // if(qp>0) printf("(*i)=%02d\n", (*i));
99 if((*i)==0) outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
108 // printf("q: %02d\n", (q));
109 // printf("qq: %02d\n", (qq));
110 //printf(" (*i)-q=%02d\n", (*i)-q);
111 // printf("================\n");
112 outp(PAL_WRITE_REG, qq); /* start at the beginning of palette */
114 if((*i)<PAL_SIZE && w==0)
116 for(; (*i)<PAL_SIZE; (*i)++)
118 //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]))
119 //____ 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
120 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]))
126 outp(PAL_WRITE_REG, qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
127 for(ii=aqpp; ii>0; ii--)
129 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3))-(bmp->offset*3))]);
130 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+1)-(bmp->offset*3))]);
131 outp(PAL_DATA_REG, p[((((*i)+((aqpp-ii)*3))+((aqpp+ii)*3)+2)-(bmp->offset*3))]);
132 // printf("position = %d\n", qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
133 /*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)]); }
134 printf("[%d]", p[((((*i)+((aqpp-ii)*3)))-(bmp->offset*3))]);
135 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3))]);
136 printf("[%d] | ", p[((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3))]);
137 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+3)-(bmp->offset*3))]);
138 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+4)-(bmp->offset*3))]);
139 printf("[%d]", p[((((*i)+((aqpp-ii)*3))+5)-(bmp->offset*3))]);
140 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))]); }*/
141 //printf("%d\n", ((*i)+((ii)*3))/3);
142 //printf("ii=%d\n", ii);
143 //printf("aqpp=%d\n", aqpp);
144 //printf(" %d\n", ((*i)+((aqpp-ii)*3))/3);
146 //printf(" %d\n",((((*i)+((aqpp-ii)*3)))-(bmp->offset*3)));
147 //printf(" %d\n",((((*i)+((aqpp-ii)*3))+1)-(bmp->offset*3)));
148 //printf(" %d\n",((((*i)+((aqpp-ii)*3))+2)-(bmp->offset*3)));
149 //printf("(*i)=%d\n", (*i));
151 //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)]);
157 if(bmp->offset==0 && (*i)<3 && q==0) outp(PAL_DATA_REG, 0);
159 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);
160 else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]);
169 long bufSize = (bmp->width * bmp->height);
170 chkcolor(bmp, &q, &a, &aa, &z);
172 /*printf("z=%d\n", z/3);
173 printf("q+z=%d\n", (q+z)/3);
174 printf("z-ppee=%d\n", (z-ppee)/3);
175 printf("q=%d\n", q/3);
176 printf("aa=%d\n", aa);*/
178 aq=0; pp = q; ppee=q;
182 //printf("a[%02d]=(%d)", aq, a[aq]);
184 else{ aqpp++; break; }
187 /* printf("aq=%02d\n", aq);
188 printf("z=%02d\n", z/3);
189 printf("(z/3)-aqpp=%02d\n", (z/3)-aqpp);
190 printf("aqpp=%02d\n", aqpp);*/
192 for(lq=0; lq<bufSize; lq++)
194 if(bmp->data[lq]+bmp->offset==aq)
196 //printf("\n%02d\n", bmp->data[lq]);
197 //printf("\n%02d\n", bmp->offset);
198 //printf("\naq= %02d\n", aq);
199 //printf("a[aq]= %02d\n", a[aq]);
200 //bmp->data[lq]=((bmp->data[lq]+bmp->offset)-a[aq]);
202 //printf("_%d \n", bmp->data[lq]);
204 else if(bmp->data[lq]+bmp->offset < (z/3)-aqpp)
206 if(bmp->data[lq]+bmp->offset >= aq) bmp->data[lq]=(bmp->data[lq]+bmp->offset)-aqpp;
207 else bmp->data[lq]+=(bmp->offset);
210 //printf("%02d ", bmp->data[lq]);
211 //if(lq > 0 && lq%bmp->width==0) printf("\n");
216 if(((pp/3)==aq || spee>0))
218 /*printf("spee=%d\n", spee);
219 printf(" pp=%02d ", pp/3);
220 printf("old bmp: [%d]", bmp->palette[(pp-ppee)]);
221 printf("[%d]", bmp->palette[(pp-ppee)+1]);
222 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/
223 //if(spee==0) printf("\npp=%02d\n\n", pp/3);
224 bmp->palette[(pp-ppee)]= bmp->palette[(pp-ppee)+3];
225 bmp->palette[(pp-ppee)+1]= bmp->palette[(pp-ppee)+4];
226 bmp->palette[(pp-ppee)+2]= bmp->palette[(pp-ppee)+5];
229 /*printf(" pp=%02d ", pp/3);
230 printf(" bmp: [%d]", bmp->palette[(pp-ppee)]);
231 printf("[%d]", bmp->palette[(pp-ppee)+1]);
232 printf("[%d]\n", bmp->palette[(pp-ppee)+2]);*/
236 //update the palette~
237 //printf(" aqpp= %d\n", aqpp);
238 VL_modexPalUpdate(bmp, &ppee, 1, aqpp);
240 //printf(" aqpp= %d\n", aqpp);
241 //printf(" ppee= %d\n", ppee);
244 printf("aqpp= %02d\n", aqpp/3);
245 printf("aq= %02d\n", aq);
246 printf("aa= %02d\n", aa);
247 printf(" ppee= %02d\n", ppee);*/
249 if(aq<aa){ /*printf("~~~~\n"); */ppee=q; aq++; goto aqpee; }
250 /*printf("ppee=%d\n", ppee);
251 printf("pp=%d\n", pp);
253 printf("(*i)=%d\n", (*i));*/