Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cycleTime error in JR NZ Operations #49

Open
TXWSLYF opened this issue Oct 18, 2023 · 0 comments
Open

cycleTime error in JR NZ Operations #49

TXWSLYF opened this issue Oct 18, 2023 · 0 comments

Comments

@TXWSLYF
Copy link

TXWSLYF commented Oct 18, 2023

The code has some minor issues. While attempting to dynamically determine the value of cycleTime based on the value of the zeroflag, the problem is that cycleTime is determined during CPU instruction initialization based on the initial value of zeroflag, which is always set to false. This leads to cycleTime always being equal to 3.

  this.addOperation({
    get instruction() {
      const value = memory.readSignedByte(registers.programCounter.value);
      if (value >= 0) {
        return `JR NZ 0x${value.toString(16)}`;
      } else {
        return `JR NZ -0x${(value * -1).toString(16)}`;
      }
    },
    byteDefinition: 0b00_100_000,
    cycleTime: !registers.flags.isResultZero ? 3 : 2,
    byteLength: 2,
    execute() {
      if (!registers.flags.isResultZero) {
        const jumpDistance = memory.readSignedByte(registers.programCounter.value);
        registers.programCounter.value++;
        registers.programCounter.value = registers.programCounter.value + jumpDistance;
      } else {
        registers.programCounter.value++;
      }
    }
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant