summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneonloop2021-03-12 16:11:08 +0000
committerneonloop2021-03-12 16:11:08 +0000
commite117e43bd06627f7fadb2c58adf07e058f100579 (patch)
tree5ee6bc026b2c6790f4cf5df1f166f3da8c4831d7
parent6d4c2c9b14b626df0fa71cb1869770d2923a470d (diff)
downloadsnes9x2002-e117e43bd06627f7fadb2c58adf07e058f100579.tar.gz
snes9x2002-e117e43bd06627f7fadb2c58adf07e058f100579.tar.bz2
snes9x2002-e117e43bd06627f7fadb2c58adf07e058f100579.zip
Initial trimui s support
-rw-r--r--Makefile.common3
-rw-r--r--Makefile.trimui89
-rw-r--r--shell/audio/alsa/sound_output.c146
-rw-r--r--shell/audio/oss/sound_output.c63
-rw-r--r--shell/audio/portaudio/sound_output.c45
-rw-r--r--shell/audio/sdl/sound_output.c119
-rw-r--r--shell/audio/sound_output.h12
-rw-r--r--shell/emu/core.c358
-rw-r--r--shell/emu/main.h8
-rw-r--r--shell/headers/boolean.h39
-rw-r--r--shell/headers/retro_inline.h39
-rw-r--r--shell/headers/shared.h30
-rw-r--r--shell/input/input.h6
-rw-r--r--shell/input/sdl/input.c100
-rw-r--r--shell/menu/buttons.h31
-rw-r--r--shell/menu/buttons_trimui.h25
-rw-r--r--shell/menu/config.h11
-rw-r--r--shell/menu/font_drawing.c131
-rw-r--r--shell/menu/font_drawing.h13
-rw-r--r--shell/menu/font_menudata.h135
-rw-r--r--shell/menu/menu.c585
-rw-r--r--shell/menu/menu.h18
-rw-r--r--shell/other/compatibility_layer.c206
-rw-r--r--shell/scalers/scaler.c138
-rw-r--r--shell/scalers/scaler.h11
-rw-r--r--shell/video/gcw0/video_blit.c106
-rw-r--r--shell/video/gcw0/video_blit.h24
-rw-r--r--shell/video/retrostone/video_blit.c107
-rw-r--r--shell/video/retrostone/video_blit.h24
-rw-r--r--shell/video/sdl/video_blit.c111
-rw-r--r--shell/video/sdl/video_blit.h24
-rw-r--r--src/asmmemfuncs.h4
-rw-r--r--src/os9x_65c816.S4
-rw-r--r--src/os9x_65c816_global.S2
-rw-r--r--src/os9x_65c816_global_armv4.S2
-rw-r--r--src/os9x_65c816_spcasm.S4
-rw-r--r--src/os9x_65c816_spcasm.s.last4
-rw-r--r--src/os9x_65c816_spcc.S4
-rw-r--r--src/port.h8
-rw-r--r--src/snes9x.h28
40 files changed, 2792 insertions, 25 deletions
diff --git a/Makefile.common b/Makefile.common
index 5bde095..1f987a9 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -25,8 +25,7 @@ SOURCES := $(CORE_DIR)/apu.c \
$(CORE_DIR)/snapshot.c \
$(CORE_DIR)/soundux.c \
$(CORE_DIR)/spc700.c \
- $(CORE_DIR)/srtc.c \
- $(LIBRETRO_DIR)/libretro.c
+ $(CORE_DIR)/srtc.c
ifeq ($(STATIC_LINKING), 1)
else
diff --git a/Makefile.trimui b/Makefile.trimui
new file mode 100644
index 0000000..4a35848
--- /dev/null
+++ b/Makefile.trimui
@@ -0,0 +1,89 @@
+GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always)"
+
+PRGNAME = snes9x
+
+VIDEO_BACKEND = sdl
+INPUT_BACKEND = sdl
+SOUND_BACKEND = sdl
+
+PREFIX = arm-buildroot-linux-gnueabi
+
+# define regarding OS, which compiler to use
+CC = $(PREFIX)-gcc
+STRIP = $(PREFIX)-strip
+AS = $(PREFIX)-as
+GASM = $(PREFIX)-g++
+
+SYSROOT := $(shell $(CC) --print-sysroot)
+SDL_CFLAGS := $(shell $(SYSROOT)/usr/bin/sdl-config --cflags)
+SDL_LIBS := $(shell $(SYSROOT)/usr/bin/sdl-config --libs)
+
+# change compilation / linking flag options
+CFLAGS = -DLSB_FIRST -DFAST_ALIGNED_LSB_WORD_ACCESS -I. -Ilibretro/libretro-common/include -Isrc -DRIGHTSHIFT_IS_SAR
+CFLAGS += -I./shell/emu -I./shell/scalers -I./shell/emu -I./shell/audio -I./shell/menu -I./shell/video/sdl -I./shell/input -Ishell/headers
+
+CFLAGS += -Ofast -fsingle-precision-constant -fno-PIC -flto
+ifndef PROFILE
+CFLAGS += -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1
+endif
+CFLAGS += -mcpu=arm926ej-s -mtune=arm926ej-s
+CFLAGS += -DNDEBUG -DAUDIO_FRAMESKIP -DGIT_VERSION=\"$(GIT_VERSION)\" -DTRIMUI -fno-builtin -fno-exceptions -ffunction-sections -std=gnu99
+CFLAGS += -Wall -Wextra -pedantic -Wno-implicit-function-declaration -Wno-implicit-fallthrough -Wno-sign-compare -Wno-unused-variable -Wno-unused-function -Wno-uninitialized -Wno-strict-aliasing -Wno-overflow -fno-strict-overflow
+
+ifeq ($(PROFILE), YES)
+CFLAGS += -fprofile-generate=./profile
+else ifeq ($(PROFILE), APPLY)
+CFLAGS += -fprofile-use -fprofile-dir=./profile -fbranch-probabilities
+endif
+
+LDFLAGS = -lc -lgcc -lm $(SDL_LIBS) -no-pie -Wl,--as-needed -Wl,--gc-sections -s -flto
+ifeq ($(SOUND_BACKEND), portaudio)
+LDFLAGS += -lasound -lportaudio
+endif
+ifeq ($(SOUND_BACKEND), libao)
+LDFLAGS += -lao
+endif
+ifeq ($(SOUND_BACKEND), alsa)
+LDFLAGS += -lasound
+endif
+ifeq ($(SOUND_BACKEND), pulse)
+LDFLAGS += -lpulse -lpulse-simple
+endif
+
+ifeq ($(PROFILE), YES)
+LDFLAGS += -lgcov
+endif
+
+CORE_DIR := ./src
+LIBRETRO_DIR := ./libretro
+
+LAGFIX = 1
+ARM_ASM = 1
+ASM_CPU = 0
+ASM_SPC700 = 0
+
+include Makefile.common
+
+# Files to be compiled
+SRCDIR = ./shell/emu ./shell/scalers ./shell/audio/$(SOUND_BACKEND) ./shell/menu ./shell/video/$(VIDEO_BACKEND) ./shell/input/$(INPUT_BACKEND) ./shell/other
+VPATH = $(SRCDIR)
+SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c))
+SRC_CP = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.cpp))
+OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C)))
+OBJ_CP = $(notdir $(patsubst %.cpp, %.o, $(SRC_CP)))
+OBJS = $(SOURCES:.c=.o) $(SOURCES_ASM:.S=.o) $(OBJ_C) $(OBJ_CP)
+
+CFLAGS += $(DEFINES) $(COMMON_DEFINES) $(INCLUDES)
+
+# Rules to make executable
+$(PRGNAME): $(OBJS)
+ $(CC) $(CFLAGS) -o $(PRGNAME) $^ $(LDFLAGS)
+
+%.o : %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+%.o: %.S
+ $(CC) $(CFLAGS) -Wa,-I./src/ -c -o $(OBJOUT)$@ $<
+
+clean:
+ rm -f $(PRGNAME)$(EXESUFFIX) *.o src/*.o
diff --git a/shell/audio/alsa/sound_output.c b/shell/audio/alsa/sound_output.c
new file mode 100644
index 0000000..4da70a7
--- /dev/null
+++ b/shell/audio/alsa/sound_output.c
@@ -0,0 +1,146 @@
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <alsa/asoundlib.h>
+
+#include "sound_output.h"
+
+static snd_pcm_t *handle;
+
+uint32_t Audio_Init()
+{
+ snd_pcm_hw_params_t *params;
+ uint32_t val;
+ int32_t dir = -1;
+ snd_pcm_uframes_t frames;
+
+ /* Open PCM device for playback. */
+ int32_t rc = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
+
+ if (rc < 0)
+ rc = snd_pcm_open(&handle, "plughw:0,0,0", SND_PCM_STREAM_PLAYBACK, 0);
+
+ if (rc < 0)
+ rc = snd_pcm_open(&handle, "plughw:0,0", SND_PCM_STREAM_PLAYBACK, 0);
+
+ if (rc < 0)
+ rc = snd_pcm_open(&handle, "plughw:1,0,0", SND_PCM_STREAM_PLAYBACK, 0);
+
+ if (rc < 0)
+ rc = snd_pcm_open(&handle, "plughw:1,0", SND_PCM_STREAM_PLAYBACK, 0);
+
+ if (rc < 0)
+ {
+ fprintf(stderr, "unable to open PCM device: %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ /* Allocate a hardware parameters object. */
+ snd_pcm_hw_params_alloca(&params);
+
+ /* Fill it in with default values. */
+ rc = snd_pcm_hw_params_any(handle, params);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_any %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ /* Set the desired hardware parameters. */
+
+ /* Interleaved mode */
+ rc = snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_set_access %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ /* Signed 16-bit little-endian format */
+ rc = snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_set_format %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ /* Two channels (stereo) */
+ rc = snd_pcm_hw_params_set_channels(handle, params, 2);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_set_channels %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ val = SOUND_OUTPUT_FREQUENCY;
+ rc = snd_pcm_hw_params_set_rate_near(handle, params, &val, &dir);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_set_rate_near %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ /* Set period size to settings.aica.BufferSize frames. */
+ frames = SOUND_SAMPLES_SIZE;
+ rc = snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &dir);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_set_buffer_size_near %s\n", snd_strerror(rc));
+ return 1;
+ }
+ frames *= 4;
+ rc = snd_pcm_hw_params_set_buffer_size_near(handle, params, &frames);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Error:snd_pcm_hw_params_set_buffer_size_near %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ /* Write the parameters to the driver */
+ rc = snd_pcm_hw_params(handle, params);
+ if (rc < 0)
+ {
+ fprintf(stderr, "Unable to set hw parameters: %s\n", snd_strerror(rc));
+ return 1;
+ }
+
+ return 0;
+}
+
+void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size)
+{
+ uint32_t i;
+ long ret, len;
+
+ if (!handle) return;
+
+ len = buffer_size;
+
+ ret = snd_pcm_writei(handle, buffer, len);
+ while(ret != len)
+ {
+ if (ret < 0)
+ {
+ snd_pcm_prepare( handle );
+ }
+ else
+ {
+ len -= ret;
+ }
+ ret = snd_pcm_writei(handle, buffer, len);
+ }
+}
+
+bool Audio_Underrun_Likely() {
+ return false;
+}
+
+void Audio_Close()
+{
+ if (handle)
+ {
+ snd_pcm_drain(handle);
+ snd_pcm_close(handle);
+ }
+}
diff --git a/shell/audio/oss/sound_output.c b/shell/audio/oss/sound_output.c
new file mode 100644
index 0000000..39a7ba3
--- /dev/null
+++ b/shell/audio/oss/sound_output.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/soundcard.h>
+
+#include "sound_output.h"
+
+static int32_t oss_audio_fd = -1;
+
+uint32_t Audio_Init()
+{
+ uint32_t channels = 2;
+ uint32_t format = AFMT_S16_LE;
+ uint32_t tmp = SOUND_OUTPUT_FREQUENCY;
+ int32_t err_ret;
+
+ oss_audio_fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK);
+ if (oss_audio_fd < 0)
+ {
+ printf("Couldn't open /dev/dsp.\n");
+ return 1;
+ }
+
+ err_ret = ioctl(oss_audio_fd, SNDCTL_DSP_SPEED,&tmp);
+ if (err_ret == -1)
+ {
+ printf("Could not set sound frequency\n");
+ return 1;
+ }
+ err_ret = ioctl(oss_audio_fd, SNDCTL_DSP_CHANNELS, &channels);
+ if (err_ret == -1)
+ {
+ printf("Could not set channels\n");
+ return 1;
+ }
+ err_ret = ioctl(oss_audio_fd, SNDCTL_DSP_SETFMT, &format);
+ if (err_ret == -1)
+ {
+ printf("Could not set sound format\n");
+ return 1;
+ }
+ return 0;
+}
+
+void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size)
+{
+ write(oss_audio_fd, buffer, buffer_size * 4 );
+}
+
+bool Audio_Underrun_Likely() {
+ return false;
+}
+
+void Audio_Close()
+{
+ if (oss_audio_fd >= 0)
+ {
+ close(oss_audio_fd);
+ oss_audio_fd = -1;
+ }
+}
diff --git a/shell/audio/portaudio/sound_output.c b/shell/audio/portaudio/sound_output.c
new file mode 100644
index 0000000..0c03c93
--- /dev/null
+++ b/shell/audio/portaudio/sound_output.c
@@ -0,0 +1,45 @@
+#include <portaudio.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "shared.h"
+
+static PaStream *apu_stream;
+
+uint32_t Audio_Init()
+{
+ Pa_Initialize();
+
+ PaStreamParameters outputParameters;
+
+ outputParameters.device = Pa_GetDefaultOutputDevice();
+
+ if (outputParameters.device == paNoDevice)
+ {
+ printf("No sound output\n");
+ return 1;
+ }
+
+ outputParameters.channelCount = 2;
+ outputParameters.sampleFormat = paInt16;
+ outputParameters.hostApiSpecificStreamInfo = NULL;
+
+ Pa_OpenStream( &apu_stream, NULL, &outputParameters, SOUND_OUTPUT_FREQUENCY, SOUND_SAMPLES_SIZE, paNoFlag, NULL, NULL);
+ Pa_StartStream( apu_stream );
+
+ return 0;
+}
+
+void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size)
+{
+ Pa_WriteStream( apu_stream, buffer, buffer_size);
+}
+
+bool Audio_Underrun_Likely() {
+ return false;
+}
+
+void Audio_Close()
+{
+ //Pa_Close();
+}
diff --git a/shell/audio/sdl/sound_output.c b/shell/audio/sdl/sound_output.c
new file mode 100644
index 0000000..0758718
--- /dev/null
+++ b/shell/audio/sdl/sound_output.c
@@ -0,0 +1,119 @@
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <SDL/SDL.h>
+
+#include "sound_output.h"
+
+#define UNDERRUN_THRESHOLD 0.5
+
+static int32_t BUFFSIZE;
+static uint8_t *buffer;
+static uint32_t buf_read_pos = 0;
+static uint32_t buf_write_pos = 0;
+static int32_t buffered_bytes = 0;
+
+static int32_t sdl_read_buffer(uint8_t* data, int32_t len)
+{
+ if (buffered_bytes >= len)
+ {
+ if(buf_read_pos + len <= BUFFSIZE )
+ {
+ memcpy(data, buffer + buf_read_pos, len);
+ }
+ else
+ {
+ int32_t tail = BUFFSIZE - buf_read_pos;
+ memcpy(data, buffer + buf_read_pos, tail);
+ memcpy(data + tail, buffer, len - tail);
+ }
+ buf_read_pos = (buf_read_pos + len) % BUFFSIZE;
+ buffered_bytes -= len;
+ }
+
+ return len;
+}
+
+
+static void sdl_write_buffer(uint8_t* data, int32_t len)
+{
+ SDL_LockAudio();
+ for(uint32_t i = 0; i < len; i += 4)
+ {
+ while (buffered_bytes == BUFFSIZE) {
+ SDL_UnlockAudio();
+ usleep(1000);
+ SDL_LockAudio();
+ }
+ *(int32_t*)((char*)(buffer + buf_write_pos)) = *(int32_t*)((char*)(data + i));
+ //memcpy(buffer + buf_write_pos, data + i, 4);
+ buf_write_pos = (buf_write_pos + 4) % BUFFSIZE;
+ buffered_bytes += 4;
+ }
+ SDL_UnlockAudio();
+}
+
+void sdl_callback(void *unused, uint8_t *stream, int32_t len)
+{
+ sdl_read_buffer((uint8_t *)stream, len);
+}
+uint32_t Audio_Init()
+{
+ SDL_AudioSpec aspec, obtained;
+
+ BUFFSIZE = (SOUND_SAMPLES_SIZE * 2 * 2) * 4;
+ buffer = (uint8_t *) malloc(BUFFSIZE);
+
+ /* Add some silence to the buffer */
+ buffered_bytes = 0;
+ buf_read_pos = 0;
+ buf_write_pos = 0;
+
+ aspec.format = AUDIO_S16SYS;
+ aspec.freq = SOUND_OUTPUT_FREQUENCY;
+ aspec.channels = 2;
+ aspec.samples = SOUND_SAMPLES_SIZE;
+ aspec.callback = (sdl_callback);
+ aspec.userdata = NULL;
+
+ /* initialize the SDL Audio system */
+ if (SDL_InitSubSystem (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE))
+ {
+ printf("SDL: Initializing of SDL Audio failed: %s.\n", SDL_GetError());
+ return 1;
+ }
+
+ /* Open the audio device and start playing sound! */
+ if(SDL_OpenAudio(&aspec, &obtained) < 0)
+ {
+ printf("SDL: Unable to open audio: %s\n", SDL_GetError());
+ return 1;
+ }
+
+ SDL_PauseAudio(0);
+
+ return 0;
+}
+
+void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size)
+{
+ sdl_write_buffer(buffer, buffer_size * 4);
+}
+
+bool Audio_Underrun_Likely() {
+ bool underrun_likely = false;
+ SDL_LockAudio();
+ underrun_likely = buffered_bytes < BUFFSIZE * UNDERRUN_THRESHOLD;
+ SDL_UnlockAudio();
+ return underrun_likely;
+}
+
+void Audio_Close()
+{
+ SDL_PauseAudio(1);
+ SDL_CloseAudio();
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ buffer = NULL;
+}
diff --git a/shell/audio/sound_output.h b/shell/audio/sound_output.h
new file mode 100644
index 0000000..b770fbe
--- /dev/null
+++ b/shell/audio/sound_output.h
@@ -0,0 +1,12 @@
+#ifndef SOUND_OUTPUT_H
+#define SOUND_OUTPUT_H
+
+#include <stdbool.h>
+#include "shared.h"
+
+extern uint32_t Audio_Init();
+extern void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size);
+extern bool Audio_Underrun_Likely();
+extern void Audio_Close();
+
+#endif
diff --git a/shell/emu/core.c b/shell/emu/core.c
new file mode 100644
index 0000000..99759a6
--- /dev/null
+++ b/shell/emu/core.c
@@ -0,0 +1,358 @@
+// Author: skogaby
+// Lots of examples were followed using other emulators found on github
+
+#include <SDL/SDL.h>
+#include <libgen.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+#include "main.h"
+#include "snes9x.h"
+#include "soundux.h"
+#include "memmap.h"
+#include "apu.h"
+#ifdef USE_BLARGG_APU
+#include "apu_blargg.h"
+#endif
+#include "cheats.h"
+#include "display.h"
+#include "gfx.h"
+#include "cpuexec.h"
+#ifdef USE_SPC7110
+#include "spc7110.h"
+#endif
+#include "srtc.h"
+#include "sa1.h"
+#include "snapshot.h"
+#include "scaler.h"
+
+#include "shared.h"
+#include "menu.h"
+#include "video_blit.h"
+#include "input.h"
+#include "sound_output.h"
+
+char GameName_emu[512];
+
+bool overclock_cycles = false;
+bool reduce_sprite_flicker = true;
+int one_c, slow_one_c, two_c;
+
+static int32_t samples_to_play = 0;
+static int32_t samples_per_frame = 0;
+static int32_t samplerate = (((SNES_CLOCK_SPEED * 6) / (32 * ONE_APU_CYCLE)));
+
+#ifdef USE_BLARGG_APU
+static void S9xAudioCallback()
+{
+ size_t avail;
+ /* Just pick a big buffer. We won't use it all. */
+ static int16_t audio_buf[0x20000];
+
+ S9xFinalizeSamples();
+ avail = S9xGetSampleCount();
+ S9xMixSamples(audio_buf, avail);
+ Audio_Write(audio_buf, avail >> 1);
+}
+#endif
+
+bool8 S9xInitUpdate() { return TRUE; }
+bool8 S9xDeinitUpdate(int width, int height, bool8_32 sixteen_bit)
+{
+ if (IPPU.RenderThisFrame) {
+ Update_Video_Ingame(width, height);
+ }
+}
+
+void SRAM_Save(char* path, uint_fast8_t state)
+{
+ FILE* savefp;
+
+ /* If SRAM is not used then don't bother saving any SRAM file */
+ if (CPU.Memory_SRAMMask == 0) return;
+
+ if (state == 1)
+ {
+ savefp = fopen(path, "rb");
+ if (savefp)
+ {
+ fread(Memory.SRAM, sizeof(uint8_t), CPU.Memory_SRAMMask, savefp);
+ fclose(savefp);
+ }
+ }
+ else
+ {
+ savefp = fopen(path, "wb");
+ if (savefp)
+ {
+ fwrite(Memory.SRAM, sizeof(uint8_t), CPU.Memory_SRAMMask, savefp);
+ fclose(savefp);
+ }
+ }
+}
+
+void SaveState(char* path, uint_fast8_t state)
+{
+ if (state == 1)
+ {
+ S9xUnfreezeGame(path);
+ }
+ else
+ {
+ S9xFreezeGame(path);
+ }
+}
+
+
+#ifdef FRAMESKIP
+static uint32_t Timer_Read(void)
+{
+ /* Timing. */
+ struct timeval tval;
+ gettimeofday(&tval, 0);
+ return (((tval.tv_sec*1000000) + (tval.tv_usec)));
+}
+static long lastTick = 0, newTick;
+static uint32_t SkipCnt = 0, video_frames = 0, FPS = 60, FrameSkip;
+static const uint32_t TblSkip[4][4] = {
+ {0, 0, 0, 0},
+ {0, 0, 0, 1},
+ {0, 0, 1, 1},
+ {0, 1, 1, 1}
+};
+#endif
+
+#ifdef AUDIO_FRAMESKIP
+#define MAX_SKIP_COUNT 3
+static uint32_t SkipCnt = 0;
+#endif
+
+void Emulation_Run (void)
+{
+#ifndef USE_BLARGG_APU
+ static int16_t audio_buf[2048];
+#endif
+
+#ifdef FRAMESKIP
+ SkipCnt++;
+ if (SkipCnt > 3) SkipCnt = 0;
+ if (TblSkip[FrameSkip][SkipCnt]) IPPU.RenderThisFrame = false;
+ else IPPU.RenderThisFrame = true;
+#else
+ IPPU.RenderThisFrame = true;
+#endif
+
+#ifdef USE_BLARGG_APU
+ S9xSetSoundMute(false);
+#endif
+ //Settings.HardDisableAudio = false;
+
+#ifdef AUDIO_FRAMESKIP
+ if (IPPU.RenderThisFrame) {
+ if (Audio_Underrun_Likely()) {
+ if (SkipCnt < MAX_SKIP_COUNT) {
+ SkipCnt++;
+ IPPU.RenderThisFrame = false;
+ } else {
+ SkipCnt = 0;
+ }
+ }
+ } else {
+ SkipCnt = 0;
+ }
+#endif
+
+ S9xMainLoop();
+
+#ifndef USE_BLARGG_APU
+ samples_to_play += samples_per_frame;
+
+ if (samples_to_play > 512)
+ {
+ S9xMixSamples(audio_buf, samples_to_play);
+ Audio_Write(audio_buf, samples_to_play / 2);
+ samples_to_play = 0;
+ }
+#else
+ S9xAudioCallback();
+#endif
+
+#ifdef FRAMESKIP
+ video_frames++;
+ newTick = Timer_Read();
+ if ( (newTick) - (lastTick) > 1000000)
+ {
+ FPS = video_frames;
+ video_frames = 0;
+ lastTick = newTick;
+ if (FPS >= 60)
+ {
+ FrameSkip = 0;
+ }
+ else
+ {
+ FrameSkip = 60 / FPS;
+ if (FrameSkip > 3) FrameSkip = 3;
+ }
+ }
+#endif
+}
+
+
+bool Load_Game_Memory(char* game_path)
+{
+ uint64_t fps;
+ CPU.Flags = 0;
+
+ if (!LoadROM(game_path))
+ return false;
+
+ Settings.FrameTime = (Settings.PAL ? Settings.FrameTimePAL : Settings.FrameTimeNTSC);
+
+ if (!Settings.PAL)
+ fps = (SNES_CLOCK_SPEED * 6.0 / (SNES_CYCLES_PER_SCANLINE * SNES_MAX_NTSC_VCOUNTER));
+ else
+ fps = (SNES_CLOCK_SPEED * 6.0 / (SNES_CYCLES_PER_SCANLINE * SNES_MAX_PAL_VCOUNTER));
+
+ samplerate = SOUND_OUTPUT_FREQUENCY;
+ Settings.SoundPlaybackRate = samplerate;
+
+#ifndef USE_BLARGG_APU
+ Settings.SixteenBitSound = true;
+ so.stereo = Settings.Stereo;
+ so.playback_rate = Settings.SoundPlaybackRate;
+ S9xSetPlaybackRate(so.playback_rate);
+
+ samples_per_frame = samplerate / fps << 1;
+#endif
+ return true;
+}
+
+
+void init_sfc_setting(void)
+{
+ memset(&Settings, 0, sizeof(Settings));
+ Settings.JoystickEnabled = false;
+ Settings.SoundPlaybackRate = samplerate;
+ Settings.Stereo = true;
+ Settings.SoundBufferSize = 0;
+ Settings.CyclesPercentage = 100;
+
+ Settings.DisableSoundEcho = false;
+ Settings.InterpolatedSound = true;
+ Settings.APUEnabled = true;
+
+ Settings.H_Max = SNES_CYCLES_PER_SCANLINE;
+ Settings.SkipFrames = AUTO_FRAMERATE;
+ Settings.FrameTimePAL = 20000;
+ Settings.FrameTimeNTSC = 16667;
+ Settings.Shutdown = Settings.ShutdownMaster = true;
+ Settings.DisableSampleCaching = false;
+ Settings.DisableMasterVolume = false;
+ Settings.Mouse = false;
+ Settings.SuperScope = false;
+ Settings.MultiPlayer5 = false;
+ Settings.ControllerOption = SNES_JOYPAD;
+#ifdef USE_BLARGG_APU
+ Settings.SoundSync = true;
+#endif
+
+ Settings.ForceTransparency = false;
+ Settings.Transparency = true;
+ Settings.SixteenBit = true;
+ Settings.SupportHiRes = false;
+ Settings.AutoSaveDelay = 30;
+ Settings.ApplyCheats = true;
+ Settings.TurboMode = false;
+ Settings.TurboSkipFrames = 15;
+#ifdef ASM_SPC700
+ Settings.asmspc700 = true;
+#endif
+ Settings.SpeedHacks = true;
+ Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX;
+}
+
+void Init_SFC(void)
+{
+ init_sfc_setting();
+ MemoryInit();
+ S9xInitAPU();
+ S9xInitDisplay(NULL, NULL);
+ S9xGraphicsInit();
+#ifdef USE_BLARGG_APU
+ S9xInitSound(1000, 0); /* just give it a 1 second buffer */
+ S9xSetSamplesAvailableCallback(S9xAudioCallback);
+#else
+ S9xInitSound();
+#endif
+}
+
+void Deinit_SFC(void)
+{
+#ifdef USE_SPC7110
+ if (Settings.SPC7110)
+ Del7110Gfx();
+#endif
+
+ S9xGraphicsDeinit();
+ S9xDeinitDisplay();
+ S9xDeinitAPU();
+ MemoryDeinit();
+}
+
+
+
+/* Main entrypoint of the emulator */
+int main(int argc, char* argv[])
+{
+ int isloaded;
+
+ printf("Starting Snes9x2002\n");
+
+ if (argc < 2)
+ {
+ printf("Specify a ROM to load in memory\n");
+ return 0;
+ }
+
+ snprintf(GameName_emu, sizeof(GameName_emu), "%s", basename(argv[1]));
+ Init_SFC();
+
+ Init_Video();
+ Audio_Init();
+
+ overclock_cycles = false;
+ one_c = 4;
+ slow_one_c = 5;
+ two_c = 6;
+ reduce_sprite_flicker = false;
+
+ isloaded = Load_Game_Memory(argv[1]);
+ if (!isloaded)
+ {
+ printf("Could not load ROM in memory\n");
+ return 0;
+ }
+
+ Init_Configuration();
+
+ // get the game ready
+ while (!exit_snes)
+ {
+ switch(emulator_state)
+ {
+ case 0:
+ Emulation_Run();
+ break;
+ case 1:
+ Menu();
+ break;
+ }
+ }
+
+ Deinit_SFC();
+ Audio_Close();
+ Video_Close();
+
+ return 0;
+}
diff --git a/shell/emu/main.h b/shell/emu/main.h
new file mode 100644
index 0000000..8bf6c42
--- /dev/null
+++ b/shell/emu/main.h
@@ -0,0 +1,8 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+// utility functions that the core requires us to implement
+extern const char* S9xGetFilename(const char* extension);
+extern const char* S9xGetDirectory(uint32_t dirtype);
+
+#endif
diff --git a/shell/headers/boolean.h b/shell/headers/boolean.h
new file mode 100644
index 0000000..2c18ef7
--- /dev/null
+++ b/shell/headers/boolean.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2010-2017 The RetroArch team
+ *
+ * ---------------------------------------------------------------------------------------
+ * The following license statement only applies to this file (boolean.h).
+ * ---------------------------------------------------------------------------------------
+ *
+ * Permission is hereby granted, free of charge,
+ * to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LIBRETRO_SDK_BOOLEAN_H
+#define __LIBRETRO_SDK_BOOLEAN_H
+
+#ifndef __cplusplus
+
+#if defined(_MSC_VER) && !defined(SN_TARGET_PS3)
+/* Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. */
+#define bool unsigned char
+#define true 1
+#define false 0
+#else
+#include <stdbool.h>
+#endif
+
+#endif
+
+#endif
diff --git a/shell/headers/retro_inline.h b/shell/headers/retro_inline.h
new file mode 100644
index 0000000..ffdaa4a
--- /dev/null
+++ b/shell/headers/retro_inline.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2010-2017 The RetroArch team
+ *
+ * ---------------------------------------------------------------------------------------
+ * The following license statement only applies to this file (retro_inline.h).
+ * ---------------------------------------------------------------------------------------
+ *
+ * Permission is hereby granted, free of charge,
+ * to any person obtaining a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __LIBRETRO_SDK_INLINE_H
+#define __LIBRETRO_SDK_INLINE_H
+
+#ifndef INLINE
+
+#if defined(_WIN32) || defined(__INTEL_COMPILER)
+#define INLINE __inline
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
+#define INLINE inline
+#elif defined(__GNUC__)
+#define INLINE __inline__
+#else
+#define INLINE
+#endif
+
+#endif
+#endif
diff --git a/shell/headers/shared.h b/shell/headers/shared.h
new file mode 100644
index 0000000..0ceff9d
--- /dev/null
+++ b/shell/headers/shared.h
@@ -0,0 +1,30 @@
+#ifndef SHARED_H
+#define SHARED_H
+
+#if defined(BITTBOY)
+#define SOUND_OUTPUT_FREQUENCY 22050
+#define SOUND_SAMPLES_SIZE 1024
+#elif defined(TRIMUI)
+#define SOUND_OUTPUT_FREQUENCY 32000
+#define SOUND_SAMPLES_SIZE 1024
+#elif defined(RS97)
+#define SOUND_OUTPUT_FREQUENCY 22050
+#define SOUND_SAMPLES_SIZE 1024
+#elif defined(ARCADEMINI)
+#define SOUND_OUTPUT_FREQUENCY 22050
+#define SOUND_SAMPLES_SIZE 1024
+#elif defined(RETROSTONE_1)
+#define SOUND_OUTPUT_FREQUENCY 48000
+#define SOUND_SAMPLES_SIZE 2048
+#elif defined(RETROSTONE_2)
+#define SOUND_OUTPUT_FREQUENCY 48000
+#define SOUND_SAMPLES_SIZE 2048
+#elif defined(ZIPIT)
+#define SOUND_OUTPUT_FREQUENCY 44100
+#define SOUND_SAMPLES_SIZE 1024
+#else
+#define SOUND_OUTPUT_FREQUENCY 48000
+#define SOUND_SAMPLES_SIZE 2048
+#endif
+
+#endif
diff --git a/shell/input/input.h b/shell/input/input.h
new file mode 100644
index 0000000..a1a89c1
--- /dev/null
+++ b/shell/input/input.h
@@ -0,0 +1,6 @@
+#ifndef INPUT_H
+#define INPUT_H
+#include <stdint.h>
+uint32_t S9xReadJoypad(int32_t port);
+extern uint8_t exit_snes;
+#endif
diff --git a/shell/input/sdl/input.c b/shell/input/sdl/input.c
new file mode 100644
index 0000000..efc44ac
--- /dev/null
+++ b/shell/input/sdl/input.c
@@ -0,0 +1,100 @@
+#include <SDL/SDL.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "main.h"
+#include "snes9x.h"
+#include "soundux.h"
+#include "memmap.h"
+#include "apu.h"
+#include "cheats.h"
+#include "display.h"
+#include "gfx.h"
+#include "cpuexec.h"
+#include "srtc.h"
+#include "sa1.h"
+#include "scaler.h"
+
+#include "menu.h"
+#include "config.h"
+#include "buttons.h"
+
+uint8_t *keystate;
+uint8_t exit_snes = 0;
+extern uint32_t emulator_state;
+
+#define CASE(realkey, key) \
+ if (keystate[realkey]) \
+ joypad |= key; \
+ else \
+ joypad &= ~key; \
+
+uint32_t S9xReadJoypad(int32_t port)
+{
+ SDL_Event event;
+ static const uint32_t snes_lut[] =
+ {
+ SNES_B_MASK,
+ SNES_Y_MASK,
+ SNES_SELECT_MASK,
+ SNES_START_MASK,
+ SNES_UP_MASK,
+ SNES_DOWN_MASK,
+ SNES_LEFT_MASK,
+ SNES_RIGHT_MASK,
+ SNES_A_MASK,
+ SNES_X_MASK,
+ SNES_TL_MASK,
+ SNES_TR_MASK
+ };
+
+ int32_t i;
+ uint32_t joypad = 0;
+
+ // Only 1P is supported
+ if (port > 0) return joypad;
+
+ keystate = SDL_GetKeyState(NULL);
+
+ while (SDL_PollEvent(&event))
+ {
+ switch (event.type)
+ {
+ case SDL_KEYDOWN:
+ switch(event.key.keysym.sym)
+ {
+ case BTN_MENU:
+ case BTN_L2:
+ emulator_state = 1;
+ break;
+ default:
+ break;
+ }
+ break;
+ case SDL_KEYUP:
+ switch(event.key.keysym.sym)
+ {
+ case BTN_HOME:
+ emulator_state = 1;
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ }
+
+ CASE(option.config_buttons[0][10], SNES_START_MASK);
+ CASE(option.config_buttons[0][11], SNES_SELECT_MASK);
+ CASE(option.config_buttons[0][4], SNES_A_MASK);
+ CASE(option.config_buttons[0][5], SNES_B_MASK);
+ CASE(option.config_buttons[0][6], SNES_X_MASK);
+ CASE(option.config_buttons[0][7], SNES_Y_MASK);
+ CASE(option.config_buttons[0][8], SNES_TL_MASK);
+ CASE(option.config_buttons[0][9], SNES_TR_MASK);
+ CASE(option.config_buttons[0][0], SNES_UP_MASK);
+ CASE(option.config_buttons[0][1], SNES_RIGHT_MASK);
+ CASE(option.config_buttons[0][2], SNES_DOWN_MASK);
+ CASE(option.config_buttons[0][3], SNES_LEFT_MASK);
+
+ return joypad;
+}
diff --git a/shell/menu/buttons.h b/shell/menu/buttons.h
new file mode 100644
index 0000000..6be3f18
--- /dev/null
+++ b/shell/menu/buttons.h
@@ -0,0 +1,31 @@
+#ifndef BUTTONS_H
+#define BUTTONS_H
+
+#ifdef TRIMUI
+#include "buttons_trimui.h"
+#else
+
+#include <SDL/SDL.h>
+
+#define BTN_UP SDLK_UP
+#define BTN_RIGHT SDLK_RIGHT
+#define BTN_DOWN SDLK_DOWN
+#define BTN_LEFT SDLK_LEFT
+#define BTN_A SDLK_LCTRL
+#define BTN_B SDLK_LALT
+#define BTN_X SDLK_LSHIFT
+#define BTN_Y SDLK_SPACE
+#define BTN_L SDLK_TAB
+#define BTN_R SDLK_BACKSPACE
+#define BTN_START SDLK_RETURN
+#define BTN_SELECT SDLK_ESCAPE
+#define BTN_MENU SDLK_RCTRL
+
+#define BTN_L2 SDLK_END
+#define BTN_R2 SDLK_3
+#define BTN_VOLUMEUP SDLK_AMPERSAND
+#define BTN_VOLUMEDOWN SDLK_WORLD_73
+#define BTN_HOME SDLK_HOME
+#endif
+
+#endif // BUTTONS_H
diff --git a/shell/menu/buttons_trimui.h b/shell/menu/buttons_trimui.h
new file mode 100644
index 0000000..36b548d
--- /dev/null
+++ b/shell/menu/buttons_trimui.h
@@ -0,0 +1,25 @@
+#ifndef BUTTONS_TRIMUI_H
+#define BUTTONS_TRIMUI_H
+#include <SDL/SDL.h>
+
+#define BTN_UP SDLK_UP
+#define BTN_RIGHT SDLK_RIGHT
+#define BTN_DOWN SDLK_DOWN
+#define BTN_LEFT SDLK_LEFT
+#define BTN_A SDLK_SPACE
+#define BTN_B SDLK_LCTRL
+#define BTN_X SDLK_LSHIFT
+#define BTN_Y SDLK_LALT
+#define BTN_L SDLK_TAB
+#define BTN_R SDLK_BACKSPACE
+#define BTN_START SDLK_RETURN
+#define BTN_SELECT SDLK_RCTRL
+#define BTN_MENU SDLK_ESCAPE
+
+#define BTN_L2 SDLK_END
+#define BTN_R2 SDLK_3
+#define BTN_VOLUMEUP SDLK_AMPERSAND
+#define BTN_VOLUMEDOWN SDLK_WORLD_73
+#define BTN_HOME SDLK_HOME
+
+#endif // BUTTONS_TRIMUI_H
diff --git a/shell/menu/config.h b/shell/menu/config.h
new file mode 100644
index 0000000..9b71fc2
--- /dev/null
+++ b/shell/menu/config.h
@@ -0,0 +1,11 @@
+#ifndef CONFIG_H__
+#define CONFIG_H__
+
+typedef struct {
+ int32_t fullscreen;
+ /* For input remapping */
+ uint32_t config_buttons[6][19];
+} t_config;
+extern t_config option;
+
+#endif
diff --git a/shell/menu/font_drawing.c b/shell/menu/font_drawing.c
new file mode 100644
index 0000000..9b964ef
--- /dev/null
+++ b/shell/menu/font_drawing.c
@@ -0,0 +1,131 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "video_blit.h"
+#include "font_drawing.h"
+#include "font_menudata.h"
+
+extern int32_t screen_width;
+//#define setPixel(buffer, x,y,c)
+
+static inline void setPixel(uint16_t* restrict buffer, uint32_t x, uint32_t y, uint16_t c)
+{
+ if (x < BACKBUFFER_WIDTH_RESOLUTION && y < BACKBUFFER_HEIGHT_RESOLUTION)
+ {
+ *((uint16_t* restrict)buffer + ((x) + (y) * BACKBUFFER_WIDTH_RESOLUTION)) = c;
+ }
+}
+
+static int32_t isOutlinePixel(uint8_t* charfont, uint32_t x, uint32_t y)
+{
+ uint32_t xis0 = !x, xis7 = x == 7, yis0 = !y, yis7 = y == 7;
+
+ if(xis0)
+ {
+ if (yis0)
+ {
+ return !(*charfont & 0x80) && ((*charfont & 0x40) || (charfont[1] & 0x80) || (charfont[1] & 0x40));
+ }
+ else if (yis7)
+ {
+ return !(charfont[7] & 0x80) && ((charfont[7] & 0x40) || (charfont[6] & 0x80) || (charfont[6] & 0x40));
+ }
+ else
+ {
+ return !(charfont[y] & 0x80) && (
+ (charfont[y - 1] & 0x80) || (charfont[y - 1] & 0x40) ||
+ (charfont[y] & 0x40) ||
+ (charfont[y + 1] & 0x80) || (charfont[y + 1] & 0x40));
+ }
+ }
+ else if (xis7)
+ {
+ if (yis0)
+ {
+ return !(*charfont & 0x01) && ((*charfont & 0x02) || (charfont[1] & 0x01) || (charfont[1] & 0x02));
+ }
+ else if (yis7)
+ {
+ return !(charfont[7] & 0x01) && ((charfont[7] & 0x02) || (charfont[6] & 0x01) || (charfont[6] & 0x02));
+ }
+ else
+ {
+ return !(charfont[y] & 0x01) && (
+ (charfont[y - 1] & 0x01) || (charfont[y - 1] & 0x02) ||
+ (charfont[y] & 0x02) ||
+ (charfont[y + 1] & 0x01) || (charfont[y + 1] & 0x02));
+ }
+ }
+ else
+ {
+ uint32_t b = 1 << (7 - x);
+ if (yis0)
+ {
+ return !(*charfont & b) && (
+ (*charfont & (b << 1)) || (*charfont & (b >> 1)) ||
+ (charfont[1] & (b << 1)) || (charfont[1] & b) || (charfont[1] & (b >> 1)));
+ }
+ else if (yis7)
+ {
+ return !(charfont[7] & b) && (
+ (charfont[7] & (b << 1)) || (charfont[7] & (b >> 1)) ||
+ (charfont[6] & (b << 1)) || (charfont[6] & b) || (charfont[6] & (b >> 1)));
+ }
+ else
+ {
+ return !(charfont[y] & b) && (
+ (charfont[y] & (b << 1)) || (charfont[y] & (b >> 1)) ||
+ (charfont[y - 1] & (b << 1)) || (charfont[y - 1] & b) || (charfont[y - 1] & (b >> 1)) ||
+ (charfont[y + 1] & (b << 1)) || (charfont[y + 1] & b) || (charfont[y + 1] & (b >> 1)));
+ }
+ }
+}
+
+static void drawChar(uint16_t* restrict buffer, uint32_t *x, uint32_t *y, uint32_t margin, char ch, uint16_t fc, uint16_t olc)
+{
+ uint32_t i, j;
+ uint8_t *charSprite;
+ if (ch == '\n')
+ {
+ *x = margin;
+ *y += 8;
+ }
+ else if(*y < (BACKBUFFER_HEIGHT_RESOLUTION-1))
+ {
+ charSprite = ch * 8 + n2DLib_font;
+ // Draw charSprite as monochrome 8*8 image using given color
+ for(i = 0; i < 8; i++)
+ {
+ for(j = 7; j; j--)
+ {
+ if((charSprite[i] >> j) & 1)
+ {
+ setPixel(buffer, *x + (7 - j), *y + i, fc);
+ }
+ else if(isOutlinePixel(charSprite, 7 - j, i))
+ {
+ setPixel(buffer, *x + (7 - j), *y + i, olc);
+ }
+ }
+ }
+ *x += 8;
+ }
+}
+
+static void drawString(uint16_t* restrict buffer, uint32_t *x, uint32_t *y, uint32_t _x, const char *str, uint16_t fc, uint16_t olc)
+{
+ uint32_t i;
+ size_t size_font;
+
+ size_font = strnlen(str, (BACKBUFFER_WIDTH_RESOLUTION/8)) + 1;
+ for(i = 0; i < size_font; i++)
+ drawChar(buffer, x, y, _x, str[i], fc, olc);
+}
+
+void print_string(const char *s, const uint16_t fg_color, const uint16_t bg_color, uint32_t x, uint32_t y, uint16_t* restrict buffer)
+{
+ if (!s) return;
+
+ drawString(buffer, &x, &y, 0, s, fg_color, bg_color);
+}
diff --git a/shell/menu/font_drawing.h b/shell/menu/font_drawing.h
new file mode 100644
index 0000000..e18ea04
--- /dev/null
+++ b/shell/menu/font_drawing.h
@@ -0,0 +1,13 @@
+#ifndef FONT_DRAWING_H
+#define FONT_DRAWING_H
+
+#include <stdint.h>
+#include <string.h>
+
+#define TextWhite 65535
+#define TextRed ((255>>3)<<11) + ((0>>2)<<5) + (0>>3)
+#define TextBlue ((0>>3)<<11) + ((0>>2)<<5) + (255>>3)
+
+void print_string(const char *s, const uint16_t fg_color, const uint16_t bg_color, uint32_t x, uint32_t y, uint16_t* restrict buffer);
+
+#endif
diff --git a/shell/menu/font_menudata.h b/shell/menu/font_menudata.h
new file mode 100644
index 0000000..f5a8cbc
--- /dev/null
+++ b/shell/menu/font_menudata.h
@@ -0,0 +1,135 @@
+#ifndef n2DLIB_FONT
+#define n2DLIB_FONT
+
+static uint8_t n2DLib_font[] =
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 000 (.) */
+ 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E, /* Char 001 (.) */
+ 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, /* Char 002 (.) */
+ 0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, /* Char 003 (.) */
+ 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, /* Char 004 (.) */
+ 0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x7C, 0x38, 0x7C, /* Char 005 (.) */
+ 0x10, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C, /* Char 006 (.) */
+ 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, /* Char 007 (.) */
+ 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, /* Char 008 (.) */
+ 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, /* Char 009 (.) */
+ 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, /* Char 010 (.) */
+ 0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, /* Char 011 (.) */
+ 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, /* Char 012 (.) */
+ 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, /* Char 013 (.) */
+ 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, /* Char 014 (.) */
+ 0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, /* Char 015 (.) */
+ 0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, /* Char 016 (.) */
+ 0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, /* Char 017 (.) */
+ 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, /* Char 018 (.) */
+ 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, /* Char 019 (.) */
+ 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, /* Char 020 (.) */
+ 0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0xCC, 0x78, /* Char 021 (.) */
+ 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, /* Char 022 (.) */
+ 0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, /* Char 023 (.) */
+ 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, /* Char 024 (.) */
+ 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, /* Char 025 (.) */
+ 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, /* Char 026 (<=)*/
+ 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, /* Char 027 (.) */
+ 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, /* Char 028 (.) */
+ 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, /* Char 029 (.) */
+ 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, /* Char 030 (.) */
+ 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, /* Char 031 (.) */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 032 ( ) */
+ 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x00, /* Char 033 (!) */
+ 0x90, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 034 (") */
+ 0x50, 0x50, 0xF8, 0x50, 0xF8, 0x50, 0x50, 0x00, /* Char 035 (#) */
+ 0x20, 0x78, 0xA0, 0x70, 0x28, 0xF0, 0x20, 0x00, /* Char 036 ($) */
+ 0xC8, 0xC8, 0x10, 0x20, 0x40, 0x98, 0x98, 0x00, /* Char 037 (%) */
+ 0x70, 0x88, 0x50, 0x20, 0x54, 0x88, 0x74, 0x00, /* Char 038 (&) */
+ 0x60, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 039 (') */
+ 0x20, 0x40, 0x80, 0x80, 0x80, 0x40, 0x20, 0x00, /* Char 040 (() */
+ 0x20, 0x10, 0x08, 0x08, 0x08, 0x10, 0x20, 0x00, /* Char 041 () */
+ 0x00, 0x20, 0xA8, 0x70, 0x70, 0xA8, 0x20, 0x00, /* Char 042 (*) */
+ 0x00, 0x00, 0x20, 0x20, 0xF8, 0x20, 0x20, 0x00, /* Char 043 (+) */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x20, 0x40, /* Char 044 (,) */
+ 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0x00, /* Char 045 (-) */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, /* Char 046 (.) */
+ 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, /* Char 047 (/) */
+ 0x70, 0x88, 0x98, 0xA8, 0xC8, 0x88, 0x70, 0x00, /* Char 048 (0) */
+ 0x40, 0xC0, 0x40, 0x40, 0x40, 0x40, 0xE0, 0x00, /* Char 049 (1) */
+ 0x70, 0x88, 0x08, 0x10, 0x20, 0x40, 0xF8, 0x00, /* Char 050 (2) */
+ 0x70, 0x88, 0x08, 0x10, 0x08, 0x88, 0x70, 0x00, /* Char 051 (3) */
+ 0x08, 0x18, 0x28, 0x48, 0xFC, 0x08, 0x08, 0x00, /* Char 052 (4) */
+ 0xF8, 0x80, 0x80, 0xF0, 0x08, 0x88, 0x70, 0x00, /* Char 053 (5) */
+ 0x20, 0x40, 0x80, 0xF0, 0x88, 0x88, 0x70, 0x00, /* Char 054 (6) */
+ 0xF8, 0x08, 0x10, 0x20, 0x40, 0x40, 0x40, 0x00, /* Char 055 (7) */
+ 0x70, 0x88, 0x88, 0x70, 0x88, 0x88, 0x70, 0x00, /* Char 056 (8) */
+ 0x70, 0x88, 0x88, 0x78, 0x08, 0x08, 0x70, 0x00, /* Char 057 (9) */
+ 0x00, 0x00, 0x60, 0x60, 0x00, 0x60, 0x60, 0x00, /* Char 058 (:) */
+ 0x00, 0x00, 0x60, 0x60, 0x00, 0x60, 0x60, 0x20, /* Char 059 (;) */
+ 0x10, 0x20, 0x40, 0x80, 0x40, 0x20, 0x10, 0x00, /* Char 060 (<) */
+ 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, /* Char 061 (=) */
+ 0x80, 0x40, 0x20, 0x10, 0x20, 0x40, 0x80, 0x00, /* Char 062 (>) */
+ 0x78, 0x84, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00, /* Char 063 (?) */
+ 0x70, 0x88, 0x88, 0xA8, 0xB8, 0x80, 0x78, 0x00, /* Char 064 (@) */
+ 0x20, 0x50, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x00, /* Char 065 (A) */
+ 0xF0, 0x88, 0x88, 0xF0, 0x88, 0x88, 0xF0, 0x00, /* Char 066 (B) */
+ 0x70, 0x88, 0x80, 0x80, 0x80, 0x88, 0x70, 0x00, /* Char 067 (C) */
+ 0xF0, 0x88, 0x88, 0x88, 0x88, 0x88, 0xF0, 0x00, /* Char 068 (D) */
+ 0xF8, 0x80, 0x80, 0xE0, 0x80, 0x80, 0xF8, 0x00, /* Char 069 (E) */
+ 0xF8, 0x80, 0x80, 0xE0, 0x80, 0x80, 0x80, 0x00, /* Char 070 (F) */
+ 0x70, 0x88, 0x80, 0x80, 0x98, 0x88, 0x78, 0x00, /* Char 071 (G) */
+ 0x88, 0x88, 0x88, 0xF8, 0x88, 0x88, 0x88, 0x00, /* Char 072 (H) */
+ 0xE0, 0x40, 0x40, 0x40, 0x40, 0x40, 0xE0, 0x00, /* Char 073 (I) */
+ 0x38, 0x10, 0x10, 0x10, 0x10, 0x90, 0x60, 0x00, /* Char 074 (J) */
+ 0x88, 0x90, 0xA0, 0xC0, 0xA0, 0x90, 0x88, 0x00, /* Char 075 (K) */
+ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xF8, 0x00, /* Char 076 (L) */
+ 0x82, 0xC6, 0xAA, 0x92, 0x82, 0x82, 0x82, 0x00, /* Char 077 (M) */
+ 0x84, 0xC4, 0xA4, 0x94, 0x8C, 0x84, 0x84, 0x00, /* Char 078 (N) */
+ 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, /* Char 079 (O) */
+ 0xF0, 0x88, 0x88, 0xF0, 0x80, 0x80, 0x80, 0x00, /* Char 080 (P) */
+ 0x70, 0x88, 0x88, 0x88, 0xA8, 0x90, 0x68, 0x00, /* Char 081 (Q) */
+ 0xF0, 0x88, 0x88, 0xF0, 0xA0, 0x90, 0x88, 0x00, /* Char 082 (R) */
+ 0x70, 0x88, 0x80, 0x70, 0x08, 0x88, 0x70, 0x00, /* Char 083 (S) */
+ 0xF8, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, /* Char 084 (T) */
+ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, /* Char 085 (U) */
+ 0x88, 0x88, 0x88, 0x50, 0x50, 0x20, 0x20, 0x00, /* Char 086 (V) */
+ 0x82, 0x82, 0x82, 0x82, 0x92, 0x92, 0x6C, 0x00, /* Char 087 (W) */
+ 0x88, 0x88, 0x50, 0x20, 0x50, 0x88, 0x88, 0x00, /* Char 088 (X) */
+ 0x88, 0x88, 0x88, 0x50, 0x20, 0x20, 0x20, 0x00, /* Char 089 (Y) */
+ 0xF8, 0x08, 0x10, 0x20, 0x40, 0x80, 0xF8, 0x00, /* Char 090 (Z) */
+ 0xE0, 0x80, 0x80, 0x80, 0x80, 0x80, 0xE0, 0x00, /* Char 091 ([) */
+ 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, /* Char 092 (\) */
+ 0xE0, 0x20, 0x20, 0x20, 0x20, 0x20, 0xE0, 0x00, /* Char 093 (]) */
+ 0x20, 0x50, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 094 (^) */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, /* Char 095 (_) */
+ 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 096 (`) */
+ 0x00, 0x00, 0x70, 0x08, 0x78, 0x88, 0x74, 0x00, /* Char 097 (a) */
+ 0x80, 0x80, 0xB0, 0xC8, 0x88, 0xC8, 0xB0, 0x00, /* Char 098 (b) */
+ 0x00, 0x00, 0x70, 0x88, 0x80, 0x88, 0x70, 0x00, /* Char 099 (c) */
+ 0x08, 0x08, 0x68, 0x98, 0x88, 0x98, 0x68, 0x00, /* Char 100 (d) */
+ 0x00, 0x00, 0x70, 0x88, 0xF8, 0x80, 0x70, 0x00, /* Char 101 (e) */
+ 0x30, 0x48, 0x40, 0xE0, 0x40, 0x40, 0x40, 0x00, /* Char 102 (f) */
+ 0x00, 0x00, 0x34, 0x48, 0x48, 0x38, 0x08, 0x30, /* Char 103 (g) */
+ 0x80, 0x80, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x00, /* Char 104 (h) */
+ 0x20, 0x00, 0x60, 0x20, 0x20, 0x20, 0x70, 0x00, /* Char 105 (i) */
+ 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x90, 0x60, /* Char 106 (j) */
+ 0x80, 0x80, 0x88, 0x90, 0xA0, 0xD0, 0x88, 0x00, /* Char 107 (k) */
+ 0xC0, 0x40, 0x40, 0x40, 0x40, 0x40, 0xE0, 0x00, /* Char 108 (l) */
+ 0x00, 0x00, 0xEC, 0x92, 0x92, 0x92, 0x92, 0x00, /* Char 109 (m) */
+ 0x00, 0x00, 0xB0, 0xC8, 0x88, 0x88, 0x88, 0x00, /* Char 110 (n) */
+ 0x00, 0x00, 0x70, 0x88, 0x88, 0x88, 0x70, 0x00, /* Char 111 (o) */
+ 0x00, 0x00, 0xB0, 0xC8, 0xC8, 0xB0, 0x80, 0x80, /* Char 112 (p) */
+ 0x00, 0x00, 0x68, 0x98, 0x98, 0x68, 0x08, 0x08, /* Char 113 (q) */
+ 0x00, 0x00, 0xB0, 0xC8, 0x80, 0x80, 0x80, 0x00, /* Char 114 (r) */
+ 0x00, 0x00, 0x78, 0x80, 0x70, 0x08, 0xF0, 0x00, /* Char 115 (s) */
+ 0x40, 0x40, 0xE0, 0x40, 0x40, 0x50, 0x20, 0x00, /* Char 116 (t) */
+ 0x00, 0x00, 0x88, 0x88, 0x88, 0x98, 0x68, 0x00, /* Char 117 (u) */
+ 0x00, 0x00, 0x88, 0x88, 0x88, 0x50, 0x20, 0x00, /* Char 118 (v) */
+ 0x00, 0x00, 0x82, 0x82, 0x92, 0x92, 0x6C, 0x00, /* Char 119 (w) */
+ 0x00, 0x00, 0x88, 0x50, 0x20, 0x50, 0x88, 0x00, /* Char 120 (x) */
+ 0x00, 0x00, 0x88, 0x88, 0x98, 0x68, 0x08, 0x70, /* Char 121 (y) */
+ 0x00, 0x00, 0xF8, 0x10, 0x20, 0x40, 0xF8, 0x00, /* Char 122 (z) */
+ 0x10, 0x20, 0x20, 0x40, 0x20, 0x20, 0x10, 0x00, /* Char 123 ({) */
+ 0x40, 0x40, 0x40, 0x00, 0x40, 0x40, 0x40, 0x00, /* Char 124 (|) */
+ 0x40, 0x20, 0x20, 0x10, 0x20, 0x20, 0x40, 0x00, /* Char 125 (}) */
+ 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Char 126 (~) */
+ 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00 /* Char 127 (.) */
+};
+#endif
diff --git a/shell/menu/menu.c b/shell/menu/menu.c
new file mode 100644
index 0000000..2b0cd2a
--- /dev/null
+++ b/shell/menu/menu.c
@@ -0,0 +1,585 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <libgen.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <time.h>
+#include <SDL/SDL.h>
+
+#include "scaler.h"
+#include "font_drawing.h"
+#include "sound_output.h"
+#include "video_blit.h"
+#include "config.h"
+#include "menu.h"
+#include "buttons.h"
+
+t_config option;
+uint32_t emulator_state = 0;
+
+extern uint8_t exit_snes;
+
+static char home_path[256], save_path[256], sram_path[256], conf_path[256], rtc_path[256];
+static uint32_t controls_chosen = 0;
+
+extern SDL_Surface *sdl_screen;
+extern char GameName_emu[512];
+
+extern void SRAM_file(char* path, uint_fast8_t state);
+extern void SaveState(char* path, uint_fast8_t state);
+extern void SRAM_Save(char* path, uint_fast8_t state);
+
+static uint8_t selectpressed = 0;
+static uint8_t save_slot = 0;
+static const int8_t upscalers_available = 2
+#ifdef SCALE2X_UPSCALER
++1
+#endif
+;
+
+static void SaveState_Menu(uint_fast8_t load_mode, uint_fast8_t slot)
+{
+ char tmp[512];
+ snprintf(tmp, sizeof(tmp), "%s/%s_%d.sts", save_path, GameName_emu, slot);
+ SaveState(tmp,load_mode);
+}
+
+static void SRAM_Menu(uint_fast8_t load_mode)
+{
+ char tmp[512];
+ snprintf(tmp, sizeof(tmp), "%s/%s.srm", sram_path, GameName_emu);
+ SRAM_Save(tmp,load_mode);
+}
+
+static void config_load()
+{
+ uint_fast8_t i;
+ char config_path[512];
+ FILE* fp;
+ snprintf(config_path, sizeof(config_path), "%s/%s.cfg", conf_path, GameName_emu);
+
+ fp = fopen(config_path, "rb");
+ if (fp)
+ {
+ fread(&option, sizeof(option), sizeof(int8_t), fp);
+ fclose(fp);
+ }
+ else
+ {
+ /* Default mapping for Horizontal */
+ option.config_buttons[0][0] = BTN_UP;
+ option.config_buttons[0][1] = BTN_RIGHT;
+ option.config_buttons[0][2] = BTN_DOWN;
+ option.config_buttons[0][3] = BTN_LEFT;
+
+ option.config_buttons[0][4] = BTN_A;
+ option.config_buttons[0][5] = BTN_B;
+ option.config_buttons[0][6] = BTN_X;
+ option.config_buttons[0][7] = BTN_Y;
+
+ option.config_buttons[0][8] = BTN_L;
+ option.config_buttons[0][9] = BTN_R;
+
+ option.config_buttons[0][10] = BTN_START;
+ option.config_buttons[0][11] = BTN_SELECT;
+
+ option.fullscreen = 0;
+ }
+}
+
+static void config_save()
+{
+ FILE* fp;
+ char config_path[512];
+ snprintf(config_path, sizeof(config_path), "%s/%s.cfg", conf_path, GameName_emu);
+
+ fp = fopen(config_path, "wb");
+ if (fp)
+ {
+ fwrite(&option, sizeof(option), sizeof(int8_t), fp);
+ fclose(fp);
+ }
+}
+
+static const char* Return_Text_Button(uint32_t button)
+{
+ switch(button)
+ {
+ /* UP button */
+ case BTN_UP:
+ return "DPAD UP";
+ break;
+ /* DOWN button */
+ case BTN_DOWN:
+ return "DPAD DOWN";
+ break;
+ /* LEFT button */
+ case BTN_LEFT:
+ return "DPAD LEFT";
+ break;
+ /* RIGHT button */
+ case BTN_RIGHT:
+ return "DPAD RIGHT";
+ break;
+ /* A button */
+ case BTN_A:
+ return "A";
+ break;
+ /* B button */
+ case BTN_B:
+ return "B";
+ break;
+ /* X button */
+ case BTN_X:
+ return "X";
+ break;
+ /* Y button */
+ case BTN_Y:
+ return "Y";
+ break;
+ /* L button */
+ case BTN_L:
+ return "L";
+ break;
+ /* R button */
+ case BTN_R:
+ return "R";
+ break;
+ /* Power button */
+ case BTN_L2:
+ return "L2";
+ break;
+ /* Brightness */
+ case BTN_R2:
+ return "R2";
+ break;
+ /* Volume - */
+ case BTN_VOLUMEUP:
+ return "Volume -";
+ break;
+ /* Volume + */
+ case BTN_VOLUMEDOWN:
+ return "Volume +";
+ break;
+ /* Start */
+ case BTN_START:
+ return "Start";
+ break;
+ /* Select */
+ case BTN_SELECT:
+ return "Select";
+ break;
+ default:
+ return "Unknown";
+ break;
+ case 0:
+ return "...";
+ break;
+ }
+}
+
+static void Input_Remapping()
+{
+ SDL_Event Event;
+ char text[50];
+ uint32_t pressed = 0;
+ int32_t currentselection = 1;
+ int32_t exit_input = 0;
+ uint32_t exit_map = 0;
+
+ while(!exit_input)
+ {
+ pressed = 0;
+ SDL_FillRect( backbuffer, NULL, 0 );
+
+ while (SDL_PollEvent(&Event))
+ {
+ if (Event.type == SDL_KEYDOWN)
+ {
+ switch(Event.key.keysym.sym)
+ {
+ case BTN_UP:
+ currentselection--;
+ if (currentselection < 1)
+ {
+ if (currentselection > 9) currentselection = 12;
+ else currentselection = 9;
+ }
+ break;
+ case BTN_DOWN:
+ currentselection++;
+ if (currentselection == 10)
+ {
+ currentselection = 1;
+ }
+ break;
+ case BTN_A:
+ case BTN_START:
+ pressed = 1;
+ break;
+ case BTN_MENU:
+ option.config_buttons[controls_chosen][currentselection - 1] = 0;
+ break;
+ case BTN_B:
+ exit_input = 1;
+ break;
+ case BTN_LEFT:
+ if (currentselection > 9) currentselection -= 9;
+ break;
+ case BTN_RIGHT:
+ if (currentselection < 10) currentselection += 9;
+ break;
+ case BTN_R:
+ controls_chosen = 1;
+ break;
+ case BTN_L:
+ controls_chosen = 0;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (pressed)
+ {
+ SDL_Delay(1);
+ switch(currentselection)
+ {
+ default:
+ exit_map = 0;
+ while( !exit_map )
+ {
+ SDL_FillRect( backbuffer, NULL, 0 );
+ print_string("Please press button for mapping", TextWhite, TextBlue, 37, 108, backbuffer->pixels);
+ while (SDL_PollEvent(&Event))
+ {
+ if (Event.type == SDL_KEYDOWN)
+ {
+ if (Event.key.keysym.sym != BTN_MENU)
+ {
+ option.config_buttons[controls_chosen][currentselection - 1] = Event.key.keysym.sym;
+ exit_map = 1;
+ }
+ }
+ }
+ Update_Video_Menu();
+ }
+ break;
+ }
+ }
+
+ if (currentselection > 12) currentselection = 12;
+
+ if (controls_chosen == 0) print_string("Player 1", TextWhite, 0, 100, 10, backbuffer->pixels);
+ else print_string("Player 2", TextWhite, 0, 100, 10, backbuffer->pixels);
+
+ print_string("Press [A] to map to a button", TextWhite, TextBlue, 50, 210, backbuffer->pixels);
+ print_string("Press [B] to Exit", TextWhite, TextBlue, 85, 225, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "UP : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][0]));
+ if (currentselection == 1) print_string(text, TextRed, 0, 5, 25+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 25+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "DOWN : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][1]));
+ if (currentselection == 2) print_string(text, TextRed, 0, 5, 45+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 45+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "LEFT : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][2]));
+ if (currentselection == 3) print_string(text, TextRed, 0, 5, 65+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 65+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "RIGHT: %s\n", Return_Text_Button(option.config_buttons[controls_chosen][3]));
+ if (currentselection == 4) print_string(text, TextRed, 0, 5, 85+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 85+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "A : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][4]));
+ if (currentselection == 5) print_string(text, TextRed, 0, 5, 105+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 105+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "B : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][5]));
+ if (currentselection == 6) print_string(text, TextRed, 0, 5, 125+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 125+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "X : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][6]));
+ if (currentselection == 7) print_string(text, TextRed, 0, 5, 145+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 145+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "Y : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][7]));
+ if (currentselection == 8) print_string(text, TextRed, 0, 5, 165+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 165+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "L : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][8]));
+ if (currentselection == 9) print_string(text, TextRed, 0, 5, 185+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 185+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "R : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][9]));
+ if (currentselection == 10) print_string(text, TextRed, 0, 165, 25+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 165, 25+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "START : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][10]));
+ if (currentselection == 11) print_string(text, TextRed, 0, 165, 45+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 165, 45+2, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "SELECT : %s\n", Return_Text_Button(option.config_buttons[controls_chosen][11]));
+ if (currentselection == 12) print_string(text, TextRed, 0, 165, 65+2, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 165, 65+2, backbuffer->pixels);
+
+ Update_Video_Menu();
+ }
+
+ config_save();
+}
+
+void Menu()
+{
+ char text[50];
+ int16_t pressed = 0;
+ int16_t currentselection = 1;
+ SDL_Rect dstRect;
+ SDL_Event Event;
+
+ Set_Video_Menu();
+
+ /* Save sram settings each time we bring up the menu */
+ SRAM_Menu(0);
+
+ while (((currentselection != 1) && (currentselection != 6)) || (!pressed))
+ {
+ pressed = 0;
+
+ SDL_FillRect( backbuffer, NULL, 0 );
+
+ print_string("SNESEmu - Built on " __DATE__, TextWhite, 0, 5, 15, backbuffer->pixels);
+
+ if (currentselection == 1) print_string("Continue", TextRed, 0, 5, 45, backbuffer->pixels);
+ else print_string("Continue", TextWhite, 0, 5, 45, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "Load State %d", save_slot);
+
+ if (currentselection == 2) print_string(text, TextRed, 0, 5, 65, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 65, backbuffer->pixels);
+
+ snprintf(text, sizeof(text), "Save State %d", save_slot);
+
+ if (currentselection == 3) print_string(text, TextRed, 0, 5, 85, backbuffer->pixels);
+ else print_string(text, TextWhite, 0, 5, 85, backbuffer->pixels);
+
+ if (currentselection == 4)
+ {
+ switch(option.fullscreen)
+ {
+ case 0:
+ print_string("Scaling : Native", TextRed, 0, 5, 105, backbuffer->pixels);
+ break;
+ case 1:
+ print_string("Scaling : Stretched", TextRed, 0, 5, 105, backbuffer->pixels);
+ break;
+ case 2:
+ print_string("Scaling : Bilinear", TextRed, 0, 5, 105, backbuffer->pixels);
+ break;
+ case 3:
+ print_string("Scaling : EPX/Scale2x", TextRed, 0, 5, 105, backbuffer->pixels);
+ break;
+ }
+ }
+ else
+ {
+ switch(option.fullscreen)
+ {
+ case 0:
+ print_string("Scaling : Native", TextWhite, 0, 5, 105, backbuffer->pixels);
+ break;
+ case 1:
+ print_string("Scaling : Stretched", TextWhite, 0, 5, 105, backbuffer->pixels);
+ break;
+ case 2:
+ print_string("Scaling : Bilinear", TextWhite, 0, 5, 105, backbuffer->pixels);
+ break;
+ case 3:
+ print_string("Scaling : EPX/Scale2x", TextWhite, 0, 5, 105, backbuffer->pixels);
+ break;
+ }
+ }
+
+ if (currentselection == 5) print_string("Input remapping", TextRed, 0, 5, 125, backbuffer->pixels);
+ else print_string("Input remapping", TextWhite, 0, 5, 125, backbuffer->pixels);
+
+ if (currentselection == 6) print_string("Quit", TextRed, 0, 5, 145, backbuffer->pixels);
+ else print_string("Quit", TextWhite, 0, 5, 145, backbuffer->pixels);
+
+ print_string("Frontend by gameblabla", TextWhite, 0, 5, 205, backbuffer->pixels);
+ print_string("Credits: Snes9x dev team, libretro", TextWhite, 0, 5, 225, backbuffer->pixels);
+
+ while (SDL_PollEvent(&Event))
+ {
+ if (Event.type == SDL_KEYDOWN)
+ {
+ switch(Event.key.keysym.sym)
+ {
+ case BTN_UP:
+ currentselection--;
+ if (currentselection == 0)
+ currentselection = 6;
+ break;
+ case BTN_DOWN:
+ currentselection++;
+ if (currentselection == 7)
+ currentselection = 1;
+ break;
+ case BTN_L2:
+ case BTN_SELECT:
+ case BTN_B:
+ pressed = 1;
+ currentselection = 1;
+ break;
+ case BTN_A:
+ case BTN_START:
+ pressed = 1;
+ break;
+ case BTN_LEFT:
+ switch(currentselection)
+ {
+ case 2:
+ case 3:
+ if (save_slot > 0) save_slot--;
+ break;
+ case 4:
+ option.fullscreen--;
+ if (option.fullscreen < 0)
+ option.fullscreen = upscalers_available;
+ break;
+ }
+ break;
+ case BTN_RIGHT:
+ switch(currentselection)
+ {
+ case 2:
+ case 3:
+ save_slot++;
+ if (save_slot == 10)
+ save_slot = 9;
+ break;
+ case 4:
+ option.fullscreen++;
+ if (option.fullscreen > upscalers_available)
+ option.fullscreen = 0;
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ else if (Event.type == SDL_QUIT)
+ {
+ currentselection = 6;
+ pressed = 1;
+ }
+ }
+
+ if (pressed)
+ {
+ switch(currentselection)
+ {
+ case 5:
+ Input_Remapping();
+ break;
+ case 4 :
+ option.fullscreen++;
+ if (option.fullscreen > upscalers_available)
+ option.fullscreen = 0;
+ break;
+ case 2 :
+ SaveState_Menu(1, save_slot);
+ currentselection = 1;
+ break;
+ case 3 :
+ SaveState_Menu(0, save_slot);
+ currentselection = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ Update_Video_Menu();
+ }
+
+ SDL_FillRect(sdl_screen, NULL, 0);
+ SDL_Flip(sdl_screen);
+ #ifdef SDL_TRIPLEBUF
+ SDL_FillRect(sdl_screen, NULL, 0);
+ SDL_Flip(sdl_screen);
+ #endif
+
+ if (currentselection == 6)
+ {
+ exit_snes = 1;
+ }
+
+ /* Switch back to emulator core */
+ config_save();
+ emulator_state = 0;
+ Set_Video_InGame();
+}
+
+static void Cleanup(void)
+{
+#ifdef SCALE2X_UPSCALER
+ if (scale2x_buf) SDL_FreeSurface(scale2x_buf);
+#endif
+ if (sdl_screen) SDL_FreeSurface(sdl_screen);
+ if (backbuffer) SDL_FreeSurface(backbuffer);
+
+ // Deinitialize audio and video output
+ Audio_Close();
+
+ SDL_Quit();
+}
+
+void Init_Configuration()
+{
+ snprintf(home_path, sizeof(home_path), "%s/.snes9x2002", getenv("HOME"));
+
+ snprintf(conf_path, sizeof(conf_path), "%s/conf", home_path);
+ snprintf(save_path, sizeof(save_path), "%s/sstates", home_path);
+ snprintf(sram_path, sizeof(sram_path), "%s/sram", home_path);
+ snprintf(rtc_path, sizeof(sram_path), "%s/rtc", home_path);
+
+ /* We check first if folder does not exist.
+ * Let's only try to create it if so in order to decrease boot times.
+ * */
+
+ if (access( home_path, F_OK ) == -1)
+ {
+ mkdir(home_path, 0755);
+ }
+
+ if (access( save_path, F_OK ) == -1)
+ {
+ mkdir(save_path, 0755);
+ }
+
+ if (access( conf_path, F_OK ) == -1)
+ {
+ mkdir(conf_path, 0755);
+ }
+
+ if (access( sram_path, F_OK ) == -1)
+ {
+ mkdir(sram_path, 0755);
+ }
+
+ if (access( rtc_path, F_OK ) == -1)
+ {
+ mkdir(rtc_path, 0755);
+ }
+
+ /* Load sram file if it exists */
+ SRAM_Menu(1);
+
+ config_load();
+}
diff --git a/shell/menu/menu.h b/shell/menu/menu.h
new file mode 100644
index 0000000..8b81ac3
--- /dev/null
+++ b/shell/menu/menu.h
@@ -0,0 +1,18 @@
+#ifndef MENU_H
+#define MENU_H
+
+#include <stdint.h>
+
+#ifndef PATH_MAX
+#define PATH_MAX 2048
+#endif
+
+#define RGB565(r,g,b) ((r << 8) | (g << 3) | (b >> 3))
+
+extern uint32_t emulator_state;
+extern uint32_t done;
+
+extern void Menu(void);
+extern void Init_Configuration(void);
+
+#endif
diff --git a/shell/other/compatibility_layer.c b/shell/other/compatibility_layer.c
new file mode 100644
index 0000000..2b67e82
--- /dev/null
+++ b/shell/other/compatibility_layer.c
@@ -0,0 +1,206 @@
+#include <SDL/SDL.h>
+#include "main.h"
+#include "snes9x.h"
+#include "soundux.h"
+#include "memmap.h"
+#include "apu.h"
+#include "cheats.h"
+#include "display.h"
+#include "gfx.h"
+#include "cpuexec.h"
+#include "srtc.h"
+#include "sa1.h"
+#include "scaler.h"
+
+static uint32_t width_snes = 256;
+bool8 ROMAPUEnabled = 0;
+
+static FILE *statefile = NULL;
+
+int s_open(const char *fname, const char *mode) {
+ if (statefile) return 0;
+ statefile = fopen(fname, mode);
+
+ if(statefile) {
+ return 1;
+ };
+
+ return 0;
+}
+
+int s_read(void *p, int l) {
+ return fread(p, sizeof(char), l, statefile);
+}
+
+int s_write(void *p, int l) {
+ return fwrite(p, sizeof(char), l, statefile);
+}
+
+void s_close(void) {
+ fclose(statefile);
+ statefile = NULL;
+}
+
+int (*statef_open)(const char *fname, const char *mode) = s_open;
+int (*statef_read)(void *p, int l) = s_read;
+int (*statef_write)(void *p, int l) = s_write;
+void (*statef_close)(void) = s_close;
+
+const char *S9xBasename (const char *filename) { return basename(filename); }
+
+const char* S9xGetFilename(const char* in)
+{
+ static char filename [PATH_MAX + 1];
+ char drive [_MAX_DRIVE + 1];
+ char dir [_MAX_PATH + 1];
+ char fname [_MAX_FNAME + 1];
+ char ext [_MAX_EXT + 1];
+ _splitpath(Memory.ROMFilename, drive, dir, fname, ext);
+ _makepath(filename, drive, dir, fname, in);
+ return filename;
+}
+
+void S9xMessage(int a, int b, const char* msg)
+{
+ //printf("%s\n", msg);
+}
+
+const char* S9xGetDirectory(uint32_t dirtype) { return NULL; }
+
+void S9xDeinitDisplay(void)
+{
+ if (GFX.Screen_buffer)
+ free(GFX.Screen_buffer);
+
+ if (GFX.ZBuffer_buffer)
+ free(GFX.ZBuffer_buffer);
+ if (GFX.SubZBuffer_buffer)
+ free(GFX.SubZBuffer_buffer);
+
+ GFX.Screen = NULL;
+ GFX.Screen_buffer = NULL;
+ GFX.SubScreen = NULL;
+ GFX.ZBuffer = NULL;
+ GFX.ZBuffer_buffer = NULL;
+ GFX.SubZBuffer = NULL;
+ GFX.SubZBuffer_buffer = NULL;
+}
+
+void S9xInitDisplay(int argc, char** argv)
+{
+ int32_t safety = 128;
+ int32_t h = IMAGE_HEIGHT;
+
+ width_snes = IMAGE_WIDTH;
+
+ GFX.Pitch = IMAGE_WIDTH * sizeof(uint16);
+ GFX.Screen_buffer = (uint8_t *) calloc(1, 2048 * 512 * 2 * 2 + safety);
+ GFX.ZBuffer_buffer = (uint8_t *) calloc(1, GFX.Pitch * 512 * sizeof(uint16) + safety);
+ GFX.SubZBuffer_buffer = (uint8_t *) calloc(1, GFX.Pitch * 512 * sizeof(uint16) + safety);
+
+ GFX.Screen = GFX.Screen_buffer + safety;
+ GFX.SubScreen = GFX.Screen + 2048 * 512 * 2;
+ GFX.ZBuffer = GFX.ZBuffer_buffer + safety;
+ GFX.SubZBuffer = GFX.SubZBuffer_buffer + safety;
+ GFX.Delta = 1048576; //(GFX.SubScreen - GFX.Screen) >> 1;
+
+ if (GFX.Delta != ((GFX.SubScreen - GFX.Screen) >> 1))
+ exit(1);
+}
+
+void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
+{
+ char *slash = strrchr ((char *) path, SLASH_CHAR);
+ char *dot = strrchr ((char *) path, '.');
+
+ *drive = '\0';
+
+ if (dot && slash && dot < slash)
+ {
+ dot = 0;
+ }
+
+ if (!slash)
+ {
+ *dir = '\0';
+ strcpy (fname, path);
+
+ if (dot)
+ {
+ fname[dot - path] = '\0';
+ strcpy (ext, dot + 1);
+ }
+ else
+ {
+ *ext = '\0';
+ }
+ }
+ else
+ {
+ strcpy (dir, path);
+ dir[slash - path] = '\0';
+ strcpy (fname, slash + 1);
+
+ if (dot)
+ {
+ fname[(dot - slash) - 1] = '\0';
+ strcpy (ext, dot + 1);
+ }
+ else
+ {
+ *ext = '\0';
+ }
+ }
+
+ return;
+}
+
+void _makepath (char *path, const char *drive, const char *dir, const char *fname,const char *ext)
+{
+ if (dir && *dir)
+ {
+ strcpy (path, dir);
+ strcat (path, "/");
+ }
+ else
+ *path = '\0';
+
+ strcat (path, fname);
+
+ if (ext && *ext)
+ {
+ strcat (path, ".");
+ strcat (path, ext);
+ }
+
+ return;
+}
+
+void S9xLoadSDD1Data() {}
+
+bool8_32 S9xReadMousePosition(int which1, int* x, int* y, uint32* buttons)
+{
+ (void) which1;
+ (void) x;
+ (void) y;
+ (void) buttons;
+ return false;
+}
+
+bool8_32 S9xReadSuperScopePosition(int* x, int* y, uint32* buttons)
+{
+ (void) x;
+ (void) y;
+ (void) buttons;
+ return true;
+}
+
+bool JustifierOffscreen(void)
+{
+ return false;
+}
+
+void JustifierButtons(uint32_t* justifiers)
+{
+ (void) justifiers;
+}
diff --git a/shell/scalers/scaler.c b/shell/scalers/scaler.c
new file mode 100644
index 0000000..8d85b8a
--- /dev/null
+++ b/shell/scalers/scaler.c
@@ -0,0 +1,138 @@
+#include <stdio.h>
+#include <stdint.h>
+#include "scaler.h"
+
+#define AVERAGE(z, x) ((((z) & 0xF7DEF7DE) >> 1) + (((x) & 0xF7DEF7DE) >> 1))
+#define AVERAGEHI(AB) ((((AB) & 0xF7DE0000) >> 1) + (((AB) & 0xF7DE) << 15))
+#define AVERAGELO(CD) ((((CD) & 0xF7DE) >> 1) + (((CD) & 0xF7DE0000) >> 17))
+
+// Support math
+#define Half(A) (((A) >> 1) & 0x7BEF)
+#define Quarter(A) (((A) >> 2) & 0x39E7)
+// Error correction expressions to piece back the lower bits together
+#define RestHalf(A) ((A) & 0x0821)
+#define RestQuarter(A) ((A) & 0x1863)
+
+// Error correction expressions for quarters of pixels
+#define Corr1_3(A, B) Quarter(RestQuarter(A) + (RestHalf(B) << 1) + RestQuarter(B))
+#define Corr3_1(A, B) Quarter((RestHalf(A) << 1) + RestQuarter(A) + RestQuarter(B))
+
+// Error correction expressions for halves
+#define Corr1_1(A, B) ((A) & (B) & 0x0821)
+
+// Quarters
+#define Weight1_3(A, B) (Quarter(A) + Half(B) + Quarter(B) + Corr1_3(A, B))
+#define Weight3_1(A, B) (Half(A) + Quarter(A) + Quarter(B) + Corr3_1(A, B))
+
+// Halves
+#define Weight1_1(A, B) (Half(A) + Half(B) + Corr1_1(A, B))
+
+
+void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height)
+{
+ uint16_t* Src16 = (uint16_t*) src;
+ uint16_t* Dst16 = (uint16_t*) dst;
+ // There are 64 blocks of 4 pixels horizontally, and 239 of 1 vertically.
+ // Each block of 4x1 becomes 5x1.
+ uint32_t BlockX, BlockY;
+ uint16_t* BlockSrc;
+ uint16_t* BlockDst;
+ for (BlockY = 0; BlockY < height; BlockY++)
+ {
+ BlockSrc = Src16 + BlockY * width * 1;
+ BlockDst = Dst16 + BlockY * 320 * 1;
+ for (BlockX = 0; BlockX < 64; BlockX++)
+ {
+ /* Horizontally:
+ * Before(4):
+ * (a)(b)(c)(d)
+ * After(5):
+ * (a)(abbb)(bc)(cccd)(d)
+ */
+
+ // -- Row 1 --
+ uint16_t _1 = *(BlockSrc );
+ *(BlockDst ) = _1;
+ uint16_t _2 = *(BlockSrc + 1);
+ *(BlockDst + 1) = Weight1_3( _1, _2);
+ uint16_t _3 = *(BlockSrc + 2);
+ *(BlockDst + 2) = Weight1_1( _2, _3);
+ uint16_t _4 = *(BlockSrc + 3);
+ *(BlockDst + 3) = Weight3_1( _3, _4);
+ *(BlockDst + 4) = _4;
+
+ BlockSrc += 4;
+ BlockDst += 5;
+ }
+ }
+}
+
+void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height)
+{
+ uint32_t midh = 240 / 2;
+ uint32_t Eh = 0;
+ uint32_t source;
+ uint32_t dh = 0;
+ uint32_t y, x;
+
+ for (y = 0; y < 240; y++)
+ {
+ source = dh * width / 2;
+
+ for (x = 0; x < 320/10; x++)
+ {
+ register uint32_t ab, cd, ef, gh;
+
+ __builtin_prefetch(dst + 4, 1);
+ __builtin_prefetch(src + source + 4, 0);
+
+ ab = src[source] & 0xF7DEF7DE;
+ cd = src[source + 1] & 0xF7DEF7DE;
+ ef = src[source + 2] & 0xF7DEF7DE;
+ gh = src[source + 3] & 0xF7DEF7DE;
+
+ if(Eh >= midh) {
+ ab = AVERAGE(ab, src[source + width/2]) & 0xF7DEF7DE; // to prevent overflow
+ cd = AVERAGE(cd, src[source + width/2 + 1]) & 0xF7DEF7DE; // to prevent overflow
+ ef = AVERAGE(ef, src[source + width/2 + 2]) & 0xF7DEF7DE; // to prevent overflow
+ gh = AVERAGE(gh, src[source + width/2 + 3]) & 0xF7DEF7DE; // to prevent overflow
+ }
+
+ *dst++ = ab;
+ *dst++ = ((ab >> 17) + ((cd & 0xFFFF) >> 1)) + (cd << 16);
+ *dst++ = (cd >> 16) + (ef << 16);
+ *dst++ = (ef >> 16) + (((ef & 0xFFFF0000) >> 1) + ((gh & 0xFFFF) << 15));
+ *dst++ = gh;
+
+ source += 4;
+
+ }
+ Eh += height; if(Eh >= 240) { Eh -= 240; dh++; }
+ }
+}
+
+
+/* alekmaul's scaler taken from mame4all */
+void bitmap_scale(uint32_t startx, uint32_t starty, uint32_t viswidth, uint32_t visheight, uint32_t newwidth, uint32_t newheight,uint32_t pitchsrc,uint32_t pitchdest, uint16_t* restrict src, uint16_t* restrict dst)
+{
+ uint32_t W,H,ix,iy,x,y;
+ x=startx<<16;
+ y=starty<<16;
+ W=newwidth;
+ H=newheight;
+ ix=(viswidth<<16)/W;
+ iy=(visheight<<16)/H;
+
+ do
+ {
+ uint16_t* restrict buffer_mem=&src[(y>>16)*pitchsrc];
+ W=newwidth; x=startx<<16;
+ do
+ {
+ *dst++=buffer_mem[x>>16];
+ x+=ix;
+ } while (--W);
+ dst+=pitchdest;
+ y+=iy;
+ } while (--H);
+}
diff --git a/shell/scalers/scaler.h b/shell/scalers/scaler.h
new file mode 100644
index 0000000..f220800
--- /dev/null
+++ b/shell/scalers/scaler.h
@@ -0,0 +1,11 @@
+#ifndef SCALER_H
+#define SCALER_H
+
+#include <stdint.h>
+
+/* Generic */
+extern void bitmap_scale(uint32_t startx, uint32_t starty, uint32_t viswidth, uint32_t visheight, uint32_t newwidth, uint32_t newheight,uint32_t pitchsrc,uint32_t pitchdest, uint16_t* restrict src, uint16_t* restrict dst);
+extern void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height);
+extern void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height);
+
+#endif
diff --git a/shell/video/gcw0/video_blit.c b/shell/video/gcw0/video_blit.c
new file mode 100644
index 0000000..da72224
--- /dev/null
+++ b/shell/video/gcw0/video_blit.c
@@ -0,0 +1,106 @@
+/* Cygne
+ *
+ * Copyright notice for this file:
+ * Copyright (C) 2002 Dox dox@space.pl
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <SDL/SDL.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include "main.h"
+#include "snes9x.h"
+#include "soundux.h"
+#include "memmap.h"
+#include "apu.h"
+#include "cheats.h"
+#include "display.h"
+#include "gfx.h"
+#include "cpuexec.h"
+#include "spc7110.h"
+#include "srtc.h"
+#include "sa1.h"
+#include "scaler.h"
+
+#include "video_blit.h"
+#include "scaler.h"
+#include "config.h"
+
+
+SDL_Surface *sdl_screen, *backbuffer;
+
+uint32_t width_of_surface;
+uint32_t* Draw_to_Virtual_Screen;
+
+#ifndef SDL_TRIPLEBUF
+#define SDL_TRIPLEBUF SDL_DOUBLEBUF
+#endif
+
+#define SDL_FLAGS SDL_HWSURFACE | SDL_TRIPLEBUF
+
+void Init_Video()
+{
+ SDL_Init( SDL_INIT_VIDEO );
+
+ SDL_ShowCursor(0);
+
+ sdl_screen = SDL_SetVideoMode(640, 480, 16, SDL_FLAGS);
+
+ backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0,0,0,0);
+
+ Set_Video_InGame();
+}
+
+void Set_Video_Menu()
+{
+ sdl_screen = SDL_SetVideoMode(320, 240, 16, SDL_FLAGS);
+}
+
+void Set_Video_InGame()
+{
+ sdl_screen = SDL_SetVideoMode(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 16, SDL_FLAGS);
+}
+
+void Video_Close()
+{
+ if (sdl_screen) SDL_FreeSurface(sdl_screen);
+ if (backbuffer) SDL_FreeSurface(backbuffer);
+ SDL_Quit();
+}
+
+void Update_Video_Menu()
+{
+ SDL_BlitSurface(backbuffer, NULL, sdl_screen, NULL);
+ SDL_Flip(sdl_screen);
+}
+
+void Update_Video_Ingame()
+{
+ uint32_t *s, *d;
+ uint32_t h, w;
+ uint8_t PAL = !!(Memory.FillRAM[0x2133] & 4);
+
+ if (SDL_LockSurface(sdl_screen) == 0)
+ {
+ if (IPPU.RenderedScreenWidth != sdl_screen->w || IPPU.RenderedScreenHeight != sdl_screen->h) Set_Video_InGame();
+ memcpy(sdl_screen->pixels, GFX.Screen, (IPPU.RenderedScreenWidth * IPPU.RenderedScreenHeight) * 2);
+ SDL_UnlockSurface(sdl_screen);
+ }
+ SDL_Flip(sdl_screen);
+}
diff --git a/shell/video/gcw0/video_blit.h b/shell/video/gcw0/video_blit.h
new file mode 100644
index 0000000..08528e1
--- /dev/null
+++ b/shell/video/gcw0/video_blit.h
@@ -0,0 +1,24 @@
+#ifndef VIDEO_BLIT_H
+#define VIDEO_BLIT_H
+
+#include <SDL/SDL.h>
+
+#define HOST_WIDTH_RESOLUTION sdl_screen->w
+#define HOST_HEIGHT_RESOLUTION sdl_screen->h
+
+#define BACKBUFFER_WIDTH_RESOLUTION backbuffer->w
+#define BACKBUFFER_HEIGHT_RESOLUTION backbuffer->h
+
+extern SDL_Surface *sdl_screen, *backbuffer;
+
+extern uint32_t width_of_surface;
+extern uint32_t* Draw_to_Virtual_Screen;
+
+void Init_Video();
+void Set_Video_Menu();
+void Set_Video_InGame();
+void Video_Close();
+void Update_Video_Menu();
+void Update_Video_Ingame();
+
+#endif
diff --git a/shell/video/retrostone/video_blit.c b/shell/video/retrostone/video_blit.c
new file mode 100644
index 0000000..fd189cc
--- /dev/null
+++ b/shell/video/retrostone/video_blit.c
@@ -0,0 +1,107 @@
+/* Cygne
+ *
+ * Copyright notice for this file:
+ * Copyright (C) 2002 Dox dox@space.pl
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <SDL/SDL.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include "main.h"
+#include "snes9x.h"
+#include "soundux.h"
+#include "memmap.h"
+#include "apu.h"
+#include "cheats.h"
+#include "display.h"
+#include "gfx.h"
+#include "cpuexec.h"
+#include "spc7110.h"
+#include "srtc.h"
+#include "sa1.h"
+#include "scaler.h"
+
+#include "video_blit.h"
+#include "scaler.h"
+#include "config.h"
+
+
+SDL_Surface *sdl_screen, *backbuffer;
+
+uint32_t width_of_surface;
+uint32_t* Draw_to_Virtual_Screen;
+
+void Init_Video()
+{
+ SDL_Init( SDL_INIT_VIDEO );
+
+ SDL_ShowCursor(0);
+
+ sdl_screen = SDL_SetVideoMode(0, 0, 16, SDL_HWSURFACE);
+
+ backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0,0,0,0);
+
+ Set_Video_InGame();
+}
+
+void Set_Video_Menu()
+{
+}
+
+void Set_Video_InGame()
+{
+}
+
+void Video_Close()
+{
+ if (sdl_screen) SDL_FreeSurface(sdl_screen);
+ if (backbuffer) SDL_FreeSurface(backbuffer);
+ SDL_Quit();
+}
+
+void Update_Video_Menu()
+{
+ SDL_SoftStretch(backbuffer, NULL, sdl_screen, NULL);
+ SDL_Flip(sdl_screen);
+}
+
+void Update_Video_Ingame()
+{
+ uint32_t *s, *d;
+ uint32_t h, w;
+ uint8_t PAL = !!(Memory.FillRAM[0x2133] & 4);
+
+ SDL_LockSurface(sdl_screen);
+
+ switch(option.fullscreen)
+ {
+ case 0:
+ bitmap_scale(0,0,IPPU.RenderedScreenWidth,IPPU.RenderedScreenHeight,IPPU.RenderedScreenWidth*2,sdl_screen->h, SNES_WIDTH, sdl_screen->w - (IPPU.RenderedScreenWidth*2),(uint16_t* restrict)GFX.Screen,(uint16_t* restrict)sdl_screen->pixels+(HOST_WIDTH_RESOLUTION-(IPPU.RenderedScreenWidth*2))/2+(HOST_HEIGHT_RESOLUTION-((HOST_HEIGHT_RESOLUTION)))/2*HOST_WIDTH_RESOLUTION);
+ break;
+ case 1:
+ case 2:
+ bitmap_scale(0, 0, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, sdl_screen->w, sdl_screen->h, SNES_WIDTH, 0, GFX.Screen, sdl_screen->pixels);
+ break;
+ }
+
+
+ SDL_UnlockSurface(sdl_screen);
+ SDL_Flip(sdl_screen);
+}
diff --git a/shell/video/retrostone/video_blit.h b/shell/video/retrostone/video_blit.h
new file mode 100644
index 0000000..09aab60
--- /dev/null
+++ b/shell/video/retrostone/video_blit.h
@@ -0,0 +1,24 @@
+#ifndef VIDEO_BLIT_H
+#define VIDEO_BLIT_H
+
+#include <SDL/SDL.h>
+
+#define HOST_WIDTH_RESOLUTION sdl_screen->w
+#define HOST_HEIGHT_RESOLUTION sdl_screen->h
+
+#define BACKBUFFER_WIDTH_RESOLUTION backbuffer->w
+#define BACKBUFFER_HEIGHT_RESOLUTION backbuffer->h
+
+extern SDL_Surface *sdl_screen, *backbuffer;
+
+extern uint32_t width_of_surface;
+extern uint32_t* Draw_to_Virtual_Screen;
+
+void Init_Video();
+void Set_Video_Menu();
+void Set_Video_InGame();
+void Close_Video();
+void Update_Video_Menu();
+void Update_Video_Ingame();
+
+#endif
diff --git a/shell/video/sdl/video_blit.c b/shell/video/sdl/video_blit.c
new file mode 100644
index 0000000..08aadcd
--- /dev/null
+++ b/shell/video/sdl/video_blit.c
@@ -0,0 +1,111 @@
+/* Cygne
+ *
+ * Copyright notice for this file:
+ * Copyright (C) 2002 Dox dox@space.pl
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <SDL/SDL.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include "main.h"
+#include "snes9x.h"
+#include "soundux.h"
+#include "memmap.h"
+#include "apu.h"
+#include "cheats.h"
+#include "display.h"
+#include "gfx.h"
+#include "cpuexec.h"
+#include "srtc.h"
+#include "sa1.h"
+#include "scaler.h"
+
+#include "video_blit.h"
+#include "scaler.h"
+#include "config.h"
+
+
+SDL_Surface *sdl_screen, *backbuffer;
+
+uint32_t width_of_surface;
+uint32_t* Draw_to_Virtual_Screen;
+
+void Init_Video()
+{
+ SDL_Init( SDL_INIT_VIDEO );
+
+ SDL_ShowCursor(0);
+
+ sdl_screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
+
+ backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0,0,0,0);
+
+ Set_Video_InGame();
+}
+
+void Set_Video_Menu()
+{
+}
+
+void Set_Video_InGame()
+{
+}
+
+void Video_Close()
+{
+ if (sdl_screen) SDL_FreeSurface(sdl_screen);
+ if (backbuffer) SDL_FreeSurface(backbuffer);
+ SDL_Quit();
+}
+
+void Update_Video_Menu()
+{
+ SDL_SoftStretch(backbuffer, NULL, sdl_screen, NULL);
+ SDL_Flip(sdl_screen);
+}
+
+void Update_Video_Ingame(int width, int height)
+{
+ uint16_t *s, *d;
+ uint32_t h, w;
+ uint8_t PAL = !!(Memory.FillRAM[0x2133] & 4);
+
+ SDL_LockSurface(sdl_screen);
+
+ switch(option.fullscreen)
+ {
+ case 0:
+ s = (uint16_t*) GFX.Screen;
+ d = (uint16_t*) sdl_screen->pixels + ((sdl_screen->w - width)/2 + (sdl_screen->h - height) * 160) - (PAL ? 0 : 2*320);
+ for(uint8_t y = 0; y < height; y++, s += GFX_PITCH / 2, d += sdl_screen->w) memmove(d, s, width * 2);
+ break;
+ case 1:
+ upscale_256xXXX_to_320x240((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, GFX_PITCH / 2, PAL ? 240 : 224);
+ break;
+ case 2:
+ if (height == 240) upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, GFX_PITCH / 2, 239);
+ else upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels + (160*8), (uint32_t*) GFX.Screen, GFX_PITCH / 2, 224);
+ break;
+ }
+ //bitmap_scale(0, 0, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, sdl_screen->w, sdl_screen->h, SNES_WIDTH*2, 0, GFX.Screen, sdl_screen->pixels);
+
+ SDL_UnlockSurface(sdl_screen);
+ SDL_Flip(sdl_screen);
+}
diff --git a/shell/video/sdl/video_blit.h b/shell/video/sdl/video_blit.h
new file mode 100644
index 0000000..08528e1
--- /dev/null
+++ b/shell/video/sdl/video_blit.h
@@ -0,0 +1,24 @@
+#ifndef VIDEO_BLIT_H
+#define VIDEO_BLIT_H
+
+#include <SDL/SDL.h>
+
+#define HOST_WIDTH_RESOLUTION sdl_screen->w
+#define HOST_HEIGHT_RESOLUTION sdl_screen->h
+
+#define BACKBUFFER_WIDTH_RESOLUTION backbuffer->w
+#define BACKBUFFER_HEIGHT_RESOLUTION backbuffer->h
+
+extern SDL_Surface *sdl_screen, *backbuffer;
+
+extern uint32_t width_of_surface;
+extern uint32_t* Draw_to_Virtual_Screen;
+
+void Init_Video();
+void Set_Video_Menu();
+void Set_Video_InGame();
+void Video_Close();
+void Update_Video_Menu();
+void Update_Video_Ingame();
+
+#endif
diff --git a/src/asmmemfuncs.h b/src/asmmemfuncs.h
index 6fe7853..d1beb1c 100644
--- a/src/asmmemfuncs.h
+++ b/src/asmmemfuncs.h
@@ -3,7 +3,7 @@
#if defined(ARM_ASM)
#define memset32(_dst, _c, _count) \
-({ uint32_t *dst = (_dst); uint32_t c __asm__ ("r7") = (_c); int count = (_count); uint32_t dummy0 __asm__ ("r4"), dummy1 __asm__ ("r5"), dummy2 __asm__ ("r6"); \
+({ uint32_t *dst = (_dst); register uint32_t c __asm__ ("r7") = (_c); register int count = (_count); register uint32_t dummy0 __asm__ ("r4"), dummy1 __asm__ ("r5"), dummy2 __asm__ ("r6"); \
__asm__ __volatile__ ( \
" cmp %[count], #4\n" \
" blt 2f\n" \
@@ -36,7 +36,7 @@
})
#define memset16(_dst, _c, _count) \
-({ uint16_t *dst = (_dst); uint16_t c __asm__ ("r7") = (_c); int count = (_count); uint32_t dummy0 __asm__ ("r4"), dummy1 __asm__ ("r5"), dummy2 __asm__ ("r6"); \
+({ uint16_t *dst = (_dst); register uint16_t c __asm__ ("r7") = (_c); register int count = (_count); register uint32_t dummy0 __asm__ ("r4"), dummy1 __asm__ ("r5"), dummy2 __asm__ ("r6"); \
__asm__ __volatile__ ( \
" cmp %[count], #2\n" \
" blt 3f\n" \
diff --git a/src/os9x_65c816.S b/src/os9x_65c816.S
index e21cc14..e0328e0 100644
--- a/src/os9x_65c816.S
+++ b/src/os9x_65c816.S
@@ -3,7 +3,7 @@
/****************************************************************
****************************************************************/
.align 4
- .include "os9x_65c816_common.s"
+ .include "os9x_65c816_common.S"
@ notaz
@@ -60,7 +60,7 @@
.endif
.endm
- .include "os9x_65c816_opcodes.s"
+ .include "os9x_65c816_opcodes.S"
/*
diff --git a/src/os9x_65c816_global.S b/src/os9x_65c816_global.S
index bde873e..cee9f11 100644
--- a/src/os9x_65c816_global.S
+++ b/src/os9x_65c816_global.S
@@ -1,7 +1,7 @@
/* .DATA*/
.text
.align 4
- .include "os9x_65c816_common.s"
+ .include "os9x_65c816_common.S"
.globl asmS9xGetByte
.globl asmS9xGetWord
diff --git a/src/os9x_65c816_global_armv4.S b/src/os9x_65c816_global_armv4.S
index 13fa1e2..46cfb7c 100644
--- a/src/os9x_65c816_global_armv4.S
+++ b/src/os9x_65c816_global_armv4.S
@@ -3,4 +3,4 @@
mov pc, \reg
.endm
-.include "os9x_65c816_global.s"
+.include "os9x_65c816_global.S"
diff --git a/src/os9x_65c816_spcasm.S b/src/os9x_65c816_spcasm.S
index 5bca8c6..41399c7 100644
--- a/src/os9x_65c816_spcasm.S
+++ b/src/os9x_65c816_spcasm.S
@@ -3,7 +3,7 @@
/****************************************************************
****************************************************************/
.align 4
- .include "os9x_65c816_common.s"
+ .include "os9x_65c816_common.S"
.macro asmAPU_EXECUTE
@@ -35,7 +35,7 @@
43211:
.endm
- .include "os9x_65c816_opcodes.s"
+ .include "os9x_65c816_opcodes.S"
/*
diff --git a/src/os9x_65c816_spcasm.s.last b/src/os9x_65c816_spcasm.s.last
index 7a622c3..7e8e650 100644
--- a/src/os9x_65c816_spcasm.s.last
+++ b/src/os9x_65c816_spcasm.s.last
@@ -3,7 +3,7 @@
/****************************************************************
****************************************************************/
.align 4
- .include "os9x_65c816_common.s"
+ .include "os9x_65c816_common.S"
.macro asmAPU_EXECUTE
@@ -35,7 +35,7 @@
43211:
.endm
- .include "os9x_65c816_opcodes.s"
+ .include "os9x_65c816_opcodes.S"
/*
diff --git a/src/os9x_65c816_spcc.S b/src/os9x_65c816_spcc.S
index 031c8a8..17b3cfd 100644
--- a/src/os9x_65c816_spcc.S
+++ b/src/os9x_65c816_spcc.S
@@ -3,7 +3,7 @@
/****************************************************************
****************************************************************/
.align 4
- .include "os9x_65c816_common.s"
+ .include "os9x_65c816_common.S"
.equ IAPU_PC_offs, 52
@@ -93,7 +93,7 @@
.endm
*/
- .include "os9x_65c816_opcodes.s"
+ .include "os9x_65c816_opcodes.S"
/*
diff --git a/src/port.h b/src/port.h
index c8d0be8..c2aa5bd 100644
--- a/src/port.h
+++ b/src/port.h
@@ -98,6 +98,14 @@ typedef short int16_32;
#define _MAX_PATH PATH_MAX
#endif
+#ifndef _MAX_FNAME
+#define _MAX_FNAME PATH_MAX
+#endif
+
+#ifndef _MAX_EXT
+#define _MAX_EXT PATH_MAX
+#endif
+
//True/False Defines
#define TRUE 1
#define FALSE 0
diff --git a/src/snes9x.h b/src/snes9x.h
index fbea13f..c62e547 100644
--- a/src/snes9x.h
+++ b/src/snes9x.h
@@ -49,13 +49,19 @@
#define ROM_NAME_LEN 23
-#include <streams/memory_stream.h>
-#define STREAM memstream_t *
-#define READ_STREAM(p, l, s) memstream_read(s, p, l)
-#define WRITE_STREAM(p, l, s) memstream_write(s, p, l)
-#define OPEN_STREAM(f, m) memstream_open(0)
-#define CLOSE_STREAM(s) memstream_close(s)
-#define SEEK_STREAM(p,r,s) memstream_seek(p,r,s)
+/* #include <streams/memory_stream.h> */
+/* #define STREAM memstream_t * */
+/* #define READ_STREAM(p, l, s) memstream_read(s, p, l) */
+/* #define WRITE_STREAM(p, l, s) memstream_write(s, p, l) */
+/* #define OPEN_STREAM(f, m) memstream_open(0) */
+/* #define CLOSE_STREAM(s) memstream_close(s) */
+/* #define SEEK_STREAM(p,r,s) memstream_seek(p,r,s) */
+
+#define STREAM FILE *
+#define READ_STREAM(p, l, s) fread(p, sizeof(char), l, s)
+#define WRITE_STREAM(p, l, s) fwrite(p, sizeof(char), l, s)
+#define OPEN_STREAM(f, m) fopen(f, m)
+#define CLOSE_STREAM(s) fclose(s)
/* SNES screen width and height */
#define SNES_WIDTH 256
@@ -92,12 +98,12 @@
// 1 / PPU clock * 342 -> 64.281us
// 64.281us / (1 / 3.546895MHz) -> 228 cycles per scanline.
-//#define SNES_SCANLINE_TIME (63.695e-6)
-//#define SNES_CLOCK_SPEED (3579545)
+#define SNES_SCANLINE_TIME (63.695e-6)
+#define SNES_CLOCK_SPEED (3579545)
-//#define SNES_CLOCK_LEN (1.0 / SNES_CLOCK_SPEED)
+#define SNES_CLOCK_LEN (1.0 / SNES_CLOCK_SPEED)
-//#define SNES_APUTIMER2_CYCLEx10000 ((uint32) 3355824)
+#define SNES_APUTIMER2_CYCLEx10000 ((uint32) 3355824)
#ifdef VAR_CYCLES
//#define SNES_CYCLES_PER_SCANLINE ((uint32) ((SNES_SCANLINE_TIME / SNES_CLOCK_LEN) * 6 + 0.5))