Subversion Repositories SvarDOS

Rev

Rev 1573 | 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_write(unsigned short handle, const void far *buf, unsigned short count, unsigned short *bytes) {
61
  unsigned short res = 0;
62
  unsigned short resax = 0;
63
  unsigned short buf_seg = FP_SEG(buf);
64
  unsigned short buf_off = FP_OFF(buf);
65
 
66
  _asm {
67
    push bx
68
    push cx
69
    push dx
70
 
71
    mov ah, 0x40
72
    mov bx, handle
73
    mov cx, count
74
    mov dx, buf_off
75
    push ds
76
    mov ds, buf_seg
77
 
78
    int 0x21
79
    pop ds
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
}