1 /*
2 * This file is released under the GNU General Public Licence
3 *
4 * authors:
5 * Richard Ashbury <richard.asbury@btinternet.com>
6 * Jean-Christophe Hoelt <jeko@ios-software.com>
7 */
8
9 #include "corona32.h"
10 #include "corona.h"
11 #include "corona_palette.h"
12
13 #include <stdlib.h>
14 #include <sys/time.h>
15 #include <time.h>
16
17 #define WIDTH 400
18 #define HEIGHT 300
19
20 static const int PALETTEDATA[][NB_PALETTES] = {
21 #include "corona_pal.h"
22 };
23
24 /* Private members */
25
26 struct _Corona32
27 {
28 Corona *corona;
29 PaletteCycler *pal;
30 TimedLevel tl;
31 int width;
32 int height;
33 };
34
35 /* Private methods */
36
corona32_init_internals(Corona32 * _this)37 void corona32_init_internals(Corona32 *_this)
38 {
39 _this->corona = new Corona();
40 _this->pal = new PaletteCycler(PALETTEDATA, NB_PALETTES);
41 _this->tl.timeStamp = 0;
42 _this->tl.lastbeat = 0;
43 _this->tl.state = normal_state;
44 _this->width = 0;
45 _this->height = 0;
46 }
47
corona32_free_internals(Corona32 * _this)48 void corona32_free_internals(Corona32 *_this)
49 {
50 delete _this->corona;
51 delete _this->pal;
52 }
53
54 /* Public methods */
55
corona32_new(void)56 Corona32 *corona32_new(void)
57 {
58 Corona32 *_this = (Corona32*)calloc(1, sizeof(Corona32));
59 corona32_init_internals(_this);
60 return _this;
61 }
62
corona32_delete(Corona32 * _this)63 void corona32_delete(Corona32 *_this)
64 {
65 corona32_free_internals(_this);
66 free(_this);
67 }
68
corona32_resize(Corona32 * _this,int width,int height)69 void corona32_resize(Corona32 *_this, int width, int height)
70 {
71 if (_this->width != 0) {
72 corona32_free_internals(_this);
73 corona32_init_internals(_this);
74 }
75 _this->corona->setUpSurface(width, height);
76 _this->width = width;
77 _this->height = height;
78 }
79
corona32_update(Corona32 * _this,int timeInMilli,short frequency[2][512])80 void corona32_update(Corona32 *_this, int timeInMilli, short frequency[2][512])
81 {
82 _this->tl.timeStamp ++;
83 for (int i=0; i<512; ++i)
84 {
85 _this->tl.frequency[0][i] = frequency[0][i];
86 _this->tl.frequency[1][i] = frequency[1][i];
87 }
88 _this->corona->update(&_this->tl); // Update Corona
89 _this->pal->update(&_this->tl); // Update Palette Cycler
90 }
91
corona32_displayRGBA(Corona32 * _this,int * screen)92 void corona32_displayRGBA(Corona32 *_this, int *screen)
93 {
94 int hwPal[256];
95 paletteToRGBA(hwPal, _this->pal->getPalette());
96 blitSurface8To32(_this->corona->getSurface(), screen, hwPal, _this->width * _this->height);
97 }
98
99