16 if ($dolinno && $linexpect != $templlinno) {
17 print "# $templlinno \"$templ\"\n" or die $!;
19 print $_[0] or die $!;
20 $linexpect= $templlinno+1;
23 sub expand_and_write () {
25 $templl =~ s/\@([a-z]+)\=(\w*)\@/
26 die "$1=$2 in $templl ?" unless exists $v{$1};
27 $v{$1} eq $2 ? '' : '@SKIP@'
29 $templl =~ m/\@SKIP\@/
31 $templl =~ s/\@([a-z]+)\@/
32 die $1 unless exists $v{$1};
40 return sprintf "0x%02x", (oct("0b$bin") | $orin);
46 if (m/^From host to PIC/) {
47 $dirn= '>'; begin("host2pic");
48 } elsif (m/^From PIC to host/) {
49 $dirn= '<'; begin("pic2host");
53 next unless defined $dirn;
54 next unless m/^ ([<>]) / && $1 eq $dirn;
57 m/^ [<>] ([01A-Za-z. ]+?)(?: +|\s+\([+? A-Z0-9a-z]+\)\s+)([^() \t\n].*)$/;
59 next if $rhs =~ m/^\}/;
60 next if $msg =~ m/\.\.\./;
61 $rhs =~ m/^([A-Z]+)\s/ or die "$rhs?";
64 if ($msg =~ m/^0[01]{7}$/) {
66 $opcodemask= '11111111';
71 $ybit= substr($msg,0,8);
72 $ybit =~ y/Y01A-Z/10/;
73 $ybit =~ m/1.*1/ and die "$msg/$ybit?";
75 $msg =~ m/[A-UW-Z]/ or die "$msg?";
78 die "$msg?" if $msg =~ m/[A-UW-Z]/;
79 die "$msg?" unless $msg =~ m/^(1[01][01V_]{6})0[V_]{7}$/ or
80 $msg =~ m/^(0[01][01V_]{6})$/;
82 die if $opcode =~ m/[V_][01]/;
84 $opcodemask =~ y/01V_/1100/;
85 $opcode =~ s/[V_]/0/g;
88 $argspat =~ s/[01]//g;
89 $argslen= length $argspat;
90 $argspat =~ m/^_*(V*)$/ or die "$msg/$argspat?";
92 $ybit= oct("0b$ybit");
94 for $yval (($ybit && $doyn) ? (0,1) : '') {
100 ($cname =~ m/nmradone/ ? 3 :
101 $cname =~ m/watchdog/ ? 3 :
102 $cname =~ m/p[io]ng/ ? 2 :
103 $cname =~ m/detect/ ? 3 :
105 $v{cnameyn}= $cname.$yval;
106 $v{cnameynu}= uc($cname.$yval);
107 $v{opcode}= b2xh($opcode, 0);
108 $v{opcodeyn}= b2xh($opcode, $ybit * $yval);
109 $v{opcodemask}= b2xh($opcodemask, 0);
110 $v{opcodemaskyn}= b2xh($opcodemask, $ybit);
112 $v{argslen}= $argslen;
113 $v{arglen}= $argslen - $vbits;
114 $v{nargs}= sprintf "%d", !!$argslen+!!$vbits;
119 open T, "$templ" or die "$templ $!";
121 $templlin= <T>; last unless length $templlin;
123 if ($templlin =~ s/\@L\@//) {
126 if ($templlin !~ m/\@\w+\@/) {
128 } elsif ($templlin =~ s/\@1\@//) {
130 $v{skeleton}= 'autogenerated - do not edit';
133 $doyn= $templlin =~ m/\@[a-z]+yn\@/;
134 $templlin =~ s/\@h2p\@/\@dname=host2pic\@/;
135 $templlin =~ s/\@p2h\@/\@dname=pic2host\@/;
136 open S, "$spec" or die "$spec $!";