X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libsrc%2Fc128%2Fmainargs.s;h=fb5fd1554da2d30b8876e6c673d29e5e9d8c7a4b;hb=7ebaec18024dc2a94de538637c20c5b4c65e530c;hp=a3e33e936bd6bdab8a4cb8599e245b4161854aa4;hpb=6211fe8205296759fb9569801d58157a4c386e63;p=cc65 diff --git a/libsrc/c128/mainargs.s b/libsrc/c128/mainargs.s index a3e33e936..fb5fd1554 100644 --- a/libsrc/c128/mainargs.s +++ b/libsrc/c128/mainargs.s @@ -3,7 +3,7 @@ ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, ; 2003-05-18, Greg King -; 2004-04-28, Ullrich von Bassewitz +; 2004-04-28, 2005-02-26, Ullrich von Bassewitz ; ; Scan a group of arguments that are in BASIC's input-buffer. ; Build an array that points to the beginning of each argument. @@ -22,19 +22,22 @@ ; - The "file-name" might be a path-name; don't copy the directory-components. ; - Add a control-character quoting mechanism. - .constructor initmainargs, 24 - .import __argc, __argv + .constructor initmainargs, 24 + .import __argc, __argv - .include "c128.inc" + .include "c128.inc" -MAXARGS = 10 ; Maximum number of arguments allowed -REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +MAXARGS = 10 ; Maximum number of arguments allowed +REM = $8f ; BASIC token-code +NAME_LEN = 16 ; maximum length of command-name -; Get possible command-line arguments. -; +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" + initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD @@ -42,27 +45,27 @@ initmainargs: ; Because the buffer, that we're copying into, was zeroed out, ; we don't need to add a NUL character. ; - ldy FNAM_LEN - cpy #NAME_LEN + 1 - bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy FNAM_LEN + cpy #NAME_LEN + 1 + bcc L1 + ldy #NAME_LEN - 1 ; limit the length L0: lda #FNAM ; Load vector address for FETCH routine ldx FNAM_BANK ; Load bank for FETCH routine jsr INDFET ; Load byte from (FETVEC),y - sta name,y ; Save byte from filename -L1: dey - bpl L0 - inc __argc ; argc always is equal to, at least, 1 + sta name,y ; Save byte from filename +L1: dey + bpl L0 + inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. ; - ldx #0 -L2: lda BASIC_BUF,x - beq done ; no "rem," no args. - inx - cmp #REM - bne L2 - ldy #1 * 2 + ldx #0 +L2: lda BASIC_BUF,x + beq done ; no "rem," no args. + inx + cmp #REM + bne L2 + ldy #1 * 2 ; Find the next argument @@ -88,11 +91,11 @@ setterm:sta term ; Set end of argument marker ; necessary. txa ; Get low byte - sta argv,y ; argv[y]= &arg - iny - lda #>BASIC_BUF - sta argv,y - iny + sta argv,y ; argv[y]= &arg + iny + lda #>BASIC_BUF + sta argv,y + iny inc __argc ; Found another arg ; Search for the end of the argument @@ -119,21 +122,21 @@ argloop:lda BASIC_BUF,x ; (The last vector in argv[] already is NULL.) -done: lda #argv - sta __argv - stx __argv + 1 - rts +done: lda #argv + sta __argv + stx __argv + 1 + rts ; These arrays are zeroed before initmainargs is called. -; char name[16+1]; +; char name[16+1]; ; char* argv[MAXARGS+1]={name}; ; .bss -term: .res 1 -name: .res NAME_LEN + 1 +term: .res 1 +name: .res NAME_LEN + 1 .data argv: .addr name - .res MAXARGS * 2 + .res MAXARGS * 2