-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoscall.c
101 lines (80 loc) · 1.61 KB
/
doscall.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
#
/*
* DOSCALL.C -- Wrapper functions for DOS-specific functions
*/
#include <ctype.h>
#include <dos.h>
#include <i86.h>
#include <stdio.h> /* for debug */
#include <stdlib.h>
#include "fatal.h"
unsigned
dosAllocMem(unsigned paragraphs)
{
unsigned segment;
if (_dos_allocmem(paragraphs, &segment) != 0)
fatal(EXIT_FAILURE, "dosAllocMem");
return segment;
}
int
dosClose(int handle)
{
if (_dos_close(handle) != 0)
fatal(EXIT_FAILURE, "dosClose");
return 0;
}
int
dosCreat(const char *path, unsigned attr)
{
int handle;
if (_dos_creat(path, attr, &handle) != 0)
fatal(EXIT_FAILURE, "dosCreat (%s)", path);
return handle;
}
int
dosFreeMem(unsigned segment)
{
if (_dos_freemem(segment) != 0)
fatal(EXIT_FAILURE, "dosFreeMem");
return 0;
}
int
dosGetDiskFree(int drive, struct diskfree_t *diskSpace)
{
unsigned error;
drive = toupper(drive) - '@'; /* A: = 1, B: = 2, ... */
if (_dos_getdiskfree(drive, diskSpace) != 0)
fatal(EXIT_FAILURE, "dosGetDiskFree (%c:)", drive + '@');
return 0;
}
int
dosReadDisk(int drive, void __far *buffer, unsigned sector, unsigned first)
{
unsigned flags;
drive = toupper(drive) - 'A'; /* A: = 0, B: = 1, ... */
__asm {
PUSH DS;
MOV AX, drive;
MOV CX, sector;
MOV DX, first;
LDS BX, buffer;
INT 25H;
POP DX; /* Discard */
POP DS;
PUSHF;
POP flags;
}
if (flags & INTR_CF)
return -1;
return 0;
}
int
dosWrite(int handle, void const __far *buffer, unsigned count)
{
unsigned written;
if (_dos_write(handle, buffer, count, &written) != 0)
fatal(EXIT_FAILURE, "dosWrite");
if (written != count)
fatal(EXIT_FAILURE, "dosWrite");
return 0;
}