20150816.25e17c0f.diff 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. diff --git a/README.md b/README.md
  2. index b9e708c..01aa299 100644
  3. --- a/README.md
  4. +++ b/README.md
  5. @@ -29,10 +29,13 @@ Usage
  6. -comment Emit comments
  7. -call Emit callers
  8. -access Emit accessors
  9. + -extern Emit labels for out-of-range addresses
  10. + -rangelabels Emit labels for ranges instead of base+offset
  11. -verbose Print info to STDERR
  12. -dump Print options in format for -a
  13. -a FILE Read options from FILE. Lines are: OPTION VALUE
  14. + Addresses may include a range, e.g. table=$300+F
  15. Addresses may include xex segment number, e.g. 3:1FAE
  16. Examples
  17. diff --git a/dis b/dis
  18. index 13090f4..83a3be2 100755
  19. --- a/dis
  20. +++ b/dis
  21. @@ -41,7 +41,7 @@ use constant {
  22. sub state {
  23. return {
  24. - #mem => [map [0], 0 .. 0x10000],
  25. + mem => [map [0], 0 .. 0x10000],
  26. segnum => 0,
  27. };
  28. }
  29. @@ -79,10 +79,10 @@ sub labels {
  30. (?:\+([0-9a-fA-F]+))? # optional range in hex
  31. /x;
  32. $match or die "ERROR: Unrecognized $opt address: $value\n";
  33. - my $label = $1;
  34. my $segnum = $2 || 0;
  35. my $base = hex($3);
  36. my $range = hex($4||0);
  37. + my $label = $1 || sprintf "u%2X", $base;
  38. for my $off (0 .. $range) {
  39. my $addr = $base + $off;
  40. if (($addr & 0xFFFF) != $addr) {
  41. @@ -92,6 +92,7 @@ sub labels {
  42. if (defined $state->{$opt}{$segnum}{$addr}) {
  43. warn sprintf "WARNING: Duplicate $opt: $value: %X\n",
  44. $addr;
  45. + next;
  46. }
  47. $state->{$opt}{$segnum}{$addr} =
  48. $off ? $rangelabels ? sprintf "${label}_%X", $off :
  49. @@ -194,14 +195,18 @@ sub trace {
  50. my $targ = rel($i, $i1);
  51. trace($state, $targ, $byte->[LABEL], $i);
  52. } elsif ($mode =~ /Ind|Z-Page/) {
  53. - my $tlabel = $mem->[$i1][LABEL];
  54. + my $data = $mem->[$i1];
  55. + my $pre = $data->[SEGNUM] ? sprintf "s$data->[SEGNUM]" : "";
  56. + my $tlabel = $data->[LABEL] ||= $pre . sprintf "l%02X", $i1;
  57. push @{$byte->[TARGETS]}, $tlabel if $tlabel;
  58. - push @{$mem->[$i1][ACCESSORS]}, seglabel($state, $i);
  59. + push @{$data->[ACCESSORS]}, seglabel($state, $i);
  60. } elsif ($mode =~ /Absolute/) {
  61. my $addr = addr($i1, $i2);
  62. - my $tlabel = $mem->[$addr][LABEL];
  63. + my $data = $mem->[$addr];
  64. + my $pre = $data->[SEGNUM] ? sprintf "s$data->[SEGNUM]" : "";
  65. + my $tlabel = $data->[LABEL] ||= $pre . sprintf "l%04X", $addr;
  66. push @{$byte->[TARGETS]}, $tlabel if $tlabel;
  67. - push @{$mem->[$addr][ACCESSORS]}, seglabel($state, $i);
  68. + push @{$data->[ACCESSORS]}, seglabel($state, $i);
  69. }
  70. $i += $len[$code];
  71. }
  72. @@ -214,23 +219,24 @@ sub extern {
  73. return if not $opts->{extern};
  74. return if not $opts->{labels};
  75. my @labels;
  76. - for my $opt (qw(code data vector)) {
  77. - for my $labels (values %{$state->{$opt}||{}}) {
  78. - for my $addr (sort {$a <=> $b} keys %$labels) {
  79. - my $label = $labels->{$addr} or next;
  80. - next if $opts->{labelled}{$label};
  81. - next if not $opts->{referenced}{$label};
  82. - next if $label =~ /\+/;
  83. - my $accessors = $state->{mem}[$addr][ACCESSORS];
  84. - my $access = "";
  85. - if ($accessors and $opts->{access}) {
  86. - $access = "\t\t; " . join " ", "Access:", uniq @$accessors;
  87. - }
  88. - push @labels, [$addr,
  89. - sprintf "$labels->{$addr} equ \$%X$access\n", $addr];
  90. - }
  91. + for (my $addr = 0; $addr < 0x10000; ++$addr) {
  92. + my $label = $state->{mem}[$addr][LABEL] or next;
  93. + next if $opts->{labelled}{$label};
  94. + next if not $opts->{referenced}{$label};
  95. + next if $label =~ /\+/;
  96. + my $comment = "";
  97. + my $accessors = $state->{mem}[$addr][ACCESSORS];
  98. + if ($accessors and $opts->{access}) {
  99. + $comment .= "\t\t; " . join " ", "Access:", uniq @$accessors;
  100. }
  101. + my $callers = $state->{mem}[$addr][CALLERS];
  102. + if ($callers and $opts->{call}) {
  103. + $comment .= "\t\t; " . join " ", "Callers:", uniq @$callers;
  104. + }
  105. + push @labels, [$addr,
  106. + sprintf "$label equ \$%X$comment\n", $addr];
  107. }
  108. + print "##EXTERN##\n";
  109. print map $_->[1], sort { $a->[0] <=> $b->[0] } @labels;
  110. }
  111. @@ -286,8 +292,6 @@ sub dis {
  112. my $targ = $imm8 = $imm16 = $rel = $targets->[-1];
  113. $targ =~ s/\+.*//;
  114. $opts->{referenced}{$targ}++;
  115. - # Use z: if label is not predeclared in zero-page
  116. - $imm8 = "z:$imm8" if not defined $mem->[$i1][VALUE];
  117. } elsif ($mode eq "Immediate" and $state->{constant}{$segnum}{$i1}) {
  118. $imm8 = $state->{constant}{$segnum}{$i1};
  119. $opts->{referenced}{$imm8}++;
  120. @@ -522,7 +526,7 @@ sub raw {
  121. my ($stream, $opts) = @_;
  122. my $start = hex($opts->{org}||0);
  123. my $end = $start + (length $stream) - 1;
  124. - printf " opt h-\n";
  125. + printf " opt h-\n" unless $opts->{headers};
  126. printf " org \$%04X\n", $start;
  127. my $state = state();
  128. layer($state, $start, $end, $stream);
  129. @@ -616,6 +620,7 @@ sub main {
  130. call!
  131. access!
  132. extern!
  133. + headers!
  134. verbose!
  135. dump!
  136. arg|a=s@
  137. @@ -650,6 +655,13 @@ sub main {
  138. warn "WARNING: Truncating file at 1M\n";
  139. }
  140. + if ($opts{extern} and open my $pipe, "-|") {
  141. + $_ = do { local $/; <$pipe> };
  142. + s/(.*)##EXTERN##\n(.*)/$2$1/s;
  143. + print;
  144. + exit 0;
  145. + }
  146. +
  147. if ($opts{type} eq "xex") {
  148. xex($stream, \%opts);
  149. } elsif ($opts{type} eq "prg") {
  150. diff --git a/sid.dop b/sid.dop
  151. index 0a85ddf..ea19fab 100644
  152. --- a/sid.dop
  153. +++ b/sid.dop
  154. @@ -28,4 +28,4 @@ data SIDPADX=$D419
  155. data SIDPADY=$D41A
  156. data SIDOSCIL=$D41B
  157. data SIDENVEL=$D41C
  158. -data SID=$D41D+D2
  159. +data SID=$D41D+E2
  160. diff --git a/sys.dop b/sys.dop
  161. index 96c7266..a875e15 100644
  162. --- a/sys.dop
  163. +++ b/sys.dop
  164. @@ -339,7 +339,7 @@ data COLOR2=$2C6
  165. data COLOR3=$2C7
  166. data COLOR4=$2C8 ;BACKGROUND
  167. ;($2C9 - $2DF SPARE)
  168. -data GLBABS=$2E0 ;GLOBAL VARIABLES
  169. +data GLBABS=$2E0+2 ;GLOBAL VARIABLES
  170. ;($2E0 - $2E3 SPARE)
  171. data RAMSIZ=$2E4 ;RAM SIZE (HI BYTE ONLY)
  172. data MEMTOP=$2E5+1 ;TOP OF AVAILABLE MEMORY