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

Subversion Repositories ag_6502

[/] [ag_6502/] [trunk/] [fighter/] [ag_main.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 olegodints
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company:   BMSTU
4
// Engineer:  Oleg Odintsov
5
// 
6
// Create Date:    15:09:47 01/19/2012 
7
// Design Name: 
8
// Module Name:    ag_main
9
// Project Name:    Agat Hardware Project
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
 
22
module RAM2kx8(input CLK, input[10:0] AB, input CS, input READ, output[7:0] DO, input[7:0] DI);
23
        reg[7:0] mem[0:2047];
24
        reg[7:0] R;
25
        assign DO = CS? R: 8'bZ;
26
        initial begin
27
                `include "monitor7.v"
28
                mem['h7FC] = 8'h00;
29
                mem['h7FD] = 8'h50;
30
        end
31
        always @(posedge CLK) if (CS) if (READ) R <= mem[AB]; else mem[AB] <= DI;
32
endmodule
33
 
34
module RAM4kx8(input CLK, input[11:0] AB, input CS, input READ, output[7:0] DO, input[7:0] DI);
35
        reg[7:0] mem[0:4095];
36
        reg[7:0] R;
37
        assign DO = CS? R: 8'bZ;
38
        always @(posedge CLK) if (CS) if (READ) R <= mem[AB]; else mem[AB] <= DI;
39
endmodule
40
 
41
module RAM8kx8(input CLK, input[12:0] AB, input CS, input READ, output[7:0] DO, input[7:0] DI);
42
        reg[7:0] mem[0:8191];
43
        reg[7:0] R;
44
        assign DO = CS? R: 8'bZ;
45
        always @(posedge CLK) if (CS) if (READ) R <= mem[AB]; else mem[AB] <= DI;
46
endmodule
47
 
48
module ag_main(
49
    input clk50,
50
         input[3:0] btns,
51
         output[7:0] leds,
52
         output[3:0] controls,
53
         output[4:0] vga_bus,
54
         input[1:0] ps2_bus_in,
55
         output clk_cpu
56
    );
57
 
58
//      assign leds = 0;
59
//      assign controls = 0;
60
//      assign vga_bus = 0;
61
 
62
        wire clk1, clk10;
63
        clk_div#5 cd5(clk50, clk10);
64
   clk_div#10 cd10(clk10, clk1);
65
 
66
 
67
        wire clk_vram;
68
        wire[13:0] AB2;
69
        wire[15:0] DI2;
70
 
71
        wire [15:0] AB;  // address bus
72
        wire [7:0] DI;           // data in, read bus
73
        wire [7:0] DO;           // data out, write bus
74
        wire read;
75
        wire rom_cs, ram_cs, xram_cs;
76
        wire phi_1, phi_2;
77
 
78
        RAM32Kx8x16 base_ram(phi_2, AB[14:0], ram_cs, read, DI, DO,
79
                                                        clk_vram, AB2, 1, DI2);
80
        RAM2kx8 rom1(phi_2, AB[10:0], rom_cs, read, DI, DO);
81
        RAM8kx8 xram(phi_2, AB[12:0], xram_cs, read, DI, DO);
82
 
83
        wire [3:0] AB_HH = AB[15:12];
84
        wire [3:0] AB_HL = AB[11:8];
85
        wire [3:0] AB_LH = AB[7:4];
86
        wire [3:0] AB_LL = AB[3:0];
87
        wire [7:0] AB_H = AB[15:8];
88
        wire [7:0] AB_L = AB[7:0];
89
        wire AB_CXXX = (AB_HH == 4'hC);
90
        wire AB_FXXX = (AB_HH == 4'hF);
91
 
92
        wire AB_C0XX = AB_CXXX && !AB_HL;
93
 
94
        wire AB_C00X = AB_C0XX && (AB_LH == 4'h0);
95
        wire AB_C01X = AB_C0XX && (AB_LH == 4'h1);
96
        wire AB_C02X = AB_C0XX && (AB_LH == 4'h2);
97
        wire AB_C03X = AB_C0XX && (AB_LH == 4'h3);
98
        wire AB_C7XX = AB_CXXX && (AB_HL == 4'h7);
99
 
100
        assign rom_cs = AB_FXXX && AB[11]; // F800-FFFF
101
        assign ram_cs = !AB[15];
102
        assign xram_cs = (AB_HH[3:1] == 3'b100);
103
 
104
 
105
        reg reset_auto = 1;
106
        wire reset;
107
        wire WE = ~read;                // write enable
108
        supply0 IRQ;            // interrupt request
109
        supply0 NMI;            // non-maskable interrupt request
110
        supply1 RDY;            // Ready signal. Pauses CPU when RDY=0 
111
        supply1 SO;                     // Set Overflow, not used.
112
        wire SYNC;
113
 
114
 
115
 
116
        reg[7:0] vmode = 0;
117
        wire[7:0] key_reg;
118
        reg[7:0] b_reg;
119
        reg lb;
120
        wire key_rus;
121
        reg key_clear = 0;
122
        wire key_rst, key_pause;
123
 
124
        reg beep_reg = 0, tape_out_reg = 0;
125
 
126
 
127
        assign reset  = 0;//btns[0];
128
        assign leds = AB[11:4];
129
        assign controls = {1'b0, beep_reg ^ tape_out_reg, tape_out_reg, beep_reg};
130
 
131
        ag_video video(clk50, vmode, clk_vram, AB2, DI2, vga_bus);
132
 
133
 
134
        wire[1:0] ps2_bus;
135
 
136
        signal_filter sf1(clk1, ps2_bus_in[0], ps2_bus[0]);
137
        signal_filter sf2(clk1, ps2_bus_in[1], ps2_bus[1]);
138
 
139
 
140
        ag_keyb keyb(phi_2, ps2_bus, key_reg, key_clear, key_rus, key_rst, key_pause);
141
 
142
        assign DI = (AB_C00X && !WE)?b_reg?b_reg:key_reg:8'bZ;
143
 
144
        always @(posedge phi_2) begin
145
                key_clear <= AB_C01X;
146
                if (AB_C01X) b_reg <= 0;
147
 
148
                if (btns[2] & ~lb) b_reg <= 8'hDD;
149
                else if (btns[0]) b_reg <= 8'h9C;
150
                else if (btns[1]) b_reg <= 8'hA0;
151
                else if (btns[3]) b_reg <= 8'h93;
152
                lb <= btns[2];
153
 
154
                if (AB_C02X) tape_out_reg <= ~tape_out_reg;
155
                if (AB_C03X) beep_reg <= ~beep_reg;
156
                if (AB_C7XX) vmode <= AB_L;
157
        end
158
        always @(posedge vga_bus[0]) begin
159
                reset_auto <= 0;
160
        end
161
 
162
        ag6502_ext_clock clk(clk50, clk1, phi_1, phi_2);
163
        ag6502 cpu(clk1, phi_1, phi_2, AB, read, DI, DO,
164
                                        RDY & ~key_pause, ~(reset | reset_auto | key_rst), ~IRQ, ~NMI, SO, SYNC);
165
 
166
        assign clk_cpu = clk1;
167
 
168
endmodule

powered by: WebSVN 2.1.0

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