-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpaddles.v
316 lines (305 loc) · 7.66 KB
/
paddles.v
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
////////////////////////////////////////////////////////////////////////////////
// Project Name: CoCo3FPGA Version 3.0
// File Name: paddles.v
//
// CoCo3 in an FPGA
//
// Revision: 3.0 08/15/15
////////////////////////////////////////////////////////////////////////////////
//
// CPU section copyrighted by John Kent
// The FDC co-processor copyrighted Daniel Wallner.
//
////////////////////////////////////////////////////////////////////////////////
//
// Color Computer 3 compatible system on a chip
//
// Version : 3.0
//
// Copyright (c) 2008 Gary Becker ([email protected])
//
// All rights reserved
//
// Redistribution and use in source and synthezised forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// Redistributions in synthesized form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Please report bugs to the author, but before you do so, please
// make sure that this is not a derivative work and that
// you have the latest version of this file.
//
// The latest version of this file can be found at:
// http://groups.yahoo.com/group/CoCo3FPGA
//
// File history :
//
// 1.0 Full Release
// 2.0 Partial Release
// 3.0 Full Release
////////////////////////////////////////////////////////////////////////////////
// Gary Becker
////////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
* Joystick to CoCo compatable
******************************************************************************/
assign PADDLE_MCLK = MCLOCK[10];
always @(negedge MCLOCK[10] or negedge RESET_N)
begin
if(~RESET_N)
begin
JOY_CLK <= 13'h000;
JOY_TRIGGER <= 1'b0;
end
else
case(JOY_CLK)
13'd0000:
begin
JOY_CLK <= 13'd0001;
JOY_TRIGGER <= 1'b0;
end
13'd5883:
begin
JOY_CLK <= 13'd5884;
JOY_TRIGGER <= 1'b1;
end
13'd8191:
begin
JOY_CLK <= 13'd0000;
JOY_TRIGGER <= 1'b0;
end
default:
JOY_CLK <= JOY_CLK + 1'b1;
endcase
end
always @(negedge PADDLE_CLK[0] or negedge RESET_N)
begin
if(~RESET_N)
begin
PADDLE_ZERO_0 <= 10'd0000;
PADDLE_VAL_0 <= 12'd0000;
PADDLE_STATE_0 <= 2'b00;
JOY1_COUNT <= 6'h00;
end
else
begin
case(PADDLE_STATE_0)
2'b00:
begin
PADDLE_ZERO_0 <= PADDLE_ZERO_0 + 1'b1;
PADDLE_VAL_0 <= 12'd0000;
if(PADDLE_ZERO_0 == 10'd611)
PADDLE_STATE_0 <= 2'b01;
end
2'b01:
begin
PADDLE_ZERO_0 <= 10'd000;
PADDLE_VAL_0 <= PADDLE_VAL_0 + 1'b1;
if(PADDLE_VAL_0 == 12'd4094)
PADDLE_STATE_0 <= 2'b10;
else
begin
if(JOY_TRIGGER)
PADDLE_STATE_0 <= 2'b10;
else
PADDLE_STATE_0 <= 2'b01;
end
end
2'b10:
begin
JOY1_COUNT <= PADDLE_VAL_0[11:6];
PADDLE_LATCH_0 <= PADDLE_VAL_0;
if(JOY_TRIGGER)
PADDLE_STATE_0 <= 2'b11;
end
2'b11:
begin
if(!JOY_TRIGGER)
PADDLE_STATE_0 <= 2'b00;
end
endcase
end
end
always @(negedge PADDLE_CLK[1] or negedge RESET_N)
begin
if(~RESET_N)
begin
PADDLE_ZERO_1 <= 10'd0000;
PADDLE_VAL_1 <= 12'd0000;
PADDLE_STATE_1 <= 2'b00;
JOY2_COUNT <= 6'h00;
end
else
begin
case(PADDLE_STATE_1)
2'b00:
begin
PADDLE_ZERO_1 <= PADDLE_ZERO_1 + 1'b1;
PADDLE_VAL_1 <= 12'd0000;
if(PADDLE_ZERO_1 == 10'd611)
PADDLE_STATE_1 <= 2'b01;
end
2'b01:
begin
PADDLE_ZERO_1 <= 10'd000;
PADDLE_VAL_1 <= PADDLE_VAL_1 + 1'b1;
if(PADDLE_VAL_1 == 12'd4094)
PADDLE_STATE_1 <= 2'b10;
else
begin
if(JOY_TRIGGER)
PADDLE_STATE_1 <= 2'b10;
else
PADDLE_STATE_1 <= 2'b01;
end
end
2'b10:
begin
JOY2_COUNT <= PADDLE_VAL_1[11:6];
PADDLE_LATCH_1 <= PADDLE_VAL_1;
if(JOY_TRIGGER)
PADDLE_STATE_1 <= 2'b11;
end
2'b11:
begin
if(!JOY_TRIGGER)
PADDLE_STATE_1 <= 2'b00;
end
endcase
end
end
always @(negedge PADDLE_CLK[2] or negedge RESET_N)
begin
if(~RESET_N)
begin
PADDLE_ZERO_2 <= 10'd0000;
PADDLE_VAL_2 <= 12'd0000;
PADDLE_STATE_2 <= 2'b00;
JOY3_COUNT <= 6'h00;
end
else
begin
case(PADDLE_STATE_2)
2'b00:
begin
PADDLE_ZERO_2 <= PADDLE_ZERO_2 + 1'b1;
PADDLE_VAL_2 <= 12'd0000;
if(PADDLE_ZERO_2 == 10'd611)
PADDLE_STATE_2 <= 2'b01;
end
2'b01:
begin
PADDLE_ZERO_2 <= 10'd000;
PADDLE_VAL_2 <= PADDLE_VAL_2 + 1'b1;
if(PADDLE_VAL_2 == 12'd4094)
PADDLE_STATE_2 <= 2'b10;
else
begin
if(JOY_TRIGGER)
PADDLE_STATE_2 <= 2'b10;
else
PADDLE_STATE_2 <= 2'b01;
end
end
2'b10:
begin
JOY3_COUNT <= PADDLE_VAL_2[11:6];
PADDLE_LATCH_2 <= PADDLE_VAL_2;
if(JOY_TRIGGER)
PADDLE_STATE_2 <= 2'b11;
end
2'b11:
begin
if(!JOY_TRIGGER)
PADDLE_STATE_2 <= 2'b00;
end
endcase
end
end
always @(negedge PADDLE_CLK[3] or negedge RESET_N)
begin
if(~RESET_N)
begin
PADDLE_ZERO_3 <= 10'd0000;
PADDLE_VAL_3 <= 12'd0000;
PADDLE_STATE_3 <= 2'b00;
JOY4_COUNT <= 6'h00;
end
else
begin
case(PADDLE_STATE_3)
2'b00:
begin
PADDLE_ZERO_3 <= PADDLE_ZERO_3 + 1'b1;
PADDLE_VAL_3 <= 12'd0000;
if(PADDLE_ZERO_3 == 10'd611)
PADDLE_STATE_3 <= 2'b01;
end
2'b01:
begin
PADDLE_ZERO_3 <= 10'd000;
PADDLE_VAL_3 <= PADDLE_VAL_3 + 1'b1;
if(PADDLE_VAL_3 == 12'd4094)
PADDLE_STATE_3 <= 2'b10;
else
begin
if(JOY_TRIGGER)
PADDLE_STATE_3 <= 2'b10;
else
PADDLE_STATE_3 <= 2'b01;
end
end
2'b10:
begin
JOY4_COUNT <= PADDLE_VAL_3[11:6];
PADDLE_LATCH_3 <= PADDLE_VAL_3;
if(JOY_TRIGGER)
PADDLE_STATE_3 <= 2'b11;
end
2'b11:
begin
if(!JOY_TRIGGER)
PADDLE_STATE_3 <= 2'b00;
end
endcase
end
end
assign JSTICK = (SEL == 2'b11) ? JOY3: // Left Y
(SEL == 2'b10) ? JOY4: // Left X
(SEL == 2'b01) ? JOY1: // Right Y
// (SEL == 2'b000) ? JOY2: // Right X
// (SEL == 2'b111) ? JOY1: // Right Y
// (SEL == 2'b110) ? JOY2: // Right X
// (SEL == 2'b101) ? JOY3: // Left Y
// JOY4; // Left X
JOY2; // Right X
assign JOY1 = (JOY1_COUNT >= DTOA_CODE) ? 1'b1:
1'b0;
assign JOY2 = (JOY2_COUNT >= DTOA_CODE) ? 1'b1:
1'b0;
assign JOY3 = (JOY3_COUNT >= DTOA_CODE) ? 1'b1:
1'b0;
assign JOY4 = (JOY4_COUNT >= DTOA_CODE) ? 1'b1:
1'b0;