bsnes/higan/ws/cpu/io.cpp

156 lines
3.5 KiB
C++
Raw Normal View History

auto CPU::keypadRead() -> uint4 {
uint4 data = 0;
if(r.ypadEnable) {
Update to v097r24 release. byuu says: Changelog: - WS: fixed bug when IRQs triggered during a rep string instruction - WS: added sprite attribute caching (per-scanline); absolutely massive speed-up - WS: emulated limit of 32 sprites per scanline - WS: emulated the extended PPU register bit behavior based on the DISP_CTRL tile bit-depth setting - WS: added "Rotate" key binding; can be used to flip the WS display between horizontal and vertical in real-time The prefix emulation may not be 100% hardware-accurate, but the edge cases should be extreme enough to not come up in the WS library. No way to get the emulation 100% down without intensive hardware testing. trap15 pointed me at a workflow diagram for it, but that diagram is impossible without a magic internal stack frame that grows with every IRQ, and can thus grow infinitely large. The rotation thing isn't exactly the most friendly set-up, but oh well. I'll see about adding a default rotation setting to manifests, so that games like GunPey can start in the correct orientation. After that, if the LCD orientation icon turns out to be reliable, then I'll start using that. But if there are cases where it's not reliable, then I'll leave it to manual button presses. Speaking of icons, I'll need a set of icons to render on the screen. Going to put them to the top right on vertical orientation, and on the bottom left for horizontal orientation. Just outside of the video output, of course. Overall, WS is getting pretty far along, but still some major bugs in various games. I really need sound emulation, though. Nobody's going to use this at all without that.
2016-03-12 13:27:41 +00:00
data |= system.keypad.y1 << 0;
data |= system.keypad.y2 << 1;
data |= system.keypad.y3 << 2;
data |= system.keypad.y4 << 3;
}
if(r.xpadEnable) {
Update to v097r24 release. byuu says: Changelog: - WS: fixed bug when IRQs triggered during a rep string instruction - WS: added sprite attribute caching (per-scanline); absolutely massive speed-up - WS: emulated limit of 32 sprites per scanline - WS: emulated the extended PPU register bit behavior based on the DISP_CTRL tile bit-depth setting - WS: added "Rotate" key binding; can be used to flip the WS display between horizontal and vertical in real-time The prefix emulation may not be 100% hardware-accurate, but the edge cases should be extreme enough to not come up in the WS library. No way to get the emulation 100% down without intensive hardware testing. trap15 pointed me at a workflow diagram for it, but that diagram is impossible without a magic internal stack frame that grows with every IRQ, and can thus grow infinitely large. The rotation thing isn't exactly the most friendly set-up, but oh well. I'll see about adding a default rotation setting to manifests, so that games like GunPey can start in the correct orientation. After that, if the LCD orientation icon turns out to be reliable, then I'll start using that. But if there are cases where it's not reliable, then I'll leave it to manual button presses. Speaking of icons, I'll need a set of icons to render on the screen. Going to put them to the top right on vertical orientation, and on the bottom left for horizontal orientation. Just outside of the video output, of course. Overall, WS is getting pretty far along, but still some major bugs in various games. I really need sound emulation, though. Nobody's going to use this at all without that.
2016-03-12 13:27:41 +00:00
data |= system.keypad.x1 << 0;
data |= system.keypad.x2 << 1;
data |= system.keypad.x3 << 2;
data |= system.keypad.x4 << 3;
}
if(r.buttonEnable) {
Update to v097r24 release. byuu says: Changelog: - WS: fixed bug when IRQs triggered during a rep string instruction - WS: added sprite attribute caching (per-scanline); absolutely massive speed-up - WS: emulated limit of 32 sprites per scanline - WS: emulated the extended PPU register bit behavior based on the DISP_CTRL tile bit-depth setting - WS: added "Rotate" key binding; can be used to flip the WS display between horizontal and vertical in real-time The prefix emulation may not be 100% hardware-accurate, but the edge cases should be extreme enough to not come up in the WS library. No way to get the emulation 100% down without intensive hardware testing. trap15 pointed me at a workflow diagram for it, but that diagram is impossible without a magic internal stack frame that grows with every IRQ, and can thus grow infinitely large. The rotation thing isn't exactly the most friendly set-up, but oh well. I'll see about adding a default rotation setting to manifests, so that games like GunPey can start in the correct orientation. After that, if the LCD orientation icon turns out to be reliable, then I'll start using that. But if there are cases where it's not reliable, then I'll leave it to manual button presses. Speaking of icons, I'll need a set of icons to render on the screen. Going to put them to the top right on vertical orientation, and on the bottom left for horizontal orientation. Just outside of the video output, of course. Overall, WS is getting pretty far along, but still some major bugs in various games. I really need sound emulation, though. Nobody's going to use this at all without that.
2016-03-12 13:27:41 +00:00
data |= system.keypad.start << 1;
data |= system.keypad.a << 2;
data |= system.keypad.b << 3;
}
return data;
}
auto CPU::portRead(uint16 addr) -> uint8 {
//DMA_SRC
if(addr == 0x0040) return r.dmaSource.byte(0);
if(addr == 0x0041) return r.dmaSource.byte(1);
if(addr == 0x0042) return r.dmaSource.byte(2);
//DMA_DST
if(addr == 0x0044) return r.dmaTarget.byte(0);
if(addr == 0x0045) return r.dmaTarget.byte(1);
//DMA_LEN
if(addr == 0x0046) return r.dmaLength.byte(0);
if(addr == 0x0047) return r.dmaLength.byte(1);
//DMA_CTRL
if(addr == 0x0048) return r.dmaMode << 0 | r.dmaEnable << 7;
//WSC_SYSTEM
if(addr == 0x0062) return (
(system.model() == Model::SwanCrystal) << 7
);
//HW_FLAGS
if(addr == 0x00a0) {
Update to v097r24 release. byuu says: Changelog: - WS: fixed bug when IRQs triggered during a rep string instruction - WS: added sprite attribute caching (per-scanline); absolutely massive speed-up - WS: emulated limit of 32 sprites per scanline - WS: emulated the extended PPU register bit behavior based on the DISP_CTRL tile bit-depth setting - WS: added "Rotate" key binding; can be used to flip the WS display between horizontal and vertical in real-time The prefix emulation may not be 100% hardware-accurate, but the edge cases should be extreme enough to not come up in the WS library. No way to get the emulation 100% down without intensive hardware testing. trap15 pointed me at a workflow diagram for it, but that diagram is impossible without a magic internal stack frame that grows with every IRQ, and can thus grow infinitely large. The rotation thing isn't exactly the most friendly set-up, but oh well. I'll see about adding a default rotation setting to manifests, so that games like GunPey can start in the correct orientation. After that, if the LCD orientation icon turns out to be reliable, then I'll start using that. But if there are cases where it's not reliable, then I'll leave it to manual button presses. Speaking of icons, I'll need a set of icons to render on the screen. Going to put them to the top right on vertical orientation, and on the bottom left for horizontal orientation. Just outside of the video output, of course. Overall, WS is getting pretty far along, but still some major bugs in various games. I really need sound emulation, though. Nobody's going to use this at all without that.
2016-03-12 13:27:41 +00:00
bool model = system.model() != Model::WonderSwan;
return (
1 << 0 //0 = BIOS mapped; 1 = cartridge mapped
Update to v097r24 release. byuu says: Changelog: - WS: fixed bug when IRQs triggered during a rep string instruction - WS: added sprite attribute caching (per-scanline); absolutely massive speed-up - WS: emulated limit of 32 sprites per scanline - WS: emulated the extended PPU register bit behavior based on the DISP_CTRL tile bit-depth setting - WS: added "Rotate" key binding; can be used to flip the WS display between horizontal and vertical in real-time The prefix emulation may not be 100% hardware-accurate, but the edge cases should be extreme enough to not come up in the WS library. No way to get the emulation 100% down without intensive hardware testing. trap15 pointed me at a workflow diagram for it, but that diagram is impossible without a magic internal stack frame that grows with every IRQ, and can thus grow infinitely large. The rotation thing isn't exactly the most friendly set-up, but oh well. I'll see about adding a default rotation setting to manifests, so that games like GunPey can start in the correct orientation. After that, if the LCD orientation icon turns out to be reliable, then I'll start using that. But if there are cases where it's not reliable, then I'll leave it to manual button presses. Speaking of icons, I'll need a set of icons to render on the screen. Going to put them to the top right on vertical orientation, and on the bottom left for horizontal orientation. Just outside of the video output, of course. Overall, WS is getting pretty far along, but still some major bugs in various games. I really need sound emulation, though. Nobody's going to use this at all without that.
2016-03-12 13:27:41 +00:00
| model << 1 //0 = WonderSwan; 1 = WonderSwan Color or SwanCrystal
| 1 << 2 //0 = 8-bit bus width; 1 = 16-bit bus width
| 1 << 7 //1 = built-in self-test passed
);
}
//INT_BASE
if(addr == 0x00b0) return (
r.interruptBase | (system.model() == Model::WonderSwan ? 3 : 0)
);
//SER_DATA
if(addr == 0x00b1) return r.serialData;
//INT_ENABLE
if(addr == 0x00b2) return r.interruptEnable;
//SER_STATUS
if(addr == 0x00b3) return (
1 << 2 //hack: always report send buffer as empty
| r.serialBaudRate << 6
| r.serialEnable << 7
);
//INT_STATUS
if(addr == 0x00b4) return r.interruptStatus;
//KEYPAD
if(addr == 0x00b5) return (
keypadRead() << 0
| r.ypadEnable << 4
| r.xpadEnable << 5
| r.buttonEnable << 6
);
return 0x00;
}
auto CPU::portWrite(uint16 addr, uint8 data) -> void {
//DMA_SRC
if(addr == 0x0040) r.dmaSource.byte(0) = data & ~1;
if(addr == 0x0041) r.dmaSource.byte(1) = data;
if(addr == 0x0042) r.dmaSource.byte(2) = data;
//DMA_DST
if(addr == 0x0044) r.dmaTarget.byte(0) = data & ~1;
if(addr == 0x0045) r.dmaTarget.byte(1) = data;
//DMA_LEN
if(addr == 0x0046) r.dmaLength.byte(0) = data & ~1;
if(addr == 0x0047) r.dmaLength.byte(1) = data;
//DMA_CTRL
if(addr == 0x0048) {
r.dmaMode = data.bit(0);
r.dmaEnable = data.bit(7);
if(r.dmaEnable) dmaTransfer();
}
//WSC_SYSTEM
if(addr == 0x0062) {
//todo: d0 = 1 powers off system
}
//HW_FLAGS
if(addr == 0x00a0) {
//todo: d2 (bus width) bit is writable; but ... it will do very bad things
}
//INT_BASE
if(addr == 0x00b0) {
Update to v097r24 release. byuu says: Changelog: - WS: fixed bug when IRQs triggered during a rep string instruction - WS: added sprite attribute caching (per-scanline); absolutely massive speed-up - WS: emulated limit of 32 sprites per scanline - WS: emulated the extended PPU register bit behavior based on the DISP_CTRL tile bit-depth setting - WS: added "Rotate" key binding; can be used to flip the WS display between horizontal and vertical in real-time The prefix emulation may not be 100% hardware-accurate, but the edge cases should be extreme enough to not come up in the WS library. No way to get the emulation 100% down without intensive hardware testing. trap15 pointed me at a workflow diagram for it, but that diagram is impossible without a magic internal stack frame that grows with every IRQ, and can thus grow infinitely large. The rotation thing isn't exactly the most friendly set-up, but oh well. I'll see about adding a default rotation setting to manifests, so that games like GunPey can start in the correct orientation. After that, if the LCD orientation icon turns out to be reliable, then I'll start using that. But if there are cases where it's not reliable, then I'll leave it to manual button presses. Speaking of icons, I'll need a set of icons to render on the screen. Going to put them to the top right on vertical orientation, and on the bottom left for horizontal orientation. Just outside of the video output, of course. Overall, WS is getting pretty far along, but still some major bugs in various games. I really need sound emulation, though. Nobody's going to use this at all without that.
2016-03-12 13:27:41 +00:00
r.interruptBase = (system.model() == Model::WonderSwan) ? data & ~7 : data & ~1;
}
//SER_DATA
if(addr == 0x00b1) r.serialData = data;
//INT_ENABLE
if(addr == 0x00b2) {
r.interruptEnable = data;
r.interruptStatus &= ~r.interruptEnable;
}
//SER_STATUS
if(addr == 0x00b3) {
r.serialBaudRate = data.bit(6);
r.serialEnable = data.bit(7);
}
//KEYPAD
if(addr == 0x00b5) {
r.ypadEnable = data.bit(4);
r.xpadEnable = data.bit(5);
r.buttonEnable = data.bit(6);
}
//INT_ACK
if(addr == 0x00b6) {
//acknowledge only edge-sensitive interrupts
r.interruptStatus &= ~(data & 0b11110010);
}
}