Previous 15994 Revisions Next

r9719 Saturday 4th December, 2010 at 13:11:04 UTC by Miodrag Milanović
Sync with MAME
[src/emu]debugger.c diexec.c emu.h emu.mak emupal.c info.c inptport.c machine.c machine.h mame.c mconfig.c mconfig.h render.c render.h rendlay.c screen.c* screen.h* sound.c state.h ui.c validity.c video.c video.h
[src/emu/debug]debugcmd.c debugcpu.c
[src/emu/machine]i2cmem.c
[src/emu/video]tms9928a.c
[src/mess/drivers]a2600.c apexc.c ssem.c tm990189.c
[src/mess/machine]sms.c zx.c
[src/mess/osd/windows]menu.c
[src/mess/tools/messtest]testmess.c
[src/mess/video]733_asr.c apple1.c arcadia.c cgenie.c gb.c mbee.c odyssey2.c pc8801.c smsvdp.c thomson.c vc4000.c vectrex.c zx.c
[src/osd/sdl]debugosx.m debugwin.c drawogl.c sdl.mak sdlfile.c sdlfile.h* sdlptty_macosx.c* sdlptty_unix.c* sdlptty_win32.c* sdlsocket.c* sound.c window.c
[src/osd/windows]drawd3d.c drawdd.c window.c
[src/osd/winui]mui_util.c properties.c

