Sprites in Block ROM



Similar documents
VGA video signal generation

Digital Systems Design. VGA Video Display Generation

Digital Design with VHDL

Below is a diagram explaining the data packet and the timing related to the mouse clock while receiving a byte from the PS-2 mouse:

An Example VHDL Application for the TM-4

if-then else : 2-1 mux mux: process (A, B, Select) begin if (select= 1 ) then Z <= A; else Z <= B; end if; end process;

Introduction to graphics and LCD technologies. NXP Product Line Microcontrollers Business Line Standard ICs

12. A B C A B C A B C 1 A B C A B C A B C JK-FF NETr

LAB #3 VHDL RECOGNITION AND GAL IC PROGRAMMING USING ALL-11 UNIVERSAL PROGRAMMER

Lenguaje VHDL. Diseño de sistemas digitales secuenciales

VHDL GUIDELINES FOR SYNTHESIS

An Integer Square Root Algorithm

Implementation of Web-Server Using Altera DE2-70 FPGA Development Kit

VHDL programmering H2

Lesson 10: Video-Out Interface

RAPID PROTOTYPING OF DIGITAL SYSTEMS Second Edition

CPE 462 VHDL: Simulation and Synthesis

Introduction to the Altera Qsys System Integration Tool. 1 Introduction. For Quartus II 12.0

(1) D Flip-Flop with Asynchronous Reset. (2) 4:1 Multiplexor. CS/EE120A VHDL Lab Programming Reference

Technical Note TN_158. What is the Camera Parallel Interface?

VHDL Test Bench Tutorial

Digital Design with Synthesizable VHDL

Note monitors controlled by analog signals CRT monitors are controlled by analog voltage. i. e. the level of analog signal delivered through the

Data Storage 3.1. Foundations of Computer Science Cengage Learning

MassArt Studio Foundation: Visual Language Digital Media Cookbook, Fall 2013

Step : Create Dependency Graph for Data Path Step b: 8-way Addition? So, the data operations are: 8 multiplications one 8-way addition Balanced binary

First Bytes Programming Lab 2

Adjusting Digitial Camera Resolution

! " # # $ '"() * #! +, # / $0123$

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

In this example the length of the vector is determined by D length and used for the index variable.

Introduction to Digital Design Using Digilent FPGA Boards Block Diagram / Verilog Examples

Preliminary Draft May 19th Video Subsystem

Camera Sensor Driver Development And Integration

3D Input Format Requirements for DLP Projectors using the new DDP4421/DDP4422 System Controller ASIC. Version 1.3, March 2 nd 2012

Lab 7: VHDL 16-Bit Shifter

CNC FOR EDM MACHINE TOOL HARDWARE STRUCTURE. Ioan Lemeni

Digital VLSI Slot Machine Project Documentation

Combining the ADS1202 with an FPGA Digital Filter for Current Measurement in Motor Control Applications

RGB - CGA, EGA, HD to VGA Converter ID# 657

MMGD0203 Multimedia Design MMGD0203 MULTIMEDIA DESIGN. Chapter 3 Graphics and Animations

2013 Intel Corporation

User Manual. LG EzSign TV Editor. Version Nov. 10,

CONTENTS. Section 1 Document Descriptions Purpose of this Document Nomenclature of this Document... 3

Hardware Implementation of the Stone Metamorphic Cipher

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

EC313 - VHDL State Machine Example

Digital Versus Analog Lesson 2 of 2

Different Display Configurations on i.mx35 Linux PDK

CH7101A. CH7101A HDMI to VGA Converter GENERAL DESCRIPTION

WINSTAR_TFT Application Note

INTRODUCTION TO DIGITAL SYSTEMS. IMPLEMENTATION: MODULES (ICs) AND NETWORKS IMPLEMENTATION OF ALGORITHMS IN HARDWARE

The 104 Duke_ACC Machine

Cascaded Counters. Page 1 BYU

Asynchronous & Synchronous Reset Design Techniques - Part Deux

