| 1 |
2 |
lcdsgmtr |
-- Copyright 2015, Jürgen Defurne
|
| 2 |
|
|
--
|
| 3 |
|
|
-- This file is part of the Experimental Unstable CPU System.
|
| 4 |
|
|
--
|
| 5 |
|
|
-- The Experimental Unstable CPU System Is free software: you can redistribute
|
| 6 |
|
|
-- it and/or modify it under the terms of the GNU Lesser General Public License
|
| 7 |
|
|
-- as published by the Free Software Foundation, either version 3 of the
|
| 8 |
|
|
-- License, or (at your option) any later version.
|
| 9 |
|
|
--
|
| 10 |
|
|
-- The Experimental Unstable CPU System is distributed in the hope that it will
|
| 11 |
|
|
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
| 13 |
|
|
-- General Public License for more details.
|
| 14 |
|
|
--
|
| 15 |
|
|
-- You should have received a copy of the GNU Lesser General Public License
|
| 16 |
|
|
-- along with Experimental Unstable CPU System. If not, see
|
| 17 |
|
|
-- http://www.gnu.org/licenses/lgpl.txt.
|
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
LIBRARY std;
|
| 21 |
|
|
USE std.textio.ALL;
|
| 22 |
|
|
USE work.exp_io.ALL;
|
| 23 |
|
|
|
| 24 |
|
|
ENTITY file_reader IS
|
| 25 |
|
|
|
| 26 |
|
|
END ENTITY file_reader;
|
| 27 |
|
|
|
| 28 |
|
|
ARCHITECTURE Imperative OF file_reader IS
|
| 29 |
|
|
|
| 30 |
|
|
-- This provides a hard coded input file.
|
| 31 |
|
|
-- This is opened when the program starts
|
| 32 |
|
|
FILE input_file_1 : TEXT OPEN READ_MODE IS "test_input.txt";
|
| 33 |
|
|
FILE std_out : TEXT OPEN WRITE_MODE IS "STD_OUTPUT";
|
| 34 |
|
|
|
| 35 |
|
|
-- These files could also be declared in the process that reads them. Then
|
| 36 |
|
|
-- they need to be opened by using file_open()
|
| 37 |
|
|
|
| 38 |
|
|
BEGIN -- ARCHITECTURE Imperative
|
| 39 |
|
|
|
| 40 |
|
|
read_file : PROCESS IS
|
| 41 |
|
|
|
| 42 |
|
|
VARIABLE input_line : LINE;
|
| 43 |
|
|
|
| 44 |
|
|
BEGIN -- PROCESS read_file
|
| 45 |
|
|
|
| 46 |
|
|
-- The endfile() function tests if the end of the passed file has been
|
| 47 |
|
|
-- reached.
|
| 48 |
|
|
IF NOT endfile(input_file_1) THEN
|
| 49 |
|
|
-- readline() reads a line from a file
|
| 50 |
|
|
readline(input_file_1, input_line);
|
| 51 |
|
|
writeline(std_out, input_line);
|
| 52 |
|
|
ELSE
|
| 53 |
|
|
write(input_line,test_f("Z"));
|
| 54 |
|
|
writeline(std_out, input_line);
|
| 55 |
|
|
WAIT;
|
| 56 |
|
|
END IF;
|
| 57 |
|
|
|
| 58 |
|
|
END PROCESS read_file;
|
| 59 |
|
|
|
| 60 |
|
|
-- Files are declared by using FILE, in addition to SIGNALs and VARIABLEs.
|
| 61 |
|
|
-- Since Xilinx XST only knows the type TEXT for file, it is of no use to try
|
| 62 |
|
|
-- other types.
|
| 63 |
|
|
-- When a file is declared in the ARCHITECTURE, then it is automatically opened.
|
| 64 |
|
|
-- When a file is declared in a PROCESS, then the file can be opened by using
|
| 65 |
|
|
-- the file_open() procedure.
|
| 66 |
|
|
-- The contents of files are read into a VARIABLE of type LINE.
|
| 67 |
|
|
-- Standard input and output must be declared as normal files, but with the
|
| 68 |
|
|
-- file names "STD_INPUT" and "STD_OUTPUT".
|
| 69 |
|
|
|
| 70 |
|
|
END ARCHITECTURE Imperative;
|