summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/sdl/output.c
blob: 0381ef16e0bae99c908ccede19d9872294bd62e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//============================================================
//
//  output.c - Generic implementation of MAME output routines
//
//  Copyright Nicola Salmoria and the MAME Team.
//  Visit http://mamedev.org for licensing and usage restrictions.
//
//============================================================

#if !defined(SDLMAME_WIN32)

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

// MAME headers
#include "emu.h"

// MAMEOS headers
#include "output.h"



//============================================================
//  CONSTANTS
//============================================================

#define SDLMAME_OUTPUT	"/tmp/sdlmame_out"

/*
 * Using long/int should be sufficient on all
 * architectures.
 */


#ifdef PTR64
#define PID_FMT "%ld"
#define PID_CAST long
#else
#define PID_FMT "%d"
#define PID_CAST int
#endif

//============================================================
//  TYPEDEFS
//============================================================

//============================================================
//  PRIVATE VARIABLES
//============================================================

static FILE *output;

//============================================================
//  FUNCTION PROTOTYPES
//============================================================

static void sdloutput_exit(running_machine &machine);
static void notifier_callback(const char *outname, INT32 value, void *param);

//============================================================
//  osd_get_pid
//============================================================

PID_CAST osd_getpid(void)
{
	return (PID_CAST) getpid();
}

//============================================================
//  sdloutput_init
//============================================================

void sdloutput_init(running_machine &machine)
{
	int fildes;

	machine.add_notifier(MACHINE_NOTIFY_EXIT, sdloutput_exit);

	fildes = open(SDLMAME_OUTPUT, O_RDWR | O_NONBLOCK);

	if (fildes < 0)
	{
		output = NULL;
		mame_printf_verbose("ouput: unable to open output notifier file %s\n", SDLMAME_OUTPUT);
	}
	else
	{
		output = fdopen(fildes, "w");

		mame_printf_verbose("ouput: opened output notifier file %s\n", SDLMAME_OUTPUT);
		fprintf(output, "MAME " PID_FMT " START %s\n", osd_getpid(), machine.system().name);
		fflush(output);
	}

	output_set_notifier(NULL, notifier_callback, NULL);
}


//============================================================
//  winoutput_exit
//============================================================

static void sdloutput_exit(running_machine &machine)
{
	if (output != NULL)
	{
		fprintf(output, "MAME " PID_FMT " STOP %s\n", osd_getpid(), machine.system().name);
		fflush(output);
		fclose(output);
		output = NULL;
		mame_printf_verbose("ouput: closed output notifier file\n");
	}
}

//============================================================
//  notifier_callback
//============================================================

static void notifier_callback(const char *outname, INT32 value, void *param)
{
	if (output != NULL)
	{
		fprintf(output, "OUT " PID_FMT " %s %d\n", osd_getpid(), outname, value);
		fflush(output);
	}
}

#else  /* SDLMAME_WIN32 */

#include "emucore.h"

//============================================================
//  Stub for win32
//============================================================

void sdloutput_init(running_machine &machine)
{
}

#endif  /* SDLMAME_WIN32 */