Skip to content

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

@SirGouki

Description

@SirGouki

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions