Subversion Repositories SvarDOS

Rev

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