News: 11 March 2016 - Forum Rules

Author Topic: Changing a password system into a save system  (Read 9605 times)

Ar8temis008

  • Full Member
  • ***
  • Posts: 106
    • View Profile
Changing a password system into a save system
« on: July 17, 2017, 05:43:50 am »
I want to add sram to Megaman 3, but know very little about nes hacking.

I know that the password system makes adding sram easier,since you don't have to track each individual value, instead you just have to make the game create, save, and load a password. I also know said values. The issue is that I have no clue what to do with them. That's what I need help with.

nesrocks

  • Hero Member
  • *****
  • Posts: 732
    • View Profile
    • nesrocks.com
Re: Changing a password system into a save system
« Reply #1 on: July 17, 2017, 09:03:29 am »
Someone correct me if I'm wrong, but I think you just use neshead tool to enable sram, then write to the 6000-8000 range for saving, and read from the same addresses for loading. On the mmc3 you need to enable PRG RAM at run time, as Disch pointed out here: http://www.romhacking.net/forum/index.php?topic=22592.msg316851#msg316851
I don't know if the same has to be done on the mmc1.

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Changing a password system into a save system
« Reply #2 on: July 17, 2017, 11:47:55 am »
That's the jist of it, yes.  Megaman 3 uses MMC3, so the info in the linked thread is apt.

1)  Enable PRG-RAM on the MMC3 by writing to $A001 at startup, as described in that other thread
2)  Flip on bit 1 ($02) of byte 6 in the header (or use a header-editing tool to do it -- they probably have it marked as "battery" or something).  This will tell the emulator to actually create an SRAM file.
3)  Write data you want saved to the $6000-7FFF range.

That's it.  Anything you write to $6000-7FFF range will be automatically saved and will persist between game loads.


Note that step 1 may already be done by the game if it's already using that RAM.  Games like SMB3 use PRG-RAM but simply don't save it (no battery).  MM3 might do the same, but I have no idea.  If MM3 is already using that RAM, you'll have to write the data you want saved in an area that it isn't using.

nesrocks

  • Hero Member
  • *****
  • Posts: 732
    • View Profile
    • nesrocks.com
Re: Changing a password system into a save system
« Reply #3 on: July 17, 2017, 02:11:04 pm »
Oh I thought it was mmc1. That's nice. Good news is that sram is disabled in the original megaman 3 rom header, so it should be safe to assume all addresses from $6000-$7FFF are free to use.

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Changing a password system into a save system
« Reply #4 on: July 17, 2017, 03:11:24 pm »
Oh I thought it was mmc1. That's nice. Good news is that sram is disabled in the original megaman 3 rom header, so it should be safe to assume all addresses from $6000-$7FFF are free to use.

No that just means the RAM isn't battery backed.  That doesn't mean the RAM isn't used.  See SMB3 (also doesn't have a battery, but does use the RAM).

kuja killer

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Changing a password system into a save system
« Reply #5 on: July 17, 2017, 04:31:46 pm »
I enabled the SaveRAM for Megaman 3 Improvement just in case people ever wanted to do any save-like stuff for that very reason.

