X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fscr%2Fplasma.c;fp=src%2Fscr%2Fplasma.c;h=5caf4f4ad75f4b1e5c62ab4f5d5cf9efe4e2ad73;hb=ba648ddfc62fc6d3f47294aa8bfc10ea6ca3f479;hp=0000000000000000000000000000000000000000;hpb=3398fc6c4188104048f99b650a6cb90beda9b6ed;p=dosdemo diff --git a/src/scr/plasma.c b/src/scr/plasma.c new file mode 100644 index 0000000..5caf4f4 --- /dev/null +++ b/src/scr/plasma.c @@ -0,0 +1,111 @@ +// Just a test with a run of the mill plasma + +#include +#include + +#include "demo.h" +#include "screen.h" + +static int init(void); +static void destroy(void); +static void start(long trans_time); +static void draw(void); + +static struct screen scr = { + "plasma", + init, + destroy, + start, + 0, + draw +}; + +static unsigned long startingTime; + +#define PSIN_SIZE 4096 +#define PPAL_SIZE 256 + +static unsigned char *psin1, *psin2, *psin3; +static unsigned short *plasmaPal; + +static unsigned short myBuffer[320 * 240]; + + +struct screen *plasma_screen(void) +{ + return &scr; +} + +static int init(void) +{ + int i; + + psin1 = (unsigned char*)malloc(sizeof(unsigned char) * PSIN_SIZE); + psin2 = (unsigned char*)malloc(sizeof(unsigned char) * PSIN_SIZE); + psin3 = (unsigned char*)malloc(sizeof(unsigned char) * PSIN_SIZE); + + for (i = 0; i < PSIN_SIZE; i++) + { + psin1[i] = (unsigned char)(sin((double)i / 45.0) * 63.0 + 63.0); + psin2[i] = (unsigned char)(sin((double)i / 75.0) * 42.0 + 42.0); + psin3[i] = (unsigned char)(sin((double)i / 32.0) * 88.0 + 88.0); + } + + plasmaPal = (unsigned short*)malloc(sizeof(unsigned short) * PPAL_SIZE); + for (i=0; i 127) c = 255 - c; + c >>= 2; + g = 31 - c; + r = c; + b = g; + plasmaPal[i] = (r<<11) | (g<<5) | b; + } + + return 0; +} + +static void destroy(void) +{ + free(psin1); + free(psin2); + free(psin3); +} + +static void start(long trans_time) +{ + startingTime = time_msec; +} + +static void draw(void) +{ + int x, y; + unsigned char c; + unsigned char s1, s2; + + float dt = (float)(time_msec - startingTime) / 1000.0f; + int t1 = sin(0.1f * dt) * 132 + 132; + int t2 = sin(0.2f * dt) * 248 + 248; + int t3 = sin(0.5f * dt) * 380 + 380; + + unsigned int *vram32 = (unsigned int*)fb_pixels; + unsigned int p0, p1; + for (y = 0; y < fb_height; y++) + { + s1 = psin2[y + t2]; + s2 = psin3[y + t1]; + for (x = 0; x < fb_width; x+=2) + { + c = psin1[x + t1] + s1 + psin3[x + y + t3] + psin1[psin2[x + t2] + s2 + t3]; + p0 = plasmaPal[c]; + c = psin1[x + 1 + t1] + s1 + psin3[x + 1 + y + t3] + psin1[psin2[x + 1 + t2] + s2 + t3]; + p1 = plasmaPal[c]; + + *vram32++ = (p1 << 16) | p0; + } + } + + swap_buffers(0); +}