diff options
-rw-r--r-- | Makefile.retrostone2 | 63 | ||||
-rw-r--r-- | icon.png | bin | 0 -> 2130 bytes | |||
-rwxr-xr-x | package_OPK | 2 | ||||
-rw-r--r-- | shell/menu/menu.c | 10 | ||||
-rw-r--r-- | shell/other/compatibility_layer.c | 44 | ||||
-rw-r--r-- | shell/scalers/scaler.c | 25 | ||||
-rw-r--r-- | shell/video/gcw0/video_blit.c | 106 | ||||
-rw-r--r-- | shell/video/gcw0/video_blit.h | 24 | ||||
-rw-r--r-- | shell/video/retrostone/video_blit.c | 5 | ||||
-rw-r--r-- | shell/video/sdl/video_blit.c | 18 |
10 files changed, 238 insertions, 59 deletions
diff --git a/Makefile.retrostone2 b/Makefile.retrostone2 new file mode 100644 index 0000000..a64a4cf --- /dev/null +++ b/Makefile.retrostone2 @@ -0,0 +1,63 @@ +PRGNAME = snes9x + +VIDEO_BACKEND = gcw0 +INPUT_BACKEND = sdl +SOUND_BACKEND = sdl +PROFILE = 0 + +# define regarding OS, which compiler to use +CC = /opt/retrostone2-toolchain/bin/arm-linux-gcc + +# change compilation / linking flag options +CFLAGS = -DLSB_FIRST -I. -Ilibretro-common/include -Isrc -DINLINE="inline" -DRIGHTSHIFT_IS_SAR -DFAST_ALIGNED_LSB_WORD_ACCESS +CFLAGS += -Isource -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 +CFLAGS += -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1 + +CFLAGS += -DNDEBUG -DLAGFIX -DGIT_VERSION=\"" c9b3980"\" -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=/home/useless/profile +else ifeq ($(PROFILE), APPLY) +CFLAGS += -fprofile-use -fbranch-probabilities +endif + +#-fprofile-generate=/mnt/int_sd/profile +LDFLAGS = -lc -lgcc -lm -lSDL -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 + +# Files to be compiled +SRCDIR = ./source ./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 = $(OBJ_C) $(OBJ_CP) + +# Rules to make executable +$(PRGNAME): $(OBJS) + $(CC) $(CFLAGS) -o $(PRGNAME) $^ $(LDFLAGS) + +$(OBJ_C) : %.o : %.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(PRGNAME)$(EXESUFFIX) *.o diff --git a/icon.png b/icon.png Binary files differnew file mode 100644 index 0000000..01a6dab --- /dev/null +++ b/icon.png diff --git a/package_OPK b/package_OPK index bcdba1f..25a586d 100755 --- a/package_OPK +++ b/package_OPK @@ -2,7 +2,7 @@ mkdir -p opk cp ./snes9x opk/snes9x -cp ./snes9x.png opk/snes9x.png +cp ./icon.png opk/icon.png # https://unix.stackexchange.com/questions/219268/how-to-add-new-lines-when-using-echo print() diff --git a/shell/menu/menu.c b/shell/menu/menu.c index a8c24b5..b79d5ab 100644 --- a/shell/menu/menu.c +++ b/shell/menu/menu.c @@ -261,8 +261,6 @@ static void Input_Remapping() { 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) @@ -274,7 +272,7 @@ static void Input_Remapping() } } } - SDL_Flip(sdl_screen); + Update_Video_Menu(); } break; } @@ -336,8 +334,7 @@ static void Input_Remapping() 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); + Update_Video_Menu(); } config_save(); @@ -516,8 +513,7 @@ void Menu() } } - 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); + Update_Video_Menu(); } SDL_FillRect(sdl_screen, NULL, 0); diff --git a/shell/other/compatibility_layer.c b/shell/other/compatibility_layer.c index 27ffb5b..3082c9a 100644 --- a/shell/other/compatibility_layer.c +++ b/shell/other/compatibility_layer.c @@ -13,6 +13,8 @@ #include "sa1.h" #include "scaler.h" +static uint32_t width_snes = 256; + const char* S9xGetFilename(const char* in) { static char filename [PATH_MAX + 1]; @@ -34,18 +36,12 @@ 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) @@ -64,25 +60,19 @@ void S9xDeinitDisplay(void) 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; + + width_snes = IMAGE_WIDTH; + + GFX.Pitch = IMAGE_WIDTH; + GFX.Screen_buffer = (uint8_t *) malloc(GFX.Pitch * h); + GFX.SubScreen_buffer = (uint8_t *) malloc(GFX.Pitch * h); + GFX.ZBuffer_buffer = (uint8_t *) malloc((GFX.Pitch >> 1) * h ); + GFX.SubZBuffer_buffer = (uint8_t *) malloc((GFX.Pitch >> 1) * h); + + GFX.Screen = GFX.Screen_buffer; + GFX.SubScreen = GFX.SubScreen_buffer; + GFX.ZBuffer = GFX.ZBuffer_buffer; + GFX.SubZBuffer = GFX.SubZBuffer_buffer; GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1; } diff --git a/shell/scalers/scaler.c b/shell/scalers/scaler.c index 3aeea05..81644aa 100644 --- a/shell/scalers/scaler.c +++ b/shell/scalers/scaler.c @@ -39,7 +39,7 @@ void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* re uint16_t* BlockDst;
for (BlockY = 0; BlockY < height; BlockY++)
{
- BlockSrc = Src16 + BlockY * 512 * 1;
+ BlockSrc = Src16 + BlockY * width * 1;
BlockDst = Dst16 + BlockY * 320 * 1;
for (BlockX = 0; BlockX < 64; BlockX++)
{
@@ -69,15 +69,15 @@ void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* re 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;
+ 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;
+ source = dh * 256 / 2;
for (x = 0; x < 320/10; x++)
{
@@ -91,12 +91,11 @@ void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, 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
+ if(Eh >= midh) {
+ ab = AVERAGE(ab, src[source + 256/2]) & 0xF7DEF7DE; // to prevent overflow
+ cd = AVERAGE(cd, src[source + 256/2 + 1]) & 0xF7DEF7DE; // to prevent overflow
+ ef = AVERAGE(ef, src[source + 256/2 + 2]) & 0xF7DEF7DE; // to prevent overflow
+ gh = AVERAGE(gh, src[source + 256/2 + 3]) & 0xF7DEF7DE; // to prevent overflow
}
*dst++ = ab;
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 index 7dcdce1..fd189cc 100644 --- a/shell/video/retrostone/video_blit.c +++ b/shell/video/retrostone/video_blit.c @@ -78,6 +78,7 @@ void Video_Close() void Update_Video_Menu() { + SDL_SoftStretch(backbuffer, NULL, sdl_screen, NULL); SDL_Flip(sdl_screen); } @@ -92,11 +93,11 @@ void Update_Video_Ingame() switch(option.fullscreen) { case 0: - bitmap_scale(0,0,IPPU.RenderedScreenWidth,IPPU.RenderedScreenHeight,IPPU.RenderedScreenWidth*2,sdl_screen->h, SNES_WIDTH*2, 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); + 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*2, 0, GFX.Screen, sdl_screen->pixels); + bitmap_scale(0, 0, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, sdl_screen->w, sdl_screen->h, SNES_WIDTH, 0, GFX.Screen, sdl_screen->pixels); break; } diff --git a/shell/video/sdl/video_blit.c b/shell/video/sdl/video_blit.c index b4a6bbe..0e489c0 100644 --- a/shell/video/sdl/video_blit.c +++ b/shell/video/sdl/video_blit.c @@ -54,7 +54,7 @@ void Init_Video() SDL_ShowCursor(0); - sdl_screen = SDL_SetVideoMode(0, 0, 16, SDL_HWSURFACE); + sdl_screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE); backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0,0,0,0); @@ -78,12 +78,13 @@ void Video_Close() void Update_Video_Menu() { + SDL_SoftStretch(backbuffer, NULL, sdl_screen, NULL); SDL_Flip(sdl_screen); } void Update_Video_Ingame() { - uint32_t *s, *d; + uint16_t *s, *d; uint32_t h, w; uint8_t PAL = !!(Memory.FillRAM[0x2133] & 4); @@ -92,17 +93,16 @@ void Update_Video_Ingame() 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); - + s = (uint16_t*) GFX.Screen; + d = (uint16_t*) sdl_screen->pixels + ((sdl_screen->w - IPPU.RenderedScreenWidth)/2 + (sdl_screen->h - IPPU.RenderedScreenHeight) * 160) - (PAL ? 0 : 2*320); + for(uint8_t y = 0; y < IPPU.RenderedScreenHeight; y++, s += IPPU.RenderedScreenWidth, d += sdl_screen->w) 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); + upscale_256xXXX_to_320x240((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, IPPU.RenderedScreenWidth, 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); + if (IPPU.RenderedScreenHeight == 240) upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, IPPU.RenderedScreenWidth, 239); + else upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels + (160*8), (uint32_t*) GFX.Screen, IPPU.RenderedScreenWidth, 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); |