cpu: Added a few cycles here and there

This fixes the joystick reading loop

Signed-off-by: Michel Pollet <buserror@gmail.com>
This commit is contained in:
Michel Pollet 2023-10-29 04:52:02 +00:00
parent 5968ee58b8
commit abc119b0b7
3 changed files with 17 additions and 27 deletions

View File

@ -222,10 +222,10 @@ next_instruction:
_FETCH(cpu->PC++); // relative branch
if (((cpu->_D >> d.s_bit) & 1) == d.s_bit_value) {
cpu->_P = cpu->PC + (int8_t)cpu->_P;
cpu->cycle++;
if ((cpu->_P & 0xff00) != (cpu->PC & 0xff00))
cpu->cycle++;
cpu->PC = cpu->_P;
cpu->cycle++;
}
} break;
case 0x90: case 0xB0: case 0xF0: case 0x30:
@ -241,7 +241,11 @@ next_instruction:
} break;
case 0x80:
{ // BRA
cpu->PC = cpu->PC + (int8_t)cpu->_P; cpu->cycle++;
cpu->_P = cpu->PC + (int8_t)cpu->_P;
_FETCH(cpu->PC);// cpu->cycle++;
if ((cpu->_P & 0xff00) != (cpu->PC & 0xff00))
cpu->cycle++;
cpu->PC = cpu->_P;
} break;
case 0x89:
{ // BIT immediate -- does not change N & V!
@ -261,6 +265,7 @@ next_instruction:
} break;
case 0x18: case 0xD8: case 0x58: case 0xB8:
{ // CLC, CLD, CLI, CLV
_FETCH(cpu->PC);
cpu->P.P[d.s_bit] = 0;
} break;
case 0xC9: case 0xC5: case 0xD5: case 0xCD: case 0xDD:
@ -284,18 +289,22 @@ next_instruction:
} break;
case 0x3A:
{ // DEC
_FETCH(cpu->PC);
_NZ(--cpu->A);
} break;
case 0xC6: case 0xD6: case 0xCE: case 0xDE:
{ // DEC
_FETCH(cpu->PC);
_NZ(--cpu->_D);
} break;
case 0xCA:
{ // DEX
_FETCH(cpu->PC);
_NZ(--cpu->X);
} break;
case 0x88:
{ // DEY
_FETCH(cpu->PC);
_NZ(--cpu->Y);
} break;
case 0x49: case 0x45: case 0x55: case 0x4D: case 0x5D:
@ -306,18 +315,22 @@ next_instruction:
} break;
case 0x1A:
{ // INC
_FETCH(cpu->PC);
_NZ(++cpu->A);
} break;
case 0xE6: case 0xF6: case 0xEE: case 0xFE:
{ // INC
_FETCH(cpu->PC);
_NZ(++cpu->_D);
} break;
case 0xE8:
{ // INX
_FETCH(cpu->PC);
_NZ(++cpu->X);
} break;
case 0xC8:
{ // INY
_FETCH(cpu->PC);
_NZ(++cpu->Y);
} break;
case 0x4C: case 0x6C: case 0x7C:
@ -361,7 +374,7 @@ next_instruction:
} break;
case 0xEA:
{ // NOP
cpu->cycle++;
_FETCH(cpu->PC);
} break;
case 0x09: case 0x05: case 0x15: case 0x0D: case 0x1D:
case 0x19: case 0x01: case 0x11: case 0x12:

View File

@ -39,14 +39,9 @@ mii_analog_access(
case 0xc070: {
// multiplying by mii->speed allows reading joystick in 'fast' mode,
// this basically simulate slowing down just for the joystick reading
/* TODO: According to various artivles, the multiplier ought
* to be 11, but we're not making the count here, which means it's
* likely the emulated core is missing a cycle for one instruction
* somewhere... */
for (int i = 0; i < 4; i++) {
a->v[i].decay = mii->cycles +
((a->v[i].value * 10.10) * mii->speed);
((a->v[i].value * 11) * mii->speed);
// printf("joystick %d: %d\n", i, a->v[i].value);
}
} break;

View File

@ -440,24 +440,6 @@ int main()
_run_this("SED ADC 99", doSED_ADC(0x99, 1), 0x00, C | D, 0);
_run_this("SED ADC BD", doSED_ADC(0xBD, 0), 0x23, C | D, 0);
_run_this("LDA ($aa)",
" LDA #$00\n"
" TAY\n"
" TYA\n"
" STA $c064\n"
" LDX #$00\n"
" LDA $c070\n"
" LDY #$00\n"
" NOP\n"
" NOP\n"
"l LDA $c064,X\n"
" BPL end\n"
" INY \n"
" BNE l\n"
" DEY \n"
"end BRK\n",
0xAA, N, 1);
#if 0
// _run_this("SED ADC FF", doSED_ADC(0xFF, 0), 0x65, C | D | N, 0);