Close
0%
0%

1Kb Space Invaders

Reimplementation of the retro game Space Invaders in an attiny for the 1 Kb Challenge

Similar projects worth following
A game heavily inspired by Space Invaders implemented in an Attiny 2313 for the 1024 byte challenge.

Many shortcuts will be taken to fit this into the allowed 1024 bytes. I do however expect to create a fully functional, playable game in the end with scoring, sound and color VGA output in 640x480 60Hz mode.

The project will be coded in assembly, with the VGA and sound output being bit banged with precise timing control.

A timer interrupt will match the VGA Hsync requirements, and since the Vsync signals are multiples of Hsyncs they will be handled in the same ISR. Careful counting of cycles inside the ISR will be used to send the VGA active data.

The VGA line frequency of 31,5 kHz will be used for generating sound, also inside the ISR.

With most of the action happening in the ISR, approximately 90% of the CPU cycles will be spent here. The game logic and everything else will be executed during the Vertical retrace period, at 60Hz. With the Interrupt routine dictating most of the CPU action, several state machines will be implemented to handle the game logic like movement of the aliens, updating the position of the missiles and overall game state housekeeping.

A limited character set defined in Program memory will act as both a font (e.g. for displaying the score) as well as some simple "sprites" for the aliens, player and bunkers.

Invaders.S

Main program, written for the air-as assembler (need some minor changes if using AVR Studio)

Assembler Source File - 14.96 kB - 01/06/2017 at 02:55

Download

Invaders.ihex

Hex file for uploading to microcontoller without needing to look at or deal with the assembly files

ihex - 2.83 kB - 01/06/2017 at 02:54

Download

2313.h

Minimal header file to keep track of the AVR registers and definitions

h - 736.00 bytes - 01/06/2017 at 02:54

Download

  • 1 × 15 pin VGA connector
  • 1 × "Nintendo style" hand controller
  • 1 × 3,5 mm Jack for sound output
  • 1 × USB A connector for power.
  • 1 × 20 MHz X-tal

View all 10 components

  • Life goes on

    MortenW01/16/2017 at 15:22 0 comments

    Just a quick update now that the dust has settled after the judges results are out. I´m still working on this even if the hope of a nifty 3D Printer or any other price is now officially crushed. No hard feelings, there was some serious competition, and I´m sure the judges had a hard time comparing apples to oranges and still arriving at the final decision. I loved the competition, and send my thanks to HaD for putting this on, and regards to all fellow competitors.

    In the coming weeks I will bring back the shoe-horn and polish to get the last functionality included as space is made available by furter refining the code. In hindsight I also need to spend some more time updating the documentation both for quantity and quality.

    Stay tuned for more, and again congratulations to the winners.

  • Final log for the competition deadline

    MortenW01/06/2017 at 02:53 2 comments

    So I finally got a working game in 1024 bytes, and this will be my final entry into the competition.

    The following features are somewhat working

    • All functionality implemented in software on an Attiny 2313, only supported by passive components.
    • VGA 640 by 480 display in RGB colours, actual resolution is a lot less, but video signals are in line with the VGA specifications.
    • VGA colours and pixel offsets are updated on the fly line pr line while the video signal is generated. At 20MHz clock and cycles pr pixel.
    • Control by a "Nintendo style" hand controller, left right and fire.
    • All graphic objects are implemented as "tile objects" but the VGA driver implemented in assembly software handles pixel offsets to allow for smooth movement and accurate placement of the tiles
    • Score updated when destroying aliens.
    • Tiles are alternated between frames to mimic the original.

    This is what happens when you do the system drawing on a cellphone without the proper software at 4 o'clock at night just before a deadline.

  • 1 Day to go

    MortenW01/05/2017 at 01:39 1 comment

    Starting to count the hours now, rather than the days. Got a few more pieces of the puzzle in place, and with a little luck I might actually see this project finished in time. Got to hook up and test the game controller logic tomorrow, then tweak the alien move pattern some more and finally test the missile firing and collision detection. If all goes well I might even be able to put back in the bunker damage / shielding function that I took out for size reasons. Compiled code and data is currently sitting at 824 bytes., which on the Attiny 2313 and its 16 bit opcodes actually is less than 400 instructions + some data.

    Currently I'm rewriting the sound routine to use the 8 bit timer in CTC mode rather than the VGA interrupt routine I used initially.

  • Deadline is fast approaching

    MortenW01/03/2017 at 23:26 2 comments

    As the deadline is fast approaching I seem to run from problem to problem on this project. Having made a brave leap from AVR studio to the GNU toolchain on OSX (because of computer problems that I already try to forget), I have been on a constant and steep learning curve this last week.

    Things are finally starting to behave they way that was intended, but documentation and examples on these tools are scarce, so I have been practising a lot of trial and error along the way, and probably hit the bigger part of the "gotchas" that are out there. Just to show that this project is still alive I decided to post a screen-shot.

    The VGA routine is up and running, as is the initialisation and house-keeping logic. I still need to add the the other VGA colours (solder the Red and Green signals to the VGA connector) and include the rest of the game logic. I ended up stripping it all down to individual components to make it easier to troubleshoot when things got really strange the other night.

    Code and data is currently at 618 bytes, but some of that goes away when I´m done debugging. If all continues according to plan, I should be wrapping up this project with 5 minutes to spare before the deadline on Thursday.

  • Hardware

    MortenW12/06/2016 at 21:02 0 comments

    I started putting together the hardware for this project. As I will be on the road for most of December, I do not expect to create anything more fancy than the prototype circuit I have already built. After all I see this more as a software competition than a Hardware one. The prototying board I'm using is a "777" board from futurlec.

    The circuit is centred around the Attiny 2313, with USB connector for Power, the ISP connector at the top, and a connector for the VGA / Kbd breakout module on the right side.

    The VGA breakout board is from Parallax. It also contains PS-2 connector for keyboard and mouse, but I will not use them for this project.

    The controller is a cheap one I got from eBay. I need to break it open and connect to the switches as I suspect that there is some kind of uController inside this one.

    From the background in these pictures, you can see that christmas has already come to my house.

    Update: After doing some research on the controller I found that it actually contains a 16 bit parallell load, serial out shift register, no code / firmware. The buttons are just making contact directly on the PCB surface, so it would not be straightforward to wire each switch to a digital input. I now plan on using the serial signal as input to the game rather than discrete switches, maybe using the USI peripheral in the attiny (like a SPI bus). If the code required for this is too much to fit, I will have to change plans to use discrete switches (left, right and fire) instead of the hand controller.

