Forum Discussion
Altera_Forum
Honored Contributor
10 years agoYes it is, but I recommend you dont read/write data files via textio.
read() and write() procedures exist implicitly for all types. The easiest way to read/write binary data is via write(f, char). You can read/write individual chars to a files (which are basically the bytes in the files). I have an entire package for reading/writing bitmap files (currently 5000 lines of VHDL) - it reads the header for the image size/other data and puts the data into a dynamic array. It can cope with 8/24/32 bit per pixel. I cant post the package here because it's not mine to give, but I can provide support for any of your efforts.
type data_file_t is file of character;
.....
file bmp : data_file_t open read_mode is "input_image.bmp";
variable c_buf : character;
...
read(bmp, c_buf); --read a char (byte) from the file
-- or something more elaborate:
-- reads a number of bytes from the file depending on the length of s
procedure read_bytes( file f : data_file_t;
varaible s : out std_logic_vector ) is
variable c_buf : character;
begin
for i in 0 to (s'length/8)-1 loop
read(f, c_buf);
s( (8*i)+7 downto i*8 ) := char_to_slv(c_buf);
end loop;
end procedure read_bytes;