-
Notifications
You must be signed in to change notification settings - Fork 1
/
farseg.c
76 lines (67 loc) · 1.42 KB
/
farseg.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
/*******************************************************************************
*
* Routines for working with segment:offset memory and near/far pointers.
*
*/
#include "farset.h"
long near2far(long address)
{
return ((address & 0xFFFF0000) >> 12) + (address & 0xFFFF);
}
long near3far(long segment, long offset)
{
return ((segment & 0xFFFF) << 4) + (offset & 0xFFFF);
}
short far2seg(long address)
{
return (address >> 4) & 0xFFFFF;
}
short far2off(long address)
{
return address & 0xF;
}
long far2near(long address)
{
return (far2seg(address) << 16) + far2off(address);
}
void farmemsetb(long segment, long buffer, long length, char value)
{
int index;
_farsetsel(segment);
for(index = 0; index < length; index++)
{
_farnspokeb(buffer + index, value);
}
}
char *nearmemcpyb(long nearptr, char *buffer, char delimiter)
{
char value;
long farptr = near2far(nearptr);
int index = 0;
_farsetsel(_dos_ds);
do
{
value = _farnspeekb(farptr);
buffer[ index ] = value;
farptr ++;
index ++;
}
while(value != delimiter);
return buffer + index;
}
short *nearmemcpyw(long nearptr, short *buffer, short delimiter)
{
short value;
long farptr = near2far(nearptr);
int index = 0;
_farsetsel(_dos_ds);
do
{
value = _farnspeekw(farptr);
buffer[ index ] = value;
farptr += 2;
index ++;
}
while(value != delimiter);
return buffer + index;
}