+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  Need help finishing 6502 bank swapping routine
Pages: [1]
Author Topic: Need help finishing 6502 bank swapping routine  (Read 2 times)
Kagemusha
Guest
« on: November 27, 2007, 07:11:48 pm »

It's almost complete, but there's a few things that I don't understand completely.

LDA $8000
PHA

LDA #$09
STA $8000

JSR $8000

PLA
STA $8000

The first instruction set is supposed to load the current page swapped in from the PPU register, but it probably won't work in its current state. Not sure if mapper 33 will let me load the current page or if I'll have to find the code that writes the page number somewhere in RAM. And finally when I'm writing the page, I'm not sure where to right it to. From what I understand each PRG slot has a range where stuff can be written. It's probably in Disch's doc, but I'm not recognizing the information.
tomaitheous
Guest
« Reply #1 on: November 27, 2007, 08:29:57 pm »

Hmm - If it's like other mappers, you can't read the mapper value(state/bank) from the memory mapped write I/O address. Because you wouldn't be able to read correct values from that address and that JSR would have problems executing the next opcode at $8000 - writing to $8000 changes banks, reading from $8000 returns ROM value of that bank. Of course I could be wrong as I haven't used that mapper (I have an old mapper doc too).
Disch
Guest
« Reply #2 on: November 27, 2007, 08:33:28 pm »

Quote from: Pennywise on November 27, 2007, 07:11:48 pm
LDA $8000
PHA

-snip-

The first instruction set is supposed to load the current page swapped in from the PPU register, but it probably won't work in its current state. Not sure if mapper 33 will let me load the current page

Remember that $8000-FFFF is PRG-ROM, so LDA $8000 will read from PRG, not from the mapper register.  Most (nearly all, in fact) mapper registers are write-only -- meaning you cannot read their current contents.

Quote
or if I'll have to find the code that writes the page number somewhere in RAM.

This is exactly what you'll likely have to do.  One way you can try and find this is to set a breakpoint on writes to this specific register and examine the routine that's writing.  If you see something like:

Code:
STA $F0
STA $8000

Then $F0 likely has the page number.  This is common practice in a lot of games, however it's not a sure thing!  it's possible that the games do not keep track of the page they swap in.  If this is the case you might be able to edit the swap routine (assuming there's only 1 or 2 of them) to keep track of it.  This will work if the game JSRs to a common routine every time it wants to swap (which again is common practice, but not guaranteed).

Quote
And finally when I'm writing the page, I'm not sure where to right it to. From what I understand each PRG slot has a range where stuff can be written. It's probably in Disch's doc, but I'm not recognizing the information.

from the doc:

Code:
PRG Setup:
---------------------------

      $8000   $A000   $C000   $E000 
    +-------+-------+-------+-------+
    | $8000 | $8001 | { -2} | { -1} |
    +-------+-------+-------+-------+

If you're trying to swap the page at $8000-9FFF, then $8000 is the address you want to write to.  If you want to swap the page at $A000-BFFF, then you want to write to $8001.

also:

Code:
Registers:
--------------------------

Range,Mask:   $8000-BFFF, $A003

Range,Mask pairings indicate the register is mirrored across several addresses.  The main readme in the doc package explains this further.  Though really -- you don't need to write to mirrored addresses.  $8000 and $8001 are all you really need.
Kagemusha
Guest
« Reply #3 on: November 27, 2007, 08:54:48 pm »

Thanks, that clears things up. I guess I got one last question for now. I'm going to be JSR'ing with the intention of immediately loading the script pointer and reading the script byte and I've been given their location in the ROM. Ideally I'd like to do things on my own without heavily relying on people to tell me technical information that I should know about the game I'm trying to hack(Although I guess it can't be helped right now) and was wondering if anyone could perhaps tell me or explain the code/process involved with loading the script pointer and reading the script byte. Sample code or anything really. Thanks again.
Disch
Guest
« Reply #4 on: November 27, 2007, 09:14:05 pm »

Dereferencing a pointer is known as indirection.  Thus you would need to use an indirect addressing mode (Indirect,Y is most common).  To use Indirect,Y, you need to put the pointer somewhere in zero page:

Code:
LDA pointer_low
STA $10     ; example address
LDA pointer_high
STA $11

LDY #$00     ; set Y to zero to stop unwanted indexing
LDA ($10),Y  ; read byte from pointer
Neil
Guest
« Reply #5 on: January 02, 2009, 08:33:02 am »

-necrobump to save a thread from the great board prune of 2009-
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC