4 # Convert a ca65 source into HTML
6 # Ullrich von Bassewitz, 05.12.2000
11 # ----------------------------------------------------------
13 # ----------------------------------------------------------
17 # Terminate with an error
23 # Print the document header
25 local $OUT = shift (@_);
26 local $Asm = shift (@_);
28 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html-40/loose.dtd">
31 <title>SDSL Traffic</title>
34 <body bgcolor="#FFFFFF" text="#000000" link="#0000d0" vlink="#000060" alink="#00d0d0">
36 <center><h1>$Asm</h1></center>
43 # Print the document footer
45 local $OUT = shift (@_);
46 local $Name = shift (@_);
48 # Get the current date and time
56 <a href=\"http://validator.w3.org/check/referer\"><img border=0
57 src=\"http://validator.w3.org/images/vh40\"
58 alt=\"Valid HTML 4.0!\" height=31 width=88 align=right></a>
59 $Name; generated on $Today by ca65html<br>
60 <a href=\"mailto:uz\@cc65.org\">uz\@cc65.org</a>
70 # Remove illegal characters from a string
72 local $S = shift (@_);
82 # ----------------------------------------------------------
84 # ----------------------------------------------------------
88 printf STDERR "Usage: %s asm-file output-file\n", $ARGV[0];
94 # Open a the input file
95 open (ASM, "<$ASM") or Abort ("Cannot open $ASM");
97 # Read all lines and remember labels
100 while ($Line = <ASM>) {
106 if ($Line =~ /^\s*([_\w][_\w\d]*)\s*(:|=)/) {
107 $Label { $1 } = $LNum++;
108 } elsif ($Line =~ /^\s*(\.import|\.importzp|.proc)\s+(.*?)(\s*)(;.*$|$)/) {
109 @L = split (/\s*,\s*/, $2);
111 $Label { $Id } = $LNum++;
116 # Reset the file pointer to the beginning
119 # Open the output file and print the HTML header
120 open (OUT, ">$OUT") or Abort ("Cannot open $OUT");
121 DocHeader (OUT, $ASM);
123 # The instructions that will have hyperlinks if a label is used
124 $Ins = "adc|add|and|bcc|bcs|beq|bit|bmi|bne|bpl|bcv|bvs|cmp|cpx|cpy|dec|".
125 "eor|inc|jmp|jsr|lda|ldx|ldy|ora|rol|sbc|sta|stx|sty|sub|";
127 # Read the input file again, replacing references by hyperlinks and mark
128 # labels as link targets.
129 while ($Line = <ASM>) {
134 # Clear the output line
137 # Check for and ignore a local label
138 if ($Line =~ /^(\s*\@[_\w][_\w\d]*\s*:)(.*)$/) {
141 # Use the remainder for line
145 # Check for a label, if we have one, remove it from the line
146 if ($Line =~ /^\s*([_\w][_\w\d]*)(\s*)(:|=)(.*)$/) {
147 # Print the label with a tag
148 $OutLine .= sprintf ("<a name=\"L%04X\">%s</a>%s%s", $Label { $1 }, $1, $2, $3);
149 # Use the remainder for line
153 # Print any leading whitespace
154 if ($Line =~ /^(\s+)(.*)$/) {
159 # Handle the import statements
160 if ($Line =~ /^(\.import|\.importzp|.proc|)(\s+)(.*)$/) {
164 # Print all identifiers if there are any
165 while ($Line =~ /^([_\w][_\w\d]*)(.*)$/) {
166 $Num = $Label { $1 };
168 $OutLine .= sprintf ("<a name=\"L%04X\">%s</a>", $Num, $1);
173 if ($Line =~ /^(\s*),(\s*)(.*)$/) {
181 # Add an remainder if there is one
182 $OutLine .= Cleanup ($Line);
184 # Check for control commands that may reference lists of labels
185 } elsif ($Line =~ /^(\.addr|\.word|\.export)(\s+)(.*)$/) {
187 # Print the command the and white space
191 # Print all identifiers if there are any
192 while ($Line =~ /^([_\w][_\w\d]*)(.*)$/) {
193 $Num = $Label { $1 };
195 $OutLine .= sprintf ("<a href=\"#L%04X\">%s</a>", $Num, $1);
200 if ($Line =~ /^(\s*),(\s*)(.*)$/) {
208 # Add an remainder if there is one
209 $OutLine .= Cleanup ($Line);
211 # Check for any legal instruction
212 } elsif ($Line =~ /^($Ins)(\s+)(.*)$/) {
214 # Print the instruction and white space
218 # Check for a comment or traling whitespace and separate it
219 if ($Line =~ /^(.*?)(\s*)(;.*)$/) {
222 } elsif ($Line =~ /^(.*?)(\s*)$/) {
229 # Check for the first identifier and replace it by a hyperlink
230 if ($Line =~ /^([^_a-zA-Z]*)([_a-zA-Z][_\w]*)(.*)$/ && $Label { $2 } != 0) {
231 $Line = sprintf ("%s<a href=\"#L%04X\">%s</a>%s",
232 Cleanup ($1), $Label { $2 }, $2, Cleanup ($3));
236 $Comment = Cleanup ($Comment);
238 # Reassemble and print the line
239 $OutLine .= "$Line$Comment";
243 # Nothing known - print the line
244 $OutLine .= Cleanup ($Line);
249 print OUT "$OutLine\n";
252 # Print the HTML footer
253 DocFooter (OUT, $OUT);