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-22 The problem which missile didn't sometimes come out from was improved.
18 //================================================================================
19 //-----------------------------------------------------------------------------------------
20 // H_CNT[0],H_CNT[1],H_CNT[2],H_CNT[3],H_CNT[4],H_CNT[5],H_CNT[6],H_CNT[7],H_CNT[8],
21 // 1 H 2 H 4H 8H 16 H 32H 64 H 128 H 256 H
22 //-----------------------------------------------------------------------------------------
23 // V_CNT[0], V_CNT[1], V_CNT[2], V_CNT[3], V_CNT[4], V_CNT[5], V_CNT[6], V_CNT[7]
24 // 1 V 2 V 4 V 8 V 16 V 32 V 64 V 128 V
25 //-----------------------------------------------------------------------------------------
76 input [2:0]I_OBJ_SUB_A;
83 output [10:0]O_OBJ_ROM_A;
84 input [7:0]I_OBJ_ROM_A_D;
85 input [7:0]I_OBJ_ROM_B_D;
116 always@(negedge I_CLK_12M)
119 W_CNTRLDn <= WB_CNTRLDn;
120 W_CNTRCLRn <= WB_CNTRCLRn;
123 W_OBJDATALn <= WB_OBJDATALn;
130 .I_CLK_6M(~I_CLK_6M),
135 .O_CNTRLDn(WB_CNTRLDn),
136 .O_CNTRCLRn(WB_CNTRCLRn),
139 .O_OBJDATALn(WB_OBJDATALn),
145 wire W_H_FLIP1 = ~I_H_CNT[8]&I_H_FLIP;
147 wire [7:3]W_HF_CNT = I_H_CNT[7:3]^{5{W_H_FLIP1}};
148 wire [7:0]W_VF_CNT = I_V_CNT[7:0]^{8{I_V_FLIP}};
150 assign O_8HF = W_HF_CNT[3];
151 assign O_1VF = W_VF_CNT[0];
154 wire [3:0]W_6J_DA = {I_H_FLIP , W_HF_CNT[7],W_HF_CNT[3],I_H_CNT[2]};
155 wire [3:0]W_6J_DB = {W_OBJ_D[6],W_HF_CNT[3]&I_H_CNT[1], I_H_CNT[2],I_H_CNT[1]};
156 wire [3:0]W_6J_Q = I_H_CNT[8] ? W_6J_DB:W_6J_DA;
158 wire W_H_FLIP2 = W_6J_Q[3];
160 wire [7:0]W_OBJ_RAM_AB = {1'b0,I_H_CNT[8],W_6J_Q[2],W_HF_CNT[6:4],W_6J_Q[1:0]};
161 wire [7:0]W_OBJ_RAM_A = I_OBJ_RAM_RQn ? W_OBJ_RAM_AB: I_A[7:0] ;
163 wire [7:0]W_OBJ_RAM_DOA,W_OBJ_RAM_DOB;
166 always@(posedge I_CLK_12M) W_H_POSI <= W_OBJ_RAM_DOB;
172 .I_WEA(~I_OBJ_RAM_WRn),
173 .I_CEA(~I_OBJ_RAM_RQn),
175 .O_DA(W_OBJ_RAM_DOA),
178 .I_ADDRB(W_OBJ_RAM_AB),
186 wire [7:0]W_OBJ_RAM_D = I_OBJ_RAM_RDn ? 8'h00: W_OBJ_RAM_DOA;
188 always@(posedge W_OBJDATALn) W_OBJ_D <= W_H_POSI;
191 wire [8:0]W_45N_Q = W_VF_CNT[7:0] + W_H_POSI ;
192 assign W_3D = ~(&W_45N_Q[7:0]);
195 always@(posedge W_VPLn or negedge I_V_BLn)
200 W_2M_Q <= W_45N_Q[7:0];
203 wire W_2N = I_H_CNT[8]&W_OBJ_D[7];
204 wire [3:0]W_1M = W_2M_Q[3:0]^{W_2N,W_2N,W_2N,W_2N};
206 wire W_VID_RAM_CSn = I_VID_RAM_RDn & I_VID_RAM_WRn;
208 wire [7:0]W_VID_RAM_DI = I_VID_RAM_WRn ? 8'h00 : I_BD ;
209 wire [7:0]W_VID_RAM_DOA;
211 wire [11:0]W_VID_RAM_AA = {~(&W_2M_Q[7:4]),W_VID_RAM_CSn, 10'h00 /*I_A[9:0]*/};
212 wire [11:0]W_VID_RAM_AB = { 1'b0, 1'b0,W_2M_Q[7:4],W_1M[3],W_HF_CNT[7:3]};
214 wire [11:0]W_VID_RAM_A = I_C_BLn ? W_VID_RAM_AB:W_VID_RAM_AA;
216 wire [7:0]W_VID_RAM_D = I_VID_RAM_RDn ? 8'h00 :W_VID_RAM_DOA;
218 wire [7:0]W_VID_RAM_DOB;
225 .I_WEA(~I_VID_RAM_WRn),
226 .I_CEA(~W_VID_RAM_CSn),
227 .O_DA(W_VID_RAM_DOA),
230 .I_ADDRB(W_VID_RAM_A[9:0]),
237 //-- VIDEO DATA OUTPUT --------------
238 assign O_BD = W_OBJ_RAM_D | W_VID_RAM_D;
240 wire W_SRLD = ~(W_LDn | W_VID_RAM_A[11]);
242 wire [7:0]W_OBJ_ROM_AB = {W_OBJ_D[5:0],W_1M[3],W_OBJ_D[6]^I_H_CNT[3]};
244 wire [7:0]W_OBJ_ROM_A = I_H_CNT[8] ? W_OBJ_ROM_AB: W_VID_RAM_DOB;
246 assign O_OBJ_ROM_A = {W_OBJ_ROM_A,W_1M[2:0]};
248 wire [7:0]W_1K_D = I_OBJ_ROM_A_D;
249 wire [7:0]W_1H_D = I_OBJ_ROM_B_D;
251 //---------------------------------------------------------------------------------
252 wire W_2L_Qa,W_2K_Qd;
253 wire W_2J_Qa,W_2H_Qd;
256 wire [3:0]W_3L_A = {W_2J_Qa,W_2L_Qa, 1'b1,W_SRLD};
257 wire [3:0]W_3L_B = {W_2H_Qd,W_2K_Qd,W_SRLD, 1'b1};
258 wire [3:0]W_3L_Y = W_H_FLIP2X ? W_3L_B: W_3L_A; // [3]=RAW1,[2]=RAW0
260 wire W_RAW0 = W_3L_Y[2];
261 wire W_RAW1 = W_3L_Y[3];
263 wire W_SRCLK = I_CLK_6M;
264 //------ PARTS 2KL ----------------------------------------------
265 wire [1:0]C_2KL = W_3L_Y[1:0];
266 wire [7:0]I_2KL = W_1K_D;
269 assign W_2L_Qa = reg_2KL[7];
270 assign W_2K_Qd = reg_2KL[0];
271 always@(posedge W_SRCLK)
274 2'b00: reg_2KL <= reg_2KL;
275 2'b10: reg_2KL <= {reg_2KL[6:0],1'b0};
276 2'b01: reg_2KL <= {1'b0,reg_2KL[7:1]};
277 2'b11: reg_2KL <= I_2KL;
280 //------ PARTS 2HJ ----------------------------------------------
281 wire [1:0]C_2HJ = W_3L_Y[1:0];
282 wire [7:0]I_2HJ = W_1H_D;
285 assign W_2J_Qa = reg_2HJ[7];
286 assign W_2H_Qd = reg_2HJ[0];
287 always@(posedge W_SRCLK)
290 2'b00: reg_2HJ <= reg_2HJ;
291 2'b10: reg_2HJ <= {reg_2HJ[6:0],1'b0};
292 2'b01: reg_2HJ <= {1'b0,reg_2HJ[7:1]};
293 2'b11: reg_2HJ <= I_2HJ;
297 //----- SHT2 -----------------------------------------------------
300 always@(posedge W_COLLn) W_6K_Q <= W_H_POSI[2:0];
304 always@(posedge I_CLK_6M)
306 if(W_LDn==1'b0) W_6P_Q <= {W_H_FLIP2,W_H_FLIP1,I_C_BLn,~I_H_CNT[8],W_6K_Q[2:0]};
307 else W_6P_Q <= W_6P_Q;
310 assign W_H_FLIP2X = W_6P_Q[6];
311 wire W_H_FLIP1X = W_6P_Q[5];
312 wire W_C_BLnX = W_6P_Q[4];
313 wire W_256HnX = W_6P_Q[3];
314 wire [2:0]W_CD = W_6P_Q[2:0];
316 assign O_256HnX = W_256HnX;
317 assign O_C_BLnX = W_C_BLnX;
319 wire W_45T_CLR = W_CNTRCLRn | W_256HnX ;
322 always@(posedge I_CLK_6M)
326 else if(W_CNTRLDn==1'b0)
329 W_45T_Q <= W_45T_Q + 1;
332 wire [7:0]W_LRAM_A = W_45T_Q^{8{W_H_FLIP1X}};
333 wire W_LRAM_WE = ~I_CLK_6M;
340 wire W_1U_CLK = ~I_CLK_6M;
342 always@(posedge W_1U_CLK)
344 W_RV <= W_LRAM_DO[1:0];
345 W_RC <= W_LRAM_DO[4:2];
348 wire W_LRAM_AND = ~(~((W_LRAM_A[4]|W_LRAM_A[5])|(W_LRAM_A[6]|W_LRAM_A[7]))|W_256HnX );
349 wire W_RAW_OR = W_RAW0 | W_RAW1 ;
354 assign W_VID[0] = ~(~(W_RAW0&W_RV[1])&W_RV[0]);
355 assign W_VID[1] = ~(~(W_RAW1&W_RV[0])&W_RV[1]);
356 assign W_COL[0] = ~(~(W_RAW_OR&W_CD[0]&W_RC[1]&W_RC[2])&W_RC[0]);
357 assign W_COL[1] = ~(~(W_RAW_OR&W_CD[1]&W_RC[2]&W_RC[0])&W_RC[1]);
358 assign W_COL[2] = ~(~(W_RAW_OR&W_CD[2]&W_RC[0]&W_RC[1])&W_RC[2]);
360 assign O_VID = W_VID;
361 assign O_COL = W_COL;
363 assign W_LRAM_DI[0] = W_LRAM_AND&W_VID[0];
364 assign W_LRAM_DI[1] = W_LRAM_AND&W_VID[1];
365 assign W_LRAM_DI[2] = W_LRAM_AND&W_COL[0];
366 assign W_LRAM_DI[3] = W_LRAM_AND&W_COL[1];
367 assign W_LRAM_DI[4] = W_LRAM_AND&W_COL[2];
381 .I_CLK_18M(I_CLK_18M),
383 .I_C_BLn_X(W_C_BLnX),
388 .O_MISSILEn(O_MISSILEn),