File: dpmi.inc

package info (click to toggle)
fasm 1.73.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,540 kB
  • sloc: pascal: 4,300; asm: 3,056; makefile: 12
file content (108 lines) | stat: -rw-r--r-- 1,997 bytes parent folder | download | duplicates (3)
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

; flat assembler interface for DOS
; Copyright (c) 1999-2022, Tomasz Grysztar.
; All rights reserved.

init_dpmi_memory:
	mov	ax,500h 		; get free memory information
	mov	edi,[buffer_address]
	int	31h
	mov	ebx,[edi]
    allocate_dpmi_memory:
	mov	edx,[memory_setting]
	shl	edx,10
	jz	dpmi_memory_size_ok
	cmp	ebx,edx
	jbe	dpmi_memory_size_ok
	mov	ebx,edx
    dpmi_memory_size_ok:
	mov	[memory_end],ebx
	mov	ecx,ebx
	shr	ebx,16
	mov	ax,501h
	int	31h
	jnc	dpmi_memory_ok
	mov	ebx,[memory_end]
	shr	ebx,1
	cmp	ebx,4000h
	jb	out_of_memory
	jmp	allocate_dpmi_memory
    dpmi_memory_ok:
	shl	ebx,16
	mov	bx,cx
	sub	ebx,[program_base]
	jc	out_of_memory
	mov	[memory_start],ebx
	add	[memory_end],ebx
	mov	ax,100h 		; get free conventional memory size
	mov	bx,-1
	int	31h
	movzx	ecx,bx
	shl	ecx,4
	jecxz	no_conventional_memory
	mov	ax,100h 		; allocate all conventional memory
	int	31h
	movzx	edi,ax
	shl	edi,4
	sub	edi,[program_base]
	jc	no_conventional_memory
	mov	[additional_memory],edi
	mov	[additional_memory_end],edi
	add	[additional_memory_end],ecx
	mov	eax,[memory_end]
	sub	eax,[memory_start]
	shr	eax,2
	cmp	eax,ecx
	ja	no_conventional_memory
	ret
    no_conventional_memory:
	mov	eax,[memory_end]
	mov	ebx,[memory_start]
	sub	eax,ebx
	shr	eax,2
	mov	[additional_memory],ebx
	add	ebx,eax
	mov	[additional_memory_end],ebx
	mov	[memory_start],ebx
	ret

dpmi_dos_int:
	mov	[real_mode_segment],main
    simulate_real_mode:
	push	0			; SS:SP (DPMI will allocate stack)
	push	0			; CS:IP (ignored)
	push	0
	push	[real_mode_segment]	; DS
	push	[real_mode_segment]	; ES
	stc
	pushfw
	push	eax
	push	ecx
	push	edx
	push	ebx
	push	0
	push	ebp
	push	esi
	push	edi
	mov	ax,300h
	mov	bx,21h
	xor	cx,cx
	mov	edi,esp
	push	es ss
	pop	es
	int	31h
	pop	es
	mov	edi,[esp]
	mov	esi,[esp+4]
	mov	ebp,[esp+8]
	mov	ebx,[esp+10h]
	mov	edx,[esp+14h]
	mov	ecx,[esp+18h]
	mov	ah,[esp+20h]
	sahf
	mov	eax,[esp+1Ch]
	lea	esp,[esp+32h]
	ret
dpmi_dos_int_with_buffer:
	mov	[real_mode_segment],buffer
	jmp	simulate_real_mode