use utf8;
use strict;
use warnings;
use Shiar_Sheet::KeyboardChars 'kbchars';

my %c64 = (
	# control keys not on pet2001
	'1' => "🖤\nBLacK",
	'2' => "🤍\nWHiTe",
	'3' => "❤️\nRED",
	'4' => "🩵\nCYaN",
	'5' => "💜\nPURple",
	'6' => "💚\nGReeN",
	'7' => "💙\nBLUe",
	'8' => "💛\nYELlow",
	'9' => "💟\nREverSe video ON",
	'0' => "💔\nREverSe video OFF",
);

my %rows = (%c64,
	# literal petscii control characters, unaltered from pet2001
	'a' => '♠',
	'b' => '🭲',
	'c' => '🭸',
	'd' => '🭷',
	'e' => '🭶',
	'f' => '🭺',
	'g' => '🭱',
	'h' => '🭴',
	'i' => '╮',
	'j' => '╰',
	'k' => '╯',
	'l' => '🭼',
	'm' => '╲',
	'n' => '╱',
	'o' => '🭽',
	'p' => '🭾',
	'q' => '●',
	'r' => '🭻',
	's' => '♥',
	't' => '🭰',
	'u' => '╭',
	'v' => '╳',
	'w' => '○',
	'x' => '♣',
	'y' => '🭵',
	'z' => '♦',
	']' => '─', # @

	# literal pet2001 keys reassigned on c64
	',' => '┼', # [ c64 +
	'.' => '│', # ] c64 -
	'\\'=> 'π', # ↑ c64 \
	'}' => '◥', # ← c64 *
	'>' => '🮌', # \ c64 ^-
	'B' => '▚', # ?

	# ! " # $ % ' & \ ( ) ←            »  1 2 3 4 5 6 7 8 9 0 + - £
	# Q W E R T Y U I O P ↑   7 8 9 /  »  Q W E R T Y U I O P @ * ↑
	# A S D F G H J K L :     4 5 6 *  »  A S D F G H J K L : ; =
	# Z X C V B N M , ; ?     1 2 3 +  »  Z X C V B N M , . /
	#     @ [ ]     < >       0 . - =

	# pet2001 top row
	'K' => '▌', # A pet !
	'I' => '▄', # B pet "
	'T' => '▔', # C pet #
	'{' => '▁', # D pet $
	'G' => '▏', # E pet %
	'M' => '▕', # G pet '
	'<' => '▒', # F pet & c64 ^+
	'/' => '🮏', # H pet ( c64 ^£
	'?' => '◤', # I pet ) c64 £

	# pet2001 bottom rows
	'[' => '🭿', # Z pet :
	'D' => '▗', # L pet ,
	'F' => '▖', # { pet ;
	'C' => '▝', # | pet <
	'V' => '▘', # ~ pet >

	# pet2001 numpad
	'Y' => '🮂', # W pet 7
	'U' => '🮃', # X pet 8
	'O' => '▃', # Y pet 9
	'P' => '▂', # O pet /
	'H' => '▎', # T pet 4
	'J' => '▍', # U pet 5
	'L' => '🮈', # V pet 6
	'N' => '🮇', # J pet *
	'E' => '┴', # Q pet 1
	'R' => '┬', # R pet 2
	'W' => '┤', # S pet 3
	'Q' => '├', # K pet +
	'A' => '┌', # P pet 0
	'S' => '┐', # N pet .
	'Z' => '└', # M pet -
	'X' => '┘', # } pet =
);

my $groups = kbchars(\%rows);

while (my ($k, $c) = each %rows) {
	$groups->{def}{''}{$k}[0] = (
		$c64{$k} ? 'g9' :
		$c =~ /\p{In=1.1}/ ? 'g2' :
		$c =~ /\p{In=4.0}/ ? 'g3' :
		$c =~ /[\x{1FB00}-\x{1FBFF}]/ ? 'g5' : # Age=V13.0
		'g0'
	);
}

+{
	%{ $groups },
	version => '1.0',
	title => 'Commodore graphics',
	category => 'legacy/graph',
	moderows => '21-1',
	intro => join("\n",
		'<abbr title="PET Standard Code of Information Interchange">PETSCII</abbr>',
		'characters designed for the 1977 PET&nbsp;2001 machine',
		'as found on the VIC-20 and C-64.',
		'See also <a href="/keyboard/altgr/msx-graph">MSX graph</a> and',
		'<a href="/keyboard/altgr/unigraph">modern Unicode</a>.',
	),
	image => 'data/keyboard/thumb/c64.jpg',
	flag => {
		g2 => ['standard' => 'original Unicode 1993'],
		g3 => ['extended' => 'Unicode 4.0'],
		g5 => ['legacy'   => 'exceptional <em>symbols for legacy computing</em> in Unicode since <abbr title="Unicode 13.0">2020</abbr>'],
		g9 => ['color'    => 'presentational controls represented by anachronistic hearts'],
	},
}
