/* espec - Sinclair Spectrum emulator Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk) 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 ------------------------------------------------------------------------- Wrapper to SDL */ #include #include #include #include #include "gfx.h" #include "exit.h" #include "config.h" #include "util.h" #include "font.h" /* ---------------------------------------- MACROS */ #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif /* ---------------------------------------- STATICS */ static SDL_Window *window; static SDL_Renderer *renderer; static SDL_Texture *texture; static Uint32 *pixels; static Uint32 ticks; static Uint32 frame; static int scale; static void (*putpixel)(int x, int y, Uint32 col); #define NO_BMPIX 10 static struct { Uint32 col; int r,g,b; } bmpix[NO_BMPIX]= { {0, 0x00,0x00,0x00}, /* BLACK */ {0, 0x00,0x00,0xff}, /* BLUE */ {0, 0xff,0x00,0x00}, /* RED */ {0, 0xff,0x00,0xff}, /* MAGENTA */ {0, 0x00,0xff,0x00}, /* GREEN */ {0, 0x00,0xff,0xff}, /* CYAN */ {0, 0xff,0xff,0x00}, /* YELLOW */ {0, 0xff,0xff,0xff}, /* WHITE */ {0, 0x60,0x60,0x60}, /* GREY */ }; /* ---------------------------------------- PRIVATE FUNCTIONS */ static void normal_putpixel(int x, int y, Uint32 pixel) { pixels[x + y * GFX_WIDTH] = pixel; } static void scale_putpixel(int x, int y, Uint32 pixel) { int sx,sy; x*=scale; y*=scale; for(sx=0;sx1) putpixel=scale_putpixel; else putpixel=normal_putpixel; frame=1000/IConfig(CONF_FRAMES_PER_SEC); if (IConfig(CONF_SOUND)) { if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_AUDIO)) Exit("Failed to init SDL: %s\n",SDL_GetError()); } else { if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO)) Exit("Failed to init SDL: %s\n",SDL_GetError()); } if (!(window=SDL_CreateWindow("eSPEC", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, GFX_WIDTH*scale, GFX_HEIGHT*scale, IConfig(CONF_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN : 0))) { Exit("Failed to open window: %s\n",SDL_GetError()); } if (!(renderer = SDL_CreateRenderer(window, -1, 0))) { Exit("Failed to create renderer: %s\n",SDL_GetError()); } if (!(texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, GFX_WIDTH*scale, GFX_HEIGHT*scale))) { Exit("Failed to create texture: %s\n",SDL_GetError()); } pixels = Malloc(sizeof(Uint32) * GFX_WIDTH*scale * GFX_HEIGHT*scale); SDL_ShowCursor(SDL_DISABLE); for(f=0;f=h) break; } else { int f; for (f=0;f=h) break; } } } /* END OF FILE */