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

A slight correction to ASL to more clearly represent the opcode definition #38

Open
SirGouki opened this issue Apr 23, 2021 · 0 comments

Comments

@SirGouki
Copy link

Per: http://www.obelisk.me.uk/6502/reference.html#TSX

C = the contents of the old bit 7

While the provided code does this, to someone newer at this kind of thing, it looks like it doesn't

I'd recommend changing the implementation to the following:

uint8_t olc6502::ASL()
{
	fetch();
	SetFlag(C, (fetched & 0x80)); //this will return either a 1 or a 0, so we don't need > 0 here

        fetched = (uint8_t)(fetched << 1); //could also be replaced with fetched *= 2.  the cast is to prevent the possibility of the compiler upgrading fetched to uint16_t)
	SetFlag(Z, (fetched & 0xFF) == 0x00);
	SetFlag(N, fetched & 0x80); //funnily enough, this is the same code we use to initially set the carry flag since bit 7 is the sign
	if (lookup[opcode].addrmode == &olc6502::IMP)
		a = fetched;
	else
		write(addr_abs, fetched);
	return 0;
}

This is pretty much my implementation of this opcode, and I was checking against the source code provided and initially thought I was doing something wrong (even though I'm not newer to this, I've written a full CHIP 8 emulator and done some other things using binary for a private server project). It took longer than I'd like to admit to realise that the code provided does the same thing, it just does some extra things that could be removed (yay optimization).

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