#include #include #include #include static int internal_vrams[3][256]; const void *vrams[4]; static int current = 0; static int delays[2]; #define GRAY_PRESCALER TIMER_Po_64 /* gray_start() Starts the gray engine. The control of the screen is transferred to the gray engine. */ void gray_start(void) { timer_start(TIMER_GRAY, delays[0], GRAY_PRESCALER, gray_interrupt, 0); } /* gray_stop() Stops the gray engine. The monochrome display system takes control of the video ram. */ void gray_stop(void) { timer_stop(TIMER_GRAY); display_useVRAM(display_getLocalVRAM()); } /* gray_lightVRAM() Returns the module's gray vram address. */ void *gray_lightVRAM(void) { return (void *)vrams[current]; } /* gray_lightVRAM() Returns the module's dark vram address. */ void *gray_darkVRAM(void) { return (void *)vrams[current + 1]; } /* gray_getDelays() Returns the gray engine delays. @arg light Will be set if non-NULL. @arg dark Will be set if non-NULL. */ void gray_getDelays(int *light, int *dark) { if(light) *light = delays[0]; if(dark) *dark = delays[1]; } /* gray_setDelays() Changes the gray engine delays. @arg light Light gray duration (the lower). @arg dark Dark gray duration (the higher). */ void gray_setDelays(int light, int dark) { delays[0] = light; delays[1] = dark; } //--- // Internal API. //--- /* gray_swap() Swaps the vram buffers. */ void gray_swap(void) { current = (current + 2) & 3; } /* gray_interrupt() Answers a timer interrupt. Swaps the buffers. */ void gray_interrupt(void) { timer_reload(TIMER_GRAY, delays[current & 1]); screen_display(vrams[current]); current ^= 1; } /* gray_init() Initializes the gray engine. */ void gray_init(void) { vrams[0] = (const void *)display_getLocalVRAM(); vrams[1] = (const void *)internal_vrams[0]; vrams[2] = (const void *)internal_vrams[1]; vrams[3] = (const void *)internal_vrams[2]; delays[0] = 3269; delays[1] = 6987; }