comparison 3x666.c @ 9:84d7bc7dfaeb

More cleanup work.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 15 Mar 2013 06:08:10 +0200
parents bbc901af24fb
children fcae85b39931
comparison
equal deleted inserted replaced
8:bbc901af24fb 9:84d7bc7dfaeb
1 #include <SDL.h>
1 #include <math.h> 2 #include <math.h>
2 #include <stdio.h>
3 #include <stdlib.h> 3 #include <stdlib.h>
4 #include <unistd.h> 4 #include <unistd.h>
5 #include <string.h> 5 #include <string.h>
6 #include "config.h" 6 #include "config.h"
7 #include "3xfont.h" 7 #include "3xfont.h"
8 8
9 /** typedefs **/ 9 /** typedefs **/
10 10
11 typedef struct 11 typedef struct
12 { 12 {
13 signed int x, y, z; 13 int x, y, z;
14 } vec3d; 14 } vec3d;
15 15
16 int TIKLGT; 16 int TIKLGT;
17 17
18 char *ruutu; 18 SDL_Color pal[256];
19 Uint8 *ruutu;
20
19 int *mxbuf; 21 int *mxbuf;
20
21 int *ballz; 22 int *ballz;
22 23
23 /**************** tEXT dRAWiNG rOUTiNES ********** 24 /**************** tEXT dRAWiNG rOUTiNES **********
24 25
25 bitmaps are for lamers :) let's use a little 12-segment calculator font... 26 bitmaps are for lamers :) let's use a little 12-segment calculator font...
43 h += y; 44 h += y;
44 y = 0; 45 y = 0;
45 } 46 }
46 if (w > 0 && h > 0) 47 if (w > 0 && h > 0)
47 { 48 {
48 char *b = ruutu + y * BUFW + x; 49 Uint8 *b = ruutu + y * BUFW + x;
49 for (; h; h--) 50 for (; h; h--)
50 { 51 {
51 memset(b, 122, w); 52 memset(b, 122, w);
52 b += BUFW; 53 b += BUFW;
53 } 54 }
83 y += yunit * 2; 84 y += yunit * 2;
84 c >>= 3; 85 c >>= 3;
85 } 86 }
86 } 87 }
87 88
88 void drawtxtscr(char *z) 89 void drawtxtscr(char *str)
89 { 90 {
90 int x = BUFW >> 4, y = BUFH >> 3; 91 int x = BUFW >> 4, y = BUFH >> 3;
91 while (*z) 92 while (*str)
92 { 93 {
93 if (*z >= 32) 94 if (*str >= 32)
94 { 95 {
95 drawchar(x, y, phont[*z - 32], BUFW / 50, BUFW / 80); 96 drawchar(x, y, phont[*str - 32], BUFW / 50, BUFW / 80);
96 x += BUFW / 10; 97 x += BUFW / 10;
97 } 98 }
98 else 99 else
99 { 100 {
100 x = BUFW >> 4; 101 x = BUFW >> 4;
101 y += BUFW / 10; 102 y += BUFW / 10;
102 } 103 }
103 z++; 104 str++;
104 } 105 }
105 } 106 }
106 107
107 108
108 void flashtxt(char *txt) 109 void flashtxt(char *str)
109 { 110 {
110 int x = (BUFW >> 1) - (strlen(txt) + 1) * 3 * BUFW / 80; 111 int x = (BUFW >> 1) - (strlen(str) + 1) * 3 * BUFW / 80;
111 while (*txt) 112 while (*str)
112 { 113 {
113 drawchar(x, BUFH >> 1, phont[*txt++ - 32], BUFW / 50, BUFW / 80); 114 drawchar(x, BUFH >> 1, phont[*str++ - 32], BUFW / 50, BUFW / 80);
114 x += BUFW / 10; 115 x += BUFW / 10;
115 } 116 }
116 } 117 }
117 118
118 /*************************** DA PHONGBALL HEAVEN ************** 119 /*************************** DA PHONGBALL HEAVEN **************
142 "twisty" but who cares, it just looks damn cool ;) 143 "twisty" but who cares, it just looks damn cool ;)
143 144
144 ***/ 145 ***/
145 146
146 #if (BUFH < BUFW) 147 #if (BUFH < BUFW)
147 # define maxR (BUFH>>1) 148 # define maxR (BUFH >> 1)
148 #else 149 #else
149 # define maxR (BUFW>>1) 150 # define maxR (BUFW >> 1)
150 #endif 151 #endif
151 152
152 struct 153 struct
153 { 154 {
154 int *tab; 155 int *tab;
176 177
177 balltab[49].R = balltab[48].R = balltab[47].R; 178 balltab[49].R = balltab[48].R = balltab[47].R;
178 balltab[49].tab = balltab[48].tab = balltab[47].tab; 179 balltab[49].tab = balltab[48].tab = balltab[47].tab;
179 } 180 }
180 181
181 /** 182
182 The i386 innerloop compiled by gcc sucked a bit so here's another 183 void drawball_inloop(Uint8 *d, int dotxyz, int ddot, int dddot, int x)
183 one. Hope it runs faster :) I tried to optimize it for the 386,
184 maybe 486 (not pentium kos it suxx)
185
186 **/
187
188 inline void drawball_inloop(char *d, int dotxyz, int ddot, int dddot, int x)
189 { 184 {
190 for (; x; x--) 185 for (; x; x--)
191 { 186 {
192 dotxyz += ddot; 187 dotxyz += ddot;
193 ddot += dddot; 188 ddot += dddot;
194 *d++ = dotxyz >> 16; 189 *d++ = dotxyz >> 16;
195 } 190 }
196 } 191 }
197 192
198 void drawball(char *d, vec3d * l, int relR) 193 void drawball(Uint8 *d, vec3d * l, int relR)
199 { 194 {
200 int R = balltab[relR].R, *s = balltab[relR].tab; 195 int R = balltab[relR].R, *s = balltab[relR].tab;
201 196
202 signed int doty = (-(R - 1) * l->y); 197 signed int doty = (-(R - 1) * l->y);
203 signed int y = R * 2 - 2; 198 signed int y = R * 2 - 2;
204 199
205 d += (BUFW >> 1) - R + ((BUFH >> 1) - R) * BUFW; 200 d += (BUFW >> 1) - R + ((BUFH >> 1) - R) * BUFW;
206 201
207 if (y) 202 if (y)
203 {
208 for (; y; y--) 204 for (; y; y--)
209 { 205 {
210 int halfw = *s++; 206 int halfw = *s++;
211 if (halfw) 207 if (halfw)
212 drawball_inloop(d + R - halfw, 208 drawball_inloop(d + R - halfw,
214 (l->x + l->z) << 8, 210 (l->x + l->z) << 8,
215 0 - ((l->z << 8) / halfw), halfw << 1); 211 0 - ((l->z << 8) / halfw), halfw << 1);
216 d += BUFW; 212 d += BUFW;
217 doty += l->y; 213 doty += l->y;
218 } 214 }
215 }
219 } 216 }
220 217
221 /* some extra for freaks: a plasma made with the phongball innerloop :) 218 /* some extra for freaks: a plasma made with the phongball innerloop :)
222 looks ugly. 219 looks ugly.
223 220
236 } 233 }
237 */ 234 */
238 235
239 /************************ oTHA FX ***************/ 236 /************************ oTHA FX ***************/
240 237
241 void rotochess(char *d, int du, int dv, int iu, int iv) 238 void rotochess(Uint8 *d, int du, int dv, int iu, int iv)
242 { 239 {
243 int hu = iu - (dv * (BUFH >> 1)) - (du * (BUFW >> 1)), 240 int hu = iu - (dv * (BUFH >> 1)) - (du * (BUFW >> 1)),
244 hv = iv + (du * (BUFH >> 1)) - (dv * (BUFW >> 1)); 241 hv = iv + (du * (BUFH >> 1)) - (dv * (BUFW >> 1));
245 242
246 int y; 243 int y;
260 } 257 }
261 } 258 }
262 259
263 /***************************************************************/ 260 /***************************************************************/
264 261
265 rgb pal[256], pal2[256]; 262
266 void setpal() 263 void setpal()
267 { 264 {
268 int i, a = 3, b = 0; 265 int i, a = 3, b = 0;
269 for (i = 255; i; i--) 266 for (i = 255; i; i--)
270 { 267 {
271 rgb *d = &pal[(i + 128) & 255]; 268 SDL_Color *d = &pal[(i + 128) & 255];
272 d->r = (abs(i - 140) >> a) & 255; 269 d->r = (abs(i - 140) >> a) & 255;
273 d->g = ((abs(i - 128) >> b) & 255) ^ 1; 270 d->g = ((abs(i - 128) >> b) & 255) ^ 1;
274 d->b = (abs(i - 96) >> b) & 255; 271 d->b = (abs(i - 96) >> b) & 255;
275 if (i == 128) 272 if (i == 128)
276 { 273 {
277 a = 0; 274 a = 0;
278 b = 1; 275 b = 1;
279 } 276 }
280 } 277 }
281 oxl_setpalette(pal); 278 oxl_setpalette(pal);
282 } 279 }
280
283 281
284 void unitvec(vec3d * v, float a, float b, float c, float m) 282 void unitvec(vec3d * v, float a, float b, float c, float m)
285 { 283 {
286 float cam = cos(a) * m, sam = sin(a) * m, sbcam = sin(b) * cam; 284 float cam = cos(a) * m, sam = sin(a) * m, sbcam = sin(b) * cam;
287 285
293 /************************* MUSiC cODE **************************/ 291 /************************* MUSiC cODE **************************/
294 292
295 /* This table was ripped (and reduced and rudely integerized) from the 293 /* This table was ripped (and reduced and rudely integerized) from the
296 Maube tracker by K .. keep on the good work man! ;) */ 294 Maube tracker by K .. keep on the good work man! ;) */
297 295
298 const int noterate[3 * 12] = 296 const Sint16 noterate[3 * 12] =
299 { 297 {
300 1000, 1059, 1122, 1189, 1259, 1334, 298 1000, 1059, 1122, 1189, 1259, 1334,
301 1414, 1498, 1587, 1681, 1781, 1887, 299 1414, 1498, 1587, 1681, 1781, 1887,
302 300
303 2000, 2118, 2244, 2378, 2519, 2669, 301 2000, 2118, 2244, 2378, 2519, 2669,
334 22, 17, 17, 22 332 22, 17, 17, 22
335 }; 333 };
336 334
337 signed int *drum0, *drum1; 335 signed int *drum0, *drum1;
338 336
337
339 /* sampling sucks! */ 338 /* sampling sucks! */
340 void audio_precalcs() 339 void audio_precalcs()
341 { 340 {
342 int drumlgt = TIKLGT * ROWTIX * 4; 341 int drumlgt = TIKLGT * ROWTIX * 4;
343 int *d = drum0 = malloc(drumlgt * sizeof(int)), 342 int *d = drum0 = malloc(drumlgt * sizeof(int)),
367 *e++ = (vol * sin(a + ((float) oo) / 60000)); 366 *e++ = (vol * sin(a + ((float) oo) / 60000));
368 367
369 a += da; 368 a += da;
370 da -= dda; 369 da -= dda;
371 vol -= dvol; 370 vol -= dvol;
372 }} 371 }
372 }
373 373
374 374
375 /* mixes the next row of music into b */ 375 /* mixes the next row of music into b */
376 int *audio_mix(void) 376 int *audio_mix(void)
377 { 377 {
388 388
389 note = basstrak[(rowno >> 1) & 31]; 389 note = basstrak[(rowno >> 1) & 31];
390 390
391 if (!note) 391 if (!note)
392 note = basstrak[((rowno >> 1) & 31) - 1]; 392 note = basstrak[((rowno >> 1) & 31) - 1];
393 else if (rowno & 1) 393 else
394 if (rowno & 1)
394 note = 0; 395 note = 0;
396
395 if ((rowno & 3) == 3) 397 if ((rowno & 3) == 3)
396 note = 0; 398 note = 0;
399
397 if (note) 400 if (note)
398 { 401 {
399 int ps = 16384, dps; 402 int ps = 16384, dps;
400 note += delta; 403 note += delta;
401 dps = ((noterate[note] << 10) / AUFREQ); 404 dps = ((noterate[note] << 10) / AUFREQ);
404 *d++ = ps; 407 *d++ = ps;
405 ps = (ps + dps) & 32767; 408 ps = (ps + dps) & 32767;
406 } 409 }
407 } 410 }
408 else 411 else
412 {
409 for (i = rowlgt; i; i--) 413 for (i = rowlgt; i; i--)
410 *d++ = 16384; 414 *d++ = 16384;
415 }
411 416
412 /* MELODY (sawtooth as well :) */ 417 /* MELODY (sawtooth as well :) */
413 418
414 if (!(silend && ((rowno & 63) > 47))) 419 if (!(silend && ((rowno & 63) > 47)))
415 { 420 {
430 *d++ += ps; 435 *d++ += ps;
431 ps = (ps + dps) & 32767; 436 ps = (ps + dps) & 32767;
432 } 437 }
433 } 438 }
434 } 439 }
440
435 /* DRUMS (rave on!!!) */ 441 /* DRUMS (rave on!!!) */
436
437 { 442 {
438 int *s = drum1; 443 int *s = drum1;
439 d = mxbuf + 1; 444 d = mxbuf + 1;
440 if (rowno & 4) 445 if (rowno & 4)
441 s = drum0; 446 s = drum0;
451 456
452 /* no switch+case? just check out how gcc handles them! 457 /* no switch+case? just check out how gcc handles them!
453 it's 1024+ bytes for every phukken switch statement! 458 it's 1024+ bytes for every phukken switch statement!
454 in this case we can prefer size to speed, can't we? */ 459 in this case we can prefer size to speed, can't we? */
455 460
456 if (!(rowno & 63)) 461 if ((rowno & 63) == 0)
457 { 462 {
458 int r = rowno >> 6; 463 int r = rowno >> 6;
459 if (r == 2) 464 if (r == 2)
460 delta = 0; 465 delta = 0;
461 if (r == 4) 466 if (r == 4)
758 #define TXTSCR 0x0400 763 #define TXTSCR 0x0400
759 #define ENDSCR 0x0800 764 #define ENDSCR 0x0800
760 #define DEMOEND 0x1000 765 #define DEMOEND 0x1000
761 766
762 const short dezign[] = { 767 const short dezign[] = {
763 0, BLACKBG | OCSALOGO | SCROLL0, 768 0 , BLACKBG | OCSALOGO | SCROLL0,
764 256, FLASHBG | BALLIE | BALLJUMPS | COUNTAH, 769 256 , FLASHBG | BALLIE | BALLJUMPS | COUNTAH,
765 384, BLACKBG | BALLIE | BALLJUMPS | COUNTAH | OCSALOGO, 770 384 , BLACKBG | BALLIE | BALLJUMPS | COUNTAH | OCSALOGO,
766 400, BLACKBG | BALLIE | COUNTAH | OCSALOGO, 771 400 , BLACKBG | BALLIE | COUNTAH | OCSALOGO,
767 416, BLACKBG | BALLIE, 772 416 , BLACKBG | BALLIE,
768 448, BLACKBG | BALLIE | TXTSCR, 773 448 , BLACKBG | BALLIE | TXTSCR,
769 512, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, 774 512 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR,
770 576, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, 775 576 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR,
771 640, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, 776 640 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR,
772 704, CHESSBG | BALLIE | BALLJUMPS | TXTSCR, 777 704 , CHESSBG | BALLIE | BALLJUMPS | TXTSCR,
773 768, FLASHBG | FLASHTXT, 778 768 , FLASHBG | FLASHTXT,
774 896, FLASHBG | FLASHTXT | TXTSCR, 779 896 , FLASHBG | FLASHTXT | TXTSCR,
775 962, FLASHBG | FLASHTXT | TXTSCR | BALLIE | BALLJUMPS, 780 962 , FLASHBG | FLASHTXT | TXTSCR | BALLIE | BALLJUMPS,
776 1024, BLACKBG | BALLIE | ENDSCR, 781 1024, BLACKBG | BALLIE | ENDSCR,
777 1152, CHESSBG | BALLIE | BALLJUMPS | ENDSCR, 782 1152, CHESSBG | BALLIE | BALLJUMPS | ENDSCR,
778 1344, FLASHBG | BALLIE | BALLJUMPS | ENDSCR, 783 1344, FLASHBG | BALLIE | BALLJUMPS | ENDSCR,
779 1536, DEMOEND 784 1536, DEMOEND
780 }; 785 };
789 int flagz = 0; 794 int flagz = 0;
790 const short *dez = dezign; 795 const short *dez = dezign;
791 char *phiword = NULL, *dizainword = NULL; 796 char *phiword = NULL, *dizainword = NULL;
792 int flixtim = 0; 797 int flixtim = 0;
793 798
794 ruutu = malloc(BUFH * BUFW * sizeof(char));
795 preball(); 799 preball();
796
797 srand((int) time(NULL)); 800 srand((int) time(NULL));
798 801
799 oxl_init_audio(ROWTIX);
800 TIKLGT = AUFREQ / DEMOHZ; 802 TIKLGT = AUFREQ / DEMOHZ;
801 mxbuf = malloc(MAXROWLGT * sizeof(int)); 803 mxbuf = malloc(MAXROWLGT * sizeof(int));
802 audio_precalcs(); 804 audio_precalcs();
803
804 oxl_init_video();
805 oxl_init_timer();
806 805
807 setpal(); 806 setpal();
808 807
809 for (;;) 808 for (;;)
810 { 809 {
886 drawball(ruutu, &joo, zoom); 885 drawball(ruutu, &joo, zoom);
887 } 886 }
888 887
889 if (flagz & FLASHTXT) 888 if (flagz & FLASHTXT)
890 flashtxt(phiword); 889 flashtxt(phiword);
891 if (flagz & TXTSCR) 890
892 if ((t / ROWTIX) & 2) 891 if ((flagz & TXTSCR) && ((t / ROWTIX) & 2))
893 drawtxtscr(dizainword); 892 drawtxtscr(dizainword);
894 893
895 if (flagz & ENDSCR) 894 if (flagz & ENDSCR)
896 doendscroll(t - 1024 * ROWTIX); 895 doendscroll(t - 1024 * ROWTIX);
897 896
898 if (flagz & COUNTAH) 897 if (flagz & COUNTAH)
916 n /= 10; 915 n /= 10;
917 } 916 }
918 917
919 /* blitzz */ 918 /* blitzz */
920 919
921 oxl_doframe(ruutu); 920 SDL_flip(...);
922 oxl_doaudio(audio_mix); 921
923 while (t == oxl_timer()) 922 SDL_Delay(25);
924 { 923 }
925 usleep(250000 / DEMOHZ); 924
926 } 925 SDL_Quit();
927 } 926 }
928 oxl_end();
929 }