Update to bsnes v029 release.

A new version of bsnes has been released. It contains a few minor emulation fixes, as well as user interface improvements. Behind the scenes, the source has been cleaned up more in preparation for running the CPU and PPU (video processor) separately from each other (eg with no enslavement.) This is required for implementing a clock cycle based PPU renderer.
    - Greatly improved invalid DMA transfer behavior, should be nearly perfect now
    - Major code cleanup -- most importantly, almost all PPU timing-related settings moved back to PPU, from CPU
    - Added option to auto-detect file type by inspecting file headers rather than file extensions
    - Rewrote video filter system to move it out of the emulation core -- HQ2x and Scale2x will work even in hires and interlace modes now, 50% scanline filter added
    - Re-added bsnes window icon
    - Added new controller graphic when assigning joypad keys [FitzRoy]
    - Redundant "Advanced" panel settings which can be configured via the GUI are no longer displayed
    - Improved speed regulation settings
    - XP and Vista themes will now apply to bsnes controls
    - Added "Path Settings" window to allow easy selection of default file directories
    - Tab key now mostly works throughout most of the GUI (needs improvement)
    - Main window will no longer disappear when setting a video multipler which results in a window size larger than the current desktop resolution
    - Added two new advanced options: one to control GUI window opacity, and one to adjust the statusbar text
This commit is contained in:
byuu 2008-03-18 06:19:43 +00:00
parent 7e6e3e3a69
commit 805398e5a8
316 changed files with 6230 additions and 4402 deletions

View File

@ -1,5 +1,5 @@
bsnes bsnes
Version: 0.028 Version: 0.029
Author: byuu Author: byuu
-------- --------
@ -17,7 +17,6 @@ Please see license.txt for important licensing information.
Known Limitations: Known Limitations:
------------------ ------------------
S-CPU S-CPU
- Invalid DMA / HDMA transfers not fully emulated
- Multiply / Divide register delays not implemented - Multiply / Divide register delays not implemented
S-PPU S-PPU

View File

