-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSHUTUP.C
More file actions
124 lines (102 loc) · 3.9 KB
/
SHUTUP.C
File metadata and controls
124 lines (102 loc) · 3.9 KB
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
/* ===============================================================================
shutUp library v3.01
copyright (c) 1997, maciej sini’o a.k.a. yarpen
universal exit, handles pre-exit routines like stop playing,
dehook irq etc.
btw, i know that shutDown is more accurate name, but i'm not going
to change "up" to "down" in all my codes using this library.
===============================================================================
*/
#include <i86.h>
#include <stdarg.h>
#include <types.h>
#define MAX_SHUTUPS 8 /* yeah, yeah, i know - it should */
/* be dynamic, but this way is */
/* _A_LOT_ easier (and more stable, */
/* i think).
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
/* useful routine, it sets our cool 0x3 video mode */
void vmode3 (void)
{
union REGS r;
r.w.ax = 0x003;
int386 (0x10, &r, &r);
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
/* it does nothing. probably it's not even necessary, but who carez¨ */
void dummyRt (void)
{
return;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
static struct { /* shutUp structure */
ubyte ControlByte;
void (*func)(void);
} shutUpTab[MAX_SHUTUPS] = {
{FALSE, dummyRt}, /* could be 0 instead of dummyRt */
{FALSE, dummyRt},
{FALSE, dummyRt},
{FALSE, dummyRt},
{FALSE, dummyRt},
{FALSE, dummyRt},
{FALSE, dummyRt},
{FALSE, dummyRt},
};
static int ShutUpNo = 0; /* counter of shutUps */
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
/* it just adds a routine, which will be called before exiting to DOS */
void addShutUp(void (*funkc)(void))
{
int i;
if (ShutUpNo == MAX_SHUTUPS) /* check if there's free slot */
{
for (i = 0; i < ShutUpNo; i++) /* call all prepared routines */
if (shutUpTab[i].ControlByte == TRUE)
shutUpTab[i].func();
vmode(3);
printf("Too Many shutUps (There Could Be Up To %d)! Change MAX_SHUTUPS.\n", MAX_SHUTUPS);
exit(1);
}
for (i = 0; i < ShutUpNo; i++) /* scan table and search for */
{ /* first free slot */
if (shutUpTab[i].ControlByte == FALSE)
{
shutUpTab[i].ControlByte = TRUE; /* fill slot */
shutUpTab[i].func = funkc;
}
}
ShutUpNo++;
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
/* remove routine, it won't be called before exit */
void subShutUp(void (*funkc)(void))
{
int i;
for (i = 0; i < ShutUpNo; i++) /* search for function */
if (shutUpTab[i].func == funkc)
break;
if (i != ShutUpNo) /* valid? */
{
shutUpTab[i].ControlByte = FALSE; /* do not call! */
ShutUpNo--; /* one shutUp less */
if (ShutUpNo < 0)
ShutUpNo = 0;
}
}
//°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
/* main shutup routine, just call it with error message(s) as a parameter */
void shutUp(char *errmsg, ...)
{
int i;
va_list argptr;
for (i = 0; i < ShutUpNo; i++)
if (shutUpTab[i].ControlByte == TRUE) /* should we call it? */
shutUpTab[i].func();
printf("\n***************** ERROR ***************\n");
/* show error message */
va_start(argptr, errmsg);
vprintf(errmsg, argptr);
va_end(argptr);
printf("\n");
exit (1); /* exit to Disk Op. System */
} /* also known as DOS */