]> git.sur5r.net Git - cc65/blob - libsrc/geos-common/system/mainargs.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / geos-common / system / mainargs.s
1 ;
2 ; Ullrich von Bassewitz, 2003-03-07
3 ; Maciej Witkowiak, 2003-05-02
4 ;
5 ; Setup arguments for main
6 ;
7 ; There is always either 1 or 3 arguments:
8 ; <program name>,0
9 ; or
10 ; <program name>, <data file name>, <data disk name>, 0
11 ; the 2nd case is when using DeskTop user drags an icon of a file and drops it
12 ; on icon of your application
13 ;
14
15             .constructor initmainargs, 24
16             .import __argc, __argv
17
18             .include "const.inc"
19             .include "geossym.inc"
20
21 .segment        "INIT"
22
23 ; Setup arguments for main
24
25 initmainargs:
26 ; Setup a pointer to our argv vector
27
28         lda #<argv
29         sta __argv
30         lda #>argv
31         sta __argv+1
32
33 ; Copy program name
34         ldy #0
35 @fn_loop:
36         lda dirEntryBuf+OFF_FNAME,y
37 .ifdef __GEOS_CBM__
38         cmp #$a0
39 .else
40         cmp #0
41 .endif
42         beq @fn_end
43         sta argv0,y
44         iny
45         cpy #16+1
46         bne @fn_loop
47 @fn_end:
48         lda #0
49         sta argv0,y
50         sta __argc+1
51
52 ; Check if there are any more arguments
53         lda dataFileName
54         bne @threeargs
55         ldx #0                  ; no dataFileName - NULL the 2nd argument
56         stx argv+2
57         stx argv+3
58         inx                     ; there is only one argument
59         bne @setargc
60 @threeargs:
61         ldx #3                  ; there are three arguments
62 @setargc:
63         stx __argc
64         rts
65
66 .data
67
68 argv:
69         .word argv0             ; Pointer to program name
70         .word dataFileName      ; dataFileName or NULL if last one
71         .word dataDiskName      ; dataDiskName
72         .word $0000             ; last one must be NULL
73
74 .bss
75
76 argv0:
77         .res 17                 ; Program name