-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopModule.vhd
593 lines (483 loc) · 15.3 KB
/
TopModule.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 09/14/2021 10:15:37 AM
-- Design Name:
-- Module Name: TopModule - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity TopModule is
Port (
clk :in std_logic;
btnCpuReset: in std_logic;
btnC: in std_logic;
btnL: in std_logic;
btnU: in std_logic;
btnR: in std_logic;
btnD: in std_logic;
sw : in std_logic_vector (15 downto 0);
PS2Clk : inout std_logic;
PS2Data : inout std_logic;
Hsync: out std_logic;
Vsync: out std_logic;
vgaRed: out std_logic_vector(3 downto 0);
vgaGreen: out std_logic_vector(3 downto 0);
vgaBlue: out std_logic_vector(3 downto 0)
);
end TopModule;
architecture Behavioral of TopModule is
--Constants :
constant H_PMax : integer := 800;
constant V_PMax : integer := 525;
constant black: std_logic_vector (11 downto 0) := X"000";
constant red: std_logic_vector (11 downto 0) := X"F25";
constant blue: std_logic_vector (11 downto 0) := X"00F";
constant Green: std_logic_vector (11 downto 0) := X"0F0";
--Signals:
signal clk25 : std_logic;
signal resetn : std_logic;
signal Farbe: std_logic_vector (11 downto 0);
signal FC : integer range 0 to 1023;
signal HC : integer range 1 to 800;
signal VC : integer range 1 to 525;
signal strobe : std_logic := '0' ;
signal tempfarbe: std_logic_vector (11 downto 0); --Mux signal Farbe
signal extemp : std_logic_vector (8 downto 0); --select signal
signal colsw : std_logic;
signal possw : std_logic;
signal collab3 : std_logic_vector(2 downto 0); --collabwehr3
signal collbal : std_logic_vector(6 downto 0); --collball
--Object1:
signal Ballcol : std_logic_vector(11 downto 0);
signal ExBall : std_logic;
--Spielrand
signal Randcol : std_logic_vector(11 downto 0);
signal ExRand : std_logic;
--Abwehr1
signal AB1col : std_logic_vector(11 downto 0);
signal Ex1Abw : std_logic;
--Abwehr2
signal AB2col : std_logic_vector(11 downto 0);
signal Ex2Abw : std_logic;
--Abwehr3
signal AB3col : std_logic_vector(11 downto 0);
signal Ex3Abw : std_logic;
--Torwand
signal Torwcol : std_logic_vector(11 downto 0);
signal ExTorw : std_logic;
--Kicker
signal kkwcol : std_logic_vector(11 downto 0);
signal Exkk : std_logic;
signal kickposout: integer;
--Torball
signal Torcol : std_logic_vector(11 downto 0);
signal Extor : std_logic;
signal ExNetz : std_logic;
--Zufall
signal seed : std_logic_vector(9 downto 0);
signal random : std_logic_vector(9 downto 0);
--Mouse
signal mouseleft : std_logic;
signal mousemiddle : std_logic;
signal mousenew_event : std_logic;
signal mouseright : std_logic;
signal mousexpos : std_logic_vector (9 downto 0);
signal mouseypos : std_logic_vector (9 downto 0);
signal mousezpos : std_logic_vector (3 downto 0);
-- Components
component clk_wiz_0 --IPclk
port(
clk_out1: out std_logic ;
resetn: in std_logic ;
clk_in1 : in std_logic);
end component;
component Object1 --BaLL
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
resetn:in std_logic;
FC: in integer;
strobe: in std_logic;
btnC: in std_logic;
btnL: in std_logic;
btnU: in std_logic;
btnR: in std_logic;
btnD: in std_logic;
posin: in integer;
collall :in std_logic_vector(6 downto 0);
BallCol: out std_logic_vector(11 downto 0);
Exist: out std_logic);
end component;
component SpielRand --Rand
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
resetn:in std_logic;
RandCol: out std_logic_vector(11 downto 0);
Exist: out std_logic
);
end component;
component Abwehr1 --Abwehr Spieler 1
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
FC: in integer;
strobe:in std_logic;
resetn:in std_logic;
Ab1Col: out std_logic_vector(11 downto 0);
colswitcher: in std_logic;
Exist: out std_logic
);
end component;
component Abwehr2 --Abwehr Spieler 2
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
FC: in integer;
strobe:in std_logic;
resetn:in std_logic;
Ab2Col: out std_logic_vector(11 downto 0);
colswitcher: in std_logic;
Exist: out std_logic
);
end component;
component Abwehr3 --Abwehr Spieler 3
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
FC: in integer;
strobe: in std_logic;
resetn:in std_logic;
rand: in std_logic_vector (9 downto 0);
AB3Col: out std_logic_vector(11 downto 0);
collall :in std_logic_vector(2 downto 0);
colswitcher: in std_logic;
poswitch : in std_logic;
Exist: out std_logic
);
end component;
component Torball -- Tor
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
resetn:in std_logic;
TorCol: out std_logic_vector(11 downto 0);
ExistTor: out std_logic;
ExistNetz: out std_logic
);
end component;
component lfsr
Port (
clk,reset : in std_logic;
seed : in std_logic_vector (9 downto 0);
random : out std_logic_vector(9 downto 0)
);
end component;
component MouseRefComp -- Mouse
port ( CLK : in std_logic;
RESOLUTION : in std_logic;
RST : in std_logic;
SWITCH : in std_logic;
LEFT : out std_logic;
MIDDLE : out std_logic;
NEW_EVENT : out std_logic;
RIGHT : out std_logic;
XPOS : out std_logic_vector (9 downto 0);
YPOS : out std_logic_vector (9 downto 0);
ZPOS : out std_logic_vector (3 downto 0);
PS2_CLK : inout std_logic;
PS2_DATA : inout std_logic);
end component;
component Torwand -- Torwand
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
FC: in integer;
strobe: in std_logic;
resetn:in std_logic;
mouseypos: in std_logic_vector(9 downto 0);
TorwandCol: out std_logic_vector(11 downto 0);
colswitcher: in std_logic;
poswitch : in std_logic;
Exist: out std_logic
);
end component;
component kicker --Kicker
Port (
clk25: in std_logic;
HC: in integer;
VC: in integer;
resetn:in std_logic;
FC: in integer;
strobe: in std_logic;
btnU: in std_logic;
btnD: in std_logic;
kkCol: out std_logic_vector(11 downto 0);
posout: out integer;
colswitcher: in std_logic;
Exist: out std_logic
);
end component;
begin
-- Para
colsw <= sw(0); --switsch0
possw <= sw(1); --switch1
resetn <= btnCpuReset;
vgaRed <= farbe (11 downto 8);
vgagreen <= farbe (7 downto 4);
vgablue <= farbe (3 downto 0);
seed <= "0110011001";
-- component map
CLkPix:clk_wiz_0
port map ( clk_out1 => clk25,
resetn => resetn,
clk_in1 => clk );
ball: Object1
port map (
clk25=> clk25,
HC => HC,
VC => VC,
resetn => resetn,
FC => FC,
strobe => strobe,
btnC => btnC,
btnL => btnL,
btnU => btnU,
btnR => btnR,
btnD => btnD,
posin => kickposout,
collall => collbal,
BallCol => Ballcol,
Exist => ExBall);
Rand: SpielRand
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
resetn =>resetn,
RandCol => Randcol,
Exist => ExRand
);
AbwehrS1: Abwehr1
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
FC => FC,
strobe => strobe,
resetn => resetn,
Ab1Col => AB1col,
colswitcher => colsw ,
Exist => Ex1Abw
);
AbwehrS2: Abwehr2
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
FC => FC,
strobe => strobe,
resetn => resetn,
Ab2Col => AB2col,
colswitcher => colsw ,
Exist => Ex2Abw
);
AbwehrS3: Abwehr3
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
FC => FC,
strobe => strobe,
resetn => resetn,
rand => random,
Ab3Col => AB3col,
collall => collab3,
colswitcher => colsw ,
poswitch => possw ,
Exist => Ex3Abw
);
TorBal: Torball
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
resetn =>resetn,
TorCol => Torcol,
ExistTor => Extor,
ExistNetz=> ExNetz
);
Zufall: lfsr
Port map(clk => clk25,
reset => resetn,
seed => seed,
random => random
);
Maus: MouseRefComp
port map( CLK =>clk,
RESOLUTION => '0',
RST => possw,--evtl anderen Button
SWITCH => '0',
LEFT => mouseleft,
MIDDLE => mousemiddle,
NEW_EVENT => mousenew_event,
RIGHT => mouseright,
XPOS => mousexpos,
YPOS => mouseypos,
ZPOS => mousezpos,
PS2_CLK => PS2Clk ,
PS2_DATA => PS2Data);
TorwandM : Torwand
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
FC => FC,
strobe => strobe,
resetn => resetn,
mouseypos => mouseypos,
TorwandCol => Torwcol,
colswitcher => colsw,
poswitch => possw ,
Exist => ExTorw
);
Kickermann : kicker
Port map (
clk25 =>clk25,
HC => HC,
VC =>Vc ,
FC => FC,
strobe => strobe,
resetn => resetn,
btnU => btnU,
btnD => btnD,
kkCol => kkwcol,
posout => kickposout,
colswitcher => colsw,
Exist => Exkk
);
Counters: process(clk25,resetn)
begin
if (resetn = '0') then
FC <= 0;
HC <= 1;
VC <= 1;
strobe <= '0';
elsif rising_edge(clk25) then
strobe <= '0';
if HC < H_PMax then
HC <= HC +1;
else
HC <= 1;
if VC < V_PMax then
VC <= VC + 1;
else
VC <= 1;
strobe <= '1';
if FC < 1023 then
FC <= FC + 1;
else
FC <= 0;
end if;
end if;
end if ;
end if;
end process Counters;
extemp <= (ExBall, ExRand, Ex1Abw, Ex2Abw, Ex3Abw, Extor, ExTorw,Exkk, ExNetz) ; -- noch Abwehr3
Display: process(HC, VC, strobe, extemp, Ballcol,Randcol,AB1col,AB2col,AB3col,Torwcol,Torcol,kkwcol, tempfarbe)
begin
-- Hsync
if (HC <= 656 or HC > 751) then
Hsync <= '1';
else
Hsync <= '0';
end if;
-- Vsync
if (VC <= 490 or VC > 492) then
Vsync <= '1';
else
Vsync <= '0';
end if;
-- Blanking
If HC > 640 or VC > 480 then
Farbe <= black;
else
Farbe <= tempFarbe;
end if;
--Displaying
case extemp is
when "100000000" => tempfarbe <= Ballcol;
when "010000000" => tempfarbe <= Randcol;
when "001000000" => tempfarbe <= AB1col;
when "000100000" => tempfarbe <= AB2col;
when "000010000" => tempfarbe <= AB3col;
when "000000100" => tempfarbe <= Torwcol;
when "000001000" => tempfarbe <= Torcol;
when "000000001" => tempfarbe <= Torcol;
when "000000000" => tempfarbe <= Green;
when "000000010" => tempfarbe <= kkwcol;
when others => tempfarbe <= red;
end case ;
end process Display;
Kollision: process(clk25, strobe, collab3)
begin
if rising_edge(clk25) then
--coll Abwehr3
if extemp(7)='1' and extemp(4)='1'then
collab3(2) <= '1'; --Rand
elsif extemp(6)='1' and extemp(4)='1'then
collab3(1) <= '1'; --Abwehr1
elsif extemp(5)='1' and extemp(4)='1'then
collab3(0) <= '1' ; --Abwehr2
end if;
--CollBall
if extemp(1)='1' and extemp(8)='1'then
collbal(6) <= '1' ; --Kicker
elsif extemp(4)='1' and extemp(8)='1'then
collbal(5) <= '1' ; --Abwehr3
elsif extemp(3)='1' and extemp(8)='1'then
collbal(4) <= '1' ; --Torball
elsif extemp(2)='1' and extemp(8)='1'then
collbal(3) <= '1' ; --Torwand
elsif extemp(7)='1' and extemp(8)='1'then
collbal(2) <= '1'; --Rand
elsif extemp(6)='1' and extemp(8)='1'then
collbal(1) <= '1'; --Abwehr1
elsif extemp(5)='1' and extemp(8)='1'then
collbal(0) <= '1' ; --Abwehr2
end if;
if strobe = '1' then
collab3 <= "000";
collbal <= "0000000";
end if;
end if;
end process Kollision;
end Behavioral;