X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=inline;f=libsrc%2Fatari%2Fgetargs.s;h=fdae55364e5628b48cbc21a663114c120a12f3bd;hb=c48fbd8a2b8b7646bfe43a633becf39ce8e9ba7f;hp=c7eb9b41c489980e37442cc0afea5ede1bf602e7;hpb=3fd58b9068f0446c88451e33f7346ab2459fc4bc;p=cc65 diff --git a/libsrc/atari/getargs.s b/libsrc/atari/getargs.s index c7eb9b41c..fdae55364 100644 --- a/libsrc/atari/getargs.s +++ b/libsrc/atari/getargs.s @@ -1,227 +1,143 @@ ; get arguments from command line (when DOS supports it) -; and supply function to get default device: char *getdefdev(void); ; Freddy Offenga, 4/21/2000 -; SpartaDOS: -; the ZCRNAME routine is only used to get the default drive because -; ZCRNAME has two disadvantages: -; 1. It will convert D: into D1: instead of Dn: (n = default drive) -; 2. It will give a 'no arguments' status if it detects something -; like Dn: (without filename). +; initmainargs is forcibly included by the C compiler if it encounters a +; main() function with arguments. Therefore it isn't referenced by the +; startup code but is nevertheless included in the compiled program when +; needed. -; OS/A+ DOS: -; ZCRNAME is slightly different from SpartaDOS. It will convert D: -; into Dn: where n is the default drive. +MAXARGS = 16 ; max. amount of arguments in arg. table +CL_SIZE = 64 ; command line buffer size +SPACE = 32 ; SPACE char. -MAXARGS = 16 ; max. amount of arguments in arg. table -CL_SIZE = 64 ; command line buffer size -SPACE = 32 ; SPACE char. - - .include "atari.inc" - .export getargs, argc, argv, __dos_type - .export _getdefdev ; get default device (e.g. "D1:") - .importzp ptr1 + .include "atari.inc" + .import __argc, __argv + .importzp ptr1 + .import __dos_type + .constructor initmainargs,25 +; -------------------------------------------------------------------------- ; Get command line -getargs: - lda #0 - sta argc - sta argc+1 - sta argv - sta argv+1 - - jsr detect - bcs argdos ; carry set = DOS supports arguments - rts - -; Initialize ourcl buffer - -argdos: lda #ATEOL - sta ourcl+CL_SIZE - -; Move SpartaDOS command line to our own buffer - - lda DOSVEC - clc - adc #LBUF - sta ptr1+1 - - ldy #0 -cpcl: lda (ptr1),y - sta ourcl,y - iny - cmp #ATEOL - beq movdon - cpy #CL_SIZE - bne cpcl +.segment "INIT" -movdon: lda #0 - sta ourcl,y ; null terminate behind ATEOL +initmainargs: + lda #0 + sta __argc + sta __argc+1 + sta __argv + sta __argv+1 -; Get default device (LBUF will be destroyed!!) + lda __dos_type ; which DOS? + cmp #ATARIDOS + beq nargdos ; DOS does not support arguments + cmp #MYDOS + bne argdos ; DOS supports arguments +nargdos:rts - ldy #BUFOFF - lda #0 - sta (DOSVEC),y ; reset buffer offset - -; Store dummy argument - - ldy #LBUF - lda #'X' - sta (DOSVEC),y - iny - lda #ATEOL - sta (DOSVEC),y - -; One extra store to avoid the buggy sequence from OS/A+ DOS: -; <:> => drive number = - - iny - sta (DOSVEC),y - -; Create crunch vector - - ldy #ZCRNAME+1 - lda (DOSVEC),y - sta crvec+1 - iny - lda (DOSVEC),y - sta crvec+2 +; Initialize ourcl buffer -crvec: jsr $FFFF ; will be set to crunch vector +argdos: lda #ATEOL + sta ourcl+CL_SIZE -; Get default device +; Move SpartaDOS command line to our own buffer - ldy #COMFNAM ; COMFNAM is always "Dn:" - lda (DOSVEC),y - sta defdev - iny - lda (DOSVEC),y - sta defdev+1 + lda DOSVEC + clc + adc #LBUF + sta ptr1+1 + + ldy #0 +cpcl: lda (ptr1),y + sta ourcl,y + iny + cmp #ATEOL + beq movdon + cpy #CL_SIZE + bne cpcl + +movdon: lda #0 + sta ourcl,y ; null terminate behind ATEOL ; Turn command line into argv table - ldy #0 -eatspc: lda ourcl,y ; eat spaces - cmp #ATEOL - beq finargs - cmp #SPACE - bne rpar ; begin of argument found - iny - cpy #CL_SIZE - bne eatspc - beq finargs ; only spaces is no argument + ;ldy #0 + tay +eatspc: lda ourcl,y ; eat spaces + cmp #ATEOL + beq finargs + cmp #SPACE + bne rpar ; begin of argument found + iny + cpy #CL_SIZE + bne eatspc + beq finargs ; only spaces is no argument ; Store argument vector -rpar: lda argc ; low-byte - asl - tax ; table index - tya ; ourcl index - clc - adc #ourcl - adc #0 - sta argv+1,x - ldx argc - inx - stx argc - cpx #MAXARGS - beq finargs +rpar: lda __argc ; low-byte + asl + tax ; table index + tya ; ourcl index + clc + adc #ourcl + adc #0 + sta argv+1,x + ldx __argc + inx + stx __argc + cpx #MAXARGS + beq finargs ; Skip this arg. skiparg: - ldx ourcl,y - cpx #ATEOL ; end of line? - beq eopar - cpx #SPACE - beq eopar - iny - cpy #CL_SIZE - bne skiparg + ldx ourcl,y + cpx #ATEOL ; end of line? + beq eopar + cpx #SPACE + beq eopar + iny + cpy #CL_SIZE + bne skiparg ; End of arg. -> place 0 eopar: - lda #0 - sta ourcl,y - iny ; y behind arg. - cpx #ATEOL ; was it the last arg? - bne eatspc + lda #0 + sta ourcl,y + iny ; y behind arg. + cpx #ATEOL ; was it the last arg? + bne eatspc ; Finish args finargs: - lda argc - asl - tax - lda #0 - sta argv,x - sta argv+1,x - rts - -; DOS type detection - -detect: - lda #ATARIDOS - sta __dos_type ; set default - - lda DOS - cmp #$53 ; "S" (SpartaDOS) - beq spdos - - ldy #COMTAB - lda #$4C - cmp (DOSVEC),y - bne nordos - - ldy #ZCRNAME - cmp (DOSVEC),y - bne nordos - - ldy #6 ; OS/A+ has a jmp here - cmp (DOSVEC),y - beq nordos - lda #OSADOS - sta __dos_type - bne spdos1 - -spdos: lda #SPARTADOS - sta __dos_type -spdos1: sec ; SpartaDOS, OS/A+ or DOS XL - rts - -nordos: clc ; normal DOS (no args) detected - rts - -; Get default device (set by getargs routine) - -_getdefdev: - lda #defdev - rts - - .data - -; Default device - -defdev: - .byte "D1:", 0 + lda __argc + asl + tax + lda #0 + sta argv,x + sta argv+1,x + lda #argv + sta __argv + stx __argv+1 + rts - .bss +; -------------------------------------------------------------------------- +; Data -argc: .res 2 -argv: .res (1 + MAXARGS) * 2 +.bss -__dos_type: .res 1 +argv: .res (1 + MAXARGS) * 2 ; Buffer for command line / argv strings -ourcl: .res CL_SIZE+1 +ourcl: .res CL_SIZE+1