nevermind apparently i didnt. im dumb :( i did use the 6000-7FFF area a few times for things but...what disch said about mario 3 :( i didnt realize heh
« Last Edit: July 17, 2017, 04:37:25 pm by kuja killer »

Ar8temis008

  • Full Member
  • ***
  • Posts: 106
    • View Profile
Re: Changing a password system into a save system
« Reply #6 on: July 17, 2017, 06:38:33 pm »
I disassembled the rom using 6502d.exe and added LDA #$80 and STA $A001

A few questions,

1. What is BRK? Is it important or Just empty space.

2.how do I re compile the rom from the disassembly.

3. What is the number in the middle, between lsr and 00000000?
               
00000000:   4E4553 LSR $5345
« Last Edit: July 17, 2017, 07:14:21 pm by Ar8temis008 »

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Changing a password system into a save system
« Reply #7 on: July 17, 2017, 08:09:25 pm »
1. What is BRK? Is it important or Just empty space.

Not all bytes are code.  That BRK probably isn't actually code, it's probably some data.  There's no way to tell whether or not it's empty space without more details.

Quote
2.how do I re compile the rom from the disassembly.

You probably can't.  Unless the ROM is specifically disassembled to be re-assemblable, it likely can't be without a lot of work.  Judging from the bit you posted (the LSR line), it seems like it's not re-assemblable.


Quote
3. What is the number in the middle, between lsr and 00000000?

That's the raw binary data that makes up the instruction.   4E is the opcode for LSR immediate, and 4553 is the low/high bytes of the address.  So 4E4553 = LSR $5345
               
« Last Edit: July 17, 2017, 08:21:04 pm by Disch »

nesrocks

  • Hero Member
  • *****
  • Posts: 732
    • View Profile
    • nesrocks.com
Re: Changing a password system into a save system
« Reply #8 on: July 17, 2017, 08:14:43 pm »
edit: Disch beat me to it  :laugh: . By the way, didn't know about that bit, nice  :thumbsup:

1. What is BRK? Is it important or Just empty space.
Quoting from www.6502.org:
"BRK causes a non-maskable interrupt and increments the program counter by one. Therefore an RTI will go to the address of the BRK +2 so that BRK may be used to replace a two-byte instruction for debugging and the subsequent RTI will be correct."
If it is repeated several times it may just be empty space.

2.how do I re compile the rom from the disassembly.
Depends on how you disassembled it (first question is what disassembler did you use). Also, you need to fix the many errors generated when it decompiled, as the decompilation may have guessed wrongly data from code, among other misinterpretations.

3. What is the number in the middle, between lsr and 00000000?
00000000:   4E4553 LSR $5345
That is the byte code version of "LSR $5345"
4E = LSR
45 53 = $5345

Ar8temis008

  • Full Member
  • ***
  • Posts: 106
    • View Profile
Re: Changing a password system into a save system
« Reply #9 on: July 17, 2017, 08:22:22 pm »
Not all bytes are code.  That BRK probably isn't actually code, it's probably some data.  There's no way to tell whether or not it's empty space without more details.

You probably can't.  Unless the ROM is specifically disassembled to be re-assemblable, it likely can't be without a lot of work.  Judging from the bit you posted (the LSR line), it seems like it's not re-assemblable.


That's the raw binary data that makes up the instruction.   4E is the opcode for LSR immediate, and 4553 is the low/high bytes of the address.  So 4E4553 = LSR $5345
               
00000000:   4E4553 LSR $5345

How do I get these other details?

If I cant re assemble a rom, how am I supposed to edit anything?

This makes sense, is there any place with the op codes for other instructions?

nesrocks

  • Hero Member
  • *****
  • Posts: 732
    • View Profile
    • nesrocks.com
Re: Changing a password system into a save system
« Reply #10 on: July 17, 2017, 08:25:31 pm »
http://www.6502.org/tutorials/6502opcodes.html

I usually edit directly on fceux's hex editor. People will often do small pieces of asm code on an asm file and then compile it and then copy paste the result into an unused area in the ROM. I prefer to write the byte codes directly.

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Changing a password system into a save system
« Reply #11 on: July 17, 2017, 08:42:45 pm »
How do I get these other details?

I'd need to see what else is around it.

Generally, determining whether or not something is free space is actually kind of difficult.  It depends on the game.  I'm not very familiar with MM3 so I probably won't be able to give you a definitive answer.

Quote
If I cant re assemble a rom, how am I supposed to edit anything?

Usually with a hex editor.  Or a patch assembler like xkas.

Quote
makes sense, is there any place with the op codes for other instructions?

http://www.obelisk.me.uk/6502/reference.html

kuja killer

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Changing a password system into a save system
« Reply #12 on: July 17, 2017, 09:33:37 pm »
umm, 4E4553 is not code there...thats the first 3 bytes of the NES header. "NES"


Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Changing a password system into a save system
« Reply #13 on: July 17, 2017, 09:42:12 pm »
umm, 4E4553 is not code there...thats the first 3 bytes of the NES header. "NES"



Oh... hahahahaha.  Yeah.  XD

pianohombre

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • My personal website of short stories and comics
Re: Changing a password system into a save system
« Reply #14 on: July 18, 2017, 02:09:48 am »
If you are successful with this you should consider adding save states to some SNES roms as well. Megaman X1-X3 and I believe MM7 still use the password system. Although, Rockman & Forte(Megaman and Bass) have a save state system.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7183
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Changing a password system into a save system
« Reply #15 on: July 18, 2017, 03:37:10 am »
If you want to disassemble a ROM and reassemble it, prepare to spend many hours/weeks/months/years doing it manually.

I haven't tried FCEUX' code logger but it sounds like for best results you would need to play the game and try to activate as much of the code as possible which could possible also take a very long time.

Do you know 6502 ASM well? If you don't, you are probably not going to progress on this.
Completely replacing a password screen with a save screen would probably require good knowledge of the game's engine (see above).

Maybe if you're lucky you could do an ASM hack to essentially auto-input passwords by replacing the password initialization with one loaded from SRAM (similar to NES Metroid on the GBA). But that still requires ASM knowledge to modify the password display routine (such as after finishing a level) to write to SRAM as well as loading when opening the password input screen.

Doesn't the Mega Man X Collection for PS2/GC have save file support? Playing that might be an easier solution.
"My watch says 30 chickens" Google, 2018

pianohombre

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • My personal website of short stories and comics
Re: Changing a password system into a save system
« Reply #16 on: July 18, 2017, 06:23:15 am »
@KingMike:
I've never had a problem with no-saving feature for those games, especially since emulators allow you to save state. I just assumed the OP was looking for a programming project. I just checked it looks like Megaman X Collection does support saving on the memory card. I think what it does is just save the passwords and then loads them up for the next screen. Someone mentioned Megaman 3 I assumed this might be for that game? Or perhaps it was just an example for MMC3 chip. MM3 already has a save feature in MM:Wily Wars anyways.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

Ar8temis008

  • Full Member
  • ***
  • Posts: 106
    • View Profile
Re: Changing a password system into a save system
« Reply #17 on: July 30, 2017, 11:06:33 am »
Oh... hahahahaha.  Yeah.  XD
That was just an example, the same format is repeated every line is repeated every line. So for example, one line below that it might say "4A 36 23". That line specifically isn't real, but you get the idea.

If you are successful with this you should consider adding save states to some SNES roms as well. Megaman X1-X3 and I believe MM7 still use the password system. Although, Rockman & Forte(Megaman and Bass) have a save state system.
That is the idea, because I see no reason for a snes game to not have an sram system.
If I can get into the swing of things, I want to do it to the rest of the nes Megaman games (with the first two being an exception, since they already have sram hacks). Then MMX 1-2 (3 has a psx release) and maybe even super castlevania. I'm definitely getting ahead of my self, but at least I know what I want to do.

So I really want to do this and I will eventually, but I just lost my computer. I tried doing it on a mac, but it's just not worth it. Between getting every program to run through wine and learning the 6502 thing, I think this is a project for another day.


pianohombre

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • My personal website of short stories and comics
Re: Changing a password system into a save system
« Reply #18 on: July 31, 2017, 12:30:14 pm »
Like KingMike was saying it's really not too much trouble. Not difficult to work around and save in other versions of the games. But if you're just learning Assembly and want a project, give it a shot.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

Psyklax

  • Hero Member
  • *****
  • Posts: 1112
    • View Profile
    • Psyklax Translations
Re: Changing a password system into a save system
« Reply #19 on: July 31, 2017, 03:23:31 pm »
Am I the only person who thinks that passwords are BETTER than SRAM? :)

I'll explain why. In this day and age, you can hack a game to use SRAM instead of passwords, and how will you then play them? Either on an emulator - all of which use save states to let you save an infinite amount of times - or on an Everdrive or equivalent - which often has save states too, though not always.

By contrast, I can play a real cart on a real machine, take a photo of the password on my phone (like I said, in this day and age), and continue playing on an emulator, or vice versa. Not only that, but in some games with less complex passwords, they can be used as a sort of level select. I recently did a hack of Iron Tank in an hour, but the fact I could use passwords between the Japanese and US versions saved a lot of time checking.

So, again, I actually prefer passwords. As long as they use obvious characters that are easy to read. I know I'm hijacking the thread with my unpopular opinion, and for that i apologise. :)