-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcapture.c
102 lines (88 loc) · 2.02 KB
/
capture.c
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
/*_ capture.c Mon Oct 31 1988 */
/* Written by Walter Bright */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <int.h>
#include "capture.h"
static unsigned buffersize;
static unsigned used;
static char *buffer;
static capture_inited = 0;
/********************************
* Look for writes to the screen, and copy them to our
* own buffer before passing them on to MS-DOS.
*/
#if MSDOS
static int handler(struct INT_DATA *pd)
{ unsigned count;
if (pd->regs.h.ah == 0x40 && /* write to handle */
(pd->regs.x.bx == 1 || pd->regs.x.bx == 2)) /* stdout or stderr */
{
sound_click();
count = pd->regs.x.cx;
if (used + count > buffersize)
count = buffersize - used;
if (count)
{
#if __INTSIZE == 2
peekbytes(pd->sregs.ds,pd->regs.x.dx,buffer + used,count);
#endif
used += count;
}
}
return 0; /* chain to previous interrupt handler */
}
#endif
/*******************************
* Setup for capturing MS-DOS output.
* If successful, all MS-DOS output is copied into an internal buffer.
* Before the program terminates, capture_term() must be called to
* finish up things and unhook the vectors.
* Input:
* size Buffer size to use (if 0, use default size of 10000)
* Returns:
* !=0 succeeded
*/
int capture_init(unsigned size)
{
#if MSDOS
int status;
buffersize = size ? size : 10000;
buffer = malloc(buffersize);
if (buffer)
{ if (int_intercept(0x21,handler,1024) == 0)
{ capture_inited = 1;
used = 0;
return 1;
}
free(buffer);
}
#endif
return 0; /* failed */
}
/******************************
* Terminate capturing MS-DOS output.
* Return a buffer to the buffer of data.
* Return in *pcount the number of bytes in the buffer.
* The caller must free the buffer.
*/
char *capture_term(unsigned *pcount)
{
#if MSDOS
if (capture_inited)
{
int_restore(0x21);
capture_inited = 0;
}
else
{ buffer = NULL;
used = 0;
}
*pcount = used;
return buffer;
#else
return NULL;
#endif
}