Subversion Repositories SvarDOS

Rev

Rev 1557 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1556 mateusz.vi 1
/*
2
 * replacement for a couple of libc functions
3
 */
4
 
5
#include <i86.h>
6
#include <stddef.h>
7
 
8
#include "libc.h"
9
 
10
 
11
size_t strlen(const char *s) {
12
  size_t res = 0;
13
  while (s[res] != 0) res++;
14
  return(res);
15
}
16
 
17
void bzero(void *ptr, size_t len) {
18
  while (len > 0) ((char *)ptr)[--len] = 0;
19
}
20
 
21
/* TODO this function does not handle overlapping strings well! */
22
void far *_fmemmove(void far *dst, const void far *src, size_t len) {
23
  while (len-- > 0) {
24
    ((char far *)dst)[len] = ((char far *)src)[len];
25
  }
26
  return(dst);
27
}
28
 
29
unsigned short mdr_dos_fclose(unsigned short handle) {
30
  unsigned short res = 0;
31
  _asm {
32
    push bx
33
 
34
    mov ah, 0x3e
35
    mov bx, handle
36
    int 0x21
37
    jnc done
38
    mov res, ax
39
    done:
40
 
41
    pop bx
42
  }
43
  return(res);
44
}
45
 
46
 
47
unsigned short _dos_freemem(unsigned short segn) {
48
  unsigned short res = 0;
49
  _asm {
50
    push es
51
    mov ah, 0x49
52
    mov es, segn
53
    int 0x21
54
    pop es
55
    jnc done
56
    mov res, ax
57
    done:
58
  }
59
  return(res);
60
}
61
 
62
 
63
unsigned short mdr_dos_allocmem(unsigned short siz) {
64
  unsigned short segnum = 0;
65
 
66
  _asm {
67
    push bx
68
 
69
    mov ah, 0x48
70
    mov bx, siz
71
    int 0x21
72
    jc done
73
    mov segnum, ax
74
 
75
    done:
76
 
77
    pop bx
78
  }
79
 
80
  return(segnum);
81
}
82
 
83
 
1557 mateusz.vi 84
unsigned short mdr_dos_resizeblock(unsigned short siz, unsigned short segn) {
1556 mateusz.vi 85
  unsigned short res = 0;
86
 
87
  _asm {
88
    push bx
89
    push es
90
 
91
    mov ah, 0x4a
92
    mov bx, siz
93
    mov es, segn
94
    int 0x21
95
    jnc done
96
    mov res, ax
97
 
98
    done:
99
 
100
    pop es
101
    pop bx
102
  }
103
 
104
  return(res);
105
}
106
 
107
 
108
unsigned short mdr_dos_read(unsigned short handle, void far *buf, unsigned short count, unsigned short *bytes) {
109
  unsigned short res = 0;
110
  unsigned short resax = 0;
111
  unsigned short buf_off = FP_OFF(buf);
112
  unsigned short buf_seg = FP_SEG(buf);
113
 
114
  _asm {
115
    push bx,
116
    push cx
117
    push dx
118
 
119
    mov ah, 0x3f
120
    mov bx, handle
121
    mov cx, count
122
    mov dx, buf_off
123
    push ds
124
    mov ds, buf_seg
125
    int 0x21
126
    pop ds
127
 
128
    jnc done
129
    mov res, ax
130
 
131
    done:
132
    mov resax, ax
133
 
134
    pop dx
135
    pop cx
136
    pop bx
137
  }
138
 
139
  *bytes = resax;
140
  return(res);
141
}
142
 
143
 
144
unsigned short mdr_dos_write(unsigned short handle, const void far *buf, unsigned short count, unsigned short *bytes) {
145
  unsigned short res = 0;
146
  unsigned short resax = 0;
147
  unsigned short buf_seg = FP_SEG(buf);
148
  unsigned short buf_off = FP_OFF(buf);
149
 
150
  _asm {
151
    push bx
152
    push cx
153
    push dx
154
 
155
    mov ah, 0x40
156
    mov bx, handle
157
    mov cx, count
158
    mov dx, buf_off
159
    push ds
160
    mov ds, buf_seg
161
 
162
    int 0x21
163
    pop ds
164
    jnc done
165
    mov res, ax
166
 
167
    done:
168
    mov resax, ax
169
 
170
    pop dx
171
    pop cx
172
    pop bx
173
  }
174
 
175
  *bytes = resax;
176
  return(res);
177
}