I have made some good progress with this project, and I am able to change the pixels of the tiles, and the colours used within palettes...
I now have an encoding routine in C# (using .net), that can check the length of the encoded data, and can scrap the tiles at the end of the data to "squeeze" the new tiles within the space of the old tiles (useful for testing, before being able to change the references to the graphics data/following code).
Pastebin of RLE.cs:https://pastebin.com/ABVsF4tB
This includes all the functions required to encode and decode graphics data (certain parameters must be set correctly). See the Program
script, listed below, for more details on the parameters I have been using to edit the graphics for Marathon mode in Tetris DX
This is an example of the side-effect of "squeezing" the graphics: (Image)
The black square is the lost data, most of this tile has be converted to "FF"'s, as this can be compressed easily to save space. You can see that this corrupted tile is the last tile in the VRAM block - look at the screen shot in my previous post (titled "Sample decompressed tile data"
). This shouldn't be left in any final release, but while testing it makes it easier to see the changes in the tiles I have edited, without corrupting the layout of the ROM.
My code is not ready to release as a compiled version for general use yet, but here is my quick and dirty Main
function (that is great for my needs) if you want to give it a go, and don't know C# very well:
Pastebin of Program.cs:https://pastebin.com/qa2c3hzV
I have found Tile Molester
to be a good tool for tile editing, allowing easy copy and pasting of tiles between files, and nice zoom and paint tools. Another tile editor with a very useful feature is YY-CHR
: you can invert the palette, or otherwise swap the 4 "colours" (i.e. palette index) around. This can be used for a "palette swap" within 1 palette, or for swapping the palette index around for a set of tiles that use differently ordered palettes to each other. This palette swapping tool gets around issues you will encounter if trying to use the paint fill tool to "swap colours" in a tile.
I am still hunting down the references to which palette is used by the tetrominos in Tetris DX. However, it does seem that for the tiles representing the tetrominos that are locked in place (these are on the GBC's background layer): the index of the tile in the tilemap is used to generate the palette number. i.e. Tile's A0 and A8 use BG palette #2 because the first 3 bits of the first byte ("A" or 1010 in binary) are 010, which indicates palette 2.
Hopefully, if I change the tile that is used, I will get the results I need. I haven't worked out how the palettes are assigned to the "falling" pieces (the sprite versions) yet though.BGB
is a great emulator for debugging the assembly (ASM) as it runs, although I don't really understand ASM yet, I am slowly learning. I have only really used a hex editor before, relying on the concept of "tables", which requires a lot of stabbing in the dark! Seeing data in RAM is very helpful, which is why BGB
is great. BGB
is also handy for viewing the currently loaded palettes (and the colours in use), along with the tiles in VRAM.
Sprites on the GBC (which use the OBJ palettes) are technically limited to 3 colours, as colour index #0 is always transparent. Currently 6 palettes are used for the falling tetrominos, so I am currently limited on the number of colours available. The background tiles can use all 4 colours in a palette, however many other parts of the screen are coloured in Tetris DX
, so currently not all colours can be changed freely. Also black and white are not "free", and will take up a slot in the palette, so this can also limit options if these colours are needed/used.
I used Photoshop
's pipette and an image of the current tetrominos, and then put the 24-bit HTML colour code in Bud Melvin's online 15-bit colour converter to produce a 15-bit colour code. I then edited the ROM in a Hex Editor to swap out the old colours for the new ones (after finding the list of colours within the ROM). I had to alter the tiles for the tetrominos so that they were using different palette indexes (to accommodate the new colours in the palettes).For Marathon mode (running on a GBC rather than a DMG):
- The 16 palettes are at offset 0xA747 in the ROM
- The encoded tilemap starts at offset 0x8179 in the ROM (and has a length of 0x9FC)
- The background colours for each of the 5(?) level increments are stored at offset 0x4903 in the ROM
I used RGBTuner
(part of the bmp2cgb
package) to fine-tune the colours in BGB
, on my DS Lite, and on my Game Boy Color (with added frontlight turned on and off). RGBTuner
is a really useful tool, as it allows you to see what the colours actually look like on specific hardware, rather than what they "should" look like. You can save your changes to the SRAM of the "game" and extract them for your own use (or run the ROM with the new save in BGB
to copy and paste from the palette there).
This is my current version of the tetrominos in Tetris DX
(slightly modified block design, colours are a reasonable match of the current standard colours): (2 Images)
The goal is to have 2 use-able colours for each piece (excluding black; which is a 3rd colour used by all pieces
), but that is not possible with the current palette arrangement. Even if the references to which palette is used can be changes, some pieces will still need to share a colour. If light blue
share a colour, and orange
share a colour, and purple
and dark blue
share a colour (or some equivalent variation), then this will work, as long as 7 OBJ palettes can be used (otherwise 2 pieces will have to share both colours - either 1 each or both use both).
At the moment: orange
share a colour, and purple
and dark blue
share a colour. Green
can only use red
as a second colour (as the BG palette used is shared with the "heart" on the pause screen). Light blue
uses its own two colours. Red
have only one colour each (as they share an OBJ palette).
And a cheeky bonus (as this was easy to achieve): I present Magic Tetris Challenge
with Tetris Guideline coloured tetrominos:
You can patch the ROM with the following IPS to play it for yourself: https://drive.google.com/open?id=17LWy0dhwEdjSfiJF_J941oYkhZgVHRNZ
- There is a limit of 1 colour per tetromino [other than them all sharing black]). It is very unlikely that more colours can be made available for use, as the rest of the screen's graphics use the remaining palettes.
- I removed the "white" highlight from the tetrominos, as it is actually transparent, and is not always "pretty" as a result. I also did this to the grey "Magical" polyominos for the same reason.
- The pips that make up the grid (and the "A" and "S" on the pause screen) are now orange, instead of pink, as a result of changing the colour of the L piece. I may change the reference to purple, if possible.
- The pieces do not dim when locked in place (like in the original) I will probably rectify this in v1.1
- I should probably tweak the colours to be more pastel, like the original. (coming in v1.1)
I will make a patch for the NES tiles in GB Tetris
too, now that I can use YY-CHR to invert the graphics easily. I should be able to select the Space Invaders palette by default too for GBC (this is the only inbuilt one that is inverted). Custom palettes suit this best though. It would be amazing to change this in to a Super Game Boy game, and have the palette change every 10 levels
But surely far too much work!
I hope this is useful to those embarking on their own GBC graphic hacking endeavours.
Game Boy Color - tile maps and palettes: https://www.chibiakumas.com/z80/platform.php#LessonP9
Game Boy Color - colour tweaking (RGBTuner, part of bmp2cgb): https://github.com/gitendo/bmp2cgb
24-bit -> 15-bit Colour converter: http://www.budmelvin.com/dev/15bitconverter.html
Emulator - BGB: https://bgb.bircd.org/
Tile Editor - Tile Molestor: https://www.romhacking.net/utilities/991/
Tile Editor - YY-CHR: https://www.romhacking.net/utilities/119/
(C++, older) OR http://www.romhacking.net/utilities/958/
(C# .net, newer) - both have the "colour swap" feature
Game Boy Header fixing - RGBDB (part of RGBDB): https://github.com/rednex/rgbds
(rgbfix -f g game.gbc
- to fix global checksum after making edits to rom)
Create and Apply IPS patches - Lunar IPS: https://www.romhacking.net/utilities/240/
(make sure only your patches, and no random errors or other hacks, are included before you create an IPS patch