1 //===============================================================================
6 // Copyright(c) 2004 Katsumi Degawa , All rights reserved
10 // This program is freeware for non-commercial use.
11 // An author does no guarantee about this program.
12 // You can use this under your own risk.
14 // 2004- 4-30 galaxian modify by K.DEGAWA
15 // 2004- 5- 6 first release.
16 // 2004- 8-23 Improvement with T80-IP.
17 // 2004- 9-18 The description of ALTERA(CYCLONE) and XILINX(SPARTAN2E) was made one.
18 // 2004- 9-22 The problem which missile didn't sometimes come out from was improved.
19 //================================================================================
21 `include "src/mc_conf.v"
73 wire W_CPU_HRDWR_RESETn;
80 output psTXD,psCLK,psSEL;
84 //output [18:0]O_ROM_AB;
85 //input [7:0]I_ROM_DB;
101 output O_VGA_H_SYNCn;
102 output O_VGA_V_SYNCn;
104 wire W_RESETn = |(~I_PSW[8:5]);
105 //------ CLOCK GEN ---------------------------
107 wire W_CLK_12M,WB_CLK_12M;
108 wire W_CLK_6M,WB_CLK_6M;
112 .CLKIN_IN(I_CLK_125M),
114 .CLKFX_OUT(I_CLK_18432M)
117 //------ H&V COUNTER -------------------------
126 //------ CPU RAM ----------------------------
127 wire [7:0]W_CPU_RAM_DO;
129 //------ ADDRESS DECDER ----------------------
151 wire W_VID_RDn = W_OBJ_RAM_RDn & W_VID_RAM_RDn ;
152 wire W_SW_OEn = W_SW0_OEn & W_SW1_OEn & W_DIP_OEn ;
153 //------- INPORT -----------------------------
155 //------- VIDEO -----------------------------
157 //--------------------------------------------
161 .I_CLK_18M(I_CLK_18432M),
162 .O_CLK_12M(WB_CLK_12M),
163 .O_CLK_06M(WB_CLK_6M)
167 `ifdef DEVICE_CYCLONE
168 assign W_CLK_12M = WB_CLK_12M;
169 assign W_CLK_6M = WB_CLK_6M;
171 `ifdef DEVICE_SPARTAN2E
172 BUFG BUFG_12MHz( .I(WB_CLK_12M),.O(W_CLK_12M) );
173 BUFG BUFG_6MHz ( .I(WB_CLK_6M ),.O(W_CLK_6M ) );
175 //--- DATA I/F -------------------------------------
176 reg [7:0]W_CPU_ROM_DO;
177 wire [7:0]W_CPU_ROM_DOB = W_CPU_ROM_CSn ? 8'h00: W_CPU_ROM_DO ;
179 wire [7:0]W_BDO = W_SW_DO | W_VID_DO | W_CPU_RAM_DO | W_CPU_ROM_DOB ;
182 //--- CPU I/F -------------------------------------
184 always@(posedge W_H_CNT[0] or negedge W_RESETn)
186 if(! W_RESETn) rst_count <= 0;
189 rst_count <= rst_count;
191 rst_count <= rst_count+1;
195 assign W_CPU_RESETn = W_RESETn;
196 assign W_CPU_CLK = W_H_CNT[0];
201 .RESET_N(W_CPU_RESETn),
208 .MREQ_N(W_CPU_MREQn),
212 .WAIT_N(W_CPU_WAITn),
214 .RFSH_N(W_CPU_RFSHn),
219 wire W_CPU_RAM_CLK = W_CLK_12M & ~W_CPU_RAM_CSn;
221 mc_cpu_ram MC_CPU_RAM(
223 .I_CLK(W_CPU_RAM_CLK),
227 .I_OE(~W_CPU_RAM_RDn ),
235 .I_CLK_12M(W_CLK_12M),
237 .I_CPU_CLK(W_H_CNT[0]),
242 .I_MREQn(W_CPU_MREQn),
243 .I_RFSHn(W_CPU_RFSHn),
249 .O_WAITn(W_CPU_WAITn),
251 .O_CPU_ROM_CSn(W_CPU_ROM_CSn),
252 .O_CPU_RAM_RDn(W_CPU_RAM_RDn),
253 .O_CPU_RAM_WRn(W_CPU_RAM_WRn),
254 .O_CPU_RAM_CSn(W_CPU_RAM_CSn),
255 .O_OBJ_RAM_RDn(W_OBJ_RAM_RDn),
256 .O_OBJ_RAM_WRn(W_OBJ_RAM_WRn),
257 .O_OBJ_RAM_RQn(W_OBJ_RAM_RQn),
258 .O_VID_RAM_RDn(W_VID_RAM_RDn),
259 .O_VID_RAM_WRn(W_VID_RAM_WRn),
260 .O_SW0_OEn(W_SW0_OEn),
261 .O_SW1_OEn(W_SW1_OEn),
262 .O_DIP_OEn(W_DIP_OEn),
263 .O_WDR_OEn(W_WDR_OEn),
264 .O_LAMP_WEn(W_LAMP_WEn),
265 .O_SOUND_WEn(W_SOUND_WEn),
270 .O_STARS_ON(W_STARS_ON)
274 //-------- SOUND I/F -----------------------------
275 //--- Parts 9L ---------
277 always@(posedge W_CLK_12M or negedge W_RESETn)
279 if(W_RESETn == 1'b0)begin
283 if(W_SOUND_WEn == 1'b0)begin
285 3'h0 : W_9L_Q[0] <= W_BDI[0];
286 3'h1 : W_9L_Q[1] <= W_BDI[0];
287 3'h2 : W_9L_Q[2] <= W_BDI[0];
288 3'h3 : W_9L_Q[3] <= W_BDI[0];
289 3'h4 : W_9L_Q[4] <= W_BDI[0];
290 3'h5 : W_9L_Q[5] <= W_BDI[0];
291 3'h6 : W_9L_Q[6] <= W_BDI[0];
292 3'h7 : W_9L_Q[7] <= W_BDI[0];
297 wire W_VOL1 = W_9L_Q[6];
298 wire W_VOL2 = W_9L_Q[7];
299 wire W_FIRE = W_9L_Q[5];
300 wire W_HIT = W_9L_Q[3];
301 wire W_FS3 = W_9L_Q[2];
302 wire W_FS2 = W_9L_Q[1];
303 wire W_FS1 = W_9L_Q[0];
304 //---------------------------------------------------
305 //---- CPU DATA WATCH -------------------------------
306 wire ZMWR = W_CPU_MREQn | W_CPU_WRn ;
309 always @(posedge W_CPU_CLK)
312 if(W_A == 16'h4007)begin
318 if(W_A == 16'h4005)begin
319 if(W_BDI == 8'h03 || W_BDI == 8'h04 )
329 always @(posedge W_CPU_CLK)
332 if(W_A == 16'h4206)begin
340 //---- PS_PAD Interface -----------------------------
342 wire VIB_SW = died & (&on_game[1:0]);
344 fpga_arcade_if pspad(
346 .CLK_18M432(I_CLK_18432M),
357 //---- SW Interface ---------------------------------
359 wire L1 = I_PSW[2] & ps_PSW[2];
360 wire R1 = I_PSW[3] & ps_PSW[3];
363 wire J1 = I_PSW[4] & ps_PSW[8];
365 wire S1 = (U1|J1) & ps_PSW[6];
366 wire S2 = (D1|J1) & ps_PSW[7];
368 wire C1 = (L1|R1|U1|~D1) & ps_PSW[4];
370 wire L1 = ! I_PSW[2];
371 wire R1 = ! I_PSW[3];
372 wire U1 = ! I_PSW[0];
373 wire D1 = ! I_PSW[1];
374 wire J1 = ! I_PSW[4];
376 wire S1 = ! I_PSW[5];
377 wire S2 = ! I_PSW[7];
379 wire C1 = ! I_PSW[6];
381 wire C2 = ! I_PSW[8];
391 .I_COIN1(~C1), // ACTIVE HI
392 .I_COIN2(~C2), // ACTIVE HI
393 .I_1P_LE(~L1), // ACTIVE HI
394 .I_1P_RI(~R1), // ACTIVE HI
395 .I_1P_SH(~J1), // ACTIVE HI
396 .I_2P_LE(~L2), // ACTIVE HI
397 .I_2P_RI(~R2), // ACTIVE HI
398 .I_2P_SH(~J2), // ACTIVE HI
399 .I_1P_START(~S1), // ACTIVE HI
400 .I_2P_START(~S2), // ACTIVE HI
402 .I_SW0_OEn(W_SW0_OEn),
403 .I_SW1_OEn(W_SW1_OEn),
404 .I_DIP_OEn(W_DIP_OEn),
410 //-----------------------------------------------------------------------------
411 //------- ROM -------------------------------------------------------
413 wire [10:0]W_OBJ_ROM_A;
414 reg [7:0]W_OBJ_ROM_A_D;
415 reg [7:0]W_OBJ_ROM_B_D;
417 wire [18:0]W_WAV_A0,W_WAV_A1,W_WAV_A2;
418 reg [7:0]W_WAV_D0,W_WAV_D1,W_WAV_D2;
420 wire [7:0]ROM_D; // = I_ROM_DB;
421 //assign O_ROM_AB = ROM_A;
423 //assign O_ROM_OEn = 1'b0;
424 //assign O_ROM_CSn = 1'b0;
425 //assign O_ROM_WEn = 1'b1;
428 .I_CLK_18432M(I_CLK_18432M),
429 .I_CLK_12M(WB_CLK_12M),
437 always @(posedge I_CLK_18432M)
439 // 24 phase generator
440 clk_d[0] <= W_H_CNT[0] & W_H_CNT[1] & W_H_CNT[2];
441 clk_d[1] <= clk_d[0];
442 seq <= (~clk_d[1] & clk_d[0]) ? 0 : seq+1;
447 W_CPU_ROM_DO <= ROM_D;
456 ROM_A <= {3'h0,W_A[15:0]};
462 W_CPU_ROM_DO <= ROM_D;
464 8:W_WAV_D2 <= ROM_D; //sound
465 10:ROM_A <= {3'h0,W_A[15:0]};
466 12:W_CPU_ROM_DO <= ROM_D;
467 16:ROM_A <= {3'h0,W_A[15:0]};
469 ROM_A <= {3'h0,4'h4,1'b0,W_OBJ_ROM_A};
470 W_CPU_ROM_DO <= ROM_D;
473 ROM_A <= {3'h0,4'h5,1'b0,W_OBJ_ROM_A};
474 W_OBJ_ROM_A_D <= ROM_D;
477 ROM_A <= {3'h0,W_A[15:0]};
478 W_OBJ_ROM_B_D <= ROM_D;
483 //-----------------------------------------------------------------------------
503 //------ VIDEO -----------------------------
514 .I_CLK_18M(I_CLK_18432M),
515 .I_CLK_12M(W_CLK_12M),
525 .I_OBJ_SUB_A(3'b000),
527 .I_OBJ_RAM_RQn(W_OBJ_RAM_RQn),
528 .I_OBJ_RAM_RDn(W_OBJ_RAM_RDn),
529 .I_OBJ_RAM_WRn(W_OBJ_RAM_WRn),
530 .I_VID_RAM_RDn(W_VID_RAM_RDn),
531 .I_VID_RAM_WRn(W_VID_RAM_WRn),
533 .O_OBJ_ROM_A(W_OBJ_ROM_A),
534 .I_OBJ_ROM_A_D(W_OBJ_ROM_A_D),
535 .I_OBJ_ROM_B_D(W_OBJ_ROM_B_D),
541 .O_MISSILEn(W_MISSILEn),
555 mc_col_pal MC_COL_PAL(
557 .I_CLK_12M(W_CLK_12M),
564 .O_STARS_OFFn(W_STARS_OFFn),
577 .I_CLK_18M(I_CLK_18432M),
578 `ifdef DEVICE_CYCLONE
579 .I_CLK_6M(~WB_CLK_6M),
581 `ifdef DEVICE_SPARTAN2E
582 .I_CLK_6M(WB_CLK_6M),
590 .I_STARS_ON(W_STARS_ON),
591 .I_STARS_OFFn(W_STARS_OFFn),
613 .I_C_BLnXX(~W_C_BLX),
614 .I_C_BLX(W_C_BLX | ~W_V_BL2n),
615 .I_MISSILEn(W_MISSILEn),
639 .O_H_SYNCn(O_VGA_H_SYNCn),
640 .O_V_SYNCn(O_VGA_V_SYNCn)
646 assign O_VGA_R[2:0] = W_R;
648 assign O_VGA_G[2:0] = W_G;
650 assign O_VGA_B[1:0] = W_B;
652 //assign O_VGA_H_SYNCn = W_H_SYNC | W_V_SYNC ; // AKIDUKI LCD USED
653 assign O_VGA_H_SYNCn = ~W_H_SYNC ;
654 assign O_VGA_V_SYNCn = ~W_V_SYNC ;
660 mc_sound_a MC_SOUND_A(
662 .I_CLK_12M(W_CLK_12M),
664 .I_H_CNT1(W_H_CNT[1]),
677 mc_sound_b MC_SOUND_B(
679 .I_CLK1(I_CLK_18432M),
681 .I_RSTn(rst_count[3]),
682 .I_SW({&on_game[1:0],W_HIT,W_FIRE}),
698 assign O_SOUND_OUT_L = W_DAC_A;
699 assign O_SOUND_OUT_R = W_DAC_B;