150 lines
2.6 KiB
Plaintext
150 lines
2.6 KiB
Plaintext
define INPUT = 0xbffe;
|
|
define SCREEN = 0xbfff;
|
|
define SPAWN_X = 1;
|
|
define SPAWN_Y = 1;
|
|
define CASE_SIZE = 42;
|
|
|
|
draw_pixel(x, y, c)
|
|
{
|
|
[SCREEN + (x & 127) + (y & 127) * 128] = c;
|
|
}
|
|
|
|
draw_x(x, y, selected)
|
|
{
|
|
local current_x = 0;
|
|
local current_y;
|
|
loop
|
|
{
|
|
if (current_x == CASE_SIZE)
|
|
return;
|
|
current_y = 0;
|
|
loop
|
|
{
|
|
if (current_y == CASE_SIZE)
|
|
break;
|
|
if (current_x == current_y | current_x == CASE_SIZE - current_y)
|
|
draw_pixel(x + current_x, y + current_y, 0xffff);
|
|
else
|
|
draw_pixel(x + current_x, y + current_y, 0x1111 * (selected + 2));
|
|
current_y++;
|
|
}
|
|
current_x++;
|
|
}
|
|
}
|
|
|
|
draw_o(x, y, selected)
|
|
{
|
|
local current_x = 0;
|
|
local current_y;
|
|
loop
|
|
{
|
|
if (current_x == CASE_SIZE)
|
|
return;
|
|
current_y = 0;
|
|
loop
|
|
{
|
|
if (current_y == CASE_SIZE)
|
|
break;
|
|
if (current_x == 2 | current_y == 2 | current_x == CASE_SIZE - 2 | current_y == CASE_SIZE - 2)
|
|
draw_pixel(x + current_x, y + current_y, 0xffff);
|
|
else
|
|
draw_pixel(x + current_x, y + current_y, 0x1111 * (selected + 2));
|
|
current_y++;
|
|
}
|
|
current_x++;
|
|
}
|
|
}
|
|
|
|
draw_blank(x, y, selected)
|
|
{
|
|
local current_x = 0;
|
|
local current_y;
|
|
loop
|
|
{
|
|
if (current_x == CASE_SIZE)
|
|
return;
|
|
current_y = 0;
|
|
loop
|
|
{
|
|
if (current_y == CASE_SIZE)
|
|
break;
|
|
draw_pixel(x + current_x, y + current_y, 0x1111 * (selected + 2));
|
|
current_y++;
|
|
}
|
|
current_x++;
|
|
}
|
|
}
|
|
|
|
draw_case(x, y, content, selected)
|
|
{
|
|
if (content == 'x')
|
|
draw_x(x, y, selected);
|
|
else if (content == 'o')
|
|
draw_o(x, y, selected);
|
|
else
|
|
draw_blank(x, y, selected);
|
|
}
|
|
|
|
draw_map(map, cursor_x, cursor_y)
|
|
{
|
|
local x = 0;
|
|
local y;
|
|
|
|
loop
|
|
{
|
|
if (x == 3)
|
|
return;
|
|
y = 0;
|
|
loop
|
|
{
|
|
if (y == 3)
|
|
break;
|
|
draw_case(x * CASE_SIZE + x, y * CASE_SIZE + y, [map + x * 3 + y], cursor_x == x & cursor_y == y);
|
|
y++;
|
|
}
|
|
x++;
|
|
}
|
|
}
|
|
|
|
global input_left;
|
|
global input_right;
|
|
global input_up;
|
|
global input_down;
|
|
|
|
input_update() {
|
|
local input = [INPUT];
|
|
input_up = (input & 0x10) != 0;
|
|
input_down = (input & 0x20) != 0;
|
|
input_left = (input & 0x40) != 0;
|
|
input_right = (input & 0x80) != 0;
|
|
}
|
|
|
|
cursor_update(cursor_x_ptr, cursor_y_ptr)
|
|
{
|
|
if (input_up)
|
|
[cursor_y_ptr] = ([cursor_y_ptr] - 1) % 3;
|
|
if (input_down)
|
|
[cursor_y_ptr] = ([cursor_y_ptr] + 1) % 3;
|
|
if (input_left)
|
|
[cursor_x_ptr] = ([cursor_x_ptr] - 1) % 3;
|
|
if (input_right)
|
|
[cursor_x_ptr] = ([cursor_x_ptr] + 1) % 3;
|
|
}
|
|
|
|
main()
|
|
{
|
|
local cursor_x, cursor_y;
|
|
local map = {'b', 'b', 'b','b', 'b', 'b', 'b', 'b', 'b'};
|
|
|
|
cursor_x = SPAWN_X;
|
|
cursor_y = SPAWN_Y;
|
|
|
|
loop
|
|
{
|
|
slp;
|
|
draw_map(map, cursor_x, cursor_y);
|
|
input_update();
|
|
cursor_update(&cursor_x, &cursor_y);
|
|
}
|
|
}
|