Arboles

Solo disponible en BuenasTareas
  • Páginas : 9 (2031 palabras )
  • Descarga(s) : 0
  • Publicado : 17 de mayo de 2011
Leer documento completo
Vista previa del texto
**********************************
* VIDEO TETRIS (C) Rickard Gunée *
**********************************

(This text is mostly a copy of the Video Tetris page on my homepage)

---- Introduction ----
I have made the game Tetris using a PIC16F84 running @ 12MHz. Tetris is an old Russian
computer game where you should try to fit in block into a play-field, quite simple but
really fun. Inmy version, the video signal is generated in software. The only hardware
used for the video generation is two resistors forming a 2-bit DA converter. Usually
the video signal is generated in video games is created with a dedicated video chips,
reading the image data from a graphics memory. In this project the video signal
is calculated in real-time by the microprocessor as the electron beamsweeps over
the screen.


---- How to play the game ----
The first screen is where you select how you want to play by moving the joystick:
DOWN: Human vs. Human (H-H), LEFT: Human vs. Computer (H-C) or RIGHT: Computer vs.
Computer (C-C). Start with FIRE. Unfortunately it is impossible to beat the computer,
since there was not enough room to make the computer beatable. That makes the computervs. computer game to play forever until someone reset the game using the reset switch.
You start serving by pressing fire, it is also possible to change direction and speed
of the ball using fire. The player who has the serve will get points. If the player
with the serve miss the ball, then the serve goes over to the other player.
When someone wins a game over picture will show and tell whowon.


---- The software ----
With a processor performing 3MIPS, it is not easy to make a video signal in software.
Each instruction performed takes 1/3 us. Each scan-line on the screen takes 64us, where
52us are visible, so it gives 52*3=156 visible clock cycles per line. Maximum resolution
that can be obtained is 156 pixels in x-axis if the software is setting one pixel per
clock (usingfor example only bcf and bsf), but more is needed to make a game, like
loops and such. A loop quantifies the time to 3-clock pieces, giving a resolution of
52 pixels. (One could obtain a kind of 156pixels resolution with one or two offset nops,
but the code to select this would eat to many clock cycles to do any good). However
Tetris is quite simple, the resoluton is quite low, and there isno motion, the blocks
of pixels are just turned on and off. The most demanding part of the game is to show the
score at the bottom of the screen, it is shown in the bottom of the screen. It obtains
higher resolution by loading the PORTB with the bitmap for the number and shift it out
one pixel per clock cycle.

So far I've only talked about the graphic generation. But there is more to it toget a
video signal. All scan-lines first have a 4us-sync pulse, then black for 8us, then the
52us graphic comes. These horizontal sync-pulses makes the TV understand when a scan-line
starts, but there is needed to send information about when a new picture starts too, it
is called vertical sync, and is a special pattern that tells the TV that a new image is
coming. There are two kinds ofvertical sync, because the image is divided into two part
images, showing even and odd lines, to get less flickering. In Tetris, the two images are
identical, so the game is not using the full y-resolution possible, but it doesn't matter
because it is way better than the x-resolution anyway, making the x-resolution the
biggest problem.

The game-field is kept in memory as a 32byte array, 16x16bits, where one bit is one pixel-
block on the screen. The area to the upper left is for showing the next block, and by making
it a part of the game field it is possible to use the same block-drawing routines as for the
game, and thereby saving memory. Each frame, the falling block is first removed from the
game-field, and then tests are performed if the block can move, as the player wants it...
tracking img