View all 5 project logs

  • 1
    Step 1

    Build the circuit. This circuit can easily be reconstructed on a breadboard. My breakout for VGA connector and programmer are both single header and fit will with breadboard development.

  • 2
    Step 2

    Pick your favourite AVR toolchain, AVR studio or GNU / GCC on Linux or OSX. You will be able to upload the included hex file with any standard free AVR tool / programmer.

  • 3
    Step 3

    Play the game, and have fun

View all 3 instructions

Enjoy this project?

Share

Discussions

Poppy Ann wrote 01/10/2017 at 12:35 point

this sounds like a great project, I remember when I bought my first computer which was a Acorn Atom which came with all the parts in one plastic bag even the keyboard had to be built with each key having 4 separate parts which you had to solder yourself one of the first things I did was space invaders which I tried in basic to start with but soon moved to assembler it took several nights programming and cursing the cassette tape player which was how you had to store programs in the end I managed it all except for different colours which at the time I was very proud of good luck with this project.

Regards Poppy Ann. 

  Are you sure? yes | no

MortenW wrote 01/10/2017 at 17:53 point

I started off with a Sinclair ZX Spectrum, same deal with BASIC built in, and assembler for speed when needed. Casette tapes for storage and TV for display. I still have it stored in a box with some of the old favourite games. Nowadays a PC emulator is faster and more convenient for playing those old games.

  Are you sure? yes | no

Mars wrote 01/09/2017 at 19:32 point

Hey, you made the front page!  Awesome

  Are you sure? yes | no

MortenW wrote 01/09/2017 at 19:35 point

Thanks. I was going to replace the "original" space invaders screenshot with my own, but as it was with most games back in the day, the picture on the box was always better than the graphics in the actual game :-)

  Are you sure? yes | no

Mars wrote 12/30/2016 at 21:53 point

Any updates?  I want to see this working!  I need someone to run that useless Grand Prize marble maze, so I can claim the 1st prize 3d printer :-)

  Are you sure? yes | no

MortenW wrote 12/30/2016 at 22:32 point

Not much updates.  My trusted MS based laptop died over X-mas, and I´m transferring the project to my Mac. I know this is last minute, but I had no access to an alternative computer.  As for the prices, it might be more fair if the top ranked projects got to pick in order from the prices.  Not to sound ungrateful, but it might not just be down to the actual sales price of the donated price, but the actual value that any lucky winner find in it. I hope to have the main VGA lSR up and running tomorrow, and will post a video. I have most of the code in place, but have not been able to test or simulate, so that will take the time between now and the deadline.  I'm currently 200+ bytes over the 1024 limit, so might have to sacrifice some part of the game to make it fit, most likely the "bunkers" and how they take damage and shield the player......

  Are you sure? yes | no

Mars wrote 12/31/2016 at 02:28 point

I also had a random computer issue: The power supply in the old computer I use to flash my AVRs died.  I still use the parallel port.  I got it up and running again, but I did loose some time figuring out what the problem was.  I'm under the limit, but there's no user interface yet: the bug segments just bump into mushrooms and work their way down.  If I end up over limit, I'll just make it a screensaver.

  Are you sure? yes | no

MortenW wrote 12/06/2016 at 18:43 point

I have an idea for a system that is tile / font based, but where i can place the grid with pixel offsets. Each VGA line will be generated on the fly using 7 CPU cycles pr pixel.

  Are you sure? yes | no

[deleted]

[this comment has been deleted]

Mars wrote 12/03/2016 at 00:10 point

VGA is easy at 20mhz, especially if you add some SRAM https://hackaday.io/project/2056-cat-644

  Are you sure? yes | no

MortenW wrote 12/05/2016 at 16:39 point

Good question. VGA is actually achievable at 20MHz Attiny clock. Since I do not have enough memory for the entire 640x480 resolution (to display anything useful), each pixel will actually be "bigger". As long as the sync signals are fairly accurate (done with interrupt) the data transmitted for the visible line is quite forgiving. My actual resolution will be about 85 by 85, but monitor will sync and display this as 640x480 @ 60 Hz.

  Are you sure? yes | no

Mars wrote 12/06/2016 at 18:27 point

You probably need to use almost exclusively race the beam techniques and/or a grid of tiles.  The Uzebox is good example, and also uses AVR.  It's worth reading a little bit of VCS 2600 programming.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates