blob: c39b15c4640e8ee31bc9d2c8552157ebcd1dd711 (
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
142
143
144
145
146
147
148
149
150
|
/***************************************************************************
watchdog.c
Watchdog handling
Copyright Nicola Salmoria and the MAME Team.
Visit http://mamedev.org for licensing and usage restrictions.
***************************************************************************/
#include "emu.h"
#include "emuopts.h"
/***************************************************************************
GLOBAL VARIABLES
***************************************************************************/
static UINT8 watchdog_enabled;
static INT32 watchdog_counter;
static emu_timer *watchdog_timer;
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
static void watchdog_internal_reset(running_machine &machine);
static TIMER_CALLBACK( watchdog_callback );
/*-------------------------------------------------
watchdog_init - one time initialization
-------------------------------------------------*/
void watchdog_init(running_machine &machine)
{
/* allocate a timer for the watchdog */
watchdog_timer = machine.scheduler().timer_alloc(FUNC(watchdog_callback));
machine.add_notifier(MACHINE_NOTIFY_RESET, machine_notify_delegate(FUNC(watchdog_internal_reset), &machine));
/* save some stuff in the default tag */
machine.save().save_item(NAME(watchdog_enabled));
machine.save().save_item(NAME(watchdog_counter));
}
/*-------------------------------------------------
watchdog_internal_reset - reset the watchdog
system
-------------------------------------------------*/
static void watchdog_internal_reset(running_machine &machine)
{
/* set up the watchdog timer; only start off enabled if explicitly configured */
watchdog_enabled = (machine.config().m_watchdog_vblank_count != 0 || machine.config().m_watchdog_time != attotime::zero);
watchdog_reset(machine);
watchdog_enabled = TRUE;
}
/*-------------------------------------------------
watchdog_callback - watchdog timer callback
-------------------------------------------------*/
static TIMER_CALLBACK( watchdog_callback )
{
logerror("Reset caused by the watchdog!!!\n");
int verbose = machine.options().verbose();
#ifdef MAME_DEBUG
verbose = 1;
#endif
if (verbose)
popmessage("Reset caused by the watchdog!!!\n");
machine.schedule_soft_reset();
}
/*-------------------------------------------------
on_vblank - updates VBLANK based watchdog
timers
-------------------------------------------------*/
static void on_vblank(running_machine &machine, screen_device &screen, bool vblank_state)
{
/* VBLANK starting */
if (vblank_state && watchdog_enabled)
{
/* check the watchdog */
if (screen.machine().config().m_watchdog_vblank_count != 0)
{
watchdog_counter = watchdog_counter - 1;
if (watchdog_counter == 0)
watchdog_callback(screen.machine(), NULL, 0);
}
}
}
/*-------------------------------------------------
watchdog_reset - reset the watchdog timer
-------------------------------------------------*/
void watchdog_reset(running_machine &machine)
{
/* if we're not enabled, skip it */
if (!watchdog_enabled)
watchdog_timer->adjust(attotime::never);
/* VBLANK-based watchdog? */
else if (machine.config().m_watchdog_vblank_count != 0)
{
watchdog_counter = machine.config().m_watchdog_vblank_count;
/* register a VBLANK callback for the primary screen */
if (machine.primary_screen != NULL)
machine.primary_screen->register_vblank_callback(vblank_state_delegate(FUNC(on_vblank), &machine));
}
/* timer-based watchdog? */
else if (machine.config().m_watchdog_time != attotime::zero)
watchdog_timer->adjust(machine.config().m_watchdog_time);
/* default to an obscene amount of time (3 seconds) */
else
watchdog_timer->adjust(attotime::from_seconds(3));
}
/*-------------------------------------------------
watchdog_enable - reset the watchdog timer
-------------------------------------------------*/
void watchdog_enable(running_machine &machine, int enable)
{
/* when re-enabled, we reset our state */
if (watchdog_enabled != enable)
{
watchdog_enabled = enable;
watchdog_reset(machine);
}
}
|