;points ES:DX to the 1st supplied item on the command line
;returns flag value in AX


process_cmdline proc near

        push    ds
        push    bx
        push    si


        mov     ah, 51h
        int     21h
        mov     ds, bx




        mov     si, 80h
        movzx   bx, byte ptr[si]
        add     si, bx
        inc     si

        mov     byte ptr[si], NULL             ;zero terminate

        mov     si, 81h

cmdlineloop:

        lodsb

        cmp     al, " "                 ; found a space?
        jz      cmdlineloop
        cmp     al, NULL                ; found end of line?
        jz      exitpc
        cmp     al, "-"                 ; found a flag?
        jz      checkflags
        cmp     al, "/"                 ; found a flag?
        jz      checkflags

        ; must be the filename here.
exitpc:
        dec     si                      ; point to start of filename
        mov     dx, si
        call    save_filename
        pop     si
        pop     bx
        pop     ds
        
        ret

checkflags:
        lodsb
        cmp     al, " "                 ; false flag
        jz      cmdlineloop
        cmp     al, NULL                ; found end of line?
        jz      exitpc
        cmp     al, "-"                 ; found a double flag?
        jz      checkflags
        cmp     al, "/"                 ; found a double flag?
        jz      checkflags

        ; must be a flag

	call	ucase

	cmp	al, "?"
	jz	sethelp

	cmp	al, "H"
	jz	sethelp
	
	cmp	al, "C"
	jz	setnocacheoff

        cmp     al, "N"
        jz      setnodelay

	cmp	al, "D"
	jz	getDelay

	cmp	al, "I"
	jz	getinterval

        cmp     al, "F"
        jz      setnofloppy

        cmp     al, "P"
        jz      setnoPICReset

	jmp     cmdlineloop             ; nothing we care about, continue
                                        ; could jump to help msg
sethelp:
        or      cmdlineflags, help
        jmp     checkflags              ; allows flags to be stacked

setnocacheoff:
        or      cmdlineflags, nocache
        jmp     checkflags

setnodelay:
        or      cmdlineflags, nodelay
        jmp     checkflags

setnofloppy:
        or      cmdlineflags, nofloppy
        jmp     checkflags

setnoPICReset:
        or      cmdlineflags, noPIC
        jmp     checkflags

getdelay:
	lodsb
	mov	ah, 30h
	call	ascii2hex
	cmp	al, 0
	jz	sethelp

	or	cmdlineflags, newdelay
	mov	cs:[delay], al
	jmp	checkflags

getinterval:
	lodsb
	mov	ah, 30h
	call	ascii2hex
	cmp	al, 0
	jz	sethelp

	or	cmdlineflags, newinterval
	mov	cs:[interval], al
	jmp	checkflags

process_cmdline endp


save_filename proc near
; copy the filename to a buffer so chooser can print it out later.

        push    es
        push    cs
        pop     es

        lea     di, fname

copychars:
        lodsb
        stosb
        cmp     al, 0
        jnz     copychars

        pop     es
        ret
save_filename endp



