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

Subversion Repositories mc6803

[/] [mc6803/] [trunk/] [MC6803.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Dukov
//MC6803 processor
2
module MC6803(
3
                input logic Clk,
4
                RST,
5
                hold,
6
                halt,
7
                //irq,
8
                nmi,
9
                input logic[7:0] PORT_A_IN,
10
                input logic[4:0] PORT_B_IN,
11
                input logic[7:0] DATA_IN,
12
                output logic[7:0] PORT_A_OUT,
13
                PORT_B_OUT,
14
                output logic[15:0] ADDRESS, last_write,
15
                output logic[7:0] DATA_OUT,
16
                output logic E_CLK, rw);
17
logic[15:0] address, counter, next_counter;// capture;
18
logic[7:0] A_DIRECTION_o, B_DIRECTION_o, data_in, data_out, outcomp_l, outcomp_h;
19
//logic[7:0] DATA_IN_S;
20
//logic[4:0] PORT_B_IN_S, PORT_A_IN_S;
21
//logic[1:0] cycle, next_cycle;
22
logic[7:0] REG_DATA;
23
logic REG_RW, iRAM_E;
24
logic B_EN, A_EN, vma, hold_s, nmi_s, PORTB_W, PORTA_W, outcomp_l_EN, outcomp_h_EN, counter_he, counter_le, counter_w, RST_S, irq_s;
25
logic OCF, TOF, EOCI, ETOI, TCSR_EN, TCSR_READ;
26
REG_8 direction_a(.Din(data_out), .Dout(A_DIRECTION_o), .EN(A_EN), .Clk);
27
REG_8 direction_b(.Din(data_out), .Dout(B_DIRECTION_o), .EN(B_EN), .Clk);
28
REG_8 port_b(.Din(data_out), .Dout(PORT_B_OUT), .EN(PORTB_W), .Clk);
29
REG_8 port_a(.Din(data_out), .Dout(PORT_A_OUT), .EN(PORTA_W), .Clk);
30
REG_8 outc_h(.Din(data_out), .Dout(outcomp_h), .EN(outcomp_h_EN), .Clk);
31
REG_8 outc_l(.Din(data_out), .Dout(outcomp_l), .EN(outcomp_l_EN), .Clk);
32
 
33
//cpu68 cpu68_inst(.clk(Clk), .rst(RST_S), .rw(rw), .vma(vma), .address(address), .data_in(data_in), .data_out(data_out), .hold(hold_s), .halt(halt), .irq(1'b0), .nmi(nmi_s));
34
cpu01 cpu01_inst(.clk(Clk), .rst(RST_S), .rw(rw), .vma(vma), .address(address), .data_in(data_in), .data_out(data_out), .hold(hold_s), .halt(halt), .irq(1'b0), .nmi(nmi_s), .irq_icf(1'b0), .irq_ocf(1'b0), .irq_tof(1'b0), .irq_sci(1'b0));
35
MEM_128_8 iMEM(.Clk, .reset(RST_S), .data_in(data_out), .data_out(REG_DATA), .RW(REG_RW), .address(address[6:0]));
36
assign ADDRESS = address;
37
assign DATA_OUT = data_out;
38
//assign last_write = {1'b1, OCF, TOF, 1'b0, EOCI, ETOI, 10'h00};
39
always_ff @ (negedge Clk)
40
begin
41
        hold_s <= hold;
42
        nmi_s <= nmi;
43
        RST_S <= RST;
44
        //irq_s <= irq;
45
        //PORT_B_IN_S <= PORT_B_IN;
46
        //PORT_A_IN_S <= PORT_A_IN;
47
        if(vma & (~rw))
48
                last_write <= address;
49
//      if(counter_he)
50
//              counter <= {data_out, counter[7:0]};
51
//      else if(counter_le)
52
//              counter <= {counter[15:8], data_out};
53
        if(RST_S)
54
        begin
55
                counter <= 0;
56
                OCF <= 0;
57
                TOF <= 0;
58
                EOCI <= 0;
59
                ETOI <= 0;
60
        end
61
        else
62
        begin
63
        if(counter_w)
64
                counter <= 16'hfff8;
65
        else
66
        begin
67
                counter <= next_counter;
68
        end
69
        //cycle <= next_cycle;
70
//      if(capture_EN)
71
//              capture <= counter;
72
        if(TCSR_EN)
73
        begin
74
                EOCI <= data_out[3];
75
                ETOI <= data_out[2];
76
        end
77
        if(TCSR_READ)
78
        begin
79
                TOF <= 0;
80
                OCF <= 0;
81
        end
82
        else
83
        begin
84
        if(counter == {outcomp_h, outcomp_l})
85
                OCF <= 1'b1;
86
        if(counter == 16'hffff)
87
                TOF <= 1'b1;
88
        end
89
        end
90
end
91
 
92
always_comb
93
begin
94
outcomp_h_EN = 0;
95
outcomp_l_EN = 0;
96
REG_RW = 1;
97
TCSR_EN = 0;
98
TCSR_READ = 0;
99
next_counter = counter + 16'h01;
100
//next_cycle = cycle + 2'b01;
101
//if(counter == {outcomp_h, outcomp_l})
102
//      capture_EN = 1'b1;
103
//else
104
//      capture_EN = 0;
105
if(address > 16'h7f && address < 16'h100 && vma)
106
        iRAM_E = 1'b1;
107
else
108
        iRAM_E = 0;
109
counter_w = 0;
110
A_EN = 0;
111
B_EN = 0;
112
PORTB_W = 0;
113
PORTA_W = 0;
114
//ADDRESS = 16'h06;
115
E_CLK = 0;
116
data_in = DATA_IN;
117
//DATA_OUT = 8'bxxxxxxxx;
118
        case (address)
119
        16'h00:
120
        begin
121
        if(vma & (~rw))
122
                A_EN = 1'b1;
123
        else if(vma)
124
                data_in = A_DIRECTION_o;
125
        end
126
        16'h01:
127
        begin
128
        if(vma & (~rw))
129
                B_EN = 1'b1;
130
        else if(vma)
131
                data_in = B_DIRECTION_o;
132
        end
133
        16'h02:
134
        begin
135
        if(vma & (~rw))
136
                PORTA_W = 1'b1;
137
        else if(vma)
138
                data_in = PORT_A_IN;
139
        end
140
        16'h03:
141
        begin
142
        if(vma & (~rw)) //write to port B
143
                PORTB_W = 1'b1;
144
        else if(vma)    //read port B
145
                data_in = {PORT_B_OUT[7:5], PORT_B_IN};
146
        end
147
        16'h08:
148
        begin
149
        if(vma & (~rw))
150
                TCSR_EN = 1'b1;
151
        else if(vma)
152
                begin
153
                TCSR_READ = 1'b1;
154
                data_in = {1'b1, OCF, TOF, 1'b0, EOCI, ETOI, 2'b00};
155
                end
156
        end
157
        16'h09:
158
        begin
159
        if(vma & (~rw))
160
                counter_w = 1'b1;       //preset the counter
161
        else if(vma)
162
                data_in = counter[15:8];
163
        end
164
        16'h0A:
165
        begin
166
        if(vma & rw)
167
                data_in = counter[7:0];
168
        end
169
        16'h0B:
170
        begin
171
        if(vma & (~rw))
172
                outcomp_h_EN = 1'b1;
173
        else if(vma)
174
                data_in = outcomp_h;
175
        end
176
        16'h0C:
177
        begin
178
        if(vma & (~rw))
179
                outcomp_l_EN = 1'b1;
180
        else if(vma)
181
                data_in = outcomp_l;
182
        end
183
//      16'h0D:
184
//      begin
185
//      if(vma & rw)
186
//              data_in = capture[15:8];
187
//      end
188
//      16'h0E:
189
//      begin
190
//      if(vma & rw)
191
//              data_in = capture[7:0];
192
//      end
193
        default:
194
        begin
195
        if(iRAM_E)
196
        begin
197
                REG_RW = rw;
198
                data_in = REG_DATA;
199
        end
200
        else
201
        begin
202
                E_CLK = vma;
203
                data_in = DATA_IN;
204
        end
205
        end
206
        endcase
207
end
208
endmodule
209
 
210
module REG_8(input logic [7:0] Din, input logic EN, Clk, output logic[7:0] Dout);
211
        always_ff @ (posedge Clk)
212
        begin
213
                if(EN)
214
                        Dout <= Din;
215
                else
216
                        Dout <= Dout;
217
        end
218
endmodule
219
 
220
module MEM_128_8(input logic[6:0] address, input logic RW, Clk, reset, input logic[7:0] data_in, output logic[7:0] data_out);
221
logic[7:0] REGS[127:0];
222
integer i;
223
always_ff @ (posedge Clk)
224
begin
225
if(reset)
226
        for(i=0; i<128; i=i+1)
227
                REGS[i]=0;
228
else if(~RW)
229
        REGS[address] <= data_in;
230
end
231
assign data_out = REGS[address];
232
endmodule
233
 

powered by: WebSVN 2.1.0

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