OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [c64libc/] [source/] [string.c] - Blame information for rev 53

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 robfinch
#define null    0
2
 
3
byte *memcpy(byte *d, byte *s, int size)
4
{
5
    asm {
6
        lw              r1,40[bp]
7
        lw              r2,32[bp]
8
        lw              r3,48[bp]
9
                tst             p0,r3
10
        p0.eq   br      .0002
11
                subui   r3,r3,#1
12
                mtspr   lc,r3
13
    .0001:
14
        lb    r4,[r1]
15
        sb    r4,[r2]
16
        addui r1,r1,#1
17
        addui r2,r2,#1
18
        loop  .0001
19
        .0002:
20
    }
21
        return d;
22
}
23
 
24
short int *memcpyH(short int *d, short int *s, int size)
25
{
26
    asm {
27
        lw              r1,40[bp]
28
        lw              r2,32[bp]
29
        lw              r3,48[bp]
30
    .0001:
31
        lh    r4,[r1]
32
        sh    r4,[r2]
33
        addui r1,r1,#4
34
        addui r2,r2,#4
35
        subui r3,r3,#1
36
                tst       p0,r3
37
    p0.gt       br      .0001
38
    }
39
        return d;
40
}
41
 
42
int *memcpyW(int *d, int *s, int size)
43
{
44
    asm {
45
        lw              r1,40[bp]
46
        lw              r2,32[bp]
47
        lw              r3,48[bp]
48
    .0001:
49
        lw    r4,[r1]
50
        sw    r4,[r2]
51
        addui r1,r1,#8
52
        addui r2,r2,#8
53
        subui r3,r3,#1
54
                tst      p0,r3
55
p0.gt   br   .0001
56
    }
57
        return d;
58
}
59
 
60
byte *memset(byte *p, byte val, int size)
61
{
62
        asm {
63
        lw    r1,32[bp]
64
        lw    r2,40[bp]
65
        lw    r3,48[bp]
66
.0001:
67
        sb    r2,[r1]
68
        addui r1,r1,#1
69
        subui r3,r3,#1
70
                tst      p0,r3
71
p0.gt   br   .0001
72
    }
73
        return p;
74
}
75
 
76
short int *memsetH(short int *p, short int val, int size)
77
{
78
        asm {
79
        lw    r1,32[bp]
80
        lw    r2,40[bp]
81
        lw    r3,48[bp]
82
.0001:
83
        sh    r2,[r1]
84
        addui r1,r1,#4
85
        subui r3,r3,#1
86
                tst      p0,r3
87
p0.gt   br   .0001
88
    }
89
        return p;
90
}
91
 
92
int *memsetW(int *p, int val, int size)
93
{
94
        asm {
95
        lw    r1,32[bp]
96
        lw    r2,40[bp]
97
        lw    r3,48[bp]
98
.0001:
99
        sw    r2,[r1]
100
        addui r1,r1,#8
101
        subui r3,r3,#1
102
                tst      p0,r3
103
p0.gt   br   .0001
104
    }
105
        return p;
106
}
107
 
108
byte *memchr(byte *p, byte val, int n)
109
{
110
        byte *su;
111
 
112
        for (su = p; n > 0; ++su, --n)
113
                if (*su==val)
114
                        return su;
115
        return null;
116
}
117
 
118
int strlen(char *p)
119
{
120
        int n;
121
 
122
        if (p==(char *)0) return 0;
123
        for (n = 0; p[n]; n++)
124
                ;
125
        return n;
126
}
127
 
128
char *strcpy(char *d, char *s)
129
{
130
        int nn;
131
 
132
        for (nn = 0; s[nn]; nn++)
133
                d[nn] = s[nn];
134
        d[nn] = '\0';
135
        return d;
136
}
137
 
138
char *strncpy(char *d, char *s, int size)
139
{
140
        int nn;
141
 
142
        for (nn = 0; nn < size; nn++) {
143
                d[nn] = s[nn];
144
                if (s[nn]=='\0')
145
                        break;
146
        }
147
        for (; nn < size; nn++)
148
                d[nn] = '\0';
149
        return d;
150
}
151
 
152
int strncmp(unsigned char *a, unsigned char *b, int len)
153
{
154
        unsigned char *ua;
155
        unsigned char *ub;
156
 
157
        ua = a;
158
        ub = b;
159
        if (ua==ub)     // duh
160
                return 0;
161
        for (; len > 0; ua++, ub++, len--)
162
                if (*ua != *ub)
163
                        return *ua < *ub ? -1 : 1;
164
                else if (*ua == '\0')
165
                        return 0;
166
        return 0;
167
}
168
 
169
char *strchr(char *p, char val, int n)
170
{
171
        char *su;
172
 
173
        for (su = p; n > 0; ++su, --n)
174
                if (*su==val)
175
                        return su;
176
        return null;
177
}
178
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.