TinyArcade
サンプルプログラム †
#include <TinyScreen.h>
#define SCREEN_WIDTH 96
#define SCREEN_HEIGHT 64
#define BUFFER_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT)
#define BUFFER_BYTES (BUFFER_SIZE * 2)
#define COLOR16(r,g,b) ((((g<<3)&0xE)|(r>>3))<<8)+(b&0xF8)|(g>>5) // GGGRRRRRBBBBBGGG
TinyScreen tiny_screen = TinyScreen(TinyScreenPlus);
unsigned short screen_buffer[BUFFER_SIZE];
// Character image
const unsigned short Hiyoko_1[10 * 10] =
{
0x0000, 0x0000, 0x0000, 0x9B06, 0x9B06, 0x9B06, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x0000, 0x0000, 0x0000,
0x0000, 0x9B06, 0x0358, 0x0358, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x0000, 0x0000,
0x0000, 0x9B06, 0xFFFF, 0x0358, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x0000, 0x0000,
0x0000, 0x9B06, 0x0358, 0x0358, 0x9B06, 0x9F46, 0x9F46, 0x9F46, 0x9F46, 0x9F46,
0x9B03, 0x9B03, 0x9B03, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x9F46,
0x0000, 0x0000, 0x0000, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x9B06, 0x9F46, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x9B06, 0x9B06, 0x9B06, 0x9F46, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x9B03, 0x0000, 0x9B03, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x9B03, 0x0000, 0x9B03, 0x0000, 0x0000, 0x0000
};
void setup()
{
tiny_screen.begin();
// 65536 color mode
tiny_screen.setBitDepth(TSBitDepth16);
// Screen brightness
tiny_screen.setBrightness(7);
}
// Draw sprite no clip
void DrawSprite(const unsigned short* buffer, int x, int y, int width, int height, int color_key)
{
int scan_x;
int scan_y;
int source_address = 0;
int destination_address = SCREEN_WIDTH * y + x;
for(scan_y = 0; scan_y < height; ++ scan_y)
{
for(scan_x = 0; scan_x < width; ++ scan_x)
{
unsigned short color = buffer[source_address + scan_x];
if(static_cast<int>(color) != color_key)
{
screen_buffer[destination_address + scan_x] = color;
}
}
source_address += width;
destination_address += SCREEN_WIDTH;
}
}
void loop()
{
// Clear buffer
for(int i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; ++ i)
{
screen_buffer[i] = COLOR16(30, 30, 100);
}
// Draw sprite
DrawSprite(Hiyoko_1, 43, 27, 10, 10, 0);
// buffer to screen
tiny_screen.goTo(0, 0);
tiny_screen.setX(0, SCREEN_WIDTH - 1);
tiny_screen.setY(0, SCREEN_HEIGHT - 1);
tiny_screen.startData();
tiny_screen.writeBuffer(reinterpret_cast<unsigned char*>(screen_buffer), BUFFER_BYTES);
tiny_screen.endTransfer();
}