OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [rtl/] [ImmediateReader.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see .
17
 
18
module ImmediateReader(input logic clk,
19
                       input logic reset,
20
                       // Control.
21
                       input logic start,
22
                       output logic busy,
23
                       output logic complete,
24
                       input logic is_8bit,
25
                       // Result.
26
                       output logic [15:0] immediate,
27
                       // Fifo Read Port.
28
                       output logic fifo_rd_en,
29
                       input logic [7:0] fifo_rd_data,
30
                       input logic fifo_empty);
31
 
32
assign fifo_rd_en = ~fifo_empty & (start | (_fetching & ~complete));
33
 
34
reg [15:0] _immediate_buf;
35
 
36
wire [1:0] _num_bytes = is_8bit ? 2'h1 : 2'h2;
37
reg [1:0] _bytes_read;
38
 
39
reg _fetch_busy;
40
wire _fetching = _fetch_busy & ~complete;
41
 
42
assign complete = reset ? 1'b0 : _bytes_read == _num_bytes - 1'b1 &&
43
    ~fifo_empty && (start || _fetch_busy);
44
 
45
assign busy = (start | _fetch_busy) & ~complete;
46
 
47
always_comb begin
48
    if (_bytes_read == 2'd0 && ~fifo_empty && start)
49
        immediate = {{8{fifo_rd_data[7]}}, fifo_rd_data[7:0]};
50
    else if (_bytes_read == 2'd1 && ~fifo_empty && !is_8bit)
51
        immediate = {fifo_rd_data, _immediate_buf[7:0]};
52
    else
53
        immediate = _immediate_buf;
54
end
55
 
56
always_ff @(posedge clk or posedge reset)
57
    if (reset)
58
        _fetch_busy <= 1'b0;
59
    else if (complete)
60
        _fetch_busy <= 1'b0;
61
    else if (start)
62
        _fetch_busy <= 1'b1;
63
 
64
always_ff @(posedge clk or posedge reset) begin
65
    if (reset) begin
66
        _bytes_read <= 2'b0;
67
    end else begin
68
        if ((start && !_fetch_busy) || complete)
69
            _bytes_read <= 2'b0;
70
        if (fifo_rd_en && !complete)
71
            _bytes_read <= _bytes_read + 2'b1;
72
    end
73
end
74
 
75
always_ff @(posedge clk or posedge reset) begin
76
    if (reset) begin
77
        _immediate_buf <= 16'b0;
78
    end else begin
79
        if (start && !_fetch_busy) begin
80
            _immediate_buf <= 16'b0;
81
        end
82
 
83
        if (_bytes_read == 2'b0 && ~fifo_empty && start) begin
84
            _immediate_buf[7:0] <= fifo_rd_data;
85
            if (is_8bit)
86
                _immediate_buf[15:8] <= {8{fifo_rd_data[7]}};
87
        end else if (_bytes_read == 2'd1 && ~fifo_empty)
88
            _immediate_buf[15:8] <= fifo_rd_data;
89
    end
90
end
91
 
92
endmodule

powered by: WebSVN 2.1.0

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