-- memoire rom, lecture du contenu dans un fichier -- rom_fic1.vhd package rompkg is constant ad_nb_bits : integer := 3 ; constant taille : integer := 2**ad_nb_bits ; subtype octet is bit_vector(7 downto 0) ; type rom_tbl is array(natural range <>) of octet ; end package rompkg ; library ieee ; use ieee.numeric_bit.all, std.textio.all, work.rompkg.all ; entity rom is port(adresse : in bit_vector(ad_nb_bits - 1 downto 0) ; donnee : out bit_vector(7 downto 0) ) ; end rom ; architecture fichier of rom is signal rom_val : rom_tbl(0 to taille - 1) ; begin lecture : process file donnees : text ; variable nom_fic : line ; variable openok : file_open_status ; variable ligne,message : line ; variable i : natural := 0 ; variable rom_buf : integer range 0 to 255 ; variable ok : boolean ; begin write(message,string'("fichier de données ?")) ; writeline(output,message) ; readline(input,nom_fic) ; file_open(openok,donnees, nom_fic.all, read_mode) ; if openok /= OPEN_OK then report "erreur ouverture" ; wait ; end if ; while not endfile(donnees) loop readline(donnees,ligne); read(ligne,rom_buf,ok) ; if ok then rom_val(i) <= octet(to_unsigned(rom_buf,8)) ; else write(message," !!! erreur de format !!! : "" " & ligne.all) ; write(message,string'(" "" à la ligne numero ")) ; write(message,i) ; writeline(output,message) ; end if ; if i < taille - 1 then i := i + 1 ; else report "rom pleine" ; exit ; end if ; end loop ; wait ; end process lecture ; donnee <= rom_val(to_integer(unsigned(adresse))) ; end fichier ;