Hi all, for about a month now, I've been working on an SNES emulator and have gotten most of my 65c816 core emulated. I would like to say I am deeply grateful for having a community like NesDev to go to along with great members who have put up with most of my questions recently. Thank you all for that!
There are lots of resources available in terms of being able to emulate a CPU. I have most of the opcodes and addressing modes emulated aside from things like WAI, STP, MVN, MVP, but looking at Super Mario World (my test ROM), it doesn't seem to be needed for now.
My CPU core is emulated at the opcode level and is essentially one big infinite loop with a switch statement that will execute the appropriate opcode logic based on the 1 byte opcode read in.
I've been running into an issue lately while testing this core. There are parts of code where there is there are two instructions:
I read that $2140 is actually mapped to the memory in the SPC700, which is part of the APU of the SNES. Once I figured that out, I faked values into $2140 and got a little further.
I am now at this point where I would actually like to stop doing this and start developing the APU system for the SNES. The problem is that I'm having a hard time conceptually understanding when the APU comes into play during CPU execution...
Some questions are...
1) When do we know when to play the sound in our CPU execution loop?
2) When do we transfer data back and forth between main and APU memory?
Is it by every other CPU cycles? For instance in my loop am I doing something like this?
My question may be convoluted but essentially I'm just having trouble in terms of how to get the APU and CPU to talk together in code. Any help and suggestions would be greatly appreciated! Thanks!
There are lots of resources available in terms of being able to emulate a CPU. I have most of the opcodes and addressing modes emulated aside from things like WAI, STP, MVN, MVP, but looking at Super Mario World (my test ROM), it doesn't seem to be needed for now.
My CPU core is emulated at the opcode level and is essentially one big infinite loop with a switch statement that will execute the appropriate opcode logic based on the 1 byte opcode read in.
I've been running into an issue lately while testing this core. There are parts of code where there is there are two instructions:
Code:
cmp $2140
bne xx
bne xx
I read that $2140 is actually mapped to the memory in the SPC700, which is part of the APU of the SNES. Once I figured that out, I faked values into $2140 and got a little further.
I am now at this point where I would actually like to stop doing this and start developing the APU system for the SNES. The problem is that I'm having a hard time conceptually understanding when the APU comes into play during CPU execution...
Some questions are...
1) When do we know when to play the sound in our CPU execution loop?
2) When do we transfer data back and forth between main and APU memory?
Is it by every other CPU cycles? For instance in my loop am I doing something like this?
Code:
while(true) {
switch(opcode) {
// CPU stuff and count cycles
}
if(current_cycles >= some_limit) {
// DO APU STUFF ---????
}
}
switch(opcode) {
// CPU stuff and count cycles
}
if(current_cycles >= some_limit) {
// DO APU STUFF ---????
}
}
My question may be convoluted but essentially I'm just having trouble in terms of how to get the APU and CPU to talk together in code. Any help and suggestions would be greatly appreciated! Thanks!