Subversion Repositories SvarDOS

Rev

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