Tetrapuzz – Tetris clone for AVR

This is a projected that I finished development on over a year ago and I’m just now getting around to documenting it. I wanted to program Tetris from scratch and make it modular so it could be used with different displays. Right now I know it’s working with a KS0108 graphic LCD screen. I also did quite a bit of work on it with the Nokia 3595 screen which is the trunk build of the SVN right now. For this writeup I threw together the KS0108 hardware and loaded that branch of the svn onto the ATmega168 so that I could take some pictures.  I’m happy to say it worked like a charm.  Details after the break.

Gameplay is quite pleasing. At power-up the screen displays a message and prompts for a button click to begin the game. The random seed used generate the order of pieces is gathered from the system clock when the first button press registers.  That way the pieces will not appear in the exact same order for every game.

I spent a lot of time working with the code to get the pieces to fit but not overlap each other or leave the game board. This can be seen in the box_game.c file. The BOX_check() and BOX_line_check() functions are where all the magic happens.  I’d love to go into detail about all the issues I ran into when coding this but since it was over a year ago I simply can’t remember.

Hardware

This is written for the AVR ATmega168 microprocessor. I prototyped this using the Dragon 500 board and an AVR Dragon programmer. The graphic LCD is a 128×64 pixel KS0108 compliant model that I picked up on eBay.

Software

I used my own local subversion repository and the Eclipse IDE when developing the software. Recently I set up Google Code project hosting for this and used svnsync to import the entire history.

Project Page: http://code.google.com/p/tetrapuzz/

Anonymous Source Checkout (graphic LCD branch):

svn checkout https://tetrapuzz.googlecode.com/svn/branches/GLCD tetrapuzz

3 thoughts on “Tetrapuzz – Tetris clone for AVR

  1. Pingback: AVR Tetris - Hack a Day

  2. I would have designed the blocks so that there was at least a 1-pixel space between each square. It makes it much easier to quickly tell the heigh or width of a section that you are about to drop your piece in. I’ve played dozens of tetris clones and the ones that have plain-solid blocks are the hardest to play. I noticed there is some dead space on either side of the well (i think that is what it is called, the playing area on tetris) you could always expand that to the full width of the screen to gain that extra pixel between each square.

  3. hello there, what would i need to port this to my pic 18f4550 project, will all the libraries work the same or will i have to write a separate game engine to run tetris or any other game on the micro controller.?

Leave a Reply