Few questions...

Few questions...
by on (#60028)
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:
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....
Re: Few questions...
by on (#60031)
windwakr wrote:
So, what does the cpu read when executing:
Code:
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).

Quote:
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.

by on (#60033)
- AFAIK, it's all correct, tokumaru.