diff --git a/bsnes/Makefile b/bsnes/Makefile index 00110304..dbd165fc 100755 --- a/bsnes/Makefile +++ b/bsnes/Makefile @@ -11,7 +11,7 @@ ui := ui # compiler c := $(compiler) -std=gnu99 cpp := $(subst cc,++,$(compiler)) -std=gnu++0x -flags := -I. -O3 -fomit-frame-pointer +flags := -I. -march=native -O3 -fomit-frame-pointer link := objects := libco diff --git a/bsnes/base/base.hpp b/bsnes/base/base.hpp index be8b356d..d3e33cd6 100755 --- a/bsnes/base/base.hpp +++ b/bsnes/base/base.hpp @@ -1,7 +1,7 @@ #ifndef BASE_HPP #define BASE_HPP -const char Version[] = "086.02"; +const char Version[] = "086.03"; #include #include diff --git a/bsnes/snes/cartridge/cartridge.cpp b/bsnes/snes/cartridge/cartridge.cpp index 5187732d..fdfff8a0 100755 --- a/bsnes/snes/cartridge/cartridge.cpp +++ b/bsnes/snes/cartridge/cartridge.cpp @@ -34,7 +34,7 @@ void Cartridge::load(Mode cartridge_mode, const char *markup) { nvram.reset(); parse_markup(markup); - print(markup, "\n\n"); +//print(markup, "\n\n"); if(ram_size > 0) { ram.map(allocate(ram_size, 0xff), ram_size); diff --git a/bsnes/snes/ppu/background/background.cpp b/bsnes/snes/ppu/background/background.cpp index a3628e34..d989323b 100755 --- a/bsnes/snes/ppu/background/background.cpp +++ b/bsnes/snes/ppu/background/background.cpp @@ -127,19 +127,18 @@ void PPU::Background::get_tile() { if(mirror_y) voffset ^= 7; offset = (character << (4 + color_depth)) + ((voffset & 7) << 1); - if(regs.mode >= Mode::BPP2) { - data[0] = ppu.vram[offset + 0]; - data[1] = ppu.vram[offset + 1]; - } - if(regs.mode >= Mode::BPP4) { - data[2] = ppu.vram[offset + 16]; - data[3] = ppu.vram[offset + 17]; - } - if(regs.mode >= Mode::BPP8) { - data[4] = ppu.vram[offset + 32]; - data[5] = ppu.vram[offset + 33]; - data[6] = ppu.vram[offset + 48]; + switch(regs.mode) { + case Mode::BPP8: data[7] = ppu.vram[offset + 49]; + data[6] = ppu.vram[offset + 48]; + data[5] = ppu.vram[offset + 33]; + data[4] = ppu.vram[offset + 32]; + case Mode::BPP4: + data[3] = ppu.vram[offset + 17]; + data[2] = ppu.vram[offset + 16]; + case Mode::BPP2: + data[1] = ppu.vram[offset + 1]; + data[0] = ppu.vram[offset + 0]; } if(mirror_x) for(unsigned n = 0; n < 8; n++) { @@ -160,7 +159,6 @@ void PPU::Background::run(bool screen) { if(hires == false) return; } - if(regs.main_enable == false && regs.sub_enable == false) return; if(regs.mode == Mode::Inactive) return; if(regs.mode == Mode::Mode7) return run_mode7(); @@ -186,20 +184,21 @@ void PPU::Background::run(bool screen) { unsigned PPU::Background::get_tile_color() { unsigned color = 0; - if(regs.mode >= Mode::BPP2) { - color += (data[0] & 0x80) ? 0x01 : 0; data[0] <<= 1; - color += (data[1] & 0x80) ? 0x02 : 0; data[1] <<= 1; - } - if(regs.mode >= Mode::BPP4) { - color += (data[2] & 0x80) ? 0x04 : 0; data[2] <<= 1; - color += (data[3] & 0x80) ? 0x08 : 0; data[3] <<= 1; - } - if(regs.mode >= Mode::BPP8) { - color += (data[4] & 0x80) ? 0x10 : 0; data[4] <<= 1; - color += (data[5] & 0x80) ? 0x20 : 0; data[5] <<= 1; - color += (data[6] & 0x80) ? 0x40 : 0; data[6] <<= 1; - color += (data[7] & 0x80) ? 0x80 : 0; data[7] <<= 1; + + switch(regs.mode) { + case Mode::BPP8: + color += (data[7] >> 0) & 0x80; data[7] <<= 1; + color += (data[6] >> 1) & 0x40; data[6] <<= 1; + color += (data[5] >> 2) & 0x20; data[5] <<= 1; + color += (data[4] >> 3) & 0x10; data[4] <<= 1; + case Mode::BPP4: + color += (data[3] >> 4) & 0x08; data[3] <<= 1; + color += (data[2] >> 5) & 0x04; data[2] <<= 1; + case Mode::BPP2: + color += (data[1] >> 6) & 0x02; data[1] <<= 1; + color += (data[0] >> 7) & 0x01; data[0] <<= 1; } + return color; } diff --git a/bsnes/snes/ppu/ppu.cpp b/bsnes/snes/ppu/ppu.cpp index 9117090a..34fde244 100755 --- a/bsnes/snes/ppu/ppu.cpp +++ b/bsnes/snes/ppu/ppu.cpp @@ -33,7 +33,7 @@ void PPU::enter() { } scanline(); - add_clocks(60); + add_clocks(68); bg1.begin(); bg2.begin(); bg3.begin(); @@ -59,13 +59,13 @@ void PPU::enter() { add_clocks(2); } - add_clocks(22); + add_clocks(14); sprite.tilefetch(); } else { - add_clocks(1052 + 22 + 136); + add_clocks(1052 + 14 + 136); } - add_clocks(lineclocks() - 60 - 1052 - 22 - 136); + add_clocks(lineclocks() - 68 - 1052 - 14 - 136); } } diff --git a/bsnes/ui/interface/gameboy/gameboy.cpp b/bsnes/ui/interface/gameboy/gameboy.cpp index 8ee13ae6..0fc8c4f2 100755 --- a/bsnes/ui/interface/gameboy/gameboy.cpp +++ b/bsnes/ui/interface/gameboy/gameboy.cpp @@ -8,6 +8,8 @@ bool InterfaceGameBoy::cartridgeLoaded() { } bool InterfaceGameBoy::loadCartridge(GameBoy::System::Revision revision, const string &filename) { + interface->unloadCartridge(); + uint8_t *data; unsigned size; @@ -19,7 +21,6 @@ bool InterfaceGameBoy::loadCartridge(GameBoy::System::Revision revision, const s interface->base = { false, nall::basename(filename) }; } - interface->unloadCartridge(); interface->game = interface->base; interface->cartridgeTitle = interface->base.title(); interface->applyPatch(interface->base, data, size); diff --git a/bsnes/ui/interface/nes/nes.cpp b/bsnes/ui/interface/nes/nes.cpp index 1120e593..5147c9e7 100755 --- a/bsnes/ui/interface/nes/nes.cpp +++ b/bsnes/ui/interface/nes/nes.cpp @@ -23,6 +23,8 @@ bool InterfaceNES::cartridgeLoaded() { } bool InterfaceNES::loadCartridge(const string &filename) { + interface->unloadCartridge(); + uint8_t *data; unsigned size; @@ -47,7 +49,6 @@ bool InterfaceNES::loadCartridge(const string &filename) { interface->base = { false, nall::basename(filename) }; } - interface->unloadCartridge(); interface->game = interface->base; interface->cartridgeTitle = interface->base.title(); interface->applyPatch(interface->base, data, size); diff --git a/bsnes/ui/interface/snes/snes.cpp b/bsnes/ui/interface/snes/snes.cpp index 6b5e3a69..1c342083 100755 --- a/bsnes/ui/interface/snes/snes.cpp +++ b/bsnes/ui/interface/snes/snes.cpp @@ -49,11 +49,12 @@ bool InterfaceSNES::loadCartridge(const string &filename, CartridgePath &cartrid } bool InterfaceSNES::loadCartridge(string basename) { + interface->unloadCartridge(); + uint8_t *data; unsigned size; if(loadCartridge(basename, interface->base, data, size) == false) return false; - interface->unloadCartridge(); interface->game = interface->base; interface->cartridgeTitle = interface->base.title(); @@ -74,12 +75,13 @@ bool InterfaceSNES::loadCartridge(string basename) { } bool InterfaceSNES::loadSatellaviewSlottedCartridge(string basename, string slotname) { + interface->unloadCartridge(); + uint8_t *data[2]; unsigned size[2]; if(loadCartridge(basename, interface->base, data[0], size[0]) == false) return false; loadCartridge(slotname, interface->slot[0], data[1], size[1]); - interface->unloadCartridge(); interface->game = !data[1] ? interface->base : interface->slot[0]; //TODO: subfolder for folders; concatenation for files interface->cartridgeTitle = interface->base.title(); if(data[1]) interface->cartridgeTitle.append(" + ", interface->slot[0].title()); @@ -103,12 +105,13 @@ bool InterfaceSNES::loadSatellaviewSlottedCartridge(string basename, string slot } bool InterfaceSNES::loadSatellaviewCartridge(string basename, string slotname) { + interface->unloadCartridge(); + uint8_t *data[2]; unsigned size[2]; if(loadCartridge(basename, interface->base, data[0], size[0]) == false) return false; loadCartridge(slotname, interface->slot[0], data[1], size[1]); - interface->unloadCartridge(); interface->game = !data[1] ? interface->base : interface->slot[0]; interface->cartridgeTitle = interface->base.title(); if(data[1]) interface->cartridgeTitle = interface->slot[0].title(); @@ -132,13 +135,14 @@ bool InterfaceSNES::loadSatellaviewCartridge(string basename, string slotname) { } bool InterfaceSNES::loadSufamiTurboCartridge(string basename, string slotAname, string slotBname) { + interface->unloadCartridge(); + uint8_t *data[3]; unsigned size[3]; if(loadCartridge(basename, interface->base, data[0], size[0]) == false) return false; loadCartridge(slotAname, interface->slot[0], data[1], size[1]); loadCartridge(slotBname, interface->slot[1], data[2], size[2]); - interface->unloadCartridge(); interface->game = !data[1] ? interface->base : interface->slot[0]; //TODO: subfolder for folders; concatenation for files interface->cartridgeTitle = interface->base.title(); if( data[1] && !data[2]) interface->cartridgeTitle = interface->slot[0].title(); @@ -168,12 +172,13 @@ bool InterfaceSNES::loadSufamiTurboCartridge(string basename, string slotAname, } bool InterfaceSNES::loadSuperGameBoyCartridge(string basename, string slotname) { + interface->unloadCartridge(); + uint8_t *data[2]; unsigned size[2]; if(loadCartridge(basename, interface->base, data[0], size[0]) == false) return false; loadCartridge(slotname, interface->slot[0], data[1], size[1]); - interface->unloadCartridge(); interface->game = !data[1] ? interface->base : interface->slot[0]; interface->cartridgeTitle = interface->base.title(); if(data[1]) interface->cartridgeTitle = interface->slot[0].title();