Giter VIP home page Giter VIP logo

Comments (8)

ch570512 avatar ch570512 commented on August 29, 2024 1
uint8_t olc6502::ADC()
{
	fetch();

	temp = (uint16_t)a + (uint16_t)fetched + (uint16_t)GetFlag(C);

	SetFlag(Z, !(temp & 0x00FF));

	if (GetFlag(D))
	{
		if ((((uint16_t)a & 0x0F) + ((uint16_t)fetched & 0x0F) + (uint16_t)GetFlag(C)) > 9) temp += 6;
		if (temp > 0x99) temp += 96;
		SetFlag(C, temp > 0x99);
	}
	else SetFlag(C, temp > 0xFF);

	SetFlag(N, temp & 0x80);
	SetFlag(V, !(((uint16_t)a ^ (uint16_t)fetched) & 0x0080) && (((uint16_t)a ^ temp) & 0x0080));
	a = temp & 0x00FF;
	return 1;
}


uint8_t olc6502::SBC()
{
	fetch();

	temp = (uint16_t)a - (uint16_t)fetched - (uint16_t)!GetFlag(C);

	SetFlag(N, temp & 0x0080);
	SetFlag(Z, !(temp & 0x00FF));
	SetFlag(V, (((uint16_t)a ^ temp) & 0x0080) && (((uint16_t)a ^ (uint16_t)fetched) & 0x0080));

	if (GetFlag(D))
	{
		if ( (((uint16_t)a & 0x0F) - (uint16_t)!GetFlag(C)) < ((uint16_t)fetched & 0x0F) ) temp -= 6;
		if (temp > 0x99) temp -= 0x60;
	}

	SetFlag(C, temp < 0x100);
	a = temp & 0xFF;
	return 1;
}

from olcnes.

raelik avatar raelik commented on August 29, 2024 1

@brccabral That's expected behavior, as detailed in https://www.qmtpro.com/~nes/misc/nestest.txt

The nestest.nes cart checks to make sure the decimal flag is never set, so the above code would have to only be enabled via a future emulator option for non-NES architectures.

from olcnes.

barongello avatar barongello commented on August 29, 2024

@rmcuenen I don't know any game that uses the decimal mode. Also it was removed from late chips to save money on royalties, licenses and such. And, IIRC, @OneLoneCoder will not be implementing this

from olcnes.

raelik avatar raelik commented on August 29, 2024

@rmcuenen Neither the Ricoh 2A03 or the 2A07 (PAL) implemented BCD. There are no games that use it, because it isn't available on any NES or Famicom.

from olcnes.

jharg93 avatar jharg93 commented on August 29, 2024

Atari 2600 games definitely used it! If you plan on making this as a more common 650x emulator.

from olcnes.

brccabral avatar brccabral commented on August 29, 2024

I tested the proposed code above, but the ADC() implementation breaks "nestest.nes" Immediate tests.

image

from olcnes.

rmcuenen avatar rmcuenen commented on August 29, 2024

That is because the 'nestest.nes' does not support/expect BCD mode.

https://github.com/christopherpow/nes-test-roms/blob/master/other/nestest.txt
01Fh - ADC # failure (decimal mode was turned on)

If you want to test BCD for the 6502 you can use BCDTEST_beeb:

  • load the contents of BCDTEST_beeb at 0x2900;
  • write JSR 2900h to address 0x200;
  • put an RTS at 0xffee, but also make sure you can trap that address;
  • set the program counter to 0x200 and keep running until it is at 0x203;
  • then test that the value at 0x84 is 0. If it is something else, that indicates failure.

from olcnes.

brccabral avatar brccabral commented on August 29, 2024

I see, thanks guys.

from olcnes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.