3 # lines, with one canonical subsegment specification (csss) each
8 # B <datumpart> <numbits> <bottombit>
9 # ((1u << numbits) - 1) << bottombit is the mask for datumpart
10 # datumpart may be Segnum Movfeatpos Edge Angle
11 # B lines are right at the start
13 # C <csss> 0x<datum> <angle-bits>
14 # where <csss> is N/[M] (see informat.txt) and <datum>
15 # is the hex value of the datum (see segcmap.h)
17 # S <segname> 0x<segnum>
18 # F <segname> 0x<segnum> <featname> 0x<prefix> <configbits>
19 # where (1<<configbits)-1 are the bits for the config
20 # and ~((1<<configbits)-1) are the bits for the prefix
22 # # comments for debugging segcmapassign etc.
24 # final line, always present
29 our ($seg,$movfeat,$movconf,$si,$fi);
34 sub read_segcmap_h () {
36 open H, "< segcmap.h" or die $!;
37 map { $bits{$_}=0 } qw(Angle Movfeatpos Segnum);
39 next unless m/^\#define\s+([A-Z])([A-Z]*)_BITS\s+([1-9]\d*)\s*$/;
41 next unless exists $bits{$p};
45 map { die $_ unless $bits{$_} } keys %bits;
50 sub pf { printf @_ or die $!; }
52 pf("B Segnum %d %d\n", $bits{Segnum}, 24-$bits{Movfeatpos}-$bits{Segnum});
53 pf("B Movfeatpos %d %d\n", $bits{Movfeatpos}, 24-$bits{Movfeatpos});
54 pf("B Edge %d %d\n", 1, $bits{Angle});
55 pf("B Angle %d %d\n", $bits{Angle}, 0);
58 my ($seg,$movfeat,$segnum,$posinfo) = @_;
61 ($posinfo << (24 - $bits{Movfeatpos})) |
62 ($segnum << (24 - $bits{Movfeatpos} - $bits{Segnum}));
63 pf("C %s/%s 0x%06x %d\n",
64 $seg, $movfeat, $datum, $bits{Angle});
68 m,^(\w*)/([A-Za-z_]*)(\d*)$, or die;
69 ($seg,$movfeat,$movconf)=($1,$2,$3);
71 die "too many $seg $movfeat" if
72 length $movfeat && $movconf >= $bits{Movfeatpos}-1;
73 cssnmap($seg,$movfeat,0,
74 length $movfeat ? 1<<($bits{Movfeatpos}-1) : 0);
77 die if length $movconf && !length $movfeat;
78 exists $seg{$seg}{Num};
80 if (length $movfeat) {
81 exists $si->{Feat}{$movfeat}{Max};
82 $fi= $si->{Feat}{$movfeat};
83 $fi->{Max}=0 unless exists $fi->{Max};
84 $fi->{Max}=$movconf unless $fi->{Max} >= $movconf;
90 our ($posbit,$posbiti,$abovenext);
92 foreach $seg (sort keys %seg) {
94 $si->{Num}= $segnum++;
95 die if $si->{Num} >= 1 << $bits{Segnum};
96 $abovenext= 1 << $bits{Movfeatpos};
99 cssnmap($seg,'', $si->{Num}, 0x00);
100 foreach $movfeat (sort {
101 $si->{Feat}{$b}{Max} <=> $si->{Feat}{$a}{Max};
102 } keys %{ $si->{Feat} }) {
103 $fi= $si->{Feat}{$movfeat};
104 $posbiti= $fi->{Max}+1;
105 $posbit= 1<<$posbiti;
106 $abovenext -= $posbit;
107 die "too many $seg" if $abovenext <= 0;
108 $fi->{Prefix}= $abovenext;
109 $fi->{ConfigMask}= $posbit-1;
110 $fi->{ConfigBits}= $posbiti;
111 pf("F %s 0x%x %s 0x%x %d\n",
113 $movfeat, $fi->{Prefix}, $fi->{ConfigBits});
114 cssnmap($seg, $movfeat, $si->{Num}, $fi->{Prefix});
118 STDIN->error and die $!;
119 print "E\n" or die $!;