/************************************************************************* * * Copyright 2008+ Mobile 1UP * All rights reserved. * *************************************************************************/ /* * @(#)application-state-plasma.inc */ /************************************************************************* * Structures *************************************************************************/ typedef struct PlasmaRunTime { color palette[256]; uint8 *canvas; int8 costable[256]; struct { uint8 a1,a2,a3,a4, b1,b2,b3,b4; } index; } PlasmaRunTime; typedef struct PlasmaExtension { PlasmaRunTime *rt; } PlasmaExtension; /************************************************************************* * Globals + Preferences *************************************************************************/ #define GLOBALS_PLASMA_DEFINE GLOBALS_ACCESS; \ PlasmaExtension *g_plasma #define GLOBALS_PLASMA_ACCESS GLOBALS_ACCESS; \ PlasmaExtension *g_plasma = globals -> pExt[STATE_PLASMA] //------------------------------------------------------------------------ // --== GLOBALS ARE FORBIDDEN! ==-- // // DAL may support the use of globals on some platforms, however, its not // guaranteed that all the destination platforms allow the use of globals // (variable or static data). use the GlobalsType structure as shown. //------------------------------------------------------------------------ /************************************************************************* * Platform Independent Implementation *************************************************************************/ boolean ApplicationStatePlasmaInitialize() { boolean result; GLOBALS_PLASMA_DEFINE; // default return value result = false; // entry requirements if (globals == NULL) goto ApplicationStatePlasmaInitialize_DONE; g_plasma = (PlasmaExtension *)_MemPtrNew(sizeof(PlasmaExtension), false); if (g_plasma != NULL) { globals -> pExt[STATE_PLASMA] = (void *)g_plasma; result = true; } ApplicationStatePlasmaInitialize_DONE:; return result; } boolean ApplicationStatePlasmaInit() { boolean result; uint16 w, h; color *p; int16 i; int8 *_p; uint32 size; GLOBALS_PLASMA_ACCESS; // default return value result = false; // entry requirements if (g_plasma == NULL) goto ApplicationStatePlasmaInit_DONE; // allocate the runtime g_plasma -> rt = _MemPtrNew(sizeof(PlasmaRunTime), false); if (g_plasma -> rt == NULL) goto ApplicationStatePlasmaInit_DONE; // initialize the palette p = g_plasma -> rt -> palette; // blue - through white - red palete *p++ = _FBGetPaletteIndex(0,0,0); for (i=1; i<=32; i++) *p++ = _FBGetPaletteIndex(0x00, 0x00, (i<<3)-1); for (i=1; i<=32; i++) *p++ = _FBGetPaletteIndex((i<<3)-1, 0x00, 0xff); for (i=1; i<=32; i++) *p++ = _FBGetPaletteIndex(0xff, (i<<3)-1, 0xff); for (i=1; i<=64; i++) *p++ = _FBGetPaletteIndex(0xff, 0xff, 0xff); for (i=1; i<=32; i++) *p++ = _FBGetPaletteIndex(0xff, 0xff, 0xff-((i<<3)-1)); for (i=1; i<=32; i++) *p++ = _FBGetPaletteIndex(0xff, 0xff-((i<<3)-1), 0x00); for (i=1; i< 32; i++) *p++ = _FBGetPaletteIndex(0xff-((i<<3)-1), 0x00, 0x00); // initialize the cosine table _p = g_plasma -> rt -> costable; for (i=0; i<256; i++) *_p++ = (int8)fxtoi(mul_f(itofx(32), _cos((360 * i) >> 8))); // get a pointer to the display _FBGetProperties(NULL, &w, &h, NULL); // allocate memory for plasma canvas size = w * h * sizeof(uint8); g_plasma -> rt -> canvas = (uint8 *)_MemPtrNew(size, false); if (g_plasma -> rt -> canvas == NULL) goto ApplicationStatePlasmaInit_DONE; // we have an empty display right now _MemSet(g_plasma -> rt -> canvas, 0, size); // configuration successful result = true; ApplicationStatePlasmaInit_DONE:; return result; } boolean ApplicationStatePlasmaHandleEvent(event *e) { boolean result; uint16 *bits, w, h, rb; uint16 *dst; uint8 *v; int i, j; uint8 a1,a2,a3,a4, b1,b2,b3,b4; GLOBALS_PLASMA_ACCESS; // default return value result = false; // entry requirements if ((g_plasma == NULL) || (g_plasma -> rt == NULL)) goto ApplicationStatePlasmaHandleEvent_DONE; switch (e -> eType) { case _nilEvent: // get a pointer to the display _FBGetProperties((void **)&bits, &w, &h, &rb); // use previous values a1 = g_plasma -> rt -> index.a1; a2 = g_plasma -> rt -> index.a2; a3 = g_plasma -> rt -> index.a3; a4 = g_plasma -> rt -> index.a4; b1 = g_plasma -> rt -> index.b1; b2 = g_plasma -> rt -> index.b2; b3 = g_plasma -> rt -> index.b3; b4 = g_plasma -> rt -> index.b4; // lets generate the plasma a1 = b1; a2 = b2; v = g_plasma -> rt -> canvas; for (j=0; j rt -> costable[a1] + g_plasma -> rt -> costable[a2] + g_plasma -> rt -> costable[a3] + g_plasma -> rt -> costable[a4]; a3 += 1; a4 += 2; } a1 += 2; a2 += 1; } b1 += 1; b2 -= 2; b3 -= 1; b4 += 3; // save values g_plasma -> rt -> index.a1 = a1; g_plasma -> rt -> index.a2 = a2; g_plasma -> rt -> index.a3 = a3; g_plasma -> rt -> index.a4 = a4; g_plasma -> rt -> index.b1 = b1; g_plasma -> rt -> index.b2 = b2; g_plasma -> rt -> index.b3 = b3; g_plasma -> rt -> index.b4 = b4; // lets map out indexed color to the display dst = bits; v = g_plasma -> rt -> canvas; for (j=0; j rt -> palette[*v++]; dst += (rb >> 1) - w; } // the screen must be repainted globals -> dirty = true; result = true; break; default: break; } ApplicationStatePlasmaHandleEvent_DONE:; return result; } void ApplicationStatePlasmaQuit() { GLOBALS_PLASMA_ACCESS; // entry requirements if (g_plasma == NULL) goto ApplicationStatePlasmaQuit_DONE; // release memory used by canvas if (g_plasma -> rt -> canvas != NULL) _MemPtrFree(g_plasma -> rt -> canvas); g_plasma -> rt -> canvas = NULL; if (g_plasma -> rt != NULL) _MemPtrFree(g_plasma -> rt); g_plasma -> rt = NULL; ApplicationStatePlasmaQuit_DONE:; } void ApplicationStatePlasmaTerminate() { GLOBALS_PLASMA_ACCESS; // entry requirements if (globals == NULL) goto ApplicationStatePlasmaTerminate_DONE; if (g_plasma != NULL) _MemPtrFree(g_plasma); globals -> pExt[STATE_PLASMA] = (void *)NULL; ApplicationStatePlasmaTerminate_DONE:; } #undef GLOBALS_PLASMA_DEFINE #undef GLOBALS_PLASMA_ACCESS /********************************* EOF ***********************************/