Subversion Repositories SvarDOS

Rev

Rev 1571 | 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
 
1557 mateusz.vi 53
unsigned short mdr_dos_resizeblock(unsigned short siz, unsigned short segn) {
1556 mateusz.vi 54
  unsigned short res = 0;
55
 
56
  _asm {
57
    push bx
58
    push es
59
 
60
    mov ah, 0x4a
61
    mov bx, siz
62
    mov es, segn
63
    int 0x21
64
    jnc done
65
    mov res, ax
66
 
67
    done:
68
 
69
    pop es
70
    pop bx
71
  }
72
 
73
  return(res);
74
}
75
 
76
 
77
unsigned short mdr_dos_read(unsigned short handle, void far *buf, unsigned short count, unsigned short *bytes) {
78
  unsigned short res = 0;
79
  unsigned short resax = 0;
80
  unsigned short buf_off = FP_OFF(buf);
81
  unsigned short buf_seg = FP_SEG(buf);
82
 
83
  _asm {
84
    push bx,
85
    push cx
86
    push dx
87
 
88
    mov ah, 0x3f
89
    mov bx, handle
90
    mov cx, count
91
    mov dx, buf_off
92
    push ds
93
    mov ds, buf_seg
94
    int 0x21
95
    pop ds
96
 
97
    jnc done
98
    mov res, ax
99
 
100
    done:
101
    mov resax, ax
102
 
103
    pop dx
104
    pop cx
105
    pop bx
106
  }
107
 
108
  *bytes = resax;
109
  return(res);
110
}
111
 
112
 
113
unsigned short mdr_dos_write(unsigned short handle, const void far *buf, unsigned short count, unsigned short *bytes) {
114
  unsigned short res = 0;
115
  unsigned short resax = 0;
116
  unsigned short buf_seg = FP_SEG(buf);
117
  unsigned short buf_off = FP_OFF(buf);
118
 
119
  _asm {
120
    push bx
121
    push cx
122
    push dx
123
 
124
    mov ah, 0x40
125
    mov bx, handle
126
    mov cx, count
127
    mov dx, buf_off
128
    push ds
129
    mov ds, buf_seg
130
 
131
    int 0x21
132
    pop ds
133
    jnc done
134
    mov res, ax
135
 
136
    done:
137
    mov resax, ax
138
 
139
    pop dx
140
    pop cx
141
    pop bx
142
  }
143
 
144
  *bytes = resax;
145
  return(res);
146
}