3. Description of the Gameboy platform

 

We chose Gameboy from Nintendo [12] as our game platform. Our choice was made based on that we had seen some pages on the Internet with a lot of information about the system, showing how one could make games for it.

 

3.1 History of the Gameboy

In 1989, Nintendo released their portable game console called Gameboy (GB). It had a monochrome display (160x144 pixels and four levels of gray), four channels stereo sound, and a link port for playing multiplayer games and all powered by a processor quite similar to the ZILOG Z80.

Figure 3.1: Gameboy Classic.

 As the Gameboy was one of the first portable game console with exchangeable games, combined with low power consumption and the large number of games available for the system, made it very popular. There were some competitors to the Gameboy, like Game Gear by Sega and Lynx by Atari. They had color to be more attractive, but the displays were consuming quite a lot of power (giving them 1/10 of the playtime compared to the Gameboy) and they also were a little bit larger. As the consumers wanted playtime on a portable system, the monochrome Gameboy survived its color competitors.

 In 1998 Nintendo released two new products. First a smaller version of the Gameboy, called Gameboy pocket (GBP). This was the same system as the Gameboy released almost ten years earlier but smaller, lower power consumption and with an improved monochrome display. The other system was more revolutionary, it was the Gameboy Color (GBC), a color version of the GBP, almost as small as the GBP, but it had a color display. To make the color system low power, it used a reflective color display without high power back light. This together with the fact that it was compatible with the old Gameboy, making it possible to run all the old Gameboy games, made it quite popular.

Figure 3.2: Gameboy pocket.

Figure 3.3: Gameboy Color.

 

3.2 Technical specifications of the system

3.2.1 Overview

The GBC system has the following technical specification:

 CPU: 8-bit (Similar to the Z80 processor.)

Main RAM: 8K Byte Video RAM: 8K Byte

