How to patch LSDj to use an inverted palette

March 4th, 2012

This article was originally posted on September 19th, 2009 and has now been revised to use BGB instead no$gmb as a debugger. However, the things described here are mostly irrelevant now, because the standard method of installing a backlight these days is with a biversion, i.e. a hardware inversion. It may still be interesting for educational purposes.

Yesterday Three years ago axolotl asked on 8bc whether it is possible to invert the monochrome palette in LSDj, for use with backlit screens with an inverted polarizing foil. And it’s very much possible to do, and it’s even possible to modify an existing ROM image. So, I’ll show you how I did it using a copy of the LSDj ROM, BGB, and optionally a hex editor. I’m using XVI32, but any hex editor would do.

The palette value is change by a hardware register, which is a place in memory that a Gameboy program can be write to, to change things. So I look it up in the Pan Docs, which is a manual to the Gameboy hardware. Let’s look in the section LCD Monochrome Palettes. There we see that the address is $ff47 in hexadecimal and how the value is constructed.

For this tutorial, right click the BGB window and choose options (or press F11), go to system and choose the Gameboy option. This will run the ROM in DMG mode, which is needed to find where the palette change happens. Open the ROM image, press esc to go to the debugger and open Debug>Access breakpoints and enter FF47 and make sure “on write” is checked. This tells the BGB to track any writes to that address so we can find the place where the palette is initialized and change it.

BGB create breakpoint

Click ok and press F9 to begin execution. (Or reset the emulator)

BGB palette breakpoint

BGB stops and show a bunch of machine instructions. The interesting part is the instructions at 019C and 019E. The instruction at 019C takes the hexadecimal value $E4, stores it in the CPU register A then writes it to the hardware register $FF47. This is the code we’re looking for. The value $E4 is the standard palette. Go back to pan docs and check again how the value is constructed.
Then let’s split the value into its individual colours.

$E4 = 11 10 01 00

11 is the lightest palette value and 00 is the darkest. Since want to invert the palette we’ll reverse the order.

      00 01 10 11 = $1B

Great. You may now right click the line at 019C, choose modify code and enter ld a,1B. The line that said ld a,E4 should now say ld a,1B. Choose run, reset to confirm that the palette is inverted and that LSDj doesn’t crash or anything. You may now go to file, save ROM as and save the file anywhere you want, preferably with a new file name.

Alternatively, you can use a hex editor to edit this value. This part of the tutorial was left unchanged from the first version, because no$gmb can’t save changes made to a ROM and thus needed a hex editor to modify the file.
Open the hex editor and replace the $E4 at position 019D with the value $1B. This address will vary depending on LSDj version.


Hex editor - before


Hex editor - after

Lastly, open the ROM in an emulator to confirm that the modification worked.


Enjoy the inverted palette.

The source lsdsong file for camvliez

June 19th, 2007

After two specific requests to release this song (From skrebbel and Bud Melvin) and one general plead for more open sav’s from neutral_insomniac, I decided to finally release the source file for Camvliez. (Click the name to see the original post where you can also listen to the tune as an MP3)

Click here for the LSDSong source for the tune

This post should also be seen as a sort of LSDj tutorial, and if you find it useful, please don’t hesitate to leave a comment or link to the post.

If you’re a beginner, who don’t know how to get started with LSDj, please do check out this comprehensive tutorial by starpause and this one by nullsleep.

