2 // Copyright (C) 2008 Tomasz Malesinski <tmal@mimuw.edu.pl>
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 module atari(clk_i
, clk2_i
, rst_i
,
30 key_code
, key_pressed
,
32 key_start
, key_select
, key_option
,
37 input key_code
, key_pressed
;
38 input key_shift
, key_break
;
39 input key_start
, key_select
, key_option
;
47 wire key_shift
, key_break
;
48 wire key_start
, key_select
, key_option
;
60 wire [7:0] gtia_dmadat_i
;
61 wire [3:0] consol_out
;
63 // Common interconnect signals.
66 reg [7:0] masterdat_o
;
73 wire [15:0] cpuadr_o
, anticadr_o
;
75 wire cpustb_o
, anticstb_o
;
77 wire cpucyc_o
, anticcyc_o
;
79 // Outputs from address decoder.
80 reg ramsel
, romsel
, bassel
;
81 reg anticsel
, gtiasel
, pokeysel
, piasel
;
84 // Outputs from arbiter.
85 wire cpugnt
, anticgnt
;
87 // Slaves STB_I signals.
88 wire ramstb
, romstb
, basstb
;
89 wire anticstb_i
, gtiastb
, pokeystb
, piastb
;
92 // Slaves DAT_O signals.
93 wire [7:0] ramdat_o
, romdat_o
, basdat_o
;
94 wire [7:0] anticdat_o
, gtiadat_o
, pokeydat_o
, piadat_o
;
96 // Slaves ACK_O signals.
97 wire ramack_o
, romack_o
, basack_o
;
98 wire anticack_o
, gtiaack_o
, pokeyack_o
, piaack_o
;
100 // Masters ACK_I signals.
101 wire cpuack_i
, anticack_i
;
104 // TODO: should it be synchronous?
105 assign cpugnt
= cpucyc_o
&& !anticcyc_o
;
106 assign anticgnt
= anticcyc_o
;
107 assign cyc
= cpucyc_o | anticcyc_o
;
109 // Masters outputs multiplexer.
110 always @ (cpuadr_o
or cpudat_o
or cpuwe_o
or cpustb_o
or
111 anticadr_o
or anticstb_o
or
112 cpugnt
or anticgnt
) begin
120 masterdat_o
= cpudat_o
;
127 always @ (adr
or portb
) begin
137 if (adr
[15:7] == {'h50
, 1'b1} && !portb
[7])
139 else if (adr
[15:8] >= 'ha0
&& adr
[15:8] < 'hc0
&& !portb
[1])
141 else if (adr
[15:8] == 'hd0
)
143 else if (adr
[15:8] == 'hd2
)
145 else if (adr
[15:8] == 'hd3
)
147 else if (adr
[15:8] == 'hd4
)
149 else if (adr
[15:8] == 'hd1 || adr
[15:8] == 'hd5 || adr
[15:8] == 'hd6 ||
152 else if (adr
[15:8] >= 'hc0
&& portb
[0])
159 assign ramstb
= ramsel
& cyc
& stb
;
160 assign romstb
= romsel
& cyc
& stb
;
161 assign basstb
= bassel
& cyc
& stb
;
162 assign anticstb_i
= anticsel
& cyc
& stb
;
163 assign gtiastb
= gtiasel
& cyc
& stb
;
164 assign pokeystb
= pokeysel
& cyc
& stb
;
165 assign piastb
= piasel
& cyc
& stb
;
166 assign dummystb
= dummysel
& cyc
& stb
;
168 // Or'd slaves ACK_O.
169 assign ack
= ramack_o | romack_o | basack_o | anticack_o | gtiaack_o |
170 pokeyack_o | piaack_o | dummystb
;
172 // Slaves DAT_O multiplexer.
173 always @ (ramsel
or ramdat_o
or
174 romsel
or romdat_o
or
175 bassel
or basdat_o
or
176 anticsel
or anticdat_o
or
177 gtiasel
or gtiadat_o
or
178 pokeysel
or pokeydat_o
or
181 slavedat_o
= ramdat_o
;
183 slavedat_o
= romdat_o
;
185 slavedat_o
= basdat_o
;
187 slavedat_o
= anticdat_o
;
189 slavedat_o
= gtiadat_o
;
191 slavedat_o
= pokeydat_o
;
193 slavedat_o
= piadat_o
;
197 // Masters ACK_I signals.
198 assign anticack_i
= ack
& anticgnt
;
199 assign cpuack_i
= ack
& cpugnt
;
201 defparam u_ram.size
= 'h10000
;
202 defparam u_ram.adrbits
= 16;
204 ram
u_ram(.
clk_i(clk_i
),
213 defparam u_rom.size
= 'h4000
;
214 defparam u_rom.adrbits
= 14;
216 rom
u_rom(.
clk_i(clk_i
),
223 defparam u_basic_rom.size
= 'h2000
;
224 defparam u_basic_rom.adrbits
= 13;
226 rom
u_basic_rom(.
clk_i(clk_i
),
233 cpu6502
u_cpu(.
clk_i(clk_i
),
245 antic
u_antic(.
clk_i(clk_i
),
248 .
slavedat_i(cpudat_o
),
249 .
masterdat_i(slavedat_o
),
260 .
antic_out(antic_out
));
262 assign gtia_dmadat_i
= we ? masterdat_o
: slavedat_o
;
264 gtia
u_gtia(.
clk_i(clk_i
),
273 .
dmadat_i(gtia_dmadat_i
),
274 .
antic_out(antic_out
),
278 // trig[3] = 0 - no cartridge
279 .
trig_in({2'b0, ~trig
}),
280 .
consol_in({1'b0, ~key_start
, ~key_select
, ~key_option
}),
281 .
consol_out(consol_out
));
283 pia
u_pia(.
clk_i(clk_i
),
294 pokey
u_pokey(.
clk_i(clk_i
),
303 .
key_code(key_code
), .
key_pressed(key_pressed
),
304 .
key_shift(key_shift
), .
key_break(key_break
));