@ -1,7 +1,5 @@
include lib/nall/Makefile.string include lib/nall/Makefile.string
prefix = /usr/local prefix = /usr/local
arch = ARCH_LSB
################ ################
### compiler ### ### compiler ###
@ -37,12 +35,11 @@ endif
ifeq ($(platform),x) # X11 ifeq ($(platform),x) # X11
ruby = video.glx video.xv video.sdl audio.openal audio.oss audio.ao input.sdl input.x ruby = video.glx video.xv video.sdl audio.openal audio.oss audio.ao input.sdl input.x
arch += PLATFORM_X
link += `pkg-config --libs gtk+-2.0` link += `pkg-config --libs gtk+-2.0`
link += $(call mklib,Xtst)
delete = rm -f $1 delete = rm -f $1
else ifeq ($(platform),win) # Windows else ifeq ($(platform),win) # Windows
ruby = video.direct3d video.directdraw video.gdi audio.directsound input.directinput ruby = video.direct3d video.directdraw video.gdi audio.directsound input.directinput
arch += PLATFORM_WIN
link += $(if $(findstring mingw,$(compiler)),-mwindows) link += $(if $(findstring mingw,$(compiler)),-mwindows)
link += $(call mklib,uuid) link += $(call mklib,uuid)
link += $(call mklib,kernel32) link += $(call mklib,kernel32)
@ -61,13 +58,16 @@ endif
### ruby ### ### ruby ###
############ ############
rubyflags =
rubyflags += $(if $(findstring .sdl,$(ruby)),`sdl-config --cflags`)
link += $(if $(findstring video.direct3d,$(ruby)),$(call mklib,d3d9)) link += $(if $(findstring video.direct3d,$(ruby)),$(call mklib,d3d9))
link += $(if $(findstring video.directdraw,$(ruby)),$(call mklib,ddraw)) link += $(if $(findstring video.directdraw,$(ruby)),$(call mklib,ddraw))
link += $(if $(findstring video.glx,$(ruby)),$(call mklib,GL)) link += $(if $(findstring video.glx,$(ruby)),$(call mklib,GL))
link += $(if $(findstring video.xv,$(ruby)),$(call mklib,Xv)) link += $(if $(findstring video.xv,$(ruby)),$(call mklib,Xv))
link += $(if $(findstring audio.ao,$(ruby)),$(call mklib,ao)) link += $(if $(findstring audio.ao,$(ruby)),$(call mklib,ao))
link += $(if $(findstring audio.directsound,$(ruby)),$(call mklib,dsound)) link += $(if $(findstring audio.directsound,$(ruby)),$(call mklib,dsound))
link += $(if $(findstring audio.openal,$(ruby)),$(call mklib,openal) $(call mklib,alut)) link += $(if $(findstring audio.openal,$(ruby)),$(if $(call streq,$(platform),x),$(call mklib,openal),$(call mklib,openal32)))
link += $(if $(findstring input.directinput,$(ruby)),$(call mklib,dinput8) $(call mklib,dxguid)) link += $(if $(findstring input.directinput,$(ruby)),$(call mklib,dinput8) $(call mklib,dxguid))
link += $(if $(findstring input.sdl,$(ruby)),`sdl-config --libs`) link += $(if $(findstring input.sdl,$(ruby)),`sdl-config --libs`)
@ -75,7 +75,7 @@ link += $(if $(findstring input.sdl,$(ruby)),`sdl-config --libs`)
### main target and dependencies ### ### main target and dependencies ###
#################################### ####################################
objects = main libco hiro ruby $(ruby) string reader cart cheat \ objects = main libco hiro ruby libfilter string reader cart cheat \
memory smemory cpu scpu smp ssmp bdsp ppu bppu snes \ memory smemory cpu scpu smp ssmp bdsp ppu bppu snes \
bsx srtc sdd1 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010 bsx srtc sdd1 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010
@ -89,7 +89,6 @@ ifeq ($(enable_jma),true)
flags += $(call mkdef,JMA_SUPPORT) flags += $(call mkdef,JMA_SUPPORT)
endif endif
arch := $(patsubst %,$(call mkdef,%),$(arch))
objects := $(patsubst %,obj/%.$(obj),$(objects)) objects := $(patsubst %,obj/%.$(obj),$(objects))
rubydef := $(foreach c,$(subst .,_,$(call strupper,$(ruby))),$(call mkdef,$c)) rubydef := $(foreach c,$(subst .,_,$(call strupper,$(ruby))),$(call mkdef,$c))
@ -124,46 +123,21 @@ all: build;
### main ### ### main ###
############ ############
obj/main.$(obj): ui/main.cpp config/* lib/nall/* lib/ruby/* ui/* ui/loader/* ui/settings/* obj/main.$(obj): ui/main.cpp ui/* ui/base/* ui/loader/* ui/settings/*
$(call compile,$(arch))
obj/bsnes.res: ui/bsnes.rc; rc /r /foobj/bsnes.res ui/bsnes.rc obj/bsnes.res: ui/bsnes.rc; rc /r /foobj/bsnes.res ui/bsnes.rc
obj/bsnesrc.$(obj): ui/bsnes.rc; windres -I data ui/bsnes.rc obj/bsnesrc.$(obj) obj/bsnesrc.$(obj): ui/bsnes.rc; windres ui/bsnes.rc obj/bsnesrc.$(obj)
############
### ruby ###
############
obj/ruby.$(obj) : lib/ruby/ruby.cpp lib/ruby/*
$(call compile,$(rubydef))
obj/video.direct3d.$(obj) : lib/ruby/video/direct3d.cpp lib/ruby/video/direct3d.*
obj/video.directdraw.$(obj) : lib/ruby/video/directdraw.cpp lib/ruby/video/directdraw.*
obj/video.gdi.$(obj) : lib/ruby/video/gdi.cpp lib/ruby/video/gdi.*
obj/video.glx.$(obj) : lib/ruby/video/glx.cpp lib/ruby/video/glx.*
obj/video.sdl.$(obj) : lib/ruby/video/sdl.cpp lib/ruby/video/sdl.*
$(call compile,`sdl-config --cflags`)
obj/video.xv.$(obj) : lib/ruby/video/xv.cpp lib/ruby/video/xv.*
obj/audio.ao.$(obj) : lib/ruby/audio/ao.cpp lib/ruby/audio/ao.*
obj/audio.directsound.$(obj): lib/ruby/audio/directsound.cpp lib/ruby/audio/directsound.*
obj/audio.openal.$(obj) : lib/ruby/audio/openal.cpp lib/ruby/audio/openal.*
obj/audio.oss.$(obj) : lib/ruby/audio/oss.cpp lib/ruby/audio/oss.*
obj/input.directinput.$(obj): lib/ruby/input/directinput.cpp lib/ruby/input/directinput.*
obj/input.sdl.$(obj) : lib/ruby/input/sdl.cpp lib/ruby/input/sdl.*
$(call compile,`sdl-config --cflags`)
obj/input.x.$(obj) : lib/ruby/input/x.cpp lib/ruby/input/x.*
############
### hiro ###
############
obj/hiro.$(obj): lib/hiro.cpp lib/hiro.* lib/hiro_gtk/* lib/hiro_win/*
$(call compile,$(if $(call streq,$(platform),x),`pkg-config --cflags gtk+-2.0`))
################# #################
### libraries ### ### libraries ###
################# #################
obj/libco.$(obj): lib/libco.c lib/libco.* lib/libco/* obj/ruby.$(obj): lib/ruby/ruby.cpp lib/ruby/*
$(call compile,$(rubydef) $(rubyflags))
obj/hiro.$(obj): lib/hiro/hiro.cpp lib/hiro/* lib/hiro/gtk/* lib/hiro/win/*
$(call compile,$(if $(call streq,$(platform),x),`pkg-config --cflags gtk+-2.0`))
obj/libco.$(obj): lib/libco/libco.c lib/libco/*
$(call compile,-static)
obj/libfilter.$(obj): lib/libfilter/libfilter.cpp lib/libfilter/*
obj/string.$(obj): lib/nall/string.cpp lib/nall/* obj/string.$(obj): lib/nall/string.cpp lib/nall/*
################# #################
@ -179,7 +153,6 @@ obj/cheat.$(obj) : cheat/cheat.cpp cheat/*
############## ##############
obj/memory.$(obj) : memory/memory.cpp memory/* obj/memory.$(obj) : memory/memory.cpp memory/*
obj/bmemory.$(obj): memory/bmemory/bmemory.cpp memory/bmemory/* memory/bmemory/mapper/*
obj/smemory.$(obj): memory/smemory/smemory.cpp memory/smemory/* memory/smemory/mapper/* obj/smemory.$(obj): memory/smemory/smemory.cpp memory/smemory/* memory/smemory/mapper/*
########### ###########
@ -270,8 +243,8 @@ build: $(objects)
$(strip $(cpp) $(call mkbin,../bsnes) $(objects) $(link)) $(strip $(cpp) $(call mkbin,../bsnes) $(objects) $(link))
install: install:
install -D -m 755 ../bsnes $(prefix)/bin/bsnes install -D -m 755 ../bsnes $(DESTDIR)$(prefix)/bin/bsnes
install -D -m 644 data/bsnes.png $(prefix)/share/icons/bsnes.png install -D -m 644 data/bsnes.png $(DESTDIR)$(prefix)/share/icons/bsnes.png
clean: clean:
-@$(call delete,obj/*.$(obj)) -@$(call delete,obj/*.$(obj))

View File

@ -1,4 +1,4 @@
#define BSNES_VERSION "0.028.01" #define BSNES_VERSION "0.029"
#define BSNES_TITLE "bsnes v" BSNES_VERSION #define BSNES_TITLE "bsnes v" BSNES_VERSION
#define BUSCORE sBus #define BUSCORE sBus
@ -7,32 +7,28 @@
#define DSPCORE bDSP #define DSPCORE bDSP
#define PPUCORE bPPU #define PPUCORE bPPU
//FAVOR_ACCURACY calculates RTO during frameskip, whereas FAVOR_SPEED does not //FAST_FRAMESKIP disables calculation of RTO during frameskip
//frameskip offers near-zero speedup if RTO is calculated //frameskip offers near-zero speedup if RTO is calculated
//accuracy is not affected by this define when frameskipping is off //accuracy is not affected by this define when frameskipping is off
#define FAST_FRAMESKIP
//#define FAVOR_ACCURACY
#define FAVOR_SPEED
//game genie + pro action replay code support (~1-3% speed hit) //game genie + pro action replay code support (~1-3% speed hit)
#define CHEAT_SYSTEM #define CHEAT_SYSTEM
#if !defined(ARCH_LSB) && !defined(ARCH_MSB)
#define ARCH_LSB //guess
#endif
#include <nall/algorithm.hpp> #include <nall/algorithm.hpp>
#include <nall/array.hpp> #include <nall/array.hpp>
#include <nall/bit.hpp> #include <nall/bit.hpp>
#include <nall/config.hpp> #include <nall/config.hpp>
#include <nall/detect.hpp>
#include <nall/function.hpp> #include <nall/function.hpp>
#include <nall/new.hpp> #include <nall/new.hpp>
#include <nall/sort.hpp> #include <nall/sort.hpp>
#include <nall/stdint.hpp>
#include <nall/string.hpp> #include <nall/string.hpp>
#include <nall/vector.hpp> #include <nall/vector.hpp>
using namespace nall; using namespace nall;
#include <libco.h> #include <libco/libco.h>
#include <bbase.h> #include <bbase.h>
//platform-specific global functions //platform-specific global functions

View File

@ -1,4 +1,5 @@
#include "../base.h" #include "../base.h"
#define CART_CPP
#include "cart_normal.cpp" #include "cart_normal.cpp"
#include "cart_bsx.cpp" #include "cart_bsx.cpp"
@ -82,12 +83,9 @@ void Cartridge::load_end() {
memory::stBrom.write_protect(true); memory::stBrom.write_protect(true);
memory::stBram.write_protect(false); memory::stBram.write_protect(false);
char fn[PATH_MAX]; if(fexists(get_cheat_filename(cart.fn, "cht"))) {
strcpy(fn, cart.fn);
modify_extension(fn, "cht");
if(fexists(fn)) {
cheat.clear(); cheat.clear();
cheat.load(fn); cheat.load(cheatfn);
} }
cart.loaded = true; cart.loaded = true;
@ -117,8 +115,8 @@ bool Cartridge::unload() {
char fn[PATH_MAX]; char fn[PATH_MAX];
strcpy(fn, cart.fn); strcpy(fn, cart.fn);
modify_extension(fn, "cht"); modify_extension(fn, "cht");
if(cheat.count() > 0 || fexists(fn)) { if(cheat.count() > 0 || fexists(get_cheat_filename(cart.fn, "cht"))) {
cheat.save(fn); cheat.save(cheatfn);
cheat.clear(); cheat.clear();
} }

View File

@ -68,6 +68,7 @@ public:
CartridgeType type; CartridgeType type;
uint32 crc32; uint32 crc32;
char filename[PATH_MAX * 4];
char name[128]; char name[128];
Region region; Region region;
@ -123,13 +124,17 @@ public:
bool load_file(const char *fn, uint8 *&data, uint &size); bool load_file(const char *fn, uint8 *&data, uint &size);
bool save_file(const char *fn, uint8 *data, uint size); bool save_file(const char *fn, uint8 *data, uint size);
char* modify_extension(char *filename, const char *extension); char* modify_extension(char *filename, const char *extension);
char* get_base_filename(char *filename);
char* get_path_filename(char *filename, const char *path, const char *source, const char *extension);
char* get_save_filename(const char *source, const char *extension); char* get_save_filename(const char *source, const char *extension);
char* get_cheat_filename(const char *source, const char *extension);
Cartridge(); Cartridge();
~Cartridge(); ~Cartridge();
private: private:
char savefn[PATH_MAX]; char savefn[PATH_MAX];
char cheatfn[PATH_MAX];
}; };
namespace memory { namespace memory {

View File

@ -1,3 +1,5 @@
#ifdef CART_CPP
void Cartridge::load_cart_bsc(const char *base, const char *slot) { void Cartridge::load_cart_bsc(const char *base, const char *slot) {
if(!base || !*base) return; if(!base || !*base) return;
@ -5,8 +7,8 @@ void Cartridge::load_cart_bsc(const char *base, const char *slot) {
strcpy(bs.fn, slot ? slot : ""); strcpy(bs.fn, slot ? slot : "");
load_begin(CartridgeBSC); load_begin(CartridgeBSC);
uint8 *data; uint8_t *data = 0;
uint size; unsigned size;
load_file(cart.fn, data, size); load_file(cart.fn, data, size);
cart.rom = data, cart.rom_size = size; cart.rom = data, cart.rom_size = size;
@ -34,8 +36,21 @@ uint size;
} }
load_end(); load_end();
//set base filename
strcpy(info.filename, cart.fn);
get_base_filename(info.filename);
if(*bs.fn) {
char filenameBS[PATH_MAX];
strcpy(filenameBS, bs.fn);
get_base_filename(filenameBS);
strcat(info.filename, " + ");
strcat(info.filename, filenameBS);
}
} }
void Cartridge::unload_cart_bsc() { void Cartridge::unload_cart_bsc() {
if(cart.ram) save_file(get_save_filename(cart.fn, "srm"), cart.ram, cart.ram_size); if(cart.ram) save_file(get_save_filename(cart.fn, "srm"), cart.ram, cart.ram_size);
} }
#endif //ifdef CART_CPP

View File

@ -1,3 +1,5 @@
#ifdef CART_CPP
void Cartridge::load_cart_bsx(const char *base, const char *slot) { void Cartridge::load_cart_bsx(const char *base, const char *slot) {
if(!base || !*base) return; if(!base || !*base) return;
@ -10,8 +12,8 @@ void Cartridge::load_cart_bsx(const char *base, const char *slot) {
info.mapper = BSXROM; info.mapper = BSXROM;
info.region = NTSC; info.region = NTSC;
uint8 *data; uint8_t *data = 0;
uint size; unsigned size;
load_file(cart.fn, data, size); load_file(cart.fn, data, size);
cart.rom = data, cart.rom_size = size; cart.rom = data, cart.rom_size = size;
cart.ram = 0, cart.ram_size = 0; cart.ram = 0, cart.ram_size = 0;
@ -37,9 +39,14 @@ uint size;
} }
load_end(); load_end();
strcpy(info.filename, !*bs.fn ? cart.fn : bs.fn);
get_base_filename(info.filename);
} }
void Cartridge::unload_cart_bsx() { void Cartridge::unload_cart_bsx() {
save_file(get_save_filename(cart.fn, "srm"), bsxcart.sram.handle (), bsxcart.sram.size ()); save_file(get_save_filename(cart.fn, "srm"), bsxcart.sram.handle (), bsxcart.sram.size ());
save_file(get_save_filename(cart.fn, "psr"), bsxcart.psram.handle(), bsxcart.psram.size()); save_file(get_save_filename(cart.fn, "psr"), bsxcart.psram.handle(), bsxcart.psram.size());
} }
#endif //ifdef CART_CPP

View File

@ -1,3 +1,5 @@
#ifdef CART_CPP
#include "../reader/filereader.h" #include "../reader/filereader.h"
#if defined(GZIP_SUPPORT) #if defined(GZIP_SUPPORT)
@ -22,29 +24,62 @@ int i;
return filename; return filename;
} }
char* Cartridge::get_save_filename(const char *source, const char *extension) { //remove directory information and file extension ("/foo/bar.ext" -> "bar")
strcpy(savefn, source); char* Cartridge::get_base_filename(char *filename) {
for(char *p = savefn; *p; p++) { if(*p == '\\') *p = '/'; } //remove extension
modify_extension(savefn, extension); for(int i = strlen(filename) - 1; i >= 0; i--) {
if(filename[i] == '.') {
filename[i] = 0;
break;
}
}
//remove directory information
for(int i = strlen(filename) - 1; i >= 0; i--) {
if(filename[i] == '/' || filename[i] == '\\') {
i++;
char *output = filename;
while(true) {
*output++ = filename[i];
if(!filename[i]) break;
i++;
}
break;
}
}
}
char* Cartridge::get_path_filename(char *filename, const char *path, const char *source, const char *extension) {
strcpy(filename, source);
for(char *p = filename; *p; p++) { if(*p == '\\') *p = '/'; }
modify_extension(filename, extension);
//override path with user-specified folder, if one was defined //override path with user-specified folder, if one was defined
if(config::path.save != "") { if(path != "") {
lstring part; lstring part;
split(part, "/", savefn); split(part, "/", filename);
string fn = (const char*)config::path.save; string fn = path;
if(strend(fn, "/") == false) strcat(fn, "/"); if(strend(fn, "/") == false) strcat(fn, "/");
strcat(fn, part[count(part) - 1]); strcat(fn, part[count(part) - 1]);
strcpy(savefn, fn); strcpy(filename, fn);
//resolve relative path, if found //resolve relative path, if found
if(strbegin(fn, "./") == true) { if(strbegin(fn, "./") == true) {
ltrim(fn, "./"); ltrim(fn, "./");
strcpy(savefn, config::path.base); strcpy(filename, config::path.base);
strcat(savefn, fn); strcat(filename, fn);
} }
} }
return savefn; return filename;
}
char* Cartridge::get_save_filename(const char *source, const char *extension) {
return get_path_filename(savefn, config::path.save, source, extension);
}
char* Cartridge::get_cheat_filename(const char *source, const char *extension) {
return get_path_filename(cheatfn, config::path.cheat, source, extension);
} }
bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) { bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) {
@ -54,7 +89,7 @@ bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) {
switch(Reader::detect(fn)) { switch(Reader::detect(fn)) {
default: default:
case Reader::RF_NORMAL: { case Reader::Normal: {
FileReader ff(fn); FileReader ff(fn);
if(!ff.ready()) { if(!ff.ready()) {
alert("Error loading image file (%s)!", fn); alert("Error loading image file (%s)!", fn);
@ -65,7 +100,7 @@ bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) {
} break; } break;
#ifdef GZIP_SUPPORT #ifdef GZIP_SUPPORT
case Reader::RF_GZ: { case Reader::GZIP: {
GZReader gf(fn); GZReader gf(fn);
if(!gf.ready()) { if(!gf.ready()) {
alert("Error loading image file (%s)!", fn); alert("Error loading image file (%s)!", fn);
@ -75,7 +110,7 @@ bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) {
data = gf.read(); data = gf.read();
} break; } break;
case Reader::RF_ZIP: { case Reader::ZIP: {
ZipReader zf(fn); ZipReader zf(fn);
size = zf.size(); size = zf.size();
data = zf.read(); data = zf.read();
@ -83,7 +118,7 @@ bool Cartridge::load_file(const char *fn, uint8 *&data, uint &size) {
#endif #endif
#ifdef JMA_SUPPORT #ifdef JMA_SUPPORT
case Reader::RF_JMA: { case Reader::JMA: {
try { try {
JMAReader jf(fn); JMAReader jf(fn);
size = jf.size(); size = jf.size();
@ -105,3 +140,5 @@ FileWriter ff(fn);
ff.write(data, size); ff.write(data, size);
return true; return true;
} }
#endif //ifdef CART_CPP

View File

@ -1,3 +1,5 @@
#ifdef CART_CPP
void Cartridge::read_header() { void Cartridge::read_header() {
uint8 *rom = cart.rom; uint8 *rom = cart.rom;
uint index = info.header_index; uint index = info.header_index;
@ -92,9 +94,9 @@ bool has_bsxflash = false;
} }
if(mapper == 0x30 && rom_type == 0xf6) { if(mapper == 0x30 && rom_type == 0xf6) {
//TODO: both ST010 and ST011 share the same mapper + rom_type //TODO: both ST010 and ST011 share the same mapper + rom_type.
//need way to determine which is which //need way to determine which is which.
//for now, default to supported ST010 //for now, default to supported ST010.
info.st010 = true; info.st010 = true;
} }
@ -113,19 +115,20 @@ bool has_bsxflash = false;
memcpy(&info.name, &rom[info.header_index + CART_NAME], 21); memcpy(&info.name, &rom[info.header_index + CART_NAME], 21);
info.name[21] = 0; info.name[21] = 0;
trim(info.name);
for(int i = 0; i < 22; i++) { //convert undisplayable characters (half-width katakana, etc) to '?' characters
if(info.name[i] & 0x80) { for(int i = 0; i < 21; i++) {
info.name[i] = '?'; if(info.name[i] & 0x80) info.name[i] = '?';
}
} }
//always display something
if(!info.name[0]) strcpy(info.name, "(untitled)");
} }
void Cartridge::find_header() { void Cartridge::find_header() {
int32 score_lo = 0, int32 score_lo = 0, score_hi = 0, score_ex = 0;
score_hi = 0, uint8_t *rom = cart.rom;
score_ex = 0;
uint8 *rom = cart.rom;
if(cart.rom_size < 0x010000) { if(cart.rom_size < 0x010000) {
//cart too small to be anything but lorom //cart too small to be anything but lorom
@ -182,3 +185,5 @@ uint16 cksum, icksum;
info.header_index = 0x40ffc0; info.header_index = 0x40ffc0;
} }
} }
#endif //ifdef CART_CPP

View File

@ -1,8 +1,10 @@
#ifdef CART_CPP
void Cartridge::load_cart_normal(const char *filename) { void Cartridge::load_cart_normal(const char *filename) {
if(!filename || !*filename) return; if(!filename || !*filename) return;
uint8 *data; uint8_t *data = 0;
uint size; unsigned size;
if(load_file(filename, data, size) == false) return; if(load_file(filename, data, size) == false) return;
strcpy(cart.fn, filename); strcpy(cart.fn, filename);
@ -34,8 +36,14 @@ uint size;
} }
load_end(); load_end();
//set base filename
strcpy(info.filename, cart.fn);
get_base_filename(info.filename);
} }
void Cartridge::unload_cart_normal() { void Cartridge::unload_cart_normal() {
if(cart.ram) save_file(get_save_filename(cart.fn, "srm"), cart.ram, cart.ram_size); if(cart.ram) save_file(get_save_filename(cart.fn, "srm"), cart.ram, cart.ram_size);
} }
#endif //ifdef CART_CPP

View File

@ -1,3 +1,5 @@
#ifdef CART_CPP
void Cartridge::load_cart_st(const char *base, const char *slotA, const char *slotB) { void Cartridge::load_cart_st(const char *base, const char *slotA, const char *slotB) {
if(!base || !*base) return; if(!base || !*base) return;
@ -10,8 +12,8 @@ void Cartridge::load_cart_st(const char *base, const char *slotA, const char *sl
info.mapper = STROM; info.mapper = STROM;
info.region = NTSC; info.region = NTSC;
uint8 *data; uint8_t *data = 0;
uint size; unsigned size;
if(load_file(cart.fn, data, size) == true) { if(load_file(cart.fn, data, size) == true) {
cart.rom = (uint8*)malloc(cart.rom_size = 0x040000); cart.rom = (uint8*)malloc(cart.rom_size = 0x040000);
memcpy(cart.rom, data, min(size, cart.rom_size)); memcpy(cart.rom, data, min(size, cart.rom_size));
@ -51,9 +53,32 @@ uint size;
} }
load_end(); load_end();
//set base filename
if(!*stA.fn && !*stB.fn) {
strcpy(info.filename, cart.fn);
get_base_filename(info.filename);
} else if(*stA.fn && !*stB.fn) {
strcpy(info.filename, stA.fn);
get_base_filename(info.filename);
} else if(!*stA.fn && *stB.fn) {
strcpy(info.filename, stB.fn);
get_base_filename(info.filename);
} else {
char filenameA[PATH_MAX], filenameB[PATH_MAX];
strcpy(filenameA, stA.fn);
get_base_filename(filenameA);
strcpy(filenameB, stB.fn);
get_base_filename(filenameB);
strcpy(info.filename, filenameA);
strcat(info.filename, " + ");
strcat(info.filename, filenameB);
}
} }
void Cartridge::unload_cart_st() { void Cartridge::unload_cart_st() {
if(stA.ram) save_file(get_save_filename(stA.fn, "srm"), stA.ram, stA.ram_size); if(stA.ram) save_file(get_save_filename(stA.fn, "srm"), stA.ram, stA.ram_size);
if(stB.ram) save_file(get_save_filename(stB.fn, "srm"), stB.ram, stB.ram_size); if(stB.ram) save_file(get_save_filename(stB.fn, "srm"), stB.ram, stB.ram_size);
} }
#endif //ifdef CART_CPP

View File

@ -14,14 +14,14 @@ string t, part;
strcpy(t, str); strcpy(t, str);
strlower(t()); strlower(t());
if(strlen(t) == 8 || (strlen(t) == 9 && t()[6] == ':')) { if(strlen(t) == 8 || (strlen(t) == 9 && t()[6] == ':')) {
type = CT_PRO_ACTION_REPLAY; type = ProActionReplay;
replace(t, ":", ""); replace(t, ":", "");
uint32 r = strhex((const char*)t); uint32 r = strhex((const char*)t);
addr = r >> 8; addr = r >> 8;
data = r & 0xff; data = r & 0xff;
return true; return true;
} else if(strlen(t) == 9 && t()[4] == '-') { } else if(strlen(t) == 9 && t()[4] == '-') {
type = CT_GAME_GENIE; type = GameGenie;
replace(t, "-", ""); replace(t, "-", "");
strtr(t, "df4709156bc8a23e", "0123456789abcdef"); strtr(t, "df4709156bc8a23e", "0123456789abcdef");
uint32 r = strhex((const char*)t); uint32 r = strhex((const char*)t);
@ -47,10 +47,10 @@ string t, part;
} }
bool Cheat::encode(char *str, uint32 addr, uint8 data, uint8 type) { bool Cheat::encode(char *str, uint32 addr, uint8 data, uint8 type) {
if(type == CT_PRO_ACTION_REPLAY) { if(type == ProActionReplay) {
sprintf(str, "%0.6x:%0.2x", addr, data); sprintf(str, "%0.6x:%0.2x", addr, data);
return true; return true;
} else if(type == CT_GAME_GENIE) { } else if(type == GameGenie) {
uint32 r = addr; uint32 r = addr;
addr = (!!(r & 0x008000) << 23) | (!!(r & 0x004000) << 22) | addr = (!!(r & 0x008000) << 23) | (!!(r & 0x004000) << 22) |
(!!(r & 0x002000) << 21) | (!!(r & 0x001000) << 20) | (!!(r & 0x002000) << 21) | (!!(r & 0x001000) << 20) |
@ -148,8 +148,9 @@ bool Cheat::read(uint32 addr, uint8 &data) {
* enabled. if any are, make sure the cheat system is on. * enabled. if any are, make sure the cheat system is on.
* otherwise, turn cheat system off to speed up emulation. * otherwise, turn cheat system off to speed up emulation.
*****/ *****/
void Cheat::update_cheat_status() { void Cheat::update_cheat_status() {
for(int i = 0; i < cheat_count; i++) { for(unsigned i = 0; i < cheat_count; i++) {
if(index[i].enabled) { if(index[i].enabled) {
cheat_enabled = true; cheat_enabled = true;
return; return;
@ -163,7 +164,7 @@ void Cheat::update_cheat_status() {
*****/ *****/
bool Cheat::add(bool enable, char *code, char *desc) { bool Cheat::add(bool enable, char *code, char *desc) {
if(cheat_count >= CHEAT_LIMIT)return false; if(cheat_count >= CheatLimit) return false;
uint32 addr, len; uint32 addr, len;
uint8 data, type; uint8 data, type;
@ -219,7 +220,7 @@ uint8 data, type;
bool Cheat::remove(uint32 n) { bool Cheat::remove(uint32 n) {
if(n >= cheat_count) return false; if(n >= cheat_count) return false;
for(int i = n; i < cheat_count; i++) { for(unsigned i = n; i < cheat_count; i++) {
index[i].enabled = index[i + 1].enabled; index[i].enabled = index[i + 1].enabled;
index[i].addr = index[i + 1].addr; index[i].addr = index[i + 1].addr;
index[i].data = index[i + 1].data; index[i].data = index[i + 1].data;
@ -282,7 +283,7 @@ string data;
lstring line; lstring line;
split(line, "\n", data); split(line, "\n", data);
for(int i = 0; i < ::count(line); i++) { for(unsigned i = 0; i < ::count(line); i++) {
lstring part; lstring part;
split(part, ",", line[i]); split(part, ",", line[i]);
if(::count(part) != 3) continue; if(::count(part) != 3) continue;
@ -296,7 +297,7 @@ lstring line;
bool Cheat::save(const char *fn) { bool Cheat::save(const char *fn) {
FILE *fp = fopen(fn, "wb"); FILE *fp = fopen(fn, "wb");
if(!fp) return false; if(!fp) return false;
for(int i = 0; i < cheat_count; i++) { for(unsigned i = 0; i < cheat_count; i++) {
fprintf(fp, "%9s = %8s, \"%s\"\r\n", fprintf(fp, "%9s = %8s, \"%s\"\r\n",
index[i].code, index[i].code,
index[i].enabled ? "enabled" : "disabled", index[i].enabled ? "enabled" : "disabled",
@ -314,7 +315,7 @@ void Cheat::clear() {
cheat_enabled = false; cheat_enabled = false;
cheat_count = 0; cheat_count = 0;
memset(mask, 0, 0x200000); memset(mask, 0, 0x200000);
for(int i = 0; i <= CHEAT_LIMIT; i++) { for(unsigned i = 0; i <= CheatLimit; i++) {
index[i].enabled = false; index[i].enabled = false;
index[i].addr = 0x000000; index[i].addr = 0x000000;
index[i].data = 0x00; index[i].data = 0x00;

View File

@ -1,10 +1,10 @@
#define CHEAT_LIMIT 1024
class Cheat { class Cheat {
public: public:
enum { enum { CheatLimit = 1024 };
CT_PRO_ACTION_REPLAY,
CT_GAME_GENIE enum Type {
ProActionReplay,
GameGenie,
}; };
struct CheatIndex { struct CheatIndex {
@ -13,7 +13,7 @@ public:
uint8 data; uint8 data;
char code[ 16 + 1]; char code[ 16 + 1];
char desc[128 + 1]; char desc[128 + 1];
} index[CHEAT_LIMIT + 1]; } index[CheatLimit + 1];
bool cheat_enabled; bool cheat_enabled;
uint32 cheat_count; uint32 cheat_count;

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define BSX_CPP
#include "bsx_base.cpp" #include "bsx_base.cpp"
#include "bsx_cart.cpp" #include "bsx_cart.cpp"

View File

@ -1,3 +1,5 @@
#ifdef BSX_CPP
void BSXBase::init() { void BSXBase::init() {
} }
@ -131,3 +133,5 @@ void BSXBase::mmio_write(uint addr, uint8 data) {
} break; } break;
} }
} }
#endif //ifdef BSX_CPP

View File

@ -1,3 +1,5 @@
#ifdef BSX_CPP
void BSXCart::init() { void BSXCart::init() {
} }
@ -93,3 +95,5 @@ BSXCart::~BSXCart() {
safe_free(sram_data); safe_free(sram_data);
safe_free(psram_data); safe_free(psram_data);
} }
#endif //ifdef BSX_CPP

View File

@ -1,3 +1,5 @@
#ifdef BSX_CPP
void BSXFlash::init() {} void BSXFlash::init() {}
void BSXFlash::enable() {} void BSXFlash::enable() {}
@ -107,3 +109,5 @@ void BSXFlash::write(uint addr, uint8 data) {
} }
} }
} }
#endif //ifdef BSX_CPP

View File

@ -6,6 +6,7 @@
*/ */
#include "../../base.h" #include "../../base.h"
#define CX4_CPP
#include "cx4data.cpp" #include "cx4data.cpp"
#include "cx4fn.cpp" #include "cx4fn.cpp"

View File

@ -1,3 +1,5 @@
#ifdef CX4_CPP
const uint8 Cx4::immediate_data[48] = { const uint8 Cx4::immediate_data[48] = {
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x80, 0xff, 0xff, 0x7f, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x80, 0xff, 0xff, 0x7f,
@ -181,3 +183,5 @@ const int16 Cx4::CosTable[512] = {
32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568, 32138, 32214, 32285, 32351, 32413, 32469, 32521, 32568,
32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765 32610, 32647, 32679, 32706, 32728, 32745, 32758, 32765
}; };
#endif //ifdef CX4_CPP

View File

@ -1,3 +1,5 @@
#ifdef CX4_CPP
#include <math.h> #include <math.h>
#define Tan(a) (CosTable[a] ? ((((int32)SinTable[a]) << 16) / CosTable[a]) : 0x80000000) #define Tan(a) (CosTable[a] ? ((((int32)SinTable[a]) << 16) / CosTable[a]) : 0x80000000)
#define sar(b, n) ((b) >> (n)) #define sar(b, n) ((b) >> (n))
@ -240,3 +242,5 @@ uint8 bit = 0x80;
LineY += D; LineY += D;
} }
} }
#endif //ifdef CX4_CPP

View File

@ -1,3 +1,5 @@
#ifdef CX4_CPP
//Build OAM //Build OAM
void Cx4::op00_00() { void Cx4::op00_00() {
uint32 oamptr = ram[0x626] << 2; uint32 oamptr = ram[0x626] << 2;
@ -217,3 +219,5 @@ uint16 mask2 = 0x3f3f;
destptr += 16; destptr += 16;
} }
} }
#endif //ifdef CX4_CPP

View File

@ -1,3 +1,5 @@
#ifdef CX4_CPP
//Sprite Functions //Sprite Functions
void Cx4::op00() { void Cx4::op00() {
switch(reg[0x4d]) { switch(reg[0x4d]) {
@ -220,3 +222,5 @@ void Cx4::op89() {
str(0, 0x054336); str(0, 0x054336);
str(1, 0xffffff); str(1, 0xffffff);
} }
#endif //ifdef CX4_CPP

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define DSP1_CPP
#include "dsp1emu.cpp" #include "dsp1emu.cpp"

View File

@ -1,3 +1,5 @@
#ifdef DSP1_CPP
// DSP-1's emulation code // DSP-1's emulation code
// //
// Based on research by Overload, The Dumper, Neviksti and Andreas Naive // Based on research by Overload, The Dumper, Neviksti and Andreas Naive
@ -1620,3 +1622,4 @@ const int16 Dsp1::SinTable[256] = {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
#endif //ifdef DSP1_CPP

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define DSP2_CPP
#include "dsp2_op.cpp" #include "dsp2_op.cpp"

View File

@ -1,3 +1,5 @@
#ifdef DSP2_CPP
//convert bitmap to bitplane tile //convert bitmap to bitplane tile
void DSP2::op01() { void DSP2::op01() {
//op01 size is always 32 bytes input and output //op01 size is always 32 bytes input and output
@ -171,3 +173,5 @@ uint8 pixelarray[512];
status.output[i] = (pixelarray[i << 1] << 4) | pixelarray[(i << 1) + 1]; status.output[i] = (pixelarray[i << 1] << 4) | pixelarray[(i << 1) + 1];
} }
} }
#endif //ifdef DSP2_CPP

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define DSP3_CPP
namespace DSP3i { namespace DSP3i {
#define bool8 uint8 #define bool8 uint8

View File

@ -1,3 +1,5 @@
#ifdef DSP3_CPP
//DSP-3 emulator code //DSP-3 emulator code
//Copyright (c) 2003-2006 John Weidman, Kris Bleakley, Lancer, z80 gaiden //Copyright (c) 2003-2006 John Weidman, Kris Bleakley, Lancer, z80 gaiden
@ -1140,3 +1142,5 @@ void InitDSP3()
{ {
DSP3_Reset(); DSP3_Reset();
} }
#endif //ifdef DSP3_CPP

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define DSP4_CPP
namespace DSP4i { namespace DSP4i {
inline uint16 READ_WORD(uint8 *addr) { inline uint16 READ_WORD(uint8 *addr) {

View File

@ -1,3 +1,5 @@
#ifdef DSP4_CPP
//DSP-4 emulator code //DSP-4 emulator code
//Copyright (c) 2004-2006 Dreamer Nom, John Weidman, Kris Bleakley, Nach, z80 gaiden //Copyright (c) 2004-2006 Dreamer Nom, John Weidman, Kris Bleakley, Nach, z80 gaiden
@ -2144,3 +2146,5 @@ void DSP4GetByte()
dsp4_byte = 0xff; dsp4_byte = 0xff;
} }
} }
#endif //ifdef DSP4_CPP

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define SDD1_CPP
#include "sdd1emu.cpp" #include "sdd1emu.cpp"

View File

@ -1,3 +1,5 @@
#ifdef SDD1_CPP
/************************************************************************ /************************************************************************
S-DD1'algorithm emulation code S-DD1'algorithm emulation code
@ -445,3 +447,5 @@ SDD1emu::SDD1emu() :
} }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
#endif //ifdef SDD1_CPP

View File

@ -1,4 +1,6 @@
#include "../../base.h" #include "../../base.h"
#define ST010_CPP
#include "st010_data.h" #include "st010_data.h"
#include "st010_op.cpp" #include "st010_op.cpp"

View File

@ -1,3 +1,5 @@
#ifdef ST010_CPP
//ST-010 emulation code - Copyright (C) 2003 The Dumper, Matthew Kendora, Overload, Feather //ST-010 emulation code - Copyright (C) 2003 The Dumper, Matthew Kendora, Overload, Feather
//bsnes port - Copyright (C) 2007 byuu //bsnes port - Copyright (C) 2007 byuu
@ -255,3 +257,5 @@ int16 x1, y1;
writew(0x0010, x1); writew(0x0010, x1);
writew(0x0012, y1); writew(0x0012, y1);
} }
#endif //ifdef ST010_CPP

View File

@ -5,6 +5,14 @@ static configuration config;
return config; return config;
} }
integral_setting File::autodetect_type(config(), "file.autodetect_type",
"Auto-detect file type by inspecting file header, rather than by file extension.\n"
"In other words, if a .zip file is renamed to .smc, it will still be correctly\n"
"identified as a .zip file. However, there is an infinitesimal (1:~500,000,000)\n"
"chance of a false detection when loading an uncompressed image file, if this\n"
"option is enabled.",
integral_setting::boolean, false);
string file_updatepath(const char *req_file, const char *req_path) { string file_updatepath(const char *req_file, const char *req_path) {
string file(req_file); string file(req_file);
replace(file, "\\", "/"); replace(file, "\\", "/");
@ -33,34 +41,16 @@ string_setting Path::base("path.base",
string_setting Path::rom(config(), "path.rom", string_setting Path::rom(config(), "path.rom",
"Default path to look for ROM files in (\"\" = use default directory)", ""); "Default path to look for ROM files in (\"\" = use default directory)", "");
string_setting Path::save(config(), "path.save", string_setting Path::save(config(), "path.save",
"Default path for all save RAM and cheat files (\"\" = use current directory)", ""); "Default path for all save RAM files (\"\" = use current directory)", "");
string_setting Path::cheat(config(), "path.cheat",
"Default path for all cheat files (\"\" = use current directory)", "");
string_setting Path::bsx(config(), "path.bsx", "", ""); string_setting Path::bsx(config(), "path.bsx", "", "");
string_setting Path::st(config(), "path.st", "", ""); string_setting Path::st(config(), "path.st", "", "");
integral_setting SNES::gamma_ramp(config(), "snes.colorfilter.gamma_ramp",
"Use precalculated TV-style gamma ramp", integral_setting::boolean, true);
integral_setting SNES::sepia(config(), "snes.colorfilter.sepia",
"Convert color to sepia tone", integral_setting::boolean, false);
integral_setting SNES::grayscale(config(), "snes.colorfilter.grayscale",
"Convert color to grayscale tone", integral_setting::boolean, false);
integral_setting SNES::invert(config(), "snes.colorfilter.invert",
"Invert output image colors", integral_setting::boolean, false);
integral_setting SNES::contrast(config(), "snes.colorfilter.contrast",
"Contrast", integral_setting::decimal, 0);
integral_setting SNES::brightness(config(), "snes.colorfilter.brightness",
"Brightness", integral_setting::decimal, 0);
integral_setting SNES::gamma(config(), "snes.colorfilter.gamma",
"Gamma", integral_setting::decimal, 80);
integral_setting SNES::ntsc_merge_fields(config(), "snes.ntsc_merge_fields",
"Merge fields in NTSC video filter\n"
"Set to true if using filter at any refresh rate other than 60hz\n"
"", integral_setting::boolean, true);
integral_setting SNES::controller_port0(config(), "snes.controller_port_1", integral_setting SNES::controller_port0(config(), "snes.controller_port_1",
"Controller attached to SNES port 1", integral_setting::decimal, ::SNES::DEVICEID_JOYPAD1); "Controller attached to SNES port 1", integral_setting::decimal, ::SNES::Input::DeviceIDJoypad1);
integral_setting SNES::controller_port1(config(), "snes.controller_port_2", integral_setting SNES::controller_port1(config(), "snes.controller_port_2",
"Controller attached to SNES port 2", integral_setting::decimal, ::SNES::DEVICEID_JOYPAD2); "Controller attached to SNES port 2", integral_setting::decimal, ::SNES::Input::DeviceIDJoypad2);
integral_setting CPU::ntsc_clock_rate(config(), "cpu.ntsc_clock_rate", integral_setting CPU::ntsc_clock_rate(config(), "cpu.ntsc_clock_rate",
"NTSC S-CPU clock rate (in hz)", integral_setting::decimal, 21477272); "NTSC S-CPU clock rate (in hz)", integral_setting::decimal, 21477272);
@ -126,4 +116,4 @@ integral_setting PPU::oam_pri1_enable("ppu.oam_pri1_enable", "Enable OAM Priorit
integral_setting PPU::oam_pri2_enable("ppu.oam_pri2_enable", "Enable OAM Priority 2", integral_setting::boolean, true); integral_setting PPU::oam_pri2_enable("ppu.oam_pri2_enable", "Enable OAM Priority 2", integral_setting::boolean, true);
integral_setting PPU::oam_pri3_enable("ppu.oam_pri3_enable", "Enable OAM Priority 3", integral_setting::boolean, true); integral_setting PPU::oam_pri3_enable("ppu.oam_pri3_enable", "Enable OAM Priority 3", integral_setting::boolean, true);
}; } //namespace config

View File

@ -4,14 +4,16 @@ extern configuration& config();
string file_updatepath(const char*, const char*); string file_updatepath(const char*, const char*);
extern struct File {
static integral_setting autodetect_type;
} file;
extern struct Path { extern struct Path {
static string_setting base, rom, save; static string_setting base, rom, save, cheat;
static string_setting bsx, st; static string_setting bsx, st;
} path; } path;
extern struct SNES { extern struct SNES {
static integral_setting gamma_ramp, sepia, grayscale, invert, contrast, brightness, gamma;
static integral_setting ntsc_merge_fields;
static integral_setting controller_port0; static integral_setting controller_port0;
static integral_setting controller_port1; static integral_setting controller_port1;
} snes; } snes;

View File

@ -1,4 +1,6 @@
#include "../base.h" #include "../base.h"
#define CPU_CPP
#include "dcpu.cpp" #include "dcpu.cpp"
CPU::CPU() { CPU::CPU() {

View File

@ -4,7 +4,6 @@ class CPU : public MMIO {
public: public:
virtual void enter() = 0; virtual void enter() = 0;
public:
//CPU version number //CPU version number
//* 1 and 2 are known //* 1 and 2 are known
//* reported by $4210 //* reported by $4210
@ -14,25 +13,20 @@ uint8 cpu_version;
//timing //timing
virtual uint16 vcounter() = 0; virtual uint16 vcounter() = 0;
virtual uint16 hcounter() = 0; virtual uint16 hcounter() = 0;
virtual uint16 hclock() = 0; virtual uint16 hdot() = 0;
virtual bool interlace() = 0;
virtual bool interlace_field() = 0;
virtual bool overscan() = 0;
virtual uint16 region_scanlines() = 0;
virtual void set_interlace(bool r) = 0;
virtual void set_overscan (bool r) = 0;
CPURegs regs; virtual uint8 pio_status() = 0;
virtual uint8 port_read(uint8 port) = 0; virtual uint8 port_read(uint8 port) = 0;
virtual void port_write(uint8 port, uint8 value) = 0; virtual void port_write(uint8 port, uint8 value) = 0;
CPURegs regs;
enum { enum {
FLAG_N = 0x80, FLAG_V = 0x40, FLAG_N = 0x80, FLAG_V = 0x40,
FLAG_M = 0x20, FLAG_X = 0x10, FLAG_M = 0x20, FLAG_X = 0x10,
FLAG_D = 0x08, FLAG_I = 0x04, FLAG_D = 0x08, FLAG_I = 0x04,
FLAG_Z = 0x02, FLAG_C = 0x01 FLAG_Z = 0x02, FLAG_C = 0x01
}; };
virtual uint8 pio_status() = 0;
virtual void scanline() = 0; virtual void scanline() = 0;
virtual void frame() = 0; virtual void frame() = 0;
virtual void power() = 0; virtual void power() = 0;

View File

@ -1,3 +1,5 @@
#ifdef CPU_CPP
uint8 CPU::dreadb(uint32 addr) { uint8 CPU::dreadb(uint32 addr) {
if((addr & 0x40ffff) >= 0x2000 && (addr & 0x40ffff) <= 0x5fff) { if((addr & 0x40ffff) >= 0x2000 && (addr & 0x40ffff) <= 0x5fff) {
//$[00-3f|80-bf]:[2000-5fff] //$[00-3f|80-bf]:[2000-5fff]
@ -423,7 +425,7 @@ uint8 op2 = dreadb(pc.d);
strcat(s, t); strcat(s, t);
strcat(s, " "); strcat(s, " ");
sprintf(t, "V:%3d H:%4d", vcounter(), hclock()); sprintf(t, "V:%3d H:%4d", vcounter(), hcounter());
strcat(s, t); strcat(s, t);
} }
@ -473,3 +475,5 @@ static uint8 op_len_tbl[256] = {
if(len == 6)return (regs.e || regs.p.x) ? 2 : 3; if(len == 6)return (regs.e || regs.p.x) ? 2 : 3;
return len; return len;
} }
#endif //ifdef CPU_CPP

View File

@ -1,3 +1,5 @@
#ifdef SCPU_CPP
#include "opfn.cpp" #include "opfn.cpp"
#include "op_read.cpp" #include "op_read.cpp"
@ -43,8 +45,6 @@ void sCPU::op_irq() {
regs.pc.w = rd.w; regs.pc.w = rd.w;
} }
//
alwaysinline void sCPU::op_io_cond2() { alwaysinline void sCPU::op_io_cond2() {
if(regs.d.l != 0x00) { if(regs.d.l != 0x00) {
op_io(); op_io();
@ -62,3 +62,5 @@ alwaysinline void sCPU::op_io_cond6(uint16 addr) {
op_io(); op_io();
} }
} }
#endif //ifdef SCPU_CPP

View File

@ -1,7 +1,7 @@
void (sCPU::*optbl[256])(); void (sCPU::*optbl[256])();
CPUReg24 aa, rd; CPUReg24 aa, rd;
uint8 dp, sp; uint8_t dp, sp;
void op_irq(); void op_irq();

View File

@ -1,3 +1,5 @@
#ifdef SCPU_CPP
//op_read //op_read
inline void sCPU::op_adc_b() { inline void sCPU::op_adc_b() {
int32 r = regs.a.l + rd.l + regs.p.c; int32 r = regs.a.l + rd.l + regs.p.c;
@ -371,3 +373,5 @@ inline void sCPU::op_tsb_w() {
regs.p.z = ((rd.w & regs.a.w) == 0); regs.p.z = ((rd.w & regs.a.w) == 0);
rd.w |= regs.a.w; rd.w |= regs.a.w;
} }
#endif //ifdef SCPU_CPP

View File

@ -1,3 +1,5 @@
#ifdef SCPU_CPP
void sCPU::dma_add_clocks(uint clocks) { void sCPU::dma_add_clocks(uint clocks) {
status.dma_clocks += clocks; status.dma_clocks += clocks;
add_clocks(clocks); add_clocks(clocks);
@ -10,30 +12,44 @@ void sCPU::dma_add_clocks(uint clocks) {
* $[00-3f|80-bf]:43[00-7f] <DMA control registers> * $[00-3f|80-bf]:43[00-7f] <DMA control registers>
* $[00-3f|80-bf]:420b <DMA enable register> * $[00-3f|80-bf]:420b <DMA enable register>
* $[00-3f|80-bf]:420c <HDMA enable register> * $[00-3f|80-bf]:420c <HDMA enable register>
* WRAM<>WRAM transfers via $2180 *
* WRAM<>WRAM transfers via $2180 are also illegal
*****/ *****/
void sCPU::dma_transfer(bool direction, uint8 bbus, uint32 abus) { void sCPU::dma_transfer(bool direction, uint8 bbus, uint32 abus) {
uint8 r; if(direction == 0) {
if(direction == 0) { //a->b //a->b transfer (to $21xx)
if((abus & 0x40ff00) == 0x2100 || (abus & 0x40ff80) == 0x4300 || if(bbus == 0x80 && ((abus & 0xfe0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) {
(abus & 0x40ffff) == 0x420b || (abus & 0x40ffff) == 0x420c) { //illegal WRAM->WRAM transfer
r = regs.mdr; //read most likely occurs; no write occurs
//read is irrelevant, as it has no observable effect on emulation
} else if((abus & 0x40ff00) == 0x2100 || (abus & 0x40ff80) == 0x4300
|| (abus & 0x40ffff) == 0x420b || (abus & 0x40ffff) == 0x420c) {
//illegal register access
bus.write(0x2100 | bbus, regs.mdr); //TODO: verify if MDR is written here
} else { } else {
r = bus.read(abus); //valid transfer
bus.write(0x2100 | bbus, bus.read(abus));
} }
bus.write(0x2100 | bbus, r);
} else { //b->a
if(bbus == 0x80 && ((abus & 0x7e0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) {
//prevent WRAM->WRAM transfers
r = regs.mdr;
} else { } else {
r = bus.read(0x2100 | bbus); //b->a transfer (from $21xx)
if(bbus == 0x80 && ((abus & 0xfe0000) == 0x7e0000 || (abus & 0x40e000) == 0x0000)) {
//illegal WRAM->WRAM transfer
//no read occurs; write does occur
//does not write MDR as expected
//TODO: 0x00 was observed on hardware; verify if other values are possible
bus.write(abus, 0x00);
} else if((abus & 0x40ff00) == 0x2100 || (abus & 0x40ff80) == 0x4300
|| (abus & 0x40ffff) == 0x420b || (abus & 0x40ffff) == 0x420c) {
//illegal register access
bus.write(abus, regs.mdr); //TODO: verify if MDR is written here
} else {
//valid transfer
bus.write(abus, bus.read(0x2100 | bbus));
} }
if((abus & 0x40ff00) == 0x2100 || (abus & 0x40ff80) == 0x4300 ||
(abus & 0x40ffff) == 0x420b || (abus & 0x40ffff) == 0x420c)return;
bus.write(abus, r);
} }
//each byte *always* consumes 8 clocks, even if transfer is invalid and no read and/or write occurs
dma_add_clocks(8); dma_add_clocks(8);
cycle_edge(); cycle_edge();
} }
@ -43,16 +59,15 @@ uint8 r;
*****/ *****/
uint8 sCPU::dma_bbus(uint8 i, uint8 index) { uint8 sCPU::dma_bbus(uint8 i, uint8 index) {
switch(channel[i].xfermode) { switch(channel[i].xfermode) { default:
default: case 0: return (channel[i].destaddr); //0
case 0: return (channel[i].destaddr); break; //0 case 1: return (channel[i].destaddr + (index & 1)); //0,1
case 1: return (channel[i].destaddr + (index & 1)); break; //0,1 case 2: return (channel[i].destaddr); //0,0
case 2: return (channel[i].destaddr); break; //0,0 case 3: return (channel[i].destaddr + ((index >> 1) & 1)); //0,0,1,1
case 3: return (channel[i].destaddr + ((index >> 1) & 1)); break; //0,0,1,1 case 4: return (channel[i].destaddr + (index & 3)); //0,1,2,3
case 4: return (channel[i].destaddr + (index & 3)); break; //0,1,2,3 case 5: return (channel[i].destaddr + (index & 1)); //0,1,0,1
case 5: return (channel[i].destaddr + (index & 1)); break; //0,1,0,1 case 6: return (channel[i].destaddr); //0,0 [2]
case 6: return (channel[i].destaddr); break; //0,0 [2] case 7: return (channel[i].destaddr + ((index >> 1) & 1)); //0,0,1,1 [3]
case 7: return (channel[i].destaddr + ((index >> 1) & 1)); break; //0,0,1,1 [3]
} }
} }
@ -144,9 +159,8 @@ inline bool sCPU::hdma_active(uint8 i) {
inline bool sCPU::hdma_active_after(uint8 i) { inline bool sCPU::hdma_active_after(uint8 i) {
for(int n = i + 1; n < 8; n++) { for(int n = i + 1; n < 8; n++) {
if(hdma_active(n) == true) { return true; } if(hdma_active(n) == true) return true;
} }
return false; return false;
} }
@ -271,3 +285,5 @@ void sCPU::dma_reset() {
channel[i].hdma_do_transfer = false; channel[i].hdma_do_transfer = false;
} }
} }
#endif //ifdef SCPU_CPP

View File

@ -1,3 +1,5 @@
#ifdef SCPU_CPP
/***** /*****
* These 3 functions control bus timing for the CPU. * These 3 functions control bus timing for the CPU.
* cpu_io is an I/O cycle, and always 6 clock cycles long. * cpu_io is an I/O cycle, and always 6 clock cycles long.
@ -119,3 +121,5 @@ alwaysinline void sCPU::op_writedp(uint32 addr, uint8 data) {
alwaysinline void sCPU::op_writesp(uint32 addr, uint8 data) { alwaysinline void sCPU::op_writesp(uint32 addr, uint8 data) {
op_write((regs.s + (addr & 0xffff)) & 0xffff, data); op_write((regs.s + (addr & 0xffff)) & 0xffff, data);
} }
#endif //ifdef SCPU_CPP

View File

@ -1,3 +1,5 @@
#ifdef SCPU_CPP
uint8 sCPU::pio_status() { uint8 sCPU::pio_status() {
return status.pio; return status.pio;
} }
@ -41,7 +43,7 @@ void sCPU::mmio_w4016(uint8 data) {
status.joypad_strobe_latch = !!(data & 1); status.joypad_strobe_latch = !!(data & 1);
if(status.joypad_strobe_latch == 1) { if(status.joypad_strobe_latch == 1) {
snes.poll_input(); snes.input.poll();
} }
} }
@ -53,7 +55,7 @@ void sCPU::mmio_w4016(uint8 data) {
//realtime or buffered status of joypadN.b //realtime or buffered status of joypadN.b
uint8 sCPU::mmio_r4016() { uint8 sCPU::mmio_r4016() {
uint8 r = regs.mdr & 0xfc; uint8 r = regs.mdr & 0xfc;
r |= (uint8)snes.port_read(0); r |= (uint8)snes.input.port_read(0);
return r; return r;
} }
@ -63,7 +65,7 @@ uint8 r = regs.mdr & 0xfc;
//1-0 = Joypad serial data //1-0 = Joypad serial data
uint8 sCPU::mmio_r4017() { uint8 sCPU::mmio_r4017() {
uint8 r = (regs.mdr & 0xe0) | 0x1c; uint8 r = (regs.mdr & 0xe0) | 0x1c;
r |= (uint8)snes.port_read(1); r |= (uint8)snes.input.port_read(1);
return r; return r;
} }
@ -189,13 +191,13 @@ uint8 r = (regs.mdr & 0x7f);
//0 = JOYPAD acknowledge //0 = JOYPAD acknowledge
uint8 sCPU::mmio_r4212() { uint8 sCPU::mmio_r4212() {
uint8 r = (regs.mdr & 0x3e); uint8 r = (regs.mdr & 0x3e);
uint16 vs = !overscan() ? 225 : 240; uint16 vs = ppu.overscan() == false ? 225 : 240;
//auto joypad polling //auto joypad polling
if(status.vcounter >= vs && status.vcounter <= (vs + 2))r |= 0x01; if(status.vcounter >= vs && status.vcounter <= (vs + 2))r |= 0x01;
//hblank //hblank
if(status.hclock <= 2 || status.hclock >= 1096)r |= 0x40; if(status.hcounter <= 2 || status.hcounter >= 1096)r |= 0x40;
//vblank //vblank
if(status.vcounter >= vs)r |= 0x80; if(status.vcounter >= vs)r |= 0x80;
@ -532,3 +534,5 @@ void sCPU::mmio_write(uint addr, uint8 data) {
case 0x420d: mmio_w420d(data); return; case 0x420d: mmio_w420d(data); return;
} }
} }
#endif //ifdef SCPU_CPP

View File

@ -1,4 +1,5 @@
#include "../../base.h" #include "../../base.h"
#define SCPU_CPP
#include "core/core.cpp" #include "core/core.cpp"
#include "dma/dma.cpp" #include "dma/dma.cpp"
@ -7,8 +8,6 @@
#include "timing/timing.cpp" #include "timing/timing.cpp"
void sCPU::power() { void sCPU::power() {
status.region = (bool)snes.region();
regs.a = regs.x = regs.y = 0x0000; regs.a = regs.x = regs.y = 0x0000;
regs.s = 0x01ff; regs.s = 0x01ff;

View File

@ -1,4 +1,5 @@
class sCPU : public CPU { public: class sCPU : public CPU {
public:
void enter(); void enter();
#include "core/core.h" #include "core/core.h"
@ -50,14 +51,8 @@ struct {
uint clock_count; uint clock_count;
//timing //timing
bool region; uint16 vcounter, hcounter;
uint16 region_scanlines;
uint16 vcounter, hcounter, hclock;
bool interlace, interlace_field;
bool overscan;
uint16 field_lines, line_clocks; uint16 field_lines, line_clocks;
uint16 prev_field_lines, prev_line_clocks;
uint16 vblstart;
bool line_rendered; bool line_rendered;
uint16 line_render_position; uint16 line_render_position;
@ -72,7 +67,6 @@ struct {
uint16 irq_delay; uint16 irq_delay;
uint16 vnmi_trigger_pos;
bool nmi_valid; bool nmi_valid;
bool nmi_line; bool nmi_line;
bool nmi_transition; bool nmi_transition;

View File

@ -1,15 +1,118 @@
#include "irqtiming.cpp" #ifdef SCPU_CPP
void sCPU::update_interrupts() {
if(irq_pos_valid() == true) {
status.virq_trigger_pos = status.virq_pos;
status.hirq_trigger_pos = 4 * ((status.hirq_enabled) ? (status.hirq_pos + 1) : 0);
} else {
status.virq_trigger_pos = IRQ_TRIGGER_NEVER;
status.hirq_trigger_pos = IRQ_TRIGGER_NEVER;
}
}
alwaysinline void sCPU::poll_interrupts() {
uint16_t vpos, hpos;
//NMI hold
if(counter.nmi_hold) {
counter.nmi_hold -= 2;
if(counter.nmi_hold == 0) {
if(status.nmi_enabled == true) status.nmi_transition = true;
}
}
//NMI test
history.query(2, vpos, hpos);
bool nmi_valid = (vpos >= (!ppu.overscan() ? 225 : 240));
if(status.nmi_valid == false && nmi_valid == true) {
//0->1 edge sensitive transition
status.nmi_line = true;
counter.nmi_hold = 4;
} else if(status.nmi_valid == true && nmi_valid == false) {
//1->0 edge sensitive transition
status.nmi_line = false;
}
status.nmi_valid = nmi_valid;
//IRQ hold
if(counter.irq_hold) counter.irq_hold -= 2;
if(status.irq_line == true && counter.irq_hold == 0) {
if(status.virq_enabled == true || status.hirq_enabled == true) status.irq_transition = true;
}
//IRQ test
history.query(10, vpos, hpos);
bool irq_valid = (status.virq_enabled == true || status.hirq_enabled == true);
if(irq_valid == true) {
if(status.virq_enabled == true && vpos != status.virq_trigger_pos) irq_valid = false;
if(status.hirq_enabled == true && hpos != status.hirq_trigger_pos) irq_valid = false;
}
if(status.irq_valid == false && irq_valid == true) {
//0->1 edge sensitive transition
status.irq_line = true;
counter.irq_hold = 4;
}
status.irq_valid = irq_valid;
}
void sCPU::nmitimen_update(uint8 data) {
bool nmi_enabled = status.nmi_enabled;
bool virq_enabled = status.virq_enabled;
bool hirq_enabled = status.hirq_enabled;
status.nmi_enabled = !!(data & 0x80);
status.virq_enabled = !!(data & 0x20);
status.hirq_enabled = !!(data & 0x10);
//0->1 edge sensitive transition
if(nmi_enabled == false && status.nmi_enabled == true && status.nmi_line == true) {
status.nmi_transition = true;
}
//?->1 level sensitive transition
if(status.virq_enabled == true && status.hirq_enabled == false && status.irq_line == true) {
status.irq_transition = true;
}
if(status.virq_enabled == false && status.hirq_enabled == false) {
status.irq_line = false;
status.irq_transition = false;
}
update_interrupts();
counter.set(counter.irq_delay, 2);
}
void sCPU::hvtime_update(uint16 addr) {
update_interrupts();
}
bool sCPU::rdnmi() {
bool result = status.nmi_line;
if(counter.nmi_hold == 0) {
status.nmi_line = false;
}
return result;
}
bool sCPU::timeup() {
bool result = status.irq_line;
if(counter.irq_hold == 0) {
status.irq_line = false;
status.irq_transition = false;
}
return result;
}
bool sCPU::irq_pos_valid() { bool sCPU::irq_pos_valid() {
uint vpos = status.virq_pos; uint vpos = status.virq_pos;
uint hpos = (status.hirq_enabled) ? status.hirq_pos : 0; uint hpos = (status.hirq_enabled) ? status.hirq_pos : 0;
uint vlimit = region_scanlines() >> 1; uint vlimit = (snes.region() == SNES::NTSC ? 525 : 625) >> 1;
//positions that can never be latched //positions that can never be latched
//vlimit = 262/NTSC, 312/PAL //vlimit = 262/NTSC, 312/PAL
//PAL results are unverified on hardware //PAL results are unverified on hardware
if(vpos == 240 && hpos == 339 && interlace() == false && interlace_field() == 1)return false; if(vpos == 240 && hpos == 339 && ppu.interlace() == false && ppu.field() == 1) return false;
if(vpos == (vlimit - 1) && hpos == 339 && interlace() == false)return false; if(vpos == (vlimit - 1) && hpos == 339 && ppu.interlace() == false) return false;
if(vpos == vlimit && interlace() == false)return false; if(vpos == vlimit && ppu.interlace() == false) return false;
if(vpos == vlimit && hpos == 339) return false; if(vpos == vlimit && hpos == 339) return false;
if(vpos > vlimit) return false; if(vpos > vlimit) return false;
if(hpos > 339) return false; if(hpos > 339) return false;
@ -17,44 +120,18 @@ uint vlimit = region_scanlines() >> 1;
return true; return true;
} }
alwaysinline alwaysinline bool sCPU::nmi_test() {
bool sCPU::nmi_test() { if(status.nmi_transition == false) return false;
if(status.nmi_transition == false) { return false; }
status.nmi_transition = false; status.nmi_transition = false;
event.wai = false; event.wai = false;
return true; return true;
} }
alwaysinline alwaysinline bool sCPU::irq_test() {
bool sCPU::irq_test() { if(status.irq_transition == false) return false;
if(status.irq_transition == false) { return false; }
status.irq_transition = false; status.irq_transition = false;
event.wai = false; event.wai = false;
return (regs.p.i) ? false : true; return regs.p.i ? false : true;
} }
/* #endif //ifdef SCPU_CPP
if(status.irq_transition == 1)goto irq_trigger;
if(status.irq_read == 0) {
if(status.irq_line == 1 && irq_edge()) {
return false;
}
goto irq_trigger;
}
if(status.irq_line == 0) {
status.irq_line = 1;
goto irq_trigger;
}
return false;
irq_trigger:
status.irq_transition = 0;
event.wai = false;
return (regs.p.i) ? false : true;
}
*/

View File

@ -1,105 +0,0 @@
void sCPU::update_interrupts() {
status.vnmi_trigger_pos = status.vblstart;
if(irq_pos_valid() == true) {
status.virq_trigger_pos = status.virq_pos;
status.hirq_trigger_pos = 4 * ((status.hirq_enabled) ? (status.hirq_pos + 1) : 0);
} else {
status.virq_trigger_pos = IRQ_TRIGGER_NEVER;
status.hirq_trigger_pos = IRQ_TRIGGER_NEVER;
}
}
alwaysinline
void sCPU::poll_interrupts() {
uint vpos = status.vcounter, hpos = status.hclock;
//NMI test
timeshift_backward(2, vpos, hpos);
bool nmi_valid = (vpos >= status.vnmi_trigger_pos);
if(status.nmi_valid == false && nmi_valid == true) {
//0->1 edge sensitive transition
status.nmi_line = true;
counter.nmi_hold = 6;
} else if(status.nmi_valid == true && nmi_valid == false) {
//1->0 edge sensitive transition
status.nmi_line = false;
}
status.nmi_valid = nmi_valid;
//NMI hold
if(counter.nmi_hold) {
counter.nmi_hold -= 2;
if(counter.nmi_hold == 0) {
if(status.nmi_enabled == true) { status.nmi_transition = true; }
}
}
//IRQ test
timeshift_backward(8, vpos, hpos);
bool irq_valid = (status.virq_enabled == true || status.hirq_enabled == true);
if(irq_valid == true) {
if(status.virq_enabled == true && vpos != status.virq_trigger_pos) { irq_valid = false; }
if(status.hirq_enabled == true && hpos != status.hirq_trigger_pos) { irq_valid = false; }
}
if(status.irq_valid == false && irq_valid == true) {
//0->1 edge sensitive transition
status.irq_line = true;
counter.irq_hold = 6;
}
status.irq_valid = irq_valid;
//IRQ hold
if(counter.irq_hold) { counter.irq_hold -= 2; }
if(status.irq_line == true && counter.irq_hold == 0) {
if(status.virq_enabled == true || status.hirq_enabled == true) { status.irq_transition = true; }
}
}
void sCPU::nmitimen_update(uint8 data) {
bool nmi_enabled = status.nmi_enabled;
bool virq_enabled = status.virq_enabled;
bool hirq_enabled = status.hirq_enabled;
status.nmi_enabled = !!(data & 0x80);
status.virq_enabled = !!(data & 0x20);
status.hirq_enabled = !!(data & 0x10);
//0->1 edge sensitive transition
if(nmi_enabled == false && status.nmi_enabled == true && status.nmi_line == true) {
status.nmi_transition = true;
}
//?->1 level sensitive transition
if(status.virq_enabled == true && status.hirq_enabled == false && status.irq_line == true) {
status.irq_transition = true;
}
if(status.virq_enabled == false && status.hirq_enabled == false) {
status.irq_line = false;
status.irq_transition = false;
}
update_interrupts();
counter.set(counter.irq_delay, 2);
}
void sCPU::hvtime_update(uint16 addr) {
update_interrupts();
}
bool sCPU::rdnmi() {
bool result = status.nmi_line;
if(counter.nmi_hold == 0) {
status.nmi_line = false;
}
return result;
}
bool sCPU::timeup() {
bool result = status.irq_line;
if(counter.irq_hold == 0) {
status.irq_line = false;
status.irq_transition = false;
}
return result;
}

View File

@ -1,8 +1,10 @@
#ifdef SCPU_CPP
void sCPU::run_auto_joypad_poll() { void sCPU::run_auto_joypad_poll() {
uint16 joy1 = 0, joy2 = 0; uint16_t joy1 = 0, joy2 = 0;
for(int i = 0; i < 16; i++) { for(unsigned i = 0; i < 16; i++) {
joy1 |= (uint16)snes.port_read(0) ? (0x8000 >> i) : 0; joy1 |= (uint16_t)snes.input.port_read(0) ? (0x8000 >> i) : 0;
joy2 |= (uint16)snes.port_read(1) ? (0x8000 >> i) : 0; joy2 |= (uint16_t)snes.input.port_read(1) ? (0x8000 >> i) : 0;
} }
status.joy1l = joy1; status.joy1l = joy1;
@ -17,3 +19,5 @@ uint16 joy1 = 0, joy2 = 0;
status.joy4l = 0x00; status.joy4l = 0x00;
status.joy4h = 0x00; status.joy4h = 0x00;
} }
#endif //ifdef SCPU_CPP

View File

@ -1,22 +0,0 @@
alwaysinline void sCPU::timeshift_forward(uint clocks, uint &vtime, uint &htime) {
htime += clocks;
if(htime >= status.line_clocks) {
htime -= status.line_clocks;
if(++vtime >= status.field_lines) {
vtime = 0;
}
}
}
alwaysinline void sCPU::timeshift_backward(uint clocks, uint &vtime, uint &htime) {
if(htime >= clocks) {
htime -= clocks;
} else {
htime += status.prev_line_clocks - clocks;
if(vtime > 0) {
vtime--;
} else {
vtime = status.prev_field_lines - 1;
}
}
}

View File

@ -1,31 +1,16 @@
#define ntsc_color_burst_phase_shift_scanline() \ #ifdef SCPU_CPP
(status.region == SNES::NTSC && status.vcounter == 240 && \
status.interlace == false && status.interlace_field == 1) #define ntsc_color_burst_phase_shift_scanline() ( \
snes.region() == SNES::NTSC && status.vcounter == 240 && \
ppu.interlace() == false && ppu.field() == 1 \
)
#include "timeshift.cpp"
#include "irq.cpp" #include "irq.cpp"
#include "joypad.cpp" #include "joypad.cpp"
uint16 sCPU::vcounter() { return status.vcounter; } uint16 sCPU::vcounter() { return status.vcounter; }
uint16 sCPU::hclock() { return status.hclock; } uint16 sCPU::hcounter() { return status.hcounter; }
uint sCPU::dma_counter() { return (status.dma_counter + status.hcounter) & 7; }
bool sCPU::interlace() { return status.interlace; }
bool sCPU::interlace_field() { return status.interlace_field; }
bool sCPU::overscan() { return status.overscan; }
uint16 sCPU::region_scanlines() { return status.region_scanlines; }
uint sCPU::dma_counter() { return (status.dma_counter + status.hclock) & 7; }
void sCPU::set_interlace(bool r) {
status.interlace = r;
update_interrupts();
}
void sCPU::set_overscan (bool r) {
status.overscan = r;
status.vblstart = (status.overscan == false) ? 225 : 240;
update_interrupts();
}
/***** /*****
* One PPU dot = 4 CPU clocks * One PPU dot = 4 CPU clocks
@ -37,16 +22,14 @@ void sCPU::set_overscan (bool r) {
* Dot 323 range = { 1292, 1294, 1296 } * Dot 323 range = { 1292, 1294, 1296 }
* Dot 327 range = { 1310, 1312, 1314 } * Dot 327 range = { 1310, 1312, 1314 }
*****/ *****/
uint16 sCPU::hcounter() { uint16 sCPU::hdot() {
if(ntsc_color_burst_phase_shift_scanline() == true) { if(ntsc_color_burst_phase_shift_scanline() == true) return (status.hcounter >> 2);
return (status.hclock >> 2); return (status.hcounter - ((status.hcounter > 1292) << 1) - ((status.hcounter > 1310) << 1)) >> 2;
}
return (status.hclock - ((status.hclock > 1292) << 1) - ((status.hclock > 1310) << 1)) >> 2;
} }
void sCPU::add_clocks(uint clocks) { void sCPU::add_clocks(uint clocks) {
if(status.dram_refreshed == false) { if(status.dram_refreshed == false) {
if(status.hclock + clocks >= status.dram_refresh_position) { if(status.hcounter + clocks >= status.dram_refresh_position) {
status.dram_refreshed = true; status.dram_refreshed = true;
clocks += 40; clocks += 40;
} }
@ -57,21 +40,17 @@ void sCPU::add_clocks(uint clocks) {
clocks >>= 1; clocks >>= 1;
while(clocks--) { while(clocks--) {
status.hclock += 2; history.enqueue(status.vcounter, status.hcounter);
if(status.hclock >= status.line_clocks) { scanline(); } status.hcounter += 2;
if(status.hcounter >= status.line_clocks) scanline();
poll_interrupts(); poll_interrupts();
} }
} }
void sCPU::scanline() { void sCPU::scanline() {
status.hclock = 0; status.hcounter = 0;
status.dma_counter = (status.dma_counter + status.line_clocks) & 7; status.dma_counter = (status.dma_counter + status.line_clocks) & 7;
if(++status.vcounter >= status.field_lines) frame();
if(++status.vcounter >= status.field_lines) {
frame();
}
status.prev_line_clocks = status.line_clocks;
status.line_clocks = (ntsc_color_burst_phase_shift_scanline() == false) ? 1364 : 1360; status.line_clocks = (ntsc_color_burst_phase_shift_scanline() == false) ? 1364 : 1360;
//dram refresh occurs once every scanline //dram refresh occurs once every scanline
@ -88,27 +67,28 @@ void sCPU::scanline() {
//hdma triggers once every visible scanline //hdma triggers once every visible scanline
status.line_rendered = false; status.line_rendered = false;
status.hdma_triggered = (status.vcounter <= (!overscan() ? 224 : 239)) ? false : true; status.hdma_triggered = (status.vcounter <= (ppu.overscan() == false ? 224 : 239)) ? false : true;
ppu.scanline(); ppu.scanline();
snes.scanline(); snes.scanline();
update_interrupts(); update_interrupts();
if(status.auto_joypad_poll == true && status.vcounter == (!overscan() ? 227 : 242)) { if(status.auto_joypad_poll == true && status.vcounter == (ppu.overscan() == false ? 227 : 242)) {
snes.poll_input(); snes.input.poll();
run_auto_joypad_poll(); run_auto_joypad_poll();
} }
} }
void sCPU::frame() { void sCPU::frame() {
ppu.frame();
snes.frame();
status.vcounter = 0; status.vcounter = 0;
status.interlace_field ^= 1; status.field_lines = (snes.region() == SNES::NTSC ? 525 : 625) >> 1;
status.prev_field_lines = status.field_lines;
status.field_lines = (status.region_scanlines >> 1);
//interlaced even fields have one extra scanline //interlaced even fields have one extra scanline
//(263+262=525 NTSC, 313+312=625 PAL) //(263+262=525 NTSC, 313+312=625 PAL)
if(status.interlace == true && status.interlace_field == 0)status.field_lines++; if(ppu.interlace() == true && ppu.field() == 0) status.field_lines++;
status.hdmainit_triggered = false; status.hdmainit_triggered = false;
if(cpu_version == 1) { if(cpu_version == 1) {
@ -116,9 +96,6 @@ void sCPU::frame() {
} else { } else {
status.hdmainit_trigger_position = 12 + dma_counter(); status.hdmainit_trigger_position = 12 + dma_counter();
} }
ppu.frame();
snes.frame();
} }
/***** /*****
@ -141,21 +118,20 @@ alwaysinline void sCPU::precycle_edge() {
*****/ *****/
void sCPU::cycle_edge() { void sCPU::cycle_edge() {
if(status.line_rendered == false) { if(status.line_rendered == false) {
if(status.hclock >= status.line_render_position) { if(status.hcounter >= status.line_render_position) {
status.line_rendered = true; status.line_rendered = true;
ppu.render_scanline(); ppu.render_scanline();
} }
} }
switch(status.dma_state) { switch(status.dma_state) {
case DMASTATE_INACTIVE: case DMASTATE_INACTIVE: break;
break;
case DMASTATE_DMASYNC: case DMASTATE_DMASYNC: {
status.dma_state = DMASTATE_RUN; status.dma_state = DMASTATE_RUN;
break; } break;
case DMASTATE_RUN: case DMASTATE_RUN: {
status.dma_state = DMASTATE_CPUSYNC; status.dma_state = DMASTATE_CPUSYNC;
status.dma_clocks = 8 - dma_counter() + 8; status.dma_clocks = 8 - dma_counter() + 8;
add_clocks(status.dma_clocks); add_clocks(status.dma_clocks);
@ -164,11 +140,11 @@ void sCPU::cycle_edge() {
if(status.hdma_pending) { hdma_run(); status.hdma_pending = false; } if(status.hdma_pending) { hdma_run(); status.hdma_pending = false; }
if(status.dma_pending) { dma_run(); status.dma_pending = false; } if(status.dma_pending) { dma_run(); status.dma_pending = false; }
break; } break;
} }
if(status.hdmainit_triggered == false) { if(status.hdmainit_triggered == false) {
if(status.hclock >= status.hdmainit_trigger_position || status.vcounter) { if(status.hcounter >= status.hdmainit_trigger_position || status.vcounter) {
status.hdmainit_triggered = true; status.hdmainit_triggered = true;
hdma_init_reset(); hdma_init_reset();
if(hdma_enabled_channels()) { if(hdma_enabled_channels()) {
@ -185,7 +161,7 @@ void sCPU::cycle_edge() {
} }
if(status.hdma_triggered == false) { if(status.hdma_triggered == false) {
if(status.hclock >= 1106) { if(status.hcounter >= 1106) {
status.hdma_triggered = true; status.hdma_triggered = true;
if(hdma_active_channels()) { if(hdma_active_channels()) {
add_clocks(18); add_clocks(18);
@ -211,7 +187,7 @@ void sCPU::cycle_edge() {
* trigger during certain events (immediately after DMA, writes to $4200, etc) * trigger during certain events (immediately after DMA, writes to $4200, etc)
*****/ *****/
void sCPU::last_cycle() { void sCPU::last_cycle() {
if(counter.irq_delay) { return; } if(counter.irq_delay) return;
status.nmi_pending |= nmi_test(); status.nmi_pending |= nmi_test();
status.irq_pending |= irq_test(); status.irq_pending |= irq_test();
@ -235,20 +211,10 @@ void sCPU::timing_reset() {
status.vcounter = 0; status.vcounter = 0;
status.hcounter = 0; status.hcounter = 0;
status.hclock = 0;
status.interlace = 0; status.field_lines = (snes.region() == SNES::NTSC ? 525 : 625) >> 1;
status.interlace_field = 0;
status.overscan = false;
status.region_scanlines = (status.region == SNES::NTSC) ? 525 : 625;
status.vblstart = 225;
status.field_lines = status.region_scanlines >> 1;
status.line_clocks = 1364; status.line_clocks = 1364;
status.prev_field_lines = status.region_scanlines >> 1;
status.prev_line_clocks = 1364;
status.line_rendered = false; status.line_rendered = false;
status.line_render_position = min(1112U, (uint)config::ppu.hack.render_scanline_position); status.line_render_position = min(1112U, (uint)config::ppu.hack.render_scanline_position);
@ -280,10 +246,14 @@ void sCPU::timing_reset() {
status.hdma_pending = false; status.hdma_pending = false;
status.hdmainit_pending = false; status.hdmainit_pending = false;
history.reset();
//initial latch values for $213c/$213d //initial latch values for $213c/$213d
//[x]0035 : [y]0000 (53.0 -> 212) [lda $2137] //[x]0035 : [y]0000 (53.0 -> 212) [lda $2137]
//[x]0038 : [y]0000 (56.5 -> 226) [nop : lda $2137] //[x]0038 : [y]0000 (56.5 -> 226) [nop : lda $2137]
//add_clocks(186); add_clocks(186);
} }
#undef ntsc_color_burst_phase_shift_scanline #undef ntsc_color_burst_phase_shift_scanline
#endif //ifdef SCPU_CPP

View File

@ -1,15 +1,6 @@
uint16 vcounter(); uint16 vcounter();
uint16 hcounter(); uint16 hcounter();
uint16 hclock(); uint16 hdot();
bool interlace();
bool interlace_field();
bool overscan();
uint16 region_scanlines();
void set_interlace(bool r);
void set_overscan(bool r);
uint dma_counter(); uint dma_counter();
void add_clocks(uint clocks); void add_clocks(uint clocks);
@ -24,9 +15,30 @@
void timing_power(); void timing_power();
void timing_reset(); void timing_reset();
//timeshift.cpp //timeshifting -- needed by NMI and IRQ timing
void timeshift_forward (uint clocks, uint &v, uint &h); struct History {
void timeshift_backward(uint clocks, uint &v, uint &h); struct Time {
uint16 vcounter;
uint16 hcounter;
} time[32];
unsigned index;
alwaysinline void enqueue(uint16 vcounter, uint16 hcounter) {
Time &t = time[index++];
index &= 31;
t.vcounter = vcounter;
t.hcounter = hcounter;
}
alwaysinline void query(unsigned offset, uint16 &vcounter, uint16 &hcounter) {
Time &t = time[(index - (offset >> 1)) & 31];
vcounter = t.vcounter;
hcounter = t.hcounter;
}
void reset() {
index = 0;
for(unsigned i = 0; i < 32; i++) time[i].vcounter = time[i].hcounter = 0;
}
History() { reset(); }
} history;
//irq.cpp //irq.cpp
enum { IRQ_TRIGGER_NEVER = 0x3fff }; enum { IRQ_TRIGGER_NEVER = 0x3fff };

1013
src/data/controller.h Normal file

File diff suppressed because it is too large Load Diff

40
src/data/icon48.h Normal file
View File

@ -0,0 +1,40 @@
static char enc_icon48[] = {
"_gAB8AHwAfAB8AHwAfAB8P8B8AHwAfAB8AHwAfAB8AHw_wHwAfAB8AHwAfAB8AHw"
"AfD_AfAB8AHwAfAB8AHwAfAB8P8B8AHwAfAB8AHwAfAB8AHw_wHwAfAB8AHwAfAB"
"8AHwAfD_AfAB8AHwAfAB8AHwAfAB8P8B8AHwAfAB8AHwAfAB8AHw_wHwAfAB8AHw"
"AfAB8AHwAfD_AfAB8AHwAfAB8AHwAfABgFD_oRYPBAA1BABWVQQAWwQAQQQAGgQA"
"Av8u8AHwAfAB8AHwAfAB8AHwVbSAAQQALQQAsAQA9FUEAP8EwPsEAM4EAFP9BAAE"
"QvAB8AHwAfAB8AHwqwHwvOAEBACFBAD5uPDVBOD-BAC9BAAUSvAB8L8B8AHwAfAB"
"8AHwvGADBACuoqjwBPAEwNsEABZS8H8B8AHwAfAB8AHwAfDAIHuvnPAE8ATwBCDH"
"BAAFVvC_AfAB8AHwAfAB8LzAIAQA3vaY8ATwBPAEYGZa8AHw3wHwAfAB8AHwwMCX"
"kPAE8OsE8ASg3wQABl7wAfAB8K8B8AHwAfC8QAYEAOeQ8PcE8ATw0OMvYvAB8AHw"
"AfDXAfAB8MBAHAQA_JDwBPALBPAE4GRi8AAAPz9U_wEEAA0EAB0EAB59BAAPBABE"
"9gHwAfDA8BVVBABxBAB3BAChUET9p5zwBPAE8BaGuMALBACqbAQAzgQA9AQA-wQA"
"qvwEAPYEANYEAHoEAL4SlvAB8AHwAfAEhjIEAF68FEKo8ATwBFCBcIFHtQQA5AQA"
"_wTwBKDuBAB-XDQQjvAB8AHwAfAQhmhHzPYE8ARgpQ5YwEBor2xBsPAE8AQQ_QQA"
"hFTyfwHwAfAB8MjA-Bgg8wTQowAQ-_-rACMuNrz_SrzwBPAE8MQgZ4LwbwHwAfAB"
"8BDJkbTwBMCnAAfLfV-0ETU6fP_mnPAE8ATwBCAkExxfhvAB8AHwAfDEgBEEAO0D"
"uPAEQKQO_f-tAIBCLDX_cTw-mPA3BPAE8ASAlYLwAUDNAKoBBAAFBAAUBAAiBAB-"
"JQhAEBAYEETz5PYE8KgABZxKRfIENju8_9eQ8ATwBPAEoOq0wKoDBAAsBACGBADM"
"BADq7AQA_AQA_gSAEBAYEOrKBACDBAAqBABMo6gAFkC88AQgrvgCBy83wP8VPj7_"
"-JDwBPCvBPAIs7yAuBDEoED_BPBXBPAEQDAQwAQAKcCAHRf8S7hQMBl_uFk4O_--"
"KYzwBPAE8ATwvEBhBABe95zwBPAE8ARg9gQAW1HAIJ8XFKwA8uhIkFUEAB-sxhkE"
"AH0EAJL1BADDBADznPAE8ATwwADozQBIBAD5kPAE8ATwAQTg-ADQACn_nrwYAshD"
"pPUB8NAQEQQA3nGgRqjwBPDAkOKI8ATw9wTwBPAEIM8UAwHwAfAB8HvIEPQYzKjw"
"BPAEQDQS0t-I8ATwBPAE8ARAeprwAfB3AfDEYLAZyqzwBPAEAMX1cAAvBADxiPAE"
"8ATwBOB68AQAGZbwAfAB8MSgHK0EAPGw8ASg_gQAScBDvj4URZTwBPAE8AQw6gQA"
"RjwN9mwJ__8IBAAT_QQAGgRADBAUEET2xHDgE6u48ARwuwQAA0CFGQQAup0EAPOc"
"8ATwBIDyBACgmADLABe0gAkEAKpFBACaBADSBADsBABa-QQA-wRADBDtBADTVQQA"
"nQQASAQACsDAGK0EAPW48AQg3QQAFfbwVcggEQQAUwQAoRxD6b0EAPRcJNwwEBAY"
"EJ8EAKpRBAAQuIAGBABuBAC66AQA_wTwBPAEgOoEAEpzBAAHSxBBOFgryF-88BQg"
"LHEB8NDQBgQAC10EAA0IQLj-vDAQBADFr5jwBPAE8ASgywQAFMRA6pm4gOcEAHAE"
"AOAgAfCvAfAB8AHwvEACBAC1jPAvBPAE8ATwBAC_VBBDMtT_TrAAeQQAPAQAYKLf"
"AfAB8AHwAfDAQBnYQozw1wTwBPAE8P0EAB1p8AHwrwHwAfAB8MDgGAQA-ojw7wTw"
"BPAE8AQA_AQA3PsB8N8B8AHwAfDA8CQVsYjwBPD3BPAE8AQAulz1AfAB8AHw1wHw"
"AfDEQA0EAL2M8ATw9wTwBKAEFBFh8AHwAfAB8FcB8AHwxIAFBABoBADjXQQA_pzw"
"BPAEgOUEAG3_hCUB8AHwAfAB8AHwAfAB8KvIEFwXPQQAkgQAz8BGXveYQwQQDBAU"
"ENAEAJT9BABB9CYB8AHwAfAB8AHwrwHwAfAB8NBwBAQADtgl_QQwDxRA5PIB8AHw"
"AfAB8P8B8AHwAfAB8AHwAfAB8AHw_wHwAfAB8AHwAfAB8AHwAfD_AfAB8AHwAfAB"
"8AHwAfAB8P8B8AHwAfAB8AHwAfAB8AHw_wHwAfAB8AHwAfAB8AHwAfD_AfAB8AHw"
"AfAB8AHwAfAB8P8B8AHwAfAB8AHwAfAB8AHwfwHwAfAB8AHwAfAB8AGA"
};

View File

@ -1,4 +1,6 @@
#include "../../base.h" #include "../../base.h"
#define ADSP_CPP
#include "adsp_tables.cpp" #include "adsp_tables.cpp"
void aDSP::enter() { loop: void aDSP::enter() { loop:
@ -579,7 +581,7 @@ int32 fir_samplel, fir_sampler;
} }
snes.audio_update(msamplel, msampler); snes.audio_update(msamplel, msampler);
scheduler.addclocks_dsp(32 * 3); scheduler.addclocks_dsp(32 * 3 * 8);
} }
aDSP::aDSP() {} aDSP::aDSP() {}

View File

@ -1,3 +1,5 @@
#ifdef ADSP_CPP
const uint16 aDSP::rate_table[32] = { const uint16 aDSP::rate_table[32] = {
0x0000, 0x000F, 0x0014, 0x0018, 0x001E, 0x0028, 0x0030, 0x003C, 0x0000, 0x000F, 0x0014, 0x0018, 0x001E, 0x0028, 0x0030, 0x003C,
0x0050, 0x0060, 0x0078, 0x00A0, 0x00C0, 0x00F0, 0x0140, 0x0180, 0x0050, 0x0060, 0x0078, 0x00A0, 0x00C0, 0x00F0, 0x0140, 0x0180,
@ -71,3 +73,5 @@ const int16 aDSP::gaussian_table[512] = {
0x513, 0x514, 0x514, 0x515, 0x516, 0x516, 0x517, 0x517, 0x513, 0x514, 0x514, 0x515, 0x516, 0x516, 0x517, 0x517,
0x517, 0x518, 0x518, 0x518, 0x518, 0x518, 0x519, 0x519 0x517, 0x518, 0x518, 0x518, 0x518, 0x518, 0x519, 0x519
}; };
#endif //ifdef ADSP_CPP

View File

@ -469,7 +469,7 @@ void bDSP::enter()
{ {
// n is currently ignored // n is currently ignored
#define NEXT_CLOCK( n ) \ #define NEXT_CLOCK( n ) \
scheduler.addclocks_dsp( 3 ); scheduler.addclocks_dsp( 3 * 8 );
// Execute clock for a particular voice // Execute clock for a particular voice
#define V( clock, voice ) voice_##clock( &m.voices [voice] ); #define V( clock, voice ) voice_##clock( &m.voices [voice] );
@ -563,7 +563,7 @@ void bDSP::enter()
} }
// Output sample to DAC // Output sample to DAC
snes.audio_update( main_out_l, main_out_r ); snes.audio.update( main_out_l, main_out_r );
m.t_main_out [0] = 0; m.t_main_out [0] = 0;
m.t_main_out [1] = 0; m.t_main_out [1] = 0;

View File

@ -1,4 +1,5 @@
class DSP { public: class DSP {
public:
virtual void enter() = 0; virtual void enter() = 0;
virtual uint8 read(uint8 addr) = 0; virtual uint8 read(uint8 addr) = 0;

View File

@ -38,12 +38,24 @@ void pHiro::init() {
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
free(argv[0]); free(argv[0]);
free(argv); free(argv);
is_composited = false;
screen = gdk_screen_get_default();
if(gdk_screen_is_composited(screen)) {
colormap = gdk_screen_get_rgba_colormap(screen);
if(colormap) is_composited = true;
else colormap = gdk_screen_get_rgb_colormap(screen); //fallback
} else {
colormap = gdk_screen_get_rgb_colormap(screen);
}
} }
void pHiro::term() { void pHiro::term() {
enable_screensaver();
} }
bool pHiro::run() { bool pHiro::run() {
if(is_screensaver_enabled == false) screensaver_tick();
gtk_main_iteration_do(false); gtk_main_iteration_do(false);
return pending(); return pending();
} }
@ -52,11 +64,34 @@ bool pHiro::pending() {
return gtk_events_pending(); return gtk_events_pending();
} }
bool pHiro::file_load(Window *focus, char *filename, const char *filter, const char *path) { bool pHiro::folder_select(Window *focus, char *filename, const char *path) {
if(!filename) return false; if(!filename) return false;
strcpy(filename, ""); strcpy(filename, "");
GtkWidget *dialog = gtk_file_chooser_dialog_new("Load File", GtkWidget *dialog = gtk_file_chooser_dialog_new("Select Folder",
focus ? GTK_WINDOW(focus->p.gtk_handle()) : (GtkWindow*)0,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
(const gchar*)0);
if(path && *path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char *fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
strcpy(filename, fn);
g_free(fn);
}
gtk_widget_destroy(dialog);
return strcmp(filename, ""); //return true if filename exists
}
bool pHiro::file_open(Window *focus, char *filename, const char *path, const char *filter) {
if(!filename) return false;
strcpy(filename, "");
GtkWidget *dialog = gtk_file_chooser_dialog_new("Open File",
focus ? GTK_WINDOW(focus->p.gtk_handle()) : (GtkWindow*)0, focus ? GTK_WINDOW(focus->p.gtk_handle()) : (GtkWindow*)0,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
@ -75,7 +110,7 @@ bool pHiro::file_load(Window *focus, char *filename, const char *filter, const c
return strcmp(filename, ""); //return true if filename exists return strcmp(filename, ""); //return true if filename exists
} }
bool pHiro::file_save(Window *focus, char *filename, const char *filter, const char *path) { bool pHiro::file_save(Window *focus, char *filename, const char *path, const char *filter) {
if(!filename) return false; if(!filename) return false;
strcpy(filename, ""); strcpy(filename, "");
@ -107,15 +142,50 @@ uint pHiro::screen_height() {
return gdk_screen_height(); return gdk_screen_height();
} }
void pHiro::enable_screensaver() {
if(is_screensaver_enabled == true) return;
is_screensaver_enabled = true;
DPMSDisable(GDK_DISPLAY());
}
void pHiro::disable_screensaver() {
if(is_screensaver_enabled == false) return;
is_screensaver_enabled = false;
DPMSEnable(GDK_DISPLAY());
}
pHiro& pHiro::handle() { pHiro& pHiro::handle() {
return hiro().p; return hiro().p;
} }
pHiro::pHiro(Hiro &self_) : self(self_) { pHiro::pHiro(Hiro &self_) : self(self_) {
is_screensaver_enabled = true;
} }
pHiro& phiro() { pHiro& phiro() {
return pHiro::handle(); return pHiro::handle();
} }
/* internal */
void pHiro::screensaver_tick() {
static clock_t delta_x = 0, delta_y = 0;
delta_y = clock();
if(delta_y - delta_x < CLOCKS_PER_SEC * 20) return;
//XSetScreenSaver(timeout = 0) does not work
//XResetScreenSaver() does not work
//XScreenSaverSuspend() does not work
//DPMSDisable() does not work
//XSendEvent(KeyPressMask) does not work
//use XTest extension to send fake keypress every ~20 seconds.
//keycode of 255 does not map to any actual key, but it will block screensaver.
delta_x = delta_y;
XTestFakeKeyEvent(GDK_DISPLAY(), 255, True, 0);
XSync(GDK_DISPLAY(), False);
XTestFakeKeyEvent(GDK_DISPLAY(), 255, False, 0);
XSync(GDK_DISPLAY(), False);
}
} //namespace libhiro } //namespace libhiro

View File

@ -3,7 +3,10 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <cairo.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <X11/extensions/dpms.h>
#include <X11/extensions/XTest.h>
namespace libhiro { namespace libhiro {
@ -36,16 +39,26 @@ public:
bool run(); bool run();
bool pending(); bool pending();
bool file_load(Window *focus, char *filename, const char *filter, const char *path); bool folder_select(Window *focus, char *filename, const char *path = "");
bool file_save(Window *focus, char *filename, const char *filter, const char *path); bool file_open(Window *focus, char *filename, const char *path = "", const char *filter = "");
bool file_save(Window *focus, char *filename, const char *path = "", const char *filter = "");
uint screen_width(); uint screen_width();
uint screen_height(); uint screen_height();
void enable_screensaver();
void disable_screensaver();
static pHiro& handle(); static pHiro& handle();
pHiro(Hiro&); pHiro(Hiro&);
/* internal */ /* internal */
GdkScreen *screen;
GdkColormap *colormap;
bool is_composited;
bool is_screensaver_enabled;
void screensaver_tick();
uint16_t translate_key(uint key); uint16_t translate_key(uint key);
}; };

Some files were not shown because too many files have changed in this diff Show More