
Show HN: I'm building a game for the Nintendo GameBoy - BonsaiDen
http://bonsaiden.github.io/Tuff.gb/
======
deathanatos
> Tuff including all graphics, characters, _ideas,_ sounds and maps are
> Copyright (c) 2014 Ivo Wetzel. All rights reserved.

(emphasis mine) IANAL, but my understanding is that at least in the US, it is
the expression of the idea (the software and code, the graphics, and the other
things mentioned on that line) that are subject to copyright, not the idea.
See [https://en.wikipedia.org/wiki/Idea-
expression_divide](https://en.wikipedia.org/wiki/Idea-expression_divide).

~~~
Mandelbug
IANAL, and yes, you can not copyright game mechanics or ideas. This is why so
many clones of every game exists. Because no one owns the rights to "a tower
defense".

~~~
zorked
IANAL, but The Tetris Company seems to have had legal successes in the area of
copyrighting mechanics.

~~~
yincrash
There is only one successful Tetris clone lawsuit.[1] Most Tetris clones are
removed just because they are fairly aggressive with their claims (not
necessarily because their claims are valid).

The successful suit was due to the playing field having the exact same
dimensions as well as very similar visual expressions as regular Tetris
outside of the just the game mechanic.

[1] [http://www.wired.co.uk/news/archive/2012-06/20/tetris-
clone-...](http://www.wired.co.uk/news/archive/2012-06/20/tetris-clone-ruling)

------
readerrrr
I have moved to the negative zone after trying the B button. :)

[http://i.imgur.com/pkZhTCJ.jpg](http://i.imgur.com/pkZhTCJ.jpg)

The screens are positioned correctly next to each other.

\----

Are you writing this in assembly?!

~~~
BonsaiDen
Yes, it's all written in z80 assembly, although the GameBoy CPU really uses a
mix of i8080 and z80 instructions, the mnemonics are all z80. I've also
written my own assembler just recently, to have more control over the output
and more easily generate debugging information:
[https://github.com/BonsaiDen/gbasm](https://github.com/BonsaiDen/gbasm)

~~~
harwoodr
"my own assembler" \- now you're just showing off. :)

~~~
BonsaiDen
Nah' I would only be showing off if I were to put it onto a real cartrdige and
GameBoy, wouldn't I? ;)

\-
[https://dl.dropboxusercontent.com/u/2332843/tuff.cartridge.j...](https://dl.dropboxusercontent.com/u/2332843/tuff.cartridge.jpg)
\-
[https://www.youtube.com/watch?v=yXNEeld8Lq8](https://www.youtube.com/watch?v=yXNEeld8Lq8)

~~~
stevelosh
If folks want to try it on a real Gameboy without all the wires, the
Drag'n'Derp works pretty well. It's a Gameboy cart with a USB port for easy
writing: [http://derpcart.com/](http://derpcart.com/)

~~~
BonsaiDen
I was looking at these option initially too, but ended up going for the
challenge since, both I read some not-so-good reviews and shipping the thing
to germany would probably ended up being at least as expensive as buying the
soldering equipment :) Building one of those custom GamePaks takes about ~4
hours once you have all the materials prepared (you really need very, very
thin wires!) and putting it together for the first time is one of those finger
crossing moments which you'll remember for a really long time :)

~~~
DanBC
I took a cart, removed the game IC, and soldered in a ZIF socket for eproms.
And I'm a klutz so it's easy enough.

[http://www.devrs.com/gb/files/faq.html](http://www.devrs.com/gb/files/faq.html)

~~~
voltagex_
Am I right in thinking that GameBoy carts are now a precious resource? We'll
run out one day?

~~~
JonnieCache
Pretty sure you could make your own with a 3d printer and one of those kitchen
PCB-etching setups you see people using. There's no magic in there AFAIK.

------
pavel_lishin
The attention to detail is awesome - I played for a little bit, then started
reading, and when I scrolled up the little bunny character was sleeping!

------
cadr
If anyone wants to go back more, AtariAge has good tutorials on 2600 game
programming. Nothing like counting clock cycles to make sure the CRT beam is
far enough over before changing the background buffer :)

[http://atariage.com/2600/programming/](http://atariage.com/2600/programming/)

~~~
pjmlp
Atari Archives also has quite a good selection of old programming books for
the later models.

[http://www.atariarchives.org/](http://www.atariarchives.org/)

------
matthewwiese
Reminds me a lot of Knytt and Knytt Stories created by Nicklas "Nifflas"
Nygren [1]

[1] - [http://nifflas.ni2.se/](http://nifflas.ni2.se/)

~~~
BonsaiDen
You got me! I enjoyed Knytt so much, and it was the game that first inspired
me to make the first version of Tuff way back in 2010 :)
[https://github.com/BonsaiDen/Tuff/commits/master](https://github.com/BonsaiDen/Tuff/commits/master)

------
ralphc
So why JavaScript for the assembler? Was it familiarity with the language, did
the dynamic nature of the language help out...?

~~~
BonsaiDen
I'm a full stack Web Developer at daytime and I'd argue that I probably do
speak JavaScript more fluently than I do English. So for me it really was a no
brainer. The custom conversion tools needed for the graphics / map / sounds
are also written in JS, so it's a bonus to have good interop with those too.

In addition to that, getting the compiler up to speed (takes < 90ms on my old
core i5) was a nice exercise in getting more familiar with v8's performance
analysis tools :)

~~~
grrowl
> probably do speak JavaScript more fluently than I do English

Ah, a feeling many of us know too well.

------
Lambdanaut
Rad. I'm writing a Z80 emulator in Haskell. I'll be sure to test Tuff on it
once I'm to the point where graphics are being drawn.

~~~
bane
You'll probably need to do a little work to make it work. The Gameboy used a
Sharp LR35902, which is kinda 8080-ish and kinda z80-ish and has some of it's
own stuff as well.

~~~
Lambdanaut
Yeah, I meant I was writing a Gameboy emulator.

~~~
bane
Either way, it's a really cool project! A working processor emulator, even a
slow one, kind of makes you realize how deceptively simple lots of old CPUs
are.

~~~
boyaka
More like the original CPU/microprocessor. The man behind the Z80 was also the
main contributor to Intel's 8080 as well as the 4004, which is arguably the
foundation of a general purpose computer (calculator + memory) on an
integrated circuit (microprocessor). I wouldn't say so much simple as it is
ingenious.

------
wslh
If you like this post you might like the titles in development for the Atari
2600+
[https://atariage.com/development_list.html](https://atariage.com/development_list.html)

------
tvirelli
Very cool. Not sure this was meant to happen, but at one point I did a double
jump over a wall and then just started to continuously fall and it never
stopped.

~~~
BonsaiDen
It's a 16x16 screen world which wraps around, if you move to the left or right
you should eventually land on a non-empty screen. The "world" is anything but
finished, to be honest, it's more of a debug / feature test world than
anything else at the moment :)

Here's a picture of the whole world for reference:
[https://dl.dropboxusercontent.com/u/2332843/tuff.map.png](https://dl.dropboxusercontent.com/u/2332843/tuff.map.png)

------
bttf
Could you go into a little more detail on how the process is for adding sounds
and sprites to the game?

I am very interested in this type of work and have been hacking at trying to
build a game for the SNES. All I've been able to do so far is to collect all
relevant documentation for developing it:
[https://github.com/bttf/snes_dev](https://github.com/bttf/snes_dev)

~~~
BonsaiDen
Sure!

I'll start with the graphics part, since that's the easier part of the two.

Since the original GameBoy has only 4 shades of gray, all "bitmaps" are 2 bits
per pixel so you can squeeze a total of 4 pixels into 1 byte, the graphics are
converted from PNG files via some JavaScript routines which can be found in
the convert.js file in the repository.

The GameBoy uses 8x8 pixel hardware tiles on a scrollable "background" and
supports up to 40 sprites which can be either 8x8 or 8x16 pixels in size.

There are 2 tile buffers in VRAM which partly overlap and only the lower one
can be used for sprites, which gives you 128, 8x8 tiles for use with sprites
and 256 for use with backgrounds.

Sprites can be mirrored, so this somewhat reduces the amount of graphics
needed for the player character.

In order to reduce the map data, each room uses 80 16x16 blocks which are
served from a meta table in memory, where each index maps to 4 8x8 tile
definitions of the block. When drawing the screen the code resolves the
individual 8x8 tiles and sets their value into the current VRAM buffer for the
screen (there are two, which are swapped, to minimize draw artefacts).

Since the meta table is limited to 256 16x16 blocks too (due to the fact that
the map format only uses 1 byte per block tile) there is some additional pre-
computation magic going on when creating the map data. Basically, the block
tiles are split into 4 x 8 rows, each screen then maps onto 4 of these "rows".
By then packing often uses block tiles together, you can have more details for
certain rooms since they don't need to use all of the different rows available
and can basically swap some of them out.

Also, all graphics and map data are additionally compressed with a custom LT
Type compression routing and are decompressed on the fly. Except for player
graphics, which are stored into a RAM buffer at start in order to avoid
graphic glichtes when switching out the sprite tile reference indexes and the
graphics at the same time.

Overall, the timing is really important since you don't have too much time
during the VBlank period (yes, it emulates a vblank!)

Now as for the sound, right now I'm really just setting the sound channel
register values pretty much "Per hand", meaning, that I pick some decent
values (tested in some GBA sound test ROM for gameboy sound channels I found
somehwere - yes the GBA still has the original GameBoys 4 channels, since it's
backwards compatible).

The sound data is stored in some kind of JSON format for easier editing, all
the bit field stuff is than generated at compile time and baked into the ROM.

I've also gotten a prototype of a music engine running (not yet in the
repository) where you'd play pre-defined sound "patterns" on virtual channels
and "mix" them down. The sound / music stuff really is a whole story of its
own, especially since there are nearly no references to find, except for some
old, undocumented ASM sources of some Rare Ware GameBoy ports of Banjo / Jet
Force Gemini which apparently got uploaded by one of the Sound Engineers at
Rare.

------
mind_heist
Quick question about the music for the game ; I see you have already answered
a few questions along those lines.

When the bunny dies , there is a sound for its micro-explosion. I remember
"Dangerous Dave" died with the same sound :) Are a lot of these
interchangeably used ? Are these just system sounds ? How do these work ?

------
arcatek
> On the web GameBoy Online is probably the best of the available JavaScript
> based emulators out there.

That's true, but I'm really trying to shake it off! And looking for
contributors, should you be interested :)

[1] [https://github.com/arcanis/virt.js](https://github.com/arcanis/virt.js)

------
bane
Wow fantastic. I can't wait to see it complete. Great art style and control
feel. Lots of nice subtle details.

------
0xA115A
Awesome project! So, are there any hard-way books or something, to begin
developing for GB platforms? ASM and C have already learned by me, but I'm
really frightened about code environment like IDE, testing and run on real hw?
Are this question already answered or I'm really can't google?

~~~
BonsaiDen
There are quite a few resources you can find after searching for a bit e.g
[http://problemkaputt.de/pandocs.htm](http://problemkaputt.de/pandocs.htm) or
[http://students.washington.edu/fidelp/galp/megaguides/GameBo...](http://students.washington.edu/fidelp/galp/megaguides/GameBoyProgrammingManual.pdf)
(the latter one being the original manual for licensed developers)

------
graup
Hey Ivo! Remember you from the Nintendocast days. Great to see you're still
doing awesome stuff! Rock on!

------
dahart
The feel of this game reminds me a lot of Montezuma's Revenge, a classic in my
book. Very cool, and nicely done!

I really like your project page as well, very concise, extremely informative,
and covers exactly the things that someone wanting to make their own would
need. Bookmarked!

------
prezjordan
I would _love_ to write GB/GBC/GBA games using something like Ruby (or
JavaScript!). Is this possible? Have any higher-level languages been used to
write games for these platforms?

~~~
jiggy2011
You would have to first port the ruby interpreter to the Zilog Z80 which could
be a challenge because it is only an 8bit CPU!

The GBA actually has a 32 bit ARM CPU, although a very slow one (16 Mhz) so
perhaps it would be possible to build a very minimal Ruby VM for that. I
wonder if it would be possible to optimize by building a JIT compiler and
JITing on an emulator before installing on the cartridge?

~~~
vegedor
libruby, if that is the core of the interpreter, weighs 2MB. That's not gonna
fly, even with heavy size optimization it would be unbearably slow, even on
just a subset.

------
justinlloyd
Nice. You can find RGBASM at OtakuNoZoku.com and the Gameboy Cribsheet too.
Along with a bunch of other tools and code. I can send you complete game
source if you want to study it.

------
hayksaakian
i fell below the water and began infinite falling

\-----

really cool and impressive that you developed an published a game on such a
platform, that's still easily playable via a browser

~~~
belzebub
So did I.

------
Globz
Seriously I am amazed by your project! I wish I had the time to do something
like that! Great job and I can't wait to play the final version.

~~~
BonsaiDen
It's a bit hard to find, but it's all there :)

\-
[http://gameboy.mongenel.com/dmg/gbspec.txt](http://gameboy.mongenel.com/dmg/gbspec.txt)
(html version
[http://problemkaputt.de/pandocs.htm#soundcontroller](http://problemkaputt.de/pandocs.htm#soundcontroller)
) \- [http://www.otakunozoku.com/nintendo-gameboy-
cribsheet/](http://www.otakunozoku.com/nintendo-gameboy-cribsheet/) \-
[http://realboyemulator.files.wordpress.com/2013/01/gbcpuman....](http://realboyemulator.files.wordpress.com/2013/01/gbcpuman.pdf)
\-
[http://students.washington.edu/fidelp/galp/megaguides/GameBo...](http://students.washington.edu/fidelp/galp/megaguides/GameBoyProgrammingManual.pdf)
(The original Manual)

There are more, but I can't seem to find the links right now :O

~~~
justinlloyd
Thanks for the shout-out! :)

You can also grab the RGASM project from the OtakuNoZoku website. I think
Carsten (Surfsmurf) may have revived it on his github. I think I also pushed
my source trees to github too. There is a GBC emulator that is both a COM
component, and works inside of Visual Studio (at least, VS from around year
2000). Bunch of docs too kicking around. I have copies of most of them still.

I wrote programmer docs, assembler (before switching to extending RGBASM),
linker, patcher, emulators, games, visual studio plugins, debugger, cartridge
downloader, serial port driver, bunch of libraries, etc. Ah... the good old
days.

------
Gracana
Cool project!

I got stuck really early on, oops:
[http://i.imgur.com/pqAblgU.png](http://i.imgur.com/pqAblgU.png)

~~~
BonsaiDen
You can do a wall jump or a double jump, at the moment all powerups are enable
from the start since I'm missing out on the animation for collecting them an
all other sorts of things. I tend to deviate from the gameplay aspects of
programming and spend a lot of time doing optimizations and tooling, just
recently I wrote my own assembler to cook the whole thing into the final ROM
image [https://github.com/BonsaiDen/gbasm](https://github.com/BonsaiDen/gbasm)

------
jastanton
Open up spotify on your mac and start playing a song. Visit
[http://bonsaiden.github.io/Tuff.gb](http://bonsaiden.github.io/Tuff.gb) is
the audio from spotify garbled?

I submit this bug:
[https://code.google.com/p/chromium/issues/detail?id=403907&t...](https://code.google.com/p/chromium/issues/detail?id=403907&thanks=403907&ts=1408045980)

~~~
BonsaiDen
It's known issue, I've to the exact same issue here on Linux, seems to be
related with their Web Audio implementation.

~~~
jastanton
If you can add anything to the bug listed above that would be super helpful
for the chrome team :)

------
Sealy
Thats really cool. Don't you find developing for it frustratingly slow though
by today's coding standards?

------
tutts
I really did get stuck.

[http://imgur.com/syZX03k](http://imgur.com/syZX03k)

~~~
albinoloverats
I ended up falling endlessly through a blank void :-\

~~~
sherjilozair
move left.

------
VikingCoder
Very cool. I hope to have spare time again in my life, at some point!

------
thisjepisje
How does this site manage to lower the volume of iTunes?

------
gnuvince
Pretty nice, I was even able to go out of bounds :)

------
c0deporn
Reminds me of A Boy and his Blob. Good work.

------
thanesh
Can I play this game in full screen?

------
Dewie
The sound I get when I open this page is pretty sharp, noisy and unpleasant. I
prefer it when websites have that turned off by default (unless it's obvious
that the web-page involves a video that I'm supposed to be watching or
something like that).

