📜 ⬆️ ⬇️

How does it feel to create a game for Game Boy in 2017

image

Everyone had a childhood dream. Personally, I dreamed of creating a game for my first console: the Nintendo Game Boy. Today my dream came true - I released the first game for the Game Boy on a real cartridge : Sheep It Up!

In this article I will talk about the tools I used and the obstacles that a newcomer had to overcome in order to create a project. The article is very long, therefore it is divided into two parts:


A game


"Sheep it up!" - This is an arcade game in which the sheep must climb up, clinging to the flying Velcro. The concept is simple, but the game itself is rapidly becoming more and more difficult: how high can you climb without falling?
')
Gameplay Sheep It Up!

I myself am a collector, so I wanted the project to be created in the spirit of old Game Boy games. Therefore, everything was designed specifically for this game: a printed circuit board, a ROM, a shell, a protective case, and even a sticker! We also sought to maintain a reasonable price so that everyone could enjoy the game: $ 15 (+ shipping) . It will run on any Game Boy model, from the very first to the GBA SP, including the Super Game Boy.



If you still have a Game Boy, then you can buy a cartridge on the publisher’s website:

https://catskullgames.com/sheep-it-up

Tools: thank you, 2017!


In the 90s, creating a game for an 8-bit console was a real challenge, and it required a whole team of experienced professionals. I consider designers, artists and developers of that time to be real heroes: they managed to create such beautiful games with the help of tools whose capabilities are much poorer than those of modern ones.

In 2017, you still need to put a lot of work to make the game for an 8-bit console. But thanks to the wonderful communities of lovers, we have a lot of tools that make life easier! Without them, a newcomer like me would not have been able alone to create a game for a Game Boy. So what are these tools?

To begin with, I will tell about a programming language. In those days, all specialized gaming equipment was programmed in assembly language. This is still possible (and even recommended). But now this is not the only option, because many development kits for 8-bit and 16-bit consoles are based on the C language. For the Game Boy, this awesome tool is called the Game Boy Developers Kit (GBDK).

In addition, to create graphics and level design, you no longer need to use millimeter paper and a handheld scanner. Fortunately, you can now use two complementary tools:



Last but not least, we need some way to test the game. And here modern tools are also important. In the 90s, developers had to use expensive ICE kits, but today we have powerful software emulators that can be run on any computer. For testing your own game, the BGB is the best choice. This is a very accurate Game Boy emulator with a powerful debugger - an indispensable tool for creating a working game!


The game itself is in the upper right corner, and all the other frightening windows are different debugging tools!

But be prepared for the fact that to ensure the performance of the game will have to test it on this equipment. In the 90s, people recorded their program on an EPROM chip and used special cartridges to insert this chip into a real Game Boy. This process is effective, but rather lengthy and expensive. Today we have the so-called "Flashcarts" - cartridges in which you can insert SD cards with a ROM image, launched on the Game Boy. The idea is similar, but new tools are more convenient and faster to use. There are different Flashcarts for Game Boy, but in my opinion the best one is created by Krikzz: Everdrive Game Boy . A newer and improved model was released this summer, but I used the old version I bought earlier.




Flashcart from the 90s and from the 2010s

Despite the existence of all these wonderful tools in 2017, creating a game for a gaming console in 1989 still remains a challenge. Especially for those who are used to using "modern tools", such as Unity, Unreal Engine or Godot. I will talk about the main difficulties that I encountered during the development of Sheep It Up! , including how I was surprised by the principles of the Game Boy.

Technical difficulties


Size limitations


Let's start with the obvious: Sheep It Up! - this is a pretty simple game. This is due to one reason - the whole game weighs only 32KB . That is - all the code, images and even sounds fit into a tiny space of 32KB. For comparison, I can say that 32KB is the size of the Wikipedia logo in a very small resolution:


Full game: 32KB


160x146 pixels (PNG-24): 32KB

Of course, not every Game Boy game fits in 32KB. For me it was a technical limitation to release the game on a real cartridge (more on this in the second part) . The best and most famous Game Boy games actually weigh much more:


