forked from libretro/beetle-psx-libretro
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Themaister
committed
Jun 3, 2012
0 parents
commit e942ae8
Showing
314 changed files
with
191,389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.o | ||
*.so | ||
*.dll | ||
*.dylib | ||
/old | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
TARGET := libretro.so | ||
|
||
MEDNAFEN_DIR := mednafen | ||
PSX_DIR := $(MEDNAFEN_DIR)/psx | ||
|
||
PSX_SOURCES := $(PSX_DIR)/psx.cpp \ | ||
$(PSX_DIR)/irq.cpp \ | ||
$(PSX_DIR)/timer.cpp \ | ||
$(PSX_DIR)/dma.cpp \ | ||
$(PSX_DIR)/frontio.cpp \ | ||
$(PSX_DIR)/sio.cpp \ | ||
$(PSX_DIR)/cpu.cpp \ | ||
$(PSX_DIR)/gte.cpp \ | ||
$(PSX_DIR)/dis.cpp \ | ||
$(PSX_DIR)/cdc.cpp \ | ||
$(PSX_DIR)/spu.cpp \ | ||
$(PSX_DIR)/gpu.cpp \ | ||
$(PSX_DIR)/mdec.cpp \ | ||
$(PSX_DIR)/input/gamepad.cpp \ | ||
$(PSX_DIR)/input/dualanalog.cpp \ | ||
$(PSX_DIR)/input/memcard.cpp \ | ||
$(PSX_DIR)/input/multitap.cpp \ | ||
$(PSX_DIR)/input/mouse.cpp | ||
|
||
MEDNAFEN_SOURCES := $(MEDNAFEN_DIR)/cdrom/cdromif.cpp \ | ||
$(MEDNAFEN_DIR)/mednafen.cpp \ | ||
$(MEDNAFEN_DIR)/PSFLoader.cpp \ | ||
$(MEDNAFEN_DIR)/error.cpp \ | ||
$(MEDNAFEN_DIR)/math_ops.cpp \ | ||
$(MEDNAFEN_DIR)/settings.cpp \ | ||
$(MEDNAFEN_DIR)/netplay.cpp \ | ||
$(MEDNAFEN_DIR)/general.cpp \ | ||
$(MEDNAFEN_DIR)/player.cpp \ | ||
$(MEDNAFEN_DIR)/cdplay.cpp \ | ||
$(MEDNAFEN_DIR)/FileWrapper.cpp \ | ||
$(MEDNAFEN_DIR)/state.cpp \ | ||
$(MEDNAFEN_DIR)/tests.cpp \ | ||
$(MEDNAFEN_DIR)/movie.cpp \ | ||
$(MEDNAFEN_DIR)/endian.cpp \ | ||
$(MEDNAFEN_DIR)/qtrecord.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/CDAccess.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/CDAccess_Image.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/CDUtility.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/lec.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/SimpleFIFO.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/audioreader.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/galois.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/pcecd.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/scsicd.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/recover-raw.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/l-ec.cpp \ | ||
$(MEDNAFEN_DIR)/cdrom/crc32.cpp \ | ||
$(MEDNAFEN_DIR)/memory.cpp \ | ||
$(MEDNAFEN_DIR)/mempatcher.cpp \ | ||
$(MEDNAFEN_DIR)/video/video.cpp \ | ||
$(MEDNAFEN_DIR)/video/text.cpp \ | ||
$(MEDNAFEN_DIR)/video/font-data.cpp \ | ||
$(MEDNAFEN_DIR)/video/tblur.cpp \ | ||
$(MEDNAFEN_DIR)/video/png.cpp \ | ||
$(MEDNAFEN_DIR)/video/Deinterlacer.cpp \ | ||
$(MEDNAFEN_DIR)/video/surface.cpp \ | ||
$(MEDNAFEN_DIR)/video/resize.cpp \ | ||
$(MEDNAFEN_DIR)/string/escape.cpp \ | ||
$(MEDNAFEN_DIR)/string/ConvertUTF.cpp \ | ||
$(MEDNAFEN_DIR)/sound/Blip_Buffer.cpp \ | ||
$(MEDNAFEN_DIR)/sound/Fir_Resampler.cpp \ | ||
$(MEDNAFEN_DIR)/sound/Stereo_Buffer.cpp \ | ||
$(MEDNAFEN_DIR)/sound/WAVRecord.cpp \ | ||
$(MEDNAFEN_DIR)/sound/sound.cpp \ | ||
$(MEDNAFEN_DIR)/file.cpp \ | ||
$(MEDNAFEN_DIR)/okiadpcm.cpp \ | ||
$(MEDNAFEN_DIR)/md5.cpp | ||
|
||
MPC_SRC := $(wildcard $(MEDNAFEN_DIR)/mpcdec/*.c) | ||
TREMOR_SRC := $(wildcard $(MEDNAFEN_DIR)/tremor/*.c) | ||
|
||
SOURCES_C := $(MEDNAFEN_DIR)/trio/trio.c \ | ||
$(MPC_SRC) \ | ||
$(TREMOR_SRC) \ | ||
$(MEDNAFEN_DIR)/trio/trionan.c \ | ||
$(MEDNAFEN_DIR)/trio/triostr.c \ | ||
$(MEDNAFEN_DIR)/string/world_strtod.c \ | ||
$(MEDNAFEN_DIR)/compress/blz.c \ | ||
$(MEDNAFEN_DIR)/compress/unzip.c \ | ||
$(MEDNAFEN_DIR)/compress/minilzo.c \ | ||
$(MEDNAFEN_DIR)/compress/quicklz.c \ | ||
$(MEDNAFEN_DIR)/compress/ioapi.c \ | ||
$(MEDNAFEN_DIR)/resampler/resample.c | ||
|
||
LIBRETRO_SOURCES := libretro.cpp stubs.cpp | ||
|
||
SOURCES := $(LIBRETRO_SOURCES) $(PSX_SOURCES) $(MEDNAFEN_SOURCES) | ||
OBJECTS := $(SOURCES:.cpp=.o) $(SOURCES_C:.c=.o) | ||
|
||
all: $(TARGET) | ||
|
||
|
||
LDFLAGS += -Wl,--no-undefined -fPIC -shared -lz -Wl,--version-script=link.T -pthread | ||
FLAGS += -ffast-math -msse -msse2 -funroll-loops -O3 -g -Wall -fPIC -fno-strict-overflow -fno-strict-aliasing | ||
FLAGS += -I. -Imednafen -Imednafen/include -Imednafen/intl -pthread | ||
|
||
WARNINGS := -Wall \ | ||
-Wno-narrowing \ | ||
-Wno-unused-but-set-variable \ | ||
-Wno-sign-compare \ | ||
-Wno-unused-variable \ | ||
-Wno-unused-function \ | ||
-Wno-uninitialized \ | ||
-Wno-unused-result \ | ||
-Wno-overflow | ||
|
||
FLAGS += -DLSB_FIRST -DHAVE_MKDIR -DSIZEOF_DOUBLE=8 $(WARNINGS) \ | ||
-DMEDNAFEN_VERSION=\"0.9.22\" -DMEDNAFEN_VERSION_NUMERIC=922 -DPSS_STYLE=1 -DMPC_FIXED_POINT -DARCH_X86 \ | ||
-DWANT_PSX_EMU -DSTDC_HEADERS | ||
|
||
CXXFLAGS += $(FLAGS) | ||
CFLAGS += $(FLAGS) -std=gnu99 | ||
|
||
$(TARGET): $(OBJECTS) | ||
$(CXX) -o $@ $^ $(LDFLAGS) | ||
|
||
%.o: %.cpp | ||
$(CXX) -c -o $@ $< $(CXXFLAGS) | ||
|
||
%.o: %.c | ||
$(CC) -c -o $@ $< $(CFLAGS) | ||
|
||
clean: | ||
rm -f $(TARGET) $(OBJECTS) | ||
|
||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
#include "mednafen/mednafen-types.h" | ||
#include "mednafen/mednafen.h" | ||
#include "mednafen/git.h" | ||
#include "mednafen/general.h" | ||
#include <iostream> | ||
#include "libretro.h" | ||
|
||
static MDFNGI *game; | ||
static retro_video_refresh_t video_cb; | ||
static retro_audio_sample_t audio_cb; | ||
static retro_audio_sample_batch_t audio_batch_cb; | ||
static retro_environment_t environ_cb; | ||
static retro_input_poll_t input_poll_cb; | ||
static retro_input_state_t input_state_cb; | ||
|
||
static MDFN_Surface *surf; | ||
|
||
static uint16_t conv_buf[680 * 512] __attribute__((aligned(16))); | ||
static uint32_t mednafen_buf[680 * 512] __attribute__((aligned(16))); | ||
|
||
void retro_init() | ||
{ | ||
MDFN_PixelFormat pix_fmt(MDFN_COLORSPACE_RGB, 16, 8, 0, 24); | ||
surf = new MDFN_Surface(mednafen_buf, 680, 512, 680, pix_fmt); | ||
|
||
std::vector<MDFNGI*> ext; | ||
MDFNI_InitializeModules(ext); | ||
|
||
std::vector<MDFNSetting> settings; | ||
std::string home = getenv("HOME"); | ||
home += "/.mednafen"; | ||
MDFNI_Initialize(home.c_str(), settings); | ||
} | ||
|
||
void retro_deinit() | ||
{ | ||
//MDFNI_Kill(); | ||
delete surf; | ||
surf = NULL; | ||
} | ||
|
||
void retro_reset() | ||
{ | ||
MDFNI_Reset(); | ||
} | ||
|
||
bool retro_load_game_special(unsigned, const struct retro_game_info *, size_t) | ||
{ | ||
return false; | ||
} | ||
|
||
bool retro_load_game(const struct retro_game_info *info) | ||
{ | ||
game = MDFNI_LoadGame("psx", info->path); | ||
return game; | ||
} | ||
|
||
void retro_unload_game() | ||
{ | ||
MDFNI_CloseGame(); | ||
} | ||
|
||
static inline uint16_t conv_pixel(uint32_t pix) | ||
{ | ||
uint16_t r = (pix >> 19) & 0x1f; | ||
uint16_t g = (pix >> 11) & 0x1f; | ||
uint16_t b = (pix >> 3) & 0x1f; | ||
return (r << 10) | (g << 5) | (b << 0); | ||
} | ||
|
||
void retro_run() | ||
{ | ||
input_poll_cb(); | ||
|
||
static int16_t sound_buf[0x10000]; | ||
static MDFN_Rect rects[512]; | ||
|
||
EmulateSpecStruct spec = {0}; | ||
spec.surface = surf; | ||
spec.SoundRate = 44100; | ||
spec.SoundBuf = sound_buf; | ||
spec.LineWidths = rects; | ||
spec.SoundBufMaxSize = sizeof(sound_buf) / 2; | ||
spec.SoundVolume = 1.0; | ||
spec.soundmultiplier = 1.0; | ||
|
||
MDFNI_Emulate(&spec); | ||
|
||
unsigned width = rects[0].w; | ||
unsigned height = spec.DisplayRect.h; | ||
|
||
for (unsigned i = 0; i < 680 * 512; i++) | ||
conv_buf[i] = conv_pixel(surf->pixels[i]); | ||
|
||
video_cb(conv_buf, width, height, 680 << 1); | ||
|
||
audio_batch_cb(spec.SoundBuf, spec.SoundBufSize); | ||
} | ||
|
||
void retro_get_system_info(struct retro_system_info *info) | ||
{ | ||
memset(info, 0, sizeof(*info)); | ||
info->library_name = "Mednafen PSX"; | ||
info->library_version = "0.9.22"; | ||
info->need_fullpath = true; | ||
info->valid_extensions = "iso|ISO"; | ||
} | ||
|
||
void retro_get_system_av_info(struct retro_system_av_info *info) | ||
{ | ||
memset(info, 0, sizeof(*info)); | ||
info->timing.fps = 59.97; | ||
info->timing.sample_rate = 44100; | ||
info->geometry.base_width = game->nominal_width; | ||
info->geometry.base_height = game->nominal_height; | ||
info->geometry.max_width = 680; | ||
info->geometry.max_height = 480; | ||
info->geometry.aspect_ratio = 4.0 / 3.0; | ||
} | ||
|
||
unsigned retro_get_region(void) | ||
{ | ||
return RETRO_REGION_NTSC; | ||
} | ||
|
||
unsigned retro_api_version(void) | ||
{ | ||
return RETRO_API_VERSION; | ||
} | ||
|
||
void retro_set_controller_port_device(unsigned port, unsigned device) | ||
{ | ||
(void)port; | ||
(void)device; | ||
} | ||
|
||
void retro_set_environment(retro_environment_t cb) | ||
{ | ||
environ_cb = cb; | ||
} | ||
|
||
void retro_set_audio_sample(retro_audio_sample_t cb) | ||
{ | ||
audio_cb = cb; | ||
} | ||
|
||
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) | ||
{ | ||
audio_batch_cb = cb; | ||
} | ||
|
||
void retro_set_input_poll(retro_input_poll_t cb) | ||
{ | ||
input_poll_cb = cb; | ||
} | ||
|
||
void retro_set_input_state(retro_input_state_t cb) | ||
{ | ||
input_state_cb = cb; | ||
} | ||
|
||
void retro_set_video_refresh(retro_video_refresh_t cb) | ||
{ | ||
video_cb = cb; | ||
} | ||
|
||
size_t retro_serialize_size(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
bool retro_serialize(void *, size_t) | ||
{ | ||
return false; | ||
} | ||
|
||
bool retro_unserialize(const void *, size_t) | ||
{ | ||
return false; | ||
} | ||
|
||
void *retro_get_memory_data(unsigned) | ||
{ | ||
return NULL; | ||
} | ||
|
||
size_t retro_get_memory_size(unsigned) | ||
{ | ||
return 0; | ||
} | ||
|
||
void retro_cheat_reset(void) | ||
{} | ||
|
||
void retro_cheat_set(unsigned, bool, const char *) | ||
{} | ||
|
Oops, something went wrong.