]> 4ch.mooo.com Git - 16.git/blob - src/lib/bakapee.c
wwww major changes in the repo and i did some house keeping in the repo ^^ and i...
[16.git] / src / lib / bakapee.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
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 publiSCREEN_HEIGHTed 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 SCREEN_HEIGHTould 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/bakapee.h"
24
25 /////////////////////////////////////////////////////////////////////////////
26 //                                                                         //
27 // setvideo() - This function Manages the video modes                                     //
28 //                                                                         //
29 /////////////////////////////////////////////////////////////////////////////
30 void setVGAmodeX(global_game_variables_t *vid, boolean vq)
31 {
32         union REGS in, out;
33
34         if(!vq)
35         { // deinit the video
36                 // change to the video mode we were in before we switched to mode 13h
37                 modexLeave();
38                 in.h.ah = 0x00;
39                 in.h.al = vid->old_mode;
40                 int86(0x10, &in, &out);
41
42         }else if(vq==1){ // init the video
43                 // get old video mode
44                 in.h.ah = 0xf;
45                 int86(0x10, &in, &out);
46                 vid->old_mode = out.h.al;
47                 // enter mode
48                 modexEnter();
49         }
50 }
51
52 void pdump(page_t *pee)
53 {
54         int mult=(QUADWH);
55         int palq=(mult)*TILEWH;
56         int palcol=0;
57         int palx, paly;
58         for(paly=0; paly<palq; paly+=mult){
59                 for(palx=0; palx<palq; palx+=mult){
60                                 modexClearRegion(pee, palx+TILEWH, paly+TILEWH, mult, mult, palcol);
61                         palcol++;
62                 }
63         }
64 }
65
66 /////////////////////////////////////////////////////////////////////////////
67 //                                                                                                                                               //
68 // cls() - This clears the screen to the specified color, on the VGA or on //
69 //               the Virtual screen.                                                                                     //
70 //                                                                                                                                               //
71 /////////////////////////////////////////////////////////////////////////////
72 void cls(page_t *page, byte color, byte *Where)
73 {
74         //modexClearRegion(page, 0, 0, page->width, page->height, color);
75         _fmemset(Where, color, page->width*(page->height*2));
76 }
77
78 //color \82Ä\82·\82Æ
79 void colortest(page_t *page, bakapee_t *pee)
80 {
81         if(pee->gq < 256)
82         {
83                 cls(page, pee->gq, VGA);
84                 pee->gq++;
85         }else pee->gq = 0;
86 }
87
88 //color \82Ä\82·\82Æ
89 void colorz(page_t *page, bakapee_t *pee)
90 {
91         if(pee->gq <= HGQ)
92         {
93                 cls(page, pee->gq, VGA);
94                 pee->gq++;
95         }else pee->gq = LGQ;
96 }
97
98 //slow spectrum down
99 void ssd(page_t *page, bakapee_t *pee, word svq)
100 {
101         if(pee->sy < SCREEN_HEIGHT+1)
102         {
103                 if(pee->sx < SCREEN_WIDTH+1)
104                 {
105                         //mxPutPixel(sx, sy, coor);
106                         printf("%d %d %d %d\n", pee->sx, pee->sy, svq, pee->coor);
107                         pee->sx++;
108                 }else pee->sx = 0;
109                 if(pee->sx == SCREEN_WIDTH)
110                 {
111                         pee->sy++;
112                         if(svq == 7) pee->coor++;
113                         if(pee->sy == SCREEN_HEIGHT && svq == 8) pee->coor = rand()%256;
114                 }
115         }else pee->sy = 0;
116 }
117
118 void dingpp(page_t *page, bakapee_t *pee)
119 {
120 #ifdef TILE
121         modexClearRegion(page, pee->xx, pee->yy, TILEWH, TILEWH, pee->coor);
122 #else
123         modexputPixel(page, pee->xx, pee->yy, pee->coor);
124 #endif
125 }
126
127 void dingo(bakapee_t *pee)
128 {
129         #ifdef TILE
130         if(pee->xx<0) pee->xx=(SCREEN_WIDTH-TILEWH);
131         if(pee->yy<0) pee->yy=(SCREEN_HEIGHT-TILEWH);
132         if(pee->xx>(SCREEN_WIDTH-TILEWH)) pee->xx=0;
133         if(pee->yy>(SCREEN_HEIGHT-TILEWH)/*+(TILEWH*BUFFMX)*/) pee->yy=0;
134         #else
135         if(pee->xx<0) pee->xx=SCREEN_WIDTH;
136         if(pee->yy<0) pee->yy=SCREEN_HEIGHT;
137         if(pee->xx>SCREEN_WIDTH) pee->xx=0;
138         if(pee->yy>SCREEN_HEIGHT) pee->yy=0;
139         #endif
140 }
141
142 void dingas(bakapee_t *pee)
143 {
144         if(pee->gq == BONK) dingu(pee);
145         if(!pee->bakax)
146         {
147                 #ifdef TILE
148                 pee->xx-=TILEWH;
149                 #else
150                 pee->xx--;
151                 #endif
152         }
153         else if(pee->bakax>1)
154         {
155                 #ifdef TILE
156                 pee->xx+=TILEWH;
157                 #else
158                 pee->xx++;
159                 #endif
160         }
161         if(!pee->bakay)
162         {
163                 #ifdef TILE
164                 pee->yy-=TILEWH;
165                 #else
166                 pee->yy--;
167                 #endif
168         }
169         else if(pee->bakay>1)
170         {
171                 #ifdef TILE
172                 pee->yy+=TILEWH;
173                 #else
174                 pee->yy++;
175                 #endif
176         }
177 }
178
179 void dingu(bakapee_t *pee)
180 {
181         if(pee->coor < HGQ && pee->coor < LGQ) pee->coor = LGQ;
182         if(pee->coor < HGQ)
183         {
184                 pee->coor++;
185         }else{ pee->coor = LGQ;
186                 pee->bakax = rand()%3; pee->bakay = rand()%3;
187         }
188 }
189
190 /*-----------ding-------------*/
191 void ding(page_t *page, bakapee_t *pee, word q)
192 {
193         word d3y, tx=0,ty=0;
194
195 //++++  if(q <= 4 && q!=2 && gq == BONK-1) coor = rand()%HGQ;
196         switch(q)
197         {
198                 case 1:
199                         if(pee->gq<BONK)
200                         {
201                                 if(pee->xx==SCREEN_WIDTH){pee->bakax=0;}
202                                 if(pee->xx==0){pee->bakax=1;}
203                                 if(pee->yy==SCREEN_HEIGHT){pee->bakay=0;}
204                                 if(pee->yy==0){pee->bakay=1;}
205                                 pee->gq++;
206                         }else pee->gq = LGQ;
207                 break;
208                 case 2:
209                         if(pee->gq<BONK)
210                         {
211                                 dingas(pee);
212                                 dingo(pee);
213                                 dingpp(page, pee);      //plot the pixel/tile
214 #ifdef TILE
215                                 modexClearRegion(page, (rand()*TILEWH)%SCREEN_WIDTH, (rand()*TILEWH)%(SCREEN_HEIGHT), TILEWH, TILEWH, 0);
216 #else
217                                 modexputPixel(page, rand()%SCREEN_WIDTH, rand()%(SCREEN_HEIGHT), 0);
218 #endif
219                                 pee->bakax = rand()%3; pee->bakay = rand()%3;
220                                 pee->gq++;
221                         }else pee->gq = LGQ;
222                 break;
223                 case 3:
224                         if(pee->gq<BONK)
225                         {
226                                 if(pee->xx!=SCREEN_WIDTH||pee->yy!=SCREEN_HEIGHT)
227                                 {
228                                         if(pee->xx==0){pee->bakax=1;pee->bakay=-1;d3y=1;}
229                                         if(pee->yy==0){pee->bakax=1;pee->bakay=0;d3y=1;}
230                                         if(pee->xx==SCREEN_WIDTH){pee->bakax=-1;pee->bakay=-1;d3y=1;}
231                                         if(pee->yy==SCREEN_HEIGHT){pee->bakax=1;pee->bakay=0;d3y=1;}
232                                 }else if(pee->xx==SCREEN_WIDTH&&pee->yy==SCREEN_HEIGHT) pee->xx=pee->yy=0;
233                                 if(d3y)
234                                 {
235                                         if(pee->bakay<0)
236                                         {
237                                                 pee->yy--;
238                                                 d3y--;
239                                         }else
240                                         if(pee->bakay>0)
241                                         {
242                                                 pee->yy++;
243                                                 d3y--;
244                                         }
245                                 }
246                                 if(pee->bakax<0)
247                                 {
248                                         pee->xx--;
249                                 }else
250                                 if(pee->bakax>0)
251                                 {
252                                         pee->xx++;
253                                 }
254                                 pee->gq++;
255                         }else pee->gq = LGQ;
256                 break;
257                 case 4:
258                         if(pee->gq<BONK)
259                         {
260                                 dingas(pee);
261                                 dingo(pee);
262                                 dingpp(page, pee);      //plot the pixel/tile
263                                 pee->bakax = rand()%3; pee->bakay = rand()%3;
264                                 pee->gq++;
265                         }else pee->gq = LGQ;
266                 break;
267                 case 5:
268                         colortest(page, pee);
269                 break;
270                 case 6:
271                         pee->coor = rand()%256;
272                         cls(page, pee->coor, VGA);
273                 break;
274                 case 7:
275                         if(pee->gq <= HGQ)
276                         {
277                                 ssd(page, pee, q);
278                                 pee->gq++;
279                         }else pee->gq = LGQ;
280                 break;
281                 case 8:
282                         colorz(page, pee);
283                         modexprint(page, SCREEN_WIDTH/2, SCREEN_HEIGHT/2, 1, 47, 0, "bakapi");
284                 break;
285                 case 9:
286                         if(pee->gq <= HGQ)
287                         {
288                                 ssd(page, pee, q); pee->coor++;
289                                 pee->gq++;
290                         }else pee->gq = LGQ;
291                 break;
292                 case 10:
293                         ssd(page, pee, q); /*printf("%d\n", pee->coor);*/
294                 break;
295                 case 11:
296                         colorz(page, pee); delay(100);
297                 break;
298
299                 case 16:        //interesting effects
300                         if(pee->gq<BONK)
301                         {
302                                 if(!pee->bakax){ pee->xx--;}
303                                 else if(pee->bakax>0){ pee->xx++; }
304                                 if(!pee->bakay){ pee->yy--;}
305                                 else if(pee->bakay>0){ pee->yy++; }
306                                 dingas(pee);
307                                 tx+=pee->xx+TILEWH+4;
308                                 ty+=pee->yy+TILEWH+4;
309                                 modexClearRegion(page, tx, ty, 4, 4, pee->coor);
310 #ifdef TILE
311                                 modexClearRegion(page, (rand()*TILEWH)%SCREEN_WIDTH, (rand()*TILEWH)%(SCREEN_HEIGHT), TILEWH, TILEWH, 0);
312 #else
313                                 modexputPixel(page, rand()%SCREEN_WIDTH, rand()%(SCREEN_HEIGHT), 0);
314 #endif
315                                 pee->bakax = rand()%3; pee->bakay = rand()%3;
316                                 //printf("%d %d %d %d %d %d\n", pee->xx, pee->yy, tx, ty, TILEWH);
317                                 pee->gq++;
318                         }else pee->gq = LGQ;
319                 break;
320                 case 0:
321                 return;
322                 break;
323                 default:
324                 return;
325                 break;
326         }
327 }