In reality, only a few games for Game Boy occupied only 32 KB. Basically, they were created in the early stages of the life of the console. For example, both Alleyway (one of the games released with the Game Boy in Japan) and Tetris (released with the console in the US and Europe) fit in 32KB. Both of these games are wonderful, but due to the small size of the cartridge, they are fairly “limited” in scale: only one screen, a small amount of graphic and sound resources, etc.



Alleyway and Tetris were 32KB games, like Sheep It Up!

Processor: play with portable power!


Game Boy has a 4MHz processor , specifically designed for the console (a combination of Zilog Z80 and Intel 8080 processors) . In general, the Gameboy's processing power is comparable to NES, and even slightly higher due to the smaller screen size and the number of colors (more on this later) . Despite the low speed at 4 MHz, all games for the Game Boy provided a stable 60fps . Learn PS4 Pro and Xbox One X!

But for a programmer who just graduated from college, the biggest limitation was the eight-bit processor. As you probably know, inside all computers use zeroes and ones for data processing. One digit, which can have a value of 0 or 1, is called a “bit” (short for “binary digit,” “binary value,” because it can have only two values) . A processor is called “8-bit” if it can process 8 bits of data in one operation.

How does this affect the creation of video games?

The fewer bits the processor can handle, the more limited the gameplay variables are. For example, games use a set of integers representing different values: energy, speed, points, etc.

With 8 data bits, an integer can store smaller values ​​compared to 16-bit variables:


If this is still not clear to you, let's take a concrete example from Sheet It Up!


As you can see in the picture, the variable points contains 5 digits and can vary from 0 to 99999. Unfortunately, this is much more than can be stored in an 8-bit integer. In fact, even a 16-bit variable will not be enough to store such a “big” account!

So, to track the number of points in Sheep It Up! I had to use not one, but five different 8-bit integer variables. Imagine how “fun” it is to handle all these variables, especially considering that I added the ability to save record results. I had to compare two values ​​stored in five different variables. Programming on an 8-bit system makes it necessary to constantly look for such complex solutions, while modern systems simply use 32-bit or 64-bit variables, and never deliver such problems to their programmers.

(Note to experienced game developers: I know that it was possible to find a more efficient approach than storing a single digit with values ​​from 0 to 9 as a whole int8. But in fact I needed each variable to take values ​​from 0 to 255 , because I do not store the points themselves, but the tile identifiers used to display this number on the screen.)

Difficulties with graphics


One world, two planes


All the images on the Game Boy consist of two elements: a background layer (BKG) and several moving objects called sprites (OBJ). On the screen there can be no more than 40 sprites. In addition, there is another limitation: Game Boy can not display more than ten sprites in one line.

Background (BKG) and Sprites (OBJ)

In fact, everything is a bit more complicated, because there is an additional layer of “window” that can scroll regardless of the background. It is usually used for the user interface (points, etc.). But this layer is opaque: it hides all the graphic data of the background layer behind it. Therefore, for the sake of simplicity, we can assume that there is one “background” layer in the Game Boy, but if necessary, its part can be scrolled independently.

Game Boy sees four colors!


Let's finally get acquainted with the most obvious: the original Game Boy model could only display four different colors.


Some may argue that Light Gray (light gray) and Dark Gray (dark gray) are actually rather Light Green (light green) and Dark Green (dark green), but this is not important: for painting graphics, in any case, we can use only four colors. At least this applies to the background, because in the case of sprites the situation is different!


And in fact, as seen in the picture, the sheep is painted in just three colors. Why so? Actually I drew a sprite in four colors. But the fourth color (here it is black) is simply not displayed, because the Game Boy is used as a “transparent color”. Because of this, not all sprites become square images, they can have various shapes, allowing you to see the background behind them.


Does this mean that you can not use black color for drawing sprites?

Of course not, as can be seen below with the example of the Velcro sprite. For this sprite, I used a different palette of 3 + 1 colors: “White” is used as a transparent color, and “Black” is displayed on the sprite.


Fun with palettes


Despite being limited to just four colors, the Game Boy actually uses three different palettes to display images, which is pretty cool!


As you can see, there is one palette in four colors for the background layer and two palettes in 3 colors + 1 transparent color that can be used by sprites (each sprite can use one or another palette) . The great thing is that you can freely assign any color to any slot of the palette. This allows you to create very interesting effects, such as a gradual decrease and increase in screen brightness, used in many games.


