Update to bsnes v022 release.

Today marks a milestone for bsnes, and possibly for SNES emulation as a whole. With this new release, bsnes' compatibility has now reached 100.0%, with zero game-specific hacks. With every last commercially released game tested by both FitzRoy and tetsuo55 for at least five minutes each, all known bugs have been resolved.
Now, needless to say, I am referring to the emulation of the base SNES unit. As many SNES cartridges contain additional coprocessors on their PCBs, there are still unplayable titles. So how can I claim compatibility of 100%? Because I don't consider special chips inside game cartridges as part of the base SNES hardware. I realize that many people enjoy these games, and I do actively attempt to emulate as many coprocessors as possible (six are supported thus far). However, coprocessors such as the SuperFX and SA-1 continue to pose very significant challenges.
So, after nearly three years of development, I've finally achieved my primary goal. But it wasn't a complete victory ... I've learned a lot over the years. Emulation accuracy is not black and white -- there are heavy costs to pay and forced tradeoffs to achieve it. I no longer believe there is only one absolute path for emulation, as I did in 2004.
So does this mean bsnes is now perfect? Of course not. There are many technical details that are not emulated correctly. This also does mean that there are no bugs, merely that there are no bugs that we are aware of. While absolute verification of 100% compatibility is obvioulsy impossible, even by actually beating every single game from start to finish, this very well should be the first time any SNES emulator could claim zero known bugs with all known games tested. I very much expect this announcement to entice many new users to begin actively searching for bugs, in an effort to discredit my above claim. My response? Go for it! I would very much appreciate any and all discovered bugs to be posted here, so that they can be verified and addressed.
One major thing that needs to be said, is that there consists of one major hack in all SNES emulators, including bsnes: the use of scanline-based PPU renderers. This necessitates global hacks in all emulators to minimize their inaccuracies. I was going to write up a very long post here, going into specifics, but I've decided an article would be a better place for that. I will hopefully be writing up this article in a few days to post here.
In the meantime, one very important issue does need to be addressed. This version fixes a bug in Uniracers 2-player mode, where the game writes to OAM during active display. Like other PPU global hacks, Uniracers required a special consession. But because this hack only affects one game, it can very fairly be seen as cheating. Suffice to say, bsnes does not contain a game-specific hack, and the change made to fix Uniracers affects all games, but I do still very much consider it to be a hack. The fix I have added is quite literally and honestly more accurate than the behavior of bsnes v0.021. Before, writes to OAM and CGRAM during active display went where a programmer would expect, which would cause bugs when ran on real hardware. Uniracers is the only game known to do this, and it is very dangerous to do so. The writes do go through, but not where one would expect. The access address basically changes as the screen is rendered. With a scanline-based PPU, it is not possible to emulate the individual 
steppings of the PPU, as there is not enough precision. Further, the entire SNES emulation community has virtually no information on how active display OAM and CGRAM writes work. Now, as Uniracers is the only game known to do this, I had the choice of either intentionally remapping the writes to an arbitrary location, or change it to the address Uniracers expects. Neither would be more accurate than the other, as both are completely wrong from a haradware standpoint. So the decision was to either fix Uniracers and deal with some calling it a game-specific hack, or to leave it broken with absolutely no gain to accuracy. Rather than decide for myself, I asked those who have supported me over the past three years for their opinions. The decision was unanimous to fix Uniracers. You can read the discussion, along with a more technical explanation of the issue, here. I will be addressing this topic in much greater detail in the article I will be writing up shortly.
Changelog:
    - Fixed buffer overflow that was manifesting as corrupted tiles in Lemmings 2
    - OAM and CGRAM addresses are now invalidated during active display, however the algorithms for how this address invalidation occurs is currently still unknown, so reads/writes are mapped to static addresses for now
    - Re-added cheat code editor.
    - Windows only: keypresses when main emulation window is not active are ignored once again
This commit is contained in:
byuu 2007-08-04 19:54:35 +00:00
parent e41aa25887
commit c57c733d7d
30 changed files with 408 additions and 218 deletions

View File

@ -53,11 +53,11 @@ information in the header. The lack of such a header indicates said file falls
under the bsnes license.
HQ2x Filter, author: MaxST, license: LGPL
JMA, author: NSRT Team, license: GPL *
JMA, author: NSRT Team, license: GPL (*)
libco, author: byuu, license: public domain
libui, author: byuu, license: public domain
NTSC Filter, author: blargg, license: LGPL
S-DD1, author: Andreas Naive, license: public domain
zlib, license: zlib license
* bsnes has received an exemption from the copyright holder to use this work.
(*) bsnes has received an exemption from the copyright holder to use this work.

View File

@ -1,5 +1,5 @@
bsnes
Version 0.021
Version 0.022
Author: byuu