Here are some advice and facts that might be useful:

  • The song is composed with Little Sound Dj v 3.1.9 and should ideally be played back with the same version to avoid incompatibilities. (However, I don’t see much in this one that could wrong on other versions)
  • When I first uploaded the file to my PC, I got a weird bug in chains like 05 and 06 (Where ever there were C commands) where the sound changed properties when the pointer reached the end of a phrase, and the note was still playing. I found out that this bug was caused by some sort of “shadow notes” on the step 0 in the phrase. B+A (LSDj command for cut/delete) on that position reset the note and made the bug go away.
  • Camvliez is really an unfinished song, and some time I will finish it for real. (Some people including myself think that it ends to abruptly) But, there also a hidden unfinished tune in there. I got some ideas while looking through the sav a last time, so I just put them there. If anyone wants to finish remix that, please do so!
  • Use the clone command! By first copying a chain or phrase to a new position, and then pressing select+{B, A} (Hold select while pressing B then A) This is my usual method of applying small variations to songs made in LSDj.
  • The MP3 version of the song was recorded on a cheap-o soundcard from redledboy, using a regular audio cable. (No fancy 192 kHz, 32-bit fireqire audiocard here…) The sound was touched up in Audacity using the builtin bass boost, then Audacity’s compressor with its default settings, then I gave the file a boost at maybe 4-7 kHz (Don’t remember) It could sound better, but to me it’s acceptable.

LSDj song screen
Overview of the song.

LSDj groove screen
I’m using a 7/5 groove, aka shuffle, which in effect means that the first note in a phrase is a little longer than usual, and the next one is a little shorter, next one is longer, next one is shorter, etc. This gives a shufffle effect similar to the one the TR and TB series of machines by Roland.
My advice to people using grooves is to keep the sum of the groove 12. (Or 24 if using two groups etc) If you don’t, the BPM will be inaccurate, and song will be harder to sync to each other over link cable.

LSDj phrase screen
This is a phrase that uses so called “pattern break”, meaning that when you reach the H00 command, the phrase will end after 4 steps, which I use for a short break thing with a rising square wave.

LSDj instrument screen (Pulse type instrument)
There we have the said rising square wave. Look at the envelope parameter. 5 is the starting volume, and E is the fade direction, E means “rise slowly”.
As you can see it has no name, which is a bad habit of mine. You should name them.

LSDj instrument screen (Kit type instrument)
Here we have the main drum instrument. Not much to say about it. It uses the 909 kit for both its software channels. Apart from that nothing is changed from the default settings.
And again, name your instruments boys and girls!

LSDj phrase screen (Bass line)
Here’s my bassline. Bud Melvin asked about it, so here the trick. Instrument 03 is 1/8 (12.5%) pulse width square wave to give some crisp to the sound, and 07 is a 1/2 (50%) wave with a tod longer decay. This gives what according to me is a pretty nice bass line.

LSDj instrument screen (Crisp pulse type instrument)

LSDj instrument screen (Fat pulse type instrument)
Also please note the vibrato setting. It’s not HF as usual, but a regular vibrato type. This affects not only vibrato, but also makes legato and pitch slide (L and P commands) slower. This allows me to do a nice lick thing with the instrument. (Check out song position 31, chain 29, phrase 42, phrase positions A-B) The PFF/P01 combo makes the pitch first go down a little, then back up again.
I actually got a ompliment on that effect, that’s why I decided to mention it. I never thought anyone would notice, but it seems like it pays off to add small details to your music.

LSDj instrument table view (Nice arpeggio)
This is a table that makes a pretty nice effect. (Used in instrument 08) 0C on the first step quickly rises the tone one octave over the played note, FA lowers it 6 semi-tones below the played note. (I actually meant it to be lowered 7 semis, making end up at the subdominant of the played note, but it sounds good this way too)
A few ticks later, I change the wave form from 1/4 (25%, as set in the instrument) to 1/8. (12.5%) This adds to the snappy character of the sound.

The H (hop) command means something else in tables than it does in phrases. As shown before, it makes a pattern break in a phrase. In a table, the H command hops within the table instead. The rightmost digit defines the target position, the leftmost one defines the number of times the loop should loop. (0=Infinitely) The H0C command here simply catches the cursor in an infinite loop, so that it won’t apply the snap effect continually.

LSDj Phrase view (Kit drums)
Here are some kit drums played on the WAV channel. I’ve put a lot of work in to gradual progression in the drums, which hopefully makes the music more interesting. (As mentioned above, use the clone command!) Also, it’s worth noticing the R (Retrig) command. It gives a quick drum roll there at the end. (But you might need to watch out if you place an empty phrase after it, since the retrig continues)

As said before, if you find this info useful, please leave a comment. :D