Screen Size 67mm (2.6")

Resolution: 160x144 (20x18 tiles)

Max # of sprites: 40

Max # sprites/line: 10

Max sprite size: 8x16

Min sprite size: 8x8

Clock Speed: 4.194304 MHz (4.194/8.388MHz GBC)

Horiz Sync: 9198 KHz

Vert Sync: 59.73 Hz

Sound: 4 channels with stereo sound

 

3.2.2 Memory map and banked memory

All of the registers controller graphics, sound, communication are mapped in memory, according to Figure 3.4. The 64kB limit of the Z80 processor makes it hard to fit everything within the memory space, therefor some parts of the memory map is divided into several memory banks. Bank switching is a common method to use when the desired address space is larger than what can be addressed, so by using a register that selects what physical memory a part of the visual address space should access, more memory can be accessed. This is for example used for the upper part of the user program memory, so larger games than 32kB can be used. By letting the lower 16kB be fixed, but the upper 16kB address one out of 64 pages, each 16kB in size, making it possible to address 8MB program memory.

Figure 3.4: The memory map of the Gameboy.

 

3.2.3 Background, window and tiles

The graphics in the Gameboy is based on tiles. A tile is a block of 8x8 pixels, which for the background can use one out of eight palettes. In memory an array of 32x32 words, the tilemap, is stored, where each word selects one tile and sets its properties of one tile. This makes it possible to build large backgrounds using very little memory, since it uses the same tiles in many places. This also makes the graphics much faster. See Figure 3.5 how the tiles and the tilemap generate the graphics seen on the screen.

Figure 3.5: Image showing how the screen is generated by the tilemap and the tile data.

Figure 3.6: Image showing how the screen is showing a small part of the entire map.

 

The screen can only show 20x18 tiles (160x144 pixels), but many games use larger backgrounds. By using a 32x32 tilemap and selecting what part of the tilemap to show on the screen, a scrolling background can be created. As shown in Figure 3.6 where a part of a landscape is selected with the scrollx and scrolly registers. The car racing game we wrote uses this functionality.

 It is also possible to place a window of transparent tiles above the background, this is for showing game status like score etc, that is placed on a static position of the screen, so this part is not scrolled with the background. In the games we wrote we didnít use this feature.

 

3.2.4 Sprites

In most games objects are moving around on the screen independently of the background. These are often referred to as sprites. The Gameboy graphics hardware support up to 40 sprites on the screen simultaneously, but with the limit of 10 sprites per scanline. Each sprite can either be 8x8 or 8x16 pixels, but all sprites must have the same size. If larger sprites are needed then several sprites are placed next to each other, forming a virtually larger sprite. In our car game we place four 8x8 tiles next to each other forming a 16x16 car.

 

3.2.5 Sound

The sound is generated in stereo with four channels:

Quadrangular wave patterns with sweep and envelope functions

Quadrangular wave patterns with envelope functions

Wave patterns in RAM

White noise with envelope.

In a real game, there must be sound to make the game attractive, but in the games we made we didnít use the sound system as the communication part was the main part of our project. Therefor we will not discuss the subject further in this report.

 

3.2.6 The link port

The GB link port is a shift register. It is accessible through memory address location 0xFF01 (shift register) and 0xFF02 (ctrl register).

When two Gameboys are connected with a serial cable, the shift registers are connected so that they feed each other, like in Figure 3.7. When one of the Gameboys want to send a byte, it tells the clock generator to generate eight pulses (500kHz), clocking both shift registers making them swap contents. When the transfer is complete, an interrupt is generated in the second Gameboy, so it can handle the received data.

Figure 3.7: The shift registers connected to exchange data between two Gameboys through the link cable.

 

3.2.7 The cartridge port

The games for Gameboy are stored in a cartridge, which is placed in the cartridge port on the back of the Gameboy. On the port, all pins of the memory bus are available, so the cartridge only need to contain a ROM and a bank select chip. (Some cartridges also contain a battery backed up RAM for saving game status, high scores etc). This design makes it possible to design a game cartridge that also can contain other features like more IO, AD converters etc. The pinout of the cartridge is shown in figure 3.8. Signals D0..D7 are used to transmit data to and from memory, A0..A15 selects what address to access, CS, RD & WR are control signals to select if the memory location should be read or written.

Figure 3.8: The pinout of a cartridge.

 

3.3 Development hardware

To be able to develop games we need a Gameboy to run them on of course, we also need a writable cartridge to try the games with and a programmer to program the cartridges.

 

3.3.1 Programmers

The writable cartridges were not available nearby. There are several programmers available on the Internet, but we chose the GameJack from UFO64 [11], a company in Hongkong. See Figure 3.9

Figure 3.9: Game Jack cartridge writer.

The programmer is attached to a parallel port of a PC and with the included loader program it is possible to program a flash cartridge with a .GB file generated by our compiler. With the programmer we chose it is also quite easy to make a copy of a game by placing the source cartridge in the left slot and putting an empty cartridge into the right slot and then pressing the start button.

 

3.3.2 Cartridges

The writeable cartridges we used (Figure 3.10 and Figure 3.11), store data in Flash memories. There is also some RAM with battery backup available on the cartridges (for saving highscores etc.). In the 64Mbit cartridge (Figure 3.11) there is also a vibrator.

Figure 3.10: 4Mb cartridge.

Figure 3.11: 64Mb cartridge with rumble.

3.4 Development software

Nintendo do not have their own development tools available for the public to use, but there is some information available on the Internet.

2.4.1 Compilers

To create software for the Gameboy, one first needs a compiler. As the processor is quite similar to the Z80 processor, a standard Z80 compiler could easily be converted to work for the Gameboy, and this have been done. Writing games in pure assembler requires a lot of work, and an easier method would be to use a high level language like C. There are a few open source c-compilers with Z80 systems as target. These could also be converted for the Gameboy system, not as easy like with an assembler, but has been done. There is one system called the GBDK [8] (Gameboy Development Kit) that is available for free and can be downloaded from http://www.sourceforge.net/gbdk and is quite easy to use. This package not only contains a compiler, it also contains some standard libraries and .H files with Gameboy registers defined, to make it easy to use the Gameboy hardware. GBDK is being improved constantly, the first version we got didnít support 16-bit integers, but after a couple of months this feature was added. This meant that we used our own 16-bit integer routines in the first game we made, but when we made the second game there was 16-bit integer support, so we didnít need to use our own routines.

 

3.4.2 Other tools

The most important tool is the simulator. There are many simulators available, but we used the No$GB simulator. It is a shareware simulator that probably is one of the most accurate simulators available as shareware. The simulator makes it possible to try to use software without having to program it into a flashcard, saving a lot of time. This can however only be done with the standard hardware, as the simulator can not simulate hardware built by your self. In our case we could not simulate the Bluetooth plugins.

 In games, one needs graphics in form of tiles and tile maps. The graphic data usually requires the most of the memory space, and is therefor not something you want to write into your code by hand, so tools for this would be great. Fortunately these tools are available on the Internet. The tools we used are called Gameboy Tile Editor (Figure 3.12) and Gameboy Map Editor (Figure 3.13) and are made by H.Mulder. Another tool we used is Gameboy High Color Converter (Figure 3.14) by Glen Cook that converts an image to a format that can be shown on the Gameboy with many colors.

Figure 3.12: Screenshot from GB Tile Editor.

Figure 3.13: Screenshot from GB map editor.

Figure 3.14: Screenshot of the Gameboy High Color Converter.

 

3.4.3 Gameboy related web sites

There is a lot of information available about the Gameboy, and also quite a lot of source code. Here is a list of some of the best web sites with information about the Gameboy that could be worth looking into. (As the Internet is constantly changing, some of them might be dead at the time you read this report)

Http://www.devrs.com/gb

Jeff Frohweinís Gameboy Devírs page. The best Gameboy development site on the net. Frequently updated!

Http://www.tripmode.com/gbdev/

Jasonís Post Punk Progression GB page contains a lot of source code

Http://gbdk.sourceforge.net/

The home of GBDK, the c/asm compiler used for game development

http://marc.rawer.de/Gameboy

Marc Rawerís GB page showing how to add extra IO to a GB through the cartridge port

Http://www.ziegler.desaign.de/readplus.htm

Reiner Zieglerís GB page showing how to rebuild a standard cartridge to a flash cartridge.

Http://www.cd64.com/

CD64, where you can buy flash cartridges and cartridge programmers.