The unified diff between revisions [34f8050e..] and [d33be27b..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'disassem.pl'

#
# old_revision [34f8050e1dacbf46115264d7077d7a0098397e5f]
# new_revision [d33be27b5ce4bc2db8cffc69bb79ff0c27767996]
#
# patch "disassem.pl"
#  from [02870da1e88f2384ce53dafaa61e56202225c42d]
#    to [98e5fd2959b6a72b0e812279f2d6d20e48a14f8f]
#
============================================================
--- disassem.pl	02870da1e88f2384ce53dafaa61e56202225c42d
+++ disassem.pl	98e5fd2959b6a72b0e812279f2d6d20e48a14f8f
@@ -1,4 +1,4 @@
-#!/usr/pkg/bin/perl
+#!/usr/bin/env perl
 
 open FILE, "input.bin" or die $!;
 
@@ -63,7 +63,7 @@ if (open LABELS, "<input.labels") {
 	    $addr = hex $addr;
 	    $labels{$addr} = $name;
 	    if ($name =~ /^L(\d+)$/) {
-		$labelnum = $1 + 1 if ($labelnum >= $1);
+		$labelnum = $1 + 1 if ($1 >= $labelnum);
 	    }
 	}
     }
@@ -210,7 +210,7 @@ foreach my $addr (sort keys %labels) {
 open LABELS, ">input.labels" or die $!;
 
 foreach my $addr (sort keys %labels) {
-    printf LABELS "%s: %.6x\n", $labels{$addr}, $addr
+    printf LABELS "%s: %06x\n", $labels{$addr}, $addr
 	if defined($labels{$addr});
 }
 
@@ -254,10 +254,12 @@ sub decode_instruction
     local $amode = undef;
     local @operands = ();
     local $comment = "";
+    local $branch = 0;
 
     if      ($byte == 0x00) {
 	output_instruction("NOP");
     } elsif ($byte == 0x01) {
+	branch();
 	output_instruction("INT9");
     } elsif ($byte == 0x02) {
 	set_operand("A");
@@ -302,6 +304,7 @@ sub decode_instruction
 	set_operand("A");
 	output_instruction("SUBDC");
     } elsif ($byte == 0x13) {
+	branch();
 	set_operand('@A');
 	output_instruction("JCTX");
     } elsif ($byte == 0x14) {
@@ -431,6 +434,7 @@ sub decode_instruction
 	read_operand_imm16();
 	output_instruction("SUBW");
     } elsif ($byte == 0x3A) {
+	branch();
 	set_operand("A");
 	read_operand_imm16();
 	read_operand_rel();
@@ -575,46 +579,59 @@ sub decode_instruction
 	read_operand_rlst();
 	output_instruction("POPW");
     } elsif ($byte == 0x60) {
+	branch();
 	read_operand_rel();
 	unconditional_branch();
 	output_instruction("BRA");
     } elsif ($byte == 0x61) {
+	branch();
 	set_operand('@A');
 	unconditional_branch();
 	output_instruction("JMP");
     } elsif ($byte == 0x62) {
+	branch();
 	read_operand_addr16();
 	unconditional_branch();
 	output_instruction("JMP");
     } elsif ($byte == 0x63) {
+	branch();
 	read_operand_addr24();
 	unconditional_branch();
 	output_instruction("JMPP");
     } elsif ($byte == 0x64) {
+	branch();
 	read_operand_addr16();
 	output_instruction("CALL");
     } elsif ($byte == 0x65) {
+	branch();
 	read_operand_addr24();
 	output_instruction("CALL");
     } elsif ($byte == 0x66) {
+	branch();
 	unconditional_branch();
 	output_instruction("RETP");
     } elsif ($byte == 0x67) {
+	branch();
 	unconditional_branch();
 	output_instruction("RET");
     } elsif ($byte == 0x68) {
+	branch();
 	read_operand_vct8();
 	output_instruction("INT");
     } elsif ($byte == 0x68) {
+	branch();
 	read_operand_vct8();
 	output_instruction("INT");
     } elsif ($byte == 0x69) {
+	branch();
 	read_operand_addr16();
 	output_instruction("INT");
     } elsif ($byte == 0x6A) {
+	branch();
 	read_operand_addr24();
 	output_instruction("INTP");
     } elsif ($byte == 0x6B) {
+	branch();
 	unconditional_branch();
 	output_instruction("RETI");
     } elsif ($byte == 0x6C) {
@@ -700,54 +717,71 @@ sub decode_instruction
 	set_operand_imm4($byte & 0xf);
 	output_instruction("MOVN");
     } elsif (($byte & 0xf0) == 0xE0) {
+	branch();
 	set_operand_imm4($byte & 0xf);
 	output_instruction("CALLV");
     } elsif ($byte == 0xF0) {
+	branch();
 	read_operand_rel();
 	output_instruction("BZ");
     } elsif ($byte == 0xF1) {
+	branch();
 	read_operand_rel();
 	output_instruction("BNZ");
     } elsif ($byte == 0xF2) {
+	branch();
 	read_operand_rel();
 	output_instruction("BC");
     } elsif ($byte == 0xF3) {
+	branch();
 	read_operand_rel();
 	output_instruction("BNC");
     } elsif ($byte == 0xF4) {
+	branch();
 	read_operand_rel();
 	output_instruction("BN");
     } elsif ($byte == 0xF5) {
+	branch();
 	read_operand_rel();
 	output_instruction("BP");
     } elsif ($byte == 0xF6) {
+	branch();
 	read_operand_rel();
 	output_instruction("BV");
     } elsif ($byte == 0xF7) {
+	branch();
 	read_operand_rel();
 	output_instruction("BNV");
     } elsif ($byte == 0xF8) {
+	branch();
 	read_operand_rel();
 	output_instruction("BT");
     } elsif ($byte == 0xF9) {
+	branch();
 	read_operand_rel();
 	output_instruction("BNT");
     } elsif ($byte == 0xFA) {
+	branch();
 	read_operand_rel();
 	output_instruction("BLT");
     } elsif ($byte == 0xFB) {
+	branch();
 	read_operand_rel();
 	output_instruction("BGE");
     } elsif ($byte == 0xFC) {
+	branch();
 	read_operand_rel();
 	output_instruction("BLE");
     } elsif ($byte == 0xFD) {
+	branch();
 	read_operand_rel();
 	output_instruction("BGT");
     } elsif ($byte == 0xFE) {
+	branch();
 	read_operand_rel();
 	output_instruction("BLS");
     } elsif ($byte == 0xFF) {
+	branch();
 	read_operand_rel();
 	output_instruction("BHI");
     } else {
@@ -801,26 +835,32 @@ sub decode_bit_manipulation
 	read_operand_addr16_bp($byte & 0x7);
 	output_instruction("SETB");
     } elsif (($byte & 0xf8) == 0x80) {
+	branch();
 	read_operand_io_bp($byte & 0x7);
 	read_operand_rel();
 	output_instruction("BBC");
     } elsif (($byte & 0xf8) == 0x88) {
+	branch();
 	read_operand_dir_bp($byte & 0x7);
 	read_operand_rel();
 	output_instruction("BBC");
     } elsif (($byte & 0xf8) == 0x98) {
+	branch();
 	read_operand_addr16_bp($byte & 0x7);
 	read_operand_rel();
 	output_instruction("BBC");
     } elsif (($byte & 0xf8) == 0xA0) {
+	branch();
 	read_operand_io_bp($byte & 0x7);
 	read_operand_rel();
 	output_instruction("BBS");
     } elsif (($byte & 0xf8) == 0xA8) {
+	branch();
 	read_operand_dir_bp($byte & 0x7);
 	read_operand_rel();
 	output_instruction("BBS");
     } elsif (($byte & 0xf8) == 0xB8) {
+	branch();
 	read_operand_addr16_bp($byte & 0x7);
 	read_operand_rel();
 	output_instruction("BBS");
@@ -1012,6 +1052,7 @@ sub decode_ea_70
 	output_instruction("SUBL");
     } elsif ($op == 0x40) {
 	set_operand_ea("RW", $byte);
+	branch();
 	read_operand_imm16();
 	read_operand_rel();
 	output_instruction("CWBNE");
@@ -1033,6 +1074,7 @@ sub decode_ea_70
 	output_instruction("XORL");
     } elsif ($op == 0xE0) {
 	set_operand_ea("R", $byte);
+	branch();
 	read_operand_imm8();
 	read_operand_rel();
 	output_instruction("CBNE");
@@ -1046,10 +1088,12 @@ sub decode_ea_71
     my $byte = getbyte();
     my $op = $byte & 0xe0;
     if ($op == 0x00) {
+	branch();
 	set_operand_ea('@RL', $byte);
 	unconditional_branch();
 	output_instruction("JMPP");
     } elsif ($op == 0x20) {
+	branch();
 	set_operand_ea('@RL', $byte);
 	output_instruction("CALLP");
     } elsif ($op == 0x40) {
@@ -1121,10 +1165,12 @@ sub decode_ea_73
     my $byte = getbyte();
     my $op = $byte & 0xe0;
     if ($op == 0x00) {
+	branch();
 	set_operand_ea('@RW', $byte);
 	unconditional_branch();
 	output_instruction("JMP");
     } elsif ($op == 0x20) {
+	branch();
 	set_operand_ea('@RW', $byte);
 	output_instruction("CALL");
     } elsif ($op == 0x40) {
@@ -1188,6 +1234,7 @@ sub decode_ea_74
 	output_instruction("XOR");
     } elsif ($op == 0xE0) {
 	set_operand_ea("R", $byte);
+	branch();
 	read_operand_rel();
 	output_instruction("DBNZ");
     } else {
@@ -1268,6 +1315,7 @@ sub decode_ea_76
 	output_instruction("XORW");
     } elsif ($op == 0xE0) {
 	set_operand_ea("RW", $byte);
+	branch();
 	read_operand_rel();
 	output_instruction("DWBNZ");
     } else {
@@ -1475,7 +1523,13 @@ sub read_operand_addr16
     my $byte2 = getbyte();
     my $addr = $byte1;
     $addr += $byte2 << 8;
-    set_operand(sprintf("%sD:0x%.4x", $at, $addr));
+    if ($branch) {
+	$addr = ($addr & 0xffff) | ($address & ~0xffff);
+        set_operand(sprintf("%s%s", $at, get_label($addr)));
+	add_comment(sprintf("0x%.6x", $addr));
+    } else {
+        set_operand(sprintf("%sD:0x%.4x", $at, $addr));
+    }
 }
 
 sub read_operand_addr16_bp
@@ -1496,7 +1550,12 @@ sub read_operand_addr24
     my $addr = $byte1;
     $addr += $byte2 << 8;
     $addr += $byte3 << 16;
-    set_operand(sprintf("0x%.6x", $addr));
+    if ($branch) {
+        set_operand(sprintf("%s", get_label($addr)));
+	add_comment(sprintf("0x%.6x", $addr));
+    } else {
+        set_operand(sprintf("0x%.6x", $addr));
+    }
 }
 
 ## ASSUMPTION: This is always the last operand!!!
@@ -1662,6 +1721,11 @@ sub set_operand_ea
     }
 }
 
+sub branch
+{
+    $branch = 1;
+}
+
 sub unconditional_branch
 {
 #    $finish_disassembly = 1;