aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorgameblabla2019-10-05 03:04:57 +0200
committergameblabla2019-10-05 03:04:57 +0200
commitd4753076e89d42cdad4a4f1ca4688fad3c56d873 (patch)
treec8641cf282f427d9329db00325e16609acca8663 /shell
parent943821f94b9b2e22315fce876c2e369da7a79bcf (diff)
downloadsnesemu-d4753076e89d42cdad4a4f1ca4688fad3c56d873.tar.gz
snesemu-d4753076e89d42cdad4a4f1ca4688fad3c56d873.tar.bz2
snesemu-d4753076e89d42cdad4a4f1ca4688fad3c56d873.zip
Port the libretro core and make it standalone.
TODO : - Input should use our config file instead. - Missing audio in some games. (Star Ocean, doesn't happen with stock retroarch code. Odd...)
Diffstat (limited to 'shell')
-rw-r--r--shell/audio/alsa/sound_output.c142
-rw-r--r--shell/audio/oss/sound_output.c59
-rw-r--r--shell/audio/portaudio/sound_output.c41
-rw-r--r--shell/audio/sdl/sound_output.c104
-rw-r--r--shell/audio/sound_output.h10
-rw-r--r--shell/emu/core.c435
-rw-r--r--shell/emu/main.h9
-rw-r--r--shell/headers/boolean.h39
-rw-r--r--shell/headers/retro_inline.h39
-rw-r--r--shell/headers/shared.h31
-rw-r--r--shell/input/input.h6
-rw-r--r--shell/input/sdl/input.c74
-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.c597
-rw-r--r--shell/menu/menu.h18
-rw-r--r--shell/other/compatibility_layer.c185
-rw-r--r--shell/scalers/scaler.c139
-rw-r--r--shell/scalers/scaler.h11
-rw-r--r--shell/video/retrostone/video_blit.c155
-rw-r--r--shell/video/retrostone/video_blit.h24
-rw-r--r--shell/video/sdl/video_blit.c132
-rw-r--r--shell/video/sdl/video_blit.h24
25 files changed, 2564 insertions, 0 deletions
diff --git a/shell/audio/alsa/sound_output.c b/shell/audio/alsa/sound_output.c
new file mode 100644
index 0000000..5173bb6
--- /dev/null
+++ b/shell/audio/alsa/sound_output.c
@@ -0,0 +1,142 @@
+#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);
+ }
+}
+
+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..2d32b1f
--- /dev/null
+++ b/shell/audio/oss/sound_output.c
@@ -0,0 +1,59 @@
+#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 );
+}
+
+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..226db5c
--- /dev/null
+++ b/shell/audio/portaudio/sound_output.c
@@ -0,0 +1,41 @@
+#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);
+}
+
+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..f14bb1d
--- /dev/null
+++ b/shell/audio/sdl/sound_output.c
@@ -0,0 +1,104 @@
+#include <sys/ioctl.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <SDL/SDL.h>
+
+#include "sound_output.h"
+
+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)
+{
+ for(uint32_t i = 0; i < len; i += 4)
+ {
+ if(buffered_bytes == BUFFSIZE) return; // just drop samples
+ *(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;
+ }
+}
+
+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_LockAudio();
+ sdl_write_buffer(buffer, buffer_size * 4);
+ SDL_UnlockAudio();
+}
+
+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..ba8a318
--- /dev/null
+++ b/shell/audio/sound_output.h
@@ -0,0 +1,10 @@
+#ifndef SOUND_OUTPUT_H
+#define SOUND_OUTPUT_H
+
+#include "shared.h"
+
+extern uint32_t Audio_Init();
+extern void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size);
+extern void Audio_Close();
+
+#endif
diff --git a/shell/emu/core.c b/shell/emu/core.c
new file mode 100644
index 0000000..2edc457
--- /dev/null
+++ b/shell/emu/core.c
@@ -0,0 +1,435 @@
+// 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"
+#include "apu_blargg.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 "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
+
+size_t retro_serialize_size(void)
+{
+ return sizeof(CPU) + sizeof(ICPU) + sizeof(PPU) + sizeof(DMA) +
+ 0x10000 + 0x20000 + 0x20000 + 0x8000 +
+#ifndef USE_BLARGG_APU
+ sizeof(APU) + sizeof(IAPU) + 0x10000 +
+#else
+ SPC_SAVE_STATE_BLOCK_SIZE +
+#endif
+ sizeof(SA1) + sizeof(s7r) + sizeof(rtc_f9);
+}
+
+void RTC_Save(char* path, uint_fast8_t state)
+{
+ FILE* savefp;
+
+ /* If RTC is disabled then don't bother saving any RTC info */
+ if (!Settings.SRTC) return;
+
+ if (state == 1)
+ {
+ savefp = fopen(path, "rb");
+ if (savefp)
+ {
+ if (Settings.SPC7110RTC)
+ {
+ fread(&rtc_f9, sizeof(uint8_t), sizeof(rtc_f9), savefp);
+ fclose(savefp);
+ S9xUpdateRTC();
+ }
+ else
+ {
+ fread(&rtc, sizeof(uint8_t), sizeof(rtc), savefp);
+ fclose(savefp);
+ S9xSRTCPostLoadState();
+ }
+ }
+ }
+ else
+ {
+ savefp = fopen(path, "wb");
+ if (savefp)
+ {
+ if (Settings.SPC7110RTC)
+ {
+ fwrite(&rtc_f9, sizeof(uint8_t), sizeof(rtc_f9), savefp);
+ fclose(savefp);
+ S9xUpdateRTC();
+ }
+ else
+ {
+ S9xSRTCPreSaveState();
+ fwrite(&rtc, sizeof(uint8_t), sizeof(rtc), savefp);
+ fclose(savefp);
+ }
+ }
+ }
+}
+
+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 (Memory.SRAMMask == 0) return;
+
+ if (state == 1)
+ {
+ savefp = fopen(path, "rb");
+ if (savefp)
+ {
+ fread(Memory.SRAM, sizeof(uint8_t), Memory.SRAMMask, savefp);
+ fclose(savefp);
+ }
+ }
+ else
+ {
+ savefp = fopen(path, "wb");
+ if (savefp)
+ {
+ fwrite(Memory.SRAM, sizeof(uint8_t), Memory.SRAMMask, savefp);
+ fclose(savefp);
+ }
+ }
+}
+
+void SaveState(char* path, uint_fast8_t state)
+{
+#ifndef USE_BLARGG_APU
+ uint8_t* IAPU_RAM_current = IAPU.RAM;
+ uintptr_t IAPU_RAM_offset;
+#endif
+ char* buffer;
+ FILE* savefp;
+
+#ifndef USE_BLARGG_APU
+ buffer = malloc(sizeof(APU) + sizeof(IAPU) + 0x10000);
+#else
+ buffer = malloc(SPC_SAVE_STATE_BLOCK_SIZE);
+#endif
+
+ if (state == 1)
+ {
+ savefp = fopen(path, "rb");
+ if (savefp)
+ {
+ S9xReset();
+
+ fread(&CPU, sizeof(uint8_t), sizeof(CPU), savefp);
+ fread(&ICPU, sizeof(uint8_t), sizeof(ICPU), savefp);
+ fread(&PPU, sizeof(uint8_t), sizeof(PPU), savefp);
+ fread(&DMA, sizeof(uint8_t), sizeof(DMA), savefp);
+
+ fread(Memory.VRAM, sizeof(uint8_t), 0x10000, savefp);
+ fread(Memory.RAM, sizeof(uint8_t), 0x20000, savefp);
+ fread(Memory.SRAM, sizeof(uint8_t), 0x20000, savefp);
+ fread(Memory.FillRAM, sizeof(uint8_t), 0x8000, savefp);
+
+ #ifndef USE_BLARGG_APU
+ fread(&APU, sizeof(uint8_t), sizeof(APU), savefp);
+ fread(&IAPU, sizeof(uint8_t), sizeof(IAPU), savefp);
+ IAPU_RAM_offset = IAPU_RAM_current - IAPU.RAM;
+ IAPU.PC += IAPU_RAM_offset;
+ IAPU.DirectPage += IAPU_RAM_offset;
+ IAPU.WaitAddress1 += IAPU_RAM_offset;
+ IAPU.WaitAddress2 += IAPU_RAM_offset;
+ IAPU.RAM = IAPU_RAM_current;
+ fread(IAPU.RAM, sizeof(uint8_t), 0x10000, savefp);
+ #else
+ S9xAPULoadState(buffer);
+ fread(buffer, sizeof(uint8_t), SPC_SAVE_STATE_BLOCK_SIZE, savefp);
+ #endif
+
+ SA1.Registers.PC = SA1.PC - SA1.PCBase;
+ S9xSA1PackStatus();
+ fread(&SA1, sizeof(uint8_t), sizeof(SA1), savefp);
+ fread(&s7r, sizeof(uint8_t), sizeof(s7r), savefp);
+ fread(&rtc_f9, sizeof(uint8_t), sizeof(rtc_f9), savefp);
+ fclose(savefp);
+
+ S9xFixSA1AfterSnapshotLoad();
+ FixROMSpeed();
+ IPPU.ColorsChanged = true;
+ IPPU.OBJChanged = true;
+ CPU.InDMA = false;
+ S9xFixColourBrightness();
+ S9xSA1UnpackStatus();
+ #ifndef USE_BLARGG_APU
+ S9xAPUUnpackStatus();
+ S9xFixSoundAfterSnapshotLoad();
+ #endif
+ ICPU.ShiftedPB = ICPU.Registers.PB << 16;
+ ICPU.ShiftedDB = ICPU.Registers.DB << 16;
+ S9xSetPCBase(ICPU.ShiftedPB + ICPU.Registers.PC);
+ S9xUnpackStatus();
+ S9xFixCycles();
+ S9xReschedule();
+ }
+ }
+ else
+ {
+ savefp = fopen(path, "wb");
+ if (savefp)
+ {
+ #ifdef LAGFIX
+ S9xPackStatus();
+ #ifndef USE_BLARGG_APU
+ S9xAPUPackStatus();
+ #endif
+ #endif
+
+ S9xUpdateRTC();
+ S9xSRTCPreSaveState();
+ fwrite(&CPU, sizeof(uint8_t), sizeof(CPU), savefp);
+ fwrite(&ICPU, sizeof(uint8_t), sizeof(ICPU), savefp);
+ fwrite(&PPU, sizeof(uint8_t), sizeof(PPU), savefp);
+ fwrite(&DMA, sizeof(uint8_t), sizeof(DMA), savefp);
+
+ fwrite(Memory.VRAM, sizeof(uint8_t), 0x10000, savefp);
+ fwrite(Memory.RAM, sizeof(uint8_t), 0x20000, savefp);
+ fwrite(Memory.SRAM, sizeof(uint8_t), 0x20000, savefp);
+ fwrite(Memory.FillRAM, sizeof(uint8_t), 0x8000, savefp);
+
+ #ifndef USE_BLARGG_APU
+ fwrite(&APU, sizeof(uint8_t), sizeof(APU), savefp);
+ fwrite(&IAPU, sizeof(uint8_t), sizeof(IAPU), savefp);
+ fwrite(IAPU.RAM, sizeof(uint8_t), 0x10000, savefp);
+ #else
+ S9xAPUSaveState(buffer);
+ fwrite(buffer, sizeof(uint8_t), SPC_SAVE_STATE_BLOCK_SIZE, savefp);
+ #endif
+
+ SA1.Registers.PC = SA1.PC - SA1.PCBase;
+ S9xSA1PackStatus();
+ fwrite(&SA1, sizeof(uint8_t), sizeof(SA1), savefp);
+ fwrite(&s7r, sizeof(uint8_t), sizeof(s7r), savefp);
+ fwrite(&rtc_f9, sizeof(uint8_t), sizeof(rtc_f9), savefp);
+ fclose(savefp);
+ }
+ }
+
+ if (buffer) free(buffer);
+}
+
+void Emulation_Run (void)
+{
+#ifndef USE_BLARGG_APU
+ static int16_t audio_buf[2048];
+#endif
+ IPPU.RenderThisFrame = true;
+#ifdef USE_BLARGG_APU
+ S9xSetSoundMute(false);
+#endif
+ Settings.HardDisableAudio = false;
+
+ S9xMainLoop();
+
+#ifndef USE_BLARGG_APU
+ samples_to_play += samples_per_frame;
+
+ if (samples_to_play > 512)
+ {
+ S9xMixSamples(audio_buf, samples_to_play * 2);
+ Audio_Write(audio_buf, samples_to_play);
+ samples_to_play = 0;
+ }
+#else
+ S9xAudioCallback();
+#endif
+
+
+#ifdef FRAMESKIP
+ if (IPPU.RenderThisFrame)
+ {
+#endif
+ Update_Video_Ingame();
+#ifdef FRAMESKIP
+ IPPU.RenderThisFrame = false;
+ }
+ else
+ {
+ IPPU.RenderThisFrame = true;
+ }
+#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
+ samples_per_frame = samplerate / fps;
+ S9xSetPlaybackRate(Settings.SoundPlaybackRate);
+#endif
+ return true;
+}
+
+
+void init_sfc_setting(void)
+{
+ memset(&Settings, 0, sizeof(Settings));
+ Settings.JoystickEnabled = false;
+ Settings.SoundPlaybackRate = samplerate;
+ Settings.CyclesPercentage = 100;
+
+ Settings.DisableSoundEcho = false;
+ Settings.InterpolatedSound = true;
+ Settings.APUEnabled = true;
+
+ Settings.H_Max = SNES_CYCLES_PER_SCANLINE;
+ Settings.FrameTimePAL = 20000;
+ Settings.FrameTimeNTSC = 16667;
+ Settings.DisableMasterVolume = false;
+ Settings.Mouse = true;
+ Settings.SuperScope = true;
+ Settings.MultiPlayer5 = true;
+ Settings.ControllerOption = SNES_JOYPAD;
+#ifdef USE_BLARGG_APU
+ Settings.SoundSync = false;
+#endif
+ Settings.ApplyCheats = true;
+ Settings.HBlankStart = (256 * Settings.H_Max) / SNES_HCOUNTER_MAX;
+}
+
+void Init_SFC(void)
+{
+ init_sfc_setting();
+ S9xInitMemory();
+ S9xInitAPU();
+ S9xInitDisplay();
+ S9xInitGFX();
+#ifdef USE_BLARGG_APU
+ S9xInitSound(1000, 0); /* just give it a 1 second buffer */
+ S9xSetSamplesAvailableCallback(S9xAudioCallback);
+#else
+ S9xInitSound();
+#endif
+ CPU.SaveStateVersion = 0;
+}
+
+void Deinit_SFC(void)
+{
+ if (Settings.SPC7110)
+ Del7110Gfx();
+
+ S9xDeinitGFX();
+ S9xDeinitDisplay();
+ S9xDeinitAPU();
+ S9xDeinitMemory();
+}
+
+
+
+/* Main entrypoint of the emulator */
+int main(int argc, char* argv[])
+{
+ int isloaded;
+
+ printf("Starting Snes9x2005\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_Video();
+
+ overclock_cycles = true;
+ one_c = 4;
+ slow_one_c = 5;
+ two_c = 6;
+ reduce_sprite_flicker = true;
+
+ Audio_Init();
+ Init_SFC();
+
+ 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..43688c3
--- /dev/null
+++ b/shell/emu/main.h
@@ -0,0 +1,9 @@
+#ifndef MAIN_H
+#define MAIN_H
+
+int ResumeEmulation;
+// 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..a44f60e
--- /dev/null
+++ b/shell/headers/shared.h
@@ -0,0 +1,31 @@
+#ifndef SHARED_H
+#define SHARED_H
+
+#define SOUND_OUTPUT_FREQUENCY 44100
+#define SOUND_SAMPLES_SIZE 1024
+
+/*
+#if defined(BITTBOY)
+#define SOUND_OUTPUT_FREQUENCY 22050
+#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..357f7d1
--- /dev/null
+++ b/shell/input/sdl/input.c
@@ -0,0 +1,74 @@
+#include <SDL/SDL.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <portaudio.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 "menu.h"
+#include "config.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;
+
+ keystate = SDL_GetKeyState(NULL);
+
+ SDL_PollEvent(&event);
+
+ CASE(SDLK_RETURN, SNES_START_MASK);
+ CASE(SDLK_ESCAPE, SNES_SELECT_MASK);
+ CASE(SDLK_LCTRL, SNES_A_MASK);
+ CASE(SDLK_LALT, SNES_B_MASK);
+ CASE(SDLK_LSHIFT, SNES_X_MASK);
+ CASE(SDLK_SPACE, SNES_Y_MASK);
+ CASE(SDLK_TAB, SNES_TL_MASK);
+ CASE(SDLK_BACKSPACE, SNES_TR_MASK);
+ CASE(SDLK_UP, SNES_UP_MASK);
+ CASE(SDLK_LEFT, SNES_LEFT_MASK);
+ CASE(SDLK_RIGHT, SNES_RIGHT_MASK);
+ CASE(SDLK_DOWN, SNES_DOWN_MASK);
+
+ if (keystate[SDLK_END]) emulator_state = 1;
+
+ return joypad;
+}
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..c1c97b9
--- /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 < HOST_WIDTH_RESOLUTION && y < HOST_HEIGHT_RESOLUTION)
+ {
+ *((uint16_t* restrict)buffer + ((x) + (y) * HOST_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 < (HOST_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, (HOST_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..70096bf
--- /dev/null
+++ b/shell/menu/menu.c
@@ -0,0 +1,597 @@
+#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"
+
+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 RTC_Save(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 RTC_Menu(uint_fast8_t load_mode)
+{
+ char tmp[512];
+ snprintf(tmp, sizeof(tmp), "%s/%s.rtc", rtc_path, GameName_emu);
+ RTC_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] = 273;
+ option.config_buttons[0][1] = 275;
+ option.config_buttons[0][2] = 274;
+ option.config_buttons[0][3] = 276;
+
+ option.config_buttons[0][4] = 306;
+ option.config_buttons[0][5] = 308;
+ option.config_buttons[0][6] = 304;
+ option.config_buttons[0][7] = 32;
+
+ option.config_buttons[0][8] = 9;
+ option.config_buttons[0][9] = 8;
+
+ option.config_buttons[0][10] = 13;
+ option.config_buttons[0][11] = 27;
+
+ option.fullscreen = 1;
+ }
+}
+
+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 273:
+ return "DPAD UP";
+ break;
+ /* DOWN button */
+ case 274:
+ return "DPAD DOWN";
+ break;
+ /* LEFT button */
+ case 276:
+ return "DPAD LEFT";
+ break;
+ /* RIGHT button */
+ case 275:
+ return "DPAD RIGHT";
+ break;
+ /* A button */
+ case 306:
+ return "A button";
+ break;
+ /* B button */
+ case 308:
+ return "B button";
+ break;
+ /* X button */
+ case 304:
+ return "X button";
+ break;
+ /* Y button */
+ case 32:
+ return "Y button";
+ break;
+ /* L button */
+ case 9:
+ return "L button";
+ break;
+ /* R button */
+ case 8:
+ return "R button";
+ break;
+ /* Power button */
+ case 279:
+ return "L2 button";
+ break;
+ /* Brightness */
+ case 51:
+ return "R2 button";
+ break;
+ /* Volume - */
+ case 38:
+ return "Volume -";
+ break;
+ /* Volume + */
+ case 233:
+ return "Volume +";
+ break;
+ /* Start */
+ case 13:
+ return "Start button";
+ break;
+ /* Select */
+ case 1:
+ return "Select button";
+ break;
+ default:
+ return "Unknown key";
+ 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 SDLK_UP:
+ currentselection--;
+ if (currentselection < 1)
+ {
+ if (currentselection > 9) currentselection = 12;
+ else currentselection = 9;
+ }
+ break;
+ case SDLK_DOWN:
+ currentselection++;
+ if (currentselection == 10)
+ {
+ currentselection = 1;
+ }
+ break;
+ case SDLK_LCTRL:
+ case SDLK_RETURN:
+ pressed = 1;
+ break;
+ case SDLK_ESCAPE:
+ option.config_buttons[controls_chosen][currentselection - 1] = 0;
+ break;
+ case SDLK_LALT:
+ exit_input = 1;
+ break;
+ case SDLK_LEFT:
+ if (currentselection > 9) currentselection -= 9;
+ break;
+ case SDLK_RIGHT:
+ if (currentselection < 10) currentselection += 9;
+ break;
+ case SDLK_BACKSPACE:
+ controls_chosen = 1;
+ break;
+ case SDLK_TAB:
+ 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);
+ bitmap_scale(0,0,320,240,sdl_screen->w,sdl_screen->h,320,0,(uint16_t* restrict)backbuffer->pixels,(uint16_t* restrict)sdl_screen->pixels);
+
+ while (SDL_PollEvent(&Event))
+ {
+ if (Event.type == SDL_KEYDOWN)
+ {
+ if (Event.key.keysym.sym != SDLK_RCTRL)
+ {
+ option.config_buttons[controls_chosen][currentselection - 1] = Event.key.keysym.sym;
+ exit_map = 1;
+ }
+ }
+ }
+ SDL_Flip(sdl_screen);
+ }
+ 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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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 : %d\n", (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);
+
+ bitmap_scale(0,0,320,240,sdl_screen->w,sdl_screen->h,320,0,(uint16_t* restrict)backbuffer->pixels,(uint16_t* restrict)sdl_screen->pixels);
+ SDL_Flip(sdl_screen);
+ }
+
+ 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);
+ RTC_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("Libretro Fork 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 SDLK_UP:
+ currentselection--;
+ if (currentselection == 0)
+ currentselection = 6;
+ break;
+ case SDLK_DOWN:
+ currentselection++;
+ if (currentselection == 7)
+ currentselection = 1;
+ break;
+ case SDLK_END:
+ case SDLK_RCTRL:
+ case SDLK_LALT:
+ pressed = 1;
+ currentselection = 1;
+ break;
+ case SDLK_LCTRL:
+ case SDLK_RETURN:
+ pressed = 1;
+ break;
+ case SDLK_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 SDLK_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;
+ }
+ }
+
+ bitmap_scale(0,0,320,240,sdl_screen->w,sdl_screen->h,320,0,(uint16_t* restrict)backbuffer->pixels,(uint16_t* restrict)sdl_screen->pixels);
+ SDL_Flip(sdl_screen);
+ }
+
+ 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 */
+ 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/.snesemu", 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);
+ RTC_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..fea850b
--- /dev/null
+++ b/shell/other/compatibility_layer.c
@@ -0,0 +1,185 @@
+#include <SDL/SDL.h>
+#include <portaudio.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"
+
+const char* S9xGetFilename(const char* in)
+{
+ static char filename [PATH_MAX + 1];
+ char drive [_MAX_DRIVE + 1];
+ char dir [_MAX_DIR + 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)
+{
+#ifdef DS2_DMA
+ if (GFX.Screen_buffer)
+ AlignedFree(GFX.Screen, PtrAdj.GFXScreen);
+#elif defined(_3DS)
+ if (GFX.Screen_buffer)
+ linearFree(GFX.Screen_buffer);
+#else
+ if (GFX.Screen_buffer)
+ free(GFX.Screen_buffer);
+#endif
+ if (GFX.SubScreen_buffer)
+ free(GFX.SubScreen_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.SubScreen_buffer = NULL;
+ GFX.ZBuffer = NULL;
+ GFX.ZBuffer_buffer = NULL;
+ GFX.SubZBuffer = NULL;
+ GFX.SubZBuffer_buffer = NULL;
+}
+
+void S9xInitDisplay(void)
+{
+ int32_t h = IMAGE_HEIGHT;
+ int32_t safety = 32;
+
+ GFX.Pitch = IMAGE_WIDTH * 2;
+#ifdef DS2_DMA
+ GFX.Screen_buffer = (uint8_t *) AlignedMalloc(GFX.Pitch * h + safety, 32, &PtrAdj.GFXScreen);
+#elif defined(_3DS)
+ safety = 0x80;
+ GFX.Screen_buffer = (uint8_t *) linearMemAlign(GFX.Pitch * h + safety, 0x80);
+#else
+ GFX.Screen_buffer = (uint8_t *) malloc(GFX.Pitch * h + safety);
+#endif
+ GFX.SubScreen_buffer = (uint8_t *) malloc(GFX.Pitch * h + safety);
+ GFX.ZBuffer_buffer = (uint8_t *) malloc((GFX.Pitch >> 1) * h + safety);
+ GFX.SubZBuffer_buffer = (uint8_t *) malloc((GFX.Pitch >> 1) * h + safety);
+
+ GFX.Screen = GFX.Screen_buffer + safety;
+ GFX.SubScreen = GFX.SubScreen_buffer + safety;
+ GFX.ZBuffer = GFX.ZBuffer_buffer + safety;
+ GFX.SubZBuffer = GFX.SubZBuffer_buffer + safety;
+
+ GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 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;
+}
+
+
+bool S9xReadMousePosition(int32_t which1, int32_t* x, int32_t* y, uint32_t* buttons)
+{
+ (void) which1;
+ (void) x;
+ (void) y;
+ (void) buttons;
+ return false;
+}
+
+bool S9xReadSuperScopePosition(int32_t* x, int32_t* y, uint32_t* 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..3aeea05
--- /dev/null
+++ b/shell/scalers/scaler.c
@@ -0,0 +1,139 @@
+#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 * 512 * 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)
+{
+ uint_fast16_t midh = 240;
+ uint_fast16_t Eh = 0;
+ uint_fast16_t source = 0;
+ uint_fast16_t dh = 0;
+ uint_fast8_t y, x;
+
+ for (y = 0; y < 240; y++)
+ {
+ source = dh * width;
+
+ 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/retrostone/video_blit.c b/shell/video/retrostone/video_blit.c
new file mode 100644
index 0000000..be84dd1
--- /dev/null
+++ b/shell/video/retrostone/video_blit.c
@@ -0,0 +1,155 @@
+/* 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 "mednafen.h"
+#include "mempatcher.h"
+#include "wswan/gfx.h"
+#include "wswan/wswan-memory.h"
+#include "wswan/sound.h"
+#include "wswan/interrupt.h"
+#include "wswan/v30mz.h"
+#include "wswan/rtc.h"
+#include "wswan/gfx.h"
+#include "wswan/eeprom.h"
+
+#include "video_blit.h"
+#include "scaler.h"
+#include "config.h"
+
+SDL_Surface *sdl_screen, *backbuffer, *wswan_vs, *wswan_vs_rot;
+
+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, HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, 0,0,0,0);
+
+ wswan_vs = SDL_CreateRGBSurface(SDL_SWSURFACE, INTERNAL_WSWAN_WIDTH, INTERNAL_WSWAN_HEIGHT, 16, 0,0,0,0);
+
+ wswan_vs_rot = SDL_CreateRGBSurface(SDL_SWSURFACE, INTERNAL_WSWAN_HEIGHT, INTERNAL_WSWAN_WIDTH, 16, 0,0,0,0);
+
+ Set_Video_InGame();
+}
+
+void Set_Video_Menu()
+{
+ if (sdl_screen->w != HOST_WIDTH_RESOLUTION)
+ {
+ memcpy(wswan_vs->pixels, sdl_screen->pixels, (INTERNAL_WSWAN_WIDTH * INTERNAL_WSWAN_HEIGHT)*2);
+ sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE);
+ }
+}
+
+void Set_Video_InGame()
+{
+ if (sdl_screen->w != HOST_WIDTH_RESOLUTION) sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE);
+ Draw_to_Virtual_Screen = wswan_vs->pixels;
+ width_of_surface = INTERNAL_WSWAN_WIDTH;
+}
+
+void Video_Close()
+{
+ if (sdl_screen) SDL_FreeSurface(sdl_screen);
+ if (backbuffer) SDL_FreeSurface(backbuffer);
+ if (wswan_vs) SDL_FreeSurface(wswan_vs);
+ if (wswan_vs_rot) SDL_FreeSurface(wswan_vs_rot);
+ SDL_Quit();
+}
+
+void Update_Video_Menu()
+{
+ SDL_Flip(sdl_screen);
+}
+
+static void rotate_90_ccw(uint16_t* restrict dst, uint16_t* restrict src)
+{
+ int32_t h = 224, w = 144;
+ src += w * h - 1;
+ for (int32_t col = w - 1; col >= 0; --col)
+ {
+ uint16_t *outcol = dst + col;
+ for(int32_t row = 0; row < h; ++row, outcol += w)
+ {
+ *outcol = *src--;
+ }
+ }
+}
+
+void Update_Video_Ingame()
+{
+ uint32_t internal_width, internal_height, keep_aspect_width, keep_aspect_height;
+ uint16_t* restrict source_graph;
+
+ if ((Wswan_IsVertical() == 1 && option.orientation_settings != 2) || option.orientation_settings == 1)
+ {
+ rotate_90_ccw((uint16_t* restrict)wswan_vs_rot->pixels, (uint16_t* restrict)wswan_vs->pixels);
+ internal_width = INTERNAL_WSWAN_HEIGHT;
+ internal_height = INTERNAL_WSWAN_WIDTH;
+ source_graph = (uint16_t* restrict)wswan_vs_rot->pixels;
+ keep_aspect_width = ((HOST_HEIGHT_RESOLUTION / INTERNAL_WSWAN_HEIGHT) * INTERNAL_WSWAN_WIDTH) / 2;
+ if (keep_aspect_width > HOST_WIDTH_RESOLUTION) keep_aspect_width -= HOST_WIDTH_RESOLUTION/2;
+ keep_aspect_height = HOST_HEIGHT_RESOLUTION;
+ }
+ else
+ {
+ internal_width = INTERNAL_WSWAN_WIDTH;
+ internal_height = INTERNAL_WSWAN_HEIGHT;
+ source_graph = (uint16_t* restrict)wswan_vs->pixels;
+ keep_aspect_width = HOST_WIDTH_RESOLUTION;
+ keep_aspect_height = ((HOST_WIDTH_RESOLUTION / INTERNAL_WSWAN_WIDTH) * INTERNAL_WSWAN_HEIGHT);
+ if (keep_aspect_height > HOST_HEIGHT_RESOLUTION) keep_aspect_height -= HOST_HEIGHT_RESOLUTION/4;
+ }
+
+ if (SDL_LockSurface(sdl_screen) == 0)
+ {
+ switch(option.fullscreen)
+ {
+ // Fullscreen
+ case 0:
+ bitmap_scale(0,0,internal_width,internal_height,internal_width*2,internal_height*2,internal_width, HOST_WIDTH_RESOLUTION - (internal_width*2),(uint16_t* restrict)source_graph,(uint16_t* restrict)sdl_screen->pixels+(HOST_WIDTH_RESOLUTION-(internal_width*2))/2+(HOST_HEIGHT_RESOLUTION-(internal_height*2))/2*HOST_WIDTH_RESOLUTION);
+ break;
+ // Fullscreen
+ case 1:
+ bitmap_scale(0, 0, internal_width, internal_height, HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, internal_width, 0, (uint16_t* restrict)source_graph, (uint16_t* restrict)sdl_screen->pixels);
+ break;
+ case 2:
+ bitmap_scale(0,0,internal_width,internal_height,keep_aspect_width,keep_aspect_height,internal_width, HOST_WIDTH_RESOLUTION - keep_aspect_width,(uint16_t* restrict)source_graph,(uint16_t* restrict)sdl_screen->pixels+(HOST_WIDTH_RESOLUTION-keep_aspect_width)/2+(HOST_HEIGHT_RESOLUTION-keep_aspect_height)/2*HOST_WIDTH_RESOLUTION);
+ break;
+ // Hqx
+ case 3:
+ 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..8e1c81c
--- /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 INTERNAL_WSWAN_WIDTH 224
+#define INTERNAL_WSWAN_HEIGHT 144
+
+extern SDL_Surface *screen, *wswan_vs, *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..9778039
--- /dev/null
+++ b/shell/video/sdl/video_blit.c
@@ -0,0 +1,132 @@
+/* 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(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE);
+
+ backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, 0,0,0,0);
+
+ Set_Video_InGame();
+}
+
+void Set_Video_Menu()
+{
+ /*if (sdl_screen->w != HOST_WIDTH_RESOLUTION)
+ {
+ sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE);
+ }*/
+}
+
+void Set_Video_InGame()
+{
+ /*switch(option.fullscreen)
+ {
+ // Native
+ #ifdef SUPPORT_NATIVE_RESOLUTION
+ case 0:
+ if (sdl_screen->w != INTERNAL_WSWAN_WIDTH) sdl_screen = SDL_SetVideoMode(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, 16, SDL_HWSURFACE);
+ Draw_to_Virtual_Screen = sdl_screen->pixels;
+ width_of_surface = sdl_screen->w;
+ break;
+ #endif
+ default:
+ if (sdl_screen->w != HOST_WIDTH_RESOLUTION) sdl_screen = SDL_SetVideoMode(HOST_WIDTH_RESOLUTION, HOST_HEIGHT_RESOLUTION, 16, SDL_HWSURFACE);
+ Draw_to_Virtual_Screen = wswan_vs->pixels;
+ width_of_surface = INTERNAL_WSWAN_WIDTH;
+ break;
+ }*/
+}
+
+void Video_Close()
+{
+ if (sdl_screen) SDL_FreeSurface(sdl_screen);
+ if (backbuffer) SDL_FreeSurface(backbuffer);
+ SDL_Quit();
+}
+
+void Update_Video_Menu()
+{
+ 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:
+ s = (uint32_t*) GFX.Screen;
+ d = (uint32_t*) sdl_screen->pixels + ((sdl_screen->w - IPPU.RenderedScreenWidth)/4 + (sdl_screen->h - IPPU.RenderedScreenHeight) * 160) - (PAL ? 0 : 4*320);
+ for(uint8_t y = 0; y < IPPU.RenderedScreenHeight; y++, s += IPPU.RenderedScreenWidth, d += sdl_screen->w/2) memmove(d, s, IPPU.RenderedScreenWidth * 2);
+
+ break;
+ case 1:
+ upscale_256xXXX_to_320x240((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, SNES_WIDTH, PAL ? 240 : 224);
+ break;
+ case 2:
+ if (IPPU.RenderedScreenHeight == 240) upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, SNES_WIDTH, 239);
+ else upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels + (160*8), (uint32_t*) GFX.Screen, SNES_WIDTH, 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..ea28ba9
--- /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 320
+#define HOST_HEIGHT_RESOLUTION 240
+
+#define INTERNAL_SNES_WIDTH_NTSC 256
+#define INTERNAL_SNES_HEIGHT_NTSC 224
+
+extern SDL_Surface *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