📄 memorylib.vhd
字号:
end if;
end if;
deallocate(prev_pnt);
deallocate(pointer);
insdel_num:= 2;
elsif (prev_pnt.value = FF) and (next_pnt.value /= FF) then
pointer.value := FF;
if (double_prev /= null) then
double_prev.nexto := pointer;
else
memory.head := pointer; -- remove the head cell
end if;
pointer.prev := double_prev;
prev_pnt.prev := null;
prev_pnt.nexto := null;
if prev_pnt = memory.middle then
memory.middle:= next_pnt;
if memory.bal_value = left then memory.bal_value := centre;
elsif memory.bal_value = centre then memory.bal_value := right;
end if;
end if;
deallocate(prev_pnt);
insdel_num := 1;
elsif (prev_pnt.value /= FF) and (next_pnt.value /= FF) then
pointer.value:= FF;
insdel_num:= 0;
else -- prev_pnt.value /= FF and next_pnt.value = FF but not both
prev_pnt.nexto:= next_pnt;
next_pnt.prev:= prev_pnt;
pointer.prev:= null;
pointer.nexto:= null;
if pointer = memory.middle then
memory.middle:= next_pnt;
if memory.bal_value = left then memory.bal_value := centre;
elsif memory.bal_value = centre then memory.bal_value := right;
end if;
end if;
deallocate(pointer);
insdel_num:= 1;
end if;
end;
--------------------------------------------------------------------
------------- Remove the head of the list ------------------------
--------------------------------------------------------------------
procedure EraseHead(variable head_pnt: inout cell_pointer; variable insdel_num: inout integer) is
variable next_pnt: cell_pointer;
begin
next_pnt:= head_pnt.nexto;
if next_pnt.value = FF then -- remove head_pnt
next_pnt.prev:= null;
head_pnt.nexto:= null;
deallocate(head_pnt);
head_pnt:= next_pnt;
insdel_num:= 1;
else -- next_pnt.value /= FF
head_pnt.value:= FF;
insdel_num:= 0;
end if;
end;
--------------------------------------------------------------------
------------- Remove the tail of the list ------------------------
--------------------------------------------------------------------
procedure EraseTail(variable tail: inout cell_pointer; variable insdel_num: inout integer) is
variable prev_pnt: cell_pointer;
begin
prev_pnt:= tail.prev;
if prev_pnt.value = FF then -- remove tail
prev_pnt.nexto:= null;
tail.prev:= null;
deallocate(tail);
tail:= prev_pnt;
tail.endAddr:= Last_Addr;
insdel_num:= 1;
else -- prev_pnt.value /= FF
tail.value:= FF;
insdel_num:= 0;
end if;
end;
----------------------------------------------------------------------
------ Update the pointer to the middle of the memory list ---------
----------------------------------------------------------------------
procedure UpdateMiddle(variable memory: inout memory_rec; variable add: in AddrMem_type; variable mode: in modality; variable insdel_num: inout integer) is
-- bal tell me if middle is not balanced, and on which side it stays
Variable pnt_middle: cell_pointer;
Variable bal: balance;
begin
pnt_middle:= memory.middle;
bal:= memory.bal_value;
if mode = writing then
if add < pnt_middle.endAddr then
if insdel_num = 2 then -- two cells have been inserted
pnt_middle:= pnt_middle.prev; -- bal not change here
elsif insdel_num = 1 then -- only a cell has been inserted
if bal = centre then bal:= right;
else
if bal = right then
pnt_middle:= pnt_middle.prev;
bal:= centre;
else bal:= centre; -- bal goes from left to centre
end if;
end if;
end if;
elsif add > pnt_middle.endAddr then
if insdel_num = 2 then -- two cells have been inserted
pnt_middle:= pnt_middle.nexto; -- bal not change here
elsif insdel_num = 1 then -- only a cell has been inserted
if bal = centre then bal:= left;
else
if bal = left then
pnt_middle:= pnt_middle.nexto;
bal:= centre;
else bal:= centre; -- bal goes from left to centre
end if;
end if;
end if;
end if;
else -- mode = erasing
if add < pnt_middle.endAddr then
if insdel_num = 2 then -- two cells have been deleted
if pnt_middle /= memory.tail then pnt_middle:= pnt_middle.nexto; -- bal not change here
end if;
elsif insdel_num = 1 then -- only a cell has been deleted
if bal = centre then bal:= left;
else
if bal = left then
pnt_middle:= pnt_middle.nexto;
bal:= centre;
else bal:= centre; -- bal goes from right to centre
end if;
end if;
end if;
elsif add > pnt_middle.endAddr then
if insdel_num = 2 then -- two cells have been deleted
pnt_middle:= pnt_middle.prev; -- bal not change here
elsif insdel_num = 1 then -- only a cell has been deleted
if bal = centre then bal:= right;
else
if bal = right then
pnt_middle:= pnt_middle.prev;
bal:= centre;
else bal:= centre; -- bal goes from left to centre
end if;
end if;
end if;
end if;
end if;
memory.middle:= pnt_middle;
memory.bal_value:= bal;
end;
----------------------------------------------------------------------------
-------- Load the memory file in the memory list -------------------------
----------------------------------------------------------------------------
procedure LoadMemoryFile(FileName: in String; variable memory: inout memory_rec) is
file p_file : text;
variable l : line;
variable ch : character;
variable address : AddrMem_type;
variable data : DataMem_type;
variable index_addr : integer;
variable index_data : integer;
Constant dataHIGH : integer := data'high;
begin
InitMemory(memory);
if (FileName/="" and FileName/=" ") then
file_open(p_file, FileName, Read_Mode);
while not endfile (p_file) loop
readline (p_file,l);
if (l'length>0) then
address := 0;
index_addr := AddrMem_Dim/4;
if ((AddrMem_Dim rem 4) = 0) then
index_addr := index_addr - 1;
end if;
index_data := 0;
read (l, ch);
if ch='#' or ch=' ' then next; end if;
while (not(ch = '/')) loop --- lettura e calcolo address
address := address + slv2int(char2quad_bits(ch))*(16**index_addr);
read (l, ch);
index_addr := index_addr - 1;
end loop;
read (l, ch);
while (not(ch = ';')) loop --- lettura dato
for i in 0 to 3 loop
data(IOBusWidth - 1 - i - 4*index_data) := To_BitVector(char2quad_bits(ch))(3-i);
end loop;
read (l, ch);
index_data := index_data + 1;
end loop;
putMemory(memory, address, data);
end if;
end loop;
end if;
end LoadMemoryFile;
------------------------------------------------------------------------------
------------- Save the memory list into a memory file ----------------------
------------------------------------------------------------------------------
procedure SaveMemoryFile(FileName: in String; variable memory: in memory_rec) is
Constant NUMCHARHEXADDR :Integer := (AddrMem_Dim / 4) + ((AddrMem_Dim mod 4)+3)/4;
Constant NUMCHARHEXDATA :Integer := (DataMem_Dim / 4);
file p_file : text open Write_Mode is FileName;
variable OutLine : line;
Variable HexAddr : String(1 to NUMCHARHEXADDR);
Variable HexData : String(1 to NUMCHARHEXDATA);
Variable pnt: cell_pointer;
begin
if ((FileName/="")) then
pnt:= memory.head;
while pnt /= null loop
if (pnt.value /= FF) then
HexAddr:=int2Hex(pnt.endAddr);
HexData:=Int2Hexdata((slv2int(To_StdLogicVector(pnt.value))));
Std.TextIO.Write(OutLine, HexAddr);
Std.TextIO.Write(OutLine, '/');
Std.TextIO.Write(OutLine, HexData);
Std.TextIO.Write(OutLine, ';');
Std.TextIO.WriteLine(p_file, OutLine);
end if;
pnt:= pnt.nexto;
end loop;
end if;
end SaveMemoryFile;
end MemoryLib;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -