From 6d9f43a37b3ba2d71a9ef82a49aa7f21ee6364bf Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Thu, 12 Nov 2015 21:15:03 +1100 Subject: [PATCH] Update to v095r05 release. byuu says: Changelog: - GBA: lots of emulation improvements - PPU PRAM is 16-bits wide - DMA masks &~1/Half, &~3/Word - VRAM OBJ 8-bit writes are ignored - OAM 8-bit writes are ignored - BGnCNT unused bits are writable* - BG(0,1)CNT can't set the d13 - BLDALPHA is readable (fixes Donkey Kong Country, etc) - SNES: lots of code cleanups - sfc/chip => sfc/coprocessor - UI: save most recent controller selection GBA test scores: 1552/1552, 37/38, 1020/1260 (* forgot to add the value to the read function, so endrift's I/O tests for them will fail. Fixed locally.) Note: SNES is the only system with multiple controller/expansion port options, and as such is the only one with a "None" option. Because it's shared by the controller and expansion port, it ends up sorted first in the list. This means that on your first run, you'll need to go to Super Famicom->Controller Port 1 and select "Gamepad", otherwise input won't work. Also note that changing the expansion port device requires loading a new cart. Unlike controllers, you aren't meant to hotplug expansion port devices. --- emulator/emulator.hpp | 2 +- gba/cpu/dma.cpp | 10 +- gba/ppu/memory.cpp | 23 +-- gba/ppu/mmio.cpp | 5 + gba/ppu/registers.cpp | 1 + gba/ppu/registers.hpp | 1 + gba/ppu/serialization.cpp | 1 + gba/ppu/state.hpp | 20 +-- nall/config.hpp | 12 ++ nall/emulation/super-famicom-usart.hpp | 75 ++++---- sfc/GNUmakefile | 30 ++-- sfc/cartridge/cartridge.cpp | 1 - sfc/cartridge/markup.cpp | 4 - sfc/cartridge/serialization.cpp | 4 - sfc/cheat/cheat.cpp | 1 - sfc/chip/chip.hpp | 33 ---- sfc/controller/controller.cpp | 1 - sfc/controller/gamepad/gamepad.cpp | 4 - sfc/controller/justifier/justifier.cpp | 4 - sfc/controller/mouse/mouse.cpp | 4 - sfc/controller/multitap/multitap.cpp | 4 - sfc/controller/superscope/superscope.cpp | 4 - sfc/controller/usart/usart.cpp | 4 - sfc/{chip => coprocessor}/armdsp/armdsp.cpp | 5 +- sfc/{chip => coprocessor}/armdsp/armdsp.hpp | 0 sfc/{chip => coprocessor}/armdsp/memory.cpp | 4 - .../armdsp/registers.hpp | 0 .../armdsp/serialization.cpp | 4 - sfc/coprocessor/coprocessor.hpp | 33 ++++ .../epsonrtc/epsonrtc.cpp | 5 +- .../epsonrtc/epsonrtc.hpp | 0 sfc/{chip => coprocessor}/epsonrtc/memory.cpp | 4 - .../epsonrtc/serialization.cpp | 4 - sfc/{chip => coprocessor}/epsonrtc/time.cpp | 4 - sfc/{chip => coprocessor}/event/event.cpp | 35 ---- sfc/{chip => coprocessor}/event/event.hpp | 0 .../hitachidsp/hitachidsp.cpp | 1 - .../hitachidsp/hitachidsp.hpp | 0 .../hitachidsp/memory.cpp | 4 - sfc/{chip => coprocessor}/hitachidsp/mmio.hpp | 0 .../hitachidsp/serialization.cpp | 4 - sfc/{chip => coprocessor}/icd2/icd2.cpp | 1 - sfc/{chip => coprocessor}/icd2/icd2.hpp | 0 .../icd2/interface/interface.cpp | 4 - .../icd2/interface/interface.hpp | 0 sfc/{chip => coprocessor}/icd2/mmio/mmio.cpp | 4 - sfc/{chip => coprocessor}/icd2/mmio/mmio.hpp | 0 .../icd2/serialization.cpp | 4 - sfc/{chip => coprocessor}/mcc/mcc.cpp | 1 - sfc/{chip => coprocessor}/mcc/mcc.hpp | 0 .../mcc/serialization.cpp | 4 - sfc/{chip => coprocessor}/msu1/msu1.cpp | 5 +- sfc/{chip => coprocessor}/msu1/msu1.hpp | 0 .../msu1/serialization.cpp | 4 - sfc/{chip => coprocessor}/necdsp/necdsp.cpp | 9 +- sfc/{chip => coprocessor}/necdsp/necdsp.hpp | 0 .../necdsp/serialization.cpp | 4 - sfc/{chip => coprocessor}/nss/nss.cpp | 1 - sfc/{chip => coprocessor}/nss/nss.hpp | 0 sfc/{chip => coprocessor}/obc1/obc1.cpp | 1 - sfc/{chip => coprocessor}/obc1/obc1.hpp | 0 .../obc1/serialization.cpp | 4 - sfc/{chip => coprocessor}/sa1/bus/bus.cpp | 12 +- sfc/{chip => coprocessor}/sa1/bus/bus.hpp | 0 sfc/{chip => coprocessor}/sa1/dma/dma.cpp | 4 - sfc/{chip => coprocessor}/sa1/dma/dma.hpp | 0 .../sa1/memory/memory.cpp | 8 +- .../sa1/memory/memory.hpp | 0 sfc/{chip => coprocessor}/sa1/mmio/mmio.cpp | 8 +- sfc/{chip => coprocessor}/sa1/mmio/mmio.hpp | 0 sfc/{chip => coprocessor}/sa1/sa1.cpp | 1 - sfc/{chip => coprocessor}/sa1/sa1.hpp | 0 .../sa1/serialization.cpp | 4 - sfc/{chip => coprocessor}/sdd1/decomp.cpp | 0 sfc/{chip => coprocessor}/sdd1/decomp.hpp | 0 sfc/{chip => coprocessor}/sdd1/sdd1.cpp | 1 - sfc/{chip => coprocessor}/sdd1/sdd1.hpp | 0 .../sdd1/serialization.cpp | 4 - sfc/{chip => coprocessor}/sharprtc/memory.cpp | 0 .../sharprtc/serialization.cpp | 4 - .../sharprtc/sharprtc.cpp | 1 - .../sharprtc/sharprtc.hpp | 0 sfc/{chip => coprocessor}/sharprtc/time.cpp | 0 sfc/{chip => coprocessor}/spc7110/alu.cpp | 4 - sfc/{chip => coprocessor}/spc7110/data.cpp | 4 - sfc/{chip => coprocessor}/spc7110/dcu.cpp | 0 .../spc7110/decompressor.cpp | 0 .../spc7110/serialization.cpp | 4 - sfc/{chip => coprocessor}/spc7110/spc7110.cpp | 5 +- sfc/{chip => coprocessor}/spc7110/spc7110.hpp | 0 sfc/{chip => coprocessor}/superfx/bus/bus.cpp | 4 - sfc/{chip => coprocessor}/superfx/bus/bus.hpp | 0 .../superfx/core/core.cpp | 4 - .../superfx/core/core.hpp | 0 .../superfx/disassembler/disassembler.cpp | 4 - .../superfx/disassembler/disassembler.hpp | 0 .../superfx/memory/memory.cpp | 4 - .../superfx/memory/memory.hpp | 0 .../superfx/mmio/mmio.cpp | 8 +- .../superfx/mmio/mmio.hpp | 0 .../superfx/serialization.cpp | 4 - sfc/{chip => coprocessor}/superfx/superfx.cpp | 1 - sfc/{chip => coprocessor}/superfx/superfx.hpp | 0 .../superfx/timing/timing.cpp | 4 - .../superfx/timing/timing.hpp | 0 sfc/cpu/cpu.cpp | 40 ++--- sfc/cpu/cpu.hpp | 77 ++++---- sfc/cpu/dma/dma.cpp | 80 ++++----- sfc/cpu/dma/dma.hpp | 46 ++--- sfc/cpu/memory/memory.cpp | 21 +-- sfc/cpu/memory/memory.hpp | 10 +- sfc/cpu/mmio/mmio.cpp | 149 ++++++++-------- sfc/cpu/mmio/mmio.hpp | 132 +++++++------- sfc/cpu/serialization.cpp | 8 +- sfc/cpu/timing/irq.cpp | 16 +- sfc/cpu/timing/joypad.cpp | 6 +- sfc/cpu/timing/timing.cpp | 28 ++- sfc/cpu/timing/timing.hpp | 30 ++-- sfc/dsp/brr.cpp | 4 - sfc/dsp/counter.cpp | 4 - sfc/dsp/dsp.cpp | 1 - sfc/dsp/echo.cpp | 4 - sfc/dsp/envelope.cpp | 4 - sfc/dsp/gaussian.cpp | 4 - sfc/dsp/misc.cpp | 4 - sfc/dsp/serialization.cpp | 4 - sfc/dsp/voice.cpp | 4 - sfc/expansion/eboot/eboot.cpp | 1 - sfc/expansion/satellaview/satellaview.cpp | 33 ++-- sfc/expansion/satellaview/satellaview.hpp | 8 +- sfc/memory/memory.cpp | 1 - sfc/ppu/background/background.cpp | 30 ++-- sfc/ppu/background/background.hpp | 73 ++++---- sfc/ppu/background/mode7.cpp | 10 +- sfc/ppu/mmio/mmio.cpp | 168 +++++++++--------- sfc/ppu/mmio/mmio.hpp | 150 ++++++++-------- sfc/ppu/ppu.cpp | 61 ++++--- sfc/ppu/ppu.hpp | 54 +++--- sfc/ppu/screen/screen.cpp | 38 ++-- sfc/ppu/screen/screen.hpp | 25 +-- sfc/ppu/serialization.cpp | 18 +- sfc/ppu/sprite/list.cpp | 26 ++- sfc/ppu/sprite/sprite.cpp | 26 ++- sfc/ppu/sprite/sprite.hpp | 47 ++--- sfc/ppu/window/window.cpp | 18 +- sfc/ppu/window/window.hpp | 17 +- sfc/scheduler/scheduler.cpp | 4 - sfc/scheduler/scheduler.hpp | 4 +- sfc/sfc.hpp | 2 +- sfc/slot/satellaview/satellaview.cpp | 1 - sfc/slot/sufamiturbo/serialization.cpp | 4 - sfc/slot/sufamiturbo/sufamiturbo.cpp | 1 - sfc/smp/memory.cpp | 14 +- sfc/smp/serialization.cpp | 4 - sfc/smp/smp.cpp | 1 - sfc/smp/timing.cpp | 4 - sfc/system/audio.cpp | 4 - sfc/system/device.cpp | 10 +- sfc/system/serialization.cpp | 4 - sfc/system/system.cpp | 11 +- sfc/system/system.hpp | 6 +- sfc/system/video.cpp | 4 - target-tomoko/configuration/configuration.cpp | 20 +++ target-tomoko/configuration/configuration.hpp | 9 + target-tomoko/presentation/presentation.cpp | 13 +- target-tomoko/program/program.cpp | 2 + 166 files changed, 913 insertions(+), 1187 deletions(-) delete mode 100644 sfc/chip/chip.hpp rename sfc/{chip => coprocessor}/armdsp/armdsp.cpp (96%) rename sfc/{chip => coprocessor}/armdsp/armdsp.hpp (100%) rename sfc/{chip => coprocessor}/armdsp/memory.cpp (98%) rename sfc/{chip => coprocessor}/armdsp/registers.hpp (100%) rename sfc/{chip => coprocessor}/armdsp/serialization.cpp (96%) create mode 100644 sfc/coprocessor/coprocessor.hpp rename sfc/{chip => coprocessor}/epsonrtc/epsonrtc.cpp (97%) rename sfc/{chip => coprocessor}/epsonrtc/epsonrtc.hpp (100%) rename sfc/{chip => coprocessor}/epsonrtc/memory.cpp (99%) rename sfc/{chip => coprocessor}/epsonrtc/serialization.cpp (96%) rename sfc/{chip => coprocessor}/epsonrtc/time.cpp (99%) rename sfc/{chip => coprocessor}/event/event.cpp (79%) rename sfc/{chip => coprocessor}/event/event.hpp (100%) rename sfc/{chip => coprocessor}/hitachidsp/hitachidsp.cpp (98%) rename sfc/{chip => coprocessor}/hitachidsp/hitachidsp.hpp (100%) rename sfc/{chip => coprocessor}/hitachidsp/memory.cpp (99%) rename sfc/{chip => coprocessor}/hitachidsp/mmio.hpp (100%) rename sfc/{chip => coprocessor}/hitachidsp/serialization.cpp (96%) rename sfc/{chip => coprocessor}/icd2/icd2.cpp (98%) rename sfc/{chip => coprocessor}/icd2/icd2.hpp (100%) rename sfc/{chip => coprocessor}/icd2/interface/interface.cpp (99%) rename sfc/{chip => coprocessor}/icd2/interface/interface.hpp (100%) rename sfc/{chip => coprocessor}/icd2/mmio/mmio.cpp (98%) rename sfc/{chip => coprocessor}/icd2/mmio/mmio.hpp (100%) rename sfc/{chip => coprocessor}/icd2/serialization.cpp (96%) rename sfc/{chip => coprocessor}/mcc/mcc.cpp (99%) rename sfc/{chip => coprocessor}/mcc/mcc.hpp (100%) rename sfc/{chip => coprocessor}/mcc/serialization.cpp (83%) rename sfc/{chip => coprocessor}/msu1/msu1.cpp (98%) rename sfc/{chip => coprocessor}/msu1/msu1.hpp (100%) rename sfc/{chip => coprocessor}/msu1/serialization.cpp (95%) rename sfc/{chip => coprocessor}/necdsp/necdsp.cpp (86%) rename sfc/{chip => coprocessor}/necdsp/necdsp.hpp (100%) rename sfc/{chip => coprocessor}/necdsp/serialization.cpp (96%) rename sfc/{chip => coprocessor}/nss/nss.cpp (95%) rename sfc/{chip => coprocessor}/nss/nss.hpp (100%) rename sfc/{chip => coprocessor}/obc1/obc1.cpp (99%) rename sfc/{chip => coprocessor}/obc1/obc1.hpp (100%) rename sfc/{chip => coprocessor}/obc1/serialization.cpp (86%) rename sfc/{chip => coprocessor}/sa1/bus/bus.cpp (77%) rename sfc/{chip => coprocessor}/sa1/bus/bus.hpp (100%) rename sfc/{chip => coprocessor}/sa1/dma/dma.cpp (99%) rename sfc/{chip => coprocessor}/sa1/dma/dma.hpp (100%) rename sfc/{chip => coprocessor}/sa1/memory/memory.cpp (98%) rename sfc/{chip => coprocessor}/sa1/memory/memory.hpp (100%) rename sfc/{chip => coprocessor}/sa1/mmio/mmio.cpp (98%) rename sfc/{chip => coprocessor}/sa1/mmio/mmio.hpp (100%) rename sfc/{chip => coprocessor}/sa1/sa1.cpp (99%) rename sfc/{chip => coprocessor}/sa1/sa1.hpp (100%) rename sfc/{chip => coprocessor}/sa1/serialization.cpp (99%) rename sfc/{chip => coprocessor}/sdd1/decomp.cpp (100%) rename sfc/{chip => coprocessor}/sdd1/decomp.hpp (100%) rename sfc/{chip => coprocessor}/sdd1/sdd1.cpp (99%) rename sfc/{chip => coprocessor}/sdd1/sdd1.hpp (100%) rename sfc/{chip => coprocessor}/sdd1/serialization.cpp (91%) rename sfc/{chip => coprocessor}/sharprtc/memory.cpp (100%) rename sfc/{chip => coprocessor}/sharprtc/serialization.cpp (90%) rename sfc/{chip => coprocessor}/sharprtc/sharprtc.cpp (99%) rename sfc/{chip => coprocessor}/sharprtc/sharprtc.hpp (100%) rename sfc/{chip => coprocessor}/sharprtc/time.cpp (100%) rename sfc/{chip => coprocessor}/spc7110/alu.cpp (98%) rename sfc/{chip => coprocessor}/spc7110/data.cpp (98%) rename sfc/{chip => coprocessor}/spc7110/dcu.cpp (100%) rename sfc/{chip => coprocessor}/spc7110/decompressor.cpp (100%) rename sfc/{chip => coprocessor}/spc7110/serialization.cpp (97%) rename sfc/{chip => coprocessor}/spc7110/spc7110.cpp (98%) rename sfc/{chip => coprocessor}/spc7110/spc7110.hpp (100%) rename sfc/{chip => coprocessor}/superfx/bus/bus.cpp (96%) rename sfc/{chip => coprocessor}/superfx/bus/bus.hpp (100%) rename sfc/{chip => coprocessor}/superfx/core/core.cpp (99%) rename sfc/{chip => coprocessor}/superfx/core/core.hpp (100%) rename sfc/{chip => coprocessor}/superfx/disassembler/disassembler.cpp (99%) rename sfc/{chip => coprocessor}/superfx/disassembler/disassembler.hpp (100%) rename sfc/{chip => coprocessor}/superfx/memory/memory.cpp (99%) rename sfc/{chip => coprocessor}/superfx/memory/memory.hpp (100%) rename sfc/{chip => coprocessor}/superfx/mmio/mmio.cpp (94%) rename sfc/{chip => coprocessor}/superfx/mmio/mmio.hpp (100%) rename sfc/{chip => coprocessor}/superfx/serialization.cpp (85%) rename sfc/{chip => coprocessor}/superfx/superfx.cpp (98%) rename sfc/{chip => coprocessor}/superfx/superfx.hpp (100%) rename sfc/{chip => coprocessor}/superfx/timing/timing.cpp (98%) rename sfc/{chip => coprocessor}/superfx/timing/timing.hpp (100%) diff --git a/emulator/emulator.hpp b/emulator/emulator.hpp index 2337b6fb..a374efb9 100644 --- a/emulator/emulator.hpp +++ b/emulator/emulator.hpp @@ -7,7 +7,7 @@ using namespace nall; namespace Emulator { static const string Name = "higan"; - static const string Version = "095.04"; + static const string Version = "095.05"; static const string Author = "byuu"; static const string License = "GPLv3"; static const string Website = "http://byuu.org/"; diff --git a/gba/cpu/dma.cpp b/gba/cpu/dma.cpp index 6174c9d2..0d84aa47 100644 --- a/gba/cpu/dma.cpp +++ b/gba/cpu/dma.cpp @@ -36,13 +36,19 @@ auto CPU::dma_exec(Registers::DMA& dma) -> void { if(dma.run.source < 0x0200'0000) { idle(); //cannot access BIOS } else { - dma.data = bus_read(mode, dma.run.source); + uint32 addr = dma.run.source; + if(mode & Word) addr &= ~3; + if(mode & Half) addr &= ~1; + dma.data = bus_read(mode, addr); } if(dma.run.target < 0x0200'0000) { idle(); //cannot access BIOS } else { - bus_write(mode, dma.run.target, dma.data); + uint32 addr = dma.run.target; + if(mode & Word) addr &= ~3; + if(mode & Half) addr &= ~1; + bus_write(mode, addr, dma.data); } switch(dma.control.sourcemode) { diff --git a/gba/ppu/memory.cpp b/gba/ppu/memory.cpp index d87e5638..4aafca9f 100644 --- a/gba/ppu/memory.cpp +++ b/gba/ppu/memory.cpp @@ -9,9 +9,9 @@ auto PPU::vram_read(unsigned mode, uint32 addr) -> uint32 { return vram[addr + 0] << 0 | vram[addr + 1] << 8; } else if(mode & Byte) { return vram[addr]; - } else { - throw; } + + return 0; //should never occur } auto PPU::vram_write(unsigned mode, uint32 addr, uint32 word) -> void { @@ -28,9 +28,13 @@ auto PPU::vram_write(unsigned mode, uint32 addr, uint32 word) -> void { vram[addr + 0] = word >> 0; vram[addr + 1] = word >> 8; } else if(mode & Byte) { + //8-bit writes to OBJ section of VRAM are ignored + if(regs.control.bgmode <= 2 && addr >= 0x10000) return; + if(regs.control.bgmode <= 5 && addr >= 0x14000) return; + addr &= ~1; - vram[addr + 0] = word; - vram[addr + 1] = word; + vram[addr + 0] = (uint8)word; + vram[addr + 1] = (uint8)word; } } @@ -48,10 +52,11 @@ auto PPU::pram_write(unsigned mode, uint32 addr, uint32 word) -> void { } if(mode & Byte) { + word = (uint8)word; return pram_write(Half, addr, word << 8 | word << 0); } - pram[addr >> 1 & 511] = word & 0x7fff; + pram[addr >> 1 & 511] = (uint16)word; } auto PPU::oam_read(unsigned mode, uint32 addr) -> uint32 { @@ -105,9 +110,7 @@ auto PPU::oam_write(unsigned mode, uint32 addr, uint32 word) -> void { return; } - if(mode & Byte) { - return oam_write(Half, addr, word << 8 | word << 0); - } + if(mode & Byte) return; //8-bit writes to OAM are ignored auto& obj = object[addr >> 3 & 127]; auto& par = objectparam[addr >> 5 & 31]; @@ -147,14 +150,14 @@ auto PPU::oam_write(unsigned mode, uint32 addr, uint32 word) -> void { } - static unsigned widths[] = { + static uint widths[] = { 8, 16, 32, 64, 16, 32, 32, 64, 8, 8, 16, 32, 8, 8, 8, 8, //invalid modes }; - static unsigned heights[] = { + static uint heights[] = { 8, 16, 32, 64, 8, 8, 16, 32, 16, 32, 32, 64, diff --git a/gba/ppu/mmio.cpp b/gba/ppu/mmio.cpp index 5498fddd..5a323c2f 100644 --- a/gba/ppu/mmio.cpp +++ b/gba/ppu/mmio.cpp @@ -37,6 +37,10 @@ uint8 PPU::read(uint32 addr) { case 0x04000050: return regs.blend.control >> 0; case 0x04000051: return regs.blend.control >> 8; + //BLDALPHA + case 0x04000052: return regs.blend.eva; + case 0x04000053: return regs.blend.evb; + } return 0u; @@ -70,6 +74,7 @@ void PPU::write(uint32 addr, uint8 byte) { case 0x0400000e: case 0x0400000f: { auto& bg = regs.bg[(addr >> 1) & 3]; unsigned shift = (addr & 1) * 8; + if(addr == 0x04000009 || addr == 0x0400000b) byte &= 0xdf; //clear affine wrap for BG0,1 bg.control = (bg.control & ~(255 << shift)) | (byte << shift); return; } diff --git a/gba/ppu/registers.cpp b/gba/ppu/registers.cpp index 9908f76d..cc807de7 100644 --- a/gba/ppu/registers.cpp +++ b/gba/ppu/registers.cpp @@ -73,6 +73,7 @@ PPU::Registers::BackgroundControl::operator uint16() const { uint16 PPU::Registers::BackgroundControl::operator=(uint16 source) { priority = source >> 0; characterbaseblock = source >> 2; + unused = source >> 4; mosaic = source >> 6; colormode = source >> 7; screenbaseblock = source >> 8; diff --git a/gba/ppu/registers.hpp b/gba/ppu/registers.hpp index c09c999e..28499b78 100644 --- a/gba/ppu/registers.hpp +++ b/gba/ppu/registers.hpp @@ -38,6 +38,7 @@ struct Registers { struct BackgroundControl { uint2 priority; uint2 characterbaseblock; + uint2 unused; uint1 mosaic; uint1 colormode; uint5 screenbaseblock; diff --git a/gba/ppu/serialization.cpp b/gba/ppu/serialization.cpp index 9ebc9667..a49b6a31 100644 --- a/gba/ppu/serialization.cpp +++ b/gba/ppu/serialization.cpp @@ -28,6 +28,7 @@ void PPU::serialize(serializer& s) { for(auto& bg : regs.bg) { s.integer(bg.control.priority); s.integer(bg.control.characterbaseblock); + s.integer(bg.control.unused); s.integer(bg.control.mosaic); s.integer(bg.control.colormode); s.integer(bg.control.screenbaseblock); diff --git a/gba/ppu/state.hpp b/gba/ppu/state.hpp index e0875e24..856db3b3 100644 --- a/gba/ppu/state.hpp +++ b/gba/ppu/state.hpp @@ -1,20 +1,20 @@ struct Pixel { - bool enable; - unsigned priority; - unsigned color; + bool enable; + uint2 priority; + uint15 color; //objects only bool translucent; bool mosaic; - alwaysinline void write(bool e) { enable = e; } - alwaysinline void write(bool e, unsigned p, unsigned c) { enable = e; priority = p; color = c; } - alwaysinline void write(bool e, unsigned p, unsigned c, bool t, bool m) { enable = e; priority = p; color = c; translucent = t; mosaic = m; } + alwaysinline auto write(bool e) { enable = e; } + alwaysinline auto write(bool e, uint p, uint c) { enable = e; priority = p; color = c; } + alwaysinline auto write(bool e, uint p, uint c, bool t, bool m) { enable = e; priority = p; color = c; translucent = t; mosaic = m; } } layer[6][240]; bool windowmask[3][240]; -unsigned vmosaic[5]; -unsigned hmosaic[5]; +uint vmosaic[5]; +uint hmosaic[5]; struct Object { uint8 y; @@ -36,8 +36,8 @@ struct Object { uint4 palette; //ancillary data - unsigned width; - unsigned height; + uint width; + uint height; } object[128]; struct ObjectParam { diff --git a/nall/config.hpp b/nall/config.hpp index 9937b764..648fdc6a 100644 --- a/nall/config.hpp +++ b/nall/config.hpp @@ -56,6 +56,18 @@ struct Node { children.append(node); } + auto find(const string& path) -> maybe { + auto p = path.split("/"); + auto name = p.takeFirst(); + for(auto& child : children) { + if(child.name == name) { + if(p.size() == 0) return child; + return child.find(p.merge("/")); + } + } + return nothing; + } + auto load(Markup::Node path) -> void { for(auto& child : children) { if(auto leaf = path[child.name]) { diff --git a/nall/emulation/super-famicom-usart.hpp b/nall/emulation/super-famicom-usart.hpp index 4de4a112..92c5c7a0 100644 --- a/nall/emulation/super-famicom-usart.hpp +++ b/nall/emulation/super-famicom-usart.hpp @@ -1,32 +1,31 @@ #ifndef NALL_EMULATION_SUPER_FAMICOM_USART_HPP #define NALL_EMULATION_SUPER_FAMICOM_USART_HPP -#include -#include +#include #include -#include +using namespace nall; #include -#include #include +#include #define usartproc dllexport -static nall::function usart_quit; -static nall::function usart_usleep; -static nall::function usart_readable; -static nall::function usart_read; -static nall::function usart_writable; -static nall::function usart_write; +static function usart_quit; +static function usart_usleep; +static function usart_readable; +static function usart_read; +static function usart_writable; +static function usart_write; -extern "C" usartproc void usart_init( - nall::function quit, - nall::function usleep, - nall::function readable, - nall::function read, - nall::function writable, - nall::function write -) { +extern "C" usartproc auto usart_init( + function quit, + function usleep, + function readable, + function read, + function writable, + function write +) -> void { usart_quit = quit; usart_usleep = usleep; usart_readable = readable; @@ -35,69 +34,67 @@ extern "C" usartproc void usart_init( usart_write = write; } -extern "C" usartproc void usart_main(int, char**); +extern "C" usartproc auto usart_main(nall::lstring) -> void; // -static nall::serial usart; +static serial usart; static bool usart_is_virtual = true; static bool usart_sigint = false; -static bool usart_virtual() { +static auto usart_virtual() -> bool { return usart_is_virtual; } // -static bool usarthw_quit() { +static auto usarthw_quit() -> bool { return usart_sigint; } -static void usarthw_usleep(unsigned milliseconds) { +static auto usarthw_usleep(uint milliseconds) -> void { usleep(milliseconds); } -static bool usarthw_readable() { +static auto usarthw_readable() -> bool { return usart.readable(); } -static uint8_t usarthw_read() { +static auto usarthw_read() -> uint8 { while(true) { - uint8_t buffer[1]; - signed length = usart.read((uint8_t*)&buffer, 1); + uint8 buffer[1]; + int length = usart.read((uint8_t*)&buffer, 1); if(length > 0) return buffer[0]; } } -static bool usarthw_writable() { +static auto usarthw_writable() -> bool { return usart.writable(); } -static void usarthw_write(uint8_t data) { - uint8_t buffer[1] = { data }; - usart.write((uint8_t*)&buffer, 1); +static auto usarthw_write(uint8 data) -> void { + uint8 buffer[1] = {data}; + usart.write((uint8*)&buffer, 1); } -static void sigint(int) { +static auto sigint(int) -> void { signal(SIGINT, SIG_DFL); usart_sigint = true; } -int main(int argc, char** argv) { +#include +auto nall::main(lstring args) -> void { setpriority(PRIO_PROCESS, 0, -20); //requires superuser privileges; otherwise priority = +0 signal(SIGINT, sigint); - if(usart.open("/dev/ttyACM0", 57600, true) == false) { - printf("error: unable to open USART hardware device\n"); - return 0; + if(!usart.open("/dev/ttyACM0", 57600, true)) { + return print("error: unable to open USART hardware device\n"); } usart_is_virtual = false; usart_init(usarthw_quit, usarthw_usleep, usarthw_readable, usarthw_read, usarthw_writable, usarthw_write); - usart_main(argc, argv); + usart_main(args); usart.close(); - - return 0; } #endif diff --git a/sfc/GNUmakefile b/sfc/GNUmakefile index a2a0811c..073939b5 100644 --- a/sfc/GNUmakefile +++ b/sfc/GNUmakefile @@ -47,26 +47,26 @@ obj/sfc-ppu.o: $(sfcppu)/ppu.cpp $(call rwildcard,$(sfcppu)/) obj/sfc-eboot.o: $(sfc)/expansion/eboot/eboot.cpp $(call rwildcard,$(sfc)/expansion/eboot/) obj/sfc-satellaviewbase.o: $(sfc)/expansion/satellaview/satellaview.cpp $(call rwildcard,$(sfc)/expansion/satellaview/) -obj/sfc-icd2.o: $(sfc)/chip/icd2/icd2.cpp $(call rwildcard,$(sfc)/chip/icd2/) -obj/sfc-mcc.o: $(sfc)/chip/mcc/mcc.cpp $(call rwildcard,$(sfc)/chip/mcc/) -obj/sfc-nss.o: $(sfc)/chip/nss/nss.cpp $(call rwildcard,$(sfc)/chip/nss/) -obj/sfc-event.o: $(sfc)/chip/event/event.cpp $(call rwildcard,$(sfc)/chip/event/) +obj/sfc-icd2.o: $(sfc)/coprocessor/icd2/icd2.cpp $(call rwildcard,$(sfc)/coprocessor/icd2/) +obj/sfc-mcc.o: $(sfc)/coprocessor/mcc/mcc.cpp $(call rwildcard,$(sfc)/coprocessor/mcc/) +obj/sfc-nss.o: $(sfc)/coprocessor/nss/nss.cpp $(call rwildcard,$(sfc)/coprocessor/nss/) +obj/sfc-event.o: $(sfc)/coprocessor/event/event.cpp $(call rwildcard,$(sfc)/coprocessor/event/) -obj/sfc-sa1.o: $(sfc)/chip/sa1/sa1.cpp $(call rwildcard,$(sfc)/chip/sa1/) -obj/sfc-superfx.o: $(sfc)/chip/superfx/superfx.cpp $(call rwildcard,$(sfc)/chip/superfx/) +obj/sfc-sa1.o: $(sfc)/coprocessor/sa1/sa1.cpp $(call rwildcard,$(sfc)/coprocessor/sa1/) +obj/sfc-superfx.o: $(sfc)/coprocessor/superfx/superfx.cpp $(call rwildcard,$(sfc)/coprocessor/superfx/) -obj/sfc-armdsp.o: $(sfc)/chip/armdsp/armdsp.cpp $(call rwildcard,$(sfc)/chip/armdsp/) -obj/sfc-hitachidsp.o: $(sfc)/chip/hitachidsp/hitachidsp.cpp $(call rwildcard,$(sfc)/chip/hitachidsp/) -obj/sfc-necdsp.o: $(sfc)/chip/necdsp/necdsp.cpp $(call rwildcard,$(sfc)/chip/necdsp/) +obj/sfc-armdsp.o: $(sfc)/coprocessor/armdsp/armdsp.cpp $(call rwildcard,$(sfc)/coprocessor/armdsp/) +obj/sfc-hitachidsp.o: $(sfc)/coprocessor/hitachidsp/hitachidsp.cpp $(call rwildcard,$(sfc)/coprocessor/hitachidsp/) +obj/sfc-necdsp.o: $(sfc)/coprocessor/necdsp/necdsp.cpp $(call rwildcard,$(sfc)/coprocessor/necdsp/) -obj/sfc-epsonrtc.o: $(sfc)/chip/epsonrtc/epsonrtc.cpp $(call rwildcard,$(sfc)/chip/epsonrtc/) -obj/sfc-sharprtc.o: $(sfc)/chip/sharprtc/sharprtc.cpp $(call rwildcard,$(sfc)/chip/sharprtc/) +obj/sfc-epsonrtc.o: $(sfc)/coprocessor/epsonrtc/epsonrtc.cpp $(call rwildcard,$(sfc)/coprocessor/epsonrtc/) +obj/sfc-sharprtc.o: $(sfc)/coprocessor/sharprtc/sharprtc.cpp $(call rwildcard,$(sfc)/coprocessor/sharprtc/) -obj/sfc-spc7110.o: $(sfc)/chip/spc7110/spc7110.cpp $(call rwildcard,$(sfc)/chip/spc7110/) -obj/sfc-sdd1.o: $(sfc)/chip/sdd1/sdd1.cpp $(call rwildcard,$(sfc)/chip/sdd1/) -obj/sfc-obc1.o: $(sfc)/chip/obc1/obc1.cpp $(call rwildcard,$(sfc)/chip/obc1/) +obj/sfc-spc7110.o: $(sfc)/coprocessor/spc7110/spc7110.cpp $(call rwildcard,$(sfc)/coprocessor/spc7110/) +obj/sfc-sdd1.o: $(sfc)/coprocessor/sdd1/sdd1.cpp $(call rwildcard,$(sfc)/coprocessor/sdd1/) +obj/sfc-obc1.o: $(sfc)/coprocessor/obc1/obc1.cpp $(call rwildcard,$(sfc)/coprocessor/obc1/) -obj/sfc-msu1.o: $(sfc)/chip/msu1/msu1.cpp $(call rwildcard,$(sfc)/chip/msu1/) +obj/sfc-msu1.o: $(sfc)/coprocessor/msu1/msu1.cpp $(call rwildcard,$(sfc)/coprocessor/msu1/) obj/sfc-satellaviewcart.o: $(sfc)/slot/satellaview/satellaview.cpp $(call rwildcard,$(sfc)/slot/satellaview/) obj/sfc-sufamiturbo.o: $(sfc)/slot/sufamiturbo/sufamiturbo.cpp $(call rwildcard,$(sfc)/slot/sufamiturbo/) diff --git a/sfc/cartridge/cartridge.cpp b/sfc/cartridge/cartridge.cpp index 2647d9de..29c98dd4 100644 --- a/sfc/cartridge/cartridge.cpp +++ b/sfc/cartridge/cartridge.cpp @@ -1,6 +1,5 @@ #include -#define CARTRIDGE_CPP namespace SuperFamicom { #include "markup.cpp" diff --git a/sfc/cartridge/markup.cpp b/sfc/cartridge/markup.cpp index 6a3c6c80..6e0cc702 100644 --- a/sfc/cartridge/markup.cpp +++ b/sfc/cartridge/markup.cpp @@ -1,5 +1,3 @@ -#ifdef CARTRIDGE_CPP - Cartridge::Mapping::Mapping(SuperFamicom::Memory& memory) { this->reader = {&SuperFamicom::Memory::read, &memory}; this->writer = {&SuperFamicom::Memory::write, &memory}; @@ -548,5 +546,3 @@ auto Cartridge::parseMarkupMSU1(Markup::Node root) -> void { } } } - -#endif diff --git a/sfc/cartridge/serialization.cpp b/sfc/cartridge/serialization.cpp index c95bfe02..1509ab49 100644 --- a/sfc/cartridge/serialization.cpp +++ b/sfc/cartridge/serialization.cpp @@ -1,7 +1,3 @@ -#ifdef CARTRIDGE_CPP - auto Cartridge::serialize(serializer& s) -> void { s.array(ram.data(), ram.size()); } - -#endif diff --git a/sfc/cheat/cheat.cpp b/sfc/cheat/cheat.cpp index 14a2ef64..8e64d33c 100644 --- a/sfc/cheat/cheat.cpp +++ b/sfc/cheat/cheat.cpp @@ -1,6 +1,5 @@ #include -#define CHEAT_CPP namespace SuperFamicom { Cheat cheat; diff --git a/sfc/chip/chip.hpp b/sfc/chip/chip.hpp deleted file mode 100644 index 076dfec5..00000000 --- a/sfc/chip/chip.hpp +++ /dev/null @@ -1,33 +0,0 @@ -struct Coprocessor : Thread { - alwaysinline auto step(unsigned clocks) -> void; - alwaysinline auto synchronize_cpu() -> void; -}; - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include - -auto Coprocessor::step(unsigned clocks) -> void { - clock += clocks * (uint64)cpu.frequency; -} - -auto Coprocessor::synchronize_cpu() -> void { - if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread); -} diff --git a/sfc/controller/controller.cpp b/sfc/controller/controller.cpp index 46725d78..6e3d83a9 100644 --- a/sfc/controller/controller.cpp +++ b/sfc/controller/controller.cpp @@ -1,6 +1,5 @@ #include -#define CONTROLLER_CPP namespace SuperFamicom { #include "gamepad/gamepad.cpp" diff --git a/sfc/controller/gamepad/gamepad.cpp b/sfc/controller/gamepad/gamepad.cpp index cef5061a..5fad8a2b 100644 --- a/sfc/controller/gamepad/gamepad.cpp +++ b/sfc/controller/gamepad/gamepad.cpp @@ -1,5 +1,3 @@ -#ifdef CONTROLLER_CPP - Gamepad::Gamepad(bool port) : Controller(port) { latched = 0; counter = 0; @@ -53,5 +51,3 @@ auto Gamepad::latch(bool data) -> void { r = interface->inputPoll(port, id, R); } } - -#endif diff --git a/sfc/controller/justifier/justifier.cpp b/sfc/controller/justifier/justifier.cpp index a122398b..6229e599 100644 --- a/sfc/controller/justifier/justifier.cpp +++ b/sfc/controller/justifier/justifier.cpp @@ -1,5 +1,3 @@ -#ifdef CONTROLLER_CPP - Justifier::Justifier(bool port, bool chained): Controller(port), chained(chained), @@ -128,5 +126,3 @@ auto Justifier::latch(bool data) -> void { counter = 0; if(latched == 0) active = !active; //toggle between both controllers, even when unchained } - -#endif diff --git a/sfc/controller/mouse/mouse.cpp b/sfc/controller/mouse/mouse.cpp index 181046dc..ddf977f5 100644 --- a/sfc/controller/mouse/mouse.cpp +++ b/sfc/controller/mouse/mouse.cpp @@ -1,5 +1,3 @@ -#ifdef CONTROLLER_CPP - Mouse::Mouse(bool port) : Controller(port) { latched = 0; counter = 0; @@ -86,5 +84,3 @@ auto Mouse::latch(bool data) -> void { x = min(127, x); y = min(127, y); } - -#endif diff --git a/sfc/controller/multitap/multitap.cpp b/sfc/controller/multitap/multitap.cpp index c6eeefb5..b17ae23b 100644 --- a/sfc/controller/multitap/multitap.cpp +++ b/sfc/controller/multitap/multitap.cpp @@ -1,5 +1,3 @@ -#ifdef CONTROLLER_CPP - Multitap::Multitap(bool port) : Controller(port) { latched = 0; counter1 = 0; @@ -37,5 +35,3 @@ auto Multitap::latch(bool data) -> void { counter1 = 0; counter2 = 0; } - -#endif diff --git a/sfc/controller/superscope/superscope.cpp b/sfc/controller/superscope/superscope.cpp index be5fe39f..c3298015 100644 --- a/sfc/controller/superscope/superscope.cpp +++ b/sfc/controller/superscope/superscope.cpp @@ -1,5 +1,3 @@ -#ifdef CONTROLLER_CPP - //The Super Scope is a light-gun: it detects the CRT beam cannon position, //and latches the counters by toggling iobit. This only works on controller //port 2, as iobit there is connected to the PPU H/V counter latch. @@ -119,5 +117,3 @@ auto SuperScope::latch(bool data) -> void { latched = data; counter = 0; } - -#endif diff --git a/sfc/controller/usart/usart.cpp b/sfc/controller/usart/usart.cpp index 4ffc849c..537a7d73 100644 --- a/sfc/controller/usart/usart.cpp +++ b/sfc/controller/usart/usart.cpp @@ -1,5 +1,3 @@ -#ifdef CONTROLLER_CPP - //Synchronous serial communications cable emulation //Hardware: @@ -133,5 +131,3 @@ auto USART::latch(bool data) -> void { latched = data; counter = 0; } - -#endif diff --git a/sfc/chip/armdsp/armdsp.cpp b/sfc/coprocessor/armdsp/armdsp.cpp similarity index 96% rename from sfc/chip/armdsp/armdsp.cpp rename to sfc/coprocessor/armdsp/armdsp.cpp index 2d3cccbc..5c3acd93 100644 --- a/sfc/chip/armdsp/armdsp.cpp +++ b/sfc/coprocessor/armdsp/armdsp.cpp @@ -1,6 +1,5 @@ #include -#define ARMDSP_CPP namespace SuperFamicom { #include "memory.cpp" @@ -49,7 +48,7 @@ void ArmDSP::step(unsigned clocks) { //a0 ignored uint8 ArmDSP::mmio_read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); uint8 data = 0x00; addr &= 0xff06; @@ -73,7 +72,7 @@ uint8 ArmDSP::mmio_read(unsigned addr) { } void ArmDSP::mmio_write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr &= 0xff06; diff --git a/sfc/chip/armdsp/armdsp.hpp b/sfc/coprocessor/armdsp/armdsp.hpp similarity index 100% rename from sfc/chip/armdsp/armdsp.hpp rename to sfc/coprocessor/armdsp/armdsp.hpp diff --git a/sfc/chip/armdsp/memory.cpp b/sfc/coprocessor/armdsp/memory.cpp similarity index 98% rename from sfc/chip/armdsp/memory.cpp rename to sfc/coprocessor/armdsp/memory.cpp index cfd8a304..f4ebad71 100644 --- a/sfc/chip/armdsp/memory.cpp +++ b/sfc/coprocessor/armdsp/memory.cpp @@ -1,5 +1,3 @@ -#ifdef ARMDSP_CPP - //note: timings are completely unverified //due to the ST018 chip design (on-die ROM), testing is nearly impossible @@ -98,5 +96,3 @@ void ArmDSP::bus_write(unsigned mode, uint32 addr, uint32 word) { return; } } - -#endif diff --git a/sfc/chip/armdsp/registers.hpp b/sfc/coprocessor/armdsp/registers.hpp similarity index 100% rename from sfc/chip/armdsp/registers.hpp rename to sfc/coprocessor/armdsp/registers.hpp diff --git a/sfc/chip/armdsp/serialization.cpp b/sfc/coprocessor/armdsp/serialization.cpp similarity index 96% rename from sfc/chip/armdsp/serialization.cpp rename to sfc/coprocessor/armdsp/serialization.cpp index 6927bca2..6747b603 100644 --- a/sfc/chip/armdsp/serialization.cpp +++ b/sfc/coprocessor/armdsp/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef ARMDSP_CPP - nall::vector ArmDSP::firmware() { nall::vector buffer; if(!cartridge.hasARMDSP()) return buffer; @@ -25,5 +23,3 @@ void ArmDSP::serialize(serializer& s) { s.integer(bridge.ready); s.integer(bridge.signal); } - -#endif diff --git a/sfc/coprocessor/coprocessor.hpp b/sfc/coprocessor/coprocessor.hpp new file mode 100644 index 00000000..927450e0 --- /dev/null +++ b/sfc/coprocessor/coprocessor.hpp @@ -0,0 +1,33 @@ +struct Coprocessor : Thread { + alwaysinline auto step(uint clocks) -> void; + alwaysinline auto synchronize_cpu() -> void; +}; + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +auto Coprocessor::step(uint clocks) -> void { + clock += clocks * (uint64)cpu.frequency; +} + +auto Coprocessor::synchronize_cpu() -> void { + if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread); +} diff --git a/sfc/chip/epsonrtc/epsonrtc.cpp b/sfc/coprocessor/epsonrtc/epsonrtc.cpp similarity index 97% rename from sfc/chip/epsonrtc/epsonrtc.cpp rename to sfc/coprocessor/epsonrtc/epsonrtc.cpp index 06bab485..f2c53fbd 100644 --- a/sfc/chip/epsonrtc/epsonrtc.cpp +++ b/sfc/coprocessor/epsonrtc/epsonrtc.cpp @@ -1,6 +1,5 @@ #include -#define EPSONRTC_CPP namespace SuperFamicom { #include "memory.cpp" @@ -145,7 +144,7 @@ void EpsonRTC::sync() { } uint8 EpsonRTC::read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr &= 3; if(addr == 0) { @@ -168,7 +167,7 @@ uint8 EpsonRTC::read(unsigned addr) { } void EpsonRTC::write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr &= 3, data &= 15; if(addr == 0) { diff --git a/sfc/chip/epsonrtc/epsonrtc.hpp b/sfc/coprocessor/epsonrtc/epsonrtc.hpp similarity index 100% rename from sfc/chip/epsonrtc/epsonrtc.hpp rename to sfc/coprocessor/epsonrtc/epsonrtc.hpp diff --git a/sfc/chip/epsonrtc/memory.cpp b/sfc/coprocessor/epsonrtc/memory.cpp similarity index 99% rename from sfc/chip/epsonrtc/memory.cpp rename to sfc/coprocessor/epsonrtc/memory.cpp index f88aa4ac..cdedf7fc 100644 --- a/sfc/chip/epsonrtc/memory.cpp +++ b/sfc/coprocessor/epsonrtc/memory.cpp @@ -1,5 +1,3 @@ -#ifdef EPSONRTC_CPP - void EpsonRTC::rtc_reset() { state = State::Mode; offset = 0; @@ -180,5 +178,3 @@ void EpsonRTC::save(uint8* data) { timestamp >>= 8; } } - -#endif diff --git a/sfc/chip/epsonrtc/serialization.cpp b/sfc/coprocessor/epsonrtc/serialization.cpp similarity index 96% rename from sfc/chip/epsonrtc/serialization.cpp rename to sfc/coprocessor/epsonrtc/serialization.cpp index 22a9e6ed..b04f97c2 100644 --- a/sfc/chip/epsonrtc/serialization.cpp +++ b/sfc/coprocessor/epsonrtc/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef EPSONRTC_CPP - void EpsonRTC::serialize(serializer& s) { Thread::serialize(s); @@ -53,5 +51,3 @@ void EpsonRTC::serialize(serializer& s) { s.integer(atime); s.integer(test); } - -#endif diff --git a/sfc/chip/epsonrtc/time.cpp b/sfc/coprocessor/epsonrtc/time.cpp similarity index 99% rename from sfc/chip/epsonrtc/time.cpp rename to sfc/coprocessor/epsonrtc/time.cpp index 7fd0f6f3..d7f755d4 100644 --- a/sfc/chip/epsonrtc/time.cpp +++ b/sfc/coprocessor/epsonrtc/time.cpp @@ -1,5 +1,3 @@ -#ifdef EPSONRTC_CPP - void EpsonRTC::irq(uint2 period) { if(stop || pause) return; @@ -182,5 +180,3 @@ void EpsonRTC::tick_year() { } } } - -#endif diff --git a/sfc/chip/event/event.cpp b/sfc/coprocessor/event/event.cpp similarity index 79% rename from sfc/chip/event/event.cpp rename to sfc/coprocessor/event/event.cpp index 008a5113..f3167c98 100644 --- a/sfc/chip/event/event.cpp +++ b/sfc/coprocessor/event/event.cpp @@ -1,6 +1,5 @@ #include -#define EVENT_CPP namespace SuperFamicom { Event event; @@ -59,40 +58,6 @@ void Event::submitScore() { data.append("mk:", mk[0], ",", mk[1], "\n"); data.append("ba:", ba[0], ",", ba[1], "\n"); } - -/*lstring side = interface->server().split("@", 1L); - string username = side(0).split(":", 1L)(0); - string password = side(0).split(":", 1L)(1); - side(1).ltrim("http://", 1L); - string hostname = side(1).split("/", 1L)(0); - string hostpath = side(1).split("/", 1L)(1); - side = hostname.split(":", 1L); - hostname = side(0); - string hostport = side(1); - if(hostport.empty()) hostport = "80"; - - http server; - if(server.connect(hostname, decimal(hostport))) { - string content = { - "username:", username, "\n", - "password:", password, "\n", - "emulator:bsnes\n", - "sha256:", interface->sha256(), "\n", - "\n", - data - }; - string packet = { - "POST /", hostpath, " HTTP/1.0\r\n", - "Host: ", hostname, "\r\n", - "Connection: close\r\n", - "Content-Type: application/octet-stream\r\n", - "Content-Length: ", content.length(), "\r\n", - "\r\n", - content - }; - server.send(packet); - server.disconnect(); - }*/ } void Event::init() { diff --git a/sfc/chip/event/event.hpp b/sfc/coprocessor/event/event.hpp similarity index 100% rename from sfc/chip/event/event.hpp rename to sfc/coprocessor/event/event.hpp diff --git a/sfc/chip/hitachidsp/hitachidsp.cpp b/sfc/coprocessor/hitachidsp/hitachidsp.cpp similarity index 98% rename from sfc/chip/hitachidsp/hitachidsp.cpp rename to sfc/coprocessor/hitachidsp/hitachidsp.cpp index 2a472b00..f12f4427 100644 --- a/sfc/chip/hitachidsp/hitachidsp.cpp +++ b/sfc/coprocessor/hitachidsp/hitachidsp.cpp @@ -1,6 +1,5 @@ #include -#define HITACHIDSP_CPP namespace SuperFamicom { #include "memory.cpp" diff --git a/sfc/chip/hitachidsp/hitachidsp.hpp b/sfc/coprocessor/hitachidsp/hitachidsp.hpp similarity index 100% rename from sfc/chip/hitachidsp/hitachidsp.hpp rename to sfc/coprocessor/hitachidsp/hitachidsp.hpp diff --git a/sfc/chip/hitachidsp/memory.cpp b/sfc/coprocessor/hitachidsp/memory.cpp similarity index 99% rename from sfc/chip/hitachidsp/memory.cpp rename to sfc/coprocessor/hitachidsp/memory.cpp index d4d5003b..2cb97b3e 100644 --- a/sfc/chip/hitachidsp/memory.cpp +++ b/sfc/coprocessor/hitachidsp/memory.cpp @@ -1,5 +1,3 @@ -#ifdef HITACHIDSP_CPP - uint8 HitachiDSP::bus_read(uint24 addr) { if((addr & 0x408000) == 0x008000) return bus.read(addr); //$00-3f,80-bf:6000-7fff if((addr & 0xf88000) == 0x700000) return bus.read(addr); //$70-77:0000-7fff @@ -139,5 +137,3 @@ void HitachiDSP::dsp_write(unsigned addr, uint8 data) { } } } - -#endif diff --git a/sfc/chip/hitachidsp/mmio.hpp b/sfc/coprocessor/hitachidsp/mmio.hpp similarity index 100% rename from sfc/chip/hitachidsp/mmio.hpp rename to sfc/coprocessor/hitachidsp/mmio.hpp diff --git a/sfc/chip/hitachidsp/serialization.cpp b/sfc/coprocessor/hitachidsp/serialization.cpp similarity index 96% rename from sfc/chip/hitachidsp/serialization.cpp rename to sfc/coprocessor/hitachidsp/serialization.cpp index aa867a0b..ddad326a 100644 --- a/sfc/chip/hitachidsp/serialization.cpp +++ b/sfc/coprocessor/hitachidsp/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef HITACHIDSP_CPP - vector HitachiDSP::firmware() { vector buffer; if(!cartridge.hasHitachiDSP()) return buffer; @@ -30,5 +28,3 @@ void HitachiDSP::serialize(serializer& s) { s.integer(mmio.r1f52); s.array(mmio.vector); } - -#endif diff --git a/sfc/chip/icd2/icd2.cpp b/sfc/coprocessor/icd2/icd2.cpp similarity index 98% rename from sfc/chip/icd2/icd2.cpp rename to sfc/coprocessor/icd2/icd2.cpp index b16be86a..cd201aad 100644 --- a/sfc/chip/icd2/icd2.cpp +++ b/sfc/coprocessor/icd2/icd2.cpp @@ -1,6 +1,5 @@ #include -#define ICD2_CPP namespace SuperFamicom { #include "interface/interface.cpp" diff --git a/sfc/chip/icd2/icd2.hpp b/sfc/coprocessor/icd2/icd2.hpp similarity index 100% rename from sfc/chip/icd2/icd2.hpp rename to sfc/coprocessor/icd2/icd2.hpp diff --git a/sfc/chip/icd2/interface/interface.cpp b/sfc/coprocessor/icd2/interface/interface.cpp similarity index 99% rename from sfc/chip/icd2/interface/interface.cpp rename to sfc/coprocessor/icd2/interface/interface.cpp index 187429a5..ca57761e 100644 --- a/sfc/chip/icd2/interface/interface.cpp +++ b/sfc/coprocessor/icd2/interface/interface.cpp @@ -1,5 +1,3 @@ -#ifdef ICD2_CPP - void ICD2::lcdScanline() { if(GameBoy::ppu.status.ly > 143) return; //Vblank if((GameBoy::ppu.status.ly & 7) == 0) { @@ -122,5 +120,3 @@ int16_t ICD2::inputPoll(unsigned port, unsigned device, unsigned id) { return 0; } - -#endif diff --git a/sfc/chip/icd2/interface/interface.hpp b/sfc/coprocessor/icd2/interface/interface.hpp similarity index 100% rename from sfc/chip/icd2/interface/interface.hpp rename to sfc/coprocessor/icd2/interface/interface.hpp diff --git a/sfc/chip/icd2/mmio/mmio.cpp b/sfc/coprocessor/icd2/mmio/mmio.cpp similarity index 98% rename from sfc/chip/icd2/mmio/mmio.cpp rename to sfc/coprocessor/icd2/mmio/mmio.cpp index 64f61e15..dfb0d294 100644 --- a/sfc/chip/icd2/mmio/mmio.cpp +++ b/sfc/coprocessor/icd2/mmio/mmio.cpp @@ -1,5 +1,3 @@ -#ifdef ICD2_CPP - uint8 ICD2::read(unsigned addr) { addr &= 0xffff; @@ -73,5 +71,3 @@ void ICD2::write(unsigned addr, uint8 data) { if(addr == 0x6006) { r6006 = data; return; } //joypad 3 if(addr == 0x6007) { r6007 = data; return; } //joypad 4 } - -#endif diff --git a/sfc/chip/icd2/mmio/mmio.hpp b/sfc/coprocessor/icd2/mmio/mmio.hpp similarity index 100% rename from sfc/chip/icd2/mmio/mmio.hpp rename to sfc/coprocessor/icd2/mmio/mmio.hpp diff --git a/sfc/chip/icd2/serialization.cpp b/sfc/coprocessor/icd2/serialization.cpp similarity index 96% rename from sfc/chip/icd2/serialization.cpp rename to sfc/coprocessor/icd2/serialization.cpp index 72dfc134..8977f5ba 100644 --- a/sfc/chip/icd2/serialization.cpp +++ b/sfc/coprocessor/icd2/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef ICD2_CPP - void ICD2::serialize(serializer& s) { Thread::serialize(s); GameBoy::system.serialize_all(s); @@ -32,5 +30,3 @@ void ICD2::serialize(serializer& s) { s.integer(write_bank); s.integer(write_addr); } - -#endif diff --git a/sfc/chip/mcc/mcc.cpp b/sfc/coprocessor/mcc/mcc.cpp similarity index 99% rename from sfc/chip/mcc/mcc.cpp rename to sfc/coprocessor/mcc/mcc.cpp index 61d683a5..5e4d32bb 100644 --- a/sfc/chip/mcc/mcc.cpp +++ b/sfc/coprocessor/mcc/mcc.cpp @@ -1,6 +1,5 @@ #include -#define MCC_CPP namespace SuperFamicom { #include "serialization.cpp" diff --git a/sfc/chip/mcc/mcc.hpp b/sfc/coprocessor/mcc/mcc.hpp similarity index 100% rename from sfc/chip/mcc/mcc.hpp rename to sfc/coprocessor/mcc/mcc.hpp diff --git a/sfc/chip/mcc/serialization.cpp b/sfc/coprocessor/mcc/serialization.cpp similarity index 83% rename from sfc/chip/mcc/serialization.cpp rename to sfc/coprocessor/mcc/serialization.cpp index b845bce1..186348c7 100644 --- a/sfc/chip/mcc/serialization.cpp +++ b/sfc/coprocessor/mcc/serialization.cpp @@ -1,8 +1,4 @@ -#ifdef MCC_CPP - auto MCC::serialize(serializer& s) -> void { s.array(ram.data(), ram.size()); s.array(psram.data(), psram.size()); } - -#endif diff --git a/sfc/chip/msu1/msu1.cpp b/sfc/coprocessor/msu1/msu1.cpp similarity index 98% rename from sfc/chip/msu1/msu1.cpp rename to sfc/coprocessor/msu1/msu1.cpp index ccb94471..2827667e 100644 --- a/sfc/chip/msu1/msu1.cpp +++ b/sfc/coprocessor/msu1/msu1.cpp @@ -1,6 +1,5 @@ #include -#define MSU1_CPP namespace SuperFamicom { MSU1 msu1; @@ -125,7 +124,7 @@ auto MSU1::audioOpen() -> void { } auto MSU1::mmioRead(unsigned addr) -> uint8 { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr = 0x2000 | (addr & 7); switch(addr) { @@ -151,7 +150,7 @@ auto MSU1::mmioRead(unsigned addr) -> uint8 { } auto MSU1::mmioWrite(unsigned addr, uint8 data) -> void { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr = 0x2000 | (addr & 7); switch(addr) { diff --git a/sfc/chip/msu1/msu1.hpp b/sfc/coprocessor/msu1/msu1.hpp similarity index 100% rename from sfc/chip/msu1/msu1.hpp rename to sfc/coprocessor/msu1/msu1.hpp diff --git a/sfc/chip/msu1/serialization.cpp b/sfc/coprocessor/msu1/serialization.cpp similarity index 95% rename from sfc/chip/msu1/serialization.cpp rename to sfc/coprocessor/msu1/serialization.cpp index 2967e999..767a8d46 100644 --- a/sfc/chip/msu1/serialization.cpp +++ b/sfc/coprocessor/msu1/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef MSU1_CPP - auto MSU1::serialize(serializer& s) -> void { Thread::serialize(s); @@ -24,5 +22,3 @@ auto MSU1::serialize(serializer& s) -> void { dataOpen(); audioOpen(); } - -#endif diff --git a/sfc/chip/necdsp/necdsp.cpp b/sfc/coprocessor/necdsp/necdsp.cpp similarity index 86% rename from sfc/chip/necdsp/necdsp.cpp rename to sfc/coprocessor/necdsp/necdsp.cpp index 37c9eb14..600363c4 100644 --- a/sfc/chip/necdsp/necdsp.cpp +++ b/sfc/coprocessor/necdsp/necdsp.cpp @@ -1,6 +1,5 @@ #include -#define NECDSP_CPP namespace SuperFamicom { #include "serialization.cpp" @@ -21,7 +20,7 @@ void NECDSP::enter() { } uint8 NECDSP::read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); if(addr & Select) { return uPD96050::sr_read(); } else { @@ -30,7 +29,7 @@ uint8 NECDSP::read(unsigned addr) { } void NECDSP::write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); if(addr & Select) { return uPD96050::sr_write(data); } else { @@ -39,12 +38,12 @@ void NECDSP::write(unsigned addr, uint8 data) { } uint8 NECDSP::ram_read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); return uPD96050::dp_read(addr); } void NECDSP::ram_write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); return uPD96050::dp_write(addr, data); } diff --git a/sfc/chip/necdsp/necdsp.hpp b/sfc/coprocessor/necdsp/necdsp.hpp similarity index 100% rename from sfc/chip/necdsp/necdsp.hpp rename to sfc/coprocessor/necdsp/necdsp.hpp diff --git a/sfc/chip/necdsp/serialization.cpp b/sfc/coprocessor/necdsp/serialization.cpp similarity index 96% rename from sfc/chip/necdsp/serialization.cpp rename to sfc/coprocessor/necdsp/serialization.cpp index f9f61138..8589dd05 100644 --- a/sfc/chip/necdsp/serialization.cpp +++ b/sfc/coprocessor/necdsp/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef NECDSP_CPP - vector NECDSP::firmware() { vector buffer; if(!cartridge.hasNECDSP()) return buffer; @@ -25,5 +23,3 @@ void NECDSP::serialize(serializer& s) { uPD96050::serialize(s); Thread::serialize(s); } - -#endif diff --git a/sfc/chip/nss/nss.cpp b/sfc/coprocessor/nss/nss.cpp similarity index 95% rename from sfc/chip/nss/nss.cpp rename to sfc/coprocessor/nss/nss.cpp index 7c50d384..7214ffb1 100644 --- a/sfc/chip/nss/nss.cpp +++ b/sfc/coprocessor/nss/nss.cpp @@ -1,6 +1,5 @@ #include -#define NSS_CPP namespace SuperFamicom { NSS nss; diff --git a/sfc/chip/nss/nss.hpp b/sfc/coprocessor/nss/nss.hpp similarity index 100% rename from sfc/chip/nss/nss.hpp rename to sfc/coprocessor/nss/nss.hpp diff --git a/sfc/chip/obc1/obc1.cpp b/sfc/coprocessor/obc1/obc1.cpp similarity index 99% rename from sfc/chip/obc1/obc1.cpp rename to sfc/coprocessor/obc1/obc1.cpp index 1c7e888c..0e9ea195 100644 --- a/sfc/chip/obc1/obc1.cpp +++ b/sfc/coprocessor/obc1/obc1.cpp @@ -1,6 +1,5 @@ #include -#define OBC1_CPP namespace SuperFamicom { #include "serialization.cpp" diff --git a/sfc/chip/obc1/obc1.hpp b/sfc/coprocessor/obc1/obc1.hpp similarity index 100% rename from sfc/chip/obc1/obc1.hpp rename to sfc/coprocessor/obc1/obc1.hpp diff --git a/sfc/chip/obc1/serialization.cpp b/sfc/coprocessor/obc1/serialization.cpp similarity index 86% rename from sfc/chip/obc1/serialization.cpp rename to sfc/coprocessor/obc1/serialization.cpp index cda5e7ea..5865d0ac 100644 --- a/sfc/chip/obc1/serialization.cpp +++ b/sfc/coprocessor/obc1/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef OBC1_CPP - void OBC1::serialize(serializer& s) { s.array(ram.data(), ram.size()); @@ -7,5 +5,3 @@ void OBC1::serialize(serializer& s) { s.integer(status.baseptr); s.integer(status.shift); } - -#endif diff --git a/sfc/chip/sa1/bus/bus.cpp b/sfc/coprocessor/sa1/bus/bus.cpp similarity index 77% rename from sfc/chip/sa1/bus/bus.cpp rename to sfc/coprocessor/sa1/bus/bus.cpp index 4fbc03bf..6f75b3fe 100644 --- a/sfc/chip/sa1/bus/bus.cpp +++ b/sfc/coprocessor/sa1/bus/bus.cpp @@ -1,5 +1,3 @@ -#ifdef SA1_CPP - //ROM / RAM access from the S-CPU unsigned SA1::CPUIRAM::size() const { @@ -7,12 +5,12 @@ unsigned SA1::CPUIRAM::size() const { } uint8 SA1::CPUIRAM::read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); return sa1.iram.read(addr & 0x07ff); } void SA1::CPUIRAM::write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); sa1.iram.write(addr & 0x07ff, data); } @@ -21,14 +19,12 @@ unsigned SA1::CPUBWRAM::size() const { } uint8 SA1::CPUBWRAM::read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); if(dma) return sa1.dma_cc1_read(addr); return sa1.bwram.read(addr); } void SA1::CPUBWRAM::write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); sa1.bwram.write(addr, data); } - -#endif diff --git a/sfc/chip/sa1/bus/bus.hpp b/sfc/coprocessor/sa1/bus/bus.hpp similarity index 100% rename from sfc/chip/sa1/bus/bus.hpp rename to sfc/coprocessor/sa1/bus/bus.hpp diff --git a/sfc/chip/sa1/dma/dma.cpp b/sfc/coprocessor/sa1/dma/dma.cpp similarity index 99% rename from sfc/chip/sa1/dma/dma.cpp rename to sfc/coprocessor/sa1/dma/dma.cpp index 346ce8bf..823c856c 100644 --- a/sfc/chip/sa1/dma/dma.cpp +++ b/sfc/coprocessor/sa1/dma/dma.cpp @@ -1,5 +1,3 @@ -#ifdef SA1_CPP - //==================== //direct data transfer //==================== @@ -135,5 +133,3 @@ void SA1::dma_cc2() { dma.line = (dma.line + 1) & 15; } - -#endif diff --git a/sfc/chip/sa1/dma/dma.hpp b/sfc/coprocessor/sa1/dma/dma.hpp similarity index 100% rename from sfc/chip/sa1/dma/dma.hpp rename to sfc/coprocessor/sa1/dma/dma.hpp diff --git a/sfc/chip/sa1/memory/memory.cpp b/sfc/coprocessor/sa1/memory/memory.cpp similarity index 98% rename from sfc/chip/sa1/memory/memory.cpp rename to sfc/coprocessor/sa1/memory/memory.cpp index 81360da0..d62ccf58 100644 --- a/sfc/chip/sa1/memory/memory.cpp +++ b/sfc/coprocessor/sa1/memory/memory.cpp @@ -1,5 +1,3 @@ -#ifdef SA1_CPP - uint8 SA1::bus_read(unsigned addr) { if((addr & 0x40fe00) == 0x002200) { //$00-3f|80-bf:2200-23ff return mmio_read(addr); @@ -182,7 +180,7 @@ void SA1::mmcrom_write(unsigned addr, uint8 data) { uint8 SA1::mmcbwram_read(unsigned addr) { if((addr & 0x40e000) == 0x006000) { //$00-3f|80-bf:6000-7fff - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr = bus.mirror(mmio.sbm * 0x2000 + (addr & 0x1fff), cpubwram.size()); return cpubwram.read(addr); } @@ -196,7 +194,7 @@ uint8 SA1::mmcbwram_read(unsigned addr) { void SA1::mmcbwram_write(unsigned addr, uint8 data) { if((addr & 0x40e000) == 0x006000) { //$00-3f|80-bf:6000-7fff - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr = bus.mirror(mmio.sbm * 0x2000 + (addr & 0x1fff), cpubwram.size()); return cpubwram.write(addr, data); } @@ -277,5 +275,3 @@ void SA1::bitmap_write(unsigned addr, uint8 data) { bwram.write(addr, data); } - -#endif diff --git a/sfc/chip/sa1/memory/memory.hpp b/sfc/coprocessor/sa1/memory/memory.hpp similarity index 100% rename from sfc/chip/sa1/memory/memory.hpp rename to sfc/coprocessor/sa1/memory/memory.hpp diff --git a/sfc/chip/sa1/mmio/mmio.cpp b/sfc/coprocessor/sa1/mmio/mmio.cpp similarity index 98% rename from sfc/chip/sa1/mmio/mmio.cpp rename to sfc/coprocessor/sa1/mmio/mmio.cpp index 839063ef..dde4b07c 100644 --- a/sfc/chip/sa1/mmio/mmio.cpp +++ b/sfc/coprocessor/sa1/mmio/mmio.cpp @@ -1,5 +1,3 @@ -#ifdef SA1_CPP - //(CCNT) SA-1 control void SA1::mmio_w2200(uint8 data) { if(mmio.sa1_resb && !(data & 0x80)) { @@ -444,7 +442,7 @@ uint8 SA1::mmio_r230e() { } uint8 SA1::mmio_read(unsigned addr) { - (co_active() == cpu.thread ? cpu.synchronize_coprocessors() : synchronize_cpu()); + (co_active() == cpu.thread ? cpu.synchronizeCoprocessors() : synchronize_cpu()); addr &= 0xffff; switch(addr) { @@ -469,7 +467,7 @@ uint8 SA1::mmio_read(unsigned addr) { } void SA1::mmio_write(unsigned addr, uint8 data) { - (co_active() == cpu.thread ? cpu.synchronize_coprocessors() : synchronize_cpu()); + (co_active() == cpu.thread ? cpu.synchronizeCoprocessors() : synchronize_cpu()); addr &= 0xffff; switch(addr) { @@ -550,5 +548,3 @@ void SA1::mmio_write(unsigned addr, uint8 data) { case 0x225b: return mmio_w225b(data); } } - -#endif diff --git a/sfc/chip/sa1/mmio/mmio.hpp b/sfc/coprocessor/sa1/mmio/mmio.hpp similarity index 100% rename from sfc/chip/sa1/mmio/mmio.hpp rename to sfc/coprocessor/sa1/mmio/mmio.hpp diff --git a/sfc/chip/sa1/sa1.cpp b/sfc/coprocessor/sa1/sa1.cpp similarity index 99% rename from sfc/chip/sa1/sa1.cpp rename to sfc/coprocessor/sa1/sa1.cpp index aa90e795..1a9636e9 100644 --- a/sfc/chip/sa1/sa1.cpp +++ b/sfc/coprocessor/sa1/sa1.cpp @@ -1,6 +1,5 @@ #include -#define SA1_CPP namespace SuperFamicom { SA1 sa1; diff --git a/sfc/chip/sa1/sa1.hpp b/sfc/coprocessor/sa1/sa1.hpp similarity index 100% rename from sfc/chip/sa1/sa1.hpp rename to sfc/coprocessor/sa1/sa1.hpp diff --git a/sfc/chip/sa1/serialization.cpp b/sfc/coprocessor/sa1/serialization.cpp similarity index 99% rename from sfc/chip/sa1/serialization.cpp rename to sfc/coprocessor/sa1/serialization.cpp index 26a0340d..461da51d 100644 --- a/sfc/chip/sa1/serialization.cpp +++ b/sfc/coprocessor/sa1/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SA1_CPP - void SA1::serialize(serializer& s) { R65816::serialize(s); Thread::serialize(s); @@ -147,5 +145,3 @@ void SA1::serialize(serializer& s) { s.integer(mmio.overflow); } - -#endif diff --git a/sfc/chip/sdd1/decomp.cpp b/sfc/coprocessor/sdd1/decomp.cpp similarity index 100% rename from sfc/chip/sdd1/decomp.cpp rename to sfc/coprocessor/sdd1/decomp.cpp diff --git a/sfc/chip/sdd1/decomp.hpp b/sfc/coprocessor/sdd1/decomp.hpp similarity index 100% rename from sfc/chip/sdd1/decomp.hpp rename to sfc/coprocessor/sdd1/decomp.hpp diff --git a/sfc/chip/sdd1/sdd1.cpp b/sfc/coprocessor/sdd1/sdd1.cpp similarity index 99% rename from sfc/chip/sdd1/sdd1.cpp rename to sfc/coprocessor/sdd1/sdd1.cpp index 05128926..ea3ea561 100644 --- a/sfc/chip/sdd1/sdd1.cpp +++ b/sfc/coprocessor/sdd1/sdd1.cpp @@ -1,6 +1,5 @@ #include -#define SDD1_CPP namespace SuperFamicom { SDD1 sdd1; diff --git a/sfc/chip/sdd1/sdd1.hpp b/sfc/coprocessor/sdd1/sdd1.hpp similarity index 100% rename from sfc/chip/sdd1/sdd1.hpp rename to sfc/coprocessor/sdd1/sdd1.hpp diff --git a/sfc/chip/sdd1/serialization.cpp b/sfc/coprocessor/sdd1/serialization.cpp similarity index 91% rename from sfc/chip/sdd1/serialization.cpp rename to sfc/coprocessor/sdd1/serialization.cpp index 725c34db..6290ece7 100644 --- a/sfc/chip/sdd1/serialization.cpp +++ b/sfc/coprocessor/sdd1/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SDD1_CPP - void SDD1::serialize(serializer& s) { s.array(ram.data(), ram.size()); @@ -13,5 +11,3 @@ void SDD1::serialize(serializer& s) { s.integer(dma[n].size); } } - -#endif diff --git a/sfc/chip/sharprtc/memory.cpp b/sfc/coprocessor/sharprtc/memory.cpp similarity index 100% rename from sfc/chip/sharprtc/memory.cpp rename to sfc/coprocessor/sharprtc/memory.cpp diff --git a/sfc/chip/sharprtc/serialization.cpp b/sfc/coprocessor/sharprtc/serialization.cpp similarity index 90% rename from sfc/chip/sharprtc/serialization.cpp rename to sfc/coprocessor/sharprtc/serialization.cpp index 802216d6..b30aed07 100644 --- a/sfc/chip/sharprtc/serialization.cpp +++ b/sfc/coprocessor/sharprtc/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SHARPRTC_CPP - void SharpRTC::serialize(serializer& s) { Thread::serialize(s); @@ -14,5 +12,3 @@ void SharpRTC::serialize(serializer& s) { s.integer(year); s.integer(weekday); } - -#endif diff --git a/sfc/chip/sharprtc/sharprtc.cpp b/sfc/coprocessor/sharprtc/sharprtc.cpp similarity index 99% rename from sfc/chip/sharprtc/sharprtc.cpp rename to sfc/coprocessor/sharprtc/sharprtc.cpp index b44e0261..1ab4cf4b 100644 --- a/sfc/chip/sharprtc/sharprtc.cpp +++ b/sfc/coprocessor/sharprtc/sharprtc.cpp @@ -1,6 +1,5 @@ #include -#define SHARPRTC_CPP namespace SuperFamicom { #include "memory.cpp" diff --git a/sfc/chip/sharprtc/sharprtc.hpp b/sfc/coprocessor/sharprtc/sharprtc.hpp similarity index 100% rename from sfc/chip/sharprtc/sharprtc.hpp rename to sfc/coprocessor/sharprtc/sharprtc.hpp diff --git a/sfc/chip/sharprtc/time.cpp b/sfc/coprocessor/sharprtc/time.cpp similarity index 100% rename from sfc/chip/sharprtc/time.cpp rename to sfc/coprocessor/sharprtc/time.cpp diff --git a/sfc/chip/spc7110/alu.cpp b/sfc/coprocessor/spc7110/alu.cpp similarity index 98% rename from sfc/chip/spc7110/alu.cpp rename to sfc/coprocessor/spc7110/alu.cpp index 68757d65..a3520548 100644 --- a/sfc/chip/spc7110/alu.cpp +++ b/sfc/coprocessor/spc7110/alu.cpp @@ -1,5 +1,3 @@ -#ifdef SPC7110_CPP - void SPC7110::alu_multiply() { add_clocks(30); @@ -83,5 +81,3 @@ void SPC7110::alu_divide() { r482f &= 0x7f; } - -#endif diff --git a/sfc/chip/spc7110/data.cpp b/sfc/coprocessor/spc7110/data.cpp similarity index 98% rename from sfc/chip/spc7110/data.cpp rename to sfc/coprocessor/spc7110/data.cpp index 5546a790..6a74921f 100644 --- a/sfc/chip/spc7110/data.cpp +++ b/sfc/coprocessor/spc7110/data.cpp @@ -1,5 +1,3 @@ -#ifdef SPC7110_CPP - uint8 SPC7110::datarom_read(unsigned addr) { unsigned size = 1 << (r4834 & 3); //size in MB unsigned mask = 0x100000 * size - 1; @@ -58,5 +56,3 @@ void SPC7110::data_port_increment_481a() { set_data_offset(offset + adjust); data_port_read(); } - -#endif diff --git a/sfc/chip/spc7110/dcu.cpp b/sfc/coprocessor/spc7110/dcu.cpp similarity index 100% rename from sfc/chip/spc7110/dcu.cpp rename to sfc/coprocessor/spc7110/dcu.cpp diff --git a/sfc/chip/spc7110/decompressor.cpp b/sfc/coprocessor/spc7110/decompressor.cpp similarity index 100% rename from sfc/chip/spc7110/decompressor.cpp rename to sfc/coprocessor/spc7110/decompressor.cpp diff --git a/sfc/chip/spc7110/serialization.cpp b/sfc/coprocessor/spc7110/serialization.cpp similarity index 97% rename from sfc/chip/spc7110/serialization.cpp rename to sfc/coprocessor/spc7110/serialization.cpp index f3c572ee..22c7fe80 100644 --- a/sfc/chip/spc7110/serialization.cpp +++ b/sfc/coprocessor/spc7110/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SPC7110_CPP - void SPC7110::serialize(serializer& s) { s.array(ram.data(), ram.size()); @@ -59,5 +57,3 @@ void SPC7110::serialize(serializer& s) { s.integer(r4833); s.integer(r4834); } - -#endif diff --git a/sfc/chip/spc7110/spc7110.cpp b/sfc/coprocessor/spc7110/spc7110.cpp similarity index 98% rename from sfc/chip/spc7110/spc7110.cpp rename to sfc/coprocessor/spc7110/spc7110.cpp index 3771c049..3888bfc4 100644 --- a/sfc/chip/spc7110/spc7110.cpp +++ b/sfc/coprocessor/spc7110/spc7110.cpp @@ -1,6 +1,5 @@ #include -#define SPC7110_CPP namespace SuperFamicom { #include "dcu.cpp" @@ -111,7 +110,7 @@ void SPC7110::reset() { } uint8 SPC7110::read(unsigned addr) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); if((addr & 0xff0000) == 0x500000) addr = 0x4800; addr = 0x4800 | (addr & 0x3f); @@ -200,7 +199,7 @@ uint8 SPC7110::read(unsigned addr) { } void SPC7110::write(unsigned addr, uint8 data) { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr = 0x4800 | (addr & 0x3f); switch(addr) { diff --git a/sfc/chip/spc7110/spc7110.hpp b/sfc/coprocessor/spc7110/spc7110.hpp similarity index 100% rename from sfc/chip/spc7110/spc7110.hpp rename to sfc/coprocessor/spc7110/spc7110.hpp diff --git a/sfc/chip/superfx/bus/bus.cpp b/sfc/coprocessor/superfx/bus/bus.cpp similarity index 96% rename from sfc/chip/superfx/bus/bus.cpp rename to sfc/coprocessor/superfx/bus/bus.cpp index d969a423..c7b8a5d0 100644 --- a/sfc/chip/superfx/bus/bus.cpp +++ b/sfc/coprocessor/superfx/bus/bus.cpp @@ -1,5 +1,3 @@ -#ifdef SUPERFX_CPP - //ROM / RAM access from the S-CPU auto SuperFX::CPUROM::size() const -> unsigned { @@ -33,5 +31,3 @@ auto SuperFX::CPURAM::read(unsigned addr) -> uint8 { auto SuperFX::CPURAM::write(unsigned addr, uint8 data) -> void { superfx.ram.write(addr, data); } - -#endif diff --git a/sfc/chip/superfx/bus/bus.hpp b/sfc/coprocessor/superfx/bus/bus.hpp similarity index 100% rename from sfc/chip/superfx/bus/bus.hpp rename to sfc/coprocessor/superfx/bus/bus.hpp diff --git a/sfc/chip/superfx/core/core.cpp b/sfc/coprocessor/superfx/core/core.cpp similarity index 99% rename from sfc/chip/superfx/core/core.cpp rename to sfc/coprocessor/superfx/core/core.cpp index 670aa25f..4ac528b3 100644 --- a/sfc/chip/superfx/core/core.cpp +++ b/sfc/coprocessor/superfx/core/core.cpp @@ -1,5 +1,3 @@ -#ifdef SUPERFX_CPP - auto SuperFX::stop() -> void { cpu.regs.irq = 1; } @@ -104,5 +102,3 @@ auto SuperFX::pixelcache_flush(pixelcache_t& cache) -> void { cache.bitpend = 0x00; } - -#endif diff --git a/sfc/chip/superfx/core/core.hpp b/sfc/coprocessor/superfx/core/core.hpp similarity index 100% rename from sfc/chip/superfx/core/core.hpp rename to sfc/coprocessor/superfx/core/core.hpp diff --git a/sfc/chip/superfx/disassembler/disassembler.cpp b/sfc/coprocessor/superfx/disassembler/disassembler.cpp similarity index 99% rename from sfc/chip/superfx/disassembler/disassembler.cpp rename to sfc/coprocessor/superfx/disassembler/disassembler.cpp index 49308fc2..562e2969 100644 --- a/sfc/chip/superfx/disassembler/disassembler.cpp +++ b/sfc/coprocessor/superfx/disassembler/disassembler.cpp @@ -1,5 +1,3 @@ -#ifdef SUPERFX_CPP - //TODO: this belongs in processor/gsu auto SuperFX::disassemble_opcode(char* output) -> void { @@ -277,5 +275,3 @@ auto SuperFX::disassemble_alt3(char* output) -> void { #undef op0 #undef op1 #undef op2 - -#endif diff --git a/sfc/chip/superfx/disassembler/disassembler.hpp b/sfc/coprocessor/superfx/disassembler/disassembler.hpp similarity index 100% rename from sfc/chip/superfx/disassembler/disassembler.hpp rename to sfc/coprocessor/superfx/disassembler/disassembler.hpp diff --git a/sfc/chip/superfx/memory/memory.cpp b/sfc/coprocessor/superfx/memory/memory.cpp similarity index 99% rename from sfc/chip/superfx/memory/memory.cpp rename to sfc/coprocessor/superfx/memory/memory.cpp index 83ba6214..3c7b6112 100644 --- a/sfc/chip/superfx/memory/memory.cpp +++ b/sfc/coprocessor/superfx/memory/memory.cpp @@ -1,5 +1,3 @@ -#ifdef SUPERFX_CPP - auto SuperFX::bus_read(unsigned addr) -> uint8 { if((addr & 0xc00000) == 0x000000) { //$00-3f:0000-7fff, $00-3f:8000-ffff while(!regs.scmr.ron && scheduler.sync != Scheduler::SynchronizeMode::All) { @@ -106,5 +104,3 @@ auto SuperFX::memory_reset() -> void { pixelcache[n].bitpend = 0x00; } } - -#endif diff --git a/sfc/chip/superfx/memory/memory.hpp b/sfc/coprocessor/superfx/memory/memory.hpp similarity index 100% rename from sfc/chip/superfx/memory/memory.hpp rename to sfc/coprocessor/superfx/memory/memory.hpp diff --git a/sfc/chip/superfx/mmio/mmio.cpp b/sfc/coprocessor/superfx/mmio/mmio.cpp similarity index 94% rename from sfc/chip/superfx/mmio/mmio.cpp rename to sfc/coprocessor/superfx/mmio/mmio.cpp index 920b44aa..dcff3197 100644 --- a/sfc/chip/superfx/mmio/mmio.cpp +++ b/sfc/coprocessor/superfx/mmio/mmio.cpp @@ -1,7 +1,5 @@ -#ifdef SUPERFX_CPP - auto SuperFX::mmio_read(unsigned addr) -> uint8 { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr &= 0xffff; if(addr >= 0x3100 && addr <= 0x32ff) { @@ -53,7 +51,7 @@ auto SuperFX::mmio_read(unsigned addr) -> uint8 { } auto SuperFX::mmio_write(unsigned addr, uint8 data) -> void { - cpu.synchronize_coprocessors(); + cpu.synchronizeCoprocessors(); addr &= 0xffff; if(addr >= 0x3100 && addr <= 0x32ff) { @@ -112,5 +110,3 @@ auto SuperFX::mmio_write(unsigned addr, uint8 data) -> void { } break; } } - -#endif diff --git a/sfc/chip/superfx/mmio/mmio.hpp b/sfc/coprocessor/superfx/mmio/mmio.hpp similarity index 100% rename from sfc/chip/superfx/mmio/mmio.hpp rename to sfc/coprocessor/superfx/mmio/mmio.hpp diff --git a/sfc/chip/superfx/serialization.cpp b/sfc/coprocessor/superfx/serialization.cpp similarity index 85% rename from sfc/chip/superfx/serialization.cpp rename to sfc/coprocessor/superfx/serialization.cpp index 6dda7da8..ad3ace66 100644 --- a/sfc/chip/superfx/serialization.cpp +++ b/sfc/coprocessor/superfx/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SUPERFX_CPP - auto SuperFX::serialize(serializer& s) -> void { GSU::serialize(s); Thread::serialize(s); @@ -7,5 +5,3 @@ auto SuperFX::serialize(serializer& s) -> void { s.array(ram.data(), ram.size()); s.integer(r15_modified); } - -#endif diff --git a/sfc/chip/superfx/superfx.cpp b/sfc/coprocessor/superfx/superfx.cpp similarity index 98% rename from sfc/chip/superfx/superfx.cpp rename to sfc/coprocessor/superfx/superfx.cpp index 176878a4..b31fb209 100644 --- a/sfc/chip/superfx/superfx.cpp +++ b/sfc/coprocessor/superfx/superfx.cpp @@ -1,6 +1,5 @@ #include -#define SUPERFX_CPP namespace SuperFamicom { #include "serialization.cpp" diff --git a/sfc/chip/superfx/superfx.hpp b/sfc/coprocessor/superfx/superfx.hpp similarity index 100% rename from sfc/chip/superfx/superfx.hpp rename to sfc/coprocessor/superfx/superfx.hpp diff --git a/sfc/chip/superfx/timing/timing.cpp b/sfc/coprocessor/superfx/timing/timing.cpp similarity index 98% rename from sfc/chip/superfx/timing/timing.cpp rename to sfc/coprocessor/superfx/timing/timing.cpp index 4fc8f8b2..48141eb4 100644 --- a/sfc/chip/superfx/timing/timing.cpp +++ b/sfc/coprocessor/superfx/timing/timing.cpp @@ -1,5 +1,3 @@ -#ifdef SUPERFX_CPP - auto SuperFX::step(unsigned clocks) -> void { if(regs.romcl) { regs.romcl -= min(clocks, regs.romcl); @@ -70,5 +68,3 @@ auto SuperFX::timing_reset() -> void { regs.ramar = 0; regs.ramdr = 0; } - -#endif diff --git a/sfc/chip/superfx/timing/timing.hpp b/sfc/coprocessor/superfx/timing/timing.hpp similarity index 100% rename from sfc/chip/superfx/timing/timing.hpp rename to sfc/coprocessor/superfx/timing/timing.hpp diff --git a/sfc/cpu/cpu.cpp b/sfc/cpu/cpu.cpp index e4a97103..aa8314c6 100644 --- a/sfc/cpu/cpu.cpp +++ b/sfc/cpu/cpu.cpp @@ -1,6 +1,5 @@ #include -#define CPU_CPP namespace SuperFamicom { CPU cpu; @@ -11,7 +10,11 @@ CPU cpu; #include "mmio/mmio.cpp" #include "timing/timing.cpp" -void CPU::step(unsigned clocks) { +CPU::CPU() { + PPUcounter::scanline = {&CPU::scanline, this}; +} + +auto CPU::step(uint clocks) -> void { smp.clock -= clocks * (uint64)smp.frequency; ppu.clock -= clocks; for(unsigned i = 0; i < coprocessors.size(); i++) { @@ -20,10 +23,10 @@ void CPU::step(unsigned clocks) { } device.controllerPort1->clock -= clocks * (uint64)device.controllerPort1->frequency; device.controllerPort2->clock -= clocks * (uint64)device.controllerPort2->frequency; - synchronize_controllers(); + synchronizeDevices(); } -void CPU::synchronize_smp() { +auto CPU::synchronizeSMP() -> void { if(SMP::Threaded == true) { if(smp.clock < 0) co_switch(smp.thread); } else { @@ -31,7 +34,7 @@ void CPU::synchronize_smp() { } } -void CPU::synchronize_ppu() { +auto CPU::synchronizePPU() -> void { if(PPU::Threaded == true) { if(ppu.clock < 0) co_switch(ppu.thread); } else { @@ -39,21 +42,21 @@ void CPU::synchronize_ppu() { } } -void CPU::synchronize_coprocessors() { +auto CPU::synchronizeCoprocessors() -> void { for(unsigned i = 0; i < coprocessors.size(); i++) { auto& chip = *coprocessors[i]; if(chip.clock < 0) co_switch(chip.thread); } } -void CPU::synchronize_controllers() { +auto CPU::synchronizeDevices() -> void { if(device.controllerPort1->clock < 0) co_switch(device.controllerPort1->thread); if(device.controllerPort2->clock < 0) co_switch(device.controllerPort2->thread); } -void CPU::Enter() { cpu.enter(); } +auto CPU::Enter() -> void { cpu.enter(); } -void CPU::enter() { +auto CPU::enter() -> void { while(true) { if(scheduler.sync == Scheduler::SynchronizeMode::CPU) { scheduler.sync = Scheduler::SynchronizeMode::All; @@ -84,14 +87,14 @@ void CPU::enter() { } } -void CPU::op_step() { +auto CPU::op_step() -> void { debugger.op_exec(regs.pc.d); op_exec(); } -void CPU::enable() { - function reader = {&CPU::mmio_read, (CPU*)&cpu}; - function writer = {&CPU::mmio_write, (CPU*)&cpu}; +auto CPU::enable() -> void { + function reader{&CPU::mmio_read, (CPU*)&cpu}; + function writer{&CPU::mmio_write, (CPU*)&cpu}; bus.map(reader, writer, 0x00, 0x3f, 0x2140, 0x2183); bus.map(reader, writer, 0x80, 0xbf, 0x2140, 0x2183); @@ -113,7 +116,7 @@ void CPU::enable() { bus.map(reader, writer, 0x7e, 0x7f, 0x0000, 0xffff, 0x020000); } -void CPU::power() { +auto CPU::power() -> void { for(auto& byte : wram) byte = random(0x55); regs.a = regs.x = regs.y = 0x0000; @@ -124,7 +127,7 @@ void CPU::power() { timing_power(); } -void CPU::reset() { +auto CPU::reset() -> void { create(Enter, system.cpuFrequency()); coprocessors.reset(); PPUcounter::reset(); @@ -147,11 +150,4 @@ void CPU::reset() { timing_reset(); } -CPU::CPU() { - PPUcounter::scanline = {&CPU::scanline, this}; -} - -CPU::~CPU() { -} - } diff --git a/sfc/cpu/cpu.hpp b/sfc/cpu/cpu.hpp index d4bb26f2..cf3ec2f0 100644 --- a/sfc/cpu/cpu.hpp +++ b/sfc/cpu/cpu.hpp @@ -1,32 +1,33 @@ struct CPU : Processor::R65816, Thread, public PPUcounter { - uint8 wram[128 * 1024]; - enum : bool { Threaded = true }; - vector coprocessors; - alwaysinline void step(unsigned clocks); - alwaysinline void synchronize_smp(); - void synchronize_ppu(); - void synchronize_coprocessors(); - void synchronize_controllers(); - uint8 port_read(uint2 port) const; - void port_write(uint2 port, uint8 data); - - uint8 pio(); - bool joylatch(); - alwaysinline bool interrupt_pending() { return status.interrupt_pending; } - - void enter(); - void enable(); - void power(); - void reset(); - - void serialize(serializer&); CPU(); - ~CPU(); + + alwaysinline auto step(uint clocks) -> void; + alwaysinline auto synchronizeSMP() -> void; + auto synchronizePPU() -> void; + auto synchronizeCoprocessors() -> void; + auto synchronizeDevices() -> void; + + auto portRead(uint2 port) const -> uint8; + auto portWrite(uint2 port, uint8 data) -> void; + + auto pio() -> uint8; + auto joylatch() -> bool; + alwaysinline auto interrupt_pending() -> bool { return status.interrupt_pending; } + + auto enter() -> void; + auto enable() -> void; + auto power() -> void; + auto reset() -> void; + + auto serialize(serializer&) -> void; + + uint8 wram[128 * 1024] = {0}; + vector coprocessors; privileged: - unsigned cpu_version = 2; //allowed: 1, 2 + uint cpu_version = 2; //allowed: 1, 2 #include "dma/dma.hpp" #include "memory/memory.hpp" @@ -36,19 +37,19 @@ privileged: struct Status { bool interrupt_pending; - unsigned clock_count; - unsigned line_clocks; + uint clock_count; + uint line_clocks; //timing bool irq_lock; - unsigned dram_refresh_position; + uint dram_refresh_position; bool dram_refreshed; - unsigned hdma_init_position; + uint hdma_init_position; bool hdma_init_triggered; - unsigned hdma_position; + uint hdma_position; bool hdma_triggered; bool nmi_valid; @@ -67,8 +68,8 @@ privileged: //DMA bool dma_active; - unsigned dma_counter; - unsigned dma_clocks; + uint dma_counter; + uint dma_clocks; bool dma_pending; bool hdma_pending; bool hdma_mode; //0 = init, 1 = run @@ -76,8 +77,8 @@ privileged: //auto joypad polling bool auto_joypad_active; bool auto_joypad_latch; - unsigned auto_joypad_counter; - unsigned auto_joypad_clock; + uint auto_joypad_counter; + uint auto_joypad_clock; //MMIO //$2140-217f @@ -112,7 +113,7 @@ privileged: uint9 virq_pos; //$420d - unsigned rom_speed; + uint rom_speed; //$4214-$4217 uint16 rddiv; @@ -126,13 +127,13 @@ privileged: } status; struct ALU { - unsigned mpyctr; - unsigned divctr; - unsigned shift; + uint mpyctr; + uint divctr; + uint shift; } alu; - static void Enter(); - void op_step(); + static auto Enter() -> void; + auto op_step() -> void; struct Debugger { hook op_exec; diff --git a/sfc/cpu/dma/dma.cpp b/sfc/cpu/dma/dma.cpp index 629fd0c0..42cf0668 100644 --- a/sfc/cpu/dma/dma.cpp +++ b/sfc/cpu/dma/dma.cpp @@ -1,6 +1,4 @@ -#ifdef CPU_CPP - -void CPU::dma_add_clocks(unsigned clocks) { +auto CPU::dma_add_clocks(uint clocks) -> void { status.dma_clocks += clocks; add_clocks(clocks); } @@ -9,13 +7,13 @@ void CPU::dma_add_clocks(unsigned clocks) { //memory access //============= -bool CPU::dma_transfer_valid(uint8 bbus, uint32 abus) { +auto CPU::dma_transfer_valid(uint8 bbus, uint32 abus) -> bool { //transfers from WRAM to WRAM are invalid; chip only has one address bus if(bbus == 0x80 && ((abus & 0xfe0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) return false; return true; } -bool CPU::dma_addr_valid(uint32 abus) { +auto CPU::dma_addr_valid(uint32 abus) -> bool { //A-bus access to B-bus or S-CPU registers are invalid if((abus & 0x40ff00) == 0x2100) return false; //$[00-3f|80-bf]:[2100-21ff] if((abus & 0x40fe00) == 0x4000) return false; //$[00-3f|80-bf]:[4000-41ff] @@ -24,7 +22,7 @@ bool CPU::dma_addr_valid(uint32 abus) { return true; } -uint8 CPU::dma_read(uint32 abus) { +auto CPU::dma_read(uint32 abus) -> uint8 { if(dma_addr_valid(abus) == false) return 0x00; return bus.read(abus); } @@ -34,14 +32,14 @@ uint8 CPU::dma_read(uint32 abus) { //cycle 1: write N+0 & read N+1 (parallel; one on A-bus, one on B-bus) //cycle 2: write N+1 & read N+2 (parallel) //cycle 3: write N+2 -void CPU::dma_write(bool valid, unsigned addr, uint8 data) { +auto CPU::dma_write(bool valid, uint addr, uint8 data) -> void { if(pipe.valid) bus.write(pipe.addr, pipe.data); pipe.valid = valid; pipe.addr = addr; pipe.data = data; } -void CPU::dma_transfer(bool direction, uint8 bbus, uint32 abus) { +auto CPU::dma_transfer(bool direction, uint8 bbus, uint32 abus) -> void { if(direction == 0) { dma_add_clocks(4); regs.mdr = dma_read(abus); @@ -59,7 +57,7 @@ void CPU::dma_transfer(bool direction, uint8 bbus, uint32 abus) { //address calculation //=================== -uint8 CPU::dma_bbus(unsigned i, unsigned index) { +auto CPU::dma_bbus(uint i, uint index) -> uint8 { switch(channel[i].transfer_mode) { default: case 0: return (channel[i].dest_addr); //0 case 1: return (channel[i].dest_addr + (index & 1)); //0,1 @@ -72,7 +70,7 @@ uint8 CPU::dma_bbus(unsigned i, unsigned index) { } } -inline uint32 CPU::dma_addr(unsigned i) { +inline auto CPU::dma_addr(uint i) -> uint32 { uint32 r = (channel[i].source_bank << 16) | (channel[i].source_addr); if(channel[i].fixed_transfer == false) { @@ -86,11 +84,11 @@ inline uint32 CPU::dma_addr(unsigned i) { return r; } -inline uint32 CPU::hdma_addr(unsigned i) { +inline auto CPU::hdma_addr(uint i) -> uint32 { return (channel[i].source_bank << 16) | (channel[i].hdma_addr++); } -inline uint32 CPU::hdma_iaddr(unsigned i) { +inline auto CPU::hdma_iaddr(uint i) -> uint32 { return (channel[i].indirect_bank << 16) | (channel[i].indirect_addr++); } @@ -98,36 +96,36 @@ inline uint32 CPU::hdma_iaddr(unsigned i) { //channel status //============== -uint8 CPU::dma_enabled_channels() { +auto CPU::dma_enabled_channels() -> uint8 { uint8 r = 0; - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(channel[i].dma_enabled) r++; } return r; } -inline bool CPU::hdma_active(unsigned i) { +inline auto CPU::hdma_active(uint i) -> bool { return (channel[i].hdma_enabled && !channel[i].hdma_completed); } -inline bool CPU::hdma_active_after(unsigned i) { - for(unsigned n = i + 1; n < 8; n++) { +inline auto CPU::hdma_active_after(uint i) -> bool { + for(uint n = i + 1; n < 8; n++) { if(hdma_active(n) == true) return true; } return false; } -inline uint8 CPU::hdma_enabled_channels() { +inline auto CPU::hdma_enabled_channels() -> uint8 { uint8 r = 0; - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(channel[i].hdma_enabled) r++; } return r; } -inline uint8 CPU::hdma_active_channels() { +inline auto CPU::hdma_active_channels() -> uint8 { uint8 r = 0; - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(hdma_active(i) == true) r++; } return r; @@ -137,15 +135,15 @@ inline uint8 CPU::hdma_active_channels() { //core functions //============== -void CPU::dma_run() { +auto CPU::dma_run() -> void { dma_add_clocks(8); dma_write(false); dma_edge(); - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(channel[i].dma_enabled == false) continue; - unsigned index = 0; + uint index = 0; do { dma_transfer(channel[i].direction, dma_bbus(i, index++), dma_addr(i)); dma_edge(); @@ -161,7 +159,7 @@ void CPU::dma_run() { status.irq_lock = true; } -void CPU::hdma_update(unsigned i) { +auto CPU::hdma_update(uint i) -> void { dma_add_clocks(4); regs.mdr = dma_read((channel[i].source_bank << 16) | channel[i].hdma_addr); dma_add_clocks(4); @@ -193,25 +191,25 @@ void CPU::hdma_update(unsigned i) { } } -void CPU::hdma_run() { +auto CPU::hdma_run() -> void { dma_add_clocks(8); dma_write(false); - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(hdma_active(i) == false) continue; channel[i].dma_enabled = false; //HDMA run during DMA will stop DMA mid-transfer if(channel[i].hdma_do_transfer) { - static const unsigned transfer_length[8] = { 1, 2, 2, 4, 4, 4, 2, 4 }; - unsigned length = transfer_length[channel[i].transfer_mode]; - for(unsigned index = 0; index < length; index++) { - unsigned addr = channel[i].indirect == false ? hdma_addr(i) : hdma_iaddr(i); + static const uint transfer_length[8] = {1, 2, 2, 4, 4, 4, 2, 4}; + uint length = transfer_length[channel[i].transfer_mode]; + for(uint index = 0; index < length; index++) { + uint addr = channel[i].indirect == false ? hdma_addr(i) : hdma_iaddr(i); dma_transfer(channel[i].direction, dma_bbus(i, index), addr); } } } - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(hdma_active(i) == false) continue; channel[i].line_counter--; @@ -222,18 +220,18 @@ void CPU::hdma_run() { status.irq_lock = true; } -void CPU::hdma_init_reset() { - for(unsigned i = 0; i < 8; i++) { +auto CPU::hdma_init_reset() -> void { + for(uint i = 0; i < 8; i++) { channel[i].hdma_completed = false; channel[i].hdma_do_transfer = false; } } -void CPU::hdma_init() { +auto CPU::hdma_init() -> void { dma_add_clocks(8); dma_write(false); - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { if(!channel[i].hdma_enabled) continue; channel[i].dma_enabled = false; //HDMA init during DMA will stop DMA mid-transfer @@ -249,8 +247,8 @@ void CPU::hdma_init() { //initialization //============== -void CPU::dma_power() { - for(unsigned i = 0; i < 8; i++) { +auto CPU::dma_power() -> void { + for(uint i = 0; i < 8; i++) { channel[i].direction = 1; channel[i].indirect = true; channel[i].unused = true; @@ -272,8 +270,8 @@ void CPU::dma_power() { } } -void CPU::dma_reset() { - for(unsigned i = 0; i < 8; i++) { +auto CPU::dma_reset() -> void { + for(uint i = 0; i < 8; i++) { channel[i].dma_enabled = false; channel[i].hdma_enabled = false; @@ -285,5 +283,3 @@ void CPU::dma_reset() { pipe.addr = 0; pipe.data = 0; } - -#endif diff --git a/sfc/cpu/dma/dma.hpp b/sfc/cpu/dma/dma.hpp index 33755bde..4a04f672 100644 --- a/sfc/cpu/dma/dma.hpp +++ b/sfc/cpu/dma/dma.hpp @@ -47,33 +47,33 @@ struct { struct { bool valid; - unsigned addr; + uint addr; uint8 data; } pipe; -void dma_add_clocks(unsigned clocks); -bool dma_transfer_valid(uint8 bbus, uint32 abus); -bool dma_addr_valid(uint32 abus); -uint8 dma_read(uint32 abus); -void dma_write(bool valid, unsigned addr = 0, uint8 data = 0); -void dma_transfer(bool direction, uint8 bbus, uint32 abus); +auto dma_add_clocks(uint clocks) -> void; +auto dma_transfer_valid(uint8 bbus, uint32 abus) -> bool; +auto dma_addr_valid(uint32 abus) -> bool; +auto dma_read(uint32 abus) -> uint8; +auto dma_write(bool valid, uint addr = 0, uint8 data = 0) -> void; +auto dma_transfer(bool direction, uint8 bbus, uint32 abus) -> void; -uint8 dma_bbus(unsigned i, unsigned channel); -uint32 dma_addr(unsigned i); -uint32 hdma_addr(unsigned i); -uint32 hdma_iaddr(unsigned i); +auto dma_bbus(uint i, uint channel) -> uint8; +auto dma_addr(uint i) -> uint32; +auto hdma_addr(uint i) -> uint32; +auto hdma_iaddr(uint i) -> uint32; -uint8 dma_enabled_channels(); -bool hdma_active(unsigned i); -bool hdma_active_after(unsigned i); -uint8 hdma_enabled_channels(); -uint8 hdma_active_channels(); +auto dma_enabled_channels() -> uint8; +auto hdma_active(uint i) -> bool; +auto hdma_active_after(uint i) -> bool; +auto hdma_enabled_channels() -> uint8; +auto hdma_active_channels() -> uint8; -void dma_run(); -void hdma_update(unsigned i); -void hdma_run(); -void hdma_init_reset(); -void hdma_init(); +auto dma_run() -> void; +auto hdma_update(uint i) -> void; +auto hdma_run() -> void; +auto hdma_init_reset() -> void; +auto hdma_init() -> void; -void dma_power(); -void dma_reset(); +auto dma_power() -> void; +auto dma_reset() -> void; diff --git a/sfc/cpu/memory/memory.cpp b/sfc/cpu/memory/memory.cpp index 97aa6bb9..b2b8c0d9 100644 --- a/sfc/cpu/memory/memory.cpp +++ b/sfc/cpu/memory/memory.cpp @@ -1,16 +1,19 @@ -#ifdef CPU_CPP +auto CPU::portRead(uint2 port) const -> uint8 { + return status.port[port]; +} -uint8 CPU::port_read(uint2 port) const { return status.port[port]; } -void CPU::port_write(uint2 port, uint8 data) { status.port[port] = data; } +auto CPU::portWrite(uint2 port, uint8 data) -> void { + status.port[port] = data; +} -void CPU::op_io() { +auto CPU::op_io() -> void { status.clock_count = 6; dma_edge(); add_clocks(6); alu_edge(); } -uint8 CPU::op_read(uint32 addr) { +auto CPU::op_read(uint32 addr) -> uint8 { status.clock_count = speed(addr); dma_edge(); add_clocks(status.clock_count - 4); @@ -21,7 +24,7 @@ uint8 CPU::op_read(uint32 addr) { return regs.mdr; } -void CPU::op_write(uint32 addr, uint8 data) { +auto CPU::op_write(uint32 addr, uint8 data) -> void { alu_edge(); status.clock_count = speed(addr); dma_edge(); @@ -30,7 +33,7 @@ void CPU::op_write(uint32 addr, uint8 data) { debugger.op_write(addr, regs.mdr); } -unsigned CPU::speed(unsigned addr) const { +auto CPU::speed(uint addr) const -> uint { if(addr & 0x408000) { if(addr & 0x800000) return status.rom_speed; return 8; @@ -40,8 +43,6 @@ unsigned CPU::speed(unsigned addr) const { return 12; } -uint8 CPU::disassembler_read(uint32 addr) { +auto CPU::disassembler_read(uint32 addr) -> uint8 { return bus.read(addr); } - -#endif diff --git a/sfc/cpu/memory/memory.hpp b/sfc/cpu/memory/memory.hpp index aacd2c5a..b21e1f63 100644 --- a/sfc/cpu/memory/memory.hpp +++ b/sfc/cpu/memory/memory.hpp @@ -1,6 +1,6 @@ -void op_io(); -uint8 op_read(uint32 addr); -void op_write(uint32 addr, uint8 data); -alwaysinline unsigned speed(unsigned addr) const; +auto op_io() -> void; +auto op_read(uint32 addr) -> uint8; +auto op_write(uint32 addr, uint8 data) -> void; +alwaysinline auto speed(uint addr) const -> uint; -uint8 disassembler_read(uint32 addr); +auto disassembler_read(uint32 addr) -> uint8; diff --git a/sfc/cpu/mmio/mmio.cpp b/sfc/cpu/mmio/mmio.cpp index c7b47b90..4372c281 100644 --- a/sfc/cpu/mmio/mmio.cpp +++ b/sfc/cpu/mmio/mmio.cpp @@ -1,30 +1,33 @@ -#ifdef CPU_CPP +auto CPU::pio() -> uint8 { + return status.pio; +} -uint8 CPU::pio() { return status.pio; } -bool CPU::joylatch() { return status.joypad_strobe_latch; } +auto CPU::joylatch() -> bool { + return status.joypad_strobe_latch; +} //WMDATA -uint8 CPU::mmio_r2180() { +auto CPU::mmio_r2180() -> uint8 { return bus.read(0x7e0000 | status.wram_addr++); } //WMDATA -void CPU::mmio_w2180(uint8 data) { +auto CPU::mmio_w2180(uint8 data) -> void { bus.write(0x7e0000 | status.wram_addr++, data); } //WMADDL -void CPU::mmio_w2181(uint8 data) { +auto CPU::mmio_w2181(uint8 data) -> void { status.wram_addr = (status.wram_addr & 0x01ff00) | (data << 0); } //WMADDM -void CPU::mmio_w2182(uint8 data) { +auto CPU::mmio_w2182(uint8 data) -> void { status.wram_addr = (status.wram_addr & 0x0100ff) | (data << 8); } //WMADDH -void CPU::mmio_w2183(uint8 data) { +auto CPU::mmio_w2183(uint8 data) -> void { status.wram_addr = (status.wram_addr & 0x00ffff) | (data << 16); } @@ -32,7 +35,7 @@ void CPU::mmio_w2183(uint8 data) { //bit 0 is shared between JOYSER0 and JOYSER1, therefore //strobing $4016.d0 affects both controller port latches. //$4017 bit 0 writes are ignored. -void CPU::mmio_w4016(uint8 data) { +auto CPU::mmio_w4016(uint8 data) -> void { device.controllerPort1->latch(data & 1); device.controllerPort2->latch(data & 1); } @@ -40,7 +43,7 @@ void CPU::mmio_w4016(uint8 data) { //JOYSER0 //7-2 = MDR //1-0 = Joypad serial data -uint8 CPU::mmio_r4016() { +auto CPU::mmio_r4016() -> uint8 { uint8 r = regs.mdr & 0xfc; r |= device.controllerPort1->data(); return r; @@ -50,31 +53,31 @@ uint8 CPU::mmio_r4016() { //7-5 = MDR //4-2 = Always 1 (pins are connected to GND) //1-0 = Joypad serial data -uint8 CPU::mmio_r4017() { +auto CPU::mmio_r4017() -> uint8 { uint8 r = (regs.mdr & 0xe0) | 0x1c; r |= device.controllerPort2->data(); return r; } //NMITIMEN -void CPU::mmio_w4200(uint8 data) { +auto CPU::mmio_w4200(uint8 data) -> void { status.auto_joypad_poll = data & 1; nmitimen_update(data); } //WRIO -void CPU::mmio_w4201(uint8 data) { +auto CPU::mmio_w4201(uint8 data) -> void { if((status.pio & 0x80) && !(data & 0x80)) ppu.latch_counters(); status.pio = data; } //WRMPYA -void CPU::mmio_w4202(uint8 data) { +auto CPU::mmio_w4202(uint8 data) -> void { status.wrmpya = data; } //WRMPYB -void CPU::mmio_w4203(uint8 data) { +auto CPU::mmio_w4203(uint8 data) -> void { status.rdmpy = 0; if(alu.mpyctr || alu.divctr) return; @@ -86,17 +89,17 @@ void CPU::mmio_w4203(uint8 data) { } //WRDIVL -void CPU::mmio_w4204(uint8 data) { +auto CPU::mmio_w4204(uint8 data) -> void { status.wrdiva = (status.wrdiva & 0xff00) | (data << 0); } //WRDIVH -void CPU::mmio_w4205(uint8 data) { +auto CPU::mmio_w4205(uint8 data) -> void { status.wrdiva = (status.wrdiva & 0x00ff) | (data << 8); } //WRDIVB -void CPU::mmio_w4206(uint8 data) { +auto CPU::mmio_w4206(uint8 data) -> void { status.rdmpy = status.wrdiva; if(alu.mpyctr || alu.divctr) return; @@ -107,27 +110,27 @@ void CPU::mmio_w4206(uint8 data) { } //HTIMEL -void CPU::mmio_w4207(uint8 data) { +auto CPU::mmio_w4207(uint8 data) -> void { status.hirq_pos = (status.hirq_pos & 0x0100) | (data << 0); } //HTIMEH -void CPU::mmio_w4208(uint8 data) { +auto CPU::mmio_w4208(uint8 data) -> void { status.hirq_pos = (status.hirq_pos & 0x00ff) | (data << 8); } //VTIMEL -void CPU::mmio_w4209(uint8 data) { +auto CPU::mmio_w4209(uint8 data) -> void { status.virq_pos = (status.virq_pos & 0x0100) | (data << 0); } //VTIMEH -void CPU::mmio_w420a(uint8 data) { +auto CPU::mmio_w420a(uint8 data) -> void { status.virq_pos = (status.virq_pos & 0x00ff) | (data << 8); } //DMAEN -void CPU::mmio_w420b(uint8 data) { +auto CPU::mmio_w420b(uint8 data) -> void { for(unsigned i = 0; i < 8; i++) { channel[i].dma_enabled = data & (1 << i); } @@ -135,14 +138,14 @@ void CPU::mmio_w420b(uint8 data) { } //HDMAEN -void CPU::mmio_w420c(uint8 data) { +auto CPU::mmio_w420c(uint8 data) -> void { for(unsigned i = 0; i < 8; i++) { channel[i].hdma_enabled = data & (1 << i); } } //MEMSEL -void CPU::mmio_w420d(uint8 data) { +auto CPU::mmio_w420d(uint8 data) -> void { status.rom_speed = (data & 1 ? 6 : 8); } @@ -150,7 +153,7 @@ void CPU::mmio_w420d(uint8 data) { //7 = NMI acknowledge //6-4 = MDR //3-0 = CPU (5a22) version -uint8 CPU::mmio_r4210() { +auto CPU::mmio_r4210() -> uint8 { uint8 r = (regs.mdr & 0x70); r |= (uint8)(rdnmi()) << 7; r |= (cpu_version & 0x0f); @@ -160,7 +163,7 @@ uint8 CPU::mmio_r4210() { //TIMEUP //7 = IRQ acknowledge //6-0 = MDR -uint8 CPU::mmio_r4211() { +auto CPU::mmio_r4211() -> uint8 { uint8 r = (regs.mdr & 0x7f); r |= (uint8)(timeup()) << 7; return r; @@ -171,7 +174,7 @@ uint8 CPU::mmio_r4211() { //6 = HBLANK acknowledge //5-1 = MDR //0 = JOYPAD acknowledge -uint8 CPU::mmio_r4212() { +auto CPU::mmio_r4212() -> uint8 { uint8 r = (regs.mdr & 0x3e); if(status.auto_joypad_active) r |= 0x01; if(hcounter() <= 2 || hcounter() >= 1096) r |= 0x40; //hblank @@ -180,41 +183,41 @@ uint8 CPU::mmio_r4212() { } //RDIO -uint8 CPU::mmio_r4213() { +auto CPU::mmio_r4213() -> uint8 { return status.pio; } //RDDIVL -uint8 CPU::mmio_r4214() { +auto CPU::mmio_r4214() -> uint8 { return status.rddiv >> 0; } //RDDIVH -uint8 CPU::mmio_r4215() { +auto CPU::mmio_r4215() -> uint8 { return status.rddiv >> 8; } //RDMPYL -uint8 CPU::mmio_r4216() { +auto CPU::mmio_r4216() -> uint8 { return status.rdmpy >> 0; } //RDMPYH -uint8 CPU::mmio_r4217() { +auto CPU::mmio_r4217() -> uint8 { return status.rdmpy >> 8; } -uint8 CPU::mmio_r4218() { return status.joy1 >> 0; } //JOY1L -uint8 CPU::mmio_r4219() { return status.joy1 >> 8; } //JOY1H -uint8 CPU::mmio_r421a() { return status.joy2 >> 0; } //JOY2L -uint8 CPU::mmio_r421b() { return status.joy2 >> 8; } //JOY2H -uint8 CPU::mmio_r421c() { return status.joy3 >> 0; } //JOY3L -uint8 CPU::mmio_r421d() { return status.joy3 >> 8; } //JOY3H -uint8 CPU::mmio_r421e() { return status.joy4 >> 0; } //JOY4L -uint8 CPU::mmio_r421f() { return status.joy4 >> 8; } //JOY4H +auto CPU::mmio_r4218() -> uint8 { return status.joy1 >> 0; } //JOY1L +auto CPU::mmio_r4219() -> uint8 { return status.joy1 >> 8; } //JOY1H +auto CPU::mmio_r421a() -> uint8 { return status.joy2 >> 0; } //JOY2L +auto CPU::mmio_r421b() -> uint8 { return status.joy2 >> 8; } //JOY2H +auto CPU::mmio_r421c() -> uint8 { return status.joy3 >> 0; } //JOY3L +auto CPU::mmio_r421d() -> uint8 { return status.joy3 >> 8; } //JOY3H +auto CPU::mmio_r421e() -> uint8 { return status.joy4 >> 0; } //JOY4L +auto CPU::mmio_r421f() -> uint8 { return status.joy4 >> 8; } //JOY4H //DMAPx -uint8 CPU::mmio_r43x0(uint8 i) { +auto CPU::mmio_r43x0(uint8 i) -> uint8 { return (channel[i].direction << 7) | (channel[i].indirect << 6) | (channel[i].unused << 5) @@ -224,64 +227,64 @@ uint8 CPU::mmio_r43x0(uint8 i) { } //BBADx -uint8 CPU::mmio_r43x1(uint8 i) { +auto CPU::mmio_r43x1(uint8 i) -> uint8 { return channel[i].dest_addr; } //A1TxL -uint8 CPU::mmio_r43x2(uint8 i) { +auto CPU::mmio_r43x2(uint8 i) -> uint8 { return channel[i].source_addr >> 0; } //A1TxH -uint8 CPU::mmio_r43x3(uint8 i) { +auto CPU::mmio_r43x3(uint8 i) -> uint8 { return channel[i].source_addr >> 8; } //A1Bx -uint8 CPU::mmio_r43x4(uint8 i) { +auto CPU::mmio_r43x4(uint8 i) -> uint8 { return channel[i].source_bank; } //DASxL //union { uint16 transfer_size; uint16 indirect_addr; }; -uint8 CPU::mmio_r43x5(uint8 i) { +auto CPU::mmio_r43x5(uint8 i) -> uint8 { return channel[i].transfer_size >> 0; } //DASxH //union { uint16 transfer_size; uint16 indirect_addr; }; -uint8 CPU::mmio_r43x6(uint8 i) { +auto CPU::mmio_r43x6(uint8 i) -> uint8 { return channel[i].transfer_size >> 8; } //DASBx -uint8 CPU::mmio_r43x7(uint8 i) { +auto CPU::mmio_r43x7(uint8 i) -> uint8 { return channel[i].indirect_bank; } //A2AxL -uint8 CPU::mmio_r43x8(uint8 i) { +auto CPU::mmio_r43x8(uint8 i) -> uint8 { return channel[i].hdma_addr >> 0; } //A2AxH -uint8 CPU::mmio_r43x9(uint8 i) { +auto CPU::mmio_r43x9(uint8 i) -> uint8 { return channel[i].hdma_addr >> 8; } //NTRLx -uint8 CPU::mmio_r43xa(uint8 i) { +auto CPU::mmio_r43xa(uint8 i) -> uint8 { return channel[i].line_counter; } //??? -uint8 CPU::mmio_r43xb(uint8 i) { +auto CPU::mmio_r43xb(uint8 i) -> uint8 { return channel[i].unknown; } //DMAPx -void CPU::mmio_w43x0(uint8 i, uint8 data) { +auto CPU::mmio_w43x0(uint8 i, uint8 data) -> void { channel[i].direction = data & 0x80; channel[i].indirect = data & 0x40; channel[i].unused = data & 0x20; @@ -291,66 +294,66 @@ void CPU::mmio_w43x0(uint8 i, uint8 data) { } //DDBADx -void CPU::mmio_w43x1(uint8 i, uint8 data) { +auto CPU::mmio_w43x1(uint8 i, uint8 data) -> void { channel[i].dest_addr = data; } //A1TxL -void CPU::mmio_w43x2(uint8 i, uint8 data) { +auto CPU::mmio_w43x2(uint8 i, uint8 data) -> void { channel[i].source_addr = (channel[i].source_addr & 0xff00) | (data << 0); } //A1TxH -void CPU::mmio_w43x3(uint8 i, uint8 data) { +auto CPU::mmio_w43x3(uint8 i, uint8 data) -> void { channel[i].source_addr = (channel[i].source_addr & 0x00ff) | (data << 8); } //A1Bx -void CPU::mmio_w43x4(uint8 i, uint8 data) { +auto CPU::mmio_w43x4(uint8 i, uint8 data) -> void { channel[i].source_bank = data; } //DASxL //union { uint16 transfer_size; uint16 indirect_addr; }; -void CPU::mmio_w43x5(uint8 i, uint8 data) { +auto CPU::mmio_w43x5(uint8 i, uint8 data) -> void { channel[i].transfer_size = (channel[i].transfer_size & 0xff00) | (data << 0); } //DASxH //union { uint16 transfer_size; uint16 indirect_addr; }; -void CPU::mmio_w43x6(uint8 i, uint8 data) { +auto CPU::mmio_w43x6(uint8 i, uint8 data) -> void { channel[i].transfer_size = (channel[i].transfer_size & 0x00ff) | (data << 8); } //DASBx -void CPU::mmio_w43x7(uint8 i, uint8 data) { +auto CPU::mmio_w43x7(uint8 i, uint8 data) -> void { channel[i].indirect_bank = data; } //A2AxL -void CPU::mmio_w43x8(uint8 i, uint8 data) { +auto CPU::mmio_w43x8(uint8 i, uint8 data) -> void { channel[i].hdma_addr = (channel[i].hdma_addr & 0xff00) | (data << 0); } //A2AxH -void CPU::mmio_w43x9(uint8 i, uint8 data) { +auto CPU::mmio_w43x9(uint8 i, uint8 data) -> void { channel[i].hdma_addr = (channel[i].hdma_addr & 0x00ff) | (data << 8); } //NTRLx -void CPU::mmio_w43xa(uint8 i, uint8 data) { +auto CPU::mmio_w43xa(uint8 i, uint8 data) -> void { channel[i].line_counter = data; } //??? -void CPU::mmio_w43xb(uint8 i, uint8 data) { +auto CPU::mmio_w43xb(uint8 i, uint8 data) -> void { channel[i].unknown = data; } -void CPU::mmio_power() { +auto CPU::mmio_power() -> void { } -void CPU::mmio_reset() { +auto CPU::mmio_reset() -> void { //$2140-217f for(auto& port : status.port) port = 0x00; @@ -402,12 +405,12 @@ void CPU::mmio_reset() { alu.shift = 0; } -uint8 CPU::mmio_read(unsigned addr) { +auto CPU::mmio_read(uint addr) -> uint8 { addr &= 0xffff; //APU if((addr & 0xffc0) == 0x2140) { //$2140-$217f - synchronize_smp(); + synchronizeSMP(); return smp.portRead(addr); } @@ -459,13 +462,13 @@ uint8 CPU::mmio_read(unsigned addr) { return regs.mdr; } -void CPU::mmio_write(unsigned addr, uint8 data) { +auto CPU::mmio_write(uint addr, uint8 data) -> void { addr &= 0xffff; //APU if((addr & 0xffc0) == 0x2140) { //$2140-$217f - synchronize_smp(); - port_write(addr, data); + synchronizeSMP(); + portWrite(addr, data); return; } @@ -515,5 +518,3 @@ void CPU::mmio_write(unsigned addr, uint8 data) { case 0x420d: mmio_w420d(data); return; } } - -#endif diff --git a/sfc/cpu/mmio/mmio.hpp b/sfc/cpu/mmio/mmio.hpp index f2cd7712..e1f94b6e 100644 --- a/sfc/cpu/mmio/mmio.hpp +++ b/sfc/cpu/mmio/mmio.hpp @@ -1,71 +1,71 @@ public: -uint8 mmio_read(unsigned addr); -void mmio_write(unsigned addr, uint8 data); +auto mmio_read(uint addr) -> uint8; +auto mmio_write(uint addr, uint8 data) -> void; privileged: -void mmio_power(); -void mmio_reset(); +auto mmio_power() -> void; +auto mmio_reset() -> void; -uint8 mmio_r2180(); -uint8 mmio_r4016(); -uint8 mmio_r4017(); -uint8 mmio_r4210(); -uint8 mmio_r4211(); -uint8 mmio_r4212(); -uint8 mmio_r4213(); -uint8 mmio_r4214(); -uint8 mmio_r4215(); -uint8 mmio_r4216(); -uint8 mmio_r4217(); -uint8 mmio_r4218(); -uint8 mmio_r4219(); -uint8 mmio_r421a(); -uint8 mmio_r421b(); -uint8 mmio_r421c(); -uint8 mmio_r421d(); -uint8 mmio_r421e(); -uint8 mmio_r421f(); -uint8 mmio_r43x0(uint8 i); -uint8 mmio_r43x1(uint8 i); -uint8 mmio_r43x2(uint8 i); -uint8 mmio_r43x3(uint8 i); -uint8 mmio_r43x4(uint8 i); -uint8 mmio_r43x5(uint8 i); -uint8 mmio_r43x6(uint8 i); -uint8 mmio_r43x7(uint8 i); -uint8 mmio_r43x8(uint8 i); -uint8 mmio_r43x9(uint8 i); -uint8 mmio_r43xa(uint8 i); -uint8 mmio_r43xb(uint8 i); +auto mmio_r2180() -> uint8; +auto mmio_r4016() -> uint8; +auto mmio_r4017() -> uint8; +auto mmio_r4210() -> uint8; +auto mmio_r4211() -> uint8; +auto mmio_r4212() -> uint8; +auto mmio_r4213() -> uint8; +auto mmio_r4214() -> uint8; +auto mmio_r4215() -> uint8; +auto mmio_r4216() -> uint8; +auto mmio_r4217() -> uint8; +auto mmio_r4218() -> uint8; +auto mmio_r4219() -> uint8; +auto mmio_r421a() -> uint8; +auto mmio_r421b() -> uint8; +auto mmio_r421c() -> uint8; +auto mmio_r421d() -> uint8; +auto mmio_r421e() -> uint8; +auto mmio_r421f() -> uint8; +auto mmio_r43x0(uint8 i) -> uint8; +auto mmio_r43x1(uint8 i) -> uint8; +auto mmio_r43x2(uint8 i) -> uint8; +auto mmio_r43x3(uint8 i) -> uint8; +auto mmio_r43x4(uint8 i) -> uint8; +auto mmio_r43x5(uint8 i) -> uint8; +auto mmio_r43x6(uint8 i) -> uint8; +auto mmio_r43x7(uint8 i) -> uint8; +auto mmio_r43x8(uint8 i) -> uint8; +auto mmio_r43x9(uint8 i) -> uint8; +auto mmio_r43xa(uint8 i) -> uint8; +auto mmio_r43xb(uint8 i) -> uint8; -void mmio_w2180(uint8 data); -void mmio_w2181(uint8 data); -void mmio_w2182(uint8 data); -void mmio_w2183(uint8 data); -void mmio_w4016(uint8 data); -void mmio_w4200(uint8 data); -void mmio_w4201(uint8 data); -void mmio_w4202(uint8 data); -void mmio_w4203(uint8 data); -void mmio_w4204(uint8 data); -void mmio_w4205(uint8 data); -void mmio_w4206(uint8 data); -void mmio_w4207(uint8 data); -void mmio_w4208(uint8 data); -void mmio_w4209(uint8 data); -void mmio_w420a(uint8 data); -void mmio_w420b(uint8 data); -void mmio_w420c(uint8 data); -void mmio_w420d(uint8 data); -void mmio_w43x0(uint8 i, uint8 data); -void mmio_w43x1(uint8 i, uint8 data); -void mmio_w43x2(uint8 i, uint8 data); -void mmio_w43x3(uint8 i, uint8 data); -void mmio_w43x4(uint8 i, uint8 data); -void mmio_w43x5(uint8 i, uint8 data); -void mmio_w43x6(uint8 i, uint8 data); -void mmio_w43x7(uint8 i, uint8 data); -void mmio_w43x8(uint8 i, uint8 data); -void mmio_w43x9(uint8 i, uint8 data); -void mmio_w43xa(uint8 i, uint8 data); -void mmio_w43xb(uint8 i, uint8 data); +auto mmio_w2180(uint8 data) -> void; +auto mmio_w2181(uint8 data) -> void; +auto mmio_w2182(uint8 data) -> void; +auto mmio_w2183(uint8 data) -> void; +auto mmio_w4016(uint8 data) -> void; +auto mmio_w4200(uint8 data) -> void; +auto mmio_w4201(uint8 data) -> void; +auto mmio_w4202(uint8 data) -> void; +auto mmio_w4203(uint8 data) -> void; +auto mmio_w4204(uint8 data) -> void; +auto mmio_w4205(uint8 data) -> void; +auto mmio_w4206(uint8 data) -> void; +auto mmio_w4207(uint8 data) -> void; +auto mmio_w4208(uint8 data) -> void; +auto mmio_w4209(uint8 data) -> void; +auto mmio_w420a(uint8 data) -> void; +auto mmio_w420b(uint8 data) -> void; +auto mmio_w420c(uint8 data) -> void; +auto mmio_w420d(uint8 data) -> void; +auto mmio_w43x0(uint8 i, uint8 data) -> void; +auto mmio_w43x1(uint8 i, uint8 data) -> void; +auto mmio_w43x2(uint8 i, uint8 data) -> void; +auto mmio_w43x3(uint8 i, uint8 data) -> void; +auto mmio_w43x4(uint8 i, uint8 data) -> void; +auto mmio_w43x5(uint8 i, uint8 data) -> void; +auto mmio_w43x6(uint8 i, uint8 data) -> void; +auto mmio_w43x7(uint8 i, uint8 data) -> void; +auto mmio_w43x8(uint8 i, uint8 data) -> void; +auto mmio_w43x9(uint8 i, uint8 data) -> void; +auto mmio_w43xa(uint8 i, uint8 data) -> void; +auto mmio_w43xb(uint8 i, uint8 data) -> void; diff --git a/sfc/cpu/serialization.cpp b/sfc/cpu/serialization.cpp index 14aafd78..e0d49192 100644 --- a/sfc/cpu/serialization.cpp +++ b/sfc/cpu/serialization.cpp @@ -1,6 +1,4 @@ -#ifdef CPU_CPP - -void CPU::serialize(serializer& s) { +auto CPU::serialize(serializer& s) -> void { R65816::serialize(s); Thread::serialize(s); PPUcounter::serialize(s); @@ -89,7 +87,7 @@ void CPU::serialize(serializer& s) { s.integer(alu.divctr); s.integer(alu.shift); - for(unsigned i = 0; i < 8; i++) { + for(uint i = 0; i < 8; i++) { s.integer(channel[i].dma_enabled); s.integer(channel[i].hdma_enabled); s.integer(channel[i].direction); @@ -114,5 +112,3 @@ void CPU::serialize(serializer& s) { s.integer(pipe.addr); s.integer(pipe.data); } - -#endif diff --git a/sfc/cpu/timing/irq.cpp b/sfc/cpu/timing/irq.cpp index 506a435e..f47b0326 100644 --- a/sfc/cpu/timing/irq.cpp +++ b/sfc/cpu/timing/irq.cpp @@ -1,11 +1,9 @@ -#ifdef CPU_CPP - //called once every four clock cycles; //as NMI steps by scanlines (divisible by 4) and IRQ by PPU 4-cycle dots. // //ppu.(vh)counter(n) returns the value of said counters n-clocks before current time; //it is used to emulate hardware communication delay between opcode and interrupt units. -void CPU::poll_interrupts() { +auto CPU::poll_interrupts() -> void { //NMI hold if(status.nmi_hold) { status.nmi_hold = false; @@ -46,7 +44,7 @@ void CPU::poll_interrupts() { status.irq_valid = irq_valid; } -void CPU::nmitimen_update(uint8 data) { +auto CPU::nmitimen_update(uint8 data) -> void { bool nmi_enabled = status.nmi_enabled; bool virq_enabled = status.virq_enabled; bool hirq_enabled = status.hirq_enabled; @@ -72,7 +70,7 @@ void CPU::nmitimen_update(uint8 data) { status.irq_lock = true; } -bool CPU::rdnmi() { +auto CPU::rdnmi() -> bool { bool result = status.nmi_line; if(!status.nmi_hold) { status.nmi_line = false; @@ -80,7 +78,7 @@ bool CPU::rdnmi() { return result; } -bool CPU::timeup() { +auto CPU::timeup() -> bool { bool result = status.irq_line; if(!status.irq_hold) { status.irq_line = false; @@ -89,18 +87,16 @@ bool CPU::timeup() { return result; } -bool CPU::nmi_test() { +auto CPU::nmi_test() -> bool { if(!status.nmi_transition) return false; status.nmi_transition = false; regs.wai = false; return true; } -bool CPU::irq_test() { +auto CPU::irq_test() -> bool { if(!status.irq_transition && !regs.irq) return false; status.irq_transition = false; regs.wai = false; return !regs.p.i; } - -#endif diff --git a/sfc/cpu/timing/joypad.cpp b/sfc/cpu/timing/joypad.cpp index ef0cdd44..0abf7afc 100644 --- a/sfc/cpu/timing/joypad.cpp +++ b/sfc/cpu/timing/joypad.cpp @@ -1,7 +1,5 @@ -#ifdef CPU_CPP - //called every 256 clocks; see CPU::add_clocks() -void CPU::step_auto_joypad_poll() { +auto CPU::step_auto_joypad_poll() -> void { if(vcounter() >= (ppu.overscan() == false ? 225 : 240)) { //cache enable state at first iteration if(status.auto_joypad_counter == 0) status.auto_joypad_latch = status.auto_joypad_poll; @@ -27,5 +25,3 @@ void CPU::step_auto_joypad_poll() { status.auto_joypad_counter++; } } - -#endif diff --git a/sfc/cpu/timing/timing.cpp b/sfc/cpu/timing/timing.cpp index 8189c01b..93f7e0ac 100644 --- a/sfc/cpu/timing/timing.cpp +++ b/sfc/cpu/timing/timing.cpp @@ -1,15 +1,13 @@ -#ifdef CPU_CPP - #include "irq.cpp" #include "joypad.cpp" -unsigned CPU::dma_counter() { +auto CPU::dma_counter() -> uint { return (status.dma_counter + hcounter()) & 7; } -void CPU::add_clocks(unsigned clocks) { +auto CPU::add_clocks(uint clocks) -> void { status.irq_lock = false; - unsigned ticks = clocks >> 1; + uint ticks = clocks >> 1; while(ticks--) { tick(); if(hcounter() & 2) poll_interrupts(); @@ -36,14 +34,14 @@ void CPU::add_clocks(unsigned clocks) { } //called by ppu.tick() when Hcounter=0 -void CPU::scanline() { +auto CPU::scanline() -> void { status.dma_counter = (status.dma_counter + status.line_clocks) & 7; status.line_clocks = lineclocks(); //forcefully sync S-CPU to other processors, in case chips are not communicating - synchronize_smp(); - synchronize_ppu(); - synchronize_coprocessors(); + synchronizeSMP(); + synchronizePPU(); + synchronizeDevices(); system.scanline(); if(vcounter() == 0) { @@ -65,7 +63,7 @@ void CPU::scanline() { } } -void CPU::alu_edge() { +auto CPU::alu_edge() -> void { if(alu.mpyctr) { alu.mpyctr--; if(status.rddiv & 1) status.rdmpy += alu.shift; @@ -84,7 +82,7 @@ void CPU::alu_edge() { } } -void CPU::dma_edge() { +auto CPU::dma_edge() -> void { //H/DMA pending && DMA inactive? //.. Run one full CPU cycle //.. HDMA pending && HDMA enabled ? DMA sync + HDMA run @@ -149,7 +147,7 @@ void CPU::dma_edge() { // //status.irq_lock is used to simulate hardware delay before interrupts can //trigger during certain events (immediately after DMA, writes to $4200, etc) -void CPU::last_cycle() { +auto CPU::last_cycle() -> void { if(status.irq_lock == false) { status.nmi_pending |= nmi_test(); status.irq_pending |= irq_test(); @@ -157,10 +155,10 @@ void CPU::last_cycle() { } } -void CPU::timing_power() { +auto CPU::timing_power() -> void { } -void CPU::timing_reset() { +auto CPU::timing_reset() -> void { status.clock_count = 0; status.line_clocks = lineclocks(); @@ -201,5 +199,3 @@ void CPU::timing_reset() { status.auto_joypad_counter = 0; status.auto_joypad_clock = 0; } - -#endif diff --git a/sfc/cpu/timing/timing.hpp b/sfc/cpu/timing/timing.hpp index 6c225dab..6d715ae1 100644 --- a/sfc/cpu/timing/timing.hpp +++ b/sfc/cpu/timing/timing.hpp @@ -1,24 +1,24 @@ //timing.cpp -unsigned dma_counter(); +auto dma_counter() -> uint; -void add_clocks(unsigned clocks); -void scanline(); +auto add_clocks(uint clocks) -> void; +auto scanline() -> void; -alwaysinline void alu_edge(); -alwaysinline void dma_edge(); -alwaysinline void last_cycle(); +alwaysinline auto alu_edge() -> void; +alwaysinline auto dma_edge() -> void; +alwaysinline auto last_cycle() -> void; -void timing_power(); -void timing_reset(); +auto timing_power() -> void; +auto timing_reset() -> void; //irq.cpp -alwaysinline void poll_interrupts(); -void nmitimen_update(uint8 data); -bool rdnmi(); -bool timeup(); +alwaysinline auto poll_interrupts() -> void; +auto nmitimen_update(uint8 data) -> void; +auto rdnmi() -> bool; +auto timeup() -> bool; -alwaysinline bool nmi_test(); -alwaysinline bool irq_test(); +alwaysinline auto nmi_test() -> bool; +alwaysinline auto irq_test() -> bool; //joypad.cpp -void step_auto_joypad_poll(); +auto step_auto_joypad_poll() -> void; diff --git a/sfc/dsp/brr.cpp b/sfc/dsp/brr.cpp index bf10549b..71dd0901 100644 --- a/sfc/dsp/brr.cpp +++ b/sfc/dsp/brr.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - auto DSP::brrDecode(Voice& v) -> void { //state.t_brr_byte = ram[v.brr_addr + v.brr_offset] cached from previous clock cycle signed nybbles = (state._brrByte << 8) + smp.apuram[(uint16)(v.brrAddress + v.brrOffset + 1)]; @@ -59,5 +57,3 @@ auto DSP::brrDecode(Voice& v) -> void { if(v.bufferOffset >= BrrBufferSize) v.bufferOffset = 0; } } - -#endif diff --git a/sfc/dsp/counter.cpp b/sfc/dsp/counter.cpp index 4b7c87b2..42edcbe0 100644 --- a/sfc/dsp/counter.cpp +++ b/sfc/dsp/counter.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - //counter_rate = number of samples per counter event //all rates are evenly divisible by counter_range (0x7800, 30720, or 2048 * 5 * 3) //note that rate[0] is a special case, which never triggers @@ -48,5 +46,3 @@ inline auto DSP::counterPoll(unsigned rate) -> bool { if(rate == 0) return false; return (((unsigned)state.counter + CounterOffset[rate]) % CounterRate[rate]) == 0; } - -#endif diff --git a/sfc/dsp/dsp.cpp b/sfc/dsp/dsp.cpp index a7d23e3a..305dc408 100644 --- a/sfc/dsp/dsp.cpp +++ b/sfc/dsp/dsp.cpp @@ -1,6 +1,5 @@ #include -#define DSP_CPP namespace SuperFamicom { DSP dsp; diff --git a/sfc/dsp/echo.cpp b/sfc/dsp/echo.cpp index 9cd4aec7..51ce14ba 100644 --- a/sfc/dsp/echo.cpp +++ b/sfc/dsp/echo.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - auto DSP::calculateFIR(signed i, bool channel) -> signed { signed s = state.echoHistory[channel][state.echoHistoryOffset + i + 1]; return (s * (int8)REG(FIR + i * 0x10)) >> 6; @@ -131,5 +129,3 @@ auto DSP::echo30() -> void { //write right echo echoWrite(1); } - -#endif diff --git a/sfc/dsp/envelope.cpp b/sfc/dsp/envelope.cpp index c017f038..81a10533 100644 --- a/sfc/dsp/envelope.cpp +++ b/sfc/dsp/envelope.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - auto DSP::envelopeRun(Voice& v) -> void { signed envelope = v.envelope; @@ -58,5 +56,3 @@ auto DSP::envelopeRun(Voice& v) -> void { if(counterPoll(rate)) v.envelope = envelope; } - -#endif diff --git a/sfc/dsp/gaussian.cpp b/sfc/dsp/gaussian.cpp index dd689f59..55f0a6a3 100644 --- a/sfc/dsp/gaussian.cpp +++ b/sfc/dsp/gaussian.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - const int16 DSP::GaussianTable[512] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, @@ -50,5 +48,3 @@ auto DSP::gaussianInterpolate(const Voice& v) -> signed { output += (reverse[ 0] * v.buffer[offset + 3]) >> 11; return sclamp<16>(output) & ~1; } - -#endif diff --git a/sfc/dsp/misc.cpp b/sfc/dsp/misc.cpp index fb7a692d..d96c00ec 100644 --- a/sfc/dsp/misc.cpp +++ b/sfc/dsp/misc.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - auto DSP::misc27() -> void { state._pmon = REG(PMON) & ~1; //voice 0 doesn't support PMON } @@ -31,5 +29,3 @@ auto DSP::misc30() -> void { state.noise = (feedback & 0x4000) ^ (state.noise >> 1); } } - -#endif diff --git a/sfc/dsp/serialization.cpp b/sfc/dsp/serialization.cpp index 1671a9c0..72c7f943 100644 --- a/sfc/dsp/serialization.cpp +++ b/sfc/dsp/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - void DSP::serialize(serializer& s) { Thread::serialize(s); @@ -59,5 +57,3 @@ void DSP::serialize(serializer& s) { s.integer(voice[n]._envxOut); } } - -#endif diff --git a/sfc/dsp/voice.cpp b/sfc/dsp/voice.cpp index 6c3898a9..3dbe2cd4 100644 --- a/sfc/dsp/voice.cpp +++ b/sfc/dsp/voice.cpp @@ -1,5 +1,3 @@ -#ifdef DSP_CPP - inline auto DSP::voiceOutput(Voice& v, bool channel) -> void { //apply left/right volume signed amp = (state._output * (int8)VREG(VOLL + channel)) >> 7; @@ -170,5 +168,3 @@ auto DSP::voice9(Voice& v) -> void { //update ENVX VREG(ENVX) = (uint8)state.envxBuffer; } - -#endif diff --git a/sfc/expansion/eboot/eboot.cpp b/sfc/expansion/eboot/eboot.cpp index f867ca06..c7aa11df 100644 --- a/sfc/expansion/eboot/eboot.cpp +++ b/sfc/expansion/eboot/eboot.cpp @@ -1,6 +1,5 @@ #include -#define EBOOT_CPP namespace SuperFamicom { eBoot eboot; diff --git a/sfc/expansion/satellaview/satellaview.cpp b/sfc/expansion/satellaview/satellaview.cpp index 41d9a6dc..31baf0bf 100644 --- a/sfc/expansion/satellaview/satellaview.cpp +++ b/sfc/expansion/satellaview/satellaview.cpp @@ -1,37 +1,28 @@ #include -#define SATELLAVIEW_EXPANSION_CPP namespace SuperFamicom { -SatellaviewBaseUnit satellaviewbaseunit; +Satellaview satellaview; -auto SatellaviewBaseUnit::init() -> void { +auto Satellaview::init() -> void { } -auto SatellaviewBaseUnit::load() -> void { - bus.map( - {&SatellaviewBaseUnit::read, &satellaviewbaseunit}, - {&SatellaviewBaseUnit::write, &satellaviewbaseunit}, - 0x00, 0x3f, 0x2188, 0x219f - ); - bus.map( - {&SatellaviewBaseUnit::read, &satellaviewbaseunit}, - {&SatellaviewBaseUnit::write, &satellaviewbaseunit}, - 0x80, 0xbf, 0x2188, 0x219f - ); +auto Satellaview::load() -> void { + bus.map({&Satellaview::read, &satellaview}, {&Satellaview::write, &satellaview}, 0x00, 0x3f, 0x2188, 0x219f); + bus.map({&Satellaview::read, &satellaview}, {&Satellaview::write, &satellaview}, 0x80, 0xbf, 0x2188, 0x219f); } -auto SatellaviewBaseUnit::unload() -> void { +auto Satellaview::unload() -> void { } -auto SatellaviewBaseUnit::power() -> void { +auto Satellaview::power() -> void { } -auto SatellaviewBaseUnit::reset() -> void { - memset(®s, 0x00, sizeof regs); +auto Satellaview::reset() -> void { + memory::fill(®s, sizeof regs); } -auto SatellaviewBaseUnit::read(unsigned addr) -> uint8 { +auto Satellaview::read(uint addr) -> uint8 { addr &= 0xffff; switch(addr) { @@ -44,7 +35,7 @@ auto SatellaviewBaseUnit::read(unsigned addr) -> uint8 { case 0x2190: return regs.r2190; case 0x2192: { - unsigned counter = regs.r2192_counter++; + uint counter = regs.r2192_counter++; if(regs.r2192_counter >= 18) regs.r2192_counter = 0; if(counter == 0) { @@ -89,7 +80,7 @@ auto SatellaviewBaseUnit::read(unsigned addr) -> uint8 { return cpu.regs.mdr; } -auto SatellaviewBaseUnit::write(unsigned addr, uint8 data) -> void { +auto Satellaview::write(uint addr, uint8 data) -> void { addr &= 0xffff; switch(addr) { diff --git a/sfc/expansion/satellaview/satellaview.hpp b/sfc/expansion/satellaview/satellaview.hpp index 17ba4091..afcc7f67 100644 --- a/sfc/expansion/satellaview/satellaview.hpp +++ b/sfc/expansion/satellaview/satellaview.hpp @@ -1,12 +1,12 @@ -struct SatellaviewBaseUnit : Memory { +struct Satellaview : Memory { auto init() -> void; auto load() -> void; auto unload() -> void; auto power() -> void; auto reset() -> void; - auto read(unsigned addr) -> uint8; - auto write(unsigned addr, uint8 data) -> void; + auto read(uint addr) -> uint8; + auto write(uint addr, uint8 data) -> void; private: struct { @@ -22,4 +22,4 @@ private: } regs; }; -extern SatellaviewBaseUnit satellaviewbaseunit; +extern Satellaview satellaview; diff --git a/sfc/memory/memory.cpp b/sfc/memory/memory.cpp index 19692ca4..f29c220c 100644 --- a/sfc/memory/memory.cpp +++ b/sfc/memory/memory.cpp @@ -1,6 +1,5 @@ #include -#define MEMORY_CPP namespace SuperFamicom { Bus bus; diff --git a/sfc/ppu/background/background.cpp b/sfc/ppu/background/background.cpp index 6a706f1e..d121173b 100644 --- a/sfc/ppu/background/background.cpp +++ b/sfc/ppu/background/background.cpp @@ -1,27 +1,28 @@ -#ifdef PPU_CPP - #include "mode7.cpp" -unsigned PPU::Background::voffset() const { +PPU::Background::Background(PPU &self, uint id) : self(self), id(id) { +} + +auto PPU::Background::voffset() const -> uint { if(regs.mosaic) return cache.voffset; return regs.voffset; } -unsigned PPU::Background::hoffset() const { +auto PPU::Background::hoffset() const -> uint { if(regs.mosaic) return cache.hoffset; return regs.hoffset; } //V = 0, H = 0 -void PPU::Background::frame() { +auto PPU::Background::frame() -> void { } //H = 0 -void PPU::Background::scanline() { +auto PPU::Background::scanline() -> void { } //H = 28 -void PPU::Background::begin() { +auto PPU::Background::begin() -> void { bool hires = (self.regs.bgmode == 5 || self.regs.bgmode == 6); x = -7; y = self.vcounter(); @@ -51,7 +52,7 @@ void PPU::Background::begin() { } } -void PPU::Background::get_tile() { +auto PPU::Background::get_tile() -> void { bool hires = (self.regs.bgmode == 5 || self.regs.bgmode == 6); unsigned color_depth = (regs.mode == Mode::BPP2 ? 0 : regs.mode == Mode::BPP4 ? 1 : 2); @@ -159,7 +160,7 @@ void PPU::Background::get_tile() { } } -void PPU::Background::run(bool screen) { +auto PPU::Background::run(bool screen) -> void { if(self.vcounter() == 0) return; bool hires = (self.regs.bgmode == 5 || self.regs.bgmode == 6); @@ -191,7 +192,7 @@ void PPU::Background::run(bool screen) { if(hires == false || screen == Screen::Sub ) if(regs.sub_enable ) output.sub = mosaic; } -unsigned PPU::Background::get_tile_color() { +auto PPU::Background::get_tile_color() -> uint { unsigned color = 0; switch(regs.mode) { @@ -211,7 +212,7 @@ unsigned PPU::Background::get_tile_color() { return color; } -void PPU::Background::reset() { +auto PPU::Background::reset() -> void { regs.tiledata_addr = (random(0x0000) & 0x07) << 13; regs.screen_addr = (random(0x0000) & 0x7c) << 9; regs.screen_size = random(0); @@ -253,7 +254,7 @@ void PPU::Background::reset() { for(unsigned n = 0; n < 8; n++) data[n] = 0; } -unsigned PPU::Background::get_tile(unsigned x, unsigned y) { +auto PPU::Background::get_tile(uint x, uint y) -> uint { bool hires = (self.regs.bgmode == 5 || self.regs.bgmode == 6); unsigned tile_height = (regs.tile_size == TileSize::Size8x8 ? 3 : 4); unsigned tile_width = (!hires ? tile_height : 4); @@ -279,8 +280,3 @@ unsigned PPU::Background::get_tile(unsigned x, unsigned y) { uint16 addr = regs.screen_addr + (offset << 1); return (ppu.vram[addr + 0] << 0) + (ppu.vram[addr + 1] << 8); } - -PPU::Background::Background(PPU &self, unsigned id) : self(self), id(id) { -} - -#endif diff --git a/sfc/ppu/background/background.hpp b/sfc/ppu/background/background.hpp index 7fa06b66..1cf390f3 100644 --- a/sfc/ppu/background/background.hpp +++ b/sfc/ppu/background/background.hpp @@ -1,11 +1,13 @@ struct Background { - struct ID { enum { BG1, BG2, BG3, BG4 }; }; - unsigned id; + struct ID { enum : uint { BG1, BG2, BG3, BG4 }; }; + const uint id; - struct Mode { enum { BPP2, BPP4, BPP8, Mode7, Inactive }; }; - struct ScreenSize { enum { Size32x32, Size32x64, Size64x32, Size64x64 }; }; - struct TileSize { enum { Size8x8, Size16x16 }; }; - struct Screen { enum { Main, Sub }; }; + struct Mode { enum : uint { BPP2, BPP4, BPP8, Mode7, Inactive }; }; + struct ScreenSize { enum : uint { Size32x32, Size32x64, Size64x32, Size64x64 }; }; + struct TileSize { enum : uint { Size8x8, Size16x16 }; }; + struct Screen { enum : uint { Main, Sub }; }; + + Background(PPU& self, uint id); struct Regs { uint16 tiledata_addr; @@ -14,9 +16,9 @@ struct Background { uint4 mosaic; bool tile_size; - unsigned mode; - unsigned priority0; - unsigned priority1; + uint mode; + uint priority0; + uint priority1; bool main_enable; bool sub_enable; @@ -30,51 +32,50 @@ struct Background { uint16 voffset; } cache; - alwaysinline unsigned voffset() const; - alwaysinline unsigned hoffset() const; + alwaysinline auto voffset() const -> uint; + alwaysinline auto hoffset() const -> uint; struct Output { struct Pixel { - unsigned priority; //0 = none (transparent) + uint priority; //0 = none (transparent) uint8 palette; uint16 tile; } main, sub; } output; struct Mosaic : Output::Pixel { - unsigned vcounter; - unsigned voffset; - unsigned hcounter; - unsigned hoffset; + uint vcounter; + uint voffset; + uint hcounter; + uint hoffset; } mosaic; struct { - signed x; - signed y; + int x; + int y; - unsigned tile_counter; - unsigned tile; - unsigned priority; - unsigned palette_number; - unsigned palette_index; + uint tile_counter; + uint tile; + uint priority; + uint palette_number; + uint palette_index; uint8 data[8]; }; - void frame(); - void scanline(); - void begin(); - void run(bool screen); - void reset(); + auto frame() -> void; + auto scanline() -> void; + auto begin() -> void; + auto run(bool screen) -> void; + auto reset() -> void; - void get_tile(); - unsigned get_tile_color(); - unsigned get_tile(unsigned x, unsigned y); - alwaysinline signed clip(signed n); - void begin_mode7(); - void run_mode7(); + auto get_tile() -> void; + auto get_tile_color() -> uint; + auto get_tile(uint x, uint y) -> uint; + alwaysinline auto clip(int n) -> int; + auto begin_mode7() -> void; + auto run_mode7() -> void; - void serialize(serializer&); - Background(PPU& self, unsigned id); + auto serialize(serializer&) -> void; PPU& self; friend class PPU; diff --git a/sfc/ppu/background/mode7.cpp b/sfc/ppu/background/mode7.cpp index fe0f79b7..a07875f6 100644 --- a/sfc/ppu/background/mode7.cpp +++ b/sfc/ppu/background/mode7.cpp @@ -1,17 +1,15 @@ -#ifdef PPU_CPP - -signed PPU::Background::clip(signed n) { +auto PPU::Background::clip(int n) -> int { //13-bit sign extend: --s---nnnnnnnnnn -> ssssssnnnnnnnnnn return n & 0x2000 ? (n | ~1023) : (n & 1023); } //H = 28 -void PPU::Background::begin_mode7() { +auto PPU::Background::begin_mode7() -> void { cache.hoffset = self.regs.mode7_hoffset; cache.voffset = self.regs.mode7_voffset; } -void PPU::Background::run_mode7() { +auto PPU::Background::run_mode7() -> void { signed a = sclip<16>(self.regs.m7a); signed b = sclip<16>(self.regs.m7b); signed c = sclip<16>(self.regs.m7c); @@ -103,5 +101,3 @@ void PPU::Background::run_mode7() { output.sub.tile = 0; } } - -#endif diff --git a/sfc/ppu/mmio/mmio.cpp b/sfc/ppu/mmio/mmio.cpp index e1add8f7..c3839ada 100644 --- a/sfc/ppu/mmio/mmio.cpp +++ b/sfc/ppu/mmio/mmio.cpp @@ -1,25 +1,23 @@ -#ifdef PPU_CPP - -bool PPU::interlace() const { +auto PPU::interlace() const -> bool { return display.interlace; } -bool PPU::overscan() const { +auto PPU::overscan() const -> bool { return display.overscan; } -bool PPU::hires() const { +auto PPU::hires() const -> bool { return true; } -void PPU::latch_counters() { - cpu.synchronize_ppu(); +auto PPU::latch_counters() -> void { + cpu.synchronizePPU(); regs.hcounter = hdot(); regs.vcounter = vcounter(); regs.counters_latched = true; } -uint16 PPU::get_vram_address() { +auto PPU::get_vram_address() -> uint16 { uint16 addr = regs.vram_addr; switch(regs.vram_mapping) { case 0: break; //direct mapping @@ -30,7 +28,7 @@ uint16 PPU::get_vram_address() { return (addr << 1); } -uint8 PPU::vram_read(unsigned addr) { +auto PPU::vram_read(uint addr) -> uint8 { uint8 data = 0x00; if(regs.display_disable || vcounter() >= (!regs.overscan ? 225 : 240)) { data = vram[addr]; @@ -39,37 +37,37 @@ uint8 PPU::vram_read(unsigned addr) { return data; } -void PPU::vram_write(unsigned addr, uint8 data) { +auto PPU::vram_write(uint addr, uint8 data) -> void { if(regs.display_disable || vcounter() >= (!regs.overscan ? 225 : 240)) { vram[addr] = data; debugger.vram_write(addr, data); } } -uint8 PPU::oam_read(unsigned addr) { +auto PPU::oam_read(uint addr) -> uint8 { uint8 data = oam[addr]; debugger.oam_read(addr, data); return data; } -void PPU::oam_write(unsigned addr, uint8 data) { +auto PPU::oam_write(uint addr, uint8 data) -> void { oam[addr] = data; sprite.update(addr, data); debugger.oam_write(addr, data); } -uint8 PPU::cgram_read(unsigned addr) { +auto PPU::cgram_read(uint addr) -> uint8 { uint8 data = cgram[addr]; debugger.cgram_read(addr, data); return data; } -void PPU::cgram_write(unsigned addr, uint8 data) { +auto PPU::cgram_write(uint addr, uint8 data) -> void { cgram[addr] = data; debugger.cgram_write(addr, data); } -void PPU::mmio_update_video_mode() { +auto PPU::mmio_update_video_mode() -> void { switch(regs.bgmode) { case 0: bg1.regs.mode = Background::Mode::BPP2; bg1.regs.priority0 = 8; bg1.regs.priority1 = 11; @@ -168,34 +166,34 @@ void PPU::mmio_update_video_mode() { } //INIDISP -void PPU::mmio_w2100(uint8 data) { +auto PPU::mmio_w2100(uint8 data) -> void { if(regs.display_disable && vcounter() == (!regs.overscan ? 225 : 240)) sprite.address_reset(); regs.display_disable = data & 0x80; regs.display_brightness = data & 0x0f; } //OBSEL -void PPU::mmio_w2101(uint8 data) { +auto PPU::mmio_w2101(uint8 data) -> void { sprite.regs.base_size = (data >> 5) & 7; sprite.regs.nameselect = (data >> 3) & 3; sprite.regs.tiledata_addr = (data & 3) << 14; } //OAMADDL -void PPU::mmio_w2102(uint8 data) { +auto PPU::mmio_w2102(uint8 data) -> void { regs.oam_baseaddr = (regs.oam_baseaddr & 0x0200) | (data << 1); sprite.address_reset(); } //OAMADDH -void PPU::mmio_w2103(uint8 data) { +auto PPU::mmio_w2103(uint8 data) -> void { regs.oam_priority = data & 0x80; regs.oam_baseaddr = ((data & 0x01) << 9) | (regs.oam_baseaddr & 0x01fe); sprite.address_reset(); } //OAMDATA -void PPU::mmio_w2104(uint8 data) { +auto PPU::mmio_w2104(uint8 data) -> void { bool latch = regs.oam_addr & 1; uint10 addr = regs.oam_addr++; if(regs.display_disable == false && vcounter() < (!regs.overscan ? 225 : 240)) addr = regs.oam_iaddr; @@ -212,7 +210,7 @@ void PPU::mmio_w2104(uint8 data) { } //BGMODE -void PPU::mmio_w2105(uint8 data) { +auto PPU::mmio_w2105(uint8 data) -> void { bg4.regs.tile_size = (data & 0x80); bg3.regs.tile_size = (data & 0x40); bg2.regs.tile_size = (data & 0x20); @@ -223,7 +221,7 @@ void PPU::mmio_w2105(uint8 data) { } //MOSAIC -void PPU::mmio_w2106(uint8 data) { +auto PPU::mmio_w2106(uint8 data) -> void { unsigned mosaic_size = (data >> 4) & 15; bg4.regs.mosaic = (data & 0x08 ? mosaic_size : 0); bg3.regs.mosaic = (data & 0x04 ? mosaic_size : 0); @@ -232,43 +230,43 @@ void PPU::mmio_w2106(uint8 data) { } //BG1SC -void PPU::mmio_w2107(uint8 data) { +auto PPU::mmio_w2107(uint8 data) -> void { bg1.regs.screen_addr = (data & 0x7c) << 9; bg1.regs.screen_size = data & 3; } //BG2SC -void PPU::mmio_w2108(uint8 data) { +auto PPU::mmio_w2108(uint8 data) -> void { bg2.regs.screen_addr = (data & 0x7c) << 9; bg2.regs.screen_size = data & 3; } //BG3SC -void PPU::mmio_w2109(uint8 data) { +auto PPU::mmio_w2109(uint8 data) -> void { bg3.regs.screen_addr = (data & 0x7c) << 9; bg3.regs.screen_size = data & 3; } //BG4SC -void PPU::mmio_w210a(uint8 data) { +auto PPU::mmio_w210a(uint8 data) -> void { bg4.regs.screen_addr = (data & 0x7c) << 9; bg4.regs.screen_size = data & 3; } //BG12NBA -void PPU::mmio_w210b(uint8 data) { +auto PPU::mmio_w210b(uint8 data) -> void { bg1.regs.tiledata_addr = (data & 0x07) << 13; bg2.regs.tiledata_addr = (data & 0x70) << 9; } //BG34NBA -void PPU::mmio_w210c(uint8 data) { +auto PPU::mmio_w210c(uint8 data) -> void { bg3.regs.tiledata_addr = (data & 0x07) << 13; bg4.regs.tiledata_addr = (data & 0x70) << 9; } //BG1HOFS -void PPU::mmio_w210d(uint8 data) { +auto PPU::mmio_w210d(uint8 data) -> void { regs.mode7_hoffset = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; @@ -277,7 +275,7 @@ void PPU::mmio_w210d(uint8 data) { } //BG1VOFS -void PPU::mmio_w210e(uint8 data) { +auto PPU::mmio_w210e(uint8 data) -> void { regs.mode7_voffset = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; @@ -286,43 +284,43 @@ void PPU::mmio_w210e(uint8 data) { } //BG2HOFS -void PPU::mmio_w210f(uint8 data) { +auto PPU::mmio_w210f(uint8 data) -> void { bg2.regs.hoffset = (data << 8) | (regs.bgofs_latchdata & ~7) | ((bg2.regs.hoffset >> 8) & 7); regs.bgofs_latchdata = data; } //BG2VOFS -void PPU::mmio_w2110(uint8 data) { +auto PPU::mmio_w2110(uint8 data) -> void { bg2.regs.voffset = (data << 8) | regs.bgofs_latchdata; regs.bgofs_latchdata = data; } //BG3HOFS -void PPU::mmio_w2111(uint8 data) { +auto PPU::mmio_w2111(uint8 data) -> void { bg3.regs.hoffset = (data << 8) | (regs.bgofs_latchdata & ~7) | ((bg3.regs.hoffset >> 8) & 7); regs.bgofs_latchdata = data; } //BG3VOFS -void PPU::mmio_w2112(uint8 data) { +auto PPU::mmio_w2112(uint8 data) -> void { bg3.regs.voffset = (data << 8) | regs.bgofs_latchdata; regs.bgofs_latchdata = data; } //BG4HOFS -void PPU::mmio_w2113(uint8 data) { +auto PPU::mmio_w2113(uint8 data) -> void { bg4.regs.hoffset = (data << 8) | (regs.bgofs_latchdata & ~7) | ((bg4.regs.hoffset >> 8) & 7); regs.bgofs_latchdata = data; } //BG4VOFS -void PPU::mmio_w2114(uint8 data) { +auto PPU::mmio_w2114(uint8 data) -> void { bg4.regs.voffset = (data << 8) | regs.bgofs_latchdata; regs.bgofs_latchdata = data; } //VMAIN -void PPU::mmio_w2115(uint8 data) { +auto PPU::mmio_w2115(uint8 data) -> void { regs.vram_incmode = data & 0x80; regs.vram_mapping = (data >> 2) & 3; switch(data & 3) { @@ -334,7 +332,7 @@ void PPU::mmio_w2115(uint8 data) { } //VMADDL -void PPU::mmio_w2116(uint8 data) { +auto PPU::mmio_w2116(uint8 data) -> void { regs.vram_addr &= 0xff00; regs.vram_addr |= (data << 0); uint16 addr = get_vram_address(); @@ -343,7 +341,7 @@ void PPU::mmio_w2116(uint8 data) { } //VMADDH -void PPU::mmio_w2117(uint8 data) { +auto PPU::mmio_w2117(uint8 data) -> void { regs.vram_addr &= 0x00ff; regs.vram_addr |= (data << 8); uint16 addr = get_vram_address(); @@ -352,69 +350,69 @@ void PPU::mmio_w2117(uint8 data) { } //VMDATAL -void PPU::mmio_w2118(uint8 data) { +auto PPU::mmio_w2118(uint8 data) -> void { uint16 addr = get_vram_address() + 0; vram_write(addr, data); if(regs.vram_incmode == 0) regs.vram_addr += regs.vram_incsize; } //VMDATAH -void PPU::mmio_w2119(uint8 data) { +auto PPU::mmio_w2119(uint8 data) -> void { uint16 addr = get_vram_address() + 1; vram_write(addr, data); if(regs.vram_incmode == 1) regs.vram_addr += regs.vram_incsize; } //M7SEL -void PPU::mmio_w211a(uint8 data) { +auto PPU::mmio_w211a(uint8 data) -> void { regs.mode7_repeat = (data >> 6) & 3; regs.mode7_vflip = data & 0x02; regs.mode7_hflip = data & 0x01; } //M7A -void PPU::mmio_w211b(uint8 data) { +auto PPU::mmio_w211b(uint8 data) -> void { regs.m7a = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; } //M7B -void PPU::mmio_w211c(uint8 data) { +auto PPU::mmio_w211c(uint8 data) -> void { regs.m7b = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; } //M7C -void PPU::mmio_w211d(uint8 data) { +auto PPU::mmio_w211d(uint8 data) -> void { regs.m7c = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; } //M7D -void PPU::mmio_w211e(uint8 data) { +auto PPU::mmio_w211e(uint8 data) -> void { regs.m7d = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; } //M7X -void PPU::mmio_w211f(uint8 data) { +auto PPU::mmio_w211f(uint8 data) -> void { regs.m7x = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; } //M7Y -void PPU::mmio_w2120(uint8 data) { +auto PPU::mmio_w2120(uint8 data) -> void { regs.m7y = (data << 8) | regs.mode7_latchdata; regs.mode7_latchdata = data; } //CGADD -void PPU::mmio_w2121(uint8 data) { +auto PPU::mmio_w2121(uint8 data) -> void { regs.cgram_addr = data << 1; } //CGDATA -void PPU::mmio_w2122(uint8 data) { +auto PPU::mmio_w2122(uint8 data) -> void { bool latch = regs.cgram_addr & 1; uint9 addr = regs.cgram_addr++; if(regs.display_disable == false @@ -431,7 +429,7 @@ void PPU::mmio_w2122(uint8 data) { } //W12SEL -void PPU::mmio_w2123(uint8 data) { +auto PPU::mmio_w2123(uint8 data) -> void { window.regs.bg2_two_enable = data & 0x80; window.regs.bg2_two_invert = data & 0x40; window.regs.bg2_one_enable = data & 0x20; @@ -443,7 +441,7 @@ void PPU::mmio_w2123(uint8 data) { } //W34SEL -void PPU::mmio_w2124(uint8 data) { +auto PPU::mmio_w2124(uint8 data) -> void { window.regs.bg4_two_enable = data & 0x80; window.regs.bg4_two_invert = data & 0x40; window.regs.bg4_one_enable = data & 0x20; @@ -455,7 +453,7 @@ void PPU::mmio_w2124(uint8 data) { } //WOBJSEL -void PPU::mmio_w2125(uint8 data) { +auto PPU::mmio_w2125(uint8 data) -> void { window.regs.col_two_enable = data & 0x80; window.regs.col_two_invert = data & 0x40; window.regs.col_one_enable = data & 0x20; @@ -467,27 +465,27 @@ void PPU::mmio_w2125(uint8 data) { } //WH0 -void PPU::mmio_w2126(uint8 data) { +auto PPU::mmio_w2126(uint8 data) -> void { window.regs.one_left = data; } //WH1 -void PPU::mmio_w2127(uint8 data) { +auto PPU::mmio_w2127(uint8 data) -> void { window.regs.one_right = data; } //WH2 -void PPU::mmio_w2128(uint8 data) { +auto PPU::mmio_w2128(uint8 data) -> void { window.regs.two_left = data; } //WH3 -void PPU::mmio_w2129(uint8 data) { +auto PPU::mmio_w2129(uint8 data) -> void { window.regs.two_right = data; } //WBGLOG -void PPU::mmio_w212a(uint8 data) { +auto PPU::mmio_w212a(uint8 data) -> void { window.regs.bg4_mask = (data >> 6) & 3; window.regs.bg3_mask = (data >> 4) & 3; window.regs.bg2_mask = (data >> 2) & 3; @@ -495,13 +493,13 @@ void PPU::mmio_w212a(uint8 data) { } //WOBJLOG -void PPU::mmio_w212b(uint8 data) { +auto PPU::mmio_w212b(uint8 data) -> void { window.regs.col_mask = (data >> 2) & 3; window.regs.oam_mask = (data >> 0) & 3; } //TM -void PPU::mmio_w212c(uint8 data) { +auto PPU::mmio_w212c(uint8 data) -> void { sprite.regs.main_enable = data & 0x10; bg4.regs.main_enable = data & 0x08; bg3.regs.main_enable = data & 0x04; @@ -510,7 +508,7 @@ void PPU::mmio_w212c(uint8 data) { } //TS -void PPU::mmio_w212d(uint8 data) { +auto PPU::mmio_w212d(uint8 data) -> void { sprite.regs.sub_enable = data & 0x10; bg4.regs.sub_enable = data & 0x08; bg3.regs.sub_enable = data & 0x04; @@ -519,7 +517,7 @@ void PPU::mmio_w212d(uint8 data) { } //TMW -void PPU::mmio_w212e(uint8 data) { +auto PPU::mmio_w212e(uint8 data) -> void { window.regs.oam_main_enable = data & 0x10; window.regs.bg4_main_enable = data & 0x08; window.regs.bg3_main_enable = data & 0x04; @@ -528,7 +526,7 @@ void PPU::mmio_w212e(uint8 data) { } //TSW -void PPU::mmio_w212f(uint8 data) { +auto PPU::mmio_w212f(uint8 data) -> void { window.regs.oam_sub_enable = data & 0x10; window.regs.bg4_sub_enable = data & 0x08; window.regs.bg3_sub_enable = data & 0x04; @@ -537,7 +535,7 @@ void PPU::mmio_w212f(uint8 data) { } //CGWSEL -void PPU::mmio_w2130(uint8 data) { +auto PPU::mmio_w2130(uint8 data) -> void { window.regs.col_main_mask = (data >> 6) & 3; window.regs.col_sub_mask = (data >> 4) & 3; screen.regs.addsub_mode = data & 0x02; @@ -545,7 +543,7 @@ void PPU::mmio_w2130(uint8 data) { } //CGADDSUB -void PPU::mmio_w2131(uint8 data) { +auto PPU::mmio_w2131(uint8 data) -> void { screen.regs.color_mode = data & 0x80; screen.regs.color_halve = data & 0x40; screen.regs.back_color_enable = data & 0x20; @@ -557,14 +555,14 @@ void PPU::mmio_w2131(uint8 data) { } //COLDATA -void PPU::mmio_w2132(uint8 data) { +auto PPU::mmio_w2132(uint8 data) -> void { if(data & 0x80) screen.regs.color_b = data & 0x1f; if(data & 0x40) screen.regs.color_g = data & 0x1f; if(data & 0x20) screen.regs.color_r = data & 0x1f; } //SETINI -void PPU::mmio_w2133(uint8 data) { +auto PPU::mmio_w2133(uint8 data) -> void { regs.mode7_extbg = data & 0x40; regs.pseudo_hires = data & 0x08; regs.overscan = data & 0x04; @@ -574,34 +572,34 @@ void PPU::mmio_w2133(uint8 data) { } //MPYL -uint8 PPU::mmio_r2134() { +auto PPU::mmio_r2134() -> uint8 { unsigned result = ((int16)regs.m7a * (int8)(regs.m7b >> 8)); regs.ppu1_mdr = (result >> 0); return regs.ppu1_mdr; } //MPYM -uint8 PPU::mmio_r2135() { +auto PPU::mmio_r2135() -> uint8 { unsigned result = ((int16)regs.m7a * (int8)(regs.m7b >> 8)); regs.ppu1_mdr = (result >> 8); return regs.ppu1_mdr; } //MPYH -uint8 PPU::mmio_r2136() { +auto PPU::mmio_r2136() -> uint8 { unsigned result = ((int16)regs.m7a * (int8)(regs.m7b >> 8)); regs.ppu1_mdr = (result >> 16); return regs.ppu1_mdr; } //SLHV -uint8 PPU::mmio_r2137() { +auto PPU::mmio_r2137() -> uint8 { if(cpu.pio() & 0x80) latch_counters(); return cpu.regs.mdr; } //OAMDATAREAD -uint8 PPU::mmio_r2138() { +auto PPU::mmio_r2138() -> uint8 { uint10 addr = regs.oam_addr++; if(regs.display_disable == false && vcounter() < (!regs.overscan ? 225 : 240)) addr = regs.oam_iaddr; if(addr & 0x0200) addr &= 0x021f; @@ -612,7 +610,7 @@ uint8 PPU::mmio_r2138() { } //VMDATALREAD -uint8 PPU::mmio_r2139() { +auto PPU::mmio_r2139() -> uint8 { uint16 addr = get_vram_address() + 0; regs.ppu1_mdr = regs.vram_readbuffer >> 0; if(regs.vram_incmode == 0) { @@ -625,7 +623,7 @@ uint8 PPU::mmio_r2139() { } //VMDATAHREAD -uint8 PPU::mmio_r213a() { +auto PPU::mmio_r213a() -> uint8 { uint16 addr = get_vram_address() + 1; regs.ppu1_mdr = regs.vram_readbuffer >> 8; if(regs.vram_incmode == 1) { @@ -638,7 +636,7 @@ uint8 PPU::mmio_r213a() { } //CGDATAREAD -uint8 PPU::mmio_r213b() { +auto PPU::mmio_r213b() -> uint8 { bool latch = regs.cgram_addr & 1; uint9 addr = regs.cgram_addr++; if(regs.display_disable == false @@ -656,7 +654,7 @@ uint8 PPU::mmio_r213b() { } //OPHCT -uint8 PPU::mmio_r213c() { +auto PPU::mmio_r213c() -> uint8 { if(regs.latch_hcounter == 0) { regs.ppu2_mdr = (regs.hcounter >> 0); } else { @@ -668,7 +666,7 @@ uint8 PPU::mmio_r213c() { } //OPVCT -uint8 PPU::mmio_r213d() { +auto PPU::mmio_r213d() -> uint8 { if(regs.latch_vcounter == 0) { regs.ppu2_mdr = (regs.vcounter >> 0); } else { @@ -680,7 +678,7 @@ uint8 PPU::mmio_r213d() { } //STAT77 -uint8 PPU::mmio_r213e() { +auto PPU::mmio_r213e() -> uint8 { regs.ppu1_mdr &= 0x10; regs.ppu1_mdr |= sprite.regs.time_over << 7; regs.ppu1_mdr |= sprite.regs.range_over << 6; @@ -689,7 +687,7 @@ uint8 PPU::mmio_r213e() { } //STAT78 -uint8 PPU::mmio_r213f() { +auto PPU::mmio_r213f() -> uint8 { regs.latch_hcounter = 0; regs.latch_vcounter = 0; @@ -706,7 +704,7 @@ uint8 PPU::mmio_r213f() { return regs.ppu2_mdr; } -void PPU::mmio_reset() { +auto PPU::mmio_reset() -> void { regs.ppu1_mdr = random(0xff); regs.ppu2_mdr = random(0xff); @@ -790,8 +788,8 @@ void PPU::mmio_reset() { regs.vcounter = 0; } -uint8 PPU::mmio_read(unsigned addr) { - cpu.synchronize_ppu(); +auto PPU::mmio_read(uint addr) -> uint8 { + cpu.synchronizePPU(); switch(addr & 0xffff) { case 0x2104: @@ -829,8 +827,8 @@ uint8 PPU::mmio_read(unsigned addr) { return cpu.regs.mdr; } -void PPU::mmio_write(unsigned addr, uint8 data) { - cpu.synchronize_ppu(); +auto PPU::mmio_write(uint addr, uint8 data) -> void { + cpu.synchronizePPU(); switch(addr & 0xffff) { case 0x2100: return mmio_w2100(data); //INIDISP @@ -887,5 +885,3 @@ void PPU::mmio_write(unsigned addr, uint8 data) { case 0x2133: return mmio_w2133(data); //SETINI } } - -#endif diff --git a/sfc/ppu/mmio/mmio.hpp b/sfc/ppu/mmio/mmio.hpp index 13023eec..1090a055 100644 --- a/sfc/ppu/mmio/mmio.hpp +++ b/sfc/ppu/mmio/mmio.hpp @@ -1,6 +1,6 @@ public: - uint8 mmio_read(unsigned addr); - void mmio_write(unsigned addr, uint8 data); + auto mmio_read(uint addr) -> uint8; + auto mmio_write(uint addr, uint8 data) -> void; privileged: struct { @@ -87,79 +87,79 @@ struct { uint16 vcounter; } regs; -alwaysinline uint16 get_vram_address(); -alwaysinline uint8 vram_read(unsigned addr); -alwaysinline void vram_write(unsigned addr, uint8 data); -alwaysinline uint8 oam_read(unsigned addr); -alwaysinline void oam_write(unsigned addr, uint8 data); -alwaysinline uint8 cgram_read(unsigned addr); -alwaysinline void cgram_write(unsigned addr, uint8 data); +alwaysinline auto get_vram_address() -> uint16; +alwaysinline auto vram_read(uint addr) -> uint8; +alwaysinline auto vram_write(uint addr, uint8 data) -> void; +alwaysinline auto oam_read(uint addr) -> uint8; +alwaysinline auto oam_write(uint addr, uint8 data) -> void; +alwaysinline auto cgram_read(uint addr) -> uint8; +alwaysinline auto cgram_write(uint addr, uint8 data) -> void; -void mmio_update_video_mode(); +auto mmio_update_video_mode() -> void; -void mmio_w2100(uint8); //INIDISP -void mmio_w2101(uint8); //OBSEL -void mmio_w2102(uint8); //OAMADDL -void mmio_w2103(uint8); //OAMADDH -void mmio_w2104(uint8); //OAMDATA -void mmio_w2105(uint8); //BGMODE -void mmio_w2106(uint8); //MOSAIC -void mmio_w2107(uint8); //BG1SC -void mmio_w2108(uint8); //BG2SC -void mmio_w2109(uint8); //BG3SC -void mmio_w210a(uint8); //BG4SC -void mmio_w210b(uint8); //BG12NBA -void mmio_w210c(uint8); //BG34NBA -void mmio_w210d(uint8); //BG1HOFS -void mmio_w210e(uint8); //BG1VOFS -void mmio_w210f(uint8); //BG2HOFS -void mmio_w2110(uint8); //BG2VOFS -void mmio_w2111(uint8); //BG3HOFS -void mmio_w2112(uint8); //BG3VOFS -void mmio_w2113(uint8); //BG4HOFS -void mmio_w2114(uint8); //BG4VOFS -void mmio_w2115(uint8); //VMAIN -void mmio_w2116(uint8); //VMADDL -void mmio_w2117(uint8); //VMADDH -void mmio_w2118(uint8); //VMDATAL -void mmio_w2119(uint8); //VMDATAH -void mmio_w211a(uint8); //M7SEL -void mmio_w211b(uint8); //M7A -void mmio_w211c(uint8); //M7B -void mmio_w211d(uint8); //M7C -void mmio_w211e(uint8); //M7D -void mmio_w211f(uint8); //M7X -void mmio_w2120(uint8); //M7Y -void mmio_w2121(uint8); //CGADD -void mmio_w2122(uint8); //CGDATA -void mmio_w2123(uint8); //W12SEL -void mmio_w2124(uint8); //W34SEL -void mmio_w2125(uint8); //WOBJSEL -void mmio_w2126(uint8); //WH0 -void mmio_w2127(uint8); //WH1 -void mmio_w2128(uint8); //WH2 -void mmio_w2129(uint8); //WH3 -void mmio_w212a(uint8); //WBGLOG -void mmio_w212b(uint8); //WOBJLOG -void mmio_w212c(uint8); //TM -void mmio_w212d(uint8); //TS -void mmio_w212e(uint8); //TMW -void mmio_w212f(uint8); //TSW -void mmio_w2130(uint8); //CGWSEL -void mmio_w2131(uint8); //CGADDSUB -void mmio_w2132(uint8); //COLDATA -void mmio_w2133(uint8); //SETINI -uint8 mmio_r2134(); //MPYL -uint8 mmio_r2135(); //MPYM -uint8 mmio_r2136(); //MPYH -uint8 mmio_r2137(); //SLHV -uint8 mmio_r2138(); //OAMDATAREAD -uint8 mmio_r2139(); //VMDATALREAD -uint8 mmio_r213a(); //VMDATAHREAD -uint8 mmio_r213b(); //CGDATAREAD -uint8 mmio_r213c(); //OPHCT -uint8 mmio_r213d(); //OPVCT -uint8 mmio_r213e(); //STAT77 -uint8 mmio_r213f(); //STAT78 +auto mmio_w2100(uint8) -> void; //INIDISP +auto mmio_w2101(uint8) -> void; //OBSEL +auto mmio_w2102(uint8) -> void; //OAMADDL +auto mmio_w2103(uint8) -> void; //OAMADDH +auto mmio_w2104(uint8) -> void; //OAMDATA +auto mmio_w2105(uint8) -> void; //BGMODE +auto mmio_w2106(uint8) -> void; //MOSAIC +auto mmio_w2107(uint8) -> void; //BG1SC +auto mmio_w2108(uint8) -> void; //BG2SC +auto mmio_w2109(uint8) -> void; //BG3SC +auto mmio_w210a(uint8) -> void; //BG4SC +auto mmio_w210b(uint8) -> void; //BG12NBA +auto mmio_w210c(uint8) -> void; //BG34NBA +auto mmio_w210d(uint8) -> void; //BG1HOFS +auto mmio_w210e(uint8) -> void; //BG1VOFS +auto mmio_w210f(uint8) -> void; //BG2HOFS +auto mmio_w2110(uint8) -> void; //BG2VOFS +auto mmio_w2111(uint8) -> void; //BG3HOFS +auto mmio_w2112(uint8) -> void; //BG3VOFS +auto mmio_w2113(uint8) -> void; //BG4HOFS +auto mmio_w2114(uint8) -> void; //BG4VOFS +auto mmio_w2115(uint8) -> void; //VMAIN +auto mmio_w2116(uint8) -> void; //VMADDL +auto mmio_w2117(uint8) -> void; //VMADDH +auto mmio_w2118(uint8) -> void; //VMDATAL +auto mmio_w2119(uint8) -> void; //VMDATAH +auto mmio_w211a(uint8) -> void; //M7SEL +auto mmio_w211b(uint8) -> void; //M7A +auto mmio_w211c(uint8) -> void; //M7B +auto mmio_w211d(uint8) -> void; //M7C +auto mmio_w211e(uint8) -> void; //M7D +auto mmio_w211f(uint8) -> void; //M7X +auto mmio_w2120(uint8) -> void; //M7Y +auto mmio_w2121(uint8) -> void; //CGADD +auto mmio_w2122(uint8) -> void; //CGDATA +auto mmio_w2123(uint8) -> void; //W12SEL +auto mmio_w2124(uint8) -> void; //W34SEL +auto mmio_w2125(uint8) -> void; //WOBJSEL +auto mmio_w2126(uint8) -> void; //WH0 +auto mmio_w2127(uint8) -> void; //WH1 +auto mmio_w2128(uint8) -> void; //WH2 +auto mmio_w2129(uint8) -> void; //WH3 +auto mmio_w212a(uint8) -> void; //WBGLOG +auto mmio_w212b(uint8) -> void; //WOBJLOG +auto mmio_w212c(uint8) -> void; //TM +auto mmio_w212d(uint8) -> void; //TS +auto mmio_w212e(uint8) -> void; //TMW +auto mmio_w212f(uint8) -> void; //TSW +auto mmio_w2130(uint8) -> void; //CGWSEL +auto mmio_w2131(uint8) -> void; //CGADDSUB +auto mmio_w2132(uint8) -> void; //COLDATA +auto mmio_w2133(uint8) -> void; //SETINI +auto mmio_r2134() -> uint8; //MPYL +auto mmio_r2135() -> uint8; //MPYM +auto mmio_r2136() -> uint8; //MPYH +auto mmio_r2137() -> uint8; //SLHV +auto mmio_r2138() -> uint8; //OAMDATAREAD +auto mmio_r2139() -> uint8; //VMDATALREAD +auto mmio_r213a() -> uint8; //VMDATAHREAD +auto mmio_r213b() -> uint8; //CGDATAREAD +auto mmio_r213c() -> uint8; //OPHCT +auto mmio_r213d() -> uint8; //OPVCT +auto mmio_r213e() -> uint8; //STAT77 +auto mmio_r213f() -> uint8; //STAT78 -void mmio_reset(); +auto mmio_reset() -> void; diff --git a/sfc/ppu/ppu.cpp b/sfc/ppu/ppu.cpp index 3400f8e2..64afa5ac 100644 --- a/sfc/ppu/ppu.cpp +++ b/sfc/ppu/ppu.cpp @@ -1,6 +1,5 @@ #include -#define PPU_CPP namespace SuperFamicom { PPU ppu; @@ -12,11 +11,27 @@ PPU ppu; #include "window/window.cpp" #include "serialization.cpp" -void PPU::step(unsigned clocks) { +PPU::PPU() : +bg1(*this, Background::ID::BG1), +bg2(*this, Background::ID::BG2), +bg3(*this, Background::ID::BG3), +bg4(*this, Background::ID::BG4), +sprite(*this), +window(*this), +screen(*this) { + surface = new uint32[512 * 512]; + output = surface + 16 * 512; +} + +PPU::~PPU() { + delete[] surface; +} + +auto PPU::step(uint clocks) -> void { clock += clocks; } -void PPU::synchronize_cpu() { +auto PPU::synchronizeCPU() -> void { if(CPU::Threaded == true) { if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread); } else { @@ -24,9 +39,9 @@ void PPU::synchronize_cpu() { } } -void PPU::Enter() { ppu.enter(); } +auto PPU::Enter() -> void { ppu.enter(); } -void PPU::enter() { +auto PPU::enter() -> void { while(true) { if(scheduler.sync == Scheduler::SynchronizeMode::All) { scheduler.exit(Scheduler::ExitReason::SynchronizeEvent); @@ -69,33 +84,33 @@ void PPU::enter() { } } -void PPU::add_clocks(unsigned clocks) { +auto PPU::add_clocks(uint clocks) -> void { clocks >>= 1; while(clocks--) { tick(2); step(2); - synchronize_cpu(); + synchronizeCPU(); } } -void PPU::enable() { - function reader = {&PPU::mmio_read, (PPU*)&ppu}; - function writer = {&PPU::mmio_write, (PPU*)&ppu}; +auto PPU::enable() -> void { + function reader{&PPU::mmio_read, (PPU*)&ppu}; + function writer{&PPU::mmio_write, (PPU*)&ppu}; bus.map(reader, writer, 0x00, 0x3f, 0x2100, 0x213f); bus.map(reader, writer, 0x80, 0xbf, 0x2100, 0x213f); } -void PPU::power() { +auto PPU::power() -> void { for(auto& n : vram) n = random(0x00); for(auto& n : oam) n = random(0x00); for(auto& n : cgram) n = random(0x00); } -void PPU::reset() { +auto PPU::reset() -> void { create(Enter, system.cpuFrequency()); PPUcounter::reset(); - memset(surface, 0, 512 * 512 * sizeof(uint32)); + memory::fill(surface, 512 * 512 * sizeof(uint32)); mmio_reset(); bg1.reset(); @@ -109,7 +124,7 @@ void PPU::reset() { frame(); } -void PPU::scanline() { +auto PPU::scanline() -> void { if(vcounter() == 0) { frame(); bg1.frame(); @@ -127,7 +142,7 @@ void PPU::scanline() { screen.scanline(); } -void PPU::frame() { +auto PPU::frame() -> void { system.frame(); sprite.frame(); @@ -135,20 +150,4 @@ void PPU::frame() { display.overscan = regs.overscan; } -PPU::PPU() : -bg1(*this, Background::ID::BG1), -bg2(*this, Background::ID::BG2), -bg3(*this, Background::ID::BG3), -bg4(*this, Background::ID::BG4), -sprite(*this), -window(*this), -screen(*this) { - surface = new uint32[512 * 512]; - output = surface + 16 * 512; -} - -PPU::~PPU() { - delete[] surface; -} - } diff --git a/sfc/ppu/ppu.hpp b/sfc/ppu/ppu.hpp index e9bb282c..757548d9 100644 --- a/sfc/ppu/ppu.hpp +++ b/sfc/ppu/ppu.hpp @@ -1,32 +1,34 @@ struct PPU : Thread, public PPUcounter { - uint8 vram[64 * 1024]; - uint8 oam[544]; - uint8 cgram[512]; - enum : bool { Threaded = true }; - alwaysinline void step(unsigned clocks); - alwaysinline void synchronize_cpu(); - void latch_counters(); - bool interlace() const; - bool overscan() const; - bool hires() const; - - void enter(); - void enable(); - void power(); - void reset(); - - void serialize(serializer&); PPU(); ~PPU(); -privileged: - unsigned ppu1_version = 1; //allowed: 1 - unsigned ppu2_version = 3; //allowed: 1, 2, 3 + alwaysinline auto step(uint clocks) -> void; + alwaysinline auto synchronizeCPU() -> void; - uint32* surface; - uint32* output; + auto latch_counters() -> void; + auto interlace() const -> bool; + auto overscan() const -> bool; + auto hires() const -> bool; + + auto enter() -> void; + auto enable() -> void; + auto power() -> void; + auto reset() -> void; + + auto serialize(serializer&) -> void; + + uint8 vram[64 * 1024] = {0}; + uint8 oam[544] = {0}; + uint8 cgram[512] = {0}; + +privileged: + uint ppu1_version = 1; //allowed: 1 + uint ppu2_version = 3; //allowed: 1, 2, 3 + + uint32* surface = nullptr; + uint32* output = nullptr; struct { bool interlace; @@ -47,11 +49,11 @@ privileged: Window window; Screen screen; - static void Enter(); - alwaysinline void add_clocks(unsigned); + static auto Enter() -> void; + alwaysinline auto add_clocks(uint) -> void; - void scanline(); - void frame(); + auto scanline() -> void; + auto frame() -> void; friend class PPU::Background; friend class PPU::Sprite; diff --git a/sfc/ppu/screen/screen.cpp b/sfc/ppu/screen/screen.cpp index b5f0001c..d6c66a2e 100644 --- a/sfc/ppu/screen/screen.cpp +++ b/sfc/ppu/screen/screen.cpp @@ -1,6 +1,7 @@ -#ifdef PPU_CPP +PPU::Screen::Screen(PPU& self) : self(self) { +} -void PPU::Screen::scanline() { +auto PPU::Screen::scanline() -> void { output = self.output + self.vcounter() * 1024; if(self.display.interlace && self.field()) output += 512; @@ -17,7 +18,7 @@ void PPU::Screen::scanline() { math.color_halve = regs.color_halve && !regs.addsub_mode && math.main.color_enable; } -void PPU::Screen::run() { +auto PPU::Screen::run() -> void { if(ppu.vcounter() == 0) return; bool hires = self.regs.pseudo_hires || self.regs.bgmode == 5 || self.regs.bgmode == 6; @@ -28,10 +29,10 @@ void PPU::Screen::run() { *output++ = (self.regs.display_brightness << 15) | (mscolor); } -uint16 PPU::Screen::get_pixel_sub(bool hires) { +auto PPU::Screen::get_pixel_sub(bool hires) -> uint16 { if(self.regs.display_disable || (!self.regs.overscan && self.vcounter() >= 225)) return 0; - unsigned priority = 0; + uint priority = 0; if(self.bg1.output.sub.priority) { priority = self.bg1.output.sub.priority; if(regs.direct_color && (self.regs.bgmode == 3 || self.regs.bgmode == 4 || self.regs.bgmode == 7)) { @@ -67,10 +68,10 @@ uint16 PPU::Screen::get_pixel_sub(bool hires) { ); } -uint16 PPU::Screen::get_pixel_main() { +auto PPU::Screen::get_pixel_main() -> uint16 { if(self.regs.display_disable || (!self.regs.overscan && self.vcounter() >= 225)) return 0; - unsigned priority = 0; + uint priority = 0; if(self.bg1.output.main.priority) { priority = self.bg1.output.main.priority; if(regs.direct_color && (self.regs.bgmode == 3 || self.regs.bgmode == 4 || self.regs.bgmode == 7)) { @@ -123,18 +124,18 @@ uint16 PPU::Screen::get_pixel_main() { ); } -uint16 PPU::Screen::addsub(unsigned x, unsigned y) { +auto PPU::Screen::addsub(uint x, uint y) -> uint16 { if(!regs.color_mode) { if(!math.color_halve) { - unsigned sum = x + y; - unsigned carry = (sum - ((x ^ y) & 0x0421)) & 0x8420; + uint sum = x + y; + uint carry = (sum - ((x ^ y) & 0x0421)) & 0x8420; return (sum - carry) | (carry - (carry >> 5)); } else { return (x + y - ((x ^ y) & 0x0421)) >> 1; } } else { - unsigned diff = x - y + 0x8420; - unsigned borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420; + uint diff = x - y + 0x8420; + uint borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420; if(!math.color_halve) { return (diff - borrow) & (borrow - (borrow >> 5)); } else { @@ -143,13 +144,13 @@ uint16 PPU::Screen::addsub(unsigned x, unsigned y) { } } -uint16 PPU::Screen::get_color(unsigned palette) { +auto PPU::Screen::get_color(uint palette) -> uint16 { palette <<= 1; self.regs.cgram_iaddr = palette; return ppu.cgram[palette + 0] + (ppu.cgram[palette + 1] << 8); } -uint16 PPU::Screen::get_direct_color(unsigned palette, unsigned tile) { +auto PPU::Screen::get_direct_color(uint palette, uint tile) -> uint16 { //palette = -------- BBGGGRRR //tile = ---bgr-- -------- //output = 0BBb00GG Gg0RRRr0 @@ -158,11 +159,11 @@ uint16 PPU::Screen::get_direct_color(unsigned palette, unsigned tile) { + ((palette << 2) & 0x001c) + ((tile >> 9) & 0x0002); } -uint16 PPU::Screen::fixed_color() const { +auto PPU::Screen::fixed_color() const -> uint16 { return (regs.color_b << 10) | (regs.color_g << 5) | (regs.color_r << 0); } -void PPU::Screen::reset() { +auto PPU::Screen::reset() -> void { regs.addsub_mode = random(false); regs.direct_color = random(false); regs.color_mode = random(false); @@ -177,8 +178,3 @@ void PPU::Screen::reset() { regs.color_g = random(0); regs.color_b = random(0); } - -PPU::Screen::Screen(PPU& self) : self(self) { -} - -#endif diff --git a/sfc/ppu/screen/screen.hpp b/sfc/ppu/screen/screen.hpp index f8cdd791..821289e5 100644 --- a/sfc/ppu/screen/screen.hpp +++ b/sfc/ppu/screen/screen.hpp @@ -29,20 +29,21 @@ struct Screen { bool color_halve; } math; - void scanline(); - alwaysinline void run(); - void reset(); - - uint16 get_pixel_sub(bool hires); - uint16 get_pixel_main(); - uint16 addsub(unsigned x, unsigned y); - alwaysinline uint16 get_color(unsigned palette); - alwaysinline uint16 get_direct_color(unsigned palette, unsigned tile); - alwaysinline uint16 fixed_color() const; - - void serialize(serializer&); Screen(PPU& self); + auto scanline() -> void; + alwaysinline auto run() -> void; + auto reset() -> void; + + auto get_pixel_sub(bool hires) -> uint16; + auto get_pixel_main() -> uint16; + auto addsub(uint x, uint y) -> uint16; + alwaysinline auto get_color(uint palette) -> uint16; + alwaysinline auto get_direct_color(uint palette, uint tile) -> uint16; + alwaysinline auto fixed_color() const -> uint16; + + auto serialize(serializer&) -> void; + PPU& self; friend class PPU; }; diff --git a/sfc/ppu/serialization.cpp b/sfc/ppu/serialization.cpp index bba07305..cc064d7f 100644 --- a/sfc/ppu/serialization.cpp +++ b/sfc/ppu/serialization.cpp @@ -1,6 +1,4 @@ -#ifdef PPU_CPP - -void PPUcounter::serialize(serializer& s) { +auto PPUcounter::serialize(serializer& s) -> void { s.integer(status.interlace); s.integer(status.field); s.integer(status.vcounter); @@ -12,7 +10,7 @@ void PPUcounter::serialize(serializer& s) { s.integer(history.index); } -void PPU::serialize(serializer& s) { +auto PPU::serialize(serializer& s) -> void { Thread::serialize(s); PPUcounter::serialize(s); @@ -90,9 +88,7 @@ void PPU::serialize(serializer& s) { screen.serialize(s); } -void PPU::Background::serialize(serializer& s) { - s.integer(id); - +auto PPU::Background::serialize(serializer& s) -> void { s.integer(regs.tiledata_addr); s.integer(regs.screen_addr); s.integer(regs.screen_size); @@ -140,7 +136,7 @@ void PPU::Background::serialize(serializer& s) { s.array(data); } -void PPU::Sprite::serialize(serializer& s) { +auto PPU::Sprite::serialize(serializer& s) -> void { for(unsigned i = 0; i < 128; i++) { s.integer(list[i].x); s.integer(list[i].y); @@ -198,7 +194,7 @@ void PPU::Sprite::serialize(serializer& s) { s.integer(output.sub.palette); } -void PPU::Window::serialize(serializer& s) { +auto PPU::Window::serialize(serializer& s) -> void { s.integer(regs.bg1_one_enable); s.integer(regs.bg1_one_invert); s.integer(regs.bg1_two_enable); @@ -263,7 +259,7 @@ void PPU::Window::serialize(serializer& s) { s.integer(two); } -void PPU::Screen::serialize(serializer& s) { +auto PPU::Screen::serialize(serializer& s) -> void { s.integer(regs.addsub_mode); s.integer(regs.direct_color); @@ -288,5 +284,3 @@ void PPU::Screen::serialize(serializer& s) { s.integer(math.addsub_mode); s.integer(math.color_halve); } - -#endif diff --git a/sfc/ppu/sprite/list.cpp b/sfc/ppu/sprite/list.cpp index 4e35742b..fd9114a0 100644 --- a/sfc/ppu/sprite/list.cpp +++ b/sfc/ppu/sprite/list.cpp @@ -1,8 +1,6 @@ -#ifdef PPU_CPP - -void PPU::Sprite::update(unsigned addr, uint8 data) { +auto PPU::Sprite::update(uint addr, uint8 data) -> void { if(addr < 0x0200) { - unsigned n = addr >> 2; + uint n = addr >> 2; addr &= 3; if(addr == 0) { list[n].x = (list[n].x & 0x100) | data; @@ -18,7 +16,7 @@ void PPU::Sprite::update(unsigned addr, uint8 data) { list[n].nameselect = data & 1; } } else { - unsigned n = (addr & 0x1f) << 2; + uint n = (addr & 0x1f) << 2; list[n + 0].x = ((data & 0x01) << 8) | (list[n + 0].x & 0xff); list[n + 0].size = data & 0x02; list[n + 1].x = ((data & 0x04) << 6) | (list[n + 1].x & 0xff); @@ -30,29 +28,27 @@ void PPU::Sprite::update(unsigned addr, uint8 data) { } } -void PPU::Sprite::synchronize() { - for(unsigned n = 0; n < 544; n++) update(n, ppu.oam[n]); +auto PPU::Sprite::synchronize() -> void { + for(uint n = 0; n < 544; n++) update(n, ppu.oam[n]); } -unsigned PPU::Sprite::SpriteItem::width() const { +auto PPU::Sprite::SpriteItem::width() const -> uint{ if(size == 0) { - static unsigned width[] = { 8, 8, 8, 16, 16, 32, 16, 16}; + static uint width[] = { 8, 8, 8, 16, 16, 32, 16, 16}; return width[ppu.sprite.regs.base_size]; } else { - static unsigned width[] = {16, 32, 64, 32, 64, 64, 32, 32}; + static uint width[] = {16, 32, 64, 32, 64, 64, 32, 32}; return width[ppu.sprite.regs.base_size]; } } -unsigned PPU::Sprite::SpriteItem::height() const { +auto PPU::Sprite::SpriteItem::height() const -> uint { if(size == 0) { if(ppu.sprite.regs.interlace && ppu.sprite.regs.base_size >= 6) return 16; - static unsigned height[] = { 8, 8, 8, 16, 16, 32, 32, 32}; + static uint height[] = { 8, 8, 8, 16, 16, 32, 32, 32}; return height[ppu.sprite.regs.base_size]; } else { - static unsigned height[] = {16, 32, 64, 32, 64, 64, 64, 32}; + static uint height[] = {16, 32, 64, 32, 64, 64, 64, 32}; return height[ppu.sprite.regs.base_size]; } } - -#endif diff --git a/sfc/ppu/sprite/sprite.cpp b/sfc/ppu/sprite/sprite.cpp index a88016e0..68e82501 100644 --- a/sfc/ppu/sprite/sprite.cpp +++ b/sfc/ppu/sprite/sprite.cpp @@ -1,22 +1,23 @@ -#ifdef PPU_CPP - #include "list.cpp" -void PPU::Sprite::address_reset() { +PPU::Sprite::Sprite(PPU& self) : self(self) { +} + +auto PPU::Sprite::address_reset() -> void { self.regs.oam_addr = self.regs.oam_baseaddr; set_first_sprite(); } -void PPU::Sprite::set_first_sprite() { +auto PPU::Sprite::set_first_sprite() -> void { regs.first_sprite = (self.regs.oam_priority == false ? 0 : (self.regs.oam_addr >> 2) & 127); } -void PPU::Sprite::frame() { +auto PPU::Sprite::frame() -> void { regs.time_over = false; regs.range_over = false; } -void PPU::Sprite::scanline() { +auto PPU::Sprite::scanline() -> void { t.x = 0; t.y = self.vcounter(); @@ -45,7 +46,7 @@ void PPU::Sprite::scanline() { } } -bool PPU::Sprite::on_scanline(SpriteItem& sprite) { +auto PPU::Sprite::on_scanline(SpriteItem& sprite) -> bool { if(sprite.x > 256 && (sprite.x + sprite.width() - 1) < 512) return false; signed height = (regs.interlace == false ? sprite.height() : (sprite.height() >> 1)); if(t.y >= sprite.y && t.y < (sprite.y + height)) return true; @@ -53,7 +54,7 @@ bool PPU::Sprite::on_scanline(SpriteItem& sprite) { return false; } -void PPU::Sprite::run() { +auto PPU::Sprite::run() -> void { output.main.priority = 0; output.sub.priority = 0; @@ -89,7 +90,7 @@ void PPU::Sprite::run() { } } -void PPU::Sprite::tilefetch() { +auto PPU::Sprite::tilefetch() -> void { auto oam_item = t.item[t.active]; auto oam_tile = t.tile[t.active]; @@ -159,7 +160,7 @@ void PPU::Sprite::tilefetch() { regs.range_over |= (t.item_count > 32); } -void PPU::Sprite::reset() { +auto PPU::Sprite::reset() -> void { for(unsigned i = 0; i < 128; i++) { list[i].x = 0; list[i].y = 0; @@ -216,8 +217,3 @@ void PPU::Sprite::reset() { output.sub.palette = 0; output.sub.priority = 0; } - -PPU::Sprite::Sprite(PPU& self) : self(self) { -} - -#endif diff --git a/sfc/ppu/sprite/sprite.hpp b/sfc/ppu/sprite/sprite.hpp index 0898db6c..2f1542a5 100644 --- a/sfc/ppu/sprite/sprite.hpp +++ b/sfc/ppu/sprite/sprite.hpp @@ -9,8 +9,8 @@ struct Sprite { uint8 priority; uint8 palette; bool size; - alwaysinline unsigned width() const; - alwaysinline unsigned height() const; + alwaysinline auto width() const -> uint; + alwaysinline auto height() const -> uint; } list[128]; struct TileItem { @@ -22,11 +22,11 @@ struct Sprite { }; struct State { - unsigned x; - unsigned y; + uint x; + uint y; - unsigned item_count; - unsigned tile_count; + uint item_count; + uint tile_count; bool active; uint8 item[2][32]; @@ -43,10 +43,10 @@ struct Sprite { uint16 tiledata_addr; uint8 first_sprite; - unsigned priority0; - unsigned priority1; - unsigned priority2; - unsigned priority3; + uint priority0; + uint priority1; + uint priority2; + uint priority3; bool time_over; bool range_over; @@ -54,28 +54,29 @@ struct Sprite { struct Output { struct Pixel { - unsigned priority; //0 = none (transparent) + uint priority; //0 = none (transparent) uint8 palette; } main, sub; } output; + Sprite(PPU& self); + //list.cpp - void update(unsigned addr, uint8 data); - void synchronize(); + auto update(uint addr, uint8 data) -> void; + auto synchronize() -> void; //sprite.cpp - alwaysinline void address_reset(); - alwaysinline void set_first_sprite(); - void frame(); - void scanline(); - void run(); - void tilefetch(); - void reset(); + alwaysinline auto address_reset() -> void; + alwaysinline auto set_first_sprite() -> void; + auto frame() -> void; + auto scanline() -> void; + auto run() -> void; + auto tilefetch() -> void; + auto reset() -> void; - bool on_scanline(SpriteItem&); + auto on_scanline(SpriteItem&) -> bool; - void serialize(serializer&); - Sprite(PPU& self); + auto serialize(serializer&) -> void; PPU& self; friend class PPU; diff --git a/sfc/ppu/window/window.cpp b/sfc/ppu/window/window.cpp index 2288800d..0356d118 100644 --- a/sfc/ppu/window/window.cpp +++ b/sfc/ppu/window/window.cpp @@ -1,10 +1,11 @@ -#ifdef PPU_CPP +PPU::Window::Window(PPU& self) : self(self) { +} -void PPU::Window::scanline() { +auto PPU::Window::scanline() -> void { x = 0; } -void PPU::Window::run() { +auto PPU::Window::run() -> void { bool main, sub; one = (x >= regs.one_left && x <= regs.one_right); two = (x >= regs.two_left && x <= regs.two_right); @@ -80,12 +81,12 @@ void PPU::Window::run() { output.sub.color_enable = sub; } -void PPU::Window::test( +auto PPU::Window::test( bool& main, bool& sub, bool one_enable, bool one_invert, bool two_enable, bool two_invert, uint8 mask, bool main_enable, bool sub_enable -) { +) -> void { bool one = Window::one ^ one_invert; bool two = Window::two ^ two_invert; bool output; @@ -109,7 +110,7 @@ void PPU::Window::test( sub = sub_enable ? output : false; } -void PPU::Window::reset() { +auto PPU::Window::reset() -> void { regs.bg1_one_enable = random(false); regs.bg1_one_invert = random(false); regs.bg1_two_enable = random(false); @@ -164,8 +165,3 @@ void PPU::Window::reset() { one = 0; two = 0; } - -PPU::Window::Window(PPU& self) : self(self) { -} - -#endif diff --git a/sfc/ppu/window/window.hpp b/sfc/ppu/window/window.hpp index 56af8a79..27985570 100644 --- a/sfc/ppu/window/window.hpp +++ b/sfc/ppu/window/window.hpp @@ -64,24 +64,25 @@ struct Window { } output; struct { - unsigned x; + uint x; bool one; bool two; }; - void scanline(); - void run(); - void reset(); + Window(PPU& self); - void test( + auto scanline() -> void; + auto run() -> void; + auto reset() -> void; + + auto test( bool& main, bool& sub, bool one_enable, bool one_invert, bool two_enable, bool two_invert, uint8 mask, bool main_enable, bool sub_enable - ); + ) -> void; - void serialize(serializer&); - Window(PPU& self); + auto serialize(serializer&) -> void; PPU& self; friend class PPU; diff --git a/sfc/scheduler/scheduler.cpp b/sfc/scheduler/scheduler.cpp index 2b332d94..ba69f7d2 100644 --- a/sfc/scheduler/scheduler.cpp +++ b/sfc/scheduler/scheduler.cpp @@ -1,5 +1,3 @@ -#ifdef SYSTEM_CPP - Scheduler scheduler; auto Scheduler::init() -> void { @@ -22,5 +20,3 @@ auto Scheduler::exit(ExitReason reason) -> void { auto Scheduler::debug() -> void { exit(ExitReason::DebuggerEvent); } - -#endif diff --git a/sfc/scheduler/scheduler.hpp b/sfc/scheduler/scheduler.hpp index acd850d6..024b65fd 100644 --- a/sfc/scheduler/scheduler.hpp +++ b/sfc/scheduler/scheduler.hpp @@ -1,6 +1,6 @@ struct Scheduler { - enum class SynchronizeMode : unsigned { None, CPU, All } sync; - enum class ExitReason : unsigned { UnknownEvent, FrameEvent, SynchronizeEvent, DebuggerEvent }; + enum class SynchronizeMode : uint { None, CPU, All } sync; + enum class ExitReason : uint { UnknownEvent, FrameEvent, SynchronizeEvent, DebuggerEvent }; auto init() -> void; auto enter() -> void; diff --git a/sfc/sfc.hpp b/sfc/sfc.hpp index e368ea5f..dc13b736 100644 --- a/sfc/sfc.hpp +++ b/sfc/sfc.hpp @@ -63,7 +63,7 @@ namespace SuperFamicom { #include #include #include - #include + #include #include #include #include diff --git a/sfc/slot/satellaview/satellaview.cpp b/sfc/slot/satellaview/satellaview.cpp index f74d54b5..5f4f61bb 100644 --- a/sfc/slot/satellaview/satellaview.cpp +++ b/sfc/slot/satellaview/satellaview.cpp @@ -1,6 +1,5 @@ #include -#define SATELLAVIEW_CARTRIDGE_CPP namespace SuperFamicom { SatellaviewCartridge satellaviewcartridge; diff --git a/sfc/slot/sufamiturbo/serialization.cpp b/sfc/slot/sufamiturbo/serialization.cpp index 3eb08baf..0f97d98c 100644 --- a/sfc/slot/sufamiturbo/serialization.cpp +++ b/sfc/slot/sufamiturbo/serialization.cpp @@ -1,7 +1,3 @@ -#ifdef SUFAMITURBO_CPP - auto SufamiTurboCartridge::serialize(serializer& s) -> void { s.array(ram.data(), ram.size()); } - -#endif diff --git a/sfc/slot/sufamiturbo/sufamiturbo.cpp b/sfc/slot/sufamiturbo/sufamiturbo.cpp index 491769a5..983fbe0d 100644 --- a/sfc/slot/sufamiturbo/sufamiturbo.cpp +++ b/sfc/slot/sufamiturbo/sufamiturbo.cpp @@ -1,6 +1,5 @@ #include -#define SUFAMITURBO_CPP namespace SuperFamicom { #include "serialization.cpp" diff --git a/sfc/smp/memory.cpp b/sfc/smp/memory.cpp index 9d1ea156..63a36f50 100644 --- a/sfc/smp/memory.cpp +++ b/sfc/smp/memory.cpp @@ -1,5 +1,3 @@ -#ifdef SMP_CPP - alwaysinline auto SMP::ramRead(uint16 addr) -> uint8 { if(addr >= 0xffc0 && status.iplromEnable) return iplrom[addr & 0x3f]; if(status.ramDisable) return 0x5a; //0xff on mini-SNES @@ -41,7 +39,7 @@ auto SMP::busRead(uint16 addr) -> uint8 { case 0xf6: //CPUIO2 case 0xf7: //CPUIO3 synchronizeCPU(); - return cpu.port_read(addr); + return cpu.portRead(addr); case 0xf8: //RAM0 return status.ram00f8; @@ -100,12 +98,12 @@ auto SMP::busWrite(uint16 addr, uint8 data) -> void { //emulated by simulating CPU writes of 0x00 synchronizeCPU(); if(data & 0x20) { - cpu.port_write(2, 0x00); - cpu.port_write(3, 0x00); + cpu.portWrite(2, 0x00); + cpu.portWrite(3, 0x00); } if(data & 0x10) { - cpu.port_write(0, 0x00); - cpu.port_write(1, 0x00); + cpu.portWrite(0, 0x00); + cpu.portWrite(1, 0x00); } } @@ -201,5 +199,3 @@ auto SMP::disassembler_read(uint16 addr) -> uint8 { if((addr & 0xffc0) == 0xffc0 && status.iplromEnable) return iplrom[addr & 0x3f]; return apuram[addr]; } - -#endif diff --git a/sfc/smp/serialization.cpp b/sfc/smp/serialization.cpp index 1ec385ec..47310970 100644 --- a/sfc/smp/serialization.cpp +++ b/sfc/smp/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SMP_CPP - auto SMP::serialize(serializer& s) -> void { SPC700::serialize(s); Thread::serialize(s); @@ -48,5 +46,3 @@ auto SMP::serialize(serializer& s) -> void { s.integer(timer2.enable); s.integer(timer2.target); } - -#endif diff --git a/sfc/smp/smp.cpp b/sfc/smp/smp.cpp index f3c53885..78fb9f52 100644 --- a/sfc/smp/smp.cpp +++ b/sfc/smp/smp.cpp @@ -1,6 +1,5 @@ #include -#define SMP_CPP namespace SuperFamicom { SMP smp; diff --git a/sfc/smp/timing.cpp b/sfc/smp/timing.cpp index ef1f0e06..a73c816b 100644 --- a/sfc/smp/timing.cpp +++ b/sfc/smp/timing.cpp @@ -1,5 +1,3 @@ -#ifdef SMP_CPP - auto SMP::addClocks(uint clocks) -> void { step(clocks); synchronizeDSP(); @@ -58,5 +56,3 @@ auto SMP::Timer::synchronizeStage1() -> void { stage2 = 0; stage3++; } - -#endif diff --git a/sfc/system/audio.cpp b/sfc/system/audio.cpp index 24454f6c..369fd2f3 100644 --- a/sfc/system/audio.cpp +++ b/sfc/system/audio.cpp @@ -1,5 +1,3 @@ -#ifdef SYSTEM_CPP - Audio audio; void Audio::coprocessor_enable(bool state) { @@ -65,5 +63,3 @@ void Audio::flush() { ); } } - -#endif diff --git a/sfc/system/device.cpp b/sfc/system/device.cpp index 7a6f2797..194725fb 100644 --- a/sfc/system/device.cpp +++ b/sfc/system/device.cpp @@ -1,11 +1,9 @@ -#ifdef SYSTEM_CPP - Device device; Device::Device() { - connect(0, ID::Gamepad); - connect(1, ID::Gamepad); - connect(2, ID::eBoot); + connect(0, ID::None); + connect(1, ID::None); + connect(2, ID::None); } Device::~Device() { @@ -43,5 +41,3 @@ auto Device::connect(uint port, Device::ID id) -> void { configuration.expansionPort = id; } } - -#endif diff --git a/sfc/system/serialization.cpp b/sfc/system/serialization.cpp index 1a8a05e9..a2c3bb0d 100644 --- a/sfc/system/serialization.cpp +++ b/sfc/system/serialization.cpp @@ -1,5 +1,3 @@ -#ifdef SYSTEM_CPP - auto System::serialize() -> serializer { serializer s(serializeSize); @@ -93,5 +91,3 @@ auto System::serializeInit() -> void { serializeAll(s); serializeSize = s.size(); } - -#endif diff --git a/sfc/system/system.cpp b/sfc/system/system.cpp index 8869dbd8..f82ba3a9 100644 --- a/sfc/system/system.cpp +++ b/sfc/system/system.cpp @@ -1,6 +1,5 @@ #include -#define SYSTEM_CPP namespace SuperFamicom { System system; @@ -70,7 +69,7 @@ auto System::init() -> void { assert(interface != nullptr); eboot.init(); - satellaviewbaseunit.init(); + satellaview.init(); icd2.init(); mcc.init(); @@ -124,7 +123,7 @@ auto System::load() -> void { cpu.enable(); ppu.enable(); - if(expansionPort() == Device::ID::Satellaview) satellaviewbaseunit.load(); + if(expansionPort() == Device::ID::Satellaview) satellaview.load(); if(expansionPort() == Device::ID::eBoot) eboot.load(); if(cartridge.hasICD2()) icd2.load(); @@ -150,7 +149,7 @@ auto System::load() -> void { } auto System::unload() -> void { - if(expansionPort() == Device::ID::Satellaview) satellaviewbaseunit.unload(); + if(expansionPort() == Device::ID::Satellaview) satellaview.unload(); if(expansionPort() == Device::ID::eBoot) eboot.unload(); if(cartridge.hasICD2()) icd2.unload(); @@ -181,7 +180,7 @@ auto System::power() -> void { dsp.power(); ppu.power(); - if(expansionPort() == Device::ID::Satellaview) satellaviewbaseunit.power(); + if(expansionPort() == Device::ID::Satellaview) satellaview.power(); if(expansionPort() == Device::ID::eBoot) eboot.power(); if(cartridge.hasICD2()) icd2.power(); @@ -211,7 +210,7 @@ auto System::reset() -> void { dsp.reset(); ppu.reset(); - if(expansionPort() == Device::ID::Satellaview) satellaviewbaseunit.reset(); + if(expansionPort() == Device::ID::Satellaview) satellaview.reset(); if(expansionPort() == Device::ID::eBoot) eboot.reset(); if(cartridge.hasICD2()) icd2.reset(); diff --git a/sfc/system/system.hpp b/sfc/system/system.hpp index ca4b93b5..9682867a 100644 --- a/sfc/system/system.hpp +++ b/sfc/system/system.hpp @@ -55,9 +55,9 @@ extern System system; #include struct Configuration { - Device::ID controllerPort1 = Device::ID::Gamepad; - Device::ID controllerPort2 = Device::ID::Gamepad; - Device::ID expansionPort = Device::ID::eBoot; + Device::ID controllerPort1 = Device::ID::None; + Device::ID controllerPort2 = Device::ID::None; + Device::ID expansionPort = Device::ID::None; System::Region region = System::Region::Autodetect; bool random = true; }; diff --git a/sfc/system/video.cpp b/sfc/system/video.cpp index a9b65fed..dcb1867e 100644 --- a/sfc/system/video.cpp +++ b/sfc/system/video.cpp @@ -1,5 +1,3 @@ -#ifdef SYSTEM_CPP - Video video; void Video::generate_palette(Emulator::Interface::PaletteMode mode) { @@ -163,5 +161,3 @@ void Video::init() { hires = false; for(auto& n : line_width) n = 256; } - -#endif diff --git a/target-tomoko/configuration/configuration.cpp b/target-tomoko/configuration/configuration.cpp index 0be6bc01..09e545b7 100644 --- a/target-tomoko/configuration/configuration.cpp +++ b/target-tomoko/configuration/configuration.cpp @@ -1,5 +1,6 @@ #include "../tomoko.hpp" ConfigurationManager* config = nullptr; +EmulatorSettings* emulatorSettings = nullptr; ConfigurationManager::ConfigurationManager() { config = this; @@ -54,3 +55,22 @@ ConfigurationManager::ConfigurationManager() { auto ConfigurationManager::quit() -> void { save(locate({configpath(), "tomoko/"}, "settings.bml")); } + +EmulatorSettings::EmulatorSettings() { + emulatorSettings = this; + (Markup::Node&)*this = BML::unserialize(string::read(locate({configpath(), "tomoko/"}, "emulators.bml"))); +} + +auto EmulatorSettings::quit() -> void { + file::write(locate({configpath(), "tomoko/"}, "emulators.bml"), BML::serialize(*this)); +} + +auto EmulatorSettings::get(string name) -> string { + name.replace(" ", ""); + return (*this)(name).text(); +} + +auto EmulatorSettings::set(string name, string value) -> void { + name.replace(" ", ""); + (*this)(name).setValue(value); +} diff --git a/target-tomoko/configuration/configuration.hpp b/target-tomoko/configuration/configuration.hpp index 7f506329..4052dc5e 100644 --- a/target-tomoko/configuration/configuration.hpp +++ b/target-tomoko/configuration/configuration.hpp @@ -50,4 +50,13 @@ struct ConfigurationManager : Configuration::Document { } timing; }; +struct EmulatorSettings : Markup::Node { + EmulatorSettings(); + auto quit() -> void; + + auto get(string name) -> string; + auto set(string name, string value) -> void; +}; + extern ConfigurationManager* config; +extern EmulatorSettings* emulatorSettings; diff --git a/target-tomoko/presentation/presentation.cpp b/target-tomoko/presentation/presentation.cpp index 256c5bd3..bf84db30 100644 --- a/target-tomoko/presentation/presentation.cpp +++ b/target-tomoko/presentation/presentation.cpp @@ -127,11 +127,22 @@ auto Presentation::updateEmulator() -> void { for(auto& device : port.device) { MenuRadioItem item{&menu}; item.setText(device.name).onActivate([=] { + emulatorSettings->set({emulator->information.name, "/", port.name}, device.name); emulator->connect(port.id, device.id); }); devices.append(item); } - if(devices.objectCount() > 1) menu.setVisible(); + if(devices.objectCount() > 1) { + string device = emulatorSettings->get({emulator->information.name, "/", port.name}); + for(auto object : devices.objects()) { + if(auto item = dynamic_cast(object.data())) { + if(item->text() == device) { + item->setChecked().doActivate(); + } + } + } + menu.setVisible(); + } } systemMenuSeparatorPorts.setVisible(inputPort1.visible() || inputPort2.visible() || inputPort3.visible()); diff --git a/target-tomoko/program/program.cpp b/target-tomoko/program/program.cpp index 9617c496..ec919659 100644 --- a/target-tomoko/program/program.cpp +++ b/target-tomoko/program/program.cpp @@ -22,6 +22,7 @@ Program::Program(lstring args) { for(auto& emulator : emulators) emulator->bind = this; new ConfigurationManager; + new EmulatorSettings; new InputManager; new SettingsManager; new CheatDatabase; @@ -96,6 +97,7 @@ auto Program::main() -> void { auto Program::quit() -> void { unloadMedia(); config->quit(); + emulatorSettings->quit(); inputManager->quit(); delete video; delete audio;