diff options
author | gameblabla | 2019-10-05 03:04:57 +0200 |
---|---|---|
committer | gameblabla | 2019-10-05 03:04:57 +0200 |
commit | d4753076e89d42cdad4a4f1ca4688fad3c56d873 (patch) | |
tree | c8641cf282f427d9329db00325e16609acca8663 /shell/video | |
parent | 943821f94b9b2e22315fce876c2e369da7a79bcf (diff) | |
download | snesemu-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/video')
-rw-r--r-- | shell/video/retrostone/video_blit.c | 155 | ||||
-rw-r--r-- | shell/video/retrostone/video_blit.h | 24 | ||||
-rw-r--r-- | shell/video/sdl/video_blit.c | 132 | ||||
-rw-r--r-- | shell/video/sdl/video_blit.h | 24 |
4 files changed, 335 insertions, 0 deletions
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 |