View File

@ -1,4 +1,4 @@
#define BSNES_VERSION "0.021"
#define BSNES_VERSION "0.022"
#define BSNES_TITLE "bsnes v" BSNES_VERSION
#define MEMCORE bMemBus

View File

@ -89,6 +89,21 @@ IntegerSetting PPU::Hack::obj_cache(&config_file, "ppu.hack.obj_cache",
"This is technically closer to the actual operation of the SNES,\n"
"but can cause problems in some games if enabled",
IntegerSetting::Boolean, false);
IntegerSetting PPU::Hack::oam_address_invalidation(&config_file, "ppu.hack.oam_address_invalidation",
"OAM access address changes during active display, as the S-PPU reads\n"
"data to render the display. Thusly, the address retrieved when accessing\n"
"OAM during active display is unpredictable. Unfortunately, the exact\n"
"algorithm for this is completely unknown at this time. It is more hardware\n"
"accurate to enable this setting, but one must *not* rely on the actual\n"
"address to match hardware under emulation.",
IntegerSetting::Boolean, true);
IntegerSetting PPU::Hack::cgram_address_invalidation(&config_file, "ppu.hack.cgram_address_invalidation",
"CGRAM access address changes during active display (excluding hblank), as\n"
"the S-PPU reads data to render the display. Thusly, as with OAM, the access\n"
"address is unpredictable. Again, enabling this setting is more hardware\n"
"accurate, but one must *not* rely on the actual address to match hardware\n"
"under emulation.",
IntegerSetting::Boolean, true);
IntegerSetting PPU::opt_enable(0, "ppu.opt_enable", "Enable offset-per-tile effects", IntegerSetting::Boolean, true);
IntegerSetting PPU::bg1_pri0_enable(0, "ppu.bg1_pri0_enable", "Enable BG1 Priority 0", IntegerSetting::Boolean, true);

View File

