<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Z Space Blog - Emulators</title><link href="https://zlg.space/blog/" rel="alternate"/><link href="https://zlg.space/blog/feeds/t/emulators.atom.xml" rel="self"/><id>https://zlg.space/blog/</id><updated>2022-12-11T11:34:00-08:00</updated><entry><title>Palette Customization with Mednafen</title><link href="https://zlg.space/blog/palette-customization-with-mednafen.html" rel="alternate"/><published>2017-09-22T00:00:00-07:00</published><updated>2022-12-11T11:34:00-08:00</updated><author><name>zlg</name></author><id>tag:zlg.space,2017-09-22:/blog/palette-customization-with-mednafen.html</id><summary type="html">&lt;p&gt;I received &lt;em&gt;Metroid: Samus Returns&lt;/em&gt; in the mail this week, which is a 3DS remake
of the original &lt;em&gt;Metroid II: Return of Samus&lt;/em&gt; for the GameBoy. Before I started
playing &lt;em&gt;Samus Returns&lt;/em&gt;, I wanted to take another romp through the original,
so I hopped on OBS and recorded myself on a casual run. This morning, I
watched &lt;a href="http://speeddemosarchive.com/Metroid2.html#100SS"&gt;Emptyeye's great single-segment 100% run of Metroid II&lt;/a&gt;,
which inspired me to record another run. Before that, though, I wanted to
see what I could do to make the game pop a little bit, so it looks and feels
good to watch. Here's the end result:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Title screen" src="https://zlg.space/blog/images/metroid2/palette-title.png"/&gt;
&lt;img alt="Samus's starting point" src="https://zlg.space/blog/images/metroid2/palette-start.png"/&gt;
&lt;img alt="Entrance to SR388's caverns" src="https://zlg.space/blog/images/metroid2/palette-entrance.png"/&gt;
&lt;img alt="Morph Ball Bombs and missile pickups" src="https://zlg.space/blog/images/metroid2/palette-items.png"/&gt;
&lt;img alt="Missile pickup" src="https://zlg.space/blog/images/metroid2/palette-pickup.png"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://files.zlg.space/s/7iHz2ASBi3CMdQF"&gt;Verdant Miasma - a palette for Metroid 2: Return of Samus&lt;/a&gt;, by zlg&lt;/p&gt;
</summary><content type="html">&lt;p&gt;I received &lt;em&gt;Metroid: Samus Returns&lt;/em&gt; in the mail this week, which is a 3DS remake
of the original &lt;em&gt;Metroid II: Return of Samus&lt;/em&gt; for the GameBoy. Before I started
playing &lt;em&gt;Samus Returns&lt;/em&gt;, I wanted to take another romp through the original,
so I hopped on OBS and recorded myself on a casual run. This morning, I
watched &lt;a href="http://speeddemosarchive.com/Metroid2.html#100SS"&gt;Emptyeye's great single-segment 100% run of Metroid II&lt;/a&gt;,
which inspired me to record another run. Before that, though, I wanted to
see what I could do to make the game pop a little bit, so it looks and feels
good to watch. Here's the end result:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Title screen" src="https://zlg.space/blog/images/metroid2/palette-title.png"&gt; 
&lt;img alt="Samus's starting point" src="https://zlg.space/blog/images/metroid2/palette-start.png"&gt;
&lt;img alt="Entrance to SR388's caverns" src="https://zlg.space/blog/images/metroid2/palette-entrance.png"&gt;
&lt;img alt="Morph Ball Bombs and missile pickups" src="https://zlg.space/blog/images/metroid2/palette-items.png"&gt;
&lt;img alt="Missile pickup" src="https://zlg.space/blog/images/metroid2/palette-pickup.png"&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://files.zlg.space/s/7iHz2ASBi3CMdQF"&gt;Verdant Miasma - a palette for Metroid 2: Return of Samus&lt;/a&gt;, by zlg&lt;/p&gt;


