Skip to content

Commit

Permalink
[Mega-CD] fix wordram dual bank access
Browse files Browse the repository at this point in the history
  • Loading branch information
TascoDLX authored and Screwtapello committed Mar 22, 2021
1 parent 205c90d commit 52af4eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
12 changes: 10 additions & 2 deletions higan/md/mcd/bus-external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ auto MCD::external_read(uint1 upper, uint1 lower, uint22 address, uint16 data) -
//if(io.wramSwitch == 1) return data;
address = (uint18)address;
} else {
address = (uint17)address << 1 | io.wramSelect == 0;
// TODO: bitmapped mode when reading $220000 thru $23ffff in 1M mode
if(io.wramSelect == 0)
address = (uint17)address + 0x020000;
else
address = (uint17)address;
}
if(!vdp.active()) return wram[address >> 1];

Expand Down Expand Up @@ -45,7 +49,11 @@ auto MCD::external_write(uint1 upper, uint1 lower, uint22 address, uint16 data)
//if(io.wramSwitch == 1) return;
address = (uint18)address;
} else {
address = (uint17)address << 1 | io.wramSelect == 0;
// TODO: bitmapped mode when writing $220000 thru $23ffff in 1M mode
if(io.wramSelect == 0)
address = (uint17)address + 0x020000;
else
address = (uint17)address;
}
if(upper) wram[address >> 1].byte(1) = data.byte(1);
if(lower) wram[address >> 1].byte(0) = data.byte(0);
Expand Down
38 changes: 29 additions & 9 deletions higan/md/mcd/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ auto MCD::read(uint1 upper, uint1 lower, uint24 address, uint16 data) -> uint16
return pram[address >> 1];
}

if(address >= 0x080000 && address <= 0x0dffff) {
if(address >= 0x080000 && address <= 0x0bffff) {
if(io.wramMode == 0) {
//if(io.wramSwitch == 0) return data;
address = (uint18)address;
} else {
address = (uint17)address << 1 | io.wramSelect == 1;
return wram[address >> 1];
}
return wram[address >> 1];
return data;
}

if(address >= 0x0c0000 && address <= 0x0dffff) {
if(io.wramMode == 1) {
if(io.wramSelect == 0)
address = (uint17)address;
else
address = (uint17)address + 0x020000;
return wram[address >> 1];
}
return data;
}

if(address >= 0x0e0000 && address <= 0x0effff) {
Expand Down Expand Up @@ -41,15 +51,25 @@ auto MCD::write(uint1 upper, uint1 lower, uint24 address, uint16 data) -> void {
return;
}

if(address >= 0x080000 && address <= 0x0dffff) {
if(address >= 0x080000 && address <= 0x0bffff) {
if(io.wramMode == 0) {
//if(io.wramSwitch == 0) return;
address = (uint18)address;
} else {
address = (uint17)address << 1 | io.wramSelect == 1;
if(upper) wram[address >> 1].byte(1) = data.byte(1);
if(lower) wram[address >> 1].byte(0) = data.byte(0);
}
return;
}

if(address >= 0x0c0000 && address <= 0x0dffff) {
if(io.wramMode == 1) {
if(io.wramSelect == 0)
address = (uint17)address;
else
address = (uint17)address + 0x020000;
if(upper) wram[address >> 1].byte(1) = data.byte(1);
if(lower) wram[address >> 1].byte(0) = data.byte(0);
}
if(upper) wram[address >> 1].byte(1) = data.byte(1);
if(lower) wram[address >> 1].byte(0) = data.byte(0);
return;
}

Expand Down
5 changes: 4 additions & 1 deletion higan/md/mcd/cdc-transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ auto MCD::CDC::Transfer::dma() -> void {
break;

case 7: //WRAM
mcd.write(1, 1, 0x080000 | (uint18)address & ~1, data);
if(mcd.io.wramMode == 0)
mcd.write(1, 1, 0x080000 | (uint18)address & ~1, data);
else
mcd.write(1, 1, 0x0C0000 | (uint17)address & ~1, data);
break;
}

Expand Down

0 comments on commit 52af4eb

Please sign in to comment.