@ -30,6 +30,8 @@ extern struct PPU {
struct Hack {
static IntegerSetting render_scanline_position;
static IntegerSetting obj_cache;
static IntegerSetting oam_address_invalidation;
static IntegerSetting cgram_address_invalidation;
} hack;
static IntegerSetting opt_enable;

View File

@ -1,5 +1,5 @@
/*
libconfig : version 0.14 ~byuu (2007-06-10)
libconfig : version 0.14 ~byuu (2007-06-12)
license: public domain
*/
@ -103,7 +103,7 @@ string data;
bool operator==(const char *x) { return !strcmp(data, x); }
bool operator!=(const char *x) { return strcmp(data, x); }
StringSetting(Config *parent, const char *r_name, const char *r_desc, char *r_data) {
StringSetting(Config *parent, const char *r_name, const char *r_desc, const char *r_data) {
type = Setting::String;
name = strdup(r_name);
desc = strdup(r_desc);

View File

@ -148,8 +148,12 @@ struct {
void cgram_write(uint16 addr, uint8 value);
uint16 get_vram_address();
uint8 vram_mmio_read (uint16 addr);
void vram_mmio_write(uint16 addr, uint8 data);
uint8 vram_mmio_read (uint16 addr);
void vram_mmio_write (uint16 addr, uint8 data);
uint8 oam_mmio_read (uint16 addr);
void oam_mmio_write (uint16 addr, uint8 data);
uint8 cgram_mmio_read (uint16 addr);
void cgram_mmio_write(uint16 addr, uint8 data);
void mmio_w2100(uint8 value); //INIDISP
void mmio_w2101(uint8 value); //OBSEL

View File

@ -16,6 +16,11 @@ uint16 addr;
return (addr << 1);
}
//NOTE: all VRAM writes during active display are invalid. Unlike OAM and CGRAM, they will
//not be written anywhere at all. The below address ranges for where writes are invalid have
//been validated on hardware, as has the edge case where the S-CPU MDR can be written if the
//write occurs during the very last clock cycle of vblank.
uint8 bPPU::vram_mmio_read(uint16 addr) {
if(regs.display_disabled == true) {
return vram_read(addr);
@ -46,20 +51,17 @@ uint16 ls = (r_cpu->region_scanlines() >> 1) - 1;
void bPPU::vram_mmio_write(uint16 addr, uint8 data) {
if(regs.display_disabled == true) {
vram_write(addr, data);
return;
return vram_write(addr, data);
}
uint16 v = r_cpu->vcounter();
uint16 hc = r_cpu->hclock();
if(v == 0) {
if(hc <= 4) {
vram_write(addr, data);
return;
return vram_write(addr, data);
}
if(hc == 6) {
vram_write(addr, r_cpu->regs.mdr);
return;
return vram_write(addr, r_cpu->regs.mdr);
}
return;
}
@ -72,13 +74,87 @@ uint16 hc = r_cpu->hclock();
if(hc <= 4) {
return;
}
vram_write(addr, data);
return;
return vram_write(addr, data);
}
vram_write(addr, data);
}
//NOTE: OAM accesses during active display are rerouted to 0x0218 ... this can be considered
//a hack. The actual address varies during rendering, as the S-PPU reads in data itself for
//processing. Unfortunately, we have yet to determine how this works. The algorithm cannot be
//reverse engineered using a scanline renderer such as this, and at this time, there does not
//exist a more accurate SNES PPU emulator to work from. The only known game to actually access
//OAM during active display is Uniracers. It expects accesses to map to offset 0x0218.
//It was decided by public consensus to map writes to this address to match Uniracers, primarily
//because it is the only game observed to do this, but also because mapping to this address does
//not contradict any of our findings, because we have no findings whatsoever on this behavior.
//Think of this what you will, I openly admit that this is a hack. But it is more accurate than
//writing to the 'expected' address set by $2102,$2103, and will catch problems in software that
//accidentally accesses OAM during active display by virtue of not returning the expected data.
//You may disable this behavior by setting config::ppu.hack.oam_address_invalidation to false,
//or by changing the address from 0x0218 to 0x0000 below if it bothers you that greatly.
uint8 bPPU::oam_mmio_read(uint16 addr) {
if(config::ppu.hack.oam_address_invalidation == false || regs.display_disabled == true) {
return oam_read(addr);
}
uint16 v = r_cpu->vcounter();
if(v < (!r_cpu->overscan() ? 225 : 240)) {
return oam_read(0x0218);
}
return oam_read(addr);
}
void bPPU::oam_mmio_write(uint16 addr, uint8 data) {
if(config::ppu.hack.oam_address_invalidation == false || regs.display_disabled == true) {
return oam_write(addr, data);
}
uint16 v = r_cpu->vcounter();
if(v < (!r_cpu->overscan() ? 225 : 240)) {
return oam_write(0x0218, data);
}
oam_write(addr, data);
}
//NOTE: CGRAM writes during hblank are valid. During active display, the actual address the
//data is written to varies, as the S-PPU itself changes the address. Like OAM, we do not know
//the exact algorithm used, but we have zero known examples of any commercial software that
//attempts to do this. Therefore, the addresses are mapped to 0x0000. There is nothing special
//about this address, it is simply more accurate to invalidate the 'expected' address than not.
uint8 bPPU::cgram_mmio_read(uint16 addr) {
if(config::ppu.hack.cgram_address_invalidation == false || regs.display_disabled == true) {
return cgram_read(addr);
}
uint16 v = r_cpu->vcounter();
uint16 hc = r_cpu->hclock();
if(v < (!r_cpu->overscan() ? 225 : 240) && hc > 0 && hc < 1096) {
return cgram_read(0x0000);
}
return cgram_read(addr);
}
void bPPU::cgram_mmio_write(uint16 addr, uint8 data) {
if(config::ppu.hack.cgram_address_invalidation == false || regs.display_disabled == true) {
return cgram_write(addr, data);
}
uint16 v = r_cpu->vcounter();
uint16 hc = r_cpu->hclock();
if(v < (!r_cpu->overscan() ? 225 : 240) && hc > 0 && hc < 1096) {
return cgram_write(0x0000, data);
}
cgram_write(addr, data);
}
//INIDISP
void bPPU::mmio_w2100(uint8 value) {
if(regs.display_disabled == true && r_cpu->vcounter() == (!r_cpu->overscan() ? 225 : 240)) {
@ -117,12 +193,12 @@ void bPPU::mmio_w2103(uint8 data) {
//OAMDATA
void bPPU::mmio_w2104(uint8 data) {
if(regs.oam_addr & 0x0200) {
oam_write(regs.oam_addr, data);
oam_mmio_write(regs.oam_addr, data);
} else if((regs.oam_addr & 1) == 0) {
regs.oam_latchdata = data;
} else {
oam_write((regs.oam_addr & ~1) + 0, regs.oam_latchdata);
oam_write((regs.oam_addr & ~1) + 1, data);
oam_mmio_write((regs.oam_addr & ~1) + 0, regs.oam_latchdata);
oam_mmio_write((regs.oam_addr & ~1) + 1, data);
}
regs.oam_addr++;
@ -353,8 +429,8 @@ void bPPU::mmio_w2122(uint8 value) {
if(!(regs.cgram_addr & 1)) {
regs.cgram_latchdata = value;
} else {
cgram_write((regs.cgram_addr & 0x01fe), regs.cgram_latchdata);
cgram_write((regs.cgram_addr & 0x01fe) + 1, value & 0x7f);
cgram_mmio_write((regs.cgram_addr & 0x01fe), regs.cgram_latchdata);
cgram_mmio_write((regs.cgram_addr & 0x01fe) + 1, value & 0x7f);
}
regs.cgram_addr++;
regs.cgram_addr &= 0x01ff;
@ -540,7 +616,7 @@ uint8 bPPU::mmio_r2137() {
//OAMDATAREAD
uint8 bPPU::mmio_r2138() {
regs.ppu1_mdr = oam_read(regs.oam_addr);
regs.ppu1_mdr = oam_mmio_read(regs.oam_addr);
regs.oam_addr++;
regs.oam_addr &= 0x03ff;
@ -581,10 +657,10 @@ uint16 addr = get_vram_address() + 1;
//update bit 7 of the PPU2 MDR.
uint8 bPPU::mmio_r213b() {
if(!(regs.cgram_addr & 1)) {
regs.ppu2_mdr = cgram_read(regs.cgram_addr) & 0xff;
regs.ppu2_mdr = cgram_mmio_read(regs.cgram_addr) & 0xff;
} else {
regs.ppu2_mdr &= 0x80;
regs.ppu2_mdr |= cgram_read(regs.cgram_addr) & 0x7f;
regs.ppu2_mdr |= cgram_mmio_read(regs.cgram_addr) & 0x7f;
}
regs.cgram_addr++;
regs.cgram_addr &= 0x01ff;

View File

@ -27,7 +27,9 @@ uint16 bPPU::bg_get_tile(uint8 bg, uint16 x, uint16 y) {
uint16 pos = ((y & 0x1f) << 5) + (x & 0x1f);
if(y & 0x20)pos += bg_info[bg].scy;
if(x & 0x20)pos += bg_info[bg].scx;
return read16(vram, regs.bg_scaddr[bg] + (pos << 1));
uint16 addr = regs.bg_scaddr[bg] + (pos << 1);
return (vram_read(addr + 0) << 0) | (vram_read(addr + 1) << 8);
}
#define setpixel_main(x) \

View File

@ -1,100 +1,4 @@
/*
* interpolation routines are located in: /src/lib/libinterp.h
*/
/*
inline uint Audio::bind_range(uint min, uint max, uint index) {
return index < min ? min : index > max ? max : index;
}
void Audio::resample_point(
uint32 *output, uint32 *input, uint output_samples, uint input_samples
) {
double scalar = double(input_samples--) / double(output_samples--); //convert lengths to upper bounds
double sindex = 0.0;
for(uint x = 0; x <= output_samples; x++) {
uint32 y0 = input[bind_range(0, input_samples, uint32(sindex) + 0)];
uint32 y1 = input[bind_range(0, input_samples, uint32(sindex) + 1)];
double mu = sindex - uint(sindex); //calculate fractional portion of step
uint16 yl = interpolate_point(mu, int16(y0 >> 0), int16(y1 >> 0));
uint16 yr = interpolate_point(mu, int16(y0 >> 16), int16(y1 >> 16));
output[x] = (yl << 0) + (yr << 16);
sindex += scalar;
}
}
void Audio::resample_linear(
uint32 *output, uint32 *input, uint output_samples, uint input_samples
) {
double scalar = double(input_samples--) / double(output_samples--); //convert lengths to upper bounds
double sindex = 0.0;
for(uint x = 0; x <= output_samples; x++) {
uint32 y0 = input[bind_range(0, input_samples, uint32(sindex) + 0)];
uint32 y1 = input[bind_range(0, input_samples, uint32(sindex) + 1)];
double mu = sindex - uint(sindex); //calculate fractional portion of step
uint16 yl = interpolate_linear(mu, int16(y0 >> 0), int16(y1 >> 0));
uint16 yr = interpolate_linear(mu, int16(y0 >> 16), int16(y1 >> 16));
output[x] = (yl << 0) + (yr << 16);
sindex += scalar;
}
}
void Audio::resample_cosine(
uint32 *output, uint32 *input, uint output_samples, uint input_samples
) {
double scalar = double(input_samples--) / double(output_samples--); //convert lengths to upper bounds
double sindex = 0.0;
for(uint x = 0; x <= output_samples; x++) {
uint32 y0 = input[bind_range(0, input_samples, uint32(sindex) + 0)];
uint32 y1 = input[bind_range(0, input_samples, uint32(sindex) + 1)];
double mu = sindex - uint(sindex); //calculate fractional portion of step
uint16 yl = interpolate_cosine(mu, int16(y0 >> 0), int16(y1 >> 0));
uint16 yr = interpolate_cosine(mu, int16(y0 >> 16), int16(y1 >> 16));
output[x] = (yl << 0) + (yr << 16);
sindex += scalar;
}
}
void Audio::resample_cubic(
uint32 *output, uint32 *input, uint output_samples, uint input_samples
) {
double scalar = double(input_samples--) / double(output_samples--); //convert lengths to upper bounds
double sindex = 0.0;
for(uint x = 0; x <= output_samples; x++) {
uint32 y0 = input[bind_range(0, input_samples, uint32(sindex) - 1)];
uint32 y1 = input[bind_range(0, input_samples, uint32(sindex) + 0)];
uint32 y2 = input[bind_range(0, input_samples, uint32(sindex) + 1)];
uint32 y3 = input[bind_range(0, input_samples, uint32(sindex) + 2)];
double mu = sindex - uint(sindex); //calculate fractional portion of step
uint16 yl = sclamp<16>( interpolate_cubic(mu, int16(y0 >> 0), int16(y1 >> 0), int16(y2 >> 0), int16(y3 >> 0)) );
uint16 yr = sclamp<16>( interpolate_cubic(mu, int16(y0 >> 16), int16(y1 >> 16), int16(y2 >> 16), int16(y3 >> 16)) );
output[x] = (yl << 0) + (yr << 16);
sindex += scalar;
}
}
void Audio::resample_hermite(
uint32 *output, uint32 *input, uint output_samples, uint input_samples
) {
double scalar = double(input_samples--) / double(output_samples--); //convert lengths to upper bounds
double sindex = 0.0;
for(uint x = 0; x <= output_samples; x++) {
uint32 y0 = input[bind_range(0, input_samples, uint32(sindex) - 1)];
uint32 y1 = input[bind_range(0, input_samples, uint32(sindex) + 0)];
uint32 y2 = input[bind_range(0, input_samples, uint32(sindex) + 1)];
uint32 y3 = input[bind_range(0, input_samples, uint32(sindex) + 2)];
double mu = sindex - uint(sindex); //calculate fractional portion of step
uint16 yl = sclamp<16>( interpolate_hermite(mu, 0.0, 0.0, int16(y0 >> 0), int16(y1 >> 0), int16(y2 >> 0), int16(y3 >> 0)) );
uint16 yr = sclamp<16>( interpolate_hermite(mu, 0.0, 0.0, int16(y0 >> 16), int16(y1 >> 16), int16(y2 >> 16), int16(y3 >> 16)) );
output[x] = (yl << 0) + (yr << 16);
sindex += scalar;
}
}
*/
//
#include "audio.h"
void Audio::update_frequency() {
uint freq = config::audio.frequency;

View File

@ -1,3 +1,6 @@
#ifndef AUDIO_H
#define AUDIO_H
class Audio {
public:
uint frequency, latency;
@ -7,14 +10,7 @@ uint frequency, latency;
virtual void init() {}
virtual void term() {}
/*
uint bind_range(uint min, uint max, uint index);
void resample_point (uint32 *output, uint32 *input, uint output_samples, uint input_samples);
void resample_linear (uint32 *output, uint32 *input, uint output_samples, uint input_samples);
void resample_cosine (uint32 *output, uint32 *input, uint output_samples, uint input_samples);
void resample_cubic (uint32 *output, uint32 *input, uint output_samples, uint input_samples);
void resample_hermite(uint32 *output, uint32 *input, uint output_samples, uint input_samples);
*/
Audio();
} *uiAudio;
#endif

View File

@ -1,10 +1,14 @@
#include "dinput.h"
void InputDI::clear_input() {
memset(keystate, 0, sizeof keystate);
}
void InputDI::poll() {
clear_input();
HRESULT hr;
DIJOYSTATE2 js;
memset(keystate, 0, sizeof(keystate));
if(di_key) {
hr = di_key->GetDeviceState(256, keystate);
if(FAILED(hr)) {

View File

@ -15,6 +15,7 @@ LPDIRECTINPUT8 di;
LPDIRECTINPUTDEVICE8 di_key, di_joy[DIRECTINPUT_JOYMAX];
uint32 di_joy_count;
void clear_input();
void poll();
void init();
void term();

View File

@ -0,0 +1 @@
#include "input.h"

View File

@ -5,9 +5,6 @@ class Input { public:
virtual bool key_down(uint16 key) { return false; }
virtual bool key_up (uint16 key) { return !key_down(key); }
virtual void signal_key_down(uint16 key) {}
virtual void signal_key_up (uint16 key) {}
virtual void clear_input() {}
virtual void poll() {}
virtual void init() {}

View File

@ -1 +0,0 @@
#include "inputui.h"

View File

@ -1,28 +0,0 @@
/*****
* InputUI
*
* Input wrapper to capture UI key presses. Useful for when OS does not
* support direct input polling methods (eg Xorg, etc)
*****/
#ifndef INPUTUI_H
#define INPUTUI_H
class InputUI : public Input {
private:
bool keystate[65536];
public:
void init() {
Input::init();
memset(keystate, 0, sizeof(keystate));
}
bool key_down(uint16 key) { return keystate[key]; }
void signal_key_down(uint16 key) { keystate[key] = true; }
void signal_key_up (uint16 key) { keystate[key] = false; }
void clear_input() { memset(keystate, 0, sizeof(keystate)); }
};
#endif

143
src/ui/input/xinput.cpp Normal file
View File

@ -0,0 +1,143 @@
#include "xinput.h"
bool InputX::key_down(uint16 key) {
#define map(i) (keymap[i >> 3] & (1 << (i & 7)))
switch(key) {
case keymap::esc: return map(0x09);
case keymap::f1: return map(0x43);
case keymap::f2: return map(0x44);
case keymap::f3: return map(0x45);
case keymap::f4: return map(0x46);
case keymap::f5: return map(0x47);
case keymap::f6: return map(0x48);
case keymap::f7: return map(0x49);
case keymap::f8: return map(0x4a);
case keymap::f9: return map(0x4b);
case keymap::f10: return map(0x4c);
case keymap::f11: return map(0x5f);
case keymap::f12: return map(0x60);
case keymap::print_screen: return map(0x6f);
case keymap::scroll_lock: return map(0x4e);
case keymap::pause: return map(0x6e);
case keymap::grave: return map(0x31);
case keymap::num_1: return map(0x0a);
case keymap::num_2: return map(0x0b);
case keymap::num_3: return map(0x0c);
case keymap::num_4: return map(0x0d);
case keymap::num_5: return map(0x0e);
case keymap::num_6: return map(0x0f);
case keymap::num_7: return map(0x10);
case keymap::num_8: return map(0x11);
case keymap::num_9: return map(0x12);
case keymap::num_0: return map(0x13);
case keymap::minus: return map(0x14);
case keymap::equal: return map(0x15);
case keymap::backspace: return map(0x16);
case keymap::ins: return map(0x6a);
case keymap::del: return map(0x6b);
case keymap::home: return map(0x61);
case keymap::end: return map(0x67);
case keymap::page_up: return map(0x63);
case keymap::page_down: return map(0x69);
case keymap::a: return map(0x26);
case keymap::b: return map(0x38);
case keymap::c: return map(0x36);
case keymap::d: return map(0x28);
case keymap::e: return map(0x1a);
case keymap::f: return map(0x29);
case keymap::g: return map(0x2a);
case keymap::h: return map(0x2b);
case keymap::i: return map(0x1f);
case keymap::j: return map(0x2c);
case keymap::k: return map(0x2d);
case keymap::l: return map(0x2e);
case keymap::m: return map(0x3a);
case keymap::n: return map(0x39);
case keymap::o: return map(0x20);
case keymap::p: return map(0x21);
case keymap::q: return map(0x18);
case keymap::r: return map(0x1b);
case keymap::s: return map(0x27);
case keymap::t: return map(0x1c);
case keymap::u: return map(0x1e);
case keymap::v: return map(0x37);
case keymap::w: return map(0x19);
case keymap::x: return map(0x35);
case keymap::y: return map(0x1d);
case keymap::z: return map(0x34);
case keymap::lbracket: return map(0x22);
case keymap::rbracket: return map(0x23);
case keymap::backslash: return map(0x33);
case keymap::semicolon: return map(0x2f);
case keymap::apostrophe: return map(0x30);
case keymap::comma: return map(0x3b);
case keymap::period: return map(0x3c);
case keymap::slash: return map(0x3d);
case keymap::kp_1: return map(0x57);
case keymap::kp_2: return map(0x58);
case keymap::kp_3: return map(0x59);
case keymap::kp_4: return map(0x53);
case keymap::kp_5: return map(0x54);
case keymap::kp_6: return map(0x55);
case keymap::kp_7: return map(0x4f);
case keymap::kp_8: return map(0x50);
case keymap::kp_9: return map(0x51);
case keymap::kp_plus: return map(0x56);
case keymap::kp_minus: return map(0x52);
case keymap::kp_mul: return map(0x3f);
case keymap::kp_div: return map(0x70);
case keymap::kp_enter: return map(0x6c);
case keymap::num_lock: return map(0x4d);
case keymap::caps_lock: return map(0x42);
case keymap::up: return map(0x62);
case keymap::down: return map(0x68);
case keymap::left: return map(0x64);
case keymap::right: return map(0x66);
case keymap::tab: return map(0x17);
case keymap::enter: return map(0x24);
case keymap::space: return map(0x41);
case keymap::lctrl: return map(0x25);
case keymap::rctrl: return map(0x6d);
case keymap::lalt: return map(0x40);
case keymap::ralt: return map(0x71);
case keymap::lshift: return map(0x32);
case keymap::rshift: return map(0x3e);
case keymap::lsuper: return map(0x73);
case keymap::rsuper: return map(0x74);
case keymap::menu: return map(0x75);
}
#undef map
return false;
}
void InputX::clear_input() {
memset(keymap, 0, sizeof keymap);
}
void InputX::poll() {
XQueryKeymap(display, keymap);
}
void InputX::init() {
Input::init();
display = XOpenDisplay(0);
}
void InputX::term() {
Input::term();
}

26
src/ui/input/xinput.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef XINPUT_H
#define XINPUT_H
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/Xv.h>
#include <X11/extensions/Xvlib.h>
#include <X11/extensions/XShm.h>
class InputX : public Input { public:
bool key_down(uint16 key);
void clear_input();
void poll();
void init();
void term();
private:
Display *display;
char keymap[32];
};
#endif

View File

@ -39,8 +39,12 @@ void SNESInterface::audio_sample(uint16 l_sample, uint16 r_sample) {
//input
//allow_input() returns true only when main emulator window has focus
//TODO: draft a more elegant way to poll lui, etc platforms from here
bool allow_input(); //defined in lui/main.cpp
void SNESInterface::input_poll() {
uiInput->poll();
allow_input() ? uiInput->poll() : uiInput->clear_input();
input_manager.poll();
}

View File

@ -17,9 +17,9 @@ uint multiplier = minmax<1, 5>(uint(config::video.multiplier));
height *= multiplier;
if(config::video.aspect_correction == true) {
if(config::video.region == 0) {
width = uint( double(width) * 8.0 / 7.0 ); //NTSC
width = uint( double(width) * 54.0 / 47.0 ); //NTSC
} else {
width = uint( double(width) * 48.0 / 35.0 ); //PAL
width = uint( double(width) * 32.0 / 23.0 ); //PAL
}
}
@ -103,6 +103,7 @@ char fn[PATH_MAX];
cartridge.load(fn);
cartridge.load_end();
snes.power();
window_cheat_editor.refresh();
}
void unload_rom() {
@ -112,6 +113,7 @@ void unload_rom() {
uiAudio->clear_audio();
}
window_main.set_text(BSNES_TITLE);
window_cheat_editor.refresh();
}
void reset() {

View File

@ -18,6 +18,15 @@ bool _term_ = false;
#include "ui.cpp"
#include "event.cpp"
bool allow_input() {
#if defined(PLATFORM_X)
//TODO: window_main.focused() does not work at all on X
return true;
#endif
//only allow input capture when main window is active
return window_main.focused() == true;
}
void alert(char *s, ...) {
char str[4096];
va_list args;
@ -58,6 +67,10 @@ void run() {
snes.runtoframe();
event::update_frame_counter();
}
#if defined(_MSC_VER)
//prevent bsnes from consuming 100% CPU resources when idle
else { Sleep(1); }
#endif
}
#if defined(PLATFORM_WIN)

View File

@ -1,4 +1,62 @@
void CheatEditorWindow::refresh() {
list.reset();
for(uint i = 0; i < cheat.count(); i++) {
bool enabled;
uint32 addr;
uint8 data;
char s_code[256], s_desc[256], s_result[1024];
cheat.get(i, enabled, addr, data, s_code, s_desc);
sprintf(s_result, "%s|%s|%s", enabled ? "Enabled" : "Disabled", s_code, s_desc);
list.add_item(s_result);
}
list.autosize_columns();
//enable controls only if cartridge is loaded
bool loaded = cartridge.loaded();
add_code.enable(loaded);
toggle_code.enable(loaded);
delete_code.enable(loaded);
}
bool CheatEditorWindow::message(uint id, uintptr_t param) {
ui::Control *control = (ui::Control*)param;
if(id == ui::Message::Clicked && control == &add_code) {
char s_code[256], s_desc[256];
code.get_text(s_code, sizeof s_code);
desc.get_text(s_desc, sizeof s_desc);
cheat.add(false, s_code, s_desc); //param 0 = new codes disabled by default
refresh();
return true;
}
if((id == ui::Message::Clicked && control == &toggle_code) ||
(id == ui::Message::DoubleClicked && control == &list)) {
int index = list.get_selection();
if(index >= 0 && index < cheat.count()) {
cheat.enabled(index) ? cheat.disable(index) : cheat.enable(index);
bool enabled;
uint32 addr;
uint8 data;
char s_code[256], s_desc[256], s_result[1024];
cheat.get(index, enabled, addr, data, s_code, s_desc);
sprintf(s_result, "%s|%s|%s", enabled ? "Enabled" : "Disabled", s_code, s_desc);
list.set_item(index, s_result);
}
return true;
}
if(id == ui::Message::Clicked && control == &delete_code) {
int index = list.get_selection();
if(index >= 0 && index < cheat.count()) {
cheat.remove(index);
refresh();
}
return true;
}
return true;
}
@ -7,9 +65,6 @@ void CheatEditorWindow::setup() {
int x = 0, y = 0;
list.create(*this, ui::Listbox::Header | ui::Listbox::VerticalScrollAlways, x, y, 475, 285, "Status|Code|Description");
list.add_item("Enabled|0123-4567|Infinite Energy");
list.add_item("Disabled|89ab-cdef|Infinite Lives");
list.autosize_columns();
y += 290;
add_code.create (*this, 0, x, y, 155, 30, "Add Code");
@ -20,7 +75,5 @@ int x = 0, y = 0;
code.create(*this, 0, x, y, 155, 30, "<code>");
desc.create(*this, 0, x + 160, y, 315, 30, "<description>");
add_code.disable();
toggle_code.disable();
delete_code.disable();
refresh();
}

View File

@ -1,10 +1,12 @@
class CheatEditorWindow : public ui::Window { public:
ui::Listbox list;
ui::Button add_code;
ui::Button toggle_code;
ui::Button delete_code;
ui::Editbox code;
ui::Editbox desc;
bool message(uint id, uintptr_t param);
void setup();
} window_cheat_editor;
class CheatEditorWindow : public ui::Window { public:
ui::Listbox list;
ui::Button add_code;
ui::Button toggle_code;
ui::Button delete_code;
ui::Editbox code;
ui::Editbox desc;
bool message(uint id, uintptr_t param);
void setup();
void refresh();
} window_cheat_editor;

View File

@ -99,16 +99,6 @@ void InputConfigWindow::refresh_list() {
bool InputConfigWindow::message(uint id, uintptr_t param) {
ui::Control *control = (ui::Control*)param;
if(id == ui::Message::KeyDown) {
if(uiInput) { uiInput->signal_key_down(param); }
return true;
}
if(id == ui::Message::KeyUp) {
if(uiInput) { uiInput->signal_key_up(param); }
return true;
}
if(id == ui::Message::Changed && control == &list) {
int pos = list.get_selection();
setkey.enable(pos >= 0);
@ -180,16 +170,6 @@ bool InputCaptureWindow::message(uint id, uintptr_t param) {
return false;
}
if(id == ui::Message::KeyDown) {
if(uiInput) { uiInput->signal_key_down(param); }
return true;
}
if(id == ui::Message::KeyUp) {
if(uiInput) { uiInput->signal_key_up(param); }
return true;
}
return true;
}

View File

@ -20,10 +20,9 @@
#include "../video/xv.cpp"
#include "../video/gtk.cpp"
#include "../audio/ao.cpp"
#include "../input/xinput.cpp"
#endif
#include "../input/inputui.cpp"
void ui_init() {
window_main.setup();
window_about.setup();
@ -49,7 +48,6 @@ void ui_init() {
(Audio*)new AudioDS(window_main.handle());
uiInput =
config::system.input == "none" ? (Input*)new Input() :
config::system.input == "ui" ? (Input*)new InputUI() :
(Input*)new InputDI(window_main.handle());
#elif defined(PLATFORM_X)
uiVideo =
@ -61,7 +59,7 @@ void ui_init() {
(Audio*)new AudioAO(config::system.audio_flags);
uiInput =
config::system.input == "none" ? (Input*)new Input() :
(Input*)new InputUI();
(Input*)new InputX();
#endif
uiVideo->init();

View File

@ -12,17 +12,11 @@ ui::Control *control = (ui::Control*)param;
}
if(id == ui::Message::KeyDown) {
if(uiInput) { uiInput->signal_key_down(param); }
if(param == keymap::esc) { event::toggle_menu(); }
if(param == keymap::f11) { event::toggle_fullscreen(); }
return true;
}
if(id == ui::Message::KeyUp) {
if(uiInput) { uiInput->signal_key_up(param); }
return true;
}
if(id == ui::Message::Clicked) {
if(control == &menu_file_load) {
event::load_rom();

View File

@ -11,10 +11,6 @@ void term_snes();
* hardware abstraction layer
*****/
#include "video/video.h"
#include "audio/audio.h"
#include "input/input.h"
#include "video/video.cpp"
#include "audio/audio.cpp"
#include "input/input.cpp"

View File

@ -0,0 +1 @@
#include "video.h"

View File

@ -1,3 +1,6 @@
#ifndef VIDEO_H
#define VIDEO_H
class Video { public:
enum Filter {
@ -18,3 +21,5 @@ enum Filter {
Video() {}
virtual ~Video() {}
} *uiVideo;
#endif