&lt;h1&gt;Setup&lt;/h1&gt;
&lt;p&gt;The first issue I had was figuring out Mednafen's palette format. Mednafen's 
documentation is rather terse on this, but a brief chat with someone in 
&lt;code&gt;#mednafen&lt;/code&gt; on Freenode set things straight for me.&lt;/p&gt;
&lt;p&gt;Here's what you need to know about palettes, at least for the &lt;code&gt;gb&lt;/code&gt; plugin (for 
original GameBoy games):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Colors are in descending brightness, starting with the brightest&lt;/li&gt;
&lt;li&gt;The brick GB and Pocket can only do four colors&lt;/li&gt;
&lt;li&gt;Super GameBoy can do eight colors; one set of four for sprites, and another 
  for tiles&lt;/li&gt;
&lt;li&gt;Mednafen supports up to twelve colors, but &lt;em&gt;Metroid II&lt;/em&gt; only uses the first 
  ten.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here's a quick rundown of the colors for &lt;em&gt;Metroid II&lt;/em&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Tile highlight color&lt;/li&gt;
&lt;li&gt;Tile mid-range color&lt;/li&gt;
&lt;li&gt;Tile shading color&lt;/li&gt;
&lt;li&gt;Background color&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I set the first three colors very deliberately. I needed colors that would add 
to the mood of SR388 without looking too cartoony. However, each shade is used 
in different ways in different areas, so I needed a set of three colors that 
wouldn't clash when mixed, but had enough of a hue shift to be useful in 
multiple contexts.&lt;/p&gt;
&lt;p&gt;The colors I settled with are a faded beige, semi-gray green, and a subdued 
purple. I felt that they represented SR388 well, and the purple really adds to 
the immersion with the way the acid and some backgrounds look. Unfortunately, 
the game is rather monochrome to begin with, so there wasn't much I could do to 
combat that.&lt;/p&gt;
&lt;p&gt;That's it for the original GameBoy palette. If you're playing via Super GameBoy,
there are four more colors:&lt;/p&gt;
&lt;ol start="5"&gt;
&lt;li&gt;Samus' yellow portion&lt;/li&gt;
&lt;li&gt;Samus' red portion&lt;/li&gt;
&lt;li&gt;Samus' outline&lt;/li&gt;
&lt;li&gt;Pause/transition/extra detail color&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The eighth color (4th in this set) is interesting, because it shows up in a few
random places. For instance, it's used to create the shadowy look of the pause
screen, Samus' silhouette when making room transitions, and appears as part of
the environment from time to time. On Super GameBoy, I believe the 8th color is
set to match color 4, so Samus's sprite is never visible during transitions. So
in practice, Super GameBoy only offers about six or seven colors.&lt;/p&gt;
&lt;p&gt;The colors chosen are pretty obvious: Samus's suit needs to be some shade of 
yellow, and the accent needs to be red. Her outline was kind of a toss-up: Dark 
red looks good, but bleeds into the yellow a bit much. I opted for a desaturated 
medium brown, which makes a good accent color and dithers well due to being a 
neutral color. The transition color is a steel blue, to add a hint of hue 
shifting to any environments that use the color (like the starting area).&lt;/p&gt;
&lt;p&gt;Remember that I mentioned Mednafen supports up to twelve colors? &lt;em&gt;Metroid II&lt;/em&gt;
supports up to ten total:&lt;/p&gt;
&lt;ol start="9"&gt;
&lt;li&gt;being struck/item highlight&lt;/li&gt;
&lt;li&gt;being struck/item shade&lt;/li&gt;
&lt;li&gt;unused&lt;/li&gt;
&lt;li&gt;unused&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Colors 9 and 10 are used when you or an enemy flashes upon being struck, and for 
item pickups that flash, such as missiles or Power Suit upgrades. Originally, I 
was going to go for light and medium gray, similar to &lt;em&gt;Super Metroid&lt;/em&gt;'s look for 
missiles. It looked a little too plain. I could've went with another &lt;em&gt;Super 
Metroid&lt;/em&gt; look (bright yellow and magenta), but I felt like the game has enough 
yellow as it is; why add more?&lt;/p&gt;
&lt;p&gt;The bright teal colors for 9 and 10 worked out fantastically, as they aid
readability and are different enough from the rest of the game's colors to pop
out to the viewer. Once I had this nailed down, I knew I had found the right 
palette for the game.&lt;/p&gt;
&lt;h1&gt;The Palette&lt;/h1&gt;
&lt;p&gt;So the actual colors are as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;#BED287&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#3A882B&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#3F2E50&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#000000&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#D2CF72&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#AE1919&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#4B320C&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#354C53&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#6AECFF&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#2493A4&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Plug those into a color previewer or just about anything else, and you'll see 
them:&lt;/p&gt;
&lt;p&gt;&lt;img alt="The colors used in the palette" src="https://zlg.space/blog/images/metroid2/palette.png"&gt;&lt;/p&gt;
&lt;h1&gt;Hex Values Ahoy!&lt;/h1&gt;
&lt;p&gt;Next, I had to come back to Mednafen and figure out how to pull this together.
As I mentioned earlier, Mednafen's documentation didn't cover much. It just said
it supported 4, 8, or 12 color triplets in RGB format. I later learned that this
is in binary, not plain-text, so I needed a hex editor. Thankfully, Gentoo has
&lt;code&gt;app-editors/hexedit&lt;/code&gt;. Most other GNU/Linux distros should have some sort of hex
editor available, too. &lt;sup id="fnref:1"&gt;&lt;a class="footnote-ref" href="#fn:1"&gt;1&lt;/a&gt;&lt;/sup&gt; Once you've gotten a hex editor, you'll need to
enter the hex values, one after the other, in the list above. The result should
look something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nl"&gt;00000000&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="mh"&gt;BE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;D2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;87&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;3A&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;88&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;2B&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;3F&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;2E&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;50&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;00&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;00&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;00&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;D2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;CF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;72&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;AE&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;19&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;19&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;4B&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;32&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;0C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;35&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;4C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;53&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="err"&gt;...:.+?.P.....r...K2.5LS&lt;/span&gt;
&lt;span class="nl"&gt;00000018&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="mh"&gt;6A&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;EC&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;FF&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;24&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;93&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;A4&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;62&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;79&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="mh"&gt;20&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;7A&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;6C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;67&lt;/span&gt;&lt;span class="w"&gt;                                    &lt;/span&gt;&lt;span class="s"&gt;        j..$..by zlg&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You'll need to make sure it's &lt;em&gt;exactly&lt;/em&gt; like the above, in a hex editor, or it 
won't work. Since &lt;em&gt;Metroid II&lt;/em&gt; doesn't use the last two colors, I had 6 extra 
bytes to work with, so I added a by-line, because why not?&lt;/p&gt;
&lt;h1&gt;Putting it All Together&lt;/h1&gt;
&lt;p&gt;If you don't have a hex editor or aren't savvy enough to figure one out for 
yourself, here's a link to the resulting &lt;code&gt;.pal&lt;/code&gt; file:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://files.zlg.space/s/7iHz2ASBi3CMdQF"&gt;Verdant Miasma: a Metroid II: Return of Samus palette by zlg&lt;/a&gt;
(it's up at the top of this article, too)&lt;/p&gt;
&lt;p&gt;You'll want to save it with a &lt;code&gt;.pal&lt;/code&gt; extension, under 
&lt;code&gt;$HOME/.mednafen/palettes&lt;/code&gt;, with the same name as the ROM. For example: 
&lt;code&gt;"$HOME/.mednafen/palettes/Metroid 2 - Return of Samus.pal"&lt;/code&gt;. Windows and OS X 
users will need to replace &lt;code&gt;$HOME/.mednafen&lt;/code&gt; with the path where their Mednafen 
configuration is saved.&lt;/p&gt;
&lt;p&gt;The next time you run the game, it should greet you with a nice, colorized 
palette!&lt;/p&gt;
&lt;p&gt;It was fun putting this palette together. I hope you enjoy it as much as I do.&lt;/p&gt;
&lt;div class="footnote"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;Vim has a binary editing mode (&lt;code&gt;-b&lt;/code&gt; on the command line),
but it was adding an extraneous byte, causing Mednafen to complain at the file
size mismatch for the palette.&amp;#160;&lt;a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text"&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</content><category term="Video Games"/><category term="Metroid"/><category term="GameBoy"/><category term="Emulators"/><category term="Mednafen"/></entry></feed>