Subversion Repositories SvarDOS

Rev

Rev 1572 | 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
 
1557 mateusz.vi 36
unsigned short mdr_dos_resizeblock(unsigned short siz, unsigned short segn) {
1556 mateusz.vi 37
  unsigned short res = 0;
38
 
39
  _asm {
40
    push bx
41
    push es
42
 
43
    mov ah, 0x4a
44
    mov bx, siz
45
    mov es, segn
46
    int 0x21
47
    jnc done
48
    mov res, ax
49
 
50
    done:
51
 
52
    pop es
53
    pop bx
54
  }
55
 
56
  return(res);
57
}
58
 
59
 
60
unsigned short mdr_dos_read(unsigned short handle, void far *buf, unsigned short count, unsigned short *bytes) {
61
  unsigned short res = 0;
62
  unsigned short resax = 0;
63
  unsigned short buf_off = FP_OFF(buf);
64
  unsigned short buf_seg = FP_SEG(buf);
65
 
66
  _asm {
67
    push bx,
68
    push cx
69
    push dx
70
 
71
    mov ah, 0x3f
72
    mov bx, handle
73
    mov cx, count
74
    mov dx, buf_off
75
    push ds
76
    mov ds, buf_seg
77
    int 0x21
78
    pop ds
79
 
80
    jnc done
81
    mov res, ax
82
 
83
    done:
84
    mov resax, ax
85
 
86
    pop dx
87
    pop cx
88
    pop bx
89
  }
90
 
91
  *bytes = resax;
92
  return(res);
93
}
94
 
95
 
96
unsigned short mdr_dos_write(unsigned short handle, const void far *buf, unsigned short count, unsigned short *bytes) {
97
  unsigned short res = 0;
98
  unsigned short resax = 0;
99
  unsigned short buf_seg = FP_SEG(buf);
100
  unsigned short buf_off = FP_OFF(buf);
101
 
102
  _asm {
103
    push bx
104
    push cx
105
    push dx
106
 
107
    mov ah, 0x40
108
    mov bx, handle
109
    mov cx, count
110
    mov dx, buf_off
111
    push ds
112
    mov ds, buf_seg
113
 
114
    int 0x21
115
    pop ds
116
    jnc done
117
    mov res, ax
118
 
119
    done:
120
    mov resax, ax
121
 
122
    pop dx
123
    pop cx
124
    pop bx
125
  }
126
 
127
  *bytes = resax;
128
  return(res);
129
}