Fixes for the (S)VGA common DAC and some card-specific DAT's (ATi 68860, BT48x family, and the Cirrus Logic DAC), fixes Star Control II among other things.

This commit is contained in:
OBattler
2018-10-04 01:19:43 +02:00
parent 6b938d63c3
commit ed92602dad
883 changed files with 444853 additions and 88 deletions

644
src/win/Makefile.mingw$ Normal file
View File

@@ -0,0 +1,644 @@
#
# 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.
#
# Makefile for Win32 (MinGW32) environment.
#
# Version: @(#)Makefile.mingw 1.0.123 2018/08/02
#
# Authors: Miran Grca, <mgrca8@gmail.com>
# Fred N. van Kempen, <decwiz@yahoo.com>
#
# Various compile-time options.
ifndef STUFF
STUFF :=
endif
# Add feature selections here.
ifndef EXTRAS
EXTRAS :=
endif
ifndef DEV_BUILD
DEV_BUILD := n
endif
ifeq ($(DEV_BUILD), y)
ifndef DEBUG
DEBUG := y
endif
ifndef DEV_BRANCH
DEV_BRANCH := y
endif
ifndef AMD_K
AMD_K := y
endif
ifndef CRASHDUMP
CRASHDUMP := y
endif
ifndef D2D
D2D := y
endif
ifndef I686
I686 := y
endif
ifndef LASERXT
LASERXT := y
endif
ifndef MRTHOR
MRTHOR := y
endif
ifndef PAS16
PAS16 := y
endif
ifndef PORTABLE3
PORTABLE3 := y
endif
ifndef STEALTH32
STEALTH32 := y
endif
ifndef VNC
VNC := y
endif
ifndef XL24
XL24 := y
endif
else
ifndef DEBUG
DEBUG := n
endif
ifndef DEV_BRANCH
DEV_BRANCH := n
endif
ifndef AMD_K
AMD_K := n
endif
ifndef CRASHDUMP
CRASHDUMP := n
endif
ifndef D2D
D2D := n
endif
ifndef I686
I686 := n
endif
ifndef LASERXT
LASERXT := n
endif
ifndef MRTHOR
MRTHOR := n
endif
ifndef PAS16
PAS16 := n
endif
ifndef PORTABLE3
PORTABLE3 := n
endif
ifndef STEALTH32
STEALTH32 := n
endif
ifndef VGAWONDER
VGAWONDER := n
endif
ifndef VNC
VNC := n
endif
ifndef XL24
XL24 := n
endif
endif
# Defaults for several build options (possibly defined in a chained file.)
ifndef AUTODEP
AUTODEP := n
endif
ifndef OPTIM
OPTIM := n
endif
ifndef RELEASE
RELEASE := n
endif
ifndef X64
X64 := n
endif
ifndef USB
USB := n
endif
ifndef RDP
RDP := n
endif
ifndef OPENAL
OPENAL := y
endif
ifndef FLUIDSYNTH
FLUIDSYNTH := y
endif
ifndef MUNT
MUNT := y
endif
ifndef DYNAREC
DYNAREC := y
endif
# Name of the executable.
ifndef PROG
PROG := 86Box
endif
#########################################################################
# Nothing should need changing from here on.. #
#########################################################################
VPATH := $(EXPATH) . cpu \
cdrom disk floppy game machine \
sound \
sound/munt sound/munt/c_interface sound/munt/sha1 \
sound/munt/srchelper \
sound/resid-fp \
scsi video network network/slirp win
ifeq ($(X64), y)
CPP := g++ -m64
CC := gcc -m64
else
CPP := g++ -m32
CC := gcc -m32
endif
WINDRES := windres
DEPS = -MMD -MF $*.d -c $<
DEPFILE := win/.depends
# Set up the correct toolchain flags.
OPTS := $(EXTRAS) $(STUFF)
ifdef EXFLAGS
OPTS += $(EXFLAGS)
endif
ifdef EXINC
OPTS += -I$(EXINC)
endif
ifeq ($(X64), y)
ifeq ($(OPTIM), y)
DFLAGS := -march=corei7
else
DFLAGS :=
endif
else
ifeq ($(OPTIM), y)
DFLAGS := -march=corei7
else
DFLAGS := -march=i686
endif
endif
ifeq ($(DEBUG), y)
DFLAGS += -ggdb -DDEBUG
AOPTIM :=
ifndef COPTIM
COPTIM := -Og
endif
else
DFLAGS += -g0
ifeq ($(OPTIM), y)
AOPTIM := -mtune=corei7
ifndef COPTIM
# COPTIM := -O3 -flto
COPTIM := -O3
endif
else
ifndef COPTIM
COPTIM := -O3
endif
endif
endif
AFLAGS := -msse2 -mfpmath=sse
RFLAGS := --input-format=rc -O coff
ifeq ($(RELEASE), y)
OPTS += -DRELEASE_BUILD
RFLAGS += -DRELEASE_BUILD
endif
ifeq ($(VRAMDUMP), y)
OPTS += -DENABLE_VRAM_DUMP
RFLAGS += -DENABLE_VRAM_DUMP
endif
ifeq ($(X64), y)
PLATCG := codegen_x86-64.o
CGOPS := codegen_ops_x86-64.h
VCG := vid_voodoo_codegen_x86-64.h
else
PLATCG := codegen_x86.o
CGOPS := codegen_ops_x86.h
VCG := vid_voodoo_codegen_x86.h
endif
# Optional modules.
ifeq ($(DYNAREC), y)
OPTS += -DUSE_DYNAREC
RFLAGS += -DUSE_DYNAREC
DYNARECOBJ := 386_dynarec_ops.o \
codegen.o \
codegen_ops.o \
codegen_timing_common.o codegen_timing_486.o \
codegen_timing_686.o codegen_timing_pentium.o \
codegen_timing_winchip.o $(PLATCG)
endif
UIOBJ := win_ui.o win_stbar.o \
win_ddraw.o win_d2d.o win_d3d.o win_sdl.o \
win_dialog.o win_about.o \
win_settings.o win_devconf.o win_snd_gain.o \
win_new_floppy.o win_jsconf.o
ifeq ($(OPENAL), y)
OPTS += -DUSE_OPENAL
endif
ifeq ($(FLUIDSYNTH), y)
OPTS += -DUSE_FLUIDSYNTH
FSYNTHOBJ := midi_fluidsynth.o
endif
ifeq ($(MUNT), y)
OPTS += -DUSE_MUNT
MUNTOBJ := midi_mt32.o \
Analog.o BReverbModel.o File.o FileStream.o LA32Ramp.o \
LA32FloatWaveGenerator.o LA32WaveGenerator.o \
MidiStreamParser.o Part.o Partial.o PartialManager.o \
Poly.o ROMInfo.o SampleRateConverter_dummy.o Synth.o \
Tables.o TVA.o TVF.o TVP.o sha1.o c_interface.o
endif
ifeq ($(D2D), y)
OPTS += -DUSE_D2D
RFLAGS += -DUSE_D2D
D2DLIB := -ld2d1
endif
ifeq ($(VNC), y)
OPTS += -DUSE_VNC
RFLAGS += -DUSE_VNC
ifneq ($(VNC_PATH), )
OPTS += -I$(VNC_PATH)\INCLUDE
VNCLIB := -L$(VNC_PATH)\LIB
endif
VNCLIB += -lvncserver
VNCOBJ := vnc.o vnc_keymap.o
endif
ifeq ($(RDP), y)
OPTS += -DUSE_RDP
RFLAGS += -DUSE_RDP
ifneq ($(RDP_PATH), )
OPTS += -I$(RDP_PATH)\INCLUDE
RDPLIB := -L$(RDP_PATH)\LIB
endif
RDPLIB += -lrdp
RDPOBJ := rdp.o
endif
# Options for the DEV branch.
ifeq ($(DEV_BRANCH), y)
OPTS += -DDEV_BRANCH
DEVBROBJ :=
ifeq ($(AMD_K), y)
OPTS += -DUSE_AMD_K
endif
ifeq ($(CRASHDUMPOBJ), y)
OPTS += -DUSE_CRASHDUMP
DEVBROBJ += win_crashdump.o
endif
ifeq ($(I686), y)
OPTS += -DUSE_I686
endif
ifeq ($(LASERXT), y)
OPTS += -DUSE_LASERXT
DEVBROBJ += m_xt_laserxt.o
endif
ifeq ($(MRTHOR), y)
OPTS += -DUSE_MRTHOR
endif
ifeq ($(PAS16), y)
OPTS += -DUSE_PAS16
DEVBROBJ += snd_pas16.o
endif
ifeq ($(PORTABLE3), y)
OPTS += -DUSE_PORTABLE3
endif
ifeq ($(STEALTH32), y)
OPTS += -DUSE_STEALTH32
DEVBROBJ += vid_icd2061.o
endif
ifeq ($(VGAWONDER), y)
OPTS += -DUSE_VGAWONDER
endif
ifeq ($(XL24), y)
OPTS += -DUSE_XL24
endif
endif
# Options for works-in-progress.
ifndef SERIAL
SERIAL := serial.o
endif
# Final versions of the toolchain flags.
CFLAGS := $(OPTS) $(DFLAGS) $(COPTIM) $(AOPTIM) \
$(AFLAGS) -m32 -fomit-frame-pointer -mstackrealign -Wall \
-fno-strict-aliasing
#########################################################################
# Create the (final) list of objects to build. #
#########################################################################
MAINOBJ := pc.o config.o random.o timer.o io.o dma.o nmi.o pic.o \
pit.o ppi.o pci.o mca.o mcr.o mem.o memregs.o rom.o \
device.o nvr.o nvr_at.o nvr_ps2.o $(VNCOBJ) $(RDPOBJ)
INTELOBJ := intel.o \
intel_flash.o \
intel_sio.o intel_piix.o
CPUOBJ := cpu.o cpu_table.o \
808x.o 386.o 386_dynarec.o \
x86seg.o x87.o \
$(DYNARECOBJ)
MCHOBJ := machine.o machine_table.o \
m_xt.o m_xt_compaq.o \
m_xt_t1000.o m_xt_t1000_vid.o \
m_xt_xi8088.o \
m_pcjr.o \
m_amstrad.o \
m_europc.o \
m_olivetti_m24.o m_tandy.o \
m_at.o \
m_at_ali1429.o m_at_commodore.o \
m_at_neat.o m_at_headland.o \
m_at_t3100e.o m_at_t3100e_vid.o \
m_ps1.o m_ps1_hdc.o \
m_ps2_isa.o m_ps2_mca.o \
m_at_opti495.o m_at_scat.o \
m_at_compaq.o m_at_wd76c10.o \
m_at_sis_85c471.o m_at_sis_85c496.o \
m_at_4x0.o
DEVOBJ := bugger.o lpt.o $(SERIAL) \
sio_fdc37c66x.o sio_fdc37c669.o sio_fdc37c93x.o \
sio_pc87306.o sio_w83877f.o sio_um8669f.o \
keyboard.o \
keyboard_xt.o keyboard_at.o \
gameport.o \
joystick_standard.o joystick_ch_flightstick_pro.o \
joystick_sw_pad.o joystick_tm_fcs.o \
mouse.o \
mouse_bus.o \
mouse_serial.o mouse_ps2.o
FDDOBJ := fdd.o fdc.o fdi2raw.o \
fdd_common.o fdd_86f.o \
fdd_fdi.o fdd_imd.o fdd_img.o fdd_json.o \
fdd_td0.o
HDDOBJ := hdd.o \
hdd_image.o hdd_table.o \
hdc.o \
hdc_mfm_xt.o hdc_mfm_at.o \
hdc_xta.o \
hdc_esdi_at.o hdc_esdi_mca.o \
hdc_xtide.o hdc_ide.o
CDROMOBJ := cdrom.o \
cdrom_dosbox.o cdrom_image.o cdrom_null.o
ZIPOBJ := zip.o
ifeq ($(USB), y)
USBOBJ := usb.o
endif
SCSIOBJ := scsi.o \
scsi_bus.o scsi_device.o \
scsi_disk.o \
scsi_x54x.o \
scsi_aha154x.o scsi_buslogic.o \
scsi_ncr5380.o scsi_ncr53c810.o
NETOBJ := network.o \
net_pcap.o \
net_slirp.o \
bootp.o ip_icmp.o misc.o socket.o tcp_timer.o cksum.o \
ip_input.o queue.o tcp_input.o debug.o ip_output.o \
sbuf.o tcp_output.o udp.o if.o mbuf.o slirp.o tcp_subr.o \
net_dp8390.o \
net_3c503.o net_ne2000.o \
net_wd8003.o
SNDOBJ := sound.o \
openal.o \
snd_opl.o snd_dbopl.o \
dbopl.o nukedopl.o \
snd_resid.o \
convolve.o convolve-sse.o envelope.o extfilt.o \
filter.o pot.o sid.o voice.o wave6581__ST.o \
wave6581_P_T.o wave6581_PS_.o wave6581_PST.o \
wave8580__ST.o wave8580_P_T.o wave8580_PS_.o \
wave8580_PST.o wave.o \
midi.o midi_system.o \
snd_speaker.o \
snd_pssj.o \
snd_lpt_dac.o snd_lpt_dss.o \
snd_adlib.o snd_adlibgold.o snd_ad1848.o snd_audiopci.o \
snd_cms.o \
snd_gus.o \
snd_sb.o snd_sb_dsp.o \
snd_emu8k.o snd_mpu401.o \
snd_sn76489.o snd_ssi2001.o \
snd_wss.o \
snd_ym7128.o
VIDOBJ := video.o \
vid_table.o \
vid_cga.o vid_cga_comp.o \
vid_compaq_cga.o \
vid_mda.o \
vid_hercules.o vid_herculesplus.o vid_incolor.o \
vid_colorplus.o \
vid_genius.o \
vid_wy700.o \
vid_ega.o vid_ega_render.o \
vid_svga.o vid_svga_render.o \
vid_vga.o \
vid_ati_eeprom.o \
vid_ati18800.o vid_ati28800.o \
vid_ati_mach64.o vid_ati68860_ramdac.o \
vid_ics2595.o \
vid_cl54xx.o \
vid_et4000.o vid_sc1502x_ramdac.o \
vid_et4000w32.o vid_stg_ramdac.o \
vid_oak_oti.o \
vid_paradise.o \
vid_ti_cf62011.o \
vid_tvga.o \
vid_tgui9440.o vid_tkd8001_ramdac.o \
vid_s3.o vid_s3_virge.o \
vid_sdac_ramdac.o \
vid_voodoo.o
PLATOBJ := win.o \
win_dynld.o win_thread.o \
win_cdrom.o win_keyboard.o \
win_mouse.o win_joystick.o win_midi.o
OBJ := $(MAINOBJ) $(INTELOBJ) $(CPUOBJ) $(MCHOBJ) $(DEVOBJ) \
$(FDDOBJ) $(CDROMOBJ) $(ZIPOBJ) $(HDDOBJ) \
$(USBOBJ) $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) \
$(PLATOBJ) $(UIOBJ) $(FSYNTHOBJ) $(MUNTOBJ) \
$(DEVBROBJ)
ifdef EXOBJ
OBJ += $(EXOBJ)
endif
LIBS := -mwindows \
-lopenal.dll \
-lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 \
-lcomctl32 -lwinmm
ifeq ($(D2D), y)
LIBS += $(D2DLIB)
endif
ifeq ($(VNC), y)
LIBS += $(VNCLIB) -lws2_32
endif
ifeq ($(RDP), y)
LIBS += $(RDPLIB)
endif
LIBS += -lpng -lz -lwsock32 -liphlpapi
LIBS += -static -lstdc++ -lgcc
ifneq ($(X64), y)
LIBS += -Wl,--large-address-aware
endif
# Build module rules.
ifeq ($(AUTODEP), y)
%.o: %.c
@echo $<
@$(CC) $(CFLAGS) $(DEPS) -c $<
%.o: %.cc
@echo $<
@$(CPP) $(CFLAGS) $(DEPS) -c $<
%.o: %.cpp
@echo $<
@$(CPP) $(CFLAGS) $(DEPS) -c $<
else
%.o: %.c
@echo $<
@$(CC) $(CFLAGS) -c $<
%.o: %.cc
@echo $<
@$(CPP) $(CFLAGS) -c $<
%.o: %.cpp
@echo $<
@$(CPP) $(CFLAGS) -c $<
%.d: %.c $(wildcard $*.d)
@echo $<
@$(CC) $(CFLAGS) $(DEPS) -E $< >NUL
%.d: %.cc $(wildcard $*.d)
@echo $<
@$(CPP) $(CFLAGS) $(DEPS) -E $< >NUL
%.d: %.cpp $(wildcard $*.d)
@echo $<
@$(CPP) $(CFLAGS) $(DEPS) -E $< >NUL
endif
all: $(PROG).exe pcap_if.exe
86Box.res: 86Box.rc
@echo Processing $<
@$(WINDRES) $(RFLAGS) $(EXTRAS) -i $< -o 86Box.res
$(PROG).exe: $(OBJ) 86Box.res
@echo Linking $(PROG).exe ..
@$(CC) -m32 -o $(PROG).exe $(OBJ) 86Box.res $(LIBS)
ifneq ($(DEBUG), y)
@strip $(PROG).exe
endif
pcap_if.res: pcap_if.rc
@echo Processing $<
@$(WINDRES) $(RFLAGS) -i $< -o pcap_if.res
pcap_if.exe: pcap_if.o win_dynld.o pcap_if.res
@echo Linking pcap_if.exe ..
@$(CC) -m32 -o pcap_if.exe pcap_if.o win_dynld.o pcap_if.res
ifneq ($(DEBUG), y)
@strip pcap_if.exe
endif
hello.exe: hello.o
$(CXX) $(LDFLAGS) -o hello.exe hello.o $(LIBS)
ifneq ($(DEBUG), y)
@strip hello.exe
endif
clean:
@echo Cleaning objects..
@-rm -f *.o 2>NUL
@-rm -f *.res 2>NUL
clobber: clean
@echo Cleaning executables..
@-rm -f *.d 2>NUL
@-rm -f *.exe 2>NUL
# @-rm -f $(DEPFILE) 2>NUL
ifneq ($(AUTODEP), y)
depclean:
@-rm -f $(DEPFILE) 2>NUL
@echo Creating dependencies..
@echo # Run "make depends" to re-create this file. >$(DEPFILE)
depends: DEPOBJ=$(OBJ:%.o=%.d)
depends: depclean $(OBJ:%.o=%.d)
@-cat $(DEPOBJ) >>$(DEPFILE)
@-rm -f $(DEPOBJ)
$(DEPFILE):
endif
# Module dependencies.
ifeq ($(AUTODEP), y)
#-include $(OBJ:%.o=%.d) (better, but sloooowwwww)
-include *.d
else
include $(wildcard $(DEPFILE))
endif
# End of Makefile.mingw.

80
src/win/startblit.fnd Normal file
View File

@@ -0,0 +1,80 @@
---------- 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();

448
src/win/win_sdl.c.bak Normal file
View File

@@ -0,0 +1,448 @@
/*
* 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);
}