/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/lib2/strncat.s
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/lib2/strncat.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1154 - (show annotations)
Sun Aug 10 18:19:54 2014 UTC (5 years, 3 months ago) by dbug
File size: 2093 byte(s)


1 ; char *strncat(char *s1, char *s2, int n)
2
3 _strncat
4 ldy #5
5 lda (sp),y ; high(n)
6 sta tmp2+1
7 dey
8 lda (sp),y
9 sta tmp2 ; low(n)
10
11 dey ; copy s2
12 lda (sp),y
13 sta strncat2+2
14 dey ; Y=#2
15 lda (sp),y
16 sta strncat2+1
17
18 dey ; Y=#1
19 lda (sp),y ; copy s1
20 sta strncat1+2
21 sta strncat3+1 ; copy return value, high
22 dey ; Y=#0
23 lda (sp),y
24 sta strncat1+1
25 sta strncat3+3 ; copy return value, low
26
27 strncat1 ; look for terminating null in s1
28 lda $2211,Y ; self-modifying
29 beq strncat1a ; terminating null found?
30 iny
31 bne strncat1
32 inc strncat1+2 ; next page (whoa, that's a long string!)
33 jmp strncat1
34
35 strncat1a
36 lda strncat1+2 ; set self-mod in strncat2+[5,4] to end of s1
37 sta strncat2+5
38 lda strncat1+1
39 sta strncat2+4
40 clc
41 tya
42 adc strncat2+4
43 sta strncat2+4
44 lda strncat2+5
45 adc #$00
46 sta strncat2+5
47 ldx #$00
48 ldy tmp2
49
50 strncat2
51 lda $2211,x
52 sta $5544,x
53 beq strncat3 ; found terminating null?
54
55 dey ; decrease n
56 cpy #$ff
57 bne strncat2a
58 dec tmp2+1
59 lda tmp2+1
60 cmp #$ff
61 beq strncat2b ; n<0?
62
63 strncat2a
64 inx ; increase pointers
65 bne strncat2
66 inc strncat2+2
67 inc strncat2+5
68 jmp strncat2
69
70 strncat2b
71 txa ; add terminating null, low order byte of pointer
72 clc
73 adc strncat2+4
74 sta tmp2
75 lda #0 ; terminating null, high order byte
76 adc strncat2+5
77 sta tmp2+1
78 lda #0 ; write terminating null
79 tay
80 sta (tmp2),y
81
82 strncat3
83 lda #$01 ; self-mod
84 ldx #$03 ; likewise
85 rts
86
87
88

  ViewVC Help
Powered by ViewVC 1.1.26