GameBoy Advance Programming Tiles. Atari 196?: As an engineering student at the University of Utah, Nolan Bushnell liked to sneak into the computer labs.

Slides:



Advertisements
Similar presentations
Using 2D sprite with OpenGL 2003 team Koguyue. Overview Motivation and basic concepts Advantages with using OpenGL Basic requirements of implementation.
Advertisements

Lecture 2 Concepts, Terms and Definitions. Display Devices They are divided into a lot of small squares called pixels (“PICture ELements”). Each pixel.
HW/Study Guide. Synchronization Make sure you understand the HW problems!
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
VGA Text Mode An introduction to font selection and to reprogramming of the Character Generator ram.
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Buffers Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Henry Hexmoor1 Chapter 7 Henry Hexmoor Registers and RTL.
Buffers Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Graphics Bitmaps Drawing characters glyphs and multicolor patterns.
Graphics and Still Images John H. Krantz Hanover College.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
UFCEKU-20-3Web Games Programming Tile-based and Isometric Worlds.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
Perspective, Scene Design, and Basic Animation
Counters and Registers
WHAT IS IT AND WHY SHOULD I CARE? 2.0.  GRAPHICS  Draw-type graphics (also called vector graphics) represent an image as a geometric shape made up of.
Higher Computing Data Representation.
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
Graphic images for computers Stored in files of binary data - Binary blobs Software has to know the binary format to decode the file and render an image.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Graphics A graphics program allows you to combine pictures and text in many different ways. Features – General Level Draw graphics Enter Text Common Tools.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Textures.
Variables and Objects, pointers and addresses: Chapter 3, Slide 1 variables and data objects are data containers with names the value of the variable is.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Lab 8 Bit-Mapped Graphics Moving from text-based graphics to bit- mapped graphics. Easy to draw graphic points and lines using INT 10h, Function 0Ch (write.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Computer Organization and Assembly Language Bitwise Operators.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
Graphics An image is made up of tiny dots called pixels (“picture elements”) The resolution determines the.
Digital Media Dr. Jim Rowan ITEC 2110 Chapter 3. Roll call.
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Homework due Test the random number generator Create a 1D array of n ints Fill the array with random numbers between 0 and 100 Compute and report the average.
Game Maker Galactic Mail Advanced Group: Complete Galactic Mail, then start developing an independent project.
COMPUTER GRAPHICS. Can refer to the number of pixels in a bitmapped image Can refer to the number of pixels in a bitmapped image The amount of space it.
Graphics in a computers memory How a picture (i.e. a graphic) is stored in a computers memory A computer screen is made up of little dots, called PICture.
Buffers Computer Graphics I, Fall 2010.
4. Kernel and VGA ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  None.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
Digital Media Dr. Jim Rowan ITEC 2110 Chapter 3. Roll call.
1 CSC103: Introduction to Computer and Programming Lecture No 27.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Lecture 11 Text mode video
Direct-Access Color Graphics Chapter 11. Graphics modes C++ provides a different combination of graphics characteristics. These characteristics include.
 Backlight 에서 나온 백색광이 액정 셀을 통과하면 서 투과율이 조절되고 red, green, blue 의 color filter 를 투과해 나오는 빛의 혼합을 통해 색이 구 성됨  Color filter 는 셀사이의 빛을 차단하는 black matrix,
Efficient Game Graphics From Flash MX 2004 Game Design Demystified.
ColecoVision Opgrade Module
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 5 Examples 1.
Computer Graphics: An Introduction
Memory Management.
Non Contiguous Memory Allocation
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
HADI Tutorial Templates
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Memory Units Memories store data in units from one to eight bits. The most common unit is the byte, which by definition is 8 bits. Computer memories are.
ECE 391 Exam 2 HKN Review Session
Microprocessor and Assembly Language
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
EE 319K Introduction to Embedded Systems
Random access memory Sequential circuits all depend upon the presence of memory. A flip-flop can store one bit of information. A register can store a single.
Registers Today we’ll see some common sequential devices: counters and registers. They’re good examples of sequential analysis and design. They are also.
C Language B. DHIVYA 17PCA140 II MCA.
Game Programming Algorithms and Techniques
Presentation transcript:

GameBoy Advance Programming Tiles

Atari 196?: As an engineering student at the University of Utah, Nolan Bushnell liked to sneak into the computer labs late at night to play computer games on the university's $7 million mainframes. 1972: Bushnell founded Atari with $250 of his own money and another $250 from business partner Ted Dabney. They then created and commercialized the world's first commercial video game, Pong. Bushnell was 27 years old. 1976: Warner Communications buys Atari from Bushnell for $28 million. 1977: Atari introduces the Atari Video Computer System (VCS), later renamed the Atari : December - Atari announces the Atari 400 and 800 personal computers. 1979: October - Atari begins shipping the Atari 400 and Atari 800 personal computers.

Typical Atari 800 Screenshot

Atari Graphics Graphics and Text Modes Display List Customizable Fonts –Area in memory that described fonts (characters) –Area in memory that was what went on screen Player/Missile Graphics

GBA Tiles Logical extension of the customizable character sets. Some of the terms used today are based on the historical derivation of the technology (The logical extension of the player/missile graphics is sprites)

Mode 3 Bitmaps Video Processing Circuitry Screen Video Memory What color to make a certain pixel

Mode 4 Bitmaps Video Processing Circuitry Screen Video Memory What color number to make a certain pixel Palette Memory What color is that?

Mode 0 Tilemaps Video Processing Circuitry Screen Video Memory What tile number to make a group of pixels Palette Memory What color is that? Tile Images (Character Blocks) What does that tile look like?

Tiles On Screen 30 20

Tiles & Tilemaps Tile –8x8 bitmap image Treated like big pixels, as the building block of an image –16 or 256 colors –32 or 64 bytes Tile Map –2D array of tile indexes –Tile : Tilemap :: Pixel : Bitmap

Tradeoff 8 bpp = 256 colors –Lots of colors –All tiles share the same palette. –Tile images take more space 4 bpp = 16 palettes of 16 colors apiece –Still have 256 colors More constraints More flexibility –Tile images smaller (i.e. can have more)

Illustrations from Tonc

GBA Tile Mode Features Up to 4 tiled background layers –Up to 1024x1024 pixels each Hardware scrolling –Maps can be larger than the screen Hardware Parallax (optional) –Layers scroll at different speeds to simulate depth Affine transformation (optional) –Rotation and scaling effects

Steps to Tiles Create tile images Create screen image Create a palette Store tile images in a character block Store screen image in one or more screen blocks Store palette in palette memory area Set image control buffer and Mode

Steps to Tiles 1.Create tile images 2.Create screen image 3.Create a palette 4.Store tile images in a character block 5.Store screen image in one or more screen blocks 6.Store palette in palette memory area 7.Set image control buffer and Mode

1&2&3. gfx2gba Usage gfx2gba -fsrc -t8 -mm file.bmp gfx2gba -fsrc -t8 -mm -c16 file.bmp -fsrc means produce c source files -t8 means 8 bit tiles -m Optimize tile images (remove duplicates, flip, etc. -c16 4bpp file.bmp should be a 256 color (8bpp) image. Add files to your project and extern them in your other files.

1&2&3. usenti

4&5. Video Buffer Layout for Tiles & Sprites Character Block Sprite Data You put tile data (images) here (what each tile looks like) You put the tile map here (where the tiles go on the screen) Screen Blocks

4&5. Video Buffer Layout for Tiles & Sprites Character Block Sprite Data You put tile data (images) here (what each tile looks like) You put the tile map here (where the tiles go on the screen) 16K 2K Screen Blocks

4,5&6. Video Memory CBB0CBB1CBB2CBB3 CBB4CBB5

4,5&6. Video Memory CBB0CBB1CBB2CBB3 CBB4CBB5 Tile Palette:0x

4,5&6. Video Memory CBB0CBB1CBB2CBB3 CBB4CBB5 Character Blocks 4 for tile images and maps0x kb2kb

4,5&6. Video Memory CBB0CBB1CBB2CBB3 CBB4CBB5 Tile Palette:0x Character Blocks 4 for tile images and maps0x kb2kb

4,5&6. Video Memory CBB0CBB1CBB2CBB3 CBB4CBB Stop Here

Tile Size One 256 color tile has 8x8 8-bit indexes for a total of 64 bytes. One character block will hold 256 of these tile images. One 16 color tile has 8x8 4-bit indexes for a total of 32 bytes. One character block will hold 512 of these images Recall that there are 4 screen blocks but space for the tile map must be allocated.

Do the Math Suppose you had an image that was very complex?

Can we tile this image?

How big are things 16 color tiles are 32 bytes apiece 256 color tiles are 64 bytes apiece

Can we tile this image? Mode 3 video memory is shorts of bytes or 75KB In tile mode at 8bpp (same as Mode 4) we will use bytes In tile mode at 4 bpp we would use only bytes EXCEPT!!!!

Max Number of Tiles In the tile map 10 bits are allocated to identify which tile goes in each position 10 bits means we can only have 1024 unique tiles –We can actually make it look like more since tiles can be flipped or be colored differently The screen is 20x30 tiles or 600 so we cannot tile an image that is > 1024 unique tiles!

Mode & BG Specifics ModeBackgroundsRotation/Scaling 00, 1, 2, 3No 10, 1, 2Yes (only background 2) 22, 3Yes BackgroundResolutionRotation/Scaling 0512 x 512No 1512 x 512No 2128 to 1024Yes 3128 to 1024Yes

Background Layers 0 & 1 –Max Resolution 512x512 –Tile map of 16 bit numbers 2 & 3 –Resolution from 128x128 to 1024x1024 –Rotation & Scaling –Tile map of 8 bit numbers

Color 256 color tiles –8 bits per pixel –Tiles share one 256 color palette 16 color tiles –4 bits per pixel –Tiles use one of 16 palettes, 16 colors each –Note: Total palette is still 256 colors Correct Incorrect: 256 color tiles being displayed as 16 color tiles

Tile Memory Double the sprite memory compared with bitmap modes Tile data video in video buffer –From 0x to 0x600FFFF –On 16k boundary (any of 4 spots) Tile map also stored in video buffer –On 2k boundary (any of 32 spots) Tile data and Tile map are in same space but normally would not overlap.

Video Memory CBB0CBB1CBB2CBB3 CBB4CBB5 Tile Palette:0x Character Blocks 4 for tile images and maps0x kb2kb

Tile Data and Tile Map The tile map is stored in the same location as the video buffer (in the bitmap video modes), an array of numbers that point to the tile images. In text backgrounds (0 and 1) the tile map is comprised of 16-bit numbers, while the rotation backgrounds (2 and 3) store 8-bit numbers in the tile map. When working with tile-based modes, video memory is divided into 4 logical char base blocks, which are made up of 32 smaller screen base blocks, as shown on the next slide.

Techniques Tile images must start at the beginning of a character block Tile maps must start at the beginning of a screen block How do we determine the correct address How do we do this in a C program?

4&5. Technique 1 Calculate the address of each character block and each screen block and create a bunch of #defines for each one #define CHARACTERBLOCK0 0x #define CHARACTERBLOCK1 0x #define SCREENBLOCK0 0x #define SCREENBLOCK1 0x

4&5. Technique 2 Write macros to calculate the addresses #define CHARBLOCK(n) \ (unsigned short *) (0x (n)*0x4000) #define SCREENBLOCK(n) \ (unsigned short *) (0x (n)*0x800)

4&5. Technique 3 Let C do all the work! Define structures: typedef struct { u16 tileimg[8192]; } charblock; typedef struct { u16 tilemap[1024]; } screenblock; Define pointers charblock *charblockBase = (charblock *)0x ; screenblock *screenblockBase = (screenblock *)0x ;

4&5. Technique 3 Continued Now you can directly access the block you want using array indexing!!!! for(i=0; i<PicTileLen; i++) { charblockBase[1].tileimg[i] = picTile[i]; } What if i exceeds 8192???

6. Palette No different than Mode 4!

7. Control Registers //background offset registers #define REG_BG0HOFS *(volatile unsigned short *)0x #define REG_BG1HOFS *(volatile unsigned short *)0x #define REG_BG2HOFS *(volatile unsigned short *)0x #define REG_BG3HOFS *(volatile unsigned short *)0x C #define REG_BG0VOFS *(volatile unsigned short *)0x #define REG_BG1VOFS *(volatile unsigned short *)0x #define REG_BG2VOFS *(volatile unsigned short *)0x A #define REG_BG3VOFS *(volatile unsigned short *)0x E //background control registers #define REG_BG0CNT *(volatile unsigned short*)0x #define REG_BG1CNT *(volatile unsigned short*)0x400000A #define REG_BG2CNT *(volatile unsigned short*)0x400000C #define REG_BG3CNT *(volatile unsigned short*)0x400000E

7. BGxCNT bits name description 0-1 Pr Priority. Determines drawing order of backgrounds. 2-3 CBB Character Base Block. Sets the charblock that serves as the base for character/tile indexing. Values: Mos Mosaic flag. Enables mosaic effect. 7 CMColor Mode. 16 colors (4bpp) if cleared; 256 colors (8bpp) if set SBB Screen Base Block. Sets the screenblock that serves as the base for screen-entry/map indexing. Values: Wr Affine Wrapping flag. If set, affine background wrap around at their edges. Has no effect on regular backgrounds as they wrap around by default Sz Background Size. Regular and affine backgrounds have different sizes available to them F0E0D0C0B0A PrCBBM CM SBB Wr Sz

BGxCNT #defines //macros and bit constants for setting the background control register specifics #define SBB(num) num << 8 #define CBB(num) num << 2 #define COLOR256 1 << 7 // Cols x Row #define BG_SIZE0 0<<14 // 32 x 32 tiles #define BG_SIZE1 1<<14 // 64 x 32 #define BG_SIZE2 2<<14 // 32 x 64 #define BG_SIZE3 3<<14 // 64 x 64

Tile Maps bits name description 0-9TIDTile ID (Thus maximum number of tiles per background is HFHorizontal flip if set 11VFVertical flip if set 12-15PBPalette bank in 4bpp (16 color) mode. Ignored in 8bpp (256 color) mode F0E0D0C0B0A PB VFHF TID

Moving on a Big Map

What's your model? Screen Moves? MAP SCREEN

What's your model? MAP SCREEN

What's your model? MAP SCREEN

What's your model? MAP SCREEN

Or Map Moves? MAP SCREEN

What's your model? MAP SCREEN

What's your model? MAP SCREEN

What's your model? MAP SCREEN

What's your model? MAP SCREEN Either Works!

I like the screen moves MAP SCREEN hoff voff The signs make more sense!

Use map coordinates MAP SCREEN hoff voff Row Col

Where to draw it? MAP SCREEN hoff voff Row Col Screen coordinates for object row screen = row -voff col screen = col -hoff

Questions?

Tile Setup //background setup registers and data #define REG_BG0CNT *(volatile unsigned short*)0x #define REG_BG1CNT *(volatile unsigned short*)0x400000A #define REG_BG2CNT *(volatile unsigned short*)0x400000C #define REG_BG3CNT *(volatile unsigned short*)0x400000E #define BG_COLOR256 0x80 #define CHAR_SHIFT 2 #define SCREEN_SHIFT 8 #define WRAPAROUND 0x1 //background tile bitmap sizes #define TEXTBG_SIZE_256x256 0x0 #define TEXTBG_SIZE_256x512 0x8000 #define TEXTBG_SIZE_512x256 0x4000 #define TEXTBG_SIZE_512x512 0xC000 //background memory offset macros #define CharBaseBlock(n) (((n)*0x4000)+0x ) #define ScreenBaseBlock(n) (((n)*0x800)+0x ) //background mode identifiers #define BG0_ENABLE 0x100 #define BG1_ENABLE 0x200 #define BG2_ENABLE 0x400 #define BG3_ENABLE 0x800

Tile setup (cont) //video identifiers #define REG_DISPCNT *(unsigned int*)0x #define BGPaletteMem ((unsigned short*)0x ) #define SetMode(mode) REG_DISPCNT = (mode) //vertical refresh register #define REG_DISPSTAT *(volatile unsigned short*)0x //button identifiers #define BUTTON_RIGHT 16 #define BUTTON_LEFT 32 #define BUTTON_UP 64 #define BUTTON_DOWN 128 #define BUTTONS (*(volatile unsigned int*)0x )

Tile setup(cont) int main(void) { //create a pointer to background 0 tilemap buffer unsigned short* bg0map =(unsigned short*)ScreenBaseBlock(31); //set up background 0 REG_BG0CNT = BG_COLOR256 | TEXTBG_SIZE_256x256 | (31 << SCREEN_SHIFT) | WRAPAROUND; //set video mode 0 with background 0 SetMode(0 | BG0_ENABLE); //copy the palette into the background palette memory DMAFastCopy((void*)test_Palette, (void*)BGPaletteMem, 256, DMA_16NOW); //copy the tile images into the tile memory DMAFastCopy((void*)test_Tiles, (void*)CharBaseBlock(0), 57984/4, DMA_32NOW); //copy the tile map into background 0 DMAFastCopy((void*)test_Map, (void*)bg0map, 512, DMA_32NOW);

Input & Tile Scrolling //main game loop while(1) { //wait for vertical refresh WaitVBlank(); //D-pad moves background if(!(BUTTONS & BUTTON_LEFT)) x--; if(!(BUTTONS & BUTTON_RIGHT)) x++; if(!(BUTTONS & BUTTON_UP)) y--; if(!(BUTTONS & BUTTON_DOWN)) y++; //use hardware background scrolling REG_BG0VOFS = y ; REG_BG0HOFS = x ; //wait for vertical refresh WaitVBlank(); for(n = 0; n < 4000; n++); } return 0; }

Questions?