Top level Atosm chip and its initial firmware
[AtosmChip.git] / atosm.v
blob5850899e2e1086b6af1e392e5a4b2179cd94122c
1 // Atosm Chip
2 // Copyright (C) 2008 Tomasz Malesinski <tmal@mimuw.edu.pl>
3 //
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.
8 //
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
18 `include "atari.v"
20 module atosm(rst_i, clk_i,
21 atari_clk_i, atari_clk2_i);
22 input rst_i, clk_i, atari_clk_i, atari_clk2_i;
24 wire rst_i, clk_i, atari_clk_i, atari_clk2_i;
26 wire [15:0] adr;
27 reg [7:0] slavedat_o;
28 wire [7:0] masterdat_o;
29 wire stb;
30 wire we;
31 wire ack;
32 wire cyc;
34 // Masters outputs.
35 wire [15:0] cpuadr_o;
36 wire [7:0] cpudat_o;
37 wire cpustb_o;
38 wire cpuwe_o;
39 wire cpucyc_o;
41 // Outputs from address decoder.
42 reg ramsel, romsel, atarisel;
43 reg dummysel;
45 // Slaves STB_I signals.
46 wire ramstb, romstb, ataristb;
47 wire dummystb;
49 // Slaves DAT_O signals.
50 wire [7:0] ramdat_o, romdat_o, ataridat_o;
52 // Slaves ACK_O signals.
53 wire ramack_o, romack_o, atariack_o;
55 // Masters ACK_I signals.
56 wire cpuack_i;
58 wire nmi, irq;
60 assign masterdat_o = cpudat_o;
61 assign adr = cpuadr_o;
62 assign we = cpuwe_o;
63 assign stb = cpustb_o;
65 assign cyc = cpucyc_o;
67 // Address decoder.
68 always @ (adr) begin
69 ramsel = 0;
70 romsel = 0;
71 atarisel = 0;
72 dummysel = 0;
73 if (adr[15] == 0)
74 ramsel = 1;
75 else if (adr[15:8] == 8'h80)
76 atarisel = 1;
77 else if (adr[15:14] == 2'b11)
78 romsel = 1;
79 else
80 dummysel = 1;
81 end
83 // Slaves stb_i.
84 assign ramstb = ramsel & cyc & stb;
85 assign romstb = romsel & cyc & stb;
86 assign ataristb = atarisel & cyc & stb;
87 assign dummystb = dummysel & cyc & stb;
89 assign ack = ramack_o | romack_o | atariack_o | dummystb;
91 assign cpuack_i = ack;
93 // Slaves dat_o mux.
94 always @ (ramsel or ramdat_o or
95 romsel or romdat_o or
96 atarisel or ataridat_o)
97 if (ramsel)
98 slavedat_o = ramdat_o;
99 else if (romsel)
100 slavedat_o = romdat_o;
101 else if (atarisel)
102 slavedat_o = ataridat_o;
103 else
104 slavedat_o = 'hff;
106 assign nmi = 0;
107 assign irq = 0;
109 defparam u_ram.size = 'h8000;
110 defparam u_ram.adrbits = 15;
112 ram u_ram(.clk_i(clk_i),
113 .adr_i(adr[14:0]),
114 .dat_i(masterdat_o),
115 .rst_i(rst_i),
116 .stb_i(ramstb),
117 .we_i(we),
118 .ack_o(ramack_o),
119 .dat_o(ramdat_o));
121 defparam u_rom.size = 'h4000;
122 defparam u_rom.adrbits = 14;
124 rom u_rom(.clk_i(clk_i),
125 .adr_i(adr[13:0]),
126 .rst_i(rst_i),
127 .stb_i(romstb),
128 .ack_o(romack_o),
129 .dat_o(romdat_o));
131 cpu6502 u_cpu(.clk_i(clk_i),
132 .adr_o(cpuadr_o),
133 .dat_i(slavedat_o),
134 .rst_i(rst_i),
135 .stb_o(cpustb_o),
136 .we_o(cpuwe_o),
137 .ack_i(cpuack_i),
138 .dat_o(cpudat_o),
139 .cyc_o(cpucyc_o),
140 .nmi(nmi),
141 .irq(irq));
143 atari u_atari(.clk_i(atari_clk_i),
144 .clk2_i(atari_clk2_i),
145 .rst_i(rst_i),
146 .ext_rst_i(rst_i),
147 .ext_clk_i(clk_i),
148 .ext_adr_i(adr[3:0]),
149 .ext_dat_i(masterdat_o),
150 .ext_dat_o(ataridat_o),
151 .ext_we_i(we),
152 .ext_stb_i(ataristb),
153 .ext_ack_o(atariack_o));
155 endmodule