]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_vlpa_.c
added a simpler mmtest.c
[16.git] / src / lib / 16_vlpa_.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2022 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
3  *
4  * This file is part of Project 16.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #include "src/lib/16_vlpal.h"
24
25 //color checker~
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)
28 {
29                 byte *pal;
30                 word zz=0;
31                 pal = modexNewPal();
32                 modexPalSave(pal);
33                 CHKCOLDBGOUT1
34                 //check palette for dups
35                 for((*z)=0; (*z)<PAL_SIZE; (*z)+=3)
36                 {
37                         CHKCOLDBGOUT2
38                         if((*z)%3==0)
39                         {
40 //=======
41                                 if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])
42                                 {
43                                         CHKCOLDBGOUT3
44 //====
45                                         break;
46                                 }
47                                 else for(zz=0; zz<(*q); zz+=3)
48                                 {
49                                         CHKCOLDBGOUT4
50                                         if(zz%3==0)
51                                         {
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])
53                                                 {
54 //====
55 //====
56                                                         CHKCOLDBGOUT5
57                                                         break;
58                                                 }
59                                                 else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])
60                                                 {
61                                                         CHKCOLDBGOUT6
62                                                         CHKCOLDBGOUT7
63                                                         a[((*z)+(*q))/3]=zz/3;
64                                                         (*aa)=((*z)+(*q))/3;
65                                                         CHKCOLDBGOUT8
66                                                 }
67                                                 /*else
68                                                 {
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");
74                                                 }*/
75                                                 CHKCOLDBGOUT9
76                                         }
77                                 }
78                         }
79                 }
80                 CHKCOLDBGOUT10
81                 //free(pal);
82 }
83
84 void
85 VL_modexPalUpdate(bitmap_t *bmp, word *i, word qp, word aqpp)
86 {
87         byte *p = bmp->palette;
88         word w=0;
89         word q=0;
90         word qq=0;
91         word ii;
92         static word a[256] = { 0 };
93         word z=0,aq=0,aa=0;
94         word pp=0,spee=0,ppee=0;
95         sword aqpw;
96
97 //      if(qp>0) printf("(*i)=%02d\n", (*i));
98         modexWaitBorder();
99         if((*i)==0) outp(PAL_WRITE_REG, 0);  /* start at the beginning of palette */
100         else if(qp==0)
101         {
102                 q=(*i);
103         }
104         else
105         {
106                 q=(*i);
107                 qq=(*i)/3;
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 */
113         }
114         if((*i)<PAL_SIZE && w==0)
115         {
116                 for(; (*i)<PAL_SIZE; (*i)++)
117                 {
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]))
121                         {
122                                 if(qp>0)
123                                 {
124                                         (*i)-=(aqpp*3);
125                                         aqpw=aqpp-1;
126                                         outp(PAL_WRITE_REG, qq+(((*i)+(aqpw*3)-(bmp->offset*3))/3));
127                                         for(ii=aqpp; ii>0; ii--)
128                                         {
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);
145                                         }
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));
150                                 }
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)]);
152                                 w++;
153                                 break;
154                         }
155                         else
156                         {
157                                 if(bmp->offset==0 && (*i)<3 && q==0) outp(PAL_DATA_REG, 0);
158                                 else
159                                 if(qp==0) outp(PAL_DATA_REG, p[(*i)-q]);
160                                 else outp(PAL_DATA_REG, p[((*i)-(bmp->offset*3))]);
161                         }
162                 }
163         }
164
165         //palette checker~
166         if(q>0 && qp==0)
167         {
168                 long lq;
169                 long bufSize = (bmp->width * bmp->height);
170                 chkcolor(bmp, &q, &a, &aa, &z);
171
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);*/
177
178                 aq=0; pp = q; ppee=q;
179 aqpee:
180                 while(aq<=aa)
181                 {
182                         //printf("a[%02d]=(%d)", aq, a[aq]);
183                         if(a[aq]==0) aq++;
184                         else{ aqpp++; break; }
185                 }
186
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);*/
191
192         for(lq=0; lq<bufSize; lq++)
193         {
194                 if(bmp->data[lq]+bmp->offset==aq)
195                 {
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]);
201                         bmp->data[lq]=a[aq];
202                         //printf("_%d \n", bmp->data[lq]);
203                 }
204                 else if(bmp->data[lq]+bmp->offset < (z/3)-aqpp)
205                 {
206                         if(bmp->data[lq]+bmp->offset >= aq) bmp->data[lq]=(bmp->data[lq]+bmp->offset)-aqpp;
207                         else bmp->data[lq]+=(bmp->offset);
208                 }
209
210                 //printf("%02d ", bmp->data[lq]);
211                 //if(lq > 0 && lq%bmp->width==0) printf("\n");
212         }
213
214         while(pp<=(aq*3))
215         {
216                 if(((pp/3)==aq || spee>0))
217                 {
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];
227                         if(spee==0) spee++;
228                 }
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]);*/
233                 pp+=3;
234         }
235
236         //update the palette~
237         //printf("      aqpp=           %d\n", aqpp);
238         VL_modexPalUpdate(bmp, &ppee, 1, aqpp);
239         (*i)=ppee;
240         //printf("      aqpp=   %d\n", aqpp);
241         //printf("      ppee=   %d\n", ppee);
242
243         /*printf(".\n");
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);*/
248
249         if(aq<aa){ /*printf("~~~~\n"); */ppee=q; aq++; goto aqpee; }
250         /*printf("ppee=%d\n", ppee);
251         printf("pp=%d\n", pp);
252         printf("q=%d\n", q);
253         printf("(*i)=%d\n", (*i));*/
254
255         }
256 }