Code: Select all
for(;;)
{
pc = InitPC;
opcode = rom[pc]
switch(opcode)
{
/* opcode emulation */
}
cycles = cycles_opcode[opcode];
}Moderator: Moderators
Code: Select all
for(;;)
{
pc = InitPC;
opcode = rom[pc]
switch(opcode)
{
/* opcode emulation */
}
cycles = cycles_opcode[opcode];
}That's not how you go about solving it. :-)ehguacho wrote:yes, but it can be easily solved. i could put the opcodes emulation in another file, or put it in a "while" loop to limit the times it's being executed.koitsu wrote:Are you aware that this loop will result in 100% CPU being used at all times? This isn't good.
you mean something like this?MottZilla wrote:You can make read and write memory functions and just call them in the opcode emulation.
Code: Select all
switch(opcode)
{
...
case 0xAD: // LDA Absolute
addr = (rom[pc + 2] << 8) | rom[pc + 1];
acc = read_mem[addr];
...
}
you mean like using a function that stops 6502 emulation and then do stuff. when finished, then turn on again the 6502 emulation... isn't it?koitsu wrote:That's not how you go about solving it.ehguacho wrote:yes, but it can be easily solved. i could put the opcodes emulation in another file, or put it in a "while" loop to limit the times it's being executed.koitsu wrote:Are you aware that this loop will result in 100% CPU being used at all times? This isn't good.
You need to make your main loop basically do the equivalent of a sleep() statement, while you have an interrupt handler or routine that gets called/induced by the kernel every X times a second (usually tied to an internal timer in Windows. In the *IX world you can use something like kqueue on BSD or SIGIO on Linux).
I'll poke Disch and ask him to provide some examples here, as Windows coding really isn't my forte.
Code: Select all
opcode = rom[pc] Wasn't there another thread about frame limiters on here?I'll poke Disch and ask him to provide some examples here, as Windows coding really isn't my forte.
i'm taking this project slowly, so first i'll try to get running mapper #0 games with only 1 (one) PRG ROM data and no Trainer. in that case all i've to do is to copy that bank into my ROM memory array, like this:one reason being that the code might not be in ROM, it might be in RAM
Code: Select all
...
FILE *romfile;
unsing char *rom;
...
fseek(romfile,16,0)
rom = (unsigned char *)malloc((ROMBanks + 1) * 16 * 1024);
fread(&rom[0x8000],1,0xc000,romfile);
...
Code: Select all
....
case 0xAD: // LDA ABSOLUTE
/* LDA Absolute emulation goes here*/
accumulator = ReadMem(address);
...