47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
#include "device/device.h"
|
|
#include "game.h"
|
|
|
|
uint32_t game_frame;
|
|
|
|
void game_init() {
|
|
game_frame = 0;
|
|
|
|
for (uint32_t x = 0; x < 8; x++) {
|
|
for (uint32_t y = 0; y < 8; y++) {
|
|
for (uint32_t z = 0; z < 4; z++) {
|
|
device_palette[
|
|
(x << 5)|(y << 2)|(z)
|
|
] =
|
|
((x * 255)/7) << 24 |
|
|
((y * 255)/7) << 16 |
|
|
((z * 255)/3) << 8;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void game_update() {
|
|
game_frame += 4;
|
|
}
|
|
|
|
void game_draw() {
|
|
for (int x = 0; x < DEVICE_W; x++) {
|
|
for (int y = 0; y < DEVICE_H; y++) {
|
|
uint32_t r = (x * 255)/(DEVICE_W - 1);
|
|
uint32_t g = (y * 255)/(DEVICE_H - 1);
|
|
uint32_t b = game_frame & 0x100 ? 0xff - game_frame & 0xff : game_frame & 0xff;
|
|
if (x % 4 == 2 && y % 4 == 2) {
|
|
r = 255 - r;
|
|
g = 255 - g;
|
|
b = 255 - b;
|
|
}
|
|
uint8_t color = (r >> 5) << 5 | (g >> 5) << 2 | (b >> 6);
|
|
device_pixels[y][x] = color;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < DEVICE_BUTTON_N; i++) {
|
|
device_pixels[0][i] = device_buttons[i] ? 0x00 : 0xff;
|
|
}
|
|
}
|