home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bbl-v-1.zip / TSTCMD.ASM < prev   
Assembly Source File  |  1992-08-18  |  9KB  |  418 lines

  1.     title    tstcmd
  2.     page    58,132
  3. ;
  4. ;    Program to test command-line handling for BBL device-driver 
  5. ;    
  6. ;    Invoke as
  7. ;        tstcmd c:\bbl.sys /font=att /mode=0
  8. ;    for example, or invoke with Turbo debugger with command line
  9. ;    as above.
  10. ;
  11.  
  12. PSP_Cmd EQU    080h
  13. LFChar    EQU    0ah
  14. CRChar    EQU    0dh
  15. HTChar    EQU    09h
  16. ModeMax    EQU    '2'        ;max number of virtual display modes
  17.  
  18. stak    SEGMENT para STACK 'STACK'
  19.  
  20.     db    64 DUP ('STACK   ')
  21. stak    ENDS
  22.  
  23. dseg    SEGMENT    para public 'DATA'
  24.  
  25. ATTMsg    db    'ATT font ptr loaded',CRChar, LFChar,'$'
  26. EGAMsg    db    'EGA font ptr loaded',CRChar, LFChar,'$'
  27. VGAMsg    db    'VGA font ptr loaded',CRChar, LFChar,'$'
  28. HexMsg    db    'Hex font ptr loaded',CRChar, LFChar,'$'
  29. ModMsg    db    'Mode set to $'
  30. FontStr    db    'FONT'
  31. ModeStr    db    'MODE'
  32. ATTStr    db    'ATT'
  33. EGAStr    db    'EGA'
  34. VGAStr    db    'VGA'
  35. CmdErrStr db    'Unrecognized switch: $'
  36. ModErrStr db    'Invalid Mode value (must be 0..2): $'
  37. HexErrStr db    'Invalid hexidecimal string: $'
  38. CRLF    db    CRChar,LFChar,'$'
  39. ;MyString db    'c:\bbl.sys /Font=ATT /Mode=2',LFChar
  40. BBLMsg    db    'Loaded BBL device driver',CRChar,LFChar,'$'
  41. CurrMode db    0
  42. fp_off    dw    0
  43. fp_seg    dw    0
  44. HexStart dw    0
  45.  
  46. dseg    ENDS
  47.  
  48. cseg    SEGMENT    para public 'CODE'
  49.     assume CS:cseg, DS:dseg, SS:stak
  50.  
  51. Main    PROC    FAR
  52.  
  53.     push    ds
  54.     xor    ax,ax
  55.     push    ax
  56.     mov    ax,dseg
  57.  
  58.     mov    ds,ax
  59. ;    mov    es,ax
  60. ;    mov    si,offset MyString
  61.  
  62.     mov    ah,62h        ;for testing purposes, get command
  63.     int    21h        ; string ptr from PSP into
  64.     mov    es,bx        ; es:si 
  65.     mov    si,PSP_Cmd
  66.  
  67. CmdLup:    call    SkipSwitch    ;skip everthing to & including '/'
  68.      jc    CmdDone        ; hit end of line ... we're done
  69.     call    GetToken    ;get the next token after the /
  70.      jc    CmdDone        ;wasn't one ... we're done
  71.  
  72.                 ;es:si points to the start of the token
  73.                 ;es:di points to the first char after it
  74.     lea    dx,FontStr    ;compare with "FONT"
  75.     call    ChkTok
  76.      jne    NotFont        ;skip if not "FONT"
  77.     mov    si,di        ;update over recognized keyword
  78.     call    Font        ;yes, got "FONT" ... do it
  79.     jmp    CmdLup        ;and return for more
  80.  
  81. NotFont: lea    dx,ModeStr    ;check "MODE"
  82.     call    ChkTok
  83.      jne    NotMode        ;skip if not "MODE"
  84.     mov    si,di        ;update over recognized keyword
  85.     call    Mode        ;yes, got "MODE"
  86.     jmp    CmdLup        ;and return for more
  87.  
  88. NotMode:
  89. ;insert others here with the pattern
  90. ;    lea    dx,CMDStr    ;check "CMD"
  91. ;    call    ChkTok
  92. ;     jne    NotCMD        ;skip if not "CMD"
  93. ;    call    CMD        ;process "CMD"
  94. ;    jmp    CmdLup        ;and return for more
  95.  
  96. NotCmd:    
  97.     mov    ah,09h        ;if none of the above, issue error
  98.     lea    dx,CmdErrStr    
  99.     int    21h
  100.     call    PrtStr        ;print the offending string & advance si
  101.     mov    ah,09h        ;now the suffix
  102.     lea    dx,CRLF
  103.     int    21h
  104.     jmp    CmdLup
  105. CmdDone: lea    dx,BBLmsg
  106.     mov    ah,09h
  107.     int    21h
  108.     retf
  109.  
  110. Main    ENDP
  111.  
  112. SkipSwitch PROC    NEAR
  113. SSLoop:    cmp    BYTE PTR es:[si],'/' ;got a switch?
  114.      je    GotS        ;yes
  115.     cmp    BYTE PTR es:[si],0ah ;end of line?
  116.      je    EndLine        ;yes
  117.     inc    si        ;none of the above ... skip it
  118.      jmp    SSLoop
  119.  
  120. Gots:    inc    si        ;skip that /
  121.     clc            ;clear the flag
  122.     ret            ;done
  123. EndLine: stc            ;set the flag to alert of eol
  124.     ret
  125. SkipSwitch ENDP
  126.  
  127. GetToken PROC    NEAR
  128.     call    SkipBlanks
  129.     mov    di,si        ;advance es:di over the token
  130. GetLup:    mov    al,BYTE PTR es:[di] ;examine next char
  131.     call    MakeUpper    ;make sure it's upper case
  132.     mov    BYTE PTR es:[di],al
  133. NotLow:    cmp    al,' '        ;blank, tab, '=', '/' or eoln is a delimiter
  134.      je    GetDone
  135.     cmp    al,LFChar
  136.      je    GetDone
  137.     cmp    al,HTChar
  138.      je    GetDone
  139.     cmp    al,'/'
  140.      je    GetDone
  141.     cmp    al,'='
  142.      je    GetDone
  143.     inc    di        ;it was none of them ... part of token
  144.     jmp    GetLup
  145. GetDone: ret
  146. GetToken ENDP
  147.  
  148. SkipBlanks PROC    NEAR
  149.                 ;skip whitespace in string es:si
  150.                 ;return advanced si pointer
  151.                 ;carry set ==> eoln (end of string) encountered
  152.                 ;carry clear ==> found non-space
  153. SBLup:    cmp    BYTE PTR es:[si],' '    ;spaces or tabs and eoln are "blanks"
  154.      je    SBInc
  155.     cmp    BYTE PTR es:[si],HTChar
  156.      je    SBInc
  157.     cmp    BYTE PTR es:[si],LFChar
  158.      je    SBeoln        ;if eoln, say so
  159.     clc            ;otherwise, clear carry (not at eoln)
  160.     ret            ; and we've done our job
  161. SBeoln:    stc            ;got an eoln ... flag it
  162.     ret            ;and ... we're done
  163. SBInc:    inc    si
  164.     jmp    SBLup        ;go look at next one
  165.  
  166. SkipBlanks ENDP
  167.  
  168. Font    PROC    NEAR
  169.  
  170.     call    SkipEqual    ;skip the equal sign
  171.     call    GetToken    ;get the option value
  172.     lea    dx,ATTStr
  173.     call    ChkTok
  174.      jne    NotATT
  175.     call    SetATT
  176.     mov    si,di        ;skip that token
  177.     ret
  178. NotATT:    lea    dx,EGAStr
  179.     call    ChkTok
  180.      jne    NotEGA
  181.     call    SetEGA
  182.     mov    si,di        ;skip that token
  183.     ret
  184. NotEGA:    lea    dx,VGAStr
  185.     call    ChkTok
  186.      jne    NotVGA
  187.     call    SetEGA
  188.     mov    si,di        ;skip that token
  189.     ret
  190. NotVGA:    mov    HexStart,si    ;save ptr to start of hex string for error msg
  191.     call    GetHex
  192.      jc    HexErr
  193.     mov    fp_seg,dx
  194.     cmp    BYTE PTR es:[si],':'    ;need ':' as a separator
  195.      jc    HexErr        ;oops
  196.     inc    si        ;ok, go on
  197.     call    GetHex
  198.      jc    HexErr
  199.     mov    fp_off,dx
  200.     lea    dx,HexMsg    ;[hdt]kill
  201.     mov    ah,09h
  202.     int    21h
  203.     ret
  204.  
  205. Font    ENDP
  206.  
  207.  
  208. SkipEqual PROC    NEAR
  209.                 ;advances es:si to the first char past
  210.                 ; next '=' on line
  211.                 ;sets carry if eoln found during scan
  212.                 ;clears if valid char follows '='
  213. SELup:    cmp    BYTE PTR es:[si],'='    ;found it yet?
  214.      je    FndEqual        ;yes
  215.     cmp    BYTE PTR es:[si],LFChar    ;no ... at end of line?
  216.      je    SEeoln        ;if eoln, say so
  217.     inc    si        ;otherwise, go look at next char
  218.     jmp    SELup
  219. SEeoln:    stc            ;got an eoln ... flag it
  220.     ret            ;and we're done
  221. FndEqual:            ;found an =
  222.     inc    si        ;skip it
  223.     cmp    BYTE PTR es:[si],LFChar    ;is it eoln?
  224.      je    SEeoln        ;yes, flag and return
  225.     clc            ;no, we're ok, just return
  226.     ret    
  227.  
  228. SkipEqual ENDP
  229.  
  230.  
  231. SetATT    PROC    NEAR
  232.  
  233.     lea    dx,ATTMsg
  234.     mov    ah,09h
  235.     int    21h
  236.     ret
  237.  
  238. SetATT    ENDP
  239.  
  240.  
  241. SetEGA    PROC    NEAR
  242.  
  243.     lea    dx,EGAMsg
  244.     mov    ah,09h
  245.     int    21h
  246.     ret
  247.  
  248. SetEGA    ENDP
  249.  
  250. HexErr    PROC    NEAR
  251.  
  252.                 ;prints out error message for invalid
  253.                 ;hex string started at es:si and ending
  254.                 ;the char before es:di
  255.                 ;advances es:si past that string
  256.     mov    ah,09h
  257.     lea    dx,HexErrStr    ;print the error msg
  258.     int    21h
  259.     call    PrtStr        ;print the offending string
  260.     mov    ah,09h
  261.     lea    dx,CRLF        ;and finish it off
  262.     int    21h
  263.     mov    si,di        ;make sure we advance past it
  264.     ret            ;and we're done
  265.  
  266. HexErr    ENDP
  267.  
  268.  
  269. GetHex    PROC    NEAR
  270.                 ;converts a 4-digit hex string 
  271.                 ;beginning at es:si into a binary hex
  272.                 ;value.  Returns
  273.                 ;    binary value in dx
  274.                 ;    es:si advanced over hex string
  275.                 ;       if no error, not advanced if
  276.                 ;       the string was invalid
  277.                 ;    carry set if error, clear if none
  278.                 ;saves other regs
  279.  
  280.     push    ax
  281.     push    cx
  282.     push    si
  283.     mov    cx,4        ;we always do 4 digits!
  284.     xor    dx,dx
  285.  
  286. GHLup:    xor    ax,ax
  287.     mov    al,BYTE PTR es:[si]    ;get the next char
  288.     inc    si        ;and record that
  289.     cmp    al,'0'        ;is it a digit?
  290.      jl    GHErr        ; no
  291.     cmp    al,'9'        ;maybe
  292.      jg    GHAlpha        ; well, not 0..9
  293.     sub    al,'0'        ;yes, valid digit
  294. GHInsert:            ;ok, insert it into the resulting word
  295.     shl    dx,1
  296.     shl    dx,1
  297.     shl    dx,1
  298.     shl    dx,1
  299.     or    dx,ax
  300.     loop    GHLup        ;and do it again
  301.     clc            ;all done - flag no error
  302.     pop    cx        ;throw away saved si -- leave string
  303.                 ;pointer advanced
  304.     pop    cx        ;restore real cx
  305.     pop    ax
  306.     ret
  307. GHAlpha: call    MakeUpper    ;raise if alpha
  308.     cmp    al,'A'        ;is it in hex range
  309.      jl    GHErr        ;no
  310.     cmp    al,'F'
  311.      jg    GHErr
  312.     sub    al,'A'        ;yes -- convert to binary value
  313.     add    al,0ah
  314.     jmp    GHInsert    ;and insert it into the resulting word
  315.  
  316. GHerr:    stc            ;oops ... some character offended ... say so
  317.     pop    si        ;restore original si
  318.     pop    cx
  319.     pop    ax
  320.     ret
  321.  
  322. GetHex    ENDP
  323.  
  324.  
  325. MakeUpper PROC    NEAR
  326.                 ;converts the char in al to upper case,
  327.                 ; if necessary
  328.     cmp    al,'a'
  329.      jl    MUDone
  330.     cmp    al,'z'
  331.      jg    MUDone
  332.     sub    al,'a'-'A'
  333. MUDone:    ret
  334.  
  335. MakeUpper ENDP
  336.  
  337. PrtStr    PROC    NEAR
  338.                 ;prints the string between es:si and
  339.                 ;the char before es:di and advances si
  340.                 ;
  341.                 ;returns si with value of initial di
  342.     push    ax
  343.     push    dx
  344. PSLup:  cmp    si,di        ;any left to print?
  345.      jge    PSDone        ;no
  346.     mov    dl,BYTE PTR es:[si]
  347.     mov    ah,02h
  348.     int    21h
  349.     inc    si
  350.     jmp    PSLup
  351. PSDone:    pop    dx
  352.     pop    ax
  353.     ret
  354.  
  355. PrtStr    ENDP
  356.  
  357.  
  358. ChkTok    PROC    NEAR
  359.                 ;compare string between es:si & es:di
  360.                 ;with string pointed to by ds:dx
  361.                 ;use je to check for equality on return
  362.     push    cx
  363.     mov    cx,di        ;compute char count for cmpsb
  364.     sub    cx,si
  365.     push    si        ;save registers
  366.     push    di
  367.     push    si
  368.     pop    di
  369.     mov    si,dx
  370.     cmpsb            ;do compare
  371.     pop    di        ;restore & return
  372.     pop    si
  373.     pop    cx
  374.     ret
  375.  
  376. ChkTok    ENDP
  377.  
  378. Mode    PROC    NEAR
  379.  
  380.     call    SkipEqual    ;skip equal sign
  381.     mov    al,BYTE PTR es:[si]    ;get that char
  382.     inc    si        ;move over it
  383.     cmp    al,'0'        ;got a digit?
  384.      jl    ModErr        ; nope ... error
  385.     cmp    al,ModeMax    ;within upper range limit?    
  386.      jg    ModErr        ; no ... report error
  387.     push    ax        ;[hdt]kill
  388.     sub    al,'0'        ;convert that digit
  389.     mov    CurrMode,al    ;set it
  390.     lea    dx,ModMsg
  391.     mov    ah,09h        ;[hdt]kill
  392.     int    21h
  393.     pop    dx
  394.     mov    ah,02h
  395.     int    21h
  396.     mov    ah,09h
  397.     lea    dx,CRLF
  398.     int    21h
  399.     
  400.  
  401.     ret
  402. ModErr:    push    ax        ;save the offending digit
  403.     mov    ah,09h        ;print error header
  404.     lea    dx,ModErrStr
  405.     int    21h
  406.     pop    dx
  407.     mov    ah,02h        ;print digit
  408.     int    21h
  409.     mov    ah,09h
  410.     lea    dx,CRLF        ;end the message
  411.     int    21h
  412.     ret
  413. Mode    ENDP
  414.  
  415. cseg    ends
  416.  
  417.     END    Main
  418.