[bug/cpu.c] fix ADC tmp overflow scenarion breaking

if the tmp variable in ADC went over 0xFF everything would break
also the overflow flag in the SR used to be set improperly
this fixes ADC (hopefully) entirely
:)
main
Joaquin 4 years ago
parent 9ee3b3df23
commit 925f557063
Signed by: puly
GPG Key ID: 9E9299CD96C65EC6
  1. 7
      cpu.c

@ -277,12 +277,12 @@ void BMI(CPU * cpu, word bytes, busTransaction (*addressing)(CPU *, word) ){
void ADC(CPU * cpu, word bytes, busTransaction (*addressing)(CPU *, word)){ void ADC(CPU * cpu, word bytes, busTransaction (*addressing)(CPU *, word)){
busTransaction x = addressing(cpu, bytes); //check line 85 for details busTransaction x = addressing(cpu, bytes); //check line 85 for details
word tmp = cpu->A + x.value + cpu->SR.flags.Carry; int tmp = cpu->A + x.value + cpu->SR.flags.Carry;
cpu->SR.flags.Overflow = tmp >= 128; cpu->SR.flags.Overflow = ((cpu->A >> 7) != ((tmp >> 7) & 1)) && ((x.value >> 7) != ((tmp >> 7) & 1));
cpu->SR.flags.Carry = tmp > 255; cpu->SR.flags.Carry = tmp > 255;
cpu->SR.flags.Zero = !((byte)tmp); cpu->SR.flags.Zero = !((byte)tmp);
cpu->SR.flags.Negative = tmp >> 7; //check for bit 8 cpu->SR.flags.Negative = (tmp >> 7) & 1; //check for bit 7
cpu->A = (byte)tmp; cpu->A = (byte)tmp;
} }
@ -1735,6 +1735,7 @@ void print_cpu(CPU * __restrict__ cpu){
printf("Y: %i\n", cpu->Y); printf("Y: %i\n", cpu->Y);
printf("SR: "BYTE_TO_BINARY_PATTERN "\n", BYTE_TO_BINARY(cpu->SR.data)); printf("SR: "BYTE_TO_BINARY_PATTERN "\n", BYTE_TO_BINARY(cpu->SR.data));
printf("SR.data: 0x%02X\n", cpu->SR.data);
#undef BYTE_TO_BINARY_PATTERN #undef BYTE_TO_BINARY_PATTERN
#undef BYTE_TO_BINARY #undef BYTE_TO_BINARY
} }

Loading…
Cancel
Save