src/osd/sdl/sdlptty_unix.c
r0r9719
1//============================================================
2//
3//  sdlptty_unix.c - SDL psuedo tty access functions
4//
5//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//============================================================
11 
12#include <sys/types.h>
13#include <sys/uio.h>
14#include <unistd.h>
15#include <fcntl.h>
16#include <errno.h>
17#include <pty.h>
18 
19#include "sdlfile.h"
20 
21const char *sdlfile_ptty_identifier  = "/dev/pts";
22 
23file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
24{
25   int master;
26   int aslave;
27   char name[100];
28 
29   if (openpty(&master, &aslave, name, NULL, NULL) >= 0)
30   {
31      printf("Slave of device %s is %s\n", path, name );
32      fcntl(master, F_SETFL, O_NONBLOCK);
33      (*file)->handle = master;
34      *filesize = 0;
35   }
36   else
37   {
38      return FILERR_ACCESS_DENIED;
39   }
40 
41   return FILERR_NONE;
42}
43 
44file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
45{
46   ssize_t result;
47 
48   result = read(file->handle, buffer, count);
49 
50   if (result < 0)
51   {
52      return error_to_file_error(errno);
53   }
54 
55   if (actual != NULL )
56   {
57      *actual = result;
58   }
59 
60   return FILERR_NONE;
61}
62 
63file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
64{
65   UINT32 result;   
66   result = write(file->handle, buffer, count);
67 
68   if (result < 0)
69   {
70      return error_to_file_error(errno);
71   }
72 
73   if (actual != NULL )
74   {
75      *actual = result;
76   }
77 
78   return FILERR_NONE;
79}
80 
81file_error sdl_close_ptty(osd_file *file)
82{
83   close(file->handle);
84   osd_free(file);
85 
86   return FILERR_NONE;
87}
src/osd/sdl/sdl.mak
r9718r9719
257257   $(SDLOBJ)/strconv.o   \
258258   $(SDLOBJ)/sdldir.o   \
259259   $(SDLOBJ)/sdlfile.o    \
260   $(SDLOBJ)/sdlptty_$(BASE_TARGETOS).o   \
261   $(SDLOBJ)/sdlsocket.o   \
260262   $(SDLOBJ)/sdlmisc_$(BASE_TARGETOS).o   \
261263   $(SDLOBJ)/sdlos_$(BASE_TARGETOS).o   \
262264   $(SDLOBJ)/sdlsync_$(SYNC_IMPLEMENTATION).o     \
r9718r9719
347349
348350INCPATH += `pkg-config --cflags fontconfig`
349351LIBS += `pkg-config --libs fontconfig`
350LIBS += -lSDL_ttf
352LIBS += -lSDL_ttf -lutil
351353
352354endif # Unix
353355
src/osd/sdl/sdlptty_macosx.c
r0r9719
1//============================================================
2//
3//  sdlptty_macos.c - SDL psuedo tty access functions
4//
5//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//============================================================
11 
12#include <sys/types.h>
13#include <sys/uio.h>
14#include <unistd.h>
15#include <util.h>
16#include <fcntl.h>
17#include <errno.h>
18 
19#include "sdlfile.h"
20 
21const char *sdlfile_ptty_identifier  = "/dev/pty";
22 
23file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
24{
25   int master;
26   int aslave;
27   char name[100];
28 
29   if( openpty(&master, &aslave, name, NULL, NULL) >= 0 )
30   {
31      printf("Slave of device %s is %s\n", path, name );
32      fcntl(master, F_SETFL, O_NONBLOCK);
33      (*file)->handle = master;
34      *filesize = 0;
35   }
36   else
37   {
38      return FILERR_ACCESS_DENIED;
39   }
40 
41   return FILERR_NONE;
42}
43 
44file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
45{
46   ssize_t result;
47 
48   result = read(file->handle, buffer, count);
49 
50   if (result < 0)
51   {
52      return error_to_file_error(errno);
53   }
54 
55   if (actual != NULL )
56   {
57      *actual = result;
58   }
59 
60   return FILERR_NONE;
61}
62 
63file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
64{
65   UINT32 result;   
66   result = write(file->handle, buffer, count);
67 
68   if (result < 0)
69   {
70      return error_to_file_error(errno);
71   }
72 
73   if (actual != NULL )
74   {
75      *actual = result;
76   }
77 
78   return FILERR_NONE;
79}
80 
81file_error sdl_close_ptty(osd_file *file)
82{
83   close(file->handle);
84   osd_free(file);
85 
86   return FILERR_NONE;
87}
src/osd/sdl/sdlfile.c
r9718r9719
3030#include <errno.h>
3131
3232// MAME headers
33#include "osdcore.h"
34#include "sdlos.h"
33#include "sdlfile.h"
3534
35
3636//============================================================
37//  GLOBAL IDENTIFIERS
38//============================================================
39
40extern const char *sdlfile_socket_identifier;
41extern const char *sdlfile_ptty_identifier;
42
43//============================================================
3744//  CONSTANTS
3845//============================================================
3946
r9718r9719
4754
4855#define NO_ERROR   (0)
4956
50
5157//============================================================
52//  TYPE DEFINITIONS
53//============================================================
54
55struct _osd_file
56{
57   int      handle;
58   char   filename[1];
59};
60
61
62//============================================================
6358//  Prototypes
6459//============================================================
6560
r9718r9719
7065//  (does filling this out on non-Windows make any sense?)
7166//============================================================
7267
73static file_error error_to_file_error(UINT32 error)
68file_error error_to_file_error(UINT32 error)
7469{
7570   switch (error)
7671   {
r9718r9719
127122      goto error;
128123   }
129124
125   if (strlen(sdlfile_socket_identifier) > 0 && strncmp(path, sdlfile_socket_identifier, strlen(sdlfile_socket_identifier)) == 0)
126   {
127      (*file)->type = SDLFILE_SOCKET;
128      filerr = sdl_open_socket(path, openflags, file, filesize);
129      goto error;
130   }
131
132   if (strlen(sdlfile_ptty_identifier) > 0 && strncmp(path, sdlfile_ptty_identifier, strlen(sdlfile_ptty_identifier)) == 0)
133   {
134      (*file)->type = SDLFILE_PTTY;
135      filerr = sdl_open_ptty(path, openflags, file, filesize);
136      goto error;
137   }
138
139   (*file)->type = SDLFILE_FILE;
140           
130141   // convert the path into something compatible
131142   dst = (*file)->filename;
132143   for (src = path; *src != 0; src++)
r9718r9719
264275file_error osd_read(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
265276{
266277   ssize_t result;
267
278   
279   switch (file->type)
280   {
281      case SDLFILE_FILE:
268282#if defined(SDLMAME_DARWIN) || defined(SDLMAME_BSD)
269   result = pread(file->handle, buffer, count, offset);
270   if (result < 0)
283         result = pread(file->handle, buffer, count, offset);
284         if (result < 0)
271285#elif defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_OS2)
272   lseek(file->handle, (UINT32)offset&0xffffffff, SEEK_SET);
273   result = read(file->handle, buffer, count);
274   if (result < 0)
286         lseek(file->handle, (UINT32)offset&0xffffffff, SEEK_SET);
287         result = read(file->handle, buffer, count);
288         if (result < 0)
275289#elif defined(SDLMAME_UNIX)
276   result = pread64(file->handle, buffer, count, offset);
277   if (result < 0)
290         result = pread64(file->handle, buffer, count, offset);
291         if (result < 0)
278292#else
279293#error Unknown SDL SUBARCH!
280294#endif
281      return error_to_file_error(errno);
282   if (actual != NULL)
283      *actual = result;
284   return FILERR_NONE;
295            return error_to_file_error(errno);
296
297         if (actual != NULL)
298            *actual = result;
299
300         return FILERR_NONE;
301         break;
302         
303      case SDLFILE_SOCKET:
304         return sdl_read_socket(file, buffer, offset, count, actual);
305         break;
306         
307      case SDLFILE_PTTY:
308         return sdl_read_ptty(file, buffer, offset, count, actual);
309         break;
310     
311      default:
312         return FILERR_FAILURE;
313    }
285314}
286315
287316
r9718r9719
293322{
294323   UINT32 result;
295324
325   switch (file->type)
326   {
327      case SDLFILE_FILE:
296328#if defined(SDLMAME_DARWIN) || defined(SDLMAME_BSD)
297   result = pwrite(file->handle, buffer, count, offset);
298   if (!result)
329         result = pwrite(file->handle, buffer, count, offset);
330         if (!result)
299331#elif defined(SDLMAME_WIN32) || defined(SDLMAME_NO64BITIO) || defined(SDLMAME_OS2)
300   lseek(file->handle, (UINT32)offset&0xffffffff, SEEK_SET);
301   result = write(file->handle, buffer, count);
302   if (!result)
332         lseek(file->handle, (UINT32)offset&0xffffffff, SEEK_SET);
333         result = write(file->handle, buffer, count);
334         if (!result)
303335#elif defined(SDLMAME_UNIX)
304   result = pwrite64(file->handle, buffer, count, offset);
305   if (!result)
336         result = pwrite64(file->handle, buffer, count, offset);
337         if (!result)
306338#else
307339#error Unknown SDL SUBARCH!
308340#endif
309      return error_to_file_error(errno);
341         return error_to_file_error(errno);
310342
311   if (actual != NULL)
312      *actual = result;
313   return FILERR_NONE;
343         if (actual != NULL)
344            *actual = result;
345         return FILERR_NONE;
346         break;
347         
348      case SDLFILE_SOCKET:
349         return sdl_write_socket(file, buffer, offset, count, actual);
350         break;
351         
352      case SDLFILE_PTTY:
353         return sdl_write_ptty(file, buffer, offset, count, actual);
354         break;
355     
356      default:
357         return FILERR_FAILURE;
358    }
314359}
315360
316361
r9718r9719
321366file_error osd_close(osd_file *file)
322367{
323368   // close the file handle and free the file structure
324   close(file->handle);
325   osd_free(file);
326   return FILERR_NONE;
369   switch (file->type)
370   {
371      case SDLFILE_FILE:
372         close(file->handle);
373         osd_free(file);
374         return FILERR_NONE;
375         break;
376
377      case SDLFILE_SOCKET:
378         return sdl_close_socket(file);
379         break;
380         
381      case SDLFILE_PTTY:
382         return sdl_close_ptty(file);
383         break;
384     
385      default:
386         return FILERR_FAILURE;
387    }
327388}
328389
329390//============================================================
src/osd/sdl/sdlfile.h
r0r9719
1//============================================================
2//
3//  sdlfile.h - SDL file access functions
4//
5//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//============================================================
11 
12#include "osdcore.h"
13#include "sdlos.h"
14 
15//============================================================
16//  ENUM DEFINITIONS
17//============================================================
18enum
19{
20   SDLFILE_FILE = 0,
21   SDLFILE_SOCKET,
22   SDLFILE_PTTY
23};
24 
25//============================================================
26//  TYPE DEFINITIONS
27//============================================================
28 
29struct _osd_file
30{
31   int   handle;
32   int   type;
33   char   filename[1];
34};
35 
36//============================================================
37//  PROTOTYPES
38//============================================================
39 
40file_error sdl_open_socket(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize);
41file_error sdl_read_socket(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
42file_error sdl_write_socket(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
43file_error sdl_close_socket(osd_file *file);
44 
45file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize);
46file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
47file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual);
48file_error sdl_close_ptty(osd_file *file);
49 
50file_error error_to_file_error(UINT32 error);
src/osd/sdl/debugosx.m
r9718r9719
11441144      if (debug_cpu_get_visible_cpu(machine) == space->cpu) {
11451145         offs_t address = downcast<debug_view_disasm *>(view)->selected_address();
11461146         if (useConsole) {
1147            NSString *command = [NSString stringWithFormat:@"go %lX", (unsigned long)address];
1147            NSString *command = [NSString stringWithFormat:@"go 0x%lX", (unsigned long)address];
11481148            debug_console_execute_command(machine, [command UTF8String], 1);
11491149         } else {
11501150            debug_cpu_get_visible_cpu(machine)->debug()->go(address);
src/osd/sdl/drawogl.c
r9718r9719
12071207
12081208   // figure out if we're vector
12091209   scrnum = is_vector = 0;
1210   for (screen = screen_first(*window->machine->config); screen != NULL; screen = screen_next(screen))
1210   for (screen = window->machine->config->first_screen(); screen != NULL; screen = screen->next_screen())
12111211   {
12121212      if (scrnum == window->index)
12131213      {
r9718r9719
29442944
29452945      scrnum = 0;
29462946      container = (render_container *)NULL;
2947      for (screen_device *screen = screen_first(*window->machine); screen != NULL; screen = screen_next(screen))
2947      for (screen_device *screen = window->machine->first_screen(); screen != NULL; screen = screen->next_screen())
29482948      {
29492949         if (scrnum == window->start_viewscreen)
29502950         {
src/osd/sdl/sdlptty_win32.c
r0r9719
1//============================================================
2//
3//  sdlptty_win32 - SDL psuedo tty access functions
4//  (Win32 has no pttys - maybe named pipes?)
5//
6//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
7//  Visit http://mamedev.org for licensing and usage restrictions.
8//
9//  SDLMAME by Olivier Galibert and R. Belmont
10//
11//============================================================
12 
13#include "sdlfile.h"
14 
15const char *sdlfile_ptty_identifier  = "";
16 
17file_error sdl_open_ptty(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
18{
19   return FILERR_ACCESS_DENIED;
20}
21 
22file_error sdl_read_ptty(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
23{
24   return FILERR_ACCESS_DENIED;
25}
26 
27file_error sdl_write_ptty(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
28{
29   return FILERR_ACCESS_DENIED;
30}
31 
32file_error sdl_close_ptty(osd_file *file)
33{
34   return FILERR_ACCESS_DENIED;
35}
src/osd/sdl/sound.c
r9718r9719
130130//============================================================
131131//  lock_buffer
132132//============================================================
133static int lock_buffer(long offset, long size, void **buffer1, long *length1, void **buffer2, long *length2)
133static int lock_buffer(running_machine &machine, long offset, long size, void **buffer1, long *length1, void **buffer2, long *length2)
134134{
135135   volatile long pstart, pend, lstart, lend;
136136
137137   if (!buf_locked)
138138   {
139      if (video_get_throttle())
139      if (machine.video().throttled())
140140      {
141141         pstart = stream_playpos;
142142         pend = (pstart + sdl_xfer_samples);
r9718r9719
213213//  copy_sample_data
214214//============================================================
215215
216static void copy_sample_data(const INT16 *data, int bytes_to_copy)
216static void copy_sample_data(running_machine &machine, const INT16 *data, int bytes_to_copy)
217217{
218218   void *buffer1, *buffer2 = (void *)NULL;
219219   long length1, length2;
220220   int cur_bytes;
221221
222222   // attempt to lock the stream buffer
223   if (lock_buffer(stream_buffer_in, bytes_to_copy, &buffer1, &length1, &buffer2, &length2) < 0)
223   if (lock_buffer(machine, stream_buffer_in, bytes_to_copy, &buffer1, &length1, &buffer2, &length2) < 0)
224224   {
225225      buffer_underflows++;
226226      return;
r9718r9719
333333
334334      // now we know where to copy; let's do it
335335      stream_buffer_in = stream_in;
336      copy_sample_data(buffer, bytes_this_frame);
336      copy_sample_data(machine(), buffer, bytes_this_frame);
337337   }
338338}
339339
src/osd/sdl/debugwin.c
r9718r9719
11261126      if (debug_cpu_get_visible_cpu(info->machine) == disasm->view->source()->device())
11271127      {
11281128         offs_t address = downcast<debug_view_disasm *>(disasm->view)->selected_address();
1129         command.printf("go %X", address);
1129         command.printf("go 0x%X", address);
11301130         debug_console_execute_command(info->machine, command, 1);
11311131      }
11321132   }
src/osd/sdl/window.c
r9718r9719
10171017      view = defview;
10181018
10191019   // query the video system to help us pick a view
1020   viewindex = video_get_view_for_target(machine, window->target, view, index, video_config.numscreens);
1020   viewindex = window->target->configured_view(view, index, video_config.numscreens);
10211021
10221022   // set the view
10231023   window->target->set_view(viewindex);
src/osd/sdl/sdlsocket.c
r0r9719
1//============================================================
2//
3//  sdlsocket.c - SDL socket (inet) access functions
4//
5//  Copyright (c) 1996-2010, Nicola Salmoria and the MAME Team.
6//  Visit http://mamedev.org for licensing and usage restrictions.
7//
8//  SDLMAME by Olivier Galibert and R. Belmont
9//
10//============================================================
11 
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include <fcntl.h>
16#include <sys/select.h>
17#include <netinet/in.h>
18#include <netinet/tcp.h>
19#include <sys/socket.h>
20#include <sys/types.h>
21#include <netdb.h>
22#include <errno.h>
23 
24#include "emu.h"
25#include "sdlfile.h"
26 
27const char *sdlfile_socket_identifier  = "/dev/socket";
28 
29file_error sdl_open_socket(const char *path, UINT32 openflags, osd_file **file, UINT64 *filesize)
30{
31   char hostname[256];
32   struct hostent *localhost;
33   struct sockaddr_in sai;
34   int flag = 1;
35   int port;
36   
37   sscanf( path+strlen(sdlfile_socket_identifier), ":%255[^:]:%d", hostname, &port );
38       
39   printf("Connecting to server '%s' on port '%d'\n", hostname, port);
40   
41   if (((*file)->handle = socket(AF_INET, SOCK_STREAM, 0)) == -1)
42   {
43      return FILERR_ACCESS_DENIED;
44   }
45 
46   if (setsockopt((*file)->handle, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag)) == -1)
47   {
48      return FILERR_ACCESS_DENIED;
49   }
50 
51   localhost = gethostbyname(hostname);
52 
53   memset(&sai, 0, sizeof(sai));
54   sai.sin_family = AF_INET;
55   sai.sin_port = htons(port);
56   sai.sin_addr = *((struct in_addr *)localhost->h_addr);
57 
58   if (connect((*file)->handle, (struct sockaddr *)&sai, sizeof(struct sockaddr)) == -1)
59   {
60      return FILERR_ACCESS_DENIED;
61   }
62   
63   *filesize = 0;
64   
65   return FILERR_NONE;
66}
67 
68file_error sdl_read_socket(osd_file *file, void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
69{
70   ssize_t result;
71   char line[80];
72   struct timeval timeout;
73   fd_set readfds;
74 
75   FD_ZERO(&readfds);
76   FD_SET(file->handle, &readfds);
77   timeout.tv_sec = timeout.tv_usec = 0;
78 
79   if (select(file->handle + 1, &readfds, NULL, NULL, &timeout) < 0)
80   {
81      sprintf(line, "%s : %s : %d ", __func__, __FILE__,  __LINE__);
82      perror(line);
83      return error_to_file_error(errno);
84   }
85   else if (FD_ISSET(file->handle, &readfds))
86   {
87      result = read(file->handle, buffer, count);
88   }
89   else
90   {
91      return FILERR_FAILURE;
92   }
93 
94   if (result < 0)
95   {
96      return error_to_file_error(errno);
97   }
98 
99   if (actual != NULL )
100   {
101      *actual = result;
102   }
103 
104   return FILERR_NONE;
105}
106 
107file_error sdl_write_socket(osd_file *file, const void *buffer, UINT64 offset, UINT32 count, UINT32 *actual)
108{
109   UINT32 result;   
110 
111   result = write(file->handle, buffer, count);
112 
113   if (result < 0)
114   {
115      return error_to_file_error(errno);
116   }
117 
118   if (actual != NULL )
119   {
120      *actual = result;
121   }
122 
123   return FILERR_NONE;
124}
125 
126file_error sdl_close_socket(osd_file *file)
127{
128   close(file->handle);
129   osd_free(file);
130   return FILERR_NONE;
131}
src/osd/windows/drawdd.c
r9718r9719
457457   if (result != DD_OK) mame_printf_verbose("DirectDraw: Error %08X unlocking blit surface\n", (int)result);
458458
459459   // sync to VBLANK
460   if ((video_config.waitvsync || video_config.syncrefresh) && video_get_throttle() && (!window->fullscreen || dd->back == NULL))
460   if ((video_config.waitvsync || video_config.syncrefresh) && window->machine->video().throttled() && (!window->fullscreen || dd->back == NULL))
461461   {
462462      result = IDirectDraw7_WaitForVerticalBlank(dd->ddraw, DDWAITVB_BLOCKBEGIN, NULL);
463463      if (result != DD_OK) mame_printf_verbose("DirectDraw: Error %08X waiting for VBLANK\n", (int)result);
r9718r9719
13331333
13341334   // determine the refresh rate of the primary screen
13351335   einfo.target_refresh = 60.0;
1336   const screen_device_config *primary_screen = screen_first(*window->machine->config);
1336   const screen_device_config *primary_screen = window->machine->config->first_screen();
13371337   if (primary_screen != NULL)
13381338      einfo.target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh());
13391339   printf("Target refresh = %f\n", einfo.target_refresh);
src/osd/windows/window.c
r9718r9719
753753      mtlog_add("winwindow_video_window_update: try lock");
754754
755755      // only block if we're throttled
756      if (video_get_throttle() || timeGetTime() - last_update_time > 250)
756      if (window->machine->video().throttled() || timeGetTime() - last_update_time > 250)
757757         osd_lock_acquire(window->render_lock);
758758      else
759759         got_lock = osd_lock_try(window->render_lock);
r9718r9719
868868      view = defview;
869869
870870   // query the video system to help us pick a view
871   viewindex = video_get_view_for_target(window->machine, window->target, view, index, video_config.numscreens);
871   viewindex = window->target->configured_view(view, index, video_config.numscreens);
872872
873873   // set the view
874874   window->target->set_view(viewindex);
src/osd/windows/drawd3d.c
r9718r9719
12831283   int modenum;
12841284
12851285   // determine the refresh rate of the primary screen
1286   const screen_device_config *primary_screen = screen_first(*window->machine->config);
1286   const screen_device_config *primary_screen = window->machine->config->first_screen();
12871287   if (primary_screen != NULL)
12881288      target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh());
12891289
src/osd/winui/mui_util.c
r9718r9719
320320
321321BOOL isDriverVector(const machine_config *config)
322322{
323   const screen_device_config *screen  = screen_first(*config);
323   const screen_device_config *screen  = config->first_screen();
324324
325325   if (screen != NULL) {
326326      // parse "vector.ini" for vector games
r9718r9719
334334
335335int numberOfScreens(const machine_config *config)
336336{
337   const screen_device_config *screen  = screen_first(*config);
337   const screen_device_config *screen  = config->first_screen();
338338   int i=0;
339   for (; screen != NULL; screen = screen_next(screen)) {
339   for (; screen != NULL; screen = screen->next_screen()) {
340340      i++;
341341   }
342342   return i;   
src/osd/winui/properties.c
r9718r9719
713713   }
714714   else
715715   {
716      const screen_device_config *screen = screen_first(config);
716      const screen_device_config *screen = config.first_screen();
717717      if (screen == NULL) {
718718         strcpy(buf, "Screenless Game");
719719      }
720720      else {
721         for (; screen != NULL; screen = screen_next(screen)) {
721         for (; screen != NULL; screen = screen->next_screen()) {
722722            char tmpbuf[256];
723723            const rectangle &visarea = screen->visible_area();
724724
src/emu/debug/debugcpu.c
r9718r9719
142142
143143void debug_cpu_init(running_machine *machine)
144144{
145   screen_device *first_screen = screen_first(*machine);
145   screen_device *first_screen = machine->first_screen();
146146   debugcpu_private *global;
147147   int regnum;
148148
src/emu/debug/debugcmd.c
r9718r9719
24182418   /* if no params, use the default behavior */
24192419   if (params == 0)
24202420   {
2421      video_save_active_screen_snapshots(machine);
2421      machine->video().save_active_screen_snapshots();
24222422      debug_console_printf(machine, "Saved snapshot\n");
24232423   }
24242424
r9718r9719
24492449         return;
24502450      }
24512451
2452      screen_save_snapshot(screen->machine, screen, fp);
2452      screen->machine->video().save_snapshot(screen, *fp);
24532453      mame_fclose(fp);
24542454      debug_console_printf(machine, "Saved screen #%d snapshot as '%s'\n", scrnum, filename);
24552455   }
src/emu/video/tms9928a.c
r9718r9719
435435    int b;
436436
437437    /* when skipping frames, calculate sprite collision */
438    if (video_skip_this_frame() ) {
438    if (machine->video().skip_this_frame()) {
439439      if (TMS_SPRITES_ENABLED) {
440440         draw_sprites (machine->primary_screen, NULL, NULL);
441441      }
src/emu/video.c
r9718r9719
3939
4040#include "emu.h"
4141#include "emuopts.h"
42#include "profiler.h"
4342#include "png.h"
4443#include "debugger.h"
4544#include "debugint/debugint.h"
46#include "rendutil.h"
4745#include "ui.h"
4846#include "aviio.h"
4947#include "crsshair.h"
r9718r9719
5250
5351
5452
55/***************************************************************************
56    DEBUGGING
57***************************************************************************/
53//**************************************************************************
54//  DEBUGGING
55//**************************************************************************
5856
5957#define LOG_THROTTLE            (0)
60#define VERBOSE                  (0)
61#define LOG_PARTIAL_UPDATES(x)      do { if (VERBOSE) logerror x; } while (0)
6258
6359
6460
65/***************************************************************************
66    CONSTANTS
67***************************************************************************/
61//**************************************************************************
62//  GLOBAL VARIABLES
63//**************************************************************************
6864
69#define SUBSECONDS_PER_SPEED_UPDATE   (ATTOSECONDS_PER_SECOND / 4)
70#define PAUSED_REFRESH_RATE         (30)
71
72
73
74/***************************************************************************
75    DEVICE DEFINITIONS
76***************************************************************************/
77
78const device_type SCREEN = screen_device_config::static_alloc_device_config;
79
80
81
82/***************************************************************************
83    TYPE DEFINITIONS
84***************************************************************************/
85
86typedef struct _video_global video_global;
87struct _video_global
65// frameskipping tables
66const UINT8 video_manager::s_skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] =
8867{
89   /* screenless systems */
90   emu_timer *            screenless_frame_timer;   /* timer to signal VBLANK start */
91
92   /* throttling calculations */
93   osd_ticks_t            throttle_last_ticks;   /* osd_ticks the last call to throttle */
94   attotime            throttle_realtime;      /* real time the last call to throttle */
95   attotime            throttle_emutime;      /* emulated time the last call to throttle */
96   UINT32               throttle_history;      /* history of frames where we were fast enough */
97
98   /* dynamic speed computation */
99   osd_ticks_t          speed_last_realtime;   /* real time at the last speed calculation */
100   attotime            speed_last_emutime;      /* emulated time at the last speed calculation */
101   double               speed_percent;         /* most recent speed percentage */
102   UINT32               partial_updates_this_frame;/* partial update counter this frame */
103
104   /* overall speed computation */
105   UINT32               overall_real_seconds;   /* accumulated real seconds at normal speed */
106   osd_ticks_t            overall_real_ticks;      /* accumulated real ticks at normal speed */
107   attotime            overall_emutime;      /* accumulated emulated time at normal speed */
108   UINT32               overall_valid_counter;   /* number of consecutive valid time periods */
109
110   /* configuration */
111   UINT8               throttle;            /* flag: TRUE if we're currently throttled */
112   UINT8               fastforward;         /* flag: TRUE if we're currently fast-forwarding */
113   UINT32               seconds_to_run;         /* number of seconds to run before quitting */
114   UINT8               auto_frameskip;         /* flag: TRUE if we're automatically frameskipping */
115   UINT32               speed;               /* overall speed (*100) */
116
117   /* frameskipping */
118   UINT8               empty_skip_count;      /* number of empty frames we have skipped */
119   UINT8               frameskip_level;      /* current frameskip level */
120   UINT8               frameskip_counter;      /* counter that counts through the frameskip steps */
121   INT8               frameskip_adjust;
122   UINT8               skipping_this_frame;   /* flag: TRUE if we are skipping the current frame */
123   osd_ticks_t            average_oversleep;      /* average number of ticks the OSD oversleeps */
124
125   /* snapshot stuff */
126   render_target *         snap_target;         /* screen shapshot target */
127   bitmap_t *            snap_bitmap;         /* screen snapshot bitmap */
128   UINT8               snap_native;         /* are we using native per-screen layouts? */
129   INT32               snap_width;            /* width of snapshots (0 == auto) */
130   INT32               snap_height;         /* height of snapshots (0 == auto) */
131
132   /* movie recording */
133   mame_file *            mngfile;            /* handle to the open movie file */
134   avi_file *            avifile;            /* handle to the open movie file */
135   attotime            movie_frame_period;      /* period of a single movie frame */
136   attotime            movie_next_frame_time;   /* time of next frame */
137   UINT32               movie_frame;         /* current movie frame number */
138};
139
140
141
142/***************************************************************************
143    GLOBAL VARIABLES
144***************************************************************************/
145
146/* global state */
147static video_global global;
148
149/* frameskipping tables */
150static const UINT8 skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS] =
151{
15268   { 0,0,0,0,0,0,0,0,0,0,0,0 },
15369   { 0,0,0,0,0,0,0,0,0,0,0,1 },
15470   { 0,0,0,0,0,1,0,0,0,0,0,1 },
r9718r9719
16581
16682
16783
168/***************************************************************************
169    FUNCTION PROTOTYPES
170***************************************************************************/
84//**************************************************************************
85//  FUNCTION PROTOTYPES
86//**************************************************************************
17187
172/* core implementation */
173static void video_exit(running_machine &machine);
174static void init_buffered_spriteram(running_machine *machine);
88// software rendering
89static void rgb888_draw_primitives(const render_primitive_list &primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch);
17590
176/* global rendering */
177static int finish_screen_updates(running_machine *machine);
178static TIMER_CALLBACK( screenless_update_callback );
17991
180/* throttling/frameskipping/performance */
181static void update_throttle(running_machine *machine, attotime emutime);
182static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t target_ticks);
183static void update_frameskip(running_machine *machine);
184static void recompute_speed(running_machine *machine, attotime emutime);
185static void update_refresh_speed(running_machine *machine);
18692
187/* screen snapshots */
188static void create_snapshot_bitmap(device_t *screen);
189static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file);
93//**************************************************************************
94//  VIDEO MANAGER
95//**************************************************************************
19096
191/* movie recording */
192static void video_mng_record_frame(running_machine *machine);
193static void video_avi_record_frame(running_machine *machine);
97//-------------------------------------------------
98//  video_manager - constructor
99//-------------------------------------------------
194100
195/* software rendering */
196static void rgb888_draw_primitives(const render_primitive_list &primlist, void *dstdata, UINT32 width, UINT32 height, UINT32 pitch);
101video_manager::video_manager(running_machine &machine)
102   : m_machine(machine),
103     m_screenless_frame_timer(NULL),
104     m_throttle_last_ticks(0),
105     m_throttle_realtime(attotime_zero),
106     m_throttle_emutime(attotime_zero),
107     m_throttle_history(0),
108     m_speed_last_realtime(0),
109     m_speed_last_emutime(attotime_zero),
110     m_speed_percent(1.0),
111     m_overall_real_seconds(0),
112     m_overall_real_ticks(0),
113     m_overall_emutime(attotime_zero),
114     m_overall_valid_counter(0),
115     m_throttle(options_get_bool(machine.options(), OPTION_THROTTLE)),
116     m_fastforward(false),
117     m_seconds_to_run(options_get_int(machine.options(), OPTION_SECONDS_TO_RUN)),
118     m_auto_frameskip(options_get_bool(machine.options(), OPTION_AUTOFRAMESKIP)),
119     m_speed(original_speed_setting()),
120     m_empty_skip_count(0),
121     m_frameskip_level(options_get_int(machine.options(), OPTION_FRAMESKIP)),
122     m_frameskip_counter(0),
123     m_frameskip_adjust(0),
124     m_skipping_this_frame(false),
125     m_average_oversleep(0),
126     m_snap_target(NULL),
127     m_snap_bitmap(NULL),
128     m_snap_native(true),
129     m_snap_width(0),
130     m_snap_height(0),
131     m_mngfile(NULL),
132     m_avifile(NULL),
133     m_movie_frame_period(attotime_zero),
134     m_movie_next_frame_time(attotime_zero),
135     m_movie_frame(0)
136{
137   // request a callback upon exiting
138   machine.add_notifier(MACHINE_NOTIFY_EXIT, exit_static);
139   state_save_register_postload(&machine, state_postload_stub<video_manager, &video_manager::postload>, this);
197140
141   // extract initial execution state from global configuration settings
142   update_refresh_speed();
198143
144   // create spriteram buffers if necessary
145   if (machine.config->m_video_attributes & VIDEO_BUFFERS_SPRITERAM)
146      init_buffered_spriteram();
199147
200/***************************************************************************
201    INLINE FUNCTIONS
202***************************************************************************/
148   // create a render target for snapshots
149   const char *viewname = options_get_string(machine.options(), OPTION_SNAPVIEW);
150   m_snap_native = (machine.primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0));
203151
204/*-------------------------------------------------
205    effective_autoframeskip - return the effective
206    autoframeskip value, accounting for fast
207    forward
208-------------------------------------------------*/
152   // the native target is hard-coded to our internal layout and has all options disabled
153   if (m_snap_native)
154   {
155      m_snap_target = machine.render().target_alloc(layout_snap, RENDER_CREATE_SINGLE_FILE | RENDER_CREATE_HIDDEN);
156      m_snap_target->set_backdrops_enabled(false);
157      m_snap_target->set_overlays_enabled(false);
158      m_snap_target->set_bezels_enabled(false);
159      m_snap_target->set_screen_overlay_enabled(false);
160      m_snap_target->set_zoom_to_screen(false);
161   }
209162
210INLINE int effective_autoframeskip(running_machine *machine)
211{
212   /* if we're fast forwarding or paused, autoframeskip is disabled */
213   if (global.fastforward || machine->paused())
214      return FALSE;
163   // other targets select the specified view and turn off effects
164   else
165   {
166      m_snap_target = machine.render().target_alloc(NULL, RENDER_CREATE_HIDDEN);
167      m_snap_target->set_view(m_snap_target->configured_view(viewname, 0, 1));
168      m_snap_target->set_screen_overlay_enabled(false);
169   }
215170
216   /* otherwise, it's up to the user */
217   return global.auto_frameskip;
218}
171   // extract snap resolution if present
172   if (sscanf(options_get_string(machine.options(), OPTION_SNAPSIZE), "%dx%d", &m_snap_width, &m_snap_height) != 2)
173      m_snap_width = m_snap_height = 0;
219174
175   // start recording movie if specified
176   const char *filename = options_get_string(machine.options(), OPTION_MNGWRITE);
177   if (filename[0] != 0)
178      begin_recording(filename, MF_MNG);
220179
221/*-------------------------------------------------
222    effective_frameskip - return the effective
223    frameskip value, accounting for fast
224    forward
225-------------------------------------------------*/
180   filename = options_get_string(machine.options(), OPTION_AVIWRITE);
181   if (filename[0] != 0)
182      begin_recording(filename, MF_AVI);
226183
227INLINE int effective_frameskip(void)
228{
229   /* if we're fast forwarding, use the maximum frameskip */
230   if (global.fastforward)
231      return FRAMESKIP_LEVELS - 1;
232
233   /* otherwise, it's up to the user */
234   return global.frameskip_level;
184   // if no screens, create a periodic timer to drive updates
185   if (machine.primary_screen == NULL)
186   {
187      m_screenless_frame_timer = timer_alloc(&machine, &screenless_update_callback, this);
188      timer_adjust_periodic(m_screenless_frame_timer, screen_device::DEFAULT_FRAME_PERIOD, 0, screen_device::DEFAULT_FRAME_PERIOD);
189   }
235190}
236191
237192
238/*-------------------------------------------------
239    effective_throttle - return the effective
240    throttle value, accounting for fast
241    forward and user interface
242-------------------------------------------------*/
193//-------------------------------------------------
194//  set_frameskip - set the current actual
195//  frameskip (-1 means autoframeskip)
196//-------------------------------------------------
243197
244INLINE int effective_throttle(running_machine *machine)
198void video_manager::set_frameskip(int frameskip)
245199{
246   /* if we're paused, or if the UI is active, we always throttle */
247   if (machine->paused() || ui_is_menu_active())
248      return TRUE;
200   // -1 means autoframeskip
201   if (frameskip == -1)
202   {
203      m_auto_frameskip = true;
204      m_frameskip_level = 0;
205   }
249206
250   /* if we're fast forwarding, we don't throttle */
251   if (global.fastforward)
252      return FALSE;
253
254   /* otherwise, it's up to the user */
255   return global.throttle;
207   // any other level is a direct control
208   else if (frameskip >= 0 && frameskip <= MAX_FRAMESKIP)
209   {
210      m_auto_frameskip = false;
211      m_frameskip_level = frameskip;
212   }
256213}
257214
258215
259/*-------------------------------------------------
260    original_speed_setting - return the original
261    speed setting
262-------------------------------------------------*/
216//-------------------------------------------------
217//  frame_update - handle frameskipping and UI,
218//  plus updating the screen during normal
219//  operations
220//-------------------------------------------------
263221
264INLINE int original_speed_setting(void)
222void video_manager::frame_update(bool debug)
265223{
266   return options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5;
267}
224   // only render sound and video if we're in the running phase
225   int phase = m_machine.phase();
226   bool skipped_it = m_skipping_this_frame;
227   if (phase == MACHINE_PHASE_RUNNING && (!m_machine.paused() || options_get_bool(m_machine.options(), OPTION_UPDATEINPAUSE)))
228   {
229      bool anything_changed = finish_screen_updates();
268230
231      // if none of the screens changed and we haven't skipped too many frames in a row,
232        // mark this frame as skipped to prevent throttling; this helps for games that
233        // don't update their screen at the monitor refresh rate
234      if (!anything_changed && !m_auto_frameskip && m_frameskip_level == 0 && m_empty_skip_count++ < 3)
235         skipped_it = true;
236      else
237         m_empty_skip_count = 0;
238   }
269239
240   // draw the user interface
241   ui_update_and_render(&m_machine, &m_machine.render().ui_container());
270242
271/***************************************************************************
272    CORE IMPLEMENTATION
273***************************************************************************/
243   // update the internal render debugger
244   debugint_update_during_game(&m_machine);
274245
275/*-------------------------------------------------
276    video_init - start up the video system
277-------------------------------------------------*/
246   // if we're throttling, synchronize before rendering
247   attotime current_time = timer_get_time(&m_machine);
248   if (!debug && !skipped_it && effective_throttle())
249      update_throttle(current_time);
278250
279void video_init(running_machine *machine)
280{
281   const char *filename;
282   const char *viewname;
251   // ask the OSD to update
252   g_profiler.start(PROFILER_BLIT);
253   m_machine.osd().update(!debug && skipped_it);
254   g_profiler.stop();
283255
284   /* validate */
285   assert(machine != NULL);
286   assert(machine->config != NULL);
256   // perform tasks for this frame
257   if (!debug)
258      m_machine.call_notifiers(MACHINE_NOTIFY_FRAME);
287259
288   /* request a callback upon exiting */
289   machine->add_notifier(MACHINE_NOTIFY_EXIT, video_exit);
260   // update frameskipping
261   if (!debug)
262      update_frameskip();
290263
291   /* reset our global state */
292   memset(&global, 0, sizeof(global));
293   global.speed_percent = 1.0;
264   // update speed computations
265   if (!debug && !skipped_it)
266      recompute_speed(current_time);
294267
295   /* extract initial execution state from global configuration settings */
296   global.speed = original_speed_setting();
297   update_refresh_speed(machine);
298   global.throttle = options_get_bool(machine->options(), OPTION_THROTTLE);
299   global.auto_frameskip = options_get_bool(machine->options(), OPTION_AUTOFRAMESKIP);
300   global.frameskip_level = options_get_int(machine->options(), OPTION_FRAMESKIP);
301   global.seconds_to_run = options_get_int(machine->options(), OPTION_SECONDS_TO_RUN);
302
303   /* create spriteram buffers if necessary */
304   if (machine->config->m_video_attributes & VIDEO_BUFFERS_SPRITERAM)
305      init_buffered_spriteram(machine);
306
307   /* create a render target for snapshots */
308   viewname = options_get_string(machine->options(), OPTION_SNAPVIEW);
309   global.snap_native = (machine->primary_screen != NULL && (viewname[0] == 0 || strcmp(viewname, "native") == 0));
310
311   /* the native target is hard-coded to our internal layout and has all options disabled */
312   if (global.snap_native)
268   // call the end-of-frame callback
269   if (phase == MACHINE_PHASE_RUNNING)
313270   {
314      global.snap_target = machine->render().target_alloc(layout_snap, RENDER_CREATE_SINGLE_FILE | RENDER_CREATE_HIDDEN);
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);
320   }
271      // reset partial updates if we're paused or if the debugger is active
272      if (m_machine.primary_screen != NULL && (m_machine.paused() || debug || debugger_within_instruction_hook(&m_machine)))
273         m_machine.primary_screen->scanline0_callback();
321274
322   /* other targets select the specified view and turn off effects */
323   else
324   {
325      global.snap_target = machine->render().target_alloc(NULL, RENDER_CREATE_HIDDEN);
326      global.snap_target->set_view(video_get_view_for_target(machine, global.snap_target, viewname, 0, 1));
327      global.snap_target->set_screen_overlay_enabled(false);
275      // otherwise, call the video EOF callback
276      else
277      {
278         g_profiler.start(PROFILER_VIDEO);
279         m_machine.driver_data<driver_device>()->video_eof();
280         g_profiler.stop();
281      }
328282   }
283}
329284
330   /* extract snap resolution if present */
331   if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &global.snap_width, &global.snap_height) != 2)
332      global.snap_width = global.snap_height = 0;
333285
334   /* start recording movie if specified */
335   filename = options_get_string(machine->options(), OPTION_MNGWRITE);
336   if (filename[0] != 0)
337      video_mng_begin_recording(machine, filename);
286//-------------------------------------------------
287//  speed_text - print the text to be displayed
288//  into a string buffer
289//-------------------------------------------------
338290
339   filename = options_get_string(machine->options(), OPTION_AVIWRITE);
340   if (filename[0] != 0)
341      video_avi_begin_recording(machine, filename);
291astring &video_manager::speed_text(astring &string)
292{
293   string.reset();
342294
343   /* if no screens, create a periodic timer to drive updates */
344   if (machine->primary_screen == NULL)
345   {
346      global.screenless_frame_timer = timer_alloc(machine, screenless_update_callback, NULL);
347      timer_adjust_periodic(global.screenless_frame_timer, screen_device::k_default_frame_period, 0, screen_device::k_default_frame_period);
348   }
349}
295   // if we're paused, just display Paused
296   bool paused = m_machine.paused();
297   if (paused)
298      string.cat("paused");
350299
300   // if we're fast forwarding, just display Fast-forward
301   else if (m_fastforward)
302      string.cat("fast ");
351303
352/*-------------------------------------------------
353    video_exit - close down the video system
354-------------------------------------------------*/
304   // if we're auto frameskipping, display that plus the level
305   else if (effective_autoframeskip())
306      string.catprintf("auto%2d/%d", effective_frameskip(), MAX_FRAMESKIP);
355307
356static void video_exit(running_machine &machine)
357{
358   int i;
308   // otherwise, just display the frameskip plus the level
309   else
310      string.catprintf("skip %d/%d", effective_frameskip(), MAX_FRAMESKIP);
359311
360   /* stop recording any movie */
361   video_mng_end_recording(&machine);
362   video_avi_end_recording(&machine);
312   // append the speed for all cases except paused
313   if (!paused)
314      string.catprintf("%4d%%", (int)(100 * m_speed_percent + 0.5));
363315
364   /* free all the graphics elements */
365   for (i = 0; i < MAX_GFX_ELEMENTS; i++)
366      gfx_element_free(machine.gfx[i]);
316   // display the number of partial updates as well
317   int partials = 0;
318   for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
319      partials += screen->partial_updates();
320   if (partials > 1)
321      string.catprintf("\n%d partial updates", partials);
367322
368   /* free the snapshot target */
369   machine.render().target_free(global.snap_target);
370   if (global.snap_bitmap != NULL)
371      global_free(global.snap_bitmap);
372
373   /* print a final result if we have at least 5 seconds' worth of data */
374   if (global.overall_emutime.seconds >= 5)
375   {
376      osd_ticks_t tps = osd_ticks_per_second();
377      double final_real_time = (double)global.overall_real_seconds + (double)global.overall_real_ticks / (double)tps;
378      double final_emu_time = attotime_to_double(global.overall_emutime);
379      mame_printf_info("Average speed: %.2f%% (%d seconds)\n", 100 * final_emu_time / final_real_time, attotime_add_attoseconds(global.overall_emutime, ATTOSECONDS_PER_SECOND / 2).seconds);
380   }
323   return string;
381324}
382325
383326
384/*-------------------------------------------------
385    init_buffered_spriteram - initialize the
386    double-buffered spriteram
387-------------------------------------------------*/
327//-------------------------------------------------
328//  save_snapshot - save a snapshot to the given
329//  file handle
330//-------------------------------------------------
388331
389static void init_buffered_spriteram(running_machine *machine)
332void video_manager::save_snapshot(screen_device *screen, mame_file &fp)
390333{
391   assert_always(machine->generic.spriteram_size != 0, "Video buffers spriteram but spriteram size is 0");
334   // validate
335   assert(!m_snap_native || screen != NULL);
392336
393   /* allocate memory for the back buffer */
394   machine->generic.buffered_spriteram.u8 = auto_alloc_array(machine, UINT8, machine->generic.spriteram_size);
337   // create the bitmap to pass in
338   create_snapshot_bitmap(screen);
395339
396   /* register for saving it */
397   state_save_register_global_pointer(machine, machine->generic.buffered_spriteram.u8, machine->generic.spriteram_size);
340   // add two text entries describing the image
341   astring text1(APPNAME, " ", build_version);
342   astring text2(m_machine.m_game.manufacturer, " ", m_machine.m_game.description);
343   png_info pnginfo = { 0 };
344   png_add_text(&pnginfo, "Software", text1);
345   png_add_text(&pnginfo, "System", text2);
398346
399   /* do the same for the second back buffer, if present */
400   if (machine->generic.spriteram2_size)
401   {
402      /* allocate memory */
403      machine->generic.buffered_spriteram2.u8 = auto_alloc_array(machine, UINT8, machine->generic.spriteram2_size);
347   // now do the actual work
348   const rgb_t *palette = (m_machine.palette != NULL) ? palette_entry_list_adjusted(m_machine.palette) : NULL;
349   png_error error = png_write_bitmap(mame_core_file(&fp), &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette);
350   if (error != PNGERR_NONE)
351      mame_printf_error("Error generating PNG for snapshot: png_error = %d\n", error);
404352
405      /* register for saving it */
406      state_save_register_global_pointer(machine, machine->generic.buffered_spriteram2.u8, machine->generic.spriteram2_size);
407   }
353   // free any data allocated
354   png_free(&pnginfo);
408355}
409356
410357
358//-------------------------------------------------
359//  save_active_screen_snapshots - save a
360//  snapshot of all active screens
361//-------------------------------------------------
411362
412/***************************************************************************
413    SCREEN MANAGEMENT
414***************************************************************************/
415
416/*-------------------------------------------------
417    screenless_update_callback - update generator
418    when there are no screens to drive it
419-------------------------------------------------*/
420
421static TIMER_CALLBACK( screenless_update_callback )
363void video_manager::save_active_screen_snapshots()
422364{
423   /* force an update */
424   video_frame_update(machine, false);
365   // if we're native, then write one snapshot per visible screen
366   if (m_snap_native)
367   {
368      // write one snapshot per visible screen
369      for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
370         if (m_machine.render().is_live(*screen))
371         {
372            mame_file *fp;
373            file_error filerr = mame_fopen_next(SEARCHPATH_SCREENSHOT, "png", fp);
374            if (filerr == FILERR_NONE)
375            {
376               save_snapshot(screen, *fp);
377               mame_fclose(fp);
378            }
379         }
380   }
381
382   // otherwise, just write a single snapshot
383   else
384   {
385      mame_file *fp;
386      file_error filerr = mame_fopen_next(SEARCHPATH_SCREENSHOT, "png", fp);
387      if (filerr == FILERR_NONE)
388      {
389         save_snapshot(NULL, *fp);
390         mame_fclose(fp);
391      }
392   }
425393}
426394
427395
428/*-------------------------------------------------
429    video_frame_update - handle frameskipping and
430    UI, plus updating the screen during normal
431    operations
432-------------------------------------------------*/
396//-------------------------------------------------
397//  begin_recording - begin recording of a movie
398//-------------------------------------------------
433399
434void video_frame_update(running_machine *machine, int debug)
400void video_manager::begin_recording(const char *name, movie_format format)
435401{
436   attotime current_time = timer_get_time(machine);
437   int skipped_it = global.skipping_this_frame;
438   int phase = machine->phase();
402   // stop any existign recording
403   end_recording();
439404
440   /* validate */
441   assert(machine != NULL);
442   assert(machine->config != NULL);
405   // create a snapshot bitmap so we know what the target size is
406   create_snapshot_bitmap(NULL);
443407
444   /* only render sound and video if we're in the running phase */
445   if (phase == MACHINE_PHASE_RUNNING && (!machine->paused() || options_get_bool(machine->options(), OPTION_UPDATEINPAUSE)))
408   // reset the state
409   m_movie_frame = 0;
410   m_movie_next_frame_time = timer_get_time(&m_machine);
411
412   // start up an AVI recording
413   if (format == MF_AVI)
446414   {
447      int anything_changed = finish_screen_updates(machine);
415      // build up information about this new movie
416      avi_movie_info info;
417      info.video_format = 0;
418      info.video_timescale = 1000 * ((m_machine.primary_screen != NULL) ? ATTOSECONDS_TO_HZ(m_machine.primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE);
419      info.video_sampletime = 1000;
420      info.video_numsamples = 0;
421      info.video_width = m_snap_bitmap->width;
422      info.video_height = m_snap_bitmap->height;
423      info.video_depth = 24;
448424
449      /* if none of the screens changed and we haven't skipped too many frames in a row,
450           mark this frame as skipped to prevent throttling; this helps for games that
451           don't update their screen at the monitor refresh rate */
452      if (!anything_changed && !global.auto_frameskip && global.frameskip_level == 0 && global.empty_skip_count++ < 3)
453         skipped_it = TRUE;
425      info.audio_format = 0;
426      info.audio_timescale = m_machine.sample_rate;
427      info.audio_sampletime = 1;
428      info.audio_numsamples = 0;
429      info.audio_channels = 2;
430      info.audio_samplebits = 16;
431      info.audio_samplerate = m_machine.sample_rate;
432
433      // create a new temporary movie file
434      mame_file *tempfile;
435      file_error filerr;
436      if (name != NULL)
437         filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &tempfile);
454438      else
455         global.empty_skip_count = 0;
456   }
439         filerr = mame_fopen_next(SEARCHPATH_MOVIE, "avi", tempfile);
457440
458   /* draw the user interface */
459   ui_update_and_render(machine, &machine->render().ui_container());
441      // compute the frame time
442      m_movie_frame_period = attotime_div(ATTOTIME_IN_SEC(1000), info.video_timescale);
460443
461   /* update the internal render debugger */
462   debugint_update_during_game(machine);
444      // if we succeeded, make a copy of the name and create the real file over top
445      if (filerr == FILERR_NONE)
446      {
447         astring fullname(mame_file_full_name(tempfile));
448         mame_fclose(tempfile);
463449
464   /* if we're throttling, synchronize before rendering */
465   if (!debug && !skipped_it && effective_throttle(machine))
466      update_throttle(machine, current_time);
450         // create the file and free the string
451         avi_error avierr = avi_create(fullname, &info, &m_avifile);
452         if (avierr != AVIERR_NONE)
453            mame_printf_error("Error creating AVI: %s\n", avi_error_string(avierr));
454      }
455   }
456   
457   // start up a MNG recording
458   else if (format == MF_MNG)
459   {
460      // create a new movie file and start recording
461      file_error filerr;
462      if (name != NULL)
463         filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &m_mngfile);
464      else
465         filerr = mame_fopen_next(SEARCHPATH_MOVIE, "mng", m_mngfile);
467466
468   /* ask the OSD to update */
469   g_profiler.start(PROFILER_BLIT);
470   machine->osd().update(!debug && skipped_it);
471   g_profiler.stop();
467      // start the capture
468      int rate = (m_machine.primary_screen != NULL) ? ATTOSECONDS_TO_HZ(m_machine.primary_screen->frame_period().attoseconds) : screen_device::DEFAULT_FRAME_RATE;
469      png_error pngerr = mng_capture_start(mame_core_file(m_mngfile), m_snap_bitmap, rate);
470      if (pngerr != PNGERR_NONE)
471         return end_recording();
472472
473   /* perform tasks for this frame */
474   if (!debug)
475      machine->call_notifiers(MACHINE_NOTIFY_FRAME);
473      // compute the frame time
474      m_movie_frame_period = ATTOTIME_IN_HZ(rate);
475   }
476}
476477
477   /* update frameskipping */
478   if (!debug)
479      update_frameskip(machine);
480478
481   /* update speed computations */
482   if (!debug && !skipped_it)
483      recompute_speed(machine, current_time);
479//-------------------------------------------------
480//  end_recording - stop recording of a movie
481//-------------------------------------------------
484482
485   /* call the end-of-frame callback */
486   if (phase == MACHINE_PHASE_RUNNING)
483void video_manager::end_recording()
484{
485   // close the file if it exists
486   if (m_avifile != NULL)
487487   {
488      /* reset partial updates if we're paused or if the debugger is active */
489      if (machine->primary_screen != NULL && (machine->paused() || debug || debugger_within_instruction_hook(machine)))
490         machine->primary_screen->scanline0_callback();
488      avi_close(m_avifile);
489      m_avifile = NULL;
490   }
491491
492      /* otherwise, call the video EOF callback */
493      else
494      {
495         g_profiler.start(PROFILER_VIDEO);
496         machine->driver_data<driver_device>()->video_eof();
497         g_profiler.stop();
498      }
492   // close the file if it exists
493   if (m_mngfile != NULL)
494   {
495      mng_capture_stop(mame_core_file(m_mngfile));
496      mame_fclose(m_mngfile);
497      m_mngfile = NULL;
499498   }
499
500   // reset the state
501   m_movie_frame = 0;
500502}
501503
502504
503/*-------------------------------------------------
504    finish_screen_updates - finish updating all
505    the screens
506-------------------------------------------------*/
505//-------------------------------------------------
506//  add_sound_to_recording - add sound to a movie
507//  recording
508//-------------------------------------------------
507509
508static int finish_screen_updates(running_machine *machine)
510void video_manager::add_sound_to_recording(const INT16 *sound, int numsamples)
509511{
510   bool anything_changed = false;
511
512   /* finish updating the screens */
513   for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
514      screen->update_partial(screen->visible_area().max_y);
515
516   /* now add the quads for all the screens */
517   for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
518      if (screen->update_quads())
519         anything_changed = true;
520
521   /* update our movie recording and burn-in state */
522   if (!machine->paused())
512   // only record if we have a file
513   if (m_avifile != NULL)
523514   {
524      video_mng_record_frame(machine);
525      video_avi_record_frame(machine);
515      g_profiler.start(PROFILER_MOVIE_REC);
526516
527      /* iterate over screens and update the burnin for the ones that care */
528      for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
529         screen->update_burnin();
530   }
517      // write the next frame
518      avi_error avierr = avi_append_sound_samples(m_avifile, 0, sound + 0, numsamples, 1);
519      if (avierr == AVIERR_NONE)
520         avierr = avi_append_sound_samples(m_avifile, 1, sound + 1, numsamples, 1);
521      if (avierr != AVIERR_NONE)
522         end_recording();
531523
532   /* draw any crosshairs */
533   for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
534      crosshair_render(*screen);
535
536   return anything_changed;
524      g_profiler.stop();
525   }
537526}
538527
539528
540529
541/***************************************************************************
542    THROTTLING/FRAMESKIPPING/PERFORMANCE
543***************************************************************************/
530//-------------------------------------------------
531//  init_buffered_spriteram - initialize the
532//  double-buffered spriteram
533//-------------------------------------------------
544534
545/*-------------------------------------------------
546    video_skip_this_frame - accessor to determine
547    if this frame is being skipped
548-------------------------------------------------*/
549
550int video_skip_this_frame(void)
535void video_manager::init_buffered_spriteram()
551536{
552   return global.skipping_this_frame;
553}
537   assert_always(m_machine.generic.spriteram_size != 0, "Video buffers spriteram but spriteram size is 0");
554538
539   // allocate memory for the back buffer
540   m_machine.generic.buffered_spriteram.u8 = auto_alloc_array(&m_machine, UINT8, m_machine.generic.spriteram_size);
555541
556/*-------------------------------------------------
557    video_get_speed_factor - return the speed
558    factor as an integer * 100
559-------------------------------------------------*/
542   // register for saving it
543   state_save_register_global_pointer(&m_machine, m_machine.generic.buffered_spriteram.u8, m_machine.generic.spriteram_size);
560544
561int video_get_speed_factor(void)
562{
563   return global.speed;
545   // do the same for the second back buffer, if present
546   if (m_machine.generic.spriteram2_size)
547   {
548      // allocate memory
549      m_machine.generic.buffered_spriteram2.u8 = auto_alloc_array(&m_machine, UINT8, m_machine.generic.spriteram2_size);
550
551      // register for saving it
552      state_save_register_global_pointer(&m_machine, m_machine.generic.buffered_spriteram2.u8, m_machine.generic.spriteram2_size);
553   }
564554}
565555
566556
567/*-------------------------------------------------
568    video_set_speed_factor - sets the speed
569    factor as an integer * 100
570-------------------------------------------------*/
557//-------------------------------------------------
558//  video_exit - close down the video system
559//-------------------------------------------------
571560
572void video_set_speed_factor(int speed)
561void video_manager::exit_static(running_machine &machine)
573562{
574   global.speed = speed;
563   machine.video().exit();
575564}
576565
577
578/*-------------------------------------------------
579    video_get_speed_text - print the text to
580    be displayed in the upper-right corner
581-------------------------------------------------*/
582
583const char *video_get_speed_text(running_machine *machine)
566void video_manager::exit()
584567{
585   bool paused = machine->paused();
586   static char buffer[1024];
587   char *dest = buffer;
568   // stop recording any movie
569   end_recording();
588570
589   /* validate */
590   assert(machine != NULL);
571   // free all the graphics elements
572   for (int i = 0; i < MAX_GFX_ELEMENTS; i++)
573      gfx_element_free(m_machine.gfx[i]);
591574
592   /* if we're paused, just display Paused */
593   if (paused)
594      dest += sprintf(dest, "paused");
575   // free the snapshot target
576   m_machine.render().target_free(m_snap_target);
577   if (m_snap_bitmap != NULL)
578      global_free(m_snap_bitmap);
595579
596   /* if we're fast forwarding, just display Fast-forward */
597   else if (global.fastforward)
598      dest += sprintf(dest, "fast ");
580   // print a final result if we have at least 5 seconds' worth of data
581   if (m_overall_emutime.seconds >= 5)
582   {
583      osd_ticks_t tps = osd_ticks_per_second();
584      double final_real_time = (double)m_overall_real_seconds + (double)m_overall_real_ticks / (double)tps;
585      double final_emu_time = attotime_to_double(m_overall_emutime);
586      mame_printf_info("Average speed: %.2f%% (%d seconds)\n", 100 * final_emu_time / final_real_time, attotime_add_attoseconds(m_overall_emutime, ATTOSECONDS_PER_SECOND / 2).seconds);
587   }
588}
599589
600   /* if we're auto frameskipping, display that plus the level */
601   else if (effective_autoframeskip(machine))
602      dest += sprintf(dest, "auto%2d/%d", effective_frameskip(), MAX_FRAMESKIP);
603590
604   /* otherwise, just display the frameskip plus the level */
605   else
606      dest += sprintf(dest, "skip %d/%d", effective_frameskip(), MAX_FRAMESKIP);
591//-------------------------------------------------
592//  screenless_update_callback - update generator
593//  when there are no screens to drive it
594//-------------------------------------------------
607595
608   /* append the speed for all cases except paused */
609   if (!paused)
610      dest += sprintf(dest, "%4d%%", (int)(100 * global.speed_percent + 0.5));
611
612   /* display the number of partial updates as well */
613   if (global.partial_updates_this_frame > 1)
614      dest += sprintf(dest, "\n%d partial updates", global.partial_updates_this_frame);
615
616   /* return a pointer to the static buffer */
617   return buffer;
596TIMER_CALLBACK( video_manager::screenless_update_callback )
597{
598   // force an update
599   reinterpret_cast<video_manager *>(ptr)->frame_update(false);
618600}
619601
620602
621/*-------------------------------------------------
622    video_get_speed_percent - return the current
623    effective speed percentage
624-------------------------------------------------*/
603//-------------------------------------------------
604//  postload - callback for resetting things after
605//  state has been loaded
606//-------------------------------------------------
625607
626double video_get_speed_percent(running_machine *machine)
608void video_manager::postload()
627609{
628   return global.speed_percent;
610   m_movie_next_frame_time = timer_get_time(&m_machine);
629611}
630612
631613
632/*-------------------------------------------------
633    video_get_frameskip - return the current
634    actual frameskip (-1 means autoframeskip)
635-------------------------------------------------*/
614//-------------------------------------------------
615//  effective_autoframeskip - return the effective
616//  autoframeskip value, accounting for fast
617//  forward
618//-------------------------------------------------
636619
637int video_get_frameskip(void)
620inline int video_manager::effective_autoframeskip() const
638621{
639   /* if autoframeskip is on, return -1 */
640   if (global.auto_frameskip)
641      return -1;
622   // if we're fast forwarding or paused, autoframeskip is disabled
623   if (m_fastforward || m_machine.paused())
624      return false;
642625
643   /* otherwise, return the direct level */
644   else
645      return global.frameskip_level;
626   // otherwise, it's up to the user
627   return m_auto_frameskip;
646628}
647629
648630
649/*-------------------------------------------------
650    video_set_frameskip - set the current
651    actual frameskip (-1 means autoframeskip)
652-------------------------------------------------*/
631//-------------------------------------------------
632//  effective_frameskip - return the effective
633//  frameskip value, accounting for fast
634//  forward
635//-------------------------------------------------
653636
654void video_set_frameskip(int frameskip)
637inline int video_manager::effective_frameskip() const
655638{
656   /* -1 means autoframeskip */
657   if (frameskip == -1)
658   {
659      global.auto_frameskip = TRUE;
660      global.frameskip_level = 0;
661   }
639   // if we're fast forwarding, use the maximum frameskip
640   if (m_fastforward)
641      return FRAMESKIP_LEVELS - 1;
662642
663   /* any other level is a direct control */
664   else if (frameskip >= 0 && frameskip <= MAX_FRAMESKIP)
665   {
666      global.auto_frameskip = FALSE;
667      global.frameskip_level = frameskip;
668   }
643   // otherwise, it's up to the user
644   return m_frameskip_level;
669645}
670646
671647
672/*-------------------------------------------------
673    video_get_throttle - return the current
674    actual throttle
675-------------------------------------------------*/
648//-------------------------------------------------
649//  effective_throttle - return the effective
650//  throttle value, accounting for fast
651//  forward and user interface
652//-------------------------------------------------
676653
677int video_get_throttle(void)
654inline bool video_manager::effective_throttle() const
678655{
679   return global.throttle;
656   // if we're paused, or if the UI is active, we always throttle
657   if (m_machine.paused() || ui_is_menu_active())
658      return true;
659
660   // if we're fast forwarding, we don't throttle
661   if (m_fastforward)
662      return false;
663
664   // otherwise, it's up to the user
665   return m_throttle;
680666}
681667
682668
683/*-------------------------------------------------
684    video_set_throttle - set the current
685    actual throttle
686-------------------------------------------------*/
669//-------------------------------------------------
670//  original_speed_setting - return the original
671//  speed setting
672//-------------------------------------------------
687673
688void video_set_throttle(int throttle)
674inline int video_manager::original_speed_setting() const
689675{
690   global.throttle = throttle;
676   return options_get_float(mame_options(), OPTION_SPEED) * 100.0 + 0.5;
691677}
692678
693679
694/*-------------------------------------------------
695    video_get_fastforward - return the current
696    fastforward value
697-------------------------------------------------*/
680//-------------------------------------------------
681//  finish_screen_updates - finish updating all
682//  the screens
683//-------------------------------------------------
698684
699int video_get_fastforward(void)
685bool video_manager::finish_screen_updates()
700686{
701   return global.fastforward;
702}
687   // finish updating the screens
688   for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
689      screen->update_partial(screen->visible_area().max_y);
703690
691   // now add the quads for all the screens
692   bool anything_changed = false;
693   for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
694      if (screen->update_quads())
695         anything_changed = true;
704696
705/*-------------------------------------------------
706    video_set_fastforward - set the current
707    fastforward value
708-------------------------------------------------*/
697   // update our movie recording and burn-in state
698   if (!m_machine.paused())
699   {
700      record_frame();
709701
710void video_set_fastforward(int _fastforward)
711{
712   global.fastforward = _fastforward;
702      // iterate over screens and update the burnin for the ones that care
703      for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
704         screen->update_burnin();
705   }
706
707   // draw any crosshairs
708   for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
709      crosshair_render(*screen);
710
711   return anything_changed;
713712}
714713
715714
716/*-------------------------------------------------
717    update_throttle - throttle to the game's
718    natural speed
719-------------------------------------------------*/
720715
721static void update_throttle(running_machine *machine, attotime emutime)
716//-------------------------------------------------
717//  update_throttle - throttle to the game's
718//  natural speed
719//-------------------------------------------------
720
721void video_manager::update_throttle(attotime emutime)
722722{
723723/*
724724
r9718r9719
764764      2,3,3,4,3,4,4,5, 3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7,
765765      3,4,4,5,4,5,5,6, 4,5,5,6,5,6,6,7, 4,5,5,6,5,6,6,7, 5,6,6,7,6,7,7,8
766766   };
767   attoseconds_t real_delta_attoseconds;
768   attoseconds_t emu_delta_attoseconds;
769   attoseconds_t real_is_ahead_attoseconds;
770   attoseconds_t attoseconds_per_tick;
771   osd_ticks_t ticks_per_second;
772   osd_ticks_t target_ticks;
773   osd_ticks_t diff_ticks;
774767
775   /* apply speed factor to emu time */
776   if (global.speed != 0 && global.speed != 100)
768   // outer scope so we can break out in case of a resync
769   while (1)
777770   {
778      /* multiply emutime by 100, then divide by the global speed factor */
779      emutime = attotime_div(attotime_mul(emutime, 100), global.speed);
780   }
771      // apply speed factor to emu time
772      if (m_speed != 0 && m_speed != 100)
773      {
774         // multiply emutime by 100, then divide by the global speed factor
775         emutime = attotime_div(attotime_mul(emutime, 100), m_speed);
776      }
781777
782   /* compute conversion factors up front */
783   ticks_per_second = osd_ticks_per_second();
784   attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second;
778      // compute conversion factors up front
779      osd_ticks_t ticks_per_second = osd_ticks_per_second();
780      attoseconds_t attoseconds_per_tick = ATTOSECONDS_PER_SECOND / ticks_per_second;
785781
786   /* if we're paused, emutime will not advance; instead, we subtract a fixed
787       amount of time (1/60th of a second) from the emulated time that was passed in,
788       and explicitly reset our tracked real and emulated timers to that value ...
789       this means we pretend that the last update was exactly 1/60th of a second
790       ago, and was in sync in both real and emulated time */
791   if (machine->paused())
792   {
793      global.throttle_emutime = attotime_sub_attoseconds(emutime, ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE);
794      global.throttle_realtime = global.throttle_emutime;
795   }
782      // if we're paused, emutime will not advance; instead, we subtract a fixed
783       // amount of time (1/60th of a second) from the emulated time that was passed in,
784       // and explicitly reset our tracked real and emulated timers to that value ...
785       // this means we pretend that the last update was exactly 1/60th of a second
786       // ago, and was in sync in both real and emulated time
787      if (m_machine.paused())
788      {
789         m_throttle_emutime = attotime_sub_attoseconds(emutime, ATTOSECONDS_PER_SECOND / PAUSED_REFRESH_RATE);
790         m_throttle_realtime = m_throttle_emutime;
791      }
796792
797   /* attempt to detect anomalies in the emulated time by subtracting the previously
798       reported value from our current value; this should be a small value somewhere
799       between 0 and 1/10th of a second ... anything outside of this range is obviously
800       wrong and requires a resync */
801   emu_delta_attoseconds = attotime_to_attoseconds(attotime_sub(emutime, global.throttle_emutime));
802   if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > ATTOSECONDS_PER_SECOND / 10)
803   {
804      if (LOG_THROTTLE)
805         logerror("Resync due to weird emutime delta: %s\n", attotime_string(attotime_make(0, emu_delta_attoseconds), 18));
806      goto resync;
807   }
793      // attempt to detect anomalies in the emulated time by subtracting the previously
794       // reported value from our current value; this should be a small value somewhere
795       // between 0 and 1/10th of a second ... anything outside of this range is obviously
796       // wrong and requires a resync
797      attoseconds_t emu_delta_attoseconds = attotime_to_attoseconds(attotime_sub(emutime, m_throttle_emutime));
798      if (emu_delta_attoseconds < 0 || emu_delta_attoseconds > ATTOSECONDS_PER_SECOND / 10)
799      {
800         if (LOG_THROTTLE)
801            logerror("Resync due to weird emutime delta: %s\n", attotime_string(attotime_make(0, emu_delta_attoseconds), 18));
802         break;
803      }
808804
809   /* now determine the current real time in OSD-specified ticks; we have to be careful
810       here because counters can wrap, so we only use the difference between the last
811       read value and the current value in our computations */
812   diff_ticks = osd_ticks() - global.throttle_last_ticks;
813   global.throttle_last_ticks += diff_ticks;
805      // now determine the current real time in OSD-specified ticks; we have to be careful
806       // here because counters can wrap, so we only use the difference between the last
807       // read value and the current value in our computations
808      osd_ticks_t diff_ticks = osd_ticks() - m_throttle_last_ticks;
809      m_throttle_last_ticks += diff_ticks;
814810
815   /* if it has been more than a full second of real time since the last call to this
816       function, we just need to resynchronize */
817   if (diff_ticks >= ticks_per_second)
818   {
819      if (LOG_THROTTLE)
820         logerror("Resync due to real time advancing by more than 1 second\n");
821      goto resync;
822   }
811      // if it has been more than a full second of real time since the last call to this
812       // function, we just need to resynchronize
813      if (diff_ticks >= ticks_per_second)
814      {
815         if (LOG_THROTTLE)
816            logerror("Resync due to real time advancing by more than 1 second\n");
817         break;
818      }
823819
824   /* convert this value into attoseconds for easier comparison */
825   real_delta_attoseconds = diff_ticks * attoseconds_per_tick;
820      // convert this value into attoseconds for easier comparison
821      attoseconds_t real_delta_attoseconds = diff_ticks * attoseconds_per_tick;
826822
827   /* now update our real and emulated timers with the current values */
828   global.throttle_emutime = emutime;
829   global.throttle_realtime = attotime_add_attoseconds(global.throttle_realtime, real_delta_attoseconds);
823      // now update our real and emulated timers with the current values
824      m_throttle_emutime = emutime;
825      m_throttle_realtime = attotime_add_attoseconds(m_throttle_realtime, real_delta_attoseconds);
830826
831   /* keep a history of whether or not emulated time beat real time over the last few
832       updates; this can be used for future heuristics */
833   global.throttle_history = (global.throttle_history << 1) | (emu_delta_attoseconds > real_delta_attoseconds);
827      // keep a history of whether or not emulated time beat real time over the last few
828       // updates; this can be used for future heuristics
829      m_throttle_history = (m_throttle_history << 1) | (emu_delta_attoseconds > real_delta_attoseconds);
834830
835   /* determine how far ahead real time is versus emulated time; note that we use the
836       accumulated times for this instead of the deltas for the current update because
837       we want to track time over a longer duration than a single update */
838   real_is_ahead_attoseconds = attotime_to_attoseconds(attotime_sub(global.throttle_emutime, global.throttle_realtime));
831      // determine how far ahead real time is versus emulated time; note that we use the
832       // accumulated times for this instead of the deltas for the current update because
833       // we want to track time over a longer duration than a single update
834      attoseconds_t real_is_ahead_attoseconds = attotime_to_attoseconds(attotime_sub(m_throttle_emutime, m_throttle_realtime));
839835
840   /* if we're more than 1/10th of a second out, or if we are behind at all and emulation
841       is taking longer than the real frame, we just need to resync */
842   if (real_is_ahead_attoseconds < -ATTOSECONDS_PER_SECOND / 10 ||
843      (real_is_ahead_attoseconds < 0 && popcount[global.throttle_history & 0xff] < 6))
844   {
845      if (LOG_THROTTLE)
846         logerror("Resync due to being behind: %s (history=%08X)\n", attotime_string(attotime_make(0, -real_is_ahead_attoseconds), 18), global.throttle_history);
847      goto resync;
848   }
836      // if we're more than 1/10th of a second out, or if we are behind at all and emulation
837       // is taking longer than the real frame, we just need to resync
838      if (real_is_ahead_attoseconds < -ATTOSECONDS_PER_SECOND / 10 ||
839         (real_is_ahead_attoseconds < 0 && popcount[m_throttle_history & 0xff] < 6))
840      {
841         if (LOG_THROTTLE)
842            logerror("Resync due to being behind: %s (history=%08X)\n", attotime_string(attotime_make(0, -real_is_ahead_attoseconds), 18), m_throttle_history);
843         break;
844      }
849845
850   /* if we're behind, it's time to just get out */
851   if (real_is_ahead_attoseconds < 0)
852      return;
846      // if we're behind, it's time to just get out
847      if (real_is_ahead_attoseconds < 0)
848         return;
853849
854   /* compute the target real time, in ticks, where we want to be */
855   target_ticks = global.throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick;
850      // compute the target real time, in ticks, where we want to be
851      osd_ticks_t target_ticks = m_throttle_last_ticks + real_is_ahead_attoseconds / attoseconds_per_tick;
856852
857   /* throttle until we read the target, and update real time to match the final time */
858   diff_ticks = throttle_until_ticks(machine, target_ticks) - global.throttle_last_ticks;
859   global.throttle_last_ticks += diff_ticks;
860   global.throttle_realtime = attotime_add_attoseconds(global.throttle_realtime, diff_ticks * attoseconds_per_tick);
861   return;
853      // throttle until we read the target, and update real time to match the final time
854      diff_ticks = throttle_until_ticks(target_ticks) - m_throttle_last_ticks;
855      m_throttle_last_ticks += diff_ticks;
856      m_throttle_realtime = attotime_add_attoseconds(m_throttle_realtime, diff_ticks * attoseconds_per_tick);
857      return;
858   }
862859
863resync:
864   /* reset realtime and emutime to the same value */
865   global.throttle_realtime = global.throttle_emutime = emutime;
860   // reset realtime and emutime to the same value
861   m_throttle_realtime = m_throttle_emutime = emutime;
866862}
867863
868864
869/*-------------------------------------------------
870    throttle_until_ticks - spin until the
871    specified target time, calling the OSD code
872    to sleep if possible
873-------------------------------------------------*/
865//-------------------------------------------------
866//  throttle_until_ticks - spin until the
867//  specified target time, calling the OSD code
868//  to sleep if possible
869//-------------------------------------------------
874870
875static osd_ticks_t throttle_until_ticks(running_machine *machine, osd_ticks_t target_ticks)
871osd_ticks_t video_manager::throttle_until_ticks(osd_ticks_t target_ticks)
876872{
877   osd_ticks_t minimum_sleep = osd_ticks_per_second() / 1000;
878   osd_ticks_t current_ticks = osd_ticks();
879   osd_ticks_t new_ticks;
880   int allowed_to_sleep = FALSE;
873   // we're allowed to sleep via the OSD code only if we're configured to do so
874    // and we're not frameskipping due to autoframeskip, or if we're paused
875   bool allowed_to_sleep = false;
876    if (options_get_bool(m_machine.options(), OPTION_SLEEP) && (!effective_autoframeskip() || effective_frameskip() == 0))
877       allowed_to_sleep = true;
878    if (m_machine.paused())
879       allowed_to_sleep = true;
881880
882   /* we're allowed to sleep via the OSD code only if we're configured to do so
883       and we're not frameskipping due to autoframeskip, or if we're paused */
884    if (options_get_bool(machine->options(), OPTION_SLEEP) && (!effective_autoframeskip(machine) || effective_frameskip() == 0))
885       allowed_to_sleep = TRUE;
886    if (machine->paused())
887       allowed_to_sleep = TRUE;
888
889   /* loop until we reach our target */
881   // loop until we reach our target
890882   g_profiler.start(PROFILER_IDLE);
883   osd_ticks_t minimum_sleep = osd_ticks_per_second() / 1000;
884   osd_ticks_t current_ticks = osd_ticks();
891885   while (current_ticks < target_ticks)
892886   {
893      osd_ticks_t delta;
894      int slept = FALSE;
887      // compute how much time to sleep for, taking into account the average oversleep
888      osd_ticks_t delta = (target_ticks - current_ticks) * 1000 / (1000 + m_average_oversleep);
895889
896      /* compute how much time to sleep for, taking into account the average oversleep */
897      delta = (target_ticks - current_ticks) * 1000 / (1000 + global.average_oversleep);
898
899      /* see if we can sleep */
890      // see if we can sleep
891      bool slept = false;
900892      if (allowed_to_sleep && delta >= minimum_sleep)
901893      {
902894         osd_sleep(delta);
903         slept = TRUE;
895         slept = true;
904896      }
905897
906      /* read the new value */
907      new_ticks = osd_ticks();
898      // read the new value
899      osd_ticks_t new_ticks = osd_ticks();
908900
909      /* keep some metrics on the sleeping patterns of the OSD layer */
901      // keep some metrics on the sleeping patterns of the OSD layer
910902      if (slept)
911903      {
904         // if we overslept, keep an average of the amount
912905         osd_ticks_t actual_ticks = new_ticks - current_ticks;
913
914         /* if we overslept, keep an average of the amount */
915906         if (actual_ticks > delta)
916907         {
908            // take 90% of the previous average plus 10% of the new value
917909            osd_ticks_t oversleep_milliticks = 1000 * (actual_ticks - delta) / delta;
910            m_average_oversleep = (m_average_oversleep * 99 + oversleep_milliticks) / 100;
918911
919            /* take 90% of the previous average plus 10% of the new value */
920            global.average_oversleep = (global.average_oversleep * 99 + oversleep_milliticks) / 100;
921
922912            if (LOG_THROTTLE)
923               logerror("Slept for %d ticks, got %d ticks, avgover = %d\n", (int)delta, (int)actual_ticks, (int)global.average_oversleep);
913               logerror("Slept for %d ticks, got %d ticks, avgover = %d\n", (int)delta, (int)actual_ticks, (int)m_average_oversleep);
924914         }
925915      }
926916      current_ticks = new_ticks;
r9718r9719
931921}
932922
933923
934/*-------------------------------------------------
935    update_frameskip - update frameskipping
936    counters and periodically update autoframeskip
937-------------------------------------------------*/
924//-------------------------------------------------
925//  update_frameskip - update frameskipping
926//  counters and periodically update autoframeskip
927//-------------------------------------------------
938928
939static void update_frameskip(running_machine *machine)
929void video_manager::update_frameskip()
940930{
941   /* if we're throttling and autoframeskip is on, adjust */
942   if (effective_throttle(machine) && effective_autoframeskip(machine) && global.frameskip_counter == 0)
931   // if we're throttling and autoframeskip is on, adjust
932   if (effective_throttle() && effective_autoframeskip() && m_frameskip_counter == 0)
943933   {
944      double speed = global.speed * 0.01;
945
946      /* if we're too fast, attempt to increase the frameskip */
947      if (global.speed_percent >= 0.995 * speed)
934      // if we're too fast, attempt to increase the frameskip
935      double speed = m_speed * 0.01;
936      if (m_speed_percent >= 0.995 * speed)
948937      {
949         /* but only after 3 consecutive frames where we are too fast */
950         if (++global.frameskip_adjust >= 3)
938         // but only after 3 consecutive frames where we are too fast
939         if (++m_frameskip_adjust >= 3)
951940         {
952            global.frameskip_adjust = 0;
953            if (global.frameskip_level > 0)
954               global.frameskip_level--;
941            m_frameskip_adjust = 0;
942            if (m_frameskip_level > 0)
943               m_frameskip_level--;
955944         }
956945      }
957946
958      /* if we're too slow, attempt to increase the frameskip */
947      // if we're too slow, attempt to increase the frameskip
959948      else
960949      {
961         /* if below 80% speed, be more aggressive */
962         if (global.speed_percent < 0.80 *  speed)
963            global.frameskip_adjust -= (0.90 * speed - global.speed_percent) / 0.05;
950         // if below 80% speed, be more aggressive
951         if (m_speed_percent < 0.80 *  speed)
952            m_frameskip_adjust -= (0.90 * speed - m_speed_percent) / 0.05;
964953
965         /* if we're close, only force it up to frameskip 8 */
966         else if (global.frameskip_level < 8)
967            global.frameskip_adjust--;
954         // if we're close, only force it up to frameskip 8
955         else if (m_frameskip_level < 8)
956            m_frameskip_adjust--;
968957
969         /* perform the adjustment */
970         while (global.frameskip_adjust <= -2)
958         // perform the adjustment
959         while (m_frameskip_adjust <= -2)
971960         {
972            global.frameskip_adjust += 2;
973            if (global.frameskip_level < MAX_FRAMESKIP)
974               global.frameskip_level++;
961            m_frameskip_adjust += 2;
962            if (m_frameskip_level < MAX_FRAMESKIP)
963               m_frameskip_level++;
975964         }
976965      }
977966   }
978967
979   /* increment the frameskip counter and determine if we will skip the next frame */
980   global.frameskip_counter = (global.frameskip_counter + 1) % FRAMESKIP_LEVELS;
981   global.skipping_this_frame = skiptable[effective_frameskip()][global.frameskip_counter];
968   // increment the frameskip counter and determine if we will skip the next frame
969   m_frameskip_counter = (m_frameskip_counter + 1) % FRAMESKIP_LEVELS;
970   m_skipping_this_frame = s_skiptable[effective_frameskip()][m_frameskip_counter];
982971}
983972
984973
985/*-------------------------------------------------
986    update_refresh_speed - update the global.speed
987    based on the maximum refresh rate supported
988-------------------------------------------------*/
974//-------------------------------------------------
975//  update_refresh_speed - update the m_speed
976//  based on the maximum refresh rate supported
977//-------------------------------------------------
989978
990static void update_refresh_speed(running_machine *machine)
979void video_manager::update_refresh_speed()
991980{
992   /* only do this if the refreshspeed option is used */
993   if (options_get_bool(machine->options(), OPTION_REFRESHSPEED))
981   // only do this if the refreshspeed option is used
982   if (options_get_bool(m_machine.options(), OPTION_REFRESHSPEED))
994983   {
995      float minrefresh = machine->render().max_update_rate();
984      float minrefresh = m_machine.render().max_update_rate();
996985      if (minrefresh != 0)
997986      {
987         // find the screen with the shortest frame period (max refresh rate)
988         // note that we first check the token since this can get called before all screens are created
998989         attoseconds_t min_frame_period = ATTOSECONDS_PER_SECOND;
999         UINT32 original_speed = original_speed_setting();
1000         UINT32 target_speed;
1001
1002         /* find the screen with the shortest frame period (max refresh rate) */
1003         /* note that we first check the token since this can get called before all screens are created */
1004         for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
990         for (screen_device *screen = m_machine.first_screen(); screen != NULL; screen = screen->next_screen())
1005991         {
1006992            attoseconds_t period = screen->frame_period().attoseconds;
1007993            if (period != 0)
1008994               min_frame_period = MIN(min_frame_period, period);
1009995         }
1010996
1011         /* compute a target speed as an integral percentage */
1012         /* note that we lop 0.25Hz off of the minrefresh when doing the computation to allow for
1013               the fact that most refresh rates are not accurate to 10 digits... */
1014         target_speed = floor((minrefresh - 0.25f) * 100.0 / ATTOSECONDS_TO_HZ(min_frame_period));
997         // compute a target speed as an integral percentage
998         // note that we lop 0.25Hz off of the minrefresh when doing the computation to allow for
999            // the fact that most refresh rates are not accurate to 10 digits...
1000         UINT32 target_speed = floor((minrefresh - 0.25f) * 100.0 / ATTOSECONDS_TO_HZ(min_frame_period));
1001         UINT32 original_speed = original_speed_setting();
10151002         target_speed = MIN(target_speed, original_speed);
10161003
1017         /* if we changed, log that verbosely */
1018         if (target_speed != global.speed)
1004         // if we changed, log that verbosely
1005         if (target_speed != m_speed)
10191006         {
10201007            mame_printf_verbose("Adjusting target speed to %d%% (hw=%.2fHz, game=%.2fHz, adjusted=%.2fHz)\n", target_speed, minrefresh, ATTOSECONDS_TO_HZ(min_frame_period), ATTOSECONDS_TO_HZ(min_frame_period * 100 / target_speed));
1021            global.speed = target_speed;
1008            m_speed = target_speed;
10221009         }
10231010      }
10241011   }
10251012}
10261013
10271014
1028/*-------------------------------------------------
1029    recompute_speed - recompute the current
1030    overall speed; we assume this is called only
1031    if we did not skip a frame
1032-------------------------------------------------*/
1015//-------------------------------------------------
1016//  recompute_speed - recompute the current
1017//  overall speed; we assume this is called only
1018//  if we did not skip a frame
1019//-------------------------------------------------
10331020
1034static void recompute_speed(running_machine *machine, attotime emutime)
1021void video_manager::recompute_speed(attotime emutime)
10351022{
1036   attoseconds_t delta_emutime;
1037
1038   /* if we don't have a starting time yet, or if we're paused, reset our starting point */
1039   if (global.speed_last_realtime == 0 || machine->paused())
1023   // if we don't have a starting time yet, or if we're paused, reset our starting point
1024   if (m_speed_last_realtime == 0 || m_machine.paused())
10401025   {
1041      global.speed_last_realtime = osd_ticks();
1042      global.speed_last_emutime = emutime;
1026      m_speed_last_realtime = osd_ticks();
1027      m_speed_last_emutime = emutime;
10431028   }
10441029
1045   /* if it has been more than the update interval, update the time */
1046   delta_emutime = attotime_to_attoseconds(attotime_sub(emutime, global.speed_last_emutime));
1030   // if it has been more than the update interval, update the time
1031   attoseconds_t delta_emutime = attotime_to_attoseconds(attotime_sub(emutime, m_speed_last_emutime));
10471032   if (delta_emutime > SUBSECONDS_PER_SPEED_UPDATE)
10481033   {
1034      // convert from ticks to attoseconds
10491035      osd_ticks_t realtime = osd_ticks();
1050      osd_ticks_t delta_realtime = realtime - global.speed_last_realtime;
1036      osd_ticks_t delta_realtime = realtime - m_speed_last_realtime;
10511037      osd_ticks_t tps = osd_ticks_per_second();
1038      m_speed_percent = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)ATTOSECONDS_PER_SECOND);
10521039
1053      /* convert from ticks to attoseconds */
1054      global.speed_percent = (double)delta_emutime * (double)tps / ((double)delta_realtime * (double)ATTOSECONDS_PER_SECOND);
1040      // remember the last times
1041      m_speed_last_realtime = realtime;
1042      m_speed_last_emutime = emutime;
10551043
1056      /* remember the last times */
1057      global.speed_last_realtime = realtime;
1058      global.speed_last_emutime = emutime;
1059
1060      /* if we're throttled, this time period counts for overall speed; otherwise, we reset the counter */
1061      if (!global.fastforward)
1062         global.overall_valid_counter++;
1044      // if we're throttled, this time period counts for overall speed; otherwise, we reset the counter
1045      if (!m_fastforward)
1046         m_overall_valid_counter++;
10631047      else
1064         global.overall_valid_counter = 0;
1048         m_overall_valid_counter = 0;
10651049
1066      /* if we've had at least 4 consecutive valid periods, accumulate stats */
1067      if (global.overall_valid_counter >= 4)
1050      // if we've had at least 4 consecutive valid periods, accumulate stats
1051      if (m_overall_valid_counter >= 4)
10681052      {
1069         global.overall_real_ticks += delta_realtime;
1070         while (global.overall_real_ticks >= tps)
1053         m_overall_real_ticks += delta_realtime;
1054         while (m_overall_real_ticks >= tps)
10711055         {
1072            global.overall_real_ticks -= tps;
1073            global.overall_real_seconds++;
1056            m_overall_real_ticks -= tps;
1057            m_overall_real_seconds++;
10741058         }
1075         global.overall_emutime = attotime_add_attoseconds(global.overall_emutime, delta_emutime);
1059         m_overall_emutime = attotime_add_attoseconds(m_overall_emutime, delta_emutime);
10761060      }
10771061   }
10781062
1079   /* if we're past the "time-to-execute" requested, signal an exit */
1080   if (global.seconds_to_run != 0 && emutime.seconds >= global.seconds_to_run)
1063   // if we're past the "time-to-execute" requested, signal an exit
1064   if (m_seconds_to_run != 0 && emutime.seconds >= m_seconds_to_run)
10811065   {
1082      if (machine->primary_screen != NULL)
1066      if (m_machine.primary_screen != NULL)
10831067      {
1084         astring fname(machine->basename(), PATH_SEPARATOR "final.png");
1085         file_error filerr;
1086         mame_file *file;
1068         astring fname(m_machine.basename(), PATH_SEPARATOR "final.png");
10871069
1088         /* create a final screenshot */
1089         filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
1070         // create a final screenshot
1071         mame_file *file;
1072         file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
10901073         if (filerr == FILERR_NONE)
10911074         {
1092            screen_save_snapshot(machine, machine->primary_screen, file);
1075            save_snapshot(m_machine.primary_screen, *file);
10931076            mame_fclose(file);
10941077         }
10951078      }
10961079
1097      /* schedule our demise */
1098      machine->schedule_exit();
1080      // schedule our demise
1081      m_machine.schedule_exit();
10991082   }
11001083}
11011084
11021085
1086//-------------------------------------------------
1087//  create_snapshot_bitmap - creates a
1088//  bitmap containing the screenshot for the
1089//  given screen
1090//-------------------------------------------------
11031091
1104/***************************************************************************
1105    SCREEN SNAPSHOTS
1106***************************************************************************/
1107
1108/*-------------------------------------------------
1109    screen_save_snapshot - save a snapshot
1110    to  the given file handle
1111-------------------------------------------------*/
1112
1113void screen_save_snapshot(running_machine *machine, device_t *screen, mame_file *fp)
1092void video_manager::create_snapshot_bitmap(device_t *screen)
11141093{
1115   png_info pnginfo = { 0 };
1116   const rgb_t *palette;
1117   png_error error;
1118   char text[256];
1119
1120   /* validate */
1121   assert(!global.snap_native || screen != NULL);
1122   assert(fp != NULL);
1123
1124   /* create the bitmap to pass in */
1125   create_snapshot_bitmap(screen);
1126
1127   /* add two text entries describing the image */
1128   sprintf(text, APPNAME " %s", build_version);
1129   png_add_text(&pnginfo, "Software", text);
1130   sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description);
1131   png_add_text(&pnginfo, "System", text);
1132
1133   /* now do the actual work */
1134   palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL;
1135   error = png_write_bitmap(mame_core_file(fp), &pnginfo, global.snap_bitmap, machine->total_colors(), palette);
1136
1137   /* free any data allocated */
1138   png_free(&pnginfo);
1139}
1140
1141
1142/*-------------------------------------------------
1143    video_save_active_screen_snapshots - save a
1144    snapshot of all active screens
1145-------------------------------------------------*/
1146
1147void video_save_active_screen_snapshots(running_machine *machine)
1148{
1149   mame_file *fp;
1150
1151   /* validate */
1152   assert(machine != NULL);
1153   assert(machine->config != NULL);
1154
1155   /* if we're native, then write one snapshot per visible screen */
1156   if (global.snap_native)
1094   // select the appropriate view in our dummy target
1095   if (m_snap_native && screen != NULL)
11571096   {
1158      /* write one snapshot per visible screen */
1159      for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
1160         if (machine->render().is_live(*screen))
1161         {
1162            file_error filerr = mame_fopen_next(machine, SEARCHPATH_SCREENSHOT, "png", &fp);
1163            if (filerr == FILERR_NONE)
1164            {
1165               screen_save_snapshot(machine, screen, fp);
1166               mame_fclose(fp);
1167            }
1168         }
1169   }
1170
1171   /* otherwise, just write a single snapshot */
1172   else
1173   {
1174      file_error filerr = mame_fopen_next(machine, SEARCHPATH_SCREENSHOT, "png", &fp);
1175      if (filerr == FILERR_NONE)
1176      {
1177         screen_save_snapshot(machine, NULL, fp);
1178         mame_fclose(fp);
1179      }
1180   }
1181}
1182
1183
1184/*-------------------------------------------------
1185    creare_snapshot_bitmap - creates a
1186    bitmap containing the screenshot for the
1187    given screen
1188-------------------------------------------------*/
1189
1190static void create_snapshot_bitmap(device_t *screen)
1191{
1192   INT32 width, height;
1193   int view_index;
1194
1195   /* select the appropriate view in our dummy target */
1196   if (global.snap_native && screen != NULL)
1197   {
1198      view_index = screen->machine->m_devicelist.index(SCREEN, screen->tag());
1097      int view_index = m_machine.m_devicelist.index(SCREEN, screen->tag());
11991098      assert(view_index != -1);
1200      global.snap_target->set_view(view_index);
1099      m_snap_target->set_view(view_index);
12011100   }
12021101
1203   /* get the minimum width/height and set it on the target */
1204   width = global.snap_width;
1205   height = global.snap_height;
1102   // get the minimum width/height and set it on the target
1103   INT32 width = m_snap_width;
1104   INT32 height = m_snap_height;
12061105   if (width == 0 || height == 0)
1207      global.snap_target->compute_minimum_size(width, height);
1208   global.snap_target->set_bounds(width, height);
1106      m_snap_target->compute_minimum_size(width, height);
1107   m_snap_target->set_bounds(width, height);
12091108
1210   /* if we don't have a bitmap, or if it's not the right size, allocate a new one */
1211   if (global.snap_bitmap == NULL || width != global.snap_bitmap->width || height != global.snap_bitmap->height)
1109   // if we don't have a bitmap, or if it's not the right size, allocate a new one
1110   if (m_snap_bitmap == NULL || width != m_snap_bitmap->width || height != m_snap_bitmap->height)
12121111   {
1213      if (global.snap_bitmap != NULL)
1214         global_free(global.snap_bitmap);
1215      global.snap_bitmap = global_alloc(bitmap_t(width, height, BITMAP_FORMAT_RGB32));
1216      assert(global.snap_bitmap != NULL);
1112      if (m_snap_bitmap != NULL)
1113         auto_free(&m_machine, m_snap_bitmap);
1114      m_snap_bitmap = auto_alloc(&m_machine, bitmap_t(width, height, BITMAP_FORMAT_RGB32));
12171115   }
12181116
1219   /* render the screen there */
1220   render_primitive_list &primlist = global.snap_target->get_primitives();
1117   // render the screen there
1118   render_primitive_list &primlist = m_snap_target->get_primitives();
12211119   primlist.acquire_lock();
1222   rgb888_draw_primitives(primlist, global.snap_bitmap->base, width, height, global.snap_bitmap->rowpixels);
1120   rgb888_draw_primitives(primlist, m_snap_bitmap->base, width, height, m_snap_bitmap->rowpixels);
12231121   primlist.release_lock();
12241122}
12251123
12261124
1227/*-------------------------------------------------
1228    mame_fopen_next - open the next non-existing
1229    file of type filetype according to our
1230    numbering scheme
1231-------------------------------------------------*/
1125//-------------------------------------------------
1126//  mame_fopen_next - open the next non-existing
1127//  file of type filetype according to our
1128//  numbering scheme
1129//-------------------------------------------------
12321130
1233static file_error mame_fopen_next(running_machine *machine, const char *pathoption, const char *extension, mame_file **file)
1131file_error video_manager::mame_fopen_next(const char *pathoption, const char *extension, mame_file *&file)
12341132{
1235   const char *snapname = options_get_string(machine->options(), OPTION_SNAPNAME);
1236   file_error filerr;
1237   astring snapstr;
1238   astring fname;
1239   int index;
1240
1241   /* handle defaults */
1133   // handle defaults
1134   const char *snapname = options_get_string(m_machine.options(), OPTION_SNAPNAME);
12421135   if (snapname == NULL || snapname[0] == 0)
12431136      snapname = "%g/%i";
1244   snapstr.cpy(snapname);
1137   astring snapstr(snapname);
12451138
1246   /* strip any extension in the provided name and add our own */
1247   index = snapstr.rchr(0, '.');
1139   // strip any extension in the provided name and add our own
1140   int index = snapstr.rchr(0, '.');
12481141   if (index != -1)
12491142      snapstr.substr(0, index);
12501143   snapstr.cat(".").cat(extension);
12511144
1252   /* substitute path and gamename up front */
1145   // substitute path and gamename up front
12531146   snapstr.replace(0, "/", PATH_SEPARATOR);
1254   snapstr.replace(0, "%g", machine->basename());
1147   snapstr.replace(0, "%g", m_machine.basename());
12551148
1256   /* determine if the template has an index; if not, we always use the same name */
1149   // determine if the template has an index; if not, we always use the same name
1150   astring fname;
12571151   if (snapstr.find(0, "%i") == -1)
12581152      fname.cpy(snapstr);
12591153
1260   /* otherwise, we scan for the next available filename */
1154   // otherwise, we scan for the next available filename
12611155   else
12621156   {
1263      int seq;
1264
1265      /* try until we succeed */
1266      for (seq = 0; ; seq++)
1157      // try until we succeed
1158      astring seqtext;
1159      for (int seq = 0; ; seq++)
12671160      {
1268         char seqtext[10];
1161         // build up the filename
1162         fname.cpy(snapstr).replace(0, "%i", seqtext.format("%04d", seq).cstr());
12691163
1270         /* make text for the sequence number */
1271         sprintf(seqtext, "%04d", seq);
1272
1273         /* build up the filename */
1274         fname.cpy(snapstr).replace(0, "%i", seqtext);
1275
1276         /* try to open the file; stop when we fail */
1277         filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, file);
1164         // try to open the file; stop when we fail
1165         file_error filerr = mame_fopen(pathoption, fname, OPEN_FLAG_READ, &file);
12781166         if (filerr != FILERR_NONE)
12791167            break;
1280         mame_fclose(*file);
1168         mame_fclose(file);
12811169      }
12821170   }
12831171
1284   /* create the final file */
1285    return mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, file);
1172   // create the final file
1173    return mame_fopen(pathoption, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
12861174}
12871175
12881176
12891177
1290/***************************************************************************
1291    MNG MOVIE RECORDING
1292***************************************************************************/
1178//-------------------------------------------------
1179//  record_frame - record a frame of a movie
1180//-------------------------------------------------
12931181
1294/*-------------------------------------------------
1295    video_mng_is_movie_active - return true if a
1296    MNG movie is currently being recorded
1297-------------------------------------------------*/
1298
1299int video_mng_is_movie_active(running_machine *machine)
1182void video_manager::record_frame()
13001183{
1301   return (global.mngfile != NULL);
1302}
1303
1304
1305/*-------------------------------------------------
1306    video_mng_begin_recording - begin recording
1307    of a MNG movie
1308-------------------------------------------------*/
1309
1310void video_mng_begin_recording(running_machine *machine, const char *name)
1311{
1312   file_error filerr;
1313   png_error pngerr;
1314   int rate;
1315
1316   /* close any existing movie file */
1317   if (global.mngfile != NULL)
1318      video_mng_end_recording(machine);
1319
1320   /* create a snapshot bitmap so we know what the target size is */
1321   create_snapshot_bitmap(NULL);
1322
1323   /* create a new movie file and start recording */
1324   if (name != NULL)
1325      filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &global.mngfile);
1326   else
1327      filerr = mame_fopen_next(machine, SEARCHPATH_MOVIE, "mng", &global.mngfile);
1328
1329   /* start the capture */
1330   rate = (machine->primary_screen != NULL) ? ATTOSECONDS_TO_HZ(machine->primary_screen->frame_period().attoseconds) : screen_device::k_default_frame_rate;
1331   pngerr = mng_capture_start(mame_core_file(global.mngfile), global.snap_bitmap, rate);
1332   if (pngerr != PNGERR_NONE)
1333   {
1334      video_mng_end_recording(machine);
1184   // ignore if nothing to do
1185   if (m_mngfile == NULL && m_avifile == NULL)
13351186      return;
1336   }
13371187
1338   /* compute the frame time */
1339   global.movie_next_frame_time = timer_get_time(machine);
1340   global.movie_frame_period = ATTOTIME_IN_HZ(rate);
1341   global.movie_frame = 0;
1342}
1188   // start the profiler and get the current time
1189   g_profiler.start(PROFILER_MOVIE_REC);
1190   attotime curtime = timer_get_time(&m_machine);
13431191
1344
1345/*-------------------------------------------------
1346    video_mng_end_recording - stop recording of
1347    a MNG movie
1348-------------------------------------------------*/
1349
1350void video_mng_end_recording(running_machine *machine)
1351{
1352   /* close the file if it exists */
1353   if (global.mngfile != NULL)
1354   {
1355      mng_capture_stop(mame_core_file(global.mngfile));
1356      mame_fclose(global.mngfile);
1357      global.mngfile = NULL;
1358      global.movie_frame = 0;
1359   }
1360}
1361
1362
1363/*-------------------------------------------------
1364    video_mng_record_frame - record a frame of a
1365    movie
1366-------------------------------------------------*/
1367
1368static void video_mng_record_frame(running_machine *machine)
1369{
1370   /* only record if we have a file */
1371   if (global.mngfile != NULL)
1372   {
1373      attotime curtime = timer_get_time(machine);
1374      png_info pnginfo = { 0 };
1375      png_error error;
1376
1377      g_profiler.start(PROFILER_MOVIE_REC);
1378
1379      /* create the bitmap */
1380      create_snapshot_bitmap(NULL);
1381
1382      /* loop until we hit the right time */
1383      while (attotime_compare(global.movie_next_frame_time, curtime) <= 0)
1384      {
1385         const rgb_t *palette;
1386
1387         /* set up the text fields in the movie info */
1388         if (global.movie_frame == 0)
1389         {
1390            char text[256];
1391
1392            sprintf(text, APPNAME " %s", build_version);
1393            png_add_text(&pnginfo, "Software", text);
1394            sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description);
1395            png_add_text(&pnginfo, "System", text);
1396         }
1397
1398         /* write the next frame */
1399         palette = (machine->palette != NULL) ? palette_entry_list_adjusted(machine->palette) : NULL;
1400         error = mng_capture_frame(mame_core_file(global.mngfile), &pnginfo, global.snap_bitmap, machine->total_colors(), palette);
1401         png_free(&pnginfo);
1402         if (error != PNGERR_NONE)
1403         {
1404            video_mng_end_recording(machine);
1405            break;
1406         }
1407
1408         /* advance time */
1409         global.movie_next_frame_time = attotime_add(global.movie_next_frame_time, global.movie_frame_period);
1410         global.movie_frame++;
1411      }
1412
1413      g_profiler.stop();
1414   }
1415}
1416
1417
1418
1419/***************************************************************************
1420    AVI MOVIE RECORDING
1421***************************************************************************/
1422
1423/*-------------------------------------------------
1424    video_avi_begin_recording - begin recording
1425    of an AVI movie
1426-------------------------------------------------*/
1427
1428void video_avi_begin_recording(running_machine *machine, const char *name)
1429{
1430   avi_movie_info info;
1431   mame_file *tempfile;
1432   file_error filerr;
1433   avi_error avierr;
1434
1435   /* close any existing movie file */
1436   if (global.avifile != NULL)
1437      video_avi_end_recording(machine);
1438
1439   /* create a snapshot bitmap so we know what the target size is */
1192   // create the bitmap
14401193   create_snapshot_bitmap(NULL);
14411194
1442   /* build up information about this new movie */
1443   info.video_format = 0;
1444   info.video_timescale = 1000 * ((machine->primary_screen != NULL) ? ATTOSECONDS_TO_HZ(machine->primary_screen->frame_period().attoseconds) : screen_device::k_default_frame_rate);
1445   info.video_sampletime = 1000;
1446   info.video_numsamples = 0;
1447   info.video_width = global.snap_bitmap->width;
1448   info.video_height = global.snap_bitmap->height;
1449   info.video_depth = 24;
1450
1451   info.audio_format = 0;
1452   info.audio_timescale = machine->sample_rate;
1453   info.audio_sampletime = 1;
1454   info.audio_numsamples = 0;
1455   info.audio_channels = 2;
1456   info.audio_samplebits = 16;
1457   info.audio_samplerate = machine->sample_rate;
1458
1459   /* create a new temporary movie file */
1460   if (name != NULL)
1461      filerr = mame_fopen(SEARCHPATH_MOVIE, name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &tempfile);
1462   else
1463      filerr = mame_fopen_next(machine, SEARCHPATH_MOVIE, "avi", &tempfile);
1464
1465   /* reset our tracking */
1466   global.movie_frame = 0;
1467   global.movie_next_frame_time = timer_get_time(machine);
1468   global.movie_frame_period = attotime_div(ATTOTIME_IN_SEC(1000), info.video_timescale);
1469
1470   /* if we succeeded, make a copy of the name and create the real file over top */
1471   if (filerr == FILERR_NONE)
1195   // loop until we hit the right time
1196   while (attotime_compare(m_movie_next_frame_time, curtime) <= 0)
14721197   {
1473      astring fullname(mame_file_full_name(tempfile));
1474      mame_fclose(tempfile);
1475
1476      /* create the file and free the string */
1477      avierr = avi_create(fullname, &info, &global.avifile);
1478   }
1479}
1480
1481
1482/*-------------------------------------------------
1483    video_avi_end_recording - stop recording of
1484    a avi movie
1485-------------------------------------------------*/
1486
1487void video_avi_end_recording(running_machine *machine)
1488{
1489   /* close the file if it exists */
1490   if (global.avifile != NULL)
1491   {
1492      avi_close(global.avifile);
1493      global.avifile = NULL;
1494      global.movie_frame = 0;
1495   }
1496}
1497
1498
1499/*-------------------------------------------------
1500    video_avi_record_frame - record a frame of a
1501    movie
1502-------------------------------------------------*/
1503
1504static void video_avi_record_frame(running_machine *machine)
1505{
1506   /* only record if we have a file */
1507   if (global.avifile != NULL)
1508   {
1509      attotime curtime = timer_get_time(machine);
1510      avi_error avierr;
1511
1512      g_profiler.start(PROFILER_MOVIE_REC);
1513
1514      /* create the bitmap */
1515      create_snapshot_bitmap(NULL);
1516
1517      /* loop until we hit the right time */
1518      while (attotime_compare(global.movie_next_frame_time, curtime) <= 0)
1198      // handle an AVI recording
1199      if (m_avifile != NULL)
15191200      {
1520         /* write the next frame */
1521         avierr = avi_append_video_frame_rgb32(global.avifile, global.snap_bitmap);
1201         // write the next frame
1202         avi_error avierr = avi_append_video_frame_rgb32(m_avifile, m_snap_bitmap);
15221203         if (avierr != AVIERR_NONE)
15231204         {
1524            video_avi_end_recording(machine);
1525            break;
1205            g_profiler.stop();
1206            return end_recording();
15261207         }
1527
1528         /* advance time */
1529         global.movie_next_frame_time = attotime_add(global.movie_next_frame_time, global.movie_frame_period);
1530         global.movie_frame++;
15311208      }
15321209
1533      g_profiler.stop();
1534   }
1535}
1536
1537
1538/*-------------------------------------------------
1539    video_avi_add_sound - add sound to an AVI
1540    recording
1541-------------------------------------------------*/
1542
1543void video_avi_add_sound(running_machine *machine, const INT16 *sound, int numsamples)
1544{
1545   /* only record if we have a file */
1546   if (global.avifile != NULL)
1547   {
1548      avi_error avierr;
1549
1550      g_profiler.start(PROFILER_MOVIE_REC);
1551
1552      /* write the next frame */
1553      avierr = avi_append_sound_samples(global.avifile, 0, sound + 0, numsamples, 1);
1554      if (avierr == AVIERR_NONE)
1555         avierr = avi_append_sound_samples(global.avifile, 1, sound + 1, numsamples, 1);
1556      if (avierr != AVIERR_NONE)
1557         video_avi_end_recording(machine);
1558
1559      g_profiler.stop();
1560   }
1561}
1562
1563
1564
1565/***************************************************************************
1566    BURN-IN GENERATION
1567***************************************************************************/
1568
1569
1570/***************************************************************************
1571    CONFIGURATION HELPERS
1572***************************************************************************/
1573
1574/*-------------------------------------------------
1575    video_get_view_for_target - select a view
1576    for a given target
1577-------------------------------------------------*/
1578
1579int video_get_view_for_target(running_machine *machine, render_target *target, const char *viewname, int targetindex, int numtargets)
1580{
1581   int viewindex = -1;
1582
1583   /* auto view just selects the nth view */
1584   if (strcmp(viewname, "auto") != 0)
1585   {
1586      /* scan for a matching view name */
1587      for (viewindex = 0; ; viewindex++)
1210      // handle a MNG recording
1211      if (m_mngfile != NULL)
15881212      {
1589         const char *name = target->view_name(viewindex);
1590
1591         /* stop scanning when we hit NULL */
1592         if (name == NULL)
1213         // set up the text fields in the movie info
1214         png_info pnginfo = { 0 };
1215         if (m_movie_frame == 0)
15931216         {
1594            viewindex = -1;
1595            break;
1217            astring text1(APPNAME, " ", build_version);
1218            astring text2(m_machine.m_game.manufacturer, " ", m_machine.m_game.description);
1219            png_add_text(&pnginfo, "Software", text1);
1220            png_add_text(&pnginfo, "System", text2);
15961221         }
1597         if (mame_strnicmp(name, viewname, strlen(viewname)) == 0)
1598            break;
1599      }
1600   }
16011222
1602   /* if we don't have a match, default to the nth view */
1603   int scrcount = screen_count(*machine->config);
1604   if (viewindex == -1 && scrcount > 0)
1605   {
1606      /* if we have enough targets to be one per screen, assign in order */
1607      if (numtargets >= scrcount)
1608      {
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
1615         /* find the first view with this screen and this screen only */
1616         for (viewindex = 0; ; viewindex++)
1223         // write the next frame
1224         const rgb_t *palette = (m_machine.palette != NULL) ? palette_entry_list_adjusted(m_machine.palette) : NULL;
1225         png_error error = mng_capture_frame(mame_core_file(m_mngfile), &pnginfo, m_snap_bitmap, m_machine.total_colors(), palette);
1226         png_free(&pnginfo);
1227         if (error != PNGERR_NONE)
16171228         {
1618            const render_screen_list &viewscreens = target->view_screens(viewindex);
1619            if (viewscreens.count() == 1 && viewscreens.contains(*screen))
1620               break;
1621            if (viewscreens.count() == 0)
1622            {
1623               viewindex = -1;
1624               break;
1625            }
1229            g_profiler.stop();
1230            return end_recording();
16261231         }
16271232      }
16281233
1629      /* otherwise, find the first view that has all the screens */
1630      if (viewindex == -1)
1631      {
1632         for (viewindex = 0; ; viewindex++)
1633         {
1634            const render_screen_list &viewscreens = target->view_screens(viewindex);
1635            if (viewscreens.count() == 0)
1636               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            }
1646         }
1647      }
1234      // advance time
1235      m_movie_next_frame_time = attotime_add(m_movie_next_frame_time, m_movie_frame_period);
1236      m_movie_frame++;
16481237   }
1649
1650   /* make sure it's a valid view */
1651   if (target->view_name(viewindex) == NULL)
1652      viewindex = 0;
1653
1654   return viewindex;
1238   g_profiler.stop();
16551239}
16561240
16571241
16581242
1659/***************************************************************************
1660    DEBUGGING HELPERS
1661***************************************************************************/
1662
16631243/*-------------------------------------------------
16641244    video_assert_out_of_range_pixels - assert if
16651245    any pixels in the given bitmap contain an
r9718r9719
16721252   int maxindex = palette_get_max_index(machine->palette);
16731253   int x, y;
16741254
1675   /* this only applies to indexed16 bitmaps */
1255   // this only applies to indexed16 bitmaps
16761256   if (bitmap->format != BITMAP_FORMAT_INDEXED16)
16771257      return;
16781258
1679   /* iterate over rows */
1259   // iterate over rows
16801260   for (y = 0; y < bitmap->height; y++)
16811261   {
16821262      UINT16 *rowbase = BITMAP_ADDR16(bitmap, y, 0);
r9718r9719
16891269
16901270
16911271//**************************************************************************
1692//  VIDEO SCREEN DEVICE CONFIGURATION
1693//**************************************************************************
1694
1695const attotime screen_device::k_default_frame_period = STATIC_ATTOTIME_IN_HZ(k_default_frame_rate);
1696
1697
1698//-------------------------------------------------
1699//  screen_device_config - constructor
1700//-------------------------------------------------
1701
1702screen_device_config::screen_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
1703   : device_config(mconfig, static_alloc_device_config, "Video Screen", tag, owner, clock),
1704     m_type(SCREEN_TYPE_RASTER),
1705     m_width(0),
1706     m_height(0),
1707     m_oldstyle_vblank_supplied(false),
1708     m_refresh(0),
1709     m_vblank(0),
1710     m_format(BITMAP_FORMAT_INVALID),
1711     m_xoffset(0.0f),
1712     m_yoffset(0.0f),
1713     m_xscale(1.0f),
1714     m_yscale(1.0f)
1715{
1716}
1717
1718
1719//-------------------------------------------------
1720//  static_alloc_device_config - allocate a new
1721//  configuration object
1722//-------------------------------------------------
1723
1724device_config *screen_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
1725{
1726   return global_alloc(screen_device_config(mconfig, tag, owner, clock));
1727}
1728
1729
1730//-------------------------------------------------
1731//  alloc_device - allocate a new device object
1732//-------------------------------------------------
1733
1734device_t *screen_device_config::alloc_device(running_machine &machine) const
1735{
1736   return auto_alloc(&machine, screen_device(machine, *this));
1737}
1738
1739
1740//-------------------------------------------------
1741//  static_set_format - configuration helper
1742//  to set the bitmap format
1743//-------------------------------------------------
1744
1745void screen_device_config::static_set_format(device_config *device, bitmap_format format)
1746{
1747   screen_device_config *screen = downcast<screen_device_config *>(device);
1748   screen->m_format = format;
1749}
1750
1751
1752//-------------------------------------------------
1753//  static_set_type - configuration helper
1754//  to set the screen type
1755//-------------------------------------------------
1756
1757void screen_device_config::static_set_type(device_config *device, screen_type_enum type)
1758{
1759   screen_device_config *screen = downcast<screen_device_config *>(device);
1760   screen->m_type = type;
1761}
1762
1763
1764//-------------------------------------------------
1765//  static_set_raw - configuration helper
1766//  to set the raw screen parameters
1767//-------------------------------------------------
1768
1769void screen_device_config::static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart)
1770{
1771   screen_device_config *screen = downcast<screen_device_config *>(device);
1772   screen->m_refresh = HZ_TO_ATTOSECONDS(pixclock) * htotal * vtotal;
1773   screen->m_vblank = screen->m_refresh / vtotal * (vtotal - (vbstart - vbend));
1774   screen->m_width = htotal;
1775   screen->m_height = vtotal;
1776   screen->m_visarea.min_x = hbend;
1777   screen->m_visarea.max_x = hbstart - 1;
1778   screen->m_visarea.min_y = vbend;
1779   screen->m_visarea.max_y = vbstart - 1;
1780}
1781
1782
1783//-------------------------------------------------
1784//  static_set_refresh - configuration helper
1785//  to set the refresh rate
1786//-------------------------------------------------
1787
1788void screen_device_config::static_set_refresh(device_config *device, attoseconds_t rate)
1789{
1790   screen_device_config *screen = downcast<screen_device_config *>(device);
1791   screen->m_refresh = rate;
1792}
1793
1794
1795//-------------------------------------------------
1796//  static_set_vblank_time - configuration helper
1797//  to set the VBLANK duration
1798//-------------------------------------------------
1799
1800void screen_device_config::static_set_vblank_time(device_config *device, attoseconds_t time)
1801{
1802   screen_device_config *screen = downcast<screen_device_config *>(device);
1803   screen->m_vblank = time;
1804   screen->m_oldstyle_vblank_supplied = true;
1805}
1806
1807
1808//-------------------------------------------------
1809//  static_set_size - configuration helper to set
1810//  the width/height of the screen
1811//-------------------------------------------------
1812
1813void screen_device_config::static_set_size(device_config *device, UINT16 width, UINT16 height)
1814{
1815   screen_device_config *screen = downcast<screen_device_config *>(device);
1816   screen->m_width = width;
1817   screen->m_height = height;
1818}
1819
1820
1821//-------------------------------------------------
1822//  static_set_visarea - configuration helper to
1823//  set the visible area of the screen
1824//-------------------------------------------------
1825
1826void screen_device_config::static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy)
1827{
1828   screen_device_config *screen = downcast<screen_device_config *>(device);
1829   screen->m_visarea.min_x = minx;
1830   screen->m_visarea.max_x = maxx;
1831   screen->m_visarea.min_y = miny;
1832   screen->m_visarea.max_y = maxy;
1833}
1834
1835
1836//-------------------------------------------------
1837//  static_set_default_position - configuration
1838//  helper to set the default position and scale
1839//  factors for the screen
1840//-------------------------------------------------
1841
1842void screen_device_config::static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs)
1843{
1844   screen_device_config *screen = downcast<screen_device_config *>(device);
1845   screen->m_xscale = xscale;
1846   screen->m_xoffset = xoffs;
1847   screen->m_yscale = yscale;
1848   screen->m_yoffset = yoffs;
1849}
1850
1851
1852//-------------------------------------------------
1853//  device_validity_check - verify device
1854//  configuration
1855//-------------------------------------------------
1856
1857bool screen_device_config::device_validity_check(const game_driver &driver) const
1858{
1859   bool error = false;
1860
1861   // sanity check dimensions
1862   if (m_width <= 0 || m_height <= 0)
1863   {
1864      mame_printf_error("%s: %s screen '%s' has invalid display dimensions\n", driver.source_file, driver.name, tag());
1865      error = true;
1866   }
1867
1868   // sanity check display area
1869   if (m_type != SCREEN_TYPE_VECTOR)
1870   {
1871      if ((m_visarea.max_x < m_visarea.min_x) ||
1872         (m_visarea.max_y < m_visarea.min_y) ||
1873         (m_visarea.max_x >= m_width) ||
1874         (m_visarea.max_y >= m_height))
1875      {
1876         mame_printf_error("%s: %s screen '%s' has an invalid display area\n", driver.source_file, driver.name, tag());
1877         error = true;
1878      }
1879
1880      // sanity check screen formats
1881      if (m_format != BITMAP_FORMAT_INDEXED16 &&
1882         m_format != BITMAP_FORMAT_RGB15 &&
1883         m_format != BITMAP_FORMAT_RGB32)
1884      {
1885         mame_printf_error("%s: %s screen '%s' has unsupported format\n", driver.source_file, driver.name, tag());
1886         error = true;
1887      }
1888   }
1889
1890   // check for zero frame rate
1891   if (m_refresh == 0)
1892   {
1893      mame_printf_error("%s: %s screen '%s' has a zero refresh rate\n", driver.source_file, driver.name, tag());
1894      error = true;
1895   }
1896   return error;
1897}
1898
1899
1900
1901//**************************************************************************
1902//  LIVE VIDEO SCREEN DEVICE
1903//**************************************************************************
1904
1905//-------------------------------------------------
1906//  screen_device - constructor
1907//-------------------------------------------------
1908
1909screen_device::screen_device(running_machine &_machine, const screen_device_config &config)
1910   : device_t(_machine, config),
1911     m_config(config),
1912     m_container(NULL),
1913     m_width(m_config.m_width),
1914     m_height(m_config.m_height),
1915     m_visarea(m_config.m_visarea),
1916     m_burnin(NULL),
1917     m_curbitmap(0),
1918     m_curtexture(0),
1919     m_texture_format(0),
1920     m_changed(true),
1921     m_last_partial_scan(0),
1922     m_screen_overlay_bitmap(NULL),
1923     m_frame_period(m_config.m_refresh),
1924     m_scantime(1),
1925     m_pixeltime(1),
1926     m_vblank_period(0),
1927     m_vblank_start_time(attotime_zero),
1928     m_vblank_end_time(attotime_zero),
1929     m_vblank_begin_timer(NULL),
1930     m_vblank_end_timer(NULL),
1931     m_scanline0_timer(NULL),
1932     m_scanline_timer(NULL),
1933     m_frame_number(0),
1934     m_callback_list(NULL)
1935{
1936   memset(m_texture, 0, sizeof(m_texture));
1937   memset(m_bitmap, 0, sizeof(m_bitmap));
1938}
1939
1940
1941//-------------------------------------------------
1942//  ~screen_device - destructor
1943//-------------------------------------------------
1944
1945screen_device::~screen_device()
1946{
1947   m_machine.render().texture_free(m_texture[0]);
1948   m_machine.render().texture_free(m_texture[1]);
1949   if (m_burnin != NULL)
1950      finalize_burnin();
1951   global_free(m_screen_overlay_bitmap);
1952}
1953
1954
1955//-------------------------------------------------
1956//  device_start - device-specific startup
1957//-------------------------------------------------
1958
1959void screen_device::device_start()
1960{
1961   // configure the default cliparea
1962   render_container::user_settings settings;
1963   m_container->get_user_settings(settings);
1964   settings.m_xoffset = m_config.m_xoffset;
1965   settings.m_yoffset = m_config.m_yoffset;
1966   settings.m_xscale = m_config.m_xscale;
1967   settings.m_yscale = m_config.m_yscale;
1968   m_container->set_user_settings(settings);
1969
1970   // allocate the VBLANK timers
1971   m_vblank_begin_timer = timer_alloc(machine, static_vblank_begin_callback, (void *)this);
1972   m_vblank_end_timer = timer_alloc(machine, static_vblank_end_callback, (void *)this);
1973
1974   // allocate a timer to reset partial updates
1975   m_scanline0_timer = timer_alloc(machine, static_scanline0_callback, (void *)this);
1976
1977   // allocate a timer to generate per-scanline updates
1978   if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0)
1979      m_scanline_timer = timer_alloc(machine, static_scanline_update_callback, (void *)this);
1980
1981   // configure the screen with the default parameters
1982   configure(m_config.m_width, m_config.m_height, m_config.m_visarea, m_config.m_refresh);
1983
1984   // reset VBLANK timing */
1985   m_vblank_start_time = attotime_zero;
1986   m_vblank_end_time = attotime_make(0, m_vblank_period);
1987
1988   // start the timer to generate per-scanline updates
1989   if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0)
1990      timer_adjust_oneshot(m_scanline_timer, time_until_pos(0), 0);
1991
1992   // create burn-in bitmap
1993   if (options_get_int(machine->options(), OPTION_BURNIN) > 0)
1994   {
1995      int width, height;
1996      if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0)
1997         width = height = 300;
1998      m_burnin = auto_alloc(machine, bitmap_t(width, height, BITMAP_FORMAT_INDEXED64));
1999      if (m_burnin == NULL)
2000         fatalerror("Error allocating burn-in bitmap for screen at (%dx%d)\n", width, height);
2001      bitmap_fill(m_burnin, NULL, 0);
2002   }
2003
2004   // load the effect overlay
2005   const char *overname = options_get_string(machine->options(), OPTION_EFFECT);
2006   if (overname != NULL && strcmp(overname, "none") != 0)
2007      load_effect_overlay(overname);
2008
2009   state_save_register_device_item(this, 0, m_width);
2010   state_save_register_device_item(this, 0, m_height);
2011   state_save_register_device_item(this, 0, m_visarea.min_x);
2012   state_save_register_device_item(this, 0, m_visarea.min_y);
2013   state_save_register_device_item(this, 0, m_visarea.max_x);
2014   state_save_register_device_item(this, 0, m_visarea.max_y);
2015   state_save_register_device_item(this, 0, m_last_partial_scan);
2016   state_save_register_device_item(this, 0, m_frame_period);
2017   state_save_register_device_item(this, 0, m_scantime);
2018   state_save_register_device_item(this, 0, m_pixeltime);
2019   state_save_register_device_item(this, 0, m_vblank_period);
2020   state_save_register_device_item(this, 0, m_vblank_start_time.seconds);
2021   state_save_register_device_item(this, 0, m_vblank_start_time.attoseconds);
2022   state_save_register_device_item(this, 0, m_vblank_end_time.seconds);
2023   state_save_register_device_item(this, 0, m_vblank_end_time.attoseconds);
2024   state_save_register_device_item(this, 0, m_frame_number);
2025}
2026
2027
2028//-------------------------------------------------
2029//  device_post_load - device-specific update
2030//  after a save state is loaded
2031//-------------------------------------------------
2032
2033void screen_device::device_post_load()
2034{
2035   realloc_screen_bitmaps();
2036   global.movie_next_frame_time = timer_get_time(machine);
2037}
2038
2039
2040//-------------------------------------------------
2041//  configure - configure screen parameters
2042//-------------------------------------------------
2043
2044void screen_device::configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period)
2045{
2046   // validate arguments
2047   assert(width > 0);
2048   assert(height > 0);
2049   assert(visarea.min_x >= 0);
2050   assert(visarea.min_y >= 0);
2051   assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_x < width);
2052   assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_y < height);
2053   assert(frame_period > 0);
2054
2055   // fill in the new parameters
2056   m_width = width;
2057   m_height = height;
2058   m_visarea = visarea;
2059
2060   // reallocate bitmap if necessary
2061   realloc_screen_bitmaps();
2062
2063   // compute timing parameters
2064   m_frame_period = frame_period;
2065   m_scantime = frame_period / height;
2066   m_pixeltime = frame_period / (height * width);
2067
2068   // if there has been no VBLANK time specified in the MACHINE_DRIVER, compute it now
2069    // from the visible area, otherwise just used the supplied value
2070   if (m_config.m_vblank == 0 && !m_config.m_oldstyle_vblank_supplied)
2071      m_vblank_period = m_scantime * (height - (visarea.max_y + 1 - visarea.min_y));
2072   else
2073      m_vblank_period = m_config.m_vblank;
2074
2075   // if we are on scanline 0 already, reset the update timer immediately
2076   // otherwise, defer until the next scanline 0
2077   if (vpos() == 0)
2078      timer_adjust_oneshot(m_scanline0_timer, attotime_zero, 0);
2079   else
2080      timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
2081
2082   // start the VBLANK timer
2083   timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
2084
2085   // adjust speed if necessary
2086   update_refresh_speed(machine);
2087}
2088
2089
2090//-------------------------------------------------
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   attotime curtime = timer_get_time(machine);
2099   m_vblank_end_time = attotime_sub_attoseconds(curtime, beamy * m_scantime + beamx * m_pixeltime);
2100   m_vblank_start_time = attotime_sub_attoseconds(m_vblank_end_time, m_vblank_period);
2101
2102   // if we are resetting relative to (0,0) == VBLANK end, call the
2103   // scanline 0 timer by hand now; otherwise, adjust it for the future
2104   if (beamy == 0 && beamx == 0)
2105      scanline0_callback();
2106   else
2107      timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
2108
2109   // if we are resetting relative to (visarea.max_y + 1, 0) == VBLANK start,
2110   // call the VBLANK start timer now; otherwise, adjust it for the future
2111   if (beamy == m_visarea.max_y + 1 && beamx == 0)
2112      vblank_begin_callback();
2113   else
2114      timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
2115}
2116
2117
2118//-------------------------------------------------
2119//  realloc_screen_bitmaps - reallocate bitmaps
2120//  and textures as necessary
2121//-------------------------------------------------
2122
2123void screen_device::realloc_screen_bitmaps()
2124{
2125   if (m_config.m_type == SCREEN_TYPE_VECTOR)
2126      return;
2127
2128   int curwidth = 0, curheight = 0;
2129
2130   // extract the current width/height from the bitmap
2131   if (m_bitmap[0] != NULL)
2132   {
2133      curwidth = m_bitmap[0]->width;
2134      curheight = m_bitmap[0]->height;
2135   }
2136
2137   // if we're too small to contain this width/height, reallocate our bitmaps and textures
2138   if (m_width > curwidth || m_height > curheight)
2139   {
2140      // free what we have currently
2141      m_machine.render().texture_free(m_texture[0]);
2142      m_machine.render().texture_free(m_texture[1]);
2143      auto_free(machine, m_bitmap[0]);
2144      auto_free(machine, m_bitmap[1]);
2145
2146      // compute new width/height
2147      curwidth = MAX(m_width, curwidth);
2148      curheight = MAX(m_height, curheight);
2149
2150      // choose the texture format - convert the screen format to a texture format
2151      palette_t *palette = NULL;
2152      switch (m_config.m_format)
2153      {
2154         case BITMAP_FORMAT_INDEXED16:   m_texture_format = TEXFORMAT_PALETTE16;   palette = machine->palette;   break;
2155         case BITMAP_FORMAT_RGB15:      m_texture_format = TEXFORMAT_RGB15;      palette = NULL;            break;
2156         case BITMAP_FORMAT_RGB32:      m_texture_format = TEXFORMAT_RGB32;      palette = NULL;            break;
2157         default:                  fatalerror("Invalid bitmap format!");                                    break;
2158      }
2159
2160      // allocate bitmaps
2161      m_bitmap[0] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format));
2162      bitmap_set_palette(m_bitmap[0], machine->palette);
2163      m_bitmap[1] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format));
2164      bitmap_set_palette(m_bitmap[1], machine->palette);
2165
2166      // allocate textures
2167      m_texture[0] = m_machine.render().texture_alloc();
2168      m_texture[0]->set_bitmap(m_bitmap[0], &m_visarea, m_texture_format, palette);
2169      m_texture[1] = m_machine.render().texture_alloc();
2170      m_texture[1]->set_bitmap(m_bitmap[1], &m_visarea, m_texture_format, palette);
2171   }
2172}
2173
2174
2175//-------------------------------------------------
2176//  set_visible_area - just set the visible area
2177//-------------------------------------------------
2178
2179void screen_device::set_visible_area(int min_x, int max_x, int min_y, int max_y)
2180{
2181   // validate arguments
2182   assert(min_x >= 0);
2183   assert(min_y >= 0);
2184   assert(min_x < max_x);
2185   assert(min_y < max_y);
2186
2187   rectangle visarea;
2188   visarea.min_x = min_x;
2189   visarea.max_x = max_x;
2190   visarea.min_y = min_y;
2191   visarea.max_y = max_y;
2192
2193   configure(m_width, m_height, visarea, m_frame_period);
2194}
2195
2196
2197//-------------------------------------------------
2198//  update_partial - perform a partial update from
2199//  the last scanline up to and including the
2200//  specified scanline
2201//-----------------------------------------------*/
2202
2203bool screen_device::update_partial(int scanline)
2204{
2205   // validate arguments
2206   assert(scanline >= 0);
2207
2208   LOG_PARTIAL_UPDATES(("Partial: update_partial(%s, %d): ", tag(), scanline));
2209
2210   // these two checks only apply if we're allowed to skip frames
2211   if (!(machine->config->m_video_attributes & VIDEO_ALWAYS_UPDATE))
2212   {
2213      // if skipping this frame, bail
2214      if (global.skipping_this_frame)
2215      {
2216         LOG_PARTIAL_UPDATES(("skipped due to frameskipping\n"));
2217         return FALSE;
2218      }
2219
2220      // skip if this screen is not visible anywhere
2221      if (!m_machine.render().is_live(*this))
2222      {
2223         LOG_PARTIAL_UPDATES(("skipped because screen not live\n"));
2224         return FALSE;
2225      }
2226   }
2227
2228   // skip if less than the lowest so far
2229   if (scanline < m_last_partial_scan)
2230   {
2231      LOG_PARTIAL_UPDATES(("skipped because less than previous\n"));
2232      return FALSE;
2233   }
2234
2235   // set the start/end scanlines
2236   rectangle clip = m_visarea;
2237   if (m_last_partial_scan > clip.min_y)
2238      clip.min_y = m_last_partial_scan;
2239   if (scanline < clip.max_y)
2240      clip.max_y = scanline;
2241
2242   // render if necessary
2243   bool result = false;
2244   if (clip.min_y <= clip.max_y)
2245   {
2246      UINT32 flags = UPDATE_HAS_NOT_CHANGED;
2247
2248      g_profiler.start(PROFILER_VIDEO);
2249      LOG_PARTIAL_UPDATES(("updating %d-%d\n", clip.min_y, clip.max_y));
2250
2251      flags = machine->driver_data<driver_device>()->video_update(*this, *m_bitmap[m_curbitmap], clip);
2252      global.partial_updates_this_frame++;
2253      g_profiler.stop();
2254
2255      // if we modified the bitmap, we have to commit
2256      m_changed |= ~flags & UPDATE_HAS_NOT_CHANGED;
2257      result = true;
2258   }
2259
2260   // remember where we left off
2261   m_last_partial_scan = scanline + 1;
2262   return result;
2263}
2264
2265
2266//-------------------------------------------------
2267//  update_now - perform an update from the last
2268//  beam position up to the current beam position
2269//-------------------------------------------------
2270
2271void screen_device::update_now()
2272{
2273   int current_vpos = vpos();
2274   int current_hpos = hpos();
2275
2276   // since we can currently update only at the scanline
2277    // level, we are trying to do the right thing by
2278    // updating including the current scanline, only if the
2279    // beam is past the halfway point horizontally.
2280    // If the beam is in the first half of the scanline,
2281    // we only update up to the previous scanline.
2282    // This minimizes the number of pixels that might be drawn
2283    // incorrectly until we support a pixel level granularity
2284   if (current_hpos < (m_width / 2) && current_vpos > 0)
2285      current_vpos = current_vpos - 1;
2286
2287   update_partial(current_vpos);
2288}
2289
2290
2291//-------------------------------------------------
2292//  vpos - returns the current vertical position
2293//  of the beam
2294//-------------------------------------------------
2295
2296int screen_device::vpos() const
2297{
2298   attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
2299   int vpos;
2300
2301   // round to the nearest pixel
2302   delta += m_pixeltime / 2;
2303
2304   // compute the v position relative to the start of VBLANK
2305   vpos = delta / m_scantime;
2306
2307   // adjust for the fact that VBLANK starts at the bottom of the visible area
2308   return (m_visarea.max_y + 1 + vpos) % m_height;
2309}
2310
2311
2312//-------------------------------------------------
2313//  hpos - returns the current horizontal position
2314//  of the beam
2315//-------------------------------------------------
2316
2317int screen_device::hpos() const
2318{
2319   attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
2320
2321   // round to the nearest pixel
2322   delta += m_pixeltime / 2;
2323
2324   // compute the v position relative to the start of VBLANK
2325   int vpos = delta / m_scantime;
2326
2327   // subtract that from the total time
2328   delta -= vpos * m_scantime;
2329
2330   // return the pixel offset from the start of this scanline
2331   return delta / m_pixeltime;
2332}
2333
2334
2335//-------------------------------------------------
2336//  time_until_pos - returns the amount of time
2337//  remaining until the beam is at the given
2338//  hpos,vpos
2339//-------------------------------------------------
2340
2341attotime screen_device::time_until_pos(int vpos, int hpos) const
2342{
2343   // validate arguments
2344   assert(vpos >= 0);
2345   assert(hpos >= 0);
2346
2347   // since we measure time relative to VBLANK, compute the scanline offset from VBLANK
2348   vpos += m_height - (m_visarea.max_y + 1);
2349   vpos %= m_height;
2350
2351   // compute the delta for the given X,Y position
2352   attoseconds_t targetdelta = (attoseconds_t)vpos * m_scantime + (attoseconds_t)hpos * m_pixeltime;
2353
2354   // if we're past that time (within 1/2 of a pixel), head to the next frame
2355   attoseconds_t curdelta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
2356   if (targetdelta <= curdelta + m_pixeltime / 2)
2357      targetdelta += m_frame_period;
2358   while (targetdelta <= curdelta)
2359      targetdelta += m_frame_period;
2360
2361   // return the difference
2362   return attotime_make(0, targetdelta - curdelta);
2363}
2364
2365
2366//-------------------------------------------------
2367//  time_until_vblank_end - returns the amount of
2368//  time remaining until the end of the current
2369//  VBLANK (if in progress) or the end of the next
2370//  VBLANK
2371//-------------------------------------------------
2372
2373attotime screen_device::time_until_vblank_end() const
2374{
2375   // if we are in the VBLANK region, compute the time until the end of the current VBLANK period
2376   attotime target_time = m_vblank_end_time;
2377   if (!vblank())
2378      target_time = attotime_add_attoseconds(target_time, m_frame_period);
2379   return attotime_sub(target_time, timer_get_time(machine));
2380}
2381
2382
2383//-------------------------------------------------
2384//  register_vblank_callback - registers a VBLANK
2385//  callback
2386//-------------------------------------------------
2387
2388void screen_device::register_vblank_callback(vblank_state_changed_func vblank_callback, void *param)
2389{
2390   // validate arguments
2391   assert(vblank_callback != NULL);
2392
2393   // check if we already have this callback registered
2394   callback_item **itemptr;
2395   for (itemptr = &m_callback_list; *itemptr != NULL; itemptr = &(*itemptr)->m_next)
2396      if ((*itemptr)->m_callback == vblank_callback)
2397         break;
2398
2399   // if not found, register
2400   if (*itemptr == NULL)
2401   {
2402      *itemptr = auto_alloc(machine, callback_item);
2403      (*itemptr)->m_next = NULL;
2404      (*itemptr)->m_callback = vblank_callback;
2405      (*itemptr)->m_param = param;
2406   }
2407}
2408
2409
2410//-------------------------------------------------
2411//  vblank_begin_callback - call any external
2412//  callbacks to signal the VBLANK period has begun
2413//-------------------------------------------------
2414
2415void screen_device::vblank_begin_callback()
2416{
2417   // reset the starting VBLANK time
2418   m_vblank_start_time = timer_get_time(machine);
2419   m_vblank_end_time = attotime_add_attoseconds(m_vblank_start_time, m_vblank_period);
2420
2421   // call the screen specific callbacks
2422   for (callback_item *item = m_callback_list; item != NULL; item = item->m_next)
2423      (*item->m_callback)(*this, item->m_param, true);
2424
2425   // if this is the primary screen and we need to update now
2426   if (this == machine->primary_screen && !(machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
2427      video_frame_update(machine, FALSE);
2428
2429   // reset the VBLANK start timer for the next frame
2430   timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
2431
2432   // if no VBLANK period, call the VBLANK end callback immedietely, otherwise reset the timer
2433   if (m_vblank_period == 0)
2434      vblank_end_callback();
2435   else
2436      timer_adjust_oneshot(m_vblank_end_timer, time_until_vblank_end(), 0);
2437}
2438
2439
2440//-------------------------------------------------
2441//  vblank_end_callback - call any external
2442//  callbacks to signal the VBLANK period has ended
2443//-------------------------------------------------
2444
2445void screen_device::vblank_end_callback()
2446{
2447   // call the screen specific callbacks
2448   for (callback_item *item = m_callback_list; item != NULL; item = item->m_next)
2449      (*item->m_callback)(*this, item->m_param, false);
2450
2451   // if this is the primary screen and we need to update now
2452   if (this == machine->primary_screen && (machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
2453      video_frame_update(machine, FALSE);
2454
2455   // increment the frame number counter
2456   m_frame_number++;
2457}
2458
2459
2460//-------------------------------------------------
2461//  scanline0_callback - reset partial updates
2462//  for a screen
2463//-------------------------------------------------
2464
2465void screen_device::scanline0_callback()
2466{
2467   // reset partial updates
2468   m_last_partial_scan = 0;
2469   global.partial_updates_this_frame = 0;
2470
2471   timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
2472}
2473
2474
2475//-------------------------------------------------
2476//  scanline_update_callback - perform partial
2477//  updates on each scanline
2478//-------------------------------------------------
2479
2480void screen_device::scanline_update_callback(int scanline)
2481{
2482   // force a partial update to the current scanline
2483   update_partial(scanline);
2484
2485   // compute the next visible scanline
2486   scanline++;
2487   if (scanline > m_visarea.max_y)
2488      scanline = m_visarea.min_y;
2489   timer_adjust_oneshot(m_scanline_timer, time_until_pos(scanline), scanline);
2490}
2491
2492
2493//-------------------------------------------------
2494//  update_quads - set up the quads for this
2495//  screen
2496//-------------------------------------------------
2497
2498bool screen_device::update_quads()
2499{
2500   // only update if live
2501   if (m_machine.render().is_live(*this))
2502   {
2503      // only update if empty and not a vector game; otherwise assume the driver did it directly
2504      if (m_config.m_type != SCREEN_TYPE_VECTOR && (machine->config->m_video_attributes & VIDEO_SELF_RENDER) == 0)
2505      {
2506         // if we're not skipping the frame and if the screen actually changed, then update the texture
2507         if (!global.skipping_this_frame && m_changed)
2508         {
2509            rectangle fixedvis = m_visarea;
2510            fixedvis.max_x++;
2511            fixedvis.max_y++;
2512
2513            palette_t *palette = (m_texture_format == TEXFORMAT_PALETTE16) ? machine->palette : NULL;
2514            m_texture[m_curbitmap]->set_bitmap(m_bitmap[m_curbitmap], &fixedvis, m_texture_format, palette);
2515
2516            m_curtexture = m_curbitmap;
2517            m_curbitmap = 1 - m_curbitmap;
2518         }
2519
2520         // create an empty container with a single quad
2521         m_container->empty();
2522         m_container->add_quad(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0xff,0xff,0xff), m_texture[m_curtexture], PRIMFLAG_BLENDMODE(BLENDMODE_NONE) | PRIMFLAG_SCREENTEX(1));
2523      }
2524   }
2525
2526   // reset the screen changed flags
2527   bool result = m_changed;
2528   m_changed = false;
2529   return result;
2530}
2531
2532
2533//-------------------------------------------------
2534//  update_burnin - update the burnin bitmap
2535//-------------------------------------------------
2536
2537void screen_device::update_burnin()
2538{
2539#undef rand
2540   if (m_burnin == NULL)
2541      return;
2542
2543   bitmap_t *srcbitmap = m_bitmap[m_curtexture];
2544   if (srcbitmap == NULL)
2545      return;
2546
2547   int srcwidth = srcbitmap->width;
2548   int srcheight = srcbitmap->height;
2549   int dstwidth = m_burnin->width;
2550   int dstheight = m_burnin->height;
2551   int xstep = (srcwidth << 16) / dstwidth;
2552   int ystep = (srcheight << 16) / dstheight;
2553   int xstart = ((UINT32)rand() % 32767) * xstep / 32767;
2554   int ystart = ((UINT32)rand() % 32767) * ystep / 32767;
2555   int srcx, srcy;
2556   int x, y;
2557
2558   // iterate over rows in the destination
2559   for (y = 0, srcy = ystart; y < dstheight; y++, srcy += ystep)
2560   {
2561      UINT64 *dst = BITMAP_ADDR64(m_burnin, y, 0);
2562
2563      // handle the 16-bit palettized case
2564      if (srcbitmap->format == BITMAP_FORMAT_INDEXED16)
2565      {
2566         const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0);
2567         const rgb_t *palette = palette_entry_list_adjusted(machine->palette);
2568         for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
2569         {
2570            rgb_t pixel = palette[src[srcx >> 16]];
2571            dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel);
2572         }
2573      }
2574
2575      // handle the 15-bit RGB case
2576      else if (srcbitmap->format == BITMAP_FORMAT_RGB15)
2577      {
2578         const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0);
2579         for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
2580         {
2581            rgb15_t pixel = src[srcx >> 16];
2582            dst[x] += ((pixel >> 10) & 0x1f) + ((pixel >> 5) & 0x1f) + ((pixel >> 0) & 0x1f);
2583         }
2584      }
2585
2586      // handle the 32-bit RGB case
2587      else if (srcbitmap->format == BITMAP_FORMAT_RGB32)
2588      {
2589         const UINT32 *src = BITMAP_ADDR32(srcbitmap, srcy >> 16, 0);
2590         for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
2591         {
2592            rgb_t pixel = src[srcx >> 16];
2593            dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel);
2594         }
2595      }
2596   }
2597}
2598
2599
2600//-------------------------------------------------
2601//  finalize_burnin - finalize the burnin bitmap
2602//-------------------------------------------------
2603
2604void screen_device::finalize_burnin()
2605{
2606   if (m_burnin == NULL)
2607      return;
2608
2609   // compute the scaled visible region
2610   rectangle scaledvis;
2611   scaledvis.min_x = m_visarea.min_x * m_burnin->width / m_width;
2612   scaledvis.max_x = m_visarea.max_x * m_burnin->width / m_width;
2613   scaledvis.min_y = m_visarea.min_y * m_burnin->height / m_height;
2614   scaledvis.max_y = m_visarea.max_y * m_burnin->height / m_height;
2615
2616   // wrap a bitmap around the subregion we care about
2617   bitmap_t *finalmap = auto_alloc(machine, bitmap_t(scaledvis.max_x + 1 - scaledvis.min_x,
2618                                    scaledvis.max_y + 1 - scaledvis.min_y,
2619                                    BITMAP_FORMAT_ARGB32));
2620
2621   int srcwidth = m_burnin->width;
2622   int srcheight = m_burnin->height;
2623   int dstwidth = finalmap->width;
2624   int dstheight = finalmap->height;
2625   int xstep = (srcwidth << 16) / dstwidth;
2626   int ystep = (srcheight << 16) / dstheight;
2627
2628   // find the maximum value
2629   UINT64 minval = ~(UINT64)0;
2630   UINT64 maxval = 0;
2631   for (int y = 0; y < srcheight; y++)
2632   {
2633      UINT64 *src = BITMAP_ADDR64(m_burnin, y, 0);
2634      for (int x = 0; x < srcwidth; x++)
2635      {
2636         minval = MIN(minval, src[x]);
2637         maxval = MAX(maxval, src[x]);
2638      }
2639   }
2640
2641   if (minval == maxval)
2642      return;
2643
2644   // now normalize and convert to RGB
2645   for (int y = 0, srcy = 0; y < dstheight; y++, srcy += ystep)
2646   {
2647      UINT64 *src = BITMAP_ADDR64(m_burnin, srcy >> 16, 0);
2648      UINT32 *dst = BITMAP_ADDR32(finalmap, y, 0);
2649      for (int x = 0, srcx = 0; x < dstwidth; x++, srcx += xstep)
2650      {
2651         int brightness = (UINT64)(maxval - src[srcx >> 16]) * 255 / (maxval - minval);
2652         dst[x] = MAKE_ARGB(0xff, brightness, brightness, brightness);
2653      }
2654   }
2655
2656   // write the final PNG
2657
2658   // compute the name and create the file
2659   astring fname;
2660   fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename(), tag());
2661   mame_file *file;
2662   file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
2663   if (filerr == FILERR_NONE)
2664   {
2665      png_info pnginfo = { 0 };
2666      png_error pngerr;
2667      char text[256];
2668
2669      // add two text entries describing the image
2670      sprintf(text, APPNAME " %s", build_version);
2671      png_add_text(&pnginfo, "Software", text);
2672      sprintf(text, "%s %s", machine->gamedrv->manufacturer, machine->gamedrv->description);
2673      png_add_text(&pnginfo, "System", text);
2674
2675      // now do the actual work
2676      pngerr = png_write_bitmap(mame_core_file(file), &pnginfo, finalmap, 0, NULL);
2677
2678      // free any data allocated
2679      png_free(&pnginfo);
2680      mame_fclose(file);
2681   }
2682}
2683
2684
2685//-------------------------------------------------
2686//  finalize_burnin - finalize the burnin bitmap
2687//-------------------------------------------------
2688
2689void screen_device::load_effect_overlay(const char *filename)
2690{
2691   // ensure that there is a .png extension
2692   astring fullname(filename);
2693   int extension = fullname.rchr(0, '.');
2694   if (extension != -1)
2695      fullname.del(extension, -1);
2696   fullname.cat(".png");
2697
2698   // load the file
2699   m_screen_overlay_bitmap = render_load_png(OPTION_ARTPATH, NULL, fullname, NULL, NULL);
2700   if (m_screen_overlay_bitmap != NULL)
2701      m_container->set_overlay(m_screen_overlay_bitmap);
2702   else
2703      mame_printf_warning("Unable to load effect PNG file '%s'\n", fullname.cstr());
2704}
2705
2706
2707
2708//**************************************************************************
27091272//  SOFTWARE RENDERING
27101273//**************************************************************************
27111274
src/emu/video.h
r9718r9719
5555const int FRAMESKIP_LEVELS = 12;
5656const int MAX_FRAMESKIP = FRAMESKIP_LEVELS - 2;
5757
58// screen types
59enum screen_type_enum
60{
61   SCREEN_TYPE_INVALID = 0,
62   SCREEN_TYPE_RASTER,
63   SCREEN_TYPE_VECTOR,
64   SCREEN_TYPE_LCD
65};
6658
6759
68
6960//**************************************************************************
7061//  TYPE DEFINITIONS
7162//**************************************************************************
7263
7364// forward references
7465class render_target;
75class render_texture;
7666class screen_device;
67typedef struct _avi_file avi_file;
7768
7869
79// callback that is called to notify of a change in the VBLANK state
80typedef void (*vblank_state_changed_func)(screen_device &device, void *param, bool vblank_state);
8170
71// ======================> video_manager
8272
83// ======================> screen_device_config
84
85class screen_device_config : public device_config
73class video_manager
8674{
8775   friend class screen_device;
88
89   // construction/destruction
90   screen_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
91
76   
9277public:
93   // allocators
94   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
95   virtual device_t *alloc_device(running_machine &machine) const;
78   // movie format options
79   enum movie_format
80   {
81      MF_MNG,
82      MF_AVI
83   };
9684
97   // configuration readers
98   screen_type_enum screen_type() const { return m_type; }
99   int width() const { return m_width; }
100   int height() const { return m_height; }
101   const rectangle &visible_area() const { return m_visarea; }
102   bool oldstyle_vblank_supplied() const { return m_oldstyle_vblank_supplied; }
103   attoseconds_t refresh() const { return m_refresh; }
104   attoseconds_t vblank() const { return m_vblank; }
105   bitmap_format format() const { return m_format; }
106   float xoffset() const { return m_xoffset; }
107   float yoffset() const { return m_yoffset; }
108   float xscale() const { return m_xscale; }
109   float yscale() const { return m_yscale; }
110
111   // inline configuration helpers
112   static void static_set_format(device_config *device, bitmap_format format);
113   static void static_set_type(device_config *device, screen_type_enum type);
114   static void static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart);
115   static void static_set_refresh(device_config *device, attoseconds_t rate);
116   static void static_set_vblank_time(device_config *device, attoseconds_t time);
117   static void static_set_size(device_config *device, UINT16 width, UINT16 height);
118   static void static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy);
119   static void static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs);
120
121private:
122   // device_config overrides
123   virtual bool device_validity_check(const game_driver &driver) const;
124
125   // inline configuration data
126   screen_type_enum   m_type;                  // type of screen
127   int               m_width, m_height;         // default total width/height (HTOTAL, VTOTAL)
128   rectangle         m_visarea;               // default visible area (HBLANK end/start, VBLANK end/start)
129   bool            m_oldstyle_vblank_supplied;   // MDRV_SCREEN_VBLANK_TIME macro used
130   attoseconds_t      m_refresh;               // default refresh period
131   attoseconds_t      m_vblank;               // duration of a VBLANK
132   bitmap_format      m_format;               // bitmap format
133   float            m_xoffset, m_yoffset;      // default X/Y offsets
134   float            m_xscale, m_yscale;         // default X/Y scale factor
135};
136
137
138
139// ======================> screen_device
140
141class screen_device : public device_t
142{
143   friend class screen_device_config;
144   friend class render_manager;
145   friend resource_pool_object<screen_device>::~resource_pool_object();
146
14785   // construction/destruction
148   screen_device(running_machine &_machine, const screen_device_config &config);
149   virtual ~screen_device();
86   video_manager(running_machine &machine);
87   
88   // getters
89   bool skip_this_frame() const { return m_skipping_this_frame; }
90   int speed_factor() const { return m_speed; }
91   int frameskip() const { return m_auto_frameskip ? -1 : m_frameskip_level; }
92   bool throttled() const { return m_throttle; }
93   bool fastforward() const { return m_fastforward; }
94   bool is_recording() const { return (m_mngfile != NULL || m_avifile != NULL); }
15095
151public:
152   // information getters
153   const screen_device_config &config() const { return m_config; }
154   screen_type_enum screen_type() const { return m_config.m_type; }
155   int width() const { return m_width; }
156   int height() const { return m_height; }
157   const rectangle &visible_area() const { return m_visarea; }
158   bitmap_format format() const { return m_config.m_format; }
159   render_container &container() const { assert(m_container != NULL); return *m_container; }
96   // setters
97   void set_speed_factor(int speed) { m_speed = speed; }
98   void set_frameskip(int frameskip);
99   void set_throttled(bool throttled = true) { m_throttle = throttled; }
100   void set_fastforward(bool ffwd = true) { m_fastforward = ffwd; }
160101
161   // dynamic configuration
162   void configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period);
163   void reset_origin(int beamy = 0, int beamx = 0);
164   void set_visible_area(int min_x, int max_x, int min_y, int max_y);
102   // render a frame   
103   void frame_update(bool debug = false);
104   
105   // current speed helpers
106   astring &speed_text(astring &string);
107   double speed_percent() const { return m_speed_percent; }
165108
166   // beam positioning and state
167   int vpos() const;
168   int hpos() const;
169   bool vblank() const { return attotime_compare(timer_get_time(machine), m_vblank_end_time) < 0; }
170   bool hblank() const { int curpos = hpos(); return (curpos < m_visarea.min_x || curpos > m_visarea.max_x); }
109   // snapshots   
110   void save_snapshot(screen_device *screen, mame_file &file);
111   void save_active_screen_snapshots();
112   
113   // movies
114   void begin_recording(const char *name, movie_format format = MF_AVI);
115   void end_recording();
116   void add_sound_to_recording(const INT16 *sound, int numsamples);
171117
172   // timing
173   attotime time_until_pos(int vpos, int hpos = 0) const;
174   attotime time_until_vblank_start() const { return time_until_pos(m_visarea.max_y + 1); }
175   attotime time_until_vblank_end() const;
176   attotime time_until_update() const { return (machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK) ? time_until_vblank_end() : time_until_vblank_start(); }
177   attotime scan_period() const { return attotime_make(0, m_scantime); }
178   attotime frame_period() const { return (this == NULL || !started()) ? k_default_frame_period : attotime_make(0, m_frame_period); };
179   UINT64 frame_number() const { return m_frame_number; }
180
181   // updating
182   bool update_partial(int scanline);
183   void update_now();
184
185   // additional helpers
186   void save_snapshot(mame_file *fp);
187   void register_vblank_callback(vblank_state_changed_func vblank_callback, void *param);
188   bitmap_t *alloc_compatible_bitmap(int width = 0, int height = 0) { return auto_bitmap_alloc(machine, (width == 0) ? m_width : width, (height == 0) ? m_height : height, m_config.m_format); }
189
190   // internal to the video system
191   bool update_quads();
192   void update_burnin();
193
194   // globally accessible constants
195   static const int k_default_frame_rate = 60;
196   static const attotime k_default_frame_period;
197
198118private:
199   // device-level overrides
200   virtual void device_start();
201   virtual void device_post_load();
202
203119   // internal helpers
204   void set_container(render_container &container) { m_container = &container; }
205   void realloc_screen_bitmaps();
120   void init_buffered_spriteram();
121   static void exit_static(running_machine &machine);
122   void exit();
123   static TIMER_CALLBACK( screenless_update_callback );
124   void postload();
125   
126   // effective value helpers
127   int effective_autoframeskip() const;
128   int effective_frameskip() const;
129   bool effective_throttle() const;
130   
131   // speed and throttling helpers
132   int original_speed_setting() const;
133   bool finish_screen_updates();
134   void update_throttle(attotime emutime);
135   osd_ticks_t throttle_until_ticks(osd_ticks_t target_ticks);
136   void update_frameskip();
137   void update_refresh_speed();
138   void recompute_speed(attotime emutime);
206139
207   static TIMER_CALLBACK( static_vblank_begin_callback ) { reinterpret_cast<screen_device *>(ptr)->vblank_begin_callback(); }
208   void vblank_begin_callback();
140   // snapshot/movie helpers
141   void create_snapshot_bitmap(device_t *screen);
142   file_error mame_fopen_next(const char *pathoption, const char *extension, mame_file *&file);
143   void record_frame();
209144
210   static TIMER_CALLBACK( static_vblank_end_callback ) { reinterpret_cast<screen_device *>(ptr)->vblank_end_callback(); }
211   void vblank_end_callback();
145   // internal state
146   running_machine &   m_machine;               // reference to our machine
147   
148   // screenless systems
149   emu_timer *         m_screenless_frame_timer;   // timer to signal VBLANK start
212150
213   static TIMER_CALLBACK( static_scanline0_callback ) { reinterpret_cast<screen_device *>(ptr)->scanline0_callback(); }
214public:   // temporary
215   void scanline0_callback();
216private:
151   // throttling calculations
152   osd_ticks_t         m_throttle_last_ticks;      // osd_ticks the last call to throttle
153   attotime         m_throttle_realtime;      // real time the last call to throttle
154   attotime         m_throttle_emutime;         // emulated time the last call to throttle
155   UINT32            m_throttle_history;         // history of frames where we were fast enough
217156
218   static TIMER_CALLBACK( static_scanline_update_callback ) { reinterpret_cast<screen_device *>(ptr)->scanline_update_callback(param); }
219   void scanline_update_callback(int scanline);
157   // dynamic speed computation
158   osd_ticks_t       m_speed_last_realtime;      // real time at the last speed calculation
159   attotime         m_speed_last_emutime;      // emulated time at the last speed calculation
160   double            m_speed_percent;         // most recent speed percentage
220161
221   void finalize_burnin();
222   void load_effect_overlay(const char *filename);
162   // overall speed computation
163   UINT32            m_overall_real_seconds;      // accumulated real seconds at normal speed
164   osd_ticks_t         m_overall_real_ticks;      // accumulated real ticks at normal speed
165   attotime         m_overall_emutime;         // accumulated emulated time at normal speed
166   UINT32            m_overall_valid_counter;   // number of consecutive valid time periods
223167
224   // internal state
225   const screen_device_config &m_config;
226   render_container *      m_container;         // pointer to our container
168   // configuration
169   bool            m_throttle;               // flag: TRUE if we're currently throttled
170   bool            m_fastforward;            // flag: TRUE if we're currently fast-forwarding
171   UINT32            m_seconds_to_run;         // number of seconds to run before quitting
172   bool            m_auto_frameskip;         // flag: TRUE if we're automatically frameskipping
173   UINT32            m_speed;               // overall speed (*100)
227174
228   // dimensions
229   int                  m_width;            // current width (HTOTAL)
230   int                  m_height;            // current height (VTOTAL)
231   rectangle            m_visarea;            // current visible area (HBLANK end/start, VBLANK end/start)
175   // frameskipping
176   UINT8            m_empty_skip_count;         // number of empty frames we have skipped
177   UINT8            m_frameskip_level;         // current frameskip level
178   UINT8            m_frameskip_counter;      // counter that counts through the frameskip steps
179   INT8            m_frameskip_adjust;
180   bool            m_skipping_this_frame;      // flag: TRUE if we are skipping the current frame
181   osd_ticks_t         m_average_oversleep;      // average number of ticks the OSD oversleeps
232182
233   // textures and bitmaps
234   render_texture *      m_texture[2];         // 2x textures for the screen bitmap
235   bitmap_t *            m_bitmap[2];         // 2x bitmaps for rendering
236   bitmap_t *            m_burnin;            // burn-in bitmap
237   UINT8               m_curbitmap;         // current bitmap index
238   UINT8               m_curtexture;         // current texture index
239   INT32               m_texture_format;      // texture format of bitmap for this screen
240   bool               m_changed;            // has this bitmap changed?
241   INT32               m_last_partial_scan;   // scanline of last partial update
242   bitmap_t *            m_screen_overlay_bitmap;// screen overlay bitmap
183   // snapshot stuff
184   render_target *      m_snap_target;            // screen shapshot target
185   bitmap_t *         m_snap_bitmap;            // screen snapshot bitmap
186   bool            m_snap_native;            // are we using native per-screen layouts?
187   INT32            m_snap_width;            // width of snapshots (0 == auto)
188   INT32            m_snap_height;            // height of snapshots (0 == auto)
243189
244   // screen timing
245   attoseconds_t         m_frame_period;         // attoseconds per frame
246   attoseconds_t         m_scantime;            // attoseconds per scanline
247   attoseconds_t         m_pixeltime;         // attoseconds per pixel
248   attoseconds_t         m_vblank_period;      // attoseconds per VBLANK period
249   attotime            m_vblank_start_time;   // time of last VBLANK start
250   attotime            m_vblank_end_time;      // time of last VBLANK end
251   emu_timer *            m_vblank_begin_timer;   // timer to signal VBLANK start
252   emu_timer *            m_vblank_end_timer;      // timer to signal VBLANK end
253   emu_timer *            m_scanline0_timer;      // scanline 0 timer
254   emu_timer *            m_scanline_timer;      // scanline timer
255   UINT64               m_frame_number;         // the current frame number
190   // movie recording
191   mame_file *         m_mngfile;               // handle to the open movie file
192   avi_file *         m_avifile;               // handle to the open movie file
193   attotime         m_movie_frame_period;      // period of a single movie frame
194   attotime         m_movie_next_frame_time;   // time of next frame
195   UINT32            m_movie_frame;            // current movie frame number
196   
197   static const UINT8      s_skiptable[FRAMESKIP_LEVELS][FRAMESKIP_LEVELS];
256198
257   struct callback_item
258   {
259      callback_item *            m_next;
260      vblank_state_changed_func   m_callback;
261      void *                  m_param;
262   };
263   callback_item *         m_callback_list;      // list of VBLANK callbacks
199   static const attoseconds_t SUBSECONDS_PER_SPEED_UPDATE = ATTOSECONDS_PER_SECOND / 4;
200   static const int PAUSED_REFRESH_RATE = 30;
264201};
265202
266203
267// device type definition
268extern const device_type SCREEN;
269204
205// ----- debugging helpers -----
270206
271
272//**************************************************************************
273//  SCREEN DEVICE CONFIGURATION MACROS
274//**************************************************************************
275
276#define MDRV_SCREEN_ADD(_tag, _type) \
277   MDRV_DEVICE_ADD(_tag, SCREEN, 0) \
278   MDRV_SCREEN_TYPE(_type) \
279
280#define MDRV_SCREEN_MODIFY(_tag) \
281   MDRV_DEVICE_MODIFY(_tag)
282
283#define MDRV_SCREEN_FORMAT(_format) \
284   screen_device_config::static_set_format(device, _format); \
285
286#define MDRV_SCREEN_TYPE(_type) \
287   screen_device_config::static_set_type(device, SCREEN_TYPE_##_type); \
288
289#define MDRV_SCREEN_RAW_PARAMS(_pixclock, _htotal, _hbend, _hbstart, _vtotal, _vbend, _vbstart) \
290   screen_device_config::static_set_raw(device, _pixclock, _htotal, _hbend, _hbstart, _vtotal, _vbend, _vbstart);
291
292#define MDRV_SCREEN_REFRESH_RATE(_rate) \
293   screen_device_config::static_set_refresh(device, HZ_TO_ATTOSECONDS(_rate)); \
294
295#define MDRV_SCREEN_VBLANK_TIME(_time) \
296   screen_device_config::static_set_vblank_time(device, _time); \
297
298#define MDRV_SCREEN_SIZE(_width, _height) \
299   screen_device_config::static_set_size(device, _width, _height); \
300
301#define MDRV_SCREEN_VISIBLE_AREA(_minx, _maxx, _miny, _maxy) \
302   screen_device_config::static_set_visarea(device, _minx, _maxx, _miny, _maxy); \
303
304#define MDRV_SCREEN_DEFAULT_POSITION(_xscale, _xoffs, _yscale, _yoffs)   \
305   screen_device_config::static_set_default_position(device, _xscale, _xoffs, _yscale, _yoffs); \
306
307
308
309//**************************************************************************
310//  FUNCTION PROTOTYPES
311//**************************************************************************
312
313/* ----- core implementation ----- */
314
315/* core initialization */
316void video_init(running_machine *machine);
317
318
319/* ----- global rendering ----- */
320
321/* update the screen, handling frame skipping and rendering */
322void video_frame_update(running_machine *machine, int debug);
323
324
325/* ----- throttling/frameskipping/performance ----- */
326
327/* are we skipping the current frame? */
328int video_skip_this_frame(void);
329
330/* get/set the speed factor as an integer * 100 */
331int video_get_speed_factor(void);
332void video_set_speed_factor(int speed);
333
334/* return text to display about the current speed */
335const char *video_get_speed_text(running_machine *machine);
336
337/* return the current effective speed percentage */
338double video_get_speed_percent(running_machine *machine);
339
340/* get/set the current frameskip (-1 means auto) */
341int video_get_frameskip(void);
342void video_set_frameskip(int frameskip);
343
344/* get/set the current throttle */
345int video_get_throttle(void);
346void video_set_throttle(int throttle);
347
348/* get/set the current fastforward state */
349int video_get_fastforward(void);
350void video_set_fastforward(int fastforward);
351
352
353/* ----- snapshots ----- */
354
355/* save a snapshot of a given screen */
356void screen_save_snapshot(running_machine *machine, device_t *screen, mame_file *fp);
357
358/* save a snapshot of all the active screens */
359void video_save_active_screen_snapshots(running_machine *machine);
360
361
362/* ----- movie recording ----- */
363
364int video_mng_is_movie_active(running_machine *machine);
365void video_mng_begin_recording(running_machine *machine, const char *name);
366void video_mng_end_recording(running_machine *machine);
367
368void video_avi_begin_recording(running_machine *machine, const char *name);
369void video_avi_end_recording(running_machine *machine);
370void video_avi_add_sound(running_machine *machine, const INT16 *sound, int numsamples);
371
372
373/* ----- configuration helpers ----- */
374
375/* select a view for a given target */
376int video_get_view_for_target(running_machine *machine, render_target *target, const char *viewname, int targetindex, int numtargets);
377
378
379/* ----- debugging helpers ----- */
380
381/* assert if any pixels in the given bitmap contain an invalid palette index */
207// assert if any pixels in the given bitmap contain an invalid palette index
382208void video_assert_out_of_range_pixels(running_machine *machine, bitmap_t *bitmap);
383209
384210
385
386//**************************************************************************
387//  INLINE HELPERS
388//**************************************************************************
389
390//-------------------------------------------------
391//  screen_count - return the number of
392//  video screen devices in a machine_config
393//-------------------------------------------------
394
395inline int screen_count(const machine_config &config)
396{
397   return config.m_devicelist.count(SCREEN);
398}
399
400
401//-------------------------------------------------
402//  screen_first - return the first
403//  video screen device config in a machine_config
404//-------------------------------------------------
405
406inline const screen_device_config *screen_first(const machine_config &config)
407{
408   return downcast<screen_device_config *>(config.m_devicelist.first(SCREEN));
409}
410
411
412//-------------------------------------------------
413//  screen_next - return the next
414//  video screen device config in a machine_config
415//-------------------------------------------------
416
417inline const screen_device_config *screen_next(const screen_device_config *previous)
418{
419   return downcast<screen_device_config *>(previous->typenext());
420}
421
422
423//-------------------------------------------------
424//  screen_count - return the number of
425//  video screen devices in a machine
426//-------------------------------------------------
427
428inline int screen_count(running_machine &machine)
429{
430   return machine.m_devicelist.count(SCREEN);
431}
432
433
434//-------------------------------------------------
435//  screen_first - return the first
436//  video screen device in a machine
437//-------------------------------------------------
438
439inline screen_device *screen_first(running_machine &machine)
440{
441   return downcast<screen_device *>(machine.m_devicelist.first(SCREEN));
442}
443
444
445//-------------------------------------------------
446//  screen_next - return the next
447//  video screen device in a machine
448//-------------------------------------------------
449
450inline screen_device *screen_next(screen_device *previous)
451{
452   return downcast<screen_device *>(previous->typenext());
453}
454
455
456211#endif   /* __VIDEO_H__ */
src/emu/inptport.c
r9718r9719
46674667      record_write_uint64(machine, curtime.attoseconds);
46684668
46694669      /* then the current speed */
4670      record_write_uint32(machine, video_get_speed_percent(machine) * (double)(1 << 20));
4670      record_write_uint32(machine, machine->video().speed_percent() * (double)(1 << 20));
46714671   }
46724672}
46734673
src/emu/emu.h
r9718r9719
121121#include "drawgfx.h"
122122#include "tilemap.h"
123123#include "emupal.h"
124#include "screen.h"
124125#include "video.h"
125126
126127// sound-related
src/emu/rendlay.c
r9718r9719
193193   char temp[100];
194194
195195   // screen 0 parameters
196   for (const screen_device_config *devconfig = screen_first(machine.m_config); devconfig != NULL; devconfig = screen_next(devconfig))
196   for (const screen_device_config *devconfig = machine.m_config.first_screen(); devconfig != NULL; devconfig = devconfig->next_screen())
197197   {
198198      int scrnum = machine.m_config.m_devicelist.index(SCREEN, devconfig->tag());
199199
src/emu/machine.c
r9718r9719
192192     m_driver_device(NULL),
193193     m_cheat(NULL),
194194     m_render(NULL),
195     m_video(NULL),
195196     m_debug_view(NULL)
196197{
197198   memset(gfx, 0, sizeof(gfx));
r9718r9719
210211   assert(m_driver_device != NULL);
211212
212213   // find devices
213   primary_screen = screen_first(*this);
214   primary_screen = downcast<screen_device *>(m_devicelist.first(SCREEN));
214215   for (device_t *device = m_devicelist.first(); device != NULL; device = device->next())
215216      if (dynamic_cast<cpu_device *>(device) != NULL)
216217      {
r9718r9719
230231
231232running_machine::~running_machine()
232233{
233   /* clear flag for added devices */
234   // clear flag for added devices
234235   options_set_bool(&m_options, OPTION_ADDED_DEVICE_OPTIONS, FALSE, OPTION_PRIORITY_CMDLINE);
235236}
236237
r9718r9719
285286
286287   // init the osd layer
287288   m_osd.init(*this);
289
290   // create the video manager
291   m_video = auto_alloc(this, video_manager(*this));
288292   ui_init(this);
289293
290294   // initialize the base time (needed for doing record/playback)
r9718r9719
320324   tilemap_init(this);
321325   crosshair_init(this);
322326   sound_init(this);
323   video_init(this);
324327
325328   // initialize the debugger
326329   if ((debug_flags & DEBUG_FLAG_ENABLED) != 0)
r9718r9719
399402
400403         // otherwise, just pump video updates through
401404         else
402            video_frame_update(this, false);
405            m_video->frame_update();
403406
404407         // handle save/load
405408         if (m_saveload_schedule != SLS_NONE)
src/emu/machine.h
r9718r9719
182182class colortable_t;
183183class cheat_manager;
184184class render_manager;
185class video_manager;
185186class debug_view_manager;
186187class osd_interface;
187188
r9718r9719
362363   const char *new_driver_name() const { return m_new_driver_pending->name; }
363364   device_scheduler &scheduler() { return m_scheduler; }
364365   osd_interface &osd() const { return m_osd; }
366   screen_device *first_screen() const { return primary_screen; }
365367
366368   // immediate operations
367369   int run(bool firstrun);
r9718r9719
390392   // managers
391393   cheat_manager &cheat() const { assert(m_cheat != NULL); return *m_cheat; }
392394   render_manager &render() const { assert(m_render != NULL); return *m_render; }
395   video_manager &video() const { assert(m_video != NULL); return *m_video; }
393396   debug_view_manager &debug_view() const { assert(m_debug_view != NULL); return *m_debug_view; }
394397
395398   // misc
r9718r9719
530533   driver_device *         m_driver_device;
531534   cheat_manager *         m_cheat;         // internal data from cheat.c
532535   render_manager *      m_render;         // internal data from render.c
536   video_manager *         m_video;         // internal data from video.c
533537   debug_view_manager *   m_debug_view;      // internal data from debugvw.c
534538};
535539
src/emu/ui.c
r9718r9719
324324
325325      /* loop while we have a handler */
326326      while (ui_handler_callback != handler_ingame && !machine->scheduled_event_pending() && !ui_menu_is_force_game_select())
327         video_frame_update(machine, FALSE);
327         machine->video().frame_update();
328328
329329      /* clear the handler and force an update */
330330      ui_set_handler(handler_ingame, 0);
331      video_frame_update(machine, FALSE);
331      machine->video().frame_update();
332332   }
333333
334334   /* if we're the empty driver, force the menus on */
r9718r9719
357357   if (force || (curtime - lastupdatetime) > osd_ticks_per_second() / 4)
358358   {
359359      lastupdatetime = curtime;
360      video_frame_update(machine, FALSE);
360      machine->video().frame_update();
361361   }
362362}
363363
r9718r9719
10001000
10011001astring &game_info_astring(running_machine *machine, astring &string)
10021002{
1003   int scrcount = screen_count(*machine->config);
1003   int scrcount = machine->m_devicelist.count(SCREEN);
10041004   int found_sound = FALSE;
10051005
10061006   /* print description, manufacturer, and CPU: */
r9718r9719
10771077      string.cat("None\n");
10781078   else
10791079   {
1080      for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
1080      for (screen_device *screen = machine->first_screen(); screen != NULL; screen = screen->next_screen())
10811081      {
10821082         if (scrcount > 1)
10831083         {
r9718r9719
12951295   /* first draw the FPS counter */
12961296   if (showfps || osd_ticks() < showfps_end)
12971297   {
1298      ui_draw_text_full(container, video_get_speed_text(machine), 0.0f, 0.0f, 1.0f,
1298      astring tempstring;
1299      ui_draw_text_full(container, machine->video().speed_text(tempstring), 0.0f, 0.0f, 1.0f,
12991300               JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, ARGB_WHITE, ARGB_BLACK, NULL, NULL);
13001301   }
13011302   else
r9718r9719
14091410
14101411   /* handle a save snapshot request */
14111412   if (ui_input_pressed(machine, IPT_UI_SNAPSHOT))
1412      video_save_active_screen_snapshots(machine);
1413      machine->video().save_active_screen_snapshots();
14131414
14141415   /* toggle pause */
14151416   if (ui_input_pressed(machine, IPT_UI_PAUSE))
r9718r9719
14331434   /* toggle movie recording */
14341435   if (ui_input_pressed(machine, IPT_UI_RECORD_MOVIE))
14351436   {
1436      if (!video_mng_is_movie_active(machine))
1437      if (!machine->video().is_recording())
14371438      {
1438         video_mng_begin_recording(machine, NULL);
1439         machine->video().begin_recording(NULL, video_manager::MF_MNG);
14391440         popmessage("REC START");
14401441      }
14411442      else
14421443      {
1443         video_mng_end_recording(machine);
1444         machine->video().end_recording();
14441445         popmessage("REC STOP");
14451446      }
14461447   }
r9718r9719
14571458   if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_INC))
14581459   {
14591460      /* get the current value and increment it */
1460      int newframeskip = video_get_frameskip() + 1;
1461      int newframeskip = machine->video().frameskip() + 1;
14611462      if (newframeskip > MAX_FRAMESKIP)
14621463         newframeskip = -1;
1463      video_set_frameskip(newframeskip);
1464      machine->video().set_frameskip(newframeskip);
14641465
14651466      /* display the FPS counter for 2 seconds */
14661467      ui_show_fps_temp(2.0);
r9718r9719
14701471   if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_DEC))
14711472   {
14721473      /* get the current value and decrement it */
1473      int newframeskip = video_get_frameskip() - 1;
1474      int newframeskip = machine->video().frameskip() - 1;
14741475      if (newframeskip < -1)
14751476         newframeskip = MAX_FRAMESKIP;
1476      video_set_frameskip(newframeskip);
1477      machine->video().set_frameskip(newframeskip);
14771478
14781479      /* display the FPS counter for 2 seconds */
14791480      ui_show_fps_temp(2.0);
r9718r9719
14811482
14821483   /* toggle throttle? */
14831484   if (ui_input_pressed(machine, IPT_UI_THROTTLE))
1484      video_set_throttle(!video_get_throttle());
1485      machine->video().set_throttled(!machine->video().throttled());
14851486
14861487   /* check for fast forward */
14871488   if (input_type_pressed(machine, IPT_UI_FAST_FORWARD, 0))
14881489   {
1489      video_set_fastforward(TRUE);
1490      machine->video().set_fastforward(true);
14901491      ui_show_fps_temp(0.5);
14911492   }
14921493   else
1493      video_set_fastforward(FALSE);
1494      machine->video().set_fastforward(false);
14941495
14951496   return 0;
14961497}
r9718r9719
16591660   }
16601661
16611662   /* add screen parameters */
1662   for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
1663   for (screen_device *screen = machine->first_screen(); screen != NULL; screen = screen->next_screen())
16631664   {
16641665      int defxscale = floor(screen->config().xscale() * 1000.0f + 0.5f);
16651666      int defyscale = floor(screen->config().yscale() * 1000.0f + 0.5f);
r9718r9719
17281729      }
17291730   }
17301731
1731   for (screen_device *screen = screen_first(*machine); screen != NULL; screen = screen_next(screen))
1732   for (screen_device *screen = machine->first_screen(); screen != NULL; screen = screen->next_screen())
17321733      if (screen->screen_type() == SCREEN_TYPE_VECTOR)
17331734      {
17341735         /* add flicker control */
r9718r9719
21292130
21302131static char *slider_get_screen_desc(screen_device &screen)
21312132{
2132   int scrcount = screen_count(*screen.machine->config);
2133   int scrcount = screen.machine->m_devicelist.count(SCREEN);
21332134   static char descbuf[256];
21342135
21352136   if (scrcount > 1)
src/emu/render.c
r9718r9719
11521152
11531153
11541154//-------------------------------------------------
1155//  configured_view - select a view for this
1156//  target based on the configuration parameters
1157//-------------------------------------------------
1158
1159int render_target::configured_view(const char *viewname, int targetindex, int numtargets)
1160{
1161   layout_view *view = NULL;
1162   int viewindex;
1163
1164   // auto view just selects the nth view
1165   if (strcmp(viewname, "auto") != 0)
1166   {
1167      // scan for a matching view name
1168      for (view = view_by_index(viewindex = 0); view != NULL; view = view_by_index(++viewindex))
1169         if (mame_strnicmp(view->name(), viewname, strlen(viewname)) == 0)
1170            break;
1171   }
1172
1173   // if we don't have a match, default to the nth view
1174   int scrcount = m_manager.machine().m_devicelist.count(SCREEN);
1175   if (view == NULL && scrcount > 0)
1176   {
1177      // if we have enough targets to be one per screen, assign in order
1178      if (numtargets >= scrcount)
1179      {
1180         int ourindex = index() % scrcount;
1181         screen_device *screen;
1182         for (screen = m_manager.machine().first_screen(); screen != NULL; screen = screen->next_screen())
1183            if (ourindex-- == 0)
1184               break;
1185
1186         // find the first view with this screen and this screen only
1187         for (view = view_by_index(viewindex = 0); view != NULL; view = view_by_index(++viewindex))
1188         {
1189            const render_screen_list &viewscreens = view->screens();
1190            if (viewscreens.count() == 1 && viewscreens.contains(*screen))
1191               break;
1192            if (viewscreens.count() == 0)
1193            {
1194               view = NULL;
1195               break;
1196            }
1197         }
1198      }
1199
1200      // otherwise, find the first view that has all the screens
1201      if (view == NULL)
1202      {
1203         for (view = view_by_index(viewindex = 0); view != NULL; view = view_by_index(++viewindex))
1204         {
1205            const render_screen_list &viewscreens = view->screens();
1206            if (viewscreens.count() == 0)
1207               break;
1208            if (viewscreens.count() >= scrcount)
1209            {
1210               screen_device *screen;
1211               for (screen = m_manager.machine().first_screen(); screen != NULL; screen = screen->next_screen())
1212                  if (!viewscreens.contains(*screen))
1213                     break;
1214               if (screen == NULL)
1215                  break;
1216            }
1217         }
1218      }
1219   }
1220
1221   // make sure it's a valid view
1222   return (view != NULL) ? view_index(*view) : 0;
1223}
1224
1225
1226//-------------------------------------------------
11551227//  view_name - return the name of the given view
11561228//-------------------------------------------------
11571229
r9718r9719
15481620         load_layout_file(cloneof->name, "default");
15491621
15501622   // now do the built-in layouts for single-screen games
1551   if (screen_count(m_manager.machine().m_config) == 1)
1623   if (m_manager.machine().m_devicelist.count(SCREEN) == 1)
15521624   {
15531625      if (gamedrv->flags & ORIENTATION_SWAP_XY)
15541626         load_layout_file(NULL, layout_vertical);
r9718r9719
23662438   config_register(&machine, "video", config_load_static, config_save_static);
23672439
23682440   // create one container per screen
2369   for (screen_device *screen = screen_first(machine); screen != NULL; screen = screen_next(screen))
2441   for (screen_device *screen = machine.first_screen(); screen != NULL; screen = screen->next_screen())
23702442      screen->set_container(*container_alloc(screen));
23712443}
23722444
src/emu/emupal.c
r9718r9719
9797void palette_init(running_machine *machine)
9898{
9999   palette_private *palette = auto_alloc_clear(machine, palette_private);
100   screen_device *device = screen_first(*machine);
100   screen_device *device = machine->first_screen();
101101
102102   /* get the format from the first screen, or use BITMAP_FORMAT_INVALID, if screenless */
103103   bitmap_format format = (device != NULL) ? device->format() : BITMAP_FORMAT_INVALID;
src/emu/render.h
r9718r9719
627627   void set_screen_overlay_enabled(bool enable) { m_layerconfig.set_screen_overlay_enabled(enable); update_layer_config(); }
628628   void set_zoom_to_screen(bool zoom) { m_layerconfig.set_zoom_to_screen(zoom); update_layer_config(); }
629629
630   // view configuration helper
631   int configured_view(const char *viewname, int targetindex, int numtargets);
632
630633   // view information
631634   const char *view_name(int viewindex);
632635   const render_screen_list &view_screens(int viewindex);
src/emu/validity.c
r9718r9719
586586   bool palette_modes = false;
587587   bool error = false;
588588
589   for (const screen_device_config *scrconfig = screen_first(config); scrconfig != NULL; scrconfig = screen_next(scrconfig))
589   for (const screen_device_config *scrconfig = config.first_screen(); scrconfig != NULL; scrconfig = scrconfig->next_screen())
590590      if (scrconfig->format() == BITMAP_FORMAT_INDEXED16)
591591         palette_modes = true;
592592
src/emu/state.h
r9718r9719
5656#define STATE_POSTLOAD(name) void name(running_machine *machine, void *param)
5757
5858
59template<class T, void (T::*func)()>
60void state_presave_stub(running_machine *machine, void *param)
61{
62   T *target = reinterpret_cast<T *>(param);
63   (target->*func)();
64}
65
66template<class T, void (T::*func)()>
67void state_postload_stub(running_machine *machine, void *param)
68{
69   T *target = reinterpret_cast<T *>(param);
70   (target->*func)();
71}
72
73
5974#ifdef __GNUC__
6075#define IS_VALID_SAVE_TYPE(_var) \
6176   (std::tr1::is_arithmetic<typeof(_var)>::value || std::tr1::is_enum<typeof(_var)>::value || \
src/emu/info.c
r9718r9719
726726   const screen_device_config *devconfig;
727727
728728   /* iterate over screens */
729   for (devconfig = screen_first(config); devconfig != NULL; devconfig = screen_next(devconfig))
729   for (devconfig = config.first_screen(); devconfig != NULL; devconfig = devconfig->next_screen())
730730   {
731731      fprintf(out, "\t\t<display");
732732
src/emu/emu.mak
r9718r9719
8989   $(EMUOBJ)/rendutil.o \
9090   $(EMUOBJ)/romload.o \
9191   $(EMUOBJ)/schedule.o \
92   $(EMUOBJ)/screen.o \
9293   $(EMUOBJ)/softlist.o \
9394   $(EMUOBJ)/sound.o \
9495   $(EMUOBJ)/state.o \
src/emu/mame.c
r9718r9719
529529      /* parse "vector.ini" for vector games */
530530      {
531531         machine_config config(*driver);
532         for (const screen_device_config *devconfig = screen_first(config); devconfig != NULL; devconfig = screen_next(devconfig))
532         for (const screen_device_config *devconfig = config.first_screen(); devconfig != NULL; devconfig = devconfig->next_screen())
533533            if (devconfig->screen_type() == SCREEN_TYPE_VECTOR)
534534            {
535535               parse_ini_file(options, "vector", OPTION_PRIORITY_VECTOR_INI);
src/emu/machine/i2cmem.c
r9718r9719
367367         {
368368            verboselog( this, 1, "stop\n" );
369369            m_state = STATE_IDLE;
370            m_byteaddr = 0;
371370         }
372371         else
373372         {
r9718r9719
570569
571570int i2cmem_device::read_sda_line()
572571{
573   int res = m_sdar & m_sdaw & 1;
572   int res = m_sdar & 1;
574573
575574   verboselog( this, 2, "read sda %d\n", res );
576575
r9718r9719
584583
585584int i2cmem_device::address_mask()
586585{
587   return ( 1 << m_config.m_address_bits ) - 1;
586   return (m_config.m_data_size - 1);
588587}
589588
590589int i2cmem_device::select_device()
src/emu/diexec.c
r9718r9719
219219   /* validate the interrupts */
220220   if (m_vblank_interrupt != NULL)
221221   {
222      if (screen_count(m_machine_config) == 0)
222      if (m_machine_config.m_devicelist.count(SCREEN) == 0)
223223      {
224224         mame_printf_error("%s: %s device '%s' has a VBLANK interrupt, but the driver is screenless!\n", driver.source_file, driver.name, devconfig->tag());
225225         error = true;
r9718r9719
629629
630630      // old style 'hack' setup - use screen #0
631631      else
632         screen = screen_first(m_machine);
632         screen = m_machine.first_screen();
633633
634634      assert(screen != NULL);
635635      screen->register_vblank_callback(static_on_vblank, NULL);
src/emu/screen.c
r0r9719
1/***************************************************************************
2 
3    screen.c
4 
5    Core MAME screen device.
6 
7****************************************************************************
8 
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 
38***************************************************************************/
39 
40#include "emu.h"
41#include "emuopts.h"
42#include "png.h"
43#include "rendutil.h"
44 
45 
46 
47//**************************************************************************
48//  DEBUGGING
49//**************************************************************************
50 
51#define VERBOSE                  (0)
52#define LOG_PARTIAL_UPDATES(x)      do { if (VERBOSE) logerror x; } while (0)
53 
54 
55 
56//**************************************************************************
57//  GLOBAL VARIABLES
58//**************************************************************************
59 
60const device_type SCREEN = screen_device_config::static_alloc_device_config;
61 
62const attotime screen_device::DEFAULT_FRAME_PERIOD = STATIC_ATTOTIME_IN_HZ(DEFAULT_FRAME_RATE);
63 
64 
65 
66//**************************************************************************
67//  SCREEN DEVICE CONFIGURATION
68//**************************************************************************
69 
70//-------------------------------------------------
71//  screen_device_config - constructor
72//-------------------------------------------------
73 
74screen_device_config::screen_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
75   : device_config(mconfig, static_alloc_device_config, "Video Screen", tag, owner, clock),
76     m_type(SCREEN_TYPE_RASTER),
77     m_width(0),
78     m_height(0),
79     m_oldstyle_vblank_supplied(false),
80     m_refresh(0),
81     m_vblank(0),
82     m_format(BITMAP_FORMAT_INVALID),
83     m_xoffset(0.0f),
84     m_yoffset(0.0f),
85     m_xscale(1.0f),
86     m_yscale(1.0f)
87{
88}
89 
90 
91//-------------------------------------------------
92//  static_alloc_device_config - allocate a new
93//  configuration object
94//-------------------------------------------------
95 
96device_config *screen_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
97{
98   return global_alloc(screen_device_config(mconfig, tag, owner, clock));
99}
100 
101 
102//-------------------------------------------------
103//  alloc_device - allocate a new device object
104//-------------------------------------------------
105 
106device_t *screen_device_config::alloc_device(running_machine &machine) const
107{
108   return auto_alloc(&machine, screen_device(machine, *this));
109}
110 
111 
112//-------------------------------------------------
113//  static_set_format - configuration helper
114//  to set the bitmap format
115//-------------------------------------------------
116 
117void screen_device_config::static_set_format(device_config *device, bitmap_format format)
118{
119   screen_device_config *screen = downcast<screen_device_config *>(device);
120   screen->m_format = format;
121}
122 
123 
124//-------------------------------------------------
125//  static_set_type - configuration helper
126//  to set the screen type
127//-------------------------------------------------
128 
129void screen_device_config::static_set_type(device_config *device, screen_type_enum type)
130{
131   screen_device_config *screen = downcast<screen_device_config *>(device);
132   screen->m_type = type;
133}
134 
135 
136//-------------------------------------------------
137//  static_set_raw - configuration helper
138//  to set the raw screen parameters
139//-------------------------------------------------
140 
141void screen_device_config::static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart)
142{
143   screen_device_config *screen = downcast<screen_device_config *>(device);
144   screen->m_refresh = HZ_TO_ATTOSECONDS(pixclock) * htotal * vtotal;
145   screen->m_vblank = screen->m_refresh / vtotal * (vtotal - (vbstart - vbend));
146   screen->m_width = htotal;
147   screen->m_height = vtotal;
148   screen->m_visarea.min_x = hbend;
149   screen->m_visarea.max_x = hbstart - 1;
150   screen->m_visarea.min_y = vbend;
151   screen->m_visarea.max_y = vbstart - 1;
152}
153 
154 
155//-------------------------------------------------
156//  static_set_refresh - configuration helper
157//  to set the refresh rate
158//-------------------------------------------------
159 
160void screen_device_config::static_set_refresh(device_config *device, attoseconds_t rate)
161{
162   screen_device_config *screen = downcast<screen_device_config *>(device);
163   screen->m_refresh = rate;
164}
165 
166 
167//-------------------------------------------------
168//  static_set_vblank_time - configuration helper
169//  to set the VBLANK duration
170//-------------------------------------------------
171 
172void screen_device_config::static_set_vblank_time(device_config *device, attoseconds_t time)
173{
174   screen_device_config *screen = downcast<screen_device_config *>(device);
175   screen->m_vblank = time;
176   screen->m_oldstyle_vblank_supplied = true;
177}
178 
179 
180//-------------------------------------------------
181//  static_set_size - configuration helper to set
182//  the width/height of the screen
183//-------------------------------------------------
184 
185void screen_device_config::static_set_size(device_config *device, UINT16 width, UINT16 height)
186{
187   screen_device_config *screen = downcast<screen_device_config *>(device);
188   screen->m_width = width;
189   screen->m_height = height;
190}
191 
192 
193//-------------------------------------------------
194//  static_set_visarea - configuration helper to
195//  set the visible area of the screen
196//-------------------------------------------------
197 
198void screen_device_config::static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy)
199{
200   screen_device_config *screen = downcast<screen_device_config *>(device);
201   screen->m_visarea.min_x = minx;
202   screen->m_visarea.max_x = maxx;
203   screen->m_visarea.min_y = miny;
204   screen->m_visarea.max_y = maxy;
205}
206 
207 
208//-------------------------------------------------
209//  static_set_default_position - configuration
210//  helper to set the default position and scale
211//  factors for the screen
212//-------------------------------------------------
213 
214void screen_device_config::static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs)
215{
216   screen_device_config *screen = downcast<screen_device_config *>(device);
217   screen->m_xscale = xscale;
218   screen->m_xoffset = xoffs;
219   screen->m_yscale = yscale;
220   screen->m_yoffset = yoffs;
221}
222 
223 
224//-------------------------------------------------
225//  device_validity_check - verify device
226//  configuration
227//-------------------------------------------------
228 
229bool screen_device_config::device_validity_check(const game_driver &driver) const
230{
231   bool error = false;
232 
233   // sanity check dimensions
234   if (m_width <= 0 || m_height <= 0)
235   {
236      mame_printf_error("%s: %s screen '%s' has invalid display dimensions\n", driver.source_file, driver.name, tag());
237      error = true;
238   }
239 
240   // sanity check display area
241   if (m_type != SCREEN_TYPE_VECTOR)
242   {
243      if ((m_visarea.max_x < m_visarea.min_x) ||
244         (m_visarea.max_y < m_visarea.min_y) ||
245         (m_visarea.max_x >= m_width) ||
246         (m_visarea.max_y >= m_height))
247      {
248         mame_printf_error("%s: %s screen '%s' has an invalid display area\n", driver.source_file, driver.name, tag());
249         error = true;
250      }
251 
252      // sanity check screen formats
253      if (m_format != BITMAP_FORMAT_INDEXED16 &&
254         m_format != BITMAP_FORMAT_RGB15 &&
255         m_format != BITMAP_FORMAT_RGB32)
256      {
257         mame_printf_error("%s: %s screen '%s' has unsupported format\n", driver.source_file, driver.name, tag());
258         error = true;
259      }
260   }
261 
262   // check for zero frame rate
263   if (m_refresh == 0)
264   {
265      mame_printf_error("%s: %s screen '%s' has a zero refresh rate\n", driver.source_file, driver.name, tag());
266      error = true;
267   }
268   return error;
269}
270 
271 
272 
273//**************************************************************************
274//  SCREEN DEVICE
275//**************************************************************************
276 
277//-------------------------------------------------
278//  screen_device - constructor
279//-------------------------------------------------
280 
281screen_device::screen_device(running_machine &_machine, const screen_device_config &config)
282   : device_t(_machine, config),
283     m_config(config),
284     m_container(NULL),
285     m_width(m_config.m_width),
286     m_height(m_config.m_height),
287     m_visarea(m_config.m_visarea),
288     m_burnin(NULL),
289     m_curbitmap(0),
290     m_curtexture(0),
291     m_texture_format(0),
292     m_changed(true),
293     m_last_partial_scan(0),
294     m_screen_overlay_bitmap(NULL),
295     m_frame_period(m_config.m_refresh),
296     m_scantime(1),
297     m_pixeltime(1),
298     m_vblank_period(0),
299     m_vblank_start_time(attotime_zero),
300     m_vblank_end_time(attotime_zero),
301     m_vblank_begin_timer(NULL),
302     m_vblank_end_timer(NULL),
303     m_scanline0_timer(NULL),
304     m_scanline_timer(NULL),
305     m_frame_number(0),
306     m_partial_updates_this_frame(0),
307     m_callback_list(NULL)
308{
309   memset(m_texture, 0, sizeof(m_texture));
310   memset(m_bitmap, 0, sizeof(m_bitmap));
311}
312 
313 
314//-------------------------------------------------
315//  ~screen_device - destructor
316//-------------------------------------------------
317 
318screen_device::~screen_device()
319{
320   m_machine.render().texture_free(m_texture[0]);
321   m_machine.render().texture_free(m_texture[1]);
322   if (m_burnin != NULL)
323      finalize_burnin();
324   global_free(m_screen_overlay_bitmap);
325}
326 
327 
328//-------------------------------------------------
329//  device_start - device-specific startup
330//-------------------------------------------------
331 
332void screen_device::device_start()
333{
334   // configure the default cliparea
335   render_container::user_settings settings;
336   m_container->get_user_settings(settings);
337   settings.m_xoffset = m_config.m_xoffset;
338   settings.m_yoffset = m_config.m_yoffset;
339   settings.m_xscale = m_config.m_xscale;
340   settings.m_yscale = m_config.m_yscale;
341   m_container->set_user_settings(settings);
342 
343   // allocate the VBLANK timers
344   m_vblank_begin_timer = timer_alloc(machine, static_vblank_begin_callback, (void *)this);
345   m_vblank_end_timer = timer_alloc(machine, static_vblank_end_callback, (void *)this);
346 
347   // allocate a timer to reset partial updates
348   m_scanline0_timer = timer_alloc(machine, static_scanline0_callback, (void *)this);
349 
350   // allocate a timer to generate per-scanline updates
351   if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0)
352      m_scanline_timer = timer_alloc(machine, static_scanline_update_callback, (void *)this);
353 
354   // configure the screen with the default parameters
355   configure(m_config.m_width, m_config.m_height, m_config.m_visarea, m_config.m_refresh);
356 
357   // reset VBLANK timing
358   m_vblank_start_time = attotime_zero;
359   m_vblank_end_time = attotime_make(0, m_vblank_period);
360 
361   // start the timer to generate per-scanline updates
362   if ((machine->config->m_video_attributes & VIDEO_UPDATE_SCANLINE) != 0)
363      timer_adjust_oneshot(m_scanline_timer, time_until_pos(0), 0);
364 
365   // create burn-in bitmap
366   if (options_get_int(machine->options(), OPTION_BURNIN) > 0)
367   {
368      int width, height;
369      if (sscanf(options_get_string(machine->options(), OPTION_SNAPSIZE), "%dx%d", &width, &height) != 2 || width == 0 || height == 0)
370         width = height = 300;
371      m_burnin = auto_alloc(machine, bitmap_t(width, height, BITMAP_FORMAT_INDEXED64));
372      if (m_burnin == NULL)
373         fatalerror("Error allocating burn-in bitmap for screen at (%dx%d)\n", width, height);
374      bitmap_fill(m_burnin, NULL, 0);
375   }
376 
377   // load the effect overlay
378   const char *overname = options_get_string(machine->options(), OPTION_EFFECT);
379   if (overname != NULL && strcmp(overname, "none") != 0)
380      load_effect_overlay(overname);
381 
382   state_save_register_device_item(this, 0, m_width);
383   state_save_register_device_item(this, 0, m_height);
384   state_save_register_device_item(this, 0, m_visarea.min_x);
385   state_save_register_device_item(this, 0, m_visarea.min_y);
386   state_save_register_device_item(this, 0, m_visarea.max_x);
387   state_save_register_device_item(this, 0, m_visarea.max_y);
388   state_save_register_device_item(this, 0, m_last_partial_scan);
389   state_save_register_device_item(this, 0, m_frame_period);
390   state_save_register_device_item(this, 0, m_scantime);
391   state_save_register_device_item(this, 0, m_pixeltime);
392   state_save_register_device_item(this, 0, m_vblank_period);
393   state_save_register_device_item(this, 0, m_vblank_start_time.seconds);
394   state_save_register_device_item(this, 0, m_vblank_start_time.attoseconds);
395   state_save_register_device_item(this, 0, m_vblank_end_time.seconds);
396   state_save_register_device_item(this, 0, m_vblank_end_time.attoseconds);
397   state_save_register_device_item(this, 0, m_frame_number);
398}
399 
400 
401//-------------------------------------------------
402//  device_post_load - device-specific update
403//  after a save state is loaded
404//-------------------------------------------------
405 
406void screen_device::device_post_load()
407{
408   realloc_screen_bitmaps();
409}
410 
411 
412//-------------------------------------------------
413//  configure - configure screen parameters
414//-------------------------------------------------
415 
416void screen_device::configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period)
417{
418   // validate arguments
419   assert(width > 0);
420   assert(height > 0);
421   assert(visarea.min_x >= 0);
422   assert(visarea.min_y >= 0);
423   assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_x < width);
424   assert(m_config.m_type == SCREEN_TYPE_VECTOR || visarea.min_y < height);
425   assert(frame_period > 0);
426 
427   // fill in the new parameters
428   m_width = width;
429   m_height = height;
430   m_visarea = visarea;
431 
432   // reallocate bitmap if necessary
433   realloc_screen_bitmaps();
434 
435   // compute timing parameters
436   m_frame_period = frame_period;
437   m_scantime = frame_period / height;
438   m_pixeltime = frame_period / (height * width);
439 
440   // if there has been no VBLANK time specified in the MACHINE_DRIVER, compute it now
441    // from the visible area, otherwise just used the supplied value
442   if (m_config.m_vblank == 0 && !m_config.m_oldstyle_vblank_supplied)
443      m_vblank_period = m_scantime * (height - (visarea.max_y + 1 - visarea.min_y));
444   else
445      m_vblank_period = m_config.m_vblank;
446 
447   // if we are on scanline 0 already, reset the update timer immediately
448   // otherwise, defer until the next scanline 0
449   if (vpos() == 0)
450      timer_adjust_oneshot(m_scanline0_timer, attotime_zero, 0);
451   else
452      timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
453 
454   // start the VBLANK timer
455   timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
456 
457   // adjust speed if necessary
458   m_machine.video().update_refresh_speed();
459}
460 
461 
462//-------------------------------------------------
463//  reset_origin - reset the timing such that the
464//  given (x,y) occurs at the current time
465//-------------------------------------------------
466 
467void screen_device::reset_origin(int beamy, int beamx)
468{
469   // compute the effective VBLANK start/end times
470   attotime curtime = timer_get_time(machine);
471   m_vblank_end_time = attotime_sub_attoseconds(curtime, beamy * m_scantime + beamx * m_pixeltime);
472   m_vblank_start_time = attotime_sub_attoseconds(m_vblank_end_time, m_vblank_period);
473 
474   // if we are resetting relative to (0,0) == VBLANK end, call the
475   // scanline 0 timer by hand now; otherwise, adjust it for the future
476   if (beamy == 0 && beamx == 0)
477      scanline0_callback();
478   else
479      timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
480 
481   // if we are resetting relative to (visarea.max_y + 1, 0) == VBLANK start,
482   // call the VBLANK start timer now; otherwise, adjust it for the future
483   if (beamy == m_visarea.max_y + 1 && beamx == 0)
484      vblank_begin_callback();
485   else
486      timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
487}
488 
489 
490//-------------------------------------------------
491//  realloc_screen_bitmaps - reallocate bitmaps
492//  and textures as necessary
493//-------------------------------------------------
494 
495void screen_device::realloc_screen_bitmaps()
496{
497   if (m_config.m_type == SCREEN_TYPE_VECTOR)
498      return;
499 
500   int curwidth = 0, curheight = 0;
501 
502   // extract the current width/height from the bitmap
503   if (m_bitmap[0] != NULL)
504   {
505      curwidth = m_bitmap[0]->width;
506      curheight = m_bitmap[0]->height;
507   }
508 
509   // if we're too small to contain this width/height, reallocate our bitmaps and textures
510   if (m_width > curwidth || m_height > curheight)
511   {
512      // free what we have currently
513      m_machine.render().texture_free(m_texture[0]);
514      m_machine.render().texture_free(m_texture[1]);
515      auto_free(machine, m_bitmap[0]);
516      auto_free(machine, m_bitmap[1]);
517 
518      // compute new width/height
519      curwidth = MAX(m_width, curwidth);
520      curheight = MAX(m_height, curheight);
521 
522      // choose the texture format - convert the screen format to a texture format
523      palette_t *palette = NULL;
524      switch (m_config.m_format)
525      {
526         case BITMAP_FORMAT_INDEXED16:   m_texture_format = TEXFORMAT_PALETTE16;   palette = machine->palette;   break;
527         case BITMAP_FORMAT_RGB15:      m_texture_format = TEXFORMAT_RGB15;      palette = NULL;            break;
528         case BITMAP_FORMAT_RGB32:      m_texture_format = TEXFORMAT_RGB32;      palette = NULL;            break;
529         default:                  fatalerror("Invalid bitmap format!");                                    break;
530      }
531 
532      // allocate bitmaps
533      m_bitmap[0] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format));
534      bitmap_set_palette(m_bitmap[0], machine->palette);
535      m_bitmap[1] = auto_alloc(machine, bitmap_t(curwidth, curheight, m_config.m_format));
536      bitmap_set_palette(m_bitmap[1], machine->palette);
537 
538      // allocate textures
539      m_texture[0] = m_machine.render().texture_alloc();
540      m_texture[0]->set_bitmap(m_bitmap[0], &m_visarea, m_texture_format, palette);
541      m_texture[1] = m_machine.render().texture_alloc();
542      m_texture[1]->set_bitmap(m_bitmap[1], &m_visarea, m_texture_format, palette);
543   }
544}
545 
546 
547//-------------------------------------------------
548//  set_visible_area - just set the visible area
549//-------------------------------------------------
550 
551void screen_device::set_visible_area(int min_x, int max_x, int min_y, int max_y)
552{
553   // validate arguments
554   assert(min_x >= 0);
555   assert(min_y >= 0);
556   assert(min_x < max_x);
557   assert(min_y < max_y);
558 
559   rectangle visarea;
560   visarea.min_x = min_x;
561   visarea.max_x = max_x;
562   visarea.min_y = min_y;
563   visarea.max_y = max_y;
564 
565   configure(m_width, m_height, visarea, m_frame_period);
566}
567 
568 
569//-------------------------------------------------
570//  update_partial - perform a partial update from
571//  the last scanline up to and including the
572//  specified scanline
573//-----------------------------------------------*/
574 
575bool screen_device::update_partial(int scanline)
576{
577   // validate arguments
578   assert(scanline >= 0);
579 
580   LOG_PARTIAL_UPDATES(("Partial: update_partial(%s, %d): ", tag(), scanline));
581 
582   // these two checks only apply if we're allowed to skip frames
583   if (!(machine->config->m_video_attributes & VIDEO_ALWAYS_UPDATE))
584   {
585      // if skipping this frame, bail
586      if (m_machine.video().skip_this_frame())
587      {
588         LOG_PARTIAL_UPDATES(("skipped due to frameskipping\n"));
589         return FALSE;
590      }
591 
592      // skip if this screen is not visible anywhere
593      if (!m_machine.render().is_live(*this))
594      {
595         LOG_PARTIAL_UPDATES(("skipped because screen not live\n"));
596         return FALSE;
597      }
598   }
599 
600   // skip if less than the lowest so far
601   if (scanline < m_last_partial_scan)
602   {
603      LOG_PARTIAL_UPDATES(("skipped because less than previous\n"));
604      return FALSE;
605   }
606 
607   // set the start/end scanlines
608   rectangle clip = m_visarea;
609   if (m_last_partial_scan > clip.min_y)
610      clip.min_y = m_last_partial_scan;
611   if (scanline < clip.max_y)
612      clip.max_y = scanline;
613 
614   // render if necessary
615   bool result = false;
616   if (clip.min_y <= clip.max_y)
617   {
618      UINT32 flags = UPDATE_HAS_NOT_CHANGED;
619 
620      g_profiler.start(PROFILER_VIDEO);
621      LOG_PARTIAL_UPDATES(("updating %d-%d\n", clip.min_y, clip.max_y));
622 
623      flags = machine->driver_data<driver_device>()->video_update(*this, *m_bitmap[m_curbitmap], clip);
624      m_partial_updates_this_frame++;
625      g_profiler.stop();
626 
627      // if we modified the bitmap, we have to commit
628      m_changed |= ~flags & UPDATE_HAS_NOT_CHANGED;
629      result = true;
630   }
631 
632   // remember where we left off
633   m_last_partial_scan = scanline + 1;
634   return result;
635}
636 
637 
638//-------------------------------------------------
639//  update_now - perform an update from the last
640//  beam position up to the current beam position
641//-------------------------------------------------
642 
643void screen_device::update_now()
644{
645   int current_vpos = vpos();
646   int current_hpos = hpos();
647 
648   // since we can currently update only at the scanline
649    // level, we are trying to do the right thing by
650    // updating including the current scanline, only if the
651    // beam is past the halfway point horizontally.
652    // If the beam is in the first half of the scanline,
653    // we only update up to the previous scanline.
654    // This minimizes the number of pixels that might be drawn
655    // incorrectly until we support a pixel level granularity
656   if (current_hpos < (m_width / 2) && current_vpos > 0)
657      current_vpos = current_vpos - 1;
658 
659   update_partial(current_vpos);
660}
661 
662 
663//-------------------------------------------------
664//  vpos - returns the current vertical position
665//  of the beam
666//-------------------------------------------------
667 
668int screen_device::vpos() const
669{
670   attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
671   int vpos;
672 
673   // round to the nearest pixel
674   delta += m_pixeltime / 2;
675 
676   // compute the v position relative to the start of VBLANK
677   vpos = delta / m_scantime;
678 
679   // adjust for the fact that VBLANK starts at the bottom of the visible area
680   return (m_visarea.max_y + 1 + vpos) % m_height;
681}
682 
683 
684//-------------------------------------------------
685//  hpos - returns the current horizontal position
686//  of the beam
687//-------------------------------------------------
688 
689int screen_device::hpos() const
690{
691   attoseconds_t delta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
692 
693   // round to the nearest pixel
694   delta += m_pixeltime / 2;
695 
696   // compute the v position relative to the start of VBLANK
697   int vpos = delta / m_scantime;
698 
699   // subtract that from the total time
700   delta -= vpos * m_scantime;
701 
702   // return the pixel offset from the start of this scanline
703   return delta / m_pixeltime;
704}
705 
706 
707//-------------------------------------------------
708//  time_until_pos - returns the amount of time
709//  remaining until the beam is at the given
710//  hpos,vpos
711//-------------------------------------------------
712 
713attotime screen_device::time_until_pos(int vpos, int hpos) const
714{
715   // validate arguments
716   assert(vpos >= 0);
717   assert(hpos >= 0);
718 
719   // since we measure time relative to VBLANK, compute the scanline offset from VBLANK
720   vpos += m_height - (m_visarea.max_y + 1);
721   vpos %= m_height;
722 
723   // compute the delta for the given X,Y position
724   attoseconds_t targetdelta = (attoseconds_t)vpos * m_scantime + (attoseconds_t)hpos * m_pixeltime;
725 
726   // if we're past that time (within 1/2 of a pixel), head to the next frame
727   attoseconds_t curdelta = attotime_to_attoseconds(attotime_sub(timer_get_time(machine), m_vblank_start_time));
728   if (targetdelta <= curdelta + m_pixeltime / 2)
729      targetdelta += m_frame_period;
730   while (targetdelta <= curdelta)
731      targetdelta += m_frame_period;
732 
733   // return the difference
734   return attotime_make(0, targetdelta - curdelta);
735}
736 
737 
738//-------------------------------------------------
739//  time_until_vblank_end - returns the amount of
740//  time remaining until the end of the current
741//  VBLANK (if in progress) or the end of the next
742//  VBLANK
743//-------------------------------------------------
744 
745attotime screen_device::time_until_vblank_end() const
746{
747   // if we are in the VBLANK region, compute the time until the end of the current VBLANK period
748   attotime target_time = m_vblank_end_time;
749   if (!vblank())
750      target_time = attotime_add_attoseconds(target_time, m_frame_period);
751   return attotime_sub(target_time, timer_get_time(machine));
752}
753 
754 
755//-------------------------------------------------
756//  register_vblank_callback - registers a VBLANK
757//  callback
758//-------------------------------------------------
759 
760void screen_device::register_vblank_callback(vblank_state_changed_func vblank_callback, void *param)
761{
762   // validate arguments
763   assert(vblank_callback != NULL);
764 
765   // check if we already have this callback registered
766   callback_item **itemptr;
767   for (itemptr = &m_callback_list; *itemptr != NULL; itemptr = &(*itemptr)->m_next)
768      if ((*itemptr)->m_callback == vblank_callback)
769         break;
770 
771   // if not found, register
772   if (*itemptr == NULL)
773   {
774      *itemptr = auto_alloc(machine, callback_item);
775      (*itemptr)->m_next = NULL;
776      (*itemptr)->m_callback = vblank_callback;
777      (*itemptr)->m_param = param;
778   }
779}
780 
781 
782//-------------------------------------------------
783//  vblank_begin_callback - call any external
784//  callbacks to signal the VBLANK period has begun
785//-------------------------------------------------
786 
787void screen_device::vblank_begin_callback()
788{
789   // reset the starting VBLANK time
790   m_vblank_start_time = timer_get_time(machine);
791   m_vblank_end_time = attotime_add_attoseconds(m_vblank_start_time, m_vblank_period);
792 
793   // call the screen specific callbacks
794   for (callback_item *item = m_callback_list; item != NULL; item = item->m_next)
795      (*item->m_callback)(*this, item->m_param, true);
796 
797   // if this is the primary screen and we need to update now
798   if (this == machine->primary_screen && !(machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
799      machine->video().frame_update();
800 
801   // reset the VBLANK start timer for the next frame
802   timer_adjust_oneshot(m_vblank_begin_timer, time_until_vblank_start(), 0);
803 
804   // if no VBLANK period, call the VBLANK end callback immedietely, otherwise reset the timer
805   if (m_vblank_period == 0)
806      vblank_end_callback();
807   else
808      timer_adjust_oneshot(m_vblank_end_timer, time_until_vblank_end(), 0);
809}
810 
811 
812//-------------------------------------------------
813//  vblank_end_callback - call any external
814//  callbacks to signal the VBLANK period has ended
815//-------------------------------------------------
816 
817void screen_device::vblank_end_callback()
818{
819   // call the screen specific callbacks
820   for (callback_item *item = m_callback_list; item != NULL; item = item->m_next)
821      (*item->m_callback)(*this, item->m_param, false);
822 
823   // if this is the primary screen and we need to update now
824   if (this == machine->primary_screen && (machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK))
825      machine->video().frame_update();
826 
827   // increment the frame number counter
828   m_frame_number++;
829}
830 
831 
832//-------------------------------------------------
833//  scanline0_callback - reset partial updates
834//  for a screen
835//-------------------------------------------------
836 
837void screen_device::scanline0_callback()
838{
839   // reset partial updates
840   m_last_partial_scan = 0;
841   m_partial_updates_this_frame = 0;
842 
843   timer_adjust_oneshot(m_scanline0_timer, time_until_pos(0), 0);
844}
845 
846 
847//-------------------------------------------------
848//  scanline_update_callback - perform partial
849//  updates on each scanline
850//-------------------------------------------------
851 
852void screen_device::scanline_update_callback(int scanline)
853{
854   // force a partial update to the current scanline
855   update_partial(scanline);
856 
857   // compute the next visible scanline
858   scanline++;
859   if (scanline > m_visarea.max_y)
860      scanline = m_visarea.min_y;
861   timer_adjust_oneshot(m_scanline_timer, time_until_pos(scanline), scanline);
862}
863 
864 
865//-------------------------------------------------
866//  update_quads - set up the quads for this
867//  screen
868//-------------------------------------------------
869 
870bool screen_device::update_quads()
871{
872   // only update if live
873   if (m_machine.render().is_live(*this))
874   {
875      // only update if empty and not a vector game; otherwise assume the driver did it directly
876      if (m_config.m_type != SCREEN_TYPE_VECTOR && (machine->config->m_video_attributes & VIDEO_SELF_RENDER) == 0)
877      {
878         // if we're not skipping the frame and if the screen actually changed, then update the texture
879         if (!m_machine.video().skip_this_frame() && m_changed)
880         {
881            rectangle fixedvis = m_visarea;
882            fixedvis.max_x++;
883            fixedvis.max_y++;
884 
885            palette_t *palette = (m_texture_format == TEXFORMAT_PALETTE16) ? machine->palette : NULL;
886            m_texture[m_curbitmap]->set_bitmap(m_bitmap[m_curbitmap], &fixedvis, m_texture_format, palette);
887 
888            m_curtexture = m_curbitmap;
889            m_curbitmap = 1 - m_curbitmap;
890         }
891 
892         // create an empty container with a single quad
893         m_container->empty();
894         m_container->add_quad(0.0f, 0.0f, 1.0f, 1.0f, MAKE_ARGB(0xff,0xff,0xff,0xff), m_texture[m_curtexture], PRIMFLAG_BLENDMODE(BLENDMODE_NONE) | PRIMFLAG_SCREENTEX(1));
895      }
896   }
897 
898   // reset the screen changed flags
899   bool result = m_changed;
900   m_changed = false;
901   return result;
902}
903 
904 
905//-------------------------------------------------
906//  update_burnin - update the burnin bitmap
907//-------------------------------------------------
908 
909void screen_device::update_burnin()
910{
911#undef rand
912   if (m_burnin == NULL)
913      return;
914 
915   bitmap_t *srcbitmap = m_bitmap[m_curtexture];
916   if (srcbitmap == NULL)
917      return;
918 
919   int srcwidth = srcbitmap->width;
920   int srcheight = srcbitmap->height;
921   int dstwidth = m_burnin->width;
922   int dstheight = m_burnin->height;
923   int xstep = (srcwidth << 16) / dstwidth;
924   int ystep = (srcheight << 16) / dstheight;
925   int xstart = ((UINT32)rand() % 32767) * xstep / 32767;
926   int ystart = ((UINT32)rand() % 32767) * ystep / 32767;
927   int srcx, srcy;
928   int x, y;
929 
930   // iterate over rows in the destination
931   for (y = 0, srcy = ystart; y < dstheight; y++, srcy += ystep)
932   {
933      UINT64 *dst = BITMAP_ADDR64(m_burnin, y, 0);
934 
935      // handle the 16-bit palettized case
936      if (srcbitmap->format == BITMAP_FORMAT_INDEXED16)
937      {
938         const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0);
939         const rgb_t *palette = palette_entry_list_adjusted(machine->palette);
940         for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
941         {
942            rgb_t pixel = palette[src[srcx >> 16]];
943            dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel);
944         }
945      }
946 
947      // handle the 15-bit RGB case
948      else if (srcbitmap->format == BITMAP_FORMAT_RGB15)
949      {
950         const UINT16 *src = BITMAP_ADDR16(srcbitmap, srcy >> 16, 0);
951         for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
952         {
953            rgb15_t pixel = src[srcx >> 16];
954            dst[x] += ((pixel >> 10) & 0x1f) + ((pixel >> 5) & 0x1f) + ((pixel >> 0) & 0x1f);
955         }
956      }
957 
958      // handle the 32-bit RGB case
959      else if (srcbitmap->format == BITMAP_FORMAT_RGB32)
960      {
961         const UINT32 *src = BITMAP_ADDR32(srcbitmap, srcy >> 16, 0);
962         for (x = 0, srcx = xstart; x < dstwidth; x++, srcx += xstep)
963         {
964            rgb_t pixel = src[srcx >> 16];
965            dst[x] += RGB_GREEN(pixel) + RGB_RED(pixel) + RGB_BLUE(pixel);
966         }
967      }
968   }
969}
970 
971 
972//-------------------------------------------------
973//  finalize_burnin - finalize the burnin bitmap
974//-------------------------------------------------
975 
976void screen_device::finalize_burnin()
977{
978   if (m_burnin == NULL)
979      return;
980 
981   // compute the scaled visible region
982   rectangle scaledvis;
983   scaledvis.min_x = m_visarea.min_x * m_burnin->width / m_width;
984   scaledvis.max_x = m_visarea.max_x * m_burnin->width / m_width;
985   scaledvis.min_y = m_visarea.min_y * m_burnin->height / m_height;
986   scaledvis.max_y = m_visarea.max_y * m_burnin->height / m_height;
987 
988   // wrap a bitmap around the subregion we care about
989   bitmap_t *finalmap = auto_alloc(machine, bitmap_t(scaledvis.max_x + 1 - scaledvis.min_x,
990                                    scaledvis.max_y + 1 - scaledvis.min_y,
991                                    BITMAP_FORMAT_ARGB32));
992 
993   int srcwidth = m_burnin->width;
994   int srcheight = m_burnin->height;
995   int dstwidth = finalmap->width;
996   int dstheight = finalmap->height;
997   int xstep = (srcwidth << 16) / dstwidth;
998   int ystep = (srcheight << 16) / dstheight;
999 
1000   // find the maximum value
1001   UINT64 minval = ~(UINT64)0;
1002   UINT64 maxval = 0;
1003   for (int y = 0; y < srcheight; y++)
1004   {
1005      UINT64 *src = BITMAP_ADDR64(m_burnin, y, 0);
1006      for (int x = 0; x < srcwidth; x++)
1007      {
1008         minval = MIN(minval, src[x]);
1009         maxval = MAX(maxval, src[x]);
1010      }
1011   }
1012 
1013   if (minval == maxval)
1014      return;
1015 
1016   // now normalize and convert to RGB
1017   for (int y = 0, srcy = 0; y < dstheight; y++, srcy += ystep)
1018   {
1019      UINT64 *src = BITMAP_ADDR64(m_burnin, srcy >> 16, 0);
1020      UINT32 *dst = BITMAP_ADDR32(finalmap, y, 0);
1021      for (int x = 0, srcx = 0; x < dstwidth; x++, srcx += xstep)
1022      {
1023         int brightness = (UINT64)(maxval - src[srcx >> 16]) * 255 / (maxval - minval);
1024         dst[x] = MAKE_ARGB(0xff, brightness, brightness, brightness);
1025      }
1026   }
1027 
1028   // write the final PNG
1029 
1030   // compute the name and create the file
1031   astring fname;
1032   fname.printf("%s" PATH_SEPARATOR "burnin-%s.png", machine->basename(), tag());
1033   mame_file *file;
1034   file_error filerr = mame_fopen(SEARCHPATH_SCREENSHOT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &file);
1035   if (filerr == FILERR_NONE)
1036   {
1037      png_info pnginfo = { 0 };
1038      png_error pngerr;
1039      char text[256];
1040 
1041      // add two text entries describing the image
1042      sprintf(text, APPNAME " %s", build_version);
1043      png_add_text(&pnginfo, "Software", text);
1044      sprintf(text, "%s %s", machine->m_game.manufacturer, machine->m_game.description);
1045      png_add_text(&pnginfo, "System", text);
1046 
1047      // now do the actual work
1048      pngerr = png_write_bitmap(mame_core_file(file), &pnginfo, finalmap, 0, NULL);
1049 
1050      // free any data allocated
1051      png_free(&pnginfo);
1052      mame_fclose(file);
1053   }
1054}
1055 
1056 
1057//-------------------------------------------------
1058//  finalize_burnin - finalize the burnin bitmap
1059//-------------------------------------------------
1060 
1061void screen_device::load_effect_overlay(const char *filename)
1062{
1063   // ensure that there is a .png extension
1064   astring fullname(filename);
1065   int extension = fullname.rchr(0, '.');
1066   if (extension != -1)
1067      fullname.del(extension, -1);
1068   fullname.cat(".png");
1069 
1070   // load the file
1071   m_screen_overlay_bitmap = render_load_png(OPTION_ARTPATH, NULL, fullname, NULL, NULL);
1072   if (m_screen_overlay_bitmap != NULL)
1073      m_container->set_overlay(m_screen_overlay_bitmap);
1074   else
1075      mame_printf_warning("Unable to load effect PNG file '%s'\n", fullname.cstr());
1076}
src/emu/debugger.c
r9718r9719
104104
105105void debugger_refresh_display(running_machine *machine)
106106{
107   video_frame_update(machine, TRUE);
107   machine->video().frame_update(true);
108108}
109109
110110
src/emu/screen.h
r0r9719
1/***************************************************************************
2 
3    screen.h
4 
5    Core MAME screen device.
6 
7****************************************************************************
8 
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 
38***************************************************************************/
39 
40#pragma once
41 
42#ifndef __EMU_H__
43#error Dont include this file directly; include emu.h instead.
44#endif
45 
46#ifndef __SCREEN_H__
47#define __SCREEN_H__
48 
49 
50//**************************************************************************
51//  CONSTANTS
52//**************************************************************************
53 
54// screen types
55enum screen_type_enum
56{
57   SCREEN_TYPE_INVALID = 0,
58   SCREEN_TYPE_RASTER,
59   SCREEN_TYPE_VECTOR,
60   SCREEN_TYPE_LCD
61};
62 
63 
64 
65//**************************************************************************
66//  TYPE DEFINITIONS
67//**************************************************************************
68 
69// forward references
70class render_texture;
71class screen_device;
72 
73 
74// device type definition
75extern const device_type SCREEN;
76 
77 
78// callback that is called to notify of a change in the VBLANK state
79typedef void (*vblank_state_changed_func)(screen_device &device, void *param, bool vblank_state);
80 
81 
82// ======================> screen_device_config
83 
84class screen_device_config : public device_config
85{
86   friend class screen_device;
87 
88   // construction/destruction
89   screen_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
90 
91public:
92   // allocators
93   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
94   virtual device_t *alloc_device(running_machine &machine) const;
95 
96   // configuration readers
97   screen_device_config *next_screen() const { return downcast<screen_device_config *>(typenext()); }
98   screen_type_enum screen_type() const { return m_type; }
99   int width() const { return m_width; }
100   int height() const { return m_height; }
101   const rectangle &visible_area() const { return m_visarea; }
102   bool oldstyle_vblank_supplied() const { return m_oldstyle_vblank_supplied; }
103   attoseconds_t refresh() const { return m_refresh; }
104   attoseconds_t vblank() const { return m_vblank; }
105   bitmap_format format() const { return m_format; }
106   float xoffset() const { return m_xoffset; }
107   float yoffset() const { return m_yoffset; }
108   float xscale() const { return m_xscale; }
109   float yscale() const { return m_yscale; }
110 
111   // inline configuration helpers
112   static void static_set_format(device_config *device, bitmap_format format);
113   static void static_set_type(device_config *device, screen_type_enum type);
114   static void static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart);
115   static void static_set_refresh(device_config *device, attoseconds_t rate);
116   static void static_set_vblank_time(device_config *device, attoseconds_t time);
117   static void static_set_size(device_config *device, UINT16 width, UINT16 height);
118   static void static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy);
119   static void static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs);
120 
121private:
122   // device_config overrides
123   virtual bool device_validity_check(const game_driver &driver) const;
124 
125   // inline configuration data
126   screen_type_enum   m_type;                  // type of screen
127   int               m_width, m_height;         // default total width/height (HTOTAL, VTOTAL)
128   rectangle         m_visarea;               // default visible area (HBLANK end/start, VBLANK end/start)
129   bool            m_oldstyle_vblank_supplied;   // MDRV_SCREEN_VBLANK_TIME macro used
130   attoseconds_t      m_refresh;               // default refresh period
131   attoseconds_t      m_vblank;               // duration of a VBLANK
132   bitmap_format      m_format;               // bitmap format
133   float            m_xoffset, m_yoffset;      // default X/Y offsets
134   float            m_xscale, m_yscale;         // default X/Y scale factor
135};
136 
137 
138// ======================> screen_device
139 
140class screen_device : public device_t
141{
142   friend class screen_device_config;
143   friend class render_manager;
144   friend resource_pool_object<screen_device>::~resource_pool_object();
145 
146   // construction/destruction
147   screen_device(running_machine &_machine, const screen_device_config &config);
148   virtual ~screen_device();
149 
150public:
151   // information getters
152   const screen_device_config &config() const { return m_config; }
153   screen_device *next_screen() const { return downcast<screen_device *>(typenext()); }
154   screen_type_enum screen_type() const { return m_config.m_type; }
155   int width() const { return m_width; }
156   int height() const { return m_height; }
157   const rectangle &visible_area() const { return m_visarea; }
158   bitmap_format format() const { return m_config.m_format; }
159   render_container &container() const { assert(m_container != NULL); return *m_container; }
160 
161   // dynamic configuration
162   void configure(int width, int height, const rectangle &visarea, attoseconds_t frame_period);
163   void reset_origin(int beamy = 0, int beamx = 0);
164   void set_visible_area(int min_x, int max_x, int min_y, int max_y);
165 
166   // beam positioning and state
167   int vpos() const;
168   int hpos() const;
169   bool vblank() const { return attotime_compare(timer_get_time(machine), m_vblank_end_time) < 0; }
170   bool hblank() const { int curpos = hpos(); return (curpos < m_visarea.min_x || curpos > m_visarea.max_x); }
171 
172   // timing
173   attotime time_until_pos(int vpos, int hpos = 0) const;
174   attotime time_until_vblank_start() const { return time_until_pos(m_visarea.max_y + 1); }
175   attotime time_until_vblank_end() const;
176   attotime time_until_update() const { return (machine->config->m_video_attributes & VIDEO_UPDATE_AFTER_VBLANK) ? time_until_vblank_end() : time_until_vblank_start(); }
177   attotime scan_period() const { return attotime_make(0, m_scantime); }
178   attotime frame_period() const { return (this == NULL || !started()) ? DEFAULT_FRAME_PERIOD : attotime_make(0, m_frame_period); };
179   UINT64 frame_number() const { return m_frame_number; }
180   int partial_updates() const { return m_partial_updates_this_frame; }
181 
182   // updating
183   bool update_partial(int scanline);
184   void update_now();
185 
186   // additional helpers
187   void register_vblank_callback(vblank_state_changed_func vblank_callback, void *param);
188   bitmap_t *alloc_compatible_bitmap(int width = 0, int height = 0) { return auto_bitmap_alloc(machine, (width == 0) ? m_width : width, (height == 0) ? m_height : height, m_config.m_format); }
189 
190   // internal to the video system
191   bool update_quads();
192   void update_burnin();
193 
194   // globally accessible constants
195   static const int DEFAULT_FRAME_RATE = 60;
196   static const attotime DEFAULT_FRAME_PERIOD;
197 
198private:
199   // device-level overrides
200   virtual void device_start();
201   virtual void device_post_load();
202 
203   // internal helpers
204   void set_container(render_container &container) { m_container = &container; }
205   void realloc_screen_bitmaps();
206 
207   static TIMER_CALLBACK( static_vblank_begin_callback ) { reinterpret_cast<screen_device *>(ptr)->vblank_begin_callback(); }
208   void vblank_begin_callback();
209 
210   static TIMER_CALLBACK( static_vblank_end_callback ) { reinterpret_cast<screen_device *>(ptr)->vblank_end_callback(); }
211   void vblank_end_callback();
212 
213   static TIMER_CALLBACK( static_scanline0_callback ) { reinterpret_cast<screen_device *>(ptr)->scanline0_callback(); }
214public:   // temporary
215   void scanline0_callback();
216private:
217 
218   static TIMER_CALLBACK( static_scanline_update_callback ) { reinterpret_cast<screen_device *>(ptr)->scanline_update_callback(param); }
219   void scanline_update_callback(int scanline);
220 
221   void finalize_burnin();
222   void load_effect_overlay(const char *filename);
223 
224   // internal state
225   const screen_device_config &m_config;
226   render_container *      m_container;         // pointer to our container
227 
228   // dimensions
229   int                  m_width;            // current width (HTOTAL)
230   int                  m_height;            // current height (VTOTAL)
231   rectangle            m_visarea;            // current visible area (HBLANK end/start, VBLANK end/start)
232 
233   // textures and bitmaps
234   render_texture *      m_texture[2];         // 2x textures for the screen bitmap
235   bitmap_t *            m_bitmap[2];         // 2x bitmaps for rendering
236   bitmap_t *            m_burnin;            // burn-in bitmap
237   UINT8               m_curbitmap;         // current bitmap index
238   UINT8               m_curtexture;         // current texture index
239   INT32               m_texture_format;      // texture format of bitmap for this screen
240   bool               m_changed;            // has this bitmap changed?
241   INT32               m_last_partial_scan;   // scanline of last partial update
242   bitmap_t *            m_screen_overlay_bitmap;// screen overlay bitmap
243 
244   // screen timing
245   attoseconds_t         m_frame_period;         // attoseconds per frame
246   attoseconds_t         m_scantime;            // attoseconds per scanline
247   attoseconds_t         m_pixeltime;         // attoseconds per pixel
248   attoseconds_t         m_vblank_period;      // attoseconds per VBLANK period
249   attotime            m_vblank_start_time;   // time of last VBLANK start
250   attotime            m_vblank_end_time;      // time of last VBLANK end
251   emu_timer *            m_vblank_begin_timer;   // timer to signal VBLANK start
252   emu_timer *            m_vblank_end_timer;      // timer to signal VBLANK end
253   emu_timer *            m_scanline0_timer;      // scanline 0 timer
254   emu_timer *            m_scanline_timer;      // scanline timer
255   UINT64               m_frame_number;         // the current frame number
256   UINT32               m_partial_updates_this_frame;// partial update counter this frame
257 
258   struct callback_item
259   {
260      callback_item *            m_next;
261      vblank_state_changed_func   m_callback;
262      void *                  m_param;
263   };
264   callback_item *         m_callback_list;      // list of VBLANK callbacks
265};
266 
267 
268 
269//**************************************************************************
270//  SCREEN DEVICE CONFIGURATION MACROS
271//**************************************************************************
272 
273#define MDRV_SCREEN_ADD(_tag, _type) \
274   MDRV_DEVICE_ADD(_tag, SCREEN, 0) \
275   MDRV_SCREEN_TYPE(_type) \
276 
277#define MDRV_SCREEN_MODIFY(_tag) \
278   MDRV_DEVICE_MODIFY(_tag)
279 
280#define MDRV_SCREEN_FORMAT(_format) \
281   screen_device_config::static_set_format(device, _format); \
282 
283#define MDRV_SCREEN_TYPE(_type) \
284   screen_device_config::static_set_type(device, SCREEN_TYPE_##_type); \
285 
286#define MDRV_SCREEN_RAW_PARAMS(_pixclock, _htotal, _hbend, _hbstart, _vtotal, _vbend, _vbstart) \
287   screen_device_config::static_set_raw(device, _pixclock, _htotal, _hbend, _hbstart, _vtotal, _vbend, _vbstart);
288 
289#define MDRV_SCREEN_REFRESH_RATE(_rate) \
290   screen_device_config::static_set_refresh(device, HZ_TO_ATTOSECONDS(_rate)); \
291 
292#define MDRV_SCREEN_VBLANK_TIME(_time) \
293   screen_device_config::static_set_vblank_time(device, _time); \
294 
295#define MDRV_SCREEN_SIZE(_width, _height) \
296   screen_device_config::static_set_size(device, _width, _height); \
297 
298#define MDRV_SCREEN_VISIBLE_AREA(_minx, _maxx, _miny, _maxy) \
299   screen_device_config::static_set_visarea(device, _minx, _maxx, _miny, _maxy); \
300 
301#define MDRV_SCREEN_DEFAULT_POSITION(_xscale, _xoffs, _yscale, _yoffs)   \
302   screen_device_config::static_set_default_position(device, _xscale, _xoffs, _yscale, _yoffs); \
303 
304 
305#endif   /* __SCREEN_H__ */
src/emu/sound.c
r9718r9719
379379      speaker->mix(leftmix, rightmix, samples_this_update, !global->enabled);
380380
381381   /* now downmix the final result */
382   finalmix_step = video_get_speed_factor();
382   finalmix_step = machine->video().speed_factor();
383383   finalmix_offset = 0;
384384   for (sample = global->finalmix_leftover; sample < samples_this_update * 100; sample += finalmix_step)
385385   {
r9718r9719
409409   {
410410      if (!global->nosound_mode)
411411         machine->osd().update_audio_stream(finalmix, finalmix_offset / 2);
412      video_avi_add_sound(machine, finalmix, finalmix_offset / 2);
412      machine->video().add_sound_to_recording(finalmix, finalmix_offset / 2);
413413      if (global->wavfile != NULL)
414414         wav_add_data_16(global->wavfile, finalmix, finalmix_offset);
415415   }
src/emu/mconfig.c
r9718r9719
101101
102102
103103//-------------------------------------------------
104//  first_screen - return a pointer to the first
105//  screen device
106//-------------------------------------------------
107
108screen_device_config *machine_config::first_screen() const
109{
110   return downcast<screen_device_config *>(m_devicelist.first(SCREEN));
111}
112
113
114//-------------------------------------------------
104115//  device_add - configuration helper to add a
105116//  new device
106117//-------------------------------------------------
src/emu/mconfig.h
r9718r9719
105105// forward references
106106struct gfx_decode_entry;
107107class driver_device;
108class screen_device_config;
108109
109110
110111
r9718r9719
124125   friend class running_machine;
125126
126127public:
128   // construction/destruction
127129   machine_config(const game_driver &gamedrv);
128130   ~machine_config();
129131
132   // getters
130133   const game_driver &gamedrv() const { return m_gamedrv; }
134   screen_device_config *first_screen() const;
131135
136   // public state
132137   attotime            m_minimum_quantum;         // minimum scheduling quantum
133138   const char *         m_perfect_cpu_quantum;      // tag of CPU to use for "perfect" scheduling
134139   INT32               m_watchdog_vblank_count;   // number of VBLANKs until the watchdog kills us
src/mess/osd/windows/menu.c
r9718r9719
12921292      joystick_menu_setup = 1;
12931293   }
12941294
1295   frameskip = video_get_frameskip();
1295   frameskip = window->machine->video().frameskip();
12961296
12971297   orientation = window->target->orientation();
12981298
1299   speed = video_get_throttle() ? video_get_speed_factor() : 0;
1299   speed = window->machine->video().throttled() ? window->machine->video().speed_factor() : 0;
13001300
13011301   has_config      = input_has_input_class(window->machine, INPUT_CLASS_CONFIG);
13021302   has_dipswitch   = input_has_input_class(window->machine, INPUT_CLASS_DIPSWITCH);
r9718r9719
14481448//  set_seped
14491449//============================================================
14501450
1451static void set_speed(int speed)
1451static void set_speed(running_machine *machine, int speed)
14521452{
14531453   if (speed != 0)
14541454   {
1455      video_set_speed_factor(speed);
1455      machine->video().set_speed_factor(speed);
14561456      options_set_int(mame_options(), OPTION_SPEED, speed / 100, OPTION_PRIORITY_CMDLINE);
14571457   }
14581458
1459   video_set_throttle(speed != 0);
1459   machine->video().set_throttled(speed != 0);
14601460   options_set_bool(mame_options(), OPTION_THROTTLE, (speed != 0), OPTION_PRIORITY_CMDLINE);
14611461}
14621462
r9718r9719
17221722         break;
17231723
17241724      case ID_FILE_SAVESCREENSHOT:
1725         video_save_active_screen_snapshots(window->machine);
1725         window->machine->video().save_active_screen_snapshots();
17261726         break;
17271727
17281728      case ID_FILE_EXIT_NEWUI:
r9718r9719
18241824#endif
18251825
18261826      case ID_FRAMESKIP_AUTO:
1827         video_set_frameskip(-1);
1827         window->machine->video().set_frameskip(-1);
18281828         options_set_bool(mame_options(), OPTION_AUTOFRAMESKIP, 1, OPTION_PRIORITY_CMDLINE);
18291829         break;
18301830
r9718r9719
18371837         break;
18381838
18391839      case ID_THROTTLE_50:
1840         set_speed(50);
1840         set_speed(window->machine, 50);
18411841         break;
18421842
18431843      case ID_THROTTLE_100:
1844         set_speed(100);
1844         set_speed(window->machine, 100);
18451845         break;
18461846
18471847      case ID_THROTTLE_200:
1848         set_speed(200);
1848         set_speed(window->machine, 200);
18491849         break;
18501850
18511851      case ID_THROTTLE_500:
1852         set_speed(500);
1852         set_speed(window->machine, 500);
18531853         break;
18541854
18551855      case ID_THROTTLE_1000:
1856         set_speed(1000);
1856         set_speed(window->machine, 1000);
18571857         break;
18581858
18591859      case ID_THROTTLE_UNTHROTTLED:
1860         set_speed(0);
1860         set_speed(window->machine, 0);
18611861         break;
18621862
18631863      default:
18641864         if ((command >= ID_FRAMESKIP_0) && (command < ID_FRAMESKIP_0 + frameskip_level_count()))
18651865         {
18661866            // change frameskip
1867            video_set_frameskip(command - ID_FRAMESKIP_0);
1867            window->machine->video().set_frameskip(command - ID_FRAMESKIP_0);
18681868            options_set_bool(mame_options(), OPTION_AUTOFRAMESKIP, 0, OPTION_PRIORITY_CMDLINE);
18691869            options_set_int(mame_options(), OPTION_FRAMESKIP, command - ID_FRAMESKIP_0, OPTION_PRIORITY_CMDLINE);
18701870         }
src/mess/tools/messtest/testmess.c
r9718r9719
224224      if (filerr == FILERR_NONE)
225225      {
226226         /* choose a screen */
227         screen_device *screen = screen_first(*machine);
227         screen_device *screen = machine->first_screen();
228228         while((screen != NULL) && !machine->render().is_live(*screen))
229229         {
230            screen = screen_next(screen);
230            screen = screen->next_screen();
231231         }
232232
233233         /* did we find a live screen? */
234234         if (screen != NULL)
235235         {
236            screen_save_snapshot(screen->machine, screen, fp);
236            screen->machine->video().save_snapshot(screen, *fp);
237237            report_message(MSG_INFO, "Saved screenshot as %s", buf);
238238         }
239239         else
src/mess/machine/sms.c
r9718r9719
124124{
125125   sms_state *state = machine->driver_data<sms_state>();
126126   const int r_x_r = LGUN_RADIUS * LGUN_RADIUS;
127   screen_device *screen = screen_first(*machine);
127   screen_device *screen = machine->first_screen();
128128   const rectangle &visarea = screen->visible_area();
129129   int beam_x = screen->hpos();
130130   int beam_y = screen->vpos();
r9718r9719
175175      else
176176         break;
177177   }
178   timer_adjust_oneshot(timer, screen_first(*machine)->time_until_pos(beam_y, beam_x), 0);
178   timer_adjust_oneshot(timer, machine->first_screen()->time_until_pos(beam_y, beam_x), 0);
179179
180180   return result;
181181}
r9718r9719
183183static UINT8 sms_vdp_hcount( running_machine *machine )
184184{
185185   UINT8 tmp;
186   screen_device *screen = screen_first(*machine);
186   screen_device *screen = machine->first_screen();
187187   int hpos = screen->hpos();
188188
189189   /* alternative method: pass HCounter test, but some others fail */
r9718r9719
238238static void lphaser1_sensor_check( running_machine *machine )
239239{
240240   sms_state *state = machine->driver_data<sms_state>();
241   const int x = screen_hpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER0"));
242   const int y = screen_vpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER1"));
241   const int x = screen_hpos_nonscaled(machine->first_screen(), input_port_read(machine, "LPHASER0"));
242   const int y = screen_vpos_nonscaled(machine->first_screen(), input_port_read(machine, "LPHASER1"));
243243
244244   if (lgun_bright_aim_area(machine, state->lphaser_1_timer, x, y))
245245   {
r9718r9719
254254static void lphaser2_sensor_check( running_machine *machine )
255255{
256256   sms_state *state = machine->driver_data<sms_state>();
257   const int x = screen_hpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER2"));
258   const int y = screen_vpos_nonscaled(screen_first(*machine), input_port_read(machine, "LPHASER3"));
257   const int x = screen_hpos_nonscaled(machine->first_screen(), input_port_read(machine, "LPHASER2"));
258   const int y = screen_vpos_nonscaled(machine->first_screen(), input_port_read(machine, "LPHASER3"));
259259   
260260   if (lgun_bright_aim_area(machine, state->lphaser_2_timer, x, y))
261261   {
r9718r9719
19411941VIDEO_START( sms1 )
19421942{
19431943   sms_state *state = machine->driver_data<sms_state>();
1944   screen_device *screen = screen_first(*machine);
1944   screen_device *screen = machine->first_screen();
19451945   int width = screen->width();
19461946   int height = screen->height();
19471947   
r9718r9719
20062006VIDEO_START( gamegear )
20072007{
20082008   sms_state *state = machine->driver_data<sms_state>();
2009   screen_device *screen = screen_first(*machine);
2009   screen_device *screen = machine->first_screen();
20102010   int width = screen->width();
20112011   int height = screen->height();
20122012   
src/mess/machine/zx.c
r9718r9719
405405    FE = turn on NMI generator
406406    FF = write HSYNC and cass data */
407407
408   screen_device *screen = screen_first(*space->machine);
408   screen_device *screen = space->machine->first_screen();
409409   int height = screen->height();
410410   UINT8 offs = offset & 0xff;
411411
src/mess/video/zx.c
r9718r9719
3939void zx_ula_bkgnd(running_machine *machine, int color)
4040{
4141   zx_state *state = machine->driver_data<zx_state>();
42   screen_device *screen = screen_first(*machine);
42   screen_device *screen = machine->first_screen();
4343   int width = screen->width();
4444   int height = screen->height();
4545   const rectangle &visarea = screen->visible_area();
r9718r9719
9999     * An NMI is issued on the ZX81 every 64us for the blanked
100100     * scanlines at the top and bottom of the display.
101101     */
102   screen_device *screen = screen_first(*machine);
102   screen_device *screen = machine->first_screen();
103103   int height = screen->height();
104104   const rectangle r1 = screen->visible_area();
105105   rectangle r;
r9718r9719
136136void zx_ula_r(running_machine *machine, int offs, const char *region, const UINT8 param)
137137{
138138   zx_state *state = machine->driver_data<zx_state>();
139   screen_device *screen = screen_first(*machine);
139   screen_device *screen = machine->first_screen();
140140   int offs0 = offs & 0x7fff;
141141   UINT8 *rom = memory_region(machine, "maincpu");
142142   UINT8 chr = rom[offs0];
src/mess/video/mbee.c
r9718r9719
258258READ8_HANDLER ( m6545_status_r )
259259{
260260   mbee_state *state = space->machine->driver_data<mbee_state>();
261   screen_device *screen = screen_first(*space->machine);
261   screen_device *screen = space->machine->first_screen();
262262   const rectangle &visarea = screen->visible_area();
263263
264264   UINT8 data = state->sy6545_status; // bit 6 = lpen strobe, bit 7 = update strobe
src/mess/video/gb.c
r9718r9719
489489         {
490490            if ( gb_lcd.current_line < 144 )
491491            {
492               screen_device *screen = screen_first(*machine);
492               screen_device *screen = machine->first_screen();
493493               rectangle r1;
494494               const rectangle &r = screen->visible_area();
495495               r1.min_y = r1.max_y = gb_lcd.current_line;
r9718r9719
11581158         {
11591159            if ( gb_lcd.current_line < 144 )
11601160            {
1161               screen_device *screen = screen_first(*machine);
1161               screen_device *screen = machine->first_screen();
11621162               rectangle r;
11631163               const rectangle &r1 = screen->visible_area();
11641164               r.min_x = r1.min_x;
src/mess/video/vectrex.c
r9718r9719
284284VIDEO_START(vectrex)
285285{
286286   vectrex_state *state = machine->driver_data<vectrex_state>();
287   screen_device *screen = screen_first(*machine);
287   screen_device *screen = machine->first_screen();
288288   const rectangle &visarea = screen->visible_area();
289289
290290   state->x_center=((visarea.max_x - visarea.min_x) / 2) << 16;
r9718r9719
484484VIDEO_START(raaspec)
485485{
486486   vectrex_state *state = machine->driver_data<vectrex_state>();
487   screen_device *screen = screen_first(*machine);
487   screen_device *screen = machine->first_screen();
488488   const rectangle &visarea = screen->visible_area();
489489
490490   state->x_center=((visarea.max_x - visarea.min_x) / 2) << 16;
src/mess/video/arcadia.c
r9718r9719
303303   }
304304
305305   {
306      screen_device *screen = screen_first(*machine);
306      screen_device *screen = machine->first_screen();
307307      int width = screen->width();
308308      int height = screen->height();
309309      state->bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16);
r9718r9719
603603INTERRUPT_GEN( arcadia_video_line )
604604{
605605   arcadia_state *state = device->machine->driver_data<arcadia_state>();
606   screen_device *screen = screen_first(*device->machine);
606   screen_device *screen = device->machine->first_screen();
607607   int width = screen->width();
608608
609609   if (state->ad_delay<=0)
src/mess/video/thomson.c
r9718r9719
5252
5353static int thom_update_screen_size( running_machine *machine )
5454{
55   screen_device *screen = screen_first(*machine);
55   screen_device *screen = machine->first_screen();
5656   const rectangle &visarea = screen->visible_area();
5757   UINT8 p = input_port_read(machine, "vconfig");
5858   int new_w, new_h, changed = 0;
src/mess/video/cgenie.c
r9718r9719
2121VIDEO_START( cgenie )
2222{
2323   cgenie_state *state = machine->driver_data<cgenie_state>();
24   screen_device *screen = screen_first(*machine);
24   screen_device *screen = machine->first_screen();
2525   int width = screen->width();
2626   int height = screen->height();
2727
src/mess/video/pc8801.c
r9718r9719
7979void pc8801_video_init( running_machine *machine, int hireso )
8080{
8181   pc88_state *state = machine->driver_data<pc88_state>();
82   screen_device *screen = screen_first(*machine);
82   screen_device *screen = machine->first_screen();
8383   int width = screen->width();
8484   int height = screen->height();
8585
src/mess/video/apple1.c
r9718r9719
356356           still use it to find what fraction of the current scanline
357357           period has elapsed. */
358358      double current_hfrac = machine->primary_screen->hpos() /
359                        screen_first(*machine)->width();
359                        machine->first_screen()->width();
360360      if (current_hfrac < cursor_hfrac)
361361         return double_to_attotime(scanline_period * (cursor_hfrac - current_hfrac));
362362   }
src/mess/video/smsvdp.c
r9718r9719
163163{
164164   smsvdp_t *smsvdp = get_safe_token(device);
165165
166   screen_device *screen = screen_first(*device->machine);
166   screen_device *screen = device->machine->first_screen();
167167   int height = screen->height();
168168   int M1, M2, M3, M4;
169169   M1 = smsvdp->reg[0x01] & 0x10;
r9718r9719
14271427   smsvdp_t *smsvdp = get_safe_token(device);
14281428   const smsvdp_interface *intf = get_interface(device);
14291429
1430   screen_device *screen = screen_first(*device->machine);
1430   screen_device *screen = device->machine->first_screen();
14311431   int width = screen->width();
14321432   int height = screen->height();
14331433
src/mess/video/odyssey2.c
r9718r9719
565565VIDEO_START( odyssey2 )
566566{
567567   odyssey2_state *state = machine->driver_data<odyssey2_state>();
568   screen_device *screen = screen_first(*machine);
568   screen_device *screen = machine->first_screen();
569569   int width = screen->width();
570570   int height = screen->height();
571571
src/mess/video/vc4000.c
r9718r9719
2727VIDEO_START(vc4000)
2828{
2929   vc4000_state *state = machine->driver_data<vc4000_state>();
30   screen_device *screen = screen_first(*machine);
30   screen_device *screen = machine->first_screen();
3131   int width = screen->width();
3232   int height = screen->height();
3333   int i;
r9718r9719
518518INLINE void vc4000_draw_grid(running_machine *machine, UINT8 *collision)
519519{
520520   vc4000_state *state = machine->driver_data<vc4000_state>();
521   screen_device *screen = screen_first(*machine);
521   screen_device *screen = machine->first_screen();
522522   int width = screen->width();
523523   int height = screen->height();
524524   int i, j, m, x, line=state->video.line-20;
src/mess/video/733_asr.c
r9718r9719
171171
172172int asr733_init_term(running_machine *machine, int unit, void (*int_callback)(running_machine *, int state))
173173{
174   screen_device *screen = screen_first(*machine);
174   screen_device *screen = machine->first_screen();
175175   int width = screen->width();
176176   int height = screen->height();
177177   const rectangle &visarea = screen->visible_area();
src/mess/drivers/tm990189.c
r9718r9719
224224static VIDEO_START( tm990_189_v )
225225{
226226   tm990189_state *state = machine->driver_data<tm990189_state>();
227   screen_device *screen = screen_first(*machine);
227   screen_device *screen = machine->first_screen();
228228   const rectangle &visarea = screen->visible_area();
229229
230230   /* NPW 27-Feb-2006 - ewwww gross!!! maybe this can be fixed when
src/mess/drivers/a2600.c
r9718r9719
16761676static MACHINE_START( a2600 )
16771677{
16781678   a2600_state *state = machine->driver_data<a2600_state>();
1679   screen_device *screen = screen_first(*machine);
1679   screen_device *screen = machine->first_screen();
16801680   state->current_screen_height = screen->height();
16811681   state->extra_RAM =   machine->region_alloc("user2", 0x8600, ROM_REQUIRED );
16821682   tia_init( machine, &tia_interface );
r9718r9719
16871687static MACHINE_START( a2600p )
16881688{
16891689   a2600_state *state = machine->driver_data<a2600_state>();
1690   screen_device *screen = screen_first(*machine);
1690   screen_device *screen = machine->first_screen();
16911691   state->current_screen_height = screen->height();
16921692   state->extra_RAM = machine->region_alloc("user2", 0x8600, ROM_REQUIRED );
16931693   tia_init( machine, &tia_interface_pal );
src/mess/drivers/ssem.c
r9718r9719
395395    va_list arg_list;
396396    char buf[32768];
397397    INT32 index = 0;
398    screen_device *screen = screen_first(*machine);
398    screen_device *screen = machine->first_screen();
399399    const rectangle &visarea = screen->visible_area();
400400
401401    va_start( arg_list, msg );
src/mess/drivers/apexc.c
r9718r9719
552552static VIDEO_START( apexc )
553553{
554554   apexc_state *state = machine->driver_data<apexc_state>();
555   screen_device *screen = screen_first(*machine);
555   screen_device *screen = machine->first_screen();
556556   int width = screen->width();
557557   int height = screen->height();
558558

Previous 15994 Revisions Next


© 1998-2018 The MESS Team