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

Author Topic: what kind of file is a snes rom?  (Read 6094 times)

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: what kind of file is a snes rom?
« Reply #20 on: July 02, 2015, 09:05:45 pm »
Just out of curiosity, but is there any reason why we're using integers?

He probably shouldn't be writing a unsigned int, since that's probably 4 bytes and is likely overwriting something it shouldn't be.  He probably should only be writing a single byte.


Quote
I was thinking that 10 lives would be represented by A and not by 10

???

A (hex) IS 10 (dec)

It's the same number.



As for OP:  I don't know much about VB so I can't give you an actual code example... but I'd say just look up a tutorial for "binary file reading/writing in VB" and go from there.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7060
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: what kind of file is a snes rom?
« Reply #21 on: July 02, 2015, 09:30:17 pm »
I'd wonder if SMW stores lives with 10 = A.

I mean, using a code where Mario dies on the title screen causes the lives to get set to "P5" which looks suspiciously like 255 (or 25 10s + 5, if "P" were the 25th "digit" in the font).
"My watch says 30 chickens" Google, 2018

Seihen

  • Sr. Member
  • ****
  • Posts: 404
    • View Profile
Re: what kind of file is a snes rom?
« Reply #22 on: July 02, 2015, 10:17:23 pm »
A (hex) IS 10 (dec)

It's the same number.

Sorry, should've been clearer. It's my understanding that if you were to write an integer (which is usually -- and forgive me if I'm wrong -- decimal only), that would output 10 (ONE-ZERO) to your file when you're writing out, ignoring the four-byte issue for a moment.

Thus, outputting values 1-9 would give Mario lives 1-9, but without doing any sort of DEC->HEX conversion in your program, attempting to give Mario 10 livse (ONE-ZERO) would instead give him 16 when read by the rom.

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: what kind of file is a snes rom?
« Reply #23 on: July 02, 2015, 10:47:00 pm »
@Seihen:  You might be confusing text files with binary files.

If you write an integer that contains "ten" to a binary file... it will write the binary representation of the number "ten" -- it will not write "one zero".


Quote
but without doing any sort of DEC->HEX conversion in your program

There is no such thing as dec->hex conversion unless you are dealing with text.

Numbers are numbers.  They don't come in different forms*.  The only difference is how they are displayed in text for humans to read.

Decimal (10), Hexadecimal (0A), and English (ten) are all 3 different textual representations of the same number:  ten.

Since text is not involved here... we just have a digital value.  So there's nothing to convert.



* they actually do come in different digital forms, but it's unrelated to what we're discussing here.  Trying to keep it simple



EDIT:

Although King Mike brings up the notion that the lives counter may in fact be BCD, in which case $10 would be "ten" and values $0A-$0F would be invalid.  In which case, yes, conversion will be necessary:

Code: [Select]
// convert 'val' to BCD using a single temp var:
temp = val / 10;
val %= 10;
val += temp*16;

// covert 'val' FROM BCD:
temp = val / 16;
val %= 16;
val += temp*10;
« Last Edit: July 02, 2015, 10:57:17 pm by Disch »

Seihen

  • Sr. Member
  • ****
  • Posts: 404
    • View Profile
Re: what kind of file is a snes rom?
« Reply #24 on: July 02, 2015, 11:10:15 pm »
Ah, thanks! Yeah, I don't work with a lot of binary files, so that clears it up.

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: what kind of file is a snes rom?
« Reply #25 on: July 04, 2015, 10:42:13 am »
Slip of the finger. I meant to use writeByte.