raw
ffa_ch4_ffacalc.kv      1 ------------------------------------------------------------------------------
ffa_ch4_ffacalc.kv 2 ------------------------------------------------------------------------------
ffa_ch4_ffacalc.kv 3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
ffa_ch4_ffacalc.kv 4 -- --
ffa_ch4_ffacalc.kv 5 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
ffa_ch4_ffacalc.kv 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
ffa_ch4_ffacalc.kv 7 -- --
ffa_ch4_ffacalc.kv 8 -- You do not have, nor can you ever acquire the right to use, copy or --
ffa_ch4_ffacalc.kv 9 -- distribute this software ; Should you use this software for any purpose, --
ffa_ch4_ffacalc.kv 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
ffa_ch4_ffacalc.kv 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
ffa_ch4_ffacalc.kv 12 -- continue doing so for the indefinite future. In any case, please --
ffa_ch4_ffacalc.kv 13 -- always : read and understand any software ; verify any PGP signatures --
ffa_ch4_ffacalc.kv 14 -- that you use - for any purpose. --
ffa_ch4_ffacalc.kv 15 -- --
ffa_ch4_ffacalc.kv 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
ffa_ch4_ffacalc.kv 17 ------------------------------------------------------------------------------
ffa_ch4_ffacalc.kv 18 ------------------------------------------------------------------------------
ffa_ch4_ffacalc.kv 19
ffa_ch4_ffacalc.kv 20 with OS; use OS;
ffa_ch4_ffacalc.kv 21
ffa_ch4_ffacalc.kv 22
ffa_ch4_ffacalc.kv 23 with Words; use Words;
ffa_ch4_ffacalc.kv 24 with W_Shifts; use W_Shifts;
ffa_ch4_ffacalc.kv 25 with FZ_Type; use FZ_Type;
ffa_ch4_ffacalc.kv 26
ffa_ch4_ffacalc.kv 27
ffa_ch4_ffacalc.kv 28 package body FFA_IO is
ffa_ch4_ffacalc.kv 29
ffa_ch4_ffacalc.kv 30 -- Obtain the WChars corresponding to the given Word
ffa_ch4_ffacalc.kv 31 function W_To_WChars(N : Word) return WChars is
ffa_ch4_ffacalc.kv 32 H : constant array(0 .. 15) of Character := "0123456789ABCDEF";
ffa_ch4_ffacalc.kv 33 W : Word := N;
ffa_ch4_ffacalc.kv 34 Result : WChars;
ffa_ch4_ffacalc.kv 35 begin
ffa_ch4_ffacalc.kv 36 for b in WChars'Range loop -- From bottom to top:
ffa_ch4_ffacalc.kv 37 Result(B) := H(Natural(W and 16#F#)); -- Get current nibble.
ffa_ch4_ffacalc.kv 38 W := Shift_Right(W, 4); -- Get the next nibble.
ffa_ch4_ffacalc.kv 39 end loop;
ffa_ch4_ffacalc.kv 40 return Result;
ffa_ch4_ffacalc.kv 41 end W_To_WChars;
ffa_ch4_ffacalc.kv 42
ffa_ch4_ffacalc.kv 43
ffa_ch4_ffacalc.kv 44 -- Display a hex representation of W to stdout
ffa_ch4_ffacalc.kv 45 procedure Dump(W : in Word) is
ffa_ch4_ffacalc.kv 46 T : WChars := W_To_WChars(W);
ffa_ch4_ffacalc.kv 47 begin
ffa_ch4_ffacalc.kv 48 for i in reverse T'Range loop
ffa_ch4_ffacalc.kv 49 Write_Char(T(i));
ffa_ch4_ffacalc.kv 50 end loop;
ffa_ch4_ffacalc.kv 51 end Dump;
ffa_ch4_ffacalc.kv 52
ffa_ch4_ffacalc.kv 53
ffa_ch4_ffacalc.kv 54 -- Display a hex representation of N to stdout
ffa_ch4_ffacalc.kv 55 procedure Dump(N : in FZ) is
ffa_ch4_ffacalc.kv 56 begin
ffa_ch4_ffacalc.kv 57 for i in reverse N'Range loop
ffa_ch4_ffacalc.kv 58 Dump(N(i));
ffa_ch4_ffacalc.kv 59 end loop;
ffa_ch4_ffacalc.kv 60
ffa_ch4_ffacalc.kv 61 -- Newline, for clarity.
ffa_ch4_ffacalc.kv 62 Write_Newline;
ffa_ch4_ffacalc.kv 63 end Dump;
ffa_ch4_ffacalc.kv 64
ffa_ch4_ffacalc.kv 65 end FFA_IO;