home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 040A / CCDL151L.ZIP / MSDOS / DEBUG / INPUT.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-03-02  |  4.7 KB  |  220 lines

  1.     .386p        
  2.     .model small
  3.  
  4. include  dispatch.ase 
  5. include  prints.ase 
  6. include  mtrap.ase 
  7. include  regs.ase 
  8. include  dump.ase 
  9. include  entry.ase 
  10. include  exec.ase 
  11. include  breaks.ase 
  12. include  dis.ase 
  13.  
  14.     PUBLIC    qerr, ReadNumber, ReadAddress, InputHandler
  15.     PUBLIC    WadeSpace, PageTrapErr, PageTrapUnerr, GetInputLine
  16.     extrn put_msg:proc, __rexit
  17.  
  18.     extrn put_char : proc, get_char : proc
  19. IBSIZE = 80
  20.  
  21.     .data
  22. oldpagetrap    df    0        ; Temp store for user page trap
  23. inputbuffer db    IBSIZE DUP (?)        ; Input buffer
  24. commands db    "bdegpqrtu"        ; List of commands
  25. comlen    = $ - commands            ; Length of list
  26. prompt    db    10,13,"* ",0        ; MONITOR prompt
  27. InvalidPaging db 10,13,"Invalid paging",0    ; Message for page trap
  28.  
  29.     .code
  30. ;
  31. ; Print an error if command wrong
  32. ;
  33. qerr    PROC    
  34.     mov    ebx,offset CRLF
  35.     call    put_msg
  36.     sub    esi,offset inputbuffer-2; Calculate error pos
  37.     mov    ecx,esi            ;
  38.     jcxz    short qestart        ;
  39.     dec    ecx            ;
  40.     jcxz    short qestart        ;
  41. qelp:                    
  42.     call    printspace              ; Space over to error pos
  43.          loop    qelp
  44. qestart:
  45.     mov    dl,'^'            ; Display error
  46.     call    put_char
  47.     stc                ; Did an error
  48.     ret    
  49. qerr    ENDP    
  50. ;
  51. ; If paging traps, it comes here
  52. ;
  53. PageTrapped    PROC    
  54.     mov    esp,[rtoss]        ;
  55.     call    PageTrapUnerr        ; Turn page trap off
  56.     mov    ebx,offset InvalidPaging
  57.     call    put_msg
  58.     jmp    InputHandler        ; Go do more input
  59. PageTrapped    ENDP    
  60. ;
  61. ; Set up monitor page trap error
  62. ;
  63. PageTrapErr    PROC    
  64.     pusha
  65.     mov     bl,14            ; get user trap vect
  66.     mov     ax,204h
  67.     int    31h
  68.     
  69.     mov    DWORD PTR [oldpagetrap],edx;
  70.     mov    WORD PTR [oldpagetrap + 4],cx;
  71.     mov    ecx,cs            ; Set MONITOR trap interrupt
  72.     mov    edx,offset PageTrapped    ;
  73.     mov    ax,205h
  74.     int     31h
  75.     popa
  76.     ret
  77. PageTrapErr    ENDP    
  78. ;
  79. ; Set user page trap error ( unset monitor error)
  80. ;
  81. PageTrapUnerr    PROC    
  82.     pusha
  83.     mov    edx,DWORD PTR [oldpagetrap]    ; Restore user value
  84.     mov    cx,WORD PTR [oldpagetrap + 4]    ;
  85.     mov    ax,205h
  86.     int     31h
  87.     popa
  88.     ret
  89. PageTrapUnerr    ENDP    
  90. ;
  91. ; Read in a number
  92. ;
  93. ReadNumber    PROC    
  94.     push    ebx
  95.     sub    ebx,ebx            ; Number = 0
  96.     push    ecx
  97.     push    edx
  98.     sub    ecx,ecx            ; digits = 0
  99. rnlp:
  100.     lodsb                ; Get char & convert to uppercase
  101.     cmp    al,60h
  102.     jc    notlower
  103.     and    al,NOT 20h
  104. notlower:
  105.     sub    al,'0'            ; Convert to binary
  106.     jc    short rn_done        ; < '0' is an error
  107.     cmp    al,10            ; See if is a digit
  108.     jc    short gotdigit        ; Yes, got it
  109.     sub    al,7            ; Convert letters to binary
  110.     cmp    al,16            ; Make sure is < 'G'
  111.     jnc    short rn_done        ; Quit if not
  112.     cmp    al,10            ; MAke sure not < 'A'
  113.     jc    short rn_done
  114. gotdigit:
  115.     shl    ebx,4            ; It is a hex digit, add in
  116.     or    bl,al            ;
  117.     inc    ecx            ; Set flag to indicate we got digits
  118.     jmp    rnlp
  119. rn_done:
  120.     dec    esi            ; Point at first non-digit
  121.     test    cl,-1            ; See if got any
  122.     jnz    gotnum            ;
  123.     stc                ; No, error
  124. gotnum:
  125.     pop    edx
  126.     pop    ecx
  127.     mov    eax,ebx
  128.     pop    ebx
  129.     ret    
  130. ReadNumber    ENDP    
  131. ;
  132. ; Read an address, composed of a number and a possible selector
  133. ;
  134. ReadAddress    PROC    
  135.     call    ReadNumber        ; Read in offset
  136.     jc    short raerr        ; Quit if error
  137.     mov    ebx,eax            ;
  138. gotaddr:
  139.     clc                ; OK, exit
  140.     ret
  141. raerr:
  142.     stc                ; Error on number input
  143.     ret
  144. ReadAddress    ENDP    
  145. ;
  146. ; Get an input line
  147. ;
  148. GetInputLine    PROC    
  149.     mov    edi,offset inputbuffer    ; Get input buffer
  150.     mov    esi,edi            ; Return buffer pointer
  151.     mov    ecx,IBSIZE        ; Size of buffer
  152. moreinput:
  153.     call    get_char
  154.     cmp    al,8            ; Is delete or rubout?
  155.     jz    short bkspc        ; Yes - go do it
  156.     cmp    al,7fh            ;
  157.     jz    short bkspc        ; yes - go do it
  158.     stosb
  159.     cmp    al,13            ; Is CR
  160.     jz    short endinput        ; Yes, return
  161.     loop    moreinput        ; Loop till buffer full
  162. endinput:
  163.     ret
  164. bkspc:
  165.     cmp    edi,offset inputbuffer    ; Quit if nothing in buffer
  166.     jz    moreinput        ; And get more input
  167.     mov    dl,' '            ;
  168.     call    put_char
  169.     mov    dl,8            ; Reset pointer
  170.     call    put_char
  171.     dec    edi            ; Point at last char
  172.     jmp    moreinput        ; Get more input
  173. GetInputLine    ENDP    
  174. ;
  175. ; Wade pasth spaces
  176. ;
  177. WadeSpace    PROC    
  178.     lodsb                ; Get char
  179.     cmp    al,' '            ; if ' ' or ',' go again
  180.     jz    short WadeSpace        ;
  181.     cmp    al,','            ;
  182.     jz    short WadeSpace        ;
  183.     dec    esi            ; Point at last space char
  184.     ret
  185. WadeSpace    ENDP    
  186. ;
  187. ; Main Input routine
  188. ;
  189. InputHandler    PROC    
  190.     mov    ebx,offset prompt
  191.     call    put_msg
  192.     call    GetInputLine        ; Get an input line
  193.     call    WadeSpace        ; Wade through spaces
  194.     cmp    al,13            ; Go again if nothing typed
  195.     jz    InputHandler        ;
  196.     inc    esi            ; Point at first non-space char
  197.     mov    edi,offset commands    ; Get command list
  198.     mov    ecx,comlen        ; Length of list
  199.     repne    scasb            ;
  200.     jnz    ierr            ; Error if not in list
  201.     mov    eax,comlen-1        ; Calculate position
  202.     sub    eax,ecx            ;
  203.     push    0            ; command arg = 0
  204.     call    TableDispatch        ; Dispatch command
  205.     dd    comlen-1
  206.     dd    breaks
  207.     dd    dump
  208.     dd    entry
  209.     dd    go
  210.     dd    proceed
  211.     dd    __rexit
  212.     dd    ModifyRegisters
  213.     dd    trap
  214.     dd    diss
  215.     jnc    InputHandler        ; Get more input if no err
  216. ierr:
  217.     call    qerr            ; Display error
  218.     jmp    InputHandler        ; Get more input
  219. InputHandler    ENDP    
  220. END