Little secrets of great savings

Why are 16 bytes is sufficient to save games, and other stuff
Fifty and one hundred years later, the programmers will still have the same problems: they will be greatly missed volume of available memory for the realization of all that I want.

25 years ago, game cartridges contain 64-128 kilobytes of memory, but somehow this volume enough to fit the game on dozens of hours of gameplay. Today, 128 KB - is the size of a small JPEG-image, and that is available in the modern home computer, in the era of Super Mario Bros. do not even have imagined.

There was music and sounds, and good for the time schedule. Yes, some could do with what happened in the game console or computer, but basically had to go to different lengths to fit into these modest possibilities enormous number of sounds, music, animations, images, and game algorithms. How is it managed to developers of those years?

The main secret games were written in assembly language, that is accounted for almost directly tells the processor which operations must be done. This is both a cause and a consequence: it would be difficult to work on large projects written in such a low level.

Another small detail: a lot of software should be written so that it could rule and fix another programmer after you. Developers of games for the Atari 2600, Sega Master System, NES and SNES and even under the more recent console late 90's type 1 or PlayStation Nintendo 64 was not to worry about it: why would someone outside the team to know how the product works? After the release of anything is not correct, the patch on the cartridge is not coasting. On the contrary, it is preferable to avoid any hacker, which produced cheat the system, for example, Game Genie . Games had almost complete control over the console without any operating systems, so did not need a multi-layer architecture that stuffing all modern products to improve the independence of software and hardware.

The basic techniques include the maximum code reuse, the same functionality is used over and over again. The same thing happened with the data: AI, graphics, music, sounds, and their only slightly altered to create the illusion of diversity. Games could generate the code and data necessary for execution, but this complicates debugging. Avoid using large amounts of meaningless. Often write their own libraries.



the merits and 8-bit address space. If 3 bits to be written is lost only 5 rather than 27, as 32-bit processor. (For this reason, 64-bit programs are almost always larger than 32-bit.) Bitmap of 16 colors does not take up much space, a block of 20 × 20 pixels require all ½ × 20 × 20 = 200 bytes. In one cycle of the processor can process 2 pixels.

Graphics had low resolution and was two-dimensional. But it was possible to successfully deceive the senses through pseudo-3D or 2.5D. The most famous 2.5D-car simulator is Rad Racer 1984. Lotus Esprit Challenge (right) in 1992 looks quite plausible.



elements 2.5D known first-person shooters Doom and Wolfenstein 3D. Left a fragment The Train: Escape to Normandy (1987) for Commodore 64 .

Music was generated on the fly, no one kept it in the recorded form - it just would not be enough space. Sometimes there are exceptions, but they only illustrate the unreasonableness of the era to keep the sounds of the game in the form of a record. Eighth of the cartridge 512 kilobytes Sonic the Hedgehog, the very first game of the series runs through the blue hedgehog from 1991, held this one sound duration of one to two seconds . It was necessary to name the company, the publisher loses at startup.

An example of this generation of music format can be MIDI, although the game at that time worked on a much lower level. Instead of notes used order patterns, which need much less memory. Here's an example of what can be achieved with one-bit sound.



The Legend of Zelda , most the first of the legendary series about elvenkind boy in a green cap for 1986 was a huge game, which even had to fit on the cartridge in the road as much as 128 kilobytes. Today, that number sounds ridiculous, but the game does not small: it consisted of one large and two nadmira dungeons, each of which was twice nadmira. The images are clickable.









The first trick is visible at once: the standard grid would be squeezed maximum. Underground consist of 16 × 16 = 256 screens nadmir of 8 × 16 = 128. Therefore, the data of the screen in which Link is, fit in one byte: 4 bits for each of the coordinates, and for one of the bits nadmira not was used. Interestingly, the second dungeon blue area in the form of the letter L does not fit in the allotted space of her, so her additional two screens are located to the left.

If you look closely, each screen is a matrix. Screens nadmira and dungeons were treated differently. Nadmira screen - a grid of 16 × 11 tiles, each of which may be ground, sand, stones, bushes, water, waterfall, tombstone, stairs, bridge / marina, hatch or a hole in the wall, plus a number of options for special decorations - trees and entrance to the cave, which were treated in a special way.

