Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --------------------------------------------------------------------
- // Copyright (c) 2007 by Terasic Technologies Inc.
- // --------------------------------------------------------------------
- //
- // Permission:
- //
- // Terasic grants permission to use and modify this code for use
- // in synthesis for all Terasic Development Boards and Altera Development
- // Kits made by Terasic. Other use of this code, including the selling
- // ,duplication, or modification of any portion is strictly prohibited.
- //
- // Disclaimer:
- //
- // This VHDL/Verilog or C/C++ source code is intended as a design reference
- // which illustrates how these types of functions can be implemented.
- // It is the user's responsibility to verify their design for
- // consistency and functionality through the use of formal
- // verification methods. Terasic provides no warranty regarding the use
- // or functionality of this code.
- //
- // --------------------------------------------------------------------
- //
- // Terasic Technologies Inc
- // 356 Fu-Shin E. Rd Sec. 1. JhuBei City,
- // HsinChu County, Taiwan
- // 302
- //
- // web: http://www.terasic.com/
- // email: support@terasic.com
- //
- // --------------------------------------------------------------------
- //
- // Revision History :
- // --------------------------------------------------------------------
- // Ver :| Author :| Mod. Date :| Changes Made:
- // V1.0 :| Johnny Fan :| 07/06/30 :| Initial Revision
- // V2.0 :| Charlotte Frenkel :| 14/08/03 :| Adaptation for ELEC2103 project
- // V3.0 :| Ludovic Moreau :| 17/02/06 :| Adaptation for ELEC2103 project
- // --------------------------------------------------------------------
- module mtl_display_controller(
- // Host Side
- iCLK, // Input LCD control clock
- iRST_n, // Input system reset
- iColorData, // Input hardcoded color data
- oNewFrame, // Output signal being a pulse when a new frame of the LCD begins
- oEndFrame, // Output signal being a pulse when a frame of the LCD ends
- // LCD Side
- oHD, // Output LCD horizontal sync
- oVD, // Output LCD vertical sync
- oLCD_R, // Output LCD red color data
- oLCD_G, // Output LCD green color data
- oLCD_B, // Output LCD blue color data
- S1, S2, S3, S4, S5, S6, S7, S8, S9, S10,code,pos,code2,
- ROM_address, ROM_data, ROM_address2, ROM_data2, point_marker
- );
- //============================================================================
- // PARAMETER declarations
- //============================================================================
- // All these parameters are given in the MTL datasheet, section 3.2,
- // available in the project file folder
- parameter H_LINE = 1056;
- parameter V_LINE = 525;
- parameter Horizontal_Blank = 46; // H_SYNC + H_Back_Porch
- parameter Horizontal_Front_Porch = 210;
- parameter Vertical_Blank = 23; // V_SYNC + V_BACK_PORCH
- parameter Vertical_Front_Porch = 22;
- //===========================================================================
- // PORT declarations
- //===========================================================================
- input iCLK;
- input iRST_n;
- input [23:0] iColorData;
- output oNewFrame;
- output oEndFrame;
- output oHD;
- output oVD;
- output [7:0] oLCD_R;
- output [7:0] oLCD_G;
- output [7:0] oLCD_B;
- input [23:0] S1, S2, S3, S4, S5, S6, S7, S8, S9, S10;
- input [31:0] code,pos, code2, point_marker;
- output [13:0] ROM_address;
- input [31:0] ROM_data;
- output [14:0] ROM_address2;
- input [7:0] ROM_data2;
- //=============================================================================
- // REG/WIRE declarations
- //=============================================================================
- reg [10:0] x_cnt, x_next2;
- reg [9:0] y_cnt, y_next2;
- wire [7:0] read_red;
- wire [7:0] read_green;
- wire [7:0] read_blue;
- wire display_area, display_area_prev;
- reg mhd;
- reg mvd;
- //=============================================================================
- // Structural coding
- //=============================================================================
- //--- Assigning the right color data as a function -------------------------
- //--- of the current pixel position ----------------------------------------
- // This signal indicates the LCD active display area shifted back from
- // 1 pixel in the x direction. This accounts for the 1-cycle delay
- // in the sequential logic.
- assign display_area = ((x_cnt>(Horizontal_Blank-2)&&
- (x_cnt<(H_LINE-Horizontal_Front_Porch-1))&&
- (y_cnt>(Vertical_Blank-1))&&
- (y_cnt<(V_LINE-Vertical_Front_Porch))));
- // This signal indicates the same LCD active display area, now shifted
- // back from 2 pixels in the x direction, again for sequential delays.
- assign display_area_prev = ((x_cnt>(Horizontal_Blank-3)&&
- (x_cnt<(H_LINE-Horizontal_Front_Porch-2))&&
- (y_cnt>(Vertical_Blank-1))&&
- (y_cnt<(V_LINE-Vertical_Front_Porch))));
- // -------- GRAPHIC DRIVER ------------
- logic Display_S1, Display_S2, Display_S3, Display_S4, Display_S5, Display_S6, Display_S7, Display_S8, Display_S9, Display_S10;
- logic Display_next_S1, Display_next_S2, Display_next_S3, Display_next_S4, Display_next_S5, Display_next_S6, Display_next_S7, Display_next_S8, Display_next_S9, Display_next_S10;
- logic [23:0] Colors_S1, Colors_S2, Colors_S3, Colors_S4, Colors_S5, Colors_S6, Colors_S7, Colors_S8, Colors_S9, Colors_S10;
- logic [3:0] ROM_addr_select;
- logic [13:0] ROM_address_S1, ROM_address_S2, ROM_address_S3, ROM_address_S4, ROM_address_S5, ROM_address_S6, ROM_address_S7, ROM_address_S8, ROM_address_S9, ROM_address_S10;
- logic TDU, Go1, Go2, C1, C2, C3, C4, C5, C6, C7, C8, C9, F1, F2;
- logic [2:0] CondStart;
- assign CondStart = point_marker[29:27];
- logic Display_SC0, Display_SC1, Display_SC2, Display_SC01, Display_SC11, Display_SC21;
- logic [13:0] N_code, E_code, W_code, G_code, A_code, M_code, Y_code, O_code, U_code, I_code, L_code, S_code, Plus_code, Moins_code, Un_code, Deux_code, Cinq_code;
- logic [18:0] pos_ed, pos_ed1, pos_ed2, pos_ed3, pos_ed4, pos_ed5, pos_ed6, pos_ed7, pos_ed8, pos_ed9, pos_ed10, pos_ed11, pos_ed12, pos_ed13, pos_ed14, pos_ed15;
- logic Disp_dr1, Disp_dr2, Disp_dr3, Disp_dr4, Disp_dr5, Disp_dr6, Disp_dr7, Disp_dr8, Disp_dr9, Disp_dr10, Disp_dr11, Disp_dr12, Disp_dr13, Disp_dr14, Disp_dr15;
- //logic Display_pp1, Display_pp2, Display_pp3, Display_pp4, Display_pp5, Display_pp6, Display_pp7, Display_pp8, Display_pp9;
- //logic Display_doigt;
- always @(posedge iCLK or negedge iRST_n)
- if(~iRST_n) pos_ed <= 0;
- else if (oEndFrame && pos[0]) pos_ed <= pos[19:1]; // Update the color displayed between
- else pos_ed <= pos_ed;
- logic dCLK;
- downclock d(iCLK, dCLK);
- always @(posedge dCLK or negedge iRST_n)
- if(~iRST_n) begin
- pos_ed1 <= 0;
- pos_ed2 <= 0;
- pos_ed3 <= 0;
- pos_ed4 <= 0;
- pos_ed5 <= 0;
- pos_ed6 <= 0;
- /*pos_ed7 <= 0;
- pos_ed8 <= 0;
- pos_ed9 <= 0;
- pos_ed10 <= 0;
- pos_ed11 <= 0;
- pos_ed12 <= 0;
- pos_ed13 <= 0;
- pos_ed14 <= 0;
- pos_ed15 <= 0;*/
- end
- else begin
- pos_ed1 <= pos_ed;
- pos_ed2 <= pos_ed1;
- pos_ed3 <= pos_ed2;
- pos_ed4 <= pos_ed3;
- pos_ed5 <= pos_ed4;
- pos_ed6 <= pos_ed5;
- /*pos_ed7 <= pos_ed6;
- pos_ed8 <= pos_ed7;
- pos_ed9 <= pos_ed8;
- pos_ed10 <= pos_ed9;
- pos_ed11 <= pos_ed10;
- pos_ed12 <= pos_ed11;
- pos_ed13 <= pos_ed12;
- pos_ed14 <= pos_ed13;
- pos_ed15 <= pos_ed14;
- Display_pp2 <= Display_pp1;
- Display_pp3 <= Display_pp2;
- Display_pp4 <= Display_pp3;
- Display_pp5 <= Display_pp4;
- Display_pp6 <= Display_pp5;
- Display_pp7 <= Display_pp6;
- Display_pp8 <= Display_pp7;
- Display_pp9 <= Display_pp8;
- */
- end
- //assign Display_doigt = ((x_cnt - pos_ed[9:0])*(x_cnt - pos_ed[9:0]) + (y_cnt - pos_ed[18:10])*(y_cnt - pos_ed[18:10])<25);*/
- //assign Display_pp1 = ((pos_ed1[9:0] - pos_ed[9:0])*(pos_ed1[9:0] - pos_ed[9:0]) + (pos_ed1[18:10] - pos_ed[18:10])*(pos_ed1[18:10] - pos_ed[18:10])<2500);
- Droite dr1(x_cnt, y_cnt, pos_ed[9:0]+44, pos_ed[18:10]+22, pos_ed1[9:0]+44, pos_ed1[18:10]+22, 3, Disp_dr1);
- Droite dr2(x_cnt, y_cnt, pos_ed1[9:0]+44, pos_ed1[18:10]+22, pos_ed2[9:0]+44, pos_ed2[18:10]+22, 3, Disp_dr2);
- Droite dr3(x_cnt, y_cnt, pos_ed2[9:0]+44, pos_ed2[18:10]+22, pos_ed3[9:0]+44, pos_ed3[18:10]+22, 3, Disp_dr3);
- Droite dr4(x_cnt, y_cnt, pos_ed3[9:0]+44, pos_ed3[18:10]+22, pos_ed4[9:0]+44, pos_ed4[18:10]+22, 3, Disp_dr4);
- Droite dr5(x_cnt, y_cnt, pos_ed4[9:0]+44, pos_ed4[18:10]+22, pos_ed5[9:0]+44, pos_ed5[18:10]+22, 3, Disp_dr5);
- Droite dr6(x_cnt, y_cnt, pos_ed5[9:0]+44, pos_ed5[18:10]+22, pos_ed6[9:0]+44, pos_ed6[18:10]+22, 3, Disp_dr6);
- /*Droite dr7(x_cnt, y_cnt, pos_ed6[9:0]+44, pos_ed6[18:10]+22, pos_ed7[9:0]+44, pos_ed7[18:10]+22, 3, Disp_dr7);
- Droite dr8(x_cnt, y_cnt, pos_ed7[9:0]+44, pos_ed7[18:10]+22, pos_ed8[9:0]+44, pos_ed8[18:10]+22, 3, Disp_dr8);
- Droite dr9(x_cnt, y_cnt, pos_ed8[9:0]+44, pos_ed8[18:10]+22, pos_ed9[9:0]+44, pos_ed9[18:10]+22, 3, Disp_dr9);
- Droite dr10(x_cnt, y_cnt, pos_ed9[9:0]+44, pos_ed9[18:10]+22, pos_ed10[9:0]+44, pos_ed10[18:10]+22, 3, Disp_dr10);
- Droite dr11(x_cnt, y_cnt, pos_ed10[9:0]+44, pos_ed10[18:10]+22, pos_ed11[9:0]+44, pos_ed11[18:10]+22, 3, Disp_dr11);
- Droite dr12(x_cnt, y_cnt, pos_ed11[9:0]+44, pos_ed11[18:10]+22, pos_ed12[9:0]+44, pos_ed12[18:10]+22, 3, Disp_dr12);
- Droite dr13(x_cnt, y_cnt, pos_ed12[9:0]+44, pos_ed12[18:10]+22, pos_ed13[9:0]+44, pos_ed13[18:10]+22, 3, Disp_dr13);
- Droite dr14(x_cnt, y_cnt, pos_ed13[9:0]+44, pos_ed13[18:10]+22, pos_ed14[9:0]+44, pos_ed14[18:10]+22, 3, Disp_dr14);
- Droite dr15(x_cnt, y_cnt, pos_ed14[9:0]+44, pos_ed14[18:10]+22, pos_ed15[9:0]+44, pos_ed15[18:10]+22, 3, Disp_dr15);
- */
- // Image logic
- assign ROM_addr_select = Display_next_S1 ? 4'd1 : (Display_next_S2 ? 4'd2 : (Display_next_S3 ? 4'd3 :
- (Display_next_S4 ? 4'd4 : (Display_next_S5 ? 4'd5 : (Display_next_S6 ? 4'd6 :
- (Display_next_S7 ? 4'd7 : (Display_next_S8 ? 4'd8 : (Display_next_S9 ? 4'd9 : 4'd10))))))));
- mux15 MUX(iCLK, ROM_addr_select, ROM_address, ROM_address_S1, ROM_address_S2, ROM_address_S3, ROM_address_S4, ROM_address_S5, ROM_address_S6,
- ROM_address_S7, ROM_address_S8, ROM_address_S9, ROM_address_S10);
- //assign ROM_address = ROM_address_S1;
- // 3-2-1-GO
- DisplayBigDigit Dispdig1(x_cnt, y_cnt, (14'b11001111 & {14 {CondStart ==3'd3}})|(14'b11011011& {14 {CondStart ==3'd2}})|(14'b1001000000000 & {14 {CondStart ==3'd1}}), 11'd514, 10'd132, TDU);
- DisplayBigDigit Dispdig2(x_cnt, y_cnt, 14'b00000010111101, 11'd594, 10'd132, Go1);
- DisplayBigDigit Dispdig3(x_cnt, y_cnt, 14'b111111, 11'd434, 10'd132, Go2);
- // New Game - You win - You Lose
- Decode dec1(6'd23, N_code);
- Decode dec2(6'd14 , E_code);
- Decode dec3(6'd32 , W_code);
- Decode dec4(6'd16 , G_code);
- Decode dec5(6'd10 , A_code);
- Decode dec6(6'd22 , M_code);
- Decode dec7(6'd34, Y_code);
- Decode dec8(6'd24 , O_code);
- Decode dec9(6'd30 , U_code);
- Decode dec10(6'd18 , I_code);
- Decode dec11(6'd21 , L_code);
- Decode dec12(6'd28 , S_code);
- Decode dec13(6'd36 , Plus_code);
- Decode dec14(6'd37 , Moins_code);
- Decode dec15(6'd1 , Un_code);
- Decode dec16(6'd2 , Deux_code);
- Decode dec17(6'd5 , Cinq_code);
- DisplayDigit Dispdig4(x_cnt, y_cnt, (N_code & {14 {point_marker[24]}})|(Y_code & ({14 {point_marker[25]}}|{14 {point_marker[26]}})), 11'd570, 10'd236, C1);
- DisplayDigit Dispdig5(x_cnt, y_cnt, (E_code & {14 {point_marker[24]}})|(O_code & ({14 {point_marker[25]}}|{14 {point_marker[26]}})), 11'd538, 10'd236, C2);
- DisplayDigit Dispdig6(x_cnt, y_cnt, (W_code & {14 {point_marker[24]}})|(U_code & ({14 {point_marker[25]}}|{14 {point_marker[26]}})), 11'd506, 10'd236, C3);
- DisplayDigit Dispdig7(x_cnt, y_cnt, (G_code & {14 {point_marker[24]}})|(14'd0 & {14 {point_marker[25]}})|(L_code & {14 {point_marker[26]}}), 11'd442, 10'd236, C4);
- DisplayDigit Dispdig8(x_cnt, y_cnt, (A_code & {14 {point_marker[24]}})|(W_code & {14 {point_marker[25]}})|(O_code & {14 {point_marker[26]}}), 11'd410, 10'd236, C5);
- DisplayDigit Dispdig9(x_cnt, y_cnt,(M_code & {14 {point_marker[24]}})|(I_code & {14 {point_marker[25]}})|(S_code & {14 {point_marker[26]}}), 11'd378, 10'd236, C6);
- DisplayDigit Dispdig10(x_cnt, y_cnt,(E_code & {14 {point_marker[24]}})|(N_code & {14 {point_marker[25]}})|(E_code & {14 {point_marker[26]}}), 11'd346, 10'd236, C7);
- DisplayDigit Dispdig11(x_cnt, y_cnt,(Moins_code & {14{point_marker[22:21]==2'd0}})|(Plus_code & {14{point_marker[22:21]!=2'd0}}), point_marker[10:0], point_marker[20:11], C8);
- DisplayDigit Dispdig12(x_cnt, y_cnt,(Un_code & {14{point_marker[22:21]==2'd1}})|(Deux_code & {14{point_marker[22:21]==2'd2}})|(Cinq_code & {14{point_marker[22:21]==2'd0|point_marker[22:21]==2'd3}}), point_marker[10:0]-11'd32, point_marker[20:11], C9);
- Rectangle Font(x_cnt, y_cnt, 9'd270, 9'd60, 11'd579, 10'd232, F1);
- // Sphere Logic
- DisplaySphere DS1(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S1, Display_S1, Display_next_S1, Colors_S1, ROM_address_S1);
- DisplaySphere DS2(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S2, Display_S2, Display_next_S2, Colors_S2, ROM_address_S2);
- DisplaySphere DS3(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S3, Display_S3, Display_next_S3, Colors_S3, ROM_address_S3);
- DisplaySphere DS4(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S4, Display_S4, Display_next_S4, Colors_S4, ROM_address_S4);
- DisplaySphere DS5(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S5, Display_S5, Display_next_S5, Colors_S5, ROM_address_S5);
- DisplaySphere DS6(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S6, Display_S6, Display_next_S6, Colors_S6, ROM_address_S6);
- DisplaySphere DS7(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S7, Display_S7, Display_next_S7, Colors_S7, ROM_address_S7);
- DisplaySphere DS8(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S8, Display_S8, Display_next_S8, Colors_S8, ROM_address_S8);
- DisplaySphere DS9(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S9, Display_S9, Display_next_S9, Colors_S9, ROM_address_S9);
- DisplaySphere DS10(iCLK, x_cnt, y_cnt, x_next2, y_next2, ROM_data,
- S10, Display_S10, Display_next_S10, Colors_S10, ROM_address_S10);
- // Score Logic
- DisplayScore DSSC0(x_cnt, y_cnt, code[20:14],100, 460,Display_SC0);
- DisplayScore DSSC1(x_cnt, y_cnt, code[13:7],85, 460, Display_SC1);
- DisplayScore DSSC2(x_cnt, y_cnt, code[6:0],70,460, Display_SC2);
- DisplayScore DSSC01(x_cnt, y_cnt, code2[20:14],830, 460,Display_SC01);
- DisplayScore DSSC11(x_cnt, y_cnt, code2[13:7],815, 460,Display_SC11);
- DisplayScore DSSC21(x_cnt, y_cnt, code2[6:0],800, 460,Display_SC21);
- assign ROM_address2 = ((15'd844 >> 2) - x_cnt[10:2]) + ((15'd502 >> 3) - y_cnt[9:3]) * 8'd200;
- //assign ROM_address2 = ((844 >> 3) - x_cnt[10:3]) + ((502 >> 3) - y_cnt[9:3]) * 7'd100; // upscaling 8x
- //assign ROM_address2 = (((846-x_cnt) >>1) /3)+ (((502-y_cnt)>>1) /3)*133; // upscaling 6x
- // Assigns the right color data.
- always_ff @(posedge iCLK) begin
- // If the screen is reset, put at zero the color signals.
- if (!iRST_n) begin
- read_red <= 8'b0;
- read_green <= 8'b0;
- read_blue <= 8'b0;
- // If we are not in the active display area...
- end else if (~display_area) begin
- read_red <= 8'b0;
- read_green <= 8'b0;
- read_blue <= 8'b0;
- end else if (Display_SC0 || Display_SC1 || Display_SC2) begin // if we are in the own score area
- read_red <= 8'h00;
- read_green <= 8'hFF;
- read_blue <= 8'h00;
- end else if (Display_SC01 || Display_SC11 || Display_SC21) begin // if we are in the oppponent score area
- read_red <= 8'hFF;
- read_green <= 8'h00;
- read_blue <= 8'h00;
- end else if (Disp_dr1 || Disp_dr2 || Disp_dr3 || Disp_dr4 || Disp_dr5 || Disp_dr6 /*| Disp_dr7 | Disp_dr8 | Disp_dr9 */) begin // if we are in the Trace zone
- read_red <= 8'h00;
- read_green <= 8'h00;
- read_blue <= 8'hFF;
- end else if ((TDU & (CondStart==3|CondStart==2|CondStart==1)) | (Go1 & CondStart ==4) | (Go2 & CondStart ==4)) begin // if we are in 3-2-1-Go zone
- read_red <= 8'hFF;
- read_green <= 8'h00;
- read_blue <= 8'h00;
- end else if (point_marker[24] & (C1|C2|C3|C4|C5|C6|C7)) begin // if we are in New Game Zone
- read_red <= 8'h00;
- read_green <= 8'h00;
- read_blue <= 8'h00;
- end else if (point_marker[25] & (C1|C2|C3|C4|C5|C6|C7)) begin // if we are in You Win zone
- read_red <= 8'h00;
- read_green <= 8'h00;
- read_blue <= 8'h00;
- end else if (point_marker[26] & (C1|C2|C3|C4|C5|C6|C7)) begin // if we are in You Lose zone
- read_red <= 8'h00;
- read_green <= 8'h00;
- read_blue <= 8'h00;
- end else if ((point_marker[24] | point_marker[25] | point_marker[26]) & F1) begin // if we are in Font zone
- read_red <= 8'hFF;
- read_green <= 8'hFF;
- read_blue <= 8'h00;
- end else if ((C8|C9) & point_marker[23]) begin // if we are in Font zone
- read_red <= 8'hFF;
- read_green <= 8'h00;
- read_blue <= 8'h00;
- end else if (Display_S1) begin // if we are in the sphere area
- read_red <= Colors_S1[23:16];
- read_green <= Colors_S1[15:8];
- read_blue <= Colors_S1[7:0];
- end else if (Display_S2) begin // if we are in the sphere area
- read_red <= Colors_S2[23:16];
- read_green <= Colors_S2[15:8];
- read_blue <= Colors_S2[7:0];
- end else if (Display_S3) begin // if we are in the sphere area
- read_red <= Colors_S3[23:16];
- read_green <= Colors_S3[15:8];
- read_blue <= Colors_S3[7:0];
- end else if (Display_S4) begin // if we are in the sphere area
- read_red <= Colors_S4[23:16];
- read_green <= Colors_S4[15:8];
- read_blue <= Colors_S4[7:0];
- end else if (Display_S5) begin // if we are in the sphere area
- read_red <= Colors_S5[23:16];
- read_green <= Colors_S5[15:8];
- read_blue <= Colors_S5[7:0];
- end else if (Display_S6) begin // if we are in the sphere area
- read_red <= Colors_S6[23:16];
- read_green <= Colors_S6[15:8];
- read_blue <= Colors_S6[7:0];
- end else if (Display_S7) begin // if we are in the sphere area
- read_red <= Colors_S7[23:16];
- read_green <= Colors_S7[15:8];
- read_blue <= Colors_S7[7:0];
- end else if (Display_S8) begin // if we are in the sphere area
- read_red <= Colors_S8[23:16];
- read_green <= Colors_S8[15:8];
- read_blue <= Colors_S8[7:0];
- end else if (Display_S9) begin // if we are in the sphere area
- read_red <= Colors_S9[23:16];
- read_green <= Colors_S9[15:8];
- read_blue <= Colors_S9[7:0];
- end else if (Display_S10) begin // if we are in the sphere area
- read_red <= Colors_S10[23:16];
- read_green <= Colors_S10[15:8];
- read_blue <= Colors_S10[7:0];
- end else if (code[21]) begin // if we are freezed
- read_red <= 8'hC0;
- read_green <= 8'hC0;
- read_blue <= 8'hC0;
- end else begin // if we are in the active display area
- read_red <= ROM_data2;
- read_green <= ROM_data2;
- read_blue <= ROM_data2;
- end
- end
- // -------- END GRAPHIC DRIVER -------
- //--- Keeping track of x and y positions of the current pixel ------------------
- //--- and generating the horiz. and vert. sync. signals ------------------------
- always@(posedge iCLK or negedge iRST_n) begin
- if (!iRST_n)
- begin
- x_cnt <= 11'd0;
- x_next2 <= 11'd2;
- mhd <= 1'd0;
- end
- else if (x_cnt == (H_LINE-1))
- begin
- x_cnt <= 11'd0;
- x_next2 <= 11'd2;
- mhd <= 1'd0;
- end
- else
- begin
- x_cnt <= x_cnt + 11'd1;
- if (x_next2 == (H_LINE-1))
- x_next2 <= 11'd0;
- else
- x_next2 <= x_next2 + 11'd1;
- mhd <= 1'd1;
- end
- end
- always@(posedge iCLK or negedge iRST_n) begin
- if (!iRST_n) begin
- y_cnt <= 10'd0;
- end
- else if (x_cnt == (H_LINE-1))
- begin
- if (y_cnt == (V_LINE-1))
- y_cnt <= 10'd0;
- else
- y_cnt <= y_cnt + 10'd1;
- end
- end
- always@(posedge iCLK or negedge iRST_n) begin
- if (!iRST_n) begin
- y_next2 <= 10'd2;
- end
- else if (x_next2 == (H_LINE-1))
- begin
- if (y_next2 == (V_LINE-1))
- y_next2 <= 10'd0;
- else
- y_next2 <= y_next2 + 10'd1;
- end
- end
- always@(posedge iCLK or negedge iRST_n) begin
- if (!iRST_n)
- mvd <= 1'b1;
- else if (y_cnt == 10'd0)
- mvd <= 1'b0;
- else
- mvd <= 1'b1;
- end
- assign oNewFrame = ((x_cnt == 11'd0) && (y_cnt == 10'd0) );
- assign oEndFrame = ((x_cnt == 11'd846) && (y_cnt == 10'd503));
- //--- Assigning synchronously the color and sync. signals ------------------
- always@(posedge iCLK or negedge iRST_n) begin
- if (!iRST_n)
- begin
- oHD <= 1'd0;
- oVD <= 1'd0;
- oLCD_R <= 8'd0;
- oLCD_G <= 8'd0;
- oLCD_B <= 8'd0;
- end
- else
- begin
- oHD <= mhd;
- oVD <= mvd;
- oLCD_R <= read_red;
- oLCD_G <= read_green;
- oLCD_B <= read_blue;
- end
- end
- endmodule
- // [23:0] sphere : {enabled, color:2, y_center:10, x_center:11}
- module DisplaySphere(input iCLK, input [10:0] x, input [9:0] y, input [10:0] x_next, input [9:0] y_next, input [31:0] ROM_data, input [23:0] sphere,
- output oDisplay, output oDisplay_next, output [23:0] oColors, output [13:0] ROM_address);
- logic [31:0] radius;
- assign radius = 31'd30;
- logic [7:0] red, green, blue;
- logic [10:0] x_center;
- logic [9:0] y_center;
- logic [1:0] color;
- assign x_center = sphere[10:0];
- assign y_center = sphere[20:11];
- assign color = sphere[22:21];
- assign oDisplay = (sphere[23]) && (ROM_data[23:0] != 24'hFFFFFF) && ((x - x_center)*(x - x_center) + (y - y_center)*(y - y_center)<radius*radius);
- assign oDisplay_next = (sphere[23]) && ((x_next - x_center)*(x_next - x_center) + (y_next - y_center)*(y_next - y_center)<radius*radius);
- // Preparing signed logic registers
- logic [13:0] pos_mem, ROM_offset;
- logic [13:0] frame_dist_x, frame_dist_y;
- logic sr1, sr2;
- Substraction #(32)(x_center+radius, x, 1'b0, 1'b0, frame_dist_x, sr1);
- Substraction #(32)(y_center+radius, y, 1'b0, 1'b0, frame_dist_y, sr2);
- assign pos_mem = frame_dist_x + frame_dist_y*14'd60;
- logic [23:0] rColors;
- always_comb
- if (color == 2'd0)
- ROM_offset = 14'd0;
- else if (color == 2'd1)
- ROM_offset = 14'd3600;
- else if (color == 2'd2)
- ROM_offset = 14'd7200;
- else
- ROM_offset = 14'd10800;
- assign oColors = rColors;
- assign ROM_address = pos_mem + ROM_offset;// + (color == 2'd0) ? 14'd0 : (color == 2'd1 ? 14'd3600 : (color == 2'd2 ? 14'd7200 : (color == 2'd3 ? 14'd10800 : 14'd0)));
- always_ff @(posedge iCLK) begin
- if (oDisplay_next) begin
- rColors <= ROM_data[23:0];
- end
- end
- endmodule
- // [23:0] sphere : {enabled, color:2, y_center:10, x_center:11}
- module DisplayScore(input [10:0] x, input [9:0] y, input [6:0] code, input [10:0] x_init, input [9:0] y_init, output oDisplay);
- logic D1, D2, D3, D4, D5, D6, D7;
- Rectangle R1(x, y, 9'd10, 9'd2, x_init-11'd2, y_init+10'd24, D1);
- Rectangle R2(x, y, 9'd2, 9'd10, x_init-11'd12, y_init+10'd14, D2);
- Rectangle R3(x, y, 9'd2, 9'd10, x_init-11'd12, y_init+10'd2, D3);
- Rectangle R4(x, y, 9'd10, 9'd2, x_init-11'd2, y_init, D4);
- Rectangle R5(x, y, 9'd2, 9'd10, x_init, y_init+10'd2, D5);
- Rectangle R6(x, y, 9'd2, 9'd10, x_init, y_init+10'd14, D6);
- Rectangle R7(x, y, 9'd10, 9'd2, x_init-11'd2, y_init+10'd12, D7);
- assign oDisplay = (code[0] && D1)||
- (code[1] && D2)||
- (code[2] && D3)||
- (code[3] && D4)||
- (code[4] && D5)||
- (code[5] && D6)||
- (code[6] && D7);
- endmodule
- module mux15 (input clk,
- input [3:0] select,
- output [13:0] out,
- input [13:0] S1,
- input [13:0] S2,
- input [13:0] S3,
- input [13:0] S4,
- input [13:0] S5,
- input [13:0] S6,
- input [13:0] S7,
- input [13:0] S8,
- input [13:0] S9,
- input [13:0] S10);
- reg [13:0] reg_out;
- assign out = reg_out;
- always @(posedge clk) begin
- case (select)
- 4'd1 : reg_out <= S1;
- 4'd2 : reg_out <= S2;
- 4'd3 : reg_out <= S3;
- 4'd4 : reg_out <= S4;
- 4'd5 : reg_out <= S5;
- 4'd6 : reg_out <= S6;
- 4'd7 : reg_out <= S7;
- 4'd8 : reg_out <= S8;
- 4'd9 : reg_out <= S9;
- 4'd10 : reg_out <= S10;
- default : reg_out <= 14'd0;
- endcase
- end
- endmodule
- module Substraction #(parameter width = 8)(input [width-1:0] a, input [width-1:0] b, input sa, input sb, output [width-1:0] result, output sr);
- assign result = (sa==sb) ? ((a>b) ? a-b : b-a): a+b;
- assign sr = (sa==sb) ? ((a>b) ? sa : ~sa): sa;
- endmodule
- module Product(input [10:0] a, input [9:0] b, input sa, input sb, output [20:0] result, output sr);
- assign result = a*b;
- assign sr = sa^sb;
- endmodule
- module Droite(input [10:0] x, input [9:0] y, input [10:0] x1, input [9:0] y1, input [10:0] x2, input [9:0] y2, input [3:0] width, output oDisplay);
- logic sdx, sdy, sdpx, sdpy, sp1, sp2, sdp;
- logic [31:0] widthsqr;
- logic [10:0] dx, dpx;
- logic [9:0] dy, dpy;
- logic [20:0] p1, p2;
- logic [31:0] dp;
- Substraction #(11) Sub1 (x,x2,1'b0,1'b0,dx,sdx);
- Substraction #(10) Sub2 (y2,y1,1'b0,1'b0,dpy,sdpy);
- Substraction #(10) Sub3 (y,y2,1'b0,1'b0,dy,sdy);
- Substraction #(11) Sub4 (x2,x1,1'b0,1'b0,dpx,sdpx);
- Product Prod1 (dx,dpy,sdx,sdpy,p1,sp1);
- Product Prod2 (dpx,dy,sdpx,sdy,p2,sp2);
- Substraction #(32) Sub5 (p1,p2,sp1,sp2,dp,sdp);
- assign widthsqr = width*width;
- assign oDisplay = ((dp*dp) <= (widthsqr*(dpx*dpx+dpy*dpy))) && ((x2>x1) ? (x1<x+width && x<x2+width):(x2<x+width && x<x1+width))&& ((y2>y1) ? (y1<y+width && y<y2+width):(y2<y+width && y<y1+width));
- endmodule
- module DisplayDigit(input [10:0] x, input [9:0] y, input [13:0] code, input [10:0] x_init, input [9:0] y_init, output oDisplay);
- logic D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14;
- Rectangle R1(x, y, 9'd20, 9'd4, x_init-11'd4, y_init+10'd48, D1);
- Rectangle R2(x, y, 9'd4, 9'd20, x_init-11'd24, y_init+10'd28, D2);
- Rectangle R3(x, y, 9'd4, 9'd20, x_init-11'd24, y_init+10'd4, D3);
- Rectangle R4(x, y, 9'd20, 9'd4, x_init-11'd4, y_init, D4);
- Rectangle R5(x, y, 9'd4, 9'd20, x_init, y_init+10'd4, D5);
- Rectangle R6(x, y, 9'd4, 9'd20, x_init, y_init+10'd28, D6);
- Rectangle R7(x, y, 9'd8, 9'd4, x_init-11'd4, y_init+10'd24, D7);
- Rectangle R8(x, y, 9'd8, 9'd4, x_init-11'd16, y_init+10'd24, D8);
- Droite dr9(x, y, x_init-11'd6, y_init+10'd46, x_init-11'd10, y_init+10'd30, 4'd1, D9);
- Rectangle R10(x, y, 9'd4, 9'd20, x_init-11'd12, y_init+10'd28, D10);
- Droite dr11(x, y, x_init-11'd22, y_init+10'd46, x_init-11'd18, y_init+10'd30, 4'd1, D11);
- Droite dr12(x, y, x_init-11'd22, y_init+10'd6, x_init-11'd18, y_init+10'd22, 4'd1, D12);
- Rectangle R13(x, y, 9'd4, 9'd20, x_init-11'd12, y_init+10'd4, D13);
- Droite dr14(x, y, x_init-11'd6, y_init+10'd6, x_init-11'd10, y_init+10'd22, 4'd1, D14);
- assign oDisplay = (code[0] && D1)||
- (code[1] && D2)||
- (code[2] && D3)||
- (code[3] && D4)||
- (code[4] && D5)||
- (code[5] && D6)||
- (code[6] && D7)||
- (code[7] && D8)||
- (code[8] && D9)||
- (code[9] && D10)||
- (code[10] && D11)||
- (code[11] && D12)||
- (code[12] && D13)||
- (code[13] && D14);
- endmodule
- module Rectangle(input [10:0] x, input [9:0] y, input [8:0] width, input[8:0] height, input [10:0] x_init, input [9:0] y_init, output oDisplay);
- assign oDisplay = (x<x_init) && (x>x_init-width) && (y>y_init) && (y<y_init+height);
- endmodule
- module downclock (input wire input_clk, output reg output_clk);
- reg [31:0] cnt = 31'b0;
- always @(posedge input_clk) begin
- if (cnt < 31'd250000)
- output_clk <= 1'b0;
- else if (cnt < 31'd500000)
- output_clk <= 1'b1;
- cnt = cnt + 1'b1;
- if (cnt == 31'd500000)
- cnt = 1'b0;
- end
- endmodule
- module DisplayBigDigit(input [10:0] x, input [9:0] y, input [13:0] code, input [10:0] x_init, input [9:0] y_init, output oDisplay);
- logic D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14;
- Rectangle R1(x, y, 9'd100, 9'd20, x_init-11'd20, y_init+10'd240, D1);
- Rectangle R2(x, y, 9'd20, 9'd100, x_init-11'd120, y_init+10'd140, D2);
- Rectangle R3(x, y, 9'd20, 9'd100, x_init-11'd120, y_init+10'd20, D3);
- Rectangle R4(x, y, 9'd100, 9'd20, x_init-11'd20, y_init, D4);
- Rectangle R5(x, y, 9'd20, 9'd100, x_init, y_init+10'd20, D5);
- Rectangle R6(x, y, 9'd20, 9'd100, x_init, y_init+10'd140, D6);
- Rectangle R7(x, y, 9'd40, 9'd20, x_init-11'd20, y_init+10'd120, D7);
- Rectangle R8(x, y, 9'd40, 9'd20, x_init-11'd80, y_init+10'd120, D8);
- Droite dr9(x, y, x_init-11'd20, y_init+10'd240, x_init-11'd60, y_init+10'd140, 4'd10, D9);
- Rectangle R10(x, y, 9'd20, 9'd100, x_init-11'd60, y_init+10'd140, D10);
- Droite dr11(x, y, x_init-11'd120, y_init+10'd240, x_init-11'd80, y_init+10'd140, 4'd10, D11);
- Droite dr12(x, y, x_init-11'd120, y_init+10'd20, x_init-11'd80, y_init+10'd120, 4'd10, D12);
- Rectangle R13(x, y, 9'd20, 9'd100, x_init-11'd60, y_init+10'd20, D13);
- Droite dr14(x, y, x_init-11'd20, y_init+10'd20, x_init-11'd60, y_init+10'd120, 4'd10, D14);
- assign oDisplay = (code[0] && D1)||
- (code[1] && D2)||
- (code[2] && D3)||
- (code[3] && D4)||
- (code[4] && D5)||
- (code[5] && D6)||
- (code[6] && D7)||
- (code[7] && D8)||
- (code[8] && D9)||
- (code[9] && D10)||
- (code[10] && D11)||
- (code[11] && D12)||
- (code[12] && D13)||
- (code[13] && D14);
- endmodule
- module Decode (input [5:0] let , output [13:0] message);
- always_comb
- case(let)
- 6'd0: message <= 14'b111111; //0
- 6'd1: message <= 14'b110; //1
- 6'd2: message <= 14'b11011011; //2
- 6'd3: message <= 14'b11001111; //3
- 6'd4: message <= 14'b11100110; //4
- 6'd5: message <= 14'b11101101; //5
- 6'd6: message <= 14'b11111101; //6
- 6'd7: message <= 14'b111; //7
- 6'd8: message <= 14'b11111111; //8
- 6'd9: message <= 14'b11101111; //9
- 6'd10: message <= 14'b11110111; //A
- 6'd11: message <= 14'b11111100; //B
- 6'd12: message <= 14'b111001; //C
- 6'd13: message <= 14'b11011110; //D
- 6'd14: message <= 14'b11111001; //E
- 6'd15: message <= 14'b1110001; //F
- 6'd16: message <= 14'b10111101; //G
- 6'd17: message <= 14'b11110110; //H
- 6'd18: message <= 14'b1001000000000; //I
- 6'd19: message <= 14'b11110; //J
- 6'd20: message <= 14'b110001110000; //K
- 6'd21: message <= 14'b111000; //L
- 6'd22: message <= 14'b10100110110; //M
- 6'd23: message <= 14'b100100110110; //N
- 6'd24: message <= 14'b111111; //O
- 6'd25: message <= 14'b11110011; //P
- 6'd26: message <= 14'b100000111111; //Q
- 6'd27: message <= 14'b100011110011; //R
- 6'd28: message <= 14'b11101101; //S
- 6'd29: message <= 14'b1001000000001; //T
- 6'd30: message <= 14'b111110; //U
- 6'd31: message <= 14'b10010000110000; //V
- 6'd32: message <= 14'b10100000110110; //W
- 6'd33: message <= 14'b10110100000000; //X
- 6'd34: message <= 14'b1010100000000; //Y
- 6'd35: message <= 14'b10010000001001; //Z
- 6'd36: message <= 14'b1001011000000; //+
- 6'd37: message <= 14'b11000000; //-
- default: message <= 14'b0; // nothing
- endcase
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement