Barcode Boy Technical Documentation 0.5
July 4th, 2017
Shonumi aka D.S. Baxter

***************************************************
1. Introduction
***************************************************

Appearing around 1992, the Barcode Boy is the earliest form of card-scanning on Nintendo's Game Boy line of handhelds, predating both the e-Reader and the Bardigun Taisen Reader by a number of years. Only a limited set of games made by Namcot were compatible (or rather absolutely required) the Barcode Boy. All of the games and the Barcode Boy itself were only released in Japan. Not much has been written about any of the games, like Battle Space or Monster Maker, and even less has been documented about the Barcode Boy hardware, the scanning process, and the barcodes. Again, here it is 2017, and there are such little efforts to preserve and record exotic portable gaming hardware. This small technical file aims to archive all the information I found through reverse engineering, hopefully serving as a guide for other emu-devs and providing details for gaming historians that would otherwise be lost to time. Here we go then.


***************************************************
2. General Hardware Information
***************************************************

* Barcode Boy is a rather bulky add-on that snaps on top of the original DMG (the gray "brick")
* Barcode Boy requires 2 AA batteries (with a DMG-01, that brings the total to 6 AA necessary to play any Barcode Boy game)
* Barcode Boy games are always labeled with a "B.B." logo with a little card.
* Includes a very, very short Link Cable
* Unlike the Barcode Taisen Bardigun reader, the Barcode Boy has no button. It is always "ON" when switched on, thus draining batteries even while not scanning


***************************************************
3. Barcode Boy Games
***************************************************

Only 5 Barcode Boy games are known to exist:

- Battle Space
- Monster Maker: Barcode Saga
- Kattobi Road
- Family Jockey 2
- Famista 3

Barcode Boy titles come in two types: those that absolutely require the Barcode Boy for any gameplay at all (専用カートリッジ) and those that merely support the Barcode Boy as an accessory for additional content (対応カートリッジ). These games are differentiated with red and blue "B.B." logos respectively. Only Battle Space and Monster Maker: Barcode Saga fall into the first group.


***************************************************
4. Barcode Boy-DMG Communication
***************************************************

Each game will first try to detect if the Barcode Boy is plugged in and turned on. The Game Boy will send the bytes [0x10, 0x07, 0x10, 0x07] as part of a handshake. A properly functioning Barcode Boy will return the bytes [0xFF, 0xFF, 0x10, 0x07]. Barcode Boy games will still successfully detect the Barcode Boy scanner even if the first two bytes in the reply to the handshake aren't 0xFF, probably to simplify the game code. As a result, the first two bytes of the handshake are useless and ignored, but the last two bytes *MUST* be [0x10, 0x07]. If the Barcode Boy is plugged in but not turned on, it responds with 0x00 for the entire handshake, and the game produces an error message.

After detection passes, the Game Boy will sit and wait for a response. The Game Boy, unlike how it works with other SIO devices, takes on a passive role with the Barcode Boy by switching to an external clock. The Game Boy actually requires the Barcode Boy to take the initiative when scanning. Therefore, it is assumed that the Barcode Boy uses an internal clock and drives serial communications while scanning a barcode.

Nitty-gritty bits:

1. The game logic pings the Barcode Boy with [0x10, 0x07, 0x10, 0x07]. The Barcode Boy is expected to reply; the first two bytes are not important (real hardware returns 0xFF), but the second two bytes must be [0x10, 0x07].

2. Afterwards, the Game Boy waits for input using an external clock. What follows are two strings of numbers representing the barcode data. The "numbers" are represented as ASCII instead of hex.

3. Both strings are 13-digits long and are the EAN-13 number corresponding to the barcode.

4. Before sending each string, the Barcode Boy sends a 0x02 byte.

5. After sending each string, the Barcode Boy sends a 0x03 byte.

6. And, that's it. Altogether, the Barcode Boy transmits 30 bytes to the Game Boy.

Overall known communication protocol:

* Handshake -> Send [0x10, 0x07, 0x10, 0x07] : Receive [0xFF, 0xFF, 0x10, 0x07]
* Start Barcode Data Transmission -> [0x02]
* Stop Barcode Data Transmission -> [0x03]

Standard communication flow:

[DMG]			[BCB]
Handshake	--->
		<---	Handshake

		<---	0x2
		<---	EAN-13
		<---	0x3

		<---	0x2
		<---	EAN-13
		<---	0x3

Since the Barcode Boy acts as master (after the handshake at least), the Game Boy never initiates a transfer during barcode transmission. When sending barcode data, the Barcode Boy doesn't seem to care what value the Game Boy writes to SB, although no Barcode Boy games write to SB at that time anyway. Ultimately unknown if the Barcode Boy accepts input beyond the handshake, but no evidence has been observed to suggest otherwise.

Once the Barcode Boy sends the handshake [0x10, 0x07] back to the Game Boy, the scanner returns 0xFF anytime the Game Boy tries to send additional data while the handheld is still on its own internal clock. After the Barcode Boy finishes sending back the barcode data to the Game Boy, it requires the handshake again. It appears the handshake can fail for unknown reasons (probably related to the hardware). For example, the Barcode Boy at times may send back [0x90, 0x07], which seems to indicate an error of some sort.