In addition to the land, more than 3 tiles is not used, so two bytes, divided into 4-bit Nibble, enough to store information about what types of tiles should be on the screen. Each tile requires only two bits of data. As a result, each screen requires 44 bytes of data (and two bytes to store information about the use of tiles). Total nadmir fit in a little less than 6 kilobytes.

Most of the screens nadmira uses either white, brown, or green color, and some - a brown to green, green to brown or white on brown. Two colors can be used as the color of the outer frame and the internal color elements. Total 6 options that fit into three bits or Nibble (polbayta).

Each of the rooms of the dungeon - a grid of 12 × 7 actual content. But this space is cut peculiar way: almost all the rooms except for special (inputs, the end of the room, and others) have no more than one type of barrier. This means that the storage of all information need only bits per tile, and a column byte 12 bytes to the whole room.

We still have 12 extra bits. Need to store information about each of the walls (personal, 3-door type, the point for the bomb exploded pass). 6 × 4 variants of the wall = 24, that is, everything fit in 5 bits. In addition, the need to store information about the type of obstruction: stone, statue, water / lava, sand or emptiness, which takes 3 bits. The last 4 bits define the color scheme of the room. Each of the color schemes defined by byte (2 options to 16 colors).

So, keeping all of the game world at the expense of the set of tricks go some kilobytes.

Conservation are also examples of different tricks. To store the information about bombs 4 bits is used, the second half byte used to store information about the number of keys (7). Boom and the money is used a single value in the byte length, so every shot of the 255 possible costs rupee. To store information about the number of pieces Triforsa swung away a byte, because you need to take into account the order of their collection.

There are 8 used treasure, but one of them has three levels, while the other two - two levels. There are 6 "passive" treasures that, for example, allow you to move through the water or move heavy stones, and one of them also has two levels. Finally, Link can be either a bronze, white or magic sword or it may be unarmed. Total possible to have 22 different items in the inventory, which is required for storage of 3 bytes, but will remain as much as 2 bits.

You can have up to 16 containers of hearts (4 bits) with different levels of occupancy (4 bits). Half hearts considered to be one of the remaining bits of equipment. Finally, the first quest can be either passed or not, it takes one more bit.

Six bits can be set 26 letters, 10 digits, and some special characters. The name given to preserve as much as 8 characters, which are stored in 6 bytes. In the Japanese version had to use the full range of ASCII, so there is a maximum length of 6 characters. Byte goes into screen coordinates in nadmire or dungeon, one byte at a variety of other data.

< So save the game fits in 16 bytes , in this case it is not just saving it signed the text. For comparison, this space is enough for 8 Cyrillic characters in UTF-8. Today, game developers are doing a lot to fit their preservation clustering file systems, but 16 bytes - it's just an error for the modern software and data.

In developing Crash Bandicoot for PlayStation 1 also had its own characteristics. RAM was the main problem, and then - all at the console was 2 megabytes of memory, so they had to go to crazy moves. Levels were more than 10 megabytes of data that had to load dynamically, avoiding sagging frame rate lower than 30 Hz.

For this was written by a wonderful system paging, which loads the pieces at 64 kilobytes as you move the player on the map. It was written so that even at the speed of the drive console 300 kbps progruzhat everything by the time the game character in the specified area of ​​the map.

For storing game resources (sounds, textures, models, code) in these pieces of 64 kilobytes utility was written wrapping. Some levels are barely frame will fit, so the utility used a variety of algorithms - first-fit, best-fit, and others. After reviewing several attempts to select the best option. The task was complicated by the fact that a change in Level-changing opportunities, wrapping design data, which was due to the complexity of the mathematical part of the process - like that is hard to explain to artists, who suddenly wanted something to alter. The biggest problem remains the optimization of code in C and assembly language, but in the end everything has gone in to the eyeballs - there were only 4 bytes of free space of two megabytes of RAM.

In the driving simulator 1984 Revs had a little trick. The game's graphics look as shown below. A large part of the screen is allocated for uniformly blue sky area

< br />


This creator of the game and took the British Geoff Crammond . He used this data area of ​​video memory for storing a rather large piece of code, which is in place for BBC Micro was very small. This area is painted over in blue, so the player does not know about it, if only the game did not end with an error - then the screen was filled with some rubbish.

Many of these tricks are used to this day, although the power of home computers and game consoles increased by many orders of magnitude.

Based on materials треда on Quora .

Source: geektimes.ru/post/242152/

Tags

See also

New and interesting