3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
19 /***********************************************************************************/
21 struct IntuitionBase
*IntuitionBase
;
22 struct GfxBase
*GfxBase
;
23 struct Library
*CyberGfxBase
;
28 ULONG cgfx_coltab
[256];
29 UBYTE remaptable
[256];
32 WORD winx
= -1, winy
= -1;
33 BOOL forcescreen
, forcewindow
;
34 BOOL mustremap
, truecolor
, remapped
, wbscreen
= TRUE
;
36 /***********************************************************************************/
38 #define RANDOM ((WORD)(rand() & 0xFFFF))
42 #define PARTICLES 4096
53 #define xspeed counter
56 static UBYTE chunkybufferarray
[W
* (H
+ 2)];
57 static UBYTE
*chunkybuffer
= &chunkybufferarray
[W
];
59 static UBYTE chunkybuffer_remapped
[W
* H
];
61 struct Particle particles
[PARTICLES
];
63 /***********************************************************************************/
65 static void refresh(void)
69 WriteLUTPixelArray(chunkybuffer
,
84 UBYTE
*src
= chunkybuffer
;
85 UBYTE
*dest
= chunkybuffer_remapped
;
87 for(i
= 0; i
< W
* H
; i
++)
89 *dest
++ = remaptable
[*src
++];
94 win
->BorderLeft
+ W
- 1,
95 win
->BorderTop
+ H
- 1,
96 chunkybuffer_remapped
,
101 WriteChunkyPixels(rp
,
104 win
->BorderLeft
+ W
- 1,
105 win
->BorderTop
+ H
- 1,
111 /***********************************************************************************/
113 static void initpalette(void)
115 static UBYTE pal
[256*3];
122 for(ecx
= 1024; ecx
; ecx
--)
124 eax
= (eax
>> 8) | (eax
& 0xFF) << 24;
125 if ((eax
& 255) >= 63)
127 eax
&= ~0xFF; eax
|= 63;
128 temp
= ((eax
& 0xFF00) + 0x400) & 0xFF00;
129 eax
&= ~0xFF00; eax
|= temp
;
134 pal
[palindex
++] = (UBYTE
)eax
;
138 for(palindex
= 0; palindex
< 256; palindex
++)
140 ULONG red
= pal
[palindex
*3] * 4;
141 ULONG green
= pal
[palindex
*3+1] * 4;
142 ULONG blue
= pal
[palindex
*3+2] * 4;
146 cgfx_coltab
[palindex
] = (red
<< 16) + (green
<< 8) + blue
;
154 remaptable
[palindex
] = ObtainBestPen(scr
->ViewPort
.ColorMap
,
158 OBP_Precision
, PRECISION_IMAGE
,
159 OBP_FailIfBad
, FALSE
,
170 SetRGB32(&scr
->ViewPort
, palindex
, red
, green
, blue
);
176 /***********************************************************************************/
178 static void ticker(void)
182 static ULONG si
= 0x100;
196 for(ecx
= 256; ecx
; ecx
--)
205 ebx
= (ebx
+ 1) & (PARTICLES
- 1);
207 p
->speed
= RANDOM
>> 6;
210 //f= (float)(*(ULONG *)(&p->speed));
211 f
= (float)((ULONG
)p
->speed
+ (ULONG
)p
->counter
* 65536);
215 xspeed
= sin(f
) * p
->speed
;
216 yspeed
= cos(f
) * p
->speed
;
220 p
->particlecolor
= 58;
221 p
->yspeed
= ((UWORD
)yspeed
) * 2;
227 /* Draw/move all particles */
229 for(ecx
= PARTICLES
; ecx
; ecx
--)
231 struct Particle
*p
= &particles
[si
];
235 p
->ypos
+= p
->yspeed
; p
->yspeed
-= (p
->yspeed
/ 16);
236 p
->xpos
+= p
->xspeed
; p
->xspeed
-= (p
->xspeed
/ 16);
241 if ((yp
>= -99) && (yp
<= 99) && (xp
>= -159) && (xp
<= 159))
243 ULONG dest
= (yp
+ 100) * W
+ xp
+ 160;
245 UBYTE col
= p
->particlecolor
--;
247 if (col
> chunkybuffer
[dest
])
249 chunkybuffer
[dest
] = col
;
253 si
= (si
+ 1) & (PARTICLES
- 1);
258 for(ecx
= 0; ecx
< W
* H
; ecx
++)
260 UBYTE col
= chunkybuffer
[ecx
];
262 col
+= chunkybuffer
[ecx
+ 1];
264 col
+= chunkybuffer
[ecx
- W
];
265 col
+= chunkybuffer
[ecx
+ W
];
268 if ((col
> 0) && (tick
& 1))
273 chunkybuffer
[ecx
] = col
;
277 /***********************************************************************************/
279 static void cleanup(char *msg
)
283 printf("Firework: %s\n",msg
);
286 if (win
) CloseWindow(win
);
292 for(i
= 0; i
< 256; i
++)
294 ReleasePen(scr
->ViewPort
.ColorMap
, remaptable
[i
]);
301 UnlockPubScreen(0, scr
);
306 if (CyberGfxBase
) CloseLibrary(CyberGfxBase
);
307 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
308 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
313 /***********************************************************************************/
315 #define ARG_TEMPLATE "WINPOSX=X/N/K,WINPOSY=Y/N/K,FORCESCREEN=SCR/S,FORCEWINDOW=WIN/S"
322 static IPTR args
[NUM_ARGS
];
324 static void getarguments(void)
326 struct RDArgs
*myargs
;
328 if ((myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
332 else if (args
[ARG_WIN
])
335 if (args
[ARG_X
]) winx
= *(IPTR
*)args
[ARG_X
];
336 if (args
[ARG_Y
]) winy
= *(IPTR
*)args
[ARG_Y
];
342 /***********************************************************************************/
344 static void openlibs(void)
346 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
348 cleanup("Can't open intuition.library V39!");
351 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
353 cleanup("Can't open graphics.library V39!");
356 if (!(CyberGfxBase
= OpenLibrary("cybergraphics.library",0)))
358 cleanup("Can't open cybergraphics.library!");
362 /***********************************************************************************/
364 static void getvisual(void)
366 if (!(scr
= LockPubScreen(NULL
)))
368 cleanup("Can't lock pub screen!");
371 if (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) <= 8)
383 if (forcescreen
) wbscreen
= FALSE
;
387 UnlockPubScreen(NULL
, scr
);
390 scr
= OpenScreenTags(NULL
, SA_Width
, W
,
395 if (!scr
) cleanup("Can't open screen!");
398 truecolor
= (GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15) ? TRUE
: FALSE
;
401 /***********************************************************************************/
403 static void makewin(void)
405 struct TagItem winonwbtags
[] =
408 {WA_DepthGadget
, TRUE
},
409 {WA_CloseGadget
, TRUE
},
410 {WA_Title
, (IPTR
)"Firework" },
414 struct TagItem winonscrtags
[] =
416 {WA_Borderless
, TRUE
},
420 if (winx
== -1) winx
= (scr
->Width
- W
- scr
->WBorLeft
- scr
->WBorRight
) / 2;
421 if (winy
== -1) winy
= (scr
->Height
- H
- scr
->WBorTop
- scr
->WBorTop
- scr
->Font
->ta_YSize
- 1) / 2;
423 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
430 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_RAWKEY
,
431 TAG_MORE
, wbscreen
? winonwbtags
: winonscrtags
);
433 if (!win
) cleanup("Can't open window");
438 /***********************************************************************************/
441 #define KC_RIGHT 0x4E
446 /***********************************************************************************/
448 static void getevents(void)
450 struct IntuiMessage
*msg
;
452 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
456 case IDCMP_CLOSEWINDOW
:
462 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
463 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
467 ReplyMsg((struct Message
*)msg
);
472 /***********************************************************************************/
474 static void action(void)
478 while (!Keys
[KC_ESC
])
488 /***********************************************************************************/
502 /***********************************************************************************/