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

Subversion Repositories aoocs

[/] [aoocs/] [trunk/] [rtl/] [ocs_input.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/*
2
 * Copyright 2010, Aleksander Osman, alfik@poczta.fm. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without modification, are
5
 * permitted provided that the following conditions are met:
6
 *
7
 *  1. Redistributions of source code must retain the above copyright notice, this list of
8
 *     conditions and the following disclaimer.
9
 *
10
 *  2. Redistributions in binary form must reproduce the above copyright notice, this list
11
 *     of conditions and the following disclaimer in the documentation and/or other materials
12
 *     provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 */
24
 
25
/*! \file
26
 * \brief OCS user input implementation with WISHBONE slave interface.
27
 */
28
 
29
/*! \brief \copybrief ocs_input.v
30
 
31
List of user input registers:
32
\verbatim
33
Implemented:
34
     [DSKDATR & *008  ER  P       Disk data early read (dummy address)          not implemented]
35
    JOY0DAT     *00A  R   D       Joystick-mouse 0 data (vert,horiz)            read implemented here
36
 
37
    JOY1DAT     *00C  R   D       Joystick-mouse 1 data (vert,horiz)            read implemented here
38
     [CLXDAT    *00E  R   D       Collision data register (read and clear)      read implemented here]
39
 
40
    JOYTEST     *036  W   D       Write to all four joystick-mouse counters at once
41
 
42
Not implemented:
43
     [ADKCONR   *010  R   P       Audio, disk control register read             read not implemented here]
44
    POT0DAT     *012  R   P( E )  Pot counter pair 0 data (vert,horiz)          read not implemented here
45
 
46
    POT1DAT     *014  R   P( E )  Pot counter pair 1 data (vert,horiz)
47
    POTGOR      *016  R   P       Pot port data read (formerly POTINP)
48
    POTGO       *034  W   P       Pot port data write and start
49
\endverbatim
50
*/
51
module ocs_input(
52
    //% \name Clock and reset
53
    //% @{
54
    input               CLK_I,
55
    input               reset_n,
56
    //% @}
57
 
58
    //% \name On-Screen-Display management interface
59
    //% @{
60
    input               on_screen_display,
61
    input               enable_joystick_1,
62
    //% @}
63
 
64
    //% \name WISHBONE slave
65
    //% @{
66
    input               CYC_I,
67
    input               STB_I,
68
    input               WE_I,
69
    input [8:2]         ADR_I,
70
    input [3:0]         SEL_I,
71
    input [31:0]        DAT_I,
72
    output reg [31:0]   DAT_O,
73
    output reg          ACK_O,
74
    //% @}
75
 
76
    //% \name Not aligned register access on a 32-bit WISHBONE bus
77
    //% @{
78
        // CLXDAT read implemented here
79
    output              na_clx_dat_read,
80
    input [15:0]        na_clx_dat,
81
        // POT0DAT read not implemented here
82
    input               na_pot0dat_read,
83
    output [15:0]       na_pot0dat,
84
    //% @}
85
 
86
    //% \name User input CIA interface
87
    //% @{
88
    // keyboard output
89
    input               sp_from_cia,
90
    output              sp_to_cia,
91
    output reg          cnt_to_cia,
92
 
93
    // CIA-A fire buttons
94
    output reg          ciaa_fire_0_n,
95
    output              ciaa_fire_1_n,
96
    //% @}
97
 
98
    //% \name drv_keyboard interface
99
    //% @{
100
    output              keyboard_ready,
101
    input               keyboard_event,
102
    input [7:0]         keyboard_scancode,
103
 
104
    // joystick on port 1
105
    input               joystick_1_up,
106
    input               joystick_1_down,
107
    input               joystick_1_left,
108
    input               joystick_1_right,
109
    input               joystick_1_fire,
110
    //% @}
111
 
112
    //% \name drv_mouse interface
113
    //% @{
114
    input               mouse_moved,
115
    input [8:0]         mouse_y_move,
116
    input [8:0]         mouse_x_move,
117
    input               mouse_left_button,
118
    input               mouse_right_button,
119
    input               mouse_middle_button
120
    //% @}
121
);
122
 
123
//-------------------- keyboard start
124
assign sp_to_cia = ~sp_shift[7];
125
 
126
assign keyboard_ready = (cnt_counter == 16'd0);
127
 
128
 
129
reg [15:0] cnt_counter;
130
reg [7:0] sp_shift;
131
always @(posedge CLK_I or negedge reset_n) begin
132
    if(reset_n == 1'b0) begin
133
        cnt_to_cia  <= 1'b1;
134
        cnt_counter <= 16'd0;
135
        sp_shift    <= 8'hFF;
136
    end
137
    else if(keyboard_event == 1'b1 && on_screen_display == 1'b0) begin
138
        sp_shift <= keyboard_scancode;
139
        cnt_counter <= cnt_counter + 16'd1;
140
        cnt_to_cia <= 1'b0;
141
    end
142
    else if(cnt_counter >= 16'd1 && cnt_counter <= 16'd15) begin
143
        cnt_counter <= cnt_counter + 16'd1;
144
        cnt_to_cia <= ~cnt_to_cia;
145
        if(cnt_to_cia == 1'b1) sp_shift <= { sp_shift[6:0], 1'b0 };
146
    end
147
    else if(cnt_counter == 16'd16 && sp_from_cia == 1'b0) begin
148
        cnt_counter <= cnt_counter + 16'd1;
149
    end
150
    else if(cnt_counter == 16'd17 && sp_from_cia == 1'b1) begin
151
        cnt_counter <= 16'd0;
152
    end
153
/*  synchronization
154
    else if(cnt_counter == 16'd65535 && sp_from_cia == 1'b1) begin
155
        cnt_to_cia <= ~cnt_to_cia;
156
        cnt_counter <= 16'd16;
157
    end
158
    else if(cnt_counter >= 16'd16 && sp_from_cia == 1'b1) begin
159
        cnt_counter <= cnt_counter + 16'd1;
160
    end
161
    else sp_from_cia == 1'b0 -> sp_from_cia == 1'b0 begin
162
        cnt_counter <= 16'd0;
163
    end
164
*/
165
end
166
//-------------------- keyboard end
167
 
168
 
169
assign na_pot0dat = 16'd0;
170
 
171
assign na_clx_dat_read =
172
    (CYC_I == 1'b1 && STB_I == 1'b1 && ACK_O == 1'b0 && WE_I == 1'b0 && { ADR_I, 2'b0 } == 9'h018 && SEL_I[1:0] != 2'b00);
173
 
174
reg [15:0] potgo;
175
reg [15:0] joy0dat;
176
reg [15:0] joy1dat;
177
reg right_button_n;
178
reg middle_button_n;
179
 
180
wire [15:0] joy1dat_final;
181
assign joy1dat_final =
182
    (enable_joystick_1 == 1'b1)?
183
    {   6'b0,                               //15-10
184
        joystick_1_left,                    //9
185
        joystick_1_up ^ joystick_1_left,    //8
186
        6'b0,                               //7-2
187
        joystick_1_right,                   //1
188
        joystick_1_down ^ joystick_1_right  //0
189
    } :
190
    joy1dat;
191
 
192
assign ciaa_fire_1_n = (enable_joystick_1 == 1'b1 && joystick_1_fire == 1'b1)? 1'b0 : 1'b1;
193
 
194
wire [15:0] potgo_final;
195
assign potgo_final = { 1'b0, potgo[14], 1'b0, potgo[12], 1'b0, right_button_n, 1'b0, middle_button_n, 7'b0, 1'b0 };
196
 
197
wire [8:0] joy0dat_y;
198
assign joy0dat_y = { joy0dat[15], joy0dat[15:8] } - mouse_y_move;
199
 
200
wire [8:0] joy0dat_x;
201
assign joy0dat_x = { joy0dat[7], joy0dat[7:0] } + mouse_x_move;
202
 
203
always @(posedge CLK_I or negedge reset_n) begin
204
    if(reset_n == 1'b0) begin
205
        DAT_O           <= 32'd0;
206
        ACK_O           <= 1'b0;
207
 
208
        ciaa_fire_0_n   <= 1'b1;
209
 
210
        potgo           <= 16'd0;
211
        joy0dat         <= 16'd0;
212
        joy1dat         <= 16'd0;
213
 
214
        right_button_n  <= 1'b1;
215
        middle_button_n <= 1'b1;
216
    end
217
    else begin
218
        if(CYC_I == 1'b1 && STB_I == 1'b1 && ACK_O == 1'b0) ACK_O <= 1'b1;
219
        else                                                ACK_O <= 1'b0;
220
 
221
        if(mouse_moved == 1'b1) begin
222
            joy0dat[15:8] <= joy0dat_y[7:0];
223
            joy0dat[7:0] <= joy0dat_x[7:0];
224
 
225
            ciaa_fire_0_n   <= ~mouse_left_button;
226
            right_button_n  <= ~mouse_right_button;
227
            middle_button_n <= ~mouse_middle_button;
228
        end
229
 
230
        if(CYC_I == 1'b1 && STB_I == 1'b1 && WE_I == 1'b0) begin
231
            if({ ADR_I, 2'b0 } == 9'h008)                       DAT_O[31:0]     <= { 16'd0 /*DSKDATR*/, joy0dat };
232
            if({ ADR_I, 2'b0 } == 9'h00C)                       DAT_O[31:0]     <= { joy1dat_final, na_clx_dat };
233
            if({ ADR_I, 2'b0 } == 9'h014)                       DAT_O[31:0]     <= { 16'd0 /*POT1DAT*/, potgo_final };
234
        end
235
        else if(CYC_I == 1'b1 && STB_I == 1'b1 && WE_I == 1'b1) begin
236
            if({ ADR_I, 2'b0 } == 9'h034 && SEL_I[3] == 1'b1)   potgo[15:8] <= DAT_I[31:24];
237
            if({ ADR_I, 2'b0 } == 9'h034 && SEL_I[2] == 1'b1)   potgo[7:0]  <= DAT_I[23:16];
238
            if({ ADR_I, 2'b0 } == 9'h034 && SEL_I[1] == 1'b1)   { joy0dat[15:8], joy1dat[15:8] } <= { DAT_I[15:8], DAT_I[15:8] };
239
            if({ ADR_I, 2'b0 } == 9'h034 && SEL_I[0] == 1'b1)   { joy0dat[7:0], joy1dat[7:0] } <= { DAT_I[7:0], DAT_I[7:0] };
240
        end
241
    end
242
end
243
 
244
endmodule

powered by: WebSVN 2.1.0

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