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

Author Topic: Help with Master System pointers.  (Read 1617 times)

DougRPG

  • Full Member
  • ***
  • Posts: 146
    • View Profile
Help with Master System pointers.
« on: October 28, 2012, 10:57:57 pm »
Hi, I'm starting to work with a Master System game, but I'm facing some trouble with the pointers.

For example, the game has this code:

Code: [Select]
LD HL,B778h
LD DE,4000h
CALL 04B3h

Inside this 04B3h subroutine the game access some data using HL, and I need the pointer to this data. Seems that I need to add 0x38000 to 0xB778, with gives 0x43778, but it's not the right place, but I know it's very near.

Someone knows how this stuff works?


The complete code fragment of this region is:

Code: [Select]
[004522] 4522 21 78 B7    LD HL,B778h      AF=0040 BC=0000 DE=C251 HL=B778 SP=CAFC IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=ef frames=0091
[004525] 4525 11 00 40    LD DE,4000h      AF=0040 BC=0000 DE=C251 HL=B778 SP=CAFC IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=ef frames=0091
[004528] 4528 CD B3 04    CALL 04B3h       AF=0040 BC=0000 DE=4000 HL=B778 SP=CAFC IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=ef frames=0091
[0004B3] 04b3 06 04       LD B,04h         AF=0040 BC=0000 DE=4000 HL=B778 SP=CAFA IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=ef frames=0091
[0004B5] 04b5 C5          PUSH BC          AF=0040 BC=0400 DE=4000 HL=B778 SP=CAFA IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=f0 frames=0091
[0004B6] 04b6 D5          PUSH DE          AF=0040 BC=0400 DE=4000 HL=B778 SP=CAF8 IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=f0 frames=0091
[0004B7] 04b7 CD C0 04    CALL 04C0h       AF=0040 BC=0400 DE=4000 HL=B778 SP=CAF6 IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=f0 frames=0091
[0004C0] 04c0 7E          LD A,(HL)        AF=0040 BC=0400 DE=4000 HL=B778 SP=CAF4 IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=f0 frames=0091
[0004C1] 04c1 23          INC HL           AF=0A40 BC=0400 DE=4000 HL=B778 SP=CAF4 IX=B8AF IY=C400 V    P0=00000 P1=04000 P2=5C000 [ROM]  vdp=0020 vc=f0 frames=0091

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6909
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Help with Master System pointers.
« Reply #1 on: October 29, 2012, 02:30:41 am »
ALL FROM WHAT I'VE READ (of the documents on SMS Power!), the majority of SMS games use the standard Sega mapper, which allows:

Code: [Select]
CPU $0000-03FF : The first 1KB of the first bank
CPU $0400-3FFF : the remaining 15KB of any ROM bank
CPU $4000-7FFF : any other ROM bank
CPU $8000-BFFF : a third selectable ROM bank or cart RAM
(though I think there were variants of this mapper, such as not allowing preventing the entire range $0-3FFF to be changed.)

Are you saying you know that the ROM bank at $38000 is what is mapped into CPU $8000-BFFF?
(which would mean the data at CPU $B778 is the data at ROM $3B778)
Then you need to take 3B778 modulus 4000 (which equals 3778), and add that to $8000 to get... B778.

Or if you have data at CPU $B778 and you want to find the ROM offset (assuming you've determined cart RAM isn't mapped in), then $B778 modulus 4000 (= 3778), add that to the ROM offset of the start of the bank.

How do you know what ROM offset is the start of the bank? Well, you could do a hex search for matching data.
On the standard Sega mapper, ROM banks are selected by writing to $FFFD-FFFF respectively for the $0-3FFF,4000-7FFF and 8000-BFFF ranges. Fortunately, those offsets overlap with a mirror of the console RAM, so they will be copied to $DFFD-DFFF.
So, the ROM bank offset would be that number times $4000.
"My watch says 30 chickens" Google, 2018