]> git.sur5r.net Git - cc65/blob - libsrc/c64/mainargs.s
Added routines to handle command line params
[cc65] / libsrc / c64 / mainargs.s
1 ;
2 ; Ullrich von Bassewitz, 2003-03-07
3 ;
4 ; Setup arguments for main.
5 ; Based on code from Stefan A. Haubenthal, <polluks@web.de>
6 ;
7
8
9         .constructor    initmainargs, 24
10         .import         __argc, __argv
11
12         .include        "c64.inc"
13
14 ;---------------------------------------------------------------------------
15 ; Setup arguments for main
16
17 .proc   initmainargs
18
19 ; Setup a pointer to our argv vector
20
21         lda     #<argv
22         sta     __argv
23         lda     #>argv
24         sta     __argv+1
25
26 ; Save the last filename as argument #0. Since the buffer we're copying into
27 ; is zeroed out, we don't need to add a NUL character.
28
29         ldy     FNAM_LEN
30         cpy     #16+1
31         bcc     L0
32         ldy     #16             ; Limit the length
33 L0:     dey
34 L1:     lda     (FNAM),y
35         sta     argv0,y
36         dey
37         bpl     L1
38         inc     __argc          ; __argc = 1
39
40 ; Find argument in BASIC buffer, if found, use it as arg #1
41
42         ldy     #0
43 L2:     lda     $200,y
44         beq     L9
45         iny
46         cmp     #$8F            ; REM token
47         bne     L2
48         sty     argv+2          ; Store offset
49         ldy     #>$200
50         sty     argv+3
51         inc     __argc          ; argc = 2
52
53 ; Done
54
55 L9:     rts
56
57 .endproc
58
59
60 ;---------------------------------------------------------------------------
61 ; Data
62
63 .data
64
65 argv:   .word   argv0           ; Pointer to program name
66         .word   $0000           ; Optional second argument
67         .word   $0000           ; Last vector must always be NULL
68
69 .bss
70 argv0:  .res    17              ; Program name
71
72