Previous 199869 Revisions Next

r34887 Friday 6th February, 2015 at 09:13:57 UTC by David Haywood
added build date information to the Gun Smoke sets, based on strings in ROM (nw)
[src/build]flags_clang.mak
[src/lib/formats]kaypro_dsk.c kaypro_dsk.h
[src/mame]mame.lst
[src/mame/drivers]gunsmoke.c peplus.c silvmil.c
[src/mame/video]jagblit.inc
[src/mess/drivers]kaypro.c pc9801.c
[src/mess/includes]kaypro.h
[src/mess/machine]kaypro.c
[src/osd/sdl]draw13.c drawbgfx.c drawogl.c drawsdl.c window.c window.h
[src/osd/windows]d3dhlsl.c drawbgfx.c drawd3d.c drawd3d.h drawdd.c drawgdi.c drawnone.c window.c window.h

trunk/src/build/flags_clang.mak
r243398r243399
55# caused by obj/sdl64d/emu/cpu/tms57002/tms57002.inc
66CCOMFLAGS += -Wno-self-assign-field
77
8# caused by src/mame/video/jagblit.inc on older clang versions
9#CCOMFLAGS += -Wno-constant-logical-operand
10
811# caused by popmessage(NULL) on older clang versions
912#CCOMFLAGS += -Wno-format-security
1013
r243398r243399
2932
3033ifeq ($(findstring 3.4,$(TEST_CLANG)),3.4)
3134CCOMFLAGS += -Wno-inline-new-delete
32
33# caused by src/mame/video/jagblit.inc
34CCOMFLAGS += -Wno-constant-logical-operand
3535endif
3636
3737ifeq ($(findstring 3.5,$(TEST_CLANG)),3.5)
trunk/src/lib/formats/kaypro_dsk.c
r243398r243399
11// license:BSD-3-Clause
2// copyright-holders:Olivier Galibert, Robbbert
2// copyright-holders:Olivier Galibert
33/*********************************************************************
44
55    formats/kaypro_dsk.c
r243398r243399
99    There is no inter-sector info on these disks. It is simply a
1010    dump of the 512 bytes from each sector and track in order.
1111    It is just like a headerless quickload.
12    Base class and gaps verified by OG. Please note that these
13    disks usually have DSK extension, but that conflicts with
14    the CPCEMU DSK format. You need to rename your Kaypro DSK
15    disks to KAY extension.
1612
1713*********************************************************************/
1814
1915#include "emu.h"
2016#include "formats/kaypro_dsk.h"
2117
22kayproii_format::kayproii_format() : upd765_format(formats)
18kayproii_format::kayproii_format() : wd177x_format(formats)
2319{
2420}
2521
r243398r243399
3531
3632const char *kayproii_format::extensions() const
3733{
38   return "kay";
34   return "dsk";
3935}
4036
37// gap info is a total guess
4138const kayproii_format::format kayproii_format::formats[] = {
4239   {   /*  191K 13cm double density single sided */
4340      floppy_image::FF_525,  floppy_image::SSDD, floppy_image::MFM,
44      2000, 10, 40, 1, 512, {}, 0, {}, 80, 16, 22, 26
41      2000, 10, 40, 1, 512, {}, 1, {}, 32, 22, 31
4542   },
4643   {}
4744};
4845
49kaypro2x_format::kaypro2x_format() : upd765_format(formats)
46kaypro2x_format::kaypro2x_format() : wd177x_format(formats)
5047{
5148}
5249
r243398r243399
6259
6360const char *kaypro2x_format::extensions() const
6461{
65   return "kay";
62   return "dsk";
6663}
6764
65// gap info is a total guess
6866const kaypro2x_format::format kaypro2x_format::formats[] = {
6967   {   /*  382K 13cm double density double sided */
7068      floppy_image::FF_525,  floppy_image::DSDD, floppy_image::MFM,
71      2000, 10, 40, 2, 512, {}, 0, {}, 80, 16, 22, 26
69      2000, 10, 80, 2, 512, {}, 1, {}, 32, 22, 31
7270   },
7371   {}
7472};
trunk/src/lib/formats/kaypro_dsk.h
r243398r243399
99#ifndef KAYPRO_DSK_H_
1010#define KAYPRO_DSK_H_
1111
12#include "upd765_dsk.h"
12#include "wd177x_dsk.h"
1313
14class kayproii_format : public upd765_format {
14class kayproii_format : public wd177x_format {
1515public:
1616   kayproii_format();
1717
r243398r243399
2323   static const format formats[];
2424};
2525
26class kaypro2x_format : public upd765_format {
26class kaypro2x_format : public wd177x_format {
2727public:
2828   kaypro2x_format();
2929
trunk/src/mame/drivers/gunsmoke.c
r243398r243399
578578
579579/* Game Drivers */
580580
581GAME( 1985, gunsmoke,   0,        gunsmoke, gunsmoke,   driver_device, 0, ROT270, "Capcom", "Gun.Smoke (World)", GAME_SUPPORTS_SAVE )
582GAME( 1985, gunsmokeb,  gunsmoke, gunsmoke, gunsmoke,   driver_device, 0, ROT270, "bootleg", "Gun.Smoke (bootleg)", GAME_SUPPORTS_SAVE ) // based on world version, warning message patched out
583GAME( 1985, gunsmokej,  gunsmoke, gunsmoke, gunsmoke,   driver_device, 0, ROT270, "Capcom", "Gun.Smoke (Japan)", GAME_SUPPORTS_SAVE )
584GAME( 1985, gunsmokeu,  gunsmoke, gunsmoke, gunsmoke,   driver_device, 0, ROT270, "Capcom (Romstar license)", "Gun.Smoke (US set 1)", GAME_SUPPORTS_SAVE )
585GAME( 1986, gunsmokeua, gunsmoke, gunsmoke, gunsmokeua, driver_device, 0, ROT270, "Capcom (Romstar license)", "Gun.Smoke (US set 2)", GAME_SUPPORTS_SAVE )
581// at 0x7E50 in the first rom is 85113 (project ident code?) and the project codename 'Gunman' both stored as ASCII.
582// Following that at (stored as raw data) is the build date in yyyymmdd format.  After that a ROM identification string(?) which I've
583// left in the comment after each set.
584
585// this information is not displayed onscreen
586
587GAME( 1985, gunsmoke,   0,        gunsmoke, gunsmoke,   driver_device, 0, ROT270, "Capcom",                   "Gun.Smoke (World, 851115)", GAME_SUPPORTS_SAVE ) // GSE_03
588GAME( 1985, gunsmokeb,  gunsmoke, gunsmoke, gunsmoke,   driver_device, 0, ROT270, "bootleg",                  "Gun.Smoke (World, 851115) (bootleg)", GAME_SUPPORTS_SAVE ) // based  on above version, warning message patched out
589GAME( 1985, gunsmokej,  gunsmoke, gunsmoke, gunsmoke,   driver_device, 0, ROT270, "Capcom",                   "Gun.Smoke (Japan, 851115)", GAME_SUPPORTS_SAVE ) // GSJ_03
590GAME( 1985, gunsmokeu,  gunsmoke, gunsmoke, gunsmoke,   driver_device, 0, ROT270, "Capcom (Romstar license)", "Gun.Smoke (US, 851115)", GAME_SUPPORTS_SAVE ) // GSR_03
591GAME( 1986, gunsmokeua, gunsmoke, gunsmoke, gunsmokeua, driver_device, 0, ROT270, "Capcom (Romstar license)", "Gun.Smoke (US, 860408)", GAME_SUPPORTS_SAVE ) // GSA_03
trunk/src/mame/drivers/peplus.c
r243398r243399
50145014   ROM_LOAD( "cap1004.u50", 0x0000, 0x0100, CRC(5eced808) SHA1(b40b8efa8cbc76cff7560c36939275eb360c6f11) )
50155015ROM_END
50165016
5017ROM_START( peps0090 ) /* Normal board : Gold, Silver & Bronze (PS0090) - Payout 90.19% */
5018   ROM_REGION( 0x10000, "maincpu", 0 )
5019   ROM_LOAD( "ps0090_569-a2c.u68",   0x00000, 0x10000, CRC(5a727ff0) SHA1(6eed9d85620eff751c598d56807470f8753e8dd5) ) /* 3 Coins Max / 1 Line */
5020   
5021   ROM_REGION( 0x020000, "gfx1", 0 )
5022   ROM_LOAD( "mro-cg1059.u72",   0x00000, 0x8000, CRC(96210de3) SHA1(10daa358f1fc507e9f4c788265c0acc57678fa40) ) /* Also contains graphics for Double Diamonds, use CAP1003 */
5023   ROM_LOAD( "mgo-cg1059.u73",   0x08000, 0x8000, CRC(cfb9a357) SHA1(a390bed240960efd8da6e7815a0b0d272133f20f) )
5024   ROM_LOAD( "mbo-cg1059.u74",   0x10000, 0x8000, CRC(6c159972) SHA1(b6fbebba2749534b7fcb9cd32fe17cdc673912f7) )
5025   ROM_LOAD( "mxo-cg1059.u75",   0x18000, 0x8000, CRC(7ec9d699) SHA1(45ec30370d2ef12511f897cb1155327ed4d2ce01) )
5026
5027   ROM_REGION( 0x100, "proms", 0 )
5028   ROM_LOAD( "cap1059.u50", 0x0000, 0x0100, CRC(a995258f) SHA1(5c33fb2a9a939cfdf4634f886690fa7ccc57fe52) )
5029ROM_END
5030
50315017ROM_START( peps0092 ) /* Normal board : Wild Cherry Slots (PS0092) - Payout 90.18% */
50325018   ROM_REGION( 0x10000, "maincpu", 0 )
50335019   ROM_LOAD( "ps0092_569-a2c.u68",   0x00000, 0x10000, CRC(d533f6d5) SHA1(9c470f7c474022445aeb45ee8c5757d1b6957a91) ) /* 3 Coins Max / 1 Line */
r243398r243399
92979283GAMEL(1996, peps0043, peps0042, peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0043) Double Diamond Slots",          0, layout_pe_slots )
92989284GAMEL(1996, peps0045, peps0021, peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0045) Red White & Blue Slots",        0, layout_pe_slots )
92999285GAMEL(1996, peps0047, 0,        peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0047) Wild Cherry Slots",             GAME_NOT_WORKING, layout_pe_slots ) /* Needs MxO-CG1004.Uxx graphics roms redumped */
9300GAMEL(1996, peps0090, 0,        peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0090) Gold, Silver & Bronze Slots",   0, layout_pe_slots )
93019286GAMEL(1996, peps0092, peps0047, peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0092) Wild Cherry Slots",             GAME_NOT_WORKING, layout_pe_slots ) /* Needs MxO-CG1004.Uxx graphics roms redumped */
93029287GAMEL(1996, peps0206, peps0021, peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0206) Red White & Blue Slots",        0, layout_pe_slots )
93039288GAMEL(1996, peps0207, peps0021, peplus, peplus_slots,   peplus_state, peplus,   ROT0,  "IGT - International Game Technology", "Player's Edge Plus (PS0207) Red White & Blue Slots",        0, layout_pe_slots )
trunk/src/mame/drivers/silvmil.c
r243398r243399
287287   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_COIN2 )
288288   PORT_BIT( 0xfc00, IP_ACTIVE_LOW, IPT_UNKNOWN )
289289
290   PORT_START("DSW") /* NOTE: In the service mode, the game reports the dipswitch banks in reverse. IE: SW1 is actually SW2 & SW2 is actually SW1 */
291   PORT_DIPUNUSED_DIPLOC( 0x0001, 0x0001, "SW1:1" ) /* Listed as "Unused" */
292   PORT_DIPUNUSED_DIPLOC( 0x0002, 0x0002, "SW1:2" ) /* Listed as "Unused" */
293   PORT_DIPUNUSED_DIPLOC( 0x0004, 0x0004, "SW1:3" ) /* Listed as "Unused" */
294   PORT_DIPUNUSED_DIPLOC( 0x0008, 0x0008, "SW1:4" ) /* Listed as "Unused" */
295   PORT_DIPUNUSED_DIPLOC( 0x0010, 0x0010, "SW1:5" ) /* Listed as "Unused" */
296   PORT_DIPUNUSED_DIPLOC( 0x0020, 0x0020, "SW1:6" ) /* Listed as "Unused" */
297   PORT_DIPUNUSED_DIPLOC( 0x0040, 0x0040, "SW1:7" ) /* Listed as "Unused" */
298   PORT_DIPUNUSED_DIPLOC( 0x0080, 0x0080, "SW1:8" ) /* Listed as "Unused" */
299   PORT_DIPNAME( 0x0300, 0x0100, DEF_STR( Difficulty ) )   PORT_DIPLOCATION("SW2:1,2")
300   PORT_DIPSETTING(      0x0300, DEF_STR( Very_Easy ) )       /* Initial start time 40 secs */
301   PORT_DIPSETTING(      0x0200, DEF_STR( Easy ) )            /* Initial start time 30 secs - Other in game effects?? */
302   PORT_DIPSETTING(      0x0100, DEF_STR( Hard ) )            /* Initial start time 30 secs - Other in game effects?? */
303   PORT_DIPSETTING(      0x0000, DEF_STR( Very_Hard ) )       /* Initial start time 30 secs - Other in game effects?? */
304   PORT_DIPNAME( 0x1c00, 0x1c00, DEF_STR( Coinage ) )   PORT_DIPLOCATION("SW2:3,4,5")
290   PORT_START("DSW")
291   PORT_DIPNAME( 0x0001, 0x0001, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:1")
292   PORT_DIPSETTING(      0x0001, DEF_STR( Off ) )
293   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
294   PORT_DIPNAME( 0x0002, 0x0002, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:2")
295   PORT_DIPSETTING(      0x0002, DEF_STR( Off ) )
296   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
297   PORT_DIPNAME( 0x0004, 0x0004, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:3")
298   PORT_DIPSETTING(      0x0004, DEF_STR( Off ) )
299   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
300   PORT_DIPNAME( 0x0008, 0x0008, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:4")
301   PORT_DIPSETTING(      0x0008, DEF_STR( Off ) )
302   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
303   PORT_DIPNAME( 0x0010, 0x0010, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:5")
304   PORT_DIPSETTING(      0x0010, DEF_STR( Off ) )
305   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
306   PORT_DIPNAME( 0x0020, 0x0020, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:6")
307   PORT_DIPSETTING(      0x0020, DEF_STR( Off ) )
308   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
309   PORT_DIPNAME( 0x0040, 0x0040, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:7")
310   PORT_DIPSETTING(      0x0040, DEF_STR( Off ) )
311   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
312   PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Unknown ) )      PORT_DIPLOCATION("SW2:8")
313   PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
314   PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
315   PORT_DIPNAME( 0x0300, 0x0300, "Game Level" )      PORT_DIPLOCATION("SW1:1,2") /* Difficulty?? - Not sure how this works for Easy --> Very Hard */
316   PORT_DIPSETTING(      0x0300, "1" ) /* Initial start time 40 secs */
317   PORT_DIPSETTING(      0x0200, "2" ) /* Initial start time 30 secs - Other in game effects?? */
318   PORT_DIPSETTING(      0x0100, "3" ) /* Initial start time 30 secs - Other in game effects?? */
319   PORT_DIPSETTING(      0x0000, "4" ) /* Initial start time 30 secs - Other in game effects?? */
320   PORT_DIPNAME( 0x1c00, 0x1c00, DEF_STR( Coinage ) )      PORT_DIPLOCATION("SW1:3,4,5")
305321   PORT_DIPSETTING(      0x1000, DEF_STR( 4C_1C ) )
306322   PORT_DIPSETTING(      0x1400, DEF_STR( 3C_1C ) )
307323   PORT_DIPSETTING(      0x0000, DEF_STR( 4C_2C ) ) /* Works the same as 2C/1C */
r243398r243399
310326   PORT_DIPSETTING(      0x0800, DEF_STR( 2C_2C ) ) /* Works the same as 1C/1C */
311327   PORT_DIPSETTING(      0x1c00, DEF_STR( 1C_1C ) )
312328   PORT_DIPSETTING(      0x0c00, DEF_STR( 1C_2C ) )
313   PORT_DIPNAME( 0x2000, 0x2000, "Coin Box" )      PORT_DIPLOCATION("SW2:6") /* Always displays total credits - No separate Credit display per player */
329   PORT_DIPNAME( 0x2000, 0x2000, "Coin Box" )      PORT_DIPLOCATION("SW1:6") /* Always displays total credits - No separate Credit display per player */
314330   PORT_DIPSETTING(      0x2000, "1" ) /* Both players use coins from either Coin 1 or Coin 2 */
315331   PORT_DIPSETTING(      0x0000, "2" ) /* Players use coins from own coin chute. IE: Player 1 -> Coin 1, Player 2 -> Coin 2 but shows only total credits */
316   PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Lives ) )      PORT_DIPLOCATION("SW2:7")
332   PORT_DIPNAME( 0x4000, 0x4000, DEF_STR( Lives ) )      PORT_DIPLOCATION("SW1:7")
317333   PORT_DIPSETTING(      0x0000, "2" )
318334   PORT_DIPSETTING(      0x4000, "3" )
319   PORT_SERVICE_DIPLOC(  0x8000, IP_ACTIVE_LOW, "SW2:8" ) /* Verified */
335   PORT_SERVICE_DIPLOC(  0x8000, IP_ACTIVE_LOW, "SW1:8" ) /* Verified */
320336INPUT_PORTS_END
321337
322338
trunk/src/mame/mame.lst
r243398r243399
1121211212peps0043        // (c) 1996 IGT - International Game Technology
1121311213peps0045        // (c) 1996 IGT - International Game Technology
1121411214peps0047        // (c) 1996 IGT - International Game Technology
11215peps0090        // (c) 1996 IGT - International Game Technology
1121611215peps0092        // (c) 1996 IGT - International Game Technology
1121711216peps0206        // (c) 1996 IGT - International Game Technology
1121811217peps0207        // (c) 1996 IGT - International Game Technology
trunk/src/mame/video/jagblit.inc
r243398r243399
344344   }
345345
346346   /* check for unhandled command bits */
347   if (LOG_UNHANDLED_BLITS && (COMMAND & 0x24003000))
347   if ((COMMAND & 0x24003000) && LOG_UNHANDLED_BLITS)
348348      logerror("Blitter unhandled: these command bits: %08X\n", COMMAND & 0x24003000);
349349
350350   /* top of the outer loop */
trunk/src/mess/drivers/kaypro.c
r243398r243399
163163
164164************************************************************/
165165
166FLOPPY_FORMATS_MEMBER( kaypro_state::kayproii_floppy_formats )
167   FLOPPY_KAYPROII_FORMAT
168FLOPPY_FORMATS_END
169
170FLOPPY_FORMATS_MEMBER( kaypro_state::kaypro2x_floppy_formats )
171   FLOPPY_KAYPRO2X_FORMAT
172FLOPPY_FORMATS_END
173
174166static SLOT_INTERFACE_START( kaypro_floppies )
175167   SLOT_INTERFACE( "drive0", FLOPPY_525_DD )
176168   SLOT_INTERFACE( "drive1", FLOPPY_525_DD )
r243398r243399
232224   MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(kaypro_state, fdc_intrq_w))
233225   MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(kaypro_state, fdc_drq_w))
234226   MCFG_WD_FDC_FORCE_READY
235   MCFG_FLOPPY_DRIVE_ADD("fdc:0", kaypro_floppies, "drive0", kaypro_state::kayproii_floppy_formats)
236   MCFG_FLOPPY_DRIVE_ADD("fdc:1", kaypro_floppies, "drive1", kaypro_state::kayproii_floppy_formats)
227   MCFG_FLOPPY_DRIVE_ADD("fdc:0", kaypro_floppies, "drive0", floppy_image_device::default_floppy_formats)
228   MCFG_FLOPPY_DRIVE_ADD("fdc:1", kaypro_floppies, "drive1", floppy_image_device::default_floppy_formats)
237229   MCFG_SOFTWARE_LIST_ADD("flop_list","kayproii")
238230MACHINE_CONFIG_END
239231
r243398r243399
295287   MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(kaypro_state, fdc_intrq_w))
296288   MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(kaypro_state, fdc_drq_w))
297289   MCFG_WD_FDC_FORCE_READY
298   MCFG_FLOPPY_DRIVE_ADD("fdc:0", kaypro_floppies, "drive0", kaypro_state::kaypro2x_floppy_formats)
299   MCFG_FLOPPY_DRIVE_ADD("fdc:1", kaypro_floppies, "drive1", kaypro_state::kaypro2x_floppy_formats)
290   MCFG_FLOPPY_DRIVE_ADD("fdc:0", kaypro_floppies, "drive0", floppy_image_device::default_floppy_formats)
291   MCFG_FLOPPY_DRIVE_ADD("fdc:1", kaypro_floppies, "drive1", floppy_image_device::default_floppy_formats)
300292MACHINE_CONFIG_END
301293
302294static MACHINE_CONFIG_DERIVED( omni2, kaypro4 )
trunk/src/mess/drivers/pc9801.c
r243398r243399
13691369UINT16 pc9801_state::egc_do_partial_op(int plane, UINT16 src, UINT16 pat, UINT16 dst)
13701370{
13711371   UINT16 out = 0;
1372   int dst_off = (m_egc.regs[6] >> 4) & 0xf;
1373   UINT16 src_tmp = src;
13721374
13731375   for(int i = 7; i >= 0; i--)
13741376   {
trunk/src/mess/includes/kaypro.h
r243398r243399
5959   DECLARE_PALETTE_INIT(kaypro);
6060   DECLARE_MACHINE_RESET(kay_kbd);
6161   DECLARE_DRIVER_INIT(kaypro);
62   DECLARE_FLOPPY_FORMATS(kayproii_floppy_formats);
63   DECLARE_FLOPPY_FORMATS(kaypro2x_floppy_formats);
6462   UINT32 screen_update_kayproii(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
6563   UINT32 screen_update_kaypro2x(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
6664   UINT32 screen_update_omni2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
trunk/src/mess/machine/kaypro.c
r243398r243399
114114      m_floppy = m_floppy1->get_device();
115115
116116   m_fdc->set_floppy(m_floppy);
117   m_fdc->dden_w(BIT(data, 5));
117   m_fdc->dden_w(BIT(data, 5)); // not connected
118118
119119   if (m_floppy)
120120   {
r243398r243399
252252   m_system_port = 0x80;
253253   m_fdc_rq = 0;
254254   m_maincpu->reset();
255   timer_set(attotime::from_hz(1), TIMER_FLOPPY);   /* kick-start the nmi timer */
255   timer_set(attotime::from_hz(1), TIMER_FLOPPY);   /* timer for rtc */
256256}
257257
258258
trunk/src/osd/sdl/draw13.c
r243398r243399
145145    sdl_info13(sdl_window_info *w)
146146    : osd_renderer(w, FLAG_NONE), m_blittimer(0), m_sdl_renderer(NULL),
147147      m_last_hofs(0), m_last_vofs(0),
148      m_last_width(0), m_last_height(0),
148      m_resize_pending(0), m_resize_width(0), m_resize_height(0),
149149      m_last_blit_time(0), m_last_blit_pixels(0)
150150    {}
151151
152   /* virtual */ int create();
152   /* virtual */ int create(const int width, const int height);
153   /* virtual */ void resize(const int width, const int height);
153154   /* virtual */ int draw(const UINT32 dc, const int update);
154155   /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt);
155156   /* virtual */ void destroy_all_textures();
r243398r243399
176177   float           m_last_hofs;
177178   float           m_last_vofs;
178179
179   int            m_last_width;
180   int            m_last_height;
180   // resize information
181181
182   UINT8           m_resize_pending;
183   UINT32          m_resize_width;
184   UINT32          m_resize_height;
185
182186   // Stats
183187   INT64           m_last_blit_time;
184188   INT64           m_last_blit_pixels;
r243398r243399
572576// a
573577//============================================================
574578
575int sdl_info13::create()
579int sdl_info13::create(int width, int height)
576580{
577581#if (SDLMAME_SDL2)
578582   // create renderer
r243398r243399
613617   return 0;
614618}
615619
620//============================================================
621//  sdl_info::resize
622//============================================================
616623
624void sdl_info13::resize(int width, int height)
625{
626   SDL_RenderSetViewport(m_sdl_renderer, NULL);
627   m_blittimer = 3;
628}
629
630
617631//============================================================
618632//  sdl_info::destroy
619633//============================================================
r243398r243399
681695      return 0;
682696   }
683697
684   if ((window().width() != m_last_width) || (window().height() != m_last_height))
698#if 0
699   if (m_resize_pending)
685700   {
686      m_last_width = window().width();
687      m_last_height = window().height();
701      SDL_SetWindowSize(window().m_sdl_window, m_resize_width, m_resize_height);
702      SDL_GetWindowSize(window().m_sdl_window, &window().width(), &window().height());
703      m_resize_pending = 0;
688704      SDL_RenderSetViewport(m_sdl_renderer, NULL);
689      m_blittimer = 3;
705      //sdlvideo_monitor_refresh(window().monitor());
706
690707   }
708#endif
691709   //SDL_SelectRenderer(window().sdl_window);
692710
693711   if (m_blittimer > 0)
trunk/src/osd/sdl/drawbgfx.c
r243398r243399
7979      m_last_blit_time(0), m_last_blit_pixels(0)
8080    {}
8181
82   /* virtual */ int create();
82   /* virtual */ int create(const int width, const int height);
83   /* virtual */ void resize(const int width, const int height);
8384   /* virtual */ int draw(const UINT32 dc, const int update);
8485   /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt);
8586   /* virtual */ void destroy_all_textures();
r243398r243399
134135//  sdl_info_bgfx::create
135136//============================================================
136137
137int sdl_info_bgfx::create()
138int sdl_info_bgfx::create(int width, int height)
138139{
139140   // create renderer
140141
r243398r243399
151152}
152153
153154//============================================================
155//  sdl_info_bgfx::resize
156//============================================================
157
158void sdl_info_bgfx::resize(int width, int height)
159{
160   m_blittimer = 3;
161}
162
163//============================================================
154164//  drawsdl_xy_to_render_target
155165//============================================================
156166
trunk/src/osd/sdl/drawogl.c
r243398r243399
224224   sdl_info_ogl(sdl_window_info *window)
225225   : osd_renderer(window, FLAG_NEEDS_OPENGL), m_blittimer(0),
226226      m_screen_width(0), m_screen_height(0),
227      m_last_width(0), m_last_height(0),
228227#if (SDLMAME_SDL2)
229228      m_gl_context_id(0),
230229#else
r243398r243399
252251         m_texVerticex[i] = 0.0f;
253252   }
254253
255   /* virtual */ int create();
254   /* virtual */ int create(const int width, const int height);
255   /* virtual */ void resize(const int width, int const height);
256256   /* virtual */ int draw(const UINT32 dc, const int update);
257257   /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt);
258258   /* virtual */ void destroy_all_textures();
r243398r243399
280280   INT32           m_blittimer;
281281   int             m_screen_width;
282282   int             m_screen_height;
283   int            m_last_width;
284   int            m_last_height;
285283
286284#if (SDLMAME_SDL2)
287285   SDL_GLContext   m_gl_context_id;
r243398r243399
711709// a
712710//============================================================
713711
714int sdl_info_ogl::create()
712int sdl_info_ogl::create(int width, int height)
715713{
716714
717715#if (SDLMAME_SDL2)
r243398r243399
756754   return 0;
757755}
758756
757//============================================================
758//  sdl_info::resize
759//============================================================
759760
761void sdl_info_ogl::resize(int width, int height)
762{
763#if (SDLMAME_SDL2)
764   m_blittimer = 3;
765#endif
766   m_init_context = 1;
767}
768
769
760770//============================================================
761771//  sdl_info::destroy
762772//============================================================
r243398r243399
12111221      return 0;
12121222   }
12131223
1214   if ((window().width() != m_last_width) || (window().height() != m_last_height))
1215   {
1216      m_last_width = window().width();
1217      m_last_height = window().height();
12181224#if (SDLMAME_SDL2)
1219      m_blittimer = 3;
1220#endif
1221      m_init_context = 1;
1222   }
1223
1224#if (SDLMAME_SDL2)
12251225   SDL_GL_MakeCurrent(window().sdl_window(), m_gl_context_id);
12261226#else
12271227   if (!m_init_context)
trunk/src/osd/sdl/drawsdl.c
r243398r243399
6565   m_last_hofs(0),
6666   m_last_vofs(0),
6767   m_old_blitwidth(0),
68   m_old_blitheight(0),
69   m_last_width(0),
70   m_last_height(0)
68   m_old_blitheight(0)
7169   { }
7270
73   /* virtual */ int create();
71   /* virtual */ int create(const int width, const int height);
72   /* virtual */ void resize(const int width, const int height);
7473   /* virtual */ int draw(const UINT32 dc, const int update);
7574   /* virtual */ int xy_to_render_target(const int x, const int y, int *xt, int *yt);
7675   /* virtual */ void destroy_all_textures();
r243398r243399
108107   int                 m_last_vofs;
109108   int                 m_old_blitwidth;
110109   int                 m_old_blitheight;
111   int                 m_last_width;
112   int                 m_last_height;
113110};
114111
115112struct sdl_scale_mode
r243398r243399
419416// a
420417//============================================================
421418
422int sdl_info::create()
419int sdl_info::create(int width, int height)
423420{
424421
425422#if (SDLMAME_SDL2)
r243398r243399
465462      }
466463   }
467464
468   setup_texture(window().width(), window().height());
465   setup_texture(width, height);
469466#else
470467#endif
471468
r243398r243399
478475}
479476
480477//============================================================
478//  sdl_info::resize
479//============================================================
480
481void sdl_info::resize(int width, int height)
482{
483#if (SDLMAME_SDL2)
484   SDL_RenderSetViewport(m_sdl_renderer, NULL);
485#else
486   const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
487   if (sdl_sm->is_yuv)
488   {
489      yuv_overlay_init();
490   }
491#endif
492}
493
494
495//============================================================
481496//  sdl_info::destroy
482497//============================================================
483498
r243398r243399
565580      return 0;
566581   }
567582
568   if ((window().width() != m_last_width) || (window().height() != m_last_height))
569   {
570      m_last_width = window().width();
571      m_last_height = window().height();
572#if (SDLMAME_SDL2)
573      SDL_RenderSetViewport(m_sdl_renderer, NULL);
574#else
575      const sdl_scale_mode *sdl_sm = &scale_modes[video_config.scale_mode];
576      if (sdl_sm->is_yuv)
577      {
578         yuv_overlay_init();
579      }
580#endif
581   }
582
583583   // lock it if we need it
584584#if (!SDLMAME_SDL2)
585585
trunk/src/osd/sdl/window.c
r243398r243399
491491   window->m_height = window->m_sdlsurf->h;
492492#endif
493493
494
495   window->renderer().resize(window->m_width, window->m_height);
496
494497   window->blit_surface_size(window->m_width, window->m_height);
495498
496499   window->clear();
r243398r243399
708711#endif
709712}
710713
711OSDWORK_CALLBACK( sdl_window_info::update_cursor_state_wt )
714static OSDWORK_CALLBACK( sdlwindow_update_cursor_state_wt )
712715{
713716   worker_param *      wp = (worker_param *) param;
714717   sdl_window_info *   window = wp->window();
r243398r243399
10201023   // adjust the cursor state
10211024   //sdlwindow_update_cursor_state(machine, window);
10221025
1023   execute_async(&update_cursor_state_wt, worker_param(this));
1026   execute_async(&sdlwindow_update_cursor_state_wt, worker_param(this));
10241027
10251028   // if we're visible and running and not in the middle of a resize, draw
10261029   if (m_target != NULL)
r243398r243399
12761279#endif
12771280
12781281   // initialize the drawing backend
1279   if (window->renderer().create())
1282   if (window->renderer().create(window->width(), window->height()))
12801283      return (void *) &result[1];
12811284
12821285   // Make sure we have a consistent state
trunk/src/osd/sdl/window.h
r243398r243399
5757   int flags() const { return m_flags; }
5858   bool check_flag(const int flag) { return ((m_flags & flag)) == flag; }
5959
60   virtual int create() = 0;
60   virtual int create(const int width, const int height) = 0;
61   virtual void resize(const int width, const int height) = 0;
6162   virtual int draw(const UINT32 dc, const int update) = 0;
6263   virtual int xy_to_render_target(const int x, const int y, int *xt, int *yt) = 0;
6364   virtual void destroy_all_textures() = 0;
r243398r243399
115116   }
116117
117118   int window_init();
119   void destroy();
118120
119121   void update();
120122   void toggle_full_screen();
121123   void modify_prescale(int dir);
122124   void resize(INT32 width, INT32 height);
123   void destroy();
124125   void clear();
125126   int xy_to_render_target(int x, int y, int *xt, int *yt);
126127
128   void get_min_bounds(int *window_width, int *window_height, int constrain);
129   void get_max_bounds(int *window_width, int *window_height, int constrain);
130
127131   running_machine &machine() const { return m_machine; }
128132   sdl_monitor_info *monitor() const { return m_monitor; }
129133   int fullscreen() const { return m_fullscreen; }
130134
135   void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; }
136   void update_cursor_state();
137
138   void blit_surface_size(int window_width, int window_height);
139   void pick_best_mode(int *fswidth, int *fsheight);
140   void set_starting_view(running_machine &machine, int index, const char *defview, const char *view);
141
131142   int index() const { return m_index; }
132143
144
145
133146   render_target *target() { return m_target; }
134147#if (SDLMAME_SDL2)
135148   SDL_Window *sdl_window() { return m_sdl_window; }
r243398r243399
159172private:
160173   // window handle and info
161174   char                m_title[256];
162   int                 m_startmaximized;
163175
164176   // diverse flags
165177   int                 m_minwidth, m_minheight;
166178   int                 m_maxwidth, m_maxheight;
179   int                 m_depth;
167180   int                 m_refresh;
168   int                 m_depth;
169181   int                 m_windowed_width;
170182   int                 m_windowed_height;
183   int                 m_startmaximized;
171184
172185   // rendering info
173186   osd_event *         m_rendered_event;
r243398r243399
206219   osd_renderer &renderer() { return *m_renderer; }
207220private:
208221   void constrain_to_aspect_ratio(int *window_width, int *window_height, int adjustment);
209   void update_cursor_state();
210   void blit_surface_size(int window_width, int window_height);
211   void pick_best_mode(int *fswidth, int *fsheight);
212   void set_starting_view(running_machine &machine, int index, const char *defview, const char *view);
213   void get_min_bounds(int *window_width, int *window_height, int constrain);
214   void get_max_bounds(int *window_width, int *window_height, int constrain);
215   void set_fullscreen(int afullscreen) { m_fullscreen = afullscreen; }
216222
217
218
219
220223   // Pointer to machine
221224   running_machine &   m_machine;
222225   // monitor info
r243398r243399
233236   static OSDWORK_CALLBACK( sdlwindow_toggle_full_screen_wt );
234237   static OSDWORK_CALLBACK( sdlwindow_clear_surface_wt );
235238   static OSDWORK_CALLBACK( destroy_all_textures_wt );
236   static OSDWORK_CALLBACK( update_cursor_state_wt );
237239
238240   void measure_fps(UINT32 dc, int update);
239241
trunk/src/osd/windows/d3dhlsl.c
r243398r243399
224224   if (!master_enable || !d3dintf->post_fx_available)
225225      return;
226226
227   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
227   renderer *d3d = (renderer *)window->m_drawdata;
228228
229229   HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), snap_width, snap_height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &snap_copy_texture);
230230   if (result != D3D_OK)
r243398r243399
276276   if (!master_enable || !d3dintf->post_fx_available)
277277      return;
278278
279   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
279   renderer *d3d = (renderer *)window->m_drawdata;
280280
281281   D3DLOCKED_RECT rect;
282282
r243398r243399
326326   if (!master_enable || !d3dintf->post_fx_available)
327327      return;
328328
329   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
329   renderer *d3d = (renderer *)window->m_drawdata;
330330
331331   D3DLOCKED_RECT rect;
332332
r243398r243399
519519   if (!master_enable || !d3dintf->post_fx_available)
520520      return;
521521
522   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
522   renderer *d3d = (renderer *)window->m_drawdata;
523523
524524   // stop any existing recording
525525   end_avi_recording();
r243398r243399
678678   if (!master_enable || !d3dintf->post_fx_available)
679679      return;
680680
681   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
681   renderer *d3d = (renderer *)window->m_drawdata;
682682
683683   if(texture != NULL)
684684   {
r243398r243399
820820   if (!master_enable || !d3dintf->post_fx_available)
821821      return;
822822
823   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
823   renderer *d3d = (renderer *)window->m_drawdata;
824824
825825   // get a pointer to the vertex buffer
826826   fsfx_vertices = (vertex *)vertbuf;
r243398r243399
892892   if (!master_enable || !d3dintf->post_fx_available)
893893      return 0;
894894
895   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
895   renderer *d3d = (renderer *)window->m_drawdata;
896896
897897   HRESULT result = (*d3dintf->device.get_render_target)(d3d->get_device(), 0, &backbuffer);
898898   if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
r243398r243399
10661066   if (!master_enable || !d3dintf->post_fx_available)
10671067      return;
10681068
1069   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1069   renderer *d3d = (renderer *)window->m_drawdata;
10701070
10711071   curr_effect = default_effect;
10721072
r243398r243399
11011101void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
11021102                  UINT32 prim_index, UINT32 prim_count, int dstw, int dsth)
11031103{
1104   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1104   renderer *d3d = (renderer *)window->m_drawdata;
11051105
11061106   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
11071107   if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
r243398r243399
11461146void shaders::blit(surface *dst, texture *src, surface *new_dst, D3DPRIMITIVETYPE prim_type,
11471147                  UINT32 prim_index, UINT32 prim_count)
11481148{
1149   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1149   renderer *d3d = (renderer *)window->m_drawdata;
11501150
11511151   HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, dst);
11521152   if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
r243398r243399
12311231   if (!master_enable || !d3dintf->post_fx_available)
12321232      return;
12331233
1234   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1234   renderer *d3d = (renderer *)window->m_drawdata;
12351235   texture_info *texture = poly->get_texture();
12361236
12371237   if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && texture != NULL)
r243398r243399
13081308
13091309void shaders::ntsc_pass(render_target *rt, vec2f &sourcedims, vec2f &delta)
13101310{
1311   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1311   renderer *d3d = (renderer *)window->m_drawdata;
13121312   UINT num_passes = 0;
13131313
13141314   if(options->yiq_enable)
r243398r243399
13701370
13711371void shaders::color_convolution_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims)
13721372{
1373   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1373   renderer *d3d = (renderer *)window->m_drawdata;
13741374   UINT num_passes = 0;
13751375
13761376   curr_effect = color_effect;
r243398r243399
13981398
13991399void shaders::prescale_pass(render_target *rt, vec2f &texsize, vec2f &sourcedims)
14001400{
1401   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1401   renderer *d3d = (renderer *)window->m_drawdata;
14021402   UINT num_passes = 0;
14031403
14041404   curr_effect = prescale_effect;
r243398r243399
14261426
14271427void shaders::deconverge_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims)
14281428{
1429   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1429   renderer *d3d = (renderer *)window->m_drawdata;
14301430   UINT num_passes = 0;
14311431
14321432   curr_effect = deconverge_effect;
r243398r243399
14541454
14551455void shaders::defocus_pass(render_target *rt, vec2f &texsize)
14561456{
1457   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1457   renderer *d3d = (renderer *)window->m_drawdata;
14581458   UINT num_passes = 0;
14591459
14601460   // Defocus pass 1
r243398r243399
15031503
15041504void shaders::phosphor_pass(render_target *rt, cache_target *ct, vec2f &texsize, bool focus_enable)
15051505{
1506   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1506   renderer *d3d = (renderer *)window->m_drawdata;
15071507   UINT num_passes = 0;
15081508
15091509   curr_effect = phosphor_effect;
r243398r243399
15611561
15621562void shaders::avi_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
15631563{
1564   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1564   renderer *d3d = (renderer *)window->m_drawdata;
15651565   UINT num_passes = 0;
15661566
15671567   curr_effect = post_effect;
r243398r243399
16161616
16171617void shaders::screen_post_pass(render_target *rt, vec2f &texsize, vec2f &delta, vec2f &sourcedims, poly_info *poly, int vertnum)
16181618{
1619   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1619   renderer *d3d = (renderer *)window->m_drawdata;
16201620   UINT num_passes = 0;
16211621
16221622   curr_effect = post_effect;
r243398r243399
16501650
16511651void shaders::raster_bloom_pass(render_target *rt, vec2f &texsize, vec2f &delta, poly_info *poly, int vertnum)
16521652{
1653   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1653   renderer *d3d = (renderer *)window->m_drawdata;
16541654   UINT num_passes = 0;
16551655
16561656   curr_effect = downsample_effect;
r243398r243399
17551755      return;
17561756
17571757   UINT num_passes = 0;
1758   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
1758   renderer *d3d = (renderer *)window->m_drawdata;
17591759   curr_texture = poly->get_texture();
17601760
17611761   if(PRIMFLAG_GET_SCREENTEX(d3d->get_last_texture_flags()) && curr_texture != NULL)
r243398r243399
20802080      return NULL;
20812081   }
20822082
2083   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
2083   renderer *d3d = (renderer *)window->m_drawdata;
20842084
20852085   return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
20862086}
20872087
20882088void shaders::create_vector_target(render_primitive *prim)
20892089{
2090   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
2090   renderer *d3d = (renderer *)window->m_drawdata;
20912091   if (!add_render_target(d3d, NULL, d3d->get_width(), d3d->get_height(), 1, 1))
20922092   {
20932093      vector_enable = false;
r243398r243399
22022202
22032203   enumerate_screens();
22042204
2205   renderer *d3d = dynamic_cast<renderer *>(window->m_renderer);
2205   renderer *d3d = (renderer *)window->m_drawdata;
22062206
22072207   int hlsl_prescale_x = prescale_force_x;
22082208   int hlsl_prescale_y = prescale_force_y;
r243398r243399
29942994   }
29952995
29962996   shaders *shadersys = m_shader->m_shaders;
2997   renderer *d3d = dynamic_cast<renderer *>(shadersys->window->m_renderer);
2997   renderer *d3d = (renderer *)shadersys->window->m_drawdata;
29982998   hlsl_options *options = shadersys->options;
29992999
30003000   switch(m_id)
r243398r243399
34223422   UINT32 origflags = file.openflags();
34233423
34243424   // handle defaults
3425   const char *snapname = templ ? templ : d3d->window().machine().options().snap_name();
3425   const char *snapname = templ ? templ : d3d->get_window()->machine().options().snap_name();
34263426
34273427   if (snapname == NULL || snapname[0] == 0)
34283428      snapname = "%g/%i";
r243398r243399
34693469         snapdevname.cpysubstr(snapstr, pos + 3, end - pos - 3);
34703470
34713471         // verify that there is such a device for this system
3472         image_interface_iterator iter(d3d->window().machine().root_device());
3472         image_interface_iterator iter(d3d->get_window()->machine().root_device());
34733473         for (device_image_interface *image = iter.first(); image != NULL; iter.next())
34743474         {
34753475            // get the device name
r243398r243399
35063506
35073507   // substitute path and gamename up front
35083508   snapstr.replace(0, "/", PATH_SEPARATOR);
3509   snapstr.replace(0, "%g", d3d->window().machine().basename());
3509   snapstr.replace(0, "%g", d3d->get_window()->machine().basename());
35103510
35113511   // determine if the template has an index; if not, we always use the same name
35123512   astring fname;
trunk/src/osd/windows/drawbgfx.c
r243398r243399
2222#include <bgfxplatform.h>
2323#include <bgfx.h>
2424
25class renderer_bgfx : public osd_renderer
26{
27public:
28   renderer_bgfx(win_window_info *window)
29   : osd_renderer(window, FLAG_NONE) { }
30
31   virtual ~renderer_bgfx() { }
32
33   virtual int init();
34   virtual render_primitive_list *get_primitives();
35   virtual int draw(HDC dc, int update);
36   virtual void save() {};
37   virtual void record() {};
38   virtual void toggle_fsfx() {};
39   virtual void destroy();
40
41private:
42};
43
44
4525//============================================================
4626//  PROTOTYPES
4727//============================================================
4828
4929// core functions
5030static void drawbgfx_exit(void);
31static int drawbgfx_window_init(win_window_info *window);
32static void drawbgfx_window_destroy(win_window_info *window);
33static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window);
34static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update);
5135
52//============================================================
53//  drawnone_create
54//============================================================
5536
56osd_renderer *drawbgfx_create(win_window_info *window)
57{
58   return global_alloc(renderer_bgfx(window));
59}
6037
6138//============================================================
6239//  drawbgfx_init
6340//============================================================
6441
65int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks)
42int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks)
6643{
6744   // fill in the callbacks
6845   memset(callbacks, 0, sizeof(*callbacks));
6946   callbacks->exit = drawbgfx_exit;
70   callbacks->create = drawbgfx_create;
47   callbacks->window_init = drawbgfx_window_init;
48   callbacks->window_get_primitives = drawbgfx_window_get_primitives;
49   callbacks->window_draw = drawbgfx_window_draw;
50   callbacks->window_destroy = drawbgfx_window_destroy;
7151   return 0;
7252}
7353
r243398r243399
8767//  drawbgfx_window_init
8868//============================================================
8969
90int renderer_bgfx::init()
70static int drawbgfx_window_init(win_window_info *window)
9171{
9272   RECT client;
93   GetClientRect(window().m_hwnd, &client);
73   GetClientRect(window->m_hwnd, &client);
9474
95   bgfx::winSetHwnd(window().m_hwnd);
75   bgfx::winSetHwnd(window->m_hwnd);
9676   bgfx::init();
9777   bgfx::reset(rect_width(&client), rect_height(&client), BGFX_RESET_VSYNC);
9878   
9979   // Enable debug text.
10080   bgfx::setDebug(BGFX_DEBUG_STATS);// BGFX_DEBUG_TEXT);
10181
82   window->m_drawdata = window->m_hwnd;
10283   return 0;
10384}
10485
r243398r243399
10889//  drawbgfx_window_destroy
10990//============================================================
11091
111void renderer_bgfx::destroy()
92static void drawbgfx_window_destroy(win_window_info *window)
11293{
11394   // Shutdown bgfx.
11495   bgfx::shutdown();
96   window->m_drawdata = NULL;
11597}
11698
11799
r243398r243399
120102//  drawbgfx_window_get_primitives
121103//============================================================
122104
123render_primitive_list *renderer_bgfx::get_primitives()
105static render_primitive_list *drawbgfx_window_get_primitives(win_window_info *window)
124106{
125107   RECT client;
126   GetClientRect(window().m_hwnd, &client);
127   window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
128   return &window().m_target->get_primitives();
108   GetClientRect(window->m_hwnd, &client);
109   window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
110   return &window->m_target->get_primitives();   
129111}
130112
131113
r243398r243399
134116//  drawbgfx_window_draw
135117//============================================================
136118
137int renderer_bgfx::draw(HDC dc, int update)
119static int drawbgfx_window_draw(win_window_info *window, HDC dc, int update)
138120{
139121   RECT client;
140   GetClientRect(window().m_hwnd, &client);
122   GetClientRect(window->m_hwnd, &client);
141123
142124   bgfx::setViewClear(0
143125      , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
r243398r243399
152134   // if no other draw calls are submitted to view 0.
153135   bgfx::submit(0);
154136
155   window().m_primlist->acquire_lock();
137   window->m_primlist->acquire_lock();
156138
157139   // now draw
158   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
140   for (render_primitive *prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
159141   {
160142      switch (prim->type)
161143      {
r243398r243399
237219      }
238220   }
239221
240   window().m_primlist->release_lock();
222   window->m_primlist->release_lock();   
241223   // Advance to next frame. Rendering thread will be kicked to
242224   // process submitted rendering primitives.
243225   bgfx::frame();
trunk/src/osd/windows/drawd3d.c
r243398r243399
179179
180180// core functions
181181static void drawd3d_exit(void);
182static int drawd3d_window_init(win_window_info *window);
183static void drawd3d_window_destroy(win_window_info *window);
184static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window);
185static void drawd3d_window_save(win_window_info *window);
186static void drawd3d_window_record(win_window_info *window);
187static void drawd3d_window_toggle_fsfx(win_window_info *window);
188static int drawd3d_window_draw(win_window_info *window, HDC dc, int update);
182189
190
183191//============================================================
184192//  drawd3d_window_init
185193//============================================================
186194
187int d3d::renderer::init()
195static int drawd3d_window_init(win_window_info *window)
188196{
189   if (!initialize())
197   // allocate memory for our structures
198   d3d::renderer *d3d = global_alloc(d3d::renderer(window));
199   window->m_drawdata = d3d;
200
201   if (!d3d->initialize())
190202   {
191      destroy();
203      drawd3d_window_destroy(window);
192204      osd_printf_error("Unable to initialize Direct3D.\n");
193205      return 1;
194206   }
r243398r243399
206218      (*d3dintf->d3d.release)(d3dintf);
207219}
208220
209void d3d::renderer::toggle_fsfx()
221static void drawd3d_window_toggle_fsfx(win_window_info *window)
210222{
211   set_restarting(true);
223   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
224   d3d->set_restarting(true);
212225}
213226
214void d3d::renderer::record()
227static void drawd3d_window_record(win_window_info *window)
215228{
216   get_shaders()->window_record();
229   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
230   d3d->get_shaders()->window_record();
217231}
218232
219void d3d::renderer::save()
233static void drawd3d_window_save(win_window_info *window)
220234{
221   get_shaders()->window_save();
235   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
236   d3d->get_shaders()->window_save();
222237}
223238
224239
r243398r243399
227242//  drawd3d_window_destroy
228243//============================================================
229244
230void d3d::renderer::destroy()
245static void drawd3d_window_destroy(win_window_info *window)
231246{
232   if (get_shaders() != NULL && get_shaders()->recording())
233      get_shaders()->window_record();
247   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
234248
249   // skip if nothing
250   if (d3d == NULL)
251      return;
252
253   if (d3d->get_shaders() != NULL && d3d->get_shaders()->recording())
254      d3d->get_shaders()->window_record();
255
256   // free the memory in the window
257   global_free(d3d);
258   window->m_drawdata = NULL;
235259}
236260
237261
r243398r243399
240264//  drawd3d_window_get_primitives
241265//============================================================
242266
243render_primitive_list *d3d::renderer::get_primitives()
267static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window)
244268{
269   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
245270   RECT client;
246271
247   GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
272   GetClientRectExceptMenu(window->m_hwnd, &client, window->m_fullscreen);
248273   if (rect_width(&client) > 0 && rect_height(&client) > 0)
249274   {
250      window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
251      window().m_target->set_max_update_rate((get_refresh() == 0) ? get_origmode().RefreshRate : get_refresh());
275      window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
276      window->m_target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh());
252277   }
253   return &window().m_target->get_primitives();
278   return &window->m_target->get_primitives();
254279}
255280
256//============================================================
257//  drawnone_create
258//============================================================
259
260static osd_renderer *drawd3d_create(win_window_info *window)
281int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
261282{
262   return global_alloc(d3d::renderer(window));
263}
264
265int drawd3d_init(running_machine &machine, osd_draw_callbacks *callbacks)
266{
267283   d3dintf = NULL;
268284
269285   // Use Direct3D9
r243398r243399
279295   // fill in the callbacks
280296   memset(callbacks, 0, sizeof(*callbacks));
281297   callbacks->exit = drawd3d_exit;
282   callbacks->create = drawd3d_create;
298   callbacks->window_init = drawd3d_window_init;
299   callbacks->window_get_primitives = drawd3d_window_get_primitives;
300   callbacks->window_draw = drawd3d_window_draw;
301   callbacks->window_save = drawd3d_window_save;
302   callbacks->window_record = drawd3d_window_record;
303   callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx;
304   callbacks->window_destroy = drawd3d_window_destroy;
283305   return 0;
284306}
285307
r243398r243399
287309//  drawd3d_window_draw
288310//============================================================
289311
290int d3d::renderer::draw(HDC dc, int update)
312static int drawd3d_window_draw(win_window_info *window, HDC dc, int update)
291313{
292   int check = pre_window_draw_check();
314   d3d::renderer *d3d = (d3d::renderer *)window->m_drawdata;
315
316   // if we haven't been created, just punt
317   if (d3d == NULL)
318      return 1;
319
320   int check = d3d->pre_window_draw_check();
293321   if (check >= 0)
294322      return check;
295323
296   begin_frame();
297   process_primitives();
298   end_frame();
324   d3d->begin_frame();
325   d3d->process_primitives();
326   d3d->end_frame();
299327
300328   return 0;
301329}
r243398r243399
468496   osd_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB");
469497
470498   // set the max texture size
471   d3d->window().m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
499   d3d->get_window()->m_target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
472500   osd_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height);
473501}
474502
r243398r243399
480508{
481509   // experimental: load a PNG to use for vector rendering; it is treated
482510   // as a brightness map
483   emu_file file(m_renderer->window().machine().options().art_path(), OPEN_FLAG_READ);
511   emu_file file(m_renderer->get_window()->machine().options().art_path(), OPEN_FLAG_READ);
484512   render_load_png(m_vector_bitmap, file, NULL, "vector.png");
485513   if (m_vector_bitmap.valid())
486514   {
r243398r243399
622650}
623651
624652renderer::renderer(win_window_info *window)
625   : osd_renderer(window, FLAG_NONE)
626653{
627654   m_device = NULL;
628655   m_restarting = false;
656   m_window = window;
629657   m_shaders = NULL;
630658   m_numverts = 0;
631659   m_numpolys = 0;
r243398r243399
644672      return false;
645673
646674   // create the device immediately for the full screen case (defer for window mode)
647   if (window().m_fullscreen && device_create())
675   if (m_window->m_fullscreen && device_create())
648676      return false;
649677
650678   return true;
r243398r243399
653681int renderer::pre_window_draw_check()
654682{
655683   // if we're in the middle of resizing, leave things alone
656   if (window().m_resize_state == RESIZE_STATE_RESIZING)
684   if (m_window->m_resize_state == RESIZE_STATE_RESIZING)
657685      return 0;
658686
659687   // if we're restarting the renderer, leave things alone
r243398r243399
678706   }
679707
680708   // in window mode, we need to track the window size
681   if (!window().m_fullscreen || m_device == NULL)
709   if (!m_window->m_fullscreen || m_device == NULL)
682710   {
683711      // if the size changes, skip this update since the render target will be out of date
684712      if (update_window_size())
r243398r243399
694722
695723void texture_manager::update_textures()
696724{
697   for (render_primitive *prim = m_renderer->window().m_primlist->first(); prim != NULL; prim = prim->next())
725   for (render_primitive *prim = m_renderer->get_window()->m_primlist->first(); prim != NULL; prim = prim->next())
698726   {
699727      if (prim->texture.base != NULL)
700728      {
r243398r243399
731759
732760   m_shaders->begin_frame();
733761
734   window().m_primlist->acquire_lock();
762   m_window->m_primlist->acquire_lock();
735763
736764   // first update any textures
737765   m_texture_manager->update_textures();
r243398r243399
752780   m_line_count = 0;
753781
754782   // loop over primitives
755   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
783   for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
756784      if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags))
757785         m_line_count++;
758786}
r243398r243399
760788void renderer::process_primitives()
761789{
762790   // Rotating index for vector time offsets
763   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
791   for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
764792   {
765793      switch (prim->type)
766794      {
r243398r243399
790818
791819void renderer::end_frame()
792820{
793   window().m_primlist->release_lock();
821   m_window->m_primlist->release_lock();
794822
795823   // flush any pending polygons
796824   primitive_flush_pending();
r243398r243399
865893   m_presentation.BackBufferCount               = video_config.triplebuf ? 2 : 1;
866894   m_presentation.MultiSampleType               = D3DMULTISAMPLE_NONE;
867895   m_presentation.SwapEffect                    = D3DSWAPEFFECT_DISCARD;
868   m_presentation.hDeviceWindow                 = window().m_hwnd;
869   m_presentation.Windowed                      = !window().m_fullscreen || win_has_menu(&window());
896   m_presentation.hDeviceWindow                 = m_window->m_hwnd;
897   m_presentation.Windowed                      = !m_window->m_fullscreen || win_has_menu(m_window);
870898   m_presentation.EnableAutoDepthStencil        = FALSE;
871899   m_presentation.AutoDepthStencilFormat        = D3DFMT_D16;
872900   m_presentation.Flags                         = 0;
873901   m_presentation.FullScreen_RefreshRateInHz    = m_refresh;
874   m_presentation.PresentationInterval          = ((video_config.triplebuf && window().m_fullscreen) ||
902   m_presentation.PresentationInterval          = ((video_config.triplebuf && m_window->m_fullscreen) ||
875903                                       video_config.waitvsync || video_config.syncrefresh) ?
876904                                       D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
877905
878906   // create the D3D device
879   result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, window().m_focus_hwnd,
907   result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_window->m_focus_hwnd,
880908               D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &m_presentation, &m_device);
881909   if (result != D3D_OK)
882910   {
r243398r243399
899927   osd_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height);
900928
901929   // set the gamma if we need to
902   if (window().m_fullscreen)
930   if (m_window->m_fullscreen)
903931   {
904932      // only set the gamma if it's not 1.0f
905      windows_options &options = downcast<windows_options &>(window().machine().options());
933      windows_options &options = downcast<windows_options &>(m_window->machine().options());
906934      float brightness = options.full_screen_brightness();
907935      float contrast = options.full_screen_contrast();
908936      float gamma = options.full_screen_gamma();
r243398r243399
10641092   int retval = 0;
10651093
10661094   m_shaders = global_alloc_clear(shaders);
1067   m_shaders->init(d3dintf, &window());
1095   m_shaders->init(d3dintf, m_window);
10681096
10691097   DWORD tempcaps;
10701098   HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
r243398r243399
12031231   }
12041232
12051233   // choose a resolution: window mode case
1206   if (!window().m_fullscreen || !video_config.switchres || win_has_menu(&window()))
1234   if (!m_window->m_fullscreen || !video_config.switchres || win_has_menu(m_window))
12071235   {
12081236      RECT client;
12091237
12101238      // bounds are from the window client rect
1211      GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
1239      GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen);
12121240      m_width = client.right - client.left;
12131241      m_height = client.bottom - client.top;
12141242
r243398r243399
12191247      // make sure it's a pixel format we can get behind
12201248      if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8)
12211249      {
1222         char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice);
1250         char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice);
12231251         if (utf8_device != NULL)
12241252         {
12251253            osd_printf_error("Device %s currently in an unsupported mode\n", utf8_device);
r243398r243399
12441272   }
12451273
12461274   // see if we can handle the device type
1247   result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !window().m_fullscreen);
1275   result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->m_fullscreen);
12481276   if (result != D3D_OK)
12491277   {
1250      char *utf8_device = utf8_from_tstring(window().m_monitor->info.szDevice);
1278      char *utf8_device = utf8_from_tstring(m_window->m_monitor->info.szDevice);
12511279      if (utf8_device != NULL)
12521280      {
12531281         osd_printf_error("Proposed video mode not supported on device %s\n", utf8_device);
r243398r243399
12751303      HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum);
12761304
12771305      // if we match the proposed monitor, this is it
1278      if (curmonitor == window().m_monitor->handle)
1306      if (curmonitor == m_window->m_monitor->handle)
12791307      {
12801308         return adapternum;
12811309      }
r243398r243399
12981326   float best_score = 0.0f;
12991327
13001328   // determine the refresh rate of the primary screen
1301   const screen_device *primary_screen = window().machine().config().first_screen();
1329   const screen_device *primary_screen = m_window->machine().config().first_screen();
13021330   if (primary_screen != NULL)
13031331   {
13041332      target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
r243398r243399
13081336   // note: technically we should not be calling this from an alternate window
13091337   // thread; however, it is only done during init time, and the init code on
13101338   // the main thread is waiting for us to finish, so it is safe to do so here
1311   window().m_target->compute_minimum_size(minwidth, minheight);
1339   m_window->m_target->compute_minimum_size(minwidth, minheight);
13121340
13131341   // use those as the target for now
13141342   INT32 target_width = minwidth;
r243398r243399
13431371         size_score *= 0.1f;
13441372
13451373      // if we're looking for a particular mode, that's a winner
1346      if (mode.Width == window().m_maxwidth && mode.Height == window().m_maxheight)
1374      if (mode.Width == m_window->m_maxwidth && mode.Height == m_window->m_maxheight)
13471375         size_score = 2.0f;
13481376
13491377      // compute refresh score
r243398r243399
13541382         refresh_score *= 0.1f;
13551383
13561384      // if we're looking for a particular refresh, make sure it matches
1357      if (mode.RefreshRate == window().m_refresh)
1385      if (mode.RefreshRate == m_window->m_refresh)
13581386         refresh_score = 2.0f;
13591387
13601388      // weight size and refresh equally
r243398r243399
13841412{
13851413   // get the current window bounds
13861414   RECT client;
1387   GetClientRectExceptMenu(window().m_hwnd, &client, window().m_fullscreen);
1415   GetClientRectExceptMenu(m_window->m_hwnd, &client, m_window->m_fullscreen);
13881416
13891417   // if we have a device and matching width/height, nothing to do
13901418   if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height)
13911419   {
13921420      // clear out any pending resizing if the area didn't change
1393      if (window().m_resize_state == RESIZE_STATE_PENDING)
1394         window().m_resize_state = RESIZE_STATE_NORMAL;
1421      if (m_window->m_resize_state == RESIZE_STATE_PENDING)
1422         m_window->m_resize_state = RESIZE_STATE_NORMAL;
13951423      return FALSE;
13961424   }
13971425
13981426   // if we're in the middle of resizing, leave it alone as well
1399   if (window().m_resize_state == RESIZE_STATE_RESIZING)
1427   if (m_window->m_resize_state == RESIZE_STATE_RESIZING)
14001428      return FALSE;
14011429
14021430   // set the new bounds and create the device again
r243398r243399
14061434      return FALSE;
14071435
14081436   // reset the resize state to normal, and indicate we made a change
1409   window().m_resize_state = RESIZE_STATE_NORMAL;
1437   m_window->m_resize_state = RESIZE_STATE_NORMAL;
14101438   return TRUE;
14111439}
14121440
r243398r243399
14161444
14171445void renderer::batch_vectors()
14181446{
1419   windows_options &options = downcast<windows_options &>(window().machine().options());
1447   windows_options &options = downcast<windows_options &>(m_window->machine().options());
14201448
14211449   int vector_size = (options.antialias() ? 24 : 6);
14221450   m_vectorbatch = mesh_alloc(m_line_count * vector_size);
r243398r243399
14261454   int line_index = 0;
14271455   float period = options.screen_vector_time_period();
14281456   UINT32 cached_flags = 0;
1429   for (render_primitive *prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
1457   for (render_primitive *prim = m_window->m_primlist->first(); prim != NULL; prim = prim->next())
14301458   {
14311459      switch (prim->type)
14321460      {
trunk/src/osd/windows/drawd3d.h
r243398r243399
9595};
9696
9797/* renderer is the information about Direct3D for the current screen */
98class renderer : public osd_renderer
98class renderer
9999{
100100public:
101   //renderer() { }
101   renderer() { }
102102   renderer(win_window_info *window);
103   virtual ~renderer();
103   ~renderer();
104104
105   virtual int init();
106   virtual render_primitive_list *get_primitives();
107   virtual int draw(HDC dc, int update);
108   virtual void save();
109   virtual void record();
110   virtual void toggle_fsfx();
111   virtual void destroy();
112
113105   int                     initialize();
114106
115107   int                     device_create();
r243398r243399
156148   int                     get_height() { return m_height; }
157149   int                     get_refresh() { return m_refresh; }
158150
151   win_window_info *       get_window() { return m_window; }
152
159153   device *                get_device() { return m_device; }
160154   present_parameters *    get_presentation() { return &m_presentation; }
161155
r243398r243399
187181   int                     m_refresh;                  // current refresh rate
188182   int                     m_create_error_count;       // number of consecutive create errors
189183
184   win_window_info *       m_window;                     // current window info
185
190186   device *                m_device;                   // pointer to the Direct3DDevice object
191187   int                     m_gamma_supported;          // is full screen gamma supported?
192188   present_parameters      m_presentation;             // set of presentation parameters
trunk/src/osd/windows/drawdd.c
r243398r243399
3636
3737
3838/* dd_info is the information about DirectDraw for the current screen */
39class renderer_dd : public osd_renderer
39struct dd_info
4040{
41public:
42   renderer_dd(win_window_info *window)
43   : osd_renderer(window, FLAG_NONE),
44      //adapter(0),
45      adapter_ptr(NULL),
46      clearouter(0),
47      blitwidth(0), blitheight(0),
48      //lastdest
49      ddraw(NULL),
50      primary(NULL),
51      back(NULL),
52      blit(NULL),
53      clipper(NULL),
54      gamma(NULL),
55      //DDSURFACEDESC2          primarydesc;
56      //DDSURFACEDESC2          blitdesc;
57      //DDSURFACEDESC2          origmode;
58      //ddcaps(0),
59      //helcaps(0),
60      membuffer(NULL),
61      membuffersize(NULL)
62   { }
63
64   virtual ~renderer_dd() { }
65
66   virtual int init();
67   virtual render_primitive_list *get_primitives();
68   virtual int draw(HDC dc, int update);
69   virtual void save() {};
70   virtual void record() {};
71   virtual void toggle_fsfx() {};
72   virtual void destroy();
73
74   int                     width, height;              // current width, height
75   int                     refresh;                    // current refresh rate
76
77private:
78
79   inline void update_outer_rects();
80
81   // surface management
82   int ddraw_create();
83   int ddraw_create_surfaces();
84   void ddraw_delete();
85   void ddraw_delete_surfaces();
86   int ddraw_verify_caps();
87   int ddraw_test_cooperative();
88   HRESULT create_surface(DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type);
89   int create_clipper();
90
91   // drawing helpers
92   void compute_blit_surface_size();
93   void blit_to_primary(int srcwidth, int srcheight);
94
95   // video modes
96   int config_adapter_mode();
97   void get_adapter_for_monitor(win_monitor_info *monitor);
98   void pick_best_mode();
99
100   // various
101   void calc_fullscreen_margins(DWORD desc_width, DWORD desc_height, RECT *margins);
102
103
10441   GUID                    adapter;                    // current display adapter
10542   GUID *                  adapter_ptr;                // pointer to current display adapter
43   int                     width, height;              // current width, height
44   int                     refresh;                    // current refresh rate
10645   int                     clearouter;                 // clear the outer areas?
10746
10847   INT32                   blitwidth, blitheight;      // current blit width/height values
r243398r243399
14079/* mode_enum_info holds information during a display mode enumeration */
14180struct mode_enum_info
14281{
143   win_window_info *      window;
82   win_window_info *       window;
14483   INT32                   minimum_width, minimum_height;
14584   INT32                   target_width, target_height;
14685   double                  target_refresh;
r243398r243399
163102//  INLINES
164103//============================================================
165104
166inline void renderer_dd::update_outer_rects()
105INLINE void update_outer_rects(dd_info *dd)
167106{
168   clearouter = (back != NULL) ? 3 : 1;
107   dd->clearouter = (dd->back != NULL) ? 3 : 1;
169108}
170109
171110
r243398r243399
184123
185124// core functions
186125static void drawdd_exit(void);
126static int drawdd_window_init(win_window_info *window);
127static void drawdd_window_destroy(win_window_info *window);
128static render_primitive_list *drawdd_window_get_primitives(win_window_info *window);
129static int drawdd_window_draw(win_window_info *window, HDC dc, int update);
187130
131// surface management
132static int ddraw_create(win_window_info *window);
133static int ddraw_create_surfaces(win_window_info *window);
134static void ddraw_delete(win_window_info *window);
135static void ddraw_delete_surfaces(win_window_info *window);
136static int ddraw_verify_caps(dd_info *dd);
137static int ddraw_test_cooperative(win_window_info *window);
138static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type);
139static int create_clipper(win_window_info *window);
188140
141// drawing helpers
142static void compute_blit_surface_size(win_window_info *window);
143static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight);
189144
190//============================================================
191//  drawnone_create
192//============================================================
145// video modes
146static int config_adapter_mode(win_window_info *window);
147static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor);
148static void pick_best_mode(win_window_info *window);
193149
194static osd_renderer *drawdd_create(win_window_info *window)
195{
196   return global_alloc(renderer_dd(window));
197}
198150
199151
200152//============================================================
201153//  drawdd_init
202154//============================================================
203155
204int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks)
156int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks)
205157{
206158   // dynamically grab the create function from ddraw.dll
207159   dllhandle = LoadLibrary(TEXT("ddraw.dll"));
r243398r243399
234186   // fill in the callbacks
235187   memset(callbacks, 0, sizeof(*callbacks));
236188   callbacks->exit = drawdd_exit;
237   callbacks->create = drawdd_create;
189   callbacks->window_init = drawdd_window_init;
190   callbacks->window_get_primitives = drawdd_window_get_primitives;
191   callbacks->window_draw = drawdd_window_draw;
192   callbacks->window_destroy = drawdd_window_destroy;
238193
239194   osd_printf_verbose("DirectDraw: Using DirectDraw 7\n");
240195   return 0;
r243398r243399
258213//  drawdd_window_init
259214//============================================================
260215
261int renderer_dd::init()
216static int drawdd_window_init(win_window_info *window)
262217{
218   dd_info *dd;
219
220   // allocate memory for our structures
221   dd = global_alloc_clear(dd_info);
222   window->m_drawdata = dd;
223
263224   // configure the adapter for the mode we want
264   if (config_adapter_mode())
225   if (config_adapter_mode(window))
265226      goto error;
266227
267228   // create the ddraw object
268   if (ddraw_create())
229   if (ddraw_create(window))
269230      goto error;
270231
271232   return 0;
272233
273234error:
274   destroy();
235   drawdd_window_destroy(window);
275236   osd_printf_error("Unable to initialize DirectDraw.\n");
276237   return 1;
277238}
r243398r243399
282243//  drawdd_window_destroy
283244//============================================================
284245
285void renderer_dd::destroy()
246static void drawdd_window_destroy(win_window_info *window)
286247{
248   dd_info *dd = (dd_info *)window->m_drawdata;
249
250   // skip if nothing
251   if (dd == NULL)
252      return;
253
287254   // delete the ddraw object
288   ddraw_delete();
255   ddraw_delete(window);
256
257   // free the memory in the window
258   global_free(dd);
259   window->m_drawdata = NULL;
289260}
290261
291262
r243398r243399
294265//  drawdd_window_get_primitives
295266//============================================================
296267
297render_primitive_list *renderer_dd::get_primitives()
268static render_primitive_list *drawdd_window_get_primitives(win_window_info *window)
298269{
299   compute_blit_surface_size();
300   window().m_target->set_bounds(blitwidth, blitheight, 0);
301   window().m_target->set_max_update_rate((refresh == 0) ? origmode.dwRefreshRate : refresh);
270   dd_info *dd = (dd_info *)window->m_drawdata;
302271
303   return &window().m_target->get_primitives();
272   compute_blit_surface_size(window);
273   window->m_target->set_bounds(dd->blitwidth, dd->blitheight, 0);
274   window->m_target->set_max_update_rate((dd->refresh == 0) ? dd->origmode.dwRefreshRate : dd->refresh);
275
276   return &window->m_target->get_primitives();
304277}
305278
306279
r243398r243399
309282//  drawdd_window_draw
310283//============================================================
311284
312int renderer_dd::draw(HDC dc, int update)
285static int drawdd_window_draw(win_window_info *window, HDC dc, int update)
313286{
287   dd_info *dd = (dd_info *)window->m_drawdata;
314288   render_primitive *prim;
315289   int usemembuffer = FALSE;
316290   HRESULT result;
317291
292   // if we haven't been created, just punt
293   if (dd == NULL)
294      return 1;
295
318296   // if we're updating, remember to erase the outer stuff
319297   if (update)
320      update_outer_rects();
298      update_outer_rects(dd);
321299
322300   // if we have a ddraw object, check the cooperative level
323   if (ddraw_test_cooperative())
301   if (ddraw_test_cooperative(window))
324302      return 1;
325303
326304   // get the size; if we're too small, delete the existing surfaces
327   if (blitwidth > blitdesc.dwWidth || blitheight > blitdesc.dwHeight)
328      ddraw_delete_surfaces();
305   if (dd->blitwidth > dd->blitdesc.dwWidth || dd->blitheight > dd->blitdesc.dwHeight)
306      ddraw_delete_surfaces(window);
329307
330308   // if we need to create surfaces, do it now
331   if (blit == NULL && ddraw_create_surfaces() != 0)
309   if (dd->blit == NULL && ddraw_create_surfaces(window) != 0)
332310      return 1;
333311
334312   // select our surface and lock it
335   result = IDirectDrawSurface7_Lock(blit, NULL, &blitdesc, DDLOCK_WAIT, NULL);
313   result = IDirectDrawSurface7_Lock(dd->blit, NULL, &dd->blitdesc, DDLOCK_WAIT, NULL);
336314   if (result == DDERR_SURFACELOST)
337315   {
338316      osd_printf_verbose("DirectDraw: Lost surfaces; deleting and retrying next frame\n");
339      ddraw_delete_surfaces();
317      ddraw_delete_surfaces(window);
340318      return 1;
341319   }
342320   if (result != DD_OK)
r243398r243399
346324   }
347325
348326   // render to it
349   window().m_primlist->acquire_lock();
327   window->m_primlist->acquire_lock();
350328
351329   // scan the list of primitives for tricky stuff
352   for (prim = window().m_primlist->first(); prim != NULL; prim = prim->next())
330   for (prim = window->m_primlist->first(); prim != NULL; prim = prim->next())
353331      if (PRIMFLAG_GET_BLENDMODE(prim->flags) != BLENDMODE_NONE ||
354332         (prim->texture.base != NULL && PRIMFLAG_GET_TEXFORMAT(prim->flags) == TEXFORMAT_ARGB32))
355333      {
r243398r243399
363341      int x, y;
364342
365343      // based on the target format, use one of our standard renderers
366      switch (blitdesc.ddpfPixelFormat.dwRBitMask)
344      switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask)
367345      {
368         case 0x00ff0000:    software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
369         case 0x000000ff:    software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
370         case 0xf800:        software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
371         case 0x7c00:        software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window().m_primlist, membuffer, blitwidth, blitheight, blitwidth);  break;
346         case 0x00ff0000:    software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth);  break;
347         case 0x000000ff:    software_renderer<UINT32, 0,0,0, 0,8,16>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth);  break;
348         case 0xf800:        software_renderer<UINT16, 3,2,3, 11,5,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth);  break;
349         case 0x7c00:        software_renderer<UINT16, 3,3,3, 10,5,0>::draw_primitives(*window->m_primlist, dd->membuffer, dd->blitwidth, dd->blitheight, dd->blitwidth);  break;
372350         default:
373            osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)blitdesc.ddpfPixelFormat.dwRBitMask, (int)blitdesc.ddpfPixelFormat.dwGBitMask, (int)blitdesc.ddpfPixelFormat.dwBBitMask);
351            osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->blitdesc.ddpfPixelFormat.dwRBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwGBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwBBitMask);
374352            break;
375353      }
376354
377355      // handle copying to both 16bpp and 32bpp destinations
378      for (y = 0; y < blitheight; y++)
356      for (y = 0; y < dd->blitheight; y++)
379357      {
380         if (blitdesc.ddpfPixelFormat.dwRGBBitCount == 32)
358         if (dd->blitdesc.ddpfPixelFormat.dwRGBBitCount == 32)
381359         {
382            UINT32 *src = (UINT32 *)membuffer + y * blitwidth;
383            UINT32 *dst = (UINT32 *)((UINT8 *)blitdesc.lpSurface + y * blitdesc.lPitch);
384            for (x = 0; x < blitwidth; x++)
360            UINT32 *src = (UINT32 *)dd->membuffer + y * dd->blitwidth;
361            UINT32 *dst = (UINT32 *)((UINT8 *)dd->blitdesc.lpSurface + y * dd->blitdesc.lPitch);
362            for (x = 0; x < dd->blitwidth; x++)
385363               *dst++ = *src++;
386364         }
387         else if (blitdesc.ddpfPixelFormat.dwRGBBitCount == 16)
365         else if (dd->blitdesc.ddpfPixelFormat.dwRGBBitCount == 16)
388366         {
389            UINT16 *src = (UINT16 *)membuffer + y * blitwidth;
390            UINT16 *dst = (UINT16 *)((UINT8 *)blitdesc.lpSurface + y * blitdesc.lPitch);
391            for (x = 0; x < blitwidth; x++)
367            UINT16 *src = (UINT16 *)dd->membuffer + y * dd->blitwidth;
368            UINT16 *dst = (UINT16 *)((UINT8 *)dd->blitdesc.lpSurface + y * dd->blitdesc.lPitch);
369            for (x = 0; x < dd->blitwidth; x++)
392370               *dst++ = *src++;
393371         }
394372      }
r243398r243399
399377   else
400378   {
401379      // based on the target format, use one of our standard renderers
402      switch (blitdesc.ddpfPixelFormat.dwRBitMask)
380      switch (dd->blitdesc.ddpfPixelFormat.dwRBitMask)
403381      {
404         case 0x00ff0000:    software_renderer<UINT32, 0,0,0, 16,8,0, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 4); break;
405         case 0x000000ff:    software_renderer<UINT32, 0,0,0, 0,8,16, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 4); break;
406         case 0xf800:        software_renderer<UINT16, 3,2,3, 11,5,0, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 2); break;
407         case 0x7c00:        software_renderer<UINT16, 3,3,3, 10,5,0, true>::draw_primitives(*window().m_primlist, blitdesc.lpSurface, blitwidth, blitheight, blitdesc.lPitch / 2); break;
382         case 0x00ff0000:    software_renderer<UINT32, 0,0,0, 16,8,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break;
383         case 0x000000ff:    software_renderer<UINT32, 0,0,0, 0,8,16, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 4); break;
384         case 0xf800:        software_renderer<UINT16, 3,2,3, 11,5,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break;
385         case 0x7c00:        software_renderer<UINT16, 3,3,3, 10,5,0, true>::draw_primitives(*window->m_primlist, dd->blitdesc.lpSurface, dd->blitwidth, dd->blitheight, dd->blitdesc.lPitch / 2); break;
408386         default:
409            osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)blitdesc.ddpfPixelFormat.dwRBitMask, (int)blitdesc.ddpfPixelFormat.dwGBitMask, (int)blitdesc.ddpfPixelFormat.dwBBitMask);
387            osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->blitdesc.ddpfPixelFormat.dwRBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwGBitMask, (int)dd->blitdesc.ddpfPixelFormat.dwBBitMask);
410388            break;
411389      }
412390   }
413   window().m_primlist->release_lock();
391   window->m_primlist->release_lock();
414392
415393   // unlock and blit
416   result = IDirectDrawSurface7_Unlock(blit, NULL);
394   result = IDirectDrawSurface7_Unlock(dd->blit, NULL);
417395   if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X unlocking blit surface\n", (int)result);
418396
419397   // sync to VBLANK
420   if ((video_config.waitvsync || video_config.syncrefresh) && window().machine().video().throttled() && (!window().m_fullscreen || back == NULL))
398   if ((video_config.waitvsync || video_config.syncrefresh) && window->machine().video().throttled() && (!window->m_fullscreen || dd->back == NULL))
421399   {
422      result = IDirectDraw7_WaitForVerticalBlank(ddraw, DDWAITVB_BLOCKBEGIN, NULL);
400      result = IDirectDraw7_WaitForVerticalBlank(dd->ddraw, DDWAITVB_BLOCKBEGIN, NULL);
423401      if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
424402   }
425403
426404   // complete the blitting
427   blit_to_primary(blitwidth, blitheight);
405   blit_to_primary(window, dd->blitwidth, dd->blitheight);
428406   return 0;
429407}
430408
r243398r243399
434412//  ddraw_create
435413//============================================================
436414
437int renderer_dd::ddraw_create()
415static int ddraw_create(win_window_info *window)
438416{
417   dd_info *dd = (dd_info *)window->m_drawdata;
439418   HRESULT result;
440419   int verify;
441420
442421   // if a device exists, free it
443   if (ddraw != NULL)
444      ddraw_delete();
422   if (dd->ddraw != NULL)
423      ddraw_delete(window);
445424
446425   // create the DirectDraw object
447   result = (*directdrawcreateex)(adapter_ptr, (LPVOID *)&ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
426   result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
448427   if (result != DD_OK)
449428   {
450429      osd_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
r243398r243399
452431   }
453432
454433   // verify the caps
455   verify = ddraw_verify_caps();
434   verify = ddraw_verify_caps(dd);
456435   if (verify == 2)
457436   {
458437      osd_printf_error("DirectDraw: Error - Device does not meet minimum requirements for DirectDraw rendering\n");
r243398r243399
463442
464443   // set the cooperative level
465444   // for non-window modes, we will use full screen here
466   result = IDirectDraw7_SetCooperativeLevel(ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW);
445   result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, win_window_list->m_hwnd, DDSCL_SETFOCUSWINDOW);
467446   if (result != DD_OK)
468447   {
469448      osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(FOCUSWINDOW) call\n", (int)result);
470449      goto error;
471450   }
472   result = IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_SETDEVICEWINDOW | (window().m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
451   result = IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_SETDEVICEWINDOW | (window->m_fullscreen ? DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE : DDSCL_NORMAL));
473452   if (result != DD_OK)
474453   {
475454      osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_SetCooperativeLevel(DEVICEWINDOW) call\n", (int)result);
r243398r243399
477456   }
478457
479458   // full screen mode: set the resolution
480   if (window().m_fullscreen && video_config.switchres)
459   if (window->m_fullscreen && video_config.switchres)
481460   {
482      result = IDirectDraw7_SetDisplayMode(ddraw, width, height, 32, refresh, 0);
461      result = IDirectDraw7_SetDisplayMode(dd->ddraw, dd->width, dd->height, 32, dd->refresh, 0);
483462      if (result != DD_OK)
484463      {
485         osd_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, width, height, refresh);
464         osd_printf_verbose("DirectDraw: Error %08X attempting to set video mode %dx%d@%d call\n", (int)result, dd->width, dd->height, dd->refresh);
486465         goto error;
487466      }
488467   }
489468
490   return ddraw_create_surfaces();
469   return ddraw_create_surfaces(window);
491470
492471error:
493   ddraw_delete();
472   ddraw_delete(window);
494473   return 1;
495474}
496475
r243398r243399
500479//  ddraw_create_surfaces
501480//============================================================
502481
503int renderer_dd::ddraw_create_surfaces()
482static int ddraw_create_surfaces(win_window_info *window)
504483{
484   dd_info *dd = (dd_info *)window->m_drawdata;
505485   HRESULT result;
506486
507487   // make a description of the primary surface
508   memset(&primarydesc, 0, sizeof(primarydesc));
509   primarydesc.dwSize = sizeof(primarydesc);
510   primarydesc.dwFlags = DDSD_CAPS;
511   primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
488   memset(&dd->primarydesc, 0, sizeof(dd->primarydesc));
489   dd->primarydesc.dwSize = sizeof(dd->primarydesc);
490   dd->primarydesc.dwFlags = DDSD_CAPS;
491   dd->primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
512492
513493   // for triple-buffered full screen mode, allocate flipping surfaces
514   if (window().m_fullscreen && video_config.triplebuf)
494   if (window->m_fullscreen && video_config.triplebuf)
515495   {
516      primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
517      primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
518      primarydesc.dwBackBufferCount = 2;
496      dd->primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
497      dd->primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
498      dd->primarydesc.dwBackBufferCount = 2;
519499   }
520500
521501   // create the primary surface and report errors
522   result = create_surface(&primarydesc, &primary, "primary");
502   result = create_surface(dd, &dd->primarydesc, &dd->primary, "primary");
523503   if (result != DD_OK) goto error;
524504
525505   // full screen mode: get the back surface
526   back = NULL;
527   if (window().m_fullscreen && video_config.triplebuf)
506   dd->back = NULL;
507   if (window->m_fullscreen && video_config.triplebuf)
528508   {
529509      DDSCAPS2 caps = { DDSCAPS_BACKBUFFER };
530      result = IDirectDrawSurface7_GetAttachedSurface(primary, &caps, &back);
510      result = IDirectDrawSurface7_GetAttachedSurface(dd->primary, &caps, &dd->back);
531511      if (result != DD_OK)
532512      {
533513         osd_printf_verbose("DirectDraw: Error %08X getting attached back surface\n", (int)result);
r243398r243399
536516   }
537517
538518   // now make a description of our blit surface, based on the primary surface
539   if (blitwidth == 0 || blitheight == 0)
540      compute_blit_surface_size();
541   blitdesc = primarydesc;
542   blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
543   blitdesc.dwWidth = blitwidth;
544   blitdesc.dwHeight = blitheight;
545   blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
519   if (dd->blitwidth == 0 || dd->blitheight == 0)
520      compute_blit_surface_size(window);
521   dd->blitdesc = dd->primarydesc;
522   dd->blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
523   dd->blitdesc.dwWidth = dd->blitwidth;
524   dd->blitdesc.dwHeight = dd->blitheight;
525   dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
546526
547527   // then create the blit surface, fall back to system memory if video mem doesn't work
548   result = create_surface(&blitdesc, &blit, "blit");
528   result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
549529   if (result != DD_OK)
550530   {
551      blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
552      result = create_surface(&blitdesc, &blit, "blit");
531      dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
532      result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit");
553533   }
554534   if (result != DD_OK) goto error;
555535
556536   // create a memory buffer for offscreen drawing
557   if (membuffersize < blitwidth * blitheight * 4)
537   if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4)
558538   {
559      membuffersize = blitwidth * blitheight * 4;
560      global_free_array(membuffer);
561      membuffer = global_alloc_array(UINT8, membuffersize);
539      dd->membuffersize = dd->blitwidth * dd->blitheight * 4;
540      global_free_array(dd->membuffer);
541      dd->membuffer = global_alloc_array(UINT8, dd->membuffersize);
562542   }
563   if (membuffer == NULL)
543   if (dd->membuffer == NULL)
564544      goto error;
565545
566546   // create a clipper for windowed mode
567   if (!window().m_fullscreen && create_clipper())
547   if (!window->m_fullscreen && create_clipper(window))
568548      goto error;
569549
570550   // full screen mode: set the gamma
571   if (window().m_fullscreen)
551   if (window->m_fullscreen)
572552   {
573553      // only set the gamma if it's not 1.0f
574      windows_options &options = downcast<windows_options &>(window().machine().options());
554      windows_options &options = downcast<windows_options &>(window->machine().options());
575555      float brightness = options.full_screen_brightness();
576556      float contrast = options.full_screen_contrast();
577      float fgamma = options.full_screen_gamma();
578      if (brightness != 1.0f || contrast != 1.0f || fgamma != 1.0f)
557      float gamma = options.full_screen_gamma();
558      if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f)
579559      {
580560         // see if we can get a GammaControl object
581         result = IDirectDrawSurface_QueryInterface(primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&gamma);
561         result = IDirectDrawSurface_QueryInterface(dd->primary, WRAP_REFIID(IID_IDirectDrawGammaControl), (void **)&dd->gamma);
582562         if (result != DD_OK)
583563         {
584564            osd_printf_warning("DirectDraw: Warning - device does not support full screen gamma correction.\n");
585            this->gamma = NULL;
565            dd->gamma = NULL;
586566         }
587567
588568         // proceed if we can
589         if (this->gamma != NULL)
569         if (dd->gamma != NULL)
590570         {
591571            DDGAMMARAMP ramp;
592572            int i;
593573
594574            // create a standard ramp and set it
595575            for (i = 0; i < 256; i++)
596               ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, fgamma) << 8;
576               ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8;
597577
598578            // attempt to set it
599            result = IDirectDrawGammaControl_SetGammaRamp(this->gamma, 0, &ramp);
579            result = IDirectDrawGammaControl_SetGammaRamp(dd->gamma, 0, &ramp);
600580            if (result != DD_OK)
601581               osd_printf_verbose("DirectDraw: Error %08X attempting to set gamma correction.\n", (int)result);
602582         }
r243398r243399
604584   }
605585
606586   // force some updates
607   update_outer_rects();
587   update_outer_rects(dd);
608588   return 0;
609589
610590error:
611   ddraw_delete_surfaces();
591   ddraw_delete_surfaces(window);
612592   return 1;
613593}
614594
r243398r243399
618598//  ddraw_delete
619599//============================================================
620600
621void renderer_dd::ddraw_delete()
601static void ddraw_delete(win_window_info *window)
622602{
603   dd_info *dd = (dd_info *)window->m_drawdata;
604
623605   // free surfaces
624   ddraw_delete_surfaces();
606   ddraw_delete_surfaces(window);
625607
626608   // restore resolutions
627   if (ddraw != NULL)
628      IDirectDraw7_RestoreDisplayMode(ddraw);
609   if (dd->ddraw != NULL)
610      IDirectDraw7_RestoreDisplayMode(dd->ddraw);
629611
630612   // reset cooperative level
631   if (ddraw != NULL && window().m_hwnd != NULL)
632      IDirectDraw7_SetCooperativeLevel(ddraw, window().m_hwnd, DDSCL_NORMAL);
613   if (dd->ddraw != NULL && window->m_hwnd != NULL)
614      IDirectDraw7_SetCooperativeLevel(dd->ddraw, window->m_hwnd, DDSCL_NORMAL);
633615
634616   // release the DirectDraw object itself
635   if (ddraw != NULL)
636      IDirectDraw7_Release(ddraw);
637   ddraw = NULL;
617   if (dd->ddraw != NULL)
618      IDirectDraw7_Release(dd->ddraw);
619   dd->ddraw = NULL;
638620}
639621
640622
r243398r243399
643625//  ddraw_delete_surfaces
644626//============================================================
645627
646void renderer_dd::ddraw_delete_surfaces()
628static void ddraw_delete_surfaces(win_window_info *window)
647629{
630   dd_info *dd = (dd_info *)window->m_drawdata;
631
648632   // release the gamma control
649   if (gamma != NULL)
650      IDirectDrawGammaControl_Release(gamma);
651   gamma = NULL;
633   if (dd->gamma != NULL)
634      IDirectDrawGammaControl_Release(dd->gamma);
635   dd->gamma = NULL;
652636
653637   // release the clipper
654   if (clipper != NULL)
655      IDirectDrawClipper_Release(clipper);
656   clipper = NULL;
638   if (dd->clipper != NULL)
639      IDirectDrawClipper_Release(dd->clipper);
640   dd->clipper = NULL;
657641
658642   // free the memory buffer
659   global_free_array(membuffer);
660   membuffer = NULL;
661   membuffersize = 0;
643   global_free_array(dd->membuffer);
644   dd->membuffer = NULL;
645   dd->membuffersize = 0;
662646
663647   // release the blit surface
664   if (blit != NULL)
665      IDirectDrawSurface7_Release(blit);
666   blit = NULL;
648   if (dd->blit != NULL)
649      IDirectDrawSurface7_Release(dd->blit);
650   dd->blit = NULL;
667651
668652   // release the back surface
669   if (back != NULL)
670      IDirectDrawSurface7_Release(back);
671   back = NULL;
653   if (dd->back != NULL)
654      IDirectDrawSurface7_Release(dd->back);
655   dd->back = NULL;
672656
673657   // release the primary surface
674   if (primary != NULL)
675      IDirectDrawSurface7_Release(primary);
676   primary = NULL;
658   if (dd->primary != NULL)
659      IDirectDrawSurface7_Release(dd->primary);
660   dd->primary = NULL;
677661}
678662
679663
r243398r243399
682666//  ddraw_verify_caps
683667//============================================================
684668
685int renderer_dd::ddraw_verify_caps()
669static int ddraw_verify_caps(dd_info *dd)
686670{
687671   int retval = 0;
688672   HRESULT result;
689673
690674   // get the capabilities
691   ddcaps.dwSize = sizeof(ddcaps);
692   helcaps.dwSize = sizeof(helcaps);
693   result = IDirectDraw7_GetCaps(ddraw, &ddcaps, &helcaps);
675   dd->ddcaps.dwSize = sizeof(dd->ddcaps);
676   dd->helcaps.dwSize = sizeof(dd->helcaps);
677   result = IDirectDraw7_GetCaps(dd->ddraw, &dd->ddcaps, &dd->helcaps);
694678   if (result != DD_OK)
695679   {
696680      osd_printf_verbose("DirectDraw: Error %08X during IDirectDraw7_GetCaps call\n", (int)result);
r243398r243399
698682   }
699683
700684   // determine if hardware stretching is available
701   if ((ddcaps.dwCaps & DDCAPS_BLTSTRETCH) == 0)
685   if ((dd->ddcaps.dwCaps & DDCAPS_BLTSTRETCH) == 0)
702686   {
703687      osd_printf_verbose("DirectDraw: Warning - Device does not support hardware stretching\n");
704688      retval = 1;
r243398r243399
713697//  ddraw_test_cooperative
714698//============================================================
715699
716int renderer_dd::ddraw_test_cooperative()
700static int ddraw_test_cooperative(win_window_info *window)
717701{
702   dd_info *dd = (dd_info *)window->m_drawdata;
718703   HRESULT result;
719704
720705   // check our current status; if we lost the device, punt to GDI
721   result = IDirectDraw7_TestCooperativeLevel(ddraw);
706   result = IDirectDraw7_TestCooperativeLevel(dd->ddraw);
722707   switch (result)
723708   {
724709      // punt to GDI if someone else has exclusive mode
725710      case DDERR_NOEXCLUSIVEMODE:
726711      case DDERR_EXCLUSIVEMODEALREADYSET:
727         ddraw_delete_surfaces();
712         ddraw_delete_surfaces(window);
728713         return 1;
729714
730715      // if we're ok, but we don't have a primary surface, create one
731716      default:
732717      case DD_OK:
733         if (primary == NULL)
734            return ddraw_create_surfaces();
718         if (dd->primary == NULL)
719            return ddraw_create_surfaces(window);
735720         return 0;
736721   }
737722}
r243398r243399
742727//  create_surface
743728//============================================================
744729
745HRESULT renderer_dd::create_surface(DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
730static HRESULT create_surface(dd_info *dd, DDSURFACEDESC2 *desc, IDirectDrawSurface7 **surface, const char *type)
746731{
747732   HRESULT result;
748733
749734   // create the surface as requested
750   result = IDirectDraw7_CreateSurface(ddraw, desc, surface, NULL);
735   result = IDirectDraw7_CreateSurface(dd->ddraw, desc, surface, NULL);
751736   if (result != DD_OK)
752737   {
753738      osd_printf_verbose("DirectDraw: Error %08X creating %s surface\n", (int)result, type);
r243398r243399
782767//  create_clipper
783768//============================================================
784769
785int renderer_dd::create_clipper()
770static int create_clipper(win_window_info *window)
786771{
772   dd_info *dd = (dd_info *)window->m_drawdata;
787773   HRESULT result;
788774
789775   // create a clipper for the primary surface
790   result = IDirectDraw7_CreateClipper(ddraw, 0, &clipper, NULL);
776   result = IDirectDraw7_CreateClipper(dd->ddraw, 0, &dd->clipper, NULL);
791777   if (result != DD_OK)
792778   {
793779      osd_printf_verbose("DirectDraw: Error %08X creating clipper\n", (int)result);
r243398r243399
795781   }
796782
797783   // set the clipper's hwnd
798   result = IDirectDrawClipper_SetHWnd(clipper, 0, window().m_hwnd);
784   result = IDirectDrawClipper_SetHWnd(dd->clipper, 0, window->m_hwnd);
799785   if (result != DD_OK)
800786   {
801787      osd_printf_verbose("DirectDraw: Error %08X setting clipper hwnd\n", (int)result);
r243398r243399
803789   }
804790
805791   // set the clipper on the primary surface
806   result = IDirectDrawSurface7_SetClipper(primary, clipper);
792   result = IDirectDrawSurface7_SetClipper(dd->primary, dd->clipper);
807793   if (result != DD_OK)
808794   {
809795      osd_printf_verbose("DirectDraw: Error %08X setting clipper on primary surface\n", (int)result);
r243398r243399
818804//  compute_blit_surface_size
819805//============================================================
820806
821void renderer_dd::compute_blit_surface_size()
807static void compute_blit_surface_size(win_window_info *window)
822808{
809   dd_info *dd = (dd_info *)window->m_drawdata;
823810   INT32 newwidth, newheight;
824811   int xscale, yscale;
825812   RECT client;
826813
827814   // start with the minimum size
828   window().m_target->compute_minimum_size(newwidth, newheight);
815   window->m_target->compute_minimum_size(newwidth, newheight);
829816
830817   // get the window's client rectangle
831   GetClientRect(window().m_hwnd, &client);
818   GetClientRect(window->m_hwnd, &client);
832819
833820   // hardware stretch case: apply prescale
834821   if (video_config.hwstretch)
r243398r243399
854841      // compute the appropriate visible area if we're trying to keepaspect
855842      if (video_config.keepaspect)
856843      {
857         win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL);
858         window().m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window().m_target->orientation(), target_width, target_height);
844         win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL);
845         window->m_target->compute_visible_area(target_width, target_height, monitor->get_aspect(), window->m_target->orientation(), target_width, target_height);
859846         desired_aspect = (float)target_width / (float)target_height;
860847      }
861848
r243398r243399
897884   // apply the final scale
898885   newwidth *= xscale;
899886   newheight *= yscale;
900   if (newwidth != blitwidth || newheight != blitheight)
887   if (newwidth != dd->blitwidth || newheight != dd->blitheight)
901888   {
902889      // force some updates
903      update_outer_rects();
890      update_outer_rects(dd);
904891      osd_printf_verbose("DirectDraw: New blit size = %dx%d\n", newwidth, newheight);
905892   }
906   blitwidth = newwidth;
907   blitheight = newheight;
893   dd->blitwidth = newwidth;
894   dd->blitheight = newheight;
908895}
909896
910897
r243398r243399
913900//  calc_fullscreen_margins
914901//============================================================
915902
916void renderer_dd::calc_fullscreen_margins(DWORD desc_width, DWORD desc_height, RECT *margins)
903static void calc_fullscreen_margins(win_window_info *window, DWORD desc_width, DWORD desc_height, RECT *margins)
917904{
918905   margins->left = 0;
919906   margins->top = 0;
920907   margins->right = desc_width;
921908   margins->bottom = desc_height;
922909
923   if (win_has_menu(&window()))
910   if (win_has_menu(window))
924911   {
925912      static int height_with_menubar = 0;
926913      if (height_with_menubar == 0)
r243398r243399
941928//  blit_to_primary
942929//============================================================
943930
944void renderer_dd::blit_to_primary(int srcwidth, int srcheight)
931static void blit_to_primary(win_window_info *window, int srcwidth, int srcheight)
945932{
946   IDirectDrawSurface7 *target = (back != NULL) ? back : primary;
947   win_monitor_info *monitor = winwindow_video_window_monitor(&window(), NULL);
933   dd_info *dd = (dd_info *)window->m_drawdata;
934   IDirectDrawSurface7 *target = (dd->back != NULL) ? dd->back : dd->primary;
935   win_monitor_info *monitor = winwindow_video_window_monitor(window, NULL);
948936   DDBLTFX blitfx = { sizeof(DDBLTFX) };
949937   RECT clear, outer, dest, source;
950938   INT32 dstwidth, dstheight;
r243398r243399
956944   source.bottom = srcheight;
957945
958946   // compute outer rect -- windowed version
959   if (!window().m_fullscreen)
947   if (!window->m_fullscreen)
960948   {
961      GetClientRect(window().m_hwnd, &outer);
962      ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[0]);
963      ClientToScreen(window().m_hwnd, &((LPPOINT)&outer)[1]);
949      GetClientRect(window->m_hwnd, &outer);
950      ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[0]);
951      ClientToScreen(window->m_hwnd, &((LPPOINT)&outer)[1]);
964952
965953      // adjust to be relative to the monitor
966954      outer.left -= monitor->info.rcMonitor.left;
r243398r243399
972960   // compute outer rect -- full screen version
973961   else
974962   {
975      calc_fullscreen_margins(primarydesc.dwWidth, primarydesc.dwHeight, &outer);
963      calc_fullscreen_margins(window, dd->primarydesc.dwWidth, dd->primarydesc.dwHeight, &outer);
976964   }
977965
978966   // if we're respecting the aspect ratio, we need to adjust to fit
r243398r243399
999987   else if (video_config.keepaspect)
1000988   {
1001989      // compute the appropriate visible area
1002      window().m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window().m_target->orientation(), dstwidth, dstheight);
990      window->m_target->compute_visible_area(rect_width(&outer), rect_height(&outer), monitor->get_aspect(), window->m_target->orientation(), dstwidth, dstheight);
1003991   }
1004992
1005993   // center within
r243398r243399
1009997   dest.bottom = dest.top + dstheight;
1010998
1011999   // compare against last destination; if different, force a redraw
1012   if (dest.left != lastdest.left || dest.right != lastdest.right || dest.top != lastdest.top || dest.bottom != lastdest.bottom)
1000   if (dest.left != dd->lastdest.left || dest.right != dd->lastdest.right || dest.top != dd->lastdest.top || dest.bottom != dd->lastdest.bottom)
10131001   {
1014      lastdest = dest;
1015      update_outer_rects();
1002      dd->lastdest = dest;
1003      update_outer_rects(dd);
10161004   }
10171005
10181006   // clear outer rects if we need to
1019   if (clearouter != 0)
1007   if (dd->clearouter != 0)
10201008   {
1021      clearouter--;
1009      dd->clearouter--;
10221010
10231011      // clear the left edge
10241012      if (dest.left > outer.left)
r243398r243399
10581046   }
10591047
10601048   // do the blit
1061   result = IDirectDrawSurface7_Blt(target, &dest, blit, &source, DDBLT_WAIT, NULL);
1049   result = IDirectDrawSurface7_Blt(target, &dest, dd->blit, &source, DDBLT_WAIT, NULL);
10621050   if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X blitting to the screen\n", (int)result);
10631051
10641052   // page flip if triple buffered
1065   if (window().m_fullscreen && back != NULL)
1053   if (window->m_fullscreen && dd->back != NULL)
10661054   {
1067      result = IDirectDrawSurface7_Flip(primary, NULL, DDFLIP_WAIT);
1055      result = IDirectDrawSurface7_Flip(dd->primary, NULL, DDFLIP_WAIT);
10681056      if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
10691057   }
10701058}
r243398r243399
10751063//  config_adapter_mode
10761064//============================================================
10771065
1078int renderer_dd::config_adapter_mode()
1066static int config_adapter_mode(win_window_info *window)
10791067{
10801068   DDDEVICEIDENTIFIER2 identifier;
1069   dd_info *dd = (dd_info *)window->m_drawdata;
10811070   HRESULT result;
10821071
10831072   // choose the monitor number
1084   get_adapter_for_monitor(window().m_monitor);
1073   get_adapter_for_monitor(dd, window->m_monitor);
10851074
10861075   // create a temporary DirectDraw object
1087   result = (*directdrawcreateex)(adapter_ptr, (LPVOID *)&ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
1076   result = (*directdrawcreateex)(dd->adapter_ptr, (LPVOID *)&dd->ddraw, WRAP_REFIID(IID_IDirectDraw7), NULL);
10881077   if (result != DD_OK)
10891078   {
10901079      osd_printf_verbose("DirectDraw: Error %08X during DirectDrawCreateEx call\n", (int)result);
r243398r243399
10921081   }
10931082
10941083   // get the identifier
1095   result = IDirectDraw7_GetDeviceIdentifier(ddraw, &identifier, 0);
1084   result = IDirectDraw7_GetDeviceIdentifier(dd->ddraw, &identifier, 0);
10961085   if (result != DD_OK)
10971086   {
10981087      osd_printf_error("Error getting identifier for device\n");
r243398r243399
11011090   osd_printf_verbose("DirectDraw: Configuring device %s\n", identifier.szDescription);
11021091
11031092   // get the current display mode
1104   memset(&origmode, 0, sizeof(origmode));
1105   origmode.dwSize = sizeof(origmode);
1106   result = IDirectDraw7_GetDisplayMode(ddraw, &origmode);
1093   memset(&dd->origmode, 0, sizeof(dd->origmode));
1094   dd->origmode.dwSize = sizeof(dd->origmode);
1095   result = IDirectDraw7_GetDisplayMode(dd->ddraw, &dd->origmode);
11071096   if (result != DD_OK)
11081097   {
11091098      osd_printf_verbose("DirectDraw: Error %08X getting current display mode\n", (int)result);
1110      IDirectDraw7_Release(ddraw);
1099      IDirectDraw7_Release(dd->ddraw);
11111100      return 1;
11121101   }
11131102
11141103   // choose a resolution: full screen mode case
1115   if (window().m_fullscreen)
1104   if (window->m_fullscreen)
11161105   {
11171106      // default to the current mode exactly
1118      width = origmode.dwWidth;
1119      height = origmode.dwHeight;
1120      refresh = origmode.dwRefreshRate;
1107      dd->width = dd->origmode.dwWidth;
1108      dd->height = dd->origmode.dwHeight;
1109      dd->refresh = dd->origmode.dwRefreshRate;
11211110
11221111      // if we're allowed to switch resolutions, override with something better
11231112      if (video_config.switchres)
1124         pick_best_mode();
1113         pick_best_mode(window);
11251114   }
11261115
11271116   // release the DirectDraw object
1128   IDirectDraw7_Release(ddraw);
1129   ddraw = NULL;
1117   IDirectDraw7_Release(dd->ddraw);
1118   dd->ddraw = NULL;
11301119
11311120   // if we're not changing resolutions, make sure we have a resolution we can handle
1132   if (!window().m_fullscreen || !video_config.switchres)
1121   if (!window->m_fullscreen || !video_config.switchres)
11331122   {
1134      switch (origmode.ddpfPixelFormat.dwRBitMask)
1123      switch (dd->origmode.ddpfPixelFormat.dwRBitMask)
11351124      {
11361125         case 0x00ff0000:
11371126         case 0x000000ff:
r243398r243399
11401129            break;
11411130
11421131         default:
1143            osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)origmode.ddpfPixelFormat.dwRBitMask, (int)origmode.ddpfPixelFormat.dwGBitMask, (int)origmode.ddpfPixelFormat.dwBBitMask);
1132            osd_printf_verbose("DirectDraw: Unknown target mode: R=%08X G=%08X B=%08X\n", (int)dd->origmode.ddpfPixelFormat.dwRBitMask, (int)dd->origmode.ddpfPixelFormat.dwGBitMask, (int)dd->origmode.ddpfPixelFormat.dwBBitMask);
11441133            return 1;
11451134      }
11461135   }
r243398r243399
11751164//  get_adapter_for_monitor
11761165//============================================================
11771166
1178void renderer_dd::get_adapter_for_monitor(win_monitor_info *monitor)
1167static void get_adapter_for_monitor(dd_info *dd, win_monitor_info *monitor)
11791168{
11801169   monitor_enum_info einfo;
11811170   HRESULT result;
r243398r243399
11891178   // set up the adapter
11901179   if (einfo.foundit && einfo.guid_ptr != NULL)
11911180   {
1192      adapter = einfo.guid;
1193      adapter_ptr = &adapter;
1181      dd->adapter = einfo.guid;
1182      dd->adapter_ptr = &dd->adapter;
11941183   }
11951184   else
1196      adapter_ptr = NULL;
1185      dd->adapter_ptr = NULL;
11971186}
11981187
11991188
r243398r243399
12061195{
12071196   float size_score, refresh_score, final_score;
12081197   mode_enum_info *einfo = (mode_enum_info *)context;
1209   renderer_dd *dd = dynamic_cast<renderer_dd *>(einfo->window->m_renderer);
1198   dd_info *dd = (dd_info *)einfo->window->m_drawdata;
12101199
12111200   // skip non-32 bit modes
12121201   if (desc->ddpfPixelFormat.dwRGBBitCount != 32)
r243398r243399
12591248//  pick_best_mode
12601249//============================================================
12611250
1262void renderer_dd::pick_best_mode()
1251static void pick_best_mode(win_window_info *window)
12631252{
1253   dd_info *dd = (dd_info *)window->m_drawdata;
12641254   mode_enum_info einfo;
12651255   HRESULT result;
12661256
r243398r243399
12681258   // note: technically we should not be calling this from an alternate window
12691259   // thread; however, it is only done during init time, and the init code on
12701260   // the main thread is waiting for us to finish, so it is safe to do so here
1271   window().m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);
1261   window->m_target->compute_minimum_size(einfo.minimum_width, einfo.minimum_height);
12721262
12731263   // use those as the target for now
12741264   einfo.target_width = einfo.minimum_width * MAX(1, video_config.prescale);
r243398r243399
12761266
12771267   // determine the refresh rate of the primary screen
12781268   einfo.target_refresh = 60.0;
1279   const screen_device *primary_screen = window().machine().config().first_screen();
1269   const screen_device *primary_screen = window->machine().config().first_screen();
12801270   if (primary_screen != NULL)
12811271      einfo.target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
12821272   printf("Target refresh = %f\n", einfo.target_refresh);
r243398r243399
12961286   }
12971287
12981288   // fill in the rest of the data
1299   einfo.window = &window();
1289   einfo.window = window;
13001290   einfo.best_score = 0.0f;
13011291
13021292   // enumerate the modes
13031293   osd_printf_verbose("DirectDraw: Selecting video mode...\n");
1304   result = IDirectDraw7_EnumDisplayModes(ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
1294   result = IDirectDraw7_EnumDisplayModes(dd->ddraw, DDEDM_REFRESHRATES, NULL, &einfo, enum_modes_callback);
13051295   if (result != DD_OK) osd_printf_verbose("DirectDraw: Error %08X during EnumDisplayModes call\n", (int)result);
1306   osd_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", width, height, refresh);
1296   osd_printf_verbose("DirectDraw: Mode selected = %4dx%4d@%3dHz\n", dd->width, dd->height, dd->refresh);
13071297}
trunk/src/osd/windows/drawgdi.c
r243398r243399
1818#include "window.h"
1919
2020
21
2122//============================================================
2223//  TYPE DEFINITIONS
2324//============================================================
2425
25class renderer_gdi : public osd_renderer
26/* gdi_info is the information for the current screen */
27struct gdi_info
2628{
27public:
28   renderer_gdi(win_window_info *window)
29   : osd_renderer(window, FLAG_NONE), bmdata(NULL), bmsize(0) { }
30
31   virtual ~renderer_gdi() { }
32
33   virtual int init();
34   virtual render_primitive_list *get_primitives();
35   virtual int draw(HDC dc, int update);
36   virtual void save() {};
37   virtual void record() {};
38   virtual void toggle_fsfx() {};
39   virtual void destroy();
40
41private:
42   /* gdi_info is the information for the current screen */
4329   BITMAPINFO              bminfo;
4430   UINT8 *                 bmdata;
4531   size_t                  bmsize;
4632};
4733
4834
35
4936//============================================================
5037//  PROTOTYPES
5138//============================================================
5239
5340// core functions
5441static void drawgdi_exit(void);
42static int drawgdi_window_init(win_window_info *window);
43static void drawgdi_window_destroy(win_window_info *window);
44static render_primitive_list *drawgdi_window_get_primitives(win_window_info *window);
45static int drawgdi_window_draw(win_window_info *window, HDC dc, int update);
5546
56//============================================================
57//  drawnone_create
58//============================================================
5947
60static osd_renderer *drawgdi_create(win_window_info *window)
61{
62   return global_alloc(renderer_gdi(window));
63}
6448
65
6649//============================================================
6750//  drawgdi_init
6851//============================================================
6952
70int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks)
53int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks)
7154{
7255   // fill in the callbacks
7356   memset(callbacks, 0, sizeof(*callbacks));
7457   callbacks->exit = drawgdi_exit;
75   callbacks->create = drawgdi_create;
58   callbacks->window_init = drawgdi_window_init;
59   callbacks->window_get_primitives = drawgdi_window_get_primitives;
60   callbacks->window_draw = drawgdi_window_draw;
61   callbacks->window_destroy = drawgdi_window_destroy;
7662   return 0;
7763}
7864
r243398r243399
9278//  drawgdi_window_init
9379//============================================================
9480
95int renderer_gdi::init()
81static int drawgdi_window_init(win_window_info *window)
9682{
83   // allocate memory for our structures
84   gdi_info *gdi = global_alloc_clear(gdi_info);
85   window->m_drawdata = gdi;
9786
9887   // fill in the bitmap info header
99   bminfo.bmiHeader.biSize            = sizeof(bminfo.bmiHeader);
100   bminfo.bmiHeader.biPlanes          = 1;
101   bminfo.bmiHeader.biBitCount        = 32;
102   bminfo.bmiHeader.biCompression     = BI_RGB;
103   bminfo.bmiHeader.biSizeImage       = 0;
104   bminfo.bmiHeader.biXPelsPerMeter   = 0;
105   bminfo.bmiHeader.biYPelsPerMeter   = 0;
106   bminfo.bmiHeader.biClrUsed         = 0;
107   bminfo.bmiHeader.biClrImportant    = 0;
88   gdi->bminfo.bmiHeader.biSize            = sizeof(gdi->bminfo.bmiHeader);
89   gdi->bminfo.bmiHeader.biPlanes          = 1;
90   gdi->bminfo.bmiHeader.biBitCount        = 32;
91   gdi->bminfo.bmiHeader.biCompression     = BI_RGB;
92   gdi->bminfo.bmiHeader.biSizeImage       = 0;
93   gdi->bminfo.bmiHeader.biXPelsPerMeter   = 0;
94   gdi->bminfo.bmiHeader.biYPelsPerMeter   = 0;
95   gdi->bminfo.bmiHeader.biClrUsed         = 0;
96   gdi->bminfo.bmiHeader.biClrImportant    = 0;
10897
10998   return 0;
11099}
r243398r243399
115104//  drawgdi_window_destroy
116105//============================================================
117106
118void renderer_gdi::destroy()
107static void drawgdi_window_destroy(win_window_info *window)
119108{
109   gdi_info *gdi = (gdi_info *)window->m_drawdata;
120110
111   // skip if nothing
112   if (gdi == NULL)
113      return;
114
121115   // free the bitmap memory
122   if (bmdata != NULL)
123      global_free_array(bmdata);
116   if (gdi->bmdata != NULL)
117      global_free_array(gdi->bmdata);
118   global_free(gdi);
119   window->m_drawdata = NULL;
124120}
125121
126122
r243398r243399
129125//  drawgdi_window_get_primitives
130126//============================================================
131127
132render_primitive_list *renderer_gdi::get_primitives()
128static render_primitive_list *drawgdi_window_get_primitives(win_window_info *window)
133129{
134130   RECT client;
135   GetClientRect(window().m_hwnd, &client);
136   window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
137   return &window().m_target->get_primitives();
131   GetClientRect(window->m_hwnd, &client);
132   window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
133   return &window->m_target->get_primitives();
138134}
139135
140136
r243398r243399
143139//  drawgdi_window_draw
144140//============================================================
145141
146int renderer_gdi::draw(HDC dc, int update)
142static int drawgdi_window_draw(win_window_info *window, HDC dc, int update)
147143{
144   gdi_info *gdi = (gdi_info *)window->m_drawdata;
148145   int width, height, pitch;
149146   RECT bounds;
150147
151148   // we don't have any special resize behaviors
152   if (window().m_resize_state == RESIZE_STATE_PENDING)
153      window().m_resize_state = RESIZE_STATE_NORMAL;
149   if (window->m_resize_state == RESIZE_STATE_PENDING)
150      window->m_resize_state = RESIZE_STATE_NORMAL;
154151
155152   // get the target bounds
156   GetClientRect(window().m_hwnd, &bounds);
153   GetClientRect(window->m_hwnd, &bounds);
157154
158155   // compute width/height/pitch of target
159156   width = rect_width(&bounds);
r243398r243399
161158   pitch = (width + 3) & ~3;
162159
163160   // make sure our temporary bitmap is big enough
164   if (pitch * height * 4 > bmsize)
161   if (pitch * height * 4 > gdi->bmsize)
165162   {
166      bmsize = pitch * height * 4 * 2;
167      global_free_array(bmdata);
168      bmdata = global_alloc_array(UINT8, bmsize);
163      gdi->bmsize = pitch * height * 4 * 2;
164      global_free_array(gdi->bmdata);
165      gdi->bmdata = global_alloc_array(UINT8, gdi->bmsize);
169166   }
170167
171168   // draw the primitives to the bitmap
172   window().m_primlist->acquire_lock();
173   software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window().m_primlist, bmdata, width, height, pitch);
174   window().m_primlist->release_lock();
169   window->m_primlist->acquire_lock();
170   software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->m_primlist, gdi->bmdata, width, height, pitch);
171   window->m_primlist->release_lock();
175172
176173   // fill in bitmap-specific info
177   bminfo.bmiHeader.biWidth = pitch;
178   bminfo.bmiHeader.biHeight = -height;
174   gdi->bminfo.bmiHeader.biWidth = pitch;
175   gdi->bminfo.bmiHeader.biHeight = -height;
179176
180177   // blit to the screen
181178   StretchDIBits(dc, 0, 0, width, height,
182179            0, 0, width, height,
183            bmdata, &bminfo, DIB_RGB_COLORS, SRCCOPY);
180            gdi->bmdata, &gdi->bminfo, DIB_RGB_COLORS, SRCCOPY);
184181   return 0;
185182}
trunk/src/osd/windows/drawnone.c
r243398r243399
1717#include "window.h"
1818
1919
20class renderer_none : public osd_renderer
21{
22public:
23   renderer_none(win_window_info *window)
24   : osd_renderer(window, FLAG_NONE) { }
2520
26   virtual ~renderer_none() { }
27
28   virtual int init();
29   virtual render_primitive_list *get_primitives();
30   virtual int draw(HDC dc, int update);
31   virtual void save() { };
32   virtual void record() { };
33   virtual void toggle_fsfx() { };
34   virtual void destroy();
35
36private:
37};
38
3921//============================================================
4022//  PROTOTYPES
4123//============================================================
4224
4325// core functions
4426static void drawnone_exit(void);
27static int drawnone_window_init(win_window_info *window);
28static void drawnone_window_destroy(win_window_info *window);
29static render_primitive_list *drawnone_window_get_primitives(win_window_info *window);
30static int drawnone_window_draw(win_window_info *window, HDC dc, int update);
4531
46//============================================================
47//  drawnone_create
48//============================================================
4932
50osd_renderer *drawnone_create(win_window_info *window)
51{
52   return global_alloc(renderer_none(window));
53}
5433
5534//============================================================
5635//  drawnone_init
5736//============================================================
5837
59int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks)
38int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks)
6039{
6140   // fill in the callbacks
6241   memset(callbacks, 0, sizeof(*callbacks));
6342   callbacks->exit = drawnone_exit;
64   callbacks->create = drawnone_create;
43   callbacks->window_init = drawnone_window_init;
44   callbacks->window_get_primitives = drawnone_window_get_primitives;
45   callbacks->window_draw = drawnone_window_draw;
46   callbacks->window_destroy = drawnone_window_destroy;
6547   return 0;
6648}
6749
r243398r243399
8163//  drawnone_window_init
8264//============================================================
8365
84int renderer_none::init()
66static int drawnone_window_init(win_window_info *window)
8567{
8668   return 0;
8769}
r243398r243399
9274//  drawnone_window_destroy
9375//============================================================
9476
95void renderer_none::destroy()
77static void drawnone_window_destroy(win_window_info *window)
9678{
9779}
9880
r243398r243399
10284//  drawnone_window_get_primitives
10385//============================================================
10486
105render_primitive_list *renderer_none::get_primitives()
87static render_primitive_list *drawnone_window_get_primitives(win_window_info *window)
10688{
10789   RECT client;
108   GetClientRect(window().m_hwnd, &client);
109   window().m_target->set_bounds(rect_width(&client), rect_height(&client), window().m_monitor->get_aspect());
110   return &window().m_target->get_primitives();
90   GetClientRect(window->m_hwnd, &client);
91   window->m_target->set_bounds(rect_width(&client), rect_height(&client), window->m_monitor->get_aspect());
92   return &window->m_target->get_primitives();
11193}
11294
11395
r243398r243399
11698//  drawnone_window_draw
11799//============================================================
118100
119int renderer_none::draw(HDC dc, int update)
101static int drawnone_window_draw(win_window_info *window, HDC dc, int update)
120102{
121103   return 0;
122104}
trunk/src/osd/windows/window.c
r243398r243399
3535#include "config.h"
3636#include "winutf8.h"
3737
38extern int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks);
39extern int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks);
40extern int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks);
41extern int drawd3d_init(running_machine &machine, osd_draw_callbacks *callbacks);
42extern int drawbgfx_init(running_machine &machine, osd_draw_callbacks *callbacks);
38extern int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks);
39extern int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks);
40extern int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks);
41extern int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks);
42extern int drawbgfx_init(running_machine &machine, win_draw_callbacks *callbacks);
4343
4444
4545//============================================================
r243398r243399
107107
108108static DWORD last_update_time;
109109
110static osd_draw_callbacks draw;
110static win_draw_callbacks draw;
111111
112112static HANDLE ui_pause_event;
113113static HANDLE window_thread_ready_event;
r243398r243399
320320      m_lastclicktime(0),
321321      m_lastclickx(0),
322322      m_lastclicky(0),
323      m_renderer(NULL),
323      m_drawdata(NULL),
324324      m_machine(machine)
325325{
326326   memset(m_title,0,sizeof(m_title));
r243398r243399
504504
505505void winwindow_take_snap(void)
506506{
507   if (draw.window_record == NULL)
508      return;
509
507510   win_window_info *window;
508511
509512   assert(GetCurrentThreadId() == main_threadid);
r243398r243399
511514   // iterate over windows and request a snap
512515   for (window = win_window_list; window != NULL; window = window->m_next)
513516   {
514      window->m_renderer->save();
517      (*draw.window_save)(window);
515518   }
516519}
517520
r243398r243399
524527
525528void winwindow_toggle_fsfx(void)
526529{
530   if (draw.window_toggle_fsfx == NULL)
531      return;
532
527533   win_window_info *window;
528534
529535   assert(GetCurrentThreadId() == main_threadid);
r243398r243399
531537   // iterate over windows and request a snap
532538   for (window = win_window_list; window != NULL; window = window->m_next)
533539   {
534      window->m_renderer->toggle_fsfx();
540      (*draw.window_toggle_fsfx)(window);
535541   }
536542}
537543
r243398r243399
544550
545551void winwindow_take_video(void)
546552{
553   if (draw.window_record == NULL)
554      return;
555
547556   win_window_info *window;
548557
549558   assert(GetCurrentThreadId() == main_threadid);
r243398r243399
551560   // iterate over windows and request a snap
552561   for (window = win_window_list; window != NULL; window = window->m_next)
553562   {
554      window->m_renderer->record();
563      (*draw.window_record)(window);
555564   }
556565}
557566
r243398r243399
803812   }
804813
805814   // if we're visible and running and not in the middle of a resize, draw
806   if (m_hwnd != NULL && m_target != NULL)
815   if (m_hwnd != NULL && m_target != NULL && m_drawdata != NULL)
807816   {
808817      int got_lock = TRUE;
809818
r243398r243399
826835         osd_lock_release(m_render_lock);
827836
828837         // ensure the target bounds are up-to-date, and then get the primitives
829         primlist = m_renderer->get_primitives();
838         primlist = (*draw.window_get_primitives)(this);
830839
831840         // post a redraw request with the primitive list as a parameter
832841         last_update_time = timeGetTime();
r243398r243399
12321241   if (!window->m_fullscreen || window->m_fullscreen_safe)
12331242   {
12341243      // finish off by trying to initialize DirectX; if we fail, ignore it
1235      window->m_renderer = draw.create(window);
1236      if (window->m_renderer->init())
1244      if ((*draw.window_init)(window))
12371245         return 1;
12381246      ShowWindow(window->m_hwnd, SW_SHOW);
12391247   }
r243398r243399
14091417
14101418      // destroy: clean up all attached rendering bits and NULL out our hwnd
14111419      case WM_DESTROY:
1412         window->m_renderer->destroy();
1413         global_free(window->m_renderer);
1414         window->m_renderer = NULL;
1420         (*draw.window_destroy)(window);
14151421         window->m_hwnd = NULL;
14161422         return DefWindowProc(wnd, message, wparam, lparam);
14171423
r243398r243399
14951501      // otherwise, render with our drawing system
14961502      else
14971503      {
1498         window->m_renderer->draw(dc, update);
1504         (*draw.window_draw)(window, dc, update);
14991505         mtlog_add("draw_video_contents: drawing finished");
15001506      }
15011507   }
r243398r243399
18651871   window->m_fullscreen = fullscreen;
18661872
18671873   // kill off the drawers
1868   window->m_renderer->destroy();
1869   global_free(window->m_renderer);
1870   window->m_renderer = NULL;
1874   (*draw.window_destroy)(window);
18711875
18721876   // hide ourself
18731877   ShowWindow(window->m_hwnd, SW_HIDE);
r243398r243399
19231927   {
19241928      if (video_config.mode != VIDEO_MODE_NONE)
19251929         ShowWindow(window->m_hwnd, SW_SHOW);
1926      window->m_renderer = draw.create(window);
1927      if (window->m_renderer->init())
1930      if ((*draw.window_init)(window))
19281931         exit(1);
19291932   }
19301933
trunk/src/osd/windows/window.h
r243398r243399
3232//  TYPE DEFINITIONS
3333//============================================================
3434
35class win_window_info;
36
37class osd_renderer
38{
39public:
40
41   /* Generic flags */
42   static const int FLAG_NONE                = 0x0000;
43   static const int FLAG_NEEDS_OPENGL          = 0x0001;
44
45   /* SDL 1.2 flags */
46   static const int FLAG_NEEDS_DOUBLEBUF       = 0x0100;
47   static const int FLAG_NEEDS_ASYNCBLIT       = 0x0200;
48
49   osd_renderer(win_window_info *window, const int flags)
50   : m_window(window), m_flags(flags) { }
51
52   virtual ~osd_renderer() { }
53
54   win_window_info &window() { return *m_window; }
55   int flags() const { return m_flags; }
56   bool check_flag(const int flag) { return ((m_flags & flag)) == flag; }
57
58   virtual int init() = 0;
59   virtual render_primitive_list *get_primitives() = 0;
60   virtual int draw(HDC dc, int update) = 0;
61   virtual void save() = 0;
62   virtual void record() = 0;
63   virtual void toggle_fsfx() = 0;
64   virtual void destroy() = 0;
65
66private:
67   win_window_info *m_window;
68   int m_flags;
69};
70
7135class win_window_info
7236{
7337public:
r243398r243399
11377   int                 m_lastclicky;
11478
11579   // drawing data
116   osd_renderer *      m_renderer;
80   void *              m_drawdata;
11781
11882private:
11983   running_machine &   m_machine;
12084};
12185
122struct osd_draw_callbacks
86
87struct win_draw_callbacks
12388{
124   osd_renderer *(*create)(win_window_info *window);
12589   void (*exit)(void);
90
91   int (*window_init)(win_window_info *window);
92   render_primitive_list *(*window_get_primitives)(win_window_info *window);
93   int (*window_draw)(win_window_info *window, HDC dc, int update);
94   void (*window_save)(win_window_info *window);
95   void (*window_record)(win_window_info *window);
96   void (*window_toggle_fsfx)(win_window_info *window);
97   void (*window_destroy)(win_window_info *window);
12698};
12799
128100


Previous 199869 Revisions Next


© 1997-2024 The MAME Team