2016-07-04 18:30:25 +02:00
|
|
|
//---
|
|
|
|
//
|
|
|
|
// gint core/drawing module: gray
|
|
|
|
//
|
|
|
|
// Runs the gray engine and handles drawing for the dual-buffer system.
|
|
|
|
//
|
|
|
|
//---
|
|
|
|
|
2016-05-05 11:49:05 +02:00
|
|
|
#include <gray.h>
|
|
|
|
#include <screen.h>
|
2016-05-20 22:04:15 +02:00
|
|
|
#include <timer.h>
|
2016-05-05 11:49:05 +02:00
|
|
|
|
|
|
|
static int internal_vrams[3][256];
|
|
|
|
const void *vrams[4];
|
|
|
|
|
|
|
|
static int current = 0;
|
2016-05-20 22:04:15 +02:00
|
|
|
static int delays[2];
|
|
|
|
|
2016-07-04 18:30:25 +02:00
|
|
|
static int runs = 0;
|
|
|
|
|
2016-05-20 22:04:15 +02:00
|
|
|
#define GRAY_PRESCALER TIMER_Po_64
|
2016-05-05 11:49:05 +02:00
|
|
|
|
2016-07-04 18:30:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Engine control.
|
|
|
|
//---
|
|
|
|
|
2016-05-05 11:49:05 +02:00
|
|
|
/*
|
|
|
|
gray_start()
|
|
|
|
Starts the gray engine. The control of the screen is transferred to the
|
|
|
|
gray engine.
|
|
|
|
*/
|
|
|
|
void gray_start(void)
|
|
|
|
{
|
2016-05-20 22:04:15 +02:00
|
|
|
timer_start(TIMER_GRAY, delays[0], GRAY_PRESCALER, gray_interrupt, 0);
|
2016-07-04 18:30:25 +02:00
|
|
|
runs = 1;
|
2016-05-05 11:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
gray_stop()
|
|
|
|
Stops the gray engine. The monochrome display system takes control of
|
|
|
|
the video ram.
|
|
|
|
*/
|
|
|
|
void gray_stop(void)
|
|
|
|
{
|
2016-05-20 22:04:15 +02:00
|
|
|
timer_stop(TIMER_GRAY);
|
2016-07-04 18:30:25 +02:00
|
|
|
runs = 0;
|
|
|
|
|
2016-05-05 11:49:05 +02:00
|
|
|
display_useVRAM(display_getLocalVRAM());
|
|
|
|
}
|
|
|
|
|
2016-07-06 11:28:51 +02:00
|
|
|
/*
|
|
|
|
gray_setDelays()
|
|
|
|
Changes the gray engine delays.
|
|
|
|
*/
|
|
|
|
void gray_setDelays(int light, int dark)
|
|
|
|
{
|
|
|
|
delays[0] = light;
|
|
|
|
delays[1] = dark;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Engine information.
|
|
|
|
//---
|
|
|
|
|
|
|
|
/*
|
|
|
|
gray_runs()
|
|
|
|
Returns 1 if the gray engine is running, 0 otherwise.
|
|
|
|
*/
|
|
|
|
inline int gray_runs(void)
|
|
|
|
{
|
|
|
|
return runs;
|
|
|
|
}
|
|
|
|
|
2016-05-05 11:49:05 +02:00
|
|
|
/*
|
|
|
|
gray_lightVRAM()
|
|
|
|
Returns the module's gray vram address.
|
|
|
|
*/
|
2016-07-04 18:30:25 +02:00
|
|
|
inline void *gray_lightVRAM(void)
|
2016-05-05 11:49:05 +02:00
|
|
|
{
|
2016-07-04 18:30:25 +02:00
|
|
|
return (void *)vrams[current & 2];
|
2016-05-05 11:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
gray_lightVRAM()
|
|
|
|
Returns the module's dark vram address.
|
|
|
|
*/
|
2016-07-04 18:30:25 +02:00
|
|
|
inline void *gray_darkVRAM(void)
|
2016-05-05 11:49:05 +02:00
|
|
|
{
|
2016-07-04 18:30:25 +02:00
|
|
|
return (void *)vrams[(current & 2) | 1];
|
2016-05-05 11:49:05 +02:00
|
|
|
}
|
|
|
|
|
2016-05-20 22:04:15 +02:00
|
|
|
/*
|
|
|
|
gray_getDelays()
|
2016-07-04 18:30:25 +02:00
|
|
|
Returns the gray engine delays. Pointers are not set if NULL.
|
2016-05-20 22:04:15 +02:00
|
|
|
*/
|
|
|
|
void gray_getDelays(int *light, int *dark)
|
|
|
|
{
|
|
|
|
if(light) *light = delays[0];
|
|
|
|
if(dark) *dark = delays[1];
|
|
|
|
}
|
|
|
|
|
2016-07-06 11:28:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
// Drawing.
|
|
|
|
//---
|
|
|
|
|
2016-05-20 22:04:15 +02:00
|
|
|
/*
|
2016-07-06 11:28:51 +02:00
|
|
|
gupdate()
|
|
|
|
Swaps the vram buffer sets.
|
2016-05-20 22:04:15 +02:00
|
|
|
*/
|
2016-07-06 11:28:51 +02:00
|
|
|
inline void gupdate(void)
|
2016-05-20 22:04:15 +02:00
|
|
|
{
|
2016-07-06 11:28:51 +02:00
|
|
|
current ^= 2;
|
2016-05-20 22:04:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---
|
2016-07-06 11:28:51 +02:00
|
|
|
// Interrupt control and initialization.
|
2016-05-20 22:04:15 +02:00
|
|
|
//---
|
|
|
|
|
2016-05-05 11:49:05 +02:00
|
|
|
/*
|
|
|
|
gray_interrupt()
|
2016-05-20 22:04:15 +02:00
|
|
|
Answers a timer interrupt. Swaps the buffers.
|
2016-05-05 11:49:05 +02:00
|
|
|
*/
|
|
|
|
void gray_interrupt(void)
|
|
|
|
{
|
2016-05-20 22:04:15 +02:00
|
|
|
timer_reload(TIMER_GRAY, delays[current & 1]);
|
2016-05-05 11:49:05 +02:00
|
|
|
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];
|
2016-05-20 22:04:15 +02:00
|
|
|
|
2016-07-04 18:30:25 +02:00
|
|
|
delays[0] = 900;
|
|
|
|
delays[1] = 1000;
|
|
|
|
}
|