File: mainargs.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (77 lines) | stat: -rw-r--r-- 1,685 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;
; Ullrich von Bassewitz, 2003-03-07
; Maciej Witkowiak, 2003-05-02
;
; Setup arguments for main
;
; There is always either 1 or 3 arguments:
; <program name>, 0
; or
; <program name>, <data file name>, <data disk name>, 0
; the 2nd case is when using DeskTop user drags an icon of a file and drops it
; on icon of your application
;

            .constructor initmainargs, 24
            .import __argc, __argv

            .include "const.inc"
            .include "geossym.inc"

.segment        "ONCE"

; Setup arguments for main

initmainargs:
; Setup a pointer to our argv vector

        lda #<argv
        sta __argv
        lda #>argv
        sta __argv+1

; Copy program name
        ldy #0
@fn_loop:
        lda dirEntryBuf+OFF_FNAME,y
.ifdef __GEOS_CBM__
        cmp #$a0
.else
        cmp #0
.endif
        beq @fn_end
        sta argv0,y
        iny
        cpy #16+1
        bne @fn_loop
@fn_end:
        lda #0
        sta argv0,y
        sta __argc+1

; Check if there are any more arguments
        lda dataFileName
        bne @threeargs
        ldx #0                  ; no dataFileName - NULL the 2nd argument
        stx argv+2
        stx argv+3
        inx                     ; there is only one argument
        bne @setargc
@threeargs:
        ldx #3                  ; there are three arguments
@setargc:
        stx __argc
        rts

.data

argv:
        .word argv0             ; Pointer to program name
        .word dataFileName      ; dataFileName or NULL if last one
        .word dataDiskName      ; dataDiskName
        .word $0000             ; last one must be NULL

.segment        "INIT"

argv0:
        .res 17                 ; Program name