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';
70 $ybit= substr($msg,0,8);
71 $ybit =~ y/Y01A-Z/10/;
72 $ybit =~ m/1.*1/ and die "$msg/$ybit?";
74 $msg =~ m/[A-Z]/ or die "$msg?";
77 die "$msg?" if $msg =~ m/[A-Z]/;
78 die "$msg?" unless $msg =~ m/^(1[01][01_]{6})0_{7}$/ or
79 $msg =~ m/^(0[01][01_]{6})$/;
81 die if $opcode =~ m/_[01]/;
83 $opcodemask =~ y/01_/110/;
87 $arglen= length $arglen;
88 $ybit= oct("0b$ybit");
90 for $yval (($ybit && $doyn) ? (0,1) : '') {
96 ($cname =~ m/nmradone/ ? 3 :
97 $cname =~ m/p[io]ng/ ? 2 :
98 $cname =~ m/detect/ ? 1 :
100 $v{cnameyn}= $cname.$yval;
101 $v{cnameynu}= uc($cname.$yval);
102 $v{opcode}= b2xh($opcode, 0);
103 $v{opcodeyn}= b2xh($opcode, $ybit * $yval);
104 $v{opcodemask}= b2xh($opcodemask, 0);
105 $v{opcodemaskyn}= b2xh($opcodemask, $ybit);
107 $v{arglentf}= sprintf "%d", !!$arglen;
112 open T, "$templ" or die "$templ $!";
114 $templlin= <T>; last unless length $templlin;
116 if ($templlin =~ s/\@L\@//) {
119 if ($templlin !~ m/\@\w+\@/) {
121 } elsif ($templlin =~ s/\@1\@//) {
123 $v{skeleton}= 'autogenerated - do not edit';
126 $doyn= $templlin =~ m/\@[a-z]+yn\@/;
127 $templlin =~ s/\@h2p\@/\@dname=host2pic\@/;
128 $templlin =~ s/\@p2h\@/\@dname=pic2host\@/;
129 open S, "$spec" or die "$spec $!";