Previous 15994 Revisions Next

r9412 Monday 18th October, 2010 at 17:17:56 UTC by Curt Coder
Synced with MAME.
[src/emu]crsshair.c devcb.c devcb.h emucore.h render.c render.h rendlay.c rendlay.h rendutil.c rendutil.h video.c video.h
[src/emu/video]mc6845.c
[src/mame/drivers]cidelsa.c
[src/mame/includes]cidelsa.h
[src/mame/video]cidelsa.c
[src/osd/windows]video.h window.c window.h

src/mame/includes/cidelsa.h
r9411r9412
11#ifndef __CIDELSA__
22#define __CIDELSA__
33
4#include "cpu/cdp1802/cdp1802.h"
4#include "cpu/cosmac/cosmac.h"
55
66#define SCREEN_TAG   "screen"
77#define CDP1802_TAG   "cdp1802"
88#define CDP1869_TAG   "cdp1869"
9#define COP402N_TAG   "cop402n"
910#define AY8910_TAG   "ay8910"
1011
1112#define DESTRYER_CHR1   3579000.0 // unverified
r9411r9412
3132      : driver_device(machine, config) { }
3233
3334   /* cpu state */
34   cdp1802_control_mode cdp1802_mode;
35   int reset;
3536
3637   /* video state */
3738   int cdp1802_q;
src/mame/video/cidelsa.c
r9411r9412
11#include "emu.h"
2#include "cpu/cosmac/cosmac.h"
23#include "sound/cdp1869.h"
34#include "sound/ay8910.h"
45#include "includes/cidelsa.h"
r9411r9412
130131   cidelsa_state *driver_state = device->machine->driver_data<cidelsa_state>();
131132
132133   /* invert PRD signal */
133   cpu_set_input_line(driver_state->cdp1802, INPUT_LINE_IRQ0, !state);
134   driver_state->cdp1869_prd = !state;
134   cpu_set_input_line(driver_state->cdp1802, COSMAC_INPUT_LINE_INT, state ? CLEAR_LINE : ASSERT_LINE);
135   cpu_set_input_line(driver_state->cdp1802, COSMAC_INPUT_LINE_EF1, state ? CLEAR_LINE : ASSERT_LINE);
135136}
136137
137138/* CDP1869 Interface */
r9411r9412
175176   draco_pcb_r,
176177   draco_charram_r,
177178   draco_charram_w,
178   DEVCB_NULL
179   DEVCB_CPU_INPUT_LINE(CDP1802_TAG, COSMAC_INPUT_LINE_EF1)
179180};
180181
181182/* Video Start */
src/mame/drivers/cidelsa.c
r9411r9412
11#include "emu.h"
2#include "cpu/cdp1802/cdp1802.h"
2#include "cpu/cosmac/cosmac.h"
33#include "cpu/cop400/cop400.h"
44#include "sound/cdp1869.h"
55#include "sound/ay8910.h"
r9411r9412
99
1010/* CDP1802 Interface */
1111
12static CDP1802_MODE_READ( cidelsa_mode_r )
12static READ_LINE_DEVICE_HANDLER( clear_r )
1313{
1414   cidelsa_state *state = device->machine->driver_data<cidelsa_state>();
1515
16   return state->cdp1802_mode;
16   return state->reset;
1717}
1818
19static CDP1802_EF_READ( cidelsa_ef_r )
20{
21   /*
22        EF1     CDP1869 _PRD
23        EF2     Test
24        EF3     Coin 2
25        EF4     Coin 1
26    */
27
28   return input_port_read(device->machine, "EF");
29}
30
3119static WRITE_LINE_DEVICE_HANDLER( cidelsa_q_w )
3220{
3321   cidelsa_state *driver_state = device->machine->driver_data<cidelsa_state>();
r9411r9412
3523   driver_state->cdp1802_q = state;
3624}
3725
38static CDP1802_INTERFACE( cidelsa_cdp1802_config )
26static COSMAC_INTERFACE( cidelsa_cdp1802_config )
3927{
40   cidelsa_mode_r,            // MODE
41   cidelsa_ef_r,            // EF
42   NULL,                  // SC
43   DEVCB_LINE(cidelsa_q_w),   // Q
44   DEVCB_NULL,               // DMA read
45   DEVCB_NULL               // DMA write
28   DEVCB_LINE_VCC,
29   DEVCB_LINE(clear_r),
30   DEVCB_NULL,
31   DEVCB_NULL,
32   DEVCB_NULL,
33   DEVCB_NULL,
34   DEVCB_LINE(cidelsa_q_w),
35   DEVCB_NULL,
36   DEVCB_NULL,
37   NULL,
38   DEVCB_NULL,
39   DEVCB_NULL
4640};
4741
4842/* Sound Interface */
r9411r9412
258252
259253static ADDRESS_MAP_START( altair_map, ADDRESS_SPACE_PROGRAM, 8 )
260254   AM_RANGE(0x0000, 0x2fff) AM_ROM
261   AM_RANGE(0x3000, 0x30ff) AM_RAM
255   AM_RANGE(0x3000, 0x30ff) AM_RAM AM_SHARE("nvram")
262256   AM_RANGE(0xf400, 0xf7ff) AM_DEVREADWRITE(CDP1869_TAG, cdp1869_charram_r, cdp1869_charram_w)
263257   AM_RANGE(0xf800, 0xffff) AM_DEVREADWRITE(CDP1869_TAG, cdp1869_pageram_r, cdp1869_pageram_w)
264258ADDRESS_MAP_END
r9411r9412
314308   return state->cdp1869_pcb;
315309}
316310
317static CUSTOM_INPUT( cidelsa_prd_r )
311static INPUT_CHANGED( ef_w )
318312{
319   cidelsa_state *state = field->port->machine->driver_data<cidelsa_state>();
320
321   return state->cdp1869_prd;
313   cputag_set_input_line(field->port->machine, CDP1802_TAG, (int)(FPTR)param, newval);
322314}
323315
324316static INPUT_PORTS_START( destryer )
r9411r9412
355347   PORT_DIPSETTING(    0x00, "Slot A: 2.5  Slot B: 5" )
356348
357349   PORT_START("EF")
358   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_CUSTOM(cidelsa_prd_r, NULL)
359   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) // ST
360   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 ) // M2
361   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 ) // M1
350   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SPECIAL ) // inverted CDP1869 PRD, pushed
351   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF2)
352   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF3)
353   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF4)
362354INPUT_PORTS_END
363355
364356static INPUT_PORTS_START( altair )
r9411r9412
405397   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
406398
407399   PORT_START("EF")
408   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_CUSTOM(cidelsa_prd_r, NULL)
409   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) // ST
410   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 ) // M2
411   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 ) // M1
400   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SPECIAL ) // inverted CDP1869 PRD, pushed
401   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF2)
402   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF3)
403   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF4)
412404INPUT_PORTS_END
413405
414406static INPUT_PORTS_START( draco )
r9411r9412
457449   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT )
458450
459451   PORT_START("EF")
460   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SPECIAL ) PORT_READ_LINE_DEVICE(CDP1869_TAG, cdp1869_predisplay_r)
461   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE ) // ST
462   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN2 ) // M2
463   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_COIN1 ) // M1
452   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SPECIAL ) // CDP1869 PRD, pushed
453   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SERVICE ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF2)
454   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN2 ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF3)
455   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_COIN1 ) PORT_CHANGED(ef_w, (void*)COSMAC_INPUT_LINE_EF4)
464456INPUT_PORTS_END
465457
466458/* Machine Start */
r9411r9412
469461{
470462   cidelsa_state *state = machine->driver_data<cidelsa_state>();
471463
472   state->cdp1802_mode = CDP1802_MODE_RUN;
464   state->reset = 1;
473465}
474466
475467static MACHINE_START( cidelsa )
476468{
477469   cidelsa_state *state = machine->driver_data<cidelsa_state>();
478470
471   /* find devices */
479472   state->cdp1802 = machine->device(CDP1802_TAG);
480473
481   /* reset the CPU */
482   state->cdp1802_mode = CDP1802_MODE_RESET;
483   timer_set(machine, ATTOTIME_IN_MSEC(200), NULL, 0, set_cpu_mode);
484
485474   /* register for state saving */
486   state_save_register_global(machine, state->cdp1802_mode);
475   state_save_register_global(machine, state->reset);
487476}
488477
489478static MACHINE_START( draco )
r9411r9412
493482   MACHINE_START_CALL( cidelsa );
494483
495484   /* setup COP402 memory banking */
496   memory_configure_bank(machine, "bank1", 0, 2, memory_region(machine, "audiocpu"), 0x400);
485   memory_configure_bank(machine, "bank1", 0, 2, memory_region(machine, COP402N_TAG), 0x400);
497486   memory_set_bank(machine, "bank1", 0);
498487
499488   /* register for state saving */
r9411r9412
505494
506495static MACHINE_RESET( cidelsa )
507496{
508   cputag_set_input_line(machine, CDP1802_TAG, INPUT_LINE_RESET, PULSE_LINE);
497   cidelsa_state *state = machine->driver_data<cidelsa_state>();
498
499   /* reset the CPU */
500   state->reset = 0;
501   timer_set(machine, ATTOTIME_IN_MSEC(200), NULL, 0, set_cpu_mode);
509502}
510503
511504/* Machine Drivers */
512505
513506static MACHINE_CONFIG_START( destryer, cidelsa_state )
514
515507   /* basic system hardware */
516   MDRV_CPU_ADD(CDP1802_TAG, CDP1802, DESTRYER_CHR1)
508   MDRV_CPU_ADD(CDP1802_TAG, COSMAC, DESTRYER_CHR1)
517509   MDRV_CPU_PROGRAM_MAP(destryer_map)
518510   MDRV_CPU_IO_MAP(destryer_io_map)
519511   MDRV_CPU_CONFIG(cidelsa_cdp1802_config)
r9411r9412
527519MACHINE_CONFIG_END
528520
529521static MACHINE_CONFIG_START( destryera, cidelsa_state )
530
531522   /* basic system hardware */
532   MDRV_CPU_ADD(CDP1802_TAG, CDP1802, DESTRYER_CHR1)
523   MDRV_CPU_ADD(CDP1802_TAG, COSMAC, DESTRYER_CHR1)
533524   MDRV_CPU_PROGRAM_MAP(destryera_map)
534525   MDRV_CPU_IO_MAP(destryer_io_map)
535526   MDRV_CPU_CONFIG(cidelsa_cdp1802_config)
r9411r9412
543534MACHINE_CONFIG_END
544535
545536static MACHINE_CONFIG_START( altair, cidelsa_state )
546
547537   /* basic system hardware */
548
549   MDRV_CPU_ADD(CDP1802_TAG, CDP1802, ALTAIR_CHR1)
538   MDRV_CPU_ADD(CDP1802_TAG, COSMAC, ALTAIR_CHR1)
550539   MDRV_CPU_PROGRAM_MAP(altair_map)
551540   MDRV_CPU_IO_MAP(altair_io_map)
552541   MDRV_CPU_CONFIG(cidelsa_cdp1802_config)
542   MDRV_NVRAM_ADD_0FILL("nvram")
553543
554544   MDRV_MACHINE_START(cidelsa)
555545   MDRV_MACHINE_RESET(cidelsa)
r9411r9412
565555MACHINE_CONFIG_END
566556
567557static MACHINE_CONFIG_START( draco, cidelsa_state )
568
569558   /* basic system hardware */
570   MDRV_CPU_ADD(CDP1802_TAG, CDP1802, DRACO_CHR1)
559   MDRV_CPU_ADD(CDP1802_TAG, COSMAC, DRACO_CHR1)
571560   MDRV_CPU_PROGRAM_MAP(draco_map)
572561   MDRV_CPU_IO_MAP(draco_io_map)
573562   MDRV_CPU_CONFIG(cidelsa_cdp1802_config)
r9411r9412
576565   MDRV_MACHINE_START(draco)
577566   MDRV_MACHINE_RESET(cidelsa)
578567
579   MDRV_CPU_ADD("audiocpu", COP402, DRACO_SND_CHR1) // COP402N
568   MDRV_CPU_ADD(COP402N_TAG, COP402, DRACO_SND_CHR1)
580569   MDRV_CPU_PROGRAM_MAP(draco_sound_map)
581570   MDRV_CPU_IO_MAP(draco_sound_io_map)
582571   MDRV_CPU_CONFIG(draco_cop_intf)
r9411r9412
594583/* ROMs */
595584
596585ROM_START( destryer )
597   ROM_REGION( 0x10000, CDP1802_TAG, 0 )
586   ROM_REGION( 0x2000, CDP1802_TAG, 0 )
598587   ROM_LOAD( "des a 2.ic4", 0x0000, 0x0800, CRC(63749870) SHA1(a8eee4509d7a52dcf33049de221d928da3632174) )
599588   ROM_LOAD( "des b 2.ic5", 0x0800, 0x0800, CRC(60604f40) SHA1(32ca95c5b38b0f4992e04d77123d217f143ae084) )
600589   ROM_LOAD( "des c 2.ic6", 0x1000, 0x0800, CRC(a7cdeb7b) SHA1(a5a7748967d4ca89fb09632e1f0130ef050dbd68) )
r9411r9412
603592
604593// this was destroyer2.rom in standalone emu..
605594ROM_START( destryera )
606   ROM_REGION( 0x10000, CDP1802_TAG, 0 )
595   ROM_REGION( 0x2000, CDP1802_TAG, 0 )
607596   ROM_LOAD( "destryera_1", 0x0000, 0x0800, CRC(421428e9) SHA1(0ac3a1e7f61125a1cd82145fa28cbc4b93505dc9) )
608597   ROM_LOAD( "destryera_2", 0x0800, 0x0800, CRC(55dc8145) SHA1(a0066d3f3ac0ae56273485b74af90eeffea5e64e) )
609598   ROM_LOAD( "destryera_3", 0x1000, 0x0800, CRC(5557bdf8) SHA1(37a9cbc5d25051d3bed7535c58aac937cd7c64e1) )
r9411r9412
611600ROM_END
612601
613602ROM_START( altair )
614   ROM_REGION( 0x10000, CDP1802_TAG, 0 )
603   ROM_REGION( 0x3000, CDP1802_TAG, 0 )
615604   ROM_LOAD( "alt a 1.ic7",  0x0000, 0x0800, CRC(37c26c4e) SHA1(30df7efcf5bd12dafc1cb6e894fc18e7b76d3e61) )
616605   ROM_LOAD( "alt b 1.ic8",  0x0800, 0x0800, CRC(76b814a4) SHA1(e8ab1d1cbcef974d929ef8edd10008f60052a607) )
617606   ROM_LOAD( "alt c 1.ic9",  0x1000, 0x0800, CRC(2569ce44) SHA1(a09597d2f8f50fab9a09ed9a59c50a2bdcba47bb) )
r9411r9412
621610ROM_END
622611
623612ROM_START( draco )
624   ROM_REGION( 0x10000, CDP1802_TAG, 0 )
613   ROM_REGION( 0x4000, CDP1802_TAG, 0 )
625614   ROM_LOAD( "dra a 1.ic10", 0x0000, 0x0800, CRC(ca127984) SHA1(46721cf42b1c891f7c88bc063a2149dd3cefea74) )
626615   ROM_LOAD( "dra b 1.ic11", 0x0800, 0x0800, CRC(e4936e28) SHA1(ddbbf769994d32a6bce75312306468a89033f0aa) )
627616   ROM_LOAD( "dra c 1.ic12", 0x1000, 0x0800, CRC(94480f5d) SHA1(8f49ce0f086259371e999d097a502482c83c6e9e) )
r9411r9412
631620   ROM_LOAD( "dra g 1.ic16", 0x3000, 0x0800, CRC(f28546c0) SHA1(daedf1d64f94358b15580d697dd77d3c977aa22c) )
632621   ROM_LOAD( "dra h 1.ic17", 0x3800, 0x0800, CRC(dce782ea) SHA1(f558096f43fb30337bc4a527169718326c265c2c) )
633622
634   ROM_REGION( 0x800, "audiocpu", 0 )
623   ROM_REGION( 0x800, COP402N_TAG, 0 )
635624   ROM_LOAD( "dra s 1.ic4",  0x0000, 0x0800, CRC(292a57f8) SHA1(b34a189394746d77c3ee669db24109ee945c3be7) )
636625ROM_END
637626
src/osd/windows/window.c
r9411r9412
718718
719719void winwindow_video_window_update(win_window_info *window)
720720{
721   int targetview, targetorient, targetlayerconfig;
721   int targetview, targetorient;
722   render_layer_config targetlayerconfig;
722723
723724   assert(GetCurrentThreadId() == main_threadid);
724725
src/osd/windows/video.h
r9411r9412
4242#ifndef __WIN_VIDEO__
4343#define __WIN_VIDEO__
4444
45#include "render.h"
4546
47
4648//============================================================
4749//  CONSTANTS
4850//============================================================
r9411r9412
9092   int               prescale;               // prescale factor
9193   int               keepaspect;               // keep aspect ratio
9294   int               numscreens;               // number of screens
93   int               layerconfig;            // default configuration of layers
95   render_layer_config   layerconfig;            // default configuration of layers
9496
9597   // per-window configuration
9698   win_window_config   window[MAX_WINDOWS];      // configuration data per-window
src/osd/windows/window.h
r9411r9412
100100   render_target *      target;
101101   int               targetview;
102102   int               targetorient;
103   int               targetlayerconfig;
103   render_layer_config   targetlayerconfig;
104104   render_primitive_list *primlist;
105105
106106   // input info
src/emu/devcb.c
r9411r9412
6868   }
6969
7070   /* device handlers */
71   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF) && (config->readline != NULL || config->readdevice != NULL))
71   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->readline != NULL || config->readdevice != NULL))
7272   {
7373      /* locate the device */
7474      if (config->type == DEVCB_TYPE_SELF)
7575         resolved->target = device;
76      else if (config->type == DEVCB_TYPE_DRIVER)
77         resolved->target = device->machine->driver_data();
7678      else
7779         resolved->target = device->siblingdevice(config->tag);
7880
r9411r9412
167169   }
168170
169171   /* device handlers */
170   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF) && (config->writeline != NULL || config->writedevice != NULL))
172   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->writeline != NULL || config->writedevice != NULL))
171173   {
172174      /* locate the device */
173175      if (config->type == DEVCB_TYPE_SELF)
174176         resolved->target = device;
177      else if (config->type == DEVCB_TYPE_DRIVER)
178         resolved->target = device->machine->driver_data();
175179      else
176180         resolved->target = device->siblingdevice(config->tag);
177181
r9411r9412
243247   }
244248
245249   /* device handlers */
246   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF) && (config->readline != NULL || config->readdevice != NULL))
250   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->readline != NULL || config->readdevice != NULL))
247251   {
248      resolved->target = (config->type == DEVCB_TYPE_SELF) ? device : device->machine->device(config->tag);
252      if (config->type == DEVCB_TYPE_SELF)
253         resolved->target = device;
254      else if (config->type == DEVCB_TYPE_DRIVER)
255         resolved->target = device->machine->driver_data();
256      else
257         resolved->target = device->siblingdevice(config->tag);
249258      if (resolved->target == NULL)
250259         fatalerror("devcb_resolve_read8: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
251260
r9411r9412
313322   }
314323
315324   /* device handlers */
316   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF) && (config->writeline != NULL || config->writedevice != NULL))
325   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->writeline != NULL || config->writedevice != NULL))
317326   {
318      resolved->target = (config->type == DEVCB_TYPE_SELF) ? device : device->machine->device(config->tag);
327      if (config->type == DEVCB_TYPE_SELF)
328         resolved->target = device;
329      else if (config->type == DEVCB_TYPE_DRIVER)
330         resolved->target = device->machine->driver_data();
331      else
332         resolved->target = device->siblingdevice(config->tag);
319333      if (resolved->target == NULL)
320334         fatalerror("devcb_resolve_write8: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
321335
src/emu/video/mc6845.c
r9411r9412
651651         mc6845->line_enable_ff = 1;
652652         /* also update the cursor state now */
653653         update_cursor_state(mc6845);
654
655         if (mc6845->screen != NULL)
656            mc6845->screen->reset_origin();
654657      }
655658      else
656659      {
src/emu/devcb.h
r9411r9412
5252#define DEVCB_TYPE_SELF            (1)
5353#define DEVCB_TYPE_INPUT         (2)
5454#define DEVCB_TYPE_DEVICE         (3)
55#define DEVCB_TYPE_MEMORY(space)   (4 + (space))
56#define DEVCB_TYPE_CPU_LINE(line)   (4 + ADDRESS_SPACES + (line))
55#define DEVCB_TYPE_DRIVER         (4)
56#define DEVCB_TYPE_MEMORY(space)   (5 + (space))
57#define DEVCB_TYPE_CPU_LINE(line)   (5 + ADDRESS_SPACES + (line))
5758
5859
5960
r9411r9412
9798
9899/* standard line or read/write handlers with the calling device passed */
99100#define DEVCB_LINE(func)                  { DEVCB_TYPE_SELF, NULL, (func), NULL, NULL }
100#define DEVCB_LINE_MEMBER(func)               { DEVCB_TYPE_SELF, NULL, &devcb_line_stub<cls, &cls::memb>, NULL, NULL }
101#define DEVCB_LINE_MEMBER(cls,memb)            { DEVCB_TYPE_SELF, NULL, &devcb_line_stub<cls, &cls::memb>, NULL, NULL }
101102#define DEVCB_LINE_GND                     { DEVCB_TYPE_SELF, NULL, devcb_line_gnd_r, NULL, NULL }
102103#define DEVCB_LINE_VCC                     { DEVCB_TYPE_SELF, NULL, devcb_line_vcc_r, NULL, NULL }
103104#define DEVCB_HANDLER(func)                  { DEVCB_TYPE_SELF, NULL, NULL, (func), NULL }
104105#define DEVCB_MEMBER(cls,memb)               { DEVCB_TYPE_SELF, NULL, NULL, &devcb_stub<cls, &cls::memb>, NULL }
105106
107/* line or read/write handlers for the driver device */
108#define DEVCB_DRIVER_LINE_MEMBER(cls,memb)      { DEVCB_TYPE_DRIVER, NULL, &devcb_line_stub<cls, &cls::memb>, NULL, NULL }
109#define DEVCB_DRIVER_MEMBER(cls,memb)         { DEVCB_TYPE_DRIVER, NULL, NULL, &devcb_stub<cls, &cls::memb>, NULL }
110
106111/* line or read/write handlers for another device */
107112#define DEVCB_DEVICE_LINE(tag,func)            { DEVCB_TYPE_DEVICE, tag, (func), NULL, NULL }
108113#define DEVCB_DEVICE_LINE_MEMBER(tag,cls,memb)   { DEVCB_TYPE_DEVICE, tag, &devcb_line_stub<cls, &cls::memb>, NULL, NULL }
src/emu/video.c
r9411r9412
312312   if (global.snap_native)
313313   {
314314      global.snap_target = machine->render().target_alloc(layout_snap, RENDER_CREATE_SINGLE_FILE | RENDER_CREATE_HIDDEN);
315      global.snap_target->set_layer_config(0);
315      global.snap_target->set_backdrops_enabled(false);
316      global.snap_target->set_overlays_enabled(false);
317      global.snap_target->set_bezels_enabled(false);
318      global.snap_target->set_screen_overlay_enabled(false);
319      global.snap_target->set_zoom_to_screen(false);
316320   }
317321
318322   /* other targets select the specified view and turn off effects */
r9411r9412
15961600   }
15971601
15981602   /* if we don't have a match, default to the nth view */
1599   if (viewindex == -1)
1603   int scrcount = screen_count(*machine->config);
1604   if (viewindex == -1 && scrcount > 0)
16001605   {
1601      int scrcount = screen_count(*machine->config);
1602
16031606      /* if we have enough targets to be one per screen, assign in order */
16041607      if (numtargets >= scrcount)
16051608      {
1609         int index = target->index() % scrcount;
1610         screen_device *screen;
1611         for (screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
1612            if (index-- == 0)
1613               break;
1614     
16061615         /* find the first view with this screen and this screen only */
16071616         for (viewindex = 0; ; viewindex++)
16081617         {
1609            UINT32 viewscreens = target->view_screens(viewindex);
1610            if (viewscreens == (1 << targetindex))
1618            const render_screen_list &viewscreens = target->view_screens(viewindex);
1619            if (viewscreens.count() == 1 && viewscreens.contains(*screen))
16111620               break;
1612            if (viewscreens == 0)
1621            if (viewscreens.count() == 0)
16131622            {
16141623               viewindex = -1;
16151624               break;
r9411r9412
16221631      {
16231632         for (viewindex = 0; ; viewindex++)
16241633         {
1625            UINT32 viewscreens = target->view_screens(viewindex);
1626            if (viewscreens == (1 << scrcount) - 1)
1634            const render_screen_list &viewscreens = target->view_screens(viewindex);
1635            if (viewscreens.count() == 0)
16271636               break;
1628            if (viewscreens == 0)
1629               break;
1637            if (viewscreens.count() >= scrcount)
1638            {
1639               screen_device *screen;
1640               for (screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
1641                  if (!viewscreens.contains(*screen))
1642                     break;
1643               if (screen == NULL)
1644                  break;
1645            }
16301646         }
16311647      }
16321648   }
r9411r9412
19421958
19431959void screen_device::device_start()
19441960{
1945   // get and validate that the container for this screen exists
1946   m_container = m_machine.render().container_for_screen(this);
1947
19481961   // configure the default cliparea
19491962   render_container::user_settings settings;
19501963   m_container->get_user_settings(settings);
r9411r9412
20752088
20762089
20772090//-------------------------------------------------
2091//  reset_origin - reset the timing such that the
2092//  given (x,y) occurs at the current time
2093//-------------------------------------------------
2094
2095void screen_device::reset_origin(int beamy, int beamx)
2096{
2097   // compute the effective VBLANK start/end times
2098   m_vblank_end_time = attotime_sub_attoseconds(timer_get_time(machine), beamy * m_scantime + beamx * m_pixeltime);
2099   m_vblank_start_time = attotime_sub_attoseconds(m_vblank_end_time, m_vblank_period);
2100
2101   // re-adjust the scanline 0 and VBLANK timers
2102   timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
2103   timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
2104}
2105
2106
2107//-------------------------------------------------
20782108//  realloc_screen_bitmaps - reallocate bitmaps
20792109//  and textures as necessary
20802110//-------------------------------------------------
src/emu/video.h
r9411r9412
141141class screen_device : public device_t
142142{
143143   friend class screen_device_config;
144   friend class render_manager;
144145   friend resource_pool_object<screen_device>::~resource_pool_object();
145146
146147   // construction/destruction
r9411r9412
159160
160161   // dynamic configuration
161162   void configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period);
163   void reset_origin(int beamy = 0, int beamx = 0);
162164   void set_visible_area(int min_x, int max_x, int min_y, int max_y);
163165
164166   // beam positioning and state
r9411r9412
199201   virtual void device_post_load();
200202
201203   // internal helpers
204   void set_container(render_container &container) { m_container = &container; }
202205   void realloc_screen_bitmaps();
203206
204207   static TIMER_CALLBACK( static_vblank_begin_callback ) { reinterpret_cast<screen_device *>(ptr)->vblank_begin_callback(); }
src/emu/rendlay.c
r9411r9412
44
55    Core rendering layout parser and manager.
66
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
107****************************************************************************
118
12    Notes:
9    Copyright Aaron Giles
10    All rights reserved.
1311
14        Unlike the old system, the artwork is not rotated with the game
15        orientation. This is to support odd configurations like two
16        monitors in different orientations. You can specify an orientation
17        for a backdrop/screen/overlay/bezel element, but it only applies
18        to the artwork itself, and does not affect coordinates in any way.
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
1915
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
2025
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38****************************************************************************
39
2140    Overview of objects:
2241
2342        layout_file -- A layout_file comprises a list of elements and a
r9411r9412
7291    STANDARD LAYOUTS
7392***************************************************************************/
7493
75/* single screen layouts */
94// single screen layouts
7695#include "horizont.lh"
7796#include "vertical.lh"
7897
79/* dual screen layouts */
98// dual screen layouts
8099#include "dualhsxs.lh"
81100#include "dualhovu.lh"
82101#include "dualhuov.lh"
83102
84/* triple screen layouts */
103// triple screen layouts
85104#include "triphsxs.lh"
86105
87/* generic color overlay layouts */
106// generic color overlay layouts
88107#include "ho20ffff.lh"
89108#include "ho2eff2e.lh"
90109#include "ho4f893d.lh"
r9411r9412
96115
97116
98117
99/***************************************************************************
100    CONSTANTS
101***************************************************************************/
118//**************************************************************************
119//  CONSTANTS
120//**************************************************************************
102121
103#define LAYOUT_VERSION         2
122const int LAYOUT_VERSION = 2;
104123
105#define LINE_CAP_NONE  0
106#define LINE_CAP_START 1
107#define LINE_CAP_END   2
108
109124enum
110125{
111   COMPONENT_TYPE_IMAGE = 0,
112   COMPONENT_TYPE_RECT,
113   COMPONENT_TYPE_DISK,
114   COMPONENT_TYPE_TEXT,
115   COMPONENT_TYPE_LED7SEG,
116   COMPONENT_TYPE_LED14SEG,
117   COMPONENT_TYPE_LED16SEG,
118   COMPONENT_TYPE_LED14SEGSC,
119   COMPONENT_TYPE_LED16SEGSC,
120   COMPONENT_TYPE_DOTMATRIX,
121   COMPONENT_TYPE_MAX
126   LINE_CAP_NONE = 0,
127   LINE_CAP_START = 1,
128   LINE_CAP_END = 2
122129};
123130
124131
125/***************************************************************************
126    TYPE DEFINITIONS
127***************************************************************************/
128132
129/* an element_component represents an image, rectangle, or disk in an element */
130struct _element_component
131{
132   element_component *   next;            /* link to next component */
133   int               type;            /* type of component */
134   int               state;            /* state where this component is visible (-1 means all states) */
135   render_bounds      bounds;            /* bounds of the element */
136   render_color      color;            /* color of the element */
137   const char *      string;            /* string for text components */
138   bitmap_t *         bitmap;            /* source bitmap for images */
139   const char *      dirname;         /* directory name of image file (for lazy loading) */
140   const char *      imagefile;         /* name of the image file (for lazy loading) */
141   const char *      alphafile;         /* name of the alpha file (for lazy loading) */
142   int               hasalpha;         /* is there any alpha component present? */
143};
133//**************************************************************************
134//  GLOBAL VARIABLES
135//**************************************************************************
144136
137const render_screen_list render_target::s_empty_screen_list;
145138
146139
147/***************************************************************************
148    FUNCTION PROTOTYPES
149***************************************************************************/
150140
151/* layout elements */
152static void layout_element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param);
153static void layout_element_draw_rect(bitmap_t &dest, const rectangle &bounds, const render_color &color);
154static void layout_element_draw_disk(bitmap_t &dest, const rectangle &bounds, const render_color &color);
155static void layout_element_draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds, const render_color &color, const char *string);
156static void layout_element_draw_led7seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state);
157static void layout_element_draw_led14seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state);
158static void layout_element_draw_led16seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state);
159static void layout_element_draw_led14segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state);
160static void layout_element_draw_led16segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state);
161static void layout_element_draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state);
141//**************************************************************************
142//  INLINE HELPERS
143//**************************************************************************
162144
163/* layout file parsing */
164static layout_element *load_layout_element(running_machine &machine, xml_data_node *elemnode, const char *dirname);
165static element_component *load_element_component(running_machine &machine, xml_data_node *compnode, const char *dirname);
166static layout_view *load_layout_view(running_machine &machine, xml_data_node *viewnode, layout_element *elemlist);
167static view_item *load_view_item(running_machine &machine, xml_data_node *itemnode, layout_element *elemlist);
168static bitmap_t *load_component_bitmap(const char *dirname, const char *file, const char *alphafile, int *hasalpha);
169static int load_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds *bounds);
170static int load_color(running_machine &machine, xml_data_node *colornode, render_color *color);
171static int load_orientation(running_machine &machine, xml_data_node *orientnode, int *orientation);
172static void layout_view_free(layout_view *view);
173static void layout_element_free(layout_element *element);
145//-------------------------------------------------
146//  gcd - compute the greatest common divisor (GCD)
147//  of two integers using the Euclidean algorithm
148//-------------------------------------------------
174149
175
176
177/***************************************************************************
178    INLINE FUNCTIONS
179***************************************************************************/
180
181/*-------------------------------------------------
182    gcd - compute the greatest common divisor (GCD)
183    of two integers using the Euclidean algorithm
184-------------------------------------------------*/
185
186INLINE int gcd(int a, int b)
150inline int gcd(int a, int b)
187151{
188152   while (b != 0)
189153   {
r9411r9412
195159}
196160
197161
198/*-------------------------------------------------
199    reduce_fraction - reduce a fraction by
200    dividing out common factors
201-------------------------------------------------*/
162//-------------------------------------------------
163//  reduce_fraction - reduce a fraction by
164//  dividing out common factors
165//-------------------------------------------------
202166
203INLINE void reduce_fraction(int *num, int *den)
167inline void reduce_fraction(int &num, int &den)
204168{
205   int div;
169   // search the greatest common divisor
170   int div = gcd(num, den);
206171
207   /* search the greatest common divisor */
208   div = gcd(*num, *den);
209
210   /* reduce the fraction if a common divisor has been found */
172   // reduce the fraction if a common divisor has been found
211173   if (div > 1)
212174   {
213      *num /= div;
214      *den /= div;
175      num /= div;
176      den /= div;
215177   }
216178}
217179
218180
219/*-------------------------------------------------
220    copy_string - make a copy of a string
221-------------------------------------------------*/
222181
223INLINE const char *copy_string(const char *string)
182//**************************************************************************
183//  SHARED PARSING HELPERS
184//**************************************************************************
185
186//-------------------------------------------------
187//  get_variable_value - compute the value of
188//  a variable in an XML attribute
189//-------------------------------------------------
190
191static int get_variable_value(running_machine &machine, const char *string, char **outputptr)
224192{
225   char *newstring = global_alloc_array(char, strlen(string) + 1);
226   strcpy(newstring, string);
227   return newstring;
193   char temp[100];
194
195   // screen 0 parameters
196   for (const screen_device_config *devconfig = screen_first(machine.m_config); devconfig != NULL; devconfig = screen_next(devconfig))
197   {
198      int scrnum = machine.m_config.m_devicelist.index(SCREEN, devconfig->tag());
199
200      // native X aspect factor
201      sprintf(temp, "~scr%dnativexaspect~", scrnum);
202      if (!strncmp(string, temp, strlen(temp)))
203      {
204         int num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x;
205         int den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y;
206         reduce_fraction(num, den);
207         *outputptr += sprintf(*outputptr, "%d", num);
208         return strlen(temp);
209      }
210
211      // native Y aspect factor
212      sprintf(temp, "~scr%dnativeyaspect~", scrnum);
213      if (!strncmp(string, temp, strlen(temp)))
214      {
215         int num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x;
216         int den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y;
217         reduce_fraction(num, den);
218         *outputptr += sprintf(*outputptr, "%d", den);
219         return strlen(temp);
220      }
221
222      // native width
223      sprintf(temp, "~scr%dwidth~", scrnum);
224      if (!strncmp(string, temp, strlen(temp)))
225      {
226         *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x);
227         return strlen(temp);
228      }
229
230      // native height
231      sprintf(temp, "~scr%dheight~", scrnum);
232      if (!strncmp(string, temp, strlen(temp)))
233      {
234         *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y);
235         return strlen(temp);
236      }
237   }
238
239   // default: copy the first character and continue
240   **outputptr = *string;
241   *outputptr += 1;
242   return 1;
228243}
229244
230245
246//-------------------------------------------------
247//  xml_get_attribute_string_with_subst - analog
248//  to xml_get_attribute_string but with variable
249//  substitution
250//-------------------------------------------------
231251
232/***************************************************************************
233    LAYOUT VIEWS
234***************************************************************************/
252static const char *xml_get_attribute_string_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, const char *defvalue)
253{
254   const char *str = xml_get_attribute_string(&node, attribute, NULL);
255   static char buffer[1000];
235256
236/*-------------------------------------------------
237    layout_view_recompute - recompute the bounds
238    and aspect ratio of a view and all of its
239    contained items
240-------------------------------------------------*/
257   // if nothing, just return the default
258   if (str == NULL)
259      return defvalue;
241260
242void layout_view_recompute(layout_view *view, int layerconfig)
261   // if no tildes, don't worry
262   if (strchr(str, '~') == NULL)
263      return str;
264
265   // make a copy of the string, doing substitutions along the way
266   const char *s;
267   char *d;
268   for (s = str, d = buffer; *s != 0; )
269   {
270      // if not a variable, just copy
271      if (*s != '~')
272         *d++ = *s++;
273
274      // extract the variable
275      else
276         s += get_variable_value(machine, s, &d);
277   }
278   *d = 0;
279   return buffer;
280}
281
282
283//-------------------------------------------------
284//  xml_get_attribute_int_with_subst - analog
285//  to xml_get_attribute_int but with variable
286//  substitution
287//-------------------------------------------------
288
289static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, int defvalue)
243290{
244   render_bounds target_bounds;
245   float xscale, yscale;
246   float xoffs, yoffs;
247   int scrfirst = TRUE;
248   int first = TRUE;
249   int layer;
291   const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL);
292   int value;
250293
251   /* reset the bounds */
252   view->bounds.x0 = view->bounds.y0 = view->bounds.x1 = view->bounds.y1 = 0.0f;
253   view->scrbounds.x0 = view->scrbounds.y0 = view->scrbounds.x1 = view->scrbounds.y1 = 0.0f;
254   view->screens = 0;
294   if (string == NULL)
295      return defvalue;
296   if (string[0] == '$')
297      return (sscanf(&string[1], "%X", &value) == 1) ? value : defvalue;
298   if (string[0] == '0' && string[1] == 'x')
299      return (sscanf(&string[2], "%X", &value) == 1) ? value : defvalue;
300   if (string[0] == '#')
301      return (sscanf(&string[1], "%d", &value) == 1) ? value : defvalue;
302   return (sscanf(&string[0], "%d", &value) == 1) ? value : defvalue;
303}
255304
256   /* loop over all layers */
257   for (layer = 0; layer < ITEM_LAYER_MAX; layer++)
305
306//-------------------------------------------------
307//  xml_get_attribute_float_with_subst - analog
308//  to xml_get_attribute_float but with variable
309//  substitution
310//-------------------------------------------------
311
312static float xml_get_attribute_float_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, float defvalue)
313{
314   const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL);
315   float value;
316
317   if (string == NULL || sscanf(string, "%f", &value) != 1)
318      return defvalue;
319   return value;
320}
321
322
323//-------------------------------------------------
324//  parse_bounds - parse a bounds XML node
325//-------------------------------------------------
326
327void parse_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds &bounds)
328{
329   // skip if nothing
330   if (boundsnode == NULL)
258331   {
259      static const int layer_mask[ITEM_LAYER_MAX] = { LAYER_CONFIG_ENABLE_BACKDROP, 0, LAYER_CONFIG_ENABLE_OVERLAY, LAYER_CONFIG_ENABLE_BEZEL };
332      bounds.x0 = bounds.y0 = 0.0f;
333      bounds.x1 = bounds.y1 = 1.0f;
334      return;
335   }
260336
261      /* determine if this layer should be visible */
262      view->layenabled[layer] = (layer_mask[layer] == 0 || (layerconfig & layer_mask[layer]));
337   // parse out the data
338   if (xml_get_attribute(boundsnode, "left") != NULL)
339   {
340      // left/right/top/bottom format
341      bounds.x0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "left", 0.0f);
342      bounds.x1 = xml_get_attribute_float_with_subst(machine, *boundsnode, "right", 1.0f);
343      bounds.y0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "top", 0.0f);
344      bounds.y1 = xml_get_attribute_float_with_subst(machine, *boundsnode, "bottom", 1.0f);
345   }
346   else if (xml_get_attribute(boundsnode, "x") != NULL)
347   {
348      // x/y/width/height format
349      bounds.x0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "x", 0.0f);
350      bounds.x1 = bounds.x0 + xml_get_attribute_float_with_subst(machine, *boundsnode, "width", 1.0f);
351      bounds.y0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "y", 0.0f);
352      bounds.y1 = bounds.y0 + xml_get_attribute_float_with_subst(machine, *boundsnode, "height", 1.0f);
353   }
354   else
355      throw emu_fatalerror("Illegal bounds value in XML");
263356
264      /* only do it if requested */
265      if (view->layenabled[layer])
266      {
267         view_item *item;
357   // check for errors
358   if (bounds.x0 > bounds.x1 || bounds.y0 > bounds.y1)
359      throw emu_fatalerror("Illegal bounds value in XML: (%f-%f)-(%f-%f)", bounds.x0, bounds.x1, bounds.y0, bounds.y1);
360}
268361
269         for (item = view->itemlist[layer]; item != NULL; item = item->next)
270         {
271            /* accumulate bounds */
272            if (first)
273               view->bounds = item->rawbounds;
274            else
275               union_render_bounds(&view->bounds, &item->rawbounds);
276            first = FALSE;
277362
278            /* accumulate screen bounds */
279            if (item->element == NULL)
280            {
281               if (scrfirst)
282                  view->scrbounds = item->rawbounds;
283               else
284                  union_render_bounds(&view->scrbounds, &item->rawbounds);
285               scrfirst = FALSE;
363//-------------------------------------------------
364//  parse_color - parse a color XML node
365//-------------------------------------------------
286366
287               /* accumulate the screens in use while we're scanning */
288               view->screens |= 1 << item->index;
289            }
290         }
291      }
367void parse_color(running_machine &machine, xml_data_node *colornode, render_color &color)
368{
369   // skip if nothing
370   if (colornode == NULL)
371   {
372      color.r = color.g = color.b = color.a = 1.0f;
373      return;
292374   }
293375
294   /* if we have an explicit bounds, override it */
295   if (view->expbounds.x1 > view->expbounds.x0)
296      view->bounds = view->expbounds;
376   // parse out the data
377   color.r = xml_get_attribute_float_with_subst(machine, *colornode, "red", 1.0);
378   color.g = xml_get_attribute_float_with_subst(machine, *colornode, "green", 1.0);
379   color.b = xml_get_attribute_float_with_subst(machine, *colornode, "blue", 1.0);
380   color.a = xml_get_attribute_float_with_subst(machine, *colornode, "alpha", 1.0);
297381
298   /* compute the aspect ratio of the view */
299   view->aspect = (view->bounds.x1 - view->bounds.x0) / (view->bounds.y1 - view->bounds.y0);
300   view->scraspect = (view->scrbounds.x1 - view->scrbounds.x0) / (view->scrbounds.y1 - view->scrbounds.y0);
382   // check for errors
383   if (color.r < 0.0 || color.r > 1.0 || color.g < 0.0 || color.g > 1.0 ||
384      color.b < 0.0 || color.b > 1.0 || color.a < 0.0 || color.a > 1.0)
385      throw emu_fatalerror("Illegal ARGB color value in XML: %f,%f,%f,%f", color.r, color.g, color.b, color.a);
386}
301387
302   /* if we're handling things normally, the target bounds are (0,0)-(1,1) */
303   if (!(layerconfig & LAYER_CONFIG_ZOOM_TO_SCREEN) || view->screens == 0)
388
389//-------------------------------------------------
390//  parse_orientation - parse an orientation XML
391//  node
392//-------------------------------------------------
393
394static void parse_orientation(running_machine &machine, xml_data_node *orientnode, int &orientation)
395{
396   // skip if nothing
397   if (orientnode == NULL)
304398   {
305      target_bounds.x0 = target_bounds.y0 = 0.0f;
306      target_bounds.x1 = target_bounds.y1 = 1.0f;
399      orientation = ROT0;
400      return;
307401   }
308402
309   /* if we're cropping, we want the screen area to fill (0,0)-(1,1) */
310   else
403   // parse out the data
404   int rotate = xml_get_attribute_int_with_subst(machine, *orientnode, "rotate", 0);
405   switch (rotate)
311406   {
312      float targwidth = (view->bounds.x1 - view->bounds.x0) / (view->scrbounds.x1 - view->scrbounds.x0);
313      float targheight = (view->bounds.y1 - view->bounds.y0) / (view->scrbounds.y1 - view->scrbounds.y0);
314      target_bounds.x0 = (view->bounds.x0 - view->scrbounds.x0) / (view->bounds.x1 - view->bounds.x0) * targwidth;
315      target_bounds.y0 = (view->bounds.y0 - view->scrbounds.y0) / (view->bounds.y1 - view->bounds.y0) * targheight;
316      target_bounds.x1 = target_bounds.x0 + targwidth;
317      target_bounds.y1 = target_bounds.y0 + targheight;
407      case 0:      orientation = ROT0;      break;
408      case 90:   orientation = ROT90;   break;
409      case 180:   orientation = ROT180;   break;
410      case 270:   orientation = ROT270;   break;
411      default:   throw emu_fatalerror("Invalid rotation in XML orientation node: %d", rotate); break;
318412   }
413   if (strcmp("yes", xml_get_attribute_string_with_subst(machine, *orientnode, "swapxy", "no")) == 0)
414      orientation ^= ORIENTATION_SWAP_XY;
415   if (strcmp("yes", xml_get_attribute_string_with_subst(machine, *orientnode, "flipx", "no")) == 0)
416      orientation ^= ORIENTATION_FLIP_X;
417   if (strcmp("yes", xml_get_attribute_string_with_subst(machine, *orientnode, "flipy", "no")) == 0)
418      orientation ^= ORIENTATION_FLIP_Y;
419}
319420
320   /* determine the scale/offset for normalization */
321   xoffs = view->bounds.x0;
322   yoffs = view->bounds.y0;
323   xscale = (target_bounds.x1 - target_bounds.x0) / (view->bounds.x1 - view->bounds.x0);
324   yscale = (target_bounds.y1 - target_bounds.y0) / (view->bounds.y1 - view->bounds.y0);
325421
326   /* normalize all the item bounds */
327   for (layer = 0; layer < ITEM_LAYER_MAX; layer++)
422
423//**************************************************************************
424//  LAYOUT ELEMENT
425//**************************************************************************
426
427//-------------------------------------------------
428//  layout_element - constructor
429//-------------------------------------------------
430
431layout_element::layout_element(running_machine &machine, xml_data_node &elemnode, const char *dirname)
432   : m_next(NULL),
433     m_machine(machine),
434     m_complist(machine.m_respool),
435     m_defstate(0),
436     m_maxstate(0),
437     m_elemtex(NULL)
438{
439   // extract the name
440   const char *name = xml_get_attribute_string_with_subst(machine, elemnode, "name", NULL);
441   if (name == NULL)
442      throw emu_fatalerror("All layout elements must have a name!\n");
443   m_name = name;
444   
445   // get the default state
446   m_defstate = xml_get_attribute_int_with_subst(machine, elemnode, "defstate", -1);
447
448   // parse components in order
449   bool first = true;
450   render_bounds bounds = { 0 };
451   for (xml_data_node *compnode = elemnode.child; compnode != NULL; compnode = compnode->next)
328452   {
329      view_item *item;
453      // allocate a new component
454      component &newcomp = m_complist.append(*auto_alloc(&machine, component(machine, *compnode, dirname)));
330455
331      /* adjust the bounds for each item */
332      for (item = view->itemlist[layer]; item; item = item->next)
333      {
334         item->bounds.x0 = target_bounds.x0 + (item->rawbounds.x0 - xoffs) * xscale;
335         item->bounds.x1 = target_bounds.x0 + (item->rawbounds.x1 - xoffs) * xscale;
336         item->bounds.y0 = target_bounds.y0 + (item->rawbounds.y0 - yoffs) * yscale;
337         item->bounds.y1 = target_bounds.y0 + (item->rawbounds.y1 - yoffs) * yscale;
338      }
456      // accumulate bounds
457      if (first)
458         bounds = newcomp.m_bounds;
459      else
460         union_render_bounds(&bounds, &newcomp.m_bounds);
461      first = false;
462
463      // determine the maximum state
464      if (newcomp.m_state > m_maxstate)
465         m_maxstate = newcomp.m_state;
466      if (newcomp.m_type == component::CTYPE_LED7SEG)
467         m_maxstate = 255;
468      if (newcomp.m_type == component::CTYPE_LED14SEG)
469         m_maxstate = 16383;
470      if (newcomp.m_type == component::CTYPE_LED14SEGSC || newcomp.m_type == component::CTYPE_LED16SEG)
471         m_maxstate = 65535;
472      if (newcomp.m_type == component::CTYPE_LED16SEGSC)
473         m_maxstate = 262143;
474      if (newcomp.m_type == component::CTYPE_DOTMATRIX)
475         m_maxstate = 255;
339476   }
477   
478   // determine the scale/offset for normalization
479   float xoffs = bounds.x0;
480   float yoffs = bounds.y0;
481   float xscale = 1.0f / (bounds.x1 - bounds.x0);
482   float yscale = 1.0f / (bounds.y1 - bounds.y0);
483
484   // normalize all the component bounds
485   for (component *curcomp = m_complist.first(); curcomp != NULL; curcomp = curcomp->next())
486   {
487      curcomp->m_bounds.x0 = (curcomp->m_bounds.x0 - xoffs) * xscale;
488      curcomp->m_bounds.x1 = (curcomp->m_bounds.x1 - xoffs) * xscale;
489      curcomp->m_bounds.y0 = (curcomp->m_bounds.y0 - yoffs) * yscale;
490      curcomp->m_bounds.y1 = (curcomp->m_bounds.y1 - yoffs) * yscale;
491   }
492
493   // allocate an array of element textures for the states
494   m_elemtex = auto_alloc_array(&machine, texture, m_maxstate + 1);
340495}
341496
342497
498//-------------------------------------------------
499//  ~layout_element - destructor
500//-------------------------------------------------
343501
344/***************************************************************************
345    LAYOUT ELEMENTS
346***************************************************************************/
502layout_element::~layout_element()
503{
504   // loop over all states and free their textures
505   auto_free(&m_machine, m_elemtex);
506}
347507
348/*-------------------------------------------------
349    layout_element_scale - scale an element by
350    rendering all the components at the
351    appropriate resolution
352-------------------------------------------------*/
353508
354static void layout_element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param)
509//-------------------------------------------------
510//  state_texture - return a pointer to a
511//  render_texture for the given state, allocating
512//  one if needed
513//-------------------------------------------------
514
515render_texture *layout_element::state_texture(int state)
355516{
356   element_texture *elemtex = (element_texture *)param;
357   element_component *component;
517   assert(state <= m_maxstate);
518   if (m_elemtex[state].m_texture == NULL)
519   {
520      m_elemtex[state].m_element = this;
521      m_elemtex[state].m_state = state;
522      m_elemtex[state].m_texture = m_machine.render().texture_alloc(element_scale, &m_elemtex[state]);
523   }
524   return m_elemtex[state].m_texture;
525}
358526
359   /* iterate over components that are part of the current state */
360   for (component = elemtex->element->complist; component != NULL; component = component->next)
361      if (component->state == -1 || component->state == elemtex->state)
527
528//-------------------------------------------------
529//  element_scale - scale an element by rendering
530//  all the components at the appropriate
531//  resolution
532//-------------------------------------------------
533
534void layout_element::element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param)
535{
536   texture *elemtex = (texture *)param;
537
538   // iterate over components that are part of the current state
539   for (component *curcomp = elemtex->m_element->m_complist.first(); curcomp != NULL; curcomp = curcomp->next())
540      if (curcomp->m_state == -1 || curcomp->m_state == elemtex->m_state)
362541      {
542         // get the local scaled bounds
363543         rectangle bounds;
544         bounds.min_x = render_round_nearest(curcomp->bounds().x0 * dest.width);
545         bounds.min_y = render_round_nearest(curcomp->bounds().y0 * dest.height);
546         bounds.max_x = render_round_nearest(curcomp->bounds().x1 * dest.width);
547         bounds.max_y = render_round_nearest(curcomp->bounds().y1 * dest.height);
364548
365         /* get the local scaled bounds */
366         bounds.min_x = render_round_nearest(component->bounds.x0 * dest.width);
367         bounds.min_y = render_round_nearest(component->bounds.y0 * dest.height);
368         bounds.max_x = render_round_nearest(component->bounds.x1 * dest.width);
369         bounds.max_y = render_round_nearest(component->bounds.y1 * dest.height);
549         // based on the component type, add to the texture
550         curcomp->draw(elemtex->m_element->m_machine, dest, bounds, elemtex->m_state);
551      }
552}
370553
371         /* based on the component type, add to the texture */
372         switch (component->type)
373         {
374            case COMPONENT_TYPE_IMAGE:
375               if (component->bitmap == NULL)
376                  component->bitmap = load_component_bitmap(component->dirname, component->imagefile, component->alphafile, &component->hasalpha);
377               render_resample_argb_bitmap_hq(
378                     BITMAP_ADDR32(&dest, bounds.min_y, bounds.min_x),
379                     dest.rowpixels,
380                     bounds.max_x - bounds.min_x,
381                     bounds.max_y - bounds.min_y,
382                     component->bitmap, NULL, &component->color);
383               break;
384554
385            case COMPONENT_TYPE_RECT:
386               layout_element_draw_rect(dest, bounds, component->color);
387               break;
555//**************************************************************************
556//  LAYOUT ELEMENT TEXTURE
557//**************************************************************************
388558
389            case COMPONENT_TYPE_DISK:
390               layout_element_draw_disk(dest, bounds, component->color);
391               break;
559//-------------------------------------------------
560//  texture - constructor
561//-------------------------------------------------
392562
393            case COMPONENT_TYPE_TEXT:
394               layout_element_draw_text(*elemtex->element->machine, dest, bounds, component->color, component->string);
395               break;
563layout_element::texture::texture()
564   : m_element(NULL),
565     m_texture(NULL),
566     m_state(0)
567{
568}
396569
397            case COMPONENT_TYPE_LED7SEG:
398               layout_element_draw_led7seg(dest, bounds, component->color, elemtex->state);
399               break;
400570
401            case COMPONENT_TYPE_LED14SEG:
402               layout_element_draw_led14seg(dest, bounds, component->color, elemtex->state);
403               break;
571//-------------------------------------------------
572//  ~texture - destructor
573//-------------------------------------------------
404574
405            case COMPONENT_TYPE_LED16SEG:
406               layout_element_draw_led16seg(dest, bounds, component->color, elemtex->state);
407               break;
575layout_element::texture::~texture()
576{
577   if (m_element != NULL)
578      m_element->m_machine.render().texture_free(m_texture);
579}
408580
409            case COMPONENT_TYPE_LED14SEGSC:
410               layout_element_draw_led14segsc(dest, bounds, component->color, elemtex->state);
411               break;
412581
413            case COMPONENT_TYPE_LED16SEGSC:
414               layout_element_draw_led16segsc(dest, bounds, component->color, elemtex->state);
415               break;
416582
417            case COMPONENT_TYPE_DOTMATRIX:
418               layout_element_draw_dotmatrix(dest, bounds, component->color, elemtex->state);
419               break;
420         }
421      }
583//**************************************************************************
584//  LAYOUT ELEMENT COMPONENT
585//**************************************************************************
586
587//-------------------------------------------------
588//  component - constructor
589//-------------------------------------------------
590
591layout_element::component::component(running_machine &machine, xml_data_node &compnode, const char *dirname)
592   : m_next(NULL),
593     m_type(CTYPE_INVALID),
594     m_state(0),
595     m_bitmap(NULL),
596     m_hasalpha(false)
597{
598   // fetch common data
599   m_state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1);
600   parse_bounds(machine, xml_get_sibling(compnode.child, "bounds"), m_bounds);
601   parse_color(machine, xml_get_sibling(compnode.child, "color"), m_color);
602
603   // image nodes
604   if (strcmp(compnode.name, "image") == 0)
605   {
606      m_type = CTYPE_IMAGE;
607      m_dirname = dirname;
608      m_imagefile = xml_get_attribute_string_with_subst(machine, compnode, "file", "");
609      m_alphafile = xml_get_attribute_string_with_subst(machine, compnode, "alphafile", "");
610   }
611
612   // text nodes
613   else if (strcmp(compnode.name, "text") == 0)
614   {
615      m_type = CTYPE_TEXT;
616      m_string = xml_get_attribute_string_with_subst(machine, compnode, "string", "");
617   }
618
619   // dotmatrix nodes
620   else if (strcmp(compnode.name, "dotmatrix") == 0)
621      m_type = CTYPE_DOTMATRIX;
622
623   // led7seg nodes
624   else if (strcmp(compnode.name, "led7seg") == 0)
625      m_type = CTYPE_LED7SEG;
626
627   // led14seg nodes
628   else if (strcmp(compnode.name, "led14seg") == 0)
629      m_type = CTYPE_LED14SEG;
630
631   // led14segsc nodes
632   else if (strcmp(compnode.name, "led14segsc") == 0)
633      m_type = CTYPE_LED14SEGSC;
634
635   // led16seg nodes
636   else if (strcmp(compnode.name, "led16seg") == 0)
637      m_type = CTYPE_LED16SEG;
638
639   // led16segsc nodes
640   else if (strcmp(compnode.name, "led16segsc") == 0)
641      m_type = CTYPE_LED16SEGSC;
642
643   // rect nodes
644   else if (strcmp(compnode.name, "rect") == 0)
645      m_type = CTYPE_RECT;
646
647   // disk nodes
648   else if (strcmp(compnode.name, "disk") == 0)
649      m_type = CTYPE_DISK;
650
651   // error otherwise
652   else
653      throw emu_fatalerror("Unknown element component: %s", compnode.name);
422654}
423655
424656
425/*-------------------------------------------------
426    layout_element_draw_rect - draw a rectangle
427    in the specified color
428-------------------------------------------------*/
657//-------------------------------------------------
658//  ~component - destructor
659//-------------------------------------------------
429660
430static void layout_element_draw_rect(bitmap_t &dest, const rectangle &bounds, const render_color &color)
661layout_element::component::~component()
431662{
432   UINT32 r, g, b, inva;
433   UINT32 x, y;
663   global_free(m_bitmap);
664}
434665
435   /* compute premultiplied colors */
436   r = color.r * color.a * 255.0;
437   g = color.g * color.a * 255.0;
438   b = color.b * color.a * 255.0;
439   inva = (1.0f - color.a) * 255.0;
440666
441   /* iterate over X and Y */
442   for (y = bounds.min_y; y < bounds.max_y; y++)
443      for (x = bounds.min_x; x < bounds.max_x; x++)
667//-------------------------------------------------
668//  draw - draw a component
669//-------------------------------------------------
670
671void layout_element::component::draw(running_machine &machine, bitmap_t &dest, const rectangle &bounds, int state)
672{
673   switch (m_type)
674   {
675      case CTYPE_IMAGE:
676         if (m_bitmap == NULL)
677            m_bitmap = load_bitmap();
678         render_resample_argb_bitmap_hq(
679               BITMAP_ADDR32(&dest, bounds.min_y, bounds.min_x),
680               dest.rowpixels,
681               bounds.max_x - bounds.min_x,
682               bounds.max_y - bounds.min_y,
683               m_bitmap, NULL, &m_color);
684         break;
685
686      case CTYPE_RECT:
687         draw_rect(dest, bounds);
688         break;
689
690      case CTYPE_DISK:
691         draw_disk(dest, bounds);
692         break;
693
694      case CTYPE_TEXT:
695         draw_text(machine, dest, bounds);
696         break;
697
698      case CTYPE_LED7SEG:
699         draw_led7seg(dest, bounds, state);
700         break;
701
702      case CTYPE_LED14SEG:
703         draw_led14seg(dest, bounds, state);
704         break;
705
706      case CTYPE_LED16SEG:
707         draw_led16seg(dest, bounds, state);
708         break;
709
710      case CTYPE_LED14SEGSC:
711         draw_led14segsc(dest, bounds, state);
712         break;
713
714      case CTYPE_LED16SEGSC:
715         draw_led16segsc(dest, bounds, state);
716         break;
717
718      case CTYPE_DOTMATRIX:
719         draw_dotmatrix(dest, bounds, state);
720         break;
721     
722      default:
723         throw emu_fatalerror("Unknown component type requested draw()");
724   }
725}
726
727
728//-------------------------------------------------
729//  draw_rect - draw a rectangle in the specified
730//  color
731//-------------------------------------------------
732
733void layout_element::component::draw_rect(bitmap_t &dest, const rectangle &bounds)
734{
735   // compute premultiplied colors
736   UINT32 r = m_color.r * m_color.a * 255.0;
737   UINT32 g = m_color.g * m_color.a * 255.0;
738   UINT32 b = m_color.b * m_color.a * 255.0;
739   UINT32 inva = (1.0f - m_color.a) * 255.0;
740
741   // iterate over X and Y
742   for (UINT32 y = bounds.min_y; y < bounds.max_y; y++)
743      for (UINT32 x = bounds.min_x; x < bounds.max_x; x++)
444744      {
445745         UINT32 finalr = r;
446746         UINT32 finalg = g;
447747         UINT32 finalb = b;
448748
449         /* if we're translucent, add in the destination pixel contribution */
749         // if we're translucent, add in the destination pixel contribution
450750         if (inva > 0)
451751         {
452752            UINT32 dpix = *BITMAP_ADDR32(&dest, y, x);
r9411r9412
455755            finalb += (RGB_BLUE(dpix) * inva) >> 8;
456756         }
457757
458         /* store the target pixel, dividing the RGBA values by the overall scale factor */
758         // store the target pixel, dividing the RGBA values by the overall scale factor
459759         *BITMAP_ADDR32(&dest, y, x) = MAKE_ARGB(0xff, finalr, finalg, finalb);
460760      }
461761}
462762
463763
464/*-------------------------------------------------
465    layout_element_draw_disk - draw an ellipse
466    in the specified color
467-------------------------------------------------*/
764//-------------------------------------------------
765//  draw_disk - draw an ellipse in the specified
766//  color
767//-------------------------------------------------
468768
469static void layout_element_draw_disk(bitmap_t &dest, const rectangle &bounds, const render_color &color)
769void layout_element::component::draw_disk(bitmap_t &dest, const rectangle &bounds)
470770{
471   float xcenter, ycenter;
472   float xradius, yradius, ooyradius2;
473   UINT32 r, g, b, inva;
474   UINT32 x, y;
771   // compute premultiplied colors
772   UINT32 r = m_color.r * m_color.a * 255.0;
773   UINT32 g = m_color.g * m_color.a * 255.0;
774   UINT32 b = m_color.b * m_color.a * 255.0;
775   UINT32 inva = (1.0f - m_color.a) * 255.0;
475776
476   /* compute premultiplied colors */
477   r = color.r * color.a * 255.0;
478   g = color.g * color.a * 255.0;
479   b = color.b * color.a * 255.0;
480   inva = (1.0f - color.a) * 255.0;
777   // find the center
778   float xcenter = (float)(bounds.min_x + bounds.max_x) * 0.5f;
779   float ycenter = (float)(bounds.min_y + bounds.max_y) * 0.5f;
780   float xradius = (float)(bounds.max_x - bounds.min_x) * 0.5f;
781   float yradius = (float)(bounds.max_y - bounds.min_y) * 0.5f;
782   float ooyradius2 = 1.0f / (yradius * yradius);
481783
482   /* find the center */
483   xcenter = (float)(bounds.min_x + bounds.max_x) * 0.5f;
484   ycenter = (float)(bounds.min_y + bounds.max_y) * 0.5f;
485   xradius = (float)(bounds.max_x - bounds.min_x) * 0.5f;
486   yradius = (float)(bounds.max_y - bounds.min_y) * 0.5f;
487   ooyradius2 = 1.0f / (yradius * yradius);
488
489   /* iterate over y */
490   for (y = bounds.min_y; y < bounds.max_y; y++)
784   // iterate over y
785   for (UINT32 y = bounds.min_y; y < bounds.max_y; y++)
491786   {
492787      float ycoord = ycenter - ((float)y + 0.5f);
493788      float xval = xradius * sqrt(1.0f - (ycoord * ycoord) * ooyradius2);
494      INT32 left, right;
495789
496      /* compute left/right coordinates */
497      left = (INT32)(xcenter - xval + 0.5f);
498      right = (INT32)(xcenter + xval + 0.5f);
790      // compute left/right coordinates
791      INT32 left = (INT32)(xcenter - xval + 0.5f);
792      INT32 right = (INT32)(xcenter + xval + 0.5f);
499793
500      /* draw this scanline */
501      for (x = left; x < right; x++)
794      // draw this scanline
795      for (UINT32 x = left; x < right; x++)
502796      {
503797         UINT32 finalr = r;
504798         UINT32 finalg = g;
505799         UINT32 finalb = b;
506800
507         /* if we're translucent, add in the destination pixel contribution */
801         // if we're translucent, add in the destination pixel contribution
508802         if (inva > 0)
509803         {
510804            UINT32 dpix = *BITMAP_ADDR32(&dest, y, x);
r9411r9412
513807            finalb += (RGB_BLUE(dpix) * inva) >> 8;
514808         }
515809
516         /* store the target pixel, dividing the RGBA values by the overall scale factor */
810         // store the target pixel, dividing the RGBA values by the overall scale factor
517811         *BITMAP_ADDR32(&dest, y, x) = MAKE_ARGB(0xff, finalr, finalg, finalb);
518812      }
519813   }
520814}
521815
522816
523/*-------------------------------------------------
524    layout_element_draw_text - draw text in the
525    specified color
526-------------------------------------------------*/
817//-------------------------------------------------
818//  draw_text - draw text in the specified color
819//-------------------------------------------------
527820
528static void layout_element_draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds, const render_color &color, const char *string)
821void layout_element::component::draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds)
529822{
823   // compute premultiplied colors
824   UINT32 r = m_color.r * 255.0;
825   UINT32 g = m_color.g * 255.0;
826   UINT32 b = m_color.b * 255.0;
827   UINT32 a = m_color.a * 255.0;
828
829   // get the width of the string
530830   render_font *font = render_font_alloc(machine, NULL);
531   bitmap_t *tempbitmap;
532   UINT32 r, g, b, a;
533831   float aspect = 1.0f;
534   INT32 curx, width;
535   const char *s;
536
537   /* compute premultiplied colors */
538   r = color.r * 255.0;
539   g = color.g * 255.0;
540   b = color.b * 255.0;
541   a = color.a * 255.0;
542
543   /* get the width of the string */
832   INT32 width;
544833   while (1)
545834   {
546      width = render_font_get_string_width(font, bounds.max_y - bounds.min_y, aspect, string);
835      width = render_font_get_string_width(font, bounds.max_y - bounds.min_y, aspect, m_string);
547836      if (width < bounds.max_x - bounds.min_x)
548837         break;
549838      aspect *= 0.9f;
550839   }
551   curx = bounds.min_x + (bounds.max_x - bounds.min_x - width) / 2;
840   INT32 curx = bounds.min_x + (bounds.max_x - bounds.min_x - width) / 2;
552841
553   /* allocate a temporary bitmap */
554   tempbitmap = global_alloc(bitmap_t(dest.width, dest.height, BITMAP_FORMAT_ARGB32));
842   // allocate a temporary bitmap
843   bitmap_t *tempbitmap = global_alloc(bitmap_t(dest.width, dest.height, BITMAP_FORMAT_ARGB32));
555844
556   /* loop over characters */
557   for (s = string; *s != 0; s++)
845   // loop over characters
846   for (const char *s = m_string; *s != 0; s++)
558847   {
848      // get the font bitmap
559849      rectangle chbounds;
560      int x, y;
561
562      /* get the font bitmap */
563850      render_font_get_scaled_bitmap_and_bounds(font, tempbitmap, bounds.max_y - bounds.min_y, aspect, *s, &chbounds);
564851
565      /* copy the data into the target */
566      for (y = 0; y < chbounds.max_y - chbounds.min_y; y++)
852      // copy the data into the target
853      for (int y = 0; y < chbounds.max_y - chbounds.min_y; y++)
567854      {
568855         int effy = bounds.min_y + y;
569856         if (effy >= bounds.min_y && effy <= bounds.max_y)
570857         {
571858            UINT32 *src = BITMAP_ADDR32(tempbitmap, y, 0);
572859            UINT32 *d = BITMAP_ADDR32(&dest, effy, 0);
573            for (x = 0; x < chbounds.max_x - chbounds.min_x; x++)
860            for (int x = 0; x < chbounds.max_x - chbounds.min_x; x++)
574861            {
575862               int effx = curx + x + chbounds.min_x;
576863               if (effx >= bounds.min_x && effx <= bounds.max_x)
r9411r9412
579866                  if (spix != 0)
580867                  {
581868                     UINT32 dpix = d[effx];
582                     UINT32 ta, tr, tg, tb;
583
584                     ta = (a * (spix + 1)) >> 8;
585                     tr = (r * ta + RGB_RED(dpix) * (0x100 - ta)) >> 8;
586                     tg = (g * ta + RGB_GREEN(dpix) * (0x100 - ta)) >> 8;
587                     tb = (b * ta + RGB_BLUE(dpix) * (0x100 - ta)) >> 8;
869                     UINT32 ta = (a * (spix + 1)) >> 8;
870                     UINT32 tr = (r * ta + RGB_RED(dpix) * (0x100 - ta)) >> 8;
871                     UINT32 tg = (g * ta + RGB_GREEN(dpix) * (0x100 - ta)) >> 8;
872                     UINT32 tb = (b * ta + RGB_BLUE(dpix) * (0x100 - ta)) >> 8;
588873                     d[effx] = MAKE_ARGB(0xff, tr, tg, tb);
589874                  }
590875               }
r9411r9412
592877         }
593878      }
594879
595      /* advance in the X direction */
880      // advance in the X direction
596881      curx += render_font_get_char_width(font, bounds.max_y - bounds.min_y, aspect, *s);
597882   }
598883
599   /* free the temporary bitmap and font */
884   // free the temporary bitmap and font
600885   global_free(tempbitmap);
601886   render_font_free(font);
602887}
603888
604889
605/*-------------------------------------------------
606    draw_segment_horizontal_caps - draw a
607    horizontal LED segment with definable end
608    and start points
609-------------------------------------------------*/
890//-------------------------------------------------
891//  load_bitmap - load a PNG file with artwork for
892//  a component
893//-------------------------------------------------
610894
611static void draw_segment_horizontal_caps(bitmap_t &dest, int minx, int maxx, int midy, int width, int caps, rgb_t color)
895bitmap_t *layout_element::component::load_bitmap()
612896{
613   int x, y;
897   // load the basic bitmap
898   bitmap_t *bitmap = render_load_png(OPTION_ARTPATH, m_dirname, m_imagefile, NULL, &m_hasalpha);
899   if (bitmap != NULL && m_alphafile)
614900
615   /* loop over the width of the segment */
616   for (y = 0; y < width / 2; y++)
617   {
618      UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0);
619      UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0);
620      int ty = (y < width / 8) ? width / 8 : y;
621
622      /* loop over the length of the segment */
623      for (x = minx + ((caps & LINE_CAP_START) ? ty : 0); x < maxx - ((caps & LINE_CAP_END) ? ty : 0); x++)
624         d0[x] = d1[x] = color;
625   }
626}
627
628
629/*-------------------------------------------------
630    draw_segment_horizontal - draw a horizontal
631    LED segment
632-------------------------------------------------*/
633
634static void draw_segment_horizontal(bitmap_t &dest, int minx, int maxx, int midy, int width, rgb_t color)
635{
636   draw_segment_horizontal_caps(dest, minx, maxx, midy, width, LINE_CAP_START | LINE_CAP_END, color);
637}
638
639
640/*-------------------------------------------------
641    draw_segment_vertical_caps - draw a
642    vertical LED segment with definable end
643    and start points
644-------------------------------------------------*/
645
646static void draw_segment_vertical_caps(bitmap_t &dest, int miny, int maxy, int midx, int width, int caps, rgb_t color)
647{
648   int x, y;
649
650   /* loop over the width of the segment */
651   for (x = 0; x < width / 2; x++)
652   {
653      UINT32 *d0 = BITMAP_ADDR32(&dest, 0, midx - x);
654      UINT32 *d1 = BITMAP_ADDR32(&dest, 0, midx + x);
655      int tx = (x < width / 8) ? width / 8 : x;
656
657      /* loop over the length of the segment */
658      for (y = miny + ((caps & LINE_CAP_START) ? tx : 0); y < maxy - ((caps & LINE_CAP_END) ? tx : 0); y++)
659         d0[y * dest.rowpixels] = d1[y * dest.rowpixels] = color;
660   }
661}
662
663
664/*-------------------------------------------------
665    draw_segment_vertical - draw a vertical
666    LED segment
667-------------------------------------------------*/
668
669static void draw_segment_vertical(bitmap_t &dest, int miny, int maxy, int midx, int width, rgb_t color)
670{
671   draw_segment_vertical_caps(dest, miny, maxy, midx, width, LINE_CAP_START | LINE_CAP_END, color);
672}
673
674
675/*-------------------------------------------------
676    draw_segment_diagonal_1 - draw a diagonal
677    LED segment that looks like this: /
678-------------------------------------------------*/
679
680static void draw_segment_diagonal_1(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color)
681{
682   int x, y;
683   float ratio;
684
685   /* compute parameters */
686   width *= 1.5;
687   ratio = (maxy - miny - width) / (float)(maxx - minx);
688
689   /* draw line */
690   for (x = minx; x < maxx; x++)
691      if (x >= 0 && x < dest.width)
901      // load the alpha bitmap if specified
902      if (render_load_png(OPTION_ARTPATH, m_dirname, m_alphafile, bitmap, &m_hasalpha) == NULL)
692903      {
693         UINT32 *d = BITMAP_ADDR32(&dest, 0, x);
694         int step = (x - minx) * ratio;
695
696         for (y = maxy - width - step; y < maxy - step; y++)
697            if (y >= 0 && y < dest.height)
698            {
699               d[y * dest.rowpixels] = color;
700            }
904         global_free(bitmap);
905         bitmap = NULL;
701906      }
702}
703907
704
705/*-------------------------------------------------
706    draw_segment_diagonal_2 - draw a diagonal
707    LED segment that looks like this: \
708-------------------------------------------------*/
709
710static void draw_segment_diagonal_2(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color)
711{
712   int x, y;
713   float ratio;
714
715   /* compute parameters */
716   width *= 1.5;
717   ratio = (maxy - miny - width) / (float)(maxx - minx);
718
719   /* draw line */
720   for (x = minx; x < maxx; x++)
721      if (x >= 0 && x < dest.width)
722      {
723         UINT32 *d = BITMAP_ADDR32(&dest, 0, x);
724         int step = (x - minx) * ratio;
725
726         for (y = miny + step; y < miny + step + width; y++)
727            if (y >= 0 && y < dest.height)
728            {
729               d[y * dest.rowpixels] = color;
730            }
731      }
732}
733
734
735/*-------------------------------------------------
736    draw_segment_decimal - draw a decimal point
737-------------------------------------------------*/
738
739static void draw_segment_decimal(bitmap_t &dest, int midx, int midy, int width, rgb_t color)
740{
741   float ooradius2;
742   UINT32 x, y;
743
744   /* compute parameters */
745   width /= 2;
746   ooradius2 = 1.0f / (float)(width * width);
747
748   /* iterate over y */
749   for (y = 0; y <= width; y++)
908   // if we can't load the bitmap, allocate a dummy one and report an error
909   if (bitmap == NULL)
750910   {
751      UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0);
752      UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0);
753      float xval = width * sqrt(1.0f - (float)(y * y) * ooradius2);
754      INT32 left, right;
911      // draw some stripes in the bitmap
912      bitmap = global_alloc(bitmap_t(100, 100, BITMAP_FORMAT_ARGB32));
913      bitmap_fill(bitmap, NULL, 0);
914      for (int step = 0; step < 100; step += 25)
915         for (int line = 0; line < 100; line++)
916            *BITMAP_ADDR32(bitmap, (step + line) % 100, line % 100) = MAKE_ARGB(0xff,0xff,0xff,0xff);
755917
756      /* compute left/right coordinates */
757      left = midx - (INT32)(xval + 0.5f);
758      right = midx + (INT32)(xval + 0.5f);
759
760      /* draw this scanline */
761      for (x = left; x < right; x++)
762         d0[x] = d1[x] = color;
918      // log an error
919      if (!m_alphafile)
920         mame_printf_warning("Unable to load component bitmap '%s'", m_imagefile.cstr());
921      else
922         mame_printf_warning("Unable to load component bitmap '%s'/'%s'", m_imagefile.cstr(), m_alphafile.cstr());
763923   }
764}
765924
766/*-------------------------------------------------
767    draw_segment_comma - draw a comma tail
768-------------------------------------------------*/
769#if 0
770static void draw_segment_comma(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color)
771{
772   int x, y;
773   float ratio;
774
775   /* compute parameters */
776   width *= 1.5;
777   ratio = (maxy - miny - width) / (float)(maxx - minx);
778
779   /* draw line */
780   for (x = minx; x < maxx; x++)
781   {
782      UINT32 *d = BITMAP_ADDR32(&dest, 0, x);
783      int step = (x - minx) * ratio;
784
785      for (y = maxy; y < maxy  - width - step; y--)
786      {
787         d[y * dest.rowpixels] = color;
788      }
789   }
925   return bitmap;
790926}
791#endif
792927
793928
794/*-------------------------------------------------
795    apply_skew - apply skew to a bitmap_t
796-------------------------------------------------*/
929//-------------------------------------------------
930//  draw_led7seg - draw a 7-segment LCD
931//-------------------------------------------------
797932
798static void apply_skew(bitmap_t &dest, int skewwidth)
933void layout_element::component::draw_led7seg(bitmap_t &dest, const rectangle &bounds, int pattern)
799934{
800   int x, y;
801
802   for (y = 0; y < dest.height; y++)
803   {
804      UINT32 *destrow = BITMAP_ADDR32(&dest, y, 0);
805      int offs = skewwidth * (dest.height - y) / dest.height;
806      for (x = dest.width - skewwidth - 1; x >= 0; x--)
807         destrow[x + offs] = destrow[x];
808      for (x = 0; x < offs; x++)
809         destrow[x] = 0;
810   }
811}
812
813
814/*-------------------------------------------------
815    layout_element_draw_led7seg - draw a
816    7-segment LCD
817-------------------------------------------------*/
818
819static void layout_element_draw_led7seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern)
820{
821935   const rgb_t onpen = MAKE_ARGB(0xff,0xff,0xff,0xff);
822936   const rgb_t offpen = MAKE_ARGB(0xff,0x20,0x20,0x20);
823   int bmwidth, bmheight, segwidth, skewwidth;
824   bitmap_t *tempbitmap;
825937
826   /* sizes for computation */
827   bmwidth = 250;
828   bmheight = 400;
829   segwidth = 40;
830   skewwidth = 40;
938   // sizes for computation
939   int bmwidth = 250;
940   int bmheight = 400;
941   int segwidth = 40;
942   int skewwidth = 40;
831943
832   /* allocate a temporary bitmap for drawing */
833   tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32));
944   // allocate a temporary bitmap for drawing
945   bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32));
834946   bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff,0x00,0x00,0x00));
835947
836   /* top bar */
948   // top bar
837949   draw_segment_horizontal(*tempbitmap, 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, 0 + segwidth/2, segwidth, (pattern & (1 << 0)) ? onpen : offpen);
838950
839   /* top-right bar */
951   // top-right bar
840952   draw_segment_vertical(*tempbitmap, 0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2, segwidth, (pattern & (1 << 1)) ? onpen : offpen);
841953
842   /* bottom-right bar */
954   // bottom-right bar
843955   draw_segment_vertical(*tempbitmap, bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2, segwidth, (pattern & (1 << 2)) ? onpen : offpen);
844956
845   /* bottom bar */
957   // bottom bar
846958   draw_segment_horizontal(*tempbitmap, 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight - segwidth/2, segwidth, (pattern & (1 << 3)) ? onpen : offpen);
847959
848   /* bottom-left bar */
960   // bottom-left bar
849961   draw_segment_vertical(*tempbitmap, bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2, segwidth, (pattern & (1 << 4)) ? onpen : offpen);
850962
851   /* top-left bar */
963   // top-left bar
852964   draw_segment_vertical(*tempbitmap, 0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2, segwidth, (pattern & (1 << 5)) ? onpen : offpen);
853965
854   /* middle bar */
966   // middle bar
855967   draw_segment_horizontal(*tempbitmap, 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight/2, segwidth, (pattern & (1 << 6)) ? onpen : offpen);
856968
857   /* apply skew */
969   // apply skew
858970   apply_skew(*tempbitmap, 40);
859971
860   /* decimal point */
972   // decimal point
861973   draw_segment_decimal(*tempbitmap, bmwidth + segwidth/2, bmheight - segwidth/2, segwidth, (pattern & (1 << 7)) ? onpen : offpen);
862974
863   /* resample to the target size */
864   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color);
975   // resample to the target size
976   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color);
865977
866978   global_free(tempbitmap);
867979}
868980
869981
870/*-------------------------------------------------
871    layout_element_draw_led14seg - draw a
872    14-segment LCD
873-------------------------------------------------*/
982//-------------------------------------------------
983//  draw_led14seg - draw a 14-segment LCD
984//-------------------------------------------------
874985
875static void layout_element_draw_led14seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern)
986void layout_element::component::draw_led14seg(bitmap_t &dest, const rectangle &bounds, int pattern)
876987{
877988   const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff);
878989   const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20);
879   int bmwidth, bmheight, segwidth, skewwidth;
880   bitmap_t *tempbitmap;
881990
882   /* sizes for computation */
883   bmwidth = 250;
884   bmheight = 400;
885   segwidth = 40;
886   skewwidth = 40;
991   // sizes for computation
992   int bmwidth = 250;
993   int bmheight = 400;
994   int segwidth = 40;
995   int skewwidth = 40;
887996
888   /* allocate a temporary bitmap for drawing */
889   tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32));
997   // allocate a temporary bitmap for drawing
998   bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32));
890999   bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00));
8911000
892   /* top bar */
1001   // top bar
8931002   draw_segment_horizontal(*tempbitmap,
8941003      0 + 2*segwidth/3, bmwidth - 2*segwidth/3, 0 + segwidth/2,
8951004      segwidth, (pattern & (1 << 0)) ? onpen : offpen);
8961005
897   /* right-top bar */
1006   // right-top bar
8981007   draw_segment_vertical(*tempbitmap,
8991008      0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2,
9001009      segwidth, (pattern & (1 << 1)) ? onpen : offpen);
9011010
902   /* right-bottom bar */
1011   // right-bottom bar
9031012   draw_segment_vertical(*tempbitmap,
9041013      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2,
9051014      segwidth, (pattern & (1 << 2)) ? onpen : offpen);
9061015
907   /* bottom bar */
1016   // bottom bar
9081017   draw_segment_horizontal(*tempbitmap,
9091018      0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight - segwidth/2,
9101019      segwidth, (pattern & (1 << 3)) ? onpen : offpen);
9111020
912   /* left-bottom bar */
1021   // left-bottom bar
9131022   draw_segment_vertical(*tempbitmap,
9141023      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2,
9151024      segwidth, (pattern & (1 << 4)) ? onpen : offpen);
9161025
917   /* left-top bar */
1026   // left-top bar
9181027   draw_segment_vertical(*tempbitmap,
9191028      0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2,
9201029      segwidth, (pattern & (1 << 5)) ? onpen : offpen);
9211030
922   /* horizontal-middle-left bar */
1031   // horizontal-middle-left bar
9231032   draw_segment_horizontal_caps(*tempbitmap,
9241033      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2,
9251034      segwidth, LINE_CAP_START, (pattern & (1 << 6)) ? onpen : offpen);
9261035
927   /* horizontal-middle-right bar */
1036   // horizontal-middle-right bar
9281037   draw_segment_horizontal_caps(*tempbitmap,
9291038      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2,
9301039      segwidth, LINE_CAP_END, (pattern & (1 << 7)) ? onpen : offpen);
9311040
932   /* vertical-middle-top bar */
1041   // vertical-middle-top bar
9331042   draw_segment_vertical_caps(*tempbitmap,
9341043      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2,
9351044      segwidth, LINE_CAP_NONE, (pattern & (1 << 8)) ? onpen : offpen);
9361045
937   /* vertical-middle-bottom bar */
1046   // vertical-middle-bottom bar
9381047   draw_segment_vertical_caps(*tempbitmap,
9391048      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2,
9401049      segwidth, LINE_CAP_NONE, (pattern & (1 << 9)) ? onpen : offpen);
9411050
942   /* diagonal-left-bottom bar */
1051   // diagonal-left-bottom bar
9431052   draw_segment_diagonal_1(*tempbitmap,
9441053      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
9451054      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
9461055      segwidth, (pattern & (1 << 10)) ? onpen : offpen);
9471056
948   /* diagonal-left-top bar */
1057   // diagonal-left-top bar
9491058   draw_segment_diagonal_2(*tempbitmap,
9501059      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
9511060      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
9521061      segwidth, (pattern & (1 << 11)) ? onpen : offpen);
9531062
954   /* diagonal-right-top bar */
1063   // diagonal-right-top bar
9551064   draw_segment_diagonal_1(*tempbitmap,
9561065      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
9571066      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
9581067      segwidth, (pattern & (1 << 12)) ? onpen : offpen);
9591068
960   /* diagonal-right-bottom bar */
1069   // diagonal-right-bottom bar
9611070   draw_segment_diagonal_2(*tempbitmap,
9621071      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
9631072      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
9641073      segwidth, (pattern & (1 << 13)) ? onpen : offpen);
9651074
966   /* apply skew */
1075   // apply skew
9671076   apply_skew(*tempbitmap, 40);
9681077
969   /* resample to the target size */
970   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color);
1078   // resample to the target size
1079   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color);
9711080
9721081   global_free(tempbitmap);
9731082}
9741083
9751084
976/*-------------------------------------------------
977    layout_element_draw_led14segsc - draw a
978    14-segment LCD with semicolon (2 extra segments)
979-------------------------------------------------*/
1085//-------------------------------------------------
1086//  draw_led14segsc - draw a 14-segment LCD with
1087//  semicolon (2 extra segments)
1088//-------------------------------------------------
9801089
981static void layout_element_draw_led14segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern)
1090void layout_element::component::draw_led14segsc(bitmap_t &dest, const rectangle &bounds, int pattern)
9821091{
9831092   const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff);
9841093   const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20);
985   int bmwidth, bmheight, segwidth, skewwidth;
986   bitmap_t *tempbitmap;
9871094
988   /* sizes for computation */
989   bmwidth = 250;
990   bmheight = 400;
991   segwidth = 40;
992   skewwidth = 40;
1095   // sizes for computation
1096   int bmwidth = 250;
1097   int bmheight = 400;
1098   int segwidth = 40;
1099   int skewwidth = 40;
9931100
994   /* allocate a temporary bitmap for drawing, adding some extra space for the tail */
995   tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32));
1101   // allocate a temporary bitmap for drawing, adding some extra space for the tail
1102   bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32));
9961103   bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00));
9971104
998   /* top bar */
1105   // top bar
9991106   draw_segment_horizontal(*tempbitmap,
10001107      0 + 2*segwidth/3, bmwidth - 2*segwidth/3, 0 + segwidth/2,
10011108      segwidth, (pattern & (1 << 0)) ? onpen : offpen);
10021109
1003   /* right-top bar */
1110   // right-top bar
10041111   draw_segment_vertical(*tempbitmap,
10051112      0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2,
10061113      segwidth, (pattern & (1 << 1)) ? onpen : offpen);
10071114
1008   /* right-bottom bar */
1115   // right-bottom bar
10091116   draw_segment_vertical(*tempbitmap,
10101117      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2,
10111118      segwidth, (pattern & (1 << 2)) ? onpen : offpen);
10121119
1013   /* bottom bar */
1120   // bottom bar
10141121   draw_segment_horizontal(*tempbitmap,
10151122      0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight - segwidth/2,
10161123      segwidth, (pattern & (1 << 3)) ? onpen : offpen);
10171124
1018   /* left-bottom bar */
1125   // left-bottom bar
10191126   draw_segment_vertical(*tempbitmap,
10201127      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2,
10211128      segwidth, (pattern & (1 << 4)) ? onpen : offpen);
10221129
1023   /* left-top bar */
1130   // left-top bar
10241131   draw_segment_vertical(*tempbitmap,
10251132      0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2,
10261133      segwidth, (pattern & (1 << 5)) ? onpen : offpen);
10271134
1028   /* horizontal-middle-left bar */
1135   // horizontal-middle-left bar
10291136   draw_segment_horizontal_caps(*tempbitmap,
10301137      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2,
10311138      segwidth, LINE_CAP_START, (pattern & (1 << 6)) ? onpen : offpen);
10321139
1033   /* horizontal-middle-right bar */
1140   // horizontal-middle-right bar
10341141   draw_segment_horizontal_caps(*tempbitmap,
10351142      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2,
10361143      segwidth, LINE_CAP_END, (pattern & (1 << 7)) ? onpen : offpen);
10371144
1038   /* vertical-middle-top bar */
1145   // vertical-middle-top bar
10391146   draw_segment_vertical_caps(*tempbitmap,
10401147      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2,
10411148      segwidth, LINE_CAP_NONE, (pattern & (1 << 8)) ? onpen : offpen);
10421149
1043   /* vertical-middle-bottom bar */
1150   // vertical-middle-bottom bar
10441151   draw_segment_vertical_caps(*tempbitmap,
10451152      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2,
10461153      segwidth, LINE_CAP_NONE, (pattern & (1 << 9)) ? onpen : offpen);
10471154
1048   /* diagonal-left-bottom bar */
1155   // diagonal-left-bottom bar
10491156   draw_segment_diagonal_1(*tempbitmap,
10501157      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
10511158      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
10521159      segwidth, (pattern & (1 << 10)) ? onpen : offpen);
10531160
1054   /* diagonal-left-top bar */
1161   // diagonal-left-top bar
10551162   draw_segment_diagonal_2(*tempbitmap,
10561163      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
10571164      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
10581165      segwidth, (pattern & (1 << 11)) ? onpen : offpen);
10591166
1060   /* diagonal-right-top bar */
1167   // diagonal-right-top bar
10611168   draw_segment_diagonal_1(*tempbitmap,
10621169      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
10631170      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
10641171      segwidth, (pattern & (1 << 12)) ? onpen : offpen);
10651172
1066   /* diagonal-right-bottom bar */
1173   // diagonal-right-bottom bar
10671174   draw_segment_diagonal_2(*tempbitmap,
10681175      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
10691176      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
10701177      segwidth, (pattern & (1 << 13)) ? onpen : offpen);
10711178
1072   /* apply skew */
1179   // apply skew
10731180   apply_skew(*tempbitmap, 40);
10741181
1075   /* decimal point */
1182   // decimal point
10761183   draw_segment_decimal(*tempbitmap, bmwidth + segwidth/2, bmheight - segwidth/2, segwidth, (pattern & (1 << 14)) ? onpen : offpen);
10771184
1078   /* comma tail */
1185   // comma tail
10791186   draw_segment_diagonal_1(*tempbitmap,
10801187      bmwidth - (segwidth/2), bmwidth + segwidth,
10811188      bmheight - (segwidth), bmheight + segwidth*1.5,
10821189      segwidth/2, (pattern & (1 << 15)) ? onpen : offpen);
10831190
1084   /* resample to the target size */
1085   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color);
1191   // resample to the target size
1192   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color);
10861193
10871194   global_free(tempbitmap);
10881195}
10891196
10901197
1091/*-------------------------------------------------
1092    layout_element_draw_led16seg - draw a
1093    16-segment LCD
1094-------------------------------------------------*/
1198//-------------------------------------------------
1199//  draw_led16seg - draw a 16-segment LCD
1200//-------------------------------------------------
10951201
1096static void layout_element_draw_led16seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern)
1202void layout_element::component::draw_led16seg(bitmap_t &dest, const rectangle &bounds, int pattern)
10971203{
10981204   const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff);
10991205   const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20);
1100   int bmwidth, bmheight, segwidth, skewwidth;
1101   bitmap_t *tempbitmap;
11021206
1103   /* sizes for computation */
1104   bmwidth = 250;
1105   bmheight = 400;
1106   segwidth = 40;
1107   skewwidth = 40;
1207   // sizes for computation
1208   int bmwidth = 250;
1209   int bmheight = 400;
1210   int segwidth = 40;
1211   int skewwidth = 40;
11081212
1109   /* allocate a temporary bitmap for drawing */
1110   tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32));
1213   // allocate a temporary bitmap for drawing
1214   bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32));
11111215   bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00));
11121216
1113   /* top-left bar */
1217   // top-left bar
11141218   draw_segment_horizontal_caps(*tempbitmap,
11151219      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, 0 + segwidth/2,
11161220      segwidth, LINE_CAP_START, (pattern & (1 << 0)) ? onpen : offpen);
11171221
1118   /* top-right bar */
1222   // top-right bar
11191223   draw_segment_horizontal_caps(*tempbitmap,
11201224      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, 0 + segwidth/2,
11211225      segwidth, LINE_CAP_END, (pattern & (1 << 1)) ? onpen : offpen);
11221226
1123   /* right-top bar */
1227   // right-top bar
11241228   draw_segment_vertical(*tempbitmap,
11251229      0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2,
11261230      segwidth, (pattern & (1 << 2)) ? onpen : offpen);
11271231
1128   /* right-bottom bar */
1232   // right-bottom bar
11291233   draw_segment_vertical(*tempbitmap,
11301234      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2,
11311235      segwidth, (pattern & (1 << 3)) ? onpen : offpen);
11321236
1133   /* bottom-right bar */
1237   // bottom-right bar
11341238   draw_segment_horizontal_caps(*tempbitmap,
11351239      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight - segwidth/2,
11361240      segwidth, LINE_CAP_END, (pattern & (1 << 4)) ? onpen : offpen);
11371241
1138   /* bottom-left bar */
1242   // bottom-left bar
11391243   draw_segment_horizontal_caps(*tempbitmap,
11401244      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight - segwidth/2,
11411245      segwidth, LINE_CAP_START, (pattern & (1 << 5)) ? onpen : offpen);
11421246
1143   /* left-bottom bar */
1247   // left-bottom bar
11441248   draw_segment_vertical(*tempbitmap,
11451249      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2,
11461250      segwidth, (pattern & (1 << 6)) ? onpen : offpen);
11471251
1148   /* left-top bar */
1252   // left-top bar
11491253   draw_segment_vertical(*tempbitmap,
11501254      0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2,
11511255      segwidth, (pattern & (1 << 7)) ? onpen : offpen);
11521256
1153   /* horizontal-middle-left bar */
1257   // horizontal-middle-left bar
11541258   draw_segment_horizontal_caps(*tempbitmap,
11551259      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2,
11561260      segwidth, LINE_CAP_START, (pattern & (1 << 8)) ? onpen : offpen);
11571261
1158   /* horizontal-middle-right bar */
1262   // horizontal-middle-right bar
11591263   draw_segment_horizontal_caps(*tempbitmap,
11601264      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2,
11611265      segwidth, LINE_CAP_END, (pattern & (1 << 9)) ? onpen : offpen);
11621266
1163   /* vertical-middle-top bar */
1267   // vertical-middle-top bar
11641268   draw_segment_vertical_caps(*tempbitmap,
11651269      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2,
11661270      segwidth, LINE_CAP_NONE, (pattern & (1 << 10)) ? onpen : offpen);
11671271
1168   /* vertical-middle-bottom bar */
1272   // vertical-middle-bottom bar
11691273   draw_segment_vertical_caps(*tempbitmap,
11701274      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2,
11711275      segwidth, LINE_CAP_NONE, (pattern & (1 << 11)) ? onpen : offpen);
11721276
1173   /* diagonal-left-bottom bar */
1277   // diagonal-left-bottom bar
11741278   draw_segment_diagonal_1(*tempbitmap,
11751279      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
11761280      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
11771281      segwidth, (pattern & (1 << 12)) ? onpen : offpen);
11781282
1179   /* diagonal-left-top bar */
1283   // diagonal-left-top bar
11801284   draw_segment_diagonal_2(*tempbitmap,
11811285      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
11821286      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
11831287      segwidth, (pattern & (1 << 13)) ? onpen : offpen);
11841288
1185   /* diagonal-right-top bar */
1289   // diagonal-right-top bar
11861290   draw_segment_diagonal_1(*tempbitmap,
11871291      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
11881292      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
11891293      segwidth, (pattern & (1 << 14)) ? onpen : offpen);
11901294
1191   /* diagonal-right-bottom bar */
1295   // diagonal-right-bottom bar
11921296   draw_segment_diagonal_2(*tempbitmap,
11931297      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
11941298      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
11951299      segwidth, (pattern & (1 << 15)) ? onpen : offpen);
11961300
1197   /* apply skew */
1301   // apply skew
11981302   apply_skew(*tempbitmap, 40);
11991303
1200   /* resample to the target size */
1201   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color);
1304   // resample to the target size
1305   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color);
12021306
12031307   global_free(tempbitmap);
12041308}
12051309
12061310
1207/*-------------------------------------------------
1208    layout_element_draw_led16segsc - draw a
1209    16-segment LCD with semicolon (2 extra segments)
1210-------------------------------------------------*/
1311//-------------------------------------------------
1312//  draw_led16segsc - draw a 16-segment LCD with
1313//  semicolon (2 extra segments)
1314//-------------------------------------------------
12111315
1212static void layout_element_draw_led16segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern)
1316void layout_element::component::draw_led16segsc(bitmap_t &dest, const rectangle &bounds, int pattern)
12131317{
12141318   const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff);
12151319   const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20);
1216   int bmwidth, bmheight, segwidth, skewwidth;
1217   bitmap_t *tempbitmap;
12181320
1219   /* sizes for computation */
1220   bmwidth = 250;
1221   bmheight = 400;
1222   segwidth = 40;
1223   skewwidth = 40;
1321   // sizes for computation
1322   int bmwidth = 250;
1323   int bmheight = 400;
1324   int segwidth = 40;
1325   int skewwidth = 40;
12241326
1225   /* allocate a temporary bitmap for drawing */
1226   tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32));
1327   // allocate a temporary bitmap for drawing
1328   bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32));
12271329   bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00));
12281330
1229   /* top-left bar */
1331   // top-left bar
12301332   draw_segment_horizontal_caps(*tempbitmap,
12311333      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, 0 + segwidth/2,
12321334      segwidth, LINE_CAP_START, (pattern & (1 << 0)) ? onpen : offpen);
12331335
1234   /* top-right bar */
1336   // top-right bar
12351337   draw_segment_horizontal_caps(*tempbitmap,
12361338      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, 0 + segwidth/2,
12371339      segwidth, LINE_CAP_END, (pattern & (1 << 1)) ? onpen : offpen);
12381340
1239   /* right-top bar */
1341   // right-top bar
12401342   draw_segment_vertical(*tempbitmap,
12411343      0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2,
12421344      segwidth, (pattern & (1 << 2)) ? onpen : offpen);
12431345
1244   /* right-bottom bar */
1346   // right-bottom bar
12451347   draw_segment_vertical(*tempbitmap,
12461348      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2,
12471349      segwidth, (pattern & (1 << 3)) ? onpen : offpen);
12481350
1249   /* bottom-right bar */
1351   // bottom-right bar
12501352   draw_segment_horizontal_caps(*tempbitmap,
12511353      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight - segwidth/2,
12521354      segwidth, LINE_CAP_END, (pattern & (1 << 4)) ? onpen : offpen);
12531355
1254   /* bottom-left bar */
1356   // bottom-left bar
12551357   draw_segment_horizontal_caps(*tempbitmap,
12561358      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight - segwidth/2,
12571359      segwidth, LINE_CAP_START, (pattern & (1 << 5)) ? onpen : offpen);
12581360
1259   /* left-bottom bar */
1361   // left-bottom bar
12601362   draw_segment_vertical(*tempbitmap,
12611363      bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2,
12621364      segwidth, (pattern & (1 << 6)) ? onpen : offpen);
12631365
1264   /* left-top bar */
1366   // left-top bar
12651367   draw_segment_vertical(*tempbitmap,
12661368      0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2,
12671369      segwidth, (pattern & (1 << 7)) ? onpen : offpen);
12681370
1269   /* horizontal-middle-left bar */
1371   // horizontal-middle-left bar
12701372   draw_segment_horizontal_caps(*tempbitmap,
12711373      0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2,
12721374      segwidth, LINE_CAP_START, (pattern & (1 << 8)) ? onpen : offpen);
12731375
1274   /* horizontal-middle-right bar */
1376   // horizontal-middle-right bar
12751377   draw_segment_horizontal_caps(*tempbitmap,
12761378      0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2,
12771379      segwidth, LINE_CAP_END, (pattern & (1 << 9)) ? onpen : offpen);
12781380
1279   /* vertical-middle-top bar */
1381   // vertical-middle-top bar
12801382   draw_segment_vertical_caps(*tempbitmap,
12811383      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2,
12821384      segwidth, LINE_CAP_NONE, (pattern & (1 << 10)) ? onpen : offpen);
12831385
1284   /* vertical-middle-bottom bar */
1386   // vertical-middle-bottom bar
12851387   draw_segment_vertical_caps(*tempbitmap,
12861388      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2,
12871389      segwidth, LINE_CAP_NONE, (pattern & (1 << 11)) ? onpen : offpen);
12881390
1289   /* diagonal-left-bottom bar */
1391   // diagonal-left-bottom bar
12901392   draw_segment_diagonal_1(*tempbitmap,
12911393      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
12921394      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
12931395      segwidth, (pattern & (1 << 12)) ? onpen : offpen);
12941396
1295   /* diagonal-left-top bar */
1397   // diagonal-left-top bar
12961398   draw_segment_diagonal_2(*tempbitmap,
12971399      0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5,
12981400      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
12991401      segwidth, (pattern & (1 << 13)) ? onpen : offpen);
13001402
1301   /* diagonal-right-top bar */
1403   // diagonal-right-top bar
13021404   draw_segment_diagonal_1(*tempbitmap,
13031405      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
13041406      0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3,
13051407      segwidth, (pattern & (1 << 14)) ? onpen : offpen);
13061408
1307   /* diagonal-right-bottom bar */
1409   // diagonal-right-bottom bar
13081410   draw_segment_diagonal_2(*tempbitmap,
13091411      bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5,
13101412      bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3,
13111413      segwidth, (pattern & (1 << 15)) ? onpen : offpen);
13121414
1313   /* decimal point */
1415   // decimal point
13141416   draw_segment_decimal(*tempbitmap, bmwidth + segwidth/2, bmheight - segwidth/2, segwidth, (pattern & (1 << 16)) ? onpen : offpen);
13151417
1316   /* comma tail */
1418   // comma tail
13171419   draw_segment_diagonal_1(*tempbitmap,
13181420      bmwidth - (segwidth/2), bmwidth + segwidth,
13191421      bmheight - (segwidth), bmheight + segwidth*1.5,
13201422      segwidth/2, (pattern & (1 << 17)) ? onpen : offpen);
13211423
1322   /* apply skew */
1424   // apply skew
13231425   apply_skew(*tempbitmap, 40);
13241426
1325   /* resample to the target size */
1326   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color);
1427   // resample to the target size
1428   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color);
13271429
13281430   global_free(tempbitmap);
13291431}
13301432
1331/*-------------------------------------------------
1332    layout_element_draw_dotmatrix - draw a
1333    row of 8 dots for a dotmatrix
1334-------------------------------------------------*/
13351433
1336static void layout_element_draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern)
1434//-------------------------------------------------
1435//  draw_dotmatrix - draw a row of 8 dots for a
1436//  dotmatrix
1437//-------------------------------------------------
1438
1439void layout_element::component::draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, int pattern)
13371440{
13381441   const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff);
13391442   const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20);
1340   int bmwidth, bmheight, dotwidth, i;
1341   bitmap_t *tempbitmap;
13421443
1343   /* sizes for computation */
1344   bmwidth = 2000;
1345   bmheight = 300;
1346   dotwidth = 250;
1444   // sizes for computation
1445   int bmwidth = 2000;
1446   int bmheight = 300;
1447   int dotwidth = 250;
13471448
1348   /* allocate a temporary bitmap for drawing */
1349   tempbitmap = global_alloc(bitmap_t(bmwidth, bmheight, BITMAP_FORMAT_ARGB32));
1449   // allocate a temporary bitmap for drawing
1450   bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth, bmheight, BITMAP_FORMAT_ARGB32));
13501451   bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00));
13511452
1352   for (i = 0; i < 8; i++)
1353   {//                                                             height
1453   for (int i = 0; i < 8; i++)
13541454      draw_segment_decimal(*tempbitmap, ((dotwidth/2 )+ (i * dotwidth)), bmheight/2, dotwidth, (pattern & (1 << i))?onpen:offpen);
1355   }
13561455
1357   /* resample to the target size */
1358   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color);
1456   // resample to the target size
1457   render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color);
13591458
13601459   global_free(tempbitmap);
13611460}
13621461
13631462
1364/***************************************************************************
1365    LAYOUT FILE PARSING
1366***************************************************************************/
1463//-------------------------------------------------
1464//  draw_segment_horizontal_caps - draw a
1465//  horizontal LED segment with definable end
1466//  and start points
1467//-------------------------------------------------
13671468
1368/*-------------------------------------------------
1369    get_variable_value - compute the value of
1370    a variable in an XML attribute
1371-------------------------------------------------*/
1372
1373static int get_variable_value(running_machine &machine, const char *string, char **outputptr)
1469void layout_element::component::draw_segment_horizontal_caps(bitmap_t &dest, int minx, int maxx, int midy, int width, int caps, rgb_t color)
13741470{
1375   const screen_device_config *devconfig;
1376   int num, den;
1377   char temp[100];
1378
1379   /* screen 0 parameters */
1380   for (devconfig = screen_first(machine.m_config); devconfig != NULL; devconfig = screen_next(devconfig))
1471   // loop over the width of the segment
1472   for (int y = 0; y < width / 2; y++)
13811473   {
1382      int scrnum = machine.m_config.m_devicelist.index(SCREEN, devconfig->tag());
1474      UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0);
1475      UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0);
1476      int ty = (y < width / 8) ? width / 8 : y;
13831477
1384      /* native X aspect factor */
1385      sprintf(temp, "~scr%dnativexaspect~", scrnum);
1386      if (!strncmp(string, temp, strlen(temp)))
1387      {
1388         num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x;
1389         den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y;
1390         reduce_fraction(&num, &den);
1391         *outputptr += sprintf(*outputptr, "%d", num);
1392         return strlen(temp);
1393      }
1394
1395      /* native Y aspect factor */
1396      sprintf(temp, "~scr%dnativeyaspect~", scrnum);
1397      if (!strncmp(string, temp, strlen(temp)))
1398      {
1399         num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x;
1400         den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y;
1401         reduce_fraction(&num, &den);
1402         *outputptr += sprintf(*outputptr, "%d", den);
1403         return strlen(temp);
1404      }
1405
1406      /* native width */
1407      sprintf(temp, "~scr%dwidth~", scrnum);
1408      if (!strncmp(string, temp, strlen(temp)))
1409      {
1410         *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x);
1411         return strlen(temp);
1412      }
1413
1414      /* native height */
1415      sprintf(temp, "~scr%dheight~", scrnum);
1416      if (!strncmp(string, temp, strlen(temp)))
1417      {
1418         *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y);
1419         return strlen(temp);
1420      }
1478      // loop over the length of the segment
1479      for (int x = minx + ((caps & LINE_CAP_START) ? ty : 0); x < maxx - ((caps & LINE_CAP_END) ? ty : 0); x++)
1480         d0[x] = d1[x] = color;
14211481   }
1422
1423   /* default: copy the first character and continue */
1424   **outputptr = *string;
1425   *outputptr += 1;
1426   return 1;
14271482}
14281483
14291484
1430/*-------------------------------------------------
1431    xml_get_attribute_string_with_subst - analog
1432    to xml_get_attribute_string but with variable
1433    substitution
1434-------------------------------------------------*/
1485//-------------------------------------------------
1486//  draw_segment_horizontal - draw a horizontal
1487//  LED segment
1488//-------------------------------------------------
14351489
1436static const char *xml_get_attribute_string_with_subst(running_machine &machine, xml_data_node *node, const char *attribute, const char *defvalue)
1490void layout_element::component::draw_segment_horizontal(bitmap_t &dest, int minx, int maxx, int midy, int width, rgb_t color)
14371491{
1438   const char *str = xml_get_attribute_string(node, attribute, NULL);
1439   static char buffer[1000];
1440   const char *s;
1441   char *d;
1492   draw_segment_horizontal_caps(dest, minx, maxx, midy, width, LINE_CAP_START | LINE_CAP_END, color);
1493}
14421494
1443   /* if nothing, just return the default */
1444   if (str == NULL)
1445      return defvalue;
14461495
1447   /* if no tildes, don't worry */
1448   if (strchr(str, '~') == NULL)
1449      return str;
1496//-------------------------------------------------
1497//  draw_segment_vertical_caps - draw a
1498//  vertical LED segment with definable end
1499//  and start points
1500//-------------------------------------------------
14501501
1451   /* make a copy of the string, doing substitutions along the way */
1452   for (s = str, d = buffer; *s != 0; )
1502void layout_element::component::draw_segment_vertical_caps(bitmap_t &dest, int miny, int maxy, int midx, int width, int caps, rgb_t color)
1503{
1504   // loop over the width of the segment
1505   for (int x = 0; x < width / 2; x++)
14531506   {
1454      /* if not a variable, just copy */
1455      if (*s != '~')
1456         *d++ = *s++;
1507      UINT32 *d0 = BITMAP_ADDR32(&dest, 0, midx - x);
1508      UINT32 *d1 = BITMAP_ADDR32(&dest, 0, midx + x);
1509      int tx = (x < width / 8) ? width / 8 : x;
14571510
1458      /* extract the variable */
1459      else
1460         s += get_variable_value(machine, s, &d);
1511      // loop over the length of the segment
1512      for (int y = miny + ((caps & LINE_CAP_START) ? tx : 0); y < maxy - ((caps & LINE_CAP_END) ? tx : 0); y++)
1513         d0[y * dest.rowpixels] = d1[y * dest.rowpixels] = color;
14611514   }
1462   *d = 0;
1463   return buffer;
14641515}
14651516
14661517
1467/*-------------------------------------------------
1468    xml_get_attribute_int_with_subst - analog
1469    to xml_get_attribute_int but with variable
1470    substitution
1471-------------------------------------------------*/
1518//-------------------------------------------------
1519//  draw_segment_vertical - draw a vertical
1520//  LED segment
1521//-------------------------------------------------
14721522
1473static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_node *node, const char *attribute, int defvalue)
1523void layout_element::component::draw_segment_vertical(bitmap_t &dest, int miny, int maxy, int midx, int width, rgb_t color)
14741524{
1475   const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL);
1476   int value;
1477
1478   if (string == NULL)
1479      return defvalue;
1480   if (string[0] == '$')
1481      return (sscanf(&string[1], "%X", &value) == 1) ? value : defvalue;
1482   if (string[0] == '0' && string[1] == 'x')
1483      return (sscanf(&string[2], "%X", &value) == 1) ? value : defvalue;
1484   if (string[0] == '#')
1485      return (sscanf(&string[1], "%d", &value) == 1) ? value : defvalue;
1486   return (sscanf(&string[0], "%d", &value) == 1) ? value : defvalue;
1525   draw_segment_vertical_caps(dest, miny, maxy, midx, width, LINE_CAP_START | LINE_CAP_END, color);
14871526}
14881527
14891528
1490/*-------------------------------------------------
1491    xml_get_attribute_float_with_subst - analog
1492    to xml_get_attribute_float but with variable
1493    substitution
1494-------------------------------------------------*/
1529//-------------------------------------------------
1530//  draw_segment_diagonal_1 - draw a diagonal
1531//  LED segment that looks like this: /
1532//-------------------------------------------------
14951533
1496static float xml_get_attribute_float_with_subst(running_machine &machine, xml_data_node *node, const char *attribute, float defvalue)
1534void layout_element::component::draw_segment_diagonal_1(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color)
14971535{
1498   const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL);
1499   float value;
1536   // compute parameters
1537   width *= 1.5;
1538   float ratio = (maxy - miny - width) / (float)(maxx - minx);
15001539
1501   if (!string || sscanf(string, "%f", &value) != 1)
1502      return defvalue;
1503   return value;
1540   // draw line
1541   for (int x = minx; x < maxx; x++)
1542      if (x >= 0 && x < dest.width)
1543      {
1544         UINT32 *d = BITMAP_ADDR32(&dest, 0, x);
1545         int step = (x - minx) * ratio;
1546
1547         for (int y = maxy - width - step; y < maxy - step; y++)
1548            if (y >= 0 && y < dest.height)
1549               d[y * dest.rowpixels] = color;
1550      }
15041551}
15051552
15061553
1507/*-------------------------------------------------
1508    layout_file_load - parse a layout XML file
1509    into a layout_file
1510-------------------------------------------------*/
1554//-------------------------------------------------
1555//  draw_segment_diagonal_2 - draw a diagonal
1556//  LED segment that looks like this:
1557//-------------------------------------------------
15111558
1512layout_file *layout_file_load(running_machine &machine, const char *dirname, const char *filename)
1559void layout_element::component::draw_segment_diagonal_2(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color)
15131560{
1514   xml_data_node *rootnode, *mamelayoutnode, *elemnode, *viewnode;
1515   layout_element **elemnext;
1516   layout_view **viewnext;
1517   layout_file *file;
1518   int version;
1561   // compute parameters
1562   width *= 1.5;
1563   float ratio = (maxy - miny - width) / (float)(maxx - minx);
15191564
1520   /* if the first character of the "file" is an open brace, assume it is an XML string */
1521   if (filename[0] == '<')
1522      rootnode = xml_string_read(filename, NULL);
1565   // draw line
1566   for (int x = minx; x < maxx; x++)
1567      if (x >= 0 && x < dest.width)
1568      {
1569         UINT32 *d = BITMAP_ADDR32(&dest, 0, x);
1570         int step = (x - minx) * ratio;
15231571
1524   /* otherwise, assume it is a file */
1525   else
1526   {
1527      file_error filerr;
1528      mame_file *layoutfile;
1572         for (int y = miny + step; y < miny + step + width; y++)
1573            if (y >= 0 && y < dest.height)
1574               d[y * dest.rowpixels] = color;
1575      }
1576}
15291577
1530      astring fname(filename, ".lay");
1531      if (dirname != NULL)
1532         fname.ins(0, PATH_SEPARATOR).ins(0, dirname);
15331578
1534      filerr = mame_fopen(SEARCHPATH_ARTWORK, fname, OPEN_FLAG_READ, &layoutfile);
1579//-------------------------------------------------
1580//  draw_segment_decimal - draw a decimal point
1581//-------------------------------------------------
15351582
1536      if (filerr != FILERR_NONE)
1537         return NULL;
1538      rootnode = xml_file_read(mame_core_file(layoutfile), NULL);
1539      mame_fclose(layoutfile);
1540   }
1583void layout_element::component::draw_segment_decimal(bitmap_t &dest, int midx, int midy, int width, rgb_t color)
1584{
1585   // compute parameters
1586   width /= 2;
1587   float ooradius2 = 1.0f / (float)(width * width);
15411588
1542   /* if unable to parse the file, just bail */
1543   if (rootnode == NULL)
1544      return NULL;
1545
1546   /* allocate the layout group object first */
1547   file = global_alloc_clear(layout_file);
1548
1549   /* find the layout node */
1550   mamelayoutnode = xml_get_sibling(rootnode->child, "mamelayout");
1551   if (mamelayoutnode == NULL)
1552      fatalerror("Invalid XML file: missing mamelayout node");
1553
1554   /* validate the config data version */
1555   version = xml_get_attribute_int(mamelayoutnode, "version", 0);
1556   if (version != LAYOUT_VERSION)
1557      fatalerror("Invalid XML file: unsupported version");
1558
1559   /* parse all the elements */
1560   file->elemlist = NULL;
1561   elemnext = &file->elemlist;
1562   for (elemnode = xml_get_sibling(mamelayoutnode->child, "element"); elemnode; elemnode = xml_get_sibling(elemnode->next, "element"))
1589   // iterate over y
1590   for (UINT32 y = 0; y <= width; y++)
15631591   {
1564      layout_element *element = load_layout_element(machine, elemnode, dirname);
1565      if (element == NULL)
1566         goto error;
1592      UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0);
1593      UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0);
1594      float xval = width * sqrt(1.0f - (float)(y * y) * ooradius2);
1595      INT32 left, right;
15671596
1568      /* add to the end of the list */
1569      *elemnext = element;
1570      elemnext = &element->next;
1571   }
1597      // compute left/right coordinates
1598      left = midx - (INT32)(xval + 0.5f);
1599      right = midx + (INT32)(xval + 0.5f);
15721600
1573   /* parse all the views */
1574   file->viewlist = NULL;
1575   viewnext = &file->viewlist;
1576   for (viewnode = xml_get_sibling(mamelayoutnode->child, "view"); viewnode; viewnode = xml_get_sibling(viewnode->next, "view"))
1577   {
1578      layout_view *view = load_layout_view(machine, viewnode, file->elemlist);
1579      if (view == NULL)
1580         goto error;
1581
1582      /* add to the end of the list */
1583      *viewnext = view;
1584      viewnext = &view->next;
1601      // draw this scanline
1602      for (UINT32 x = left; x < right; x++)
1603         d0[x] = d1[x] = color;
15851604   }
1586
1587   xml_file_free(rootnode);
1588   return file;
1589
1590error:
1591   layout_file_free(file);
1592   xml_file_free(rootnode);
1593   return NULL;
15941605}
15951606
15961607
1597/*-------------------------------------------------
1598    load_layout_element - parse an element XML
1599    node from the layout file
1600-------------------------------------------------*/
1608//-------------------------------------------------
1609//  draw_segment_comma - draw a comma tail
1610//-------------------------------------------------
16011611
1602static layout_element *load_layout_element(running_machine &machine, xml_data_node *elemnode, const char *dirname)
1612void layout_element::component::draw_segment_comma(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color)
16031613{
1604   render_bounds bounds = { 0 };
1605   element_component **nextcomp;
1606   element_component *component;
1607   xml_data_node *compnode;
1608   layout_element *element;
1609   float xscale, yscale;
1610   float xoffs, yoffs;
1611   const char *name;
1612   int state;
1613   int first;
1614   // compute parameters
1615   width *= 1.5;
1616   float ratio = (maxy - miny - width) / (float)(maxx - minx);
16141617
1615   /* allocate a new element */
1616   element = global_alloc_clear(layout_element);
1617
1618   /* extract the name */
1619   name = xml_get_attribute_string_with_subst(machine, elemnode, "name", NULL);
1620   if (name == NULL)
1618   // draw line
1619   for (int x = minx; x < maxx; x++)
16211620   {
1622      logerror("All layout elements must have a name!\n");
1623      goto error;
1624   }
1625   element->machine = &machine;
1626   element->name = copy_string(name);
1627   element->defstate = xml_get_attribute_int_with_subst(machine, elemnode, "defstate", -1);
1621      UINT32 *d = BITMAP_ADDR32(&dest, 0, x);
1622      int step = (x - minx) * ratio;
16281623
1629   /* parse components in order */
1630   first = TRUE;
1631   nextcomp = &element->complist;
1632   for (compnode = elemnode->child; compnode; compnode = compnode->next)
1633   {
1634      /* allocate a new component */
1635      element_component *new_component = load_element_component(machine, compnode, dirname);
1636      if (new_component == NULL)
1637         goto error;
1638
1639      /* link it into the list */
1640      *nextcomp = new_component;
1641      nextcomp = &new_component->next;
1642
1643      /* accumulate bounds */
1644      if (first)
1645         bounds = new_component->bounds;
1646      else
1647         union_render_bounds(&bounds, &new_component->bounds);
1648      first = FALSE;
1649
1650      /* determine the maximum state */
1651      if (new_component->state > element->maxstate)
1652         element->maxstate = new_component->state;
1653      if (new_component->type == COMPONENT_TYPE_LED7SEG)
1654         element->maxstate = 255;
1655      if (new_component->type == COMPONENT_TYPE_LED14SEG)
1656         element->maxstate = 16383;
1657      if (new_component->type == COMPONENT_TYPE_LED14SEGSC || new_component->type == COMPONENT_TYPE_LED16SEG)
1658         element->maxstate = 65535;
1659      if (new_component->type == COMPONENT_TYPE_LED16SEGSC)
1660         element->maxstate = 262143;
1661      if (new_component->type == COMPONENT_TYPE_DOTMATRIX)
1662         element->maxstate = 255;
1624      for (int y = maxy; y < maxy  - width - step; y--)
1625         d[y * dest.rowpixels] = color;
16631626   }
1664   /* determine the scale/offset for normalization */
1665   xoffs = bounds.x0;
1666   yoffs = bounds.y0;
1667   xscale = 1.0f / (bounds.x1 - bounds.x0);
1668   yscale = 1.0f / (bounds.y1 - bounds.y0);
1669
1670   /* normalize all the component bounds */
1671   for (component = element->complist; component != NULL; component = component->next)
1672   {
1673      component->bounds.x0 = (component->bounds.x0 - xoffs) * xscale;
1674      component->bounds.x1 = (component->bounds.x1 - xoffs) * xscale;
1675      component->bounds.y0 = (component->bounds.y0 - yoffs) * yscale;
1676      component->bounds.y1 = (component->bounds.y1 - yoffs) * yscale;
1677   }
1678
1679   /* allocate an array of element textures for the states */
1680   element->elemtex = global_alloc_array(element_texture, element->maxstate + 1);
1681   for (state = 0; state <= element->maxstate; state++)
1682   {
1683      element->elemtex[state].element = element;
1684      element->elemtex[state].state = state;
1685      element->elemtex[state].texture = machine.render().texture_alloc(layout_element_scale, &element->elemtex[state]);
1686   }
1687
1688   return element;
1689
1690error:
1691   layout_element_free(element);
1692   return NULL;
16931627}
16941628
16951629
1696/*-------------------------------------------------
1697    load_element_component - parse a component
1698    XML node (image/rect/disk)
1699-------------------------------------------------*/
1630//-------------------------------------------------
1631//  apply_skew - apply skew to a bitmap_t
1632//-------------------------------------------------
17001633
1701static element_component *load_element_component(running_machine &machine, xml_data_node *compnode, const char *dirname)
1634void layout_element::component::apply_skew(bitmap_t &dest, int skewwidth)
17021635{
1703   element_component *component;
1704
1705   /* allocate memory for the component */
1706   component = global_alloc_clear(element_component);
1707
1708   /* fetch common data */
1709   component->state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1);
1710   if (load_bounds(machine, xml_get_sibling(compnode->child, "bounds"), &component->bounds))
1711      goto error;
1712   if (load_color(machine, xml_get_sibling(compnode->child, "color"), &component->color))
1713      goto error;
1714
1715   /* image nodes */
1716   if (strcmp(compnode->name, "image") == 0)
1636   for (int y = 0; y < dest.height; y++)
17171637   {
1718      const char *file = xml_get_attribute_string_with_subst(machine, compnode, "file", NULL);
1719      const char *afile = xml_get_attribute_string_with_subst(machine, compnode, "alphafile", NULL);
1720
1721      /* load and allocate the bitmap */
1722      component->type = COMPONENT_TYPE_IMAGE;
1723      component->dirname = (dirname == NULL) ? NULL : copy_string(dirname);
1724      component->imagefile = (file == NULL) ? NULL : copy_string(file);
1725      component->alphafile = (afile == NULL) ? NULL : copy_string(afile);
1638      UINT32 *destrow = BITMAP_ADDR32(&dest, y, 0);
1639      int offs = skewwidth * (dest.height - y) / dest.height;
1640      for (int x = dest.width - skewwidth - 1; x >= 0; x--)
1641         destrow[x + offs] = destrow[x];
1642      for (int x = 0; x < offs; x++)
1643         destrow[x] = 0;
17261644   }
1645}
17271646
1728   /* text nodes */
1729   else if (strcmp(compnode->name, "text") == 0)
1730   {
1731      const char *text = xml_get_attribute_string_with_subst(machine, compnode, "string", "");
1732      char *string;
17331647
1734      /* allocate a copy of the string */
1735      component->type = COMPONENT_TYPE_TEXT;
1736      string = global_alloc_array(char, strlen(text) + 1);
1737      strcpy(string, text);
1738      component->string = string;
1739   }
17401648
1741   /* dotmatrix nodes */
1742   else if (strcmp(compnode->name, "dotmatrix") == 0)
1743      component->type = COMPONENT_TYPE_DOTMATRIX;
1649//**************************************************************************
1650//  LAYOUT VIEW
1651//**************************************************************************
17441652
1745   /* led7seg nodes */
1746   else if (strcmp(compnode->name, "led7seg") == 0)
1747      component->type = COMPONENT_TYPE_LED7SEG;
1653//-------------------------------------------------
1654//  layout_view - constructor
1655//-------------------------------------------------
17481656
1749   /* led14seg nodes */
1750   else if (strcmp(compnode->name, "led14seg") == 0)
1751      component->type = COMPONENT_TYPE_LED14SEG;
1657layout_view::layout_view(running_machine &machine, xml_data_node &viewnode, simple_list<layout_element> &elemlist)
1658   : m_next(NULL),
1659     m_aspect(1.0f),
1660     m_scraspect(1.0f),
1661     m_screens(machine.m_respool),
1662     m_backdrop_list(machine.m_respool),
1663     m_screen_list(machine.m_respool),
1664     m_overlay_list(machine.m_respool),
1665     m_bezel_list(machine.m_respool)
1666{
1667   // allocate a copy of the name
1668   m_name = xml_get_attribute_string_with_subst(machine, viewnode, "name", "");
17521669
1753   /* led14segsc nodes */
1754   else if (strcmp(compnode->name, "led14segsc") == 0)
1755      component->type = COMPONENT_TYPE_LED14SEGSC;
1670   // if we have a bounds item, load it
1671   xml_data_node *boundsnode = xml_get_sibling(viewnode.child, "bounds");
1672   m_expbounds.x0 = m_expbounds.y0 = m_expbounds.x1 = m_expbounds.y1 = 0;
1673   if (boundsnode != NULL)
1674      parse_bounds(machine, xml_get_sibling(boundsnode, "bounds"), m_expbounds);
17561675
1757   /* led16seg nodes */
1758   else if (strcmp(compnode->name, "led16seg") == 0)
1759      component->type = COMPONENT_TYPE_LED16SEG;
1676   // load backdrop items
1677   for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "backdrop"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "backdrop"))
1678      m_backdrop_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist)));
17601679
1761   /* led16segsc nodes */
1762   else if (strcmp(compnode->name, "led16segsc") == 0)
1763      component->type = COMPONENT_TYPE_LED16SEGSC;
1680   // load screen items
1681   for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "screen"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "screen"))
1682      m_screen_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist)));
17641683
1765   /* rect nodes */
1766   else if (strcmp(compnode->name, "rect") == 0)
1767      component->type = COMPONENT_TYPE_RECT;
1684   // load overlay items
1685   for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "overlay"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "overlay"))
1686      m_overlay_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist)));
17681687
1769   /* disk nodes */
1770   else if (strcmp(compnode->name, "disk") == 0)
1771      component->type = COMPONENT_TYPE_DISK;
1688   // load bezel items
1689   for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "bezel"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "bezel"))
1690      m_bezel_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist)));
17721691
1773   /* error otherwise */
1774   else
1775      fatalerror("Unknown element component: %s", compnode->name);
1776
1777   return component;
1778
1779error:
1780   global_free(component);
1781   return NULL;
1692   // recompute the data for the view based on a default layer config
1693   recompute(render_layer_config());
17821694}
17831695
17841696
1785/*-------------------------------------------------
1786    load_layout_view - parse a view XML node
1787-------------------------------------------------*/
1697//-------------------------------------------------
1698//  layout_view - destructor
1699//-------------------------------------------------
17881700
1789static layout_view *load_layout_view(running_machine &machine, xml_data_node *viewnode, layout_element *elemlist)
1701layout_view::~layout_view()
17901702{
1791   xml_data_node *boundsnode;
1792   view_item **itemnext;
1793   layout_view *view;
1794   int layer;
1703}
17951704
1796   /* first allocate memory */
1797   view = global_alloc_clear(layout_view);
17981705
1799   /* allocate a copy of the name */
1800   view->name = copy_string(xml_get_attribute_string_with_subst(machine, viewnode, "name", ""));
1706//-------------------------------------------------
1707//  first_item - return the first item in the
1708//  appropriate list
1709//-------------------------------------------------
18011710
1802   /* if we have a bounds item, load it */
1803   boundsnode = xml_get_sibling(viewnode->child, "bounds");
1804   if (boundsnode != NULL && load_bounds(machine, xml_get_sibling(boundsnode, "bounds"), &view->expbounds))
1805      goto error;
1806
1807   /* loop over all the layer types we support */
1808   for (layer = 0; layer < ITEM_LAYER_MAX; layer++)
1711layout_view::item *layout_view::first_item(item_layer layer) const
1712{
1713   switch (layer)
18091714   {
1810      static const char *const layer_node_name[ITEM_LAYER_MAX] = { "backdrop", "screen", "overlay", "bezel" };
1811      xml_data_node *itemnode;
1812
1813      /* initialize the list */
1814      view->itemlist[layer] = NULL;
1815      itemnext = &view->itemlist[layer];
1816
1817      /* parse all of the elements of that type */
1818      for (itemnode = xml_get_sibling(viewnode->child, layer_node_name[layer]); itemnode; itemnode = xml_get_sibling(itemnode->next, layer_node_name[layer]))
1819      {
1820         view_item *item = load_view_item(machine, itemnode, elemlist);
1821         if (!item)
1822            goto error;
1823
1824         /* add to the end of the list */
1825         *itemnext = item;
1826         itemnext = &item->next;
1827      }
1715      case ITEM_LAYER_BACKDROP:   return m_backdrop_list.first();
1716      case ITEM_LAYER_SCREEN:      return m_screen_list.first();
1717      case ITEM_LAYER_OVERLAY:   return m_overlay_list.first();
1718      case ITEM_LAYER_BEZEL:      return m_bezel_list.first();
1719      default:               return NULL;
18281720   }
1829
1830   /* recompute the data for the view */
1831   layout_view_recompute(view, ~0);
1832   return view;
1833
1834error:
1835   layout_view_free(view);
1836   return NULL;
18371721}
18381722
18391723
1840/*-------------------------------------------------
1841    load_view_item - parse an item XML node
1842-------------------------------------------------*/
1724//-------------------------------------------------
1725//  recompute - recompute the bounds and aspect
1726//  ratio of a view and all of its contained items
1727//-------------------------------------------------
18431728
1844static view_item *load_view_item(running_machine &machine, xml_data_node *itemnode, layout_element *elemlist)
1729void layout_view::recompute(render_layer_config layerconfig)
18451730{
1846   view_item *item;
1847   const char *name;
1731   // reset the bounds
1732   m_bounds.x0 = m_bounds.y0 = m_bounds.x1 = m_bounds.y1 = 0.0f;
1733   m_scrbounds.x0 = m_scrbounds.y0 = m_scrbounds.x1 = m_scrbounds.y1 = 0.0f;
1734   m_screens.reset();
18481735
1849   /* allocate a new item */
1850   item = global_alloc_clear(view_item);
1851
1852   /* allocate a copy of the output name */
1853   item->output_name = copy_string(xml_get_attribute_string_with_subst(machine, itemnode, "name", ""));
1854
1855   /* allocate a copy of the input tag */
1856   item->input_tag = copy_string(xml_get_attribute_string_with_subst(machine, itemnode, "inputtag", ""));
1857
1858   /* find the associated element */
1859   name = xml_get_attribute_string_with_subst(machine, itemnode, "element", NULL);
1860   if (name != NULL)
1736   // loop over all layers
1737   bool first = true;
1738   bool scrfirst = true;
1739   for (item_layer layer = ITEM_LAYER_FIRST; layer < ITEM_LAYER_MAX; layer++)
18611740   {
1862      layout_element *element;
1741      // determine if this layer should be visible
1742      switch (layer)
1743      {
1744         case ITEM_LAYER_BACKDROP:   m_layenabled[layer] = layerconfig.backdrops_enabled();   break;
1745         case ITEM_LAYER_OVERLAY:   m_layenabled[layer] = layerconfig.overlays_enabled();   break;
1746         case ITEM_LAYER_BEZEL:      m_layenabled[layer] = layerconfig.bezels_enabled();      break;
1747         default:               m_layenabled[layer] = true;                        break;
1748      }
18631749
1864      /* search the list of elements for a match */
1865      for (element = elemlist; element; element = element->next)
1866         if (strcmp(name, element->name) == 0)
1867            break;
1750      // only do it if requested
1751      if (m_layenabled[layer])
1752         for (item *curitem = first_item(layer); curitem != NULL; curitem = curitem->next())
1753         {
1754            // accumulate bounds
1755            if (first)
1756               m_bounds = curitem->m_rawbounds;
1757            else
1758               union_render_bounds(&m_bounds, &curitem->m_rawbounds);
1759            first = false;
18681760
1869      /* error if not found */
1870      if (element == NULL)
1871         fatalerror("Unable to find layout element %s", name);
1872      item->element = element;
1761            // accumulate screen bounds
1762            if (curitem->m_screen != NULL)
1763            {
1764               if (scrfirst)
1765                  m_scrbounds = curitem->m_rawbounds;
1766               else
1767                  union_render_bounds(&m_scrbounds, &curitem->m_rawbounds);
1768               scrfirst = false;
1769
1770               // accumulate the screens in use while we're scanning
1771               m_screens.add(*curitem->m_screen);
1772            }
1773         }
18731774   }
18741775
1875   /* fetch common data */
1876   item->index = xml_get_attribute_int_with_subst(machine, itemnode, "index", -1);
1877   item->input_mask = xml_get_attribute_int_with_subst(machine, itemnode, "inputmask", 0);
1878   if (item->output_name[0] != 0 && item->element != 0)
1879      output_set_value(item->output_name, item->element->defstate);
1880   if (load_bounds(machine, xml_get_sibling(itemnode->child, "bounds"), &item->rawbounds))
1881      goto error;
1882   if (load_color(machine, xml_get_sibling(itemnode->child, "color"), &item->color))
1883      goto error;
1884   if (load_orientation(machine, xml_get_sibling(itemnode->child, "orientation"), &item->orientation))
1885      goto error;
1776   // if we have an explicit bounds, override it
1777   if (m_expbounds.x1 > m_expbounds.x0)
1778      m_bounds = m_expbounds;
18861779
1887   /* sanity checks */
1888   if (strcmp(itemnode->name, "screen") == 0)
1780   // compute the aspect ratio of the view
1781   m_aspect = (m_bounds.x1 - m_bounds.x0) / (m_bounds.y1 - m_bounds.y0);
1782   m_scraspect = (m_scrbounds.x1 - m_scrbounds.x0) / (m_scrbounds.y1 - m_scrbounds.y0);
1783
1784   // if we're handling things normally, the target bounds are (0,0)-(1,1)
1785   render_bounds target_bounds;
1786   if (!layerconfig.zoom_to_screen() || m_screens.count() == 0)
18891787   {
1890      if (item->index < 0)
1891         fatalerror("Layout references invalid screen index %d", item->index);
1788      target_bounds.x0 = target_bounds.y0 = 0.0f;
1789      target_bounds.x1 = target_bounds.y1 = 1.0f;
18921790   }
1791
1792   // if we're cropping, we want the screen area to fill (0,0)-(1,1)
18931793   else
18941794   {
1895      if (item->element == NULL)
1896         fatalerror("Layout item of type %s require an element tag", itemnode->name);
1795      float targwidth = (m_bounds.x1 - m_bounds.x0) / (m_scrbounds.x1 - m_scrbounds.x0);
1796      float targheight = (m_bounds.y1 - m_bounds.y0) / (m_scrbounds.y1 - m_scrbounds.y0);
1797      target_bounds.x0 = (m_bounds.x0 - m_scrbounds.x0) / (m_bounds.x1 - m_bounds.x0) * targwidth;
1798      target_bounds.y0 = (m_bounds.y0 - m_scrbounds.y0) / (m_bounds.y1 - m_bounds.y0) * targheight;
1799      target_bounds.x1 = target_bounds.x0 + targwidth;
1800      target_bounds.y1 = target_bounds.y0 + targheight;
18971801   }
18981802
1899   return item;
1803   // determine the scale/offset for normalization
1804   float xoffs = m_bounds.x0;
1805   float yoffs = m_bounds.y0;
1806   float xscale = (target_bounds.x1 - target_bounds.x0) / (m_bounds.x1 - m_bounds.x0);
1807   float yscale = (target_bounds.y1 - target_bounds.y0) / (m_bounds.y1 - m_bounds.y0);
19001808
1901error:
1902   if (item->output_name != NULL)
1903      global_free(item->output_name);
1904   if (item->input_tag != NULL)
1905      global_free(item->input_tag);
1906   global_free(item);
1907   return NULL;
1809   // normalize all the item bounds
1810   for (item_layer layer = ITEM_LAYER_FIRST; layer < ITEM_LAYER_MAX; layer++)
1811      for (item *curitem = first_item(layer); curitem != NULL; curitem = curitem->next())
1812      {
1813         curitem->m_bounds.x0 = target_bounds.x0 + (curitem->m_rawbounds.x0 - xoffs) * xscale;
1814         curitem->m_bounds.x1 = target_bounds.x0 + (curitem->m_rawbounds.x1 - xoffs) * xscale;
1815         curitem->m_bounds.y0 = target_bounds.y0 + (curitem->m_rawbounds.y0 - yoffs) * yscale;
1816         curitem->m_bounds.y1 = target_bounds.y0 + (curitem->m_rawbounds.y1 - yoffs) * yscale;
1817      }
19081818}
19091819
19101820
1911/*-------------------------------------------------
1912    load_component_bitmap - load a PNG file
1913    with artwork for a component
1914-------------------------------------------------*/
19151821
1916static bitmap_t *load_component_bitmap(const char *dirname, const char *file, const char *alphafile, int *hasalpha)
1917{
1918   bitmap_t *bitmap;
1822//**************************************************************************
1823//  LAYOUT VIEW ITEM
1824//**************************************************************************
19191825
1920   /* load the basic bitmap */
1921   bitmap = render_load_png(OPTION_ARTPATH, dirname, file, NULL, hasalpha);
1922   if (bitmap != NULL && alphafile != NULL)
1826//-------------------------------------------------
1827//  item - constructor
1828//-------------------------------------------------
19231829
1924      /* load the alpha bitmap if specified */
1925      if (render_load_png(OPTION_ARTPATH, dirname, alphafile, bitmap, hasalpha) == NULL)
1926      {
1927         global_free(bitmap);
1928         bitmap = NULL;
1929      }
1830layout_view::item::item(running_machine &machine, xml_data_node &itemnode, simple_list<layout_element> &elemlist)
1831   : m_next(NULL),
1832     m_element(NULL),
1833     m_input_mask(0),
1834     m_screen(NULL),
1835     m_orientation(ROT0)
1836{
1837   // allocate a copy of the output name
1838   m_output_name = xml_get_attribute_string_with_subst(machine, itemnode, "name", "");
19301839
1931   /* if we can't load the bitmap, allocate a dummy one and report an error */
1932   if (bitmap == NULL)
1840   // allocate a copy of the input tag
1841   m_input_tag = xml_get_attribute_string_with_subst(machine, itemnode, "inputtag", "");
1842
1843   // find the associated element
1844   const char *name = xml_get_attribute_string_with_subst(machine, itemnode, "element", NULL);
1845   if (name != NULL)
19331846   {
1934      int step, line;
1847      // search the list of elements for a match
1848      for (m_element = elemlist.first(); m_element != NULL; m_element = m_element->next())
1849         if (strcmp(name, m_element->name()) == 0)
1850            break;
19351851
1936      /* draw some stripes in the bitmap */
1937      bitmap = global_alloc(bitmap_t(100, 100, BITMAP_FORMAT_ARGB32));
1938      bitmap_fill(bitmap, NULL, 0);
1939      for (step = 0; step < 100; step += 25)
1940         for (line = 0; line < 100; line++)
1941            *BITMAP_ADDR32(bitmap, (step + line) % 100, line % 100) = MAKE_ARGB(0xff,0xff,0xff,0xff);
1942
1943      /* log an error */
1944      if (alphafile == NULL)
1945         logerror("Unable to load component bitmap '%s'", file);
1946      else
1947         logerror("Unable to load component bitmap '%s'/'%s'", file, alphafile);
1852      // error if not found
1853      if (m_element == NULL)
1854         throw emu_fatalerror("Unable to find layout element %s", name);
19481855   }
19491856
1950   return bitmap;
1951}
1857   // fetch common data
1858   int index = xml_get_attribute_int_with_subst(machine, itemnode, "index", -1);
1859   if (index != -1)
1860      m_screen = downcast<screen_device *>(machine.m_devicelist.find(SCREEN, index));
1861   m_input_mask = xml_get_attribute_int_with_subst(machine, itemnode, "inputmask", 0);
1862   if (m_output_name[0] != 0 && m_element != NULL)
1863      output_set_value(m_output_name, m_element->default_state());
1864   parse_bounds(machine, xml_get_sibling(itemnode.child, "bounds"), m_rawbounds);
1865   parse_color(machine, xml_get_sibling(itemnode.child, "color"), m_color);
1866   parse_orientation(machine, xml_get_sibling(itemnode.child, "orientation"), m_orientation);
19521867
1953
1954/*-------------------------------------------------
1955    load_bounds - parse a bounds XML node
1956-------------------------------------------------*/
1957
1958static int load_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds *bounds)
1959{
1960   /* skip if nothing */
1961   if (boundsnode == NULL)
1868   // sanity checks
1869   if (strcmp(itemnode.name, "screen") == 0)
19621870   {
1963      bounds->x0 = bounds->y0 = 0.0f;
1964      bounds->x1 = bounds->y1 = 1.0f;
1965      return 0;
1871      if (m_screen == NULL)
1872         throw emu_fatalerror("Layout references invalid screen index %d", index);
19661873   }
1967
1968   /* parse out the data */
1969   if (xml_get_attribute(boundsnode, "left") != NULL)
1970   {
1971      /* left/right/top/bottom format */
1972      bounds->x0 = xml_get_attribute_float_with_subst(machine, boundsnode, "left", 0.0f);
1973      bounds->x1 = xml_get_attribute_float_with_subst(machine, boundsnode, "right", 1.0f);
1974      bounds->y0 = xml_get_attribute_float_with_subst(machine, boundsnode, "top", 0.0f);
1975      bounds->y1 = xml_get_attribute_float_with_subst(machine, boundsnode, "bottom", 1.0f);
1976   }
1977   else if (xml_get_attribute(boundsnode, "x") != NULL)
1978   {
1979      /* x/y/width/height format */
1980      bounds->x0 = xml_get_attribute_float_with_subst(machine, boundsnode, "x", 0.0f);
1981      bounds->x1 = bounds->x0 + xml_get_attribute_float_with_subst(machine, boundsnode, "width", 1.0f);
1982      bounds->y0 = xml_get_attribute_float_with_subst(machine, boundsnode, "y", 0.0f);
1983      bounds->y1 = bounds->y0 + xml_get_attribute_float_with_subst(machine, boundsnode, "height", 1.0f);
1984   }
19851874   else
19861875   {
1987      fatalerror("Illegal bounds value in XML");
1988      return 1;
1876      if (m_element == NULL)
1877         throw emu_fatalerror("Layout item of type %s require an element tag", itemnode.name);
19891878   }
1990
1991   /* check for errors */
1992   if (bounds->x0 > bounds->x1 || bounds->y0 > bounds->y1)
1993   {
1994      fatalerror("Illegal bounds value in XML: (%f-%f)-(%f-%f)", bounds->x0, bounds->x1, bounds->y0, bounds->y1);
1995      return 1;
1996   }
1997   return 0;
19981879}
19991880
20001881
2001/*-------------------------------------------------
2002    load_color - parse a color XML node
2003-------------------------------------------------*/
1882//-------------------------------------------------
1883//  item - destructor
1884//-------------------------------------------------
20041885
2005static int load_color(running_machine &machine, xml_data_node *colornode, render_color *color)
1886layout_view::item::~item()
20061887{
2007   /* skip if nothing */
2008   if (colornode == NULL)
2009   {
2010      color->r = color->g = color->b = color->a = 1.0f;
2011      return 0;
2012   }
2013
2014   /* parse out the data */
2015   color->r = xml_get_attribute_float_with_subst(machine, colornode, "red", 1.0);
2016   color->g = xml_get_attribute_float_with_subst(machine, colornode, "green", 1.0);
2017   color->b = xml_get_attribute_float_with_subst(machine, colornode, "blue", 1.0);
2018   color->a = xml_get_attribute_float_with_subst(machine, colornode, "alpha", 1.0);
2019
2020   /* check for errors */
2021   if (color->r < 0.0 || color->r > 1.0 || color->g < 0.0 || color->g > 1.0 ||
2022      color->b < 0.0 || color->b > 1.0 || color->a < 0.0 || color->a > 1.0)
2023   {
2024      fatalerror("Illegal ARGB color value in XML: %f,%f,%f,%f", color->r, color->g, color->b, color->a);
2025      return 1;
2026   }
2027   return 0;
20281888}
20291889
20301890
2031/*-------------------------------------------------
2032    load_orientation - parse an orientation XML
2033    node
2034-------------------------------------------------*/
1891//-------------------------------------------------
1892//  state - fetch state based on configured source
1893//-------------------------------------------------
20351894
2036static int load_orientation(running_machine &machine, xml_data_node *orientnode, int *orientation)
1895int layout_view::item::state() const
20371896{
2038   int rotate;
2039
2040   /* skip if nothing */
2041   if (orientnode == NULL)
1897   int state = 0;
1898   
1899   assert(m_element != NULL);
1900   
1901   // if configured to an output, fetch the output value
1902   if (m_output_name[0] != 0)
1903      state = output_get_value(m_output_name);
1904   
1905   // if configured to an input, fetch the input value
1906   else if (m_input_tag[0] != 0)
20421907   {
2043      *orientation = ROT0;
2044      return 0;
1908      const input_field_config *field = input_field_by_tag_and_mask(m_element->machine().m_portlist, m_input_tag, m_input_mask);
1909      if (field != NULL)
1910         state = ((input_port_read_safe(&m_element->machine(), m_input_tag, 0) ^ field->defvalue) & m_input_mask) ? 1 : 0;
20451911   }
2046
2047   /* parse out the data */
2048   rotate = xml_get_attribute_int_with_subst(machine, orientnode, "rotate", 0);
2049   switch (rotate)
2050   {
2051      case 0:      *orientation = ROT0;   break;
2052      case 90:   *orientation = ROT90;   break;
2053      case 180:   *orientation = ROT180;   break;
2054      case 270:   *orientation = ROT270;   break;
2055      default:
2056         fatalerror("Invalid rotation in XML orientation node: %d", rotate);
2057         return 1;
2058   }
2059   if (strcmp("yes", xml_get_attribute_string_with_subst(machine, orientnode, "swapxy", "no")) == 0)
2060      *orientation ^= ORIENTATION_SWAP_XY;
2061   if (strcmp("yes", xml_get_attribute_string_with_subst(machine, orientnode, "flipx", "no")) == 0)
2062      *orientation ^= ORIENTATION_FLIP_X;
2063   if (strcmp("yes", xml_get_attribute_string_with_subst(machine, orientnode, "flipy", "no")) == 0)
2064      *orientation ^= ORIENTATION_FLIP_Y;
2065   return 0;
1912   return state;
20661913}
20671914
20681915
2069/*-------------------------------------------------
2070    layout_file_free - free memory for a
2071    layout_file and all of its subelements
2072-------------------------------------------------*/
20731916
2074void layout_file_free(layout_file *file)
2075{
2076   /* free each element in the list */
2077   while (file->elemlist != NULL)
2078   {
2079      layout_element *temp = file->elemlist;
2080      file->elemlist = temp->next;
2081      layout_element_free(temp);
2082   }
1917//**************************************************************************
1918//  LAYOUT FILE
1919//**************************************************************************
20831920
2084   /* free each layout */
2085   while (file->viewlist != NULL)
2086   {
2087      layout_view *temp = file->viewlist;
2088      file->viewlist = temp->next;
2089      layout_view_free(temp);
2090   }
1921//-------------------------------------------------
1922//  layout_file - constructor
1923//-------------------------------------------------
20911924
2092   /* free the file itself */
2093   global_free(file);
2094}
2095
2096
2097/*-------------------------------------------------
2098    layout_view_free - free memory for a
2099    layout_view and all of its subelements
2100-------------------------------------------------*/
2101
2102static void layout_view_free(layout_view *view)
1925layout_file::layout_file(running_machine &machine, xml_data_node &rootnode, const char *dirname)
1926   : m_next(NULL),
1927     m_elemlist(machine.m_respool),
1928     m_viewlist(machine.m_respool)
21031929{
2104   int layer;
1930   // find the layout node
1931   xml_data_node *mamelayoutnode = xml_get_sibling(rootnode.child, "mamelayout");
1932   if (mamelayoutnode == NULL)
1933      throw emu_fatalerror("Invalid XML file: missing mamelayout node");
21051934
2106   /* for each layer, free each item in that layer */
2107   for (layer = 0; layer < ITEM_LAYER_MAX; layer++)
2108      while (view->itemlist[layer] != NULL)
2109      {
2110         view_item *temp = view->itemlist[layer];
2111         view->itemlist[layer] = temp->next;
2112         if (temp->output_name != NULL)
2113            global_free(temp->output_name);
2114         if (temp->input_tag != NULL)
2115            global_free(temp->input_tag);
2116         global_free(temp);
2117      }
1935   // validate the config data version
1936   int version = xml_get_attribute_int(mamelayoutnode, "version", 0);
1937   if (version != LAYOUT_VERSION)
1938      throw emu_fatalerror("Invalid XML file: unsupported version");
21181939
2119   /* free the view itself */
2120   if (view->name != NULL)
2121      global_free((void *)view->name);
2122   global_free(view);
1940   // parse all the elements
1941   for (xml_data_node *elemnode = xml_get_sibling(mamelayoutnode->child, "element"); elemnode != NULL; elemnode = xml_get_sibling(elemnode->next, "element"))
1942      m_elemlist.append(*auto_alloc(&machine, layout_element(machine, *elemnode, dirname)));
1943
1944   // parse all the views
1945   for (xml_data_node *viewnode = xml_get_sibling(mamelayoutnode->child, "view"); viewnode != NULL; viewnode = xml_get_sibling(viewnode->next, "view"))
1946      m_viewlist.append(*auto_alloc(&machine, layout_view(machine, *viewnode, m_elemlist)));
21231947}
21241948
21251949
2126/*-------------------------------------------------
2127    layout_element_free - free memory for a
2128    layout_element and its components
2129-------------------------------------------------*/
1950//-------------------------------------------------
1951//  ~layout_file - destructor
1952//-------------------------------------------------
21301953
2131static void layout_element_free(layout_element *element)
1954layout_file::~layout_file()
21321955{
2133   /* free all allocated components */
2134   while (element->complist != NULL)
2135   {
2136      element_component *temp = element->complist;
2137      element->complist = temp->next;
2138      if (temp->string != NULL)
2139         global_free(temp->string);
2140      if (temp->dirname != NULL)
2141         global_free(temp->dirname);
2142      if (temp->imagefile != NULL)
2143         global_free(temp->imagefile);
2144      if (temp->alphafile != NULL)
2145         global_free(temp->alphafile);
2146      global_free(temp->bitmap);
2147      global_free(temp);
2148   }
2149
2150   /* free all textures */
2151   if (element->elemtex != NULL)
2152   {
2153      int state;
2154
2155      /* loop over all states and free their textures */
2156      for (state = 0; state <= element->maxstate; state++)
2157         element->machine->render().texture_free(element->elemtex[state].texture);
2158
2159      global_free(element->elemtex);
2160   }
2161
2162   /* free the element itself */
2163   if (element->name != NULL)
2164      global_free(element->name);
2165   global_free(element);
21661956}
src/emu/rendlay.h
r9411r9412
44
55    Core rendering layout parser and manager.
66
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
7****************************************************************************
98
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
1038***************************************************************************/
1139
1240#ifndef __RENDLAY_H__
r9411r9412
1442
1543#include "render.h"
1644
17#include <math.h>
1845
46//**************************************************************************
47//  CONSTANTS
48//**************************************************************************
1949
20
21/***************************************************************************
22
23    Theory of operation
24    -------------------
25
26    A render "target" is described by 5 parameters:
27
28        - width = width, in pixels
29        - height = height, in pixels
30        - bpp = depth, in bits per pixel
31        - orientation = orientation of the target
32        - pixel_aspect = aspect ratio of the pixels
33
34    Width, height, and bpp are self-explanatory. The remaining parameters
35    need some additional explanation.
36
37    Regarding orientation, there are three orientations that need to be
38    dealt with: target orientation, UI orientation, and game orientation.
39    In the current model, the UI orientation tracks the target orientation
40    so that the UI is (in theory) facing the correct direction. The game
41    orientation is specified by the game driver and indicates how the
42    game and artwork are rotated.
43
44    Regarding pixel_aspect, this is the aspect ratio of the individual
45    pixels, not the aspect ratio of the screen. You can determine this by
46    dividing the aspect ratio of the screen by the aspect ratio of the
47    resolution. For example, a 4:3 screen displaying 640x480 gives a
48    pixel aspect ratio of (4/3)/(640/480) = 1.0, meaning the pixels are
49    square. That same screen displaying 1280x1024 would have a pixel
50    aspect ratio of (4/3)/(1280/1024) = 1.06666, meaning the pixels are
51    slightly wider than they are tall.
52
53    Artwork is always assumed to be a 1.0 pixel aspect ratio. The game
54    screens themselves can be variable aspect ratios.
55
56***************************************************************************/
57
58
59/***************************************************************************
60    CONSTANTS
61***************************************************************************/
62
63enum
50enum item_layer
6451{
65   ITEM_LAYER_BACKDROP = 0,
52   ITEM_LAYER_FIRST = 0,
53   ITEM_LAYER_BACKDROP = ITEM_LAYER_FIRST,
6654   ITEM_LAYER_SCREEN,
6755   ITEM_LAYER_OVERLAY,
6856   ITEM_LAYER_BEZEL,
6957   ITEM_LAYER_MAX
7058};
59DECLARE_ENUM_OPERATORS(item_layer);
7160
7261
7362
74/***************************************************************************
75    TYPE DEFINITIONS
76***************************************************************************/
63//**************************************************************************
64//  TYPE DEFINITIONS
65//**************************************************************************
7766
78typedef struct _element_component element_component;
79typedef struct _element_texture element_texture;
80typedef struct _layout_element layout_element;
81typedef struct _view_item_state view_item_state;
82typedef struct _view_item view_item;
83typedef struct _layout_view layout_view;
84typedef struct _layout_file layout_file;
8567
86/* an element_texture encapsulates a texture for a given element in a given state */
87struct _element_texture
68// ======================> layout_element
69
70// a layout_element is a single named element, which may have multiple components
71class layout_element
8872{
89   layout_element *   element;         /* pointer back to the element */
90   render_texture *   texture;         /* texture for this state */
91   int               state;            /* associated state number */
92};
73   friend class simple_list<layout_element>;
74   
75public:
76   // construction/destruction
77   layout_element(running_machine &machine, xml_data_node &elemnode, const char *dirname);
78   virtual ~layout_element();
9379
80   // getters   
81   layout_element *next() const { return m_next; }
82   const char *name() const { return m_name; }
83   running_machine &machine() const { return m_machine; }
84   int default_state() const { return m_defstate; }
85   int maxstate() const { return m_maxstate; }
86   render_texture *state_texture(int state);
9487
95/* a layout_element is a single named element, which may have multiple components */
96struct _layout_element
97{
98   layout_element *   next;            /* link to next element */
99   running_machine *   machine;
100   const char *      name;            /* name of this element */
101   element_component *   complist;         /* head of the list of components */
102   int               defstate;         /* default state of this element */
103   int               maxstate;         /* maximum state value for all components */
104   element_texture *   elemtex;         /* array of element textures used for managing the scaled bitmaps */
105};
88private:
89   // a component represents an image, rectangle, or disk in an element
90   class component
91   {
92      friend class layout_element;
93      friend class simple_list<component>;
94     
95   public:
96      // construction/destruction
97      component(running_machine &machine, xml_data_node &compnode, const char *dirname);
98      ~component();
10699
100      // getters
101      component *next() const { return m_next; }
102      const render_bounds &bounds() const { return m_bounds; }
103     
104      // operations
105      void draw(running_machine &machine, bitmap_t &dest, const rectangle &bounds, int state);
107106
108/* a view_item_state contains the string-tagged state of a view item */
109struct _view_item_state
110{
111   view_item_state *   next;            /* pointer to the next one */
112   const char *      name;            /* string that was set */
113   int               curstate;         /* current state */
114};
107   private:
108      // component types
109      enum component_type
110      {
111         CTYPE_INVALID = 0,
112         CTYPE_IMAGE,
113         CTYPE_RECT,
114         CTYPE_DISK,
115         CTYPE_TEXT,
116         CTYPE_LED7SEG,
117         CTYPE_LED14SEG,
118         CTYPE_LED16SEG,
119         CTYPE_LED14SEGSC,
120         CTYPE_LED16SEGSC,
121         CTYPE_DOTMATRIX,
122         CTYPE_MAX
123      };
124     
125      // helpers
126      void draw_rect(bitmap_t &dest, const rectangle &bounds);
127      void draw_disk(bitmap_t &dest, const rectangle &bounds);
128      void draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds);
129      bitmap_t *load_bitmap();
130      void draw_led7seg(bitmap_t &dest, const rectangle &bounds, int pattern);
131      void draw_led14seg(bitmap_t &dest, const rectangle &bounds, int pattern);
132      void draw_led14segsc(bitmap_t &dest, const rectangle &bounds, int pattern);
133      void draw_led16seg(bitmap_t &dest, const rectangle &bounds, int pattern);
134      void draw_led16segsc(bitmap_t &dest, const rectangle &bounds, int pattern);
135      void draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, int pattern);
136      void draw_segment_horizontal_caps(bitmap_t &dest, int minx, int maxx, int midy, int width, int caps, rgb_t color);
137      void draw_segment_horizontal(bitmap_t &dest, int minx, int maxx, int midy, int width, rgb_t color);
138      void draw_segment_vertical_caps(bitmap_t &dest, int miny, int maxy, int midx, int width, int caps, rgb_t color);
139      void draw_segment_vertical(bitmap_t &dest, int miny, int maxy, int midx, int width, rgb_t color);
140      void draw_segment_diagonal_1(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color);
141      void draw_segment_diagonal_2(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color);
142      void draw_segment_decimal(bitmap_t &dest, int midx, int midy, int width, rgb_t color);
143      void draw_segment_comma(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color);
144      void apply_skew(bitmap_t &dest, int skewwidth);
115145
146      // internal state
147      component *         m_next;         // link to next component
148      component_type      m_type;         // type of component
149      int               m_state;      // state where this component is visible (-1 means all states)
150      render_bounds      m_bounds;      // bounds of the element
151      render_color      m_color;      // color of the element
152      astring            m_string;      // string for text components
153      bitmap_t *         m_bitmap;      // source bitmap for images
154      astring            m_dirname;      // directory name of image file (for lazy loading)
155      astring            m_imagefile;   // name of the image file (for lazy loading)
156      astring            m_alphafile;   // name of the alpha file (for lazy loading)
157      bool            m_hasalpha;      // is there any alpha component present?
158   };
116159
117/* a view_item is a single backdrop, screen, overlay, or bezel item */
118struct _view_item
119{
120   view_item *         next;            /* link to next item */
121   layout_element *   element;         /* pointer to the associated element (non-screens only) */
122   const char *      output_name;      /* name of this item */
123   const char *      input_tag;         /* input tag of this item */
124   UINT32            input_mask;         /* input mask of this item */
125   int               index;            /* index for this item (screens only) */
126   int               orientation;      /* orientation of this item */
127   render_bounds      bounds;            /* bounds of the item */
128   render_bounds      rawbounds;         /* raw (original) bounds of the item */
129   render_color      color;            /* color of the item */
130};
160   // a texture encapsulates a texture for a given element in a given state
161   class texture
162   {
163   public:
164      texture();
165      ~texture();
166   
167      layout_element *   m_element;      // pointer back to the element
168      render_texture *   m_texture;      // texture for this state
169      int               m_state;      // associated state number
170   };
131171
172   // internal helpers
173   static void element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param);
132174
133/* a layout_view encapsulates a named list of items */
134struct _layout_view
135{
136   layout_view *      next;            /* pointer to next layout in the list */
137   const char *      name;            /* name of the layout */
138   float            aspect;            /* X/Y of the layout */
139   float            scraspect;         /* X/Y of the screen areas */
140   UINT32            screens;         /* bitmask of screens used */
141   render_bounds      bounds;            /* computed bounds of the view */
142   render_bounds      scrbounds;         /* computed bounds of the screens within the view */
143   render_bounds      expbounds;         /* explicit bounds of the view */
144   UINT8            layenabled[ITEM_LAYER_MAX]; /* is this layer enabled? */
145   view_item *         itemlist[ITEM_LAYER_MAX]; /* list of layout items for each layer */
175   // internal state
176   layout_element *   m_next;            // link to next element
177   running_machine &   m_machine;         // reference to the owning machine
178   astring            m_name;            // name of this element
179   simple_list<component> m_complist;      // list of components
180   int               m_defstate;         // default state of this element
181   int               m_maxstate;         // maximum state value for all components
182   texture *         m_elemtex;         // array of element textures used for managing the scaled bitmaps
146183};
147184
148185
149/* a layout_file consists of a list of elements and a list of views */
150struct _layout_file
186// ======================> layout_view
187
188// a layout_view encapsulates a named list of items
189class layout_view
151190{
152   layout_file *      next;            /* pointer to the next file in the list */
153   layout_element *   elemlist;         /* list of shared layout elements */
154   layout_view *      viewlist;         /* list of views */
155};
191   friend class simple_list<layout_view>;
156192
193public:
194   // an item is a single backdrop, screen, overlay, or bezel item
195   class item
196   {
197      friend class layout_view;
198      friend class simple_list<item>;
157199
200   public:
201      // construction/destruction
202      item(running_machine &machine, xml_data_node &itemnode, simple_list<layout_element> &elemlist);
203      virtual ~item();
158204
159/***************************************************************************
160    FUNCTION PROTOTYPES
161***************************************************************************/
205      // getters
206      item *next() const { return m_next; }
207      layout_element *element() const { return m_element; }
208      screen_device *screen() { return m_screen; }
209      const render_bounds &bounds() const { return m_bounds; }
210      const render_color &color() const { return m_color; }
211      int orientation() const { return m_orientation; }
212      render_container *screen_container(running_machine &machine) const { return (m_screen != NULL) ? &m_screen->container() : NULL; }
213      bool has_input() const { return bool(m_input_tag); }
214      const char *input_tag_and_mask(UINT32 &mask) const { mask = m_input_mask; return m_input_tag; }
215     
216      // fetch state based on configured source
217      int state() const;
162218
163/* ----- layout views ----- */
164void layout_view_recompute(layout_view *view, int layerconfig);
219   private:
220      // internal state
221      item *            m_next;            // link to next item
222      layout_element *   m_element;         // pointer to the associated element (non-screens only)
223      astring            m_output_name;      // name of this item
224      astring            m_input_tag;      // input tag of this item
225      UINT32            m_input_mask;      // input mask of this item
226      screen_device *      m_screen;         // pointer to screen
227      int               m_orientation;      // orientation of this item
228      render_bounds      m_bounds;         // bounds of the item
229      render_bounds      m_rawbounds;      // raw (original) bounds of the item
230      render_color      m_color;         // color of the item
231   };
232   
233   // construction/destruction
234   layout_view(running_machine &machine, xml_data_node &viewnode, simple_list<layout_element> &elemlist);
235   virtual ~layout_view();
165236
237   // getters
238   layout_view *next() const { return m_next; }
239   item *first_item(item_layer layer) const;
240   const char *name() const { return m_name; }
241   const render_screen_list &screens() const { return m_screens; }
242   bool layer_enabled(item_layer layer) const { return m_layenabled[layer]; }
166243
167/* ----- layout file parsing ----- */
168layout_file *layout_file_load(running_machine &machine, const char *dirname, const char *filename);
169void layout_file_free(layout_file *file);
244   //
245   bool has_art() const { return (m_backdrop_list.count() + m_overlay_list.count() + m_bezel_list.count() != 0); }
246   float effective_aspect(render_layer_config config) const { return (config.zoom_to_screen() && m_screens.count() != 0) ? m_scraspect : m_aspect; }
170247
248   // operations
249   void recompute(render_layer_config layerconfig);
171250
251private:
252   // internal state
253   layout_view *      m_next;            // pointer to next layout in the list
254   astring            m_name;            // name of the layout
255   float            m_aspect;         // X/Y of the layout
256   float            m_scraspect;      // X/Y of the screen areas
257   render_screen_list    m_screens;          // list of active screens
258   render_bounds      m_bounds;         // computed bounds of the view
259   render_bounds      m_scrbounds;      // computed bounds of the screens within the view
260   render_bounds      m_expbounds;      // explicit bounds of the view
261   bool            m_layenabled[ITEM_LAYER_MAX]; // is this layer enabled?
262   simple_list<item>    m_backdrop_list;   // list of backdrop items
263   simple_list<item>    m_screen_list;      // list of screen items
264   simple_list<item>    m_overlay_list;      // list of overlay items
265   simple_list<item>    m_bezel_list;      // list of bezel items
266};
172267
173/***************************************************************************
174    GLOBAL VARIABLES
175***************************************************************************/
176268
177/* single screen layouts */
178extern const char layout_horizont[];   /* horizontal 4:3 screens */
179extern const char layout_vertical[];   /* vertical 4:3 screens */
269// ======================> layout_file
180270
181/* dual screen layouts */
182extern const char layout_dualhsxs[];   /* dual 4:3 screens side-by-side */
183extern const char layout_dualhovu[];   /* dual 4:3 screens above and below */
184extern const char layout_dualhuov[];   /* dual 4:3 screens below and above */
271// a layout_file consists of a list of elements and a list of views
272class layout_file
273{
274   friend class simple_list<layout_file>;
275   
276public:
277   // construction/destruction
278   layout_file(running_machine &machine, xml_data_node &rootnode, const char *dirname);
279   virtual ~layout_file();
185280
186/* triple screen layouts */
187extern const char layout_triphsxs[];   /* triple 4:3 screens side-by-side */
281   // getters
282   layout_file *next() const { return m_next; }
283   layout_element *first_element() const { return m_elemlist.first(); }
284   layout_view *first_view() const { return m_viewlist.first(); }
188285
189/* generic color overlay layouts */
190extern const char layout_ho20ffff[];   /* horizontal 4:3 with 20,FF,FF color overlay */
191extern const char layout_ho2eff2e[];   /* horizontal 4:3 with 2E,FF,2E color overlay */
192extern const char layout_ho4f893d[];   /* horizontal 4:3 with 4F,89,3D color overlay */
193extern const char layout_ho88ffff[];   /* horizontal 4:3 with 88,FF,FF color overlay */
194extern const char layout_hoa0a0ff[];   /* horizontal 4:3 with A0,A0,FF color overlay */
195extern const char layout_hoffe457[];   /* horizontal 4:3 with FF,E4,57 color overlay */
196extern const char layout_hoffff20[];   /* horizontal 4:3 with FF,FF,20 color overlay */
197extern const char layout_voffff20[];   /* vertical 4:3 with FF,FF,20 color overlay */
286private:
287   // internal state
288   layout_file *      m_next;            // pointer to the next file in the list
289   simple_list<layout_element> m_elemlist;   // list of shared layout elements
290   simple_list<layout_view> m_viewlist;   // list of views
291};
198292
199293
200294
201/***************************************************************************
202    INLINE FUNCTIONS
203***************************************************************************/
295//**************************************************************************
296//  GLOBAL VARIABLES
297//**************************************************************************
204298
205/*-------------------------------------------------
206    layout_view_has_art - true if a render_view contains
207    any non-screen elements
208-------------------------------------------------*/
299// single screen layouts
300extern const char layout_horizont[];   // horizontal 4:3 screens
301extern const char layout_vertical[];   // vertical 4:3 screens
209302
210INLINE int layout_view_has_art(layout_view *view)
211{
212   return (view->itemlist[ITEM_LAYER_BACKDROP] != 0 ||
213         view->itemlist[ITEM_LAYER_OVERLAY] != 0 ||
214         view->itemlist[ITEM_LAYER_BEZEL] != 0);
215}
303// dual screen layouts
304extern const char layout_dualhsxs[];   // dual 4:3 screens side-by-side
305extern const char layout_dualhovu[];   // dual 4:3 screens above and below
306extern const char layout_dualhuov[];   // dual 4:3 screens below and above
216307
308// triple screen layouts
309extern const char layout_triphsxs[];   // triple 4:3 screens side-by-side
217310
311// generic color overlay layouts
312extern const char layout_ho20ffff[];   // horizontal 4:3 with 20,FF,FF color overlay
313extern const char layout_ho2eff2e[];   // horizontal 4:3 with 2E,FF,2E color overlay
314extern const char layout_ho4f893d[];   // horizontal 4:3 with 4F,89,3D color overlay
315extern const char layout_ho88ffff[];   // horizontal 4:3 with 88,FF,FF color overlay
316extern const char layout_hoa0a0ff[];   // horizontal 4:3 with A0,A0,FF color overlay
317extern const char layout_hoffe457[];   // horizontal 4:3 with FF,E4,57 color overlay
318extern const char layout_hoffff20[];   // horizontal 4:3 with FF,FF,20 color overlay
319extern const char layout_voffff20[];   // vertical 4:3 with FF,FF,20 color overlay
218320
219#endif   /* __RENDLAY_H__ */
321
322#endif   // __RENDLAY_H__
src/emu/crsshair.c
r9411r9412
154154   char filename[20];
155155   rgb_t color = crosshair_colors[player];
156156
157   /* if we have a bitmap for this player, kill it */
157   /* if we have a bitmap and texture for this player, kill it */
158158   global_free(global.bitmap[player]);
159   machine->render().texture_free(global.texture[player]);
159160
160161   if (global.name[player][0] != 0)
161162   {
r9411r9412
208209
209210void crosshair_init(running_machine *machine)
210211{
211   const input_port_config *port;
212   const input_field_config *field;
213
214212   /* request a callback upon exiting */
215213   machine->add_notifier(MACHINE_NOTIFY_EXIT, crosshair_exit);
216214
r9411r9412
221219   global.auto_time = CROSSHAIR_VISIBILITY_AUTOTIME_DEFAULT;
222220
223221   /* determine who needs crosshairs */
224   for (port = machine->m_portlist.first(); port != NULL; port = port->next())
225      for (field = port->fieldlist; field != NULL; field = field->next)
222   for (const input_port_config *port = machine->m_portlist.first(); port != NULL; port = port->next())
223      for (const input_field_config *field = port->fieldlist; field != NULL; field = field->next)
226224         if (field->crossaxis != CROSSHAIR_AXIS_NONE)
227225         {
228226            int player = field->player;
r9411r9412
258256
259257static void crosshair_exit(running_machine &machine)
260258{
261   int player;
262
263259   /* free bitmaps and textures for each player */
264   for (player = 0; player < MAX_PLAYERS; player++)
260   for (int player = 0; player < MAX_PLAYERS; player++)
265261   {
266262      machine.render().texture_free(global.texture[player]);
267263      global.texture[player] = NULL;
src/emu/render.c
r9411r9412
201201//  appropriate layer index and blendmode
202202//-------------------------------------------------
203203
204inline int get_layer_and_blendmode(const layout_view &view, int index, int &blendmode)
204inline item_layer get_layer_and_blendmode(const layout_view &view, int index, int &blendmode)
205205{
206    const int *layer_order = layer_order_standard;
207    int layer;
208
209206   //  if we have multiple backdrop pieces and no overlays, render:
210207    //      backdrop (add) + screens (add) + bezels (alpha)
211208    //  else render:
212209    //      screens (add) + overlays (RGB multiply) + backdrop (add) + bezels (alpha)
213210
214   if (view.itemlist[ITEM_LAYER_BACKDROP] != NULL && view.itemlist[ITEM_LAYER_BACKDROP]->next != NULL && view.itemlist[ITEM_LAYER_OVERLAY] == NULL)
211    const int *layer_order = layer_order_standard;
212   if (view.first_item(ITEM_LAYER_BACKDROP) != NULL && view.first_item(ITEM_LAYER_BACKDROP)->next() != NULL && view.first_item(ITEM_LAYER_OVERLAY) == NULL)
215213      layer_order = layer_order_alternate;
216214
217215   // select the layer
218   layer = layer_order[index];
216   int layer = layer_order[index];
219217
220218   // pick a blendmode
221219   if (layer == ITEM_LAYER_SCREEN && layer_order == layer_order_standard)
r9411r9412
227225   else
228226      blendmode = BLENDMODE_ALPHA;
229227
230   return layer;
228   return item_layer(layer);
231229}
232230
233231
r9411r9412
10251023   : m_next(NULL),
10261024     m_manager(manager),
10271025     m_curview(NULL),
1028     m_filelist(NULL),
1026     m_filelist(*auto_alloc(&manager.machine(), simple_list<layout_file>(manager.machine().m_respool))),
10291027     m_flags(flags),
10301028     m_listindex(0),
10311029     m_width(640),
r9411r9412
10331031     m_pixel_aspect(0.0f),
10341032     m_max_refresh(0),
10351033     m_orientation(0),
1036     m_layerconfig(LAYER_CONFIG_DEFAULT),
10371034     m_base_view(NULL),
10381035     m_base_orientation(ROT0),
1039     m_base_layerconfig(LAYER_CONFIG_DEFAULT),
10401036     m_maxtexwidth(65536),
10411037     m_maxtexheight(65536),
10421038     m_debug_containers(manager.machine().m_respool)
10431039{
10441040   // determine the base layer configuration based on options
1045   if (!options_get_bool(manager.machine().options(), OPTION_USE_BACKDROPS)) m_base_layerconfig &= ~LAYER_CONFIG_ENABLE_BACKDROP;
1046   if (!options_get_bool(manager.machine().options(), OPTION_USE_OVERLAYS)) m_base_layerconfig &= ~LAYER_CONFIG_ENABLE_OVERLAY;
1047   if (!options_get_bool(manager.machine().options(), OPTION_USE_BEZELS)) m_base_layerconfig &= ~LAYER_CONFIG_ENABLE_BEZEL;
1048   if (options_get_bool(manager.machine().options(), OPTION_ARTWORK_CROP)) m_base_layerconfig |= LAYER_CONFIG_ZOOM_TO_SCREEN;
1041   m_base_layerconfig.set_backdrops_enabled(options_get_bool(manager.machine().options(), OPTION_USE_BACKDROPS));
1042   m_base_layerconfig.set_overlays_enabled(options_get_bool(manager.machine().options(), OPTION_USE_OVERLAYS));
1043   m_base_layerconfig.set_bezels_enabled(options_get_bool(manager.machine().options(), OPTION_USE_BEZELS));
1044   m_base_layerconfig.set_zoom_to_screen(options_get_bool(manager.machine().options(), OPTION_ARTWORK_CROP));
10491045
10501046   // determine the base orientation based on options
10511047   m_orientation = ROT0;
r9411r9412
10861082
10871083render_target::~render_target()
10881084{
1089   // free the layout files
1090   while (m_filelist != NULL)
1091   {
1092      layout_file *temp = m_filelist;
1093      m_filelist = temp->next;
1094      layout_file_free(temp);
1095   }
1085   auto_free(&m_manager.machine(), &m_filelist);
10961086}
10971087
10981088
r9411r9412
11341124
11351125
11361126//-------------------------------------------------
1137//  set_layer_config - set the layer config of a
1138//  target
1139//-------------------------------------------------
1140
1141void render_target::set_layer_config(int layerconfig)
1142{
1143   m_layerconfig = layerconfig;
1144   layout_view_recompute(m_curview, layerconfig);
1145}
1146
1147
1148//-------------------------------------------------
11491127//  set_view - dynamically change the view for
11501128//  a target
11511129//-------------------------------------------------
r9411r9412
11561134   if (view != NULL)
11571135   {
11581136      m_curview = view;
1159      layout_view_recompute(view, m_layerconfig);
1137      view->recompute(m_layerconfig);
11601138   }
11611139}
11621140
r9411r9412
11801158const char *render_target::view_name(int viewindex)
11811159{
11821160   layout_view *view = view_by_index(viewindex);
1183   return (view != NULL) ? view->name : NULL;
1161   return (view != NULL) ? view->name() : NULL;
11841162}
11851163
11861164
r9411r9412
11901168//  given view
11911169//-------------------------------------------------
11921170
1193UINT32 render_target::view_screens(int viewindex)
1171const render_screen_list &render_target::view_screens(int viewindex)
11941172{
11951173   layout_view *view = view_by_index(viewindex);
1196   return (view != NULL) ? view->screens : NULL;
1174   return (view != NULL) ? view->screens() : s_empty_screen_list;
11971175}
11981176
11991177
r9411r9412
12121190   if (target_pixel_aspect != 0.0f)
12131191   {
12141192      // start with the aspect ratio of the square pixel layout
1215      width = (zoom_to_screen() && m_curview->screens > 0) ? m_curview->scraspect : m_curview->aspect;
1193      width = m_curview->effective_aspect(m_layerconfig);
12161194      height = 1.0f;
12171195
12181196      // first apply target orientation
r9411r9412
12541232{
12551233   float maxxscale = 1.0f, maxyscale = 1.0f;
12561234   int screens_considered = 0;
1235   
1236   // early exit in case we are called between device teardown and render teardown
1237   if (m_manager.machine().m_devicelist.count() == 0)
1238   {
1239      minwidth = 640;
1240      minheight = 480;
1241      return;
1242   }
12571243
12581244   // scan the current view for all screens
1259   for (int layer = 0; layer < ITEM_LAYER_MAX; layer++)
1245   for (item_layer layer = ITEM_LAYER_FIRST; layer < ITEM_LAYER_MAX; layer++)
12601246
12611247      // iterate over items in the layer
1262      for (view_item *item = m_curview->itemlist[layer]; item != NULL; item = item->next)
1263         if (item->element == NULL)
1248      for (layout_view::item *curitem = m_curview->first_item(layer); curitem != NULL; curitem = curitem->next())
1249         if (curitem->screen() != NULL)
12641250         {
1265            const screen_device_config *scrconfig = downcast<const screen_device_config *>(m_manager.machine().config->m_devicelist.find(SCREEN, item->index));
1266            screen_device *screendev = m_manager.machine().device<screen_device>(scrconfig->tag());
1267
1268            // we may be called very early, before machine->visible_area is initialized; handle that case
1251            // use a hard-coded default visible area for vector screens
1252            screen_device *screen = curitem->screen();
12691253            const rectangle vectorvis = { 0, 639, 0, 479 };
1270            const rectangle *visarea = NULL;
1271            if (scrconfig->screen_type() == SCREEN_TYPE_VECTOR)
1272               visarea = &vectorvis;
1273            else if (screendev != NULL && screendev->started())
1274               visarea = &screendev->visible_area();
1275            else
1276               visarea = &scrconfig->visible_area();
1254            const rectangle &visarea = (screen->screen_type() == SCREEN_TYPE_VECTOR) ? vectorvis : screen->visible_area();
12771255
12781256            // apply target orientation to the bounds
1279            render_bounds bounds = item->bounds;
1257            render_bounds bounds = curitem->bounds();
12801258            apply_orientation(bounds, m_orientation);
12811259            normalize_bounds(bounds);
12821260
12831261            // based on the orientation of the screen container, check the bitmap
1284            render_container *container = m_manager.m_screen_container_list.find(item->index);
12851262            float xscale, yscale;
1286            if (!(orientation_add(m_orientation, container->orientation()) & ORIENTATION_SWAP_XY))
1263            if (!(orientation_add(m_orientation, screen->container().orientation()) & ORIENTATION_SWAP_XY))
12871264            {
1288               xscale = (float)(visarea->max_x + 1 - visarea->min_x) / (bounds.x1 - bounds.x0);
1289               yscale = (float)(visarea->max_y + 1 - visarea->min_y) / (bounds.y1 - bounds.y0);
1265               xscale = (float)(visarea.max_x + 1 - visarea.min_x) / (bounds.x1 - bounds.x0);
1266               yscale = (float)(visarea.max_y + 1 - visarea.min_y) / (bounds.y1 - bounds.y0);
12901267            }
12911268            else
12921269            {
1293               xscale = (float)(visarea->max_y + 1 - visarea->min_y) / (bounds.x1 - bounds.x0);
1294               yscale = (float)(visarea->max_x + 1 - visarea->min_x) / (bounds.y1 - bounds.y0);
1270               xscale = (float)(visarea.max_y + 1 - visarea.min_y) / (bounds.x1 - bounds.x0);
1271               yscale = (float)(visarea.max_x + 1 - visarea.min_x) / (bounds.y1 - bounds.y0);
12951272            }
12961273
12971274            // pick the greater
r9411r9412
13481325
13491326   // iterate over layers back-to-front, but only if we're running
13501327   if (m_manager.machine().phase() >= MACHINE_PHASE_RESET)
1351      for (int layernum = 0; layernum < ITEM_LAYER_MAX; layernum++)
1328      for (item_layer layernum = ITEM_LAYER_FIRST; layernum < ITEM_LAYER_MAX; layernum++)
13521329      {
13531330         int blendmode;
1354         int layer = get_layer_and_blendmode(*m_curview, layernum, blendmode);
1355         if (m_curview->layenabled[layer])
1331         item_layer layer = get_layer_and_blendmode(*m_curview, layernum, blendmode);
1332         if (m_curview->layer_enabled(layer))
13561333         {
13571334            // iterate over items in the layer
1358            for (view_item *item = m_curview->itemlist[layer]; item != NULL; item = item->next)
1335            for (layout_view::item *curitem = m_curview->first_item(layer); curitem != NULL; curitem = curitem->next())
13591336            {
13601337               // first apply orientation to the bounds
1361               render_bounds bounds = item->bounds;
1338               render_bounds bounds = curitem->bounds();
13621339               apply_orientation(bounds, root_xform.orientation);
13631340               normalize_bounds(bounds);
13641341
r9411r9412
13681345               item_xform.yoffs = root_xform.yoffs + bounds.y0 * root_xform.yscale;
13691346               item_xform.xscale = (bounds.x1 - bounds.x0) * root_xform.xscale;
13701347               item_xform.yscale = (bounds.y1 - bounds.y0) * root_xform.yscale;
1371               item_xform.color.r = item->color.r * root_xform.color.r;
1372               item_xform.color.g = item->color.g * root_xform.color.g;
1373               item_xform.color.b = item->color.b * root_xform.color.b;
1374               item_xform.color.a = item->color.a * root_xform.color.a;
1375               item_xform.orientation = orientation_add(item->orientation, root_xform.orientation);
1348               item_xform.color.r = curitem->color().r * root_xform.color.r;
1349               item_xform.color.g = curitem->color().g * root_xform.color.g;
1350               item_xform.color.b = curitem->color().b * root_xform.color.b;
1351               item_xform.color.a = curitem->color().a * root_xform.color.a;
1352               item_xform.orientation = orientation_add(curitem->orientation(), root_xform.orientation);
13761353                    item_xform.no_center = false;
13771354
13781355               // if there is no associated element, it must be a screen element
1379               if (item->element != NULL)
1380               {
1381                  int state = 0;
1382                  if (item->output_name[0] != 0)
1383                     state = output_get_value(item->output_name);
1384                  else if (item->input_tag[0] != 0)
1385                  {
1386                     const input_field_config *field = input_field_by_tag_and_mask(m_manager.machine().m_portlist, item->input_tag, item->input_mask);
1387                     if (field != NULL)
1388                        state = ((input_port_read_safe(&m_manager.machine(), item->input_tag, 0) ^ field->defvalue) & item->input_mask) ? 1 : 0;
1389                  }
1390                  add_element_primitives(list, item_xform, *item->element, state, blendmode);
1391               }
1356               if (curitem->screen() != NULL)
1357                  add_container_primitives(list, item_xform, curitem->screen()->container(), blendmode);
13921358               else
1393               {
1394                  render_container *container = m_manager.m_screen_container_list.find(item->index);
1395                  add_container_primitives(list, item_xform, *container, blendmode);
1396               }
1359                  add_element_primitives(list, item_xform, *curitem->element(), curitem->state(), blendmode);
13971360            }
13981361         }
13991362      }
r9411r9412
14681431
14691432bool render_target::map_point_container(INT32 target_x, INT32 target_y, render_container &container, float &container_x, float &container_y)
14701433{
1471   view_item *item;
1472   return map_point_internal(target_x, target_y, &container, container_x, container_y, item);
1434   const char *input_tag;
1435   UINT32 input_mask;
1436   return map_point_internal(target_x, target_y, &container, container_x, container_y, input_tag, input_mask);
14731437}
14741438
14751439
r9411r9412
14811445
14821446bool render_target::map_point_input(INT32 target_x, INT32 target_y, const char *&input_tag, UINT32 &input_mask, float &input_x, float &input_y)
14831447{
1484   view_item *item = NULL;
1485
1486   bool result = map_point_internal(target_x, target_y, NULL, input_x, input_y, item);
1487   if (result && item != NULL)
1488   {
1489      input_tag = item->input_tag;
1490      input_mask = item->input_mask;
1491   }
1492   return result;
1448   return map_point_internal(target_x, target_y, NULL, input_x, input_y, input_tag, input_mask);
14931449}
14941450
14951451
r9411r9412
15481504
15491505
15501506//-------------------------------------------------
1507//  update_layer_config - recompute after a layer
1508//  config change
1509//-------------------------------------------------
1510
1511void render_target::update_layer_config()
1512{
1513   m_curview->recompute(m_layerconfig);
1514}
1515
1516
1517//-------------------------------------------------
15511518//  load_layout_files - load layout files for a
15521519//  given render target
15531520//-------------------------------------------------
15541521
15551522void render_target::load_layout_files(const char *layoutfile, bool singlefile)
15561523{
1557   layout_file **nextfile = &m_filelist;
1558
15591524   // if there's an explicit file, load that first
15601525   const char *basename = m_manager.machine().basename();
15611526   if (layoutfile != NULL)
1562   {
1563      *nextfile = layout_file_load(m_manager.machine(), basename, layoutfile);
1564      if (*nextfile != NULL)
1565         nextfile = &(*nextfile)->next;
1566   }
1527      load_layout_file(basename, layoutfile);
15671528
15681529   // if we're only loading this file, we know our final result
15691530   if (singlefile)
r9411r9412
15711532
15721533   // try to load a file based on the driver name
15731534   const game_driver *gamedrv = m_manager.machine().gamedrv;
1574   *nextfile = layout_file_load(m_manager.machine(), basename, gamedrv->name);
1575   if (*nextfile == NULL)
1576      *nextfile = layout_file_load(m_manager.machine(), basename, "default");
1577   if (*nextfile != NULL)
1578      nextfile = &(*nextfile)->next;
1535   if (!load_layout_file(basename, gamedrv->name))
1536      load_layout_file(basename, "default");
15791537
15801538   // if a default view has been specified, use that as a fallback
15811539   if (gamedrv->default_layout != NULL)
1582   {
1583      *nextfile = layout_file_load(m_manager.machine(), NULL, gamedrv->default_layout);
1584      if (*nextfile != NULL)
1585         nextfile = &(*nextfile)->next;
1586   }
1540      load_layout_file(NULL, gamedrv->default_layout);
15871541   if (m_manager.machine().m_config.m_default_layout != NULL)
1588   {
1589      *nextfile = layout_file_load(m_manager.machine(), NULL, m_manager.machine().m_config.m_default_layout);
1590      if (*nextfile != NULL)
1591         nextfile = &(*nextfile)->next;
1592   }
1542      load_layout_file(NULL, m_manager.machine().m_config.m_default_layout);
15931543
15941544   // try to load another file based on the parent driver name
15951545   const game_driver *cloneof = driver_get_clone(gamedrv);
15961546   if (cloneof != NULL)
1597   {
1598      *nextfile = layout_file_load(m_manager.machine(), cloneof->name, cloneof->name);
1599      if (*nextfile == NULL)
1600         *nextfile = layout_file_load(m_manager.machine(), cloneof->name, "default");
1601      if (*nextfile != NULL)
1602         nextfile = &(*nextfile)->next;
1603   }
1547      if (!load_layout_file(cloneof->name, cloneof->name))
1548         load_layout_file(cloneof->name, "default");
16041549
16051550   // now do the built-in layouts for single-screen games
16061551   if (screen_count(m_manager.machine().m_config) == 1)
16071552   {
16081553      if (gamedrv->flags & ORIENTATION_SWAP_XY)
1609         *nextfile = layout_file_load(m_manager.machine(), NULL, layout_vertical);
1554         load_layout_file(NULL, layout_vertical);
16101555      else
1611         *nextfile = layout_file_load(m_manager.machine(), NULL, layout_horizont);
1612      assert_always(*nextfile != NULL, "Couldn't parse default layout??");
1613      nextfile = &(*nextfile)->next;
1556         load_layout_file(NULL, layout_horizont);
1557      assert_always(m_filelist.count() > 0, "Couldn't parse default layout??");
16141558   }
16151559}
16161560
16171561
16181562//-------------------------------------------------
1563//  load_layout_file - load a single layout file
1564//  and append it to our list
1565//-------------------------------------------------
1566
1567bool render_target::load_layout_file(const char *dirname, const char *filename)
1568{
1569   // if the first character of the "file" is an open brace, assume it is an XML string
1570   xml_data_node *rootnode;
1571   if (filename[0] == '<')
1572      rootnode = xml_string_read(filename, NULL);
1573
1574   // otherwise, assume it is a file
1575   else
1576   {
1577      // build the path and optionally prepend the directory
1578      astring fname(filename, ".lay");
1579      if (dirname != NULL)
1580         fname.ins(0, PATH_SEPARATOR).ins(0, dirname);
1581
1582      // attempt to open the file; bail if we can't
1583      mame_file *layoutfile;
1584      file_error filerr = mame_fopen(SEARCHPATH_ARTWORK, fname, OPEN_FLAG_READ, &layoutfile);
1585      if (filerr != FILERR_NONE)
1586         return false;
1587         
1588      // read the file
1589      rootnode = xml_file_read(mame_core_file(layoutfile), NULL);
1590      mame_fclose(layoutfile);
1591   }
1592   
1593   // if we didn't get a properly-formatted XML file, record a warning and exit
1594   if (rootnode == NULL)
1595   {
1596      if (filename[0] != '<')
1597         mame_printf_warning("Improperly formatted XML file '%s', ignorning\n", filename);
1598      else
1599         mame_printf_warning("Improperly formatted XML string, ignorning");
1600      return false;
1601   }
1602   
1603   // parse and catch any errors
1604   bool result = true;
1605   try
1606   {
1607      m_filelist.append(*auto_alloc(&m_manager.machine(), layout_file(m_manager.machine(), *rootnode, dirname)));
1608   }
1609   catch (emu_fatalerror &err)
1610   {
1611      if (filename[0] != '<')
1612         mame_printf_warning("Error in XML file '%s': %s\n", filename, err.string());
1613      else
1614         mame_printf_warning("Error in XML string: %s", err.string());
1615      result = false;
1616   }
1617
1618   // free the root node
1619   xml_file_free(rootnode);
1620   return result;
1621}
1622
1623
1624//-------------------------------------------------
16191625//  add_container_primitives - add primitives
16201626//  based on the container
16211627//-------------------------------------------------
r9411r9412
17671773   }
17681774
17691775   // add the overlay if it exists
1770   if (container.overlay() != NULL && screen_overlay_enabled())
1776   if (container.overlay() != NULL && m_layerconfig.screen_overlay_enabled())
17711777   {
17721778      INT32 width, height;
17731779
r9411r9412
18011807//  for an element in the current state
18021808//-------------------------------------------------
18031809
1804void render_target::add_element_primitives(render_primitive_list &list, const object_transform &xform, const layout_element &element, int state, int blendmode)
1810void render_target::add_element_primitives(render_primitive_list &list, const object_transform &xform, layout_element &element, int state, int blendmode)
18051811{
18061812   // if we're out of range, bail
1807   if (state > element.maxstate)
1813   if (state > element.maxstate())
18081814      return;
18091815   if (state < 0)
18101816      state = 0;
18111817
18121818   // get a pointer to the relevant texture
1813   render_texture *texture = element.elemtex[state].texture;
1819   render_texture *texture = element.state_texture(state);
18141820   if (texture != NULL)
18151821   {
18161822      render_primitive *prim = list.alloc(render_primitive::QUAD);
r9411r9412
18561862//  mapping points
18571863//-------------------------------------------------
18581864
1859bool render_target::map_point_internal(INT32 target_x, INT32 target_y, render_container *container, float &mapped_x, float &mapped_y, view_item *&mapped_item)
1865bool render_target::map_point_internal(INT32 target_x, INT32 target_y, render_container *container, float &mapped_x, float &mapped_y, const char *&mapped_input_tag, UINT32 &mapped_input_mask)
18601866{
18611867   // default to point not mapped
18621868   mapped_x = -1.0;
18631869   mapped_y = -1.0;
1870   mapped_input_tag = NULL;
1871   mapped_input_mask = 0;
18641872
18651873   // convert target coordinates to float
18661874   float target_fx = (float)target_x / m_width;
r9411r9412
18751883         // this point was successfully mapped
18761884         mapped_x = target_fx;
18771885         mapped_y = target_fy;
1878         mapped_item = NULL;
18791886         return true;
18801887      }
18811888      return false;
18821889   }
18831890
18841891   // loop through each layer
1885   for (int layernum = 0; layernum < ITEM_LAYER_MAX; layernum++)
1892   for (item_layer layernum = ITEM_LAYER_FIRST; layernum < ITEM_LAYER_MAX; layernum++)
18861893   {
18871894      int blendmode;
1888      int layer = get_layer_and_blendmode(*m_curview, layernum, blendmode);
1889      if (m_curview->layenabled[layer])
1895      item_layer layer = get_layer_and_blendmode(*m_curview, layernum, blendmode);
1896      if (m_curview->layer_enabled(layer))
18901897      {
18911898         // iterate over items in the layer
1892         for (view_item *item = m_curview->itemlist[layer]; item != NULL; item = item->next)
1899         for (layout_view::item *item = m_curview->first_item(layer); item != NULL; item = item->next())
18931900         {
18941901            bool checkit;
18951902
18961903            // if we're looking for a particular container, verify that we have the right one
18971904            if (container != NULL)
1898               checkit = (item->element == NULL && container == m_manager.m_screen_container_list.find(item->index));
1905               checkit = (item->screen() != NULL && &item->screen()->container() == container);
18991906
19001907            // otherwise, assume we're looking for an input
19011908            else
1902               checkit = (item->input_tag[0] != 0);
1909               checkit = item->has_input();
19031910
19041911            // this target is worth looking at; now check the point
1905            if (checkit && target_fx >= item->bounds.x0 && target_fx < item->bounds.x1 && target_fy >= item->bounds.y0 && target_fy < item->bounds.y1)
1912            if (checkit && target_fx >= item->bounds().x0 && target_fx < item->bounds().x1 && target_fy >= item->bounds().y0 && target_fy < item->bounds().y1)
19061913            {
19071914               // point successfully mapped
1908               mapped_x = (target_fx - item->bounds.x0) / (item->bounds.x1 - item->bounds.x0);
1909               mapped_y = (target_fy - item->bounds.y0) / (item->bounds.y1 - item->bounds.y0);
1910               mapped_item = item;
1915               mapped_x = (target_fx - item->bounds().x0) / (item->bounds().x1 - item->bounds().x0);
1916               mapped_y = (target_fy - item->bounds().y0) / (item->bounds().y1 - item->bounds().y0);
1917               mapped_input_tag = item->input_tag_and_mask(mapped_input_mask);
19111918               return true;
19121919            }
19131920         }
r9411r9412
19251932layout_view *render_target::view_by_index(int index) const
19261933{
19271934   // scan the list of views within each layout, skipping those that don't apply
1928   for (layout_file *file = m_filelist; file != NULL; file = file->next)
1929      for (layout_view *view = file->viewlist; view != NULL; view = view->next)
1930         if (!(m_flags & RENDER_CREATE_NO_ART) || !layout_view_has_art(view))
1935   for (layout_file *file = m_filelist.first(); file != NULL; file = file->next())
1936      for (layout_view *view = file->first_view(); view != NULL; view = view->next())
1937         if (!(m_flags & RENDER_CREATE_NO_ART) || !view->has_art())
19311938            if (index-- == 0)
19321939               return view;
19331940   return NULL;
r9411r9412
19451952   int index = 0;
19461953
19471954   // scan the list of views within each layout, skipping those that don't apply
1948   for (layout_file *file = m_filelist; file != NULL; file = file->next)
1949      for (layout_view *view = file->viewlist; view != NULL; view = view->next)
1950         if (!(m_flags & RENDER_CREATE_NO_ART) || !layout_view_has_art(view))
1955   for (layout_file *file = m_filelist.first(); file != NULL; file = file->next())
1956      for (layout_view *view = file->first_view(); view != NULL; view = view->next())
1957         if (!(m_flags & RENDER_CREATE_NO_ART) || !view->has_art())
19511958         {
19521959            if (&targetview == view)
19531960               return index;
r9411r9412
20382045   // output the view
20392046   if (m_curview != m_base_view)
20402047   {
2041      xml_set_attribute(&targetnode, "view", m_curview->name);
2048      xml_set_attribute(&targetnode, "view", m_curview->name());
20422049      changed = true;
20432050   }
20442051
20452052   // output the layer config
20462053   if (m_layerconfig != m_base_layerconfig)
20472054   {
2048      xml_set_attribute_int(&targetnode, "backdrops", backdrops_enabled());
2049      xml_set_attribute_int(&targetnode, "overlays", overlays_enabled());
2050      xml_set_attribute_int(&targetnode, "bezels", bezels_enabled());
2051      xml_set_attribute_int(&targetnode, "zoom", zoom_to_screen());
2055      xml_set_attribute_int(&targetnode, "backdrops", m_layerconfig.backdrops_enabled());
2056      xml_set_attribute_int(&targetnode, "overlays", m_layerconfig.overlays_enabled());
2057      xml_set_attribute_int(&targetnode, "bezels", m_layerconfig.bezels_enabled());
2058      xml_set_attribute_int(&targetnode, "zoom", m_layerconfig.zoom_to_screen());
20522059      changed = true;
20532060   }
20542061
r9411r9412
23602367
23612368   // create one container per screen
23622369   for (screen_device *screen = screen_first(machine); screen != NULL; screen = screen_next(screen))
2363      container_alloc(screen);
2370      screen->set_container(*container_alloc(screen));
23642371}
23652372
23662373
r9411r9412
23852392
23862393bool render_manager::is_live(screen_device &screen) const
23872394{
2388   int screen_index = screen.machine->m_devicelist.index(SCREEN, screen.tag());
2389   assert(screen_index != -1);
2390
23912395   // iterate over all live targets and or together their screen masks
2392   UINT32 bitmask = 0;
23932396   for (render_target *target = m_targetlist.first(); target != NULL; target = target->next())
2394      bitmask |= target->view_screens(target->view());
2395
2396   return (bitmask & (1 << screen_index)) ? true : false;
2397      if (target->view_screens(target->view()).contains(screen))
2398         return true;
2399   return false;
23972400}
23982401
23992402
r9411r9412
24852488
24862489
24872490//-------------------------------------------------
2488//  container_for_screen - return the container
2489//  allocated for the given screen device
2490//-------------------------------------------------
2491
2492render_container *render_manager::container_for_screen(screen_device *screen)
2493{
2494   // scan the list of screen containers for a match
2495   for (render_container *container = m_screen_container_list.first(); container != NULL; container = container->next())
2496      if (container->screen() == screen)
2497         return container;
2498   return NULL;
2499}
2500
2501
2502//-------------------------------------------------
25032491//  texture_alloc - allocate a new texture
25042492//-------------------------------------------------
25052493
src/emu/render.h
r9411r9412
113113const UINT8 RENDER_CREATE_HIDDEN      = 0x04;         // don't make this target visible
114114
115115
116// layer config masks
117const UINT8 LAYER_CONFIG_ENABLE_BACKDROP      = 0x01;   // enable backdrop layers
118const UINT8 LAYER_CONFIG_ENABLE_OVERLAY         = 0x02;   // enable overlay layers
119const UINT8 LAYER_CONFIG_ENABLE_BEZEL         = 0x04;   // enable bezel layers
120const UINT8 LAYER_CONFIG_ZOOM_TO_SCREEN         = 0x08;   // zoom to screen area by default
121const UINT8 LAYER_CONFIG_ENABLE_SCREEN_OVERLAY   = 0x10;   // enable screen overlays
122
123const UINT8 LAYER_CONFIG_DEFAULT =   (LAYER_CONFIG_ENABLE_BACKDROP |
124                            LAYER_CONFIG_ENABLE_OVERLAY |
125                            LAYER_CONFIG_ENABLE_BEZEL |
126                            LAYER_CONFIG_ENABLE_SCREEN_OVERLAY);
127
128
129116// flags for primitives
130117const int PRIMFLAG_TEXORIENT_SHIFT = 0;
131118const UINT32 PRIMFLAG_TEXORIENT_MASK = 15 << PRIMFLAG_TEXORIENT_SHIFT;
r9411r9412
183170typedef struct _xml_data_node xml_data_node;
184171typedef struct _render_font render_font;
185172struct object_transform;
186typedef struct _layout_element layout_element;
187typedef struct _layout_view layout_view;
188typedef struct _view_item view_item;
189typedef struct _layout_file layout_file;
173class layout_element;
174class layout_view;
175class layout_file;
190176
191177
192178// texture scaling callback
r9411r9412
243229};
244230
245231
232// ======================> render_screen_list
233
234// a render_screen_list is a list of screen_devices
235class render_screen_list
236{
237   // screen list item
238   class item
239   {
240      friend class simple_list<item>;
241      friend class render_screen_list;
242     
243   public:
244      // construction/destruction
245      item(screen_device &screen)
246         : m_next(NULL),
247           m_screen(screen) { }
248
249      // state
250      item *            m_next;            // next screen in list
251      screen_device &      m_screen;         // reference to screen device
252   };
253
254public:
255   // construction/destruction
256   render_screen_list(resource_pool &pool = global_resource_pool)
257      : m_list(pool) { }
258
259   // getters
260   int count() const { return m_list.count(); }
261
262   // operations
263   void add(screen_device &screen) { m_list.append(*pool_alloc(m_list.pool(), item(screen))); }
264   void reset() { m_list.reset(); }
265   
266   // query
267   bool contains(screen_device &screen) const
268   {
269      for (item *curitem = m_list.first(); curitem != NULL; curitem = curitem->m_next)
270         if (&curitem->m_screen == &screen) return true;
271      return false;
272   }
273
274private:
275   // internal state
276   simple_list<item> m_list;
277};
278
279
280// ======================> render_layer_config
281
282// render_layer_config - describes the state of layers
283class render_layer_config
284{
285   static const UINT8 ENABLE_BACKDROP         = 0x01;   // enable backdrop layers
286   static const UINT8 ENABLE_OVERLAY         = 0x02;   // enable overlay layers
287   static const UINT8 ENABLE_BEZEL            = 0x04;   // enable bezel layers
288   static const UINT8 ZOOM_TO_SCREEN         = 0x08;   // zoom to screen area by default
289   static const UINT8 ENABLE_SCREEN_OVERLAY   = 0x10;   // enable screen overlays
290   static const UINT8 DEFAULT = ENABLE_BACKDROP | ENABLE_OVERLAY | ENABLE_BEZEL | ENABLE_SCREEN_OVERLAY;
291
292public:
293   render_layer_config()
294      : m_state(DEFAULT) { }
295
296   bool operator==(const render_layer_config &rhs) const { return m_state == rhs.m_state; }
297   bool operator!=(const render_layer_config &rhs) const { return m_state != rhs.m_state; }
298
299   bool backdrops_enabled() const { return ((m_state & ENABLE_BACKDROP) != 0); }
300   bool overlays_enabled() const { return ((m_state & ENABLE_OVERLAY) != 0); }
301   bool bezels_enabled() const { return ((m_state & ENABLE_BEZEL) != 0); }
302   bool screen_overlay_enabled() const { return ((m_state & ENABLE_SCREEN_OVERLAY) != 0); }
303   bool zoom_to_screen() const { return ((m_state & ZOOM_TO_SCREEN) != 0); }
304
305   render_layer_config &set_backdrops_enabled(bool enable) { if (enable) m_state |= ENABLE_BACKDROP; else m_state &= ~ENABLE_BACKDROP; return *this; }
306   render_layer_config &set_overlays_enabled(bool enable) { if (enable) m_state |= ENABLE_OVERLAY; else m_state &= ~ENABLE_OVERLAY; return *this; }
307   render_layer_config &set_bezels_enabled(bool enable) { if (enable) m_state |= ENABLE_BEZEL; else m_state &= ~ENABLE_BEZEL; return *this; }
308   render_layer_config &set_screen_overlay_enabled(bool enable) { if (enable) m_state |= ENABLE_SCREEN_OVERLAY; else m_state &= ~ENABLE_SCREEN_OVERLAY; return *this; }
309   render_layer_config &set_zoom_to_screen(bool zoom) { if (zoom) m_state |= ZOOM_TO_SCREEN; else m_state &= ~ZOOM_TO_SCREEN; return *this; }
310
311private:
312   UINT8            m_state;
313};
314
315
246316// ======================> render_primitive
247317
248318// render_primitive - a single low-level primitive for the rendering engine
r9411r9412
530600   float pixel_aspect() const { return m_pixel_aspect; }
531601   float max_update_rate() const { return m_max_refresh; }
532602   int orientation() const { return m_orientation; }
533   int layer_config() const { return m_layerconfig; }
603   render_layer_config layer_config() const { return m_layerconfig; }
534604   int view() const { return view_index(*m_curview); }
535605   bool hidden() const { return ((m_flags & RENDER_CREATE_HIDDEN) != 0); }
536   bool backdrops_enabled() const { return (m_layerconfig & LAYER_CONFIG_ENABLE_BACKDROP) != 0; }
537   bool overlays_enabled() const { return (m_layerconfig & LAYER_CONFIG_ENABLE_OVERLAY) != 0; }
538   bool bezels_enabled() const { return (m_layerconfig & LAYER_CONFIG_ENABLE_BEZEL) != 0; }
539   bool screen_overlay_enabled() const { return (m_layerconfig & LAYER_CONFIG_ENABLE_SCREEN_OVERLAY) != 0; }
540   bool zoom_to_screen() const { return (m_layerconfig & LAYER_CONFIG_ZOOM_TO_SCREEN) != 0; }
541606   bool is_ui_target() const;
542607   int index() const;
543608
r9411r9412
545610   void set_bounds(INT32 width, INT32 height, float pixel_aspect = 0);
546611   void set_max_update_rate(float updates_per_second) { m_max_refresh = updates_per_second; }
547612   void set_orientation(int orientation) { m_orientation = orientation; }
548   void set_layer_config(int layerconfig);
549613   void set_view(int viewindex);
550614   void set_max_texture_size(int maxwidth, int maxheight);
551   void set_backdrops_enabled(bool enable) { set_layer_config(enable ? (m_layerconfig | LAYER_CONFIG_ENABLE_BACKDROP) : (m_layerconfig & ~LAYER_CONFIG_ENABLE_BACKDROP)); }
552   void set_overlays_enabled(bool enable) { set_layer_config(enable ? (m_layerconfig | LAYER_CONFIG_ENABLE_OVERLAY) : (m_layerconfig & ~LAYER_CONFIG_ENABLE_OVERLAY)); }
553   void set_bezels_enabled(bool enable) { set_layer_config(enable ? (m_layerconfig | LAYER_CONFIG_ENABLE_BEZEL) : (m_layerconfig & ~LAYER_CONFIG_ENABLE_BEZEL)); }
554   void set_screen_overlay_enabled(bool enable) { set_layer_config(enable ? (m_layerconfig | LAYER_CONFIG_ENABLE_SCREEN_OVERLAY) : (m_layerconfig & ~LAYER_CONFIG_ENABLE_SCREEN_OVERLAY)); }
555   void set_zoom_to_screen(bool zoom) { set_layer_config(zoom ? (m_layerconfig | LAYER_CONFIG_ZOOM_TO_SCREEN) : (m_layerconfig & ~LAYER_CONFIG_ZOOM_TO_SCREEN)); }
556615
616   // layer config getters
617   bool backdrops_enabled() const { return m_layerconfig.backdrops_enabled(); }
618   bool overlays_enabled() const { return m_layerconfig.overlays_enabled(); }
619   bool bezels_enabled() const { return m_layerconfig.bezels_enabled(); }
620   bool screen_overlay_enabled() const { return m_layerconfig.screen_overlay_enabled(); }
621   bool zoom_to_screen() const { return m_layerconfig.zoom_to_screen(); }
622
623   // layer config setters
624   void set_backdrops_enabled(bool enable) { m_layerconfig.set_backdrops_enabled(enable); update_layer_config(); }
625   void set_overlays_enabled(bool enable) { m_layerconfig.set_overlays_enabled(enable); update_layer_config(); }
626   void set_bezels_enabled(bool enable) { m_layerconfig.set_bezels_enabled(enable); update_layer_config(); }
627   void set_screen_overlay_enabled(bool enable) { m_layerconfig.set_screen_overlay_enabled(enable); update_layer_config(); }
628   void set_zoom_to_screen(bool zoom) { m_layerconfig.set_zoom_to_screen(zoom); update_layer_config(); }
629
557630   // view information
558631   const char *view_name(int viewindex);
559   UINT32 view_screens(int viewindex);
632   const render_screen_list &view_screens(int viewindex);
560633
561634   // bounds computations
562635   void compute_visible_area(INT32 target_width, INT32 target_height, float target_pixel_aspect, int target_orientation, INT32 &visible_width, INT32 &visible_height);
r9411r9412
579652
580653private:
581654   // internal helpers
655   void update_layer_config();
582656   void load_layout_files(const char *layoutfile, bool singlefile);
657   bool load_layout_file(const char *dirname, const char *filename);
583658   void add_container_primitives(render_primitive_list &list, const object_transform &xform, render_container &container, int blendmode);
584   void add_element_primitives(render_primitive_list &list, const object_transform &xform, const layout_element &element, int state, int blendmode);
585   bool map_point_internal(INT32 target_x, INT32 target_y, render_container *container, float &mapped_x, float &mapped_y, view_item *&mapped_item);
659   void add_element_primitives(render_primitive_list &list, const object_transform &xform, layout_element &element, int state, int blendmode);
660   bool map_point_internal(INT32 target_x, INT32 target_y, render_container *container, float &mapped_x, float &mapped_y, const char *&mapped_input_tag, UINT32 &mapped_input_mask);
586661
587662   // config callbacks
588663   void config_load(xml_data_node &targetnode);
r9411r9412
606681   render_target *         m_next;                  // link to next target
607682   render_manager &      m_manager;               // reference to our owning manager
608683   layout_view *         m_curview;               // current view
609   layout_file *         m_filelist;               // list of layout files
684   simple_list<layout_file> &m_filelist;            // list of layout files
610685   UINT32               m_flags;               // creation flags
611686   render_primitive_list   m_primlist[NUM_PRIMLISTS];   // list of primitives
612687   int                  m_listindex;            // index of next primlist to use
r9411r9412
616691   float               m_pixel_aspect;            // aspect ratio of individual pixels
617692   float               m_max_refresh;            // maximum refresh rate, 0 or if none
618693   int                  m_orientation;            // orientation
619   int                  m_layerconfig;            // layer configuration
694   render_layer_config      m_layerconfig;            // layer configuration
620695   layout_view *         m_base_view;            // the view at the time of first frame
621696   int                  m_base_orientation;         // the orientation at the time of first frame
622   int                  m_base_layerconfig;         // the layer configuration at the time of first frame
697   render_layer_config      m_base_layerconfig;         // the layer configuration at the time of first frame
623698   int                  m_maxtexwidth;            // maximum width of a texture
624699   int                  m_maxtexheight;            // maximum height of a texture
625700   simple_list<render_container> m_debug_containers;   // list of debug containers
626701   INT32               m_clear_extent_count;      // number of clear extents
627702   INT32               m_clear_extents[MAX_CLEAR_EXTENTS]; // array of clear extents
703
704   static const render_screen_list s_empty_screen_list;
628705};
629706
630707
r9411r9412
658735   void set_ui_target(render_target &target) { m_ui_target = &target; }
659736   float ui_aspect();
660737
661   // screen containers
662   render_container *container_for_screen(screen_device *screen);
663
664738   // UI containers
665739   render_container &ui_container() const { assert(m_ui_container != NULL); return *m_ui_container; }
666740
src/emu/rendutil.c
r9411r9412
2323/* utilities */
2424static void resample_argb_bitmap_average(UINT32 *dest, UINT32 drowpixels, UINT32 dwidth, UINT32 dheight, const UINT32 *source, UINT32 srowpixels, UINT32 swidth, UINT32 sheight, const render_color *color, UINT32 dx, UINT32 dy);
2525static void resample_argb_bitmap_bilinear(UINT32 *dest, UINT32 drowpixels, UINT32 dwidth, UINT32 dheight, const UINT32 *source, UINT32 srowpixels, UINT32 swidth, UINT32 sheight, const render_color *color, UINT32 dx, UINT32 dy);
26static void copy_png_to_bitmap(bitmap_t *bitmap, const png_info *png, int *hasalpha);
27static void copy_png_alpha_to_bitmap(bitmap_t *bitmap, const png_info *png, int *hasalpha);
26static void copy_png_to_bitmap(bitmap_t *bitmap, const png_info *png, bool *hasalpha);
27static void copy_png_alpha_to_bitmap(bitmap_t *bitmap, const png_info *png, bool *hasalpha);
2828
2929
3030
r9411r9412
560560    bitmap_t
561561-------------------------------------------------*/
562562
563bitmap_t *render_load_png(const char *path, const char *dirname, const char *filename, bitmap_t *alphadest, int *hasalpha)
563bitmap_t *render_load_png(const char *path, const char *dirname, const char *filename, bitmap_t *alphadest, bool *hasalpha)
564564{
565565   bitmap_t *bitmap = NULL;
566566   file_error filerr;
r9411r9412
636636    bitmap
637637-------------------------------------------------*/
638638
639static void copy_png_to_bitmap(bitmap_t *bitmap, const png_info *png, int *hasalpha)
639static void copy_png_to_bitmap(bitmap_t *bitmap, const png_info *png, bool *hasalpha)
640640{
641641   UINT8 accumalpha = 0xff;
642642   UINT8 *src;
r9411r9412
701701    to the alpha channel of a bitmap
702702-------------------------------------------------*/
703703
704static void copy_png_alpha_to_bitmap(bitmap_t *bitmap, const png_info *png, int *hasalpha)
704static void copy_png_alpha_to_bitmap(bitmap_t *bitmap, const png_info *png, bool *hasalpha)
705705{
706706   UINT8 accumalpha = 0xff;
707707   UINT8 *src;
src/emu/rendutil.h
r9411r9412
2828int render_clip_line(render_bounds *bounds, const render_bounds *clip);
2929int render_clip_quad(render_bounds *bounds, const render_bounds *clip, render_quad_texuv *texcoords);
3030void render_line_to_quad(const render_bounds *bounds, float width, render_bounds *bounds0, render_bounds *bounds1);
31bitmap_t *render_load_png(const char *path, const char *dirname, const char *filename, bitmap_t *alphadest, int *hasalpha);
31bitmap_t *render_load_png(const char *path, const char *dirname, const char *filename, bitmap_t *alphadest, bool *hasalpha);
3232
3333
3434
src/emu/emucore.h
r9411r9412
374374      m_count(0) { }
375375
376376   virtual ~simple_list() { reset(); }
377   
378   resource_pool &pool() const { return m_pool; }
377379
378380   T *first() const { return m_head; }
379381   T *last() const { return m_tail; }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team