OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [cpu/] [toplevel/] [tb_io.sv] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 gdevic
//--------------------------------------------------------------
2
// Implements I/O Model for simulation
3
//--------------------------------------------------------------
4
module io (Address, Data, CS, WE, OE);
5
 
6
// Set to 1 to have text output to the file "iolog.txt"
7
int iolog = 1;
8
 
9
// Set to 1 if you want debug printout on each IO access
10
int debug = 0;
11
 
12
int fd;
13
input [15:0] Address;
14
inout [7:0] Data;
15
input CS, WE, OE;
16
 
17
reg [7:0] IO [0:1<<16];
18
 
19
// Return data for the specified IO address:
20
//  1. If the current address is 0A00, that's the UART busy bit (which is never busy for ModelSim), so return 00
21
//  2. If the IO map is not defined for the current address, return FF
22
//  3. If the IO map is defined, return the value from it
23
//  4. Lastly, if !CS and !OE (not selecting the IO), tri-state the data bus
24
assign Data = (!CS && !OE) ? (Address==16'h0A00)? 8'h00 : (IO[Address]===8'hxx) ? 8'hFF : IO[Address] : {8{1'bz}};
25
 
26
// Read the initial content of the IO map from file
27
initial begin : init
28
    $readmemh("io.hex", IO);
29
    // If logging to a file was enabled, clear the file so we can append
30
    if (iolog) begin
31
        fd = $fopen("iolog.txt", "wb");
32
        $fclose(fd);
33
    end
34
end : init
35
 
36
always @(!CS && !OE) begin
37
    if (debug)
38
        $strobe("[IO] IN A=%H, D=%H", Address, Data);
39
end
40
 
41
always @(CS or WE)
42
    if (!CS && !WE) begin
43
        if (debug)
44
            $strobe("[IO] OUT A=%H, D=%H", Address, Data);
45
        if (Address==8*256) begin
46
            $write("%c", Data);
47
            // If logging to a file was enabled, append a character
48
            if (iolog) begin
49
                fd = $fopen("iolog.txt", "ab");
50
                $fwrite(fd, "%c", Data);
51
                $fclose(fd);
52
            end
53
        end
54
        IO[Address] = Data;
55
    end
56
 
57
always @(WE or OE)
58
    if (!WE && !OE)
59
        $display("[IO] error: OE and WE both active!");
60
 
61
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.