; cmdline.as - process command line from MSX-DOS(2) ; Copyright (C) 2001 ag0ny@ag0ny.com BDOS equ 00005h DTA equ 00080h _STROUT equ 009h LF equ 00ah ; Line feed CR equ 00dh ; Carriage return system macro func ld c,func call BDOS endm start: ld (STACK),sp ld hl,ifile ; Clear FCBs for ifile and ofile ld de,ifile+1 ld bc,75 ld (hl),0 ldir call cmdline jp end ; *************** ; * Subroutines * ; *************** cmdline: ld hl,DTA ld a,(hl) ; Read command line size or a jp z,usage inc hl ; First character after the command ; name is always a space param: inc hl ld a,(hl) or a ret z ; return if no more parameters cp '-' jr nz,param inc hl ld a,(hl) cp 'v' ; -v jp z,version cp 'i' ; -i or -i call z,inputfile cp 'o' ; -o or -o call z,outputfile cp '?' ; -? jp z,usage jr param inputfile: push af inc hl ld de,ifile call parsefile pop af ret outputfile: push af inc hl ld de,ofile call parsefile pop af ret ; parse filename ; input: HL -> pointer to start of filename ; DE -> filename buffer ; note: removes spaces at the beginning of the pointed string ; note: will return after finding a SPACE or NULL after the filename, ; so more parameters can be processed from the commandline ; parsefile: push hl push de ; clear filename buffer ld h,d ld l,e ld (hl),32 ; ASCII 32 = SPACE inc de ld bc,10 ldir pop de pop hl ld (tmpword),de ; because we'll need this address ; on the .EXT parsing part ld a,(hl) ; return if NULL found or a ret z pf.2: cp ' ' ; remove space(s) at the beginning jr nz,pf.1 inc hl ld a,(hl) jr pf.2 pf.1: ; get main filename part (FFFFFFFF) ld b,8 pf.4: or a ; return if NULL found ret z cp ' ' ; return if SPACE (get next param) ret z cp '.' jr z,pf.3 ; point found, process extension ld (de),a ; tests passed, store character inc de inc hl ld a,(hl) djnz pf.4 pf.3: ; get extension (.EXT) inc hl ld a,(hl) ld b,3 ld de,(tmpword) ; now DE = start of filename again inc de inc de inc de inc de inc de inc de inc de inc de ; now DE = start of .EXT part pf.5: or a ; return if NULL found ret z cp ' ' ; return if SPACE (get next param) ret z ld (de),a ; tests passed, store character inc de inc hl ld a,(hl) djnz pf.5 ret ; print version information version: ld de,msg005 system _STROUT jp end ; print program information and usage usage: ld de,msg003 system _STROUT ; restore original stack and exit to MSX-DOS(2) end: ld hl,(STACK) ld sp,hl ret ; error - display error message pointed by DE followed by usage and exit error: system _STROUT ld de,msg004 system _STROUT jp end ifile: defs 37 ; FCB for input file ofile: defs 37 ; FCB for output file ifileon: defb 0 ; Input file specified in commandline? ofileon: defb 0 ; Output file specified in commandline? STACK: defs 2 ; Original program stack tmpword: defs 2 ; Temporary storage place msg000: defb 'Input file : $' msg001: defb 'Output file: $' msg002: defb 'Boolean : $' msg003: defb 'cmdline.as - process command line from MSX-DOS(2)' defb CR,LF defb 'Copyright (C) 2001 ag0ny@ag0ny.com',CR,LF,CR,LF msg004: defb 'Usage: cmdline [options]',CR,LF,CR,LF defb ' -i Input file (must be a binary dump of' defb ' a ROM or program)',CR,LF defb ' -o Output file. If not present, defaults' defb ' to the same name as the',CR,LF defb ' input filename with .HEX extension.' defb CR,LF defb ' -v Print version and exit',CR,LF defb ' -? Print this help message and exit',CR,LF defb '$' msg005: defb 'v0.01/20010424',CR,LF,'$' msgon: defb 'ON$' msgoff: defb 'OFF$' error000: defb 'Error: invalid input filename.',CR,LF,CR,LF,'$' error001: defb 'Error: (2)',CR,LF,CR,LF,'$' error002: defb 'Error: (3)',CR,LF crlf: defb CR,LF,'$'  Input file (must be a binary dump of' defb ' a ROM or program)',CR,LF defb ' -o Output file. If not present, defaults' defb ' to the same name as the',CR,LF defb ' input filename with .HEX extension.' defb CR,LF defb ' -v Print version and exit',CR,LF defb ' -? Print this help message and exit',CR,LF defb '$' msg005: defb 'v0.01/20010424',CR,LF,'$' msgon: defb 'ON$' msgoff: defb 'OFF$' error000: defb 'Error: invalid input filename.',CR,LF,CR,LF,'$' error001: defb 'Error: (2)',CR,LF,CR,LF,'$' error002: defb 'Error: (3)',CR,LF crlf: defb CR,LF,'$'  crlf: defb CR,LF,'$'