To implement on the Game Boy screen shading, just change the colors in the three palettes. At the first stage, all the slots of the palettes are filled with white. Then, in the second stage, the darkest slot of color (black) is filled with light gray, gradually revealing the image. At the third stage, the light gray becomes dark gray, and so on, until all four colors are displayed in each palette.

Using a similar method, we can make the character "flicker", changing the colors in the palette in each frame. For example, this method is used when Mario in Super Mario Land catches an asterisk and becomes invulnerable.

Create a world of tiles!


There is one more, the last, oddity in how the Game Boy displays images, especially it is unusual for a game developer working with the current generation engines. Since the console does not have a “frame buffer”, we must set the color of each pixel on the screen separately. All screen images are collected from a variety of "tiles", i.e. 8x8 pixels. This applies to both backgrounds and sprites:


This technique, designed to reduce the amount of video memory needed to display graphics, implies that we cannot draw arbitrary lines on the Game Boy screen. But this is also one of the secrets that allow the Game Boy to display such beautiful games with a processor of only 4 MHz and 8KB of video memory (that's right, kilobyte, not megabytes or gigabytes).
However, one of the drawbacks of such a tile mapping is that our sheep and sticky sprites consist of several sprites. The sheep has a size of 16x16 pixels, so in theory it needs four 8x8 sprites to display it. Fortunately, the Game Boy also has an 8x16 sprite display mode, and that means every object in Sheep It Up! It consists of only two sprites, not four.


Do you remember that we are limited to a maximum of 40 sprites on the screen ? In addition, the Game Boy cannot display more than 10 sprites on a single line .

In our case, this means that we can place no more than five sheep on one line, rather than ten, as you might have thought at first (because from the point of view of the “iron” the sheep consists of two sprites) .

Full screen tiles


I did not mention this before, but the Game Boy screen resolution is 160x144 pixels. This means that to close the entire screen, you need 20x18 = 360 tiles .


Unfortunately, the Game Boy video memory is limited (8KB) , and can store only 256 different sprites . This means that without software tricks you cannot display a full-screen image:


The secret is in reuse of tiles: as you can see, there is a lot of “empty space” in the image of the tile, that is, one “white tile” of RAM is located on the image several times. The screen saver uses only 178 different tiles, that is, if you wish, I could add additional details.


I don’t know what type of tile reuse was used in the 90s, but today we have a very handy tool for this called the Game Boy Tile Data Generator . We give him a PNG image (in four colors) , and it automatically generates tiles and a tile map that needs to be displayed on a real Game Boy. Obviously, it also automatically recognizes and re-uses identical tiles in order to save as much console video memory as possible!


For reference, most of the 80s and 90s consoles worked in a similar way and had an 8x8-based screen: Nes, Master System, PC-Engine, Super Nintendo, Genesis, Game Boy, Game Gear ... The first popular home consoles with PlayStation and Saturn were the frame buffer, and the first portable console with this technology was the Game Boy Advance (Atari Lynx was the first portable console to manage individual pixels) . That is, having mastered the "work with tiles" on the Game Boy, you can use your skills in the future on other retroconsole!

Pro tips: create four-color sprites!


Let's end with a little advice given by talented Nintendo developers. Look at the screenshot from Wario Land:


Do you see that the coin sprite is actually drawn in four colors? How did they manage to do this if I said that the Game Boy can only display three colors per sprite?

Gif

The answer is simple: each coin consists of two sprites, and each sprite uses its own palette. As you can see, when we divide a coin into two halves, it is actually made up of two 8x16 sprites. As usual, Nintendo is very attentive to details: they do not just look like two connected “sprite halves”, the developers slightly shifted them and they overlap each other by one pixel, which makes the coin look more like a single element!

Conclusion


This concludes the first part of the post-mortem of my game. Thanks for reading! In the second part, we will discuss problems with sound (there is also a lot of strange there!) And the creation of cartridges without destroying the already existing game for the Game Boy. I will also review reviews received from players in Sheep It Up!


Hope you enjoyed the article! And if you have a Game Boy console, don't forget that you can buy a beautiful Sheep It Up cartridge for only $ 15 from Catskull games. Before sending each cartridge is assembled manually!

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


All Articles