It is currently Mon Dec 11, 2017 8:25 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Mon Jul 24, 2006 10:29 am 
Offline

Joined: Mon Jul 24, 2006 10:27 am
Posts: 3
Okay here's the code: (I'm learning to program asm for the NES)

code:
lda #$3F ; these 4 lines tell $2006 that we
sta $2006 ; want the stuff we load $2007 with
lda #$00 ; to start at memory location $3F00
sta $2006 ; . Note that since we can only store a byte at a time we store twice
; to get the whole address in there.

ldx #$00 ; load X with 0.
loadpal: ; note that labels are followed by a ':' and aren't tabbed in.
lda ourpal, x ; load A with pallete value at location ourpal + x.
sta $2007 ; store the next pallete value into $2007 which will put it in
; the right place for us.

inx ; you've never seen this instruction before but it stands for INcrement X.
; it adds 1 to X.

cpx #32 ; ComPare X with 32 which is how many pallete values we need to load.
;bne loadpal ; bne stands for Branch on Not Equal, so this will branch to
; loadpalif X wasn't equal to 32. If X is 32, then the loop will stop and
; were done loading the pallete.



Pretty much I understand everything, but I don't understand how the value 3F00 stored in memory address 2006 tells the NES that the stuff stored in 2007 needs to start at memory location 3F00. There is no reference to the 2006 memory location after the first four lines of code. Oh and FYI the ourpal label is referenced somewhere else and not needed for this question. It simply loads the pallete file.

Are there any good online manuals on 6502 asm and more specifically NES asm programming? The tutorial I'm learning is a 25 day "course" and although it covers a lot, I want to go into more detail.

Also are there any good guides in reverse engineering NES roms (nes asm hacking)? I specifically want to learn how you insert your modified asm code back into the NES rom. I understand how you can extract the asm code from the debugger, but injecting the new code into the nes rom is what I'm unsure about.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 10:52 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1393
$2006 is not a memory location - it is an I/O register within the PPU itself. The same goes for $2007 - that's why writing straight to that address causes the data to land in different locations within PPU memory.

Also, that "bne loadpal" shouldn't be commented out (i.e. drop the semicolon at the beginning of the line).

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 10:57 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7312
Location: Chexbres, VD, Switzerland
Well, it is good to comment your code, but... don't exaggerate.

As Quitetust stated, by writing to $2006, you setup an internal PPU 16-bit pointer, and by writing to or reading from $2007, you can write to/read from that location, and the internal pointer will automatically increase by one, or by 32 if one bit in the $2000 register is set, wich is usefull to draw columns in Name Table.

About tutorials, if you learn 6502 to the end, knowing all instructions and how to write different kind of loops and conditionnal jumps, you're done in theory, but need practice in order to gain experience.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 6:05 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
Here are some good docs, by chip's original designers:
http://www.westerndesigncenter.com/wdc/datasheets/Programmanual.pdf

NES CPU is the regular 6502 (not 65C02). You can also ignore anything about decimal mode, it's not on the NES CPU.

Putting code back into a ROM might not be trivial. If the new code is smaller than the old, you can just overwrite it (if it's small, just assemble it by hand in a hex editor, people do that with NSFs all the time). But if you have to move any of the other code around, all the labels and pointer locations throughout the whole ROM would have to be adjusted. And that's not easy at all (especially since you'd have to track down all the pointers, tables, references to them). Some disassemblers can output something that will reassemble, maybe with a little work.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:24 am 
Offline

Joined: Mon Jul 24, 2006 10:27 am
Posts: 3
Okay guys, I got another question that's related to the following tutorial:

http://desnet.fobby.net/doc/fceud_tutor1.txt

Pretty much I understand all the asm code in the debugger, but I'm not clear on the following statement:

Quote:
I loaded NESten (currently has a better cheat
search than FCEUd :P) and did a simple cheat search. While Samus was on the ground, not moving, the value was always equal to the last. I would then jump, and search for "changed" values while Samus was in the air. And then search for "changed" values when she was back on the ground. I repeated this several times until I ended up with three addresses: $01EE, $01F0, $0312. I know that any address in the range between $0100 - $01FF is stack space, so those get ommited. This left me with just one address - $0312.


This tutorial didn't clearly explain how the author determined that addresses $0100 - $01FF is stack space. Is this universal for all nintendo games? Also is it recomended I use NESten for cheat searching rather than FCEU?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 2:33 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7312
Location: Chexbres, VD, Switzerland
The stack at $100-$1ff isn't only universal for the Nintendo Entertainement System, but for any system running based on a 6502 CPU.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 3:48 am 
Offline

Joined: Mon Jul 24, 2006 10:27 am
Posts: 3
Bregalad wrote:
The stack at $100-$1ff isn't only universal for the Nintendo Entertainement System, but for any system running based on a 6502 CPU.


Excellent, thank you. This is a great board. I'm going to read up some more docs on the NES and the 6502 to better understand the architecture.

Should I use NESten for cheat searching, or stick with my existing emulator?

Also why would stuff like values changed during jumping never be in stack space? Is it because stuff like that stays in the registers?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 11:26 am 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
IceAIM wrote:
Also why would stuff like values changed during jumping never be in stack space? Is it because stuff like that stays in the registers?


It can be in the stack space (it's still normal RAM), but if it's an address like $1E0-$1FF you can be pretty sure it's just a stack value.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 12:18 pm 
Offline
User avatar

Joined: Sat Jul 22, 2006 12:06 pm
Posts: 96
Location: USA
Try to avoid NESten, as it isn't very accurate.

I'm trying to recall whether Nestopia has a workable cheat searcher. (This isn't my normal home computer I'm posting from...) EDIT: Well, probably not, but you might be able to try using Nintendulator. Note that it is slower than Nestopia, though.

_________________
Warning: I am not a serious developer (yet), but CS and EE really interest me.
I was -_pentium5.1_- until I screwed up. This is why I screwed up. ^_^


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 12:27 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 2:13 pm
Posts: 1667
Location: .ma.us
Or you can use FCEUXDSP which is easy on the resources, accurate and has a very straight forward cheat console.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group