And two more in win/.
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
|
||||
---------- 86BOX.MANIFEST
|
||||
|
||||
---------- 86BOX.RC
|
||||
|
||||
---------- MAKEFILE.MINGW
|
||||
|
||||
---------- PCAP_IF.RC
|
||||
|
||||
---------- PLAT_DIR.H
|
||||
|
||||
---------- RESOURCE.H
|
||||
|
||||
---------- STARTBLIT.FND
|
||||
|
||||
---------- WIN.C
|
||||
startblit();
|
||||
startblit();
|
||||
startblit();
|
||||
startblit(void)
|
||||
|
||||
---------- WIN.H
|
||||
|
||||
---------- WIN_ABOUT.C
|
||||
|
||||
---------- WIN_CDROM.C
|
||||
|
||||
---------- WIN_CRASHDUMP.C
|
||||
|
||||
---------- WIN_D2D.CPP
|
||||
|
||||
---------- WIN_D2D.H
|
||||
|
||||
---------- WIN_D3D.CPP
|
||||
|
||||
---------- WIN_D3D.H
|
||||
|
||||
---------- WIN_DDRAW.CPP
|
||||
|
||||
---------- WIN_DDRAW.H
|
||||
|
||||
---------- WIN_DEVCONF.C
|
||||
|
||||
---------- WIN_DIALOG.C
|
||||
|
||||
---------- WIN_DYNLD.C
|
||||
|
||||
---------- WIN_JOYSTICK.CPP
|
||||
|
||||
---------- WIN_JSCONF.C
|
||||
|
||||
---------- WIN_KEYBOARD.C
|
||||
|
||||
---------- WIN_MIDI.C
|
||||
|
||||
---------- WIN_MOUSE.CPP
|
||||
|
||||
---------- WIN_NEW_FLOPPY.C
|
||||
|
||||
---------- WIN_OPENDIR.C
|
||||
|
||||
---------- WIN_SDL.C
|
||||
|
||||
---------- WIN_SDL.C.BAK
|
||||
|
||||
---------- WIN_SDL.H
|
||||
|
||||
---------- WIN_SERIAL.C
|
||||
|
||||
---------- WIN_SETTINGS.C
|
||||
|
||||
---------- WIN_SND_GAIN.C
|
||||
|
||||
---------- WIN_STBAR.C
|
||||
|
||||
---------- WIN_THREAD.C
|
||||
|
||||
---------- WIN_UI.C
|
||||
startblit();
|
||||
startblit();
|
@@ -1,448 +0,0 @@
|
||||
/*
|
||||
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||
* running old operating systems and software designed for IBM
|
||||
* PC systems and compatibles from 1981 through fairly recent
|
||||
* system designs based on the PCI bus.
|
||||
*
|
||||
* This file is part of the 86Box distribution.
|
||||
*
|
||||
* Rendering module for libSDL2
|
||||
*
|
||||
* NOTE: Given all the problems reported with FULLSCREEN use of SDL,
|
||||
* we will not use that, but, instead, use a new window which
|
||||
* coverrs the entire desktop.
|
||||
*
|
||||
* Version: @(#)win_sdl.c 1.0.0 2018/05/26
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Michael Dr<44>ing, <michael@drueing.de>
|
||||
*
|
||||
* Copyright 2018 Fred N. van Kempen.
|
||||
* Copyright 2018 Michael Dr<44>ing.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with
|
||||
* or without modification, are permitted provided that the
|
||||
* following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the entire
|
||||
* above notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names
|
||||
* of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#define UNICODE
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "../86box.h"
|
||||
#include "../device.h"
|
||||
#include "../plat.h"
|
||||
#include "../plat_dynld.h"
|
||||
#include "../video/video.h"
|
||||
#include "win.h"
|
||||
#include "win_sdl.h"
|
||||
|
||||
|
||||
#define PATH_SDL_DLL "sdl2.dll"
|
||||
|
||||
|
||||
static void *sdl_handle = NULL; /* handle to libSDL2 DLL */
|
||||
static void *sdl_win = NULL;
|
||||
static void *sdl_render = NULL;
|
||||
static void *sdl_tex = NULL;
|
||||
static HWND sdl_hwnd = NULL;
|
||||
static int sdl_w, sdl_h;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int16_t x, y;
|
||||
uint16_t w, h;
|
||||
} SDL_Rect;
|
||||
|
||||
typedef struct SDL_version {
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t patch;
|
||||
} SDL_version;
|
||||
|
||||
#define SDL_INIT_VIDEO 0x00000020
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
|
||||
SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
|
||||
acceleration */
|
||||
SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized
|
||||
with the refresh rate */
|
||||
SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports
|
||||
rendering to texture */
|
||||
} SDL_RendererFlags;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
|
||||
SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
|
||||
} SDL_TextureAccess;
|
||||
|
||||
/** Pixel type. */
|
||||
enum
|
||||
{
|
||||
SDL_PIXELTYPE_UNKNOWN,
|
||||
SDL_PIXELTYPE_INDEX1,
|
||||
SDL_PIXELTYPE_INDEX4,
|
||||
SDL_PIXELTYPE_INDEX8,
|
||||
SDL_PIXELTYPE_PACKED8,
|
||||
SDL_PIXELTYPE_PACKED16,
|
||||
SDL_PIXELTYPE_PACKED32,
|
||||
SDL_PIXELTYPE_ARRAYU8,
|
||||
SDL_PIXELTYPE_ARRAYU16,
|
||||
SDL_PIXELTYPE_ARRAYU32,
|
||||
SDL_PIXELTYPE_ARRAYF16,
|
||||
SDL_PIXELTYPE_ARRAYF32
|
||||
};
|
||||
|
||||
/** Bitmap pixel order, high bit -> low bit. */
|
||||
enum
|
||||
{
|
||||
SDL_BITMAPORDER_NONE,
|
||||
SDL_BITMAPORDER_4321,
|
||||
SDL_BITMAPORDER_1234
|
||||
};
|
||||
|
||||
/** Packed component order, high bit -> low bit. */
|
||||
enum
|
||||
{
|
||||
SDL_PACKEDORDER_NONE,
|
||||
SDL_PACKEDORDER_XRGB,
|
||||
SDL_PACKEDORDER_RGBX,
|
||||
SDL_PACKEDORDER_ARGB,
|
||||
SDL_PACKEDORDER_RGBA,
|
||||
SDL_PACKEDORDER_XBGR,
|
||||
SDL_PACKEDORDER_BGRX,
|
||||
SDL_PACKEDORDER_ABGR,
|
||||
SDL_PACKEDORDER_BGRA
|
||||
};
|
||||
|
||||
/** Array component order, low byte -> high byte. */
|
||||
/* !!! FIXME: in 2.1, make these not overlap differently with
|
||||
!!! FIXME: SDL_PACKEDORDER_*, so we can simplify SDL_ISPIXELFORMAT_ALPHA */
|
||||
enum
|
||||
{
|
||||
SDL_ARRAYORDER_NONE,
|
||||
SDL_ARRAYORDER_RGB,
|
||||
SDL_ARRAYORDER_RGBA,
|
||||
SDL_ARRAYORDER_ARGB,
|
||||
SDL_ARRAYORDER_BGR,
|
||||
SDL_ARRAYORDER_BGRA,
|
||||
SDL_ARRAYORDER_ABGR
|
||||
};
|
||||
|
||||
/** Packed component layout. */
|
||||
enum
|
||||
{
|
||||
SDL_PACKEDLAYOUT_NONE,
|
||||
SDL_PACKEDLAYOUT_332,
|
||||
SDL_PACKEDLAYOUT_4444,
|
||||
SDL_PACKEDLAYOUT_1555,
|
||||
SDL_PACKEDLAYOUT_5551,
|
||||
SDL_PACKEDLAYOUT_565,
|
||||
SDL_PACKEDLAYOUT_8888,
|
||||
SDL_PACKEDLAYOUT_2101010,
|
||||
SDL_PACKEDLAYOUT_1010102
|
||||
};
|
||||
|
||||
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
|
||||
((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
|
||||
((bits) << 8) | ((bytes) << 0))
|
||||
|
||||
#define SDL_PIXELFORMAT_ARGB8888 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_8888, 32, 4)
|
||||
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
static void (*sdl_GetVersion)(void *ver);
|
||||
static char *const (*sdl_GetError)(void);
|
||||
static int (*sdl_Init)(uint32_t flags);
|
||||
static void (*sdl_Quit)(void);
|
||||
static void *(*sdl_CreateWindowFrom)(const void *data);
|
||||
static void (*sdl_DestroyWindow)(void *window);
|
||||
static void *(*sdl_CreateRenderer)(void *window,
|
||||
int index, uint32_t flags);
|
||||
static void (*sdl_DestroyRenderer)(void *renderer);
|
||||
static void *(*sdl_CreateTexture)(void *renderer,
|
||||
uint32_t format, int access,
|
||||
int w, int h);
|
||||
static void (*sdl_DestroyTexture)(void *texture);
|
||||
static int (*sdl_LockTexture)(void *texture,
|
||||
const SDL_Rect *rect,
|
||||
void **pixels, int *pitch);
|
||||
static void (*sdl_UnlockTexture)(void *texture);
|
||||
static int (*sdl_RenderCopy)(void *renderer,
|
||||
void *texture,
|
||||
const SDL_Rect *srcrect,
|
||||
const SDL_Rect *dstrect);
|
||||
static void (*sdl_RenderPresent)(void *renderer);
|
||||
|
||||
|
||||
static dllimp_t sdl_imports[] = {
|
||||
{ "SDL_GetVersion", &sdl_GetVersion },
|
||||
{ "SDL_GetError", &sdl_GetError },
|
||||
{ "SDL_Init", &sdl_Init },
|
||||
{ "SDL_Quit", &sdl_Quit },
|
||||
{ "SDL_CreateWindowFrom", &sdl_CreateWindowFrom },
|
||||
{ "SDL_DestroyWindow", &sdl_DestroyWindow },
|
||||
{ "SDL_CreateRenderer", &sdl_CreateRenderer },
|
||||
{ "SDL_DestroyRenderer", &sdl_DestroyRenderer },
|
||||
{ "SDL_CreateTexture", &sdl_CreateTexture },
|
||||
{ "SDL_DestroyTexture", &sdl_DestroyTexture },
|
||||
{ "SDL_LockTexture", &sdl_LockTexture },
|
||||
{ "SDL_UnlockTexture", &sdl_UnlockTexture },
|
||||
{ "SDL_RenderCopy", &sdl_RenderCopy },
|
||||
{ "SDL_RenderPresent", &sdl_RenderPresent },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
sdl_blit(int x, int y, int y1, int y2, int w, int h)
|
||||
{
|
||||
SDL_Rect r_src;
|
||||
void *pixeldata;
|
||||
int pitch;
|
||||
int yy;
|
||||
|
||||
if (buffer32 == NULL) {
|
||||
video_blit_complete();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* SDL_UpdateTexture() might be better here, as it is
|
||||
* (reportedly) slightly faster.
|
||||
*/
|
||||
sdl_LockTexture(sdl_tex, 0, &pixeldata, &pitch);
|
||||
|
||||
for (yy = y1; yy < y2; yy++) {
|
||||
if ((y + yy) >= 0 && (y + yy) < buffer32->h)
|
||||
memset((uint32_t *) &(((uint8_t *)pixeldata)[yy * pitch]), 0xff, w * 4);
|
||||
// memcpy((uint32_t *) &(((uint8_t *)pixeldata)[yy * pitch]), &(((uint32_t *)buffer32->line[y + yy])[x]), w * 4);
|
||||
}
|
||||
|
||||
video_blit_complete();
|
||||
|
||||
sdl_UnlockTexture(sdl_tex);
|
||||
|
||||
r_src.x = 0;
|
||||
r_src.y = 0;
|
||||
r_src.w = w;
|
||||
r_src.h = h;
|
||||
|
||||
sdl_RenderCopy(sdl_render, sdl_tex, &r_src, 0);
|
||||
|
||||
sdl_RenderPresent(sdl_render);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sdl_close(void)
|
||||
{
|
||||
/* Unregister our renderer! */
|
||||
video_setblit(NULL);
|
||||
|
||||
if (sdl_tex != NULL) {
|
||||
sdl_DestroyTexture(sdl_tex);
|
||||
sdl_tex = NULL;
|
||||
}
|
||||
|
||||
if (sdl_render != NULL) {
|
||||
sdl_DestroyRenderer(sdl_render);
|
||||
sdl_render = NULL;
|
||||
}
|
||||
|
||||
if (sdl_win != NULL) {
|
||||
sdl_DestroyWindow(sdl_win);
|
||||
sdl_win = NULL;
|
||||
}
|
||||
|
||||
if (sdl_hwnd != NULL) {
|
||||
plat_set_input(hwndMain);
|
||||
|
||||
DestroyWindow(sdl_hwnd);
|
||||
sdl_hwnd = NULL;
|
||||
|
||||
SetFocus(hwndMain);
|
||||
}
|
||||
|
||||
/* Quit and unload the DLL if possible. */
|
||||
if (sdl_handle != NULL) {
|
||||
sdl_Quit();
|
||||
|
||||
dynld_close(sdl_handle);
|
||||
sdl_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
sdl_init_common(int fs)
|
||||
{
|
||||
wchar_t temp[128];
|
||||
SDL_version ver;
|
||||
|
||||
pclog("SDL: init (fs=%d)\n", fs);
|
||||
|
||||
cgapal_rebuild();
|
||||
|
||||
/* Try loading the DLL. */
|
||||
sdl_handle = dynld_module(PATH_SDL_DLL, sdl_imports);
|
||||
if (sdl_handle == NULL) {
|
||||
pclog("SDL: unable to load '%s', SDL not available.\n", PATH_SDL_DLL);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Get and log the version of the DLL we are using. */
|
||||
sdl_GetVersion(&ver);
|
||||
pclog("SDL: version %d.%d.%d\n", ver.major, ver.minor, ver.patch);
|
||||
|
||||
/* Initialize the SDL system. */
|
||||
if (sdl_Init(SDL_INIT_VIDEO) < 0) {
|
||||
pclog("SDL: initialization failed (%s)\n", sdl_GetError());
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (fs) {
|
||||
/* Get the size of the (current) desktop. */
|
||||
sdl_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
sdl_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
/* Create the desktop-covering window. */
|
||||
_swprintf(temp, L"%s v%s", EMU_NAME_W, EMU_VERSION_W);
|
||||
sdl_hwnd = CreateWindowEx(
|
||||
0,
|
||||
SUB_CLASS_NAME,
|
||||
temp,
|
||||
WS_POPUP,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
640,
|
||||
480,
|
||||
HWND_DESKTOP,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
pclog("SDL: FS %dx%d window at %08lx\n", sdl_w, sdl_h, sdl_hwnd);
|
||||
|
||||
/* Redirect RawInput to this new window. */
|
||||
plat_set_input(sdl_hwnd);
|
||||
|
||||
/* Show the window, make it topmost, and give it focus. */
|
||||
SetWindowPos(sdl_hwnd, HWND_TOPMOST,
|
||||
0, 0, sdl_w, sdl_h, SWP_SHOWWINDOW);
|
||||
|
||||
/* Now create the SDL window from that. */
|
||||
sdl_win = sdl_CreateWindowFrom((void *)sdl_hwnd);
|
||||
} else {
|
||||
/* Redirect RawInput to this new window. */
|
||||
plat_set_input(hwndMain);
|
||||
|
||||
// ShowWindow(hwndRender, TRUE);
|
||||
ShowWindow(hwndRender, SW_SHOW);
|
||||
|
||||
SetFocus(hwndMain);
|
||||
|
||||
/* Create the SDL window from the render window. */
|
||||
sdl_win = sdl_CreateWindowFrom((void *)hwndRender);
|
||||
}
|
||||
if (sdl_win == NULL) {
|
||||
pclog("SDL: unable to CreateWindowFrom (%s)\n", sdl_GetError());
|
||||
sdl_close();
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* SDL_RENDERER_SOFTWARE, because SDL tries to do funky stuff
|
||||
* otherwise (it turns off Win7 Aero and it looks like it's
|
||||
* trying to switch to fullscreen even though the window is
|
||||
* not a fullscreen window?)
|
||||
*/
|
||||
// sdl_render = sdl_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE);
|
||||
sdl_render = sdl_CreateRenderer(sdl_win, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (sdl_render == NULL) {
|
||||
pclog("SDL: unable to create renderer (%s)\n", sdl_GetError());
|
||||
sdl_close();
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* Actually the source is (apparently) XRGB8888, but the alpha
|
||||
* channel seems to be set to 255 everywhere, so ARGB8888 works
|
||||
* just as well.
|
||||
*/
|
||||
sdl_tex = sdl_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING, 2048, 2048);
|
||||
if (sdl_tex == NULL) {
|
||||
pclog("SDL: unable to create texture (%s)\n", sdl_GetError());
|
||||
sdl_close();
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* Make sure we get a clean exit. */
|
||||
atexit(sdl_close);
|
||||
|
||||
/* Register our renderer! */
|
||||
video_setblit(sdl_blit);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sdl_init(HWND h)
|
||||
{
|
||||
return sdl_init_common(0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sdl_init_fs(HWND h)
|
||||
{
|
||||
return sdl_init_common(1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sdl_take_screenshot(const wchar_t *fn)
|
||||
{
|
||||
/* TODO: implement */
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sdl_pause(void)
|
||||
{
|
||||
return(0);
|
||||
}
|
Reference in New Issue
Block a user