aboutsummaryrefslogtreecommitdiffstats
path: root/drvlib.c
blob: 33997be5dfacb0fc9cf783db0348c017eba07be4 (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
#include <string.h>
#include "winhack.h"

#include "drvlib.h"
#include "dpmi.h"

#pragma code_seg( _INIT )

void drv_memcpy(void __far *dst, void __far *src, long size)
{
	unsigned char __far *psrc = src;
	unsigned char __far *pdst = dst;
	
	
	while(size-- > 0)
	{
		*pdst = *psrc;
		
		psrc++;
		pdst++;
	}
}


void __far *drv_malloc(DWORD dwSize, DWORD __far *lpLinear)
{
	WORD    wSel;
	DWORD   dwLin;

	wSel = DPMI_AllocLDTDesc(1);
	if(!wSel)
		return NULL;

	dwLin = DPMI_AllocMemBlk(dwSize);
    
	if(dwLin)
	{
		DPMI_SetSegBase(wSel, dwLin);
		DPMI_SetSegLimit(wSel, dwSize - 1);
    
    *lpLinear = dwLin;
    
		return wSel :> 0;
	}

	return NULL;
}

/**
 * MEMSET for area larger than one segment. This function is not very effective,
 * I assume it will be called only in few speed non critical situation
 * (driver/screen inicialization or reset).
 *
 * @param dwLinearBase: linear address
 * @param dwOffset: offset to linear address
 * @param value: value to set (same bahaviour as C memset)
 * @param dwNum: number of bytes to set;
 *
 **/
void drv_memset_large(DWORD dwLinearBase, DWORD dwOffset, UINT value, DWORD dwNum)
{
	WORD  wSel;
	DWORD dwLinPtr;
	DWORD dwLinPtrMax;
	WORD  wAddr;
	BYTE __far *lpPM16Ptr;
	
	wSel = DPMI_AllocLDTDesc(1);
	if(!wSel) return;
	
	dwLinPtr = dwLinearBase + dwOffset;
	dwLinPtrMax = dwLinPtr + dwNum;
	
	/* overflow or nothing to do */
	if(dwLinPtrMax <= dwLinPtr) return;
	
	DPMI_SetSegBase(wSel, dwLinPtr);
	DPMI_SetSegLimit(wSel, 0xFFFF);
	
	for(; dwLinPtr < dwLinPtrMax; dwLinPtr++)
	{
		wAddr = dwLinPtr & 0xFFFF;
		
		/* move to new segment */
		if(wAddr == 0x0000)
		{
			DPMI_SetSegBase(wSel, dwLinPtr);
		}
		
		lpPM16Ptr = (BYTE __far *)(wSel :> wAddr);
		
		*lpPM16Ptr = value;
	}
	
	DPMI_FreeLDTDesc(wSel);
}