]> git.sur5r.net Git - cc65/blob - libsrc/common/utscopy.s
New uname function
[cc65] / libsrc / common / utscopy.s
1 ;
2 ; Ullrich von Bassewitz, 2003-08-12
3 ;
4 ; This module contains a utility function for the machine dependent parts
5 ; of uname (__sysuname): It copies a packed struct utsname (just the strings
6 ; without padding) into a struct utsname. The source of the data is an
7 ; external symbol named "utsdata", the target is passed in a/x.
8 ; The function is written so that it is a direct replacement for __sysuname
9 ; for systems where utsdata is fixed. It may also be called via jump or
10 ; subroutine on systems where utsdata must be changed at runtime.
11 ;
12
13         .export         utscopy
14
15         .import         utsdata
16         .importzp       ptr1, tmp1
17
18         .include        "utsname.inc"
19
20
21
22 ;--------------------------------------------------------------------------
23 ; Data.
24
25 .rodata
26
27 ; Table with offsets into struct utsname
28 fieldoffs:
29         .byte   utsname_sysname
30         .byte   utsname_nodename
31         .byte   utsname_release
32         .byte   utsname_version
33         .byte   utsname_machine
34
35 ;--------------------------------------------------------------------------
36
37 .code
38
39 .proc   utscopy
40
41         sta     ptr1
42         stx     ptr1+1          ; Save buf
43
44         ldx     #0
45         stx     tmp1            ; Field number
46
47 next:   ldy     tmp1
48         cpy     #utsname_fieldcount
49         beq     done
50         inc     tmp1            ; Bump field counter
51         lda     fieldoffs,y     ; Get next field offset
52         tay                     ; Field offset -> y
53
54 loop:   lda     utsdata,x
55         sta     (ptr1),y
56         inx                     ; Next char in utsdata
57         cmp     #$00            ; Check for end of string
58         beq     next            ; Jump for next field
59         iny                     ; Next char in utsname struct
60         bne     loop            ; Copy string
61
62 done:   lda     #$00            ; Always successful
63         rts
64
65 .endproc
66
67