205 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			205 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
define INPUT = 0xbffe;
 | 
						|
define SCREEN = 0xbfff;
 | 
						|
define SPAWN_X = 1;
 | 
						|
define SPAWN_Y = 1;
 | 
						|
define CASE_SIZE = 42;
 | 
						|
 | 
						|
global player_turn = 0;
 | 
						|
 | 
						|
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;
 | 
						|
global input_space;
 | 
						|
 | 
						|
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;
 | 
						|
	input_space = (input & 0x1) != 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; 
 | 
						|
}
 | 
						|
 | 
						|
check_victory(map, new_block_x, new_block_y)
 | 
						|
{
 | 
						|
	local row = 1;
 | 
						|
	loop
 | 
						|
	{
 | 
						|
		if ([map + ((new_block_x + row) % 3) * 3 + new_block_y] != [map + new_block_x * 3 + new_block_y])
 | 
						|
			break;
 | 
						|
		if (row == 2)
 | 
						|
			return (1);
 | 
						|
		row++;
 | 
						|
	}
 | 
						|
	row = 1;
 | 
						|
	loop
 | 
						|
	{
 | 
						|
		if ([map + new_block_x * 3 + ((new_block_y + row) % 3)] != [map + new_block_x * 3 + new_block_y])
 | 
						|
			break;
 | 
						|
		if (row == 2)
 | 
						|
			return (1);
 | 
						|
		row++;
 | 
						|
	}
 | 
						|
	row = 1;
 | 
						|
	loop
 | 
						|
	{
 | 
						|
		if ([map + ((new_block_x + row) % 3) * 3 + ((new_block_y + row) % 3)] != [map + new_block_x * 3 + new_block_y])
 | 
						|
			break;
 | 
						|
		if (row == 2)
 | 
						|
			return (1);
 | 
						|
		row++;
 | 
						|
	}
 | 
						|
	return (0);
 | 
						|
}
 | 
						|
 | 
						|
map_update(map, cursor_x, cursor_y)
 | 
						|
{
 | 
						|
	if (input_space == 0 | [map + cursor_x * 3 + cursor_y] != 'b')
 | 
						|
		return;
 | 
						|
	if (player_turn)
 | 
						|
		[map + cursor_x * 3 + cursor_y] = 'x';
 | 
						|
	else
 | 
						|
		[map + cursor_x * 3 + cursor_y] = 'o';
 | 
						|
	player_turn = player_turn == 0;
 | 
						|
}
 | 
						|
 | 
						|
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;
 | 
						|
		slp;
 | 
						|
		slp;
 | 
						|
		draw_map(map, cursor_x, cursor_y);
 | 
						|
		input_update();
 | 
						|
		cursor_update(&cursor_x, &cursor_y);
 | 
						|
		if (input_space)
 | 
						|
		{
 | 
						|
			map_update(map, cursor_x, cursor_y);
 | 
						|
			if (check_victory(map, cursor_x, cursor_y))
 | 
						|
				break;
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |