News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: How to find the correct offset for graphics in Bsnes?  (Read 1782 times)

pianohombre

  • Sr. Member
  • ****
  • Posts: 282
    • View Profile
    • My personal website of short stories and comics
How to find the correct offset for graphics in Bsnes?
« on: May 24, 2017, 05:10:08 am »
This has bothered me for awhile, but there's no documentation online for this program despite being considered one of the best ones on the free market.

It's got this neat viewing window so I can see the VRAM, just like in-game and I can use the CGRAM to load the correct palette, but where exactly is this offset location in the actual rom? It says "base tile address" then lists 0x$000 for the bg1-4 and oam. Also, would these be pc addresses or snes addresses?

I wanted to find the correct offset, then decompress the graphics using lunar compress and have it viewable in a program like tile layer pro. Also, does anyone know if lunar compress uses snes addresses or pc addresses?

Thanks.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

dougeff

  • Sr. Member
  • ****
  • Posts: 359
    • View Profile
Re: How to find the correct offset for graphics in Bsnes?
« Reply #1 on: May 24, 2017, 08:16:07 am »
Base tile address, is where in the VRAM the tiles have been loaded. Not where in the ROM they came from.

BG tile base position set with registers
210b  wb++?-
210c  wb++?-
        bbbbaaaa
            aaaa = Base address for BG1/3 (Addr>>12)
        bbbb     = Base address for BG2/4 (Addr>>12)

OBJ(sprite) tile base position set by register
2101  wb++?-
         sssnnbbb
bbb  = Name Base Select (Addr>>14)


Tiles can be anywhere in the VRAM, which is why you need to tell it where they are. It's like a pointer to an array.
« Last Edit: May 24, 2017, 08:25:09 am by dougeff »
nesdoug.com -- blog/tutorial on programming for the NES

pianohombre

  • Sr. Member
  • ****
  • Posts: 282
    • View Profile
    • My personal website of short stories and comics
Re: How to find the correct offset for graphics in Bsnes?
« Reply #2 on: May 25, 2017, 12:51:55 am »
BG tile base position set with registers
210b  wb++?-
210c  wb++?-
        bbbbaaaa
            aaaa = Base address for BG1/3 (Addr>>12)
        bbbb     = Base address for BG2/4 (Addr>>12)

OBJ(sprite) tile base position set by register
2101  wb++?-
         sssnnbbb
bbb  = Name Base Select (Addr>>14)

Can you go into a little detail about the variables you used? So 210b/c are the base tile set registers? How does that relate to finding an offset for a graphic?
bbbbaaaa = offset composed of all the graphics in bg1-4?
So if I want all the graphics I use an 8-byte offset but for 1 background I use a 4-byte offset? Ok so bg 3 is right-shifted from bg 1, but you're still using variables. How do you get an exact offset? Do I just have to increment the write buffer (I'm assuming wb = write buffer) and use trial and error?
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6932
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: How to find the correct offset for graphics in Bsnes?
« Reply #3 on: May 25, 2017, 01:26:16 am »
That info is about how VRAM is mapped.

It tells you nothing about where the data is found in the ROM.
If you need the graphics decompressed by Lunar Compress (AND that's assuming Lunar Compress supports it, I don't know since I don't use Lunar Compress because I've seen enough variation in graphics compression formats to not expect someone else's tool to magically find them), then you have to know how to read an ASM log enough to find where the graphics are stored.
Graphics are usually decompressed to RAM, and then transferred to VRAM.

What I would do to find a compressed graphics offset:
-look in a trace log for writes to address $2116/2117, which is the VRAM address register. Near that will probably be DMA registers. Writes to $43x2-43x4 will be the address the DMA will transfer from, so it will likely be RAM with a decompressed graphics buffer (if the graphics indeed were decompressed). Then it's a matter of finding in the trace log where whatever wrote to that RAM, to find the ROM address it decompressed from.
If that is too much to understand, then the short answer is that sorry, an emulator is not going to easily find the ROM address for you.
"My watch says 30 chickens" Google, 2018

pianohombre

  • Sr. Member
  • ****
  • Posts: 282
    • View Profile
    • My personal website of short stories and comics
Re: How to find the correct offset for graphics in Bsnes?
« Reply #4 on: May 26, 2017, 09:30:49 am »
If you need the graphics decompressed by Lunar Compress (AND that's assuming Lunar Compress supports it, I don't know since I don't use Lunar Compress because I've seen enough variation in graphics compression formats to not expect someone else's tool to magically find them)

Lunar compress is a pretty powerful tool. It supports compression algorithms for many games, and even the one I'm looking for. It's too bad that those were the values for VRAM loaded and not where in the ROM the graphics came from. I know the location in the ROM for bg1 so in the VRAM it's bitwise shifted by 12 units from bg3, but unfortunately that won't help me with the actual location. I'll have to do the trace log like KingMike said.

May 29, 2017, 08:31:39 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Alright,
I tried doing this today. Wasn't able to complete it. Would be nice if someone made a small step-by-step guide on this and had it in the DOCUMENTS section.

I'm not exactly sure how to trace log. I see there's an option in the Debugger to Trace S-CPU opcodes, Trace S-SMP opcodes, Trace S-A1 opcodes, Trace SuperFX opcodes, and in the breakpoint editor there's an option to change the source to S-PPU VRAM and S-PPU OAM. Off the top of my head I'm not sure what most of those trace locations are. So when I set up the breakpoint editor to break on value 2116 for the S-CPU bus it stops, but not when I select S-PPU VRAM. Which values should I select for tracing?

Appreciate the help folks. Just assuming that you have all done this before.
« Last Edit: May 29, 2017, 08:31:39 pm by pianohombre »
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds