📜 ⬆️ ⬇️

Shake Space Invaders analogue in 1 kilobyte (original 1978 takes 8)



This game, largely inspired by Space Invaders, was written from scratch for ATtiny2313 and sent to the recently completed 1-kilobyte program on Hackaday .

It's not easy to put such a game at 1024 bytes. But the author decided to get a full-featured game with scoring, sound and a VGA-video output with a resolution of 640x480 and a frequency of 60 Hz.
')
Of course, all the code is written entirely in assembler, and to obtain sound and video, it is programmed to obtain exact time intervals.

A timer interrupt meets the VGA line synchronization requirements, and since the frame rate is obtained by dividing the line number by an integer, both types of synchronization can be put into one interrupt handling procedure. To do this, the procedure performs an exact counting of cycles.

The lower frequency of 31.5 kHz is taken in the same procedure as a basis for receiving sounds.

The interrupt handling procedure takes 90% of the machine time, so all the game logic is calculated during the ray retrace. Several state machines control the movement of characters, the determination of the position of rockets, etc.

A small character generator is used to store both the font for displaying the account, and tiles and sprites.

Just a few hours before the end of the reception of materials, the code was ready and sent to the competition. It turned out to be implemented everything that was planned. Generation of a standard VGA signal (although the actual resolution is significantly less than 640x480 - “huge square pixels”), control from a gamepad for SNES or its clone with three signals Clock, Latch, Data, software sprites with smooth movement, rather than jumping from familiarity in familiarity, scoring, cyclic change of tiles as in the original ...



The same gamepad:



You can also make the same device and play the 1-kilobyte analogue of Space Invaders. Assemble the circuit (quartz at 20 MHz is not shown, connects to pins 4 and 5, the connector on the right above is for the programmer). The author claims that he drew this scheme on a smartphone at 4 am just before being sent to the competition. Of course, an adapter of the company Parallax is optional, you can just take a VGA-connector.



When using an adapter, the device looks like this:



Compile the source ( program and header file ) using AVR Studio or GCC, or simply fill in the attached HEX file — it's faster, but you can't dig into the code. And you can personally make sure that the analogue of Space Invaders that fits into one kilobyte is a reality.

Source: https://habr.com/ru/post/446984/


All Articles