It should be noted that the barcode data itself is encapsulated by ASCII control codes, where 0x02 represents the Start of Text (STX) and 0x03 represents the End of Text (ETX).


***************************************************
5. Barcode Format
***************************************************

The two strings are the actual barcode data in numerical form. The barcode format itself is EAN-13, and a few games use JAN-13 specifically. Older JAN-13 barcodes start off with the flag code 49. Interestingly enough, the newer JAN-13 flag code is 45 and was introduced in 1992, the same year the Barcode Boy was released. Probably due to timing or convenience, the JAN-13 barcodes on the cards stuck to the older flag code. Some Barcode Boy barcodes are technically "coupons/vouchers" types, as they use the flag code 99 instead of 45 or 49. Family Jockey 2 and Famista 3 don't use JAN-13 specifically; instead they use random EAN-13 barcodes with varying flag codes.

Using scans of the barcode @ 600 DPI, the smallest bar width is approximately 7 pixels (give or take). With that information, it's possible to recreate the EAN-13 number with a sufficient image and barcode scanning software. It should be noted that the Barcode Boy appears to do away with the center guard, however, it maintains left and right guards.


***************************************************
6. Card Dumping + Emulation
***************************************************

Amazingly simple in comparison to something like Barcode Taisen Bardigun, chiefly because such a small amount of bytes need to be sent to the Game Boy. Basically, all you need to do is convert the barcode to EAN-13. Anything capable of reading standard barcodes found on most products should be sufficient to grab the numerical form of each card.

As far as emulation goes, simply convert the EAN-13 ASCII string to hex and transmit it accordingly.


***************************************************
7. Barcode Errors
***************************************************

Interestingly enough, a vast majority of the barcodes for Family Jockey 2 are completely incorrect. Only 3 out of the 8 barcodes actually generate horses with the stats listed on the cards. Barcodes A1, B1, and A4 work fine; the rest give stats that do not match up with the card's. Some, such as A2, even generate horses that are totally unfit for competition (A2 produces stats with 2s and 0s, and the max is supposed to be 9 in each category). It's not clear if this was a programming glitch or a mistake Namcot made when printing the cards, or some combination of the two. All other Barcode Boy games came packaged with cards that have no issues whatsoever.


***************************************************
8. Link Cable Compatibility
***************************************************

The Barcode Boy requires 5V power via Pin 1 of the Link Cable. As such it is incompatible with all official Link Cables (DMG-04, MGB-008, MGB-010, and CGB-003) since each one lacks Pin 1. However, the Link Cable included with the Barcode Boy is a special case that does have Pin 1 present. When using the Barcode Boy's Link Cable, it is possible to connect it to a Game Boy Pocket/Light/Color system with the MGB-004, as the adapter exposes Pin 1.


***************************************************
9. Barcodes
***************************************************

Below are the full 13 digit barcodes for all known Barcode Boy cards along with any names, other identifying information found on the card, or important notes.

Battle Space

	* Berserker		バーサーカー
	* 4907981000301

	* Valkyrie		バルキリー
	* 4908052808369

	* Grizzly Bear		グリズリー
	* 4916911302309

	* Magic Soldier		マホウセンシ
	* 4902776809367

	* Knight		ナイト
	* 4905672306367

	* Wraith		レイス
	* 4912713004366

	* Shaman		シャーマン
	* 4913508504399

	* Thief			シーフ
	* 4918156001351

	* Sorcerer		ソーサラー
	* 4911826551347

	* Warrior		ウォリアー
	* 4909062206350

Family Jockey 2

	* A1
	* 5893713522816

	* A2			(Erroneous Barcode)
	* 2378649896765

	* A4
	* 9845554422318

	* B1
	* 1509843019075

	* B2			(Erroneous Barcode)
	* 4232978865152

	* B4			(Erroneous Barcode)
	* 3572821107673

	* C3			(Erroneous Barcode)
	* 7164625542390

	* C5			(Erroneous Barcode)
	* 6319537443513

Famista 3

	* Home-Run Batter	ホームランバッター
	* 8357933639923

	* Senior Batter		高打者バッター
	* 7814374127798

	* Swift Batter		駿打者バッター
	* 9880692151263

	* Pitcher		ピッチャー
	* 1414213562177

Kattobi Road

	* Truck			フォワールド
	* 4902105002063

	* Sedan			ガウディ
	* 4901121110004

	* Racecar		ナイト 2000
	* 4903301160625

	* Japanese Street Car	ミイラターボ
	* 4902888119101

	* 4x4 Jeep		リイスラックス
	* 4901780161157

	* F1-style racecar	ロクタスヨンート

Monster Maker: Barcode Saga

	* Archer Lorian		弓使いロリエーン
	* 9998017308336

	* Archer Elysice	弓使いエリサイス
	* 9447410810323

	* Knight Lauren		騎士ローラン
	* 9052091324955

	* Dragon Knight Haagun	竜騎士ハーグン
	* 9322158686716

	* Warrior Diane		戦士ディアーネ
	* 9752412234900

	* Warrior Tamron	戦士タムローン
	* 9362462085911
