Skip to content

Commit

Permalink
Get rid of conditional in mapper287.c
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Dec 18, 2023
1 parent 25566b0 commit 7345a86
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/mappers/mapper287.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,31 @@
#include "mmc3.h"

static uint8 reset_flag = 0;
static uint8 isK3088;

static void BMCK3088CCW(uint32 A, uint8 V) {
setchr1(A, V | ((EXPREGS[0] & 0x07) << 7));
}

static void BMCK3088CPW(uint32 A, uint8 V) {
if (EXPREGS[0] & 8) { /* 32K Mode */
if (A == 0x8000)
/* bit 0-1 of register should be used as outer bank regardless of banking modes */
setprg32(A, ((EXPREGS[0] >> 4) & 3) | ((EXPREGS[0] & 0x07) << 2));
} else /* MMC3 Mode */
setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x07) << 4));
}

static void BMC411120CCW(uint32 A, uint8 V) {
uint32 mask = isK3088 ? 0x07 : 0x03;
setchr1(A, V | ((EXPREGS[0] & mask) << 7));
setchr1(A, V | ((EXPREGS[0] & 0x03) << 7));
}

static void BMC411120CPW(uint32 A, uint8 V) {
uint32 mask = isK3088 ? 0x07 : 0x03;
if (EXPREGS[0] & (isK3088 ? 8 : (8 | reset_flag))) { /* 32K Mode */
if (EXPREGS[0] & (8 | reset_flag)) { /* 32K Mode */
if (A == 0x8000)
/* bit 0-1 of register should be used as outer bank regardless of banking modes */
setprg32(A, ((EXPREGS[0] >> 4) & 3) | ((EXPREGS[0] & mask) << 2));
setprg32(A, ((EXPREGS[0] >> 4) & 3) | ((EXPREGS[0] & 0x03) << 2));
} else /* MMC3 Mode */
setprg8(A, (V & 0x0F) | ((EXPREGS[0] & mask) << 4));
setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x03) << 4));
}

static void BMC411120CLoWrite(uint32 A, uint8 V) {
Expand All @@ -68,20 +78,18 @@ static void BMC411120CPower(void) {
}

void BMC411120C_Init(CartInfo *info) {
isK3088 = 0;
GenMMC3_Init(info, 128, 128, 8, 0);
pwrap = BMC411120CPW;
cwrap = BMC411120CCW;
pwrap = BMC411120CPW;
cwrap = BMC411120CCW;
info->Power = BMC411120CPower;
info->Reset = BMC411120CReset;
AddExState(EXPREGS, 1, 0, "EXPR");
}

void BMCK3088_Init(CartInfo *info) {
isK3088 = 1;
GenMMC3_Init(info, 128, 128, 8, 0);
pwrap = BMC411120CPW;
cwrap = BMC411120CCW;
pwrap = BMCK3088CPW;
cwrap = BMCK3088CCW;
info->Power = BMC411120CPower;
info->Reset = BMC411120CReset;
AddExState(EXPREGS, 1, 0, "EXPR");
Expand Down

0 comments on commit 7345a86

Please sign in to comment.