Few questions...

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
windwakr
Posts: 1
Joined: Wed Apr 14, 2010 5:28 pm

Few questions...

Post by windwakr » Wed Apr 14, 2010 6:17 pm

Hello, I've been really interested in NES emulation for the past week or so. Right now I'm researching and beginning to code a 6502 emulator, but I have a few questions.


For an (indirect,x) operation, can the read word pass a page boundary? Because I've read this:
6502_cpu.txt wrote: Write instructions (STA, SAX)

# address R/W description
--- ----------- --- ------------------------------------------
1 PC R fetch opcode, increment PC
2 PC R fetch pointer address, increment PC
3 pointer R read from the address, add X to it
4 pointer+X R fetch effective address low
5 pointer+X+1 R fetch effective address high
6 address W write to effective address

Note: The effective address is always fetched from zero page,
i.e. the zero page boundary crossing is not handled.
So, what does the cpu read when executing:

Code: Select all

lda ($FF,x)   ;x=0
$00FF, then $0100? Or $00FF, then $0000?





.....dangit, I went and ate some food and forgot the rest of my questions.

Well, here's one. How's my basic emulation theory look, I got some ideas from http://www.slack.net/~ant/nes-emu/6502.html , but my actual code in progress is quite a bit different.
my emulation cycle wrote: My 6502 emulation function takes in the number of cycles to run(although, it can go over since I don't do cycle-by-cycle emulation).

I grab the opcode.

Adjust the "cycles to run" value with the current instructions cycle count, taken from a table.

Grab the addressing mode of the instruction from a table, and resolve the final address needed for the instruction, also adjusting for page boundary cycle hits on the necessary instructions.

Run the instruction.

Check to see if we've ran through enough cycles. If not, go back to grabbing an opcode.

How do I handle NMI's and IRQ's? Where do they fit into my emulation cycle?




....if I remember my other questions, I'll come back and add them....

User avatar
tokumaru
Posts: 11991
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Few questions...

Post by tokumaru » Wed Apr 14, 2010 6:44 pm

windwakr wrote:So, what does the cpu read when executing:

Code: Select all

lda ($FF,x)   ;x=0
$00FF, then $0100? Or $00FF, then $0000?
I think $00FF, then $0000, but I'll let someone else give you a final answer. I doubt any programs will rely on this behavior though (not that this is a reason for you to not emulate it right, you definitely should do it as accurate as you can).
How do I handle NMI's and IRQ's? Where do they fit into my emulation cycle?
I believe that the 6502 checks for interrupts between instructions. Since your 6502 function receives the number of cycles to execute as a parameter, maybe you should pre-calculate when the interrupts are supposed to fire and give that to your function as well, so it can interrupt the program at the correct times.

User avatar
Zepper
Formerly Fx3
Posts: 3223
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Post by Zepper » Wed Apr 14, 2010 7:22 pm

- AFAIK, it's all correct, tokumaru.

Post Reply