MONOCHROME RGB YCbCr VIDEO DIGITIZER

Video Fall 2009 Lecture 12

Floating point package user s guide By David Bishop (dbishop@vhdl.org)

Microsoft Picture Manager. Picture Manager

Memory Basics. SRAM/DRAM Basics

DDS. 16-bit Direct Digital Synthesizer / Periodic waveform generator Rev Key Design Features. Block Diagram. Generic Parameters.

AES (Rijndael) IP-Cores

Video-Conferencing System

Printed Circuit Board Design with HDL Designer

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Car Racing Game. Figure 1 The Car Racing Game

MicroVGA - Device Overview

ANALYSIS OF THE COMPRESSION RATIO AND QUALITY IN MEDICAL IMAGES

How To Change Your Site On Drupal Cloud On A Pcode On A Microsoft Powerstone On A Macbook Or Ipad (For Free) On A Freebie (For A Free Download) On An Ipad Or Ipa (For

Technical Note. Micron NAND Flash Controller via Xilinx Spartan -3 FPGA. Overview. TN-29-06: NAND Flash Controller on Spartan-3 Overview

UNIVERSITY OF CALICUT

USER MANUAL MODEL

Grasshopper3 U3. Point Grey Research Inc Riverside Way Richmond, BC Canada V6W 1K7 T (604)

Specification and Design of a Video Phone System

The Answer to the 14 Most Frequently Asked Modbus Questions

Using Xilinx ISE for VHDL Based Design

Basler. Line Scan Cameras

T O B C A T C A S E G E O V I S A T DETECTIE E N B L U R R I N G V A N P E R S O N E N IN P A N O R A MISCHE BEELDEN

Lab 2.0 Thermal Camera Interface

Portable III. No extended memory when using the expanded memory board E17-2 to E17-3 and E17-5 to E17-6

Fixplot Instruction Manual. (data plotting program)

Embedded Systems Design Course Applying the mbed microcontroller

Simple Image File Formats

MULTIMEDIA INSTALLING THE MULTIMEDIA UPGRADE

Mirror Mount Video Monitor/Recorder with Front and Rear View Night Cameras PLCMDVR5

Computer Organization. and Instruction Execution. August 22

Coding Guidelines for Datapath Synthesis

AN974 APPLICATION NOTE

How to create buttons and navigation bars

Raspberry-Pi VGA Fen Logic Ltd. 8 September 2014 G.J. van Loo

OPERATION MANUAL. MV-410RGB Layout Editor. Version 2.1- higher

Chapter I Model801, Model802 Functions and Features

Xilinx Answer Data2Mem Usage and Debugging Guide

Wireless Device Low-Level API Specification

Artikel-Detailinformationen

Online Visa Photo Upload Process

Modeling a GPS Receiver Using SystemC

KIP 720 CIS SCANNING SYSTEM WITH ADVANCED KIP REAL TIME THRESHOLDING TECHNOLOGY

Creating Web Pages with Microsoft FrontPage

Transcription:

Sprites in Block ROM 1 Example 37 Sprites in Block ROM In Example 36 we made a sprite by storing the bit map of three initials in a VHDL ROM. To make a larger sprite we could use the Core Generator to store the sprite image in either distributed or block RAM/ROM. Block ROM will allow larger images to be stored and in this example we will use a block ROM to store the image of the two loons shown in Fig. 6.11. The size of this image is 240 x 160 pixels and is available at www.lbebooks.com as the image file loons240x160.jpg. In Example 30 we showed how to create a block ROM using the Core Generator where the initial data is stored in a.coe file. We can convert the JPEG image in the file loons240x160.jpg to a corresponding.coe file called loons240x160.coe by using the Matlab function IMG2coe8(imgfile, outfile) shown in Listing 6.7. This function will work with other standard image formats other than JPEG such as bmp, gif, and tif. Note that the.coe file produced by this function contains an 8-bit byte for each image pixel with the format color byte = [R2,R1,R0,G2,G1,G0,B1,B0] (6-3) The original image read into the Matlab function in Listing 6.7 will contain 8-bits of red, 8-bits of green, and 8-bits of blue. The 8-bit color byte stored in the.coe file will contain only the upper 3 bits of red, the upper 3 bits of green, and the upper 2 bits of blue. We need to do this because as we have seen the Nexys-2 board supports only 8-bit VGA colors. The resulting 8-bit color image is called img2 in Listing 6.7 and will be of reduced quality from the original image as can be seen in Fig. 6.12. Figure 6.11 Loon photo by Edie Haskell Figure 6.12 The image img2 produced by Listing 6.7

2 Example 37 Listing 6.7 IMG2coe8.m function img2 = IMG2coe8(imgfile, outfile) % Create.coe file from.jpg image %.coe file contains 8-bit words (bytes) % each byte contains one 8-bit pixel % color byte: [R2,R1,R0,G2,G1,G0,B1,B0] % img2 = IMG2coe8(imgfile, outfile) % img2 is 8-bit color image % imgfile = input.jpg file % outfile = output.coe file % Example: % img2 = IMG2coe8('loons240x160.jpg', 'loons240x160.coe'); img = imread(imgfile); height = size(img, 1); width = size(img, 2); s = fopen(outfile,'wb'); %opens the output file fprintf(s,'%s\n','; VGA Memory Map '); fprintf(s,'%s\n',';.coe file with hex coefficients '); fprintf(s,'; Height: %d, Width: %d\n\n', height, width); fprintf(s,'%s\n','memory_initialization_radix=16;'); fprintf(s,'%s\n','memory_initialization_vector='); cnt = 0; img2 = img; for r=1:height for c=1:width cnt = cnt + 1; R = img(r,c,1); G = img(r,c,2); B = img(r,c,3); Rb = dec2bin(r,8); Gb = dec2bin(g,8); Bb = dec2bin(b,8); img2(r,c,1) = bin2dec([rb(1:3) '00000']); img2(r,c,2) = bin2dec([gb(1:3) '00000']); img2(r,c,3) = bin2dec([bb(1:2) '000000']); Outbyte = [ Rb(1:3) Gb(1:3) Bb(1:2) ]; if (Outbyte(1:4) == '0000') fprintf(s,'0%x',bin2dec(outbyte)); else fprintf(s,'%x',bin2dec(outbyte)); if ((c == width) && (r == height)) fprintf(s,'%c',';'); else if (mod(cnt,32) == 0) fprintf(s,'%c\n',','); else fprintf(s,'%c',','); fclose(s);

Sprites in Block ROM 3 The.coe file produced by Listing 6.7 will contain 240 160 = 38,400 bytes. Following the procedure described in Example 30 we can use the Core Generator to create a read only block memory component called loons240x160, which is 8 bits wide with a depth of 38400 as shown in Fig. 6.13. This component would be part of the toplevel design shown in Fig. 6.14. Figure 6.13 Generating the component loons240x160 btn(3) mclk 50 MHz clr clkdiv clk25 btn(3) clk clr vga_640x480 hsync vsync hc(9:0) vc(9:0) vidon clk loons240x160 rom_addr16(15:0) M(7:0) vga_bsprite sw(7:0) red(2:0) green(2:0) blue(1:0) Figure 6.14 Top-level design to display the loon photo on the VGA screen

4 Example 37 Listing 6.8 is the VHDL program for the component vga_bsprite shown in Fig. 6.14. It is similar to the component vga_initials shown in Fig. 6.9 of Example 36 and described by Listing 6.5. The main difference is that rom_addr16(15:0) is now calculated from the formula rom _ addr16 = ypix 240 + xpix where xpix and ypix are the local image coordinates within the loon image of the pixel whose color byte is at address rom_addr16 in the block ROM loons240x160. Listing 6.8 vga_bsprite.vhd -- Example 37a: vga_bsprite library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity vga_bsprite is port ( vidon: in std_logic; hc : in std_logic_vector(9 downto 0); vc : in std_logic_vector(9 downto 0); M: in std_logic_vector(7 downto 0); sw: in std_logic_vector(7 downto 0); rom_addr16: out std_logic_vector(15 downto 0); red : out std_logic_vector(2 downto 0); green : out std_logic_vector(2 downto 0); blue : out std_logic_vector(1 downto 0) ); vga_bsprite; architecture vga_bsprite of vga_bsprite is constant hbp: std_logic_vector(9 downto 0) := "0010010000"; --Horizontal back porch = 144 (128+16) constant vbp: std_logic_vector(9 downto 0) := "0000011111"; --Vertical back porch = 31 (2+29) constant w: integer := 240; constant h: integer := 160; signal xpix, ypix: std_logic_vector(9 downto 0); signal rom_addr : std_logic_vector(16 downto 0); signal C1, R1: std_logic_vector(9 downto 0); signal spriteon, R, G, B: std_logic; --set C1 and R1 using switches C1 <= '0' & SW(3 downto 0) & "00001"; R1 <= '0' & SW(7 downto 4) & "00001"; ypix <= vc - vbp - R1; xpix <= hc - hbp - C1; --Enable sprite video out when within the sprite region spriteon <= '1' when (((hc >= C1 + hbp) and (hc < C1 + hbp + w)) and ((vc >= R1 + vbp) and (vc < R1 + vbp + h))) else '0';

Sprites in Block ROM 5 Listing 6.8 (cont.) vga_bsprite.vhd process(xpix, ypix) variable rom_addr1, rom_addr2: STD_LOGIC_VECTOR (16 downto 0); rom_addr1 := (ypix & "0000000") + ('0' & ypix & "000000") + ("00" & ypix & "00000") + ("000" & ypix & "0000"); -- y*(128+64+32+16) = y*240 rom_addr2 := rom_addr1 + ("00000000" & xpix); -- y*240+x rom_addr16 <= rom_addr2(15 downto 0); process; process(spriteon, vidon, M) variable j: integer; red <= "000"; green <= "000"; blue <= "00"; if spriteon = '1' and vidon = '1' then red <= M(7 downto 5); green <= M(4 downto 2); blue <= M(1 downto 0); if; process; vga_bsprite; that Notice how we multiply ypix by 240 using a shift and add method by recognizing ( ) ypix 240 = ypix 128 + 64 + 32 + 16 The red, green, and blue outputs are obtained from the loon240x160 ROM output M(7:0) according to the color byte format shown in Eq. (6-3). Listing 6.9 is the VHDL program for the top-level design shown in Fig. 6.14.

6 Example 37 Listing 6.9 vga_bsprite_top.vhd -- Example 37b: vga_bsprite_top library IEEE; use IEEE.STD_LOGIC_1164.all; use work.vga_components.all; entity vga_bsprite_top is port( mclk : in STD_LOGIC; btn : in STD_LOGIC_VECTOR(3 downto 0); sw : in STD_LOGIC_VECTOR(7 downto 0); hsync : out STD_LOGIC; vsync : out STD_LOGIC; red : out std_logic_vector(2 downto 0); green : out std_logic_vector(2 downto 0); blue : out std_logic_vector(1 downto 0) ); vga_bsprite_top; architecture vga_bsprite_top of vga_bsprite_top is signal clr, clk25, vidon: std_logic; signal hc, vc: std_logic_vector(9 downto 0); signal M: std_logic_vector(7 downto 0); signal rom_addr16: std_logic_vector(15 downto 0); clr <= btn(3); U1 : clkdiv port map(mclk => mclk, clr => clr, clk25 => clk25); U2 : vga_640x480 port map(clk => clk25, clr => clr, hsync => hsync, vsync => vsync, hc => hc, vc => vc, vidon => vidon); U3 : vga_bsprite port map(vidon => vidon, hc => hc, vc => vc, M => M, sw => sw, rom_addr16 => rom_addr16, red => red, green => green, blue => blue); U4 : loons240x160 port map (addr => rom_addr16, clk => clk25, dout => M); vga_bsprite_top;