BSNESv115+: pull upstream

43e42b2dcaf84c41d09c49745d82f8515e4f7771: simplify SA1 division
c0c60c83a84a49d4a2b822a0491cb258a3c5b98a: fix justifier controller
This commit is contained in:
Morilli 2022-12-11 15:47:44 +01:00
parent 27f6800d45
commit b0af99a68a
3 changed files with 8 additions and 8 deletions

Binary file not shown.

View File

@ -90,9 +90,7 @@ auto Justifier::latch(bool data) -> void {
}
auto Justifier::latch() -> void {
/* active value is inverted here ... */
if(active != 0) {
if(!active) {
int nx = platform->inputPoll(port, device, 0 + X);
int ny = platform->inputPoll(port, device, 0 + Y);
player1.x = max(-16, min(256 + 16, nx + player1.x));
@ -100,8 +98,7 @@ auto Justifier::latch() -> void {
bool offscreen = (player1.x < 0 || player1.y < 0 || player1.x >= 256 || player1.y >= (int)ppu.vdisp());
if(!offscreen) ppu.latchCounters(player1.x, player1.y);
}
if(active != 1) {
else {
int nx = platform->inputPoll(port, device, 4 + X);
int ny = platform->inputPoll(port, device, 4 + Y);
player2.x = max(-16, min(256 + 16, nx + player2.x));

View File

@ -431,14 +431,17 @@ auto SA1::writeIOSA1(uint address, uint8 data) -> void {
mmio.mr = (uint32)((int16)mmio.ma * (int16)mmio.mb);
mmio.mb = 0;
} else {
//unsigned division
//signed division
if(mmio.mb == 0) {
mmio.mr = 0;
} else {
int16 dividend = mmio.ma;
uint16 divisor = mmio.mb;
uint16 remainder = dividend >= 0 ? uint16(dividend % divisor) : uint16((dividend % divisor + divisor) % divisor);
uint16 quotient = (dividend - remainder) / divisor;
//sa1 division rounds toward negative infinity, but C division rounds toward zero
//adding divisor*65536 ensures it rounds down
uint32 dividend_ext = dividend + (uint32)divisor*65536;
uint16 remainder = dividend_ext % divisor;
uint16 quotient = dividend_ext / divisor - 65536;
mmio.mr = remainder << 16 | quotient;
}
mmio.ma = 0;