---------------------------------------------------------------- {{{ ---------- --: Copyright © 2020 … 2023 Martin Krischik «krischik@users.sourceforge.net» ------------------------------------------------------------------------------- --: This library is free software; you can redistribute it and/or modify it --: under the terms of the GNU Library General Public License as published by --: the Free Software Foundation; either version 2 of the License, or (at your --: option) any later version. --: --: This library is distributed in the hope that it will be useful, but WITHOUT --: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or --: FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public --: License for more details. --: --: You should have received a copy of the GNU Library General Public License --: along with this library; if not, write to the Free Software Foundation, --: Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ---------------------------------------------------------------- }}} ---------- pragma License (Modified_Gpl); pragma Ada_2022; with Ada.Strings.Wide_Wide_Fixed; with Ada.Text_IO; with Ada.Wide_Wide_Text_IO; with AdaCL.Strings.Hex; with AdaCL.Wide_Wide_Strings.Hex; with AdaCL.Trace; with EXE_Tools.Byte_IO; with EXE_Tools.Segment_Body; with EXE_Tools.Segment_Header; with EXE_Tools.CommandLine; --- -- --: @ value procedure EXE_Tools.Segment_Print (File_Name : in String; Operation : in EXE_Tools.CommandLine.Operation_Type := EXE_Tools.CommandLine.Print_All) is Trace : AdaCL.Trace.Object := AdaCL.Trace.Function_Trace; pragma Unreferenced (Trace); package CL renames EXE_Tools.CommandLine; package Text_IO renames Ada.Text_IO; File : Byte_IO.File_Type; begin AdaCL.Trace.Write ("Filename : " & File_Name); Byte_IO.Open (File, Byte_IO.In_File, File_Name, Form => ""); declare use Segment_Header; use Segment_Body; use type Word; procedure Write_Segment_Header (Header : in Header_Type'Class) is package Hex renames AdaCL.Strings.Hex; begin Text_IO.Put ("Magic: $"); Text_IO.Put (Hex.Image (Header.Magic)); Text_IO.Put ("; Start: $"); Text_IO.Put (Hex.Image (Header.Start_Address)); Text_IO.Put ("; End: $"); Text_IO.Put (Hex.Image (Header.End_Address)); Text_IO.Put ("; Length:"); Text_IO.Put (Header.Length'Image); end Write_Segment_Header; --- -- Create a memory dump -- --: @value Segment to be dumped. procedure Write_Segment_Data (Segment : in Body_Type) is use Ada.Wide_Wide_Text_IO; package Hex renames AdaCL.Wide_Wide_Strings.Hex; package Fixed renames Ada.Strings.Wide_Wide_Fixed; Line_Len : constant := 16; Byte_Len : constant := 2; Address_Len : constant := 4; Byte_Offset : constant := Address_Len + 3; -- «0130: » ASCII_Offset : constant := Byte_Offset + Line_Len * (Byte_Len + 1) + 1; Text_Len : constant := ASCII_Offset + Line_Len; Text : Wide_Wide_String (1 .. Text_Len); Line : Word := Segment'First; Col : Word := 0; Byte_Col : Integer; begin Dump_Line : while Line <= Segment'Last loop declare Address_Text : constant Wide_Wide_String := Hex.Image (Line); begin Fixed.Move (Source => Address_Text & ": ", Target => Text); end; Col := 0; Byte_Col := Byte_Offset; Dump_Column : while Col < Line_Len and then Line + Col <= Segment'Last loop declare Byte_Value : constant Byte := Segment (Line + Col); Byte_Text : constant Wide_Wide_String := Hex.Image (Byte_Value); Byte_Char : constant Wide_Wide_Character := ATASCII_US (Byte_Value); begin Text (Byte_Col .. Byte_Col + 1) := Byte_Text; Text (Natural (ASCII_Offset + Col)) := Byte_Char; end; Col := Col + 1; Byte_Col := Byte_Col + (Byte_Len + 1); end loop Dump_Column; Put_Line (Text); Line := Line + Line_Len; end loop Dump_Line; end Write_Segment_Data; --- -- Create a memory dump -- -- String to be written procedure Write_Execution_Info (Segment : in Body_Type; Prefix : in String) is package Hex renames AdaCL.Strings.Hex; New_Line_Needed : Boolean := Prefix'Length > 0; begin if Segment_Body.Has_Run_Address (Segment) then Text_IO.Put (Prefix); Text_IO.Put ("Run: $"); Text_IO.Put (Hex.Image (Segment_Body.Get_Word (Segment, Run_Address))); New_Line_Needed := True; end if; if Segment_Body.Has_Init_Address (Segment) then Text_IO.Put (Prefix); Text_IO.Put ("Init: $"); Text_IO.Put (Hex.Image (Segment_Body.Get_Word (Segment, Init_Address))); New_Line_Needed := True; end if; if New_Line_Needed then Text_IO.New_Line; end if; end Write_Execution_Info; begin Text_IO.Put ("File: "); Text_IO.Put (File_Name); Text_IO.New_Line; All_Segments : loop One_Segment : declare Header : constant Header_Type'Class := Read (File); Segment : constant Body_Type := Read (File, Header); begin case Operation is when CL.Print_All => Write_Segment_Header (Header); Write_Execution_Info (Segment, "; "); Write_Segment_Data (Segment); when CL.Print_Header => Write_Segment_Header (Header); Write_Execution_Info (Segment, "; "); when CL.Print_Data => Write_Segment_Data (Segment); Write_Execution_Info (Segment, ""); end case; end One_Segment; exit All_Segments when Byte_IO.End_Of_File (File); end loop All_Segments; end; Byte_IO.Close (File); return; end EXE_Tools.Segment_Print; ---------------------------------------------------------------- {{{ ---------- --: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab : --: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr : --: vim: set spell spelllang=en_gb :